-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeOS.sh
More file actions
executable file
·66 lines (54 loc) · 2.1 KB
/
makeOS.sh
File metadata and controls
executable file
·66 lines (54 loc) · 2.1 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
#!/bin/zsh
#
# SPDX-License-Identifier: 0BSD
# SPDX-FileCopyrightText: © 2026 Sebastian Ritter
#
set -e
# same target like in our Package.swift
export TARGET="aarch64-none-none-elf"
BUILD_DIR=".build"
SWIFT_BUILD_DIR="${BUILD_DIR}/${TARGET}/release"
# compile our Swift
echo "STEP 1: compile Swift kernel..."
swift build -c release --triple ${TARGET}
SWIFT_OBJS=($(find "${SWIFT_BUILD_DIR}" -name "*.swift.o"))
# compile our minimal Assembler
echo "STEP 2: compile Assembler bridge..."
clang -target ${TARGET} -c Sources/Boot/Boot.s -o .build/boot.o
BOOT_OBJS=(
".build/boot.o"
)
# link all together
echo "STEP 3: link all together ..."
clang -target ${TARGET} \
-T Sources/linker.ld \
"${BOOT_OBJS[@]}" "${SWIFT_OBJS[@]}" \
-o "${BUILD_DIR}/kernel.elf" \
-fuse-ld=lld \
-nostdlib \
-static
# optional / on error check symbols - for example if LLVM optimize to hard
#echo "=== binary symbols ==="
#nm "${BUILD_DIR}/kernel.elf" | grep -E "(kmain|_start|swift)"
# optional / on error disassembly kmain - for example if LLVM optimize to hard
#echo "=== kmain disassembly ==="
#llvm-objdump -d "${BUILD_DIR}/kernel.elf" | grep -A 20 "kmain"
# create a flat kernel.bin
echo "STEP 4: get flat kernel.bin"
llvm-objcopy -O binary "${BUILD_DIR}/kernel.elf" "${BUILD_DIR}/kernel.bin"
# with kernel.bin (not kernel.elf) qemu generate a Device Tree Blob and send it to our kernel
echo "STEP 5: start QEMU..."
qemu-system-aarch64 -M virt -cpu cortex-a57 \
-nographic -serial mon:stdio \
-kernel "${BUILD_DIR}/kernel.bin"
# optional create Xcode documentation
echo "STEP 6: create documentation ..."
cp Package.swift "${BUILD_DIR}/"
sed -i '' '/^\/\*START/d; /^END\*\//d' Package.swift
swift package plugin generate-documentation --transform-for-static-hosting --emit-digest --target SOS
cp "${BUILD_DIR}/Package.swift" .
#optional import generated documentation in XCode - remove existing import before
#open .build/plugins/Swift-DocC/outputs/SOS.doccarchive
echo \*\*\* NOTE: import documentation with copy and execute next line \*\*\*
echo open "${BUILD_DIR}/plugins/Swift-DocC/outputs/SOS.doccarchive"
#EOF