M3 Operating System Development

A chronicle of the development of the M3 operating system

Linker woes and missing strings

leave a comment »

Boy – getting my print function to work took some doing. I wrote the initial version of this function last night, and ran it to no avail. My clearscreen function was clearing the screen, and that’s it. My strings were not getting printed to the screen by my print function.

Poking around on OSDev.org led me to believe that there was a problem with my rodata section (for read-only data, I suppose), which is the section where string constants reside. I was declaring the following string constant in my code:

char *welcome = "Welcome to M3\nLine 2 here\n";

Which should put the string between the quotes into the rodata section (along with a terminating null char).

The first place that I checked was my linker script. I noticed that I was aligning everything to start at 0x1000. I’m not sure why I did this – probably had something to do with the fact that controlling the linker is completely new to me. My guess is that this had the effect of putting all the sections on top of each other.

I changed the linker script to put rodata right after the text section, and aligned the data section to start on the next page boundary, so it’s well out of the way. After linking the file with this modified script, I could see that things were no longer being dumped on top of each other. The -M switch to the ld command was helpful here, as was the trace switch (-t). Here’s the command I was using:

ld -T link.ld -M -t -o kernel.o start.o main.o

Executing this binary yielded something at the top of the screen – several seemingly miscellaneous characters on the first line, and couple of miscellaneous characters on the second line. This was definitely better, but not the desired goal.

Then I looked at my C code, and yeah, I’m definitely rusty. I guess it was kind of late when I wrote the first version of this code, because it was just plain wrong. I wasn’t iterating through my string properly – for some reason I was jumping two characters at a time. Bah. I’ll just chalk it up to the late hour.

After de-stupiding my C code, I rebuilt and re-ran, and voila! I saw my two-line string printed nicely at the top of my blank screen. Excellent.

Baby steps…


Written by m3os

March 21, 2009 at 10:27 am

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: