PDCLib

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
Knyght
Posts: 7
Joined: Mon Oct 15, 2012 8:52 pm
Location: UK

PDCLib

Post by Knyght »

I'm quite new to this. After some pondering about whether I want a vga console driver in my microkernel I decided that I probably do want it so that I can spam error messages if things go wrong before the other stuff gets to load. Anyway, after reading up on VGA, which seems simple enough, I figure I'm probably going to start needing stuff like memcpy and friends. So I figure the easiest and probably best way is to just use PDCLib and use the functions from there rather than reinventing the wheel.

But I have no idea how to do this. From what I gather from the rather scarce documentation, I need to implement (or at least dummy-implement) some system calls and set some constants by messing with the example platform files and then overwriting them back over the main directory, which seems simple enough. After that, I'm not sure what to do so that I can access this stuff from my kernel. Some insight (or a hand-holding guide at this point) would be appreciated.

Thanks.
User avatar
Griwes
Member
Member
Posts: 374
Joined: Sat Jul 30, 2011 10:07 am
Libera.chat IRC: Griwes
Location: Wrocław/Racibórz, Poland
Contact:

Re: PDCLib

Post by Griwes »

Stuff like memcpy and friends is dead simple, if you cannot write then reasonably quickly, you should probably consider another hobby. Also, OSDev is entirely about reinventing the wheel; why don't you want to do it with dead simple functions?

Also, don't expect hand holding and detailed step by step guides above "how to boot my kernel" level here.
Reaver Project :: Repository :: Ohloh project page
<klange> This is a horror story about what happens when you need a hammer and all you have is the skulls of the damned.
<drake1> as long as the lock is read and modified by atomic operations
Knyght
Posts: 7
Joined: Mon Oct 15, 2012 8:52 pm
Location: UK

Re: PDCLib

Post by Knyght »

I could write that stuff very quickly and easily yes, but I figure that since they're in the standard library, why bother to write it only to replace it? Personally I think that having the C library around from the start just stops me repeating myself and having to incrementally add more functions that I would just replace later when I did switch to PDCLib.

And yes, I realise the whole thing is about re-inventing the wheel, but rewriting the standard library (or even a subset) isn't my idea of fun, really and I'd rather be spending my time on the stuff that I consider to be fun.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: PDCLib

Post by JamesM »

Knyght wrote:I could write that stuff very quickly and easily yes, but I figure that since they're in the standard library, why bother to write it only to replace it? Personally I think that having the C library around from the start just stops me repeating myself and having to incrementally add more functions that I would just replace later when I did switch to PDCLib.

And yes, I realise the whole thing is about re-inventing the wheel, but rewriting the standard library (or even a subset) isn't my idea of fun, really and I'd rather be spending my time on the stuff that I consider to be fun.
Only a very very very small subset of the C library will actually run baremetal. Most of it requires some underlying support such as malloc/sbrk/mmap at the least.

It's not worth the pain, IMHO. Just implement memcpy,memset,strlen,strncpy and printf yourself. That's all you need.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: PDCLib

Post by Owen »

Now that I've taken up the reins, PDCLib's build system no longer copies any files around; it builds them straight from the source directory.

It provides it's own malloc (actually dlmalloc, found in opt/dlmalloc), which requires you to provide a memory allocation function. You can stub that out for now: stdio works without it.

It also needs the C11 mutex functions. You can find stub (single thread emulation) implementations of those in opt/nothread

Your best bet is to copy the example (stub) implementation and work from there, using the win32 implementation as a guide (it is the most complete)

IO goes through the _PDCLIB_fillbuffer/_PDCLIB_flushbuffer methods. IMO, these aren't well enough factored (i.e. they require too much messing with the internals of the IO system), so I will be cleaning those up soon. It's on my todo list, or rather, in the bug tracker

Porting PDCLib will likely be significantly easier and quicker than implementing a full printf on your own. Before I'd even started working on the project and gotten used to the codebase, it took me ~30mins to port it to run in my kernel. It is far easier to port than newlib, for example (which requires malloc before stdio can work).
Knyght
Posts: 7
Joined: Mon Oct 15, 2012 8:52 pm
Location: UK

Re: PDCLib

Post by Knyght »

I have decided that my kernel will simple enough that I don't even need that much stuff. So yes you guys were right.

Owen, is there any chance you (or anyone really) could throw together a tutorial on porting PDCLib for a pretty barebones minimal kernel? It'd be useful not only for me if I do decide to do this, but for many others I expect.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: PDCLib

Post by Kevin »

There's a Readme.txt. Read it. It's really not hard.

The one thing that I found less than optimal in the past was upgrading PDCLib. It's really nasty if you have to check and forward port all of your platform specific code. That's why I tend to keep sitting on old PDCLib versions...
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: PDCLib

Post by Owen »

Knyght wrote:I have decided that my kernel will simple enough that I don't even need that much stuff. So yes you guys were right.

Owen, is there any chance you (or anyone really) could throw together a tutorial on porting PDCLib for a pretty barebones minimal kernel? It'd be useful not only for me if I do decide to do this, but for many others I expect.
More comprehensive documentation is on my todo list.
Kevin wrote:The one thing that I found less than optimal in the past was upgrading PDCLib. It's really nasty if you have to check and forward port all of your platform specific code. That's why I tend to keep sitting on old PDCLib versions...
This is one of the reasons I want to churn the I/O APIs now, rather than later. Where feasible, I want the PDCLib <-> Platform to "smell like" POSIX in broad strokes; and looking at POSIX provides a system which has well understood flaws.

Obviously if you restructure PDCLib you'll have more trouble moving to newer versions. I have PDCLib as a mercurial sub repository and just have the build system enter PDCLib as a normal sub directory. Actually, the tricky part is going to be enabling it to be built multiple times (potentially three: bootloader, kernel, userspace)
Post Reply