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