Hi All,
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:
void _kmain(uint32_t magic, uint32_t mbi_addr) {
init_term(NULL);
...
Signature of init_term as such.
Code:
void init_term(term_api_t *api);
I'm performing a check first thing in init_term:
Code:
if (api) { // <== triple fault when executing this line.
// load term functions by api.
}
I've tried "if (api != NULL)" not working, too.
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:
#define NULL ((void *) 0)
EDIT 2: Please point out if more information are needed.
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:
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;
In my term.c source file, I declare the variable:
Code:
static term_api_t _api;
The variable [_api] is at 0xC0406000. Back to where I remove the parameter, first line of code is:
Code:
_api.get_color = get_color;
The get_color function is at 0xC04037E0 and the signature is:
Code:
static const term_color_t *get_color(void)
matching the _api.getcolor.
Then I the debugger break automatically giving me the stack trace:
Code:
??@0x0000e05b (Unknown Source:0)
0x0000e05b? non of the code is at this address, how can it end up there?
Continue execution will cause a TP and qemu reset.