1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2025-05-26 18:11:54 -04:00

Power off and test example kernels

This commit is contained in:
Alex Kotov 2022-01-12 14:40:35 +05:00
parent 5296e9cce3
commit 120c21b8dd
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
14 changed files with 58 additions and 28 deletions

View file

@ -1,2 +1,3 @@
/image.iso
/output.txt
/rootfs/boot/kernel

View file

@ -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 $@

Binary file not shown.

View file

@ -5,7 +5,7 @@
#include <kernaux/console.h>
#include <kernaux/multiboot2.h>
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)

View file

@ -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

View file

@ -1,4 +1,5 @@
/image.iso
/output.txt
/rootfs/boot/kernel
/rootfs/boot/limine-cd.bin
/rootfs/boot/limine-eltorito-efi.bin

View file

@ -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 $@

Binary file not shown.

View file

@ -5,7 +5,7 @@
#include <kernaux/console.h>
#include <kernaux/multiboot2.h>
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)

View file

@ -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

View file

@ -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

View file

@ -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 $@

View file

@ -2,7 +2,9 @@
#include <stddef.h>
#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));
}