Create a multiboot header in ld script

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
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Create a multiboot header in ld script

Post 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 ;)
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Create a multiboot header in ld script

Post 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!
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Create a multiboot header in ld script

Post by Solar »

Very slick, very clean. I love it!
Every good solution is obvious once you've found it.
torshie
Member
Member
Posts: 89
Joined: Sun Jan 11, 2009 7:41 pm

Re: Create a multiboot header in ld script

Post 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.
User avatar
blobmiester
Member
Member
Posts: 45
Joined: Fri Jul 16, 2010 9:49 am

Re: Create a multiboot header in ld script

Post by blobmiester »

I must add my voice to the rabble and say, "Well Done". =D>
I'll definitely implement this in my boot stage.
Post Reply