-
Notifications
You must be signed in to change notification settings - Fork 0
/
Setup
88 lines (76 loc) · 2.2 KB
/
Setup
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
#!/usr/bin/setup -f
declare BUILD=.build SRC=src
declare -g OMEGA_PREFIX="$SETUP_PREFIX"
declare -a sources=( $(find "$SRC" -name '*.c' -o -name '*.s') )
declare -a objects=( "${sources[@]/#$SRC\//$BUILD/}" )
objects=( "${objects[@]/%/.o}" )
declare arg
declare -a o_files=( )
prepare "$BUILD/constants.S" = Omega.ASMConstants "$SRC/constants.h"
prepare "$BUILD/ld.conf" = Omega.LD.conf "$SRC/constants.h"
for arg in boot/kmain.S "${sources[@]#$SRC/}"; do
case "$arg" in
*.s|*.S) prepare "$BUILD/$arg.o" = Omega.ASM "$SRC/$arg" "$BUILD/constants.S" -felf32;;
*.c) prepare "$BUILD/$arg.o" = Omega.CC "$SRC/$arg";;
esac
o_files+=( "$BUILD/$arg.o" )
done
prepare "$BUILD/kernel.bin" = Omega.LD "$BUILD/ld.conf" "${o_files[@]}"
prepare "$BUILD/bootsector.bin" = Omega.ASM "$SRC/boot/bootsector.S" "$BUILD/constants.S"
prepare "$BUILD/Omega.img" = Omega.IMG "$BUILD/"{bootsector,kernel}".bin"
if Setup.params -package; then
Setup.use Pkg
Pkg.package Pkg.files usr/share/omega/Omega.img=.build/Omega.img
fi
function Omega.IMG() {
local out="$1" ; shift
local bootsect="$1" kernel="$2"
mkpdir "$out"
cat "$bootsect" "$kernel" /dev/zero 2> /dev/null \
| dd if='/dev/stdin' of="$out" bs=512 count=128 conv=notrunc 2> /dev/null
}
function Omega.ASMConstants() { mkpdir "$1"; sed -rn 's/^#define/%define/p' "$2" > "$1"; }
function Omega.ASM() {
mkpdir "$1"
nasm -i "${OMEGA_PREFIX}.build/" -i "${OMEGA_PREFIX}src/" $4 "$2" -o "$1"
}
function Omega.CC() {
mkpdir "$1"
gcc -Werror -Wall -Wno-char-subscripts -fno-builtin -nostdlib -Os -m32 -c -I"${OMEGA_PREFIX}src" "$2" -o "$1"
}
function Omega.LD() {
local out="$1" ; shift
local script="$1"; shift
mkpdir "$out"
ld -T "$script" -m elf_i386 -o "$out" "$@"
}
function Omega.LD.conf() {
local src="$2"
local entry="$(sed -rn 's/#define\s+KERNEL_START\s+//p' "$src")"
mkpdir "$1"
cat > "$1" <<EOF
OUTPUT_FORMAT("binary")
SECTIONS
{
. = $entry;
.text : {
KERNEL_CODE = .;
*(.text)
*(.rodata)
}
.data ALIGN(8) : {
KERNEL_DATA = .;
*(.data)
}
.bss ALIGN(8) : {
KERNEL_BSS = .;
*(.bss)
}
KERNEL_END = .;
}
EOF
}
# Local Variables:
# mode: shell-script
# sh-shell: bash
# End: