Added missing entrypoint and other files

This commit is contained in:
Nocturn9x 2022-11-16 15:40:29 +01:00
parent 1e7f6dd22e
commit 46a560910b
3 changed files with 66 additions and 0 deletions

37
src/bootloader/gdt.s Normal file
View File

@ -0,0 +1,37 @@
; Definition of our Global Descriptor Table
gdt_start: ; The labels are important to compute the size of the GDT: don't touch them!
; The GDT starts with 8 null bytes
dd 0x0 ; 4 byte
dd 0x0 ; 4 byte
; GDT for code segment. base = 0x00000000, length = 0xfffff
; for flags, refer to os-dev.pdf document, page 36
gdt_code:
dw 0xffff ; segment length, bits 0-15
dw 0x0 ; segment base, bits 0-15
db 0x0 ; segment base, bits 16-23
db 10011010b ; flags (8 bits)
db 11001111b ; flags (4 bits) + segment length, bits 16-19
db 0x0 ; segment base, bits 24-31
; GDT for data segment. base and length identical to code segment
; some flags changed, again, refer to os-dev.pdf
gdt_data:
dw 0xffff
dw 0x0
db 0x0
db 10010010b
db 11001111b
db 0x0
gdt_end:
; GDT descriptor
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; size (16 bit), always one less of its true size
dd gdt_start ; address (32 bit)
; define some constants for later use
CODE_SEG equ gdt_code - gdt_start
DATA_SEG equ gdt_data - gdt_start

25
src/bootloader/switch32.s Normal file
View File

@ -0,0 +1,25 @@
[bits 16]
switch_to_protected_mode:
cli ; We disable interrupts...
lgdt [gdt_descriptor] ; ... load the GDT descriptor...
mov eax, cr0
or eax, 0x1 ; ... set 32-bit mode in CR0
mov cr0, eax
jmp CODE_SEG:switch32 ; ... and perform a far jump using a different segment
[bits 32]
switch32: ; We're not in 32 bit mode, yay!
mov ax, DATA_SEG ; Time to update the segment registers with their new values
mov ds, ax
mov ss, ax
mov es, ax
; Bonus: we have two more user-defined
; segment registers when in 32-bit mode
mov fs, ax
mov gs, ax
mov ebp, 0x90000 ; We also move the stack further up
mov esp, ebp
call BEGIN_32BIT ; We call back into mbr.s which loads the kernel

4
src/entrypoint.s Normal file
View File

@ -0,0 +1,4 @@
[bits 32]
[extern kmain]
call kmain
jmp $