📄 sysvnecv70.tex
字号:
@node syscalls,machine,reentrancy,Top@chapter NEC V70 system callsThe library needs a certain amount of system-specific support in orderto operate. These routines have to be written for each uniquetarget environment. For testing purposes,a set of system calls specific to an NEC V70 Unix PC running AT&T UnixSystem V R2 are included. These files are in the @file{sys/sysvnecv70}directory.All the calls have to be implemented in order to avoid link timeerrors, but the implementation need not include all possiblefunctionality; in general, for any functionality that isn'tavailable, returning an error code is sufficient.@section Input/OutputThe V70 target may not have any character I/O devices.In this case, the @code{fstat}, @code{ioctl}, @code{isatty},@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).Sometimes it is correct to implement the functions in a verysimple and machine specific way. For instance, the target board mayhave one serial line.In this case, the @code{write} system call can be ``hard-wired'' toalways print to the serial device, no matter what the supplied filehandle says. Similarly, the other I/O system calls can be written totake advantage of a known configuration.Note that the library starts up assuming that three files are alreadyopen. File handles used are:@table @code@item 0Is used for all input from @code{stdin}.@item 1Is used for all output to @code{stdout}. This includes functions like@code{putc} and @code{printf}.@item 2Is used for all output to @code{stderr}. The library will use thisfile to print error messages from the math functions. Output canalso be sent to @code{stderr} by @code{fprintf(stderr,@dots{})}@end table@section Example @code{write} routineOn a board with a very simple I/O structure, this would be adequate:@example@groupchar *duart_status = DUART_ADDR;void poll()@{ /* Dummy function to fool optimizer */@} int write(fd, string, len)int fd;char *string;int len; @{ int i; for (i = 0; i < len; i++) @{ while (*duart_status & DUART_BUSY) poll(); *duart_port = string[i]; @} return len;@}@end group @end example@section Memory allocationThe library allocates memory from the heap either for its own use, or whenyou explicitly call @code{malloc}. It asks the system formemory by calling the @code{sbrk} function. On a Unix system, @code{sbrk} keeps track of the heap's extent by keeping apointer to the end of the @code{bss} section. Unix linkerstraditionaly mark the end of @code{bss} by creating a symbol@code{_end}. When the library wants more memory, it calls@code{sbrk} with the size of the request. @code{sbrk} must thenperform an operation specific to the target environment, and return a pointerto the new area. For a simple application, the following fragment maybe sufficient:@example@groupchar *moving_end = &end;char *sbrk(request)int request;@{ char *return_address; return_address = moving_end; moving_end += request; return return_address;@}@end group@end example@section Initialization and terminationThe system dependent support routines are responsible forinitializing the library for use by an application, and cleaning upwhen the application is complete.This functionality is traditionally provided in @code{crt0} and@code{_exit}. The @code{crt0} function usually contains the instructions first runby the operating system when an application starts. The@code{crt0} function can take advantage of this and prepare the wayfor the libary.Another task for @code{crt0} is to call the @code{main} functionprovided by the application writer, and also to call @code{exit} ifthe main function ever returns.@code{exit} tells the operating system that the application hasfinished.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -