1 @node syscalls,machine,reentrancy,Top
2 @chapter NEC V70 system calls
4 The library needs a certain amount of system-specific support in order
5 to operate. These routines have to be written for each unique
6 target environment. For testing purposes,
7 a set of system calls specific to an NEC V70 Unix PC running AT&T Unix
8 System V R2 are included. These files are in the @file
{sys/sysvnecv70
}
11 All the calls have to be implemented in order to avoid link time
12 errors, but the implementation need not include all possible
13 functionality; in general, for any functionality that isn't
14 available, returning an error code is sufficient.
18 The V70 target may not have any character I/O devices.
19 In this case, the @code
{fstat
}, @code
{ioctl
}, @code
{isatty
},
20 @code
{lseek
}, @code
{read
} and @code
{write
} routines may all return @code
{-
1},
21 to signal failure (inspect @file
{cerror.s
} to see how to do this).
23 Sometimes it is correct to implement the functions in a very
24 simple and machine specific way. For instance, the target board may
27 In this case, the @code
{write
} system call can be ``hard-wired'' to
28 always print to the serial device, no matter what the supplied file
29 handle says. Similarly, the other I/O system calls can be written to
30 take advantage of a known configuration.
32 Note that the library starts up assuming that three files are already
33 open. File handles used are:
36 Is used for all input from @code
{stdin
}.
38 Is used for all output to @code
{stdout
}. This includes functions like
39 @code
{putc
} and @code
{printf
}.
41 Is used for all output to @code
{stderr
}. The library will use this
42 file to print error messages from the math functions. Output can
43 also be sent to @code
{stderr
} by @code
{fprintf(stderr,@dots
{})
}
45 @section Example @code
{write
} routine
46 On a board with a very simple I/O structure, this would be adequate:
51 char *duart_status = DUART_ADDR;
55 /* Dummy function to fool optimizer */
58 int write(fd, string, len)
65 for (i =
0; i < len; i++)
67 while
(*duart_status & DUART_BUSY)
69 *duart_port = string[i];
76 @section Memory allocation
78 The library allocates memory from the heap either for its own use, or when
79 you explicitly call @code{malloc}. It asks the system for
80 memory by calling the @code{sbrk} function.
82 On a Unix system, @code{sbrk} keeps track of the heap's extent by keeping a
83 pointer to the end of the @code{bss} section. Unix linkers
84 traditionaly mark the end of @code{bss} by creating a symbol
85 @code{_end}. When the library wants more memory, it calls
86 @code{sbrk} with the size of the request. @code{sbrk} must then
87 perform an operation specific to the target environment, and return a pointer
88 to the new area. For a simple application, the following fragment may
93 char *moving_end = &end;
100 return_address = moving_end;
101 moving_end += request;
102 return return_address;
107 @section Initialization and termination
109 The system dependent support routines are responsible for
110 initializing the library for use by an application, and cleaning up
111 when the application is complete.
113 This functionality is traditionally provided in @code{crt0} and
116 The @code{crt0} function usually contains the instructions first run
117 by the operating system when an application starts. The
118 @code{crt0} function can take advantage of this and prepare the way
121 Another task for @code{crt0} is to call the @code{main} function
122 provided by the application writer, and also to call @code{exit} if
123 the main function ever returns.
125 @code{exit} tells the operating system that the application has