Porting Newlib: Difference between revisions
Jump to navigation
Jump to search
[unchecked revision] | [unchecked revision] |
Content deleted Content added
m Syntax highlighting. FIXME: the asm one is borked -- does this extension support AT&T syntax? |
|||
Line 236: | Line 236: | ||
According to the documentation, you should also redefine errno as an 'extern char': |
According to the documentation, you should also redefine errno as an 'extern char': |
||
<source lang="C"> |
|||
<pre> |
|||
#include <errno.h> |
#include <errno.h> |
||
#undef errno |
#undef errno |
||
extern int errno; |
extern int errno; |
||
</ |
</source> |
||
Re-entrant versions of these are a bit harder and are outlined in the documentation. |
Re-entrant versions of these are a bit harder and are outlined in the documentation. |
||
Line 255: | Line 255: | ||
Once the source was downloaded, I loaded up Cygwin. All that needs to be done here is to build newlib: |
Once the source was downloaded, I loaded up Cygwin. All that needs to be done here is to build newlib: |
||
<source lang="bash"> |
|||
<pre> |
|||
cd /usr/src |
cd /usr/src |
||
mkdir build-newlib |
mkdir build-newlib |
||
Line 261: | Line 261: | ||
../newlib-''<version>''/configure --prefix=''<location to put libarary>'' --target=i586-elf |
../newlib-''<version>''/configure --prefix=''<location to put libarary>'' --target=i586-elf |
||
make all install |
make all install |
||
</ |
</source> |
||
Simple! However, if you try linking a previously written program with newlib you'll get undefined references everywhere. Why? You haven't yet put your 'glue' into the newlib yet. |
Simple! However, if you try linking a previously written program with newlib you'll get undefined references everywhere. Why? You haven't yet put your 'glue' into the newlib yet. |
||
Line 286: | Line 286: | ||
Finally you must write something called the CRT0, basically the startup code for the executable. My CRT0 is really simple (GAS syntax): |
Finally you must write something called the CRT0, basically the startup code for the executable. My CRT0 is really simple (GAS syntax): |
||
<source lang="asm"> |
|||
<pre> |
|||
.global _start |
.global _start |
||
.extern main |
.extern main |
||
Line 305: | Line 305: | ||
hlt |
hlt |
||
jmp lp |
jmp lp |
||
</ |
</source> |
||
All programs must link this as the '''first''' object ([[Linker_Scripts|linker script]] to the rescue). |
All programs must link this as the '''first''' object ([[Linker_Scripts|linker script]] to the rescue). |
||
Line 312: | Line 312: | ||
I suggest writing a simple test program, the following will suffice: |
I suggest writing a simple test program, the following will suffice: |
||
<source lang="C"> |
|||
<pre> |
|||
int main() |
int main() |
||
{ |
{ |
||
Line 318: | Line 318: | ||
return 0; |
return 0; |
||
} |
} |
||
</ |
</source> |
||
Put a little bit of code into your system call interface to print the function number that has been called and look for any possible calls. |
Put a little bit of code into your system call interface to print the function number that has been called and look for any possible calls. |