At the moment I am just working on my bootloader, and am attempting to set up unreal mode (so I can load my kernel after the 1 MB mark without trouble (theoretically)). I am running into an error when attempting to reload real mode (swap back to real mode after starting protected mode) that states "load_seg_reg(DS, 0x0008): invalid segment".
Based on what I have read about unreal mode it is best to have a20 mode set up first (so you can get the odd 1 MB blocks), so I have set that up and it seems to work (or at least not cause a panic). I have also gone through an loaded a simple GDT for the bootloader, and found the amount of RAM the VM has available (storing it in 0x1000, amount between 1 and 16 MB, and 0x1004, number of 64 KB pages after the 16 MB mark), and it does in fact find the entire amount of RAM I allow it to use (256 MB).
Anyways, here is my current bootloader code:
Code: Select all
[BITS 16]
[ORG 0x700]
checkENine:
in al, 0xe9
cmp al, 0xe9
jne .noENine
jmp .ENine
.noENine:
mov al, 'N'
jmp .print
.ENine:
mov al, 'Y'
.print:
mov ah, 0x0e
mov bh, 0x0f
mov bl, 0
int 0x10
reset_drive:
mov ah, 0
int 0x13
or ah, ah
jnz reset_drive
xor ax, ax ; set up the stack
mov ss, ax
mov sp, 0x600
mov al, '1'
call eNinePrint
loadGDT:
xor ax, ax
mov ds, ax
lgdt [gdt_desc]
findRAM:
xor cx, cx
xor dx, dx
mov ax, 0xe801
int 0x15
jc .err
cmp ah, 0x86
je .err
cmp ah, 0x80
je .err
jcxz .useax
mov ax, cx
mov bx, dx
.useax:
mov [0x1000], ax
mov [0x1004], bx
jmp .end
.err:
mov al, 'e'
call eNinePrint
mov al, 'r'
call eNinePrint
mov al, 'r'
call eNinePrint
mov al, ' '
call eNinePrint
.end:
check_for_a20:
cli
xor ax, ax
mov es, ax
not ax
mov dx, ax
mov di, 0x500
mov si, 0x510
mov al, byte [es:di]
push ax
mov al, byte [ds:si]
push ax
mov byte [es:di], 0x00
mov byte [ds:si], 0xff
cmp byte [es:di], 0xff
pop ax
mov byte [ds:si], al
pop ax
mov byte [es:di], al
sti
mov ax, 0
je .exit
.enableATwenty:
mov ax, 0x2401
int 0x15
mov al, 'Y'
call eNinePrint
.exit:
mov al, 'E'
call eNinePrint
unrealMode:
push ds
mov eax, cr0 ; goto protected mode
or al, 1
mov cr0, eax ; end pmode switch
mov bx, 0x08
mov ds, bx ; kernel panic is caused either here
and al, 0xfe ; go back to real mode ; or here as far as I can tell
mov cr0, eax
pop ds
sti
;
;loadKernel: ; does nothing other than theoretically output a smiley to the screen
; mov bx, 0xf01
; mov eax, 0xb8000
; mov word [ds:eax], bx
halt:
hlt
jmp halt
eNinePrint:
out 0xe9, al
ret
gdt:
gdt_null:
dd 0
dd 0
gdt_code:
dw 0x0ffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
gdt_data:
dw 0x0ffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
gdt_end:
gdt_desc:
dw gdt_end - gdt - 1 ; the size of the gdt
dd gdt ; address of the gdt
times 510-($-$$) db 0
dw 0x0aa55Code: Select all
nasm -f bin bootloader.s -o bootloader.bin
cat bootloader.bin > floppy.imgThanks for your time
