I want to write a bare metal hello-world for ARM. the message should be outputted at the uart. The device tree file says about the uart:
uart@09000 {
compatible = "arm,pl011", "arm,primecell";
reg = <0x9000 0x1000>;
interrupts = <0x5>;
};
Here is my hello world program.
// vexpress.js:651
const int DR = 0x00;
const int FR = 0x18;
const int IBRD = 0x24;
const int FBRD = 0x28;
const int LCR_H = 0x2c;
const int CR = 0x30;
const int IFLS = 0x34;
const int IMSC = 0x38;
const int MIS = 0x40;
const int ICR = 0x44;
unsigned int *uart;
void
putc(char c)
{
// wait for UART to become ready to transmit
// vexpress.js:707
while ((uart[FR] & (1 << 7)));
uart[DR]= c;
while ((uart[FR] & (1 << 7)));
}
void
puts(char *s) {
while(*s)
putc(*(s++));
}
int
main()
{
char s[] = { 'H', 'a', 'l', 'l', 'o' , 0};
int i;
// vexpress.js:1455
uart = (unsigned int*)0x10009000;
// 1
putc('H');
putc('a');
putc('l');
putc('l');
putc('o');
putc(' ');
putc('W');
putc('e');
putc('l');
putc('t');
putc('\n');
putc('\r');
// 2
puts(s);
// 3
for(i=97;i<123;i++){
putc((char)i);
}
// 4
puts("Hello World\n\r");
while(1);
}
So, this program uses several ways out output stuff to the uart. Section 1 (with all the calls to putc does work. But putc seems not to like being called in a loop. Neither 2 nor 3 nor 4 do work. The first charter does work, oddly '\0' are sent thereafter, and i have no clue why. The output is
Hallo Welt
a\0\0\0\0.........
I use arm-js because that is the only arm emulator that was either complete enough (mmu, can run linux) and is simple enough to single step (no jit or alike).
Also, is there a way to integrate a uart driver that does read information for a device tree file at build time? Is there a kernel that allow me to use that part stand alone easily?
/edit
The cpu is a ARMv5 cortex-a9 vexpress processor. I'm not sure what other information are of interest, so
this is the device tree file and this is the assembler code
0x90001000; device tree is probably big endian due to PowerPC heritage, but I would trust a data sheet for the UART's physical address. - artless noise