Move drivers to separate subdirectory (#91)

This commit is contained in:
Alex Kotov 2022-06-23 13:43:53 +03:00 committed by GitHub
parent 2ad235f319
commit c331e6dafd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 193 additions and 107 deletions

View File

@ -94,6 +94,22 @@ jobs:
- name: install - name: install
run: sudo make install run: sudo make install
freestanding:
runs-on: ubuntu-latest
strategy:
matrix:
debug: ['--disable-debug', '--enable-debug']
steps:
- uses: actions/checkout@v2
- name: dependencies
run: sudo apt-get --yes install crossbuild-essential-i386
- 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)"
- name: make
run: make
dist: dist:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:

2
.gitignore vendored
View File

@ -101,7 +101,7 @@
/include/Makefile /include/Makefile
/include/kernaux.h /include/kernaux.h
/include/kernaux/console.h /include/kernaux/drivers/console.h
/include/kernaux/multiboot2.h /include/kernaux/multiboot2.h
/include/kernaux/printf.h /include/kernaux/printf.h
/include/kernaux/version.h /include/kernaux/version.h

View File

@ -1,3 +1,7 @@
2022-06-23 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Added package "drivers"
2022-06-22 Alex Kotov <kotovalexarian@gmail.com> 2022-06-22 Alex Kotov <kotovalexarian@gmail.com>
* include/kernaux/free_list.h: Finished * include/kernaux/free_list.h: Finished

View File

@ -23,6 +23,10 @@ AM_CFLAGS += -DKERNAUX_ACCESS_PRIVATE
lib_LTLIBRARIES = libkernaux.la lib_LTLIBRARIES = libkernaux.la
##################
# Required files #
##################
libkernaux_la_LIBADD = libkernaux_la_LIBADD =
libkernaux_la_SOURCES = \ libkernaux_la_SOURCES = \
src/assert.c \ src/assert.c \
@ -30,6 +34,18 @@ libkernaux_la_SOURCES = \
src/generic/malloc.c \ src/generic/malloc.c \
src/generic/mutex.c src/generic/mutex.c
########
# libc #
########
if WITH_LIBC
libkernaux_la_LIBADD += libc/libc.la
endif
#######
# ASM #
#######
if ASM_I386 if ASM_I386
libkernaux_la_SOURCES += src/asm/i386.S libkernaux_la_SOURCES += src/asm/i386.S
endif endif
@ -39,27 +55,34 @@ endif
if ASM_X86_64 if ASM_X86_64
libkernaux_la_SOURCES += src/asm/x86_64.S libkernaux_la_SOURCES += src/asm/x86_64.S
endif endif
###########
# Drivers #
###########
if WITH_DRIVERS
libkernaux_la_SOURCES += \
src/drivers/console.c \
src/drivers/framebuffer.c \
src/drivers/intel_8259_pic.c
endif
####################
# Default packages #
####################
if WITH_CMDLINE if WITH_CMDLINE
libkernaux_la_SOURCES += src/cmdline.c libkernaux_la_SOURCES += src/cmdline.c
endif endif
if WITH_CONSOLE
libkernaux_la_SOURCES += src/console.c
endif
if WITH_ELF if WITH_ELF
libkernaux_la_SOURCES += src/elf.c libkernaux_la_SOURCES += src/elf.c
endif endif
if WITH_FRAMEBUFFER
libkernaux_la_SOURCES += src/framebuffer.c
endif
if WITH_FREE_LIST if WITH_FREE_LIST
libkernaux_la_SOURCES += src/free_list.c libkernaux_la_SOURCES += src/free_list.c
endif endif
if WITH_IO if WITH_IO
libkernaux_la_SOURCES += src/io.c libkernaux_la_SOURCES += src/io.c
endif endif
if WITH_LIBC
libkernaux_la_LIBADD += libc/libc.la
endif
if WITH_MBR if WITH_MBR
libkernaux_la_SOURCES += src/mbr.c libkernaux_la_SOURCES += src/mbr.c
endif endif

View File

