system.inc issues

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

system.inc issues

Post by brodeur235 »

I'm writing a system.inc header that I want all my kernel modules to include. So far the header just defines some %define's and %macro's, which is all fine and good. However a problem soon arises... Situation:

1.) I have a k_main module containing my k_main procedure.
2.) I have a k_mem module containing procedures that reference the k_main procedure for various, necessary purposes.

The second module (the k_mem) needs to know that k_main is defined externally (with an "extern k_main" statement), but the k_main module will generate an error stating: "error: symbol `_k_main' redefined". I understand this; please don't post a response explaining why this is happening.

The problem is that all kernel modules besides k_main will need to know that the k_main procedure label is external, so it seems like a good thing to put in the system.inc. However, this will generate the previously described error when assembling the header with the k_main module.

What is a good solution to this? I'm hoping I won't have to go to each individual module and pencil in exactly what procedures need to be defined externally for that one file... It just feels wrong..

Help appreciated,

Brodeur235

EDIT: Basically, I want to do it like this tutorial does it in C, except in asm. http://osdever.net/bkerndev/index.php. As the author creates new kernel modules, his system.h accumulates the function prototypes from that module, and they're all with an extern keyword. Then he includes system.h in the same file, yet GCC apparently does not throw a "function redeclared" error... Nasm does.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: system.inc issues

Post by ru2aqare »

brodeur235 wrote:As the author creates new kernel modules, his system.h accumulates the function prototypes from that module, and they're all with an extern keyword. Then he includes system.h in the same file, yet GCC apparently does not throw a "function redeclared" error... Nasm does.
I dont know the nasm syntax, but you could do something similar to this C pseudocode

Code: Select all


// kmain.c
#define KMAIN_API /* nothing */
#include "system.inc"

// kmem.c
#include "system.inc"

// system.inc
#ifndef KMAIN_API
#define KMAIN_API extern
#endif

KMAIN_API kmain(void);

// and so on.
KMEM_API kmem_something(void);
KMEM_API kmem_something2(void);
KMAIN_API kmain2(void);
// etc.
brodeur235
Member
Member
Posts: 86
Joined: Sat Jun 06, 2009 11:55 am

Re: system.inc issues

Post by brodeur235 »

That's a good idea. I was thinking about something else since I last posted the thread starter, but that idea's even better,

Brodeur235
Post Reply