OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:35 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 8:29 am 
Offline
Member
Member

Joined: Fri Jul 23, 2010 8:26 am
Posts: 53
Hello,

I am looking into porting GCC to my hobby OS. I need to know what API functions it requires. I have searched around and am unable to find what I am looking for. If anyone knows what API functions are needed, it would help me greatly.

Hoozim


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 9:09 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2111
Location: Bucharest, Romania
It will obviously require partial POSIX support. Also, see http://wiki.osdev.org/OS_Specific_Toolchain

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 10:09 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
Love4Boobies wrote:
It will obviously require partial POSIX support. Also, see http://wiki.osdev.org/OS_Specific_Toolchain


I like the tutorial, but there is one problem with the approach: Whenever any of these projects are updated (and they are updated all the time), your build will not easily be able to use these updates. You will be stuck on an outdated version. To remedy this, you need to provide patches (and get them accepted) by the maintainers, which is no easy task. A serious, long-term, OS project definitely needs live support in the toolchains it uses.


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 11:01 am 
Offline
Member
Member

Joined: Fri Jul 23, 2010 8:26 am
Posts: 53
Hello,

Thank you for your replies. I should probably start by porting some simpler things for practice. Any suggestions?

Hoozim


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 11:47 am 
Offline
Member
Member

Joined: Fri Jan 13, 2012 11:18 am
Posts: 37
Newlib, perhaps?

A good start for porting anything, as you'll need a libc to port most programs including.... you guessed - GCC!

_________________
Not sane
Just remember, FIND Is Not DOS :)


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 11:51 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
Just checked the proposed changes in binutils, and all of these contain rdos. Seems like I could go ahead and try to provide patches for GCC if I want to support this environment now. The only problem is that I state to use elf32 as output format. I should have used PE, but I suppose that was not fully functional at the time.

Even if all the propositions in the wiki-article are covered in the rdos port, does not mean there might not be some other files as well that I modified.


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 12:14 pm 
Offline
Member
Member

Joined: Fri Jul 23, 2010 8:26 am
Posts: 53
Hello,

I am current writing my own C library instead of porting Newlib. If it works out, I will stick with my C library, otherwise I will port Newlib.


Hoozim


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 12:56 pm 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 3191
Hoozim wrote:
I am current writing my own C library instead of porting Newlib. If it works out, I will stick with my C library, otherwise I will port Newlib.


That's another way to go about it. I suppose you could use GCC to link to your own library, provided some minimal requirements are met (like using the correct startup-code). The downside would be that you might be less POSIX-compatible. By using libc or newlib you are guaranteed a high level of POSIX compliance. This would be the major reason why I would try to provide a GCC port, as my current compiler (OpenWatcom) has poor C and POSIX compliance.

I also suppose I could use the files I already provided to OpenWatcom's clib and use them for a C library instead of using libc or newlib, but I probably won't as I want the best possible POSIX compliance.


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sat Mar 24, 2012 1:51 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
berkus wrote:
For the binutils part there's http://sourceforge.net/apps/trac/elftoolchain/ which still misses LD, unfortunately.

It seems there is something in-tree, no idea how far along it is yet.

http://sourceforge.net/apps/trac/elftoo ... r/trunk/ld

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sun Mar 25, 2012 9:34 am 
Offline
Member
Member

Joined: Thu Feb 23, 2012 8:39 am
Posts: 60
I wanted to give Solar's PDCLib a try, is it worth something? :)


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sun Mar 25, 2012 11:07 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 05, 2009 5:04 pm
Posts: 234
Location: UK
ydoom wrote:
I wanted to give Solar's PDCLib a try, is it worth something? :)


Its worth about 300 internet dollars. ;-)

_________________
My homepage. | Discord RPG Bot | D++ - The C++ Discord API Library for Bots


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Sun Mar 25, 2012 11:28 pm 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
ydoom wrote:
I wanted to give Solar's PDCLib a try, is it worth something? :)


It is not complete. Locale support, wide / multibyte character support, the functions from <time.h> and anything having to do with floating points is not yet implemented.

It is also not optimized. It comes with generic (and naive) implementations of memcpy(), memmove() etc.; if your compiler of choice comes with builtin functions of these, making the apropriate adjustments for using them will benefit performance. (I will add an appropriately optimized GCC overlay in the future. It's not difficult at all, given the structure of PDCLib actively enabling such patching; it just didn't have priority for me so far.)

malloc() / free() are also naively implemented placeholders, and could do with being replaced with something more... apropriate. (In the long run, I plan to integrate dlmalloc().)

But what is there is fully functional, and if I may say so, reasonably well-tested. I have several users who use PDCLib for their OS projects, including one running a full-blown, dash-shell based usespace on top.

Overall, development is in hiatus for now, as I am working on another large (non-software) project, which I will probably finish during the summer.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Mon Mar 26, 2012 1:04 am 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 7:42 pm
Posts: 1391
Location: Unknown. Momentum is pretty certain, however.
IIRC, porting gcc isn't terribly difficult. The previously linked to OS Specific Toolchain tutorial + a simple implementation of sysconf is mostly all of what you need. I have a fairly functional port of gcc running on my OS (by fairly functional I mean it compiles my OS correctly). It can be a fairly lengthy procedure to port it, I remember having numerous errors in compilation that I had to fix, and I recall various runtime errors that needed to be fixed as well, but overall it's not terrible complicated.
Good luck.

-JL

_________________
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Tue Mar 27, 2012 7:04 am 
Offline
Member
Member

Joined: Thu Feb 23, 2012 8:39 am
Posts: 60
Solar wrote:
Overall, development is in hiatus for now, as I am working on another large (non-software) project, which I will probably finish during the summer.


I like the comment about "I really want to think about something else than stdio!" in readme ;)
Please forgive careless language, I know that it's "worth something" :) What I meant was, is it enough to compile GCC, or will I have to port newlib anyway?
Regards,


Top
 Profile  
 
 Post subject: Re: Porting GCC to my OS
PostPosted: Tue Mar 27, 2012 8:33 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
ydoom wrote:
What I meant was, is it enough to compile GCC, or will I have to port newlib anyway?


It will definitely not be enough. I expect GCC to make use of several POSIX calls, whereas PDCLib is "only" C99 (so that it does not limit your design choices by making additional demands on the kind of system calls that you provide). That means that stuff like execve(), fchdir(), stat() etc. will need to be implemented on top and beside of PDCLib. Have a look at Rink Springer's Ananas project. He has got dash, Lua and coreutils running on top of PDCLib plus POSIX extensions of his making, and is actively working towards getting binutils / GCC to compile on his OS. You might want to link up with him and combine efforts. I might be interested in hosting a "PDCLib POSIX layer" somewhere down the line, and will certainly accept any sensible patches to PDCLib that might turn up during your endeavour (as I accepted Rink's patches). His code is beerware, by the way.

Edit: A quick sketch. PDCLib provides only the "CLib" part (with the aforementioned limitations as it's not yet "released"), while keeping a minimal footprint. Newlib would give you POSIX, with more demands on your kernel, and a different licensing / upstream situation. It's your choice. PDCLib is mostly for those people who don't want to support POSIX, or shun the available libraries for aesthetic reasons. 8)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], Majestic-12 [Bot] and 64 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group