Which registers to push on the stack during interrupt handli
Which registers to push on the stack during interrupt handli
In my ASM stub for handling interrupts, I currently use pusha to push all registers on the stack, but now I ask myself if I should also push the extended registers on the stack during these procedure with pushad... (I already tried it, inserting a pushad instruction after the pusha and a popad instruction before the popa instruction, and interrupts still worked, so what is the difference/which is better?)
BTW, if I'm using software-based task switching, I believe I still need a TSS in order to jump from Ring 3 to Ring 0. Is this right?
Candamir
BTW, if I'm using software-based task switching, I believe I still need a TSS in order to jump from Ring 3 to Ring 0. Is this right?
Candamir
Re:Which registers to push on the stack during interrupt han
You need to push general-purpose resgisters with pushad and flag register with pushf and push the segment registers DS,SS,ES,DS,GS,FS and stack pointer SP.
Yes u'll need that tooBTW, if I'm using software-based task switching, I believe I still need a TSS in order to jump from Ring 3 to Ring 0. Is this right?
Re:Which registers to push on the stack during interrupt han
And all these segment registers have to be set to 0x10?
Candamir
Edit: In my current ASM routine, I only deal with ds, es, fs and gs, but not with ss. Is there something wrong with it?
Candamir
Edit: In my current ASM routine, I only deal with ds, es, fs and gs, but not with ss. Is there something wrong with it?
Re:Which registers to push on the stack during interrupt han
You don't need to push the flags explicitly, they are already pushed implicitly by the cpu, when an interrupt occured. If you're using a flat memory model, with only 2 global segment descriptors, then you also don't need to push the segment registers (cs & ss are nonetheless pushed implicitly by the cpu). You also don't need the user-level stackpointer, because this is also implicitly pushed by the cpu.
Re:Which registers to push on the stack during interrupt han
Neither saves any segment registers (CS,DS,SS,ES,FS,GS). The pusha is just the 16bit version which pushes in the order of: AX, CX, DX, BX, SP (state before the pusha instruction), BP, SI, and DI. And so pushad is the equivalent but pushing EAX, ECX.. and so on. However, I'm afraid both mnemonics are same opcode (60h), which the assembler may treat pusha in 32bit mode as pushad or it might place an operand override size which correctly differs the two mnemonics. But ofcourse it depends on the assembler, and same goes with popa/popad.Candamir wrote:(I already tried it, inserting a pushad instruction after the pusha and a popad instruction before the popa instruction, and interrupts still worked, so what is the difference/which is better?)
I 'm thinking you thought the pusha instruction pushes segment registers which it doesn't. If that is the case, you need to manually save those segment registers, meaning push/pop them individually.Candamir wrote:Edit: In my current ASM routine, I only deal with ds, es, fs and gs, but not with ss. Is there something wrong with it?
Re:Which registers to push on the stack during interrupt han
That's not the case. In order to avoid further misunderstandings, I'll put my code here:Ryu wrote: I 'm thinking you thought the pusha instruction pushes segment registers which it doesn't.
Code: Select all
pusha ; pushad instead? Or both?
push ds
push es
push fs
push gs ; What about push ss?
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov eax, esp
push eax
mov eax, c_routine
call eax
pop eax
pop gs ; What about pop ss?
pop fs
pop es
pop ds
popa ; popad instead? Or both?
add esp, 8
iret
Candamir
Edit: This code /does/ work for interrupts and everything, but I'm asking myself if it is already enough to support multitasking routines...
Re:Which registers to push on the stack during interrupt han
Let me see if I understood it: In order to set up multitasking, the interrupt handler (the timer) just has to save all values on the stack into the current process_info struct, ask the scheduler for the next process and push its values on the stack. Is this correct?
If I have paging enabled, during which step do I change cr3? After pushing the new process values on the stack?
Candamir
If I have paging enabled, during which step do I change cr3? After pushing the new process values on the stack?
Candamir
Re:Which registers to push on the stack during interrupt han
combination of int/iret already saves the SS register (along with CS and EIP).; What about pop ss?
Re:Which registers to push on the stack during interrupt han
oh yeah...and eflags too ::)
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Which registers to push on the stack during interrupt han
doing a "pop ss" would result in nothing good anyway ... you cannot safely switch to a new stack segment without switching to a new stack pointer atomically... and no, "popad" will not "restore" the pushed value of ESP...