@ -53,10 +53,6 @@ zero). Work-in-progress APIs can change at any time.
* [Example](/examples/generic_malloc.c) * [Example](/examples/generic_malloc.c)
* [Mutex](/include/kernaux/generic/mutex.h) (*non-breaking since* **?.?.?**) * [Mutex](/include/kernaux/generic/mutex.h) (*non-breaking since* **?.?.?**)
* [Example](/examples/generic_mutex.c) * [Example](/examples/generic_mutex.c)
* Device drivers (for debugging only)
* [Serial console](/include/kernaux/console.h) (*work in progress*)
* [Framebuffer](/include/kernaux/framebuffer.h) (*planned*)
* USB (*planned*)
* Algorithms * Algorithms
* [Free list memory allocator](/include/kernaux/free_list.h) (*non-breaking since* **?.?.?**) * [Free list memory allocator](/include/kernaux/free_list.h) (*non-breaking since* **?.?.?**)
* [Simple command line parser](/include/kernaux/cmdline.h) (*non-breaking since* **0.2.0**) * [Simple command line parser](/include/kernaux/cmdline.h) (*non-breaking since* **0.2.0**)
@ -91,6 +87,11 @@ zero). Work-in-progress APIs can change at any time.
* [stdlib.h](/libc/include/stdlib.h) * [stdlib.h](/libc/include/stdlib.h)
* [string.h](/libc/include/string.h) * [string.h](/libc/include/string.h)
* [sys/types.h](/libc/include/sys/types.h) * [sys/types.h](/libc/include/sys/types.h)
* Device drivers (for debugging only)
* [Serial console](/include/kernaux/drivers/console.h) (*work in progress*)
* [Framebuffer](/include/kernaux/drivers/framebuffer.h) (*planned*)
* [Intel 8259 PIC](/include/kernaux/drivers/intel_8259_pic.h) (*planned*)
* USB (*planned*)
### Definitions ### Definitions
@ -138,6 +139,7 @@ stable options.
#### Packages #### Packages
* `--with-drivers` - device drivers
* `--with-libc` - provides the replacement for some standard C functions. * `--with-libc` - provides the replacement for some standard C functions.
Useful in freestanding environment, where no libc is present. Useful in freestanding environment, where no libc is present.
@ -200,6 +202,7 @@ without it in `$PATH`:
./configure \ ./configure \
--host='i386-elf' \ --host='i386-elf' \
--enable-freestanding \ --enable-freestanding \
--with-drivers \
--with-libc \ --with-libc \
AR="$(which i386-elf-ar)" \ AR="$(which i386-elf-ar)" \
CC="$(which i386-elf-gcc)" \ CC="$(which i386-elf-gcc)" \

View File

@ -14,4 +14,4 @@ export AR="$CROSS-ar"
export CC="$CROSS-gcc" export CC="$CROSS-gcc"
export RANLIB="$CROSS-ranlib" export RANLIB="$CROSS-ranlib"
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -14,4 +14,4 @@ export AR="$CROSS-ar"
export CC="$CROSS-gcc" export CC="$CROSS-gcc"
export RANLIB="$CROSS-ranlib" export RANLIB="$CROSS-ranlib"
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -16,4 +16,4 @@ export RANLIB="$CROSS-ranlib"
export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone'
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -14,4 +14,4 @@ export AR="$TARGET-ar"
export CC="$TARGET-gcc" export CC="$TARGET-gcc"
export RANLIB="$TARGET-ranlib" export RANLIB="$TARGET-ranlib"
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -14,4 +14,4 @@ export AR="$TARGET-ar"
export CC="$TARGET-gcc" export CC="$TARGET-gcc"
export RANLIB="$TARGET-ranlib" export RANLIB="$TARGET-ranlib"
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -16,4 +16,4 @@ export RANLIB="$TARGET-ranlib"
export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone' export CFLAGS='-mabi=sysv -mcmodel=kernel -mno-80387 -mno-red-zone'
"$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-libc "$REPO/configure" --host="$HOST" --prefix="$PREFIX" --enable-freestanding --with-drivers --with-libc

View File

