the goal here is to get to protected mode (which should be a quick and simple task) and then call the kernel.
what happens in bochs: it causes a reset during jmp [cs:clear_pipe]
i'm guessing this means it's not in protected mode, but i can't figure out why, maybe someone else can spot my error?
pretend the "checkpoints" that write single characters to the screen and hang i put in aren't there; it doesn't even make it to them, they're just left over from trying to spot the problematic line.
Code: Select all
[BITS 16]
;read kernel into low memory temporarily
load_kernel:
mov ah, 0h
mov dl, 0h
int 13h
or ah,ah
jnz load_kernel
mov dl,0h
mov dh,0h
mov ch,0h
mov cl,2h
mov bx,0h
mov ax,50h
mov es,ax
mov al,8h
mov ah,02h
int 13h
jnc done_loading
disk_err:
mov ah,0eh
mov al,'E'
int 10h
mov al,'R'
int 10h
int 10h
mov al,ah
mov ah,0eh
add al,'0'
int 10h
jmp $
gdt_desc:
dw gdt_end - gdt - 1
dd gdt
%include "a20line.asm"
done_loading:
call enable_a20
;move into protected mode
cli
xor ax,ax
mov ds,ax
lgdt [gdt_desc]
mov eax,cr0
or eax,1
mov cr0,eax
jmp [cs:clear_pipe]
[BITS 32]
clear_pipe:
mov byte [ds:0b8000h],'A'
jmp $
mov ax,10h
mov ds,ax
mov ss,ax
mov esp,90000h
mov dword [ds:0b8000h],'P M '
mov dword [ds:0b8004h],'O D '
mov dword [ds:0b8008h],'E - '
;move kernel code from 500h to 100000h
mov ecx,500h ;original code buffer
mov edx,100000h ;new code buffer
movekernelloop:
mov ebx,[ds:ecx]
mov [ds:edx],ebx
add ecx,4
add edx,4
cmp edx,101000h
jne movekernelloop
;call [cs:100000h]
mov byte [ds:0b8000h],'B'
jmp $
gdt:
gdt_null:
dd 0
dd 0
gdt_code:
dw 0ffffh
dw 0h
db 0h
db 10011010b
db 11001111b
db 0h
gdt_data:
dw 0ffffh
dw 0h
db 0h
db 10010010b
db 11001111b
db 0h
gdt_end:
times 510-($-$$) db 0
dw 0aa55h
Code: Select all
enable_a20:
call a20wait
mov al,0xAD
out 0x64,al
call a20wait
mov al,0xD0
out 0x64,al
call a20wait2
in al,0x60
push eax
call a20wait
mov al,0xD1
out 0x64,al
call a20wait
pop eax
or al,2
out 0x60,al
call a20wait
mov al,0xAE
out 0x64,al
call a20wait
sti
ret
a20wait:
.l0: in al,0x64
test al,2
jz .l2
jmp .l0
.l2: ret
a20wait2:
.l0: in al,0x64
test al,1
jnz .l2
jmp .l0
.l2: ret