Page 1 of 1

Create a multiboot header in ld script

Posted: Sun Jul 10, 2011 5:38 pm
by torshie
Add the following section at the beginning your ld script.

Code: Select all

	.mboot : ALIGN(16) {
		/* Multiboot header */
		LONG(0x1BADB002); /* Magic */
		LONG(1 << 16); /* Flags */
		LONG(-((1 << 16) + 0x1BADB002)); /* Checksum */
		LONG(ADDR(.mboot));
		LONG(ADDR(.text));
		LONG(__data_end__); /* End of data section */
		LONG(__bss_end__); /* End of bss section */
		LONG(_start); /* Entry point */
	}
Have fun ;)

Re: Create a multiboot header in ld script

Posted: Mon Jul 11, 2011 1:45 am
by xenos
Very nice! I guess one needs to add some arithmetics if the physical and virtual addresses of the sections differ, such as

Code: Select all

   .mboot : ALIGN(16) {
      /* Multiboot header */
      LONG(0x1BADB002); /* Magic */
      LONG(1 << 16); /* Flags */
      LONG(-((1 << 16) + 0x1BADB002)); /* Checksum */
      LONG(ADDR(.mboot) - KERNEL_OFFSET);
      LONG(ADDR(.text) - KERNEL_OFFSET);
      LONG(__data_end__ - KERNEL_OFFSET); /* End of data section */
      LONG(__bss_end__ - KERNEL_OFFSET); /* End of bss section */
      LONG(_start - KERNEL_OFFSET); /* Entry point */
   }
And of course some people may want to add some flags (module page alignment, memory info...). But anyway, I really like the idea!

Re: Create a multiboot header in ld script

Posted: Mon Jul 11, 2011 1:52 am
by Solar
Very slick, very clean. I love it!

Re: Create a multiboot header in ld script

Posted: Mon Jul 11, 2011 2:33 am
by torshie
Found a better way to specify the end address of a section :D
"LONG(__data_end__)" and "LONG(__bss_end__)" can be replaced with "LONG(ADDR(.data) + SIZEOF(.data))" and "LONG(ADDR(.bss) + SIZEOF(.bss))" respectively.

Re: Create a multiboot header in ld script

Posted: Mon Jul 11, 2011 10:27 am
by blobmiester
I must add my voice to the rabble and say, "Well Done". =D>
I'll definitely implement this in my boot stage.