IRC channel logs

2026-01-16.log

back to list of logs

<damo22>preserving a register during interrupts/traps is hairy
<damo22>youpi: if i need a value saved for determining where to return to at the end of an interrupt or trap, can i just put it on the stack after pusha and PUSH_SEGMENTS? or will eg R_CS(%rsp) be then at the wrong place?
<damo22>where can i put such a value
<damo22>s/where to return to/whether swapgs is needed or not
<damo22>can i store it in a segment register? :P
<youpi>you can as well just look at the pushed cs value
<youpi>ah, no, because gs might have been switched or not
<damo22>yeah i need to save it in the SWAPGS_ENTRY thing
<damo22>that is where it knows
<youpi>adding something on the stack is possible, yes, it just needs an update of the offsets
<damo22>where are these offsets
<damo22>why is there no r11:
<damo22>offset i386_saved_state r r10
<damo22>offset i386_saved_state r r12
<youpi>just nobody needed it
<youpi>you can just add it if you need
<damo22>does that mean r11 is spare throughout
<youpi>no
<damo22>but we are not saving it?
<youpi>we have to, otherwise it'd be a bug
<youpi>the pusha macro does it
<damo22>ah its just nobody referred to it in the code
<youpi>yes
<damo22>why cant i use something like r15 that isnt saved or restored in the ISR?
<damo22>and just do an extra save and restore for that?
<youpi>I'm not sure what you call ISR
<damo22>PUSH_REGS_ISR
<damo22>its seems only a subset are needed for the interrupt/traps?
<youpi>there is no free lunch :)
<youpi>all_intrs knows it doesn't have to save r15 because it knows that its callees will not change it
<youpi>but otherwise it has to keep it unchanged
<youpi>otherwise it'd thrash state
<damo22>ok
<damo22>what is %es for?
<youpi>similar to %ds
<youpi>just another segment register (not the default)
<youpi>only for USER32
<damo22>ok
<damo22>i need to rewrite the stack
<youpi>? really ?
<youpi>you can just add what you want in i386_interrupt_state
<youpi>there is no constraint there
<youpi>it just needs to match what you push/pop on interrupt
<damo22>ohh that makes more sense
<damo22>i was looking for that struct
<damo22>if i add r12 that isnt already there, does that mean i can use r12 throughout the interrupt context as long as i push and pop it ?
<damo22>if i set r12 near the beginning, will it then survive until the end even with all the stack switching etc and traps or do i need to push it to the stack again with a new value
<youpi>yes
<youpi>it won't be changed by the callees since it's callee-saved
<youpi>so you don't need to push it again
<damo22>that will save me a lot of headache
<youpi>you can just save the value from the interrupted context, and put what you want it in
<damo22>yeah
<youpi>it'll stay there, just like previously the value of the interrupted context was staying there
<damo22>great
<damo22>seems like a waste of a whole register, but it will do
<youpi>not of a register, but 8bytes in the isr structure
<youpi>so really not much
<damo22>will debug more tomorrrow