I don't even know the subject is describing my problem correctly, as I'm noob in C. Here's the story, been scratching my head for days.
My kernel are loaded at 0xC0100000. Function init_term is at 0xC0403CA7. Kernel stack bottom: 0xC0406014, top 0xC0506014
Code: Select all
void _kmain(uint32_t magic, uint32_t mbi_addr) {
init_term(NULL);
...
Code: Select all
void init_term(term_api_t *api);
Code: Select all
if (api) { // <== triple fault when executing this line.
// load term functions by api.
}
When run debugging, it seems like [api] is not poiting to the kernel stack space. It is at 0x80000011, which non of the page are mapped to...
I just don't understand why this is happening, I'm expecting [api] should be at kernel stack top - 20 byte, because:
@loader
push mbi_addr <= - 4
push magic <= - 4
call _kmain <= - 4 (return address)
@_kmain
push 0 <= - 4
call init_term <= - 4 (return address)
but, as mention, it is 0x80000011, not 0xC0506028.
I don't know what happen.
EDIT: [NULL] is define as
Code: Select all
#define NULL ((void *) 0)
EDIT 3: I'm thinking maybe I should forget about the parameter, for now, and go on. So I remove the parameter and then I'm stuck again:
I'm trying to assign a function to a function pointer, which is a member of a struct:
Code: Select all
typedef struct {
const term_color_t *(*get_color)(void);
void (*set_color)(const term_color_t *color);
const cursor_info_t *(*get_cursor_info)(void);
void (*set_cursor_info)(const cursor_info_t *info);
void (*set_cursor_point)(const cursor_point_t *point);
void (*putc)(char c);
void (*putc_at)(char c, const cursor_point_t *point);
void (*puts)(const char *s);
void (*clear)(void);
} term_api_t;
Code: Select all
static term_api_t _api;
Code: Select all
_api.get_color = get_color;
Code: Select all
static const term_color_t *get_color(void)
Then I the debugger break automatically giving me the stack trace:
Code: Select all
??@0x0000e05b (Unknown Source:0)
Continue execution will cause a TP and qemu reset.