-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathucode.c
332 lines (256 loc) · 3.93 KB
/
ucode.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "type.h"
int pid;
char line[64], pathname[32], i2[32], i3[32];
char *name[16], components[64];
int nk;
#define EOF -1
int getpid()
{
return syscall(0,0,0);
}
int getppid()
{
return syscall(1,0,0);
}
int getpri()
{
return syscall(2,0,0);
}
int chpri(int value)
{
return syscall(3,value,0);
}
int getuid()
{
return syscall(4,0,0);
}
int chuid(int uid, int gid)
{
return syscall(5,uid, gid);
}
int tswitch()
{
return syscall(6,0,0);
}
int fork()
{
return syscall(10, 0, 0);
}
int exec(char *cmd_line)
{
return syscall(11, cmd_line, 0);
}
int wait(int *status)
{
return syscall(12, status, 0);
}
int vfork()
{
return syscall(13,0,0);
}
int thread(int fn, int stack, int flag, int ptr)
{
return syscall(14, fn, stack, flag, ptr);
}
// 15-19: mutex for threads
int mutex_creat()
{
return syscall(15, 0,0);
}
int mutex_lock(int *m)
{
return syscall(16, m, 0);
}
int mutex_unlock(int *m)
{
return syscall(17, m, 0);
}
int mutex_destroy(int *m)
{
return syscall(18, m, 0);
}
int mkdir(char *name)
{
return syscall(20, name, 0);
}
int rmdir(char *name)
{
return syscall(21, name, 0);
}
int creat(char *filename)
{
return syscall(22, filename, 30);
}
int link(char *oldfile, char *newfile)
{
return syscall(23, oldfile, newfile,0);
}
int unlink(char *file)
{
return syscall(24, file, 0);
}
int symlink(char *oldfile, char *newfile)
{
return syscall(25, oldfile, newfile);
}
int readlink(char *file, char *linkname)
{
return syscall(26, file, linkname, 0);
}
int chdir(char *name)
{
return syscall(27, name, 0);
}
int getcwd(char *cwdname)
{
return syscall(28, cwdname, 0);
}
int stat(char *filename, struct stat *sPtr)
{
return syscall(29, filename, sPtr);
}
int fstat(int fd, struct stat *sptr)
{
return syscall(30,fd,sptr,0);
}
int open(char *file, int flag)
{
return syscall(31, file, flag);
}
int close(int fd)
{
return syscall(32, fd);
}
u32 lseek(int fd, u32 offset, int ww)
{
return syscall(33, fd, (u32)offset, ww);
}
int read(int fd, char *buf, int nbytes)
{
return syscall(34, fd, buf, nbytes);
}
int write(int fd, char *buf, int nbytes)
{
return syscall(35, fd, buf, nbytes);
}
int pipe(int *pd)
{
return syscall(36, pd, 0);
}
int chmod(char *file, u16 mode)
{
return syscall(37, file, mode);
}
int chown(char *file, int uid)
{
return syscall(38, file, uid);
}
int touch(char *filename)
{
return syscall(39, filename, 0);
}
int fixtty(char *tty)
{
return syscall(40, tty, 0);
}
int settty(char *tty)
{
return syscall(40, tty, 0);
}
int gettty(char *tty)
{
return syscall(41, tty, 0);
}
int dup(int fd)
{
return syscall(42, fd, 0);
}
int dup2(int fd, int gd)
{
return syscall(43, fd, gd);
}
int ps(char *y)
{
return syscall(44,y,0);
}
int mount(char *dev, char **mpt)
{
return syscall(45, dev, mpt);
}
int umount(char *dev)
{
return syscall(46, dev);
}
/********** CDROM syscalls ******************/
int getSector(u32 sector, char *ubuf, u16 nsector)
{
return syscall(47, (u32)sector, ubuf, nsector);
}
int do_cmd(u16 cmd, u16 value)
{
return syscall(48, cmd, value);
}
int kill(int sig, int pid)
{
return syscall(50, sig, pid);
}
int signal(u16 sig, u16 catcher)
{
return syscall(51, sig, catcher);
}
int pause(u16 t)
{
return syscall(52, t);
}
int itimer(u16 t)
{
return syscall(53, t);
}
int send(char *msg, int pid)
{
syscall(54, msg, pid);
}
int recv(char *msg)
{
syscall(55,msg, 0);
}
int do_texit()
{
int pid = getpid();
printf("thread %d texit()\n", pid);
texit(pid);
}
int tjoin(int n)
{
return syscall(56, n, 0);
}
int texit(int v)
{
syscall(57,v,0);
}
int khits(int *requests, int *hits)
{
syscall(58,requests,hits);
}
int setcolor(int color)
{
return syscall(59, color,0);
}
int sync()
{
return syscall(60, 0, 0);
}
int thinit()
{
return syscall(61, 0, 0);
}
int exit(int value)
{
syscall(9, value, 0);
}
int pwd()
{
char cwd[64];
getcwd(cwd);
printf("%s\n", cwd);
}