Merge branch 'master' into stacktrace

This commit is contained in:
Alex Kotov 2022-12-21 11:07:56 +04:00
commit 664e2940ab
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
72 changed files with 1733 additions and 988 deletions

View File

@ -12,7 +12,7 @@ main_freebsd_task:
- pip install --user Jinja2 PyYAML
main_build_script:
- ./autogen.sh
- ./configure --enable-debug --enable-checks-all CFLAGS='-O3'
- ./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3'
- make
- sudo make install
main_test_script:
@ -46,7 +46,7 @@ ruby_freebsd_task:
CPATH: '/usr/local/include'
LIBRARY_PATH: '/usr/local/lib'
dependencies_script:
- pkg install --yes autoconf automake git libtool wget
- pkg install --yes autoconf automake cppcheck git libtool wget
dependencies_ruby_script:
- wget https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.3.tar.gz
- tar -xzf ruby-3.0.3.tar.gz
@ -86,3 +86,19 @@ rust_freebsd_task:
- ~/.cargo/bin/cargo test
- ~/.cargo/bin/cargo clippy
- ~/.cargo/bin/cargo fmt --check
main_freebsd_port_task:
name: Main (FreeBSD port)
only_if: "changesInclude('.cirrus.yml', 'pkgs/freebsd/**')"
dependencies_script:
- pkg install --yes portfmt portlint porttools
port_prepare_script:
- echo 'DEVELOPER=yes' >> /etc/make.conf
- rm -rf /usr/ports/devel/libkernaux/
- cp -r $CIRRUS_WORKING_DIR/pkgs/freebsd/devel/libkernaux /usr/ports/devel/
port_test_script:
- cd /usr/ports/devel/libkernaux/
- portfmt -D Makefile
- portclippy --strict Makefile
- portlint -A
- port test .

View File

@ -34,7 +34,7 @@ jobs:
- name: autogen
run: ./autogen.sh
- name: configure
run: ./configure ${{matrix.debug}} --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}'
run: ./configure ${{matrix.debug}} --enable-fixtures --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}'
- name: make
run: make
- name: check

View File

@ -46,6 +46,3 @@ jobs:
- working-directory: bindings/mruby
name: lint
run: rake
- working-directory: bindings/mruby
name: cppcheck
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability .

View File

@ -44,6 +44,3 @@ jobs:
- working-directory: bindings/ruby
name: test & lint
run: SKIP_COVERAGE='${{matrix.packages.skip_coverage}}' rake
- working-directory: bindings/ruby
name: cppcheck
run: cppcheck --quiet --error-exitcode=1 --std=c99 --enable=warning,style,performance,portability .

67
.gitignore vendored
View File

