libcortex_a9: add interrupt exit support for interrupt_handler macro #107

Merged
sb10q merged 4 commits from morgan/zynq-rs:interrupt into master 2023-11-20 12:30:29 +08:00
Showing only changes of commit 63c604e336 - Show all commits

View File

@ -66,7 +66,7 @@ macro_rules! interrupt_handler {
concat!("movtne r1, :upper16:", stringify!($stack1)),
"mov r0, sp",
"mov sp, r1",
"push {{r0, r1}}", // for stack alignment
"push {{r0, r1}}", // 2 registers are pushed to maintain 8 byte stack alignment
Outdated
Review

Unclear what this "stack alignment" does exactly and why it is needed.

Unclear what this "stack alignment" does exactly and why it is needed.

The arm doc state the stack need to be 8 byte align and the easiest way to do it is to push/pop in multiple of 2 registers.

When push {{r0}} is used with a timer interrupt, the wrpll satellite will result in the following error.
Which I suspect the compiler assume the stack pointer is 8 byte alignment and mess up the dellocation.

...
[     0.000067s]  INFO(satman): ARTIQ satellite manager starting...
[     0.006019s]  INFO(satman): gateware ident satellite
[     0.016080s]  INFO(libboard_zynq::i2c): PCA9548 detected
[     0.458796s]  INFO(libboard_artiq::wrpll): Main Si549 started
[     0.564532s]  INFO(satman): Switching SYS clocks...
[     0.619395s]  INFO(satman): SYS CLK switched successfully
[     0.921209s]  INFO(libboard_artiq::wrpll): Helper Si549 started
[     0.927196s]  INFO(satman): uplink is up, switching to recovered clock
[     0.933935s]  INFO(libboard_artiq::wrpll): WRPLL started
[     0.939230s]  INFO(libboard_artiq::wrpll): warming up si549...
[    20.945048s]  INFO(libboard_artiq::wrpll): tracking gtx frequency...
[    21.101694s]  INFO(libboard_artiq::wrpll): starting helper PLL...
[    21.468593s]  INFO(libboard_artiq::wrpll): ...locked
[    21.473541s]  INFO(libboard_artiq::wrpll): starting main PLL interrupt...
[    21.715075s]  INFO(satman): TSC loaded from uplink
[    21.724998s]  INFO(satman): rank: 1
[    21.728472s]  INFO(satman): routing table: RoutingTable { 0: 0; 1: 1 0; 2: 2 0; 3: 3 0; 4: 4 0; }
[    24.900000s]  INFO(ksupport::irq): current count = 50000001 <---- interrupt prints
[    29.880000s]  INFO(ksupport::irq): current count = 60000001
[    34.860000s]  INFO(ksupport::irq): current count = 70000001
[    36.263504s]  INFO(satman): uplink is down, switching to local oscillator clock
[    36.272139s] ERROR@�): received packet of an unknown type
[    37.454274s]  INFO@�): uplink is up, switching to recovered clock
[    37.461085s]  INFO(libboard_artiq::wrpll): WRPLL started
[    37.466302s]  INFO(libboard_artiq::wrpll): warming up si549...
[    57.472198s]  INFO(libboard_artiq::wrpll): tracking gtx frequency...
[    57.628844s]  INFO(libboard_artiq::wrpll): starting helper PLL...
[    57.995403s]  INFO(libboard_artiq::wrpll): ...locked
[    58.000352s]  INFO(libboard_artiq::wrpll): starting main PLL interrupt...
[    58.296202s]  INFO@�): TSC loaded from uplink
[    58.306209s]  INFO@�): rank: 1
[    58.309682s]  INFO@�): routing table: RoutingTable { 0: 0; 1: 1 0; 2: 2 0; 3: 3 0; 4: 4 0; }
[    59.760001s]  INFO(ksupport::irq): current count = 120000001
[    64.740001s]  INFO(ksupport::irq): current count = 130000001
[    66.578307s]  INFO@�): uplink is down, switching to local oscillator clock
Core 0 panic at /build/cargo-vendor-dir/linked_list_allocator-0.8.11/src/hole.rs:293:9: invalid deallocation (probably a double free)


