2020-12-07 04:46:37 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2020-11-30 11:40:33 +00:00
|
|
|
#include "config.h"
|
2020-12-07 04:46:37 +00:00
|
|
|
#endif
|
2020-11-30 11:40:33 +00:00
|
|
|
|
2022-05-24 23:01:51 +00:00
|
|
|
#include <kernaux/assert.h>
|
2022-01-17 09:54:44 +00:00
|
|
|
#include <kernaux/console.h>
|
2022-06-07 05:35:14 +00:00
|
|
|
|
|
|
|
#include "libc.h"
|
2022-01-17 09:54:44 +00:00
|
|
|
|
2021-12-20 06:14:40 +00:00
|
|
|
#ifdef ASM_I386
|
|
|
|
#include <kernaux/asm/i386.h>
|
2020-11-30 11:32:12 +00:00
|
|
|
#endif
|
2022-01-11 06:48:54 +00:00
|
|
|
#ifdef ASM_X86_64
|
|
|
|
#include <kernaux/asm/x86_64.h>
|
|
|
|
#endif
|
2022-06-07 18:08:47 +00:00
|
|
|
|
|
|
|
#ifdef WITH_FILE
|
|
|
|
#include <kernaux/file.h>
|
|
|
|
#endif
|
2022-01-17 09:54:44 +00:00
|
|
|
#ifdef WITH_PRINTF
|
2020-12-07 00:09:47 +00:00
|
|
|
#include <kernaux/printf.h>
|
2022-01-17 09:54:44 +00:00
|
|
|
#endif
|
2020-11-30 11:32:12 +00:00
|
|
|
|
2022-01-19 12:01:21 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-06-07 18:08:47 +00:00
|
|
|
#if defined(WITH_FILE) && defined(WITH_PRINTF)
|
2022-01-19 12:04:46 +00:00
|
|
|
static void kernaux_console_printf_putc(
|
|
|
|
const char c,
|
|
|
|
void *const arg __attribute__((unused))
|
|
|
|
) {
|
|
|
|
kernaux_console_putc(c);
|
|
|
|
}
|
2022-01-20 11:34:12 +00:00
|
|
|
#endif
|
2022-01-19 12:04:46 +00:00
|
|
|
|
2020-12-06 01:41:31 +00:00
|
|
|
void kernaux_console_putc(const char c __attribute__((unused)))
|
|
|
|
{
|
2022-01-11 06:21:52 +00:00
|
|
|
#ifdef ASM_I386
|
2022-01-24 02:50:16 +00:00
|
|
|
kernaux_asm_i386_outportb(0x3f8, c);
|
2020-11-30 11:32:12 +00:00
|
|
|
#endif
|
2022-01-11 06:48:54 +00:00
|
|
|
#ifdef ASM_X86_64
|
2022-01-24 02:50:16 +00:00
|
|
|
kernaux_asm_x86_64_outportb(0x3f8, c);
|
2022-01-11 06:48:54 +00:00
|
|
|
#endif
|
2020-11-30 11:32:12 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 06:15:49 +00:00
|
|
|
void kernaux_console_print(const char *const s)
|
|
|
|
{
|
2022-05-24 23:01:51 +00:00
|
|
|
KERNAUX_NOTNULL_RETURN(s);
|
|
|
|
|
2021-12-26 06:15:49 +00:00
|
|
|
for (const char *c = s; *c; ++c) {
|
|
|
|
kernaux_console_putc(*c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 18:08:47 +00:00
|
|
|
#if defined(WITH_FILE) && defined(WITH_PRINTF)
|
2021-12-26 06:15:49 +00:00
|
|
|
void kernaux_console_printf(const char *format, ...)
|
|
|
|
{
|
2022-05-24 23:01:51 +00:00
|
|
|
KERNAUX_NOTNULL_RETURN(format);
|
|
|
|
|
2021-12-26 06:15:49 +00:00
|
|
|
va_list va;
|
|
|
|
va_start(va, format);
|
2022-06-07 18:08:47 +00:00
|
|
|
struct KernAux_File file = KernAux_File_create(kernaux_console_printf_putc);
|
|
|
|
kernaux_vfprintf(&file, NULL, format, va);
|
2021-12-26 06:15:49 +00:00
|
|
|
va_end(va);
|
|
|
|
}
|
2022-01-17 09:54:44 +00:00
|
|
|
#endif
|
2021-12-26 06:15:49 +00:00
|
|
|
|
2020-11-30 11:32:12 +00:00
|
|
|
void kernaux_console_puts(const char *const s)
|
|
|
|
{
|
2022-05-24 23:01:51 +00:00
|
|
|
KERNAUX_NOTNULL_RETURN(s);
|
|
|
|
|
2020-11-30 11:32:12 +00:00
|
|
|
kernaux_console_print(s);
|
|
|
|
kernaux_console_putc('\n');
|
|
|
|
}
|
|
|
|
|
2021-12-16 15:26:16 +00:00
|
|
|
void kernaux_console_write(const char *const data, const size_t size)
|
2020-12-06 01:41:31 +00:00
|
|
|
{
|
2022-05-24 23:01:51 +00:00
|
|
|
KERNAUX_NOTNULL_RETURN(data);
|
|
|
|
|
2021-12-16 15:26:16 +00:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2020-11-30 11:32:12 +00:00
|
|
|
kernaux_console_putc(data[i]);
|
|
|
|
}
|
|
|
|
}
|