[Modified] reorganize the project
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
|
.vscode/
|
||||||
build/
|
build/
|
||||||
@@ -1,26 +1,72 @@
|
|||||||
cmake_minimum_required(VERSION 3.12)
|
cmake_minimum_required(VERSION 3.12)
|
||||||
cmake_policy(SET CMP0074 NEW)
|
cmake_policy(SET CMP0074 NEW)
|
||||||
project(lacpu)
|
project(neula)
|
||||||
|
|
||||||
# set environment variables for verilator
|
# 为 Verilator 设置环境变量
|
||||||
# remove if already install one
|
if(NOT DEFINED VERILATOR_ROOT)
|
||||||
set(verilator_DIR "/home/blur/gits/verilator")
|
set(ENV{VERILATOR_ROOT} "/home/blur/gits/verilator")
|
||||||
set(ENV{VERILATOR_ROOT} ${verilator_DIR})
|
endif()
|
||||||
|
|
||||||
find_package(verilator)
|
# 设置编译器参数
|
||||||
|
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
|
||||||
|
message("Turn On Debugger")
|
||||||
|
add_compile_options(-D DEBUG_MODE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
# ----- ----- 构建虚拟外设 ----- -----
|
||||||
|
set(LABUS labus)
|
||||||
|
set(LA_BUS_TARGET ${PROJECT_NAME}-bus)
|
||||||
|
|
||||||
|
# 包含头文件,以可以利用尖括号获取,辅助队友开发
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/${LABUS}/include)
|
||||||
|
|
||||||
|
# 获取所有的 CXX 源文件
|
||||||
|
file(GLOB_RECURSE LABUS_SRC ${CMAKE_SOURCE_DIR}/${LABUS}/*.cc)
|
||||||
|
|
||||||
|
add_library(${LA_BUS_TARGET} ${LABUS_SRC})
|
||||||
|
link_libraries(${LA_BUS_TARGET})
|
||||||
|
|
||||||
|
|
||||||
|
# ----- ----- 构建虚拟处理器 ----- -----
|
||||||
|
set(LASIM lasim)
|
||||||
|
set(LA_SIM_TARGET ${PROJECT_NAME}-sim)
|
||||||
|
|
||||||
|
# 包含头文件,以可以利用尖括号获取,辅助队友开发
|
||||||
|
include_directories(${CMAKE_SOURCE_DIR}/${LASIM}/include)
|
||||||
|
|
||||||
|
# 获取所有的 CXX 源文件
|
||||||
|
file(GLOB_RECURSE LASIM_SRC ${CMAKE_SOURCE_DIR}/${LASIM}/*.cc)
|
||||||
|
|
||||||
|
add_executable(${LA_SIM_TARGET} ${LASIM_SRC})
|
||||||
|
|
||||||
|
|
||||||
|
# ----- ----- 构建操作系统 ----- -----
|
||||||
|
set(LAOS laos)
|
||||||
|
add_subdirectory(${LAOS})
|
||||||
|
|
||||||
|
|
||||||
|
# ----- ----- 构建 Verilator 项目 ----- -----
|
||||||
|
set(LACPU lacpu)
|
||||||
|
set(LAVSIM lavsim)
|
||||||
|
set(LA_VSIM_TARGET ${PROJECT_NAME}-vsim)
|
||||||
|
|
||||||
|
include_directories(${verilator_DIR}/include)
|
||||||
|
|
||||||
|
find_package(verilator HINTS $ENV{VERILATOR_ROOT} ${VERILATOR_ROOT})
|
||||||
|
|
||||||
if (NOT verilator_FOUND)
|
if (NOT verilator_FOUND)
|
||||||
message(FATAL_ERROR "Verilator was not found.")
|
message(FATAL_ERROR "Verilator was not found.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# set default top module as top file
|
# set default top module as top file
|
||||||
set(VSRC ${CMAKE_SOURCE_DIR}/vsrc/top.v)
|
set(VSRC ${CMAKE_SOURCE_DIR}/${LACPU}/top.v)
|
||||||
|
|
||||||
# get all cxx source files from cxxsrc
|
# get all cxx source files from lavsim folder
|
||||||
file(GLOB_RECURSE CXXSRC ${CMAKE_SOURCE_DIR}/cxxsrc/*.cc)
|
file(GLOB_RECURSE LAVSIM_SRC ${CMAKE_SOURCE_DIR}/${LAVSIM}/*.cc)
|
||||||
|
|
||||||
add_executable(${CMAKE_PROJECT_NAME} ${CXXSRC})
|
add_executable(${LA_VSIM_TARGET} ${LAVSIM_SRC})
|
||||||
|
|
||||||
verilate(${CMAKE_PROJECT_NAME}
|
verilate(${LA_VSIM_TARGET}
|
||||||
INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/vsrc ${verilator_DIR}/include
|
INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/${LACPU} ${VERILATOR_ROOT}/include
|
||||||
SOURCES ${VSRC})
|
SOURCES ${VSRC})
|
||||||
34
README.md
34
README.md
@@ -1,3 +1,33 @@
|
|||||||
# neulacpu
|
# LoongArch CPU
|
||||||
|
|
||||||
loongarch cpu development repo
|
龙芯处理器设计
|
||||||
|
|
||||||
|
## 文件组织建议
|
||||||
|
|
||||||
|
|文件夹名称|文件夹用处|
|
||||||
|
|-|-|
|
||||||
|
|lacpu | 龙芯处理器设计 Verilog |
|
||||||
|
|lasim | 龙芯模拟 软件模拟 C++ |
|
||||||
|
|lavsim | 龙芯模拟 Verilator 模拟 |
|
||||||
|
|labus | 龙芯虚拟外设 |
|
||||||
|
|laos | 龙芯操作系统 |
|
||||||
|
|
||||||
|
除了 `lavsim` 和 `lacpu` 是在一起编译成一个文件,其余都会编译成单独的二进制文件
|
||||||
|
|
||||||
|
### lacpu
|
||||||
|
|
||||||
|
### lasim
|
||||||
|
|
||||||
|
`lasim` 模拟龙芯行为,主要用于操作系统的软件模拟,通过软件角度对龙芯的基本硬件特性进行模拟,以辅助操作系统设计。
|
||||||
|
|
||||||
|
### lavsim
|
||||||
|
|
||||||
|
`lavsim` 主要用于测试 Verilog 设计的正确性。
|
||||||
|
|
||||||
|
### labus
|
||||||
|
|
||||||
|
`labus` 模拟外设行为,主要用于设计虚拟外设以软件模拟外设行为是否正确。
|
||||||
|
|
||||||
|
### laos
|
||||||
|
|
||||||
|
`laos` 自主设计操作系统,会参考其他项目进行设计。
|
||||||
1
labus/include/sysbus.hh
Normal file
1
labus/include/sysbus.hh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
int fetch();
|
||||||
3
labus/sysbus.cc
Normal file
3
labus/sysbus.cc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
int fetch() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
14
lacpu/top.v
Normal file
14
lacpu/top.v
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
// DESCRIPTION: Verilator: Verilog example module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2017 by Wilson Snyder.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
// See also https://verilator.org/guide/latest/examples.html"
|
||||||
|
|
||||||
|
module top;
|
||||||
|
initial begin
|
||||||
|
$display("Hello World!");
|
||||||
|
$finish;
|
||||||
|
end
|
||||||
|
endmodule
|
||||||
8
laos/CMakeLists.txt
Normal file
8
laos/CMakeLists.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
|
set(LA_OS_TARGET ${PROJECT_NAME}-os)
|
||||||
|
|
||||||
|
# get all cxx source files from lasim folder
|
||||||
|
file(GLOB_RECURSE LAOS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.c)
|
||||||
|
|
||||||
|
add_executable(${LA_OS_TARGET} ${LAOS_SRC})
|
||||||
11
lasim/main.cc
Normal file
11
lasim/main.cc
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include <sysbus.hh>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
fetch();
|
||||||
|
#ifdef DEBUG_MODE
|
||||||
|
std::cout << "Hello" << std::endl;
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
0
lasim/spec.cc
Normal file
0
lasim/spec.cc
Normal file
46
lavsim/main.cc
Normal file
46
lavsim/main.cc
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
// DESCRIPTION: Verilator: Verilog example module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||||
|
// any use, without warranty, 2017 by Wilson Snyder.
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
//======================================================================
|
||||||
|
|
||||||
|
// Include common routines
|
||||||
|
#include <verilated.h>
|
||||||
|
|
||||||
|
// Include model header, generated from Verilating "top.v"
|
||||||
|
#include "Vtop.h"
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
// See a similar example walkthrough in the verilator manpage.
|
||||||
|
|
||||||
|
// This is intended to be a minimal example. Before copying this to start a
|
||||||
|
// real project, it is better to start with a more complete example,
|
||||||
|
// e.g. examples/c_tracing.
|
||||||
|
|
||||||
|
// Construct a VerilatedContext to hold simulation time, etc.
|
||||||
|
VerilatedContext* contextp = new VerilatedContext;
|
||||||
|
|
||||||
|
// Pass arguments so Verilated code can see them, e.g. $value$plusargs
|
||||||
|
// This needs to be called before you create any model
|
||||||
|
contextp->commandArgs(argc, argv);
|
||||||
|
|
||||||
|
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
|
||||||
|
Vtop* top = new Vtop{contextp};
|
||||||
|
|
||||||
|
// Simulate until $finish
|
||||||
|
while (!contextp->gotFinish()) {
|
||||||
|
|
||||||
|
// Evaluate model
|
||||||
|
top->eval();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Final model cleanup
|
||||||
|
top->final();
|
||||||
|
|
||||||
|
// Destroy model
|
||||||
|
delete top;
|
||||||
|
|
||||||
|
// Return good completion status
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
module top (
|
|
||||||
input wire i_x,
|
|
||||||
output wire o_y
|
|
||||||
);
|
|
||||||
assign o_y = i_x;
|
|
||||||
endmodule
|
|
||||||
Reference in New Issue
Block a user