If have a "panic" function in my kernel, during VERY early boot it just prints to video memory. I want to have a way to hook it at run time. What's the best way to do that?
Currently, I have a little abstraction. So that when I make the switch from compile time hookable to run time hookable, it will have no effect on code that uses panic.
Here is panic.h:
Code:
#ifndef PANIC_H_INCLUDED
#define PANIC_H_INCLUDED
extern void panic(char *function, char *message);
#endif /* PANIC_H_INCLUDED */
panic.c
Code:
void print(char *message)
{
int i;
static int j;
char* video_mem = (char*)0xb8000;
for(i = 0;message[i] != 0;i++)
{
if(j >= 0x1000)
j = 0;
video_mem[j*2] = message[i];
video_mem[(j*2) + 1] = 7;
j++;
}
}
void panic(char *function, char *message)
{
print("panic: ");
print(function);
print(" : ");
print(message);
}
Is there a way to do this w/o resorting to making a pointer to hold the location of the hook and calling the pointer(with panic as a wrapper to call the real function that hooked it)?