Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get started on writing my own mobile OS for ARM processors?

I am interested in creating my own mobile OS. I read that the existing mobile OSes run on ARM processors and use their assembly language, while desktop OSes like Linux and Windows are written in asm. C appears to be a language common to both. This leads me to some questions:

  • Do I have to learn ARM assembly language if I want to build my own mobile OS targeting the ARM Cortex processor?

If so, then once I start doing it:

  • Where/how do I test it? Can it run in a virtual machine?
  • There are boards like Beagleboard, but I don't understand why I'd need to buy them if I can use a VM - am I missing something here?
  • Can a single OS run on both x86 and ARM?

I'm sure that I want to build a mobile OS which can run on ARM processors like most of the existing mobile OSes do.

  • What should my initial steps be? Will it help to look at open source projects like android or any other OS?
  • Where can I find ARM assembly language resources and IDEs?
like image 525
Pointer Avatar asked Dec 02 '22 23:12

Pointer


1 Answers

1) some assembly is required for all platforms, you probably need some startup code to cover the assumptions of the programming language, for example a C compiler assumes you have setup the stack (pointer), and zeroed out .bss memory, .data is in the right place, etc. Depending on the processor, but usually, you may need some code for interrupt handling, and maybe task switching, etc.

2) yes there are many virtual machines, qemu, skyeye, etc.

3) it is very rare that an instruction set simulator or virtual machine, etc exactly matches the processor. Just because it works on the vm/sim doesnt mean it works. No different than running code in a debugger and outside a debugger. You should try different simulators as well as hardware to verify the quality of the simulator. One arm processor to another or one x86 to another can vary enough to lead to your software failing so even running on hardware isnt enough to sort out all of your potential bugs.

4) linux runs on many platforms yes? Netbsd runs on even more, yes? Depending on how you design your program it can be very portable or not portable or anywhere in between. It is up to you.

5) You need some operating system basics. maybe get the MicroC/OS-II book or some other similar materials. Get through the basics of task switching, etc.

6) IDE's and editors, etc are a very personal thing, one persons favorite is loathed by others. For ARM development you need to get the ARM ARM (ARM Architectural Reference Manual). What used to be a single document has split due to them having so many different cores and families. What is the oldest looking one the ARMv5 or ARMv6 ARM is what used to be the singular one. Get that one and you can at least write code that is more portable across the whole family of arm cores. You will want to get some TRM's (Technical Reference Manuals). Get the one for the ARM7TDMI (ARMv4T), its like getting the 486 manual from intel, pretty much everything (32bit arm instructions) since is compatible back to that core. Probably want to get TRM's for other families. Understand that even though an older version for example a rev 1.0 (r1p0) might be marked as obsolete if there is a manual for it ARM has sold it to someone and it exists in some chips somewhere, and you might need to know the differences between cores (if you target that closely). Peripherals such as the pl310 L2 cache are often found attached to some cores, you will likely want to know what is in there if you have an interest in turning on and using the cache. Hmmm, the arm7 (ARMv4, not to be confused with the ARMv7) does not have an mmu, I think the ARM9 does, so depending on how you want to manage apps and their memory, you might want to use the ARM9 or something newer as a baseline.

get the codesourcery lite gnu based toolchain. codesourcery is now part of mentor graphics. It is not hard to build your own cross compiler for arm or get some other (emdebian, etc). ARM makes a good compiler but it is pricey and most support will come from them at a price, certainly some online googling for help but most free help is gcc based. the llvm compiler tools are getting better every day, they are used on iPhones from what I understand. I use the clang compiler which is part of llvm. You dont have to build a cross compiler necessarily out of the box they are a cross compiler from language to intermediate to target's assembly. assembling and linking is targeted to the host, but you can use the gnu binutils assembler and linker for that final step.

Like the IDE/editor, your programming style and preferences might lean you toward one compile environment over another.

You might find my arm examples on github useful or not, they are low level, board bring up type examples. Mostly thumb based but some arm as well where possible.

like image 142
old_timer Avatar answered Dec 15 '22 14:12

old_timer