@ -1,3 +1,6 @@
/build/*
!/build/.keep
##########################
# Common generated files #
##########################
@ -38,10 +41,9 @@
/m4/*
!/m4/.keep
# Custom
/Makefile.in
/examples/Makefile.in
/fixtures/Makefile.in
/include/Makefile.in
/libc/Makefile.in
/libc/include/Makefile.in
@ -57,7 +59,6 @@
/libtool
/stamp-h1
# Temporary
/confcache
/confdefs.h
/confinc.mk
@ -73,68 +74,10 @@
/tests/test_*.log
/tests/test_*.trs
# Custom
/Makefile
/examples/Makefile
/fixtures/Makefile
/include/Makefile
/libc/Makefile
/libc/include/Makefile
/tests/Makefile
/include/kernaux/version.h
/examples/assert
/examples/cmdline
/examples/generic_display
/examples/generic_malloc
/examples/generic_mutex
/examples/macro_bits
/examples/macro_cast
/examples/macro_container_of
/examples/macro_packing
/examples/macro_static_test
/examples/memmap
/examples/multiboot2_header_macro
/examples/ntoa
/examples/panic
/examples/pfa
/examples/printf_file
/examples/printf_file_va
/examples/printf_fmt
/examples/printf_str
/examples/printf_str_va
/examples/units_human
/tests/multiboot2_header_print0
/tests/multiboot2_header_print1
/tests/multiboot2_header_print2
/tests/multiboot2_info_print0
/tests/multiboot2_info_print1
/tests/multiboot2_info_print2
/tests/test_arch_i386
/tests/test_cmdline
/tests/test_cmdline_gen
/tests/test_cmdline_gen.c
/tests/test_elf
/tests/test_free_list
/tests/test_mbr
/tests/test_memmap
/tests/test_multiboot2_common_packing
/tests/test_multiboot2_header_helpers
/tests/test_multiboot2_header_print
/tests/test_multiboot2_header_validation
/tests/test_multiboot2_info_helpers
/tests/test_multiboot2_info_print
/tests/test_multiboot2_info_validation
/tests/test_ntoa
/tests/test_ntoa_assert
/tests/test_pfa
/tests/test_pfa_assert
/tests/test_printf
/tests/test_printf_fmt_gen
/tests/test_printf_fmt_gen.c
/tests/test_printf_gen
/tests/test_printf_gen.c
/tests/test_stack_trace
/tests/test_units_human

View File

@ -31,7 +31,7 @@ tasks:
- build: |
cd libkernaux
./autogen.sh
./configure --enable-debug --enable-checks-all CFLAGS='-O3'
./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3'
make
doas make install
- test: |

View File

@ -1,10 +1,15 @@
2022-12-19 Alex Kotov <kotovalexarian@gmail.com>
* src/multiboot2/*_print.c: Print Multiboot 2 ELF section headers
2022-12-17 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Feature "--(enable|disable)-fixtures" has been added
* src/multiboot2/*_print.c: Print some values in hex
2022-12-16 Alex Kotov <kotovalexarian@gmail.com>
* configure.ac: Feature "--with[out]-multiboot2" has been added
* configure.ac: Package "--with[out]-multiboot2" has been added
* include/kernaux/multiboot2.h: Has been made stable
2022-12-14 Alex Kotov <kotovalexarian@gmail.com>

View File

@ -13,6 +13,10 @@ endif
SUBDIRS += .
if ENABLE_FIXTURES
SUBDIRS += fixtures
endif
if ENABLE_CHECKS
SUBDIRS += examples tests
endif

View File

@ -142,6 +142,7 @@ stable options.
* `--enable-checks-pthreads` - enable tests that require pthreads
* `--enable-checks-python` - enable tests that require Python 3 with YAML and
Jinja2
* `--enable-fixtures` - enable fixtures for tests and bindings
#### Packages
@ -196,12 +197,18 @@ environment.
```
./autogen.sh # if present
./configure --enable-checks # or --enable-checks-all, but see prerequisites
./configure --enable-fixtures --enable-checks # or --enable-checks-all, but see prerequisites
make
```
You can test with `make check`.
#### See also
* [GitHub Actions](/.github/) for **GNU/Linux** build environment
* [Cirrus CI](/.cirrus.yml) for **FreeBSD** build environment
* [sourcehut CI](/.openbsd.yml) for **OpenBSD** build environment
### Cross
Create configuration script with `./autogen.sh` (if present).

View File

@ -4,7 +4,7 @@ desc 'Run default checks'
task default: :lint
desc 'Run code analysis tools'
task lint: :rubocop
task lint: %i[rubocop cppcheck]
desc 'Fix code style (rubocop --auto-correct)'
task fix: 'rubocop:auto_correct'
@ -15,3 +15,15 @@ begin
rescue LoadError
nil
end
desc 'Run cppcheck'
task :cppcheck do
sh(
'cppcheck',
'--quiet',
'--error-exitcode=1',
'--std=c99',
'--enable=warning,style,performance,portability',
__dir__,
)
end

View File

@ -1,8 +1,5 @@
#include "main.h"
#include <stddef.h>
#include <string.h>
#include <mruby/presym.h>
#include <mruby/string.h>
#include <mruby/variable.h>

View File

@ -1,9 +1,5 @@
#include "main.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <mruby/array.h>
#include <mruby/presym.h>
#include <mruby/string.h>

View File

@ -4,6 +4,12 @@
#include <kernaux.h>
#include <mruby.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
void current_mrb_start(mrb_state *mrb);
void current_mrb_finish(mrb_state *mrb);
mrb_state *current_mrb_get();

View File

@ -1,7 +1,5 @@
#include "main.h"
#include <stdint.h>
#include <mruby/numeric.h>
#include <mruby/presym.h>
#include <mruby/string.h>

View File

@ -29,8 +29,7 @@ void init_printf(mrb_state *const mrb)
mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self)
{
// FIXME: const
char *format;
const char *format;
mrb_value *args;
mrb_int argc;
mrb_get_args(mrb, "z*", &format, &args, &argc);
@ -45,12 +44,9 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self)
continue;
}
// FIXME: unnecessary
const char *const old_format = format;
++format;
struct KernAux_PrintfFmt_Spec spec =
// FIXME: no type cast
KernAux_PrintfFmt_Spec_create_out((const char**)&format);
KernAux_PrintfFmt_Spec_create_out(&format);
if (spec.set_width) {
TAKE_ARG;
@ -87,14 +83,16 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self)
DynArg_use_str(&dynarg, RSTRING_CSTR(mrb, arg_rb));
}
// 1 additional byte for the '%' character.
// 1 additional byte for the terminating '\0' character.
char old_format[2 + spec.format_limit - spec.format_start];
memset(old_format, '\0', sizeof(old_format));
old_format[0] = '%';
strncpy(&old_format[1], spec.format_start, sizeof(old_format) - 2);
char buffer[BUFFER_SIZE];
int slen;
// FIXME: it's a hack
// TODO: convert printf format spec to string
const char tmp = *format;
*format = '\0';
if (spec.set_width) {
if (spec.set_precision) {
if (dynarg.use_dbl) {
@ -133,7 +131,6 @@ mrb_value rb_KernAux_sprintf(mrb_state *const mrb, mrb_value self)
}
}
*format = tmp;
mrb_str_cat(mrb, result, buffer, slen);
}

View File

@ -70,8 +70,8 @@ if KernAux::Version.with_cmdline?
end
end
assert 'usign common tests' do
cmdline_yml = File.expand_path('../../../../common/cmdline.yml', __FILE__)
assert 'usign fixtures' do
cmdline_yml = File.expand_path('../../../../fixtures/cmdline.yml', __FILE__)
YAML.load(File.read(cmdline_yml)).each do |test|
escape_str = lambda do |str|

View File

@ -65,12 +65,12 @@ if KernAux::Version.with_printf?
end
[
['', 'using regular tests'],
['_orig', 'using original tests'],
['', 'using regular fixtures'],
['_orig', 'using original fixtures'],
].each do |(suffix, description)|
assert description do
printf_yml =
File.expand_path("../../../../common/printf#{suffix}.yml", __FILE__)
File.expand_path("../../../../fixtures/printf#{suffix}.yml", __FILE__)
YAML.load(File.read(printf_yml)).each do |test|
expected = test['result']

View File

@ -20,13 +20,13 @@ CLEAN << 'doc'
CLEAN << 'spec/examples.txt'
desc 'Run default checks'
task default: %i[test lint yard:cov]
task default: %i[test lint]
desc 'Run tests'
task test: :spec
desc 'Run code analysis tools'
task lint: :rubocop
task lint: %i[rubocop cppcheck yard:cov]
desc 'Fix code style (rubocop --auto-correct)'
task fix: 'rubocop:auto_correct'
@ -66,6 +66,18 @@ task :console do
sh 'bundle', 'exec', File.expand_path(File.join('bin', 'console'), __dir__)
end
desc 'Run cppcheck'
task :cppcheck do
sh(
'cppcheck',
'--quiet',
'--error-exitcode=1',
'--std=c99',
'--enable=warning,style,performance,portability',
__dir__,
)
end
namespace :yard do
desc 'Measure documentation coverage'
task :cov do

View File

@ -4,6 +4,12 @@
#include <kernaux.h>
#include <ruby.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
extern ID rb_intern_call;
extern ID rb_intern_freeze;
extern ID rb_intern_LESS;

View File

@ -31,8 +31,7 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self)
{
if (argc == 0) rb_raise(rb_eArgError, "too few arguments");
// FIXME: const
char *format = StringValueCStr(argv[0]);
const char *format = StringValueCStr(argv[0]);
int arg_index = 1;
VALUE result = rb_str_new_literal("");
@ -43,12 +42,9 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self)
continue;
}
// FIXME: unnecessary
const char *const old_format = format;
++format;
struct KernAux_PrintfFmt_Spec spec =
// FIXME: no type cast
KernAux_PrintfFmt_Spec_create_out((const char**)&format);
KernAux_PrintfFmt_Spec_create_out(&format);
if (spec.set_width) {
TAKE_ARG;
@ -82,14 +78,16 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self)
DynArg_use_str(&dynarg, StringValueCStr(arg_rb));
}
// 1 additional byte for the '%' character.
// 1 additional byte for the terminating '\0' character.
char old_format[2 + spec.format_limit - spec.format_start];
memset(old_format, '\0', sizeof(old_format));
old_format[0] = '%';
strncpy(&old_format[1], spec.format_start, sizeof(old_format) - 2);
char buffer[BUFFER_SIZE];
int slen;
// FIXME: it's a hack
// TODO: convert printf format spec to string
const char tmp = *format;
*format = '\0';
if (spec.set_width) {
if (spec.set_precision) {
if (dynarg.use_dbl) {
@ -128,7 +126,6 @@ VALUE rb_KernAux_sprintf(const int argc, VALUE *const argv, VALUE self)
}
}
*format = tmp;
rb_str_cat(result, buffer, slen);
}

View File

@ -91,8 +91,9 @@ KernAux::Version.with_cmdline? and RSpec.describe KernAux, '.cmdline' do
end
end
context 'using common tests' do
cmdline_yml = File.expand_path('../../../../../common/cmdline.yml', __dir__)
context 'using fixtures' do
cmdline_yml =
File.expand_path('../../../../../fixtures/cmdline.yml', __dir__)
YAML.safe_load_file(cmdline_yml).each do |test|
escape_str = lambda do |str|

View File

@ -39,12 +39,12 @@ KernAux::Version.with_printf? and RSpec.describe KernAux, '.sprintf' do
end
[
['', 'using regular tests'],
['_orig', 'using original tests'],
['', 'using regular fixtures'],
['_orig', 'using original fixtures'],
].each do |(suffix, description)|
context description do
printf_yml = File.expand_path(
"../../../../../common/printf#{suffix}.yml",
"../../../../../fixtures/printf#{suffix}.yml",
__dir__,
)

0
build/.keep Normal file
View File

View File

@ -26,11 +26,15 @@ AC_CONFIG_SRCDIR([src/assert.c])
AC_CONFIG_FILES([
Makefile
examples/Makefile
fixtures/Makefile
fixtures/multiboot2_bin_examples_gen.c
include/Makefile
libc/Makefile
libc/include/Makefile
include/kernaux/version.h
tests/Makefile
tests/test_multiboot2_header_print.c
tests/test_multiboot2_info_print.c
])
AM_INIT_AUTOMAKE([1.16 subdir-objects])
@ -49,6 +53,7 @@ AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [dis
AC_ARG_ENABLE([werror], AS_HELP_STRING([--disable-werror], [disable -Werror]))
dnl Features (disabled by default)
AC_ARG_ENABLE([fixtures], AS_HELP_STRING([--enable-fixtures], [enable fixtures for tests and bindings]))
AC_ARG_ENABLE([freestanding], AS_HELP_STRING([--enable-freestanding], [build for freestanding environment]))
AC_ARG_ENABLE([split-libc], AS_HELP_STRING([--enable-split-libc], [split off libc]))
AC_ARG_ENABLE([checks], AS_HELP_STRING([--enable-checks], [enable usual tests and examples]))
@ -136,6 +141,7 @@ AS_IF([test "$enable_float" = no ], [enable_float=no], [ena
AS_IF([test "$enable_werror" = no ], [enable_werror=no], [enable_werror=yes])
dnl Features (disabled by default)
AS_IF([test "$enable_fixtures" = yes], [enable_fixtures=yes], [enable_fixtures=no])
AS_IF([test "$enable_freestanding" = yes], [enable_freestanding=yes], [enable_freestanding=no])
AS_IF([test "$enable_split_libc" = yes], [enable_split_libc=yes], [enable_split_libc=no])
AS_IF([test "$enable_checks" = yes], [enable_checks=yes], [enable_checks=no])
@ -173,8 +179,10 @@ AS_IF([test "$with_libc" = yes], [with_libc=yes], [wit
# Test args #
#############
AS_IF([test "$enable_checks" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests]))
AS_IF([test "$enable_checks" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests]))
AS_IF([test "$enable_checks" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests]))
AS_IF([test "$enable_fixtures" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding fixtures]))
AS_IF([test "$enable_checks" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests]))
AS_IF([test "$enable_fixtures" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with fixtures]))
AS_IF([test "$with_printf" = yes -a "$with_ntoa" = no], AC_MSG_ERROR([package `printf' requires package `ntoa']))
AS_IF([test "$with_printf" = yes -a "$with_printf_fmt" = no], AC_MSG_ERROR([package `printf' requires package `printf-fmt']))
@ -200,6 +208,7 @@ AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" = yes])
AM_CONDITIONAL([ENABLE_WERROR], [test "$enable_werror" = yes])
dnl Features (disabled by default)
AM_CONDITIONAL([ENABLE_FIXTURES], [test "$enable_fixtures" = yes])
AM_CONDITIONAL([ENABLE_FREESTANDING], [test "$enable_freestanding" = yes])
AM_CONDITIONAL([ENABLE_SPLIT_LIBC], [test "$enable_split_libc" = yes])
AM_CONDITIONAL([ENABLE_CHECKS], [test "$enable_checks" = yes])
@ -253,6 +262,7 @@ AS_IF([test "$enable_werror" = yes], [AC_DEFINE([ENABLE_WERROR],
dnl Features (disabled by default)
AS_IF([test "$enable_split_libc" = yes], [AC_DEFINE([ENABLE_SPLIT_LIBC], [1], [split off libc])])
AS_IF([test "$enable_fixtures" = yes], [AC_DEFINE([ENABLE_FIXTURES], [1], [enabled fixtures for tests and bindings])])
AS_IF([test "$enable_freestanding" = yes], [AC_DEFINE([ENABLE_FREESTANDING], [1], [build for freestanding environment])])
AS_IF([test "$enable_checks" = yes], [AC_DEFINE([ENABLE_CHECKS], [1], [enabled usual tests and examples])])
AS_IF([test "$enable_checks_cppcheck" = yes], [AC_DEFINE([ENABLE_CHECKS_CPPCHECK], [1], [enabled cppcheck])])

21
examples/.gitignore vendored Normal file
View File

@ -0,0 +1,21 @@
/assert
/cmdline
/generic_display
/generic_malloc
/generic_mutex
/macro_bits
/macro_cast
/macro_container_of
/macro_packing
/macro_static_test
/memmap
/multiboot2_header_macro
/ntoa
/panic
/pfa
/printf_file
/printf_file_va
/printf_fmt
/printf_str
/printf_str_va
/units_human

8
fixtures/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
/multiboot2_bin_examples_gen
/multiboot2_bin_examples_gen.c
/multiboot2_header_example0.bin
/multiboot2_header_example1.bin
/multiboot2_header_example2.bin
/multiboot2_info_example0.bin
/multiboot2_info_example1.bin
/multiboot2_info_example2.bin

61
fixtures/Makefile.am Normal file
View File

@ -0,0 +1,61 @@
include $(top_srcdir)/make/shared.am
noinst_PROGRAMS =
nodist_noinst_DATA =
EXTRA_DIST = \
multiboot2_header_example0.txt \
multiboot2_header_example1.txt \
multiboot2_header_example2.txt \
multiboot2_info_example0.txt \
multiboot2_info_example1.txt \
multiboot2_info_example2.txt
#########################################
# multiboot2_(header|info)_example*.bin #
#########################################
if WITH_MULTIBOOT2
nodist_noinst_DATA += \
multiboot2_header_example0.bin \
multiboot2_header_example1.bin \
multiboot2_header_example2.bin \
multiboot2_info_example0.bin \
multiboot2_info_example1.bin \
multiboot2_info_example2.bin
endif
multiboot2_header_example0.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen header 0
multiboot2_header_example1.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen header 1
multiboot2_header_example2.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen header 2
multiboot2_info_example0.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen info 0
multiboot2_info_example1.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen info 1
multiboot2_info_example2.bin: multiboot2_bin_examples_gen
./multiboot2_bin_examples_gen info 2
###############################
# multiboot2_bin_examples_gen #
###############################
if WITH_MULTIBOOT2
noinst_PROGRAMS += multiboot2_bin_examples_gen
multiboot2_bin_examples_gen_LDADD = $(top_builddir)/libkernaux.la
nodist_multiboot2_bin_examples_gen_SOURCES = multiboot2_bin_examples_gen.c
multiboot2_bin_examples_gen_SOURCES = \
multiboot2_header_example0.h \
multiboot2_header_example1.h \
multiboot2_header_example2.h \
multiboot2_info_example0.h \
multiboot2_info_example1.h \
multiboot2_info_example2.h
endif

View File

@ -0,0 +1,84 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "multiboot2_header_example0.h"
#include "multiboot2_header_example1.h"
#include "multiboot2_header_example2.h"
#include "multiboot2_info_example0.h"
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
static void assert_cb(
const char *const file,
const int line,
const char *const msg
) {
fprintf(stderr, "%s:%d:%s\n", file, line, msg);
abort();
}
#define EXAMPLE(type, number) do { \
static const char *const filename = \
"@abs_top_builddir@/fixtures/multiboot2_"#type"_example"#number".bin"; \
FILE *const file = fopen(filename, "w"); \
assert(file); \
assert( \
fwrite( \
&multiboot2_##type##_example##number, \
1, \
sizeof(multiboot2_##type##_example##number), \
file \
) == sizeof(multiboot2_##type##_example##number) \
); \
assert(fclose(file) == 0); \
} while (0)
int main(const int argc, const char *const *const argv)
{
kernaux_assert_cb = assert_cb;
assert(argc == 3);
const char *const type = argv[1];
const char *const number = argv[2];
if (strcmp(type, "header") == 0) {
if (strcmp(number, "0") == 0) {
EXAMPLE(header, 0);
}
else if (strcmp(number, "1") == 0) {
EXAMPLE(header, 1);
}
else if (strcmp(number, "2") == 0) {
EXAMPLE(header, 2);
}
else {
abort();
}
} else if (strcmp(type, "info") == 0) {
if (strcmp(number, "0") == 0) {
EXAMPLE(info, 0);
}
else if (strcmp(number, "1") == 0) {
EXAMPLE(info, 1);
}
else if (strcmp(number, "2") == 0) {
EXAMPLE(info, 2);
}
else {
abort();
}
} else {
abort();
}
exit(EXIT_SUCCESS);
}

View File

@ -0,0 +1,11 @@
Multiboot 2 header {
u32 magic: 0xe85250d6
u32 arch: 0 (i386)
u32 size: 24
u32 checksum: 0x17adaf12
}
Multiboot 2 header tag {
u16 type: 0 (none)
u16 flags: 0x0 ()
u32 size: 8
}

View File

@ -0,0 +1,52 @@
Multiboot 2 header {
u32 magic: 0xe85250d6
u32 arch: 4 (MIPS32)
u32 size: 104
u32 checksum: 0x17adaebe
}
Multiboot 2 header tag {
u16 type: 4 (flags)
u16 flags: 0x0 ()
u32 size: 12
u32 console_flags: 0x0 ()
}
Multiboot 2 header tag {
u16 type: 4 (flags)
u16 flags: 0x0 ()
u32 size: 12
u32 console_flags: 0x1 (
REQUIRE_CONSOLE
)
}
Multiboot 2 header tag {
u16 type: 4 (flags)
u16 flags: 0x0 ()
u32 size: 12
u32 console_flags: 0x2 (
EGA_SUPPORT
)
}
Multiboot 2 header tag {
u16 type: 4 (flags)
u16 flags: 0x0 ()
u32 size: 12
u32 console_flags: 0x3 (
REQUIRE_CONSOLE |
EGA_SUPPORT
)
}
Multiboot 2 header tag {
u16 type: 1 (information request)
u16 flags: 0x1 (
OPTIONAL
)
u32 size: 12
u32 mbi_tag_types[]: [
0 (none)
]
}
Multiboot 2 header tag {
u16 type: 0 (none)
u16 flags: 0x0 ()
u32 size: 8
}

View File

@ -0,0 +1,100 @@
Multiboot 2 header {
u32 magic: 0xe85250d6
u32 arch: 0 (i386)
u32 size: 272
u32 checksum: 0x17adae1a
}
Multiboot 2 header tag {
u16 type: 1 (information request)
u16 flags: 0x0 ()
u32 size: 96
u32 mbi_tag_types[]: [
0 (none)
1 (boot cmd line)
2 (boot loader name)
3 (module)
4 (basic memory info)
5 (BIOS boot device)
6 (memory map)
7 (VBE info)
8 (framebuffer info)
9 (ELF symbols)
10 (APM table)
11 (EFI 32bit system table ptr)
12 (EFI 64bit system table ptr)
13 (SMBIOS tables)
14 (ACPI old RSDP)
15 (ACPI new RSDP)
16 (networking info)
17 (EFI memory map)
18 (EFI boot services not terminated)
19 (EFI 32bit image handle ptr)
20 (EFI 64bit image handle ptr)
21 (image load base phys addr)
]
}
Multiboot 2 header tag {
u16 type: 2 (address)
u16 flags: 0x0 ()
u32 size: 24
u32 header_addr: 0xcafebabe
u32 load_addr: 0xdeadbeaf
u32 load_end_addr: 0xdeadbabe
u32 bss_end_addr: 0xcafebeaf
}
Multiboot 2 header tag {
u16 type: 3 (entry address)
u16 flags: 0x0 ()
u32 size: 12
u32 entry_addr: 0xcafebabe
}
Multiboot 2 header tag {
u16 type: 4 (flags)
u16 flags: 0x0 ()
u32 size: 12
u32 console_flags: 0x0 ()
}
Multiboot 2 header tag {
u16 type: 5 (framebuffer)
u16 flags: 0x0 ()
u32 size: 20
u32 width: 80
u32 height: 25
u32 depth: 8
}
Multiboot 2 header tag {
u16 type: 6 (module alignment)
u16 flags: 0x0 ()
u32 size: 8
}
Multiboot 2 header tag {
u16 type: 7 (EFI boot services)
u16 flags: 0x0 ()
u32 size: 8
}
Multiboot 2 header tag {
u16 type: 8 (EFI i386 entry address)
u16 flags: 0x0 ()
u32 size: 12
u32 entry_addr: 0xcafebabe
}
Multiboot 2 header tag {
u16 type: 9 (EFI amd64 entry address)
u16 flags: 0x0 ()
u32 size: 12
u32 entry_addr: 0xdeadbeaf
}
Multiboot 2 header tag {
u16 type: 10 (relocatable header)
u16 flags: 0x0 ()
u32 size: 24
u32 min_addr: 0xcafebabe
u32 max_addr: 0xdeadbeaf
u32 align: 8
u32 preference: 1 (lowest)
}
Multiboot 2 header tag {
u16 type: 0 (none)
u16 flags: 0x0 ()
u32 size: 8
}

View File

@ -0,0 +1,8 @@
Multiboot 2 info {
u32 size: 16
u32 reserved: 0x0
}
Multiboot 2 info tag {
u32 type: 0 (none)
u32 size: 8
}

View File

@ -0,0 +1,264 @@
Multiboot 2 info {
u32 size: 864
u32 reserved: 0x0
}
Multiboot 2 info tag {
u32 type: 21 (image load base phys addr)
u32 size: 12
u32 load_base_addr: 0x400000
}
Multiboot 2 info tag {
u32 type: 1 (boot cmd line)
u32 size: 21
char cmdline[]: "hello kernel"
}
Multiboot 2 info tag {
u32 type: 2 (boot loader name)
u32 size: 30
char name[]: "GRUB 2.02-2ubuntu8.20"
}
Multiboot 2 info tag {
u32 type: 10 (APM table)
u32 size: 28
u16 version: 258
u16 cseg: 61440
u32 offset: 54479
u16 cseg_16: 61440
u16 dseg: 61440
u16 flags: 3
u16 cseg_len: 65520
u16 cseg_16_len: 65520
u16 dseg_len: 65520
}
Multiboot 2 info tag {
u32 type: 3 (module)
u32 size: 29
u32 mod_start: 0x102000
u32 mod_end: 0x10329c
char cmdline[]: "hello module"
}
Multiboot 2 info tag {
u32 type: 3 (module)
u32 size: 17
u32 mod_start: 0x104000
u32 mod_end: 0x105254
char cmdline[]: ""
}
Multiboot 2 info tag {
u32 type: 6 (memory map)
u32 size: 160
u32 entry_size: 24
u32 entry_version: 0
varies(entry_size) entries[]: [
[0]: {
u64 base_addr: 0x0
u64 length: 654336
u32 type: 1
u32 reserved: 0x0
}
[1]: {
u64 base_addr: 0x9fc00
u64 length: 1024
u32 type: 2
u32 reserved: 0x0
}
[2]: {
u64 base_addr: 0xf0000
u64 length: 65536
u32 type: 2
u32 reserved: 0x0
}
[3]: {
u64 base_addr: 0x100000
u64 length: 133038080
u32 type: 1
u32 reserved: 0x0
}
[4]: {
u64 base_addr: 0x7fe0000
u64 length: 131072
u32 type: 2
u32 reserved: 0x0
}
[5]: {
u64 base_addr: 0xfffc0000
u64 length: 262144
u32 type: 2
u32 reserved: 0x0
}
]
}
Multiboot 2 info tag {
u32 type: 9 (ELF symbols)
u32 size: 420
u32 num: 10
u32 entsize: 40
u32 shndx: 9
varies(entsize) section_headers[]: [
[0]: {
name: 0
type: 0 (NULL)
flags: 0x0 ()
addr: 0x0
offset: 0x0
size: 0
link: 0
info: 0
addralign: 0
entsize: 0
}
[1]: {
name: 27
type: 1 (PROGBITS)
flags: 0x6 (
ALLOC |
EXECINSTR
)
addr: 0x400000
offset: 0x1000
size: 13718
link: 0
info: 0
addralign: 4096
entsize: 0
}
[2]: {
name: 33
type: 1 (PROGBITS)
flags: 0x2 (
ALLOC
)
addr: 0x404000
offset: 0x5000
size: 2824
link: 0
info: 0
addralign: 4096
entsize: 0
}
[3]: {
name: 41
type: 1 (PROGBITS)
flags: 0x2 (
ALLOC
)
addr: 0x404b08
offset: 0x5b08
size: 2692
link: 0
info: 0
addralign: 4
entsize: 0
}
[4]: {
name: 51
type: 1 (PROGBITS)
flags: 0x3 (
WRITE |
ALLOC
)
addr: 0x406000
offset: 0x7000
size: 1
link: 0
info: 0
addralign: 4096
entsize: 0
}
[5]: {
name: 57
type: 8 (NOBITS)
flags: 0x3 (
WRITE |
ALLOC
)
addr: 0x407000
offset: 0x7001
size: 43328
link: 0
info: 0
addralign: 4096
entsize: 0
}
[6]: {
name: 62
type: 1 (PROGBITS)
flags: 0x30 ()
addr: 0x100000
offset: 0x7001
size: 17
link: 0
info: 0
addralign: 1
entsize: 1
}
[7]: {
name: 1
type: 2 (SYMTAB)
flags: 0x0 ()
addr: 0x100014
offset: 0x7014
size: 3248
link: 8
info: 72
addralign: 4
entsize: 16
}
[8]: {
name: 9
type: 3 (STRTAB)
flags: 0x0 ()
addr: 0x100cc4
offset: 0x7cc4
size: 3536
link: 0
info: 0
addralign: 1
entsize: 0
}
[9]: {
name: 17
type: 3 (STRTAB)
flags: 0x0 ()
addr: 0x101a94
offset: 0x8a94
size: 71
link: 0
info: 0
addralign: 1
entsize: 0
}
]
}
Multiboot 2 info tag {
u32 type: 4 (basic memory info)
u32 size: 16
u32 mem_lower: 639
u32 mem_upper: 129920
}
Multiboot 2 info tag {
u32 type: 5 (BIOS boot device)
u32 size: 20
u32 biosdev: 224
u32 partition: 4294967295
u32 sub_partition: 4294967295
}
Multiboot 2 info tag {
u32 type: 8 (framebuffer info)
u32 size: 32
u64 framebuffer_addr: 0xb8000
u32 framebuffer_pitch: 160
u32 framebuffer_width: 80
u32 framebuffer_height: 25
u8 framebuffer_bpp: 16
u8 framebuffer_type: 2
u16 reserved: 0x0
}
Multiboot 2 info tag {
u32 type: 14 (ACPI old RSDP)
u32 size: 28
}
Multiboot 2 info tag {
u32 type: 0 (none)
u32 size: 8
}

View File

@ -0,0 +1,369 @@
Multiboot 2 info {
u32 size: 1816
u32 reserved: 0x0
}
Multiboot 2 info tag {
u32 type: 1 (boot cmd line)
u32 size: 23
char cmdline[]: "Hello, Kernel!"
}
Multiboot 2 info tag {
u32 type: 2 (boot loader name)
u32 size: 30
char name[]: "GRUB 2.02-2ubuntu8.20"
}
Multiboot 2 info tag {
u32 type: 3 (module)
u32 size: 33
u32 mod_start: 0x7b
u32 mod_end: 0x1c8
char cmdline[]: "Hello, Module 1!"
}
Multiboot 2 info tag {
u32 type: 3 (module)
u32 size: 33
u32 mod_start: 0x7b
u32 mod_end: 0x1c8
char cmdline[]: "Hello, Module 2!"
}
Multiboot 2 info tag {
u32 type: 4 (basic memory info)
u32 size: 16
u32 mem_lower: 123
u32 mem_upper: 456
}
Multiboot 2 info tag {
u32 type: 5 (BIOS boot device)
u32 size: 20
u32 biosdev: 0
u32 partition: 1
u32 sub_partition: 2
}
Multiboot 2 info tag {
u32 type: 6 (memory map)
u32 size: 160
u32 entry_size: 24
u32 entry_version: 0
varies(entry_size) entries[]: [
[0]: {
u64 base_addr: 0x0
u64 length: 654336
u32 type: 1
u32 reserved: 0x0
}
[1]: {
u64 base_addr: 0x9fc00
u64 length: 1024
u32 type: 2
u32 reserved: 0x0
}
[2]: {
u64 base_addr: 0xf0000
u64 length: 65536
u32 type: 2
u32 reserved: 0x0
}
[3]: {
u64 base_addr: 0x100000
u64 length: 133038080
u32 type: 1
u32 reserved: 0x0
}
[4]: {
u64 base_addr: 0x7fe0000
u64 length: 131072
u32 type: 2
u32 reserved: 0x0
}
[5]: {
u64 base_addr: 0xfffc0000
u64 length: 262144
u32 type: 2
u32 reserved: 0x0
}
]
}
Multiboot 2 info tag {
u32 type: 7 (VBE info)
u32 size: 784
u16 vbe_mode: 0
u16 vbe_interface_seg: 123
u16 vbe_interface_off: 456
u16 vbe_interface_len: 789
u8 vbe_control_info[]: [
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
123 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 123
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
]
u8 vbe_mode_info[]: [
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
]
}
Multiboot 2 info tag {
u32 type: 8 (framebuffer info)
u32 size: 40
u64 framebuffer_addr: 0x7b
u32 framebuffer_pitch: 456
u32 framebuffer_width: 123
u32 framebuffer_height: 456
u8 framebuffer_bpp: 8
u8 framebuffer_type: 1
u16 reserved: 0x0
}
Multiboot 2 info tag {
u32 type: 9 (ELF symbols)
u32 size: 420
u32 num: 10
u32 entsize: 40
u32 shndx: 9
varies(entsize) section_headers[]: [
[0]: {
name: 0
type: 0 (NULL)
flags: 0x0 ()
addr: 0x0
offset: 0x0
size: 0
link: 0
info: 0
addralign: 0
entsize: 0
}
[1]: {
name: 27
type: 1 (PROGBITS)
flags: 0x6 (
ALLOC |
EXECINSTR
)
addr: 0x400000
offset: 0x1000
size: 13718
link: 0
info: 0
addralign: 4096
entsize: 0
}
[2]: {
name: 33
type: 1 (PROGBITS)
flags: 0x2 (
ALLOC
)
addr: 0x404000
offset: 0x5000
size: 2824
link: 0
info: 0
addralign: 4096
entsize: 0
}
[3]: {
name: 41
type: 1 (PROGBITS)
flags: 0x2 (
ALLOC
)
addr: 0x404b08
offset: 0x5b08
size: 2692
link: 0
info: 0
addralign: 4
entsize: 0
}
[4]: {
name: 51
type: 1 (PROGBITS)
flags: 0x3 (
WRITE |
ALLOC
)
addr: 0x406000
offset: 0x7000
size: 1
link: 0
info: 0
addralign: 4096
entsize: 0
}
[5]: {
name: 57
type: 8 (NOBITS)
flags: 0x3 (
WRITE |
ALLOC
)
addr: 0x407000
offset: 0x7001
size: 43328
link: 0
info: 0
addralign: 4096
entsize: 0
}
[6]: {
name: 62
type: 1 (PROGBITS)
flags: 0x30 ()
addr: 0x100000
offset: 0x7001
size: 17
link: 0
info: 0
addralign: 1
entsize: 1
}
[7]: {
name: 1
type: 2 (SYMTAB)
flags: 0x0 ()
addr: 0x100014
offset: 0x7014
size: 3248
link: 8
info: 72
addralign: 4
entsize: 16
}
[8]: {
name: 9
type: 3 (STRTAB)
flags: 0x0 ()
addr: 0x100cc4
offset: 0x7cc4
size: 3536
link: 0
info: 0
addralign: 1
entsize: 0
}
[9]: {
name: 17
type: 3 (STRTAB)
flags: 0x0 ()
addr: 0x101a94
offset: 0x8a94
size: 71
link: 0
info: 0
addralign: 1
entsize: 0
}
]
}
Multiboot 2 info tag {
u32 type: 10 (APM table)
u32 size: 28
u16 version: 0
u16 cseg: 123
u32 offset: 456
u16 cseg_16: 789
u16 dseg: 123
u16 flags: 1
u16 cseg_len: 456
u16 cseg_16_len: 789
u16 dseg_len: 123
}
Multiboot 2 info tag {
u32 type: 11 (EFI 32bit system table ptr)
u32 size: 12
u32 pointer: 0
}
Multiboot 2 info tag {
u32 type: 12 (EFI 64bit system table ptr)
u32 size: 16
u64 pointer: 0
}
Multiboot 2 info tag {
u32 type: 13 (SMBIOS tables)
u32 size: 24
u8 major: 1
u8 minor: 2
u8 reserved[6]: [0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
}
Multiboot 2 info tag {
u32 type: 14 (ACPI old RSDP)
u32 size: 16
}
Multiboot 2 info tag {
u32 type: 15 (ACPI new RSDP)
u32 size: 16
}
Multiboot 2 info tag {
u32 type: 16 (networking info)
u32 size: 16
}
Multiboot 2 info tag {
u32 type: 17 (EFI memory map)
u32 size: 24
u32 descriptor_size: 123
u32 descriptor_version: 1
}
Multiboot 2 info tag {
u32 type: 18 (EFI boot services not terminated)
u32 size: 8
}
Multiboot 2 info tag {
u32 type: 19 (EFI 32bit image handle ptr)
u32 size: 12
u32 pointer: 0
}
Multiboot 2 info tag {
u32 type: 20 (EFI 64bit image handle ptr)
u32 size: 16
u64 pointer: 0
}
Multiboot 2 info tag {
u32 type: 21 (image load base phys addr)
u32 size: 12
u32 load_base_addr: 0x7b
}
Multiboot 2 info tag {
u32 type: 0 (none)
u32 size: 8
}

1
include/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/kernaux/version.h

View File

@ -7,87 +7,173 @@ extern "C" {
#include <kernaux/macro.h>
#include <stdbool.h>
#include <stdint.h>
#include <kernaux/macro/packing_start.run>
struct KernAux_ELF_Ident {
uint8_t magic_0x7f;
uint8_t magic_E;
uint8_t magic_L;
uint8_t magic_F;
uint8_t class_;
uint8_t data;
uint8_t version;
uint8_t unused[9];
}
KERNAUX_PACKED;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Ident, 16);
// KernAux_ELF_Ident.class_
#define KERNAUX_ELF_CLASS_NONE 0 // Invalid class
#define KERNAUX_ELF_CLASS_32 1 // 32-bit objects
#define KERNAUX_ELF_CLASS_64 2 // 64-bit objects
// KernAux_ELF_Ident.data
#define KERNAUX_ELF_DATA_NONE 0 // Invalid data encoding
#define KERNAUX_ELF_DATA_2LSB 1 // 0x01020304 == [0x04, 0x03, 0x02, 0x01]
#define KERNAUX_ELF_DATA_2MSB 2 // 0x01020304 == [0x01, 0x02, 0x03, 0x04]
struct KernAux_ELF_Header {
unsigned magic_0x7f : 8;
unsigned magic_E : 8;
unsigned magic_L : 8;
unsigned magic_F : 8;
unsigned bitness : 8;
unsigned endianness : 8;
unsigned header_version : 8;
unsigned os_abi : 8;
unsigned unused1 : 32;
unsigned unused2 : 32;
unsigned obj_type : 16;
unsigned isa : 16;
unsigned elf_version : 32;
unsigned entrypoint : 32;
unsigned prog_table_pos : 32;
unsigned sect_table_pos : 32;
unsigned arch_flags : 32;
unsigned header_size : 16;
unsigned prog_entr_size : 16;
unsigned prog_entr_num : 16;
unsigned sect_entr_size : 16;
unsigned sect_entr_num : 16;
unsigned sect_names_idx : 16;
struct KernAux_ELF_Ident ident;
uint16_t type;
uint16_t machine;
uint32_t version;
uint32_t entry;
uint32_t phoff;
uint32_t shoff;
uint32_t flags;
uint16_t ehsize;
uint16_t phentsize;
uint16_t phnum;
uint16_t shentsize;
uint16_t shnum;
uint16_t shstrndx;
}
KERNAUX_PACKED;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Header, 52);
struct KernAux_ELF_ProgramEntry {
unsigned type : 32;
unsigned offset : 32;
unsigned virt_addr : 32;
unsigned phys_addr : 32;
unsigned file_size : 32;
unsigned mem_size : 32;
unsigned flags : 32;
unsigned align : 32;
// KernAux_ELF_Header.type
#define KERNAUX_ELF_TYPE_NONE 0 // No file type
#define KERNAUX_ELF_TYPE_REL 1 // Relocatable file
#define KERNAUX_ELF_TYPE_EXEC 2 // Executable file
#define KERNAUX_ELF_TYPE_DYN 3 // Shared object file
#define KERNAUX_ELF_TYPE_CORE 4 // Core file
#define KERNAUX_ELF_TYPE_LOPROC 0xff00 // Processor-specific
#define KERNAUX_ELF_TYPE_HIPROC 0xffff // Processor-specific
// KernAux_ELF_Header.machine
#define KERNAUX_ELF_MACHINE_NONE 0 // No machine
#define KERNAUX_ELF_MACHINE_M32 1 // AT&T WE 32100
#define KERNAUX_ELF_MACHINE_SPARC 2 // SPARC
#define KERNAUX_ELF_MACHINE_386 3 // Intel 80386
#define KERNAUX_ELF_MACHINE_68K 4 // Motorola 68000
#define KERNAUX_ELF_MACHINE_88K 5 // Motorola 88000
#define KERNAUX_ELF_MACHINE_860 7 // Intel 80860
#define KERNAUX_ELF_MACHINE_MIPS 8 // MIPS RS3000
// KernAux_ELF_Header.version
#define KERNAUX_ELF_VERSION_NONE 0 // Invalid version
#define KERNAUX_ELF_VERSION_CURRENT 1 // Current version
struct KernAux_ELF_Section {
uint32_t name;
uint32_t type;
uint32_t flags;
uint32_t addr;
uint32_t offset;
uint32_t size;
uint32_t link;
uint32_t info;
uint32_t addralign;
uint32_t entsize;
}
KERNAUX_PACKED;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_ProgramEntry, 32);
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Section, 40);
struct KernAux_ELF_SectionEntry {
unsigned name : 32;
unsigned type : 32;
unsigned flags : 32;
unsigned vaddr : 32;
unsigned file_offset : 32;
unsigned file_size : 32;
unsigned link : 32;
unsigned info : 32;
unsigned alignment : 32;
unsigned ent_size : 32;
#define KERNAUX_ELF_SECT_TYPE_NULL 0
#define KERNAUX_ELF_SECT_TYPE_PROGBITS 1
#define KERNAUX_ELF_SECT_TYPE_SYMTAB 2
#define KERNAUX_ELF_SECT_TYPE_STRTAB 3
#define KERNAUX_ELF_SECT_TYPE_RELA 4
#define KERNAUX_ELF_SECT_TYPE_HASH 5
#define KERNAUX_ELF_SECT_TYPE_DYNAMIC 6
#define KERNAUX_ELF_SECT_TYPE_NOTE 7
#define KERNAUX_ELF_SECT_TYPE_NOBITS 8
#define KERNAUX_ELF_SECT_TYPE_REL 9
#define KERNAUX_ELF_SECT_TYPE_SHLIB 10
#define KERNAUX_ELF_SECT_TYPE_DYNSYM 11
#define KERNAUX_ELF_SECT_TYPE_LOPROC 0x70000000
#define KERNAUX_ELF_SECT_TYPE_HIPROC 0x7fffffff
#define KERNAUX_ELF_SECT_TYPE_LOUSER 0x80000000
#define KERNAUX_ELF_SECT_TYPE_HIUSER 0xffffffff
#define KERNAUX_ELF_SECT_FLAGS_WRITE 0x1
#define KERNAUX_ELF_SECT_FLAGS_ALLOC 0x2
#define KERNAUX_ELF_SECT_FLAGS_EXECINSTR 0x4
#define KERNAUX_ELF_SECT_FLAGS_MASKPROC 0xf0000000
const char *KernAux_ELF_Section_Type_to_str(uint32_t type);
struct KernAux_ELF_Symbol {
uint32_t name;
uint32_t value;
uint32_t size;
uint8_t info;
uint8_t other;
uint16_t shndx;
}
KERNAUX_PACKED;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_SectionEntry, 40);
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Symbol, 16);
struct KernAux_ELF_RelocationEntry {
unsigned virt_addr : 32;
unsigned info : 32;
#define KERNAUX_ELF_SYM_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
#define KERNAUX_ELF_SYM_BIND(info) ((info) >> 4)
#define KERNAUX_ELF_SYM_TYPE(info) ((into) & 0xf)
#define KERNAUX_ELF_SYM_BIND_LOCAL 0
#define KERNAUX_ELF_SYM_BIND_GLOBAL 1
#define KERNAUX_ELF_SYM_BIND_WEAK 2
#define KERNAUX_ELF_SYM_BIND_LOPROC 13
#define KERNAUX_ELF_SYM_BIND_HIPROC 15
#define KERNAUX_ELF_SYM_TYPE_NOTYPE 0
#define KERNAUX_ELF_SYM_TYPE_OBJECT 1
#define KERNAUX_ELF_SYM_TYPE_FUNC 2
#define KERNAUX_ELF_SYM_TYPE_SECTION 3
#define KERNAUX_ELF_SYM_TYPE_FILE 4
#define KERNAUX_ELF_SYM_TYPE_LOPROC 13
#define KERNAUX_ELF_SYM_TYPE_HIPROC 15
struct KernAux_ELF_Program {
uint32_t type;
uint32_t offset;
uint32_t vaddr;
uint32_t paddr;
uint32_t filesz;
uint32_t memsz;
uint32_t flags;
uint32_t align;
}
KERNAUX_PACKED;
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_RelocationEntry, 8);
KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_ELF_Program, 32);
#define KERNAUX_ELF_PROG_TYPE_NULL 0
#define KERNAUX_ELF_PROG_TYPE_LOAD 1
#define KERNAUX_ELF_PROG_TYPE_DYNAMIC 2
#define KERNAUX_ELF_PROG_TYPE_INTERP 3
#define KERNAUX_ELF_PROG_TYPE_NOTE 4
#define KERNAUX_ELF_PROG_TYPE_SHLIB 5
#define KERNAUX_ELF_PROG_TYPE_PHDR 6
#define KERNAUX_ELF_PROG_TYPE_LOPROC 0x70000000
#define KERNAUX_ELF_PROG_TYPE_HIPROC 0x7fffffff
#include <kernaux/macro/packing_end.run>
typedef struct KernAux_ELF_ProgramEntry KernAux_ELF_ProgramTable[];
typedef struct KernAux_ELF_SectionEntry KernAux_ELF_SectionTable[];
typedef struct KernAux_ELF_RelocationEntry KernAux_ELF_RelocationTable[];
bool KernAux_ELF_Header_is_valid(const struct KernAux_ELF_Header *header);
#ifdef __cplusplus
}
#endif

View File

@ -366,7 +366,7 @@ struct KernAux_Multiboot2_ITag_ELFSymbols {
uint32_t entsize;
uint32_t shndx;
// DATA: varies section_headers[]
// DATA: varies(entsize) section_headers[]
}
KERNAUX_PACKED;

1
pkgs/freebsd/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/devel/libkernaux/work/

View File

@ -0,0 +1,18 @@
PORTNAME= libkernaux
DISTVERSION= 0.6.1
CATEGORIES= devel
MASTER_SITES= https://github.com/tailix/libkernaux/releases/download/v${DISTVERSION}/
MAINTAINER= kotovalexarian@gmail.com
COMMENT= Auxiliary library for kernel development
WWW= https://github.com/tailix/libkernaux
LICENSE= MIT
LICENSE_FILE= ${WRKSRC}/COPYING
USES= libtool
USE_LDCONFIG= yes
GNU_CONFIGURE= yes
CONFIGURE_ARGS+= --enable-shared
.include <bsd.port.mk>

View File

@ -0,0 +1,3 @@
TIMESTAMP = 1671469243
SHA256 (libkernaux-0.6.1.tar.gz) = 16fc83a36826cad527ec0a232032b7b131b5be0468ccff9163df12e3e3986b9f
SIZE (libkernaux-0.6.1.tar.gz) = 486595

View File

@ -0,0 +1,3 @@
Auxiliary library for kernel development.
It's in the early stage of the development so there is no detailed description.

View File

@ -0,0 +1,28 @@
include/kernaux.h
include/kernaux/arch/i386.h
include/kernaux/arch/riscv64.h
include/kernaux/arch/x86.h
include/kernaux/arch/x86_64.h
include/kernaux/assert.h
include/kernaux/cmdline.h
include/kernaux/elf.h
include/kernaux/free_list.h
include/kernaux/generic/malloc.h
include/kernaux/generic/mutex.h
include/kernaux/macro.h
include/kernaux/macro/packing_end.run
include/kernaux/macro/packing_start.run
include/kernaux/mbr.h
include/kernaux/memmap.h
include/kernaux/multiboot2.h
include/kernaux/multiboot2/header_macro.h
include/kernaux/ntoa.h
include/kernaux/pfa.h
include/kernaux/printf.h
include/kernaux/printf_fmt.h
include/kernaux/units.h
include/kernaux/version.h
lib/libkernaux.a
lib/libkernaux.so
lib/libkernaux.so.0
lib/libkernaux.so.0.0.0

View File

@ -2,56 +2,47 @@
#include "config.h"
#endif
#include <kernaux/assert.h>
#include <kernaux/elf.h>
#include <kernaux/macro.h>
bool KernAux_ELF_Header_is_valid(
const struct KernAux_ELF_Header *const header
) {
KERNAUX_ASSERT(header);
#include <stddef.h>
if (!(
header->magic_0x7f == 0x7f &&
header->magic_E == 'E' &&
header->magic_L == 'L' &&
header->magic_F == 'F' &&
header->header_version == 1 &&
header->elf_version == 1
)) {
return false;
const char *KernAux_ELF_Section_Type_to_str(const uint32_t type)
{
switch (type) {
case KERNAUX_ELF_SECT_TYPE_NULL:
return "NULL";
case KERNAUX_ELF_SECT_TYPE_PROGBITS:
return "PROGBITS";
case KERNAUX_ELF_SECT_TYPE_SYMTAB:
return "SYMTAB";
case KERNAUX_ELF_SECT_TYPE_STRTAB:
return "STRTAB";
case KERNAUX_ELF_SECT_TYPE_RELA:
return "RELA";
case KERNAUX_ELF_SECT_TYPE_HASH:
return "HASH";
case KERNAUX_ELF_SECT_TYPE_DYNAMIC:
return "DYNAMIC";
case KERNAUX_ELF_SECT_TYPE_NOTE:
return "NOTE";
case KERNAUX_ELF_SECT_TYPE_NOBITS:
return "NOBITS";
case KERNAUX_ELF_SECT_TYPE_REL:
return "REL";
case KERNAUX_ELF_SECT_TYPE_SHLIB:
return "SHLIB";
case KERNAUX_ELF_SECT_TYPE_DYNSYM:
return "DYNSYM";
case KERNAUX_ELF_SECT_TYPE_LOPROC:
return "LOPROC";
case KERNAUX_ELF_SECT_TYPE_HIPROC:
return "HIPROC";
case KERNAUX_ELF_SECT_TYPE_LOUSER:
return "LOUSER";
case KERNAUX_ELF_SECT_TYPE_HIUSER:
return "HIUSER";
default:
return NULL;
}
if (!(
header->bitness == 1 || // 32 bit
header->bitness == 2 // 64 bit
)) {
return false;
}
if (!(
header->endianness == 1 || // Little endian
header->endianness == 2 // Big endian
)) {
return false;
}
if (!(header->os_abi <= 0x12 && header->os_abi != 0x05)) {
return false;
}
if (!(
header->obj_type == 0x00 || // NONE
header->obj_type == 0x01 || // REL
header->obj_type == 0x02 || // EXEC
header->obj_type == 0x03 || // DYN
header->obj_type == 0x04 || // CORE
header->obj_type == 0xfe00 || // LOOS
header->obj_type == 0xfeff || // HIOS
header->obj_type == 0xff00 || // LOPROC
header->obj_type == 0xffff // HIPROC
)) {
return false;
}
return true;
}

View File

@ -225,26 +225,30 @@ void KernAux_Multiboot2_HTag_InfoReq_print(
// Print data:
PRINTLN(" u32 mbi_tag_types[]: [");
if ((tag->base.size - sizeof(*tag)) / sizeof(uint32_t) == 0) {
PRINTLN(" u32 mbi_tag_types[]: []");
} else {
PRINTLN(" u32 mbi_tag_types[]: [");
const uint32_t *const mbi_tag_types =
(const uint32_t*)KERNAUX_MULTIBOOT2_DATA(tag);
const uint32_t *const mbi_tag_types =
(const uint32_t*)KERNAUX_MULTIBOOT2_DATA(tag);
for (
size_t index = 0;
index < (tag->base.size - sizeof(*tag)) / sizeof(uint32_t);
++index
) {
KERNAUX_CAST_CONST(unsigned long, type, mbi_tag_types[index]);
for (
size_t index = 0;
index < (tag->base.size - sizeof(*tag)) / sizeof(uint32_t);
++index
) {
KERNAUX_CAST_CONST(unsigned long, type, mbi_tag_types[index]);
PRINTLNF(" %lu (%s)",
type,
KernAux_Multiboot2_ITag_to_str(type)
);
PRINTLNF(" %lu (%s)",
type,
KernAux_Multiboot2_ITag_to_str(type)
);
}
PRINTLN(" ]");
}
PRINTLN(" ]");
FOOTER;
}

View File

@ -3,10 +3,12 @@
#endif
#include <kernaux/assert.h>
#include <kernaux/elf.h>
#include <kernaux/generic/display.h>
#include <kernaux/macro.h>
#include <kernaux/multiboot2.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -39,6 +41,44 @@
#define FOOTER do { PRINTLN("}"); } while (0)
#define INDENT do { \
for (unsigned index = 0; index < basic_indentation; ++index) PRINT(" "); \
} while (0)
#define INDENT_MORE do { \
for (unsigned index = 0; index < indentation_delta; ++index) PRINT(" "); \
} while (0)
static const struct {
uint32_t number;
const char *name;
} section_flag_names[] = {
{
.number = KERNAUX_ELF_SECT_FLAGS_WRITE,
.name = "WRITE",
},
{
.number = KERNAUX_ELF_SECT_FLAGS_ALLOC,
.name = "ALLOC",
},
{
.number = KERNAUX_ELF_SECT_FLAGS_EXECINSTR,
.name = "EXECINSTR",
},
{
.number = KERNAUX_ELF_SECT_FLAGS_MASKPROC,
.name = "MASKPROC",
},
};
static void KernAux_ELF_Section_Flags_print(
uint16_t flags,
KernAux_Display display,
unsigned basic_indentation,
unsigned indentation_delta,
bool indent_first
);
void KernAux_Multiboot2_Info_print(
const struct KernAux_Multiboot2_Info *const multiboot2_info,
const KernAux_Display display
@ -308,31 +348,43 @@ void KernAux_Multiboot2_ITag_MemoryMap_print(
// Print data:
PRINTLN (" varies(entry_size) entries[]: [");
if (tag->entry_size == 0 ||
(tag->base.size - sizeof(*tag)) / tag->entry_size == 0)
{
PRINTLN (" varies(entry_size) entries[]: []");
} else {
PRINTLN (" varies(entry_size) entries[]: [");
const struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase *const entries =
(struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*)
KERNAUX_MULTIBOOT2_DATA((struct KernAux_Multiboot2_ITag_MemoryMap*)tag);
const struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*
const entries =
(struct KernAux_Multiboot2_ITag_MemoryMap_EntryBase*)
KERNAUX_MULTIBOOT2_DATA(tag);
for (
size_t index = 0;
index < (tag->base.size - sizeof(*tag)) / tag->entry_size;
++index
) {
KERNAUX_CAST_CONST(unsigned long long, base_addr, entries[index].base_addr);
KERNAUX_CAST_CONST(unsigned long long, length, entries[index].length);
KERNAUX_CAST_CONST(unsigned long, type, entries[index].type);
KERNAUX_CAST_CONST(unsigned long, reserved, entries[index].reserved);
for (
size_t index = 0;
index < (tag->base.size - sizeof(*tag)) / tag->entry_size;
++index
) {
KERNAUX_CAST_CONST(unsigned long long, base_addr,
entries[index].base_addr);
KERNAUX_CAST_CONST(unsigned long long, length,
entries[index].length);
KERNAUX_CAST_CONST(unsigned long, type,
entries[index].type);
KERNAUX_CAST_CONST(unsigned long, reserved,
entries[index].reserved);
PRINTLNF(" [%zu] entry: {", index);
PRINTLNF(" u64 base_addr: 0x%llx", base_addr);
PRINTLNF(" u64 length: %llu", length);
PRINTLNF(" u32 type: %lu", type);
PRINTLNF(" u32 reserved: 0x%lx", reserved);
PRINTLN (" }");
PRINTLNF(" [%zu]: {", index);
PRINTLNF(" u64 base_addr: 0x%llx", base_addr);
PRINTLNF(" u64 length: %llu", length);
PRINTLNF(" u32 type: %lu", type);
PRINTLNF(" u32 reserved: 0x%lx", reserved);
PRINTLN (" }");
}
PRINTLN(" ]");
}
PRINTLN(" ]");
FOOTER;
}
@ -426,7 +478,62 @@ void KernAux_Multiboot2_ITag_ELFSymbols_print(
PRINTLNF(" u32 entsize: %lu", entsize);
PRINTLNF(" u32 shndx: %lu", shndx);
// TODO: Print data?
// Print data:
if (tag->num == 0) {
PRINTLN(" varies(entsize) section_headers[]: []");
} else {
PRINTLN(" varies(entsize) section_headers[]: [");
const struct KernAux_ELF_Section *section =
(const struct KernAux_ELF_Section*)
KERNAUX_MULTIBOOT2_DATA(tag);
for (size_t index = 0; index < tag->num; ++index) {
KERNAUX_CAST_CONST(unsigned long, name, section->name);
KERNAUX_CAST_CONST(unsigned long, type, section->type);
KERNAUX_CAST_CONST(unsigned long, addr, section->addr);
KERNAUX_CAST_CONST(unsigned long, offset, section->offset);
KERNAUX_CAST_CONST(unsigned long, size, section->size);
KERNAUX_CAST_CONST(unsigned long, link, section->link);
KERNAUX_CAST_CONST(unsigned long, info, section->info);
KERNAUX_CAST_CONST(unsigned long, addralign, section->addralign);
KERNAUX_CAST_CONST(unsigned long, s_entsize, section->entsize);
const char *const type_name =
#ifdef WITH_ELF
KernAux_ELF_Section_Type_to_str(section->type);
#else
"?";
#endif
PRINTLNF(" [%zu]: {", index);
PRINTLNF(" name: %lu", name);
PRINTLNF(" type: %lu (%s)", type, type_name);
PRINT (" flags: ");
KernAux_ELF_Section_Flags_print(
section->flags,
display,
6,
2,
false
);
PRINTLNF(" addr: 0x%lx", addr);
PRINTLNF(" offset: 0x%lx", offset);
PRINTLNF(" size: %lu", size);
PRINTLNF(" link: %lu", link);
PRINTLNF(" info: %lu", info);
PRINTLNF(" addralign: %lu", addralign);
PRINTLNF(" entsize: %lu", s_entsize);
PRINTLN (" }");
section =
(const struct KernAux_ELF_Section*)
(((const uint8_t*)section) + tag->entsize);
}
PRINTLN(" ]");
}
FOOTER;
}
@ -610,3 +717,45 @@ void KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr_print(
FOOTER;
}
void KernAux_ELF_Section_Flags_print(
const uint16_t flags,
const KernAux_Display display,
const unsigned basic_indentation,
const unsigned indentation_delta,
const bool indent_first
) {
KERNAUX_CAST_CONST(unsigned long, flags_ul, flags);
if (indent_first) INDENT;
PRINTF("0x%lx (", flags_ul);
bool is_first = true;
for (
size_t index = 0;
index < sizeof(section_flag_names) / sizeof(section_flag_names[0]);
++index
) {
if (flags & section_flag_names[index].number) {
if (is_first) {
PRINTLN("");
} else {
PRINTLN(" |");
}
INDENT;
INDENT_MORE;
PRINTF("%s", section_flag_names[index].name);
is_first = false;
}
}
if (is_first) {
PRINTLN(")");
} else {
PRINTLN("");
INDENT;
PRINTLN(")");
}
}

34
tests/.gitignore vendored Normal file
View File

@ -0,0 +1,34 @@
/multiboot2_header_print0
/multiboot2_header_print1
/multiboot2_header_print2
/multiboot2_info_print0
/multiboot2_info_print1
/multiboot2_info_print2
/test_arch_i386
/test_cmdline
/test_cmdline_gen
/test_cmdline_gen.c
/test_elf
/test_free_list
/test_mbr
/test_memmap
/test_multiboot2_common_packing
/test_multiboot2_header_helpers
/test_multiboot2_header_print
/test_multiboot2_header_print.c
/test_multiboot2_header_validation
/test_multiboot2_info_helpers
/test_multiboot2_info_print
/test_multiboot2_info_print.c
/test_multiboot2_info_validation
/test_ntoa
/test_ntoa_assert
/test_pfa
/test_pfa_assert
/test_printf
/test_printf_fmt_gen
/test_printf_fmt_gen.c
/test_printf_gen
/test_printf_gen.c
/test_stack_trace
/test_units_human

View File

@ -14,7 +14,7 @@ multiboot2_header_print0_LDADD = $(top_builddir)/libkernaux.la
multiboot2_header_print0_SOURCES = \
main.c \
multiboot2_header_print0.c \
multiboot2_header_example0.h
../fixtures/multiboot2_header_example0.h
endif
############################
@ -27,7 +27,7 @@ multiboot2_header_print1_LDADD = $(top_builddir)/libkernaux.la
multiboot2_header_print1_SOURCES = \
main.c \
multiboot2_header_print1.c \
multiboot2_header_example1.h
../fixtures/multiboot2_header_example1.h
endif
############################
@ -40,7 +40,7 @@ multiboot2_header_print2_LDADD = $(top_builddir)/libkernaux.la
multiboot2_header_print2_SOURCES = \
main.c \
multiboot2_header_print2.c \
multiboot2_header_example2.h
../fixtures/multiboot2_header_example2.h
endif
##########################
@ -53,7 +53,7 @@ multiboot2_info_print0_LDADD = $(top_builddir)/libkernaux.la
multiboot2_info_print0_SOURCES = \
main.c \
multiboot2_info_print0.c \
multiboot2_info_example0.h
../fixtures/multiboot2_info_example0.h
endif
##########################
@ -66,7 +66,7 @@ multiboot2_info_print1_LDADD = $(top_builddir)/libkernaux.la
multiboot2_info_print1_SOURCES = \
main.c \
multiboot2_info_print1.c \
multiboot2_info_example1.h
../fixtures/multiboot2_info_example1.h
endif
##########################
@ -79,7 +79,7 @@ multiboot2_info_print2_LDADD = $(top_builddir)/libkernaux.la
multiboot2_info_print2_SOURCES = \
main.c \
multiboot2_info_print2.c \
multiboot2_info_example2.h
../fixtures/multiboot2_info_example2.h
endif
##################
@ -121,7 +121,7 @@ test_cmdline_gen_SOURCES = \
test_cmdline_gen.c \
cmdline_gen.py \
cmdline_gen.jinja \
$(top_srcdir)/common/cmdline.yml \
$(top_srcdir)/fixtures/cmdline.yml \
cmdline_test.h \
cmdline_test.c
endif
@ -129,8 +129,8 @@ endif
CLEANFILES += test_cmdline_gen.c
test_cmdline_gen.c: $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml
$(PYTHON) $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/common/cmdline.yml test_cmdline_gen.c
test_cmdline_gen.c: $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/fixtures/cmdline.yml
$(PYTHON) $(top_srcdir)/tests/cmdline_gen.py $(top_srcdir)/tests/cmdline_gen.jinja $(top_srcdir)/fixtures/cmdline.yml test_cmdline_gen.c
############
# test_elf #
@ -190,8 +190,8 @@ test_multiboot2_common_packing_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_common_packing_SOURCES = \
main.c \
test_multiboot2_common_packing.c \
multiboot2_header_example2.h \
multiboot2_info_example2.h
../fixtures/multiboot2_header_example2.h \
../fixtures/multiboot2_info_example2.h
endif
##################################
@ -204,8 +204,8 @@ test_multiboot2_header_helpers_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_header_helpers_SOURCES = \
main.c \
test_multiboot2_header_helpers.c \
multiboot2_header_example1.h \
multiboot2_header_example2.h
../fixtures/multiboot2_header_example1.h \
../fixtures/multiboot2_header_example2.h
endif
################################
@ -217,7 +217,10 @@ TESTS += test_multiboot2_header_print
test_multiboot2_header_print_DEPENDENCIES = \
multiboot2_header_print0 \
multiboot2_header_print1 \
multiboot2_header_print2
multiboot2_header_print2 \
../fixtures/multiboot2_header_example0.txt \
../fixtures/multiboot2_header_example1.txt \
../fixtures/multiboot2_header_example2.txt
test_multiboot2_header_print_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_header_print_SOURCES = \
main.c \
@ -234,8 +237,8 @@ test_multiboot2_header_validation_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_header_validation_SOURCES = \
main.c \
test_multiboot2_header_validation.c \
multiboot2_header_example1.h \
multiboot2_header_example2.h
../fixtures/multiboot2_header_example1.h \
../fixtures/multiboot2_header_example2.h
endif
################################
@ -248,8 +251,8 @@ test_multiboot2_info_helpers_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_info_helpers_SOURCES = \
main.c \
test_multiboot2_info_helpers.c \
multiboot2_info_example1.h \
multiboot2_info_example2.h
../fixtures/multiboot2_info_example1.h \
../fixtures/multiboot2_info_example2.h
endif
##############################
@ -261,7 +264,10 @@ TESTS += test_multiboot2_info_print
test_multiboot2_info_print_DEPENDENCIES = \
multiboot2_info_print0 \
multiboot2_info_print1 \
multiboot2_info_print2
multiboot2_info_print2 \
../fixtures/multiboot2_info_example0.txt \
../fixtures/multiboot2_info_example1.txt \
../fixtures/multiboot2_info_example2.txt
test_multiboot2_info_print_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_info_print_SOURCES = \
main.c \
@ -278,8 +284,8 @@ test_multiboot2_info_validation_LDADD = $(top_builddir)/libkernaux.la
test_multiboot2_info_validation_SOURCES = \
main.c \
test_multiboot2_info_validation.c \
multiboot2_info_example1.h \
multiboot2_info_example2.h
../fixtures/multiboot2_info_example1.h \
../fixtures/multiboot2_info_example2.h
endif
#############
@ -359,14 +365,14 @@ test_printf_fmt_gen_SOURCES = \
test_printf_fmt_gen.c \
printf_fmt_gen.py \
printf_fmt_gen.jinja \
$(top_srcdir)/common/printf_fmt.yml
$(top_srcdir)/fixtures/printf_fmt.yml
endif
endif
CLEANFILES += test_printf_fmt_gen.c
test_printf_fmt_gen.c: $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml
$(PYTHON) $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/common/printf_fmt.yml test_printf_fmt_gen.c
test_printf_fmt_gen.c: $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/fixtures/printf_fmt.yml
$(PYTHON) $(top_srcdir)/tests/printf_fmt_gen.py $(top_srcdir)/tests/printf_fmt_gen.jinja $(top_srcdir)/fixtures/printf_fmt.yml test_printf_fmt_gen.c
###################
# test_printf_gen #
@ -381,15 +387,15 @@ test_printf_gen_SOURCES = \
test_printf_gen.c \
printf_gen.py \
printf_gen.jinja \
$(top_srcdir)/common/printf.yml \
$(top_srcdir)/common/printf_orig.yml
$(top_srcdir)/fixtures/printf.yml \
$(top_srcdir)/fixtures/printf_orig.yml
endif
endif
CLEANFILES += test_printf_gen.c
test_printf_gen.c: $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml
$(PYTHON) $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/common/printf.yml $(top_srcdir)/common/printf_orig.yml test_printf_gen.c
test_printf_gen.c: $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/fixtures/printf.yml $(top_srcdir)/fixtures/printf_orig.yml
$(PYTHON) $(top_srcdir)/tests/printf_gen.py $(top_srcdir)/tests/printf_gen.jinja $(top_srcdir)/fixtures/printf.yml $(top_srcdir)/fixtures/printf_orig.yml test_printf_gen.c
####################
# test_stack_trace #

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example0.h"
#include "../fixtures/multiboot2_header_example0.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example1.h"
#include "../fixtures/multiboot2_header_example1.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_header_example2.h"
#include "../fixtures/multiboot2_header_example2.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example0.h"
#include "../fixtures/multiboot2_info_example0.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example1.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -12,7 +12,7 @@
#include <stdarg.h>
#include <stdio.h>
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example2.h"
static void my_putc(void *display KERNAUX_UNUSED, char c)
{

View File

@ -4,25 +4,4 @@
#include <kernaux/elf.h>
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#define BUFFER_SIZE (1024 * 1024)
void test_main(int argc, char **argv)
{
assert(argc >= 1);
FILE *const fd = fopen(argv[0], "r");
assert(fd);
uint8_t buffer[BUFFER_SIZE];
const size_t size = fread(buffer, sizeof(uint8_t), BUFFER_SIZE, fd);
assert(size > 0);
assert(KernAux_ELF_Header_is_valid((struct KernAux_ELF_Header*)buffer));
fclose(fd);
}
void test_main() {}

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include <stdint.h>
#include "multiboot2_header_example2.h"
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_header_example2.h"
#include "../fixtures/multiboot2_info_example2.h"
#define HEAD_SIZEOF1(type, inst, size) \
do { \

View File

@ -4,8 +4,8 @@
#include <kernaux/multiboot2.h>
#include "multiboot2_header_example1.h"
#include "multiboot2_header_example2.h"
#include "../fixtures/multiboot2_header_example1.h"
#include "../fixtures/multiboot2_header_example2.h"
void test_main()
{

View File

@ -1,218 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#ifndef __USE_POSIX2
#define __USE_POSIX2
#endif
#include <stdio.h>
static const char output0[] =
"Multiboot 2 header {\n"
" u32 magic: 0xe85250d6\n"
" u32 arch: 0 (i386)\n"
" u32 size: 24\n"
" u32 checksum: 0x17adaf12\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 0 (none)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 8\n"
"}\n";
static const char output1[] =
"Multiboot 2 header {\n"
" u32 magic: 0xe85250d6\n"
" u32 arch: 4 (MIPS32)\n"
" u32 size: 104\n"
" u32 checksum: 0x17adaebe\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 4 (flags)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 console_flags: 0x0 ()\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 4 (flags)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 console_flags: 0x1 (\n"
" REQUIRE_CONSOLE\n"
" )\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 4 (flags)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 console_flags: 0x2 (\n"
" EGA_SUPPORT\n"
" )\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 4 (flags)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 console_flags: 0x3 (\n"
" REQUIRE_CONSOLE |\n"
" EGA_SUPPORT\n"
" )\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 1 (information request)\n"
" u16 flags: 0x1 (\n"
" OPTIONAL\n"
" )\n"
" u32 size: 12\n"
" u32 mbi_tag_types[]: [\n"
" 0 (none)\n"
" ]\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 0 (none)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 8\n"
"}\n";
static const char output2[] =
"Multiboot 2 header {\n"
" u32 magic: 0xe85250d6\n"
" u32 arch: 0 (i386)\n"
" u32 size: 272\n"
" u32 checksum: 0x17adae1a\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 1 (information request)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 96\n"
" u32 mbi_tag_types[]: [\n"
" 0 (none)\n"
" 1 (boot cmd line)\n"
" 2 (boot loader name)\n"
" 3 (module)\n"
" 4 (basic memory info)\n"
" 5 (BIOS boot device)\n"
" 6 (memory map)\n"
" 7 (VBE info)\n"
" 8 (framebuffer info)\n"
" 9 (ELF symbols)\n"
" 10 (APM table)\n"
" 11 (EFI 32bit system table ptr)\n"
" 12 (EFI 64bit system table ptr)\n"
" 13 (SMBIOS tables)\n"
" 14 (ACPI old RSDP)\n"
" 15 (ACPI new RSDP)\n"
" 16 (networking info)\n"
" 17 (EFI memory map)\n"
" 18 (EFI boot services not terminated)\n"
" 19 (EFI 32bit image handle ptr)\n"
" 20 (EFI 64bit image handle ptr)\n"
" 21 (image load base phys addr)\n"
" ]\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 2 (address)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 24\n"
" u32 header_addr: 0xcafebabe\n"
" u32 load_addr: 0xdeadbeaf\n"
" u32 load_end_addr: 0xdeadbabe\n"
" u32 bss_end_addr: 0xcafebeaf\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 3 (entry address)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 entry_addr: 0xcafebabe\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 4 (flags)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 console_flags: 0x0 ()\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 5 (framebuffer)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 20\n"
" u32 width: 80\n"
" u32 height: 25\n"
" u32 depth: 8\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 6 (module alignment)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 8\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 7 (EFI boot services)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 8\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 8 (EFI i386 entry address)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 entry_addr: 0xcafebabe\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 9 (EFI amd64 entry address)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 12\n"
" u32 entry_addr: 0xdeadbeaf\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 10 (relocatable header)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 24\n"
" u32 min_addr: 0xcafebabe\n"
" u32 max_addr: 0xdeadbeaf\n"
" u32 align: 8\n"
" u32 preference: 1 (lowest)\n"
"}\n"
"Multiboot 2 header tag {\n"
" u16 type: 0 (none)\n"
" u16 flags: 0x0 ()\n"
" u32 size: 8\n"
"}\n";
void test_main()
{
{
FILE *const fd = popen("./multiboot2_header_print0", "r");
assert(fd != NULL);
for (const char *ch = output0; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
{
FILE *const fd = popen("./multiboot2_header_print1", "r");
assert(fd != NULL);
for (const char *ch = output1; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
{
FILE *const fd = popen("./multiboot2_header_print2", "r");
assert(fd != NULL);
for (const char *ch = output2; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
}

View File

@ -0,0 +1,61 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#ifndef __USE_POSIX2
#define __USE_POSIX2
#endif
#include <stdio.h>
void test_main()
{
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_header_print0", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example0.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_header_print1", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example1.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_header_print2", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_header_example2.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
}

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example2.h"
#include <kernaux/macro/packing_start.run>

View File

@ -1,441 +0,0 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#ifndef __USE_POSIX2
#define __USE_POSIX2
#endif
#include <stdio.h>
static const char output0[] =
"Multiboot 2 info {\n"
" u32 size: 16\n"
" u32 reserved: 0x0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 0 (none)\n"
" u32 size: 8\n"
"}\n";
static const char output1[] =
"Multiboot 2 info {\n"
" u32 size: 864\n"
" u32 reserved: 0x0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 21 (image load base phys addr)\n"
" u32 size: 12\n"
" u32 load_base_addr: 0x400000\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 1 (boot cmd line)\n"
" u32 size: 21\n"
" char cmdline[]: \"hello kernel\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 2 (boot loader name)\n"
" u32 size: 30\n"
" char name[]: \"GRUB 2.02-2ubuntu8.20\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 10 (APM table)\n"
" u32 size: 28\n"
" u16 version: 258\n"
" u16 cseg: 61440\n"
" u32 offset: 54479\n"
" u16 cseg_16: 61440\n"
" u16 dseg: 61440\n"
" u16 flags: 3\n"
" u16 cseg_len: 65520\n"
" u16 cseg_16_len: 65520\n"
" u16 dseg_len: 65520\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 3 (module)\n"
" u32 size: 29\n"
" u32 mod_start: 0x102000\n"
" u32 mod_end: 0x10329c\n"
" char cmdline[]: \"hello module\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 3 (module)\n"
" u32 size: 17\n"
" u32 mod_start: 0x104000\n"
" u32 mod_end: 0x105254\n"
" char cmdline[]: \"\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 6 (memory map)\n"
" u32 size: 160\n"
" u32 entry_size: 24\n"
" u32 entry_version: 0\n"
" varies(entry_size) entries[]: [\n"
" [0] entry: {\n"
" u64 base_addr: 0x0\n"
" u64 length: 654336\n"
" u32 type: 1\n"
" u32 reserved: 0x0\n"
" }\n"
" [1] entry: {\n"
" u64 base_addr: 0x9fc00\n"
" u64 length: 1024\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [2] entry: {\n"
" u64 base_addr: 0xf0000\n"
" u64 length: 65536\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [3] entry: {\n"
" u64 base_addr: 0x100000\n"
" u64 length: 133038080\n"
" u32 type: 1\n"
" u32 reserved: 0x0\n"
" }\n"
" [4] entry: {\n"
" u64 base_addr: 0x7fe0000\n"
" u64 length: 131072\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [5] entry: {\n"
" u64 base_addr: 0xfffc0000\n"
" u64 length: 262144\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" ]\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 9 (ELF symbols)\n"
" u32 size: 420\n"
" u32 num: 10\n"
" u32 entsize: 40\n"
" u32 shndx: 9\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 4 (basic memory info)\n"
" u32 size: 16\n"
" u32 mem_lower: 639\n"
" u32 mem_upper: 129920\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 5 (BIOS boot device)\n"
" u32 size: 20\n"
" u32 biosdev: 224\n"
" u32 partition: 4294967295\n"
" u32 sub_partition: 4294967295\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 8 (framebuffer info)\n"
" u32 size: 32\n"
" u64 framebuffer_addr: 0xb8000\n"
" u32 framebuffer_pitch: 160\n"
" u32 framebuffer_width: 80\n"
" u32 framebuffer_height: 25\n"
" u8 framebuffer_bpp: 16\n"
" u8 framebuffer_type: 2\n"
" u16 reserved: 0x0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 14 (ACPI old RSDP)\n"
" u32 size: 28\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 0 (none)\n"
" u32 size: 8\n"
"}\n";
static const char output2_part1[] =
"Multiboot 2 info {\n"
" u32 size: 1816\n"
" u32 reserved: 0x0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 1 (boot cmd line)\n"
" u32 size: 23\n"
" char cmdline[]: \"Hello, Kernel!\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 2 (boot loader name)\n"
" u32 size: 30\n"
" char name[]: \"GRUB 2.02-2ubuntu8.20\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 3 (module)\n"
" u32 size: 33\n"
" u32 mod_start: 0x7b\n"
" u32 mod_end: 0x1c8\n"
" char cmdline[]: \"Hello, Module 1!\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 3 (module)\n"
" u32 size: 33\n"
" u32 mod_start: 0x7b\n"
" u32 mod_end: 0x1c8\n"
" char cmdline[]: \"Hello, Module 2!\"\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 4 (basic memory info)\n"
" u32 size: 16\n"
" u32 mem_lower: 123\n"
" u32 mem_upper: 456\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 5 (BIOS boot device)\n"
" u32 size: 20\n"
" u32 biosdev: 0\n"
" u32 partition: 1\n"
" u32 sub_partition: 2\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 6 (memory map)\n"
" u32 size: 160\n"
" u32 entry_size: 24\n"
" u32 entry_version: 0\n"
" varies(entry_size) entries[]: [\n"
" [0] entry: {\n"
" u64 base_addr: 0x0\n"
" u64 length: 654336\n"
" u32 type: 1\n"
" u32 reserved: 0x0\n"
" }\n"
" [1] entry: {\n"
" u64 base_addr: 0x9fc00\n"
" u64 length: 1024\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [2] entry: {\n"
" u64 base_addr: 0xf0000\n"
" u64 length: 65536\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [3] entry: {\n"
" u64 base_addr: 0x100000\n"
" u64 length: 133038080\n"
" u32 type: 1\n"
" u32 reserved: 0x0\n"
" }\n"
" [4] entry: {\n"
" u64 base_addr: 0x7fe0000\n"
" u64 length: 131072\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" [5] entry: {\n"
" u64 base_addr: 0xfffc0000\n"
" u64 length: 262144\n"
" u32 type: 2\n"
" u32 reserved: 0x0\n"
" }\n"
" ]\n"
"}\n";
static const char output2_part2[] =
"Multiboot 2 info tag {\n"
" u32 type: 7 (VBE info)\n"
" u32 size: 784\n"
" u16 vbe_mode: 0\n"
" u16 vbe_interface_seg: 123\n"
" u16 vbe_interface_off: 456\n"
" u16 vbe_interface_len: 789\n"
" u8 vbe_control_info[]: [\n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 123 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 123\n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" ]\n"
" u8 vbe_mode_info[]: [\n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 32 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 255 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 32 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 255\n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n"
" ]\n"
"}\n";
static const char output2_part3[] =
"Multiboot 2 info tag {\n"
" u32 type: 8 (framebuffer info)\n"
" u32 size: 40\n"
" u64 framebuffer_addr: 0x7b\n"
" u32 framebuffer_pitch: 456\n"
" u32 framebuffer_width: 123\n"
" u32 framebuffer_height: 456\n"
" u8 framebuffer_bpp: 8\n"
" u8 framebuffer_type: 1\n"
" u16 reserved: 0x0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 9 (ELF symbols)\n"
" u32 size: 420\n"
" u32 num: 10\n"
" u32 entsize: 40\n"
" u32 shndx: 9\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 10 (APM table)\n"
" u32 size: 28\n"
" u16 version: 0\n"
" u16 cseg: 123\n"
" u32 offset: 456\n"
" u16 cseg_16: 789\n"
" u16 dseg: 123\n"
" u16 flags: 1\n"
" u16 cseg_len: 456\n"
" u16 cseg_16_len: 789\n"
" u16 dseg_len: 123\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 11 (EFI 32bit system table ptr)\n"
" u32 size: 12\n"
" u32 pointer: 0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 12 (EFI 64bit system table ptr)\n"
" u32 size: 16\n"
" u64 pointer: 0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 13 (SMBIOS tables)\n"
" u32 size: 24\n"
" u8 major: 1\n"
" u8 minor: 2\n"
" u8 reserved[6]: [0x0, 0x0, 0x0, 0x0, 0x0, 0x0]\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 14 (ACPI old RSDP)\n"
" u32 size: 16\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 15 (ACPI new RSDP)\n"
" u32 size: 16\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 16 (networking info)\n"
" u32 size: 16\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 17 (EFI memory map)\n"
" u32 size: 24\n"
" u32 descriptor_size: 123\n"
" u32 descriptor_version: 1\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 18 (EFI boot services not terminated)\n"
" u32 size: 8\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 19 (EFI 32bit image handle ptr)\n"
" u32 size: 12\n"
" u32 pointer: 0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 20 (EFI 64bit image handle ptr)\n"
" u32 size: 16\n"
" u64 pointer: 0\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 21 (image load base phys addr)\n"
" u32 size: 12\n"
" u32 load_base_addr: 0x7b\n"
"}\n"
"Multiboot 2 info tag {\n"
" u32 type: 0 (none)\n"
" u32 size: 8\n"
"}\n";
void test_main()
{
{
FILE *const fd = popen("./multiboot2_info_print0", "r");
assert(fd != NULL);
for (const char *ch = output0; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
{
FILE *const fd = popen("./multiboot2_info_print1", "r");
assert(fd != NULL);
for (const char *ch = output1; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
{
const size_t part1_len = strlen(output2_part1);
const size_t part2_len = strlen(output2_part2);
const size_t part3_len = strlen(output2_part3);
char *const output2 = malloc(1 + part1_len + part2_len + part3_len);
assert(output2);
strcpy(output2, output2_part1);
strcat(output2, output2_part2);
strcat(output2, output2_part3);
FILE *const fd = popen("./multiboot2_info_print2", "r");
assert(fd != NULL);
for (const char *ch = output2; *ch; ++ch) {
assert(fgetc(fd) == *ch);
}
const int status = pclose(fd);
assert(status == 0);
}
}

View File

@ -0,0 +1,61 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#ifndef __USE_POSIX2
#define __USE_POSIX2
#endif
#include <stdio.h>
void test_main()
{
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_info_print0", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example0.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_info_print1", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example1.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
{
FILE *const print_file =
popen("@abs_top_builddir@/tests/multiboot2_info_print2", "r");
FILE *const text_file =
fopen("@abs_top_srcdir@/fixtures/multiboot2_info_example2.txt", "r");
assert(print_file != NULL);
assert(text_file != NULL);
while (!feof(text_file)) {
assert(fgetc(print_file) == fgetc(text_file));
}
assert(pclose(print_file) == 0);
assert(fclose(text_file) == 0);
}
}

View File

@ -7,8 +7,8 @@
#include <assert.h>
#include "multiboot2_info_example1.h"
#include "multiboot2_info_example2.h"
#include "../fixtures/multiboot2_info_example1.h"
#include "../fixtures/multiboot2_info_example2.h"
#include <kernaux/macro/packing_start.run>