Skip to content

Commit 146269c

Browse files
authored
Merge pull request #4945 from wormsX/master
[BSP]: Support QEMU run for Xuantie-E9xx Series CPU.
2 parents 70376d2 + ac824e0 commit 146269c

File tree

11 files changed

+58
-51
lines changed

11 files changed

+58
-51
lines changed

bsp/thead-smart/README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ SMART-EVB is a development board provided by T-HEAD, based on FPGA to provide im
33

44
## The main resources on board are as follows:
55

6-
1. SMART-EVB for E906/E906F/E906FD
6+
1. SMART-EVB for T-Head CPU E9xx Series
77

88
| res | description |
99
| -- | -- |
@@ -25,15 +25,21 @@ SMART-EVB is a development board provided by T-HEAD, based on FPGA to provide im
2525

2626
# Compile T-HEAD BSP
2727
SMART-EVB BSP supports GCC compiler, the version information is:
28-
29-
1. SMART-EVB for E906/E906F/E906FD
28+
1. SMART-EVB for E906/7/F/D/P
3029

3130
| IDE/Compiler| version|
3231
| - | - |
3332
| GCC | gcc version 8.4.0 (C-SKY RISCV Tools V1.9.6 B20200616) |
33+
2. select cpu in rtconfig.py
34+
3. scons -c; scons
3435

35-
# run smart-evb bsp
36+
# Quick start with qemu
37+
1. download qemu
38+
wget https://occ-oss-prod.oss-cn-hangzhou.aliyuncs.com/resource/1356021/1612269502091/csky-qemu-x86_64-Ubuntu-16.04-20210202-1445.tar.gz
39+
2. qemu run
40+
qemu-system-riscv32 -cpu e906fdp -M smartl -kernel rtthread-e9xx.elf -nographic
3641

42+
# Quick start with smart-evb
3743
1. Connect JTAG
3844
2. Connect the serial port
3945
3. riscv64-unknown-elf-gdb rtthread-e906f.elf

bsp/thead-smart/drivers/board.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ extern int __bss_end__;
2323

2424
extern usart_handle_t console_handle;
2525
extern void ioreuse_initial(void);
26-
26+
extern int rt_hw_usart_init(void);
2727

2828
/**
2929
* This function will initial smart-evb board.

bsp/thead-smart/drivers/csi_config.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,7 @@
1313
#ifndef __CSI_CONFIG_H
1414
#define __CSI_CONFIG_H
1515

16-
#define CONFIG_ARCH_RV32 1
17-
#define CONFIG_CPU_E906FD 1
18-
#define CONFIG_RV32_CORETIM 1
19-
#define CONFIG_CHIP_SMARTL_RV32 1
20-
#define CONFIG_BOARD_SMARTL_E906_EVB 1
21-
#define CONFIG_BOARD_NAME_STR "smartl_e906_evb"
16+
#define CONFIG_BOARD_NAME_STR "smart_e906_evb"
2217
#define CONFIG_SUPPORT_TSPEND 1
2318
#define CONFIG_ARCH_INTERRUPTSTACK 4096
2419
#define CONFIG_NEWLIB_WRAP 1

bsp/thead-smart/drivers/system.c

+3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ void systemmap_config(void)
6565
void SystemInit(void)
6666
{
6767
int i;
68+
#if ((CONFIG_CPU_E902 != 1) && (CONFIG_CPU_E902M != 1))
6869
systemmap_config();
70+
#endif
71+
6972
/* enable mstatus FS */
7073
#if (__riscv_flen)
7174
uint32_t mstatus = __get_MSTATUS();

bsp/thead-smart/gdbinit

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ set *(int *)0x40011008=0x0
66
set *(int *)0x4001101c=0x0
77
set disassemble-next-line on
88
show disassemble-next-line
9+
10+
hb Default_Handler
911
lo
12+
c
1013

1114

bsp/thead-smart/rtconfig.h

-14
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@
3838
#define RT_CONSOLEBUF_SIZE 128
3939
#define RT_CONSOLE_DEVICE_NAME "uart1"
4040
#define RT_VER_NUM 0x40003
41-
#define ARCH_RISCV
42-
#define ARCH_RISCV32
43-
#if(__riscv_flen == 64)
44-
#define ARCH_RISCV_FPU
45-
#define ARCH_RISCV_FPU_D
46-
#elif(__riscv_flen == 32)
47-
#define ARCH_RISCV_FPU
48-
#define ARCH_RISCV_FPU_S
49-
#else
50-
#endif
51-
#ifdef __riscv_zp64
52-
#define ARCH_RISCV_DSP
53-
#endif
54-
5541

5642
/* RT-Thread Components */
5743

bsp/thead-smart/rtconfig.py

-6
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,5 @@
6767

6868
CXXFLAGS = CFLAGS
6969

70-
# M_CFLAGS = DEVICE + ' -EL -G0 -O2 -mno-abicalls -fno-common -fno-exceptions -fno-omit-frame-pointer -mlong-calls -fno-pic '
71-
# M_CXXFLAGS = M_CFLAGS
72-
# M_LFLAGS = DEVICE + ' -EL -r -Wl,--gc-sections,-z,max-page-size=0x4' +\
73-
# ' -nostartfiles -static-libgcc'
74-
# M_POST_ACTION = STRIP + ' -R .hash $TARGET\n' + SIZE + ' $TARGET \n'
75-
7670
DUMP_ACTION = OBJDUMP + ' -D -S $TARGET > rtt.asm\n'
7771
POST_ACTION = OBJCPY + ' -O binary $TARGET rtthread.bin\n' + SIZE + ' $TARGET \n'

