forked from abanu-org/abanu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
abctl
executable file
·531 lines (435 loc) · 10 KB
/
abctl
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
#!/bin/bash
cd $(dirname $0)
function loadenv {
source env/$1
}
loadenv unix
mkdir -p $ABANU_OSDIR
mkdir -p $ABANU_LOGDIR
mkdir -p $ABANU_TMPDIR
mkdir -p $ABANU_ISODIR
#dd if=/dev/zero of=/tmp/network-disk.img bs=10M count=1
#touch tmp/network-disk.img
if [ ! -f $ABANU_TMPDIR/network-disk.img ]; then
dd if=/dev/zero of=$ABANU_TMPDIR/network-disk.img bs=10M count=1
fi
loadenv auto
#set -x
rm -f os/*.lock
function configure {
case $1 in
all)
configure patch apply
;;
external)
git clone --recursive git@github.com:abanu-org/abanu-tools.git tools
;;
git)
git remote set-url origin git@github.com:abanu-org/abanu.git
cd external/MOSA-Project
git remote set-url origin git@github.com:arakis/MOSA-Project.git
git remote add upstream https://github.com/mosa/MOSA-Project.git 2> /dev/null
git remote add tgiphil https://github.com/tgiphil/MOSA-Project.git 2> /dev/null
git fetch origin
git fetch upstream
git fetch tgiphil
cd ../..
;;
patch)
patch ${@:2}
;;
mosa)
external/MOSA-Project/Source/Compile.sh
;;
packages)
cd external/MOSA-Project/Source;
rm -rf packages
${nuget} restore Mosa.Tool.Mosactl.sln
${nuget} restore Mosa.sln
cd ../../..
${nuget} restore src/Abanu.Tools.sln
${nuget} restore src/Abanu.Kernel.sln
;;
*)
echo $"Usage: abctl configure {all|patch|mosa|packages|git}"
exit 1
esac
}
function clean {
loadenv unix
case $1 in
all)
clean packages
clean bin
clean os
clean logs
;;
bin)
rm -rf bin
rm -rf external/MOSA-Project/bin
find src -type d -name "bin" -exec rm -rf {} \;
;;
logs)
rm -rf logs
;;
obj)
find . -type d -name "obj" -exec rm -rf {} \;
;;
os)
rm -rf os
;;
packages)
rm -rf external/MOSA-Project/Source/packages
;;
*)
echo $"Usage: abctl clean {all|bin|os||logs|packages}"
exit 1
esac
loadenv auto
}
function reset {
case $1 in
all)
#reset git
echo Skipping reset git. Call reset git manually.
;;
git)
cd external/MOSA-Project
git clean -xfd
git reset --hard
cd ../../
git clean -xfd
git reset --hard
git submodule update --recursive
;;
*)
echo $"Usage: abctl reset {all|git}"
exit 1
esac
}
function update {
case $1 in
all)
update git
;;
git)
cd external/MOSA-Project
git pull
cd ../../
git pull
git submodule update --recursive
;;
*)
echo $"Usage: abctl reset {all|git}"
exit 1
esac
}
function patch {
case $1 in
apply)
patches/apply
;;
revert)
patches/apply --reverse
;;
*)
echo $"Usage: abctl configure patch {apply|revert}"
exit 1
esac
}
function build {
case $1 in
all)
build builder
build assembly
build native
build app
build app2
build service.basic
build service.hostcommunication
build app.shell
build loader
build kernel
build image
build disk
;;
builder)
(cd src && ${msbuild} Abanu.Tools.sln /p:Configuration=Release -verbosity:minimal -m)
cp external/MOSA-Project/bin/Mosa.Plug.Korlib.dll bin
cp external/MOSA-Project/bin/Mosa.Plug.Korlib.x86.dll bin
cp external/MOSA-Project/bin/Mosa.Plug.Korlib.x64.dll bin
cp external/MOSA-Project/bin/dnlib.* bin
cp external/MOSA-Project/bin/Priority\ Queue.dll bin
;;
assembly)
(cd src && ${msbuild} Abanu.Kernel.sln /p:Configuration=Debug -verbosity:minimal -m)
;;
native)
src/Abanu.Native.${ABANU_ARCH}/build
;;
app)
(cd bin && $ABANU_BUILD build --bin=app)
;;
app2)
(cd bin && $ABANU_BUILD build --bin=app2)
;;
app.shell)
(cd bin && $ABANU_BUILD build --bin=app.shell)
;;
service.basic)
(cd bin && $ABANU_BUILD build --bin=service.basic)
;;
service.hostcommunication)
(cd bin && $ABANU_BUILD build --bin=service.hostcommunication)
;;
loader)
(cd bin && $ABANU_BUILD build --bin=loader)
;;
kernel)
(cd bin && $ABANU_BUILD build --bin=kernel)
;;
loader,kernel)
build loader
build kernel
;;
image)
_image
;;
disk)
_disk
;;
*)
echo $"Usage: abctl build {all|builder|assembly|native|app|app2|image|disk}"
exit 1
esac
}
function run {
case $1 in
bochs)
_bochs ${@:2}
;;
qemu)
_qemu ${@:2}
;;
*)
echo $"Usage: abctl run {qemu|bochs}"
exit 1
esac
}
function debug {
loadenv auto
case $1 in
qemu-kernel)
# TODO: Maybe this will never the case, but we should check if this is really our instance
pkill gdb
#trap '' SIGINT
#./abctl debug qemu-kernel-run &
#debug qemu-kernel-run
#$ABANU_PROJDIR/bin/Abanu.Tools.HostCommunication.exe &
#sleep 1
HostCommunication_PID=$!
gdb -x conf/gdb-load-symbols -nx -x conf/gdbinit -x conf/gdb-attach-unix -x conf/gdb-workspace
#kill -9 $HostCommunication_PID
#gdb -x conf/gdb-load-symbols -x conf/gdb-attach-mswin -x conf/gdb-workspace
;;
qemu-kernel-run)
#loadenv $QEMU_RUNTIME
loadenv unix
#trap '' SIGINT
# Uncomment if not required!
DEBUG_INTERRUPTS=,int
#qemu_app=$QEMU_X64
qemu_app=$QEMU_X86
#echo $qemu_app
#-gdb stdio
$qemu_app \
-drive file=${ABANU_OSDIR}/Abanu.OS.Core.${ABANU_ARCH}.img,index=0,media=disk,format=raw \
-drive file=${ABANU_TMPDIR}/network-disk.img,index=1,media=disk,format=raw,copy-on-read=off,cache=none \
-kernel os/Abanu.OS.image.${ABANU_ARCH}.bin -serial file:${ABANU_LOGDIR}/kernel.log -serial tcp::2244,server,nowait,reconnect=100 -S -gdb stdio -d pcall,cpu_reset,guest_errors${DEBUG_INTERRUPTS} -D ${ABANU_LOGDIR}/emulator.log -m 256
;;
qemu-grub-hybrid)
gdb -x conf/gdb-qemu-grub-hybrid
;;
qemu-grub-hybrid-run)
loadenv unix
# Uncomment if not required!
DEBUG_INTERRUPTS=,int
qemu_app=$QEMU_X86
bios="-L /usr/share/seabios"
disk=${ABANU_OSDIR}/Abanu.Kernel.Core.x86-grub-hybrid.disk.img
$qemu_app ${bios} -hda $disk -serial file:${ABANU_LOGDIR}/kernel.log -S -gdb stdio -d pcall,cpu_reset,guest_errors${DEBUG_INTERRUPTS} -D ${ABANU_LOGDIR}/emulator.log -m 256
;;
*)
echo $"Usage: abctl run {qemu-kernel|qemu-grub-hybrid}"
exit 1
esac
loadenv auto
}
function _image {
(cd bin && ${ABANU_BUILD} build --image)
}
function _disk {
#image=$ABANU_OSDIR/abanu.kernel.image.bin
#loader=$ABANU_PROJDIR/os/Abanu.Kernel.Loader.bin
#kernel=$ABANU_PROJDIR/os/Abanu.Kernel.Core.bin
#rm -f $image
#cat $loader $kernel > $image
#printf '\x31\xc0\xc3' | dd of=$image bs=1 seek=3 count=3 conv=notrunc
create_efi_disk
create_grub_hybrid_disk
}
function _bochs {
case $1 in
x86)
arch=x86
;;
x86-grub-vbe)
arch=x86-grub-vbe
;;
x64)
arch=x64
;;
*)
echo $"Usage: abctl run bochs {x86|x86-grub-vbe|x64|host}"
exit 1
esac
bochsrc="${ABANU_PROJDIR}/conf/bochs-${arch}.bxrc"
bochs -f ${bochsrc} -rc "${ABANU_PROJDIR}/conf/bochs.rc"
}
function _qemu {
loadenv unix
disk=${ABANU_OSDIR}/Abanu.OS.Core.x86.img
case $1 in
x86)
arch=x86
qemubin=qemu-system-i386
cpu=qemu32,+sse4.1
bios="-L /usr/share/seabios"
;;
x86-grub-vbe)
arch=x86
qemubin=qemu-system-i386
cpu=qemu32,+sse4.1
bios="-L /usr/share/seabios"
disk=${ABANU_OSDIR}/Abanu.OS.Core.x86-grub-hybrid.disk.img
;;
x86-efi)
arch=x86
qemubin=qemu-system-i386
cpu=qemu32,+sse4.1
bios="-bios ${ABANU_PROJDIR}/tools/ovmf-ia32/OVMF-pure-efi.fd"
disk=${ABANU_OSDIR}/Abanu.OS.Core.x86-efi.disk.img
;;
x64)
arch=x64
qemubin=qemu-system-x86_64
cpu=qemu64
bios="-L /usr/share/seabios"
;;
host)
arch=x64
qemubin=qemu-system-x86_64
cpu=host
kvmargs=-enable-kvm
bios="-L /usr/share/seabios"
;;
*)
echo $"Usage: abctl run qemu {x86|x86-efi|x86-grub-vbe|x64|host}"
exit 1
esac
echo ${qemubin} ${bios} ${kvmargs} -cpu ${cpu} -hda $disk -serial file:${ABANU_PROJDIR}/logs/kernel.log -d pcall,cpu_reset,guest_errors -D ${ABANU_PROJDIR}/logs/emulator.log
${qemubin} ${bios} ${kvmargs} -cpu ${cpu} -hda $disk -serial file:${ABANU_PROJDIR}/logs/kernel.log -d pcall,cpu_reset,guest_errors -D ${ABANU_PROJDIR}/logs/emulator.log
loadenv auto
}
#function create_chroot {
#wget ${alpine_mirror}/latest-stable/main/x86_64/apk-tools-static-${alpine_version}.apk
#tar -xzf apk-tools-static-*.apk
#wget https://raw.githubusercontent.com/alpinelinux/alpine-chroot-install/v0.9.0/alpine-chroot-install \
#&& echo 'e5dfbbdc0c4b3363b99334510976c86bfa6cb251 alpine-chroot-install' | sha1sum -c \
#|| exit 1
#chmod +x alpine-chroot-install
#}
function create_efi_disk {
loadenv unix
disk=${ABANU_OSDIR}/Abanu.Kernel.Core.x86-efi.disk.img
size=40880 #kb
let "block=((size * 1024) / (512 * 16 * 16)) - 1"
echo $block
dd if=/dev/zero of=$disk bs=1k count=$size
mformat -i $disk -h 16 -t 16 -s $block ::
mcopy -i $disk -s $ABANU_TOOLSDIR/grub-efi-x86/efi ::/
mcopy -i $disk -s $ABANU_TOOLSDIR/grub-efi-x86/boot ::/
mcopy -i $disk -s $ABANU_TOOLSDIR/grub-efi-x86/NvVars ::/
mcopy -i $disk -s $ABANU_TOOLSDIR/grub-efi-x86/.disk ::/
mcopy -i $disk -s $ABANU_OSDIR/Abanu.OS.image.${ABANU_ARCH}.bin ::/abanu.bin
loadenv auto
}
function create_grub_hybrid_disk {
loadenv unix
disk=${ABANU_OSDIR}/Abanu.Kernel.Core.x86-grub-hybrid.disk.img
isodir=$ABANU_PROJDIR/tmp/iso-grub-hybrid
mkdir -p $isodir;
cp $ABANU_OSDIR/abanu.os.image.${ABANU_ARCH}.bin $isodir/abanu.bin
mkdir -p $isodir/boot/grub
cp $ABANU_TOOLSDIR/grub-efi-x86/boot/grub/grub.cfg $isodir/boot/grub
grub-mkrescue -o $disk $isodir
loadenv auto
}
function logs {
case $1 in
kernel)
less +F "${ABANU_PROJDIR}/logs/kernel.log"
;;
emulator)
less +F "${ABANU_PROJDIR}/logs/emulator.log"
;;
*)
echo $"Usage: abctl logs {kernel|emulator}"
exit 1
esac
}
function _test {
case $1 in
cloud)
;;
*)
echo $"Usage: abctl test {cloud}"
exit 1
esac
}
case $1 in
configure)
configure ${@:2}
;;
clean)
clean ${@:2}
;;
update)
update ${@:2}
;;
reset)
reset ${@:2}
;;
build)
build ${@:2}
;;
run)
run ${@:2}
;;
logs)
logs ${@:2}
;;
f1)
create_efi_disk ${@:2}
#create_chroot
;;
debug)
debug ${@:2}
;;
test)
_test ${@:2}
;;
*)
echo $"Usage: abctl {configure|build|run|debug|clean|reset|logs|update}"
exit 1
esac