I already found the Baking Pi tutorials, but they only use assembly language. I followed the first lessons, but I am already wondering how to use C instead. I mean, there is a reason they invented higher-level languages. I tried just compiling the C code to an object (.o
) file, compiling
.section .init
.globl _start
_start:
bl main
loop$:
b loop$
to another object file and linking them together and so obtaining kernel.img
. I then replaced the already present kernel with my own, but it doesn't execute the C code. The C code I wrote should just turn on the OK LED and then return (then comes loop$: b loop$
). But the OK LED flashes randomly a few times and then just stays off. Here's my C code:
int main(int argc, char ** argv) {
volatile unsigned *gpioAddr = (volatile unsigned *)0x20200000;
*(gpioAddr + 4) = 1 << 18;
*(gpioAddr + 40) = 1 << 16;
return 0;
}
How do I use C for operating system development on a Raspberry Pi?
I doubt it is an error in the code (although I'm just a hobbyist). I'm aware setting up C may be complicated, but I'm not the first one doing this. AFAIK, all the currently dominant OSes are mainly written in C, so there has to be an article explaining the process. I would be very happy with a list of steps too, so I can google for those steps and perhaps ask a question a little less broad.
Note: the ARM assembly equivalent of the above C code works just fine. It turns on the LED (after a bit of blinking). I think (hope) that indicates my Raspberry Pi is fine.