annotate kernel/syscall.c3 @ 300:158068af716c

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