Skip to content

Commit a6fcb8b

Browse files
committed
cortex-m3 added comments to switch_task + changed to named label for offset
1 parent a86c6a2 commit a6fcb8b

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

targets/arm/rtos/cortex-m3.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ namespace klib::rtos::cortex_m3 {
133133
rtos::detail::base_task** current_task,
134134
rtos::detail::base_task** next_task
135135
) {
136+
// r0 contains current_task, r1 contains next_task
136137
__asm__ volatile(
137138
// save context of current and next task is not a nullptr
138139
"ldr r2, [r0]\n"
@@ -146,7 +147,7 @@ namespace klib::rtos::cortex_m3 {
146147

147148
// store the stack pointer with the offset in %0
148149
"ldr r3, [r0]\n"
149-
"str r2, [r3, %0]\n"
150+
"str r2, [r3, %[offset]]\n"
150151

151152
"switch_task_next_task:\n"
152153

@@ -155,7 +156,7 @@ namespace klib::rtos::cortex_m3 {
155156
"str r3, [r0]\n"
156157

157158
// get the stack pointer of the next task
158-
"ldr r2, [r3, %0]\n"
159+
"ldr r2, [r3, %[offset]]\n"
159160

160161
// pop the registers from the stack that are not saved by hardware
161162
"ldmia r2!, {r4-r11}\n"
@@ -164,8 +165,8 @@ namespace klib::rtos::cortex_m3 {
164165
// return
165166
"bx lr\n"
166167
:
167-
: "I" (offsetof(rtos::detail::base_task, stack_pointer))
168-
: "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "memory"
168+
: [current]"r"(current_task), [next]"r"(next_task), [offset]"I" (offsetof(rtos::detail::base_task, stack_pointer))
169+
: "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "memory", "cc"
169170
);
170171
}
171172

0 commit comments

Comments
 (0)