summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile19
-rwxr-xr-x[-rw-r--r--]build.sh0
-rw-r--r--src/boot/bootloader.asm29
-rw-r--r--src/kernel.asm27
-rw-r--r--src/linker.ld27
6 files changed, 77 insertions, 26 deletions
diff --git a/.gitignore b/.gitignore
index a8a0dce..f6cf5af 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
*.bin
+build/cemOS.o build/kernel.asm.o
diff --git a/Makefile b/Makefile
index 4df65dd..8f4b284 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,24 @@
+FILLES = ./build/kernel.asm.o
+
BOOTLOADER=./src/boot/bootloader.asm
TARGET=./bin/boot.bin
-all:
+all: ./bin/boot.bin ./bin/kernel.bin
+ rm -rf ./bin/os.bin
+ dd if=./bin/boot.bin >> ./bin/os.bin
+ dd if=./bin/kernel.bin >> ./bin/os.bin
+ dd if=/dev/zero bs=512 count=100 >> ./bin/os.bin
+./bin/kernel.bin: ./build/kernel.asm.o
+ i686-elf-ld -g -relocatable ./build/kernel.asm.o -o ./build/cemOS.o
+ i686-elf-gcc -T ./src/linker.ld -o ./bin/kernel.bin -ffreestanding -O0 -nostdlib ./build/cemOS.o
+
+./bin/boot.bin: ./src/boot/bootloader.asm
nasm -f bin $(BOOTLOADER) -o $(TARGET)
+
+./build/kernel.asm.o: ./src/kernel.asm
+ nasm -f elf -g ./src/kernel.asm -o ./build/kernel.asm.o
+
clean:
rm -f $(TARGET)
+ rm -f build/cemOS.o
+ rm -f build/kernel.asm.o
diff --git a/build.sh b/build.sh
index ff9b513..ff9b513 100644..100755
--- a/build.sh
+++ b/build.sh
diff --git a/src/boot/bootloader.asm b/src/boot/bootloader.asm
index fc17af8..eb226a6 100644
--- a/src/boot/bootloader.asm
+++ b/src/boot/bootloader.asm
@@ -3,6 +3,7 @@ BITS 16
CODE_SEG equ gdt_code - gdt_start ; 0x8
DATA_SEG equ gdt_data - gdt_start ; 0x10
+
_start:
jmp short start
nop
@@ -34,7 +35,9 @@ step2:
mov eax, cr0
or eax, 0x1
mov cr0, eax
- jmp CODE_SEG:start_32
+
+ jmp $
+; jmp CODE_SEG:start_32
; GDT table description
gdt_start:
@@ -71,30 +74,6 @@ gdt_table:
dw gdt_end - gdt_start - 1
dd gdt_start
-
-[BITS 32]
-
-; No access to BIOS from now on....
-start_32:
- ; Set all segments to the same as the DATA_SEG
- mov ax, DATA_SEG
- mov ds, ax
- mov es, ax
- mov fs, ax
- mov gs, ax
- mov ss, ax
-
- ; Set the stack pointer and base pointer further in mem
- mov ebp, 0x00200000
- mov esp, ebp
-
- ; Enable A20 line
- in al, 0x92
- or al, 2
- out 0x92, al
-
- jmp $
-
; Fill in to the end and add bootloader signature
times 510 - ($ - $$) db 0
dw 0xAA55
diff --git a/src/kernel.asm b/src/kernel.asm
new file mode 100644
index 0000000..93afff7
--- /dev/null
+++ b/src/kernel.asm
@@ -0,0 +1,27 @@
+[BITS 32]
+global _start
+
+CODE_SEG equ 0x08
+DATA_SEG equ 0x10
+
+; No access to BIOS from now on....
+_start:
+ ; Set all segments to the same as the DATA_SEG
+ mov ax, DATA_SEG
+ mov ds, ax
+ mov es, ax
+ mov fs, ax
+ mov gs, ax
+ mov ss, ax
+
+ ; Set the stack pointer and base pointer further in mem
+ mov ebp, 0x00200000
+ mov esp, ebp
+
+ ; Enable A20 line
+ in al, 0x92
+ or al, 2
+ out 0x92, al
+
+ jmp $
+
diff --git a/src/linker.ld b/src/linker.ld
new file mode 100644
index 0000000..9ea0171
--- /dev/null
+++ b/src/linker.ld
@@ -0,0 +1,27 @@
+ENTRY(_start)
+OUTPUT_FORMAT(binary)
+
+SECTIONS {
+ . = 1M;
+
+ .text :
+ {
+ *(.text)
+ }
+
+ .rodata :
+ {
+ *(.rodata)
+ }
+
+ .data :
+ {
+ *(.data)
+ }
+
+ .bss :
+ {
+ *(COMMON)
+ *(.bss)
+ }
+}