How to use newlib

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.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

How to use newlib

Post by quanganht »

Err, maybe this is a stupid question, but I'm a "pre-beginner" :oops:
After porting building newlib what do have to do ? And how to integrate newlib to my OS ?
"Programmers are tools for converting caffeine into code."
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: How to use newlib

Post by AJ »

Have you already ported newlib? If you have, the question is "what do you want to do?". What is the aim of your OS?

From the second part of your question, I would assume the next thing would be to create a native build of GCC using your newly ported C library. I don't quite understand how a "pre-beginner" has already ported newlib, though?

Cheers,
Adam
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

Seems like I haven't rebuild the toolchain using the newlib yet
http://wiki.osdev.org/OS_Specific_Toolchain

Or, according to this page http://wiki.osdev.org/GCC_Cross-Compiler , I've done step 2 so far.

"pre-beginner" == beginner + stupid + lazy :?
"Programmers are tools for converting caffeine into code."
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

Ok, so now I'm working on my OS ( the first one). I'm going to use Newlib. And it says, for eaxample, printf needs
Supporting OS subroutines required: close, fstat, isatty, lseek, read, sbrk, write.
How do I implement these, and where should I put them?
"Programmers are tools for converting caffeine into code."
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: How to use newlib

Post by LoseThos »

How I started was by placing the text of files I wanted to compile inside my turbo asm's output kernel binary image. I then made an interpreter. For the command-line you need an interpreter and you probably want to parse batch-file scripts of some sort. The scripts I wanted done, i placed into the binary image before I had a file system.

For parser you make a lexical analyser which filters-out comments, gets the next tolken, a string, an indentifier, a number, etc. The parser must handle expressions. You can do a LR parse if you look it up, but it's not efficient. Anyway, you'll probably want to build an expression tree and a function to evaluate an expression.

Eventually, i converted from an interpreter to a compiler -- pretty easy. I made a file system. I have low level routines to read and write blocks, a routine to allocate a block (or cluster), routines to make a directory entry, delete a directory entry or find directory entries, read and write files by allocating clusters and storing data.

It's a lot of work. Are you doing it to have fun? You might want to use more stuff from other people, i don't know.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

LoseThos wrote:How I started was by placing the text of files I wanted to compile inside my turbo asm's output kernel binary image. I then made an interpreter. For the command-line you need an interpreter and you probably want to parse batch-file scripts of some sort. The scripts I wanted done, i placed into the binary image before I had a file system.

For parser you make a lexical analyser which filters-out comments, gets the next tolken, a string, an indentifier, a number, etc. The parser must handle expressions. You can do a LR parse if you look it up, but it's not efficient. Anyway, you'll probably want to build an expression tree and a function to evaluate an expression.

Eventually, i converted from an interpreter to a compiler -- pretty easy. I made a file system. I have low level routines to read and write blocks, a routine to allocate a block (or cluster), routines to make a directory entry, delete a directory entry or find directory entries, read and write files by allocating clusters and storing data.

It's a lot of work. Are you doing it to have fun? You might want to use more stuff from other people, i don't know.
What do you mean? "close, fstat, isatty, lseek, read, sbrk, write" is syscalls, not shell commands !
"Programmers are tools for converting caffeine into code."
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: How to use newlib

Post by LoseThos »

Why bother doing an operating system if you start with a standard library? Explain what your goals are. I use nothing standard and use not a single line of code from elsewhere.

Suppose you speak spanish, make the key words spanish and non ASCII.

I laugh at all the people who are not patient and use other people's code. It give the appearance of getting stuff done fast, but in the end, you've accomplished nothing but plugged together a few modules. If you're playing around, set less ambitious goals.

Be patient and do it from scratch.
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

LoseThos wrote:Why bother doing an operating system if you start with a standard library? Explain what your goals are. I use nothing standard and use not a single line of code from elsewhere.
Because you don't use standard code from others so you may not know. :roll: I use Newlib because I don't want to have myself implementing all the libc - an must have part in any OS. And as I port it to suit my OS, I need to work around with my own syscalls ( it is supposed to be OS-dependent). Using standard lib will help me extend my OS easier later (as I can run lots of linux or posix compatible apps).

If you want, you can roll your own code. Maybe I'm lazy ( I said before :lol: ). And does it really necessary for me to do everything if there are standard code ? Lots of people don't thing so.
"Programmers are tools for converting caffeine into code."
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: How to use newlib

Post by JamesM »

Hi,
LoseThos wrote:How I started was by placing the text of files I wanted to compile inside my turbo asm's output kernel binary image. I then made an interpreter. For the command-line you need an interpreter and you probably want to parse batch-file scripts of some sort. The scripts I wanted done, i placed into the binary image before I had a file system.

For parser you make a lexical analyser which filters-out comments, gets the next tolken, a string, an indentifier, a number, etc. The parser must handle expressions. You can do a LR parse if you look it up, but it's not efficient. Anyway, you'll probably want to build an expression tree and a function to evaluate an expression.

