diff options
Diffstat (limited to 'libcpu')
| -rw-r--r-- | libcpu/rh850/SConscript | 14 | ||||
| -rw-r--r-- | libcpu/rh850/common/Kconfig | 10 | ||||
| -rw-r--r-- | libcpu/rh850/common/SConscript | 13 | ||||
| -rw-r--r-- | libcpu/rh850/common/context_gcc.S | 231 | ||||
| -rw-r--r-- | libcpu/rh850/common/cpuport.c | 77 | ||||
| -rw-r--r-- | libcpu/rh850/common/rh850_asm.h | 29 | ||||
| -rw-r--r-- | libcpu/rh850/common/rh850_cpu.h | 65 | ||||
| -rw-r--r-- | libcpu/rh850/common/rh850_sysreg.h | 36 | ||||
| -rw-r--r-- | libcpu/rh850/common/trap.c | 91 | ||||
| -rw-r--r-- | libcpu/rh850/common/vector_gcc.S | 75 | ||||
| -rw-r--r-- | libcpu/rh850/g4kh/SConscript | 13 | ||||
| -rw-r--r-- | libcpu/rh850/g4kh/rh850_core.h | 56 | ||||
| -rw-r--r-- | libcpu/rh850/g4kh/rh850_core.inc | 62 |
13 files changed, 772 insertions, 0 deletions
diff --git a/libcpu/rh850/SConscript b/libcpu/rh850/SConscript new file mode 100644 index 0000000000..38b62b632a --- /dev/null +++ b/libcpu/rh850/SConscript @@ -0,0 +1,14 @@ +# RT-Thread building script for bridge + +import os +from building import * + +Import('rtconfig') + +cwd = GetCurrentDir() +group = SConscript(os.path.join('common', 'SConscript')) + +if os.path.isfile(os.path.join(cwd, rtconfig.CPU, 'SConscript')): + group = group + SConscript(os.path.join(rtconfig.CPU, 'SConscript')) + +Return('group') diff --git a/libcpu/rh850/common/Kconfig b/libcpu/rh850/common/Kconfig new file mode 100644 index 0000000000..99c37c8a7a --- /dev/null +++ b/libcpu/rh850/common/Kconfig @@ -0,0 +1,10 @@ +menu "RT-Thread RH850 CPU" + + config RT_USING_FPU + bool "Using Float Point Unit" + default y + help + Build for the hardware FPU and save its context. + If disabled, the code is built with -msoft-float. + +endmenu diff --git a/libcpu/rh850/common/SConscript b/libcpu/rh850/common/SConscript new file mode 100644 index 0000000000..a70265676b --- /dev/null +++ b/libcpu/rh850/common/SConscript @@ -0,0 +1,13 @@ +# RT-Thread building script for component + +from building import * + +Import('rtconfig') + +cwd = GetCurrentDir() +src = Glob('*.c') + Glob('*_gcc.S') +CPPPATH = [cwd] + +group = DefineGroup('CPU', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/libcpu/rh850/common/context_gcc.S b/libcpu/rh850/common/context_gcc.S new file mode 100644 index 0000000000..7a5086d65d --- /dev/null +++ b/libcpu/rh850/common/context_gcc.S @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#include <rtconfig.h> +#include "rh850_asm.h" +#include "rh850_core.h" + +#if defined(RT_USING_FPU) && RH850_CORE_HAS_SYNCE +#define RH850_SYNCE 1 +#endif +#if defined(RT_USING_FPU) && RH850_CORE_HAS_FPEC +#define RH850_FPEC 1 +#endif + +/* Layout of struct rt_hw_stack_frame */ + .macro SAVE_CONTEXT +#ifdef RH850_SYNCE + /* FPU results and FPI reports are complete before FPSR is read */ + synce +#endif + pushsp r1-r2 + pushsp r4-r31 + add -16, sp + rh850_stsr RH850_SR_EIPC, r10 + st.w r10, 0[sp] + rh850_stsr RH850_SR_EIPSW, r10 + st.w r10, 4[sp] +#ifdef RT_USING_FPU + rh850_stsr RH850_SR_FPSR, r10 + st.w r10, 8[sp] + rh850_stsr RH850_SR_FPEPC, r10 + st.w r10, 12[sp] +#endif + .endm + +/* While FPEC.FPIVD is 1, keep FPEPC and the FPSR cause bits */ + .macro RESTORE_FPU + ld.w 8[sp], r10 +#ifdef RH850_FPEC + rh850_stsr RH850_SR_FPEC, r11 + andi RH850_FPEC_FPIVD, r11, r11 + bz .Lfpu_frame\@ + rh850_stsr RH850_SR_FPSR, r11 + andi RH850_FPSR_XC_MASK, r11, r11 + andi RH850_FPSR_XC_MASK, r10, r12 + xor r12, r10 + or r11, r10 + ldsr r10, RH850_SR_FPSR + br .Lfpu_done\@ +.Lfpu_frame\@: +#endif + ldsr r10, RH850_SR_FPSR + ld.w 12[sp], r10 + ldsr r10, RH850_SR_FPEPC +.Lfpu_done\@: + .endm + + .macro RESTORE_CONTEXT +#ifdef RT_USING_FPU + RESTORE_FPU +#endif + ld.w 4[sp], r10 + ldsr r10, RH850_SR_EIPSW + ld.w 0[sp], r10 + ldsr r10, RH850_SR_EIPC + addi 16, sp, sp + popsp r4-r31 + popsp r1-r2 + eiret + .endm + + .text + + .globl C_SYM(rt_hw_interrupt_disable) + .type C_SYM(rt_hw_interrupt_disable), @function +C_SYM(rt_hw_interrupt_disable): + stsr 5, r10, 0 + di + jmp [lp] + + .globl C_SYM(rt_hw_interrupt_enable) + .type C_SYM(rt_hw_interrupt_enable), @function +C_SYM(rt_hw_interrupt_enable): + andi RH850_PSW_ID, r6, r10 + bnz 1f + ei +1: + jmp [lp] + +/* EP = 1, so that EIRET leaves ISPR as it is */ + .globl C_SYM(rt_hw_context_switch_to) + .type C_SYM(rt_hw_context_switch_to), @function +C_SYM(rt_hw_context_switch_to): + rh850_stsr RH850_SR_PSW, r10 + ori RH850_PSW_EP | RH850_PSW_ID, r10, r10 + ldsr r10, RH850_SR_PSW + ld.w 0[r6], sp + RESTORE_CONTEXT + +/* PSW.ID is 1 here, so a pending FPI of this thread is reported as a fault */ + .globl C_SYM(rt_hw_context_switch) + .type C_SYM(rt_hw_context_switch), @function +C_SYM(rt_hw_context_switch): +#ifdef RH850_FPEC + synce + rh850_stsr RH850_SR_FPEC, r10 + andi RH850_FPEC_FPIVD, r10, r10 + bz 1f + jr C_SYM(rh850_fpi_pending) +1: +#endif + trap 0 + jmp [lp] + + .globl rh850_trap0_entry +rh850_trap0_entry: + SAVE_CONTEXT + st.w sp, 0[r6] + ld.w 0[r7], sp + RESTORE_CONTEXT + +/* Return state and the GCC call-used registers of a nested interrupt */ + .macro SAVE_NESTED +#ifdef RH850_SYNCE + synce +#endif + pushsp r1-r2 + pushsp r5-r19 + pushsp r30-r31 + add -16, sp + rh850_stsr RH850_SR_EIPC, r10 + st.w r10, 0[sp] + rh850_stsr RH850_SR_EIPSW, r10 + st.w r10, 4[sp] +#ifdef RT_USING_FPU + rh850_stsr RH850_SR_FPSR, r10 + st.w r10, 8[sp] + rh850_stsr RH850_SR_FPEPC, r10 + st.w r10, 12[sp] +#endif + .endm + + .macro RESTORE_NESTED +#ifdef RT_USING_FPU + RESTORE_FPU +#endif + ld.w 4[sp], r10 + ldsr r10, RH850_SR_EIPSW + ld.w 0[sp], r10 + ldsr r10, RH850_SR_EIPC + addi 16, sp, sp + popsp r30-r31 + popsp r5-r19 + popsp r1-r2 + eiret + .endm + + .globl rh850_eiint_entry +rh850_eiint_entry: + addi -8, sp, sp + st.w r10, 0[sp] + st.w r11, 4[sp] + mov hilo(C_SYM(rh850_irq_nest)), r10 + ld.w 0[r10], r11 + cmp r0, r11 + ld.w 0[sp], r10 + ld.w 4[sp], r11 + /* movea keeps the flags of cmp */ + movea 8, sp, sp + bne 1f + + SAVE_CONTEXT + mov hilo(C_SYM(rh850_thread_sp)), r10 + st.w sp, 0[r10] + mov hilo(__stack_top), sp + br 2f + +1: + SAVE_NESTED + +2: + mov hilo(C_SYM(rh850_irq_nest)), r10 + ld.w 0[r10], r11 + add 1, r11 + st.w r11, 0[r10] + /* EIIC is read before EI: a nested interrupt overwrites it */ + rh850_stsr RH850_SR_EIIC, r6 + jarl C_SYM(rh850_irq_handle), lp + mov hilo(C_SYM(rh850_irq_nest)), r10 + ld.w 0[r10], r11 + add -1, r11 + st.w r11, 0[r10] + cmp r0, r11 + bne 3f + + mov hilo(C_SYM(rt_thread_switch_interrupt_flag)), r10 + ld.w 0[r10], r11 + cmp r0, r11 + be 4f +#ifdef RH850_FPEC + /* A pending FPI is taken after EIRET: keep the switch for a later exit */ + rh850_stsr RH850_SR_FPEC, r11 + andi RH850_FPEC_FPIVD, r11, r11 + bnz 4f +#endif + st.w r0, 0[r10] + mov hilo(C_SYM(rh850_thread_sp)), r10 + ld.w 0[r10], r11 + mov hilo(C_SYM(rt_interrupt_from_thread)), r10 + ld.w 0[r10], r10 + st.w r11, 0[r10] + mov hilo(C_SYM(rt_interrupt_to_thread)), r10 + ld.w 0[r10], r10 + ld.w 0[r10], sp + /* EIRET with EP = 0 ends the interrupt in ISPR */ + RESTORE_CONTEXT + +4: + mov hilo(C_SYM(rh850_thread_sp)), r10 + ld.w 0[r10], sp + RESTORE_CONTEXT + +3: + RESTORE_NESTED diff --git a/libcpu/rh850/common/cpuport.c b/libcpu/rh850/common/cpuport.c new file mode 100644 index 0000000000..6f4c0859c1 --- /dev/null +++ b/libcpu/rh850/common/cpuport.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#include <rthw.h> +#include <rtthread.h> +#include "rh850_cpu.h" +#include "rh850_core.h" + +#ifdef RT_USING_FPU +#define THREAD_PSW (RH850_PSW_EBV | RH850_PSW_CU0) +#else +#define THREAD_PSW RH850_PSW_EBV +#endif + +volatile rt_ubase_t rt_interrupt_from_thread; +volatile rt_ubase_t rt_interrupt_to_thread; +volatile rt_ubase_t rt_thread_switch_interrupt_flag; + +rt_uint32_t rh850_irq_nest; +rt_ubase_t rh850_thread_sp; + +rt_weak int rt_hw_cpu_id(void) +{ + return 0; +} + +rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter, + rt_uint8_t *stack_addr, void *texit) +{ + struct rt_hw_stack_frame *frame; + rt_ubase_t stk; + + stk = RT_ALIGN_DOWN((rt_ubase_t)stack_addr + sizeof(rt_ubase_t), 8); + frame = (struct rt_hw_stack_frame *)(stk - sizeof(*frame)); + rt_memset(frame, 0, sizeof(*frame)); + + frame->eipc = (rt_ubase_t)tentry; + frame->eipsw = THREAD_PSW; +#ifdef RT_USING_FPU + frame->fpsr = RH850_FPSR_FS; +#endif + frame->FRAME_GPR(6) = (rt_ubase_t)parameter; + frame->FRAME_GPR(31) = (rt_ubase_t)texit; + + return (rt_uint8_t *)frame; +} + +void rt_hw_context_switch_interrupt(rt_ubase_t from, rt_ubase_t to, + rt_thread_t from_thread, + rt_thread_t to_thread) +{ + RT_UNUSED(from_thread); + RT_UNUSED(to_thread); + + if (rt_thread_switch_interrupt_flag == 0) + { + rt_interrupt_from_thread = from; + rt_thread_switch_interrupt_flag = 1; + } + rt_interrupt_to_thread = to; +} + +void rh850_irq_handle(rt_uint32_t eiic) +{ + rt_interrupt_enter(); + rh850_ei(); + rt_hw_interrupt_dispatch(eiic); + rh850_di(); + rt_interrupt_leave(); +} diff --git a/libcpu/rh850/common/rh850_asm.h b/libcpu/rh850/common/rh850_asm.h new file mode 100644 index 0000000000..97ff5b0212 --- /dev/null +++ b/libcpu/rh850/common/rh850_asm.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#ifndef __RH850_ASM_H__ +#define __RH850_ASM_H__ + +#include "rh850_sysreg.h" + +/* GCC v850 puts __USER_LABEL_PREFIX__ ("_") in front of C symbols */ +#define RH850_CAT2(a, b) a##b +#define RH850_CAT(a, b) RH850_CAT2(a, b) +#define C_SYM(s) RH850_CAT(__USER_LABEL_PREFIX__, s) + +/* clang-format off */ +#ifdef __ASSEMBLER__ + .macro rh850_stsr id, sel, reg + stsr \id, \reg, \sel + .endm +#endif +/* clang-format on */ + +#endif diff --git a/libcpu/rh850/common/rh850_cpu.h b/libcpu/rh850/common/rh850_cpu.h new file mode 100644 index 0000000000..546204b2c0 --- /dev/null +++ b/libcpu/rh850/common/rh850_cpu.h @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#ifndef __RH850_CPU_H__ +#define __RH850_CPU_H__ + +#include <rtdef.h> +#include "rh850_sysreg.h" + +#define rh850_stsr_(id, sel) \ + ({ \ + rt_uint32_t v_; \ + __asm__ volatile("stsr %1, %0, %2" : "=r"(v_) : "i"(id), "i"(sel)); \ + v_; \ + }) +#define RH850_STSR(sr) rh850_stsr_(sr) + +rt_inline void rh850_di(void) +{ + __asm__ volatile("di" ::: "memory"); +} + +rt_inline void rh850_ei(void) +{ + __asm__ volatile("ei" ::: "memory"); +} + +rt_inline void rh850_syncp(void) +{ + __asm__ volatile("syncp" ::: "memory"); +} + +rt_inline void rh850_halt(void) +{ + __asm__ volatile("halt" ::: "memory"); +} + +/* Layout of SAVE_CONTEXT in context_gcc.S and of the fault entries */ +struct rt_hw_stack_frame +{ + rt_ubase_t eipc; + rt_ubase_t eipsw; + rt_ubase_t fpsr; + rt_ubase_t fpepc; + rt_ubase_t r31_r4[28]; + rt_ubase_t r2; + rt_ubase_t r1; +}; + +#define FRAME_GPR(n) r31_r4[31 - (n)] + +extern volatile rt_ubase_t rt_interrupt_from_thread; +extern volatile rt_ubase_t rt_interrupt_to_thread; +extern volatile rt_ubase_t rt_thread_switch_interrupt_flag; + +void rt_hw_interrupt_dispatch(rt_uint32_t eiic); + +#endif diff --git a/libcpu/rh850/common/rh850_sysreg.h b/libcpu/rh850/common/rh850_sysreg.h new file mode 100644 index 0000000000..d23bc4d980 --- /dev/null +++ b/libcpu/rh850/common/rh850_sysreg.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#ifndef __RH850_SYSREG_H__ +#define __RH850_SYSREG_H__ + +#define RH850_SR_EIPC 0, 0 +#define RH850_SR_EIPSW 1, 0 +#define RH850_SR_FEPC 2, 0 +#define RH850_SR_FEPSW 3, 0 +#define RH850_SR_PSW 5, 0 +#define RH850_SR_FPSR 6, 0 +#define RH850_SR_FPEPC 7, 0 +#define RH850_SR_FPST 8, 0 +#define RH850_SR_FPCC 9, 0 +#define RH850_SR_EIIC 13, 0 +#define RH850_SR_FEIC 14, 0 +#define RH850_SR_CTPC 16, 0 +#define RH850_SR_EIWR 28, 0 +#define RH850_SR_FEWR 29, 0 +#define RH850_SR_EBASE 3, 1 +#define RH850_SR_INTBP 4, 1 + +#define RH850_PSW_ID 0x00000020 +#define RH850_PSW_EP 0x00000040 +#define RH850_PSW_EBV 0x00008000 +#define RH850_PSW_CU0 0x00010000 + +#endif diff --git a/libcpu/rh850/common/trap.c b/libcpu/rh850/common/trap.c new file mode 100644 index 0000000000..5a6a3c0cf2 --- /dev/null +++ b/libcpu/rh850/common/trap.c @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#include <stdarg.h> +#include <rthw.h> +#include <rtthread.h> +#include "rh850_cpu.h" + +static rt_err_t (*rh850_exception_hook)(void *context); + +void rt_hw_exception_install(rt_err_t (*exception_handle)(void *context)) +{ + rh850_exception_hook = exception_handle; +} + +static void fault_print(const char *fmt, ...) +{ + char buf[96]; + va_list args; + + va_start(args, fmt); + rt_vsnprintf(buf, sizeof(buf), fmt, args); + va_end(args); + rt_hw_console_output(buf); +} + +/* While a switch from an interrupt is held back, "from" still runs */ +static rt_thread_t running_thread(void) +{ + if (rt_thread_switch_interrupt_flag != 0) + { + return rt_container_of((rt_ubase_t *)rt_interrupt_from_thread, + struct rt_thread, sp); + } + + return rt_thread_self(); +} + +static void __attribute__((noreturn)) fault_halt(void *context) +{ + if (rh850_exception_hook != RT_NULL) + { + rh850_exception_hook(context); + } + + for (;;) + { + rh850_halt(); + } +} + +void rh850_fault(rt_uint32_t fe, rt_uint32_t cause, + struct rt_hw_stack_frame *frame) +{ + rt_thread_t thread = running_thread(); + int n; + + fault_print("\n%s exception: cause 0x%08x, thread %s\n", fe ? "FE" : "EI", + cause, thread ? thread->parent.name : "-"); + fault_print("pc 0x%08x psw 0x%08x sp 0x%08x\n", frame->eipc, + frame->eipsw, (rt_ubase_t)(frame + 1)); + fault_print("fpsr 0x%08x fpepc 0x%08x\n", frame->fpsr, frame->fpepc); + fault_print("r1 0x%08x r2 0x%08x\n", frame->r1, frame->r2); + for (n = 4; n <= 31; n += 4) + { + fault_print("r%-2d 0x%08x r%-2d 0x%08x r%-2d 0x%08x r%-2d 0x%08x\n", + n, frame->FRAME_GPR(n), n + 1, frame->FRAME_GPR(n + 1), + n + 2, frame->FRAME_GPR(n + 2), n + 3, + frame->FRAME_GPR(n + 3)); + } + + fault_halt(frame); +} + +void rh850_fpi_pending(rt_ubase_t from) +{ + rt_thread_t thread = + rt_container_of((rt_ubase_t *)from, struct rt_thread, sp); + + fault_print("\nFPI pending at a thread switch: thread %s, fpepc 0x%08x\n", + thread->parent.name, RH850_STSR(RH850_SR_FPEPC)); + + fault_halt(RT_NULL); +} diff --git a/libcpu/rh850/common/vector_gcc.S b/libcpu/rh850/common/vector_gcc.S new file mode 100644 index 0000000000..88f235401d --- /dev/null +++ b/libcpu/rh850/common/vector_gcc.S @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#include <rtconfig.h> +#include "rh850_asm.h" + + .macro vector target + .balign 16 + jr \target + .endm + + .section .vectors, "ax" + .balign 512 + .globl rh850_vectors +rh850_vectors: + vector __start /* 000H RESET */ + vector rh850_fe_fault /* 010H SYSERR */ + vector rh850_fe_fault /* 020H reserved */ + vector rh850_fe_fault /* 030H FETRAP */ + vector rh850_trap0_entry /* 040H TRAP0 */ + vector rh850_ei_fault /* 050H TRAP1 */ + vector rh850_fe_fault /* 060H RIE */ + vector rh850_ei_fault /* 070H FPE, FPI */ + vector rh850_fe_fault /* 080H UCPOP */ + vector rh850_fe_fault /* 090H MIP, MDP */ + vector rh850_fe_fault /* 0A0H PIE */ + vector rh850_fe_fault /* 0B0H reserved */ + vector rh850_fe_fault /* 0C0H MAE */ + vector rh850_fe_fault /* 0D0H reserved */ + vector rh850_fe_fault /* 0E0H FENMI */ + vector rh850_fe_fault /* 0F0H FEINT */ + .rept 16 + vector rh850_eiint_entry /* 100H-1F0H EIINT priority 0-15 */ + .endr + + .text + + .macro FAULT_FRAME pcid, pcsel, pswid, pswsel + pushsp r1-r2 + pushsp r4-r31 + add -16, sp + rh850_stsr \pcid, \pcsel, r10 + st.w r10, 0[sp] + rh850_stsr \pswid, \pswsel, r10 + st.w r10, 4[sp] +#ifdef RT_USING_FPU + rh850_stsr RH850_SR_FPSR, r10 + st.w r10, 8[sp] + rh850_stsr RH850_SR_FPEPC, r10 + st.w r10, 12[sp] +#else + st.w r0, 8[sp] + st.w r0, 12[sp] +#endif + mov sp, r8 + .endm + +rh850_fe_fault: + FAULT_FRAME RH850_SR_FEPC, RH850_SR_FEPSW + mov 1, r6 + rh850_stsr RH850_SR_FEIC, r7 + jr C_SYM(rh850_fault) + +rh850_ei_fault: + FAULT_FRAME RH850_SR_EIPC, RH850_SR_EIPSW + mov 0, r6 + rh850_stsr RH850_SR_EIIC, r7 + jr C_SYM(rh850_fault) diff --git a/libcpu/rh850/g4kh/SConscript b/libcpu/rh850/g4kh/SConscript new file mode 100644 index 0000000000..207ce6cf0f --- /dev/null +++ b/libcpu/rh850/g4kh/SConscript @@ -0,0 +1,13 @@ +# RT-Thread building script for component + +from building import * + +Import('rtconfig') + +cwd = GetCurrentDir() +src = [] +CPPPATH = [cwd] + +group = DefineGroup('CPU', src, depend = [''], CPPPATH = CPPPATH) + +Return('group') diff --git a/libcpu/rh850/g4kh/rh850_core.h b/libcpu/rh850/g4kh/rh850_core.h new file mode 100644 index 0000000000..c8fd9cabe0 --- /dev/null +++ b/libcpu/rh850/g4kh/rh850_core.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#ifndef __RH850_CORE_G4KH_H__ +#define __RH850_CORE_G4KH_H__ + +#include "rh850_sysreg.h" + +#define RH850_CORE_HAS_FPU 1 +#define RH850_CORE_HAS_SYNCE 1 +#define RH850_CORE_HAS_FPEC 1 + +#define RH850_FPSR_FS 0x00020000 +#define RH850_FPSR_RM_SHIFT 18 +#define RH850_FPSR_RM_MASK 0x000c0000 +#define RH850_FPSR_XC_MASK 0x0000fc00 + +#define RH850_SR_FPEC 11, 0 +#define RH850_FPEC_FPIVD 0x00000001 + +#define RH850_SR_MEA 6, 2 +#define RH850_SR_MEI 8, 2 +#define RH850_SR_RBIP 18, 2 + +#define RH850_CORE_MPU_ENTRIES 24 +#define RH850_SR_MCA 8, 5 +#define RH850_SR_MCS 9, 5 +#define RH850_SR_MCR 11, 5 +#define RH850_SR_MCI 12, 5 +#define RH850_SR_MPIDX 16, 5 +#define RH850_SR_MPLA 20, 5 +#define RH850_SR_MPUA 21, 5 +#define RH850_SR_MPAT 22, 5 +#define RH850_SR_MPID0 24, 5 +#define RH850_SR_MPID1 25, 5 +#define RH850_SR_MPID2 26, 5 +#define RH850_SR_MPID3 27, 5 +#define RH850_SR_MPID4 28, 5 +#define RH850_SR_MPID5 29, 5 +#define RH850_SR_MPID6 30, 5 +#define RH850_SR_MPID7 31, 5 + +#define RH850_SR_ICTAGL 16, 4 +#define RH850_SR_ICTAGH 17, 4 +#define RH850_SR_ICDATL 18, 4 +#define RH850_SR_ICDATH 19, 4 +#define RH850_SR_ICERR 28, 4 + +#endif diff --git a/libcpu/rh850/g4kh/rh850_core.inc b/libcpu/rh850/g4kh/rh850_core.inc new file mode 100644 index 0000000000..c809bd651b --- /dev/null +++ b/libcpu/rh850/g4kh/rh850_core.inc @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2026, Linumiz + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2026-11-06 Parthiban first version + */ + +#include "rh850_core.h" + +/* clang-format off */ + + .macro rh850_core_clear_error_regs + ldsr r0, RH850_SR_MEA + ldsr r0, RH850_SR_MEI + ldsr r0, RH850_SR_RBIP + .endm + +/* PSW.CU0 must already be in effect */ + .macro rh850_core_init_fpu tmp + ldsr r0, RH850_SR_FPST + ldsr r0, RH850_SR_FPCC + mov hilo(RH850_FPSR_FS), \tmp + ldsr \tmp, RH850_SR_FPSR + ldsr r0, RH850_SR_FPEPC + .endm + + .macro rh850_core_clear_mpu idx, end + ldsr r0, RH850_SR_MCA + ldsr r0, RH850_SR_MCS + ldsr r0, RH850_SR_MCR + ldsr r0, RH850_SR_MCI + mov r0, \idx + movea RH850_CORE_MPU_ENTRIES, r0, \end +1: + ldsr \idx, RH850_SR_MPIDX + ldsr r0, RH850_SR_MPLA + ldsr r0, RH850_SR_MPUA + ldsr r0, RH850_SR_MPAT + add 1, \idx + cmp \end, \idx + bl 1b + ldsr r0, RH850_SR_MPIDX + ldsr r0, RH850_SR_MPID0 + ldsr r0, RH850_SR_MPID1 + ldsr r0, RH850_SR_MPID2 + ldsr r0, RH850_SR_MPID3 + ldsr r0, RH850_SR_MPID4 + ldsr r0, RH850_SR_MPID5 + ldsr r0, RH850_SR_MPID6 + ldsr r0, RH850_SR_MPID7 + .endm + + .macro rh850_core_clear_icache + ldsr r0, RH850_SR_ICTAGL + ldsr r0, RH850_SR_ICTAGH + ldsr r0, RH850_SR_ICDATL + ldsr r0, RH850_SR_ICDATH + ldsr r0, RH850_SR_ICERR + .endm |
