Add API <kernaux/console.h>

This commit is contained in:
Alex Kotov 2020-11-30 16:32:12 +05:00
parent 7f6240a42c
commit 8e7bdf9d16
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
7 changed files with 58 additions and 2 deletions

4
.gitignore vendored
View File

@ -21,6 +21,10 @@
/include/Makefile.in
/install-sh
/missing
/src/config.h
/src/config.h.in
/src/config.h.in~
/src/stamp-h1
/test-driver
/test-suite.log
/tests/test*.log

View File

@ -16,6 +16,7 @@ noinst_PROGRAMS = \
tests/multiboot2_print2
libkernaux_a_SOURCES = \
src/console.c \
src/multiboot2/helpers.c \
src/multiboot2/is_valid.c \
src/multiboot2/print.c \

View File

@ -22,7 +22,7 @@ API
---
* [Multiboot 2 (GRUB 2) information parser](/include/kernaux/multiboot2.h)
* Serial console *(planned)*
* [Serial console](/include/kernaux/console.h)
* [Page Frame Allocator](/include/kernaux/pfa.h) *(work in progress)*
* ELF utils *(planned)*
* [Architecture-specific helpers](/include/kernaux/arch/)

View File

@ -6,10 +6,14 @@ AC_INIT([libkernaux],
[https://github.com/kernelmq/libkernaux])
AC_CONFIG_SRCDIR([src/pfa.c])
AC_CONFIG_HEADERS([src/config.h])
AC_CANONICAL_HOST
AM_CONDITIONAL(ARCH_X86, test "${host_cpu}" = "x86")
AS_IF([test x"${host_cpu}" = x"x86"],
[AC_DEFINE([ARCH_X86],[1],[architecture is x86])])
AM_CONDITIONAL(ARCH_X86, test x"${host_cpu}" = x"x86")
AM_INIT_AUTOMAKE([1.9 subdir-objects -Wall -Werror])

View File

@ -1,5 +1,6 @@
nobase_include_HEADERS = \
kernaux/arch/x86.h \
kernaux/console.h \
kernaux/multiboot2.h \
kernaux/pfa.h \
kernaux/stdlib.h

17
include/kernaux/console.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef KERNAUX_INCLUDED_CONSOLE
#define KERNAUX_INCLUDED_CONSOLE 1
#ifdef __cplusplus
extern "C" {
#endif
void kernaux_console_print(const char *s);
void kernaux_console_putc(char c);
void kernaux_console_puts(const char *s);
void kernaux_console_write(const char *data, unsigned int size);
#ifdef __cplusplus
}
#endif
#endif

29
src/console.c Normal file
View File

@ -0,0 +1,29 @@
#ifdef ARCH_X86
#include <kernaux/arch/x86.h>
#endif
#include <kernaux/console.h>
#include <kernaux/stdlib.h>
void kernaux_console_print(const char *const s)
{
kernaux_console_write(s, kernaux_strlen(s));
}
void kernaux_console_putc(const char c __attribute__((unused))) {
#ifdef ARCH_X86
kernaux_arch_x86_outportb(0x3F8, c);
#endif
}
void kernaux_console_puts(const char *const s)
{
kernaux_console_print(s);
kernaux_console_putc('\n');
}
void kernaux_console_write(const char *const data, const unsigned int size) {
for (unsigned int i = 0; i < size; i++) {
kernaux_console_putc(data[i]);
}
}