Skip to content

Commit

Permalink
feat: libcpu/risc-v: unify low-level bringups
Browse files Browse the repository at this point in the history
This patch consolidates the separated architecture-specific code for
rv64 (virt64 and c906) under a more unified approach. The changes
aim to enhance maintainability and code reuse, reducing duplication
between these two architectures while adding small improvements in
porting compatibility.

Changes:
- Modified build scripts (SConscript) for both virt64 and c906 to
  remove ASID and vector dependencies when not required.
- Updated c906's sbi.c and sbi.h to use standard integer types
  (uint32_t) and include the missing <stdint.h> header.
- Unified inline function declaration for `sbi_call` across both
  c906 and virt64 using `rt_inline`.
- Disabled FPU and vector in c906's startup assembly file, aligning it
  with the virt64 handling.
- Corrected syscall handler type definitions in c906 for consistency.

Signed-off-by: Shell <[email protected]>
  • Loading branch information
polarvid authored and mysterywolf committed Sep 11, 2024
1 parent e244c19 commit c78a19e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
4 changes: 3 additions & 1 deletion libcpu/risc-v/t-head/c906/SConscript
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# RT-Thread building script for component

from building import *

cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S')
CPPPATH = [cwd]

if not GetDepend('ARCH_USING_ASID'):
SrcRemove(src, ['asid.c'])

group = DefineGroup('libcpu', src, depend = [''], CPPPATH = CPPPATH)

Return('group')
4 changes: 2 additions & 2 deletions libcpu/risc-v/t-head/c906/sbi.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ static struct sbi_ret sbi_get_impl_version(void)

void sbi_print_version(void)
{
unsigned int major;
unsigned int minor;
uint32_t major;
uint32_t minor;

/* For legacy SBI implementations. */
if (sbi_spec_version == 0)
Expand Down
3 changes: 2 additions & 1 deletion libcpu/risc-v/t-head/c906/sbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#ifndef _MACHINE_SBI_H_
#define _MACHINE_SBI_H_

#include <stdint.h>
#include <rtdef.h>

/* SBI Specification Version */
Expand Down Expand Up @@ -140,7 +141,7 @@ struct sbi_ret
long value;
};

static inline struct sbi_ret
rt_inline struct sbi_ret
sbi_call(uint64_t arg7, uint64_t arg6, uint64_t arg0, uint64_t arg1,
uint64_t arg2, uint64_t arg3, uint64_t arg4)
{
Expand Down
2 changes: 2 additions & 0 deletions libcpu/risc-v/t-head/c906/startup_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ _start:
li x31,0

/* set to disable FPU */
li t0, SSTATUS_FS + SSTATUS_VS
csrc sstatus, t0
li t0, SSTATUS_SUM
csrs sstatus, t0

Expand Down
2 changes: 1 addition & 1 deletion libcpu/risc-v/t-head/c906/syscall_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "riscv_mmu.h"
#include "stack.h"

typedef rt_size_t (*syscallfunc_t)(rt_size_t, rt_size_t, rt_size_t, rt_size_t, rt_size_t, rt_size_t, rt_size_t);
typedef rt_ubase_t (*syscallfunc_t)(rt_ubase_t, rt_ubase_t, rt_ubase_t, rt_ubase_t, rt_ubase_t, rt_ubase_t, rt_ubase_t);

void syscall_handler(struct rt_hw_stack_frame *regs)
{
Expand Down
10 changes: 6 additions & 4 deletions libcpu/risc-v/virt64/SConscript
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# RT-Thread building script for component

from building import *

Import('rtconfig')

cwd = GetCurrentDir()
src = Glob('*.c') + Glob('*.cpp') + Glob('*_gcc.S')
src = src + ['../common/atomic_riscv.c']
CPPPATH = [cwd]

if not GetDepend('ARCH_USING_ASID'):
SrcRemove(src, ['asid.c'])

if not GetDepend('ARCH_RISCV_VECTOR'):
SrcRemove(src, ['vector_gcc.S'])

group = DefineGroup('libcpu', src, depend = [''], CPPPATH = CPPPATH)

Return('group')
2 changes: 1 addition & 1 deletion libcpu/risc-v/virt64/sbi.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ struct sbi_ret
long value;
};

static __inline struct sbi_ret
rt_inline struct sbi_ret
sbi_call(uint64_t arg7, uint64_t arg6, uint64_t arg0, uint64_t arg1,
uint64_t arg2, uint64_t arg3, uint64_t arg4)
{
Expand Down
3 changes: 2 additions & 1 deletion libcpu/risc-v/virt64/startup_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
* 2018/10/01 Bernard The first version
* 2018/12/27 Jesven Add SMP support
* 2020/6/12 Xim Port to QEMU and remove SMP support
* 2024-06-30 Shell Support of kernel remapping
*/

#include <encoding.h>
#include <cpuport.h>

.data
.global boot_hartid /* global varible rt_boot_hartid in .data section */
boot_hartid:
boot_hartid:
.word 0xdeadbeef

.global _start
Expand Down

0 comments on commit c78a19e

Please sign in to comment.