How to implement LibC

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
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

How to implement LibC

Post by AlfaOmega08 »

How does libc (for example) print a string?
It cannot access directly to 0xB8000. Because it's executed in user mode, and it would cause a page fault. Does libc use system calls?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Yes, libc normally uses the read() and write() system calls.

On a *NIX system, it uses write() on the file descriptor "stdout" (normally FD 1, iirc).
jgraef
Member
Member
Posts: 47
Joined: Wed Jan 16, 2008 7:37 am
Location: Wonsheim, Germany

Post by jgraef »

Hi,

The printf function writes to the stdout, what normally is redirected in the parent process' stdin. When the string you want to print reaches your init process you can pass it to a screen driver. I do this over a device file. The screen driver uses a special flag for malloc() to allocate 0xB8000. So the screen driver can put your string on screen.
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post by lukem95 »

It depends if you want your OS to conform to a standard (e.g. POSIX) or not.

i have a putch() system call, to make my life easier :) This detects what graphical mode your in (through a external volatile int) and then calls the required putch (VGA, console etc)
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

Well, I implemented IO channels, you can call read, write, open, close, or custom through syscalls. It then calls a handler function (in kernel mode) which does what is requested.
Channel 0 is kernel (reset, asm("hlt")), Channel 1 is Terminal (getchar, puts, clear, setXY).

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