-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathabctl
executable file
·689 lines (564 loc) · 13.7 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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
#!/bin/bash
#set -x
# abort on error
set -eE -o functrace
failure() {
local lineno=$1
local msg=$2
echo "Failed at $lineno: $msg"
}
trap 'failure ${LINENO} "$BASH_COMMAND"' ERR
ORIGIN_DIR=$(pwd)
THIS_DIR=$(dirname $0)
cd $THIS_DIR
function loadenv {
source env/$1
}
loadenv unix
mkdir -p bin
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 [email protected]:abanu-org/abanu-tools.git tools
;;
git)
git remote set-url origin [email protected]:abanu-org/abanu.git
cd external/MOSA-Project
git remote set-url origin [email protected]: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)
rm -rf external/MOSA-Project/Source/packages;
${nuget} restore external/MOSA-Project/Source/Mosa.sln
${nuget} restore src/Abanu.sln
;;
cloud-test)
git submodule update --recursive --init
./abctl configure packages
;;
*)
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)
if [ -d external/MOSA-Project ]; then
cd external/MOSA-Project
git clean -xfd
git reset --hard
cd ../../
fi
git clean -xfd
git reset --hard
git submodule init
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)
if [ ! -d external/MOSA-Project/Source/packages ]; then
./abctl configure packages
fi
if [ ! -d external/MOSA-Project/bin ]; then
./abctl configure mosa
fi
build builder
build assembly
build native
build app
build app2
build service.consoleserver
build service.basic
build service.hostcommunication
build app.shell
build loader
build kernel
build image
build disk
;;
builder)
# mono: /verbosity:minimal
(cd src && ${msbuild} Abanu.Tools.sln /p:Configuration=Release /verbosity:minimal /p:RunCodeAnalysis=false -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)
#set -x
# mono: /verbosity:minimal
(cd src && ${msbuild} Abanu.sln /p:Configuration=Debug /verbosity:minimal /p:RunCodeAnalysis=false -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)
;;
external)
(cd bin && $ABANU_BUILD build --bin=external $2)
;;
service.consoleserver)
(cd bin && $ABANU_BUILD build --bin=service.consoleserver)
;;
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)
export ABANU_DEBUG_TARGET=$1;
# 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
_renameLogs
#trap '' SIGINT
rootdisk=${ABANU_OSDIR}/Abanu.Kernel.Core.x86-efi.disk.img
# 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=${rootdisk},index=1,media=disk,format=raw,copy-on-read=off,cache=none \
-drive file=${ABANU_TMPDIR}/network-disk.img,index=2,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 \
2> /dev/null
;;
qemu-attach-unix)
#echo "####################"
#echo /$ABANU_DEBUG_TARGET/
#echo ~~~~~~~~~~~~~
case $ABANU_DEBUG_TARGET in
qemu-kernel)
debug qemu-kernel-run
;;
qemu-grub-hybrid)
debug qemu-grub-hybrid-run
;;
*)
echo $"Unkown debug name"
exit 1
esac
;;
qemu-grub-hybrid)
export ABANU_DEBUG_TARGET=$1;
#gdb -x conf/gdb-qemu-grub-hybrid
gdb -x conf/gdb-load-symbols -nx -x conf/gdbinit -x conf/gdb-attach-unix -x conf/gdb-workspace
;;
qemu-grub-hybrid-run)
loadenv unix
_renameLogs
rootdisk=${ABANU_OSDIR}/Abanu.Kernel.Core.x86-efi.disk.img
# 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} \
-drive file=${disk},index=0,media=disk,format=raw \
-drive file=${rootdisk},index=1,media=disk,format=raw,copy-on-read=off,cache=none \
-drive file=${ABANU_TMPDIR}/network-disk.img,index=2,media=disk,format=raw,copy-on-read=off,cache=none \
-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 \
2> /dev/null
;;
*)
echo $"Usage: abctl run {qemu-kernel|qemu-grub-hybrid}"
exit 1
esac
loadenv auto
}
function _renameLogs {
current=${ABANU_LOGDIR}/kernel.log
prev1=${ABANU_LOGDIR}/kernel.1.log
prev2=${ABANU_LOGDIR}/kernel.2.log
if [ -f $prev2 ]; then
rm $prev2
fi
if [ -f $prev1 ]; then
mv $prev1 $prev2
fi
if [ -f $current ]; then
mv $current $prev1
fi
}
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.Kernel.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.Kernel.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 -m 256
${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 -m 256
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=51100 #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 ::
# TODO: avoid code duplication
isodir=$ABANU_PROJDIR/tmp/iso-efi-disk
mkdir -p $isodir
rm -f $isodir/TEST.TXT
echo "This is a test file V2" > $isodir/TEST.TXT
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
if [ -f $ABANU_OSDIR/Abanu.DisplayServer.bin ]; then
mcopy -i $disk -s $ABANU_OSDIR/Abanu.DisplayServer.bin ::/DSPSRV.BIN
fi
if [ -f $ABANU_OSDIR/App.GuiDemo.bin ]; then
mcopy -i $disk -s $ABANU_OSDIR/App.GuiDemo.bin ::/GUIDEMO.BIN
fi
if [ -f $ABANU_OSDIR/c-hello-world.bin ]; then
mcopy -i $disk -s $ABANU_OSDIR/c-hello-world.bin ::/CHELLO.BIN
fi
mcopy -i $disk -s $isodir/TEST.TXT ::/TEST.TXT
echo $disk created
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
# additional files
if [ -f $ABANU_OSDIR/Abanu.DisplayServer.bin ]; then
cp $ABANU_OSDIR/Abanu.DisplayServer.bin $isodir/DSPSRV.BIN 2>/dev/null
fi
if [ -f $ABANU_OSDIR/App.GuiDemo.bin ]; then
cp $ABANU_OSDIR/App.GuiDemo.bin $isodir/GUIDEMO.BIN 2>/dev/null
fi
if [ -f $ABANU_OSDIR/c-hello-world.bin ]; then
cp $ABANU_OSDIR/c-hello-world.bin $isodir/CHELLO.BIN 2>/dev/null
fi
rm -f $isodir/TEST.TXT
echo "This is a test file V2" > $isodir/TEST.TXT
mkdir -p $isodir/boot/grub
cp $ABANU_TOOLSDIR/grub-efi-x86/boot/grub/grub.cfg $isodir/boot/grub
grub-mkrescue -o $disk $isodir
echo $disk created
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)
(cd bin && ${ABANU_BUILD} run --emulator=qemu --boot=direct --test)
echo Test finished
;;
*)
echo $"Usage: abctl test {cloud}"
exit 1
esac
}
function _tool {
case $1 in
msbuild)
(cd $ORIGIN_DIR && $msbuild ${@:2})
;;
*)
echo $"Usage: tool {msbuild}"
exit 1
esac
}
function _abspath {
loadenv auto
cd $ORIGIN_DIR;
echo $(__platform_abspath $1)
cd $THIS_DIR;
}
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}
;;
abspath)
_abspath ${@:2}
;;
tool)
_tool ${@:2}
;;
*)
echo $"Usage: abctl {configure|build|run|debug|clean|reset|logs|update}"
exit 1
esac