diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 5e8e03c6..f4a7e678 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -45,7 +45,7 @@ target_compile_definitions(moon PRIVATE IN_MOON) target_compile_options(moon PRIVATE -Os) -target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla) +target_compile_options(moon PRIVATE -Wall -Wextra -Werror -Wvla -Wsign-conversion) target_compile_options(moon PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self) target_compile_options(moon PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) target_compile_options(moon PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) diff --git a/kernel/src/Log.cpp b/kernel/src/Log.cpp index 5d242ac6..e820dfd9 100644 --- a/kernel/src/Log.cpp +++ b/kernel/src/Log.cpp @@ -29,7 +29,7 @@ static void log_serial(LogLevel level, const char* format, va_list origin) cstyle_format( format, [](char c, void*) -> Result { - Serial::putchar(c); + Serial::putchar((u8)c); return {}; }, nullptr, ap); diff --git a/kernel/src/arch/Serial.cpp b/kernel/src/arch/Serial.cpp index 7e6f5f98..e82d75e1 100644 --- a/kernel/src/arch/Serial.cpp +++ b/kernel/src/arch/Serial.cpp @@ -7,12 +7,12 @@ namespace Serial { void write(const char* str, usize size) { - while (size--) putchar(*str++); + while (size--) putchar((u8)*str++); } void print(const char* str) { - while (*str) putchar(*str++); + while (*str) putchar((u8)*str++); } void println(const char* str) @@ -28,7 +28,7 @@ namespace Serial auto rc = cstyle_format( format, [](char c, void*) -> Result { - putchar(c); + putchar((u8)c); return {}; }, nullptr, ap); diff --git a/kernel/src/arch/Timer.cpp b/kernel/src/arch/Timer.cpp index 4ed1b780..09500356 100644 --- a/kernel/src/arch/Timer.cpp +++ b/kernel/src/arch/Timer.cpp @@ -6,16 +6,16 @@ static u64 timer_ticks = 0; static u64 boot_timestamp; -static inline constexpr int isleap(int year) +static inline constexpr bool isleap(u32 year) { return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); } -static constexpr int make_yday(int year, int month) +static constexpr u32 make_yday(u32 year, u32 month) { - constexpr short int upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; + constexpr u16 upto[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - int yd = upto[month - 1]; + u32 yd = upto[month - 1]; if (month > 2 && isleap(year)) yd++; return yd; } @@ -30,19 +30,19 @@ static constexpr u64 broken_down_to_unix(u64 year, u64 yday, u64 hour, u64 min, // The bootloader encodes the date and time in Binary-Coded Decimal (BCD), which represents decimal digits using // hexadecimal digits. For example, BCD 0x22 is 22 in decimal. // https://gitlab.com/bztsrc/bootboot/-/blob/master/bootboot_spec_1st_ed.pdf, page 15. -static inline constexpr int bcd_number_to_decimal(int num) +static inline constexpr u32 bcd_number_to_decimal(u32 num) { return ((num >> 4) * 10) + (num & 0xf); } static u64 bootloader_time_to_unix(const u8 boottime[8]) { - const int year = bcd_number_to_decimal(boottime[0]) * 100 + bcd_number_to_decimal(boottime[1]); - const int month = bcd_number_to_decimal(boottime[2]); - const int day = bcd_number_to_decimal(boottime[3]); - const int hour = bcd_number_to_decimal(boottime[4]); - const int minute = bcd_number_to_decimal(boottime[5]); - const int second = bcd_number_to_decimal(boottime[6]); + const u32 year = bcd_number_to_decimal(boottime[0]) * 100 + bcd_number_to_decimal(boottime[1]); + const u32 month = bcd_number_to_decimal(boottime[2]); + const u32 day = bcd_number_to_decimal(boottime[3]); + const u32 hour = bcd_number_to_decimal(boottime[4]); + const u32 minute = bcd_number_to_decimal(boottime[5]); + const u32 second = bcd_number_to_decimal(boottime[6]); // "The last byte can store 1/100th second precision, but in lack of support on most platforms, it is 0x00". // Therefore, let's not rely on it. kinfoln("Current time: %.2d/%.2d/%d %.2d:%.2d:%.2d UTC", day, month, year, hour, minute, second); diff --git a/luna/CMakeLists.txt b/luna/CMakeLists.txt index 286619d6..afdc8c8e 100644 --- a/luna/CMakeLists.txt +++ b/luna/CMakeLists.txt @@ -19,7 +19,7 @@ set(SOURCES add_library(luna-freestanding ${FREESTANDING_SOURCES}) target_compile_definitions(luna-freestanding PRIVATE USE_FREESTANDING) target_compile_options(luna-freestanding PRIVATE -Wall -Wextra -Werror -Wvla) -target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -Wcast-align -Wsign-conversion) +target_compile_options(luna-freestanding PRIVATE -Wdisabled-optimization -Wformat=2 -Winit-self -Wsign-conversion) target_compile_options(luna-freestanding PRIVATE -Wmissing-include-dirs -Wswitch-default -Wcast-qual -Wundef) target_compile_options(luna-freestanding PRIVATE -Wcast-align -Wwrite-strings -Wlogical-op -Wredundant-decls -Wshadow -Wconversion) target_compile_options(luna-freestanding PRIVATE -fno-rtti -ffreestanding -fno-exceptions) diff --git a/luna/include/luna/Alignment.h b/luna/include/luna/Alignment.h index 439bf2a1..90fa632a 100644 --- a/luna/include/luna/Alignment.h +++ b/luna/include/luna/Alignment.h @@ -7,9 +7,9 @@ template constexpr T is_aligned(T value) return (value % alignment == 0); } -static_assert(is_aligned<512>(1024)); -static_assert(!is_aligned<32>(235)); -static_assert(is_aligned<4096>(40960)); +static_assert(is_aligned<512>(1024u)); +static_assert(!is_aligned<32>(235u)); +static_assert(is_aligned<4096>(40960u)); // Must ALWAYS be called with a power of two as alignment. template constexpr T align_down(T value) @@ -18,9 +18,9 @@ template constexpr T align_down(T value) return value - value % alignment; } -static_assert(align_down<512>(598) == 512); -static_assert(align_down<64>(194) == 192); -static_assert(align_down<32>(64) == 64); +static_assert(align_down<512>(598ul) == 512ul); +static_assert(align_down<64>(194ul) == 192ul); +static_assert(align_down<32>(64ul) == 64ul); // Must ALWAYS be called with a power of two as alignment. template constexpr T align_up(T value) @@ -29,9 +29,9 @@ template constexpr T align_up(T value) return align_down(value) + alignment; } -static_assert(align_up<512>(598) == 1024); -static_assert(align_up<64>(194) == 256); -static_assert(align_up<32>(64) == 64); +static_assert(align_up<512>(598ul) == 1024ul); +static_assert(align_up<64>(194ul) == 256ul); +static_assert(align_up<32>(64ul) == 64ul); template constexpr T get_blocks_from_size(T value, T block_size) {