Skip to content

Commit 6b8ed7e

Browse files
committed
arch: arm: documentation improvements in ARM assembly sources
Add more documentation and inline explanatory comments in assembly sources swap_helper.S and userspace.S and remove redundant/wrong documentation when applicable. Signed-off-by: Ioannis Glaropoulos <[email protected]>
1 parent 8e23ac2 commit 6b8ed7e

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

arch/arm/core/swap_helper.S

+15-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ GDATA(_kernel)
4141
* already been taken. In other words, when z_arm_pendsv() runs, we *know* we
4242
* have to swap *something*.
4343
*
44+
* For Cortex-M, z_arm_pendsv() is invoked with no arguments.
45+
*
4446
* For Cortex-R, PendSV exception is not supported by the architecture and this
4547
* function is directly called either by _IntExit in case of preemption, or
4648
* z_arm_svc in case of cooperative switching.
@@ -163,7 +165,9 @@ out_fp_endif:
163165
str v3, [v4, #0]
164166
#endif
165167

166-
/* Restore previous interrupt disable state (irq_lock key) */
168+
/* Restore previous interrupt disable state (irq_lock key)
169+
* (We clear the arch.basepri field after restoring state)
170+
*/
167171
#if (defined(CONFIG_CPU_CORTEX_M0PLUS) || defined(CONFIG_CPU_CORTEX_M0)) && \
168172
_thread_offset_to_basepri > 124
169173
/* Doing it this way since the offset to thread->arch.basepri can in
@@ -410,13 +414,21 @@ _oops:
410414
* @return N/A
411415
*/
412416
SECTION_FUNC(TEXT, z_arm_svc)
417+
/* Use EXC_RETURN state to find out if stack frame is on the
418+
* MSP or PSP
419+
*/
413420
tst lr, #0x4 /* did we come from thread mode ? */
414421
ite eq /* if zero (equal), came from handler mode */
415422
mrseq r0, MSP /* handler mode, stack frame is on MSP */
416423
mrsne r0, PSP /* thread mode, stack frame is on PSP */
417424

425+
426+
/* Figure out what SVC call number was invoked */
427+
418428
ldr r1, [r0, #24] /* grab address of PC from stack frame */
419-
/* SVC is a two-byte instruction, point to it and read encoding */
429+
/* SVC is a two-byte instruction, point to it and read the
430+
* SVC number (lower byte of SCV instruction)
431+
*/
420432
ldrh r1, [r1, #-2]
421433

422434
/*
@@ -425,8 +437,6 @@ SECTION_FUNC(TEXT, z_arm_svc)
425437
* 1: irq_offload (if configured)
426438
* 2: kernel panic or oops (software generated fatal exception)
427439
* 3: System call (if user mode supported)
428-
* Planned implementation of system calls for memory protection will
429-
* expand this case.
430440
*/
431441
ands r1, #0xff
432442
#if defined(CONFIG_USERSPACE)
@@ -442,7 +452,7 @@ SECTION_FUNC(TEXT, z_arm_svc)
442452
tst r2, #0x1
443453
bne _oops
444454

445-
#endif
455+
#endif /* CONFIG_USERSPACE */
446456

447457
cmp r1, #2
448458
beq _oops

arch/arm/core/userspace.S

+10-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ GDATA(_k_syscall_table)
3333
* The conversion is one way, and threads which transition to user mode do
3434
* not transition back later, unless they are doing system calls.
3535
*
36+
* The function is invoked as:
37+
* z_arm_userspace_enter(user_entry, p1, p2, p3,
38+
* stack_info.start, stack_info.size);
3639
*/
3740
SECTION_FUNC(TEXT,z_arm_userspace_enter)
3841
/* move user_entry to lr */
@@ -44,14 +47,20 @@ SECTION_FUNC(TEXT,z_arm_userspace_enter)
4447
msr PSPLIM, r0
4548
#endif
4649

47-
/* set stack to privileged stack */
50+
/* prepare to set stack to privileged stack */
4851
ldr r0, =_kernel
4952
ldr r0, [r0, #_kernel_offset_to_current]
5053
ldr r0, [r0, #_thread_offset_to_priv_stack_start] /* priv stack ptr */
5154
ldr ip, =CONFIG_PRIVILEGED_STACK_SIZE
5255
add r0, r0, ip
5356

57+
/* store current stack pointer to ip
58+
* the current stack pointer is needed to retrieve
59+
* stack_info.start and stack_info.size
60+
*/
5461
mov ip, sp
62+
63+
/* set stack to privileged stack */
5564
msr PSP, r0
5665

5766
#if defined(CONFIG_BUILTIN_STACK_GUARD)

0 commit comments

Comments
 (0)