Skip to content

Conversation

@jhol
Copy link
Contributor

@jhol jhol commented Oct 23, 2025

This PR follows on from #83933 which was closed due to inactivity. It has been many months since I have had any time to put into up-streaming these patches, so the PR was automatically closed.

Here is v9 of the patch-set with the following changes:

  • Rebased on Zephyr v4.2.1
    • Update to picolibc version is already upstream.
  • Support non-multi-threaded operation.
  • Fix stack initialization (thanks @NomanKhan777).
  • Fix typo Interatively.
  • Don't use z_openrisc_thread_start for SECTION_FUNC, because we don't want a section division here when _isr_tail falls through to it.
  • Ensure r0 is initialized to zero (thanks @zgliu799).
  • Moved interrupt control functions into irq.h and make them inline.
  • Support multi-level IRQ handling.
  • Moved __reset and __start labels into reset exception handler.
  • Removed redundant call to z_check_stack_sentinel in _isr_tail. It is already called in z_get_next_switch_handle.
  • Call z_check_stack_sentinel in z_openrisc_handle_irqs.
  • Save the usage of r15 in _isr_tail.
  • load_caller_saved afer load_mac and load_esr_epcr for symmetry with storage macros.
  • Various linker script improvements:
    • Add support for XIP.
    • Place snippets before noload and bss sections so as not to pad output image.
    • Support device-tree regions.
  • Added heading to include/zephyr/arch/openrisc/arch.h similar to match include/zephyr/arch/mips/arch.h.

The Zephyr port for the proprietary cousin of this architecture has now entered full production.

@zgliu799 has tested v8 version of the patches running an OpenRISC processor on an FPGA, and reports that they have worked successfully. He has also test the build using the Zephyr or1k tool-chain from the sdk-ng PR.

The sdk-ng patches are the main roadblock to getting this PR merged. They have been tested and rebased on the sdk-ng main branch.

jhol added 14 commits October 23, 2025 14:21
.balign is available in the or1k GNU assembler, therefore ALIGN and
PERFOPT_ALIGN are both configured use it.

Signed-off-by: Joel Holdsworth <[email protected]>

FIX: balign
A common set of macros: GTEXT(), GDATA(), WTEXT() and WDATA() is defined
for Arm, Arm66, MIPS, RISC-V, RX and Xtensa. This patch adds OpenRISC
to this set.

Signed-off-by: Joel Holdsworth <[email protected]>
Existing versions of GEN_ABSOLUTE_SYM and GEN_ABSOLUTE_SYM_KCONFIG are
defined for all supported architectures. This patch adds a definition of
the same kind used for MIPS, RISC-V and Xtensa.

Signed-off-by: Joel Holdsworth <[email protected]>
The OpenRISC or1k-elf GCC compiler output format is named "elf32-or1k".
This patch adds an OUTPUT_FORMAT linker macro for this platform.

Signed-off-by: Joel Holdsworth <[email protected]>
Zephyr maps the start and end of the rodata section with variables using
the __rodata_region_start and __rodata_region_end. This patch adopts this
convention for the OpenRISC architecture.

Signed-off-by: Joel Holdsworth <[email protected]>
This patch adds support for the OpenRISC 1000 (or1k) architecture: a
MIPS-like open hardware ISA which was first introduced in 2000.

The thread switching implementation uses the modern Zephyr thread "switch"
architecture.

Signed-off-by: Joel Holdsworth <[email protected]>
In OpenRISC 1000, the stack pointer is stored in the r1 register. This
patch stores the offset of this value within in the thread structure into
the thread info offsets.

Signed-off-by: Joel Holdsworth <[email protected]>
The OpenRISC 1000 Tick Timer is tightly coupled to the or1k CPU core, and
is explicitly designed to facilitate task scheduling and high-resolution
timing.

The timer is documented in Chapter 14 of the OpenRISC 1000 Architecture
Manual:

    https://openrisc.io/or1k.html#__RefHeading__504849_595890882

Signed-off-by: Joel Holdsworth <[email protected]>
The Qemu emulator executable for the OpenRISC 1000 (or1k) architecture is
named qemu-or1k. This patch adds this information to the qemu architecture
suffix list.

Signed-off-by: Joel Holdsworth <[email protected]>
Qemu includes support for the OpenRISC 1000 CPU architecture. This patch
adds a Zephyr SoC definition which enables usage of this feature.

The SoC definition closely mirrors the Qemu MIPS Malta SoC definition.

Signed-off-by: Joel Holdsworth <[email protected]>
Qemu includes support for the OpenRISC 1000 CPU architecture. This patch
adds a Zephyr virtual board definition which enables usage of this feature.

The board definition closely mirrors the Qemu MIPS Malta board definition.

Signed-off-by: Joel Holdsworth <[email protected]>
The OpenRISC CPU architecture is signified by the CONFIG_OPENRISC Kconfig
option. This patch adds this information to the log database ARCHS table.

Signed-off-by: Joel Holdsworth <[email protected]>
Adds the openrisc CPU architecture to the twister platform definitions.

Signed-off-by: Joel Holdsworth <[email protected]>
The OpenRISC 1000 architecture can be tested through the qemu_or1k emulated
SoC and board. Because this emulated device has minimal external hardware
by default, this patch enables a minimal suite of tests covering core
kernel features for the CPU architecture.

When running the test suite, OpenRISC was found to require additional stack
space to prevent an overflow. Therefore, a minimal additional amount of
storage: 128-bytes, was added that was found in practice to allow tests to
complete.

Note that Qemu version 9.2.0 or newer is required so as to include the
following commit:

    commit 3eb43aeb164f1f83c97ff693c7d464b49755110c
    Author: Joel Holdsworth <[email protected]>
    Date:   Fri Jun 7 15:29:33 2024 -0700

        hw/openrisc: Fixed undercounting of TTCR in continuous mode

This fixes a bug in the implementation of the emulated OpenRISC Tick Timer
which prevents the Zephyr OpenRISC port from task-scheduling properly.

Signed-off-by: Joel Holdsworth <[email protected]>
@sonarqubecloud
Copy link

@nordicjm
Copy link
Contributor

Can you explain why openrisc is a separate architecture to risc (I don't have knowledge on them but assumed they would be the ISA compatible?)

@henrikbrixandersen henrikbrixandersen added the Architecture Review Discussion in the Architecture WG required label Oct 24, 2025
@zgliu799
Copy link

Can you explain why openrisc is a separate architecture to risc (I don't have knowledge on them but assumed they would be the ISA compatible?)

You can refer to https://openrisc.io/

Comment on lines +27 to +29
#if defined(CONFIG_SOC_PREP_HOOK)
soc_prep_hook();
#endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the if is not needed, it is already handled in zephyr/platform/hooks.h

@maass-hamburg
Copy link
Member

Can you explain why openrisc is a separate architecture to risc (I don't have knowledge on them but assumed they would be the ISA compatible?)

did you meant RISCV? they are completely different, just like ARM and RISCV are

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Architecture Review Discussion in the Architecture WG required

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

8 participants