diff --git a/SDK/CRT/INC/stddef.h b/SDK/CRT/INC/stddef.h new file mode 100644 index 0000000..e29727f --- /dev/null +++ b/SDK/CRT/INC/stddef.h @@ -0,0 +1,60 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + stddef.h + +Abstract: + + Provides standard types and definitions. + +--*/ + +#pragma once + +#ifndef _STDDEF_H +#define _STDDEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#ifdef __cplusplus +#define NULL 0 +#else +#define NULL ((void*)0) +#endif +#endif + +#ifndef _SIZE_T_DEFINED +#define _SIZE_T_DEFINED +#ifdef _WIN64 +typedef unsigned __int64 size_t; +#else +typedef unsigned int size_t; +#endif +#endif + +#ifndef _PTRDIFF_T_DEFINED +#define _PTRDIFF_T_DEFINED +#ifdef _WIN64 +typedef __int64 ptrdiff_t; +#else +typedef long int ptrdiff_t; +#endif +#endif + +#ifndef _WCHAR_T_DEFINED +#define _WCHAR_T_DEFINED +typedef unsigned short wchar_t; +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* !_STDDEF_H */ diff --git a/SDK/CRT/INC/string.h b/SDK/CRT/INC/string.h new file mode 100644 index 0000000..ba4d158 --- /dev/null +++ b/SDK/CRT/INC/string.h @@ -0,0 +1,37 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + string.h + +Abstract: + + Provides definitions for string routines. + +--*/ + +#pragma once + +#ifndef _STRING_H +#define _STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +size_t strlen(const char *str); +size_t strnlen(const char *str, size_t maxlen); + +void *memset(void *dest, int c, size_t count); +void *memcpy(void *dest, const void *src, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* !_STRING_H */ diff --git a/SDK/CRT/INC/wchar.h b/SDK/CRT/INC/wchar.h new file mode 100644 index 0000000..39ca953 --- /dev/null +++ b/SDK/CRT/INC/wchar.h @@ -0,0 +1,37 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + wchar.h + +Abstract: + + Provides definitions for wide string routines. + +--*/ + +#pragma once + +#ifndef _WCHAR_H +#define _WCHAR_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +size_t wcslen(const wchar_t *str); +size_t wcsnlen(const wchar_t *str, size_t maxlen); + +wchar_t *wmemset(wchar_t *dest, wchar_t c, size_t count); +wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t count); + +#ifdef __cplusplus +} +#endif + +#endif /* !_WCHAR_H */ diff --git a/SDK/CRT/STRING/mem.c b/SDK/CRT/STRING/mem.c new file mode 100644 index 0000000..31cf63b --- /dev/null +++ b/SDK/CRT/STRING/mem.c @@ -0,0 +1,53 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + mem.c + +Abstract: + + Provides memory manipulation routines. + +--*/ + +#include + +void * +memset ( + void *dest, + int c, + size_t count + ) + +{ + void *ptr = dest; + + while (count--) { + *(char *)dest = (char)c; + dest = (char *)dest + 1; + } + + return ptr; +} + +void * +memcpy ( + void *dest, + const void *src, + size_t count + ) + +{ + void *ptr = dest; + + while (count--) { + *(char *)dest = *(char *)src; + dest = (char *)dest + 1; + src = (char *)src + 1; + } + + return ptr; +} diff --git a/SDK/CRT/STRING/str.c b/SDK/CRT/STRING/str.c new file mode 100644 index 0000000..d6efba9 --- /dev/null +++ b/SDK/CRT/STRING/str.c @@ -0,0 +1,45 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + str.c + +Abstract: + + Provides string manipulation routines. + +--*/ + +#include + +size_t +strlen ( + const char *str + ) + +{ + const char *ptr; + + ptr = str; + while (*ptr++); + + return ptr - str - sizeof(char); +} + +size_t +strnlen ( + const char *str, + size_t maxlen + ) + +{ + size_t len; + + len = 0; + while (len < maxlen && str[len++]); + + return len - sizeof(char); +} diff --git a/SDK/CRT/STRING/wmem.c b/SDK/CRT/STRING/wmem.c new file mode 100644 index 0000000..1cb7d3c --- /dev/null +++ b/SDK/CRT/STRING/wmem.c @@ -0,0 +1,53 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + wmem.c + +Abstract: + + Provides wide memory manipulation routines. + +--*/ + +#include + +wchar_t * +wmemset ( + wchar_t *dest, + wchar_t c, + size_t count + ) + +{ + void *ptr = dest; + + while (count--) { + *(wchar_t *)dest = c; + dest = (wchar_t *)dest + 1; + } + + return ptr; +} + +wchar_t * +wmemcpy ( + wchar_t *dest, + const wchar_t *src, + size_t count + ) + +{ + void *ptr = dest; + + while (count--) { + *(wchar_t *)dest = *(wchar_t *)src; + dest = (wchar_t *)dest + 1; + src = (wchar_t *)src + 1; + } + + return ptr; +} diff --git a/SDK/CRT/STRING/wstr.c b/SDK/CRT/STRING/wstr.c new file mode 100644 index 0000000..0146d8f --- /dev/null +++ b/SDK/CRT/STRING/wstr.c @@ -0,0 +1,45 @@ +/*++ + +Copyright (c) 2024, Quinn Stephens. +Provided under the BSD 3-Clause license. + +Module Name: + + wstr.c + +Abstract: + + Provides wide string manipulation routines. + +--*/ + +#include + +size_t +wcslen ( + const wchar_t *str + ) + +{ + const wchar_t *ptr; + + ptr = str; + while (*ptr++); + + return (const char*)ptr - (const char*)str - sizeof(wchar_t); +} + +size_t +wcsnlen ( + const wchar_t *str, + size_t maxlen + ) + +{ + size_t len; + + len = 0; + while (len < maxlen && str[len++]); + + return len - sizeof(wchar_t); +} diff --git a/premake5.lua b/premake5.lua index 09e41d3..f75122c 100644 --- a/premake5.lua +++ b/premake5.lua @@ -3,27 +3,44 @@ --- Provided under the BSD 3-Clause license. --- -workspace("LibreXP") +workspace("Alcyone") + configurations({ "DEBUG", "RELEASE" }) language("C") toolset("clang") - configurations({ "Debug", "Release" }) + system("windows") + warnings("Extra") - filter("configurations:Debug") - defines({ "DEBUG" }) + filter("configurations:DEBUG") symbols("On") + defines({ "_DEBUG" }) - filter("configurations:Release") - defines({ "NDEBUG" }) - optimize("On") + filter("configurations:RELEASE") + optimize("Speed") + filter("toolset:clang") + buildoptions({ "-target x86_64-windows-unknown", "-ffreestanding" }) + linkoptions({ "-target x86_64-windows-unknown", "-fuse-ld=lld-link", "-Wl,-nodefaultlib" }) + +project("CRT") + kind("StaticLib") + location("SDK/CRT") + + includedirs({ "SDK/CRT/INC" }) + objdir("BUILD/SDK/CRT") + targetdir("BUILD/SDK") + targetname("crt") + files({ "SDK/CRT/INC/**.h", "SDK/CRT/**.c" }) + +--[[ project("BOOT") kind("ConsoleApp") - includedirs({ "BOOT/ENVIRON/INC" }) + includedirs({ "BOOT/ENVIRON/INC", "SDK/INC/CRT" }) objdir("BUILD/BOOT") targetdir("BUILD/BOOT") files({ "BOOT/ENVIRON/INC/**.h", "BOOT/ENVIRON/**.c" }) filter("toolset:clang") - buildoptions({ "-target x86_64-windows-unknown", "-Wall", "-Wextra", "-O2", "-ffreestanding", "-fshort-wchar", "-fno-strict-aliasing", "-fno-stack-protector", "-fno-stack-check", "-mno-red-zone" }) - linkoptions({ "-target x86_64-windows-unknown", "-fuse-ld=lld-link", "-Wl,-subsystem:efi_application", "-Wl,-entry:EfiEntry", "-Wl,-nodefaultlib" }) + buildoptions({ "-fshort-wchar", "-fno-strict-aliasing", "-fno-stack-protector", "-fno-stack-check", "-mno-red-zone" }) + linkoptions({ "-Wl,-subsystem:efi_application", "-Wl,-entry:EfiEntry", "crt.lib" }) +--]]