Skip to content

Commit ee704d6

Browse files
Merge pull request #13 from robamu/cortex-r-und-abt-stack-setup
Cortex-R: UND and ABT stack setup
2 parents 8f91e39 + d971d70 commit ee704d6

File tree

4 files changed

+78
-13
lines changed

4 files changed

+78
-13
lines changed

cortex-ar/CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [unreleased]
9+
10+
## [v0.1.0]
11+
12+
Initial release
13+
14+
[unreleased]: https://github.com/rust-embedded/cortex-ar/compare/cortex-ar-v0.1.0...HEAD
15+
[v0.1.0]: https://github.com/rust-embedded/cortex-ar/releases/tag/cortex-ar-v0.1.0

cortex-r-rt/CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [unreleased]
9+
10+
## Added
11+
12+
- Added ABT und UND mode stack setup.
13+
14+
## [v0.1.0]
15+
16+
Initial release
17+
18+
[unreleased]: https://github.com/rust-embedded/cortex-ar/compare/cortex-r-rt-v0.1.0...HEAD
19+
[v0.1.0]: https://github.com/rust-embedded/cortex-ar/releases/tag/cortex-r-rt-v0.1.0

cortex-r-rt/link.x

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,19 @@ and a FIQ stack, plus the remainder is our system stack.
7878
You must keep _stack_top and the stack sizes aligned to eight byte boundaries.
7979
*/
8080
PROVIDE(_stack_top = ORIGIN(DATA) + LENGTH(DATA));
81-
PROVIDE(_fiq_stack_size = 0x100);
81+
PROVIDE(_fiq_stack_size = 0x400);
8282
PROVIDE(_irq_stack_size = 0x1000);
83+
PROVIDE(_abt_stack_size = 0x400);
84+
PROVIDE(_und_stack_size = 0x400);
8385
PROVIDE(_svc_stack_size = 0x1000);
8486

8587
ASSERT(_stack_top % 8 == 0, "ERROR(cortex-r-rt): top of stack is not 8-byte aligned");
8688
ASSERT(_fiq_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of FIQ stack is not 8-byte aligned");
8789
ASSERT(_irq_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of IRQ stack is not 8-byte aligned");
90+
ASSERT(_fiq_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of FIQ stack is not 8-byte aligned");
91+
ASSERT(_abt_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of ABT stack is not 8-byte aligned");
92+
ASSERT(_und_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of UND stack is not 8-byte aligned");
93+
ASSERT(_svc_stack_size % 8 == 0, "ERROR(cortex-r-rt): size of SVC stack is not 8-byte aligned");
8894

8995
PROVIDE(_asm_undefined_handler =_asm_default_handler);
9096
PROVIDE(_asm_prefetch_handler =_asm_default_handler);

cortex-r-rt/src/lib.rs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -342,21 +342,32 @@ core::arch::global_asm!(
342342
343343
.type _el1_start, %function
344344
_el1_start:
345-
// Set stack pointer (as the top) and mask interrupts for for FIQ mode (Mode 0x11)
345+
// Set up stacks.
346346
ldr r0, =_stack_top
347-
msr cpsr, {fiq_mode}
347+
// Set stack pointer (right after) and mask interrupts for for UND mode (Mode 0x1B)
348+
msr cpsr, {und_mode}
348349
mov sp, r0
349-
ldr r1, =_fiq_stack_size
350+
ldr r1, =_und_stack_size
351+
sub r0, r0, r1
352+
// Set stack pointer (right after) and mask interrupts for for SVC mode (Mode 0x13)
353+
msr cpsr, {svc_mode}
354+
mov sp, r0
355+
ldr r1, =_svc_stack_size
356+
sub r0, r0, r1
357+
// Set stack pointer (right after) and mask interrupts for for ABT mode (Mode 0x17)
358+
msr cpsr, {abt_mode}
359+
mov sp, r0
360+
ldr r1, =_abt_stack_size
350361
sub r0, r0, r1
351362
// Set stack pointer (right after) and mask interrupts for for IRQ mode (Mode 0x12)
352363
msr cpsr, {irq_mode}
353364
mov sp, r0
354365
ldr r1, =_irq_stack_size
355366
sub r0, r0, r1
356-
// Set stack pointer (right after) and mask interrupts for for SVC mode (Mode 0x13)
357-
msr cpsr, {svc_mode}
367+
// Set stack pointer (right after) and mask interrupts for for FIQ mode (Mode 0x11)
368+
msr cpsr, {fiq_mode}
358369
mov sp, r0
359-
ldr r1, =_svc_stack_size
370+
ldr r1, =_fiq_stack_size
360371
sub r0, r0, r1
361372
// Set stack pointer (right after) and mask interrupts for for System mode (Mode 0x1F)
362373
msr cpsr, {sys_mode}
@@ -395,23 +406,37 @@ core::arch::global_asm!(
395406
b .
396407
.size _el1_start, . - _el1_start
397408
"#,
398-
fiq_mode = const {
409+
und_mode = const {
399410
Cpsr::new_with_raw_value(0)
400-
.with_mode(ProcessorMode::Fiq)
411+
.with_mode(ProcessorMode::Und)
401412
.with_i(true)
402413
.with_f(true)
403414
.raw_value()
404415
},
405-
irq_mode = const {
416+
svc_mode = const {
406417
Cpsr::new_with_raw_value(0)
407-
.with_mode(ProcessorMode::Irq)
418+
.with_mode(ProcessorMode::Svc)
408419
.with_i(true)
409420
.with_f(true)
410421
.raw_value()
411422
},
412-
svc_mode = const {
423+
abt_mode = const {
413424
Cpsr::new_with_raw_value(0)
414-
.with_mode(ProcessorMode::Svc)
425+
.with_mode(ProcessorMode::Abt)
426+
.with_i(true)
427+
.with_f(true)
428+
.raw_value()
429+
},
430+
fiq_mode = const {
431+
Cpsr::new_with_raw_value(0)
432+
.with_mode(ProcessorMode::Fiq)
433+
.with_i(true)
434+
.with_f(true)
435+
.raw_value()
436+
},
437+
irq_mode = const {
438+
Cpsr::new_with_raw_value(0)
439+
.with_mode(ProcessorMode::Irq)
415440
.with_i(true)
416441
.with_f(true)
417442
.raw_value()

0 commit comments

Comments
 (0)