Gigasoft wrote:Why are you jumping to 0x1000? According to the map file, "kernel" is at 0x7e00. What you had initially should work, assuming that you have loaded the sectors to the correct addresses. Note that loading the sectors to address 0x1000 won't work, since the kernel assumes that it resides at 0x7e00. Try with "jmp kernel" and see what happens when you step through the jmp. EIP becoming 47e87c5f could mean that an exception occurs, and you haven't initialized the IDT. If you load IDTR with a limit of 0, Bochs should tell you which exception occurred. Maybe it would be easier to diagnose if you post the entire bootloader.asm or os.bin.
Oops, my bad. - That's because I forgot to tell you that I loaded kernel.o into 0x1000.
Anyway, I've changed it (again
), so here's the full "bootloader.asm":
Code: Select all
[bits 16]
boot:
mov ax, 0x0000
mov ds, ax
call clearScreen
call resetCursor
mov si, loadingKernel
call print
call resetDiskSystem
call enableA20
call installGDT
call protectedMode
protectedMode:
cli
mov eax, cr0
or eax, 0x0001
mov cr0, eax
jmp 0x0008:loadKernel
installGDT:
cli
lgdt[GDT]
sti
ret
enableA20:
mov ax, 0x2401
int 0x0015
jc enableA20
ret
resetDiskSystem:
xor ax, ax
int 0x0013
jc resetDiskSystem
ret
print:
lodsb
cmp al, 0
jz donePrinting
mov ah, 0x000e
int 0x0010
jmp print
donePrinting:
ret
resetCursor:
mov ah, 0x0002
mov bh, 0x0000
mov dh, 0x0000
mov dl, 0x0000
int 0x0010
ret
clearScreen:
mov ax, 0x0600
mov cx, 0x0000
mov dx, 0x1950
mov bh, 0x0007
int 0x0010
ret
[bits 32]
[global loadKernel]
loadKernel:
mov ax, 0x0010
mov ds, ax
mov ss, ax
mov esp, 0x90000
jmp 0x0008:0x7e00
GDTNull:
dd 0
dd 0
GDTCode:
dw 0x0FFFF
dw 0
db 0
db 10011010b
db 11001111b
db 0
GDTData:
dw 0x0FFFF
dw 0
db 0
db 10010010b
db 11001111b
db 0
endOfGDT:
GDT:
dw endOfGDT - GDTNull - 1
dd GDTNull
loadingKernel db "Loading kernel..", 0dh, 0ah, 0
times 510 - ($ - $$) db 0
dw 0xaa55
Full "kernel.asm":
Code: Select all
[bits 32]
[global kernel]
kernel:
mov edi, 0xb8000
mov byte [edi], 'K'
mov byte [edi + 1], 0x0007
hlt
Full "build.bat":
Code: Select all
@echo off
nasm -f elf bootloader.asm -o bootloader.elf
nasm -f elf kernel.asm -o kernel.elf
ld -o kernel.o kernel.elf
ld -Ttext 0x7c00 -Map os.map -o os.o bootloader.elf kernel.elf
objcopy -R .note -R .comment -S -O binary os.o os.bin
echo os.bin created!
rawwrite.exe
Full "os.bin" opened in Notepad:
Code: Select all
¸ ŽØèU èG ¾|è5 è+ è è è ú Àf
"Àêk| ú—|ûø$ÍrùÃ1ÀÍrúì< t´Íëõô· ¶ ² Íø ¹ ºP·ÍÃf¸ ŽØŽÐ¼ ê ~ ÿÿ šÏ ÿÿ ’Ï | Loading kernel..
Uª¿ € ÆKÆGôÿÿÿÿ ÿÿÿÿ
Some of "os.map":
Code: Select all
Adressen på sektionen .text sat til 0x7c00
LOAD bootloader.elf
LOAD kernel.elf
0x000001f0 . = SIZEOF_HEADERS
0x00001000 . = ALIGN (__section_alignment__)
.text 0x00007c00 0x400
*(.init)
*(.text)
.text 0x00007c00 0x200 bootloader.elf
0x00007c6b loadKernel
.text 0x00007e00 0xd kernel.elf
0x00007e00 kernel
And finally the error message in "bochsout.txt":
Code: Select all
00014073431i[CPU0 ] 0x000000000000fda8>> int1 : F1
00014073431e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
Now, the funny thing is that it runs without crashing in Microsoft Virtual PC and on real hardware, BUT, even though it doesn't crash, it doesn't execute the "kernel" function..??