System calls and saving to PCB
Posted: Fri May 28, 2010 4:10 am
This is something that has been troubling me, someone here maybe can help me. This is basic stuff which i'm trying to get to work and learn, but I cannot find anything i'm afraid.
Right now, I have a interrupt handler which looks something like this in pseudo-code (a regular basic interrupt handler). This is where it jumps on an interrupt.
First the ASM handler:
C handler
ASM interrupt handler last part:
It works as well, no problems with context-switching and so on...
When however a system call is invoked, I have to remove the saving/loading of registers into the PCB (that is, an if-clause is added that doesn't save the PCB if it's a system call). First I didn't know why I had to do this, so I simply removed the lines that saved/loaded the PCB state with an if-clause like mentioned, because I thought it probably anyways will come back to the same process after a system call. That worked, and my logic is probably correct. But I cannot do that now anymore, because I have to implement a thing that needs to load a new PCB directly after a certain system call has been made.
I realise now that when a system call is invoked, the registers have to be saved in some other way? Because when I do a system call and save its registers I realised that when it later comes back to the process which invoked the system call, it seems that the EPC and all other registers weren't saved correctly. In other words, how do you save the PCB state when doing a system call?
Thankful for help : )
Right now, I have a interrupt handler which looks something like this in pseudo-code (a regular basic interrupt handler). This is where it jumps on an interrupt.
First the ASM handler:
Code: Select all
Save all hardware registers to a buffer
Jump to C handler
Code: Select all
Get current state of all registers from the buffer
Save this to the current running PCB
If System Call exception
Perform system call function
Increase EPC with 4
If Timer Interrupt
Schedule processes
If I/O Interrupt
...
Load state of next PCB to run into the buffer
Goes back to ASM interrupt handler
Code: Select all
Restore all hardware registers from the buffer
Iret
When however a system call is invoked, I have to remove the saving/loading of registers into the PCB (that is, an if-clause is added that doesn't save the PCB if it's a system call). First I didn't know why I had to do this, so I simply removed the lines that saved/loaded the PCB state with an if-clause like mentioned, because I thought it probably anyways will come back to the same process after a system call. That worked, and my logic is probably correct. But I cannot do that now anymore, because I have to implement a thing that needs to load a new PCB directly after a certain system call has been made.
I realise now that when a system call is invoked, the registers have to be saved in some other way? Because when I do a system call and save its registers I realised that when it later comes back to the process which invoked the system call, it seems that the EPC and all other registers weren't saved correctly. In other words, how do you save the PCB state when doing a system call?
Thankful for help : )