Page 1 of 1
register preservation considerations across syscalls
Posted: Fri Nov 24, 2023 8:00 pm
by ITchimp
When a hardware interrupt is generated, usually all register values are saved on the kernel stack...
but I have seen, in minix 3.1 that eax ebx, ecx, edx , est are not saved at all, only esi is preserved,
also I have seen in some context switch code, that the registers are not saved at all,,,
what are the considerations for determining whether registers should be saved, and if so, which ones?
Re: register preservation considerations across syscalls
Posted: Fri Nov 24, 2023 9:54 pm
by klange
You are mistaken.
The interrupt handlers in Minix 3 all use the macro
SAVE_PROCESS_CTX:
https://github.com/Stichting-MINIX-Rese ... _asm.S#L21
This, in turn, uses another macro
SAVE_GP_REGS:
https://github.com/Stichting-MINIX-Rese ... onst.h#L83
This macro saves EAX, ECX, EDX, EBX, ESI, and EDI:
https://github.com/Stichting-MINIX-Rese ... .h#L51-L56
Re: register preservation considerations across syscalls
Posted: Sat Nov 25, 2023 2:22 am
by ITchimp
I am talking about the version 3.1 of minix, you re referring to 3.3 version which switches from segment based
multitasking to paging... we are not talking bout the same version of minix
Re: register preservation considerations across syscalls
Posted: Sat Nov 25, 2023 2:53 am
by klange
Re: register preservation considerations across syscalls
Posted: Sat Nov 25, 2023 3:07 am
by klange
Further, support for 8086 segmentation was removed
before 3.1 was released with the 3rd edition of OSDI.
Some of the history before then still exists in the converted git repository, though, and we can look at the 16-bit version of the interrupt handlers, where we find the general purpose registers being saved:
https://github.com/Stichting-MINIX-Rese ... 35C20-L349
Re: register preservation considerations across syscalls
Posted: Sat Nov 25, 2023 3:06 pm
by Octocontrabass
ITchimp wrote:what are the considerations for determining whether registers should be saved, and if so, which ones?
Hardware interrupts may happen any time they're enabled, so any registers the interrupt handler may modify must be saved. Software interrupts occur only when requested, so no registers need to be saved.
In practice, though, it's usually easier to save all registers when entering the interrupt handler. It simplifies things like debugging, where you might want to peek at the current state of an interrupted program, and it simplifies context switching since the program's entire context has already been saved. For software interrupts, it also removes the risk of leaking privileged data.
Re: register preservation considerations across syscalls
Posted: Sat Nov 25, 2023 10:27 pm
by nullplan
Octocontrabass wrote:In practice, though, it's usually easier to save all registers when entering the interrupt handler. It simplifies things like debugging, where you might want to peek at the current state of an interrupted program, and it simplifies context switching since the program's entire context has already been saved. For software interrupts, it also removes the risk of leaking privileged data.
Uniformity in what exactly the stack frame looks like also allows syscalls to use the same register structure as the rest of the kernel, and it allows syscalls and interrupts to share the return code. Because it turns out in a UNIX based OS, that is where you can do a few things.