Skip to content

Commit 11a86f8

Browse files
doc: add hooks to arch porting documentation
Document the expected early boot sequence and when platform hooks should be called by the arch-specific coode, and under what conditions. Signed-off-by: Mathieu Choplain <[email protected]>
1 parent 41caa2a commit 11a86f8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

doc/hardware/porting/arch.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,69 @@ Some examples of architecture-specific steps that have to be taken:
8787
race conditions.
8888
* Setup FIRQ and regular IRQ handling on ARCv2.
8989

90+
Early Boot Sequence Hooks
91+
=========================
92+
93+
Zephyr exposes several hooks (described in :zephyr_file:`include/zephyr/platform/hooks.h`)
94+
that allow execution of SoC- or board-specific code at precise moments of the boot process.
95+
96+
The kernel takes care of calling most of the hooks from architecture-agnostic
97+
code. However, some hooks must be called during the early boot process; since
98+
this is implemented in architecture-specific code, the call to the hooks must
99+
be implemented there too. The following gives a rough overview of the early
100+
boot sequence and when hooks should be called by architecture-specific code:
101+
102+
* Execution begins in the function named :kconfig:option:`CONFIG_KERNEL_ENTRY`
103+
104+
* Architecture-specific state is re-initialized immediately if
105+
:kconfig:option:`CONFIG_INIT_ARCH_HW_AT_BOOT` is enabled
106+
107+
* :c:func:`soc_early_reset_hook()` is called
108+
109+
* Providing a valid stack to this hook is not necessary.
110+
However, the stack pointer register *may* be overwritten by
111+
the hook before returning.
112+
113+
* On architectures with multiple stack pointers, there is usually a
114+
"primary" register accessible directly and other "secondary" stack
115+
pointer registers. The hook *may* only overwrite the "primary" stack
116+
pointer register and must leave "secondary" stack pointer registers
117+
untouched.
118+
119+
* For example, the ARM Cortex-A architecture defines one ``sp_<mode>``
120+
register for each of the processor's execution modes; the ``sp``
121+
general-purpose register internally corresponds to ``sp_<mode>``
122+
of the processor's current execution mode. On this architecture,
123+
:c:func:`soc_early_reset_hook()` is allowed to overwrite ``sp``
124+
but not ``sp_<mode>`` of a different execution mode.
125+
126+
* This allows architecture-specific code to set up exception stacks
127+
(when applicable) before calling :c:func:`soc_early_reset_hook`
128+
129+
* An initial stack for use during the rest of the early boot sequence is setup
130+
131+
* The architecture-specific "resume from suspend-to-RAM" logic is executed
132+
133+
* Refer to :kconfig:option:`CONFIG_PM_S2RAM` for more details, but note
134+
that the rest of the early boot sequence is not executed if this
135+
logic determines that an exit from suspend-to-RAM is ongoing
136+
137+
* :c:func:`soc_reset_hook()` is called
138+
139+
* *Architecture-specific work (in assembly) occurs here...*
140+
141+
* :c:func:`z_prep_c` is called
142+
143+
* This function is implemented in C by the architecture layer
144+
145+
* :c:func:`z_prep_c()` immediately calls :c:func:`soc_prep_hook()`
146+
147+
* *Architecture-specific work (in C) occurs here...*
148+
149+
* :c:func:`z_cstart` is called
150+
151+
* Architecture-agnostic code takes over when this function is called
152+
90153
Interrupt and Exception Handling
91154
********************************
92155

0 commit comments

Comments
 (0)