Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
227 lines (190 loc) · 6.31 KB
/
Copy pathMakefile
File metadata and controls
227 lines (190 loc) · 6.31 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
215
216
217
218
219
220
221
222
223
224
225
226
227
.PHONY: setup image qemu
.EXPORT_ALL_VARIABLES:
setup:
curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none
rustup show
cargo install bootimage
# Compilation options
output = video# video, serial
keyboard = qwerty# qwerty, azerty, dvorak
mode = release
# Emulation options
arch = x86_64# x86_64, i686
cpu = core2duo
smp = 2
memory = 32
nic = rtl8139# rtl8139, pcnet, e1000
snd = sb16# ac97, sb16
audio = sdl# sdl, coreaudio
signal = off# on
kvm = false
pcap = false
trace = false# e1000
monitor = false
bootloader = rust# rust, limine, grub
bootloader-proto = limine# limine, multiboot
export MOROS_VERSION = $(shell git describe --tags | sed "s/^v//")
export MOROS_KEYBOARD = $(keyboard)
user-nasm:
basename -s .s dsk/src/bin/*.s | xargs -I {} \
nasm dsk/src/bin/{}.s -o dsk/bin/{}.tmp
basename -s .s dsk/src/bin/*.s | xargs -I {} \
sh -c "printf '\x7FBIN' | cat - dsk/bin/{}.tmp > dsk/bin/{}"
rm dsk/bin/*.tmp
user-cargo-opts = --release --no-default-features --features userspace
ifeq ($(shell uname -s),Darwin)
user-ld = x86_64-elf-ld
user-strip = x86_64-elf-strip
else
user-ld = ld
user-strip = strip
endif
# Userspace programs are linked inside the user memory region, which lives
# in its own L4 page table entry.
user-ld-opts = -Ttext=8000800000 -Trodata=8000900000 -Tbss=8000950000
user-linker-opts = -C linker=$(user-ld) -C link-args="$(user-ld-opts)" \
-C linker-flavor=ld
user-rust:
basename -s .rs src/bin/*.rs | xargs -I {} \
touch dsk/bin/{}
basename -s .rs src/bin/*.rs | xargs -I {} \
cargo rustc $(user-cargo-opts) --bin {} \
-- $(user-linker-opts)
basename -s .rs src/bin/*.rs | xargs -I {} \
cp target/x86_64-moros/release/{} dsk/bin/{}
basename -s .rs src/bin/*.rs | xargs -I {} \
$(user-strip) dsk/bin/{}
bin = moros-$(arch).img
img = disk.img
$(img):
qemu-img create $(img) 32M
cargo-opts = --bin moros
ifeq ($(mode),release)
cargo-opts += --release
endif
cargo-opts += --no-default-features --features $(output)
# Rebuild MOROS if the features list changed
image: $(img)
touch src/lib.rs
env | grep MOROS
cargo bootimage $(cargo-opts)
cp target/x86_64-moros/$(mode)/bootimage-moros.bin $(bin)
dd conv=notrunc if=$(bin) of=$(img)
qemu-opts = -name "MOROS $$MOROS_VERSION" \
-m $(memory) -smp $(smp) \
-drive file=$(img),format=raw \
-audiodev $(audio),id=a0 -machine pcspk-audiodev=a0 \
-audio driver=$(audio),model=$(snd) \
-netdev user,id=e0,hostfwd=tcp::8080-:80 -device $(nic),netdev=e0
ifeq ($(kvm),true)
qemu-opts += -cpu host -accel kvm
else
qemu-opts += -cpu $(cpu)
endif
ifeq ($(pcap),true)
qemu-opts += -object filter-dump,id=f1,netdev=e0,file=/tmp/qemu.pcap
endif
ifeq ($(monitor),true)
qemu-opts += -monitor telnet:127.0.0.1:7777,server,nowait
endif
ifeq ($(output),serial)
qemu-opts += -display none
qemu-opts += -chardev stdio,id=s0,signal=$(signal) -serial chardev:s0
endif
ifeq ($(mode),debug)
qemu-opts += -s -S
endif
ifeq ($(trace),e1000)
qemu-opts += -trace 'e1000*'
endif
ifeq ($(arch),i686)
qemu = qemu-system-i386
cpu = n270
smp = 1
else ifeq ($(arch),i586)
qemu = qemu-system-i386
qemu-opts += -d int,cpu_reset -D qemu.log -no-reboot -no-shutdown
cpu = pentium
smp = 1
else
qemu = qemu-system-x86_64
endif
# In debug mode, open another terminal with the following command
# and type `continue` to start the boot process:
# > gdb target/x86_64-moros/debug/moros -ex "target remote :1234"
qemu:
$(qemu) $(qemu-opts)
test-opts = --lib
ifeq ($(mode),release)
test-opts += --release
endif
test:
cargo test $(test-opts) --no-default-features --features serial -- \
-m $(memory) -cpu $(cpu) -display none -serial stdio \
-device isa-debug-exit,iobase=0xF4,iosize=0x04 -device $(nic)
limine-version = 11.3.1
limine-url = https://github.com/Limine-Bootloader/Limine/releases/download/v$(limine-version)/limine-$(limine-version).tar.gz
limine-dir = tmp/limine-$(limine-version)
# Require clang llvm lld xorriso nasm
limine-setup:
mkdir -p tmp
wget -O $(limine-dir).tar.gz $(limine-url)
tar xf $(limine-dir).tar.gz -C tmp
cd $(limine-dir) && ./configure --enable-bios --enable-bios-cd && make
cp $(limine-dir)/bin/limine-bios-cd.bin run/boot/limine/
cp $(limine-dir)/bin/limine-bios.sys run/boot/limine/
limine-image: RUSTFLAGS = -C link-arg=-Trun/boot/$(bootloader-proto).ld -C link-arg=-z -C link-arg=norelro
limine-image:
cargo build $(cargo-opts),$(bootloader-proto) --target $(arch)-moros.json
cp target/$(arch)-moros/$(mode)/moros run/boot/kernel.elf
sed -i.old "s/default_entry:.*/default_entry: $(bootloader-proto)/" run/boot/limine/limine.conf
rm run/boot/limine/limine.conf.old
xorriso -as mkisofs \
-b limine/limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
-partition_offset 16 \
--protective-msdos-label \
run/boot -o $(bin)
$(limine-dir)/bin/limine bios-install $(bin)
dd conv=notrunc if=$(bin) of=$(img)
limine-test: RUSTFLAGS = -C link-arg=-Trun/boot/multiboot.ld -C link-arg=-z -C link-arg=norelro
limine-test: LIMINE_DIR = $(limine-dir)
limine-test:
cargo test $(test-opts) --no-default-features --features serial,$(bootloader-proto) --target $(arch)-moros.json -- \
-m $(memory) -cpu $(cpu) -display none -serial stdio \
-device isa-debug-exit,iobase=0xF4,iosize=0x04 -device $(nic)
ifeq ($(shell uname -s),Darwin)
grub = i686-elf-grub
grub-dir = /usr/local/lib/i686-elf/grub/i386-pc/
else
grub = grub
grub-dir = /usr/lib/grub/i386-pc
endif
grub-modules = multiboot2 $(shell cat $(grub-dir)/partmap.lst)
grub-image: RUSTFLAGS = -C link-arg=-Trun/boot/multiboot.ld -C link-arg=-z -C link-arg=norelro
grub-image: $(img)
cargo build $(cargo-opts),multiboot --target $(arch)-moros.json
cp target/$(arch)-moros/$(mode)/moros run/boot/kernel.elf
$(grub)-mkrescue -d $(grub-dir) \
--install-modules="$(grub-modules)" \
--fonts= --locales= --themes= \
-o $(bin) /boot=run/boot
dd conv=notrunc if=$(bin) of=$(img)
website:
make grub-image bootloader-proto=multiboot arch=i686 img=demo.img
cp demo.img www/demo/disk.img
zstd -19 --rm -f www/demo/disk.img -o www/demo/disk.img.zst
sh run/grub-floppy.sh
cp moros-i686-floppy.img www/floppy.img
cd www && sh build.sh
spell:
cd dsk/lib/spell && sh build.sh
pkg:
ls -1 dsk/var/pkg | grep -v index.html > dsk/var/pkg/index.html
pkg-kernel:
cp $(bin) dsk/ini/kernel.img
sh run/deflate.sh dsk/ini/kernel.img
clean:
cargo clean
rm -f www/*.html www/images/*.png
rm -f moros-*.img