crash on long jump in memory
Posted: Sun Sep 27, 2020 2:53 am
Greetings
I understand this question has been asked in one way or another before, however I have genuinely searched through probably every single forum post and whatnot about this topic and couldn't find the missing piece of information that I need; I don't know why this crashes and I don't understand why.
At first I wrote a bios simple boot sector successfully and tried to enter protected mode, and I experienced a crash when performing the jump. Realizing my incompetence, I followed an online tutorial seemingly exactly to see what I did wrong but I was met with the same result. I will provide all my code and all information so if anyone wants to help me they have the information.
Boot sect:
Moon.asm:
Gdt.asm:
Disk.asm:
Batch file to compile:
To explain the batch file to compile, it goes into the dir with nasm.exe, compiles the boot sect and extended code, then performs copy /b to them, and finally it runs in qemu, however alternatively I can use bochs after compiling like this
I have debugged this in BOCHS x64 and QEMUx86_64 and was met with the exact same result.
Information retrieved from the BOCHS log:
- A20 line enabled
- CPU is in protected mode (active)
- Hardware reset called after 3 (13) exception with no resolution
- Registers at crash: Eax=60000011,Ebx=00007e00,Ecx=00090002,Edx=0,Esp=00009000,Ebp=esp,Esi=000e0000,Edi=0000ffac,cr0=eax,cr2=0,cr3=0,cr4=0,eip=00007e55
I have aimlessly tried to:
- Change bp/sp in bootsect to various different places in free memory, and 7c00h
- Removed all my functions that use the stack because they are not required for now
- Modifying gdt in various ways
- Many things I can not remember right now
The crash occurs on moon.asm line 15, I have commented following the instruction on the line so it is more clear
Thanks...
I understand this question has been asked in one way or another before, however I have genuinely searched through probably every single forum post and whatnot about this topic and couldn't find the missing piece of information that I need; I don't know why this crashes and I don't understand why.
At first I wrote a bios simple boot sector successfully and tried to enter protected mode, and I experienced a crash when performing the jump. Realizing my incompetence, I followed an online tutorial seemingly exactly to see what I did wrong but I was met with the same result. I will provide all my code and all information so if anyone wants to help me they have the information.
Boot sect:
Code: Select all
[org 7c00h]
start:
mov [BOOT_DISK],dl
;----------
;Init stack
mov bp,9000h
mov sp,bp
;----------
call readDisk
jmp PROGRAM_SPACE
jmp $
%include 'C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\disk.asm'
times 510-($-$$) db 0
dw 0aa55h
Code: Select all
[org 7e00h]
jmp enterPm
%include 'C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\gdt.asm'
enterPm:
cli
call enableA20
lgdt [gdt_descriptor]
mov eax,cr0
or eax,1
mov cr0,eax
jmp codeseg:startPm ; < < < < < Crash on this line of code
jmp $
enableA20:
in al,92h
or al,2
out 92h,al
ret
[bits 32]
startPm:
mov ax,dataseg
mov ds,ax
mov ss,ax
mov es,ax
mov fs,ax
mov gs,ax
jmp $
times 2048-($-$$) db 0
Code: Select all
gdt_nulldesc:
dd 0
dd 0
gdt_codedesc:
dw 0ffffh ;Limit
dw 0000h ;Base,low
db 00h ;Base,med
db 10011010b ;Flags
db 11001111b ;Flags & upper limit
db 00h ;Base,high
gdt_datadesc:
dw 0ffffh
dw 0000h
db 00h
db 10010010b
db 11001111b
db 00h
gdt_end:
gdt_descriptor:
gdt_size:
db gdt_end-gdt_nulldesc-1
db gdt_nulldesc
codeseg equ gdt_codedesc-gdt_nulldesc
dataseg equ gdt_datadesc-gdt_nulldesc
Code: Select all
PROGRAM_SPACE equ 7e00h
readDisk:
mov ah,02h
mov bx,PROGRAM_SPACE
mov al,4
mov dl,[BOOT_DISK]
mov ch,00h
mov dh,00h
mov cl,02h
int 13h
jnc doneRdDisk
;push diskRdFailedStr
;call printStr
jmp $
doneRdDisk:
ret
BOOT_DISK:
db 0
diskRdFailedStr:
db 'Disk read failed',0
Code: Select all
cd "C:\Users\Elite\Documents\SharpDevelop Projects\AsmEditor\Astro-Editor\AstroEditor\bin\Debug\include"
nasm -f bin "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\main.asm" -o "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\Moon.bin"
nasm -f bin "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\moon.asm" -o "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\moon_e.bin"
copy /b "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\Moon.bin"+"C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\moon_e.bin" "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\moon.flp"
"C:\Program Files\qemu\qemu-system-x86_64w.exe" "C:\Users\Elite\Documents\AstroEditor Projects\Moon\src\bin\moon.flp"
pause
I have debugged this in BOCHS x64 and QEMUx86_64 and was met with the exact same result.
Information retrieved from the BOCHS log:
- A20 line enabled
- CPU is in protected mode (active)
- Hardware reset called after 3 (13) exception with no resolution
- Registers at crash: Eax=60000011,Ebx=00007e00,Ecx=00090002,Edx=0,Esp=00009000,Ebp=esp,Esi=000e0000,Edi=0000ffac,cr0=eax,cr2=0,cr3=0,cr4=0,eip=00007e55
I have aimlessly tried to:
- Change bp/sp in bootsect to various different places in free memory, and 7c00h
- Removed all my functions that use the stack because they are not required for now
- Modifying gdt in various ways
- Many things I can not remember right now
The crash occurs on moon.asm line 15, I have commented following the instruction on the line so it is more clear
Thanks...