Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multicore support, new standard library, etc... #287

Open
wants to merge 588 commits into
base: multicore
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
588 commits
Select commit Hold shift + click to select a range
dd0d278
STABS debug info is deprecated in gcc
Woazboat Sep 6, 2022
0749a2b
Replace x86_64 atomic functions with template using builtin
Woazboat Sep 6, 2022
c0b7f4a
Move arch independent multicore functions to SMP namespace/class
Woazboat Sep 6, 2022
6c1178c
Silence compiler warnings about executable stacks in assembly files
Woazboat Sep 6, 2022
cdbe60d
Export cmake compile commands by default
Woazboat Sep 6, 2022
07b1a89
Conditionally use attribute in klibc new if supported by compiler
Woazboat Sep 6, 2022
78c2294
Set defines to always include int limit macros in klibc header files
Woazboat Sep 6, 2022
3f5a030
Change ArchThreadRegisters forward declaration to match definition as…
Woazboat Sep 6, 2022
2ec6223
Move BootstrapRangeAllocator ctor definition to cpp file
Woazboat Sep 7, 2022
5b3eacb
Move load initrd functions to bootloader module namespace
Woazboat Sep 7, 2022
389bc06
Move system state to separate file, clean up thread state enum + strings
Woazboat Sep 7, 2022
25e29a9
Always print thread list info even if SCHEDULER debug category disabled
Woazboat Sep 7, 2022
f2a065e
Minor refactoring of Thread + UserProcess
Woazboat Sep 7, 2022
55efd4f
Change define to enum in scheduler lock
Woazboat Sep 8, 2022
3ff18bd
Add missing getInstructionPointer function for arm
Woazboat Sep 8, 2022
8066961
Convert arm atomics to templates + conditionally use builtins if poss…
Woazboat Sep 8, 2022
48433ac
Fix 32 bit elf parsing for dwarf debug data
Woazboat Sep 8, 2022
b653cc4
Update libelfin version used in add-debug utility
Woazboat Sep 8, 2022
e1dd64f
Use dwarf-4 debug info everywhere
Woazboat Sep 8, 2022
4c8a6c3
Eliminate 'unknown function' from start of kernel thread backtrace by…
Woazboat Sep 8, 2022
dcfe9fd
Compile utils with c++17
Woazboat Sep 8, 2022
6e8ecf4
Move cpu local storage code into separate files
Woazboat Sep 9, 2022
c3fd052
Split cpu info class into common base class + derived arch dependent …
Woazboat Sep 9, 2022
5d180a9
Add thread runtime to scheduler debug print
Woazboat Sep 9, 2022
fec49ab
Move thread stack top calculation out of function call
Woazboat Sep 9, 2022
687b43d
Fix armv8 timestamp
Woazboat Sep 9, 2022
cb70e19
Reduce assert wait time
Woazboat Sep 12, 2022
e52d17e
Reduce debug output spam when A_INTERRUPTS enabled
Woazboat Sep 12, 2022
234904e
Improve inter-cpu communication and TLB shootdowns
Woazboat Sep 12, 2022
a001153
Deduplicate common x86 ArchMulticore code
Woazboat Sep 13, 2022
53ecfe2
Move arch dependent parts of SMP function call message sending to arc…
Woazboat Sep 14, 2022
f5f9338
Synchronize printing of backtrace debug output between cpu cores on a…
Woazboat Sep 14, 2022
c83ef31
Load kernel debug info for x86_32 from module similar to x86_64
Woazboat Sep 14, 2022
d6814af
Minor cleanup in scheduler
Woazboat Sep 14, 2022
c52710a
Rename AtomicMpScQueue push function
Woazboat Sep 14, 2022
97ad621
Add architecture independent timer tick handler
Woazboat Sep 14, 2022
883470c
Fix debug assert in arm exception handler
Woazboat Sep 14, 2022
fd0141a
Use system timer + cpu local interrupt controller for arm_rpi2 timer …
Woazboat Sep 14, 2022
11daff7
Re-/Store fsbase on context switch
Woazboat Sep 19, 2022
66e65d5
Fix IntervalSet::erase when interval needs to be split as a result
Woazboat Oct 10, 2022
2d0fe29
Change KMM lock from Spinlock to Mutex
Woazboat Oct 13, 2022
d8a41aa
Move thread deschedule code into separate function
Woazboat Oct 13, 2022
32e4c22
Ensure backtrace and kernel panic message are printed consecutively t…
Woazboat Oct 13, 2022
f5a4513
Better lock assert info strings
Woazboat Oct 13, 2022
36fb017
Terminate forked process in shell when exec failed
Woazboat Oct 15, 2022
7a752da
Properly handle file offset on read/write error
Woazboat Oct 16, 2022
e325d8f
Add strnlen_s to userspace libc
Woazboat Oct 17, 2022
e00a15b
Add define for MAP_FIXED mmap flag
Woazboat Oct 17, 2022
7c94690
Add info string for assertion in minixfs readBlocks()
Woazboat Oct 17, 2022
0107bb1
Fix bug in PIC8259 irq masking
Woazboat Oct 21, 2022
485dde3
Common prefix autocompletion for shell
Woazboat Oct 22, 2022
047772d
Fix restoration/use of invalid fsbase on return from interrupt to ker…
Woazboat Oct 29, 2022
952ce66
Fix check whether swapgs is required on interrupt return with error code
Woazboat Oct 29, 2022
e72ccbc
Add gcc malloc attributes to new/delete functions
Woazboat Oct 29, 2022
e792a2f
Add isHeldBy function to BasicSpinLock
Woazboat Oct 29, 2022
50ed4d4
Print thread TID + address in backtrace
Woazboat Oct 29, 2022
f573deb
Optimisation for BlockDeviceInode when read/write size is multiple of…
Woazboat Oct 29, 2022
cd2d64b
Print used kernel memory when max kernel heap size reached
Woazboat Oct 29, 2022
c11ea6b
Add debugAlways debug print macro that always prints regardless of en…
Woazboat Oct 30, 2022
7a3f15b
Pass call location to MutexLock
Woazboat Oct 30, 2022
1a01690
Use debugAlways for user triggered debug prints and prints on assert
Woazboat Oct 30, 2022
14c25f4
Pass call site location from eastl allocations new to KMM
Woazboat Oct 30, 2022
743eb83
Add fake symbols + stack frame to interrupt handler functions to fix …
Woazboat Oct 30, 2022
b09fc03
Fix kprintfd recursion detection
Woazboat Oct 30, 2022
591b3b6
Add nop after enabling interrupts to ensure stack frame is still inta…
Woazboat Nov 1, 2022
7bb3e92
Use per-cpu in_assert flag for assert recursion detection
Woazboat Nov 1, 2022
2408def
Print warning when assert happens in interrupt handler that the asser…
Woazboat Nov 1, 2022
582b8b6
Release assert print lock on assert recursion
Woazboat Nov 1, 2022
953f578
Don't send halt IPI to self on assert just print normal assert debug …
Woazboat Nov 1, 2022
30f38bd
Ensure BasicSpinLock acquire is usable before CLS init
Woazboat Nov 1, 2022
610f5e0
Add debug flag to lock that enables debug prints for chosen locks
Woazboat Nov 1, 2022
b8456bd
Remove too fine grained debug prints in ArchMulticore
Woazboat Nov 1, 2022
7524529
Always start QEMU gdbserver
Woazboat Nov 1, 2022
b40c471
Move I/O APIC code to separate file
Woazboat Nov 1, 2022
4a36afd
Add cpuid functions + supported feature bitset
Woazboat Nov 1, 2022
2f63b14
Minor style fixes
Woazboat Nov 1, 2022
912ed36
Add templated helper class for model specific registers
Woazboat Nov 2, 2022
b349ad3
Define x2APIC registers
Woazboat Nov 2, 2022
73da19b
Lock disk image file while running exe2minixfs
Woazboat Nov 9, 2022
62c8d8f
x2APIC support
Woazboat Nov 9, 2022
59113b8
Use bit_cast
Woazboat Nov 11, 2022
71ff0e4
Type safe register read/write for IoApic
Woazboat Nov 11, 2022
74dc83e
Simplify IoApic redir entry initialization
Woazboat Nov 11, 2022
895708f
Use c++20
Woazboat Nov 13, 2022
c815caa
C++20 coroutine support
Woazboat Nov 13, 2022
6df258e
Add cleandisk target
Woazboat Nov 13, 2022
6e4ef22
Replace external tool calls with cmake builtin tools for cross platfo…
Woazboat Nov 13, 2022
e6b3b5d
Define setInterrupts function
Woazboat Nov 13, 2022
ec46906
Increase kernel heap memory
Woazboat Nov 13, 2022
dceb677
Print currentThread address in syscall
Woazboat Nov 13, 2022
410b6c5
Inherit AllocBlockIterator from eastl::iterator
Woazboat Nov 13, 2022
6d4a3e3
Use enum for ACPI MADT table enumeration
Woazboat Nov 14, 2022
3058b4d
Enable APIC mode in IMCR register on APIC init
Woazboat Nov 14, 2022
ff278ed
Add source_location
Woazboat Nov 22, 2022
7d00ca5
Add SMP:cpu to get cpu info by id
Woazboat Nov 22, 2022
5224ab4
Add debugAdvanced macro to only output debug info when advanced flag …
Woazboat Nov 22, 2022
341e8b6
Add missing sections to kernel linker script
Woazboat Nov 22, 2022
1e65244
Remove duplicate assert.h header file
Woazboat Nov 26, 2022
144d5c9
Mark hdd image and kernel.dbg files as byproducts for cleanup
Woazboat Nov 26, 2022
9cf7740
Add .clang-format file
Woazboat Nov 30, 2022
f51bcfc
Add .clangd lsp server config file
Woazboat Dec 2, 2022
3bfe61a
Add subrange
Woazboat Dec 7, 2022
3085668
Add reverse_view
Woazboat Dec 7, 2022
dd9393b
Assert new returns nonnull if dynamic kmm disabled
Woazboat Dec 7, 2022
97f8055
clang compatibility for inttypes.h
Woazboat Dec 7, 2022
9482b37
Minor fixes for cmake files + some range views
Woazboat Dec 13, 2022
72e860b
Fix EASTL iterator operator* return type to work with non reference t…
Woazboat Dec 13, 2022
764186d
Change EASTL config
Woazboat Dec 13, 2022
a74a790
Change SMP cpu list to static local variable for automatic initializa…
Woazboat Dec 13, 2022
959ec6b
Revamp irq and device + driver handling
Woazboat Dec 13, 2022
041465e
Fix ATA disk interrupts
Woazboat Dec 13, 2022
769004a
Mark kernel.dbg file as build byproduct
Woazboat Dec 13, 2022
305322a
Rename IoApic
Woazboat Dec 14, 2022
5740d1a
Remove empty header
Woazboat Dec 14, 2022
56d5fdb
Iterator traits member types for transform view iterator
Woazboat Dec 14, 2022
37146fb
Function to get bound device list for specialized drivers
Woazboat Dec 14, 2022
d4d8b32
Fix reading of received data in serial port irq handler
Woazboat Dec 14, 2022
a59d6c2
Chunk serial port transmit buffer writes
Woazboat Dec 14, 2022
4a12764
Make CharacterDevices Inodes
Woazboat Dec 14, 2022
a97b554
Add function to get associated inodes for devices
Woazboat Dec 14, 2022
0f6485c
Extract sector size in exe2minixfs into variable
Woazboat Dec 16, 2022
9cb75c1
Remove vfs lock again
Woazboat Dec 16, 2022
702c87b
Make vsnprintf function available to EASTL for string formatting
Woazboat Dec 16, 2022
a98f7d1
Use eastl::to_string for int to string conversion
Woazboat Dec 16, 2022
7d02222
Move MBR definitions out of IDE driver file
Woazboat Dec 16, 2022
f7c4afa
Use vector in FIFO instead of manually allocated array
Woazboat Dec 16, 2022
1a7e66b
Make IDEDriver a DeviceDriver + change BDManager to static singleton
Woazboat Dec 16, 2022
ae0709f
Refactor IDE driver
Woazboat Dec 22, 2022
22d6848
Allow bus specific driver types + probe registered drivers for compat…
Woazboat Dec 29, 2022
3e27270
Convert ProcessRegistry to static local singleton
Woazboat Dec 29, 2022
f25d4db
Convert global file descriptor list instance to static local
Woazboat Dec 29, 2022
d47921f
Virtual destructors for console + minor cleanup
Woazboat Dec 29, 2022
790fc85
Thread cleanup + use unique_ptr for thread registers
Woazboat Dec 30, 2022
22299fa
Add -fno-sync-libcalls compiler flag
Woazboat Dec 30, 2022
8f72f29
Use static emulator debugconsole io port instead of ad-hoc outportb i…
Woazboat Dec 30, 2022
f2615f2
Always inline io port ops
Woazboat Dec 30, 2022
ca3cfe1
Use override where appropriate, remove unnecessary semicolons, etc...
Woazboat Dec 30, 2022
29cce2c
Merge branch 'master' into multicore
Woazboat Dec 30, 2022
5794f79
Use C++ attributes + remove unnecessary typedefs in x86_64 paging-def…
Woazboat Dec 30, 2022
125351d
Add more default IDE controller ports
Woazboat Dec 30, 2022
f6f9ff2
Move ATA command definitions to separate file
Woazboat Dec 30, 2022
4df0b73
Allow use of C++ in userspace
Woazboat Dec 30, 2022
6c29c0f
Compile shell as C++
Woazboat Dec 30, 2022
344d475
Format shell.cpp
Woazboat Dec 30, 2022
1224d7f
Remove preempt protect kprintfd output
Woazboat Dec 30, 2022
574aff7
Use subrange for BootstrapRangeAllocator::freePages range view instea…
Woazboat Dec 30, 2022
8b5628b
Change PageManager instance to static local + return reference
Woazboat Jan 1, 2023
75dd476
Use one generic interrupt entry function
Woazboat Jan 10, 2023
548d17c
Unify interrupt handling on x86_64
Woazboat Jan 13, 2023
60846d0
Keep debug info available for debugger outside of QEMU
Woazboat Jan 17, 2023
67a67ab
Fix nullptr dereference in IrqDomain iterators when intitialized with…
Woazboat Jan 24, 2023
eae0e5b
x86_32 compatibility
Woazboat Feb 25, 2023
3207271
Clean up MSR code
Woazboat Feb 25, 2023
f33f580
Add timer tick debug output
Woazboat Feb 25, 2023
9ed2e0a
Change return value type of Scheduler::getCpuTimerTicks() to size_t
Woazboat Feb 25, 2023
c3ec73c
Clean up TextConsole::consoleSetCharacter
Woazboat Feb 25, 2023
80aad9d
Make KMM functions const nodiscard + minor clean up of fillSegment
Woazboat Feb 25, 2023
742f1b6
Define __UINT64_C if not already defined for clangd compatibility
Woazboat Feb 25, 2023
1d8fbca
Make CpuFeatures::cpuHasFeature const nodiscard
Woazboat Feb 25, 2023
0dccc69
Disable x86_64 poison double float
Woazboat Feb 25, 2023
74b9e39
SerialPort use of FIFO in interrupt is broken
Woazboat Feb 25, 2023
c5df2cf
Reformat ATADriver
Woazboat Feb 25, 2023
79e5e12
Some more files to .gitignore
Woazboat Feb 25, 2023
57c1919
Separate RangeAllocator template from BootstrapRangeAllocator with fi…
Woazboat Feb 28, 2023
e39e52b
Create kernel virtual memory allocator for mapping of MMIO pages
Woazboat Feb 28, 2023
4138fda
Add IDE isDataReady function + debug print changes
Woazboat Feb 28, 2023
55ac0e8
Allow software disabling of detected cpuid features
Woazboat Feb 28, 2023
79cfa08
Remove static IDT pointer object, just create a new one from IDT
Woazboat Feb 28, 2023
7df34a8
Always start qemu with gdbserver in x86_32
Woazboat Feb 28, 2023
a1514a0
x86_32_pae compatibility
Woazboat Mar 1, 2023
4dc48aa
Fix rpi3 userspace compiler flags
Woazboat Mar 2, 2023
d7fca44
Add user console debug print when userspace partition could not be mo…
Woazboat Mar 4, 2023
da3a185
Remove unnecessary line break from debug print
Woazboat Mar 4, 2023
ce94f80
Change IrqDomain internal storage container to vector to allow more c…
Woazboat Mar 4, 2023
9747ab4
Ensure correct drive is selected when reading/writing ATA devices
Woazboat Mar 4, 2023
2cb32a9
Move MasterBootRecord + generic partition detection to common code
Woazboat Mar 4, 2023
7f28fa2
Move platform specific driver initialization to architecture dependen…
Woazboat Mar 4, 2023
068f5e3
Architecture specific block device drivers + use generic partition de…
Woazboat Mar 4, 2023
3b09d0c
aarch64: add irq domains for compatibility
Woazboat Mar 4, 2023
145b6c7
aarch64: compound bit op + assignment on volatiles is deprecated
Woazboat Mar 4, 2023
d2b31df
aarch64: use unique ptr for thread registers for compatibility
Woazboat Mar 4, 2023
afb4d3f
aarch64: Instance variables returned by reference
Woazboat Mar 4, 2023
cb92af4
Fix aarch64 compiler flags + compile with c++20
Woazboat Mar 4, 2023
673b8ea
Add aarch64 kernel virtual mem allocator
Woazboat Mar 4, 2023
7274e04
Remove IDE driver from aarch64 and use specific MMC driver instead
Woazboat Mar 4, 2023
08cf108
Stop compilation with error when compiler not found for arm_rpi2
Woazboat Mar 6, 2023
ecce728
Stop compilation with error when compiler not found for arm_icp
Woazboat Mar 6, 2023
2575f07
Remove interrupt debug output from MBR partition detection
Woazboat Mar 6, 2023
94a6989
minor cleanup
Woazboat Mar 6, 2023
efc00b5
Always start armv8_rpi3 with gdbserver
Woazboat Mar 6, 2023
11a2385
armv7 compatibility
Woazboat Mar 6, 2023
a700a9b
Fix deadlock on armv7 when using static objects
Woazboat Mar 6, 2023
b2c43c2
Add comment about aarch64 bare metal toolchain source
Woazboat Mar 6, 2023
b906309
Adapt ARM integratorcp MMCDriver
Woazboat Mar 6, 2023
c83ae67
Fix x86_32 compatibility
Woazboat Mar 6, 2023
8ce3015
Move IDEDriver to x86 architecture specific code
Woazboat Mar 6, 2023
3c98dd2
Change debug category for MBR partition detection
Woazboat Mar 6, 2023
d459bab
Move more initialization into init thread
Woazboat Mar 6, 2023
ee3c98d
Alloc InitThread on heap to allow it to be deleted
Woazboat Mar 7, 2023
c0df7ba
Call global constructors on startup
Woazboat Mar 7, 2023
3865209
Clean up old interrupt handling code + special casing and use new int…
Woazboat Mar 7, 2023
b82a43b
Define constants for interrupt vectors
Woazboat Mar 8, 2023
8256d12
Move application processor start code from APIC to ArchMulticore
Woazboat Mar 8, 2023
3786d05
Use new interrupt framework for SMP startup delays
Woazboat Mar 8, 2023
1a22ad6
Fix IoApic indentation + consistent use of irq/global system interrupt
Woazboat Mar 8, 2023
ff3b77b
Fix race condition in ATADriver
Woazboat Mar 8, 2023
0f2a2ef
Merge branch 'main' into multicore
Woazboat Mar 10, 2023
d1be536
Merge branch 'main' into multicore
Woazboat Mar 10, 2023
0d7a53a
Adjust debug flags
Woazboat Mar 10, 2023
44f61ea
Move interrupt mapping debug print to InitThread after block device i…
Woazboat Mar 10, 2023
7f17215
Use atomic flag for BDManager::probeIRQ
Woazboat Mar 11, 2023
80652da
Categorize & sort includes + fix missing/order dependent includes
Woazboat Mar 11, 2023
62634a3
Add missing include
Woazboat Mar 11, 2023
9a37026
Fix non-architecture independent printf format flags
Woazboat Mar 11, 2023
d373715
Change InterruptDescriptorTable to static local singleton
Woazboat Mar 11, 2023
fc139cb
Remove unused code
Woazboat Mar 11, 2023
ad5a360
Fix cmake arm_rpi2 qemugdb target
Woazboat Mar 11, 2023
2f5c539
Fix arm_rpi2 boot
Woazboat Mar 11, 2023
7ce63a6
Make SMP cpu list lock a static local singleton
Woazboat Mar 11, 2023
c36d7a8
Better bounds check + clean up userspace
Woazboat Mar 11, 2023
82b0ba9
Fix TextConsole out of bounds access
Woazboat Mar 11, 2023
88929df
Add functions for text mode framebuffer dimensions
Woazboat Mar 11, 2023
87042b1
Add paging initialized parameter to boottime kprintf functions
Woazboat Mar 11, 2023
90df805
Save multiboot framebuffer info
Woazboat Mar 11, 2023
dc336a9
Add PAT MSR defines
Woazboat Mar 11, 2023
18a9e3e
Save bootloader commandline
Woazboat Mar 12, 2023
f8b2378
Fix initial kernel memory mapping size on boot
Woazboat Mar 12, 2023
2393e73
Fix block offset in ATADriver write + improved debug output + debug i…
Woazboat Mar 14, 2023
1ff6845
New bitmap constructor for initialization with existing data
Woazboat Mar 14, 2023
75e0905
Fix infinite recursion on kernel panic
Woazboat Mar 14, 2023
b146551
Loader ELF init debug output
Woazboat Mar 14, 2023
cc4965c
Add partition type list comment to MBR
Woazboat Mar 14, 2023
1877015
Better file system debug output
Woazboat Mar 14, 2023
35fdfb3
Add bitmap byte size function
Woazboat Mar 14, 2023
23b3766
Simplify MinixStorageManager::flush
Woazboat Mar 14, 2023
90da924
Make File/Inode flush() virtual + default forward to inode
Woazboat Mar 14, 2023
0c018e6
Change Initthred debug color to red
Woazboat Mar 14, 2023
810bfe5
Change debug spinner color: user thread = blue, kernel thread = green
Woazboat Mar 14, 2023
1754d42
Return error from UserProcess constructor when initialization failed
Woazboat Mar 14, 2023
b6553dc
Ignore empty commands in shell
Woazboat Mar 14, 2023
589569b
Fix debug format flag for 32 bit multiarch compatibility
Woazboat Mar 14, 2023
ca7e6eb
Remove EASTL tests
Woazboat Mar 14, 2023
76f5d01
Prevent read/write outside of partition in exe2minixfs
Woazboat Mar 15, 2023
60ac14d
Fix backtrace
Woazboat Mar 15, 2023
227cc48
fix typo
daef Mar 17, 2023
03207d0
Fix UB in add-debug libelfin library when calling front() on an empty…
Woazboat Mar 25, 2023
c586289
Fix potential integer overflow in libelfin mmap_loader::load()
Woazboat Mar 25, 2023
614b780
Merge branch 'main' into multicore
Woazboat Apr 27, 2023
ad1b59a
Use __is_convertible builtin in ustl when available
Woazboat Mar 25, 2023
a901873
Merge branch 'main' into multicore
Woazboat May 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true

