mirror of
https://github.com/tailix/libkernaux.git
synced 2025-04-14 17:32:55 -04:00
Maintenance (#98)
* Fix copyright * Remove thanks * Update CONTRIBUTING.md * Remove bitfields from struct KernAux_Arch_I386_TSS * Change description of package "mbr" * Make generic file stable * Rename printf examples
This commit is contained in:
parent
74d14aff8f
commit
0922a18e70
18 changed files with 168 additions and 95 deletions
8
.gitignore
vendored
8
.gitignore
vendored
|
@ -108,8 +108,6 @@
|
|||
|
||||
/examples/assert
|
||||
/examples/cmdline
|
||||
/examples/fprintf
|
||||
/examples/fprintf_va
|
||||
/examples/generic_file
|
||||
/examples/generic_malloc
|
||||
/examples/generic_mutex
|
||||
|
@ -117,9 +115,11 @@
|
|||
/examples/ntoa
|
||||
/examples/panic
|
||||
/examples/pfa
|
||||
/examples/printf_file
|
||||
/examples/printf_file_va
|
||||
/examples/printf_fmt
|
||||
/examples/snprintf
|
||||
/examples/snprintf_va
|
||||
/examples/printf_str
|
||||
/examples/printf_str_va
|
||||
/examples/units_human
|
||||
|
||||
/tests/multiboot2_header_print1
|
||||
|
|
|
@ -2,16 +2,73 @@ Common
|
|||
------
|
||||
|
||||
* Add your name to [COPYING](/COPYING).
|
||||
* **Don't** add your name to `AUTHORS` - it's for maintainers.
|
||||
* Don't add your name to `AUTHORS` - it's for maintainers.
|
||||
* Add copyright notice in the beginning of changed files except the headers.
|
||||
* If you change the behavior (even just fix a bug) of **libkernaux** (stable) or
|
||||
[libc](/libc), add a record to [ChangeLog](/ChangeLog).
|
||||
|
||||
Prohibitions:
|
||||
|
||||
* Don't commit binary files
|
||||
* Don't commit configuration files of your editor or IDE
|
||||
* Don't use encodings other than ASCII and UTF-8
|
||||
* Don't use alphabets other than Latin
|
||||
* Don't use languages other than English
|
||||
* Don't use tabulations (I don't hate tabs, but people can not use them
|
||||
properly)
|
||||
* Don't leave trailing whitespaces
|
||||
* Don't forget the newline character in the end of files
|
||||
|
||||
The following statements are recommendations, but highly encouraged:
|
||||
|
||||
* Write documentation
|
||||
* Write tests
|
||||
* Keep lines less than 80 characters long for better experience on split screen
|
||||
|
||||
### Programming mistakes
|
||||
|
||||
* Always check documentation, manuals and specifications
|
||||
|
||||
Avoid stupid errors with:
|
||||
|
||||
* Manual memory management
|
||||
* `malloc` may return `NULL`
|
||||
* Memory leak (forget to `free`)
|
||||
* Use after `free`/`realloc`
|
||||
* Double `free`/`realloc`
|
||||
* `free`ing/`realloc`ating unallocated memory
|
||||
* Changing the original pointer to the allocated memory (use `const`!)
|
||||
* `NULL` pointers and `nil`/`None`/whatever objects
|
||||
* Division by zero
|
||||
* Pointer arithmetic - consider type size
|
||||
* Type sizes (like `long` on 32-bit and 64-bit)
|
||||
* Integer arithmetic overflow
|
||||
* Bit shift
|
||||
* Endianness (byte order)
|
||||
* Data packing
|
||||
* Data alignment
|
||||
* Thread safety
|
||||
* Undefined behavior
|
||||
* Logical expressions (tautology, whatever)
|
||||
* Checking for an error (return value, pointer argument, whatever)
|
||||
* Use of not fully initialized data
|
||||
* Not reading beyond a buffer, array or string
|
||||
* The index of the last item, which is less than the buffer size
|
||||
* Negative indices
|
||||
* The terminating null character in a string
|
||||
* Allowed values of arguments
|
||||
* Possible values of parameters
|
||||
* Operator precedence
|
||||
* Default case in switch statements
|
||||
* Braces (curly brackets) around code blocks
|
||||
|
||||
|
||||
|
||||
C language
|
||||
----------
|
||||
|
||||
Use **cppcheck**.
|
||||
|
||||
* Name regular functions (*not methods*) and variables in lower snake case
|
||||
(example: `foo_bar`).
|
||||
* Name macros in upper snake case (example: `FOO_BAR`).
|
||||
|
@ -78,6 +135,22 @@ FooBar_init(foobar);
|
|||
FooBar_do_something(foobar);
|
||||
```
|
||||
|
||||
* Mark variables and parameters with `const` if you don't plan to modify them
|
||||
* Only omit braces (curly brackets) of a block if it's statement is placed on
|
||||
the same line as conditional statement:
|
||||
|
||||
```c
|
||||
// Good:
|
||||
if (foo) return bar;
|
||||
if (foo) {
|
||||
return bar;
|
||||
}
|
||||
|
||||
// Bad:
|
||||
if (foo)
|
||||
return bar;
|
||||
```
|
||||
|
||||
|
||||
|
||||
Python
|
||||
|
@ -90,6 +163,8 @@ Nothing here yet.
|
|||
Ruby
|
||||
----
|
||||
|
||||
* Freeze objects if you don't plan to modify them
|
||||
|
||||
### Matz's Ruby interpreter
|
||||
|
||||
Use **RuboCop**. See [bindings/ruby/.rubocop.yml](/bindings/ruby/.rubocop.yml)
|
||||
|
|
14
README.md
14
README.md
|
@ -48,7 +48,7 @@ zero). Work-in-progress APIs can change at any time.
|
|||
* [Declarations](/include/kernaux/arch/)
|
||||
* [Functions](/include/kernaux/asm/)
|
||||
* Generic types
|
||||
* [File](/include/kernaux/generic/file.h) (*work in progress*)
|
||||
* [File](/include/kernaux/generic/file.h) (*non-breaking since* **?.?.?**)
|
||||
* [Example](/examples/generic_file.c)
|
||||
* [Memory allocator](/include/kernaux/generic/malloc.h) (*non-breaking since* **?.?.?**)
|
||||
* [Example](/examples/generic_malloc.c)
|
||||
|
@ -62,7 +62,7 @@ zero). Work-in-progress APIs can change at any time.
|
|||
* [Example](/examples/pfa.c)
|
||||
* Data formats
|
||||
* [ELF](/include/kernaux/elf.h) (*work in progress*)
|
||||
* [Master Boot Record](/include/kernaux/mbr.h) (*work in progress*)
|
||||
* [MBR](/include/kernaux/mbr.h) (*work in progress*)
|
||||
* [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h) (*work in progress*)
|
||||
* Utilities
|
||||
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
|
||||
|
@ -70,17 +70,15 @@ zero). Work-in-progress APIs can change at any time.
|
|||
* [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**)
|
||||
* [Example](/examples/memmap.c)
|
||||
* [printf format parser](/include/kernaux/printf_fmt.h) (*work in progress*)
|
||||
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you!
|
||||
* [Example](/examples/printf_fmt.c)
|
||||
* Usual functions
|
||||
* [itoa/ftoa replacement](/include/kernaux/ntoa.h) (*non-breaking since* **0.4.0**)
|
||||
* [Example](/examples/ntoa.c)
|
||||
* [printf replacement](/include/kernaux/printf.h.in) (*non-breaking since* **?.?.?**)
|
||||
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you!
|
||||
* [Example: fprintf](/examples/fprintf.c)
|
||||
* [Example: vfprintf](/examples/fprintf_va.c)
|
||||
* [Example: snprintf](/examples/snprintf.c)
|
||||
* [Example: vsnprintf](/examples/snprintf_va.c)
|
||||
* [Example: fprintf](/examples/printf_file.c)
|
||||
* [Example: vfprintf](/examples/printf_file_va.c)
|
||||
* [Example: snprintf](/examples/printf_str.c)
|
||||
* [Example: vsnprintf](/examples/printf_str_va.c)
|
||||
* libc replacement (*work in progress*)
|
||||
* [ctype.h](/libc/include/ctype.h)
|
||||
* [inttypes.h](/libc/include/inttypes.h)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# The code was taken from Marco Paland's printf.
|
||||
|
||||
# Copyright (c) 2014-2019 Marco Paland <info@paland.com>
|
||||
# Copyright (c) 2020-2022 Alex Kotov
|
||||
# Copyright (c) 2021-2022 Alex Kotov
|
||||
|
||||
# TODO: add remaining tests from
|
||||
# https://github.com/mpaland/printf/blob/master/test/test_suite.cpp
|
||||
|
|
|
@ -65,7 +65,7 @@ AC_ARG_WITH( [asm], AS_HELP_STRING([--without-asm], [without
|
|||
AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser]))
|
||||
AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils]))
|
||||
AC_ARG_WITH( [free-list], AS_HELP_STRING([--without-free-list], [without free list memory allocator]))
|
||||
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record]))
|
||||
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without MBR utils]))
|
||||
AC_ARG_WITH( [memmap], AS_HELP_STRING([--without-memmap], [without memory map]))
|
||||
AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser]))
|
||||
AC_ARG_WITH( [ntoa], AS_HELP_STRING([--without-ntoa], [without itoa/ftoa]))
|
||||
|
@ -248,7 +248,7 @@ AS_IF([test "$with_asm" = yes], [AC_DEFINE([WITH_ASM], [1]
|
|||
AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])])
|
||||
AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])])
|
||||
AS_IF([test "$with_free_list" = yes], [AC_DEFINE([WITH_FREE_LIST], [1], [with free list memory allocator])])
|
||||
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 MBR utils])])
|
||||
AS_IF([test "$with_memmap" = yes], [AC_DEFINE([WITH_MEMMAP], [1], [with memory map])])
|
||||
AS_IF([test "$with_multiboot2" = yes], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])])
|
||||
AS_IF([test "$with_ntoa" = yes], [AC_DEFINE([WITH_NTOA], [1], [with ntoa])])
|
||||
|
|
|
@ -21,26 +21,6 @@ cmdline_LDADD = $(top_builddir)/libkernaux.la
|
|||
cmdline_SOURCES = main.c cmdline.c
|
||||
endif
|
||||
|
||||
###########
|
||||
# fprintf #
|
||||
###########
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += fprintf
|
||||
fprintf_LDADD = $(top_builddir)/libkernaux.la
|
||||
fprintf_SOURCES = main.c fprintf.c
|
||||
endif
|
||||
|
||||
##############
|
||||
# fprintf_va #
|
||||
##############
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += fprintf_va
|
||||
fprintf_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
fprintf_va_SOURCES = main.c fprintf_va.c
|
||||
endif
|
||||
|
||||
################
|
||||
# generic_file #
|
||||
################
|
||||
|
@ -103,6 +83,26 @@ pfa_LDADD = $(top_builddir)/libkernaux.la
|
|||
pfa_SOURCES = main.c pfa.c
|
||||
endif
|
||||
|
||||
###############
|
||||
# printf_file #
|
||||
###############
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += printf_file
|
||||
printf_file_LDADD = $(top_builddir)/libkernaux.la
|
||||
printf_file_SOURCES = main.c printf_file.c
|
||||
endif
|
||||
|
||||
##################
|
||||
# printf_file_va #
|
||||
##################
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += printf_file_va
|
||||
printf_file_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
printf_file_va_SOURCES = main.c printf_file_va.c
|
||||
endif
|
||||
|
||||
##############
|
||||
# printf_fmt #
|
||||
##############
|
||||
|
@ -113,24 +113,24 @@ printf_fmt_LDADD = $(top_builddir)/libkernaux.la
|
|||
printf_fmt_SOURCES = main.c printf_fmt.c
|
||||
endif
|
||||
|
||||
############
|
||||
# snprintf #
|
||||
############
|
||||
##############
|
||||
# printf_str #
|
||||
##############
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += snprintf
|
||||
snprintf_LDADD = $(top_builddir)/libkernaux.la
|
||||
snprintf_SOURCES = main.c snprintf.c
|
||||
TESTS += printf_str
|
||||
printf_str_LDADD = $(top_builddir)/libkernaux.la
|
||||
printf_str_SOURCES = main.c printf_str.c
|
||||
endif
|
||||
|
||||
###############
|
||||
# snprintf_va #
|
||||
###############
|
||||
#################
|
||||
# printf_str_va #
|
||||
#################
|
||||
|
||||
if WITH_PRINTF
|
||||
TESTS += snprintf_va
|
||||
snprintf_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
snprintf_va_SOURCES = main.c snprintf_va.c
|
||||
TESTS += printf_str_va
|
||||
printf_str_va_LDADD = $(top_builddir)/libkernaux.la
|
||||
printf_str_va_SOURCES = main.c printf_str_va.c
|
||||
endif
|
||||
|
||||
###############
|
||||
|
|
|
@ -82,48 +82,48 @@ KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_Arch_I386_DTE, 8);
|
|||
*/
|
||||
struct KernAux_Arch_I386_TSS {
|
||||
// 0x00
|
||||
unsigned prev_tss : 16;
|
||||
unsigned _zero0 : 16;
|
||||
uint16_t prev_tss;
|
||||
uint16_t _zero0;
|
||||
// 0x04
|
||||
unsigned esp0 : 32;
|
||||
unsigned ss0 : 16;
|
||||
unsigned _zero1 : 16;
|
||||
unsigned esp1 : 32;
|
||||
unsigned ss1 : 16;
|
||||
unsigned _zero2 : 16;
|
||||
unsigned esp2 : 32;
|
||||
unsigned ss2 : 16;
|
||||
unsigned _zero3 : 16;
|
||||
uint32_t esp0;
|
||||
uint16_t ss0;
|
||||
uint16_t _zero1;
|
||||
uint32_t esp1;
|
||||
uint16_t ss1;
|
||||
uint16_t _zero2;
|
||||
uint32_t esp2;
|
||||
uint16_t ss2;
|
||||
uint16_t _zero3;
|
||||
// 0x1c
|
||||
unsigned cr3 : 32;
|
||||
unsigned eip : 32;
|
||||
unsigned eflags : 32;
|
||||
unsigned eax : 32;
|
||||
unsigned ecx : 32;
|
||||
unsigned edx : 32;
|
||||
unsigned ebx : 32;
|
||||
unsigned esp : 32;
|
||||
unsigned ebp : 32;
|
||||
unsigned esi : 32;
|
||||
unsigned edi : 32;
|
||||
uint32_t cr3;
|
||||
uint32_t eip;
|
||||
uint32_t eflags;
|
||||
uint32_t eax;
|
||||
uint32_t ecx;
|
||||
uint32_t edx;
|
||||
uint32_t ebx;
|
||||
uint32_t esp;
|
||||
uint32_t ebp;
|
||||
uint32_t esi;
|
||||
uint32_t edi;
|
||||
// 0x48
|
||||
unsigned es : 16;
|
||||
unsigned _zero4 : 16;
|
||||
unsigned cs : 16;
|
||||
unsigned _zero5 : 16;
|
||||
unsigned ss : 16;
|
||||
unsigned _zero6 : 16;
|
||||
unsigned ds : 16;
|
||||
unsigned _zero7 : 16;
|
||||
unsigned fs : 16;
|
||||
unsigned _zero8 : 16;
|
||||
unsigned gs : 16;
|
||||
unsigned _zero9 : 16;
|
||||
unsigned ldt : 16;
|
||||
unsigned _zero10 : 16;
|
||||
uint16_t es;
|
||||
uint16_t _zero4;
|
||||
uint16_t cs;
|
||||
uint16_t _zero5;
|
||||
uint16_t ss;
|
||||
uint16_t _zero6;
|
||||
uint16_t ds;
|
||||
uint16_t _zero7;
|
||||
uint16_t fs;
|
||||
uint16_t _zero8;
|
||||
uint16_t gs;
|
||||
uint16_t _zero9;
|
||||
uint16_t ldt;
|
||||
uint16_t _zero10;
|
||||
// 0x64
|
||||
unsigned _zero11 : 16;
|
||||
unsigned io_map_base : 16;
|
||||
uint16_t _zero11;
|
||||
uint16_t io_map_base;
|
||||
}
|
||||
KERNAUX_PACKING_ATTR;
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
/**
|
||||
* The code was taken from musl libc.
|
||||
*
|
||||
* Copyright (c) 2011 Rich Felker
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2022 Alexander Monakov
|
||||
* Copyright (c) 2011 Rich Felker
|
||||
* Copyright (c) 2022 Alexander Monakov
|
||||
* Copyright (c) 2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* The code was taken from musl libc.
|
||||
*
|
||||
* Copyright (c) 2011-2015 Rich Felker
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
*
|
||||
* Copyright (c) 2011 Nicholas J. Kain
|
||||
* Copyright (c) 2011-2012 Rich Felker
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2022 Alexander Monakov
|
||||
* Copyright (c) 2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
*
|
||||
* Copyright (c) 2011 Nicholas J. Kain
|
||||
* Copyright (c) 2011-2012 Rich Felker
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2022 Alexander Monakov
|
||||
* Copyright (c) 2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* The code was inspired by the Embedded Artistry's libmemory.
|
||||
*
|
||||
* Copyright (c) 2017-2022 Embedded Artistry LLC
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* The code was taken from Marco Paland's printf.
|
||||
*
|
||||
* Copyright (c) 2014-2019 Marco Paland <info@paland.com>
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2021-2022 Alex Kotov
|
||||
*
|
||||
* Tiny [v]fprintf, sfprintf and [v]snprintf implementation, optimized for speed
|
||||
* on embedded systems with a very limited resources. These routines are thread
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* The code was taken from Marco Paland's printf.
|
||||
*
|
||||
* Copyright (c) 2014-2019 Marco Paland <info@paland.com>
|
||||
* Copyright (c) 2020-2022 Alex Kotov
|
||||
* Copyright (c) 2021-2022 Alex Kotov
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
|
Loading…
Add table
Reference in a new issue