283
|
1 module syscall;
|
|
2
|
292
|
3 /*
|
|
4 This module handles all the system calls from user space.
|
|
5 */
|
|
6
|
300
|
7 /*
|
292
|
8 enum {
|
|
9 SendMsg = 1,
|
|
10 ReceiveMsg = 2,
|
|
11
|
|
12 } syscall_t;
|
300
|
13 */
|
|
14
|
|
15 type int syscall_t;
|
283
|
16
|
|
17 // System call handlers. System calls are made from user space.
|
300
|
18 function void handle_system_call(int callId, int a, int b, int c, int d)
|
292
|
19 {
|
|
20 // Main entry, check what to do here
|
|
21 switch(callId)
|
|
22 {
|
|
23 case SendMsg:
|
|
24 handle_send_msg();
|
|
25 proc = process.byId(a);
|
|
26 if (not proc)
|
|
27 {
|
|
28 panic();
|
|
29 }
|
283
|
30
|
292
|
31 proc.setMessage();
|
300
|
32 // scheduler.current.setState(Sleep);
|
292
|
33 break;
|
|
34 case ReceiveMsg:
|
|
35 break;
|
|
36 case Reboot:
|
|
37 arch.reboot();
|
|
38 break;
|
|
39 default:
|
|
40 return NO_SUCH_CALL;
|
|
41 }
|
|
42
|
|
43 return OK;
|
283
|
44 }
|
|
45
|
292
|
46 // Handle send message syscall
|
|
47 func void handle_send_msg()
|
|
48 {
|
|
49 p = process.byId(msg.to_id);
|
|
50 scheduler.attempt(p);
|
|
51 }
|
|
52
|
|
53 func handle_recv_msg()
|
|
54 {
|
|
55 // Block until we have a message
|
|
56 currentProc->setState(Sleep);
|
|
57 scheduler.executeNext();
|
|
58 }
|
|
59
|
|
60 func handle_reboot()
|
|
61 {
|
|
62 reboot();
|
|
63 }
|
|
64
|