annotate kernel/syscall.c3 @ 292:534b94b40aa8

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