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

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
Silverhawk

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

Post 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 !
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

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

Post by Neo »

what about using EXTERN/extern variables?
Only Human
Chris Giese

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

Post 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; }
Silverhawk

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

Post by Silverhawk »

OK, thanks guys,

I will try it this Week-end.
Post Reply