Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!watmath!watnot!ccplumb From: ccplumb@watnot.UUCP (Colin Plumb) Newsgroups: comp.lang.forth Subject: Unix system calls from Forth Message-ID: <12234@watnot.UUCP> Date: Fri, 28-Nov-86 15:22:35 EST Article-I.D.: watnot.12234 Posted: Fri Nov 28 15:22:35 1986 Date-Received: Fri, 28-Nov-86 21:51:26 EST Reply-To: ccplumb@watnot.UUCP (Colin Plumb) Distribution: net Organization: U of Waterloo, Ontario Lines: 47 Summary: How should the interface be implemented? I'm working on a 32-bit Forth for a VAX under BSD 4.2 Unix. I'm trying to figure out how to implement the system call interface. At the lowest level, the interface provided by the system looks like this: - Register 12 (r12, the argument pointer) is expected to be pointing to a stack frame containing the arguments taken by the system call. - The actual system call is implemented with the chmk (change mode to kernel) instruction, with the argument being the number of the call (given in ). - On return, if the carry flag is clear, then no error ocurred, and the return values are in r0 and r1 (as needed - some calls don't return values, most return one, in r0). - If the carry flag is set, then the error code is in r0. I'm trying to figure out a good way to implement this in Forth. In C, the library checks for an error, and returns -1 in that case, setting errno to the error number. If there are two return values (pipe(2) is an example), the usual solution is to require an array of 2 int's to be passed to the library routine (the actual pipe system call doesn't take arguments), which fills it in. I could either emulate the C interface, leaving the return value (even if meaningless, for calls that don't return values) on the stack, and use a VARIABLE ERRNO, or try for something Forthier. The idea I'm currently playing with is to leave a flag - -1 (true) for error, and 0 (false) for no error - on top of the stack, followed by either the error code, or the return values (if any). Would anyone like to comment on the above ideas, or suggest another? The first has the advantage that it's familiar to people with experience in C, and always leaves the same number of values on the stack, while the second is conceptually cleaner, and I don't think the two cases for the number of return values will matter too much - in most cases, one value is returned, making two stack values in all cases, and the test for error is generally immediately after the return, anyway. -Colin Plumb (ccplumb@watnot.UUCP) Zippy says: I was born in a Hostess Cupcake factory before the sexual revolution!