We are working on a toy operating system as a assignment for a class. I'm having some trouble with writing of the kernel panic function.
It should save all registers, call some printf-like function, then print the saved registers and halt the cpu. Right now it's defined as a macro:
#define panic(...) \
do{ \
asm volatile("SAVE_REGISTERS %1\n\t" : "m="(_panic_context)); \
_panic_printk(&_panic_context, __VA_ARGS__); \
while(0)
_panic_context
is a global variable that contains saved registers of a thread and some more stuff. The problem is with SAVE_REGISTERS
. It is a macro defined somewhere in an assembler header file, but I don't know how to include it. Simple #include in the file obviously doesn't work. I've tried googling and writing funny and desperate stuff (like #include in the assembler strings :-) ) but nothing helped. Do you have any ideas how to solve this?
We're using GCC and compile for MIPS (running in a simulator :-) )
edit:
SAVE_REGISTERS
is defined with .macro SAVE_REGISTERS
... . It can't be in a C macro, because it's used in other assembly modules.
I can't make a .S file with it, because panic has to be variadic. Or at least I couldn't come up with any other way to do it.