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 !
Sharing data between nasm, gcc and ld script's code
Re:Sharing data between nasm, gcc and ld script's code
what about using EXTERN/extern variables?
Only Human
-
Chris Giese
Re:Sharing data between nasm, gcc and ld script's code
; 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; }
; 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
OK, thanks guys,
I will try it this Week-end.
I will try it this Week-end.
