# soc-lab-core364 **Repository Path**: zhushunyi/soc-lab-core364 ## Basic Information - **Project Name**: soc-lab-core364 - **Description**: OpenC910 LoongArch - **Primary Language**: Verilog - **License**: GPL-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2024-06-04 - **Last Updated**: 2024-06-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # OpenC910-LoongArch ## 简介 OpenC910是3译码、4发射、具有先进的12级流水线,乱序执行的超标量处理器。 ## 项目代码结构 - **constraints**: include all vivado project constraints files. - **ext**: this folder include some external rtl projects, this palce all other peripheral code, for example uart, spi, iic, and so on. - **ip**: xilinx ip dir, include it's tcl and makefile script. - **rtl**: this include all centaur320 main rtl verilog code. - **works**: this is main dirctory where vivado run, include some temp .xci and project workspace. - **README**: this file. - **Makefile**: make script. - **Top.lst**: this file contains all verilog file list. ## 下载源代码与安装工具 ### 1. 下载源码 ```shell git clone https://github.com/lyw19b/soc-lab-core364.git ``` ### 2. 安装交叉编译器 ```shell wget https://github.com/LoongsonLab/oscomp-toolchains-for-oskernel/releases/download/gcc-13.2.0-loongarch64/gcc-13.2.0-loongarch64-linux-gnu.tgz tar zxf gcc-13.2.0-loongarch64-linux-gnu.tgz # 在.bashrc中增加交叉编译器路径。假设当前路径为:/opt/gcc-13.2.0-loongarch64-linux-gnu export PATH=${PATH}:/opt/gcc-13.2.0-loongarch64-linux-gnu/bin # 如果配置正确,输入如下命令 loongarch64-linux-gnu-gcc -v #会显示如下: Using built-in specs. COLLECT_GCC=loongarch64-linux-gnu-gcc COLLECT_LTO_WRAPPER=/home/airxs/local/gcc-13.2.0-loongarch64-linux-gnu/bin/../libexec/gcc/loongarch64-linux-gnu/13.2.0/lto-wrapper Target: loongarch64-linux-gnu Configured with: ../configure --prefix=/home/airxs/user/gnu/cross-tools --build=x86_64-cross-linux-gnu --host=x86_64-cross-linux-gnu --target=loongarch64-linux-gnu --with-sysroot=/home/airxs/user/gnu/cross-tools/sysroot --with-mpfr=/home/airxs/user/gnu/cross-tools --with-gmp=/home/airxs/user/gnu/cross-tools --with-mpc=/home/airxs/user/gnu/cross-tools --enable-__cxa_atexit --enable-threads=posix --with-system-zlib --enable-libstdcxx-time --enable-checking=release --enable-default-pie --enable-languages=c,c++,fortran,objc,obj-c++,lto Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.2.0 (GCC) #编译c文件 loongarch64-linux-gnu-gcc main.c -o mian -static ``` ## 如何运行模拟器 我们提供了VCS和Verilator两种模拟环境。 仿真环境选择: > 如果调试内部微架构,测试文件比较小的话,优先选择VCS。VCS可以生成FSDB格式调试文件,配合Verdi 工具 > 能够快速的定位查找出错的位置。 > > > 如何测试大的文件,我们优先选择Verilator,支持多线程仿真,仿真速率快。缺点是生成的VCD格式文件较大(G级别), > 生成的VCD转换成fsdb格式,再使用Verdi来调试。也可使用gtkwave直接查看VCD格式波形图。 > ### 1. 运行用户空间程序Hello hello程序代码在ext/simu-hello,make 可产生相应的ELF可执行文件以及仿真使用的BIN文件。前提是我们完整的安装了交叉编译器。 ```shell cd verif/vcs/hello # 直接运行,打印log信息 make sim # 在编译的时候,VCS直接调用Verdi,可调试 make compile ``` ### 2. 运行 CoreMark coremake 测试程序有两种,一种是直接在没有页表映射的情况下运行,一种是在建立页表的 的情况使用,一遍测试MMU相关功能。具体的代码在ext/simu-coremark-\* make 可产生相应的ELF可执行文件以及仿真使用的BIN文件。 ```shell cd verif/vcs/coremark # 直接运行,打印log信息 make sim # 在编译的时候,VCS直接调用Verdi,可调试 make compile ``` ### 3. 运行 Linux Kernel 运行Linux kernel的时候,由于文件比较大,采用VCS仿真时比较慢,因此采用Verilator。 在ext/simu-kernel的Makefile中,修改KERNEL_DIR,指向模拟使用的linux目录。 编译linux内核: ```shell # 下载用于仿真内核的代码 git clone https://github.com/lyw19b/linux-4.19-labcore-sim.git cd linux-4.19-labcore-sim cp arch/loongarch/configs/soc_lab_core364_sim_deconfig .config make -j ``` ```shell cd verif/verilator/VerSimKernel # 修改配置,在Makefile中,修改CONFIG,指定仿真的配置文件。 # 如果是仿真kernel的话,设置CONFIG := ./config/config.kernel # 在config/config.kernel文件中,kernel=../../../ext/simu-kernel/vmlinux指定位置 # 直接运行,打印log信息 ./build ``` ## 调试 调试平台如前面所示,可以通过参数控制是否生成波形文件FSDB或者VCD。 我们提供了一个verdi使用的配置文件soc_cpu_pipeline_vl.rc,能够提供整个流水线主要的控制信号 以及数据通路,方便我们调试。如下图所示: ![Verdi 调试CPU](doc/img/verdi_debug_cpu_pipeline.png "Verdi 调试CPU") ## FPGA实例化 我们验证的平台是AMD的[VCU118](https://china.xilinx.com/products/boards-and-kits/vcu118.html),具体配置可访问官网。Vivado使用的是2022.2。 ### 编译综合 目前SOC平台支持最大的时钟频率为100MHz,可选择支持不同的时钟频率,可选的为50MHz, 20MHZ。 ```shell # 在项目主目录下,直接编译 make # 运行完成后会在impl/work-xlnx目录下产生所需要的所有文件。 ``` ### 上板运行验证 准备好Linux kernel和busybox的简易Rootfs。此时将FPGA与Vivado正确连接。 ```shell # 在主目录下的Makefile中,修改LINUX_DIR,指向Linux # 生成我们所需要的BIN文件,用于上传的FPGA make vmlinux # 上传生成的BIN文件到DDR,并且复位CPU执行(0x1c000000) make upload ``` 运行情况如下图所示: ![启动Linux内核](doc/img/boot-linux-info.png "启动Linux内核")