@ -30,7 +30,7 @@ AC_CONFIG_FILES([
libc/Makefile libc/Makefile
libc/include/Makefile libc/include/Makefile
include/kernaux.h include/kernaux.h
include/kernaux/console.h include/kernaux/drivers/console.h
include/kernaux/multiboot2.h include/kernaux/multiboot2.h
include/kernaux/printf.h include/kernaux/printf.h
include/kernaux/version.h include/kernaux/version.h
@ -58,9 +58,7 @@ AC_ARG_ENABLE([tests-python], AS_HELP_STRING([--enable-tests-python], [enable te
dnl Packages (enabled by default) dnl Packages (enabled by default)
AC_ARG_WITH( [all], AS_HELP_STRING([--without-all], [without all default packages])) AC_ARG_WITH( [all], AS_HELP_STRING([--without-all], [without all default packages]))
AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser])) AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser]))
AC_ARG_WITH( [console], AS_HELP_STRING([--without-console], [without serial console]))
AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils])) AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils]))
AC_ARG_WITH( [framebuffer], AS_HELP_STRING([--without-framebuffer], [without framebuffer]))
AC_ARG_WITH( [free-list], AS_HELP_STRING([--without-free-list], [without free list memory allocator])) AC_ARG_WITH( [free-list], AS_HELP_STRING([--without-free-list], [without free list memory allocator]))
AC_ARG_WITH( [io], AS_HELP_STRING([--without-io], [without input/output])) AC_ARG_WITH( [io], AS_HELP_STRING([--without-io], [without input/output]))
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record])) AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record]))
@ -73,6 +71,7 @@ AC_ARG_WITH( [printf-fmt], AS_HELP_STRING([--without-printf-fmt], [without p
AC_ARG_WITH( [units], AS_HELP_STRING([--without-units], [without measurement units utils])) AC_ARG_WITH( [units], AS_HELP_STRING([--without-units], [without measurement units utils]))
dnl Packages (disabled by default) 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])) AC_ARG_WITH( [libc], AS_HELP_STRING([--with-libc], [with libc replacement]))
@ -91,9 +90,7 @@ AS_IF([test "$enable_tests_all" = yes], do_enable_tests_all)
AC_DEFUN([do_without_all], AC_DEFUN([do_without_all],
[ [
if test -z "$with_cmdline"; then with_cmdline=no; fi if test -z "$with_cmdline"; then with_cmdline=no; fi
if test -z "$with_console"; then with_console=no; fi
if test -z "$with_elf"; then with_elf=no; fi if test -z "$with_elf"; then with_elf=no; fi
if test -z "$with_framebuffer"; then with_framebuffer=no; fi
if test -z "$with_free_list"; then with_free_list=no; fi if test -z "$with_free_list"; then with_free_list=no; fi
if test -z "$with_io"; then with_io=no; fi if test -z "$with_io"; then with_io=no; fi
if test -z "$with_mbr"; then with_mbr=no; fi if test -z "$with_mbr"; then with_mbr=no; fi
@ -128,9 +125,7 @@ AS_IF([test "$enable_tests_python" = yes], [enable_tests_python=yes], [enable_te
dnl Packages (enabled by default) dnl Packages (enabled by default)
AS_IF([test "$with_all" = no ], [with_all=no], [with_all=yes]) AS_IF([test "$with_all" = no ], [with_all=no], [with_all=yes])
AS_IF([test "$with_cmdline" = no ], [with_cmdline=no], [with_cmdline=yes]) AS_IF([test "$with_cmdline" = no ], [with_cmdline=no], [with_cmdline=yes])
AS_IF([test "$with_console" = no ], [with_console=no], [with_console=yes])
AS_IF([test "$with_elf" = no ], [with_elf=no], [with_elf=yes]) AS_IF([test "$with_elf" = no ], [with_elf=no], [with_elf=yes])
AS_IF([test "$with_framebuffer" = no ], [with_framebuffer=no], [with_framebuffer=yes])
AS_IF([test "$with_free_list" = no ], [with_free_list=no], [with_free_list=yes]) AS_IF([test "$with_free_list" = no ], [with_free_list=no], [with_free_list=yes])
AS_IF([test "$with_io" = no ], [with_io=no], [with_io=yes]) AS_IF([test "$with_io" = no ], [with_io=no], [with_io=yes])
AS_IF([test "$with_mbr" = no ], [with_mbr=no], [with_mbr=yes]) AS_IF([test "$with_mbr" = no ], [with_mbr=no], [with_mbr=yes])
@ -143,6 +138,7 @@ AS_IF([test "$with_printf_fmt" = no ], [with_printf_fmt=no], [with_prin
AS_IF([test "$with_units" = no ], [with_units=no], [with_units=yes]) AS_IF([test "$with_units" = no ], [with_units=no], [with_units=yes])
dnl Packages (disabled by default) 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]) AS_IF([test "$with_libc" = yes], [with_libc=yes], [with_libc=no])
@ -184,9 +180,7 @@ AM_CONDITIONAL([ENABLE_TESTS_PYTHON], [test "$enable_tests_python" = yes])
dnl Packages (enabled by default) dnl Packages (enabled by default)
AM_CONDITIONAL([WITH_CMDLINE], [test "$with_cmdline" = yes]) AM_CONDITIONAL([WITH_CMDLINE], [test "$with_cmdline" = yes])
AM_CONDITIONAL([WITH_CONSOLE], [test "$with_console" = yes])
AM_CONDITIONAL([WITH_ELF], [test "$with_elf" = yes]) AM_CONDITIONAL([WITH_ELF], [test "$with_elf" = yes])
AM_CONDITIONAL([WITH_FRAMEBUFFER], [test "$with_framebuffer" = yes])
AM_CONDITIONAL([WITH_FREE_LIST], [test "$with_free_list" = yes]) AM_CONDITIONAL([WITH_FREE_LIST], [test "$with_free_list" = yes])
AM_CONDITIONAL([WITH_IO], [test "$with_io" = yes]) AM_CONDITIONAL([WITH_IO], [test "$with_io" = yes])
AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" = yes]) AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" = yes])
@ -199,6 +193,7 @@ AM_CONDITIONAL([WITH_PRINTF_FMT], [test "$with_printf_fmt" = yes])
AM_CONDITIONAL([WITH_UNITS], [test "$with_units" = yes]) AM_CONDITIONAL([WITH_UNITS], [test "$with_units" = yes])
dnl Packages (disabled by default) dnl Packages (disabled by default)
AM_CONDITIONAL([WITH_DRIVERS], [test "$with_drivers" = yes])
AM_CONDITIONAL([WITH_LIBC], [test "$with_libc" = yes]) AM_CONDITIONAL([WITH_LIBC], [test "$with_libc" = yes])
@ -225,9 +220,7 @@ AS_IF([test "$enable_tests_python" = yes], [AC_DEFINE([ENABLE_TESTS_PYTHON], [1]
dnl Packages (enabled by default) dnl Packages (enabled by default)
AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])]) AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])])
AS_IF([test "$with_console" = yes], [AC_DEFINE([WITH_CONSOLE], [1], [with serial console])])
AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])]) AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])])
AS_IF([test "$with_framebuffer" = yes], [AC_DEFINE([WITH_FRAMEBUFFER], [1], [with framebuffer])])
AS_IF([test "$with_free_list" = yes], [AC_DEFINE([WITH_FREE_LIST], [1], [with free list memory allocator])]) AS_IF([test "$with_free_list" = yes], [AC_DEFINE([WITH_FREE_LIST], [1], [with free list memory allocator])])
AS_IF([test "$with_io" = yes], [AC_DEFINE([WITH_IO], [1], [with input/output])]) AS_IF([test "$with_io" = yes], [AC_DEFINE([WITH_IO], [1], [with input/output])])
AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])]) AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])])
@ -240,6 +233,7 @@ AS_IF([test "$with_printf_fmt" = yes], [AC_DEFINE([WITH_PRINTF_FMT], [1]
AS_IF([test "$with_units", = yes], [AC_DEFINE([WITH_UNITS], [1], [with measurement units utils])]) AS_IF([test "$with_units", = yes], [AC_DEFINE([WITH_UNITS], [1], [with measurement units utils])])
dnl Packages (disabled by default) 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])]) AS_IF([test "$with_libc" = yes], [AC_DEFINE([WITH_LIBC], [1], [with libc replacement])])
dnl Additional dnl Additional
@ -253,9 +247,7 @@ AS_IF([test "$enable_debug" = yes], [AC_DEFINE([KERNAUX_DEBUG], [1]
dnl Packages (enabled by default) dnl Packages (enabled by default)
AS_IF([test "$with_cmdline" = no], [AC_SUBST([comment_line_cmdline], [//])]) AS_IF([test "$with_cmdline" = no], [AC_SUBST([comment_line_cmdline], [//])])
AS_IF([test "$with_console" = no], [AC_SUBST([comment_line_console], [//])])
AS_IF([test "$with_elf" = no], [AC_SUBST([comment_line_elf], [//])]) AS_IF([test "$with_elf" = no], [AC_SUBST([comment_line_elf], [//])])
AS_IF([test "$with_framebuffer" = no], [AC_SUBST([comment_line_framebuffer], [//])])
AS_IF([test "$with_free_list" = no], [AC_SUBST([comment_line_free_list], [//])]) AS_IF([test "$with_free_list" = no], [AC_SUBST([comment_line_free_list], [//])])
AS_IF([test "$with_io" = no], [AC_SUBST([comment_line_io], [//])]) AS_IF([test "$with_io" = no], [AC_SUBST([comment_line_io], [//])])
AS_IF([test "$with_mbr" = no], [AC_SUBST([comment_line_mbr], [//])]) AS_IF([test "$with_mbr" = no], [AC_SUBST([comment_line_mbr], [//])])

View File

@ -2,7 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <kernaux/asm/i386.h> #include <kernaux/asm/i386.h>
#include <kernaux/console.h> #include <kernaux/drivers/console.h>
#include <kernaux/multiboot2.h> #include <kernaux/multiboot2.h>
void poweroff(); void poweroff();
@ -18,24 +18,32 @@ void main(
if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) { if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) {
panic("Multiboot 2 header is invalid"); panic("Multiboot 2 header is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 header is valid\n"); kernaux_drivers_console_printf("Multiboot 2 header is valid\n");
} }
KernAux_Multiboot2_Header_print(&multiboot2_header, kernaux_console_printf); KernAux_Multiboot2_Header_print(
&multiboot2_header,
kernaux_drivers_console_printf
);
if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) { if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) {
panic("Multiboot 2 info magic number is invalid"); panic("Multiboot 2 info magic number is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 info magic number is valid\n"); kernaux_drivers_console_printf(
"Multiboot 2 info magic number is valid\n"
);
} }
if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) { if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) {
panic("Multiboot 2 info is invalid"); panic("Multiboot 2 info is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 info is valid\n"); kernaux_drivers_console_printf("Multiboot 2 info is valid\n");
} }
KernAux_Multiboot2_Info_print(multiboot2_info, kernaux_console_printf); KernAux_Multiboot2_Info_print(
multiboot2_info,
kernaux_drivers_console_printf
);
} }
void poweroff() void poweroff()
@ -45,6 +53,6 @@ void poweroff()
void panic(const char *const str) void panic(const char *const str)
{ {
kernaux_console_printf("panic: %s\n", str); kernaux_drivers_console_printf("panic: %s\n", str);
poweroff(); poweroff();
} }

View File

@ -2,7 +2,7 @@
#include <stdint.h> #include <stdint.h>
#include <kernaux/asm/i386.h> #include <kernaux/asm/i386.h>
#include <kernaux/console.h> #include <kernaux/drivers/console.h>
#include <kernaux/multiboot2.h> #include <kernaux/multiboot2.h>
void poweroff(); void poweroff();
@ -18,24 +18,32 @@ void main(
if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) { if (!KernAux_Multiboot2_Header_is_valid(&multiboot2_header)) {
panic("Multiboot 2 header is invalid"); panic("Multiboot 2 header is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 header is valid\n"); kernaux_drivers_console_printf("Multiboot 2 header is valid\n");
} }
KernAux_Multiboot2_Header_print(&multiboot2_header, kernaux_console_printf); KernAux_Multiboot2_Header_print(
&multiboot2_header,
kernaux_drivers_console_printf
);
if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) { if (multiboot2_info_magic != KERNAUX_MULTIBOOT2_INFO_MAGIC) {
panic("Multiboot 2 info magic number is invalid"); panic("Multiboot 2 info magic number is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 info magic number is valid\n"); kernaux_drivers_console_printf(
"Multiboot 2 info magic number is valid\n"
);
} }
if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) { if (!KernAux_Multiboot2_Info_is_valid(multiboot2_info)) {
panic("Multiboot 2 info is invalid"); panic("Multiboot 2 info is invalid");
} else { } else {
kernaux_console_printf("Multiboot 2 info is valid\n"); kernaux_drivers_console_printf("Multiboot 2 info is valid\n");
} }
KernAux_Multiboot2_Info_print(multiboot2_info, kernaux_console_printf); KernAux_Multiboot2_Info_print(
multiboot2_info,
kernaux_drivers_console_printf
);
} }
void poweroff() void poweroff()
@ -45,6 +53,6 @@ void poweroff()
void panic(const char *const str) void panic(const char *const str)
{ {
kernaux_console_printf("panic: %s\n", str); kernaux_drivers_console_printf("panic: %s\n", str);
poweroff(); poweroff();
} }

View File

@ -1,3 +1,7 @@
##################
# Required files #
##################
nobase_include_HEADERS = \ nobase_include_HEADERS = \
kernaux.h \ kernaux.h \
kernaux/arch/i386.h \ kernaux/arch/i386.h \
@ -9,6 +13,10 @@ nobase_include_HEADERS = \
kernaux/generic/malloc.h \ kernaux/generic/malloc.h \
kernaux/generic/mutex.h kernaux/generic/mutex.h
#######
# ASM #
#######
if ASM_I386 if ASM_I386
nobase_include_HEADERS += kernaux/asm/i386.h nobase_include_HEADERS += kernaux/asm/i386.h
endif endif
@ -19,18 +27,27 @@ if ASM_X86_64
nobase_include_HEADERS += kernaux/asm/x86_64.h nobase_include_HEADERS += kernaux/asm/x86_64.h
endif endif
###########
# Drivers #
###########
if WITH_DRIVERS
nobase_include_HEADERS += \
kernaux/drivers/console.h \
kernaux/drivers/framebuffer.h \
kernaux/drivers/intel_8259_pic.h
endif
####################
# Default packages #
####################
if WITH_CMDLINE if WITH_CMDLINE
nobase_include_HEADERS += kernaux/cmdline.h nobase_include_HEADERS += kernaux/cmdline.h
endif endif
if WITH_CONSOLE
nobase_include_HEADERS += kernaux/console.h
endif
if WITH_ELF if WITH_ELF
nobase_include_HEADERS += kernaux/elf.h nobase_include_HEADERS += kernaux/elf.h
endif endif
if WITH_FRAMEBUFFER
nobase_include_HEADERS += kernaux/framebuffer.h
endif
if WITH_FREE_LIST if WITH_FREE_LIST
nobase_include_HEADERS += kernaux/free_list.h nobase_include_HEADERS += kernaux/free_list.h
endif endif

View File

@ -11,9 +11,7 @@
#include <kernaux/generic/mutex.h> #include <kernaux/generic/mutex.h>
@comment_line_cmdline@#include <kernaux/cmdline.h> @comment_line_cmdline@#include <kernaux/cmdline.h>
@comment_line_console@#include <kernaux/console.h>
@comment_line_elf@#include <kernaux/elf.h> @comment_line_elf@#include <kernaux/elf.h>
@comment_line_framebuffer@#include <kernaux/framebuffer.h>
@comment_line_free_list@#include <kernaux/free_list.h> @comment_line_free_list@#include <kernaux/free_list.h>
@comment_line_io@#include <kernaux/io.h> @comment_line_io@#include <kernaux/io.h>
@comment_line_mbr@#include <kernaux/mbr.h> @comment_line_mbr@#include <kernaux/mbr.h>

View File

@ -1,22 +0,0 @@
#ifndef KERNAUX_INCLUDED_CONSOLE
#define KERNAUX_INCLUDED_CONSOLE
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
void kernaux_console_putc(char c);
void kernaux_console_print(const char *s);
@comment_line_printf@void kernaux_console_printf(const char *format, ...)
@comment_line_printf@__attribute__((format(printf, 1, 2)));
void kernaux_console_puts(const char *s);
void kernaux_console_write(const char *data, size_t size);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,22 @@
#ifndef KERNAUX_INCLUDED_DRIVERS_CONSOLE
#define KERNAUX_INCLUDED_DRIVERS_CONSOLE
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
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)));
void kernaux_drivers_console_puts(const char *s);
void kernaux_drivers_console_write(const char *data, size_t size);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,12 @@
#ifndef KERNAUX_INCLUDED_DRIVERS_FRAMEBUFFER
#define KERNAUX_INCLUDED_DRIVERS_FRAMEBUFFER
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,12 @@
#ifndef KERNAUX_INCLUDED_DRIVERS_INTEL_8259_PIC
#define KERNAUX_INCLUDED_DRIVERS_INTEL_8259_PIC
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,12 +0,0 @@
#ifndef KERNAUX_INCLUDED_FRAMEBUFFER
#define KERNAUX_INCLUDED_FRAMEBUFFER
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -2,9 +2,7 @@
#define KERNAUX_INCLUDED_VERSION #define KERNAUX_INCLUDED_VERSION
@comment_line_cmdline@#define KERNAUX_VERSION_WITH_CMDLINE @comment_line_cmdline@#define KERNAUX_VERSION_WITH_CMDLINE
@comment_line_console@#define KERNAUX_VERSION_WITH_CONSOLE
@comment_line_elf@#define KERNAUX_VERSION_WITH_ELF @comment_line_elf@#define KERNAUX_VERSION_WITH_ELF
@comment_line_framebuffer@#define KERNAUX_VERSION_WITH_FRAMEBUFFER
@comment_line_io@#define KERNAUX_VERSION_WITH_IO @comment_line_io@#define KERNAUX_VERSION_WITH_IO
@comment_line_mbr@#define KERNAUX_VERSION_WITH_MBR @comment_line_mbr@#define KERNAUX_VERSION_WITH_MBR
@comment_line_multiboot2@#define KERNAUX_VERSION_WITH_MULTIBOOT2 @comment_line_multiboot2@#define KERNAUX_VERSION_WITH_MULTIBOOT2

View File

@ -3,9 +3,7 @@
#endif #endif
#include <kernaux/assert.h> #include <kernaux/assert.h>
#include <kernaux/console.h> #include <kernaux/drivers/console.h>
#include "libc.h"
#ifdef ASM_I386 #ifdef ASM_I386
#include <kernaux/asm/i386.h> #include <kernaux/asm/i386.h>
@ -24,15 +22,15 @@
#include <stddef.h> #include <stddef.h>
#if defined(WITH_IO) && defined(WITH_PRINTF) #if defined(WITH_IO) && defined(WITH_PRINTF)
static void kernaux_console_printf_putc( static void kernaux_drivers_console_printf_putc(
const char c, const char c,
void *const arg __attribute__((unused)) void *const arg __attribute__((unused))
) { ) {
kernaux_console_putc(c); kernaux_drivers_console_putc(c);
} }
#endif #endif
void kernaux_console_putc(const char c __attribute__((unused))) void kernaux_drivers_console_putc(const char c __attribute__((unused)))
{ {
#ifdef ASM_I386 #ifdef ASM_I386
kernaux_asm_i386_outportb(0x3f8, c); kernaux_asm_i386_outportb(0x3f8, c);
@ -42,41 +40,42 @@ void kernaux_console_putc(const char c __attribute__((unused)))
#endif #endif
} }
void kernaux_console_print(const char *const s) void kernaux_drivers_console_print(const char *const s)
{ {
KERNAUX_ASSERT(s); KERNAUX_ASSERT(s);
for (const char *c = s; *c; ++c) { for (const char *c = s; *c; ++c) {
kernaux_console_putc(*c); kernaux_drivers_console_putc(*c);
} }
} }
#if defined(WITH_IO) && defined(WITH_PRINTF) #if defined(WITH_IO) && defined(WITH_PRINTF)
void kernaux_console_printf(const char *format, ...) void kernaux_drivers_console_printf(const char *format, ...)
{ {
KERNAUX_ASSERT(format); KERNAUX_ASSERT(format);
va_list va; va_list va;
va_start(va, format); va_start(va, format);
struct KernAux_File file = KernAux_File_create(kernaux_console_printf_putc); struct KernAux_File file =
KernAux_File_create(kernaux_drivers_console_printf_putc);
kernaux_vfprintf(&file, NULL, format, va); kernaux_vfprintf(&file, NULL, format, va);
va_end(va); va_end(va);
} }
#endif #endif
void kernaux_console_puts(const char *const s) void kernaux_drivers_console_puts(const char *const s)
{ {
KERNAUX_ASSERT(s); KERNAUX_ASSERT(s);
kernaux_console_print(s); kernaux_drivers_console_print(s);
kernaux_console_putc('\n'); kernaux_drivers_console_putc('\n');
} }
void kernaux_console_write(const char *const data, const size_t size) void kernaux_drivers_console_write(const char *const data, const size_t size)
{ {
KERNAUX_ASSERT(data); KERNAUX_ASSERT(data);
for (size_t i = 0; i < size; i++) { for (size_t i = 0; i < size; i++) {
kernaux_console_putc(data[i]); kernaux_drivers_console_putc(data[i]);
} }
} }

View File

@ -2,7 +2,7 @@
#include "config.h" #include "config.h"
#endif #endif
#include <kernaux/framebuffer.h> #include <kernaux/drivers/framebuffer.h>
__attribute__((unused)) __attribute__((unused))
static const int foobar = 0; static const int foobar = 0;

View File

@ -0,0 +1,8 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/drivers/intel_8259_pic.h>
__attribute__((unused))
static const int foobar = 0;