Bare Bones linker script

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
Post Reply
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Bare Bones linker script

Post 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".
Every good solution is obvious once you've found it.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Bare Bones linker script

Post 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
User avatar
xenos
Member
Member
Posts: 1115
Joined: Thu Aug 11, 2005 11:00 pm
Freenode IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Bare Bones linker script

Post 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
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: Bare Bones linker script

Post 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:
Every good solution is obvious once you've found it.
User avatar
xenos
Member
Member
Posts: 1115
Joined: Thu Aug 11, 2005 11:00 pm
Freenode IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Bare Bones linker script

Post 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...
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: Bare Bones linker script

Post 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)
Every good solution is obvious once you've found it.
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Bare Bones linker script

Post 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:
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Freenode IRC: jfu
Contact:

Re: Bare Bones linker script

Post 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.
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Bare Bones linker script

Post 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.
Every good solution is obvious once you've found it.
User avatar
narke
Member
Member
Posts: 117
Joined: Wed Dec 26, 2007 3:37 am
Location: France

Re: Bare Bones linker script

Post 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?
OS for PowerPC Macs: https://github.com/narke/Einherjar
Operating system: colorForth computing environment for x86.: https://github.com/narke/Roentgenium
User avatar
sortie
Member
Member
Posts: 930
Joined: Wed Mar 21, 2012 3:01 pm
Freenode IRC: sortie

Re: Bare Bones linker script

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Freenode IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Bare Bones linker script

Post by Combuster »

Use a crosscompiler first before complaining?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
axxo1
Posts: 1
Joined: Sun Sep 15, 2013 7:54 am

Re: Bare Bones linker script

Post 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
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: Bare Bones linker script

Post by qw »

Now you've bumped this thread, you may also want to change the comment into

Code: Select all

# reserve 32B stack
Post Reply