-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyscalls.c~
executable file
·71 lines (58 loc) · 1.78 KB
/
syscalls.c~
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
// syscalls.c
// calls to kernel services
#include "kernel_constants.h" // SYS_WRITE 4, SYS_GETPID 20, etc.
#include "syscalls.h"
int sys_getpid(void) {
int pid;
asm("movl %1, %%eax; // service #20 (SYS_GETPID)
int $128; // interrupt CPU with IDT entry 128
movl %%ebx, %0" //####newline
: "=g"(pid) // output syntax
: "g"(SYS_GETPID) // input syntax
: "eax", "ebx" // used registers
);
return pid;
}
void sys_write(int fileno, char *str, int len) {
asm(
"movl %0, %%eax; // send service #4 (SYS_WRITE) via eax
movl %1, %%ebx; // send in fileno via ebx (e.g., STDOUT)
movl %2, %%ecx; // send in str addr via ecx
movl %3, %%edx; // send in str len via edx
int $128" // initiate service call, intr 128 (IDT entry 128)
: // no output
: "g"(SYS_WRITE), "g"(fileno), "g"(str), "g"(len)
: "eax", "ebx", "ecx", "edx"
);
}
void sys_sleep(int centi_sec) { // 1 centi-second is 1/100 of a second
asm(
"movl %0, %%eax; // service #162 (SYS_SLEEP)
movl %1, %%ebx; // send in centi-seconds via ebx
int $128"
://NOT SURE IF I NEED TO ADD THIS...NOT IN Prof's CodingHinits.txt
: "g"(SYS_SLEEP), "g"(centi_sec)
// :"g" (centi_sec) //###newline
: "eax", "ebx"
);
}
/*
void sys_semwait(int sem_num){
asm("movl %0, %%eax;7
movl %1, %%ebx;
int $128"
:
:"g"(SYS_SEMWAIT), "g"(sem_num)
:"eax", "ebx"
);
}
void sys_sempost(int sem_num){
asm("movl %0, %%eax;
movl %1, %%ebx;
int $128"
:
:"g"(SYS_SEMPOST), "g"(sem_num)
:"eax", "ebx"
);
}
*/