bsp/thead-smart/theadconfig.h

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef THEAD_CONFIG_H__
2+
#define THAED_CONFIG_H__
3+
4+
#define ARCH_RISCV
5+
#define ARCH_RISCV32
6+
#if(__riscv_flen == 64)
7+
#define ARCH_RISCV_FPU
8+
#define ARCH_RISCV_FPU_D
9+
#elif(__riscv_flen == 32)
10+
#define ARCH_RISCV_FPU
11+
#define ARCH_RISCV_FPU_S
12+
#else
13+
#endif
14+
#ifdef __riscv_zp64
15+
#define ARCH_RISCV_DSP
16+
#endif
17+
18+
#ifdef __riscv_xthead
19+
#ifdef __riscv_xtheade
20+
#define CONFIG_THEAD_EXT_SPUSHEN
21+
#endif
22+
#endif
23+
24+
#endif

libcpu/risc-v/t-head/e9xx/context_gcc.S

+9-17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
22
* Copyright (c) 2006-2018, RT-Thread Development Team
3+
* Copyright (c) 2021, Alibaba Group Holding Limited
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*
67
* Change Logs:
78
* Date Author Notes
89
* 2020/08/20 zx.chen The T-HEAD RISC-V CPU E906 porting implementation
10+
* 2021/08/13 zx.chen update T-HEAD E9xx-series(E906/7/F/D/P) CPU porting code.
911
*/
1012

1113
#include "cpuport.h"
@@ -29,8 +31,6 @@ vPortYield:
2931

3032
ret
3133

32-
33-
3434
/*
3535
* #ifdef RT_USING_SMP
3636
* void rt_hw_context_switch_to(rt_ubase_t to, stuct rt_thread *to_thread);
@@ -56,12 +56,10 @@ rt_hw_context_switch_to:
5656
li t1, 1
5757
STORE t1, (t0)
5858

59-
/* enable mexstatus SPUSHEN and SPSWAPEN */
60-
#if ((CONFIG_CPU_E906==1) || (CONFIG_CPU_E906F==1) || (CONFIG_CPU_E906FD==1))
61-
uint32_t mexstatus;
62-
mexstatus = __get_MEXSTATUS();
63-
mexstatus |= (0x2 << 16);
64-
__set_MEXSTATUS(mexstatus);
59+
/* enable mexstatus SPUSHEN */
60+
#ifdef CONFIG_THEAD_EXT_SPUSHEN
61+
li t0, 0x10000
62+
csrs mexstatus, t0
6563
#endif
6664

6765
csrw mscratch, sp
@@ -140,7 +138,7 @@ PendSV_Handler:
140138
lw t1, (t0)
141139
beqz t1, .switch_to_thead
142140

143-
/* save from thread context */
141+
/* restore from thread context t0,t1 */
144142
lw t0, (-4)(sp)
145143
lw t1, (-8)(sp)
146144

@@ -191,10 +189,6 @@ PendSV_Handler:
191189
csrr x1, mepc
192190
STORE x1, 0 * REGBYTES(sp)
193191
csrr x1, mstatus
194-
andi x1, x1, 8
195-
beqz x1, .save_mpie
196-
li x1, 0x80
197-
.save_mpie:
198192
STORE x1, 2 * REGBYTES(sp)
199193
/* x3 don't need save */
200194
STORE x4, 4 * REGBYTES(sp)
@@ -256,11 +250,9 @@ PendSV_Handler:
256250
csrw mepc, a1
257251
LOAD x1, 1 * REGBYTES(sp)
258252

259-
/* force to machin mode(MPP=11) */
260-
li a1, 0x1880
261-
csrs mstatus, a1
253+
/* force to machine mode(MPP=11) */
262254
LOAD a1, 2 * REGBYTES(sp)
263-
csrs mstatus, a1
255+
csrw mstatus, a1
264256
/* x3 don't need restore */
265257
LOAD x4, 4 * REGBYTES(sp)
266258
LOAD x5, 5 * REGBYTES(sp)

libcpu/risc-v/t-head/e9xx/cpuport.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
22
* Copyright (c) 2006-2021, RT-Thread Development Team
3+
* Copyright (c) 2021, Alibaba Group Holding Limited
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*
67
* Change Logs:
78
* Date Author Notes
89
* 2020/08/20 zx.chen The T-HEAD RISC-V CPU E906 porting code.
10+
* 2021/08/13 zx.chen update T-HEAD E9xx-series(E906/7/F/D/P) CPU porting code.
911
*/
1012

1113
#include <rthw.h>
@@ -143,8 +145,8 @@ rt_uint8_t *rt_hw_stack_init(void *tentry,
143145

144146
rt_base_t rt_hw_interrupt_disable(void)
145147
{
146-
__asm volatile("csrc mstatus, 8");
147-
return 0;
148+
__asm volatile("csrrci a0, mstatus, 8");
149+
return;
148150
}
149151

150152
/**
@@ -154,9 +156,10 @@ rt_base_t rt_hw_interrupt_disable(void)
154156
*
155157
* @return none
156158
*/
159+
/* XXX:rename rt_hw_interrupt_restore? */
157160
void rt_hw_interrupt_enable(rt_base_t level)
158161
{
159-
__asm volatile("csrs mstatus, 8");
162+
__asm volatile("csrw mstatus, a0");
160163
}
161164

162165
/** shutdown CPU */

libcpu/risc-v/t-head/e9xx/cpuport.h

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#define CPUPORT_H__
1313

1414
#include <rtconfig.h>
15+
#include <theadconfig.h>
1516

1617
/* bytes of register width */
1718
#ifdef ARCH_RISCV_64

0 commit comments

Comments
 (0)