From f7f758d4d1c7cd7e0c1cf1d9f4e0d98ed48a29f8 Mon Sep 17 00:00:00 2001 From: Christian Herber Date: Mon, 22 Sep 2025 14:00:52 +0200 Subject: [PATCH 1/3] Smtp: Making stack layout normative --- src/aclic.adoc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/aclic.adoc b/src/aclic.adoc index 8cd8b51..3c1c8e1 100644 --- a/src/aclic.adoc +++ b/src/aclic.adoc @@ -1044,9 +1044,9 @@ Once the instruction retires, or the interrupts are disabled, no late preemption === Stack layout -To ease debugging, a stack layout is recommended for the saved context. - -NOTE: This stack layout is not mandated to allow e.g. shadow register sets +Trap handlers may need to access stacked context. +E.g. an ECALL handler needs to increment the epc value by 4 to avoid re-executing the ECALL instruction. +To simplify access to the stacked context, the stack layout is defined as follows. [source] ---- @@ -1060,8 +1060,8 @@ stack pointer adjustment: 32 20: x14 16: x13 12: x12 -8: x11 -4: x10 + 8: x11 + 4: x10 ** XLEN = 64: @@ -1072,7 +1072,7 @@ stack pointer adjustment: 48 32: x13 24: x12 16: x11 -8: x10 + 8: x10 * Smnip/Ssnip present: From dca3ed4d72869988e6d81d0e3c5e4043641e04b5 Mon Sep 17 00:00:00 2001 From: Christian Herber Date: Mon, 22 Sep 2025 14:02:54 +0200 Subject: [PATCH 2/3] Smtp: Fixing typo in stack definition Closes #607 --- src/aclic.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aclic.adoc b/src/aclic.adoc index 3c1c8e1..891e47d 100644 --- a/src/aclic.adoc +++ b/src/aclic.adoc @@ -1085,11 +1085,11 @@ stack pointer adjustment: 32 32: xpistatus (XLEN) 28: xpepc (XLEN) -** XLEN = 32 +** XLEN = 64 stack pointer adjustment: 64 -60: xpistatus (XLEN) +64: xpistatus (XLEN) 56: xpepc (XLEN) ---- From d65e7ba8f650befed40cfbd1b6f714ba7bf7ff5b Mon Sep 17 00:00:00 2001 From: Christian Herber Date: Fri, 26 Sep 2025 12:43:41 +0200 Subject: [PATCH 3/3] Smtp: changing stack offsets to negative ones --- src/aclic.adoc | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/aclic.adoc b/src/aclic.adoc index 891e47d..7e1bda0 100644 --- a/src/aclic.adoc +++ b/src/aclic.adoc @@ -1056,23 +1056,23 @@ To simplify access to the stacked context, the stack layout is defined as follow stack pointer adjustment: 32 -24: x15 -20: x14 -16: x13 -12: x12 - 8: x11 - 4: x10 +-24: x15 +-20: x14 +-16: x13 +-12: x12 + -8: x11 + -4: x10 ** XLEN = 64: stack pointer adjustment: 48 -48: x15 -40: x14 -32: x13 -24: x12 -16: x11 - 8: x10 +-48: x15 +-40: x14 +-32: x13 +-24: x12 +-16: x11 + -8: x10 * Smnip/Ssnip present: @@ -1082,15 +1082,15 @@ start of stackframe remains same. In addition: stack pointer adjustment: 32 -32: xpistatus (XLEN) -28: xpepc (XLEN) +-32: xpistatus (XLEN) +-28: xpepc (XLEN) ** XLEN = 64 stack pointer adjustment: 64 -64: xpistatus (XLEN) -56: xpepc (XLEN) +-64: xpistatus (XLEN) +-56: xpepc (XLEN) ---- === Fault handling