diff options
author | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-31 05:00:21 -0500 |
---|---|---|
committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-01-31 05:03:20 -0500 |
commit | 696cc120ed8fcb61f4ae38e2c53b52bdfe8c904c (patch) | |
tree | 00849f8722f42bf5c5a295fe9bd460f5861be269 /kernel | |
parent | 91491cf19d18168fea7ded80ac5128efa2f9bb09 (diff) |
{halt,io,stack_smashing_protector,printf}: C->C++
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/CMakeLists.txt | 8 | ||||
-rw-r--r-- | kernel/include/kernel/halt.h | 8 | ||||
-rw-r--r-- | kernel/include/kernel/io.h | 8 | ||||
-rw-r--r-- | kernel/kernel/halt.cc (renamed from kernel/kernel/halt.c) | 3 | ||||
-rw-r--r-- | kernel/kernel/io.cc (renamed from kernel/kernel/io.c) | 19 | ||||
-rw-r--r-- | kernel/kernel/stack_smashing_protector.cc (renamed from kernel/kernel/stack_smashing_protector.c) | 2 | ||||
-rw-r--r-- | kernel/libk/printf.cc (renamed from kernel/libk/printf.c) | 36 |
7 files changed, 42 insertions, 42 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index cb39e32..e3212b0 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -9,13 +9,13 @@ set(SRC drivers/serial.cc drivers/vga_text_buffer.cc - kernel/halt.c - kernel/io.c + kernel/halt.cc + kernel/io.cc kernel/kernel.cc kernel/spinlock.cc - kernel/stack_smashing_protector.c + kernel/stack_smashing_protector.cc - libk/printf.c + libk/printf.cc libk/printk.cc libk/strlen.cc libk/kmalloc.cc diff --git a/kernel/include/kernel/halt.h b/kernel/include/kernel/halt.h index 60ac008..db511cf 100644 --- a/kernel/include/kernel/halt.h +++ b/kernel/include/kernel/halt.h @@ -19,15 +19,7 @@ #ifndef __kernel_halt_h #define __kernel_halt_h -#ifdef __cplusplus -extern "C" { -#endif - void halt(void); void exit(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/kernel/include/kernel/io.h b/kernel/include/kernel/io.h index 5cef4f5..f58bd2d 100644 --- a/kernel/include/kernel/io.h +++ b/kernel/include/kernel/io.h @@ -21,15 +21,7 @@ #include <stdint.h> -#ifdef __cplusplus -extern "C" { -#endif - uint8_t inb(uint16_t port); void outb(uint16_t port, uint8_t val); -#ifdef __cplusplus -} -#endif - #endif diff --git a/kernel/kernel/halt.c b/kernel/kernel/halt.cc index 2640829..b40ad0e 100644 --- a/kernel/kernel/halt.c +++ b/kernel/kernel/halt.cc @@ -16,10 +16,9 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include <libk/stdio.h> - #include <kernel/halt.h> #include <kernel/io.h> +#include <libk/stdio.h> void halt(void) diff --git a/kernel/kernel/io.c b/kernel/kernel/io.cc index f8feb32..e081ed7 100644 --- a/kernel/kernel/io.c +++ b/kernel/kernel/io.cc @@ -1,6 +1,23 @@ -#include <stdint.h> +/* + * bubbl + * Copyright (C) 2024-2025 Raghuram Subramani <raghus2247@gmail.com> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ #include <kernel/io.h> +#include <stdint.h> /* Sends a 8/16/32-bit value on a I/O location. Traditional names are outb, * outw and outl respectively. The a modifier enforces val to be placed in the diff --git a/kernel/kernel/stack_smashing_protector.c b/kernel/kernel/stack_smashing_protector.cc index f9c83b2..2a63540 100644 --- a/kernel/kernel/stack_smashing_protector.c +++ b/kernel/kernel/stack_smashing_protector.cc @@ -25,7 +25,7 @@ uintptr_t __stack_chk_guard = STACK_CHK_GUARD; -void +extern "C" void __stack_chk_fail(void) { /* TODO: Panic the kernel */ diff --git a/kernel/libk/printf.c b/kernel/libk/printf.cc index 017556c..cacb338 100644 --- a/kernel/libk/printf.c +++ b/kernel/libk/printf.cc @@ -1,10 +1,14 @@ +#include <libk/stdio.h> +#include <libk/string.h> #include <limits.h> #include <stdarg.h> #include <stddef.h> #include <stdint.h> -#include <libk/stdio.h> -#include <libk/string.h> +/* warning: narrowing conversion of 'uc' from 'unsigned char' to 'char' is + * ill-formed in C++11 [-Wnarrowing] */ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnarrowing" int sprintf(char *str, const char *fmt, ...) @@ -39,7 +43,7 @@ struct _output_args { static int _vsnprintf_output(const char *str, size_t len, void *state) { - struct _output_args *args = state; + struct _output_args *args = (struct _output_args *) state; size_t count = 0; while (count < len) { if (args->pos < args->len) { @@ -80,15 +84,12 @@ vsnprintf(char *str, size_t len, const char *fmt, va_list ap) #define LEADZEROFLAG 0x00001000 #define BLANKPOSFLAG 0x00002000 static char * -longlong_to_string(char *buf, - unsigned long long n, - size_t len, - unsigned int flag, - char *signchar) +longlong_to_string( + char *buf, uint64_t n, size_t len, unsigned int flag, char *signchar) { size_t pos = len; int negative = 0; - if ((flag & SIGNEDFLAG) && (long long) n < 0) { + if ((flag & SIGNEDFLAG) && (int64_t) n < 0) { negative = 1; n = -n; } @@ -115,10 +116,7 @@ static const char hextable[] = { '0', '1', '2', '3', '4', '5', '6', '7', static const char hextable_caps[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; static char * -longlong_to_hexstring(char *buf, - unsigned long long u, - size_t len, - unsigned int flag) +longlong_to_hexstring(char *buf, uint64_t u, size_t len, unsigned int flag) { size_t pos = len; const char *table = (flag & CAPSFLAG) ? hextable_caps : hextable; @@ -368,7 +366,7 @@ _printf_engine(_printf_engine_output_func out, unsigned char uc; const char *s; size_t string_len; - unsigned long long n; + uint64_t n; void *ptr; int flags; unsigned int format_num; @@ -477,7 +475,7 @@ _printf_engine(_printf_engine_output_func out, goto next_format; case 'i': case 'd': - n = (flags & LONGLONGFLAG) ? va_arg(ap, long long) + n = (flags & LONGLONGFLAG) ? va_arg(ap, int64_t) : (flags & LONGFLAG) ? va_arg(ap, long) : (flags & HALFHALFFLAG) ? (signed char) va_arg(ap, int) : (flags & HALFFLAG) ? (short) va_arg(ap, int) @@ -490,7 +488,7 @@ _printf_engine(_printf_engine_output_func out, num_buffer, n, sizeof(num_buffer), flags, &signchar); goto _output_string; case 'u': - n = (flags & LONGLONGFLAG) ? va_arg(ap, unsigned long long) + n = (flags & LONGLONGFLAG) ? va_arg(ap, uint64_t) : (flags & LONGFLAG) ? va_arg(ap, unsigned long) : (flags & HALFHALFFLAG) ? (unsigned char) va_arg(ap, unsigned int) : (flags & HALFFLAG) ? (unsigned short) va_arg(ap, unsigned int) @@ -509,7 +507,7 @@ _printf_engine(_printf_engine_output_func out, /* fallthrough */ hex: case 'x': - n = (flags & LONGLONGFLAG) ? va_arg(ap, unsigned long long) + n = (flags & LONGLONGFLAG) ? va_arg(ap, uint64_t) : (flags & LONGFLAG) ? va_arg(ap, unsigned long) : (flags & HALFHALFFLAG) ? (unsigned char) va_arg(ap, unsigned int) : (flags & HALFFLAG) ? (unsigned short) va_arg(ap, unsigned int) @@ -530,7 +528,7 @@ _printf_engine(_printf_engine_output_func out, case 'n': ptr = va_arg(ap, void *); if (flags & LONGLONGFLAG) - *(long long *) ptr = chars_written; + *(int64_t *) ptr = chars_written; else if (flags & LONGFLAG) *(long *) ptr = chars_written; else if (flags & HALFHALFFLAG) @@ -613,3 +611,5 @@ _printf_engine(_printf_engine_output_func out, exit: return (err < 0) ? err : (int) chars_written; } + +#pragma GCC diagnostic pop |