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.
torshie
Member
Posts: 89 Joined: Sun Jan 11, 2009 7:41 pm
Post
by torshie » Sun Jul 10, 2011 5:38 pm
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
xenos
Member
Posts: 1121 Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:
Post
by xenos » Mon Jul 11, 2011 1:45 am
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!
Solar
Member
Posts: 7615 Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:
Post
by Solar » Mon Jul 11, 2011 1:52 am
Very slick, very clean. I love it!
Every good solution is obvious once you've found it.
torshie
Member
Posts: 89 Joined: Sun Jan 11, 2009 7:41 pm
Post
by torshie » Mon Jul 11, 2011 2:33 am
Found a better way to specify the end address of a section
"LONG(__data_end__)" and "LONG(__bss_end__)" can be replaced with "LONG(ADDR(.data) + SIZEOF(.data))" and "LONG(ADDR(.bss) + SIZEOF(.bss))" respectively.
blobmiester
Member
Posts: 45 Joined: Fri Jul 16, 2010 9:49 am
Post
by blobmiester » Mon Jul 11, 2011 10:27 am
I must add my voice to the rabble and say, "Well Done".
I'll definitely implement this in my boot stage.