OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 7:32 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: What happens on interrupt in long mode
PostPosted: Thu Jul 02, 2015 11:11 am 
Offline

Joined: Tue Jun 09, 2015 9:34 am
Posts: 5
I have trouble finding this information - most things I find are either tutorials (mostly 32 bit) which don't really explain much (well - I can use it and it will probably work but I won't know how or why) or structure description. I was trying to find it in Intel manual but it seems to be spread out across several chapters (5-7) and concentrate on structures as well - furthermore it describes long mode only as differences to protected mode. That makes it hard to find information if you don't really know where to look for it.

What happens when there is exception or interrupt in long mode? I believe that IDT is used to lookup the interrupt service routine start address (offset field) and type (type field). It does also check if current code can call it (in case of software interrupts) and change it to #GP if it cannot but I cannot see any further information. What are the steps of processor when it gets an interrupt in long mode?


Top
 Profile  
 
 Post subject: Re: What happens on interrupt in long mode
PostPosted: Thu Jul 02, 2015 4:06 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
The wiki entry on IDT explains a lot of this, and even talks about the differences between 32 and 64-bit operation.

But in general, the procedure is the same. When an interrupt is triggered by an INT instruction, or an IRQ, the CPU looks up the interrupt number in the IDT to get a segment and an offset for the interrupt handler routine, pushes the current IP/EIP/RIP to the stack, pushes any additional information to the stack (like error numbers, etc.), then jumps to the interrupt handler routine.

Is there something specific that you want to know about?

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: What happens on interrupt in long mode
PostPosted: Thu Jul 02, 2015 11:30 pm 
Offline

Joined: Tue Jun 09, 2015 9:34 am
Posts: 5
SpyderTL wrote:
The wiki entry on IDT explains a lot of this, and even talks about the differences between 32 and 64-bit operation.

But in general, the procedure is the same. When an interrupt is triggered by an INT instruction, or an IRQ, the CPU looks up the interrupt number in the IDT to get a segment and an offset for the interrupt handler routine, pushes the current IP/EIP/RIP to the stack,


Thanks. I've through that there is an automatic stack switch for example (as with say sysenter or sysexit).

SpyderTL wrote:
pushes any additional information to the stack (like error numbers, etc.), then jumps to the interrupt handler routine.


What prevents a userspace thread running on separate core from corrupting this information?


Top
 Profile  
 
 Post subject: Re: What happens on interrupt in long mode
PostPosted: Fri Jul 03, 2015 12:35 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 11:33 pm
Posts: 3882
Location: Eindhoven
There's a mechanism called IST stack switch. Three bits in the IDT entry are used to indicate which IST stack to use. The IST stacks can be found in the 64-bit TSS. On entry it always switches to the indicated IST stack.

Note that you should actively prevent an IST stack from being used concurrently (on 2 cores) or reentrantly (interrupting an interrupt handler); both won't work and will cause weird crashes.

When you have IST working, you can also re-enable the red zone for other code. This is why tutorials say you should disable it.


Top
 Profile  
 
 Post subject: Re: What happens on interrupt in long mode
PostPosted: Fri Jul 03, 2015 5:04 am 
Offline
Member
Member

Joined: Wed Jun 03, 2015 5:03 am
Posts: 397
mpiechotka wrote:
I have trouble finding this information - most things I find are either tutorials (mostly 32 bit) which don't really explain much (well - I can use it and it will probably work but I won't know how or why) or structure description. I was trying to find it in Intel manual but it seems to be spread out across several chapters (5-7) and concentrate on structures as well - furthermore it describes long mode only as differences to protected mode. That makes it hard to find information if you don't really know where to look for it.

The best way to understand the 64-bit modes is to read first about 32-bit modes. There is very detailed explanation of what's going on in Intel's manual for 32-bit modes and 64-bit modes just add some minor corrections to the 32-bit modes behavior. So, if you miss something while you are reading about a 64-bit interrupt it is highly probable you can find it when read about 32-bit interrupt.

_________________
My previous account (embryo) was accidentally deleted, so I have no chance but to use something new. But may be it was a good lesson about software reliability :)


Top
 Profile  
 
 Post subject: Re: What happens on interrupt in long mode
PostPosted: Sat Jul 04, 2015 12:09 am 
Offline

Joined: Tue Jun 09, 2015 9:34 am
Posts: 5
Thanks. I found what I asked for in the Volume 2 (instruction set) as it was combined with INT instruction description.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 127 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