User avatar
liz
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 5197
Joined: Thu Jul 28, 2011 7:22 pm
Contact: Website

Re: Programming the RPi on the bare metal

Mon Jul 09, 2012 9:12 pm

To (name redacted): Please don't PM me asking me to close threads like this where people are having perfectly above-board language flamewars! (I actually rather enjoyed reading this.)
Director of Communications, Raspberry Pi

pygmy_giant
Posts: 1562
Joined: Sun Mar 04, 2012 12:49 am

Re: Programming the RPi on the bare metal

Mon Jul 09, 2012 9:33 pm

Ok I wont - I didn't ask for it to be closed - I just dont want anyone to say anything they regret - I personally don't enjoy bickering
Last edited by pygmy_giant on Mon Jul 09, 2012 9:38 pm, edited 2 times in total.
Ostendo ignarus addo scientia.

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4249
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Programming the RPi on the bare metal

Mon Jul 09, 2012 9:34 pm

Sorry Liz; pygmy_giant is right we're not talking about languages any more. I'm taking it to PMs.

bobc
Posts: 86
Joined: Fri Apr 06, 2012 8:01 am

Re: Programming the RPi on the bare metal

Tue Jul 10, 2012 12:21 am

FWIW, I think it is very useful for embedded/bare metal programmers to have an understanding of the machine architecture and it's assembly code. I have seen people get by with a C compiler and printf, but being able to look under the hood and understand what is going on helps a lot. For example, when you get a Data Abort, being able to look at the stack and see where it occurred, or if you have to work with startup code etc.

I just wouldn't write the whole application in assembly, even for small projects. By lines of code, the Linux kernel is about 3% assembly code. EETimes surveys puts the percentage of projects written "mostly in assembly" at about 5%, but 60% of programmers use assembly code as part of their project. Those figures include all those small 8/16 bit projects which are still done in assembly.

So there you go, your software should be 97% HLL, 3% assembly. Real Programmers of course, use FORTRAN. On punched cards :D

tufty
Posts: 1456
Joined: Sun Sep 11, 2011 2:32 pm

Re: Programming the RPi on the bare metal

Tue Jul 10, 2012 6:35 am

Oh, any bare metal programmer /has/ to have at least some knowledge of the target assembler and the host hardware. That doesn't mean they have to be a guru - indeed, I doubt if there are more than one or two ARM gurus around here (outside of the Broadcom employees) - I'm certainly not one. That's part of why I believe one should use as little assembly as possible - it's close to impossible to get collaborators when a miniscule fraction of your target audience can get a grip on your code, let alone criticise it.

But in the end, it's all choices, innit? I'm doing away with assembler to use scheme. Bare metal schemers, put your hands up. Just me, then? Figures...

Simon

Bakul Shah
Posts: 305
Joined: Sun Sep 25, 2011 1:25 am

Re: Programming the RPi on the bare metal

Tue Jul 10, 2012 8:12 am

bobc wrote:Real Programmers of course, use FORTRAN. On punched cards :D
Real old programmers : ) My one and only Fortran program, an autorouter, was entered on punched cards because that is what we had to use back then! My first boss told me he had entered code for a Fortran subset compiler through the front panel switches! That's about as bare metal as it gets! [I believed him. He was meticulous and had the patience of Job.]

User avatar
rurwin
Forum Moderator
Forum Moderator
Posts: 4249
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

Re: Programming the RPi on the bare metal

Tue Jul 10, 2012 8:32 am

You will almost certainly have to write some assembler in order to do bare-metal work. But, in my view, if you are using C then it should be just the initial configuration and the semaphores implementation and maybe some interrupt routines. If you are using another language then there might be more, but even that should be written in C. So you would have the bare minimum of code is assembler, the code that needed to talk to the hardware in C and everything else in your other language. That means you have to be tri-lingual but that's a good thing right? ;-)

The first thing bare-metal code on the RaspPi probably needs to do is to find out where it is loaded, install the interrupt vectors at zero, load the rest of itself to a well-known location and jump there. That sort of stuff needs to be assembler, and it is fairly non-trivial assembler at that. Then the framebuffer driver and the USB and Ethernet stacks should be C with optimisations where necessary in assembler. The rule of thumb should be that everything that does not need to be in a lower level language should be coded in a higher level one.

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 21653
Joined: Sat Jul 30, 2011 7:41 pm

Re: Programming the RPi on the bare metal

Tue Jul 10, 2012 8:32 am

Too late. DexOS, sorry, you started it. You need to chill and keep on enjoying assembler and writing your OS, rather than arguing that assembler is the best thing since sliced bread. (it is, in some circumstances, it isn't in others)

And as a hint for everyone to get programming, in whatever language you like best, I'm closing this thread as its gone too far and is likely to go futher. Please start a new thread.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Contrary to popular belief, humorous signatures are allowed. Here's an example...
"My grief counseller just died, luckily, he was so good, I didn't care."

Return to “Bare metal, Assembly language”