Skip to content

Commit d4ea196

Browse files
committed
arch: Added initial OpenRISC architecture port
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]>
1 parent 212f7ac commit d4ea196

32 files changed

+2659
-3
lines changed

MAINTAINERS.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5696,3 +5696,15 @@ zbus:
56965696
- "area: llext"
56975697
tests:
56985698
- llext
5699+
5700+
OpenRISC Arch:
5701+
status: maintained
5702+
maintainers:
5703+
- jhol
5704+
files:
5705+
- arch/openrisc/
5706+
- include/zephyr/arch/openrisc/
5707+
labels:
5708+
- "area: OpenRISC"
5709+
tests:
5710+
- arch.openrisc

arch/Kconfig

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ config MIPS
6666
help
6767
MIPS architecture
6868

69+
config OPENRISC
70+
bool
71+
select ARCH_IS_SET
72+
select ATOMIC_OPERATIONS_BUILTIN
73+
select BIG_ENDIAN
74+
select USE_SWITCH
75+
select USE_SWITCH_SUPPORTED
76+
help
77+
OpenRISC architecture
78+
6979
config SPARC
7080
bool
7181
select ARCH_IS_SET
@@ -227,7 +237,7 @@ config SRAM_BASE_ADDRESS
227237
/chosen/zephyr,sram in devicetree. The user should generally avoid
228238
changing it via menuconfig or in configuration files.
229239

230-
if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV
240+
if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV || OPENRISC
231241

232242
# Workaround for not being able to have commas in macro arguments
233243
DT_CHOSEN_Z_FLASH := zephyr,flash
@@ -250,7 +260,7 @@ config FLASH_BASE_ADDRESS
250260
normally set by the board's defconfig file and the user should generally
251261
avoid modifying it via the menu configuration.
252262

253-
endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV
263+
endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV || OPENRISC
254264

255265
if ARCH_HAS_TRUSTED_EXECUTION
256266

arch/archs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ archs:
99
path: mips
1010
- name: nios2
1111
path: nios2
12+
- name: openrisc
13+
path: openrisc
1214
- name: posix
1315
path: posix
1416
- name: riscv

arch/openrisc/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-or1k")
8+
9+
add_subdirectory(core)
10+
zephyr_include_directories(include)

arch/openrisc/Kconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
menu "OpenRISC Options"
8+
depends on OPENRISC
9+
10+
config ARCH
11+
string
12+
default "openrisc"
13+
14+
config GEN_ISR_TABLES
15+
default y
16+
17+
config GEN_IRQ_VECTOR_TABLE
18+
default n
19+
20+
config GEN_SW_ISR_TABLE
21+
default y
22+
23+
config NUM_IRQS
24+
int
25+
26+
endmenu

arch/openrisc/core/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
zephyr_library()
8+
9+
zephyr_library_sources(
10+
cpu_idle.c
11+
exception.S
12+
fatal.c
13+
irq_manage.c
14+
irq_offload.c
15+
prep_c.c
16+
reboot.c
17+
switch.S
18+
thread.c
19+
)
20+
21+
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)

arch/openrisc/core/asm_macros.inc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 NVIDIA Corporation
3+
*
4+
* Convenience macros for assembly code
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/* Convenience macros for assembly code. */
10+
11+
12+
/*
13+
* Helper macro which stores the value of a register to a the address contained
14+
* in a pointer register plus an immediate offset.
15+
*/
16+
17+
.macro op_store_reg reg, off, ptr_reg
18+
l.sw \off(\ptr_reg), \reg
19+
.endm
20+
21+
22+
/*
23+
* Helper macro which loads a value to a register from an address contained in
24+
* a pointer register plus an immediate offset.
25+
*/
26+
27+
.macro op_load_reg reg, off, ptr_reg
28+
l.lwz \reg, \off(\ptr_reg)
29+
.endm

arch/openrisc/core/cpu_idle.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 NVIDIA Corporation <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/irq.h>
8+
9+
#include <zephyr/tracing/tracing.h>
10+
11+
#include <openrisc/openriscregs.h>
12+
13+
static ALWAYS_INLINE void openrisc_idle(unsigned int key)
14+
{
15+
sys_trace_idle();
16+
17+
/* unlock interrupts */
18+
irq_unlock(key);
19+
20+
/* wait for interrupt */
21+
if (openrisc_read_spr(SPR_UPR) & SPR_UPR_PMP) {
22+
openrisc_write_spr(SPR_PMR, openrisc_read_spr(SPR_PMR) | SPR_PMR_DME);
23+
}
24+
}
25+
26+
#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_IDLE
27+
void arch_cpu_idle(void)
28+
{
29+
openrisc_idle(1);
30+
}
31+
#endif
32+
33+
#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
34+
void arch_cpu_atomic_idle(unsigned int key)
35+
{
36+
openrisc_idle(key);
37+
}
38+
#endif

0 commit comments

Comments
 (0)