Kernel EXE format

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
PrzemekG_

Kernel EXE format

Post by PrzemekG_ »

Hi,
I have already a working boot sector that reads from my fs, a boot loader that loads the kernel to RM memory, setup GDT, enter PM, copy the kernel from RM to PM and jump to it. I use DJGPP for compiling the kernel.

(Oh, and I made a GUI program to generate GDT descriptors, if anybody wants a copy, please email me).

The problem is I must link all kernel objects and set the code start to 0x0000 (with -Ttext). And what about data, how should I prepare the a GDT descriptor for it without knowing where the data is located in the memory? Do I have to recompile the bootloader each time?

I know ld have scripts, if it whould be possible to write bytes to the output file from that script, it whould be easy to create a simple format like (signature, code start, data start => code, data)
carbonBased

RE:Kernel EXE format

Post by carbonBased »

You can't really append bytes to the output file through LD, per se... but you can create symbols to reference the start of the code and data segments, like so:

  .text 0x00000000 :{
    textStart = .;
    *(.text)
    *(.text.*)
    *(.rodata)
  }
  textEnd = .;

And likewise for your .data and .bss segments

And then in your C code, you can reference those as regular symbols:

extern long textStart;
location of .text is then &textStart

Hope that helps,
Jeff
PrzemekG_

RE:Kernel EXE format - YES I CAN

Post by PrzemekG_ »

BYTE(0x45);
BYTE(0x45);
BYTE(0x46);
BYTE(eef_version);
BYTE(eef_release);
LONG(SIZEOF(.header));
LONG(SIZEOF(.text));
LONG(main);
LONG(SIZEOF(.data));
LONG(__data_start);
LONG(SIZEOF(.bss));
LONG(__bss_start);
LONG(stack_size);
LONG(__exit_addr);

I found that example!
Post Reply