riscv cpu 移植 rt-thread 需要考虑的内容

rt-rhread 移植 rv32 和 rv64 bsp 的 代码

bsp/riscv32-virt/  		//	和 rv32和rv64 没关系
libcpu/risc-v/common 	// 兼容 rv32 和 rv64 // cpu 通用
libcpu/risc-v/virt32 	// virt32 cpu 独有
libcpu/risc-v/virt64 	// virt64 cpu 独有
libcpu/risc-v/k210 		// k210 64 cpu 独有
libcpu/risc-v/e310 		// e310 ?? cpu 独有
libcpu/risc-v/rv32m1 	// 32位    cpu 独有
    这里以 rv32m1 和 virt64 为例
rv32m1 的 代码比较乱,很多功能放到了 bsp 目录中
	例如 中断处理函数 及  对 rt_tick_increase 的调用
    再次以 virt32 和 virt64为例
// 这里面有一个 fpu , 所以涉及到 fpu 寄存器的设置,保存
riscv32_rtt/libcpu/risc-v/common/cpuport.c 
riscv32_rtt/libcpu/risc-v/virt/tick.c
riscv32_rtt/libcpu/risc-v/common/context_gcc.S
riscv32_rtt/libcpu/risc-v/virt/interrupt_gcc.S
riscv32_rtt/libcpu/risc-v/virt/startup_gcc.S

// 这里面没有 fpu , 所以不涉及到 fpu 寄存器的设置,保存
riscv64_rtt/libcpu/risc-v/virt/cpuport.c
riscv64_rtt/libcpu/risc-v/virt/tick.c
riscv64_rtt/libcpu/risc-v/virt/context_gcc.S
riscv64_rtt/libcpu/risc-v/virt/interrupt_gcc.S
riscv64_rtt/libcpu/risc-v/virt/startup_gcc.S

// 可见 virt rv64 和 virt rv32 的 boot code 和 一级终端处理函数 是差不多的
// 调度 和栈初始化是不大相同的
	// 仔细看了一下栈初始化的区别,也不大
	// 调度区别也不大


// 最大的区别在这里,这里做了 RV64 和 RV32 loadstore 指令的兼容
libcpu/risc-v/virt/cpuport.h
/* bytes of register width  */
#ifdef ARCH_CPU_64BIT
#define STORE                   sd
#define LOAD                    ld
#define REGBYTES                8
#else
#define STORE                   sw
#define LOAD                    lw
#define REGBYTES                4
// error here, not portable
#endif

这些代码需要提供的功能及API

    功能
1. boot 的 第一行代码
2. 一级中断处理函数
3. 调度的 switch_to
4. 时钟中断处理函数 调用调度
    API
需要调用
	rt_tick_increase

需要提供
	rt_hw_context_switch_to
	rt_hw_stack_init
	rt_hw_cpu_shutdown
    具体文件
cpuport.c 中提供
	rt_hw_stack_init
	rt_hw_cpu_shutdown
interrupt_gcc.S 中提供
	一级中断处理函数
interrupt.c & tick.c提供
	二级中断处理函数
context_gcc.S 提供
	rt_hw_interrupt_disable
	rt_hw_interrupt_enable
	rt_hw_context_switch_to
	rt_hw_context_switch
	rt_hw_context_switch_interrupt
	rt_hw_context_switch_exit
	
start.S 提供
	启动的第一行代码
经验分享 程序员 微信小程序 职场和发展