# Tab indentation required
[Makefile]
indent_style = tab
indent_size = 2

[{*.md,*.rst}]
trim_trailing_whitespace = false
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ sweb.kdev*
.cdtbuild
.idea
cmake-build-*/*
.dir-locals.el

# OS-specific files
*.DS_Store
*Thumbs.db
.directory

GPATH
GRTAGS
GTAGS
166 changes: 79 additions & 87 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
cmake_minimum_required(VERSION 3.5)
cmake_minimum_required(VERSION 3.13)

cmake_policy(SET CMP0079 NEW)

if ("${ARCH}" STREQUAL "")
set (ARCH "x86/64")
endif("${ARCH}" STREQUAL "")
MESSAGE("-- Target architecture: ${ARCH}")

if ("${ARCH}" MATCHES "arm.*")
add_definitions(-DARM)
endif("${ARCH}" MATCHES "arm.*")

# Needs to be set before everything else
set(CMAKE_TOOLCHAIN_FILE arch/${ARCH}/CMakeLists.compiler)

set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

set(BUILD_SHARED_LIBS OFF)

# Include custom CMake modules from the cmake/ subdirectory
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

project(sweb
LANGUAGES C CXX ASM)

add_executable(kernel)
set_target_properties(kernel PROPERTIES OUTPUT_NAME kernel.x)

# https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#interface-libraries
add_library(arch_options INTERFACE)
add_library(kernel_options INTERFACE)
add_library(userspace_options INTERFACE)

target_link_libraries(kernel_options INTERFACE arch_options)
target_link_libraries(userspace_options INTERFACE arch_options)
target_link_libraries(kernel PUBLIC kernel_options)


set(HDD_IMAGE_RAW "SWEB-flat.vmdk")
set(HDD_IMAGE "SWEB.qcow2")
set(INITRD_FILE ${PROJECT_BINARY_DIR}/sweb_initrd)
# set(HDD_IMAGE_FILE ${PROJECT_BINARY_DIR}/SWEB-flat.vmdk)

if ("${ARCH}" STREQUAL "")
set (ARCH "x86/64")
endif("${ARCH}" STREQUAL "")
MESSAGE("-- Target architecture: ${ARCH}")

if ("${ARCH}" MATCHES "arm.*")
add_definitions(-DARM)
endif("${ARCH}" MATCHES "arm.*")

unset(CMAKE_CROSSCOMPILING)
if(APPLE OR WIN32)
Expand All @@ -26,10 +53,6 @@ endif(APPLE OR WIN32)
# add-dbg for userspace binaries
include(AddDebugInfo)

include(arch/${ARCH}/CMakeLists.compiler)

project(sweb
LANGUAGES C CXX ASM)

string(REPLACE "/" ";" ARCH_LIST ${ARCH})
string(REPLACE "/" "_" ARCH_ESC ${ARCH})
Expand Down Expand Up @@ -81,8 +104,6 @@ set(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}")

include(arch/${ARCH}/CMakeLists.include)
include(arch/${ARCH}/CMakeLists.userspace)
string (REPLACE ";" " " KERNEL_CMAKE_C_FLAGS_STR "${KERNEL_CMAKE_C_FLAGS}")
set(CMAKE_ASM_FLAGS ${KERNEL_CMAKE_C_FLAGS_STR})

if(CMAKE_CROSSCOMPILING)
set(CMAKE_CROSS_COMPILE_FLAGS -G "Unix Makefiles")
Expand All @@ -99,133 +120,104 @@ endif()
function(ADD_PROJECT_LIBRARY LIBRARY_NAME)
arch2obj(archobj_libname ${LIBRARY_NAME})

file(GLOB source_files ${SOURCE_WILDCARDS})

set(library_files)

if(source_files)
set(library_files ${source_files})
endif(source_files)

if(archobj_libname)
set(library_files ${library_files} $<TARGET_OBJECTS:${archobj_libname}>)
endif(archobj_libname)

if(library_files)
add_library(${LIBRARY_NAME} ${library_files})

if(archobj_libname)
add_dependencies(${LIBRARY_NAME} ${archobj_libname})
endif(archobj_libname)
file(GLOB source_files CONFIGURE_DEPENDS ${SOURCE_WILDCARDS})

target_compile_options(${LIBRARY_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:${KERNEL_CMAKE_CXX_FLAGS}>
$<$<COMPILE_LANGUAGE:C>:${KERNEL_CMAKE_C_FLAGS}>
)
target_sources(kernel PUBLIC
${source_files})

set(ENV{LIBRARY_NAMES} "$ENV{LIBRARY_NAMES};${LIBRARY_NAME}")
endif(library_files)
target_link_libraries(kernel PUBLIC
${archobj_libname})
endfunction(ADD_PROJECT_LIBRARY)

set (SOURCE_WILDCARDS *.cpp *.c *.S)

set(LIBRARY_FILENAMES)

#Initialize global (environment) variables
# Initialize global (environment) variables
set(ENV{LIBRARY_NAMES})

#Create target for userspace libc (Need to to that here because some files (e.g. syscall.c) are all over the place)
# Build the Linker command
target_link_options(kernel_options INTERFACE
-g -u entry -Wl,-T ${CMAKE_SOURCE_DIR}/arch/${ARCH}/utils/kernel-ld-script.ld ${ARCH_APPEND_LD_ARGUMENTS})


# Create target for userspace libc (Need to to that here because some files (e.g. syscall.c) are all over the place)
add_library(userspace_libc "")
target_compile_options(userspace_libc PUBLIC ${ARCH_USERSPACE_COMPILE_OPTIONS})
target_link_libraries(userspace_libc PUBLIC userspace_options)

#Add the source directories
# Add the source directories
add_subdirectory(arch)
add_subdirectory(common)
add_subdirectory(utils)
add_subdirectory(userspace)
add_subdirectory(lib)

target_link_libraries(kernel_libc PUBLIC kernel_options)
target_link_libraries(kernel PUBLIC kernel_libc)

#FINAL_LIB_NAMES should contain the names of all libraries
#these names can be used to link the kernel, no unpacking of *.a files is needed anymore
# FINAL_LIB_NAMES should contain the names of all libraries
# these names can be used to link the kernel, no unpacking of *.a files is needed anymore
set(FINAL_LIB_NAMES $ENV{LIBRARY_NAMES})

#Name of the executables of the userspace, needed for dependency checking
# Name of the executables of the userspace, needed for dependency checking
set(FINAL_USERSPACE_NAMES $ENV{USERSPACE_NAMES})



#Build the Linker command
set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} -g -u entry -Wl,-T ${CMAKE_SOURCE_DIR}/arch/${ARCH}/utils/kernel-ld-script.ld)
set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} -o ${PROJECT_BINARY_DIR}/kernel.x)
#set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} -Wl,-Map -Wl,${PROJECT_BINARY_DIR}/kernel.map)

set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} -Wl,--start-group)
foreach(libfile ${FINAL_LIB_NAMES})
set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} ${LIBRARY_OUTPUT_PATH}/lib${libfile}.a)
endforeach(libfile)
set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} -Wl,--end-group)
set(KERNEL_LD_ARGUMENT ${KERNEL_LD_ARGUMENT} ${ARCH_APPEND_LD_ARGUMENTS})

#Build userspace exe2minixfs command
# Build userspace exe2minixfs command
set(MINIXFS_ARGUMENT "")
foreach(file $ENV{USERSPACE_NAMES_EXE2MINIX})
list(APPEND MINIXFS_ARGUMENT ${file})
endforeach(file)

file(GLOB userspace_data userspace/data/*)
file(GLOB userspace_data CONFIGURE_DEPENDS userspace/data/*)
foreach(file ${userspace_data})
get_filename_component(datafile ${file} NAME)
list(APPEND MINIXFS_ARGUMENT ${file} ${datafile})
endforeach(file)



#Custom Target: hdd_image
#Creates the hd image and copies all files to it
add_custom_target (hdd_image ALL
DEPENDS kernel_to_image userspace_to_image
COMMAND qemu-img convert -f raw -O qcow2 ${HDD_IMAGE_RAW} ${HDD_IMAGE}
DEPENDS kernel_to_image userspace_to_image
COMMAND qemu-img convert -f raw -O qcow2 ${HDD_IMAGE_RAW} ${HDD_IMAGE}
)

#Custom Command: invoke exe2minixfs and copy boot files to our hd image
add_custom_target (kernel_to_image
DEPENDS blank_hdd_image kernel_image exe2minixfs
DEPENDS blank_hdd_image kernel exe2minixfs mkminixfs userspace_to_image "${HDD_IMAGE_RAW}" "${CMAKE_SOURCE_DIR}/utils/images/menu.lst" # "${INITRD_FILE}"

# x86/32 doesn't generate kernel.dbg
COMMAND ${CMAKE_COMMAND} -E touch "./kernel.dbg"
COMMAND ./exe2minixfs ${HDD_IMAGE_RAW} 32256 "${CMAKE_SOURCE_DIR}/utils/images/menu.lst" boot/grub/menu.lst
./kernel.x boot/kernel.x
./kernel.dbg boot/kernel.dbg
#COMMAND ./mkminixfs "${HDD_IMAGE_RAW}" 1
COMMAND ./exe2minixfs "${HDD_IMAGE_RAW}" 1 "${CMAKE_SOURCE_DIR}/utils/images/menu.lst" boot/grub/menu.lst
$<TARGET_FILE:kernel> boot/kernel.x
./kernel.dbg boot/kernel.dbg
#"${INITRD_FILE}" boot/initrd
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Copying kernel files to image..."
)

#Custom Command: Outputs kernel_image
#Executes the linker command after all libraries where build successfully
if("${ARCH}" MATCHES "armv8")
#For armv8 we need to execute the final linking step twice because after the first time
#The debug info gets extracted and linked in at the second link step
add_custom_target (kernel_image
DEPENDS ${FINAL_LIB_NAMES} add-dbg
COMMAND ${LD_EXECUTABLE} ${KERNEL_LD_ARGUMENT} ${KERNEL_IMAGE_OBJCOPY}
COMMAND ${LD_EXECUTABLE} ${KERNEL_LD_ARGUMENT} ${ADD_LD_ARGUMENT}
WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}
)

else()

add_custom_target (kernel_image
DEPENDS ${FINAL_LIB_NAMES} add-dbg
COMMAND ${LD_EXECUTABLE} ${KERNEL_LD_ARGUMENT} ${KERNEL_IMAGE_OBJCOPY}
WORKING_DIRECTORY ${LIBRARY_OUTPUT_PATH}
)

endif()
add_custom_command (OUTPUT ${INITRD_FILE}
DEPENDS mkminixfs exe2minixfs
COMMAND dd if=/dev/zero of="${INITRD_FILE}" bs=512 count=1024
COMMAND ./mkminixfs -d "${INITRD_FILE}"
COMMAND ./exe2minixfs "${INITRD_FILE}" 0 ${CMAKE_SOURCE_DIR}/README.md README.md
COMMENT "Creating empty initrd..."
)

#Custom Command: invoke exe2minixfs and copy all userspace programs to our hd image second partition
add_custom_target (userspace_to_image
DEPENDS blank_hdd_image ${FINAL_USERSPACE_NAMES} exe2minixfs
DEPENDS blank_hdd_image ${FINAL_USERSPACE_NAMES} exe2minixfs mkminixfs "${HDD_IMAGE_RAW}" # "${INITRD_FILE}"
COMMAND mkdir -p userspace/data
COMMAND cp -f ${CMAKE_SOURCE_DIR}/userspace/data/* ${PROJECT_BINARY_DIR}/userspace/data
COMMAND ./exe2minixfs ${HDD_IMAGE_RAW} 10321920 ${MINIXFS_ARGUMENT}
# COMMAND ./mkminixfs -d "${HDD_IMAGE_RAW}" -p 2
COMMAND ./exe2minixfs "${HDD_IMAGE_RAW}" 2 ${MINIXFS_ARGUMENT}
# COMMAND ./exe2minixfs "${INITRD_FILE}" 0 ${MINIXFS_ARGUMENT}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMENT "Copying userspace programs to image..."
)
Expand Down
5 changes: 2 additions & 3 deletions arch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

include_directories(common/include
target_include_directories(kernel PUBLIC
common/include
../common/include
../common/include/cache
../common/include/console
Expand All @@ -10,9 +11,7 @@ include_directories(common/include
../common/include/fs/unixfs
../common/include/kernel
../common/include/mm
../common/include/ustl
../common/include/util
)

include(${ARCH}/CMakeLists.subfolders)

2 changes: 1 addition & 1 deletion arch/arm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include_directories(
target_include_directories(kernel PUBLIC
common/include
common/include/usb
../${ARCH}/include
Expand Down
Loading