Compare commits
3 Commits
d6f0499217
...
71dd36c287
Author | SHA1 | Date | |
---|---|---|---|
71dd36c287 | |||
95bebf3312 | |||
452bd1bd57 |
@ -1 +1,2 @@
|
||||
build
|
||||
fw/build
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
||||
build
|
||||
fw/build
|
||||
|
@ -1,3 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(rvscc)
|
||||
include(ExternalProject)
|
||||
|
||||
include_directories(test)
|
||||
ExternalProject_Add(firmware
|
||||
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fw
|
||||
BINARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fw/build
|
||||
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/fw/cmake/riscv-toolchain.cmake
|
||||
STEP_TARGETS build
|
||||
INSTALL_COMMAND ""
|
||||
)
|
||||
|
||||
add_subdirectory(test)
|
||||
|
@ -5,7 +5,7 @@ MAINTAINER Mario Romero <mario@1159.cl>
|
||||
# Install packages
|
||||
RUN echo "http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
|
||||
&& apk update \
|
||||
&& apk add wget git make cmake gcc-riscv-none-elf newlib-riscv-none-elf verilator vim
|
||||
&& apk add build-base wget git make cmake gcc-riscv-none-elf newlib-riscv-none-elf verilator vim
|
||||
|
||||
# Clone the repository
|
||||
WORKDIR /root
|
||||
|
@ -1,6 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(rv32fw)
|
||||
project(firmware)
|
||||
|
||||
add_subdirectory(sandbox)
|
||||
add_subdirectory(test)
|
||||
option(TEST "Enable test firmware compilation" ON)
|
||||
option(SANDBOX_ASM "Enable sandbox compilation using ASM language" OFF)
|
||||
option(SANDBOX_C "Enable sandbox compilation using C language" OFF)
|
||||
|
||||
if (SANDBOX_ASM)
|
||||
add_subdirectory(sandbox/asm)
|
||||
elseif (SANDBOX_C)
|
||||
add_subdirectory(sandbox/c)
|
||||
endif()
|
||||
|
||||
if (TEST)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
@ -1,12 +1,13 @@
|
||||
set(CMAKE_SYSTEM_NAME Generic)
|
||||
|
||||
find_program(RISCV_GCC_FOUND
|
||||
NAMES riscv-none-elf-gcc riscv32-unknown-linux-gnu-gcc)
|
||||
NAMES riscv-none-elf-gcc riscv32-unknown-elf-gcc)
|
||||
|
||||
get_filename_component(GCC_BIN ${RISCV_GCC_FOUND} NAME)
|
||||
|
||||
string(REPLACE gcc "" TOOLCHAIN_PREFIX ${GCC_BIN})
|
||||
|
||||
set(CMAKE_ASM_COMPILER ${TOOLCHAIN_PREFIX}as)
|
||||
set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
|
||||
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
|
||||
set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
|
31
fw/cmake/utils.cmake
Normal file
31
fw/cmake/utils.cmake
Normal file
@ -0,0 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
function(rvscc_bin_to_verilog_mem_file)
|
||||
cmake_parse_arguments(RVSCC
|
||||
""
|
||||
"TARGET"
|
||||
""
|
||||
${ARGN}
|
||||
)
|
||||
add_custom_command(TARGET ${RVSCC_TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJCOPY} -j .text
|
||||
-O verilog
|
||||
--verilog-data-width=1
|
||||
--reverse-bytes=4
|
||||
"$<TARGET_FILE:${RVSCC_TARGET}>" ${RVSCC_TARGET}.mem
|
||||
COMMENT "Invoking: Verilog Hexdump"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function(rvscc_dissasemble)
|
||||
cmake_parse_arguments(RVSCC
|
||||
""
|
||||
"TARGET"
|
||||
""
|
||||
${ARGN}
|
||||
)
|
||||
add_custom_command(TARGET ${RVSCC_TARGET} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJDUMP} -S "$<TARGET_FILE:${RVSCC_TARGET}>" > ${RVSCC_TARGET}.disasm
|
||||
COMMENT "Invoking: Disassemble"
|
||||
)
|
||||
endfunction()
|
@ -1,36 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(sandbox C)
|
||||
|
||||
set(SOURCE_FILES
|
||||
src/main.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-O0
|
||||
-march=rv32id
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
-nostartfiles
|
||||
-static
|
||||
-Wl,-T${CMAKE_SOURCE_DIR}/linker-script.ld
|
||||
-Wl,-z,stack-size=64
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJDUMP} -S "$<TARGET_FILE:${PROJECT_NAME}>" > ${PROJECT_NAME}.disasm
|
||||
COMMENT "Invoking: Disassemble"
|
||||
)
|
||||
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${CMAKE_OBJCOPY} -j .text
|
||||
-O verilog
|
||||
--verilog-data-width=1
|
||||
--reverse-bytes=4
|
||||
"$<TARGET_FILE:${PROJECT_NAME}>" ${PROJECT_NAME}.mem
|
||||
COMMENT "Invoking: Verilog Hexdump"
|
||||
)
|
||||
|
18
fw/sandbox/asm/CMakeLists.txt
Normal file
18
fw/sandbox/asm/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(sandbox_asm ASM)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/utils.cmake)
|
||||
|
||||
set(SOURCE_FILES main.s)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-march=rv32id
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
-T ${CMAKE_CURRENT_SOURCE_DIR}/../../linker-script.ld
|
||||
)
|
||||
|
||||
rvscc_bin_to_verilog_mem_file(TARGET ${PROJECT_NAME})
|
7
fw/sandbox/asm/main.s
Normal file
7
fw/sandbox/asm/main.s
Normal file
@ -0,0 +1,7 @@
|
||||
.section .text
|
||||
.global main
|
||||
|
||||
main:
|
||||
addi t0, t0, 3
|
||||
addi t1, t1, 4
|
||||
add a0, t1, t0
|
25
fw/sandbox/c/CMakeLists.txt
Normal file
25
fw/sandbox/c/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(sandbox_c C)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/utils.cmake)
|
||||
|
||||
set(SOURCE_FILES
|
||||
main.c
|
||||
)
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
|
||||
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-O0
|
||||
-march=rv32id
|
||||
)
|
||||
|
||||
target_link_options(${PROJECT_NAME} PRIVATE
|
||||
-nostartfiles
|
||||
-static
|
||||
-Wl,-T${CMAKE_CURRENT_SOURCE_DIR}/../../linker-script.ld
|
||||
-Wl,-z,stack-size=64
|
||||
)
|
||||
|
||||
rvscc_dissasemble(TARGET ${PROJECT_NAME})
|
||||
rvscc_bin_to_verilog_mem_file(TARGET ${PROJECT_NAME})
|
@ -1,6 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(test ASM)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/../cmake/utils.cmake)
|
||||
|
||||
option(DISSASEMBLY "Enable dissasembly" OFF)
|
||||
|
||||
list(APPEND TEST_SUBDIRS
|
||||
itype
|
||||
@ -8,12 +11,20 @@ list(APPEND TEST_SUBDIRS
|
||||
)
|
||||
|
||||
foreach(TEST_SUBDIR IN LISTS TEST_SUBDIRS)
|
||||
set(TARGET "test-${TEST_SUBDIR}")
|
||||
add_executable(${TARGET} ${TEST_SUBDIR}/main.s)
|
||||
target_link_options(${TARGET} PRIVATE
|
||||
-nostartfiles
|
||||
-static
|
||||
-Wl,-T${CMAKE_SOURCE_DIR}/linker-script.ld
|
||||
-Wl,-z,stack-size=64
|
||||
)
|
||||
set(TEST_TARGET "test-${TEST_SUBDIR}")
|
||||
|
||||
add_executable(${TEST_TARGET} ${TEST_SUBDIR}/main.s)
|
||||
|
||||
target_compile_options(${TEST_TARGET} PRIVATE
|
||||
-march=rv32id
|
||||
)
|
||||
|
||||
target_link_options(${TEST_TARGET} PRIVATE
|
||||
-T ${CMAKE_SOURCE_DIR}/linker-script.ld
|
||||
)
|
||||
|
||||
if(DISSASEMBLY)
|
||||
rvscc_dissasemble(TARGET ${TEST_TARGET})
|
||||
endif()
|
||||
rvscc_bin_to_verilog_mem_file(TARGET ${TEST_TARGET})
|
||||
endforeach()
|
||||
|
Loading…
Reference in New Issue
Block a user