[solved] my OS get restarted when jmp to PM
[solved] my OS get restarted when jmp to PM
i attached the entire code in a single file, please help, i don't know why this is happening.
PS: i'm using Bochs and Fasm.
[edit:] subject changed.
PS: i'm using Bochs and Fasm.
[edit:] subject changed.
Last edited by Teehee on Mon Mar 07, 2011 8:12 am, edited 2 times in total.
Sorry if bad english.
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: help: my OS get restarted when jmp to PM
What error message, if any, is in the Bochs log? It should say something about whether you have valid descriptors or not.
Does anything show up on the screen?
Don't just dump a bunch of code on us and expect us to do your debugging for you.
Does anything show up on the screen?
Don't just dump a bunch of code on us and expect us to do your debugging for you.
Re: help: my OS get restarted when jmp to PM
Hi. This is bochs output log (only error and panic events enabled):
And this is the log of a test i'm doing to try to solve this problem (just boot and PM change):
Code: Select all
00014091086e[WGUI ]00014600000e[WGUI ] Sim client size(720, 333) != stretched size(720, 400)!
00028183098e[WGUI ] Sim client size(726, 432) != stretched size(1280, 1024)!
00028183098e[WGUI ] Sim client size(1276, 1020) != stretched size(1280, 1024)!
00028184021e[CPU0 ] jump_protected: gate type 3 unsupported
00028184021e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00028184021e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00028184021e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00028800000e[WGUI ] Sim client size(720, 333) != stretched size(720, 400)!
00035600000p[WGUI ] >>PANIC<< POWER button turned off.
Code: Select all
00014132869e[CPU0 ] jump_protected: gate type 0 unsupported
00014132869e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00014132869e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
00014132869e[CPU0 ] exception(): 3rd (13) exception with no resolution, shutdown status is 00h, resetting
00015400000p[WGUI ] >>PANIC<< POWER button turned off.
Sorry if bad english.
Re: help: my OS get restarted when jmp to PM
Code: Select all
00014132869e[CPU0 ] jump_protected: gate type 0 unsupported
Either way, your GDT is in mess...beside the binary and hexadecimal notation you could also use decimal to make things even worse. Be consistent.
____
Dario
Dario
Re: help: my OS get restarted when jmp to PM
this is my gdt:
whats wrong with it? i changed to many values and got the same problem.
Code: Select all
align 4
gdtr: dw gdt_size ; limit
dd gdt ; base
align 4
gdt: dq 0
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'1010b, 1100'1111b, 0x00 ; 0x08 code segment selector
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'0010b, 1100'1111b, 0x00 ; 0x10 data segment selector
gdt_size = $-gdt-1
Sorry if bad english.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: help: my OS get restarted when jmp to PM
- Read enough sectors.
- Use DL from the bios
- Your linked and execution addresses do not match.
- Use DL from the bios
- Your linked and execution addresses do not match.
- DavidCooper
- Member
- Posts: 1150
- Joined: Wed Oct 27, 2010 4:53 pm
- Location: Scotland
Re: help: my OS get restarted when jmp to PM
I don't use assembler so I don't know how the rest of the above works, but your actual GDT values are fine.Teehee wrote:this is my gdt:whats wrong with it? i changed to many values and got the same problem.Code: Select all
align 4 gdtr: dw gdt_size ; limit dd gdt ; base align 4 gdt: dq 0 db 0xFF,0xFF, 0x00,0x00,0x00, 1001'1010b, 1100'1111b, 0x00 ; 0x08 code segment selector db 0xFF,0xFF, 0x00,0x00,0x00, 1001'0010b, 1100'1111b, 0x00 ; 0x10 data segment selector gdt_size = $-gdt-1
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Re: help: my OS get restarted when jmp to PM
maybe its something here:
?
Code: Select all
mov ax,0x0050
mov bx,0x0000
mov es,ax
mov ah,0x02
mov al,2 ; number of sectors to read (1-128 dec.)
mov ch,1
mov cl,2 ; sector number (1-17 dec.)
mov dx,0
int 0x13 ; http://www.stanislavs.org/helppc/int_13-2.html
Sorry if bad english.
Re: help: my OS get restarted when jmp to PM
here the test i'm doing:
edit: updating the code
Code: Select all
format binary as 'img'
use16
org 0
jmp 0x07C0:@f
@@: mov ax,cs
mov ds,ax
mov ss,ax
mov sp,512-1-2
@@: mov ah,0 ; Reset floppy disk function
mov dl,0 ; drive 0 = floppy drive
int 0x13 ;
jc @b ; CF: 1 error, 0 ok
mov ax,0x0050
mov bx,0x0000
mov es,ax
mov ah,0x02
mov al,1 ; number of sectors to read (1-128 dec.)
mov ch,0 ; track/cylinder number (0-1023 dec.)
mov cl,2 ; sector number (1-17 dec.)
mov dx,0
int 0x13 ; http://www.stanislavs.org/helppc/int_13-2.html
jc @b
jmp 0x0050:kernel16
rb 510-($-$$)
dw 0xAA55
use16
org 0
kernel16:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,512
mov ax,0x2401
int 0x15
cli
lgdt [gdtr]
mov eax,cr0
or eax,1
mov cr0,eax
jmp 0x08:kernel32
align 4
gdtr: dw gdt_size ; limit
dd gdt ; base
align 4
gdt: dq 0
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'1010b, 1100'1111b, 0x00 ; 0x08 code segment selector
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'0010b, 1100'1111b, 0x00 ; 0x10 data segment selector
gdt_size = $-gdt-1
use32
;org 0
align 4
kernel32:
mov eax,0x10
mov ds,ax
mov es,ax
mov gs,ax
mov fs,ax
mov ss,ax
mov esp,0x00FFFFFF
hlt
jmp $
times 512-($-kernel16) db 0
Last edited by Teehee on Mon Mar 07, 2011 7:23 am, edited 5 times in total.
Sorry if bad english.
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: help: my OS get restarted when jmp to PM
1) You use ORG 0 but you don't set CS to 0x07C0. This might not affect things, though.
2) Are you sure that drive 0 is the boot drive?
3) Are you sure that you are loading enough sectors?
4) You didn't check for errors after calling int 0x13. Floppy drives may return multiple errors, as the interrupt list says:
6) When you use "org 0" in the 32-bit part, it assumes that means that kernel32 is loaded at 0x000000000 (which is the real mode IDT) and tries to jump there. Try just removing the org 0 statement for now, and if that doesn't work, calculate the address to jump to at run time.
2) Are you sure that drive 0 is the boot drive?
3) Are you sure that you are loading enough sectors?
4) You didn't check for errors after calling int 0x13. Floppy drives may return multiple errors, as the interrupt list says:
5) Not all BIOSes support int 15/AX=2401. If the return value in ah is 0x86, then the function is not supported and you have to set the A20 gate yourself. The easiest way is to use the keyboard controller, but I think there are a few others as well.Errors on a floppy may be due to the motor failing to spin up quickly enough; the read should be retried at least three times, resetting the disk with AH=00h between attempts.
6) When you use "org 0" in the 32-bit part, it assumes that means that kernel32 is loaded at 0x000000000 (which is the real mode IDT) and tries to jump there. Try just removing the org 0 statement for now, and if that doesn't work, calculate the address to jump to at run time.
Re: help: my OS get restarted when jmp to PM
Hi, Tosi.
Oops, i did fix it.Tosi wrote:1) You use ORG 0 but you don't set CS to 0x07C0. This might not affect things, though.
according to this, dl = 0 = A:.2) Are you sure that drive 0 is the boot drive?
no these descriptions confuse me:3) Are you sure that you are loading enough sectors?
As it returns me the correct value of sectors read (al=1) so i presume yes.mov al,1 ; number of sectors to read (1-128 dec.)
mov ch,0 ; track/cylinder number (0-1023 dec.)
mov cl,2 ; sector number (1-17 dec.)
i didnt put it into the code, but i checked it before, and it was ok. i will update the last code.4) You didn't check for errors after calling int 0x13.
yea, i checked for support. The int 15 is ok.5) Not all BIOSes support int 15/AX=2401. If the return value in ah is 0x86, then the function is not supported and you have to set the A20 gate yourself.
i removed it. Didn't work. how do i make that calc?6) When you use "org 0" in the 32-bit part, it assumes that means that kernel32 is loaded at 0x000000000 (which is the real mode IDT) and tries to jump there. Try just removing the org 0 statement for now, and if that doesn't work, calculate the address to jump to at run time.
Last edited by Teehee on Mon Mar 07, 2011 6:58 am, edited 1 time in total.
Sorry if bad english.
Re: help: my OS get restarted when jmp to PM
When you make the far jump to protected mode code, you have to reload the segment registers with proper selector. This might fix your issue. Good Luck.Teehee wrote:here the test i'm doing:[edit:]updating the code.Code: Select all
format binary as 'img' use16 org 0 jmp 0x07C0:@f @@:mov ax,cs mov ds,ax mov ss,ax mov sp,512-1-2 @@: mov ax,0x0050 mov bx,0x0000 mov es,ax mov ah,0x02 mov al,1 ; number of sectors to read (1-128 dec.) mov ch,0 ; track/cylinder number (0-1023 dec.) mov cl,2 ; sector number (1-17 dec.) mov dx,0 int 0x13 ; http://www.stanislavs.org/helppc/int_13-2.html jc @b jmp 0x0050:kernel16 rb 510-($-$$) dw 0xAA55 use16 org 0 kernel16: mov ax,cs mov ds,ax mov es,ax mov ss,ax mov sp,0x010 mov ax,0x2401 int 0x15 cli lgdt [gdtr] mov eax,cr0 or eax,1 mov cr0,eax jmp 0x08:kernel32 use32 ;org 0 align 4 kernel32: hlt jmp $ align 4 gdtr: dw gdt_size ; limit dd gdt ; base align 4 gdt: dq 0 db 0xFF,0xFF, 0x00,0x00,0x00, 1001'1010b, 1100'1111b, 0x00 ; 0x08 code segment selector db 0xFF,0xFF, 0x00,0x00,0x00, 1001'0010b, 1100'1111b, 0x00 ; 0x10 data segment selector gdt_size = $-gdt-1 times 512-($-kernel16) db 0
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: help: my OS get restarted when jmp to PM
unfortunately, no. It does not [nor at least] hit kernel32: label line.Chandra wrote:When you make the far jump to protected mode code, you have to reload the segment registers with proper selector. This might fix your issue. Good Luck.
Sorry if bad english.
-
- Member
- Posts: 255
- Joined: Tue Jun 15, 2010 9:27 am
- Location: Flyover State, United States
- Contact:
Re: help: my OS get restarted when jmp to PM
As you have it now, you load the part after the bootloader to 0x0500 and set the code segment, so you use "org 0." Hence the address to jump to when you switch to protected mode would be 0x0500 + kernel32, because you are no longer using real mode segmentation. You could do something like:
Code: Select all
jmp (0x0500 + kernel32)
Re: help: my OS get restarted when jmp to PM
Hi, Tosi. That didn't work.
But i changed the orgs to 0x7C00 and 0x0500, and removed the jmp 0x0050:kernel16 and it works now. But i didn't understand why:
I would like to know the reason.
But i changed the orgs to 0x7C00 and 0x0500, and removed the jmp 0x0050:kernel16 and it works now. But i didn't understand why:
Code: Select all
format binary as 'img'
use16
org 0x7C00
mov ax,cs
mov ds,ax
mov ss,ax
mov sp,512-1-2
@@: mov ah,0 ; Reset floppy disk function
mov dl,0 ; drive 0 = floppy drive
int 0x13 ;
jc @b ; CF: 1 error, 0 ok
mov ax,0x0050
mov bx,0x0000
mov es,ax
mov ah,0x02
mov al,1 ; number of sectors to read (1-128 dec.)
mov ch,0 ; track/cylinder number (0-1023 dec.)
mov cl,2 ; sector number (1-17 dec.)
mov dx,0
int 0x13 ; http://www.stanislavs.org/helppc/int_13-2.html
jc @b
jmp kernel16
rb 510-($-$$)
dw 0xAA55
use16
org 0x0500
kernel16:
mov ax,cs
mov ds,ax
mov es,ax
mov ss,ax
mov sp,512
mov ax,0x2401
int 0x15
cli
lgdt [gdtr]
mov eax,cr0
or eax,1
mov cr0,eax
jmp 0x08:kernel32
align 4
gdtr: dw gdt_size
dd gdt
align 4
gdt: dq 0
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'1010b, 1100'1111b, 0x00 ; 0x08 code segment selector
db 0xFF,0xFF, 0x00,0x00,0x00, 1001'0010b, 1100'1111b, 0x00 ; 0x10 data segment selector
gdt_size = $-gdt-1
use32
align 4
kernel32:
mov eax,0x10
mov ds,ax
mov es,ax
mov gs,ax
mov fs,ax
mov ss,ax
mov esp,0x00FFFFFF
hlt
jmp $
times 512-($-kernel16) db 0
Sorry if bad english.