From e93d08ee70030bed61b098b664b774247b7fae25 Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Sat, 3 Dec 2022 14:23:52 +0400 Subject: [PATCH] Maintenance (#125) --- .github/workflows/main.yml | 12 ++++---- ChangeLog | 5 ++++ Makefile.am | 22 ++------------- README.md | 1 + configure.ac | 16 ++++------- examples/Makefile.am | 2 +- .../i386-multiboot2-grub}/.gitignore | 0 .../i386-multiboot2-grub}/Makefile | 26 ++++++++--------- .../i386-multiboot2-grub}/expected.txt | 0 .../i386-multiboot2-grub}/linker.ld | 0 .../i386-multiboot2-grub}/main.c | 11 ++------ .../i386-multiboot2-grub}/multiboot2.c | 11 ++++++-- .../rootfs/boot/grub/grub.cfg | 0 .../i386-multiboot2-grub}/start.S | 7 ++--- .../i386-multiboot2-limine}/.gitignore | 0 .../i386-multiboot2-limine}/Makefile | 28 +++++++++---------- .../i386-multiboot2-limine}/expected.txt | 0 .../i386-multiboot2-limine}/linker.ld | 0 .../i386-multiboot2-limine}/main.c | 11 ++------ .../i386-multiboot2-limine}/multiboot2.c | 11 ++++++-- .../rootfs/boot/limine.cfg | 0 .../i386-multiboot2-limine}/start.S | 7 ++--- .../riscv64}/.gitignore | 0 .../riscv64}/Makefile | 25 +++++++++-------- .../riscv64}/linker.ld | 0 .../{arch-riscv64-min => full/riscv64}/main.c | 3 ++ .../riscv64}/start.S | 0 examples/multiboot2_header_macro.c | 2 +- include/Makefile.am | 3 +- include/kernaux/drivers/console.h.in | 6 ++-- include/kernaux/drivers/qemu.h | 14 ---------- include/kernaux/macro.h | 7 ++++- include/kernaux/multiboot2.h.in | 24 ++++++---------- libc/Makefile.am | 2 +- make/checks.am | 16 +++++++++++ shared.am => make/shared.am | 0 test-suite-log => make/test-suite-log | 0 src/drivers/console.c | 7 +++-- src/drivers/qemu.c | 19 ------------- src/drivers/shutdown.c | 12 ++++++-- src/ntoa.c | 1 + src/pfa.c | 2 ++ tests/Makefile.am | 2 +- tests/multiboot2_header_example1.h | 8 +++++- tests/multiboot2_header_example2.h | 4 ++- tests/multiboot2_info_example2.h | 4 ++- tests/printf_gen.jinja | 2 +- vendor/opensbi | 2 +- vendor/u-boot | 2 +- 49 files changed, 161 insertions(+), 176 deletions(-) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/.gitignore (100%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/Makefile (67%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/expected.txt (100%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/linker.ld (100%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-grub}/main.c (90%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/multiboot2.c (78%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-grub}/rootfs/boot/grub/grub.cfg (100%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-grub}/start.S (79%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/.gitignore (100%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/Makefile (80%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/expected.txt (100%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/linker.ld (100%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-limine}/main.c (90%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/multiboot2.c (78%) rename examples/{bootloader-multiboot2-limine => full/i386-multiboot2-limine}/rootfs/boot/limine.cfg (100%) rename examples/{bootloader-multiboot2-grub => full/i386-multiboot2-limine}/start.S (79%) rename examples/{arch-riscv64-min => full/riscv64}/.gitignore (100%) rename examples/{arch-riscv64-min => full/riscv64}/Makefile (51%) rename examples/{arch-riscv64-min => full/riscv64}/linker.ld (100%) rename examples/{arch-riscv64-min => full/riscv64}/main.c (79%) rename examples/{arch-riscv64-min => full/riscv64}/start.S (100%) delete mode 100644 include/kernaux/drivers/qemu.h create mode 100644 make/checks.am rename shared.am => make/shared.am (100%) rename test-suite-log => make/test-suite-log (100%) delete mode 100644 src/drivers/qemu.c diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8e0c4e4..cc4a955 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,8 +17,8 @@ jobs: run: ./autogen.sh - name: configure run: ./configure --enable-checks-cppcheck - - name: cppcheck - run: make check-cppcheck + - name: check + run: make check test: runs-on: ubuntu-latest @@ -38,7 +38,7 @@ jobs: - name: make run: make - name: check - run: make check || (./test-suite-log && false) + run: make check || (./make/test-suite-log && false) - name: install run: sudo make install @@ -80,7 +80,7 @@ jobs: - name: make run: make - name: check - run: make check || (./test-suite-log && false) + run: make check || (./make/test-suite-log && false) - name: install run: sudo make install @@ -103,7 +103,7 @@ jobs: - name: make run: make - name: check - run: make check || (./test-suite-log && false) + run: make check || (./make/test-suite-log && false) - name: install run: sudo make install @@ -140,6 +140,6 @@ jobs: - name: make run: cd "libkernaux-$(cat VERSION)" && make - name: check - run: cd "libkernaux-$(cat VERSION)" && make check || (./test-suite-log && false) + run: cd "libkernaux-$(cat VERSION)" && make check || (./make/test-suite-log && false) - name: install run: cd "libkernaux-$(cat VERSION)" && sudo make install diff --git a/ChangeLog b/ChangeLog index fc36702..6408266 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-12-03 Alex Kotov + + * include/kernaux/macro.h: Add macros "KERNAUX_ALIGNED", "KERNAUX_PRINTF", + "KERNAUX_USED", "KERNAUX_SECTION" + 2022-12-02 Alex Kotov * configure.ac: Rename args "--enable-tests*" to "--enable-checks*" diff --git a/Makefile.am b/Makefile.am index 9441d17..3067a82 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ -include $(top_srcdir)/shared.am +include $(top_srcdir)/make/shared.am +include $(top_srcdir)/make/checks.am ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = autogen.sh CONTRIBUTING.md sha256sums.txt @@ -23,22 +24,6 @@ AM_CFLAGS += -DKERNAUX_ACCESS_PRIVATE lib_LTLIBRARIES = libkernaux.la -########## -# Checks # -########## - -MY_CHECKS = -check: $(MY_CHECKS) - -if ENABLE_CHECKS_CPPCHECK -MY_CHECKS += check-cppcheck -check-cppcheck: - $(CPPCHECK) $(CPPCHECK_ARGS) $(CPPCHECK_PATHS) - -CPPCHECK_ARGS = --quiet --error-exitcode=1 --std=c99 --inline-suppr --enable=warning,style,performance,portability -CPPCHECK_PATHS = examples/ include/ libc/ src/ tests/ -endif - ################## # Required files # ################## @@ -135,8 +120,7 @@ if WITH_DRIVERS libkernaux_la_SOURCES += \ src/drivers/console.c \ src/drivers/framebuffer.c \ - src/drivers/shutdown.c \ - src/drivers/qemu.c + src/drivers/shutdown.c # Intel 8253-compatible programmable interval timer diff --git a/README.md b/README.md index d7bbe82..0613dbd 100644 --- a/README.md +++ b/README.md @@ -138,6 +138,7 @@ stable options. * `--enable-checks` - enable usual tests and examples * `--enable-checks-all` - enable all tests +* `--enable-checks-cppcheck` - enable cppcheck * `--enable-checks-python` - enable tests that require Python 3 with YAML and Jinja2 diff --git a/configure.ac b/configure.ac index 83da5fa..2769ad0 100644 --- a/configure.ac +++ b/configure.ac @@ -7,9 +7,9 @@ LT_PREREQ([2.4.6]) -####################### -# Initialize Autoconf # -####################### +################################## +# Initialize Autoconf & Automake # +################################## AC_INIT([libkernaux], m4_normalize(m4_include([VERSION])), @@ -36,6 +36,8 @@ AC_CONFIG_FILES([ tests/Makefile ]) +AM_INIT_AUTOMAKE([1.16 subdir-objects]) + ############### @@ -316,14 +318,6 @@ AS_IF([test "$enable_freestanding" = yes], -####################### -# Initialize Automake # -####################### - -AM_INIT_AUTOMAKE([1.16 subdir-objects]) - - - ############## # Run checks # ############## diff --git a/examples/Makefile.am b/examples/Makefile.am index 3fda5ce..1308dfa 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -1,4 +1,4 @@ -include $(top_srcdir)/shared.am +include $(top_srcdir)/make/shared.am TESTS = noinst_PROGRAMS = $(TESTS) diff --git a/examples/bootloader-multiboot2-grub/.gitignore b/examples/full/i386-multiboot2-grub/.gitignore similarity index 100% rename from examples/bootloader-multiboot2-grub/.gitignore rename to examples/full/i386-multiboot2-grub/.gitignore diff --git a/examples/bootloader-multiboot2-grub/Makefile b/examples/full/i386-multiboot2-grub/Makefile similarity index 67% rename from examples/bootloader-multiboot2-grub/Makefile rename to examples/full/i386-multiboot2-grub/Makefile index 0059f72..daf80a2 100644 --- a/examples/bootloader-multiboot2-grub/Makefile +++ b/examples/full/i386-multiboot2-grub/Makefile @@ -1,13 +1,14 @@ all: test -CCPREFIX = ../../vendor/cross/root/bin/i386-elf- +REPO = ../../.. + +CCPREFIX = $(REPO)/vendor/cross/root/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc -LIBKERNAUX_SRC = ../.. -LIBKERNAUX_BUILD = ../../build/dev-cross-i386 -LIBKERNAUX_DEST = ../../dest/dev-cross-i386 +LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-i386 +LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-i386 DIFF = diff GRUB_FILE = grub-file @@ -24,15 +25,14 @@ GRUBCFG = $(ROOTFS)/boot/grub/grub.cfg KERNEL = $(ROOTFS)/boot/kernel CFLAGS = \ - -std=c99 \ - -pedantic \ - -Wall \ - -Wextra \ - -Werror \ - -ffreestanding \ - -fno-stack-protector \ - -I$(LIBKERNAUX_SRC)/include \ - -I$(LIBKERNAUX_BUILD)/include + -std=c99 \ + -pedantic \ + -Wall \ + -Wextra \ + -Werror \ + -ffreestanding \ + -fno-stack-protector \ + -I$(LIBKERNAUX_DEST)/include OBJS = main.c.o multiboot2.c.o start.S.o diff --git a/examples/bootloader-multiboot2-grub/expected.txt b/examples/full/i386-multiboot2-grub/expected.txt similarity index 100% rename from examples/bootloader-multiboot2-grub/expected.txt rename to examples/full/i386-multiboot2-grub/expected.txt diff --git a/examples/bootloader-multiboot2-grub/linker.ld b/examples/full/i386-multiboot2-grub/linker.ld similarity index 100% rename from examples/bootloader-multiboot2-grub/linker.ld rename to examples/full/i386-multiboot2-grub/linker.ld diff --git a/examples/bootloader-multiboot2-limine/main.c b/examples/full/i386-multiboot2-grub/main.c similarity index 90% rename from examples/bootloader-multiboot2-limine/main.c rename to examples/full/i386-multiboot2-grub/main.c index b131c12..223b314 100644 --- a/examples/bootloader-multiboot2-limine/main.c +++ b/examples/full/i386-multiboot2-grub/main.c @@ -1,12 +1,10 @@ #include #include -#include #include +#include #include -void poweroff(); - extern const struct KernAux_Multiboot2_Header multiboot2_header; static void panic(const char *str); @@ -46,13 +44,8 @@ void main( ); } -void poweroff() -{ - kernaux_asm_i386_outportw(0x604, 0x2000); -} - void panic(const char *const str) { kernaux_drivers_console_printf("panic: %s\n", str); - poweroff(); + kernaux_drivers_shutdown_poweroff(); } diff --git a/examples/bootloader-multiboot2-grub/multiboot2.c b/examples/full/i386-multiboot2-grub/multiboot2.c similarity index 78% rename from examples/bootloader-multiboot2-grub/multiboot2.c rename to examples/full/i386-multiboot2-grub/multiboot2.c index acaf61a..919967e 100644 --- a/examples/bootloader-multiboot2-grub/multiboot2.c +++ b/examples/full/i386-multiboot2-grub/multiboot2.c @@ -1,13 +1,16 @@ #include +#include + // TODO: add more tags -__attribute__((section(".multiboot2"), used)) -__attribute__((aligned(KERNAUX_MULTIBOOT2_HEADER_ALIGN))) +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; } -__attribute__((packed)) +KERNAUX_PACKED multiboot2_header = { .multiboot2_header = { .magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC, @@ -26,3 +29,5 @@ multiboot2_header = { }, }, }; + +#include diff --git a/examples/bootloader-multiboot2-grub/rootfs/boot/grub/grub.cfg b/examples/full/i386-multiboot2-grub/rootfs/boot/grub/grub.cfg similarity index 100% rename from examples/bootloader-multiboot2-grub/rootfs/boot/grub/grub.cfg rename to examples/full/i386-multiboot2-grub/rootfs/boot/grub/grub.cfg diff --git a/examples/bootloader-multiboot2-limine/start.S b/examples/full/i386-multiboot2-grub/start.S similarity index 79% rename from examples/bootloader-multiboot2-limine/start.S rename to examples/full/i386-multiboot2-grub/start.S index 5c6a4f1..713cdd0 100644 --- a/examples/bootloader-multiboot2-limine/start.S +++ b/examples/full/i386-multiboot2-grub/start.S @@ -14,9 +14,7 @@ _kernel_stack_end: .global _start -.type _start, @function -.type main, @function -.type poweroff, @function +.type _start, @function _start: mov $_kernel_stack_end, %esp // Initialize stack @@ -24,7 +22,6 @@ _start: push %ebx // Multiboot information pointer push %eax // Multiboot magic number call main - - call poweroff + call kernaux_drivers_shutdown_poweroff .size _start, . - _start diff --git a/examples/bootloader-multiboot2-limine/.gitignore b/examples/full/i386-multiboot2-limine/.gitignore similarity index 100% rename from examples/bootloader-multiboot2-limine/.gitignore rename to examples/full/i386-multiboot2-limine/.gitignore diff --git a/examples/bootloader-multiboot2-limine/Makefile b/examples/full/i386-multiboot2-limine/Makefile similarity index 80% rename from examples/bootloader-multiboot2-limine/Makefile rename to examples/full/i386-multiboot2-limine/Makefile index a488e54..3f81acf 100644 --- a/examples/bootloader-multiboot2-limine/Makefile +++ b/examples/full/i386-multiboot2-limine/Makefile @@ -1,17 +1,18 @@ all: test -CCPREFIX = ../../vendor/cross/root/bin/i386-elf- +REPO = ../../.. + +CCPREFIX = $(REPO)/vendor/cross/root/bin/i386-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc -LIBKERNAUX_SRC = ../.. -LIBKERNAUX_BUILD = ../../build/dev-cross-i386 -LIBKERNAUX_DEST = ../../dest/dev-cross-i386 +LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-i386 +LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-i386 DIFF = diff GRUB_FILE = grub-file -LIMINE = ../../vendor/limine/build/bin +LIMINE = $(REPO)/vendor/limine/build/bin QEMU = qemu-system-x86_64 -serial stdio -display none XORRISO = xorriso @@ -39,15 +40,14 @@ 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_SRC)/include \ - -I$(LIBKERNAUX_BUILD)/include + -std=c99 \ + -pedantic \ + -Wall \ + -Wextra \ + -Werror \ + -ffreestanding \ + -fno-stack-protector \ + -I$(LIBKERNAUX_DEST)/include OBJS = main.c.o multiboot2.c.o start.S.o diff --git a/examples/bootloader-multiboot2-limine/expected.txt b/examples/full/i386-multiboot2-limine/expected.txt similarity index 100% rename from examples/bootloader-multiboot2-limine/expected.txt rename to examples/full/i386-multiboot2-limine/expected.txt diff --git a/examples/bootloader-multiboot2-limine/linker.ld b/examples/full/i386-multiboot2-limine/linker.ld similarity index 100% rename from examples/bootloader-multiboot2-limine/linker.ld rename to examples/full/i386-multiboot2-limine/linker.ld diff --git a/examples/bootloader-multiboot2-grub/main.c b/examples/full/i386-multiboot2-limine/main.c similarity index 90% rename from examples/bootloader-multiboot2-grub/main.c rename to examples/full/i386-multiboot2-limine/main.c index b131c12..223b314 100644 --- a/examples/bootloader-multiboot2-grub/main.c +++ b/examples/full/i386-multiboot2-limine/main.c @@ -1,12 +1,10 @@ #include #include -#include #include +#include #include -void poweroff(); - extern const struct KernAux_Multiboot2_Header multiboot2_header; static void panic(const char *str); @@ -46,13 +44,8 @@ void main( ); } -void poweroff() -{ - kernaux_asm_i386_outportw(0x604, 0x2000); -} - void panic(const char *const str) { kernaux_drivers_console_printf("panic: %s\n", str); - poweroff(); + kernaux_drivers_shutdown_poweroff(); } diff --git a/examples/bootloader-multiboot2-limine/multiboot2.c b/examples/full/i386-multiboot2-limine/multiboot2.c similarity index 78% rename from examples/bootloader-multiboot2-limine/multiboot2.c rename to examples/full/i386-multiboot2-limine/multiboot2.c index acaf61a..919967e 100644 --- a/examples/bootloader-multiboot2-limine/multiboot2.c +++ b/examples/full/i386-multiboot2-limine/multiboot2.c @@ -1,13 +1,16 @@ #include +#include + // TODO: add more tags -__attribute__((section(".multiboot2"), used)) -__attribute__((aligned(KERNAUX_MULTIBOOT2_HEADER_ALIGN))) +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; } -__attribute__((packed)) +KERNAUX_PACKED multiboot2_header = { .multiboot2_header = { .magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC, @@ -26,3 +29,5 @@ multiboot2_header = { }, }, }; + +#include diff --git a/examples/bootloader-multiboot2-limine/rootfs/boot/limine.cfg b/examples/full/i386-multiboot2-limine/rootfs/boot/limine.cfg similarity index 100% rename from examples/bootloader-multiboot2-limine/rootfs/boot/limine.cfg rename to examples/full/i386-multiboot2-limine/rootfs/boot/limine.cfg diff --git a/examples/bootloader-multiboot2-grub/start.S b/examples/full/i386-multiboot2-limine/start.S similarity index 79% rename from examples/bootloader-multiboot2-grub/start.S rename to examples/full/i386-multiboot2-limine/start.S index 5c6a4f1..713cdd0 100644 --- a/examples/bootloader-multiboot2-grub/start.S +++ b/examples/full/i386-multiboot2-limine/start.S @@ -14,9 +14,7 @@ _kernel_stack_end: .global _start -.type _start, @function -.type main, @function -.type poweroff, @function +.type _start, @function _start: mov $_kernel_stack_end, %esp // Initialize stack @@ -24,7 +22,6 @@ _start: push %ebx // Multiboot information pointer push %eax // Multiboot magic number call main - - call poweroff + call kernaux_drivers_shutdown_poweroff .size _start, . - _start diff --git a/examples/arch-riscv64-min/.gitignore b/examples/full/riscv64/.gitignore similarity index 100% rename from examples/arch-riscv64-min/.gitignore rename to examples/full/riscv64/.gitignore diff --git a/examples/arch-riscv64-min/Makefile b/examples/full/riscv64/Makefile similarity index 51% rename from examples/arch-riscv64-min/Makefile rename to examples/full/riscv64/Makefile index ac2b684..f3ba738 100644 --- a/examples/arch-riscv64-min/Makefile +++ b/examples/full/riscv64/Makefile @@ -1,12 +1,14 @@ all: run -CCPREFIX = ../../vendor/cross/root/bin/riscv64-elf- +REPO = ../../.. + +CCPREFIX = $(REPO)/vendor/cross/root/bin/riscv64-elf- AS = $(CCPREFIX)as CC = $(CCPREFIX)gcc -LIBKERNAUX_BUILD = ../../build/dev-cross-riscv64 -LIBKERNAUX_DEST = ../../dest/dev-cross-riscv64 +LIBKERNAUX_BUILD = $(REPO)/build/dev-cross-riscv64 +LIBKERNAUX_DEST = $(REPO)/dest/dev-cross-riscv64 QEMU = qemu-system-riscv64 -serial stdio -display none @@ -14,13 +16,14 @@ KERNEL = kernel.elf LINKERSCR = linker.ld CFLAGS = \ - -std=c99 \ - -pedantic \ - -Wall \ - -Wextra \ - -Werror \ - -ffreestanding \ - -mcmodel=medany + -std=c99 \ + -pedantic \ + -Wall \ + -Wextra \ + -Werror \ + -ffreestanding \ + -mcmodel=medany \ + -I$(LIBKERNAUX_DEST)/include OBJS = main.c.o start.S.o @@ -30,7 +33,7 @@ run: $(KERNEL) clean: rm -f $(KERNEL) $(OBJS) -$(KERNEL): $(LINKERSCR) $(OBJS) build-libkernaux.a +$(KERNEL): $(LINKERSCR) build-libkernaux.a $(OBJS) $(CC) -T $(LINKERSCR) -o $@ $(OBJS) -nostdlib -lkernaux -lgcc -Wl,-L$(LIBKERNAUX_DEST)/lib build-libkernaux.a: diff --git a/examples/arch-riscv64-min/linker.ld b/examples/full/riscv64/linker.ld similarity index 100% rename from examples/arch-riscv64-min/linker.ld rename to examples/full/riscv64/linker.ld diff --git a/examples/arch-riscv64-min/main.c b/examples/full/riscv64/main.c similarity index 79% rename from examples/arch-riscv64-min/main.c rename to examples/full/riscv64/main.c index 3dc692b..9c5826a 100644 --- a/examples/arch-riscv64-min/main.c +++ b/examples/full/riscv64/main.c @@ -1,6 +1,8 @@ #include #include +#include + static unsigned char *const uart = (unsigned char*)0x10000000; static void putchar(char c) { @@ -16,4 +18,5 @@ static void print(const char * str) { void main() { print("Hello world!\r\n"); + kernaux_drivers_shutdown_poweroff(); } diff --git a/examples/arch-riscv64-min/start.S b/examples/full/riscv64/start.S similarity index 100% rename from examples/arch-riscv64-min/start.S rename to examples/full/riscv64/start.S diff --git a/examples/multiboot2_header_macro.c b/examples/multiboot2_header_macro.c index 1cf5faa..779c4fd 100644 --- a/examples/multiboot2_header_macro.c +++ b/examples/multiboot2_header_macro.c @@ -4,7 +4,7 @@ #include -__attribute__((aligned(KERNAUX_MULTIBOOT2_HEADER_ALIGN))) +KERNAUX_ALIGNED(KERNAUX_MULTIBOOT2_HEADER_ALIGN) static const struct { struct KernAux_Multiboot2_Header header; // This macro may be used to create the tag diff --git a/include/Makefile.am b/include/Makefile.am index bce1eb0..ba0be6c 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -98,8 +98,7 @@ if WITH_DRIVERS nobase_include_HEADERS += \ kernaux/drivers/console.h \ kernaux/drivers/framebuffer.h \ - kernaux/drivers/shutdown.h \ - kernaux/drivers/qemu.h + kernaux/drivers/shutdown.h # Intel 8253-compatible programmable interval timer diff --git a/include/kernaux/drivers/console.h.in b/include/kernaux/drivers/console.h.in index d8d63d1..491ac5f 100644 --- a/include/kernaux/drivers/console.h.in +++ b/include/kernaux/drivers/console.h.in @@ -5,13 +5,15 @@ extern "C" { #endif +#include + #include void kernaux_drivers_console_putc(char c); void kernaux_drivers_console_print(const char *s); -@comment_line_printf@void kernaux_drivers_console_printf(const char *format, ...) -@comment_line_printf@__attribute__((format(printf, 1, 2))); +@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); diff --git a/include/kernaux/drivers/qemu.h b/include/kernaux/drivers/qemu.h deleted file mode 100644 index f1cf6cf..0000000 --- a/include/kernaux/drivers/qemu.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef KERNAUX_INCLUDED_DRIVERS_QEMU -#define KERNAUX_INCLUDED_DRIVERS_QEMU - -#ifdef __cplusplus -extern "C" { -#endif - -void kernaux_drivers_qemu_poweroff(); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/include/kernaux/macro.h b/include/kernaux/macro.h index a6e8217..50f8bfc 100644 --- a/include/kernaux/macro.h +++ b/include/kernaux/macro.h @@ -12,9 +12,14 @@ extern "C" { * Language features * *********************/ -#define KERNAUX_UNUSED __attribute__((unused)) #define KERNAUX_NORETURN __attribute__((noreturn)) #define KERNAUX_RETURNS_TWICE __attribute__((returns_twice)) +#define KERNAUX_UNUSED __attribute__((unused)) +#define KERNAUX_USED __attribute__((used)) + +#define KERNAUX_ALIGNED(num) __attribute__((aligned(num))) +#define KERNAUX_PRINTF(fmt, rest) __attribute__((format(printf, fmt, rest))) +#define KERNAUX_SECTION(name) __attribute__((section(name))) #ifdef __TINYC__ # define KERNAUX_PACKED diff --git a/include/kernaux/multiboot2.h.in b/include/kernaux/multiboot2.h.in index 5b1d94b..66383e5 100644 --- a/include/kernaux/multiboot2.h.in +++ b/include/kernaux/multiboot2.h.in @@ -789,14 +789,12 @@ bool KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr_is_valid( void KernAux_Multiboot2_Header_print( const struct KernAux_Multiboot2_Header *multiboot2_header, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_HTagBase_print( const struct KernAux_Multiboot2_HTagBase *tag_base, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); /******************************* @@ -805,38 +803,32 @@ void KernAux_Multiboot2_HTagBase_print( void KernAux_Multiboot2_Info_print( const struct KernAux_Multiboot2_Info *multiboot2_info, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_ITagBase_print( const struct KernAux_Multiboot2_ITagBase *tag_base, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_ITag_BootCmdLine_print( const struct KernAux_Multiboot2_ITag_BootCmdLine *tag, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_ITag_BootLoaderName_print( const struct KernAux_Multiboot2_ITag_BootLoaderName *tag, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_ITag_MemoryMap_print( const struct KernAux_Multiboot2_ITag_MemoryMap *tag, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); void KernAux_Multiboot2_ITag_ELFSymbols_print( const struct KernAux_Multiboot2_ITag_ELFSymbols *tag, - void (*printf)(const char *format, ...) - __attribute__((format(printf, 1, 2))) + void (*printf)(const char *format, ...) KERNAUX_PRINTF(1, 2) ); #ifdef __cplusplus diff --git a/libc/Makefile.am b/libc/Makefile.am index dcee272..524872f 100644 --- a/libc/Makefile.am +++ b/libc/Makefile.am @@ -1,4 +1,4 @@ -include $(top_srcdir)/shared.am +include $(top_srcdir)/make/shared.am SUBDIRS = include diff --git a/make/checks.am b/make/checks.am new file mode 100644 index 0000000..278aceb --- /dev/null +++ b/make/checks.am @@ -0,0 +1,16 @@ +# vim: set syntax=automake: + +MY_CHECKS = +check: $(MY_CHECKS) + +if ENABLE_CHECKS_CPPCHECK +MY_CHECKS += check-cppcheck +check-cppcheck: + $(CPPCHECK) $(CPPCHECK_ARGS) $(CPPCHECK_INC) $(CPPCHECK_SUPPRESS) $(CPPCHECK_PATHS) + +CPPCHECK_ARGS = --quiet --error-exitcode=1 --std=c99 --inline-suppr --enable=warning,style,performance,portability +CPPCHECK_INC = -I$(top_builddir)/include -I$(top_srcdir)/include +CPPCHECK_SUPPRESS = --suppress='unusedStructMember:examples/multiboot2_header_macro.c' +CPPCHECK_SUPPRESS += --suppress='unusedStructMember:tests/test_multiboot2_info_*.c' +CPPCHECK_PATHS = examples/ include/ libc/ src/ tests/ +endif diff --git a/shared.am b/make/shared.am similarity index 100% rename from shared.am rename to make/shared.am diff --git a/test-suite-log b/make/test-suite-log similarity index 100% rename from test-suite-log rename to make/test-suite-log diff --git a/src/drivers/console.c b/src/drivers/console.c index 49839a3..7a53f5e 100644 --- a/src/drivers/console.c +++ b/src/drivers/console.c @@ -4,6 +4,7 @@ #include #include +#include #ifdef ASM_I386 #include @@ -22,10 +23,12 @@ static void file_putc(char c, void *arg); #endif -void kernaux_drivers_console_putc(const char c KERNAUX_UNUSED) +void kernaux_drivers_console_putc(const char c) { -#ifdef ASM_X86 +#if defined(ASM_X86) kernaux_asm_x86_outportb(0x3f8, c); +#else + (void)c; #endif } diff --git a/src/drivers/qemu.c b/src/drivers/qemu.c deleted file mode 100644 index 842820e..0000000 --- a/src/drivers/qemu.c +++ /dev/null @@ -1,19 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#ifdef ASM_X86 -#include -#endif - -void kernaux_drivers_qemu_poweroff() -{ -#ifdef ASM_X86 - // QEMU >= 2.0 - kernaux_asm_x86_outportw(0x604, 0x2000); - // QEMU < 2.0 - kernaux_asm_x86_outportw(0xB004, 0x2000); -#endif -} diff --git a/src/drivers/shutdown.c b/src/drivers/shutdown.c index f097575..881de2f 100644 --- a/src/drivers/shutdown.c +++ b/src/drivers/shutdown.c @@ -3,7 +3,10 @@ #endif #include -#include + +#ifdef ASM_X86 +#include +#endif void kernaux_drivers_shutdown_halt() { @@ -18,7 +21,12 @@ void kernaux_drivers_shutdown_halt() void kernaux_drivers_shutdown_poweroff() { - kernaux_drivers_qemu_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(); diff --git a/src/ntoa.c b/src/ntoa.c index 447da60..561e008 100644 --- a/src/ntoa.c +++ b/src/ntoa.c @@ -12,6 +12,7 @@ char *kernaux_utoa(uint64_t value, char *buffer, int base, const char *prefix) KERNAUX_ASSERT(buffer); // Protect caller from invalid state in case of future assertions + // cppcheck-suppress ctunullpointer *buffer = '\0'; switch (base) { diff --git a/src/pfa.c b/src/pfa.c index e54e59b..76aec89 100644 --- a/src/pfa.c +++ b/src/pfa.c @@ -42,6 +42,7 @@ static void KernAux_PFA_mark( void KernAux_PFA_initialize(const KernAux_PFA pfa) { KERNAUX_ASSERT(pfa); + // cppcheck-suppress ctunullpointer memset(pfa->flags, 0, sizeof(pfa->flags)); } @@ -50,6 +51,7 @@ bool KernAux_PFA_is_available(const KernAux_PFA pfa, const size_t page_addr) KERNAUX_ASSERT(pfa); KERNAUX_ASSERT(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); + // cppcheck-suppress ctunullpointer return GET_FLAG_FROM_ADDR(pfa, page_addr); } diff --git a/tests/Makefile.am b/tests/Makefile.am index 41f3e14..aa54c1b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,4 +1,4 @@ -include $(top_srcdir)/shared.am +include $(top_srcdir)/make/shared.am CLEANFILES = TESTS = diff --git a/tests/multiboot2_header_example1.h b/tests/multiboot2_header_example1.h index 93cdc03..5d743db 100644 --- a/tests/multiboot2_header_example1.h +++ b/tests/multiboot2_header_example1.h @@ -1,7 +1,11 @@ +#include + static const struct { struct KernAux_Multiboot2_Header multiboot2_header; struct KernAux_Multiboot2_HTag_None tag_none; -} multiboot2_header_example1 = { +} +KERNAUX_PACKED +multiboot2_header_example1 = { .multiboot2_header = { .magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC, .arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_MIPS32, @@ -19,3 +23,5 @@ static const struct { }, }, }; + +#include diff --git a/tests/multiboot2_header_example2.h b/tests/multiboot2_header_example2.h index 6bd4af9..26d3e59 100644 --- a/tests/multiboot2_header_example2.h +++ b/tests/multiboot2_header_example2.h @@ -34,7 +34,9 @@ static const struct { struct KernAux_Multiboot2_HTag_RelocatableHeader tag_relocatable_header; struct KernAux_Multiboot2_HTag_None tag_none; -} KERNAUX_PACKED multiboot2_header_example2 = { +} +KERNAUX_PACKED +multiboot2_header_example2 = { .multiboot2_header = { .magic = KERNAUX_MULTIBOOT2_HEADER_MAGIC, .arch = KERNAUX_MULTIBOOT2_HEADER_ARCH_I386, diff --git a/tests/multiboot2_info_example2.h b/tests/multiboot2_info_example2.h index fe9c1dc..f807a34 100644 --- a/tests/multiboot2_info_example2.h +++ b/tests/multiboot2_info_example2.h @@ -105,7 +105,9 @@ static const struct { uint8_t _align11[4]; struct KernAux_Multiboot2_ITag_None tag_none; -} KERNAUX_PACKED multiboot2_info_example2 = { +} +KERNAUX_PACKED +multiboot2_info_example2 = { .multiboot2_info = { .total_size = sizeof(multiboot2_info_example2), .reserved1 = 0, diff --git a/tests/printf_gen.jinja b/tests/printf_gen.jinja index 47ec110..3d1cf4a 100644 --- a/tests/printf_gen.jinja +++ b/tests/printf_gen.jinja @@ -20,7 +20,7 @@ static const char *const data = "foobar"; static char buffer[BUFFER_SIZE]; static size_t buffer_index; -static void test_putc(char c, KERNAUX_UNUSED void *arg) +static void test_putc(char c, void *arg KERNAUX_UNUSED) { if (buffer_index >= BUFFER_SIZE) { printf("Buffer overflow!\n"); diff --git a/vendor/opensbi b/vendor/opensbi index 6dde435..4489876 160000 --- a/vendor/opensbi +++ b/vendor/opensbi @@ -1 +1 @@ -Subproject commit 6dde43584f185f71a8dd713deb438d7c724a9ad5 +Subproject commit 4489876e933d8ba0d8bc6c64bae71e295d45faac diff --git a/vendor/u-boot b/vendor/u-boot index 0962da9..4debc57 160000 --- a/vendor/u-boot +++ b/vendor/u-boot @@ -1 +1 @@ -Subproject commit 0962da92a1dfb210eef8c936e33862812fa1b208 +Subproject commit 4debc57a3da6c3f4d3f89a637e99206f4cea0a96