Here is the code that I ended up with:
Code: Select all
org 0x07c00
jmp short begin_boot
bootmesg db "Our OS boot sector loading......"
pm_mesg db "Switching to protected mode....."
dw 512
db 1
dw 1
db 2
dw 0x000e0
dw 0x0b40
db 0x0f0
dw 9
dw 18
dw 2
dw 0
print_mesg:
mov ah, 0x13
mov al, 0x00
mov bx, 0x0007
mov cx, 0x20
mov dx, 0x0000
int 0x10
ret
get_key:
mov ah, 0x00
int 0x16
ret
clrscr:
mov ax, 0x0600
mov cx, 0x0000
mov dx, 0x174f
mov bh, 0
int 0x10
ret
begin_boot:
call clrscr
mov bp, bootmesg
call print_mesg
call get_key
bits 16
call clrscr
mov ax, 0xb800
mov gs, ax
mov word [gs:0], 0x641
call get_key
mov bp, pm_mesg
call print_mesg
call get_key
call clrscr
cli
lgdt[gdtr]
mov eax, cr0
or al, 0x01
mov cr0, eax
jmp codesel:go_pm
bits 32
go_pm:
mov ax, datasel
mov ds, ax
mov es, ax
mov ax, videosel
mov gs, ax
mov word [gs:0], 0x741
;;;;;;;;;;;;;;;;;;;
;;;;;; This is where i need help
;;;;;;;;;;;;;;;;;;;
mov ax, 0x0600
mov cx, 0x0000
mov dx, 0x174f
mov bh, 0
int 0x10
spin: jmp spin
bits 16
gdtr:
dw gdt_end-gdt-1
dd gdt
gdt
nullsel equ $-gdt
gdt0
dd 0
dd 0
codesel equ $-gdt
code_gdt
dw 0x0ffff
dw 0x0000
db 0x00
db 0x09a
db 0x0cf
db 0x00
datasel equ $-gdt
data_gdt
dw 0x0ffff
dw 0x0000
db 0x00
db 0x092
db 0x0cf
db 0x00
videosel equ $-gdt
dw 3999
dw 0x8000
db 0x0b
db 0x92
db 0x00
db 0x00
gdt_end
The OS boots fine when I don't include the area that I commented about, but when I include the marked code, the computer resets itself after it gets to the end, instead of looping... Why is this?
If it matters, I'm running this on Bochs on an OpenSUSE machine.