The [arm doc](https://developer.arm.com/documentation/ddi0419/c/System-Level-Architecture/System-Level-Programmers--Model/ARMv6-M-exception-model/Stack-alignment-on-exception-entry?lang=en) state the stack need to be 8 byte align and the easiest way to do it is to push/pop in multiple of 2 registers. When `push {{r0}}` is used with a timer interrupt, the wrpll satellite will result in the following error. Which I suspect the compiler assume the stack pointer is 8 byte alignment and mess up the dellocation. ```bash ... [ 0.000067s] INFO(satman): ARTIQ satellite manager starting... [ 0.006019s] INFO(satman): gateware ident satellite [ 0.016080s] INFO(libboard_zynq::i2c): PCA9548 detected [ 0.458796s] INFO(libboard_artiq::wrpll): Main Si549 started [ 0.564532s] INFO(satman): Switching SYS clocks... [ 0.619395s] INFO(satman): SYS CLK switched successfully [ 0.921209s] INFO(libboard_artiq::wrpll): Helper Si549 started [ 0.927196s] INFO(satman): uplink is up, switching to recovered clock [ 0.933935s] INFO(libboard_artiq::wrpll): WRPLL started [ 0.939230s] INFO(libboard_artiq::wrpll): warming up si549... [ 20.945048s] INFO(libboard_artiq::wrpll): tracking gtx frequency... [ 21.101694s] INFO(libboard_artiq::wrpll): starting helper PLL... [ 21.468593s] INFO(libboard_artiq::wrpll): ...locked [ 21.473541s] INFO(libboard_artiq::wrpll): starting main PLL interrupt... [ 21.715075s] INFO(satman): TSC loaded from uplink [ 21.724998s] INFO(satman): rank: 1 [ 21.728472s] INFO(satman): routing table: RoutingTable { 0: 0; 1: 1 0; 2: 2 0; 3: 3 0; 4: 4 0; } [ 24.900000s] INFO(ksupport::irq): current count = 50000001 <---- interrupt prints [ 29.880000s] INFO(ksupport::irq): current count = 60000001 [ 34.860000s] INFO(ksupport::irq): current count = 70000001 [ 36.263504s] INFO(satman): uplink is down, switching to local oscillator clock [ 36.272139s] ERROR@�): received packet of an unknown type [ 37.454274s] INFO@�): uplink is up, switching to recovered clock [ 37.461085s] INFO(libboard_artiq::wrpll): WRPLL started [ 37.466302s] INFO(libboard_artiq::wrpll): warming up si549... [ 57.472198s] INFO(libboard_artiq::wrpll): tracking gtx frequency... [ 57.628844s] INFO(libboard_artiq::wrpll): starting helper PLL... [ 57.995403s] INFO(libboard_artiq::wrpll): ...locked [ 58.000352s] INFO(libboard_artiq::wrpll): starting main PLL interrupt... [ 58.296202s] INFO@�): TSC loaded from uplink [ 58.306209s] INFO@�): rank: 1 [ 58.309682s] INFO@�): routing table: RoutingTable { 0: 0; 1: 1 0; 2: 2 0; 3: 3 0; 4: 4 0; } [ 59.760001s] INFO(ksupport::irq): current count = 120000001 [ 64.740001s] INFO(ksupport::irq): current count = 130000001 [ 66.578307s] INFO@�): uplink is down, switching to local oscillator clock Core 0 panic at /build/cargo-vendor-dir/linked_list_allocator-0.8.11/src/hole.rs:293:9: invalid deallocation (probably a double free) ```
Outdated
Review

Code comment needs to be expanded.

Code comment needs to be expanded.
concat!("bl ", stringify!($name2)),
"pop {{r0, r1}}",
"mov sp, r0",