OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [libc/] [sys/] [sysvnecv70/] [sysvnecv70.tex] - Diff between revs 148 and 158

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 148 Rev 158
@node syscalls,machine,reentrancy,Top
@node syscalls,machine,reentrancy,Top
@chapter NEC V70 system calls
@chapter NEC V70 system calls
 
 
The library needs a certain amount of system-specific support in order
The library needs a certain amount of system-specific support in order
to operate.  These routines have to be written for each unique
to operate.  These routines have to be written for each unique
target environment.  For testing purposes,
target environment.  For testing purposes,
a set of system calls specific to an NEC V70 Unix PC running AT&T Unix
a set of system calls specific to an NEC V70 Unix PC running AT&T Unix
System V R2 are included.  These files are in the @file{sys/sysvnecv70}
System V R2 are included.  These files are in the @file{sys/sysvnecv70}
directory.
directory.
 
 
All the calls have to be implemented in order to avoid link time
All the calls have to be implemented in order to avoid link time
errors, but the implementation need not include all possible
errors, but the implementation need not include all possible
functionality; in general, for any functionality that isn't
functionality; in general, for any functionality that isn't
available, returning an error code is sufficient.
available, returning an error code is sufficient.
 
 
@section Input/Output
@section Input/Output
 
 
The V70 target may not have any character I/O devices.
The V70 target may not have any character I/O devices.
In this case, the @code{fstat}, @code{ioctl}, @code{isatty},
In this case, the @code{fstat}, @code{ioctl}, @code{isatty},
@code{lseek}, @code{read} and @code{write} routines may all return @code{-1},
@code{lseek}, @code{read} and @code{write} routines may all return @code{-1},
to signal failure (inspect @file{cerror.s} to see how to do this).
to signal failure (inspect @file{cerror.s} to see how to do this).
 
 
Sometimes it is correct to implement the functions in a very
Sometimes it is correct to implement the functions in a very
simple and machine specific way.  For instance, the target board may
simple and machine specific way.  For instance, the target board may
have one serial line.
have one serial line.
 
 
In this case, the @code{write} system call can be ``hard-wired'' to
In this case, the @code{write} system call can be ``hard-wired'' to
always print to the serial device, no matter what the supplied file
always print to the serial device, no matter what the supplied file
handle says. Similarly, the other I/O system calls can be written to
handle says. Similarly, the other I/O system calls can be written to
take advantage of a known configuration.
take advantage of a known configuration.
 
 
Note that the library starts up assuming that three files are already
Note that the library starts up assuming that three files are already
open.  File handles used are:
open.  File handles used are:
@table @code
@table @code
@item 0
@item 0
Is used for all input from @code{stdin}.
Is used for all input from @code{stdin}.
@item 1
@item 1
Is used for all output to @code{stdout}.  This includes functions like
Is used for all output to @code{stdout}.  This includes functions like
@code{putc} and @code{printf}.
@code{putc} and @code{printf}.
@item 2
@item 2
Is used for all output to @code{stderr}.  The library will use this
Is used for all output to @code{stderr}.  The library will use this
file to print error messages from the math functions.  Output can
file to print error messages from the math functions.  Output can
also be sent to @code{stderr} by @code{fprintf(stderr,@dots{})}
also be sent to @code{stderr} by @code{fprintf(stderr,@dots{})}
@end table
@end table
@section Example @code{write} routine
@section Example @code{write} routine
On a board with a very simple I/O structure, this would be adequate:
On a board with a very simple I/O structure, this would be adequate:
 
 
@example
@example
 
 
@group
@group
char *duart_status = DUART_ADDR;
char *duart_status = DUART_ADDR;
 
 
void poll()
void poll()
@{
@{
   /* Dummy function to fool optimizer */
   /* Dummy function to fool optimizer */
@}
@}
 
 
int write(fd, string, len)
int write(fd, string, len)
int fd;
int fd;
char *string;
char *string;
int len;
int len;
@{
@{
  int i;
  int i;
 
 
  for (i = 0; i < len; i++)
  for (i = 0; i < len; i++)
  @{
  @{
    while (*duart_status & DUART_BUSY)
    while (*duart_status & DUART_BUSY)
     poll();
     poll();
    *duart_port = string[i];
    *duart_port = string[i];
  @}
  @}
  return len;
  return len;
@}
@}
@end group
@end group
@end example
@end example
 
 
@section Memory allocation
@section Memory allocation
 
 
The library allocates memory from the heap either for its own use, or when
The library allocates memory from the heap either for its own use, or when
you explicitly call @code{malloc}.  It asks the system for
you explicitly call @code{malloc}.  It asks the system for
memory by calling the @code{sbrk} function.
memory by calling the @code{sbrk} function.
 
 
On a Unix system, @code{sbrk} keeps track of the heap's extent by keeping a
On a Unix system, @code{sbrk} keeps track of the heap's extent by keeping a
pointer to the end of the @code{bss} section.  Unix linkers
pointer to the end of the @code{bss} section.  Unix linkers
traditionaly mark the end of @code{bss} by creating a symbol
traditionaly mark the end of @code{bss} by creating a symbol
@code{_end}.  When the library wants more memory, it calls
@code{_end}.  When the library wants more memory, it calls
@code{sbrk} with the size of the request.  @code{sbrk} must then
@code{sbrk} with the size of the request.  @code{sbrk} must then
perform an operation specific to the target environment, and return a pointer
perform an operation specific to the target environment, and return a pointer
to the new area.  For a simple application, the following fragment may
to the new area.  For a simple application, the following fragment may
be sufficient:
be sufficient:
@example
@example
 
 
@group
@group
char *moving_end = &end;
char *moving_end = &end;
 
 
char *sbrk(request)
char *sbrk(request)
int request;
int request;
@{
@{
  char *return_address;
  char *return_address;
 
 
  return_address = moving_end;
  return_address = moving_end;
  moving_end += request;
  moving_end += request;
  return return_address;
  return return_address;
@}
@}
@end group
@end group
@end example
@end example
 
 
@section Initialization and termination
@section Initialization and termination
 
 
The system dependent support routines are responsible for
The system dependent support routines are responsible for
initializing the library for use by an application, and cleaning up
initializing the library for use by an application, and cleaning up
when the application is complete.
when the application is complete.
 
 
This functionality is traditionally provided in @code{crt0} and
This functionality is traditionally provided in @code{crt0} and
@code{_exit}.
@code{_exit}.
 
 
The @code{crt0} function usually contains the instructions first run
The @code{crt0} function usually contains the instructions first run
by the operating system when an application starts.  The
by the operating system when an application starts.  The
@code{crt0} function can take advantage of this and prepare the way
@code{crt0} function can take advantage of this and prepare the way
for the libary.
for the libary.
 
 
Another task for @code{crt0} is to call the @code{main} function
Another task for @code{crt0} is to call the @code{main} function
provided by the application writer, and also to call @code{exit} if
provided by the application writer, and also to call @code{exit} if
the main function ever returns.
the main function ever returns.
 
 
@code{exit} tells the operating system that the application has
@code{exit} tells the operating system that the application has
finished.
finished.
 
 
 
 
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.