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
//! ARM Cortex-M implementation of [`ISyscall`].
use crateArch;
use crateISyscall;
use ;
/// Extract and prepare system call for Rust handler.
/// r0 is used to store the service id, r1-r3 can contain call parameter.
///
/// The system call service id (`svc xy`) is not passed on, we have to
/// retrieve it from code memory. Thus we load the stack pointer from the
/// callee and read the link register. The link register is pointing to
/// instruction just after the system call, the system call service id is
/// placed two bytes before that.
///
/// The exception link register tells SVC which privilege mode the callee used
/// | EXC_RETURN (lr) | Privilege Mode | Stack |
/// |-----------------|--------------------|------ |
/// | 0xFFFFFFF1 | Handler Mode | MSP |
/// | 0xFFFFFFF9 | Thread Mode | MSP |
/// | 0xFFFFFFFD | Thread Mode | PSP |
/// | 0xFFFFFFE1 | Handler Mode (FPU) | MSP |
/// | 0xFFFFFFE9 | Thread Mode (FPU) | MSP |
/// | 0xFFFFFFED | Thread Mode (FPU) | PSP |
unsafe extern "C"