diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-05 21:08:58 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2021-03-05 21:09:05 +0200 |
commit | 81429ad8e8daee9bc90e4558525535e4b37dbe5c (patch) | |
tree | 13bea920f7c42f14d5e9b48e78f4d1e791dd4507 | |
parent | add broken Scheduler (diff) | |
download | kernel.cpp-81429ad8e8daee9bc90e4558525535e4b37dbe5c.tar.xz |
libk: add int_t min max size constants
-rw-r--r-- | drivers/makefile | 2 | ||||
-rw-r--r-- | libk/types.h | 29 | ||||
-rw-r--r-- | libk/types/test.cc | 64 | ||||
-rw-r--r-- | makefile | 13 | ||||
-rw-r--r-- | src/makefile | 2 | ||||
-rw-r--r-- | toolchain.makefile | 2 |
6 files changed, 75 insertions, 37 deletions
diff --git a/drivers/makefile b/drivers/makefile index 2a1fa0c..9405f0b 100644 --- a/drivers/makefile +++ b/drivers/makefile @@ -6,7 +6,7 @@ HWH := drivers/hardware.h autogen := $(autogen) $(HWH) $(HWH): .config - @echo " GEN $@" + @echo " GEN $@" @echo \/\* autogenerated hardware description \*\/ > $(HWH) @echo \#pragma once >> $(HWH) ifdef CONFIG_video0_enable diff --git a/libk/types.h b/libk/types.h index 4c50a35..7f16206 100644 --- a/libk/types.h +++ b/libk/types.h @@ -4,27 +4,36 @@ typedef unsigned short size_t; typedef int ssize_t; typedef unsigned char uint8_t; +constexpr uint8_t uint8_t_min = 0; +constexpr uint8_t uint8_t_max = 0xff; typedef unsigned short uint16_t; constexpr uint16_t uint16_t_min = 0; constexpr uint16_t uint16_t_max = 0xffff; typedef unsigned int uint32_t; -typedef unsigned long long int uint64_t; +constexpr uint32_t uint32_t_min = 0; +constexpr uint32_t uint32_t_max = 0xffffffff; + +typedef unsigned long long uint64_t; +constexpr uint64_t uint64_t_min = 0; +constexpr uint64_t uint64_t_max = 0xffffffffffffffff; typedef char int8_t; +constexpr int8_t int8_t_max = uint8_t_max / 2; +constexpr int8_t int8_t_min = -int8_t_max - 1; + typedef short int16_t; +constexpr int16_t int16_t_max = uint16_t_max / 2; +constexpr int16_t int16_t_min = -int16_t_max - 1; + typedef int int32_t; -typedef long long int int64_t; +constexpr int32_t int32_t_max = uint32_t_max / 2; +constexpr int32_t int32_t_min = -int32_t_max - 1; -/* in x86: - * byte: 1 byte, 8 bits - * word: 2 bytes, 16 bits - * dword: 4 bytes, 32 bits - * qword: 8 bytes, 64 bits - * */ -typedef uint16_t uword_t; -typedef int16_t word_t; +typedef long long int int64_t; +constexpr int64_t int64_t_max = uint64_t_max / 2; +constexpr int64_t int64_t_min = -int64_t_max - 1; // Type Traits diff --git a/libk/types/test.cc b/libk/types/test.cc index f93d883..b3f29d9 100644 --- a/libk/types/test.cc +++ b/libk/types/test.cc @@ -1,29 +1,51 @@ -#include <types.h> +#include <stdint.h> + +namespace libk { +#include "types.h" +} // types -static_assert(sizeof(size_t) >= 2); +static_assert(sizeof(libk::size_t) >= 2); + +static_assert(sizeof(libk::uint8_t) == 1); +static_assert(libk::uint8_t_max == UINT8_MAX); + +static_assert(sizeof(libk::uint16_t) == 2); +static_assert(libk::uint16_t_max == UINT16_MAX); + +static_assert(sizeof(libk::uint32_t) == 4); +static_assert(libk::uint32_t_max == UINT32_MAX); -static_assert(sizeof(uint8_t) == 1); -static_assert(sizeof(uint16_t) == 2); -static_assert(sizeof(uint32_t) == 4); -static_assert(sizeof(uint64_t) == 8); +static_assert(sizeof(libk::uint64_t) == 8); +static_assert(libk::uint64_t_max == UINT64_MAX); -static_assert(sizeof(int8_t) == 1); -static_assert(sizeof(int16_t) == 2); -static_assert(sizeof(int32_t) == 4); -static_assert(sizeof(int64_t) == 8); +static_assert(sizeof(libk::int8_t) == 1); +static_assert(libk::int8_t_min == INT8_MIN); +static_assert(libk::int8_t_max == INT8_MAX); + +static_assert(sizeof(libk::int16_t) == 2); +static_assert(libk::int16_t_min == INT16_MIN); +static_assert(libk::int16_t_max == INT16_MAX); + +static_assert(sizeof(libk::int32_t) == 4); +static_assert(libk::int32_t_min == INT32_MIN); +static_assert(libk::int32_t_max == INT32_MAX); + +static_assert(sizeof(libk::int64_t) == 8); +static_assert(libk::int64_t_min == INT64_MIN); +static_assert(libk::int64_t_max == INT64_MAX); // is_same -static_assert(is_same<int, int>() == true); -static_assert(is_same<int, unsigned int>() == false); +static_assert(libk::is_same<int, int>() == true); +static_assert(libk::is_same<int, unsigned int>() == false); // is_unsigned -static_assert(is_unsigned<uint8_t>() == true); -static_assert(is_unsigned<uint16_t>() == true); -static_assert(is_unsigned<uint32_t>() == true); -static_assert(is_unsigned<uint64_t>() == true); - -static_assert(is_unsigned<int8_t>() == false); -static_assert(is_unsigned<int16_t>() == false); -static_assert(is_unsigned<int32_t>() == false); -static_assert(is_unsigned<int64_t>() == false); +static_assert(libk::is_unsigned<uint8_t>() == true); +static_assert(libk::is_unsigned<uint16_t>() == true); +static_assert(libk::is_unsigned<uint32_t>() == true); +static_assert(libk::is_unsigned<uint64_t>() == true); + +static_assert(libk::is_unsigned<int8_t>() == false); +static_assert(libk::is_unsigned<int16_t>() == false); +static_assert(libk::is_unsigned<int32_t>() == false); +static_assert(libk::is_unsigned<int64_t>() == false); @@ -17,20 +17,25 @@ CXX_INCLUDE := $(addprefix -I, $(CXX_INCLUDE)) CXX_SYSTEM_INCLUDE := $(addprefix -isystem, $(CXX_SYSTEM_INCLUDE)) glitch.elf: $(autogen) $(AS_OBJ) $(CXX_OBJ) - @echo " LD $@" + @echo " LD $@" @$(LD) $(LD_FLAGS) -o $@ $(AS_OBJ) $(CXX_OBJ) $(AS_OBJ): $(OBJ_DIR)/%.o: %.S @mkdir -p $(@D) - @echo " AS $<" + @echo " AS $<" @$(AS) -target $(TARGET) -nostdlib -Wall -Wextra -c $^ -o $@ -include $(CXX_DEP) -$(CXX_OBJ) $(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc +$(CXX_OBJ): $(OBJ_DIR)/%.o : %.cc @mkdir -p $(@D) - @echo " CXX $<" + @echo " CXX $<" @$(CXX) -target $(TARGET) $(CXX_FLAGS) $(CXX_INCLUDE) $(CXX_SYSTEM_INCLUDE) -MMD -c $< -o $@ +$(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc + @mkdir -p $(@D) + @echo " TEST $<" + @$(TEST_CXX) -target $(TARGET) $(CXX_TEST_FLAGS) $(CXX_INCLUDE) -MMD -c $< -o $@ + clean: @rm -rf $(autogen) $(AS_OBJ) $(CXX_OBJ) $(CXX_DEP) $(CXX_TEST_OBJ) glitch.elf isodir diff --git a/src/makefile b/src/makefile index d4b2ac8..ceaf5ef 100644 --- a/src/makefile +++ b/src/makefile @@ -12,7 +12,7 @@ CXX_OBJ += src/kernel.o \ src/scheduler.o src/cpu/irq.h: $(OBJ_DIR)/src/idt/stubs.o - @echo " GEN $@" + @echo " GEN $@" @echo '#pragma once' > $@ @echo 'extern "C" {' >> $@ @echo '/* interrupt map */' >> $@ diff --git a/toolchain.makefile b/toolchain.makefile index 0631904..ae791c1 100644 --- a/toolchain.makefile +++ b/toolchain.makefile @@ -11,6 +11,7 @@ LD := ld.lld LD_FLAGS := -T linker.ld CXX := clang++ +TEST_CXX := clang++ CXX_FLAGS := -std=c++20 \ -mkernel -ffreestanding -nostdlib -nostdinc -nostdinc++ \ -Wall -Wextra -Werror=pedantic -O2 \ @@ -18,6 +19,7 @@ CXX_FLAGS := -std=c++20 \ -Werror=shadow-all \ -Wold-style-cast -Wconversion \ -Wconsumed +CXX_TEST_FLAGS := -std=c++20 -Wall -Wextra -Werror=pedantic CXX_INCLUDE := $(CURDIR)/libk $(CURDIR)/src $(CURDIR)/drivers CXX_SYSTEM_INCLUDE := $(CURDIR)/grub |