Skip to content

Commit

Permalink
separate kernel and bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
pcichowski committed Oct 15, 2022
1 parent 71a31ff commit 78e8cee
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 31 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
all:
FILES = ./build/kernel.asm.o

all: ./bin/boot.bin $(FILES)
rm -rf ./bin/os.bin
dd if=./bin/boot.bin >> ./bin/os.bin

./bin/boot.bin: ./src/boot/boot.asm
nasm -f bin ./src/boot/boot.asm -o ./bin/boot.bin

./build/kernel.asm.o: ./src/kernel.asm
nasm -f elf -g ./src/kernel.asm -o ./build/kernel.asm.o

clean:
rm -rf ./bin/boot.bin
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

export PREFIX="$HOME/opt/cross"
export TARGET=i686-elf
export PATH="$PREFIX/bin:$PATH"
make all
Binary file added build/kernel.asm.o
Binary file not shown.
32 changes: 2 additions & 30 deletions src/boot/boot.asm
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ step2:
mov eax, cr0
or eax, 0x1
mov cr0, eax
jmp CODE_SEG:load32

;jmp CODE_SEG:load32
jmp $

; -- GDT --
gdt_start:
Expand Down Expand Up @@ -58,33 +58,5 @@ gdt_descriptor:
dw gdt_end - gdt_start-1
dd gdt_start

;
; ---- protected mode starts here ----
;
[BITS 32]
load32:
; set data segments to the correct GDT
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax

; move the stack furthet
mov ebp, 0x00200000
mov esp, ebp

; enable the A20 line
in al, 0x92
test al, 2
jnz .after
or al, 2
and al, 0xFE
out 0x92, al
.after:

jmp $

times 510- ($ - $$) db 0 ; zero out 510 bytes of data
dw 0xAA55 ; add boot signature
27 changes: 27 additions & 0 deletions src/kernel.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[BITS 32]
CODE_SEG equ 0x08
DATA_SEG equ 0x10

load32:
; set data segments to the correct GDT
mov ax, DATA_SEG
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax

; move the stack furthet
mov ebp, 0x00200000
mov esp, ebp

; enable the A20 line
in al, 0x92
test al, 2
jnz .after
or al, 2
and al, 0xFE
out 0x92, al
.after:

jmp $
27 changes: 27 additions & 0 deletions src/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ENTRY(_start)
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 1M
.text :
{
*(.text)
}

.rodata :
{
*(.rodata)
}

.data :
{
*(.data)
}

.bss :
{
*(COMMON)
*(.bss)
}
}

0 comments on commit 78e8cee

Please sign in to comment.