Portable OS using Gcc. Can be?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Portable OS using Gcc. Can be?

Post by Jef »

Is it possible to write an OS that will be cross platform ?
I am developing AsteriOS in ASM but project goes too slow. Now i want to write the most of kernel code in C.
My primary target so far of my OS is x86-32 bit. But now i want to write something about PDAs and routerboards that use ARM CPU.
If we exclude the boot part that will be in ASM, can be done the rest in C that will also run in ARM CPU ?
Actually i don't have idea about ARM CPUs and i don't know how to replace the Windows Mobile from my PDA with another OS.
Of course some routines will be exclusively used for only one platform.

If anyone has involve with OS developing in PDAs, any information is welcome.
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
User avatar
JackScott
Member
Member
Posts: 1035
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Re: Portable OS using Gcc. Can be?

Post by JackScott »

I don't have any experience with PDAs specifically, but I can give some general hints.

Yes, an OS (written in a compiled HLL such as C or C++) can be made largely portable. There are some parts that will have to be rewritten for each architecture, such as the paging mechanism, interrupt support, and so on, but this can be abstracted so that all the other parts of the kernel see the same thing (a 'generic' architecture). This is called a HAL (hardware abstraction layer).

This is, AFAIK, how the Linux kernel does things. Most of the kernel is written to be portable (with autoconf and make doing a bit of jiggery-pokery at compile time), with sections written for each architecture specifically to make it portable.

A bit offtopic, but a similar thing is true in multi-platform compilers such as GCC. GCC's backend can be changed at compile time to target multiple architectures. Most of the GCC compiler works on a specification for a 'generic' architecture, then the backend translates that generic architecture into something useful (x86, PowerPC, ARM, SPARC, etc). You can take advantage of that in writing a (semi-)portable operating system.

If you're looking for inspiration, you might want to look at project Pedigree (http://code.google.com/p/pedigree). It's being designed by a few members here, and at the moment supports x86, x86-64, and PowerPC (as well as a few others).

Hope this helps.
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Re: Portable OS using Gcc. Can be?

Post by Jef »

From a quick view,... this project seems helps. Thanks.

So in general, if i use only standard commands (for / while loops etc) operators and structures, i choose the target CPU and i get an object without OS specific libraries.
I don't know if some commands such sprintf, memcpy are translated in opcodes, so can be used in my OS, or translated to OS API calls.
Of course i can write these functions in C, but its waste time already exists without calling OS API (windows, linux, etc).

Is there a list of OS independent commands ?

Thanks again,

Christos
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Portable OS using Gcc. Can be?

Post by AJ »

Hi,
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Standards.html wrote:The ISO C standard defines (in clause 4) two classes of conforming implementation. A conforming hosted implementation supports the whole standard including all the library facilities; a conforming freestanding implementation is only required to provide certain library facilities: those in <float.h>, <limits.h>, <stdarg.h>, and <stddef.h>; since AMD1, also those in <iso646.h>; and in C99, also those in <stdbool.h> and <stdint.h>.
Cheers,
Adam
User avatar
Jef
Member
Member
Posts: 112
Joined: Tue Jan 08, 2008 7:25 am
Location: Greece
Contact:

Re: Portable OS using Gcc. Can be?

Post by Jef »

So if i use only these includes, my code it will be OS independent.
That's a good information.
Thanks
Keep coding...
...the sky is the limit

AsteriOS project: http://www.mindfields.gr/main/index.php ... &Itemid=27
Post Reply