Reputation:
When I try to boot on qemu I get an endless reboot loop, I was able to narrow it down the line
call 0x1000
This is my first time delving into osdev and if there are any other things i'm doing wrong please inform me:) thanks in advance!!
[org 0x7c00]
[bits 16]
bootdrive db 0x00
xor ax,ax
mov ds, ax
mov ss, ax
mov sp, 0x9c00
mov bp, sp
mov [bootdrive], dl
mov bx, 0x1000
mov dh, 0x01
mov dl, bootdrive
loadkernel:
pusha
push dx
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
pop dx
popa
setgdt:
cli
lgdt[gdtr]
call openA20
call EnablePmode
openA20:
push ax
mov ax, 0x2401
int 0x15
pop ax
ret
EnablePmode:
mov eax, cr0
or al, 1
mov cr0, eax
jmp (CODE_DESC - NULL_DESC) : Pmode
NULL_DESC:
dd 0
dd 0
CODE_DESC:
dw 0xffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_DESC:
dw 0xffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdtr:
Limit dw gdtr - NULL_DESC - 1
Base dd NULL_DESC
[bits 32]
Pmode:
mov ax, DATA_DESC - NULL_DESC
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
call 0x1000
jmp $
times 510-($-$$) db 0
dw 0xaa55
Upvotes: 0
Views: 104
Reputation: 43
This code has many problems.
First of all,make sure CPU does not execute 0x00.
In line 3,you have bootdrive db 0
.
It should look like this:
[BITS 16]
[ORG 0x7C00]
jmp main
bootdev db 0
main:
Second one is you are trying to assign a word(pointer of bootdev) to DL.Which is not correct.it should look like this:
mov dl,[bootdev]
And you are trying to read Head:0 Cylinder/Track:0 and Sector 2.You think it will load to BX address which is 0x1000. but it will load at [ES:BX].if you want to jump 0x1000, then make sure ES is 0.
xor ax,ax ;AX is 0 now.
mov es,ax ;Thats how you reset ES.
You should enable A20 before loading GDT.
Your new code should look like this:
[org 0x7c00]
[bits 16]
jmp main
bootdrive db 0x00
main:
xor ax,ax
mov ds, ax
mov ss, ax
mov sp, 0x9c00
mov bp, sp
mov [bootdrive], dl
mov bx, 0x1000
mov dh, 0x01
mov dl, [bootdrive]
loadkernel:
pusha
push dx
xor ax,ax
mov es,ax
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
pop dx
popa
setgdt:
cli
call openA20
lgdt[gdtr]
call EnablePmode
openA20:
push ax
mov ax, 0x2401
int 0x15
pop ax
ret
EnablePmode:
mov eax, cr0
or al, 1
mov cr0, eax
jmp (CODE_DESC - NULL_DESC) : Pmode
NULL_DESC:
dd 0
dd 0
CODE_DESC:
dw 0xffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
DATA_DESC:
dw 0xffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdtr:
Limit dw gdtr - NULL_DESC - 1
Base dd NULL_DESC
[bits 32]
Pmode:
mov ax, DATA_DESC - NULL_DESC
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
call 0x1000
jmp $
times 510-($-$$) db 0
dw 0xaa55
And The Kernel:
BITS 32
org 0x1000
Start:
mov eax,0xB8000
mov byte [eax],78
mov byte [eax+1],71
jmp $
It will print red backgrounded grey "N" to top left.
Happy Coding!
Upvotes: 2