From 120c21b8ddfc2f94b8e7fae77ee9ef3364a2b01c Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Wed, 12 Jan 2022 14:40:35 +0500 Subject: [PATCH] Power off and test example kernels --- examples/kernel-multiboot2-grub/.gitignore | 1 + examples/kernel-multiboot2-grub/Makefile | 13 ++++++++++--- examples/kernel-multiboot2-grub/expected.txt | Bin 0 -> 1908 bytes examples/kernel-multiboot2-grub/main.c | 6 +++--- examples/kernel-multiboot2-grub/start.S | 8 ++++---- examples/kernel-multiboot2-limine/.gitignore | 1 + examples/kernel-multiboot2-limine/Makefile | 13 ++++++++++--- examples/kernel-multiboot2-limine/expected.txt | Bin 0 -> 1307 bytes examples/kernel-multiboot2-limine/main.c | 6 +++--- examples/kernel-multiboot2-limine/start.S | 8 ++++---- examples/kernel-stivale2-limine/.gitignore | 1 + examples/kernel-stivale2-limine/Makefile | 13 ++++++++++--- examples/kernel-stivale2-limine/expected.txt | 0 examples/kernel-stivale2-limine/main.c | 16 +++++++++++----- 14 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 examples/kernel-multiboot2-grub/expected.txt create mode 100644 examples/kernel-multiboot2-limine/expected.txt create mode 100644 examples/kernel-stivale2-limine/expected.txt diff --git a/examples/kernel-multiboot2-grub/.gitignore b/examples/kernel-multiboot2-grub/.gitignore index 0ac0a35..6631cd5 100644 --- a/examples/kernel-multiboot2-grub/.gitignore +++ b/examples/kernel-multiboot2-grub/.gitignore @@ -1,2 +1,3 @@ /image.iso +/output.txt /rootfs/boot/kernel diff --git a/examples/kernel-multiboot2-grub/Makefile b/examples/kernel-multiboot2-grub/Makefile index 3b429ae..73bd6a8 100644 --- a/examples/kernel-multiboot2-grub/Makefile +++ b/examples/kernel-multiboot2-grub/Makefile @@ -1,15 +1,19 @@ -all: run +all: test CCPREFIX = ../../vendor/cross/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +DIFF = diff GRUB_FILE = grub-file GRUB_MKRESCUE = grub-mkrescue +QEMU = qemu-system-i386 +EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld +OUTPUT = output.txt ROOTFS = rootfs GRUBCFG = $(ROOTFS)/boot/grub/grub.cfg @@ -28,11 +32,14 @@ CFLAGS = \ OBJS = main.c.o start.S.o +test: run + $(DIFF) -a -Z $(EXPECTED) $(OUTPUT) + run: $(IMAGE) - qemu-system-i386 -cdrom $< -serial stdio -display none + $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: - rm -f $(IMAGE) $(KERNEL) $(OBJS) + rm -f $(OUTPUT) $(IMAGE) $(KERNEL) $(OBJS) $(IMAGE): $(GRUBCFG) $(KERNEL) $(GRUB_MKRESCUE) $(ROOTFS) -o $@ diff --git a/examples/kernel-multiboot2-grub/expected.txt b/examples/kernel-multiboot2-grub/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e382f3ab68473eb2e1bbe78fdd68fa7a930798bc GIT binary patch literal 1908 zcma)7OK;mS4DPwVg2(L8!jf&p@vYqp1y-zBvGZWZaw5zxSa!PX*N>zUR}PjSw}@mu zzCM0_9;?CRZ99O3I@_2vG-I9X9*l)uR+-}V=GhA|P1#;>-QECL^H-;^lnFh0ZFRrX zg-9WoBMsSx0)~Bu(Ne&|V0sNzn-!2}RztVlTgZx{|L~3~B>jGmA$JOqSVdtFUBE|p z?r~igP?<)1kWvsNI>?^FR##OEzjfc}>H?rV08%M9tR|~{%#bn3n8Mc|KOaHf2hp7v z^RXF5sqRI10a^sGczAh+AcmPIGn3De*=7|iYF)Se9@*7-V;73y zbu*yLQAXkh0i0!ObBZ$BrsO|Hu!EjV7Dt51hCOVCEwvGaAf2WJ9Pya&EYkiGw@9hZ27yAqwZc!Dm1D2W{z$TQU*hC!GF z$&~lX>F|2lTz9$jEa%%a?CgNk$-iYp`lF0F+=ZHVIUc^7k&=o8`fBOP< zU*~OQJ&Iyeln?bV1-><;hhr++?Y1fYp!o1(&ZV=tB9x8HqR1X@g5=c8D0qPALy3FS zsB9`+Q3+%jyN)bEu2yuJXH&$mczpW)3aod9-kJ4GM7Y}Av=-2ZD&h#-W&L0V)|ES^ zza8^mC&sfG6IhfzYF$2-C4D&NJ%zk}KfvAU64|YIp}wy(!y51Qpboz0%@lOej<3FB ztIcMMk|&urz9;WGf}#ofW{)OUu1(vw= #include -void halt(); +void poweroff(); static void panic(const char *str); @@ -28,9 +28,9 @@ void main( KernAux_Multiboot2_print(multiboot2_info, kernaux_console_printf); } -void halt() +void poweroff() { - panic("Kernel main function returned"); + kernaux_asm_i386_outportw(0x604, 0x2000); } void panic(const char *const str) diff --git a/examples/kernel-multiboot2-grub/start.S b/examples/kernel-multiboot2-grub/start.S index 73e36df..3c668a3 100644 --- a/examples/kernel-multiboot2-grub/start.S +++ b/examples/kernel-multiboot2-grub/start.S @@ -32,9 +32,9 @@ _kernel_stack_end: .global _start -.type _start, @function -.type main, @function -.type halt, @function +.type _start, @function +.type main, @function +.type poweroff, @function _start: mov $_kernel_stack_end, %esp // Initialize stack @@ -43,6 +43,6 @@ _start: push %eax // Multiboot magic number call main - call halt + call poweroff .size _start, . - _start diff --git a/examples/kernel-multiboot2-limine/.gitignore b/examples/kernel-multiboot2-limine/.gitignore index 84096a8..e59723f 100644 --- a/examples/kernel-multiboot2-limine/.gitignore +++ b/examples/kernel-multiboot2-limine/.gitignore @@ -1,4 +1,5 @@ /image.iso +/output.txt /rootfs/boot/kernel /rootfs/boot/limine-cd.bin /rootfs/boot/limine-eltorito-efi.bin diff --git a/examples/kernel-multiboot2-limine/Makefile b/examples/kernel-multiboot2-limine/Makefile index 9826e1e..56d1fc8 100644 --- a/examples/kernel-multiboot2-limine/Makefile +++ b/examples/kernel-multiboot2-limine/Makefile @@ -1,16 +1,20 @@ -all: run +all: test CCPREFIX = ../../vendor/cross/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +DIFF = diff GRUB_FILE = grub-file LIMINE = ../../vendor/limine/build/bin +QEMU = qemu-system-x86_64 XORRISO = xorriso +EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld +OUTPUT = output.txt ROOTFS = rootfs LIMINE_CD = $(LIMINE)/limine-cd.bin @@ -43,11 +47,14 @@ CFLAGS = \ OBJS = main.c.o start.S.o +test: run + $(DIFF) -a -Z $(EXPECTED) $(OUTPUT) + run: $(IMAGE) - qemu-system-x86_64 -cdrom $< -serial stdio -display none + $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: - rm -f $(IMAGE) $(OBJS) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) + rm -f $(OUTPUT) $(IMAGE) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(OBJS) $(IMAGE): $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(XORRISO) -as mkisofs -b $(REL_LIMINE_CD) -no-emul-boot -boot-load-size 4 -boot-info-table --efi-boot $(REL_LIMINE_ELTORITO) -efi-boot-part --efi-boot-image --protective-msdos-label $(ROOTFS) -o $@ diff --git a/examples/kernel-multiboot2-limine/expected.txt b/examples/kernel-multiboot2-limine/expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8f235096a4f0fd04d36ef3d2a5ffe6076a645204 GIT binary patch literal 1307 zcma)6O^=%}5Z!Zr#T=>BN*DtR94oa_rHy*nUtkt*;?^G#CTY{E|Ggd?SUYM^B@Xy` z{NBv-c=l&GiQbqA3Q+7IUO=B!&qojzE=-DH_ppybgnl&}Te}AUD}M0~s|doZKOm)u6lks65<`)0-te8G+k{~N@k;(zDwA^HAn zD7KJ&dio6Zs(K@1Ia)dsUE*goD{wspyFG4?didEv2#UnFoUb8MT$%CesyHQ;c}geX zwt_}cqIf_qe6+%7f2#o#+;+IXMEK*l?3v}jhQYbAVv_5_bnKw6N=m(l7&-SsU`gzo z4+d@D5I4*z(Lzu1kn_6S{mxOu760UKYx~~2qLh{Eo>!7eM?-k)6&yB)|qAp0eYA;2k z=q7(WWs=!Yx~I&n8%%Sb;s{C_6+Lx(Ak7c%nyjYnf}Bq$L`c!Lh4b;QL=KrY$<%T0 GclQ_2sZ;3y literal 0 HcmV?d00001 diff --git a/examples/kernel-multiboot2-limine/main.c b/examples/kernel-multiboot2-limine/main.c index aa0f485..ecdd7de 100644 --- a/examples/kernel-multiboot2-limine/main.c +++ b/examples/kernel-multiboot2-limine/main.c @@ -5,7 +5,7 @@ #include #include -void halt(); +void poweroff(); static void panic(const char *str); @@ -28,9 +28,9 @@ void main( KernAux_Multiboot2_print(multiboot2_info, kernaux_console_printf); } -void halt() +void poweroff() { - panic("Kernel main function returned"); + kernaux_asm_i386_outportw(0x604, 0x2000); } void panic(const char *const str) diff --git a/examples/kernel-multiboot2-limine/start.S b/examples/kernel-multiboot2-limine/start.S index 73e36df..3c668a3 100644 --- a/examples/kernel-multiboot2-limine/start.S +++ b/examples/kernel-multiboot2-limine/start.S @@ -32,9 +32,9 @@ _kernel_stack_end: .global _start -.type _start, @function -.type main, @function -.type halt, @function +.type _start, @function +.type main, @function +.type poweroff, @function _start: mov $_kernel_stack_end, %esp // Initialize stack @@ -43,6 +43,6 @@ _start: push %eax // Multiboot magic number call main - call halt + call poweroff .size _start, . - _start diff --git a/examples/kernel-stivale2-limine/.gitignore b/examples/kernel-stivale2-limine/.gitignore index d8315e6..d9e790b 100644 --- a/examples/kernel-stivale2-limine/.gitignore +++ b/examples/kernel-stivale2-limine/.gitignore @@ -1,5 +1,6 @@ /image.iso /main.c.d +/output.txt /rootfs/boot/kernel /rootfs/boot/limine-cd.bin /rootfs/boot/limine-eltorito-efi.bin diff --git a/examples/kernel-stivale2-limine/Makefile b/examples/kernel-stivale2-limine/Makefile index 3cfe350..b27f3fc 100644 --- a/examples/kernel-stivale2-limine/Makefile +++ b/examples/kernel-stivale2-limine/Makefile @@ -1,15 +1,19 @@ -all: run +all: test CCPREFIX = ../../vendor/cross/bin/x86_64-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc +DIFF = diff LIMINE = ../../vendor/limine/build/bin +QEMU = qemu-system-x86_64 XORRISO = xorriso +EXPECTED = expected.txt IMAGE = image.iso LINKERSCR = linker.ld +OUTPUT = output.txt ROOTFS = rootfs LIMINE_CD = $(LIMINE)/limine-cd.bin @@ -52,11 +56,14 @@ CFLAGS = \ OBJS = main.c.o # start.S.o +test: run + $(DIFF) -a -Z $(EXPECTED) $(OUTPUT) + run: $(IMAGE) - qemu-system-x86_64 -cdrom $< -serial stdio # -display none + $(QEMU) -cdrom $< -serial stdio -display none | tee $(OUTPUT) clean: - rm -f $(IMAGE) $(OBJS) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) + rm -f $(OUTPUT) $(IMAGE) $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(OBJS) $(IMAGE): $(FULL_KERNEL) $(FULL_LIMINE_CD) $(FULL_LIMINE_ELTORITO) $(FULL_LIMINE_SYS) $(XORRISO) -as mkisofs -b $(REL_LIMINE_CD) -no-emul-boot -boot-load-size 4 -boot-info-table --efi-boot $(REL_LIMINE_ELTORITO) -efi-boot-part --efi-boot-image --protective-msdos-label $(ROOTFS) -o $@ diff --git a/examples/kernel-stivale2-limine/expected.txt b/examples/kernel-stivale2-limine/expected.txt new file mode 100644 index 0000000..e69de29 diff --git a/examples/kernel-stivale2-limine/main.c b/examples/kernel-stivale2-limine/main.c index a6dd220..3cbe250 100644 --- a/examples/kernel-stivale2-limine/main.c +++ b/examples/kernel-stivale2-limine/main.c @@ -2,7 +2,9 @@ #include #include "stivale2.h" - + +static void poweroff(); + // We need to tell the stivale bootloader where we want our stack to be. // We are going to allocate our stack as an array in .bss. static uint8_t stack[8192]; @@ -126,8 +128,12 @@ void _start(struct stivale2_struct *stivale2_struct) { // a simple "Hello World" to screen. term_write("Hello World", 11); - // We're done, just hang... - for (;;) { - __asm__ ("hlt"); - } + poweroff(); +} + +void poweroff() +{ + const uint16_t port = 0x604; + const uint16_t value = 0x2000; + __asm__ volatile("outw %1, %0" : : "dN" (port), "a" (value)); }