OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 1:02 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Solved] an issuse about GP exception in infinte loop
PostPosted: Fri May 01, 2020 10:31 pm 
Offline

Joined: Fri May 01, 2020 10:06 pm
Posts: 6
I am learning things about os dev and I write a simple loader promgram.

It loads gdt, enters protected mode and runs inito a infinte loop.

The problem is

when program runs into the infinte loop like "jmp $"...

it causes GP exception, then again, finally I get a triple fault.

but if I enter "si" continusly in GDB to run "jmp $"

it runs as expected...

are there any mechanisms in processor to prevent this kind of inf loop?

or it is just fault of my code.

thanks in advance!


Last edited by whereware on Sat May 02, 2020 6:50 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 12:52 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
It would help if you posted a link to your code (in an online repository - don't just paste all the code here) and detailed the exact steps that you followed in gdb.

On the face of it, if a program causes a GPF when run it will do the same when running under gdb.


Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 4:24 am 
Offline

Joined: Fri May 01, 2020 10:06 pm
Posts: 6
iansjack wrote:
It would help if you posted a link to your code (in an online repository - don't just paste all the code here) and detailed the exact steps that you followed in gdb.

On the face of it, if a program causes a GPF when run it will do the same when running under gdb.


Thank you for your reply!

Here is the code:

https://github.com/D0ot/dotkernel/blob/osloader-dev/osloader/osloader.asm

It would cause some GPFs and finally a tripple fault with QEMU + gdb.

Steps:
(type in gdb)
1. "b _flush" , _flush is a label in the file above , at line 38
2. "si" "si" , type many si, it will reach the "jmp $"
3. "si", it runs "jmp $" well. no GPF
4. "c", QEMU closes(i used the option "--no-reboot" when lanuching QEMU) and leaves log saying :

Code:
check_exception old: 0xffffffff new 0xd
     1: v=0d e=0042 i=0 cpl=0 IP=0008:00007e38 pc=00007e38 SP=0010:00007c00 env->regs[R_EAX]=d88e0010
...
check_exception old: 0xd new 0xd
     2: v=08 e=0000 i=0 cpl=0 IP=0008:00007e38 pc=00007e38 SP=0010:00007c00 env->regs[R_EAX]=d88e0010
...
check_exception old: 0x8 new 0xd
Triple fault


disassembly outpu by objdump:
"i686-elf-objdump -d -M intel -M i386 osloader.elf"
Code:
  00007e29 <_flush>:
      7e29:       66 b8 10 00             mov    ax,0x10
      7e2d:       8e d8                   mov    ds,eax
      7e2f:       8e c0                   mov    es,eax
      7e31:       8e d0                   mov    ss,eax
      7e33:       bc 00 7c 00 00          mov    esp,0x7c00
      7e38:       eb fe                   jmp    7e38 <_flush+0xf>


I don't know why...


Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 4:42 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5100
whereware wrote:
Code:
e=0042

This means the IDT entry for INT 0x08 (IRQ0) is invalid.

Perhaps you should disable interrupts before switching to protected mode.


Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 4:56 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
As exception 0x08 is a double fault, I don't think that is the root cause. But, as there is no IDT to be valid or invalid, the root cause is obviously some interrupt or exception occurring. Could be the timer interrupt and you just didn't single-step enough times to hit it.

As already said, either disable interrupts or create a valid IDT with valid handlers.


Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 5:19 am 
Offline

Joined: Fri May 01, 2020 10:06 pm
Posts: 6
Octocontrabass wrote:
whereware wrote:
Code:
e=0042

This means the IDT entry for INT 0x08 (IRQ0) is invalid.

Perhaps you should disable interrupts before switching to protected mode.


Thanks!

I am just a beginner and I don't know the meaning of that "e=xxx". :D thanks again. hahaha


Top
 Profile  
 
 Post subject: Re: an issuse about GP exception in infinte loop
PostPosted: Sat May 02, 2020 5:28 am 
Offline

Joined: Fri May 01, 2020 10:06 pm
Posts: 6
iansjack wrote:
As exception 0x08 is a double fault, I don't think that is the root cause. But, as there is no IDT to be valid or invalid, the root cause is obviously some interrupt or exception occurring. Could be the timer interrupt and you just didn't single-step enough times to hit it.

As already said, either disable interrupts or create a valid IDT with valid handlers.


Thanks!

It could be a best practice? Maybe I should read code of someone else. hahaha. Thanks again!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group