Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do all ARM bootloaders have assembly code?

Writing in assembler reduces the code size and the execution time. But suppose I have enough memory and enough time. Can I use just C code and boot the device? I mean, from power on, directly run C code. I'm specifically interested in ARM processors.

like image 443
user1225606 Avatar asked Dec 16 '22 23:12

user1225606


1 Answers

Actually you can make a C-only firmware for ARM's Cortex-M3 microcontrollers. Because its vector table includes an entry for the stack pointer, its value will be initialized by the processor and you can use compiled code straight away from the reset. You still need to set up the peripherals and initialize the C library environment, but you don't have to do it in assembler. Cortex-M3 also automatically saves volatile registers on interrupt handler entry so they can also be written straight in C.

That said, most compiler vendors still provide startup written in assembler since it offers the most control.

like image 104
Igor Skochinsky Avatar answered Dec 28 '22 10:12

Igor Skochinsky