[NSWI004] program counter register

Petr Tuma petr.tuma at d3s.mff.cuni.cz
Fri Nov 6 16:18:44 CET 2020


Hi Georgii,

I touched upon this in toady's lecture, but I entirely forgot that the `cpu_switch_context` function is in assembly and therefore does not behave like a normal C function would. I've updated the discussion notes in the repository - to cut the long story short, by the time the `cpu_switch_context` function is called, the return address is in the `ra` register, and that is saved as part of the context.

(The return address is typically saved on stack at the entry to C functions (you would see something like `addiu sp,sp,-40` and `sw ra,36(sp)` as the first two instructions), but this is not the case for `cpu_switch_context`.)

Hope this helps, Petr


On 06/11/2020 13:29, Georgii Ekserdzhian wrote:
> Good afternoon,
> context_t doesn't contain a PC register.
> How should I initialize it to make my thread call this function?
> And does cpu_switch_context actually switch PC register?
> 
> Georgii Ekserdzhian
> 
> _______________________________________________
> NSWI004 mailing list
> NSWI004 at d3s.mff.cuni.cz
> https://d3s.mff.cuni.cz/mailman/listinfo/nswi004
> 


More information about the NSWI004 mailing list