summaryrefslogtreecommitdiff
path: root/user/lib/syscall.S
blob: 46fcb89e52b079e2c1a012e7ab5e2a3edbf508b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
** @file	ulibs.S
**
** @author	CSCI-452 class of 20245
**
** @brief	assembly-language user-level library functions
*/

#define	ASM_SRC

// get the system call codes

#include <syscalls.h>

/**
** System call stubs
**
** All have the same structure:
**
**      move a code into EAX
**      generate the interrupt
**      return to the caller
**
** As these are simple "leaf" routines, we don't use
** the standard enter/leave method to set up a stack
** frame - that takes time, and we don't really need it.
**
** Could be modified to use the UNIX/Linux convention of
** having the syscall code set the 'C' flag to indicate that
** the value being returned in %EAX is an error code:
**
**	  ...
**	int	$VEC_SYSCALL
**	jc	set_errno
**	ret
**	  ...
**
**	.globl	errno
** set_errno:
**	movl	%eax, errno
**	movl	$-1, %eax
**	ret
*/

#define	SYSCALL(name) \
	.globl	name			; \
name:					; \
	movl	$SYS_##name, %eax	; \
	int	$VEC_SYSCALL	; \
	ret

/*
** "real" system calls
*/

SYSCALL(exit)
SYSCALL(waitpid)
SYSCALL(fork)
SYSCALL(exec)
SYSCALL(read)
SYSCALL(write)
SYSCALL(getpid)
SYSCALL(getppid)
SYSCALL(gettime)
SYSCALL(getprio)
SYSCALL(setprio)
SYSCALL(kill)
SYSCALL(sleep)

/*
** This is a bogus system call; it's here so that we can test
** our handling of out-of-range syscall codes in the syscall ISR.
*/
SYSCALL(bogus)

/*
** Other library functions
*/

/**
** fake_exit()
**
** Dummy "startup" function
**
** calls exit(%eax) - serves as the "return to" code for
** main() functions, in case they don't call exit() themselves
*/

	.globl	fake_exit
fake_exit:
	// alternate: could push a "fake exit" status
	pushl	%eax	// termination status returned by main()
	call	exit	// terminate this process