OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:23 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Bare Bones linker script
PostPosted: Thu Oct 13, 2011 2:38 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
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.


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Thu Oct 13, 2011 11:32 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
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


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Fri Oct 14, 2011 1:16 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
I'm not quite sure, but doesn't
Code:
.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


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Fri Oct 14, 2011 3:43 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
XenOS wrote:
I'm not quite sure, but doesn't
Code:
.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.


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Fri Oct 14, 2011 9:09 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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:
.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


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Fri Oct 14, 2011 9:53 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
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:
.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)

Quote:
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.


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Sat Oct 15, 2011 8:29 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
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:
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:
  .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 !


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Sun Oct 16, 2011 6:38 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 26, 2007 1:53 am
Posts: 395
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/


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Mon Oct 17, 2011 6:45 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
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.


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Thu Jan 10, 2013 3:35 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 26, 2007 3:37 am
Posts: 117
Location: France
Code:
.comm stack, STACKSIZE, 32              # reserve 16k stack on a quadword boundary

This line seems to not compile, I just removed STACKSIZE, becoming
Code:
.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


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Thu Jan 10, 2013 5:45 pm 
Offline
Member
Member
User avatar

Joined: Wed Mar 21, 2012 3:01 pm
Posts: 930
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.


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Fri Jan 11, 2013 2:14 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Sun Sep 15, 2013 8:22 am 
Offline

Joined: Sun Sep 15, 2013 7:54 am
Posts: 1
narke wrote:
Code:
.comm stack, STACKSIZE, 32              # reserve 16k stack on a quadword boundary

This line seems to not compile, I just removed STACKSIZE, becoming
Code:
.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


Top
 Profile  
 
 Post subject: Re: Bare Bones linker script
PostPosted: Wed Sep 18, 2013 7:23 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Now you've bumped this thread, you may also want to change the comment into
Code:
# reserve 32B stack


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group