Eventually, i converted from an interpreter to a compiler -- pretty easy. I made a file system. I have low level routines to read and write blocks, a routine to allocate a block (or cluster), routines to make a directory entry, delete a directory entry or find directory entries, read and write files by allocating clusters and storing data.

It's a lot of work. Are you doing it to have fun? You might want to use more stuff from other people, i don't know.
The rule of thumb on these forums is to answer the question given, not one you make up so that you can give a commentary as to how you implemented something.

The OP asked a question. He expects an answer, not a paragraph on how you made a LR(1) parser.
LoseThos wrote:Why bother doing an operating system if you start with a standard library?
Some people prefer to implement parts at a time, and use pluggable components written by others that definitely work until they know the code that they wrote themselves works. It's a type of unit-design methodology.

Others prefer not to write every component of their hobby OS project, and just write the stuff they are interested in, which may or may not include the grime of writing a C library (see Solar's PDCLib for how long a properly implemented and tested portable C library takes to implement).

Either way it is irrelevant to the OP's question.
Explain what your goals are.
I believe he explained his goal - to use newlib as the C library in his OS.
I use nothing standard and use not a single line of code from elsewhere.
That's very clever of you. I'm sure many people will pat you on the back for reinventing the wheel. I'm not one of them.
Suppose you speak spanish, make the key words spanish and non ASCII.
On what evidence do you base this supposition?
I laugh at all the people who are not patient and use other people's code. It give the appearance of getting stuff done fast, but in the end, you've accomplished nothing but plugged together a few modules. If you're playing around, set less ambitious goals. Be patient and do it from scratch.
I laugh at people who feel the only way to accomplish anything is to write every line of code yourself. Actually, that's a lie. I don't laugh at anyone because of their design methodologies and personal inclinations. You seem to, however.

Realistically using others' code in certain places in your own solution can be a good thing. It helps you learn to interface with prewritten code, and to read and understand specifications and documentation, which are essential life skills in the world of software engineering.

@quanganht:

Those functions are POSIX-standard. Look them up in the POSIX specification to see how they should behave and what their proper signature is.

Normally you implement these functions yourself and "glue" them into newlib, using one of several methods. See Porting Newlib for full documentation.

Cheers,

James
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

JamesM wrote: Those functions are POSIX-standard. Look them up in the POSIX specification to see how they should behave and what their proper signature is.

Normally you implement these functions yourself and "glue" them into newlib, using one of several methods. See Porting Newlib for full documentation.

Cheers,

James
Well, thanks very much. I've seen wiki page, but I thought the syscalls in there were " Minimal implementation" ??? :oops:
Thanks again.
LoseThos wrote:Suppose you speak spanish, make the key words spanish and non ASCII.
Actually, I speak Vietnamese :)
LoseThos wrote:I use nothing standard and use not a single line of code from elsewhere.
Another thing that you might not know yet, I'm just 16 years old, so I'm not clever enough to go all by myself :)
"Programmers are tools for converting caffeine into code."
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: How to use newlib

Post by JamesM »

Hi,
quanganht wrote:
JamesM wrote: Those functions are POSIX-standard. Look them up in the POSIX specification to see how they should behave and what their proper signature is.

Normally you implement these functions yourself and "glue" them into newlib, using one of several methods. See Porting Newlib for full documentation.

Cheers,

James
Well, thanks very much. I've seen wiki page, but I thought the syscalls in there were " Minimal implementation" ??? :oops:
Thanks again.
They are minimally implemented. You need to add your own code to make the function operate in the way described in the POSIX specification which I linked to (I actually linked to the documentation for the open() function). The wiki page however will tell you how to get that code "glued" into newlib.

Cheers,

James
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: How to use newlib

Post by quanganht »

Oh I see now :D
Agian, thanks.
"Programmers are tools for converting caffeine into code."
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: How to use newlib

Post by LoseThos »

It's easier to make a standard than implement one. If you use GCC, you will be locking yourself into an object file format and a language syntax. You have to do a parser for the command line anyway, just make your own languages. I'm sure the elf object file is crusty. I've seen formats like that. You will be starting a 64-bit OS encumbered with cruft.

Edit: OT content removed - AJ
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: How to use newlib

Post by JamesM »

LoseThos wrote:It's easier to make a standard than implement one. If you use GCC, you will be locking yourself into an object file format and a language syntax. You have to do a parser for the command line anyway, just make your own languages. I'm sure the elf object file is crusty. I've seen formats like that. You will be starting a 64-bit OS encumbered with cruft.
Reinventing something because you're too lazy or arrogant about your own programming prowess to investigate currently existing solutions is a retarded idea. End of story.
LoseThos
Member
Member
Posts: 112
Joined: Tue Oct 30, 2007 6:41 pm
Location: Las Vegas, NV USA
Contact:

Re: How to use newlib

Post by LoseThos »

I take it you're making a linux clone?
Post Reply