blob: 346267cca8a693f826b903030ae2152d0312a782 (
plain)
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
|
#!/bin/sh -e
print_u32() {
printf "\\$(printf %o $(($1&0xFF)))\\$(printf %o $((($1 >> 8)&0xFF)))\\$(printf %o $((($1 >> 16)&0xFF)))\\$(printf %o $((($1 >> 24)&0xFF)))"
}
write_u32() {
print_u32 $1 | dd if=/dev/stdin of=$3 conv=notrunc bs=1 seek=$2 status=none
}
# :Tell hare to use our custom runtime
# and linker scripts (this feature is so simple and neat :))
export HAREPATH=.
# :Tell the linker to add this argument to discard
# unused sections
export LDFLAGS="--gc-sections"
# :Do the build
hare build -X^ -T+x86_64 -T+bios
# :Create a flat binary out of the elf file
# (while also removing the breaking gnu note)
objcopy \
--remove-section .note.gnu.property \
-I elf64-x86-64 -O binary \
--binary-architecture=i386:x86-64 \
boot boot.bin
size=$(stat -c %s boot.bin)
sectors=$((size/512 + 1))
write_u32 1 $((446 + 8)) boot.bin
write_u32 $sectors $((446 + 12)) boot.bin
[ -f boot.img ] && rm boot.img
../gptman/gptman convert boot.bin boot.img
chmod +rw boot.img
bochs
|