Page 1 of 1

Bare Bones linker script

Posted: Thu Oct 13, 2011 2:38 am
by Solar
Two questions on the Bare Bones / C++ Bare Bones linker scripts:

1) Could someone with a better grasp of ASM please check if the stack aligning / setup makes any sense? I wrote it ages ago, but never developed my own kernel to the point where I could say with confidence that I did it right.

2) Should we include two symbols for beginning and end of the other sections, as we did for BSS? The question "how do I determine the size of my kernel" has shown up a couple of times, but I'm not sure if this is within the scope of a "bare bones".

Re: Bare Bones linker script

Posted: Thu Oct 13, 2011 11:32 am
by AJ
Hi,
Solar wrote:2) Should we include two symbols for beginning and end of the other sections, as we did for BSS? The question "how do I determine the size of my kernel" has shown up a couple of times, but I'm not sure if this is within the scope of a "bare bones".
My vote for this is that we simply include symbols for the kernel start and kernel end, rather than identifying each section individually. If someone wants to identify a particular section, I feel that they would only want to do so for non-standard reasons (i.e. it would be beyond the scope of the tutorial). I would also suggest that there is a footnote about how to (correctly!) identify these symbols from the C code. Not because it belongs in a barebones, but more because the question is asked so often.

Cheers,
Adam

Re: Bare Bones linker script

Posted: Fri Oct 14, 2011 1:16 am
by xenos
I'm not quite sure, but doesn't

Code: Select all

.comm stack, STACKSIZE, 32              # reserve 16k stack on a quadword boundary
align the stack on a 32 byte boundary, according to this doc?

BTW, I still cannot believe you got a new avatar - I still need to get used to it... Somehow I miss the image of the "wise guy sitting in a chair in front of his desk and sharing his wisdom with us". Oh, and I felt urged to get myself an avatar, too ;)




edit JAAman: fixed broken code tag

Re: Bare Bones linker script

Posted: Fri Oct 14, 2011 3:43 am
by Solar
XenOS wrote:I'm not quite sure, but doesn't

Code: Select all

.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
align the stack on a 32 byte boundary, according to this doc?
That might well be. I always was fuzzy about the word / doubleword / quadword thing, and always had to look it up. (Another reason why I am a strong evangelist of <stdint.h>.)
XenOS wrote:Somehow I miss the image of the "wise guy sitting in a chair in front of his desk and sharing his wisdom with us".
Actually I was reclining on the couch in the living room, trying to figure out a nasty problem on the company laptop. :D

But I've grown old(er), and fat(ter), I switched company (twice), I moved from that flat to my own house, and neither that laptop nor that t-shirt exist anymore. The problem I was trying to solve at that time was related to Pro-POS, my OS project defunct for seven years now. The only thing from that pic that's still around is the couch. 8)

All in all, I didn't want to still use a picture of me at age 29 when I turn 39 this month. But I might look for a more "computerish" pic of mine if the image of a soccer-cheering computer geek disturbs you. :wink:

Re: Bare Bones linker script

Posted: Fri Oct 14, 2011 9:09 am
by xenos
Just one more thing: Is there any good reason for putting the "stack" symbol into .common by using .comm instead of something like this?

Code: Select all

.section .bss
.align 4
stack:
.space STACKSIZE
I guess this is the GAS equivalent of the NASM code in the bare bones tutorials.

OT: I wouldn't call it "disturbing", just... very different ;) Let me see whether I can find an "authentic" one from my office, with the blackboard in the background... Unfortunately I moved to a different office recently where I have a whiteboard instead, and there is no comparison between chalk and whiteboard markers...

Re: Bare Bones linker script

Posted: Fri Oct 14, 2011 9:53 am
by Solar
XenOS wrote:Just one more thing: Is there any good reason for putting the "stack" symbol into .common by using .comm instead of something like this?

Code: Select all

.section .bss
.align 4
stack:
.space STACKSIZE
No specific reason. IIRC, I simply found .comm in the documentation before I found .section / .space all those years ago, never having used binutils before. Or perhaps I just liked having only one line instead of multiple ones. 8)
I guess this is the GAS equivalent of the NASM code in the bare bones tutorials.
I'd like to point out that the GAS code is older. 8)

Re: Bare Bones linker script

Posted: Sat Oct 15, 2011 8:29 am
by Chandra
XenOS wrote:Just one more thing: Is there any good reason for putting the "stack" symbol into .common by using .comm instead of something like this?

Code: Select all

Code:
.section .bss
.align 4
stack:
.space STACKSIZE

I guess this is the GAS equivalent of the NASM code in the bare bones tutorials.
There are couple of other choices as well. .fill, .skip(which is apparently equivalent to .space) and my personal favorite .rept:

Code: Select all

  .rept   STACKSIZE
  .byte   0
  .endr
Solar wrote:But I've grown old(er), and fat(ter)
But you look rather young now, over the previous Avatar you got. Looks like an old celebrity hitting gym. :wink:

Re: Bare Bones linker script

Posted: Sun Oct 16, 2011 6:38 am
by Jezze
One thing I think could be mentioned is that you might want to add a section .mboot before .text for holding the multiboot information. This is to make sure the multiboot information is available in the beginning of your kernel image so that grub is able to pick it up because else you will get questions about why the kernel stops booting after adding some seemingly unrelated code to your kernel and the problem was that grub no longer can find the multiboot information. Also I think it could be a good idea to reserve space for the entire mboot header. You only reserve space for MAGIC, FLAGS and CHECKSUM but there should be four more I think.

Re: Bare Bones linker script

Posted: Mon Oct 17, 2011 6:45 am
by Solar
berkus wrote:Looks like you've been retouched in MS Paint at 16x zoom.
You got me. :twisted: (No, really. :-D )

I'll do a touching-up ASAP.

Re: Bare Bones linker script

Posted: Thu Jan 10, 2013 3:35 pm
by narke

Code: Select all

.comm stack, STACKSIZE, 32              # reserve 16k stack on a quadword boundary
This line seems to not compile, I just removed STACKSIZE, becoming

Code: Select all

.comm stack, 32              # reserve 16k stack on a quadword boundary
and it just works.

I'm new to gas syntax, can someone tell if it's normal?

Re: Bare Bones linker script

Posted: Thu Jan 10, 2013 5:45 pm
by sortie
That .lcomm, .comm thing again? That tutorial has been broken for ages. I think I'll just update the wiki with some simpler (working) code.

Re: Bare Bones linker script

Posted: Fri Jan 11, 2013 2:14 am
by Combuster
Use a crosscompiler first before complaining?

Re: Bare Bones linker script

Posted: Sun Sep 15, 2013 8:22 am
by axxo1
narke wrote:

Code: Select all

.comm stack, STACKSIZE, 32              # reserve 16k stack on a quadword boundary
This line seems to not compile, I just removed STACKSIZE, becoming

Code: Select all

.comm stack, 32              # reserve 16k stack on a quadword boundary
and it just works.

I'm new to gas syntax, can someone tell if it's normal?
=D> working now

Re: Bare Bones linker script

Posted: Wed Sep 18, 2013 7:23 am
by qw
Now you've bumped this thread, you may also want to change the comment into

Code: Select all

# reserve 32B stack