HART Context

Is there a function in metal library which can be used to save current HART’s context for Hifive1 Rev B?

I am looking to back up current HART’s context in exception handler.

From my experience of reading the FreeRTOS and other OS source code, this saving context process has to be written in assembly language, because C cannot do register level things.

You need to use asm to get access to the registers and save them on the stack frame when switch out. Read the stack frame and load the register when switch in.

It is called trap.S

Generally, declaring your exception handler as “attribute((interrupt))” is sufficient as the C compiler then generates the necessary instructions to save all necessary registers on to the current stack.

Only if you want to do something else (e.g. switch stacks first, save registers in a global area, return to a different thread) do you need something else.

HI Bruce,

Yes, I need to backup in a specific location in custom order. Is there any existing leeway to make my job easier?

If you need something nonstandard such as a custom order of the registers then I don’t know how something standard would help you? Just write a few lines of assembly language.