|
1 | 1 | use core::arch::asm; |
2 | | -use libtock_platform::{syscall_class, RawSyscalls, Register}; |
| 2 | +use libtock_platform::{RawSyscalls, Register}; |
3 | 3 |
|
4 | 4 | unsafe impl RawSyscalls for crate::TockSyscalls { |
5 | 5 | unsafe fn yield1([Register(r0)]: [Register; 1]) { |
@@ -43,92 +43,56 @@ unsafe impl RawSyscalls for crate::TockSyscalls { |
43 | 43 | } |
44 | 44 | } |
45 | 45 |
|
46 | | - unsafe fn syscall1<const CLASS: usize>([Register(mut r0)]: [Register; 1]) -> [Register; 2] { |
| 46 | + unsafe fn syscall1<const SYSCALL_CLASS_NUMBER: usize>( |
| 47 | + [Register(mut r0)]: [Register; 1], |
| 48 | + ) -> [Register; 2] { |
47 | 49 | let r1; |
48 | 50 | // Safety: This matches the invariants required by the documentation on |
49 | 51 | // RawSyscalls::syscall1 |
50 | 52 | unsafe { |
51 | | - // Syscall class 5 is Memop, the only syscall class that syscall1 |
52 | | - // supports. |
53 | | - asm!("svc 5", |
54 | | - inlateout("r0") r0, |
55 | | - lateout("r1") r1, |
56 | | - options(preserves_flags, nostack, nomem), |
| 53 | + asm!( |
| 54 | + "svc {SYSCALL_CLASS_NUMBER}", |
| 55 | + inlateout("r0") r0, |
| 56 | + lateout("r1") r1, |
| 57 | + options(preserves_flags, nostack, nomem), |
| 58 | + SYSCALL_CLASS_NUMBER = const SYSCALL_CLASS_NUMBER, |
57 | 59 | ); |
58 | 60 | } |
59 | 61 | [Register(r0), Register(r1)] |
60 | 62 | } |
61 | 63 |
|
62 | | - unsafe fn syscall2<const CLASS: usize>( |
| 64 | + unsafe fn syscall2<const SYSCALL_CLASS_NUMBER: usize>( |
63 | 65 | [Register(mut r0), Register(mut r1)]: [Register; 2], |
64 | 66 | ) -> [Register; 2] { |
65 | 67 | // Safety: This matches the invariants required by the documentation on |
66 | 68 | // RawSyscalls::syscall2 |
67 | 69 | unsafe { |
68 | | - // TODO: Replace this match statement with a `const` operand when |
69 | | - // asm_const [1] is stabilized, or redesign RawSyscalls to not need |
70 | | - // this match statement. |
71 | | - // |
72 | | - // [1] https://github.com/rust-lang/rust/issues/93332 |
73 | | - match CLASS { |
74 | | - syscall_class::MEMOP => asm!("svc 5", |
75 | | - inlateout("r0") r0, |
76 | | - inlateout("r1") r1, |
77 | | - options(preserves_flags, nostack, nomem) |
78 | | - ), |
79 | | - syscall_class::EXIT => asm!("svc 6", |
80 | | - inlateout("r0") r0, |
81 | | - inlateout("r1") r1, |
82 | | - options(preserves_flags, nostack, nomem) |
83 | | - ), |
84 | | - _ => unreachable!(), |
85 | | - } |
| 70 | + asm!( |
| 71 | + "svc {SYSCALL_CLASS_NUMBER}", |
| 72 | + inlateout("r0") r0, |
| 73 | + inlateout("r1") r1, |
| 74 | + options(preserves_flags, nostack, nomem), |
| 75 | + SYSCALL_CLASS_NUMBER = const SYSCALL_CLASS_NUMBER, |
| 76 | + ); |
86 | 77 | } |
87 | 78 | [Register(r0), Register(r1)] |
88 | 79 | } |
89 | 80 |
|
90 | | - unsafe fn syscall4<const CLASS: usize>( |
| 81 | + unsafe fn syscall4<const SYSCALL_CLASS_NUMBER: usize>( |
91 | 82 | [Register(mut r0), Register(mut r1), Register(mut r2), Register(mut r3)]: [Register; 4], |
92 | 83 | ) -> [Register; 4] { |
93 | 84 | // Safety: This matches the invariants required by the documentation on |
94 | 85 | // RawSyscalls::syscall4 |
95 | 86 | unsafe { |
96 | | - // TODO: Replace this match statement with a `const` operand when |
97 | | - // asm_const [1] is stabilized, or redesign RawSyscalls to not need |
98 | | - // this match statement. |
99 | | - // |
100 | | - // [1] https://github.com/rust-lang/rust/issues/93332 |
101 | | - match CLASS { |
102 | | - syscall_class::SUBSCRIBE => asm!("svc 1", |
103 | | - inlateout("r0") r0, |
104 | | - inlateout("r1") r1, |
105 | | - inlateout("r2") r2, |
106 | | - inlateout("r3") r3, |
107 | | - options(preserves_flags, nostack), |
108 | | - ), |
109 | | - syscall_class::COMMAND => asm!("svc 2", |
110 | | - inlateout("r0") r0, |
111 | | - inlateout("r1") r1, |
112 | | - inlateout("r2") r2, |
113 | | - inlateout("r3") r3, |
114 | | - options(preserves_flags, nostack), |
115 | | - ), |
116 | | - syscall_class::ALLOW_RW => asm!("svc 3", |
117 | | - inlateout("r0") r0, |
118 | | - inlateout("r1") r1, |
119 | | - inlateout("r2") r2, |
120 | | - inlateout("r3") r3, |
121 | | - options(preserves_flags, nostack), |
122 | | - ), |
123 | | - syscall_class::ALLOW_RO => asm!("svc 4", |
124 | | - inlateout("r0") r0, |
125 | | - inlateout("r1") r1, |
126 | | - inlateout("r2") r2, |
127 | | - inlateout("r3") r3, |
128 | | - options(preserves_flags, nostack), |
129 | | - ), |
130 | | - _ => unreachable!(), |
131 | | - } |
| 87 | + asm!( |
| 88 | + "svc {SYSCALL_CLASS_NUMBER}", |
| 89 | + inlateout("r0") r0, |
| 90 | + inlateout("r1") r1, |
| 91 | + inlateout("r2") r2, |
| 92 | + inlateout("r3") r3, |
| 93 | + options(preserves_flags, nostack), |
| 94 | + SYSCALL_CLASS_NUMBER = const SYSCALL_CLASS_NUMBER, |
| 95 | + ); |
132 | 96 | } |
133 | 97 | [Register(r0), Register(r1), Register(r2), Register(r3)] |
134 | 98 | } |
|
0 commit comments