0

I am trying to build a small os. I have an asm file that puts the processor in 64 bit mode with paging enabled. After this, i am jumping to my C code. I want the C code and asm code to be linked into the same file but the C code to have base address at 0xFFFFFF8000000000 and the asm file at 0x5000. How can I do this with ld. This is what I have so far:

nasm -f elf64 os_init.asm -o ../bin/os_init.o
gcc -c -Os -nostdlib -nostartfiles -nodefaultlibs -fno-builtin vga/*.c utils/*.c *.c memory_management/*.c
ld -Ttext 0x5000 ../bin/os_init.o *.o -o ../bin/kernel.out
objcopy -S -O binary ../bin/kernel.out ../bin/kernel.bin

Currently both files are linked at 0x5000

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Cristi
  • 1
  • 1
    To do what you want you will really need to start using a linker script. You can create a section where all your higher half code is and a section for your lower half. If you put your project online (ie: github) I could take a look. – Michael Petch Apr 29 '19 at 23:39
  • I assume you also wrote your own bootloader (there are indirect indications of it in your question) and you aren't using GRUB. – Michael Petch Apr 29 '19 at 23:43

0 Answers0