Page 1 of 1

Sharing data between nasm, gcc and ld script's code

Posted: Sun Apr 17, 2005 5:31 am
by Silverhawk
Hello !
I would like to have my kernel's memory organization to be entirely configurable...
In order to do that, I would like to share some definitions between my nasm code, my c code, and my linker script !
For example, the following variables are necessary in the 3 cases :

; // Kernel addresses
%define KERNEL_PADDR 0x100000
%define KERNEL_VADDR 0xC0000000

; // Paging constants
%define PAGE_SHIFT   12
%define   PAGE_SIZE    0x1000
   
%define PAGE_PRESENT   0x1
%define PAGE_RW      0x2
%define PAGE_4M      0x80

...

Someone knows a solution ?

Thanks !

Re:Sharing data between nasm, gcc and ld script's code

Posted: Sun Apr 17, 2005 9:24 pm
by Neo
what about using EXTERN/extern variables?

Re:Sharing data between nasm, gcc and ld script's code

Posted: Wed Apr 20, 2005 10:07 pm
by Chris Giese
; NASM code to export constant values
; Use these for ELF kernel
; (or COFF kernel compiled with -fno-leading-underscore)
global KERNEL_PADDR
KERNEL_PADDR equ 0x100000
global KERNEL_VADDR
KERNEL_VADDR equ 0xC0000000

; Use these for COFF kernel
global _KERNEL_PADDR
_KERNEL_PADDR equ 0x100000
global _KERNEL_VADDR
_KERNEL_VADDR equ 0xC0000000

/* C code to import constant values from asm or linker script */
#include <stdio.h>

/* "extern int KERNEL_PADDR" doesn't work
"extern char *KERNEL_PADDR" doesn't work */
extern char KERNEL_PADDR[], KERNEL_VADDR[];

int main(void) {
   printf("KERNEL_PADDR=0x%p, KERNEL_VADDR=0x%p\n",
      KERNEL_PADDR, KERNEL_VADDR);
   return 0; }

Re:Sharing data between nasm, gcc and ld script's code

Posted: Thu Apr 21, 2005 11:31 am
by Silverhawk
OK, thanks guys,

I will try it this Week-end.