Skip to content

Commit bf2cc5f

Browse files
committed
Added loading of kernel and added kernel itself. Last working build stored in build folder
1 parent 6002012 commit bf2cc5f

9 files changed

Lines changed: 29 additions & 23 deletions

File tree

boot.asm

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
[bits 16] ; Defines architecture of bootloader
22
org 0x7c00 ; Defines general offset
33

4-
5-
global _start ; Defines entrypoint
4+
global _boot ; Defines entrypoint
65

76
; Code section
87
section .text:
9-
_start:
8+
_boot:
9+
xor ax, ax
10+
mov ds, ax
11+
mov es, ax
12+
1013
mov bp, 0x8000 ; Set origin of stack
1114
push bp
1215
mov bp, sp
@@ -16,7 +19,7 @@ section .text:
1619

1720
push ax ; Saves AX to stack
1821
push bx ; Saves BX to stack
19-
push msg1 ; Loads message to stack
22+
push msg ; Loads message to stack
2023
call _printformat ; Prints the message
2124
pop ax ; Recover AX value from stack
2225
pop bx ; Recover BX value from stack
@@ -35,9 +38,12 @@ section .text:
3538

3639
mov [disk_index], dl ; Save boot disk to variable
3740
mov bx, kernel_address ; Write to BX kernel origin
38-
mov dh, 1 ; Read one sectors
41+
mov dh, 0x02 ; Read two sectors
3942
call _read_disk ; Read 16 bits from disk
4043

44+
mov ax, 0x03 ; Clears screen
45+
int 10h ; Use interuption
46+
4147

4248
cli ; Disables BIOS interupts
4349
lgdt [GDT_descriptor] ; Load GDT
@@ -47,8 +53,6 @@ section .text:
4753
jmp CODE_SEG:_enter_protected_mode
4854

4955
_stop:
50-
push msg2
51-
call _printformat
5256
call _shutdown
5357

5458

@@ -57,8 +61,7 @@ section .text:
5761
%include "bootloader/disk_mng.asm"
5862
%include "bootloader/shutdown.asm"
5963

60-
msg1: db "Hello, There!\nDo You want to enter 32 bit mode?[Y]/[N](default=Y) \0" ; Printable string
61-
msg2: db "Goodby!\0"
64+
msg: db "Hello, There!\nDo You want to enter 32 bit mode?[Y]/[N](default=Y) \0" ; Printable string
6265

6366
buffer: db 'Y' ; Defines input buffer
6467

@@ -105,13 +108,17 @@ GDT_start:
105108

106109
[bits 32]
107110
_enter_protected_mode:
108-
mov al, 'A'
109-
mov ah, 0x0f
110-
mov [0xb8000], ax
111-
jmp $
111+
mov ax, DATA_SEG
112+
mov ds, ax
113+
mov ss, ax
114+
mov es, ax
115+
mov fs, ax
116+
mov gs, ax
112117

118+
mov ebp, 0xF0000
119+
mov esp, ebp
113120

114-
times 510-($-$$) db 0 ; Fills binary with 0 to keep the offset of 512
115-
dw 0xAA55 ; Magic Word
121+
jmp kernel_address
116122

117-
times 512 db 'A' ; sector 2 = 512 bytes
123+
times 510-($-$$) db 0 ; Fills binary with 0 to keep the offset of 512
124+
dw 0xAA55 ; Magic Word

bootloader/kernel_entry.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
[bits 32]
22

33
extern main
4-
global _load_kernel
5-
64
section .text:
7-
_load_kernel:
5+
global _start
6+
_start:
87
call main
98
jmp $

bootloader/zeroes.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
times 10240 db 0

build/OS.bin

10.5 KB
Binary file not shown.

build/full_kernel.bin

21 Bytes
Binary file not shown.

build/kernel.o

1.65 KB
Binary file not shown.

build/kernel_entry.o

512 Bytes
Binary file not shown.

build/zeroes.bin

10 KB
Binary file not shown.

run.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/bin/bash
22

33
nasm -f bin -o build/boot.bin boot.asm
4+
nasm -f bin -o build/zeroes.bin bootloader/zeroes.asm
45
nasm -f elf -o build/kernel_entry.o bootloader/kernel_entry.asm
56
i386-elf-gcc -ffreestanding -m32 -g -c kernel/kernel.cpp -o build/kernel.o
67

78
i386-elf-ld -o build/full_kernel.bin -Ttext 0x1000 build/kernel_entry.o build/kernel.o --oformat binary
89

9-
cat build/boot.bin build/full_kernel.bin > build/OS.bin
10+
cat build/boot.bin build/full_kernel.bin build/zeroes.bin > build/OS.bin
1011

11-
# qemu-system-x86_64 -fda boot.bin
12-
13-
qemu-system-x86_64 -drive format=raw,file="build/OS.bin",index=0,if=flash, -m 128M
12+
qemu-system-x86_64 -drive format=raw,file="build/OS.bin",index=0,if=floppy, -m 128M

0 commit comments

Comments
 (0)