-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
125 lines (105 loc) · 4.04 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
set(TOOLCHAIN_PREFIX "/opt/riscv/bin/riscv64-unknown-elf")
set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}-gcc")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++")
set(CMAKE_ASM_COMPILER ${CMAKE_CXX_COMPILER})
set(CMAKE_OBJCOPY "${TOOLCHAIN_PREFIX}-objcopy")
set(CMAKE_OBJDUMP "${TOOLCHAIN_PREFIX}-objdump")
cmake_minimum_required(VERSION 3.13)
project(vcb-riscv VERSION 1.0 LANGUAGES CXX C ASM)
set(CPU_NAME "cpu-v0_1")
set(RAM_SIZE "4096K") # 4096K bytes is max size of VMEM (20 bit address of 32-bit word -> 2^20 * (32/8) = 4096K)
set(DISPLAY_POINTER_ADDRESS "0x3FFFF4")
set(STACK_SIZE "4K")
set(STACK_TOP "0x2FFFFC")
set(LINKER_SCRIPTS "${CMAKE_SOURCE_DIR}/linker_scripts")
set(INIT_ASSEMBLIES "${CMAKE_SOURCE_DIR}/init_assemblies")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build)
set(LINKER_SCRIPT "${LINKER_SCRIPTS}/default.ld")
set(INIT_ASSEMBLY "${INIT_ASSEMBLIES}/default.s")
set(CMAKE_SYSTEM_NAME "Generic")
set(CMAKE_SYSTEM_PROCESSOR "riscv")
set(CMAKE_CROSSCOMPILING 1)
set(COMMON_OPTIONS
-O4
-mabi=ilp32
-march=rv32i
-mstrict-align
-mbranch-cost=2
-mtune=size
# Verbose logging
# --verbose
# -Wl,--verbose
# -Wl,--print-gc-sections
)
set(CMAKE_CXX_STANDARD 20)
add_compile_options(
${COMMON_OPTIONS}
# Include debug symbols (can be used to add source code annotation to disassembly)
-g
)
SET(CMAKE_ASM_FLAGS
)
add_link_options(
${COMMON_OPTIONS}
-nostartfiles
-static
-T ${LINKER_SCRIPT}
-Wl,--defsym=__RAM_SIZE__=${RAM_SIZE}
-Wl,--defsym=__DISPLAY_POINTER_ADDRESS__=${DISPLAY_POINTER_ADDRESS}
-Wl,--defsym=__STACK_SIZE__=${STACK_SIZE}
-Wl,--defsym=__STACK_TOP__=${STACK_TOP}
-Wl,--gc-sections
# Set the text and data sections to be readable and writable. Also, do not page-align the data segment, and disable linking against shared libraries.
-Wl,--omagic
-Wl,--no-warn-rwx-segment
)
# Function to add a disassembly step to a target
function(add_disassembly target)
set(disassembly_output_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.elf.d")
add_custom_command(
COMMENT "Disassembling ${target}"
DEPENDS ${target}
OUTPUT ${disassembly_output_path}
COMMAND ${CMAKE_OBJDUMP} --disassemble --demangle --source $<TARGET_FILE:${target}> > ${disassembly_output_path}
)
add_custom_target("disassemble_${target}" ALL
DEPENDS ${disassembly_output_path}
)
endfunction()
# Function to add a vcbmem generating step to a target
function(add_vcbmem target)
set(disassembly_output_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.elf.d")
set(elf_binary_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.bin")
set(vcbmem_output_path "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${target}.vcbmem")
add_custom_command(
COMMENT "Generating vcbmem for ${target}"
DEPENDS ${target}
OUTPUT ${vcbmem_output_path}
COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${target}> ${elf_binary_path}
COMMAND ${CMAKE_OBJCOPY} -I binary -O binary --reverse-bytes=4 ${elf_binary_path} ${vcbmem_output_path}
COMMAND rm ${elf_binary_path}
)
add_custom_target("vcbmem_${target}" ALL
DEPENDS ${vcbmem_output_path}
)
add_custom_target("cpu_${target}"
COMMENT "Using ${target} program for CPU ${CPU_NAME} vcbmem"
DEPENDS ${vcbmem_output_path} ${disassembly_output_path}
COMMAND cp ${vcbmem_output_path} ${CMAKE_SOURCE_DIR}/${CPU_NAME}.vcbmem
)
endfunction()
# Function to add target for updating .vcb project file
function(add_cpu_config target config_path)
add_custom_target("cpu_config_${target}" ALL
COMMAND ${CMAKE_SOURCE_DIR}/vcb_project_config/update_vcb_project.sh ${CMAKE_SOURCE_DIR}/${CPU_NAME}.vcb ${config_path}
)
endfunction()
include_directories(src)
add_subdirectory(lib/libsimple_font)
add_subdirectory(lib/libsprite)
add_subdirectory(lib/libvdisplay_driver)
add_subdirectory(lib/libvdisplay_sprite)
add_subdirectory(lib/libvinput)
add_subdirectory(src/display_hello)
add_subdirectory(src/fibonacci)
add_subdirectory(riscof)