Segment registers are now zeroed, kernel stack is expanded to 2MiB, load_disk now does not fill cl automatically
This commit is contained in:
parent
6a020aeeee
commit
82bb637147
5
Makefile
5
Makefile
|
@ -88,4 +88,7 @@ image: $(BUILDDIR)/mbr.bin $(BUILDDIR)/kernel.bin
|
||||||
|
|
||||||
|
|
||||||
run: image
|
run: image
|
||||||
qemu-system-x86_64 -drive format=raw,file=$(DISTDIR)/os.img,index=0,media=disk
|
qemu-system-x86_64 -drive format=raw,file=$(DISTDIR)/os.img,index=0,media=disk
|
||||||
|
|
||||||
|
debug: image
|
||||||
|
qemu-system-x86_64 -drive format=raw,file=$(DISTDIR)/os.img,index=0,media=disk -monitor stdio
|
|
@ -22,13 +22,21 @@ kernel_offset: equ 0x1000
|
||||||
; We save the value of the current boot drive
|
; We save the value of the current boot drive
|
||||||
mov [boot_drive], dl
|
mov [boot_drive], dl
|
||||||
|
|
||||||
|
; This isn't needed inside the qemu emulator, but
|
||||||
|
; real hardware is unlikely to start up with the
|
||||||
|
; segment registers zeroed, so we do it here
|
||||||
|
mov ax, 0
|
||||||
|
mov ds, ax
|
||||||
|
mov ss, ax
|
||||||
|
mov es, ax
|
||||||
|
xor ax, ax
|
||||||
|
|
||||||
; Now we setup the stack by setting the
|
; Now we setup the stack by setting the
|
||||||
; base pointer to address 0x9000. The address
|
; base pointer to a location that's far
|
||||||
; itself doesn't matter as long as it's far
|
; enough from where the code for the BIOS
|
||||||
; enough away from memory already in use by
|
; is located
|
||||||
; the BIOS
|
mov sp, 0x9000
|
||||||
mov bp, 0x9000
|
mov bp, sp
|
||||||
mov sp, bp
|
|
||||||
call bios_cls
|
call bios_cls
|
||||||
mov si, real_mode_msg
|
mov si, real_mode_msg
|
||||||
call bios_println
|
call bios_println
|
||||||
|
@ -58,6 +66,7 @@ load_kernel: ; Loads the kernel into memory
|
||||||
mov si, loading_kernel_msg
|
mov si, loading_kernel_msg
|
||||||
call bios_println
|
call bios_println
|
||||||
mov bx, kernel_offset
|
mov bx, kernel_offset
|
||||||
|
mov cl, 2
|
||||||
mov dh, 4
|
mov dh, 4
|
||||||
mov dl, [boot_drive]
|
mov dl, [boot_drive]
|
||||||
call load_disk
|
call load_disk
|
||||||
|
|
|
@ -43,7 +43,7 @@ switch32: ; We're not in 32 bit mode, yay!
|
||||||
mov fs, ax
|
mov fs, ax
|
||||||
mov gs, ax
|
mov gs, ax
|
||||||
|
|
||||||
mov ebp, 0x90000 ; We also move the stack further up
|
mov ebp, 0x1f8400 ; We also make the stack larger (2MiB)
|
||||||
mov esp, ebp
|
mov esp, ebp
|
||||||
|
|
||||||
call BEGIN_32BIT ; We call back into mbr.s which loads the kernel
|
call BEGIN_32BIT ; We call back into mbr.s which loads the kernel
|
|
@ -17,14 +17,12 @@
|
||||||
|
|
||||||
|
|
||||||
load_disk:
|
load_disk:
|
||||||
; Loads 'dh' sectors from drive 'dl' (this
|
; Loads 'dh' sectors from drive 'dl' starting
|
||||||
; register is set by the BIOS before calling
|
; from sector 'cl'
|
||||||
; the bootloader) into es:bx
|
|
||||||
pusha
|
pusha
|
||||||
push dx
|
push dx
|
||||||
mov ah, 0x2 ; Perform a read operation
|
mov ah, 0x2 ; Perform a read operation
|
||||||
mov al, dh ; Number of sectors
|
mov al, dh ; Number of sectors
|
||||||
mov cl, 0x2 ; 0x1 is us, so 0x2 is the first sector we want
|
|
||||||
mov ch, 0x0 ; Cylinder 0
|
mov ch, 0x0 ; Cylinder 0
|
||||||
mov dh, 0x0 ; Head position is 0 too
|
mov dh, 0x0 ; Head position is 0 too
|
||||||
int 0x13 ; Once this returns, the data will be in es:bx
|
int 0x13 ; Once this returns, the data will be in es:bx
|
||||||
|
@ -58,4 +56,4 @@ disk_loop:
|
||||||
|
|
||||||
|
|
||||||
disk_read_error_msg: db "TSOS: Read error: ", 0
|
disk_read_error_msg: db "TSOS: Read error: ", 0
|
||||||
disk_sectors_error_msg: db "TSOS: Sector read count error", 0
|
disk_sectors_error_msg: db "TSOS: Incomplete read", 0
|
||||||
|
|
|
@ -201,5 +201,4 @@ vga_printh:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
|
||||||
NEWLINE: db 0xA, 0xD
|
|
||||||
HEX_OUT_LONG: db '0x00000000', 0
|
HEX_OUT_LONG: db '0x00000000', 0
|
|
@ -17,4 +17,4 @@
|
||||||
[bits 32]
|
[bits 32]
|
||||||
[extern kmain]
|
[extern kmain]
|
||||||
call kmain
|
call kmain
|
||||||
jmp $
|
jmp $
|
||||||
|
|
Loading…
Reference in New Issue