mirror of
https://github.com/tailix/libkernaux.git
synced 2024-10-30 11:54:01 -04:00
Remove drivers (#127)
This commit is contained in:
parent
e93d08ee70
commit
081318c2c7
47 changed files with 7 additions and 1268 deletions
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
|
@ -119,7 +119,7 @@ jobs:
|
|||
- name: autogen
|
||||
run: ./autogen.sh
|
||||
- name: configure
|
||||
run: ./configure --host='i386-elf' ${{matrix.debug}} --enable-freestanding --with-drivers --with-libc AR="$(which i686-linux-gnu-ar)" CC="$(which i686-linux-gnu-gcc)" LD="$(which i686-linux-gnu-ld)" RANLIB="$(which i686-linux-gnu-ranlib)"
|
||||
run: ./configure --host='i386-elf' ${{matrix.debug}} --enable-freestanding --with-libc AR="$(which i686-linux-gnu-ar)" CC="$(which i686-linux-gnu-gcc)" LD="$(which i686-linux-gnu-ld)" RANLIB="$(which i686-linux-gnu-ranlib)"
|
||||
- name: make
|
||||
run: make
|
||||
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -101,7 +101,6 @@
|
|||
/include/Makefile
|
||||
|
||||
/include/kernaux.h
|
||||
/include/kernaux/drivers/console.h
|
||||
/include/kernaux/multiboot2.h
|
||||
/include/kernaux/version.h
|
||||
|
||||
|
|
9
.gitmodules
vendored
9
.gitmodules
vendored
|
@ -2,15 +2,6 @@
|
|||
path = vendor/cross
|
||||
url = https://github.com/tailix/cross.git
|
||||
ignore = dirty
|
||||
[submodule "vendor/limine"]
|
||||
path = vendor/limine
|
||||
url = https://github.com/limine-bootloader/limine.git
|
||||
[submodule "vendor/opensbi"]
|
||||
path = vendor/opensbi
|
||||
url = https://github.com/riscv-software-src/opensbi.git
|
||||
[submodule "vendor/u-boot"]
|
||||
path = vendor/u-boot
|
||||
url = https://source.denx.de/u-boot/u-boot.git
|
||||
[submodule "vendor/mruby"]
|
||||
path = vendor/mruby
|
||||
url = https://github.com/mruby/mruby.git
|
||||
|
|
24
Makefile.am
24
Makefile.am
|
@ -111,27 +111,3 @@ endif
|
|||
if WITH_UNITS
|
||||
libkernaux_la_SOURCES += src/units.c
|
||||
endif
|
||||
|
||||
###########
|
||||
# Drivers #
|
||||
###########
|
||||
|
||||
if WITH_DRIVERS
|
||||
libkernaux_la_SOURCES += \
|
||||
src/drivers/console.c \
|
||||
src/drivers/framebuffer.c \
|
||||
src/drivers/shutdown.c
|
||||
|
||||
# Intel 8253-compatible programmable interval timer
|
||||
|
||||
if ASM_I386
|
||||
libkernaux_la_SOURCES += src/drivers/intel_8253_pit.c
|
||||
endif
|
||||
|
||||
# Intel 8259-compatible programmable interrupt controller
|
||||
|
||||
if ASM_I386
|
||||
libkernaux_la_SOURCES += src/drivers/intel_8259_pic.c
|
||||
endif
|
||||
|
||||
endif # WITH_DRIVERS
|
||||
|
|
|
@ -90,12 +90,6 @@ zero). Work-in-progress APIs can change at any time.
|
|||
* Architecture-specific code (*work in progress*)
|
||||
* [Declarations](/include/kernaux/arch/)
|
||||
* [Functions](/include/kernaux/asm/)
|
||||
* Device drivers (for debugging only)
|
||||
* [Serial console](/include/kernaux/drivers/console.h) (*work in progress*)
|
||||
* [Framebuffer](/include/kernaux/drivers/framebuffer.h) (*planned*)
|
||||
* [Intel 8253-compatible PIT](/include/kernaux/drivers/intel_8253_pit.h) (*work in progress*)
|
||||
* [Intel 8259-compatible PIC](/include/kernaux/drivers/intel_8259_pic.h) (*work in progress*)
|
||||
* USB (*planned*)
|
||||
|
||||
### Definitions
|
||||
|
||||
|
@ -144,7 +138,6 @@ stable options.
|
|||
|
||||
#### Packages
|
||||
|
||||
* `--with-drivers` - device drivers
|
||||
* `--with-libc` - provides the replacement for some standard C functions.
|
||||
Useful in freestanding environment, where no libc is present.
|
||||
|
||||
|
@ -211,7 +204,6 @@ without it in `$PATH`:
|
|||
./configure \
|
||||
--host='i386-elf' \
|
||||
--enable-freestanding \
|
||||
--with-drivers \
|
||||
--with-libc \
|
||||
AR="$(which i386-elf-ar)" \
|
||||
CC="$(which i386-elf-gcc)" \
|
||||
|
|
|
@ -14,4 +14,4 @@ export AR="$CROSS-ar"
|
|||
export CC="$CROSS-gcc"
|
||||
export RANLIB="$CROSS-ranlib"
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -14,4 +14,4 @@ export AR="$CROSS-ar"
|
|||
export CC="$CROSS-gcc"
|
||||
export RANLIB="$CROSS-ranlib"
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -16,4 +16,4 @@ export RANLIB="$CROSS-ranlib"
|
|||
|
||||
export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone'
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -14,4 +14,4 @@ export AR="$TARGET-ar"
|
|||
export CC="$TARGET-gcc"
|
||||
export RANLIB="$TARGET-ranlib"
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -14,4 +14,4 @@ export AR="$TARGET-ar"
|
|||
export CC="$TARGET-gcc"
|
||||
export RANLIB="$TARGET-ranlib"
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -16,4 +16,4 @@ export RANLIB="$TARGET-ranlib"
|
|||
|
||||
export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone'
|
||||
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc
|
||||
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc
|
||||
|
|
|
@ -30,7 +30,6 @@ AC_CONFIG_FILES([
|
|||
libc/Makefile
|
||||
libc/include/Makefile
|
||||
include/kernaux.h
|
||||
include/kernaux/drivers/console.h
|
||||
include/kernaux/multiboot2.h
|
||||
include/kernaux/version.h
|
||||
tests/Makefile
|
||||
|
@ -77,7 +76,6 @@ AC_ARG_WITH( [printf-fmt], AS_HELP_STRING([--without-printf-fmt], [wit
|
|||
AC_ARG_WITH( [units], AS_HELP_STRING([--without-units], [without measurement units utils]))
|
||||
|
||||
dnl Packages (disabled by default)
|
||||
AC_ARG_WITH( [drivers], AS_HELP_STRING([--with-drivers], [with drivers]))
|
||||
AC_ARG_WITH( [libc], AS_HELP_STRING([--with-libc], [with libc replacement]))
|
||||
|
||||
|
||||
|
@ -161,7 +159,6 @@ AS_IF([test "$with_printf_fmt" = no ], [with_printf_fmt=no], [wit
|
|||
AS_IF([test "$with_units" = no ], [with_units=no], [with_units=yes])
|
||||
|
||||
dnl Packages (disabled by default)
|
||||
AS_IF([test "$with_drivers" = yes], [with_drivers=yes], [with_drivers=no])
|
||||
AS_IF([test "$with_libc" = yes], [with_libc=yes], [with_libc=no])
|
||||
|
||||
|
||||
|
@ -223,7 +220,6 @@ AM_CONDITIONAL([WITH_PRINTF_FMT], [test "$with_printf_fmt" = yes])
|
|||
AM_CONDITIONAL([WITH_UNITS], [test "$with_units" = yes])
|
||||
|
||||
dnl Packages (disabled by default)
|
||||
AM_CONDITIONAL([WITH_DRIVERS], [test "$with_drivers" = yes])
|
||||
AM_CONDITIONAL([WITH_LIBC], [test "$with_libc" = yes])
|
||||
|
||||
dnl Packages (virtual)
|
||||
|
@ -274,7 +270,6 @@ AS_IF([test "$with_printf_fmt" = yes], [AC_DEFINE([WITH_PRINTF_FMT],
|
|||
AS_IF([test "$with_units", = yes], [AC_DEFINE([WITH_UNITS], [1], [with measurement units utils])])
|
||||
|
||||
dnl Packages (disabled by default)
|
||||
AS_IF([test "$with_drivers" = yes], [AC_DEFINE([WITH_DRIVERS], [1], [with drivers])])
|
||||
AS_IF([test "$with_libc" = yes], [AC_DEFINE([WITH_LIBC], [1], [with libc replacement])])
|
||||
|
||||
dnl Packages (virtual)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
/image.iso
|
||||
/output.txt
|
||||
/rootfs/boot/kernel
|
|
@ -1,62 +0,0 @@
|
|||
all: test
|
||||
|
||||
REPO = ../../..
|
||||
|
||||
CCPREFIX = $(REPO)/vendor/cross/root/bin/i386-elf-
|
||||
|
||||
AS = $(CCPREFIX)as
|
||||
CC = $(CCPREFIX)gcc
|
||||
|
||||
LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-i386
|
||||
LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-i386
|
||||
|
||||
DIFF = diff
|
||||
GRUB_FILE = grub-file
|
||||
GRUB_MKRESCUE = grub-mkrescue
|
||||
QEMU = qemu-system-i386 -serial stdio -display none
|
||||
|
||||
EXPECTED = expected.txt
|
||||
IMAGE = image.iso
|
||||
LINKERSCR = linker.ld
|
||||
OUTPUT = output.txt
|
||||
ROOTFS = rootfs
|
||||
|
||||
GRUBCFG = $(ROOTFS)/boot/grub/grub.cfg
|
||||
KERNEL = $(ROOTFS)/boot/kernel
|
||||
|
||||
CFLAGS = \
|
||||
-std=c99 \
|
||||
-pedantic \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-I$(LIBKERNAUX_DEST)/include
|
||||
|
||||
OBJS = main.c.o multiboot2.c.o start.S.o
|
||||
|
||||
test: run
|
||||
$(DIFF) -a -Z $(EXPECTED) $(OUTPUT)
|
||||
|
||||
run: $(IMAGE)
|
||||
$(QEMU) -cdrom $< | tee $(OUTPUT)
|
||||
|
||||
clean:
|
||||
rm -f $(OUTPUT) $(IMAGE) $(KERNEL) $(OBJS)
|
||||
|
||||
$(IMAGE): $(GRUBCFG) $(KERNEL)
|
||||
$(GRUB_MKRESCUE) $(ROOTFS) -o $@
|
||||
|
||||
$(KERNEL): $(LINKERSCR) build-libkernaux.a $(OBJS)
|
||||
$(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_DEST)/lib
|
||||
$(GRUB_FILE) --is-x86-multiboot2 $@
|
||||
|
||||
build-libkernaux.a:
|
||||
cd $(LIBKERNAUX_BUILD) && ./config && make install
|
||||
|
||||
%.c.o: %.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
%.S.o: %.S
|
||||
$(AS) $< -o $@
|
|
@ -1,109 +0,0 @@
|
|||
Multiboot 2 header is valid
|
||||
Multiboot 2 header
|
||||
magic: 3897708758
|
||||
arch: 0 (i386)
|
||||
size: 24
|
||||
checksum: 397258514
|
||||
Multiboot 2 header tag
|
||||
type: 0 (none)
|
||||
flags: 0
|
||||
size: 8
|
||||
Multiboot 2 info magic number is valid
|
||||
Multiboot 2 info is valid
|
||||
Multiboot 2 info
|
||||
size: 1088
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 21 (image load base phys addr)
|
||||
size: 12
|
||||
load base addr: 4194304
|
||||
Multiboot 2 info tag
|
||||
type: 1 (boot cmd line)
|
||||
size: 21
|
||||
cmdline: hello kernel
|
||||
Multiboot 2 info tag
|
||||
type: 2 (boot loader name)
|
||||
size: 31
|
||||
name: GRUB 2.04-1ubuntu26.15
|
||||
Multiboot 2 info tag
|
||||
type: 10 (APM table)
|
||||
size: 28
|
||||
version: 258
|
||||
cseg: 61440
|
||||
offset: 53676
|
||||
cseg 16: 61440
|
||||
dseg: 61440
|
||||
flags: 3
|
||||
cseg len: 65520
|
||||
cseg 16 len: 65520
|
||||
dseg len: 65520
|
||||
Multiboot 2 info tag
|
||||
type: 6 (memory map)
|
||||
size: 160
|
||||
entry size: 24
|
||||
entry version: 0
|
||||
entries:
|
||||
entry 0
|
||||
base addr: 0
|
||||
length: 654336
|
||||
type: 1
|
||||
reserved1: 0
|
||||
entry 1
|
||||
base addr: 654336
|
||||
length: 1024
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 2
|
||||
base addr: 983040
|
||||
length: 65536
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 3
|
||||
base addr: 1048576
|
||||
length: 133038080
|
||||
type: 1
|
||||
reserved1: 0
|
||||
entry 4
|
||||
base addr: 134086656
|
||||
length: 131072
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 5
|
||||
base addr: 4294705152
|
||||
length: 262144
|
||||
type: 2
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 9 (ELF symbols)
|
||||
size: 700
|
||||
num: 17
|
||||
entsize: 0
|
||||
shndx: 40
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 4 (basic memory info)
|
||||
size: 16
|
||||
mem lower: 639
|
||||
mem upper: 129920
|
||||
Multiboot 2 info tag
|
||||
type: 5 (BIOS boot device)
|
||||
size: 20
|
||||
bios dev: 224
|
||||
partition: 4294967295
|
||||
sub_partition: 4294967295
|
||||
Multiboot 2 info tag
|
||||
type: 8 (framebuffer info)
|
||||
size: 32
|
||||
framebuffer addr: 753664
|
||||
framebuffer pitch: 160
|
||||
framebuffer width: 80
|
||||
framebuffer height: 25
|
||||
framebuffer bpp: 16
|
||||
framebuffer type: 2
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 14 (ACPI old RSDP)
|
||||
size: 28
|
||||
Multiboot 2 info tag
|
||||
type: 0 (none)
|
||||
size: 8
|
|
@ -1,38 +0,0 @@
|
|||
OUTPUT_ARCH("i386")
|
||||
ENTRY(_start)
|
||||
|
||||
_kernel_offset = 0xc0000000; /* 3 GiB */
|
||||
|
||||
_kernel_phys_base = 4M;
|
||||
_kernel_virt_base = (_kernel_phys_base + _kernel_offset);
|
||||
|
||||
_kernel_stack_size = _kernel_stack_end - _kernel_stack_start;
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _kernel_phys_base;
|
||||
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.multiboot2);
|
||||
*(.text);
|
||||
}
|
||||
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata);
|
||||
}
|
||||
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data);
|
||||
}
|
||||
|
||||
.bss BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(COMMON);
|
||||
*(.bss);
|
||||
}
|
||||
|
||||
_kernel_size = . - _kernel_phys_base;
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
#include <kernaux/multiboot2.h>
|
||||
|
||||
extern const struct KernAux_Multiboot2_Header multiboot2_header;
|
||||
|
||||
static void panic(const char *str);
|
||||
|
||||
void main(
|
||||
const uint32_t multiboot2_info_magic,
|
||||
const struct KernAux_Multiboot2_Info *const multiboot2_info
|
||||
) {
|
||||
if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) {
|
||||
panic("Multiboot 2 header is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf("Multiboot 2 header is valid\n");
|
||||
}
|
||||
|
||||
KernAux_Multiboot2_Header_print(
|
||||
&multiboot2_header,
|
||||
kernaux_drivers_console_printf
|
||||
);
|
||||
|
||||
if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) {
|
||||
panic("Multiboot 2 info magic number is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf(
|
||||
"Multiboot 2 info magic number is valid\n"
|
||||
);
|
||||
}
|
||||
|
||||
if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) {
|
||||
panic("Multiboot 2 info is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf("Multiboot 2 info is valid\n");
|
||||
}
|
||||
|
||||
KernAux_Multiboot2_Info_print(
|
||||
multiboot2_info,
|
||||
kernaux_drivers_console_printf
|
||||
);
|
||||
}
|
||||
|
||||
void panic(const char *const str)
|
||||
{
|
||||
kernaux_drivers_console_printf("panic: %s\n", str);
|
||||
kernaux_drivers_shutdown_poweroff();
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#include <kernaux/multiboot2.h>
|
||||
|
||||
#include <kernaux/macro/packing_start.run>
|
||||
|
||||
// TODO: add more tags
|
||||
KERNAUX_SECTION(".multiboot2")
|
||||
KERNAUX_USED
|
||||
KERNAUX_ALIGNED(KERNAUX_MULTIBOOT2_HEADER_ALIGN)
|
||||
const struct {
|
||||
struct KernAux_Multiboot2_Header multiboot2_header;
|
||||
struct KernAux_Multiboot2_HTag_None tag_none;
|
||||
}
|
||||
KERNAUX_PACKED
|
||||
multiboot2_header = {
|
||||
.multiboot2_header = {
|
||||
.magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC,
|
||||
.arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||
.total_size = sizeof(multiboot2_header),
|
||||
.checksum = KERNAUX_MULTIBOOT2_HEADER_CHECKSUM(
|
||||
KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||
sizeof(multiboot2_header)
|
||||
),
|
||||
},
|
||||
.tag_none = {
|
||||
.base = {
|
||||
.type = KERNAUX_MULTIBOOT2_HTAG_NONE,
|
||||
.flags = 0,
|
||||
.size = sizeof(multiboot2_header.tag_none),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
#include <kernaux/macro/packing_end.run>
|
|
@ -1,5 +0,0 @@
|
|||
set timeout=0
|
||||
|
||||
menuentry "Kernel" {
|
||||
multiboot2 /boot/kernel hello kernel
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
.section .bss
|
||||
|
||||
.global _kernel_stack_start
|
||||
.global _kernel_stack_end
|
||||
|
||||
.align 16
|
||||
_kernel_stack_start:
|
||||
.skip 16384 # 16 KiB
|
||||
_kernel_stack_end:
|
||||
|
||||
|
||||
|
||||
.section .text
|
||||
|
||||
.global _start
|
||||
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
mov $_kernel_stack_end, %esp // Initialize stack
|
||||
|
||||
push %ebx // Multiboot information pointer
|
||||
push %eax // Multiboot magic number
|
||||
call main
|
||||
call kernaux_drivers_shutdown_poweroff
|
||||
|
||||
.size _start, . - _start
|
|
@ -1,6 +0,0 @@
|
|||
/image.iso
|
||||
/output.txt
|
||||
/rootfs/boot/kernel
|
||||
/rootfs/boot/limine-cd.bin
|
||||
/rootfs/boot/limine-eltorito-efi.bin
|
||||
/rootfs/boot/limine.sys
|
|
@ -1,87 +0,0 @@
|
|||
all: test
|
||||
|
||||
REPO = ../../..
|
||||
|
||||
CCPREFIX = $(REPO)/vendor/cross/root/bin/i386-elf-
|
||||
|
||||
AS = $(CCPREFIX)as
|
||||
CC = $(CCPREFIX)gcc
|
||||
|
||||
LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-i386
|
||||
LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-i386
|
||||
|
||||
DIFF = diff
|
||||
GRUB_FILE = grub-file
|
||||
LIMINE = $(REPO)/vendor/limine/build/bin
|
||||
QEMU = qemu-system-x86_64 -serial stdio -display none
|
||||
XORRISO = xorriso
|
||||
|
||||
EXPECTED = expected.txt
|
||||
IMAGE = image.iso
|
||||
LINKERSCR = linker.ld
|
||||
OUTPUT = output.txt
|
||||
ROOTFS = rootfs
|
||||
|
||||
LIMINE_CD = $(LIMINE)/limine-cd.bin
|
||||
LIMINE_ELTORITO = $(LIMINE)/limine-eltorito-efi.bin
|
||||
LIMINE_INSTALL = $(LIMINE)/limine-install
|
||||
LIMINE_SYS = $(LIMINE)/limine.sys
|
||||
|
||||
REL_KERNEL = boot/kernel
|
||||
REL_LIMINE_CD = boot/limine-cd.bin
|
||||
REL_LIMINE_CFG = boot/limine.cfg
|
||||
REL_LIMINE_ELTORITO = boot/limine-eltorito-efi.bin
|
||||
REL_LIMINE_SYS = boot/limine.sys
|
||||
|
||||
FULL_KERNEL = $(ROOTFS)/$(REL_KERNEL)
|
||||
FULL_LIMINE_CD = $(ROOTFS)/$(REL_LIMINE_CD)
|
||||
FULL_LIMINE_CFG = $(ROOTFS)/$(REL_LIMINE_CFG)
|
||||
FULL_LIMINE_ELTORITO = $(ROOTFS)/$(REL_LIMINE_ELTORITO)
|
||||
FULL_LIMINE_SYS = $(ROOTFS)/$(REL_LIMINE_SYS)
|
||||
|
||||
CFLAGS = \
|
||||
-std=c99 \
|
||||
-pedantic \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-ffreestanding \
|
||||
-fno-stack-protector \
|
||||
-I$(LIBKERNAUX_DEST)/include
|
||||
|
||||
OBJS = main.c.o multiboot2.c.o start.S.o
|
||||
|
||||
test: run
|
||||
$(DIFF) -a -Z $(EXPECTED) $(OUTPUT)
|
||||
|
||||
run: $(IMAGE)
|
||||
$(QEMU) -cdrom $< | tee $(OUTPUT)
|
||||
|
||||
clean:
|
||||
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 $@
|
||||
$(LIMINE_INSTALL) $@
|
||||
|
||||
$(FULL_KERNEL): $(LINKERSCR) build-libkernaux.a $(OBJS)
|
||||
$(CC) -T $(LINKERSCR) -o $@ $(OBJS) -ffreestanding -nostdlib -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_DEST)/lib
|
||||
$(GRUB_FILE) --is-x86-multiboot2 $@
|
||||
|
||||
$(FULL_LIMINE_CD):
|
||||
cp -f $(LIMINE_CD) $(FULL_LIMINE_CD)
|
||||
|
||||
$(FULL_LIMINE_ELTORITO):
|
||||
cp -f $(LIMINE_ELTORITO) $(FULL_LIMINE_ELTORITO)
|
||||
|
||||
$(FULL_LIMINE_SYS):
|
||||
cp -f $(LIMINE_SYS) $(FULL_LIMINE_SYS)
|
||||
|
||||
build-libkernaux.a:
|
||||
cd $(LIBKERNAUX_BUILD) && ./config && make install
|
||||
|
||||
%.c.o: %.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
%.S.o: %.S
|
||||
$(AS) $< -o $@
|
|
@ -1,80 +0,0 @@
|
|||
Multiboot 2 header is valid
|
||||
Multiboot 2 header
|
||||
magic: 3897708758
|
||||
arch: 0 (i386)
|
||||
size: 24
|
||||
checksum: 397258514
|
||||
Multiboot 2 header tag
|
||||
type: 0 (none)
|
||||
flags: 0
|
||||
size: 8
|
||||
Multiboot 2 info magic number is valid
|
||||
Multiboot 2 info is valid
|
||||
Multiboot 2 info
|
||||
size: 952
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 1 (boot cmd line)
|
||||
size: 21
|
||||
cmdline: hello kernel
|
||||
Multiboot 2 info tag
|
||||
type: 2 (boot loader name)
|
||||
size: 15
|
||||
name: Limine
|
||||
Multiboot 2 info tag
|
||||
type: 13 (SMBIOS tables)
|
||||
size: 16
|
||||
major: 2
|
||||
minor: 8
|
||||
reserved1: {0, 0, 0, 0, 0, 0}
|
||||
Multiboot 2 info tag
|
||||
type: 9 (ELF symbols)
|
||||
size: 700
|
||||
num: 17
|
||||
entsize: 0
|
||||
shndx: 40
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 6 (memory map)
|
||||
size: 160
|
||||
entry size: 24
|
||||
entry version: 0
|
||||
entries:
|
||||
entry 0
|
||||
base addr: 0
|
||||
length: 654336
|
||||
type: 1
|
||||
reserved1: 0
|
||||
entry 1
|
||||
base addr: 654336
|
||||
length: 1024
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 2
|
||||
base addr: 983040
|
||||
length: 65536
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 3
|
||||
base addr: 1048576
|
||||
length: 133038080
|
||||
type: 1
|
||||
reserved1: 0
|
||||
entry 4
|
||||
base addr: 134086656
|
||||
length: 131072
|
||||
type: 2
|
||||
reserved1: 0
|
||||
entry 5
|
||||
base addr: 4294705152
|
||||
length: 262144
|
||||
type: 2
|
||||
reserved1: 0
|
||||
Multiboot 2 info tag
|
||||
type: 4 (basic memory info)
|
||||
size: 16
|
||||
mem lower: 639
|
||||
mem upper: 129920
|
||||
Multiboot 2 info tag
|
||||
type: 0 (none)
|
||||
size: 8
|
|
@ -1,38 +0,0 @@
|
|||
OUTPUT_ARCH("i386")
|
||||
ENTRY(_start)
|
||||
|
||||
_kernel_offset = 0xc0000000; /* 3 GiB */
|
||||
|
||||
_kernel_phys_base = 4M;
|
||||
_kernel_virt_base = (_kernel_phys_base + _kernel_offset);
|
||||
|
||||
_kernel_stack_size = _kernel_stack_end - _kernel_stack_start;
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = _kernel_phys_base;
|
||||
|
||||
.text BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.multiboot2);
|
||||
*(.text);
|
||||
}
|
||||
|
||||
.rodata BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.rodata);
|
||||
}
|
||||
|
||||
.data BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(.data);
|
||||
}
|
||||
|
||||
.bss BLOCK(4K) : ALIGN(4K)
|
||||
{
|
||||
*(COMMON);
|
||||
*(.bss);
|
||||
}
|
||||
|
||||
_kernel_size = . - _kernel_phys_base;
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
#include <kernaux/multiboot2.h>
|
||||
|
||||
extern const struct KernAux_Multiboot2_Header multiboot2_header;
|
||||
|
||||
static void panic(const char *str);
|
||||
|
||||
void main(
|
||||
const uint32_t multiboot2_info_magic,
|
||||
const struct KernAux_Multiboot2_Info *const multiboot2_info
|
||||
) {
|
||||
if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) {
|
||||
panic("Multiboot 2 header is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf("Multiboot 2 header is valid\n");
|
||||
}
|
||||
|
||||
KernAux_Multiboot2_Header_print(
|
||||
&multiboot2_header,
|
||||
kernaux_drivers_console_printf
|
||||
);
|
||||
|
||||
if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) {
|
||||
panic("Multiboot 2 info magic number is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf(
|
||||
"Multiboot 2 info magic number is valid\n"
|
||||
);
|
||||
}
|
||||
|
||||
if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) {
|
||||
panic("Multiboot 2 info is invalid");
|
||||
} else {
|
||||
kernaux_drivers_console_printf("Multiboot 2 info is valid\n");
|
||||
}
|
||||
|
||||
KernAux_Multiboot2_Info_print(
|
||||
multiboot2_info,
|
||||
kernaux_drivers_console_printf
|
||||
);
|
||||
}
|
||||
|
||||
void panic(const char *const str)
|
||||
{
|
||||
kernaux_drivers_console_printf("panic: %s\n", str);
|
||||
kernaux_drivers_shutdown_poweroff();
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#include <kernaux/multiboot2.h>
|
||||
|
||||
#include <kernaux/macro/packing_start.run>
|
||||
|
||||
// TODO: add more tags
|
||||
KERNAUX_SECTION(".multiboot2")
|
||||
KERNAUX_USED
|
||||
KERNAUX_ALIGNED(KERNAUX_MULTIBOOT2_HEADER_ALIGN)
|
||||
const struct {
|
||||
struct KernAux_Multiboot2_Header multiboot2_header;
|
||||
struct KernAux_Multiboot2_HTag_None tag_none;
|
||||
}
|
||||
KERNAUX_PACKED
|
||||
multiboot2_header = {
|
||||
.multiboot2_header = {
|
||||
.magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC,
|
||||
.arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||
.total_size = sizeof(multiboot2_header),
|
||||
.checksum = KERNAUX_MULTIBOOT2_HEADER_CHECKSUM(
|
||||
KERNAUX_MULTIBOOT2_HEADER_ARCH_I386,
|
||||
sizeof(multiboot2_header)
|
||||
),
|
||||
},
|
||||
.tag_none = {
|
||||
.base = {
|
||||
.type = KERNAUX_MULTIBOOT2_HTAG_NONE,
|
||||
.flags = 0,
|
||||
.size = sizeof(multiboot2_header.tag_none),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
#include <kernaux/macro/packing_end.run>
|
|
@ -1,8 +0,0 @@
|
|||
DEFAULT_ENTRY=1
|
||||
TIMEOUT=0
|
||||
|
||||
:Kernel
|
||||
|
||||
PROTOCOL=multiboot2
|
||||
KERNEL_PATH=boot:///boot/kernel
|
||||
KERNEL_CMDLINE=hello kernel
|
|
@ -1,27 +0,0 @@
|
|||
.section .bss
|
||||
|
||||
.global _kernel_stack_start
|
||||
.global _kernel_stack_end
|
||||
|
||||
.align 16
|
||||
_kernel_stack_start:
|
||||
.skip 16384 # 16 KiB
|
||||
_kernel_stack_end:
|
||||
|
||||
|
||||
|
||||
.section .text
|
||||
|
||||
.global _start
|
||||
|
||||
.type _start, @function
|
||||
|
||||
_start:
|
||||
mov $_kernel_stack_end, %esp // Initialize stack
|
||||
|
||||
push %ebx // Multiboot information pointer
|
||||
push %eax // Multiboot magic number
|
||||
call main
|
||||
call kernaux_drivers_shutdown_poweroff
|
||||
|
||||
.size _start, . - _start
|
1
examples/full/riscv64/.gitignore
vendored
1
examples/full/riscv64/.gitignore
vendored
|
@ -1 +0,0 @@
|
|||
/kernel.elf
|
|
@ -1,46 +0,0 @@
|
|||
all: run
|
||||
|
||||
REPO = ../../..
|
||||
|
||||
CCPREFIX = $(REPO)/vendor/cross/root/bin/riscv64-elf-
|
||||
|
||||
AS = $(CCPREFIX)as
|
||||
CC = $(CCPREFIX)gcc
|
||||
|
||||
LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-riscv64
|
||||
LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-riscv64
|
||||
|
||||
QEMU = qemu-system-riscv64 -serial stdio -display none
|
||||
|
||||
KERNEL = kernel.elf
|
||||
LINKERSCR = linker.ld
|
||||
|
||||
CFLAGS = \
|
||||
-std=c99 \
|
||||
-pedantic \
|
||||
-Wall \
|
||||
-Wextra \
|
||||
-Werror \
|
||||
-ffreestanding \
|
||||
-mcmodel=medany \
|
||||
-I$(LIBKERNAUX_DEST)/include
|
||||
|
||||
OBJS = main.c.o start.S.o
|
||||
|
||||
run: $(KERNEL)
|
||||
$(QEMU) -machine virt -bios $<
|
||||
|
||||
clean:
|
||||
rm -f $(KERNEL) $(OBJS)
|
||||
|
||||
$(KERNEL): $(LINKERSCR) build-libkernaux.a $(OBJS)
|
||||
$(CC) -T $(LINKERSCR) -o $@ $(OBJS) -nostdlib -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_DEST)/lib
|
||||
|
||||
build-libkernaux.a:
|
||||
cd $(LIBKERNAUX_BUILD) && ./config && make install
|
||||
|
||||
%.c.o: %.c
|
||||
$(CC) -c $< -o $@ $(CFLAGS)
|
||||
|
||||
%.S.o: %.S
|
||||
$(AS) $< -o $@
|
|
@ -1,33 +0,0 @@
|
|||
ENTRY(_start);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x80000000;
|
||||
|
||||
.text : ALIGN(4K)
|
||||
{
|
||||
*(.init);
|
||||
*(.text);
|
||||
}
|
||||
|
||||
.rodata : ALIGN(4K)
|
||||
{
|
||||
*(.rodata);
|
||||
}
|
||||
|
||||
.data : ALIGN(4K)
|
||||
{
|
||||
*(.data);
|
||||
}
|
||||
|
||||
.bss : ALIGN(4K)
|
||||
{
|
||||
PROVIDE(bss_start = .);
|
||||
*(.bss);
|
||||
. += 4096;
|
||||
PROVIDE(stack_top = .);
|
||||
. += 4096;
|
||||
PROVIDE(global_pointer = .);
|
||||
PROVIDE(bss_end = .);
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
|
||||
static unsigned char *const uart = (unsigned char*)0x10000000;
|
||||
|
||||
static void putchar(char c) {
|
||||
*uart = c;
|
||||
}
|
||||
|
||||
static void print(const char * str) {
|
||||
while (*str != '\0') {
|
||||
putchar(*str);
|
||||
str++;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
print("Hello world!\r\n");
|
||||
kernaux_drivers_shutdown_poweroff();
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
.section .init
|
||||
|
||||
.option norvc
|
||||
|
||||
.type _start, @function
|
||||
.global _start
|
||||
_start:
|
||||
.cfi_startproc
|
||||
|
||||
.option push
|
||||
.option norelax
|
||||
la gp, global_pointer
|
||||
.option pop
|
||||
|
||||
/* Reset satp */
|
||||
csrw satp, zero
|
||||
|
||||
/* Setup stack */
|
||||
la sp, stack_top
|
||||
|
||||
/* Clear the BSS section */
|
||||
la t5, bss_start
|
||||
la t6, bss_end
|
||||
bss_clear:
|
||||
sd zero, (t5)
|
||||
addi t5, t5, 8
|
||||
bgeu t5, t6, bss_clear
|
||||
|
||||
la t0, main
|
||||
csrw mepc, t0
|
||||
|
||||
/* Jump to kernel! */
|
||||
tail main
|
||||
|
||||
.cfi_endproc
|
||||
|
||||
.end
|
|
@ -89,27 +89,3 @@ endif
|
|||
if WITH_UNITS
|
||||
nobase_include_HEADERS += kernaux/units.h
|
||||
endif
|
||||
|
||||
###########
|
||||
# Drivers #
|
||||
###########
|
||||
|
||||
if WITH_DRIVERS
|
||||
nobase_include_HEADERS += \
|
||||
kernaux/drivers/console.h \
|
||||
kernaux/drivers/framebuffer.h \
|
||||
kernaux/drivers/shutdown.h
|
||||
|
||||
# Intel 8253-compatible programmable interval timer
|
||||
|
||||
if ASM_I386
|
||||
nobase_include_HEADERS += kernaux/drivers/intel_8253_pit.h
|
||||
endif
|
||||
|
||||
# Intel 8259-compatible programmable interrupt controller
|
||||
|
||||
if ASM_I386
|
||||
nobase_include_HEADERS += kernaux/drivers/intel_8259_pic.h
|
||||
endif
|
||||
|
||||
endif # WITH_DRIVERS
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
#ifndef KERNAUX_INCLUDED_DRIVERS_CONSOLE
|
||||
#define KERNAUX_INCLUDED_DRIVERS_CONSOLE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <kernaux/macro.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void kernaux_drivers_console_putc(char c);
|
||||
|
||||
void kernaux_drivers_console_print(const char *s);
|
||||
@comment_line_printf@KERNAUX_PRINTF(1, 2)
|
||||
@comment_line_printf@void kernaux_drivers_console_printf(const char *format, ...);
|
||||
void kernaux_drivers_console_puts(const char *s);
|
||||
void kernaux_drivers_console_write(const char *data, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
#ifndef KERNAUX_INCLUDED_DRIVERS_FRAMEBUFFER
|
||||
#define KERNAUX_INCLUDED_DRIVERS_FRAMEBUFFER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* @brief A driver for Intel 8253-compatible programmable interval timer
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Intel_8253
|
||||
* @see https://wiki.osdev.org/PIT
|
||||
*/
|
||||
|
||||
#ifndef KERNAUX_INCLUDED_DRIVERS_INTEL_8253_PIT
|
||||
#define KERNAUX_INCLUDED_DRIVERS_INTEL_8253_PIT
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void kernaux_drivers_intel_8253_pit_initialize(unsigned int freq);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,57 +0,0 @@
|
|||
/**
|
||||
* @brief A driver for Intel 8259-compatible programmable interrupt controller
|
||||
*
|
||||
* @details
|
||||
* This is not a driver for a random Intel 8259-compatible PIC, but only for a
|
||||
* typical configuration of it that can be found in most PCs.
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Intel_8259
|
||||
* @see https://wiki.osdev.org/8259_PIC
|
||||
* @see https://pdos.csail.mit.edu/6.828/2005/readings/hardware/8259A.pdf
|
||||
*/
|
||||
|
||||
#ifndef KERNAUX_INCLUDED_DRIVERS_INTEL_8259_PIC
|
||||
#define KERNAUX_INCLUDED_DRIVERS_INTEL_8259_PIC
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable PIC
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_enable_all();
|
||||
|
||||
/**
|
||||
* @brief Disable PIC
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_disable_all();
|
||||
|
||||
/**
|
||||
* @brief Enable single IRQ line
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_enable(unsigned char number);
|
||||
|
||||
/**
|
||||
* @brief Disable single IRQ line
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_disable(unsigned char number);
|
||||
|
||||
/**
|
||||
* @brief Remap PIC
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_remap(
|
||||
unsigned char new_master_start,
|
||||
unsigned char new_slave_start
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Signal end of interrupt
|
||||
*/
|
||||
void kernaux_drivers_intel_8259_pic_eoi(unsigned char number);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef KERNAUX_INCLUDED_DRIVERS_SHUTDOWN
|
||||
#define KERNAUX_INCLUDED_DRIVERS_SHUTDOWN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <kernaux/macro.h>
|
||||
|
||||
KERNAUX_NORETURN void kernaux_drivers_shutdown_halt();
|
||||
KERNAUX_NORETURN void kernaux_drivers_shutdown_poweroff();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,78 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/drivers/console.h>
|
||||
#include <kernaux/macro.h>
|
||||
|
||||
#ifdef ASM_I386
|
||||
#include <kernaux/asm/i386.h>
|
||||
#endif
|
||||
#ifdef ASM_X86_64
|
||||
#include <kernaux/asm/x86_64.h>
|
||||
#endif
|
||||
|
||||
#ifdef WITH_PRINTF
|
||||
#include <kernaux/printf.h>
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef WITH_PRINTF
|
||||
static void file_putc(char c, void *arg);
|
||||
#endif
|
||||
|
||||
void kernaux_drivers_console_putc(const char c)
|
||||
{
|
||||
#if defined(ASM_X86)
|
||||
kernaux_asm_x86_outportb(0x3f8, c);
|
||||
#else
|
||||
(void)c;
|
||||
#endif
|
||||
}
|
||||
|
||||
void kernaux_drivers_console_print(const char *const s)
|
||||
{
|
||||
KERNAUX_ASSERT(s);
|
||||
|
||||
for (const char *c = s; *c; ++c) {
|
||||
kernaux_drivers_console_putc(*c);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_PRINTF
|
||||
void kernaux_drivers_console_printf(const char *format, ...)
|
||||
{
|
||||
KERNAUX_ASSERT(format);
|
||||
|
||||
va_list va;
|
||||
va_start(va, format);
|
||||
kernaux_vfprintf(file_putc, NULL, format, va);
|
||||
va_end(va);
|
||||
}
|
||||
#endif
|
||||
|
||||
void kernaux_drivers_console_puts(const char *const s)
|
||||
{
|
||||
KERNAUX_ASSERT(s);
|
||||
|
||||
kernaux_drivers_console_print(s);
|
||||
kernaux_drivers_console_putc('\n');
|
||||
}
|
||||
|
||||
void kernaux_drivers_console_write(const char *const data, const size_t size)
|
||||
{
|
||||
KERNAUX_ASSERT(data);
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
kernaux_drivers_console_putc(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_PRINTF
|
||||
void file_putc(char c, void *arg KERNAUX_UNUSED)
|
||||
{
|
||||
kernaux_drivers_console_putc(c);
|
||||
}
|
||||
#endif
|
|
@ -1,9 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/drivers/framebuffer.h>
|
||||
#include <kernaux/macro.h>
|
||||
|
||||
KERNAUX_UNUSED
|
||||
static const int foobar = 0;
|
|
@ -1,26 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/drivers/intel_8253_pit.h>
|
||||
|
||||
#ifdef ASM_I386
|
||||
#include <kernaux/asm/i386.h>
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void kernaux_drivers_intel_8253_pit_initialize(const unsigned int freq)
|
||||
{
|
||||
KERNAUX_ASSERT(freq);
|
||||
|
||||
const unsigned int divisor = 1193180 / freq;
|
||||
|
||||
const uint8_t l = divisor & 0xff;
|
||||
const uint8_t h = (divisor >> 8) & 0xff;
|
||||
|
||||
kernaux_asm_x86_outportb(0x43, 0x36);
|
||||
kernaux_asm_x86_outportb(0x40, l);
|
||||
kernaux_asm_x86_outportb(0x40, h);
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/assert.h>
|
||||
#include <kernaux/drivers/intel_8259_pic.h>
|
||||
#include <kernaux/macro.h>
|
||||
|
||||
#ifdef ASM_I386
|
||||
#include <kernaux/asm/i386.h>
|
||||
#endif
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MASTER_COMMAND_PORT 0x20
|
||||
#define SLAVE_COMMAND_PORT 0xA0
|
||||
|
||||
#define MASTER_DATA_PORT 0x21
|
||||
#define SLAVE_DATA_PORT 0xA1
|
||||
|
||||
#define IRQS_COUNT 8
|
||||
#define IRQS_TOTAL 16
|
||||
|
||||
static unsigned char master_start = 0;
|
||||
static unsigned char slave_start = 8;
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_enable_all()
|
||||
{
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, 0);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, 0);
|
||||
}
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_disable_all()
|
||||
{
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, 0xFF);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, 0xFF);
|
||||
}
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_enable(const unsigned char number)
|
||||
{
|
||||
KERNAUX_ASSERT(number < IRQS_TOTAL);
|
||||
|
||||
if (number < IRQS_COUNT) {
|
||||
const uint8_t mask = kernaux_asm_x86_inportb(MASTER_DATA_PORT);
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT,
|
||||
mask & ~KERNAUX_BITS8(number));
|
||||
} else {
|
||||
const uint8_t mask = kernaux_asm_x86_inportb(SLAVE_DATA_PORT);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT,
|
||||
mask & ~KERNAUX_BITS8((number - IRQS_COUNT)));
|
||||
}
|
||||
}
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_disable(const unsigned char number)
|
||||
{
|
||||
KERNAUX_ASSERT(number < IRQS_TOTAL);
|
||||
|
||||
if (number < IRQS_COUNT) {
|
||||
const uint8_t mask = kernaux_asm_x86_inportb(MASTER_DATA_PORT);
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT,
|
||||
mask | KERNAUX_BITS8(number));
|
||||
} else {
|
||||
const uint8_t mask = kernaux_asm_x86_inportb(SLAVE_DATA_PORT);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT,
|
||||
mask | KERNAUX_BITS8((number - IRQS_COUNT)));
|
||||
}
|
||||
}
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_remap(
|
||||
const unsigned char new_master_start,
|
||||
const unsigned char new_slave_start
|
||||
) {
|
||||
master_start = new_master_start;
|
||||
slave_start = new_slave_start;
|
||||
|
||||
// Save masks
|
||||
const uint8_t master_mask = kernaux_asm_x86_inportb(MASTER_DATA_PORT);
|
||||
const uint8_t slave_mask = kernaux_asm_x86_inportb(SLAVE_DATA_PORT);
|
||||
|
||||
// Start the initialization sequence
|
||||
kernaux_asm_x86_outportb(MASTER_COMMAND_PORT, 0x11);
|
||||
kernaux_asm_x86_outportb(SLAVE_COMMAND_PORT, 0x11);
|
||||
|
||||
// Set IRQ vectors
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, new_master_start);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, new_slave_start);
|
||||
|
||||
// Connect master and slave with each other
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, 0x04);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, 0x02);
|
||||
|
||||
// 8086/88 (MCS-80/85) mode
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, 0x01);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, 0x01);
|
||||
|
||||
// Restore masks
|
||||
kernaux_asm_x86_outportb(MASTER_DATA_PORT, master_mask);
|
||||
kernaux_asm_x86_outportb(SLAVE_DATA_PORT, slave_mask);
|
||||
}
|
||||
|
||||
void kernaux_drivers_intel_8259_pic_eoi(const unsigned char number)
|
||||
{
|
||||
KERNAUX_ASSERT(number < IRQS_TOTAL);
|
||||
|
||||
const bool to_slave =
|
||||
number >= slave_start && number < slave_start + IRQS_COUNT;
|
||||
const bool to_master = to_slave ||
|
||||
(number >= master_start && number < master_start + IRQS_COUNT);
|
||||
|
||||
if (to_slave) kernaux_asm_x86_outportb(SLAVE_COMMAND_PORT, 0x20);
|
||||
if (to_master) kernaux_asm_x86_outportb(MASTER_COMMAND_PORT, 0x20);
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <kernaux/drivers/shutdown.h>
|
||||
|
||||
#ifdef ASM_X86
|
||||
#include <kernaux/asm/x86.h>
|
||||
#endif
|
||||
|
||||
void kernaux_drivers_shutdown_halt()
|
||||
{
|
||||
#ifdef ASM_X86
|
||||
// Disable interrupts
|
||||
KERNAUX_ASM("cli");
|
||||
#endif
|
||||
|
||||
volatile int x = 0;
|
||||
for (;;) ++x;
|
||||
}
|
||||
|
||||
void kernaux_drivers_shutdown_poweroff()
|
||||
{
|
||||
#ifdef ASM_X86
|
||||
// QEMU >= 2.0
|
||||
kernaux_asm_x86_outportw(0x604, 0x2000);
|
||||
// QEMU < 2.0
|
||||
kernaux_asm_x86_outportw(0xB004, 0x2000);
|
||||
#endif
|
||||
|
||||
// If we can't poweroff then we halt
|
||||
kernaux_drivers_shutdown_halt();
|
||||
}
|
1
vendor/limine
vendored
1
vendor/limine
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 3277ad25cfbe5150daeae2de61d2c0b6613b8a0b
|
1
vendor/opensbi
vendored
1
vendor/opensbi
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 4489876e933d8ba0d8bc6c64bae71e295d45faac
|
1
vendor/u-boot
vendored
1
vendor/u-boot
vendored
|
@ -1 +0,0 @@
|
|||
Subproject commit 4debc57a3da6c3f4d3f89a637e99206f4cea0a96
|
Loading…
Reference in a new issue