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