Simple crt0.o Question

Programming, for all ages and all languages.
Post Reply
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Simple crt0.o Question

Post by mark3094 »

Hi,

Until now, I have been working on x86 only, but recently I have started looking into ARM (specifically, the Raspberry Pi).
I used to use C in Visual Studio, but since I want to use ARM, I have decided to look at using GCC instead. I've only just started looking into it, so please forgive any stupid questions / comments.

I started looking at the Cambridge RPi tutorials, which suggested using YAGARTO. This has been working fine on their assembly tutorials, but now I want to try writing some C code.
I created a basic main.c just to see if I could get it tom compile, however I can't even get that to work.

It can't find crt0.o, which from my understanding is the C Runtime. According to a few ideas from this site, I created crt0.s:

Code: Select all

.global _start

.extern main
.extern exit

_start:
bl main
bl exit

.wait:
bl .wait
and linker.ld:

Code: Select all

STARTUP(crt0.o)
I have tried to compile with:

Code: Select all

arm-none-eabi-gcc -o kernel.img crt0.s main.c -T linker.ld
It still can't find crt0.o

I realise this is probably very obvious to many of you out there, but I've only just started on GCC, and it's eluding me so far...

Can anyone point me in the right direction?


Thankyou
User avatar
Jezze
Member
Member
Posts: 395
Joined: Thu Jul 26, 2007 1:53 am
Libera.chat IRC: jfu
Contact:

Re: Simple crt0.o Question

Post by Jezze »

A crt0 is only needed for programs running on your os and should only link with those. At the moment you are trying to compile a kernel for arm and these don't use the crt0 at all. What you need instead is to write bootcode (basically set up the interrupt vector, set stack and jump to your kernel main, if you've written that in c that is).
Fudge - Simplicity, clarity and speed.
http://github.com/Jezze/fudge/
User avatar
mark3094
Member
Member
Posts: 164
Joined: Mon Feb 14, 2011 10:32 pm
Location: Australia
Contact:

Re: Simple crt0.o Question

Post by mark3094 »

Jezze wrote:basically set up the interrupt vector, set stack and jump to your kernel main
The RPi already comes with a bootloader in its firmware, so I didn't think I would need to do that... I will look into this.


I have found a workaround, which is simply to compile the crt0.s file first:

Code: Select all

arm-none-eabi-as -o crt0.o crt0.s
Then compile main.c later:

Code: Select all

arm-none-eabi-gcc -T -o kernel.img crt0.o main.c -nostartfiles -nodefaultlibs
This seems to work. I put inline ASM code into the C file to test it (it turns on the RPi OK light), and it's working just fine.

I'm sure there's a way to automate this with make files or something, but it seems to work for now.
Post Reply