Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: Added initial OpenRISC port #83933

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions MAINTAINERS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5696,3 +5696,18 @@ zbus:
- "area: llext"
tests:
- llext

OpenRISC Arch:
status: maintained
maintainers:
- jhol
files:
- arch/openrisc/
- boards/qemu/or1k/
- drivers/timer/*openrisc*
- include/zephyr/arch/openrisc/
- soc/qemu/or1k/
labels:
- "area: OpenRISC"
tests:
- arch.openrisc
14 changes: 12 additions & 2 deletions arch/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ config MIPS
help
MIPS architecture

config OPENRISC
bool
select ARCH_IS_SET
select ATOMIC_OPERATIONS_BUILTIN
select BIG_ENDIAN
select USE_SWITCH
select USE_SWITCH_SUPPORTED
help
OpenRISC architecture

config SPARC
bool
select ARCH_IS_SET
Expand Down Expand Up @@ -227,7 +237,7 @@ config SRAM_BASE_ADDRESS
/chosen/zephyr,sram in devicetree. The user should generally avoid
changing it via menuconfig or in configuration files.

if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV
if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV || OPENRISC

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

endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV
endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV || OPENRISC

if ARCH_HAS_TRUSTED_EXECUTION

Expand Down
2 changes: 2 additions & 0 deletions arch/archs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ archs:
path: mips
- name: nios2
path: nios2
- name: openrisc
path: openrisc
- name: posix
path: posix
- name: riscv
Expand Down
10 changes: 10 additions & 0 deletions arch/openrisc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

set_property(GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT "elf32-or1k")

add_subdirectory(core)
zephyr_include_directories(include)
26 changes: 26 additions & 0 deletions arch/openrisc/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

menu "OpenRISC Options"
depends on OPENRISC

config ARCH
string
default "openrisc"

config GEN_ISR_TABLES
default y

config GEN_IRQ_VECTOR_TABLE
default n

config GEN_SW_ISR_TABLE
default y

config NUM_IRQS
int

endmenu
21 changes: 21 additions & 0 deletions arch/openrisc/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2025 NVIDIA Corporation <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
#

zephyr_library()

zephyr_library_sources(
cpu_idle.c
exception.S
fatal.c
irq_manage.c
irq_offload.c
prep_c.c
reboot.c
switch.S
thread.c
)

zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
29 changes: 29 additions & 0 deletions arch/openrisc/core/asm_macros.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2025 NVIDIA Corporation
*
* Convenience macros for assembly code
*
* SPDX-License-Identifier: Apache-2.0
*/

/* Convenience macros for assembly code. */


/*
* Helper macro which stores the value of a register to a the address contained
* in a pointer register plus an immediate offset.
*/

.macro op_store_reg reg, off, ptr_reg
l.sw \off(\ptr_reg), \reg
.endm


/*
* Helper macro which loads a value to a register from an address contained in
* a pointer register plus an immediate offset.
*/

.macro op_load_reg reg, off, ptr_reg
l.lwz \reg, \off(\ptr_reg)
.endm
38 changes: 38 additions & 0 deletions arch/openrisc/core/cpu_idle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2025 NVIDIA Corporation <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/irq.h>

#include <zephyr/tracing/tracing.h>

#include <openrisc/openriscregs.h>

static ALWAYS_INLINE void openrisc_idle(unsigned int key)
{
sys_trace_idle();

/* unlock interrupts */
irq_unlock(key);

/* wait for interrupt */
if (openrisc_read_spr(SPR_UPR) & SPR_UPR_PMP) {
openrisc_write_spr(SPR_PMR, openrisc_read_spr(SPR_PMR) | SPR_PMR_DME);
}
}

#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_IDLE
void arch_cpu_idle(void)
{
openrisc_idle(1);
}
#endif

#ifndef CONFIG_ARCH_HAS_CUSTOM_CPU_ATOMIC_IDLE
void arch_cpu_atomic_idle(unsigned int key)
{
openrisc_idle(key);
}
#endif
Loading
Loading