-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
214 lines (179 loc) · 6.99 KB
/
CMakeLists.txt
File metadata and controls
214 lines (179 loc) · 6.99 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.13.0)
cmake_policy(VERSION 3.13.0)
# For IDE users.
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
# Set the RAMFS root
if(NOT DEFINED BADGER_RAMFS_ROOT)
set(BADGER_RAMFS_ROOT ${CMAKE_CURRENT_LIST_DIR}/root)
endif()
# Include the config.
include(.config/config.cmake)
include(config_helper.cmake)
set(CMAKE_C_COMPILER ${CONFIG_COMPILER})
# Include port-specific.
include(cpu/${CONFIG_CPU}/CMakeLists.txt)
# Define options.
config_const(BOOT_PROTOCOL "limine" "Boot protocol")
if("${CONFIG_CPU}" STREQUAL "x86_64")
config_const(ENABLE_ACPI true "Enable ACPI support")
config_const(ENABLE_DTB false "Enable DTB support")
else()
config_bool(ENABLE_ACPI true "Enable ACPI support")
config_bool(ENABLE_DTB true "Enable DTB support")
endif()
config_enum(
STACK_SIZE 262144 "Kernel stack size"
8192 16384 32768 65536 131072 262144
)
config_enum(
TICKS_PER_SEC 500 "How many tick interrupts happen per second"
100 200 250 500 1000
)
config_enum(
MAX_CPUS 32 "Maximum number of usable CPUs (more will be ignored)"
32 64 128 256
)
config_enum(
LOAD_MEASURE_WINDOW 200 "How many ticks to average over for load CPU measurement"
25 50 100 200 500 1000
)
config_const(PAGE_SIZE 4096 "MMU / memory map page size")
config_bool(KTEST false "Run kernel self tests")
set(common_compiler_flags
-ffreestanding -DCHAR_BIT=8 # We do not compile against an OS.
-march=${CONFIG_KISA_SPEC} # Selects the target CPU.
-mabi=${CONFIG_KABI_SPEC} # Selects target ABI
-nodefaultlibs # Do not link any default libraries like libgcc or libc.
-ggdb -gdwarf-2 # Generate debug information in default extended format.
-Werror=return-type # Error when a function doesn't return a value, but declares to do so.
-Werror=implicit-fallthrough
-Werror=int-conversion
-Werror=incompatible-pointer-types
-Werror=implicit-function-declaration
-Wall -Wextra # Ramp up warning level.
-Wno-missing-braces
-std=gnu11 # We use the C11 standard
-DBADGEROS_KERNEL=1 # Tell the code we're building for the kernel
-DBADGEROS_MALLOC_DEBUG_LEVEL=2 # Malloc debug level set to WARN
-DSOFTBIT # Turn on our emulated bit operations
-fno-omit-frame-pointer # Always use frame pointer
-static
-ffunction-sections
-fno-stack-protector
-fno-exceptions
-Wno-unused-parameter
)
if(CMAKE_BUILD_TYPE STREQUAL "Release")
message("Building in release mode")
list(APPEND common_compiler_flags -O2)
else()
message("Building in debug mode")
list(APPEND common_compiler_flags -O0)
endif()
# we must pass the same options to GCC and LD when using LTO, as the linker will actually do the codegen
add_compile_options(${common_compiler_flags} ${cpu_flags})
add_link_options(
${common_compiler_flags} ${cpu_flags} ${cpu_link}
-Wl,--gc-sections -Wl,--build-id=none -nodefaultlibs -nostartfiles
-T${CMAKE_CURRENT_LIST_DIR}/misc/ld/${CONFIG_CPU}.ld
)
# Define executable.
project(badgeros C ASM)
set(kernel_src
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/arrays.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/badge_format_str.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/badge_strings.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/fifo.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/hash.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/list.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/log.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/map.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/num_to_str.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/radixtree.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/rawprint.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/refcount.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/set.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/spinlock.c
${CMAKE_CURRENT_LIST_DIR}/src/badgelib/nanoprintf.c
${CMAKE_CURRENT_LIST_DIR}/src/boot/${CONFIG_BOOT_PROTOCOL}.c
${CMAKE_CURRENT_LIST_DIR}/src/device/builtin_driver/pcie.c
${CMAKE_CURRENT_LIST_DIR}/src/device/class/block.c
${CMAKE_CURRENT_LIST_DIR}/src/device/class/char.c
${CMAKE_CURRENT_LIST_DIR}/src/device/class/pcictl.c
${CMAKE_CURRENT_LIST_DIR}/src/device/class/tty.c
${CMAKE_CURRENT_LIST_DIR}/src/device/builtin_drivers.c
${CMAKE_CURRENT_LIST_DIR}/src/device/device.c
${CMAKE_CURRENT_LIST_DIR}/src/freestanding/int_routines.c
${CMAKE_CURRENT_LIST_DIR}/src/freestanding/string.c
${CMAKE_CURRENT_LIST_DIR}/src/malloc/malloc.c
${CMAKE_CURRENT_LIST_DIR}/src/malloc/static-buddy-compat.c
${CMAKE_CURRENT_LIST_DIR}/src/malloc/slab-alloc.c
${CMAKE_CURRENT_LIST_DIR}/src/mem/mod.c
${CMAKE_CURRENT_LIST_DIR}/src/errno.c
${CMAKE_CURRENT_LIST_DIR}/src/page_alloc.c
)
set(kernel_include
${CMAKE_CURRENT_LIST_DIR}/lib/nanoprintf
${CMAKE_CURRENT_LIST_DIR}/include
${CMAKE_CURRENT_LIST_DIR}/include/badgelib
${CMAKE_CURRENT_LIST_DIR}/.config
)
if(${CONFIG_ENABLE_ACPI})
include(lib/uacpi/uacpi.cmake)
set(kernel_src ${kernel_src}
${CMAKE_CURRENT_LIST_DIR}/src/device/uacpi_kernel_api.c
${UACPI_SOURCES}
)
set(kernel_include ${kernel_include} ${UACPI_INCLUDES})
endif()
if(${CONFIG_ENABLE_DTB})
include(lib/uacpi/uacpi.cmake)
set(kernel_src ${kernel_src}
${CMAKE_CURRENT_LIST_DIR}/src/device/dtb/dtb.c
${CMAKE_CURRENT_LIST_DIR}/src/device/dtb/dtparse.c
)
set(kernel_include ${kernel_include} ${UACPI_INCLUDES})
endif()
add_executable(badger-os.elf
${kernel_src}
${cpu_src}
)
include_directories(
${kernel_include}
${cpu_include}
)
# Export configs in a way visible to Rust.
set(RUST_CONFIG_FILE "")
foreach(config_name ${ALL_CONFIGS})
set(RUST_CONFIG_FILE "${RUST_CONFIG_FILE}cmake_config!(${config_name}, ${CONFIG_${config_name}});")
endforeach()
file(CONFIGURE OUTPUT "cmake_config.rs" CONTENT "${RUST_CONFIG_FILE}")
# Integrate Rust.
set(rust_features)
if(${CONFIG_KTEST})
set(rust_features ${rust_features} --features=ktest)
endif()
if(${CONFIG_ENABLE_ACPI})
set(rust_features ${rust_features} --features=acpi)
endif()
if(${CONFIG_ENABLE_DTB})
set(rust_features ${rust_features} --features=dtb)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(rust_features ${rust_features} --release)
set(rust_build_type release)
else()
set(rust_build_type debug)
endif()
set(rust_target ${CMAKE_CURRENT_LIST_DIR}/misc/rust_target/${CONFIG_CPU}-kernel.json)
set(rust_lib ${CMAKE_CURRENT_LIST_DIR}/target/${CONFIG_CPU}-kernel/${rust_build_type}/libkernel.a)
add_custom_target(
rust.target ALL
cargo build ${rust_features} --target=${rust_target}
)
add_dependencies(badger-os.elf rust.target)
target_link_libraries(badger-os.elf PRIVATE -Wl,--whole-archive ${rust_lib} -Wl,--no-whole-archive)
# Copy the BadgerOS binary to the output directory.
install(TARGETS badger-os.elf DESTINATION .)