Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the flag register need to be saved when an interrupt occurs, or a process scheduling happens?

I know all the general registers are pushed on the stack when the an interrupts happen, but I can't see any code that flag register are save. The assembly instruction like setl which depends on the flag register, is easy to make a wrong result when restoring from an interrupt, if the flag register is corrupted.

like image 550
venus.w Avatar asked Sep 15 '25 12:09

venus.w


1 Answers

Yes, the (e/r)flags register needs to be saved across context switches like that.

All interrupts (hardware and software, including exceptions) save it automatically on the stack and the iret instruction at the end of the ISR restores it.

System calls use the same or similar mechanism and preserve the register.

Scheduling is triggered by interrupts or system calls. So, everything's covered.

like image 161
Alexey Frunze Avatar answered Sep 18 '25 09:09

Alexey Frunze