Bare Bones linker script
Bare Bones linker script
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".
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".
Every good solution is obvious once you've found it.
Re: Bare Bones linker script
Hi,
Cheers,
Adam
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.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".
Cheers,
Adam
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Bare Bones linker script
I'm not quite sure, but doesn't
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
Code: Select all
.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
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
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:I'm not quite sure, but doesn'talign the stack on a 32 byte boundary, according to this doc?Code: Select all
.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
Actually I was reclining on the couch in the living room, trying to figure out a nasty problem on the company laptop.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".
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.
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.
Every good solution is obvious once you've found it.
- xenos
- Member
- Posts: 1121
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Bare Bones linker script
Just one more thing: Is there any good reason for putting the "stack" symbol into .common by using .comm instead of something like this?
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...
Code: Select all
.section .bss
.align 4
stack:
.space STACKSIZE
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
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.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
I'd like to point out that the GAS code is older.I guess this is the GAS equivalent of the NASM code in the bare bones tutorials.
Every good solution is obvious once you've found it.
Re: Bare Bones linker script
There are couple of other choices as well. .fill, .skip(which is apparently equivalent to .space) and my personal favorite .rept: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.
Code: Select all
.rept STACKSIZE
.byte 0
.endr
But you look rather young now, over the previous Avatar you got. Looks like an old celebrity hitting gym.Solar wrote:But I've grown old(er), and fat(ter)
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: Bare Bones linker script
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.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
http://github.com/Jezze/fudge/
Re: Bare Bones linker script
You got me. (No, really. )berkus wrote:Looks like you've been retouched in MS Paint at 16x zoom.
I'll do a touching-up ASAP.
Every good solution is obvious once you've found it.
Re: Bare Bones linker script
Code: Select all
.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
Code: Select all
.comm stack, 32 # reserve 16k stack on a quadword boundary
I'm new to gas syntax, can someone tell if it's normal?
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
Re: Bare Bones linker script
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.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Bare Bones linker script
Use a crosscompiler first before complaining?
Re: Bare Bones linker script
working nownarke wrote:This line seems to not compile, I just removed STACKSIZE, becomingCode: Select all
.comm stack, STACKSIZE, 32 # reserve 16k stack on a quadword boundary
and it just works.Code: Select all
.comm stack, 32 # reserve 16k stack on a quadword boundary
I'm new to gas syntax, can someone tell if it's normal?
Re: Bare Bones linker script
Now you've bumped this thread, you may also want to change the comment into
Code: Select all
# reserve 32B stack