Compare commits
4 Commits
1b5a01a6c9
...
fe6a6de923
Author | SHA1 | Date |
---|---|---|
|
fe6a6de923 | |
|
318ce5dec8 | |
|
526d4369ce | |
|
c69919738b |
|
@ -1,7 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(BAN CXX)
|
||||
|
||||
set(BAN_SOURCES
|
||||
BAN/Assert.cpp
|
||||
BAN/New.cpp
|
||||
|
@ -9,16 +5,8 @@ set(BAN_SOURCES
|
|||
BAN/Time.cpp
|
||||
)
|
||||
|
||||
add_custom_target(ban-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_library(ban ${BAN_SOURCES})
|
||||
add_dependencies(ban headers libc-install)
|
||||
banan_link_library(ban libc)
|
||||
|
||||
add_custom_target(ban-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libban.a ${BANAN_LIB}/
|
||||
DEPENDS ban
|
||||
BYPRODUCTS ${BANAN_LIB}/libban.a
|
||||
)
|
||||
banan_install_headers(ban)
|
||||
install(TARGETS ban)
|
||||
|
|
|
@ -193,7 +193,7 @@ namespace BAN
|
|||
|
||||
}
|
||||
|
||||
inline constexpr BAN::StringView operator""sv(const char* str, BAN::StringView::size_type len) { return BAN::StringView(str, len); }
|
||||
inline constexpr BAN::StringView operator""_sv(const char* str, BAN::StringView::size_type len) { return BAN::StringView(str, len); }
|
||||
|
||||
namespace BAN::Formatter
|
||||
{
|
||||
|
|
|
@ -10,52 +10,48 @@ add_compile_definitions(__enable_sse=1)
|
|||
project(banan-os CXX C ASM)
|
||||
|
||||
set(BANAN_BASE_SYSROOT ${CMAKE_SOURCE_DIR}/base-sysroot.tar.gz)
|
||||
|
||||
set(BANAN_INCLUDE ${BANAN_SYSROOT}/usr/include)
|
||||
set(BANAN_LIB ${BANAN_SYSROOT}/usr/lib)
|
||||
set(BANAN_BIN ${BANAN_SYSROOT}/usr/bin)
|
||||
set(BANAN_SHARE ${BANAN_SYSROOT}/usr/share)
|
||||
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
|
||||
set(BANAN_LIB ${BANAN_SYSROOT}/usr/lib)
|
||||
set(BANAN_BIN ${BANAN_SYSROOT}/usr/bin)
|
||||
set(BANAN_ETC ${BANAN_SYSROOT}/usr/etc)
|
||||
set(BANAN_SHARE ${BANAN_SYSROOT}/usr/share)
|
||||
set(BANAN_BOOT ${BANAN_SYSROOT}/boot)
|
||||
|
||||
set(CMAKE_INSTALL_BINDIR ${BANAN_BIN})
|
||||
set(CMAKE_INSTALL_SBINDIR ${BANAN_BIN})
|
||||
set(CMAKE_INSTALL_LIBDIR ${BANAN_LIB})
|
||||
set(CMAKE_INSTALL_INCLUDEDIR ${BANAN_INCLUDE})
|
||||
set(CMAKE_INSTALL_SYSCONF ${BANAN_ETC})
|
||||
set(CMAKE_INSTALL_MESSAGE NEVER)
|
||||
|
||||
# include headers of ${library} to ${target}
|
||||
function(banan_include_headers target library)
|
||||
target_include_directories(${target} PRIVATE $<TARGET_PROPERTY:${library},SOURCE_DIR>/include)
|
||||
endfunction()
|
||||
|
||||
# include headers and link ${library} to ${target}
|
||||
function(banan_link_library target library)
|
||||
target_link_libraries(${target} PRIVATE ${library})
|
||||
banan_include_headers(${target} ${library})
|
||||
endfunction()
|
||||
|
||||
# add install step for all header files of target
|
||||
function(banan_install_headers target)
|
||||
file(GLOB_RECURSE headers RELATIVE $<TARGET_PROPERTY:${target},SOURCE_DIR>/include "*.h")
|
||||
foreach(header ${headers})
|
||||
get_filename_component(subdirectory ${header} DIRECTORY)
|
||||
install(FILES include/${header} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${subdirectory} OPTIONAL)
|
||||
endforeach()
|
||||
target_include_directories(${target} PRIVATE $<TARGET_PROPERTY:${target},SOURCE_DIR>/include)
|
||||
endfunction()
|
||||
|
||||
add_subdirectory(kernel)
|
||||
add_subdirectory(bootloader)
|
||||
add_subdirectory(BAN)
|
||||
add_subdirectory(libc)
|
||||
add_subdirectory(LibELF)
|
||||
add_subdirectory(LibFont)
|
||||
add_subdirectory(LibGUI)
|
||||
add_subdirectory(LibImage)
|
||||
add_subdirectory(LibInput)
|
||||
add_subdirectory(userspace)
|
||||
|
||||
add_custom_target(sysroot
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${BANAN_SYSROOT}
|
||||
COMMAND cd ${BANAN_SYSROOT} && tar xf ${BANAN_BASE_SYSROOT}
|
||||
)
|
||||
|
||||
add_custom_target(headers
|
||||
DEPENDS kernel-headers
|
||||
DEPENDS ban-headers
|
||||
DEPENDS libc-headers
|
||||
DEPENDS libelf-headers
|
||||
DEPENDS libfont-headers
|
||||
DEPENDS libgui-headers
|
||||
DEPENDS libimage-headers
|
||||
DEPENDS libinput-headers
|
||||
)
|
||||
|
||||
add_custom_target(install-sysroot
|
||||
DEPENDS kernel-install
|
||||
DEPENDS ban-install
|
||||
DEPENDS libc-install
|
||||
DEPENDS userspace-install
|
||||
DEPENDS libelf-install
|
||||
DEPENDS libfont-install
|
||||
DEPENDS libgui-install
|
||||
DEPENDS libimage-install
|
||||
DEPENDS libinput-install
|
||||
)
|
||||
|
||||
add_custom_target(package-sysroot
|
||||
COMMAND cd ${BANAN_SYSROOT} && tar cf ${BANAN_SYSROOT_TAR} *
|
||||
DEPENDS install-sysroot
|
||||
)
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(LibELF CXX)
|
||||
|
||||
add_custom_target(libelf-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_custom_target(libelf-install
|
||||
DEPENDS libelf-headers
|
||||
)
|
|
@ -1,25 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(libfont CXX)
|
||||
|
||||
set(LIBGUI_SOURCES
|
||||
Font.cpp
|
||||
PSF.cpp
|
||||
)
|
||||
|
||||
add_custom_target(libfont-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_library(libfont ${LIBGUI_SOURCES})
|
||||
add_dependencies(libfont headers libc-install)
|
||||
target_link_libraries(libfont PUBLIC libc)
|
||||
|
||||
add_custom_target(libfont-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libfont.a ${BANAN_LIB}/
|
||||
DEPENDS libfont
|
||||
BYPRODUCTS ${BANAN_LIB}/libfont.a
|
||||
)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
@ -1,24 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(libgui CXX)
|
||||
|
||||
set(LIBGUI_SOURCES
|
||||
Window.cpp
|
||||
)
|
||||
|
||||
add_custom_target(libgui-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_library(libgui ${LIBGUI_SOURCES})
|
||||
add_dependencies(libgui headers libc-install)
|
||||
target_link_libraries(libgui PUBLIC libc libfont)
|
||||
|
||||
add_custom_target(libgui-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libgui.a ${BANAN_LIB}/
|
||||
DEPENDS libgui
|
||||
BYPRODUCTS ${BANAN_LIB}/libgui.a
|
||||
)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
@ -1,27 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(libimage CXX)
|
||||
|
||||
set(LIBIMAGE_SOURCES
|
||||
Image.cpp
|
||||
Netbpm.cpp
|
||||
PNG.cpp
|
||||
)
|
||||
|
||||
add_custom_target(libimage-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_library(libimage ${LIBIMAGE_SOURCES})
|
||||
add_dependencies(libimage headers libc-install)
|
||||
target_link_libraries(libimage PUBLIC libc)
|
||||
target_compile_options(libimage PRIVATE -O3)
|
||||
|
||||
add_custom_target(libimage-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libimage.a ${BANAN_LIB}/
|
||||
DEPENDS libimage
|
||||
BYPRODUCTS ${BANAN_LIB}/libimage.a
|
||||
)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
@ -1,24 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(libinput CXX)
|
||||
|
||||
set(LIBINPUT_SOURCES
|
||||
KeyEvent.cpp
|
||||
KeyboardLayout.cpp
|
||||
)
|
||||
|
||||
add_custom_target(libinput-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_library(libinput ${LIBINPUT_SOURCES})
|
||||
target_link_libraries(libinput PUBLIC libc ban)
|
||||
|
||||
add_custom_target(libinput-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libinput.a ${BANAN_LIB}/
|
||||
DEPENDS libinput
|
||||
BYPRODUCTS ${BANAN_LIB}/libinput.a
|
||||
)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
@ -1,474 +0,0 @@
|
|||
#include <BAN/Debug.h>
|
||||
#include <BAN/HashMap.h>
|
||||
#include <BAN/String.h>
|
||||
#include <BAN/StringView.h>
|
||||
#include <LibInput/KeyboardLayout.h>
|
||||
|
||||
#if __is_kernel
|
||||
#include <kernel/FS/VirtualFileSystem.h>
|
||||
#else
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
namespace LibInput
|
||||
{
|
||||
|
||||
struct StringViewLower
|
||||
{
|
||||
BAN::StringView value;
|
||||
|
||||
StringViewLower(BAN::StringView sv)
|
||||
: value(sv)
|
||||
{ }
|
||||
|
||||
bool operator==(const StringViewLower& other) const
|
||||
{
|
||||
if (value.size() != other.value.size())
|
||||
return false;
|
||||
for (size_t i = 0; i < value.size(); i++)
|
||||
if (tolower(value[i]) != tolower(other.value[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
struct StringViewLowerHash
|
||||
{
|
||||
BAN::hash_t operator()(const StringViewLower& value) const
|
||||
{
|
||||
constexpr BAN::hash_t FNV_offset_basis = 0x811c9dc5;
|
||||
constexpr BAN::hash_t FNV_prime = 0x01000193;
|
||||
|
||||
BAN::hash_t hash = FNV_offset_basis;
|
||||
for (size_t i = 0; i < value.value.size(); i++)
|
||||
{
|
||||
hash *= FNV_prime;
|
||||
hash ^= (uint8_t)tolower(value.value[i]);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
static BAN::UniqPtr<KeyboardLayout> s_instance;
|
||||
|
||||
BAN::ErrorOr<void> KeyboardLayout::initialize()
|
||||
{
|
||||
ASSERT(!s_instance);
|
||||
s_instance = TRY(BAN::UniqPtr<KeyboardLayout>::create());
|
||||
return {};
|
||||
}
|
||||
|
||||
KeyboardLayout& KeyboardLayout::get()
|
||||
{
|
||||
ASSERT(s_instance);
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
KeyboardLayout::KeyboardLayout()
|
||||
{
|
||||
for (auto& key : m_keycode_to_key_normal)
|
||||
key = Key::None;
|
||||
for (auto& key : m_keycode_to_key_shift)
|
||||
key = Key::None;
|
||||
for (auto& key : m_keycode_to_key_altgr)
|
||||
key = Key::None;
|
||||
}
|
||||
|
||||
KeyEvent KeyboardLayout::key_event_from_raw(RawKeyEvent event)
|
||||
{
|
||||
KeyEvent result;
|
||||
result.modifier = event.modifier;
|
||||
if (result.shift())
|
||||
result.key = m_keycode_to_key_shift[event.keycode];
|
||||
else if (result.ralt())
|
||||
result.key = m_keycode_to_key_altgr[event.keycode];
|
||||
else
|
||||
result.key = m_keycode_to_key_normal[event.keycode];
|
||||
return result;
|
||||
}
|
||||
|
||||
static BAN::Optional<uint8_t> parse_keycode(BAN::StringView str)
|
||||
{
|
||||
if (str.size() > 3)
|
||||
return {};
|
||||
uint16_t keycode = 0;
|
||||
for (char c : str)
|
||||
{
|
||||
if (!isdigit(c))
|
||||
return {};
|
||||
keycode = (keycode * 10) + (c - '0');
|
||||
}
|
||||
if (keycode >= 0xFF)
|
||||
return {};
|
||||
return keycode;
|
||||
}
|
||||
|
||||
static BAN::HashMap<StringViewLower, Key, StringViewLowerHash> s_name_to_key;
|
||||
static BAN::ErrorOr<void> initialize_name_to_key();
|
||||
|
||||
static BAN::Optional<Key> parse_key(BAN::StringView name)
|
||||
{
|
||||
if (s_name_to_key.contains(name))
|
||||
return s_name_to_key[name];
|
||||
return {};
|
||||
}
|
||||
|
||||
static BAN::ErrorOr<BAN::Vector<BAN::String>> load_keymap_lines_and_parse_includes(BAN::StringView path)
|
||||
{
|
||||
BAN::String file_data;
|
||||
BAN::String canonical_path;
|
||||
|
||||
#if __is_kernel
|
||||
{
|
||||
auto file = TRY(Kernel::VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, path, 0));
|
||||
TRY(file_data.resize(file.inode->size()));
|
||||
TRY(file.inode->read(0, BAN::ByteSpan { reinterpret_cast<uint8_t*>(file_data.data()), file_data.size() }));
|
||||
canonical_path = file.canonical_path;
|
||||
}
|
||||
#else
|
||||
{
|
||||
char null_path[PATH_MAX];
|
||||
strncpy(null_path, path.data(), path.size());
|
||||
null_path[path.size()] = '\0';
|
||||
|
||||
struct stat st;
|
||||
if (stat(null_path, &st) == -1)
|
||||
return BAN::Error::from_errno(errno);
|
||||
TRY(file_data.resize(st.st_size));
|
||||
int fd = open(null_path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
return BAN::Error::from_errno(errno);
|
||||
ssize_t nread = read(fd, file_data.data(), st.st_size);
|
||||
close(fd);
|
||||
if (nread != st.st_size)
|
||||
return BAN::Error::from_errno(errno);
|
||||
MUST(canonical_path.append(path));
|
||||
}
|
||||
#endif
|
||||
|
||||
BAN::Vector<BAN::String> result;
|
||||
|
||||
auto lines = TRY(file_data.sv().split('\n'));
|
||||
for (auto line : lines)
|
||||
{
|
||||
auto parts = TRY(line.split([](char c) -> bool { return isspace(c); }));
|
||||
if (parts.empty() || parts.front().front() == '#')
|
||||
continue;
|
||||
|
||||
if (parts.front() == "include"sv)
|
||||
{
|
||||
if (parts.size() != 2)
|
||||
{
|
||||
dprintln("Invalid modifier instruction in keymap '{}'", line);
|
||||
dprintln(" format: include \"PATH\"");
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
if (parts[1].size() < 2 || parts[1].front() != '"' || parts[1].back() != '"')
|
||||
{
|
||||
dprintln("Invalid modifier instruction in keymap '{}'", line);
|
||||
dprintln(" format: include \"PATH\"");
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
parts[1] = parts[1].substring(1, parts[1].size() - 2);
|
||||
|
||||
BAN::String include_path;
|
||||
TRY(include_path.append(canonical_path));
|
||||
ASSERT(include_path.sv().contains('/'));
|
||||
while (include_path.back() != '/')
|
||||
include_path.pop_back();
|
||||
TRY(include_path.append(parts[1]));
|
||||
|
||||
auto new_lines = TRY(load_keymap_lines_and_parse_includes(include_path));
|
||||
TRY(result.reserve(result.size() + new_lines.size()));
|
||||
for (auto& line : new_lines)
|
||||
TRY(result.push_back(BAN::move(line)));
|
||||
}
|
||||
else
|
||||
{
|
||||
BAN::String line_str;
|
||||
TRY(line_str.append(line));
|
||||
TRY(result.push_back(BAN::move(line_str)));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<void> KeyboardLayout::load_from_file(BAN::StringView path)
|
||||
{
|
||||
if (s_name_to_key.empty())
|
||||
TRY(initialize_name_to_key());
|
||||
|
||||
auto new_layout = TRY(BAN::UniqPtr<KeyboardLayout>::create());
|
||||
|
||||
bool shift_is_mod = false;
|
||||
bool altgr_is_mod = false;
|
||||
|
||||
auto lines = TRY(load_keymap_lines_and_parse_includes(path));
|
||||
for (const auto& line : lines)
|
||||
{
|
||||
auto parts = TRY(line.sv().split([](char c) -> bool { return isspace(c); }));
|
||||
if (parts.empty() || parts.front().front() == '#')
|
||||
continue;
|
||||
|
||||
if (parts.size() == 1)
|
||||
{
|
||||
dprintln("Invalid line in keymap '{}'", line);
|
||||
dprintln(" format: KEYCODE KEY [MODIFIER=KEY]...");
|
||||
dprintln(" format: mod MODIFIER");
|
||||
dprintln(" format: include \"PATH\"");
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
if (parts.front() == "mod"sv)
|
||||
{
|
||||
if (parts.size() != 2)
|
||||
{
|
||||
dprintln("Invalid modifier instruction in keymap '{}'", line);
|
||||
dprintln(" format: mod MODIFIER");
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
if (parts[1] == "shift"sv)
|
||||
shift_is_mod = true;
|
||||
else if (parts[1] == "altgr"sv)
|
||||
altgr_is_mod = true;
|
||||
else
|
||||
{
|
||||
dprintln("Unrecognized modifier '{}'", parts[1]);
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
auto keycode = parse_keycode(parts.front());
|
||||
if (!keycode.has_value())
|
||||
{
|
||||
dprintln("Invalid keycode '{}', keycode must number between [0, 0xFF[", parts.front());
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
auto default_key = parse_key(parts[1]);
|
||||
if (!default_key.has_value())
|
||||
{
|
||||
dprintln("Unrecognized key '{}'", parts[1]);
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
new_layout->m_keycode_to_key_normal[*keycode] = *default_key;
|
||||
new_layout->m_keycode_to_key_shift[*keycode] = *default_key;
|
||||
new_layout->m_keycode_to_key_altgr[*keycode] = *default_key;
|
||||
|
||||
for (size_t i = 2; i < parts.size(); i++)
|
||||
{
|
||||
auto pair = TRY(parts[i].split('='));
|
||||
if (pair.size() != 2)
|
||||
{
|
||||
dprintln("Invalid modifier format '{}', modifier format: MODIFIRER=KEY", parts[i]);
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
auto key = parse_key(pair.back());
|
||||
if (!key.has_value())
|
||||
{
|
||||
dprintln("Unrecognized key '{}'", pair.back());
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
|
||||
if (shift_is_mod && pair.front() == "shift"sv)
|
||||
new_layout->m_keycode_to_key_shift[*keycode] = *key;
|
||||
else if (altgr_is_mod && pair.front() == "altgr"sv)
|
||||
new_layout->m_keycode_to_key_altgr[*keycode] = *key;
|
||||
else
|
||||
{
|
||||
dprintln("Unrecognized modifier '{}'", pair.front());
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < new_layout->m_keycode_to_key_normal.size(); i++)
|
||||
if (new_layout->m_keycode_to_key_normal[i] != Key::None)
|
||||
m_keycode_to_key_normal[i] = new_layout->m_keycode_to_key_normal[i];
|
||||
|
||||
for (size_t i = 0; i < new_layout->m_keycode_to_key_shift.size(); i++)
|
||||
if (new_layout->m_keycode_to_key_shift[i] != Key::None)
|
||||
m_keycode_to_key_shift[i] = new_layout->m_keycode_to_key_shift[i];
|
||||
|
||||
for (size_t i = 0; i < new_layout->m_keycode_to_key_altgr.size(); i++)
|
||||
if (new_layout->m_keycode_to_key_altgr[i] != Key::None)
|
||||
m_keycode_to_key_altgr[i] = new_layout->m_keycode_to_key_altgr[i];
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstack-usage="
|
||||
static BAN::ErrorOr<void> initialize_name_to_key()
|
||||
{
|
||||
ASSERT(s_name_to_key.empty());
|
||||
TRY(s_name_to_key.insert("A_Ring"sv, Key::A_Ring));
|
||||
TRY(s_name_to_key.insert("A_Umlaut"sv, Key::A_Umlaut));
|
||||
TRY(s_name_to_key.insert("A"sv, Key::A));
|
||||
TRY(s_name_to_key.insert("Acute"sv, Key::Acute));
|
||||
TRY(s_name_to_key.insert("AltGr"sv, Key::AltGr));
|
||||
TRY(s_name_to_key.insert("Ampersand"sv, Key::Ampersand));
|
||||
TRY(s_name_to_key.insert("ArrowDown"sv, Key::ArrowDown));
|
||||
TRY(s_name_to_key.insert("ArrowLeft"sv, Key::ArrowLeft));
|
||||
TRY(s_name_to_key.insert("ArrowRight"sv, Key::ArrowRight));
|
||||
TRY(s_name_to_key.insert("ArrowUp"sv, Key::ArrowUp));
|
||||
TRY(s_name_to_key.insert("Asterix"sv, Key::Asterix));
|
||||
TRY(s_name_to_key.insert("AtSign"sv, Key::AtSign));
|
||||
TRY(s_name_to_key.insert("B"sv, Key::B));
|
||||
TRY(s_name_to_key.insert("BackSlash"sv, Key::BackSlash));
|
||||
TRY(s_name_to_key.insert("Backspace"sv, Key::Backspace));
|
||||
TRY(s_name_to_key.insert("BackTick"sv, Key::BackTick));
|
||||
TRY(s_name_to_key.insert("BrokenBar"sv, Key::BrokenBar));
|
||||
TRY(s_name_to_key.insert("C"sv, Key::C));
|
||||
TRY(s_name_to_key.insert("Calculator"sv, Key::Calculator));
|
||||
TRY(s_name_to_key.insert("CapsLock"sv, Key::CapsLock));
|
||||
TRY(s_name_to_key.insert("Caret"sv, Key::Caret));
|
||||
TRY(s_name_to_key.insert("Cedilla"sv, Key::Cedilla));
|
||||
TRY(s_name_to_key.insert("CloseCurlyBracket"sv, Key::CloseCurlyBracket));
|
||||
TRY(s_name_to_key.insert("CloseParenthesis"sv, Key::CloseParenthesis));
|
||||
TRY(s_name_to_key.insert("CloseSquareBracket"sv, Key::CloseSquareBracket));
|
||||
TRY(s_name_to_key.insert("Colon"sv, Key::Colon));
|
||||
TRY(s_name_to_key.insert("Comma"sv, Key::Comma));
|
||||
TRY(s_name_to_key.insert("Currency"sv, Key::Currency));
|
||||
TRY(s_name_to_key.insert("D"sv, Key::D));
|
||||
TRY(s_name_to_key.insert("Delete"sv, Key::Delete));
|
||||
TRY(s_name_to_key.insert("Dollar"sv, Key::Dollar));
|
||||
TRY(s_name_to_key.insert("DoubleQuote"sv, Key::DoubleQuote));
|
||||
TRY(s_name_to_key.insert("E"sv, Key::E));
|
||||
TRY(s_name_to_key.insert("End"sv, Key::End));
|
||||
TRY(s_name_to_key.insert("Enter"sv, Key::Enter));
|
||||
TRY(s_name_to_key.insert("Equals"sv, Key::Equals));
|
||||
TRY(s_name_to_key.insert("Escape"sv, Key::Escape));
|
||||
TRY(s_name_to_key.insert("Euro"sv, Key::Euro));
|
||||
TRY(s_name_to_key.insert("Exclamation"sv, Key::ExclamationMark));
|
||||
TRY(s_name_to_key.insert("ExclamationMark"sv, Key::ExclamationMark));
|
||||
TRY(s_name_to_key.insert("F"sv, Key::F));
|
||||
TRY(s_name_to_key.insert("F1"sv, Key::F1));
|
||||
TRY(s_name_to_key.insert("F10"sv, Key::F10));
|
||||
TRY(s_name_to_key.insert("F11"sv, Key::F11));
|
||||
TRY(s_name_to_key.insert("F12"sv, Key::F12));
|
||||
TRY(s_name_to_key.insert("F2"sv, Key::F2));
|
||||
TRY(s_name_to_key.insert("F3"sv, Key::F3));
|
||||
TRY(s_name_to_key.insert("F4"sv, Key::F4));
|
||||
TRY(s_name_to_key.insert("F5"sv, Key::F5));
|
||||
TRY(s_name_to_key.insert("F6"sv, Key::F6));
|
||||
TRY(s_name_to_key.insert("F7"sv, Key::F7));
|
||||
TRY(s_name_to_key.insert("F8"sv, Key::F8));
|
||||
TRY(s_name_to_key.insert("F9"sv, Key::F9));
|
||||
TRY(s_name_to_key.insert("G"sv, Key::G));
|
||||
TRY(s_name_to_key.insert("GreaterThan"sv, Key::GreaterThan));
|
||||
TRY(s_name_to_key.insert("H"sv, Key::H));
|
||||
TRY(s_name_to_key.insert("Half"sv, Key::Half));
|
||||
TRY(s_name_to_key.insert("Hashtag"sv, Key::Hashtag));
|
||||
TRY(s_name_to_key.insert("Home"sv, Key::Home));
|
||||
TRY(s_name_to_key.insert("Hyphen"sv, Key::Hyphen));
|
||||
TRY(s_name_to_key.insert("I"sv, Key::I));
|
||||
TRY(s_name_to_key.insert("Insert"sv, Key::Insert));
|
||||
TRY(s_name_to_key.insert("J"sv, Key::J));
|
||||
TRY(s_name_to_key.insert("K"sv, Key::K));
|
||||
TRY(s_name_to_key.insert("Key0"sv, Key::_0));
|
||||
TRY(s_name_to_key.insert("Key1"sv, Key::_1));
|
||||
TRY(s_name_to_key.insert("Key2"sv, Key::_2));
|
||||
TRY(s_name_to_key.insert("Key3"sv, Key::_3));
|
||||
TRY(s_name_to_key.insert("Key4"sv, Key::_4));
|
||||
TRY(s_name_to_key.insert("Key5"sv, Key::_5));
|
||||
TRY(s_name_to_key.insert("Key6"sv, Key::_6));
|
||||
TRY(s_name_to_key.insert("Key7"sv, Key::_7));
|
||||
TRY(s_name_to_key.insert("Key8"sv, Key::_8));
|
||||
TRY(s_name_to_key.insert("Key9"sv, Key::_9));
|
||||
TRY(s_name_to_key.insert("L"sv, Key::L));
|
||||
TRY(s_name_to_key.insert("LAlt"sv, Key::LeftAlt));
|
||||
TRY(s_name_to_key.insert("LControl"sv, Key::LeftCtrl));
|
||||
TRY(s_name_to_key.insert("LeftAlt"sv, Key::LeftAlt));
|
||||
TRY(s_name_to_key.insert("LeftControl"sv, Key::LeftCtrl));
|
||||
TRY(s_name_to_key.insert("LeftShift"sv, Key::LeftShift));
|
||||
TRY(s_name_to_key.insert("LessThan"sv, Key::LessThan));
|
||||
TRY(s_name_to_key.insert("LShift"sv, Key::LeftShift));
|
||||
TRY(s_name_to_key.insert("M"sv, Key::M));
|
||||
TRY(s_name_to_key.insert("MediaNext"sv, Key::MediaNext));
|
||||
TRY(s_name_to_key.insert("MediaPlayPause"sv, Key::MediaPlayPause));
|
||||
TRY(s_name_to_key.insert("MediaPrevious"sv, Key::MediaPrevious));
|
||||
TRY(s_name_to_key.insert("MediaStop"sv, Key::MediaStop));
|
||||
TRY(s_name_to_key.insert("N"sv, Key::N));
|
||||
TRY(s_name_to_key.insert("Negation"sv, Key::Negation));
|
||||
TRY(s_name_to_key.insert("None"sv, Key::None));
|
||||
TRY(s_name_to_key.insert("NumLock"sv, Key::NumLock));
|
||||
TRY(s_name_to_key.insert("Numpad0"sv, Key::Numpad0));
|
||||
TRY(s_name_to_key.insert("Numpad1"sv, Key::Numpad1));
|
||||
TRY(s_name_to_key.insert("Numpad2"sv, Key::Numpad2));
|
||||
TRY(s_name_to_key.insert("Numpad3"sv, Key::Numpad3));
|
||||
TRY(s_name_to_key.insert("Numpad4"sv, Key::Numpad4));
|
||||
TRY(s_name_to_key.insert("Numpad5"sv, Key::Numpad5));
|
||||
TRY(s_name_to_key.insert("Numpad6"sv, Key::Numpad6));
|
||||
TRY(s_name_to_key.insert("Numpad7"sv, Key::Numpad7));
|
||||
TRY(s_name_to_key.insert("Numpad8"sv, Key::Numpad8));
|
||||
TRY(s_name_to_key.insert("Numpad9"sv, Key::Numpad9));
|
||||
TRY(s_name_to_key.insert("NumpadDecimal"sv, Key::NumpadDecimal));
|
||||
TRY(s_name_to_key.insert("NumpadDivide"sv, Key::NumpadDivide));
|
||||
TRY(s_name_to_key.insert("NumpadEnter"sv, Key::NumpadEnter));
|
||||
TRY(s_name_to_key.insert("NumpadMinus"sv, Key::NumpadMinus));
|
||||
TRY(s_name_to_key.insert("NumpadMultiply"sv, Key::NumpadMultiply));
|
||||
TRY(s_name_to_key.insert("NumpadPlus"sv, Key::NumpadPlus));
|
||||
TRY(s_name_to_key.insert("O_Umlaut"sv, Key::O_Umlaut));
|
||||
TRY(s_name_to_key.insert("O"sv, Key::O));
|
||||
TRY(s_name_to_key.insert("OpenCurlyBracket"sv, Key::OpenCurlyBracket));
|
||||
TRY(s_name_to_key.insert("OpenParenthesis"sv, Key::OpenParenthesis));
|
||||
TRY(s_name_to_key.insert("OpenSquareBracket"sv, Key::OpenSquareBracket));
|
||||
TRY(s_name_to_key.insert("P"sv, Key::P));
|
||||
TRY(s_name_to_key.insert("PageDown"sv, Key::PageDown));
|
||||
TRY(s_name_to_key.insert("PageUp"sv, Key::PageUp));
|
||||
TRY(s_name_to_key.insert("Percent"sv, Key::Percent));
|
||||
TRY(s_name_to_key.insert("Period"sv, Key::Period));
|
||||
TRY(s_name_to_key.insert("Pipe"sv, Key::Pipe));
|
||||
TRY(s_name_to_key.insert("Plus"sv, Key::Plus));
|
||||
TRY(s_name_to_key.insert("Pound"sv, Key::Pound));
|
||||
TRY(s_name_to_key.insert("PrintScreen"sv, Key::PrintScreen));
|
||||
TRY(s_name_to_key.insert("Q"sv, Key::Q));
|
||||
TRY(s_name_to_key.insert("Question"sv, Key::QuestionMark));
|
||||
TRY(s_name_to_key.insert("QuestionMark"sv, Key::QuestionMark));
|
||||
TRY(s_name_to_key.insert("R"sv, Key::R));
|
||||
TRY(s_name_to_key.insert("RAlt"sv, Key::RightAlt));
|
||||
TRY(s_name_to_key.insert("RControl"sv, Key::RightCtrl));
|
||||
TRY(s_name_to_key.insert("RightAlt"sv, Key::RightAlt));
|
||||
TRY(s_name_to_key.insert("RightControl"sv, Key::RightCtrl));
|
||||
TRY(s_name_to_key.insert("RightShift"sv, Key::RightShift));
|
||||
TRY(s_name_to_key.insert("RShift"sv, Key::RightShift));
|
||||
TRY(s_name_to_key.insert("S"sv, Key::S));
|
||||
TRY(s_name_to_key.insert("ScrollLock"sv, Key::ScrollLock));
|
||||
TRY(s_name_to_key.insert("Section"sv, Key::Section));
|
||||
TRY(s_name_to_key.insert("Semicolon"sv, Key::Semicolon));
|
||||
TRY(s_name_to_key.insert("SingleQuote"sv, Key::SingleQuote));
|
||||
TRY(s_name_to_key.insert("Slash"sv, Key::Slash));
|
||||
TRY(s_name_to_key.insert("Space"sv, Key::Space));
|
||||
TRY(s_name_to_key.insert("Super"sv, Key::Super));
|
||||
TRY(s_name_to_key.insert("T"sv, Key::T));
|
||||
TRY(s_name_to_key.insert("Tab"sv, Key::Tab));
|
||||
TRY(s_name_to_key.insert("Tilde"sv, Key::Tilde));
|
||||
TRY(s_name_to_key.insert("TwoDots"sv, Key::TwoDots));
|
||||
TRY(s_name_to_key.insert("U"sv, Key::U));
|
||||
TRY(s_name_to_key.insert("Underscore"sv, Key::Underscore));
|
||||
TRY(s_name_to_key.insert("V"sv, Key::V));
|
||||
TRY(s_name_to_key.insert("VolumeDown"sv, Key::VolumeDown));
|
||||
TRY(s_name_to_key.insert("VolumeMute"sv, Key::VolumeMute));
|
||||
TRY(s_name_to_key.insert("VolumeUp"sv, Key::VolumeUp));
|
||||
TRY(s_name_to_key.insert("W"sv, Key::W));
|
||||
TRY(s_name_to_key.insert("X"sv, Key::X));
|
||||
TRY(s_name_to_key.insert("Y"sv, Key::Y));
|
||||
TRY(s_name_to_key.insert("Z"sv, Key::Z));
|
||||
return {};
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
}
|
|
@ -18,5 +18,5 @@ set(SOURCES
|
|||
add_executable(banan_os-bootloader-installer ${SOURCES})
|
||||
target_compile_options(banan_os-bootloader-installer PRIVATE -O2 -std=c++20)
|
||||
target_compile_definitions(banan_os-bootloader-installer PRIVATE __arch=${BANAN_ARCH})
|
||||
target_include_directories(banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../LibELF/include)
|
||||
target_include_directories(banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../userspace/libraries/LibELF/include)
|
||||
target_include_directories(banan_os-bootloader-installer PRIVATE ${CMAKE_SOURCE_DIR}/../../kernel/include)
|
||||
|
|
|
@ -1,13 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(kernel CXX C ASM)
|
||||
|
||||
if("${BANAN_ARCH}" STREQUAL "x86_64")
|
||||
set(ELF_FORMAT elf64-x86-64)
|
||||
elseif("${BANAN_ARCH}" STREQUAL "i686")
|
||||
set(ELF_FORMAT elf32-i386)
|
||||
endif()
|
||||
|
||||
set(KERNEL_SOURCES
|
||||
font/prefs.psf.o
|
||||
kernel/ACPI/ACPI.cpp
|
||||
|
@ -66,6 +56,7 @@ set(KERNEL_SOURCES
|
|||
kernel/Networking/E1000/E1000E.cpp
|
||||
kernel/Networking/IPv4Layer.cpp
|
||||
kernel/Networking/NetworkInterface.cpp
|
||||
kernel/Networking/NetworkLayer.cpp
|
||||
kernel/Networking/NetworkManager.cpp
|
||||
kernel/Networking/NetworkSocket.cpp
|
||||
kernel/Networking/TCPSocket.cpp
|
||||
|
@ -105,7 +96,7 @@ set(KERNEL_SOURCES
|
|||
icxxabi.cpp
|
||||
)
|
||||
|
||||
#set(ENABLE_KERNEL_UBSAN True)
|
||||
set(ENABLE_KERNEL_UBSAN False)
|
||||
|
||||
if(ENABLE_KERNEL_UBSAN)
|
||||
set(KERNEL_SOURCES ${KERNEL_SOURCES} ubsan.cpp)
|
||||
|
@ -148,22 +139,21 @@ set(KLIBC_SOURCES
|
|||
)
|
||||
|
||||
set(LIBELF_SOURCES
|
||||
../LibELF/LibELF/LoadableELF.cpp
|
||||
../userspace/libraries/LibELF/LibELF/LoadableELF.cpp
|
||||
)
|
||||
|
||||
set(LIBFONT_SOURCES
|
||||
../LibFont/Font.cpp
|
||||
../LibFont/PSF.cpp
|
||||
../userspace/libraries/LibFont/Font.cpp
|
||||
../userspace/libraries/LibFont/PSF.cpp
|
||||
)
|
||||
|
||||
set(LIBINPUT_SOURCE
|
||||
../LibInput/KeyboardLayout.cpp
|
||||
../LibInput/KeyEvent.cpp
|
||||
../userspace/libraries/LibInput/KeyboardLayout.cpp
|
||||
../userspace/libraries/LibInput/KeyEvent.cpp
|
||||
)
|
||||
|
||||
set(KERNEL_SOURCES
|
||||
${KERNEL_SOURCES}
|
||||
${LAI_SOURCES}
|
||||
${BAN_SOURCES}
|
||||
${KLIBC_SOURCES}
|
||||
${LIBELF_SOURCES}
|
||||
|
@ -172,7 +162,6 @@ set(KERNEL_SOURCES
|
|||
)
|
||||
|
||||
add_executable(kernel ${KERNEL_SOURCES})
|
||||
add_dependencies(kernel headers)
|
||||
|
||||
target_compile_definitions(kernel PUBLIC __is_kernel)
|
||||
target_compile_definitions(kernel PUBLIC __arch=${BANAN_ARCH})
|
||||
|
@ -199,18 +188,6 @@ endif()
|
|||
|
||||
target_link_options(kernel PUBLIC -ffreestanding -nostdlib)
|
||||
|
||||
set_source_files_properties(${LAI_SOURCES} PROPERTIES COMPILE_FLAGS -Wno-stack-usage)
|
||||
|
||||
add_custom_target(kernel-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_custom_target(kernel-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/kernel ${BANAN_BOOT}/banan-os.kernel
|
||||
DEPENDS kernel
|
||||
)
|
||||
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtbegin.o OUTPUT_VARIABLE CRTBEGIN OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=crtend.o OUTPUT_VARIABLE CRTEND OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
|
@ -227,6 +204,22 @@ add_custom_command(
|
|||
# COMMAND x86_64-banan_os-strip ${CMAKE_CURRENT_BINARY_DIR}/kernel
|
||||
#)
|
||||
|
||||
banan_include_headers(kernel ban)
|
||||
banan_include_headers(kernel libc)
|
||||
banan_include_headers(kernel libfont)
|
||||
banan_include_headers(kernel libelf)
|
||||
banan_include_headers(kernel libinput)
|
||||
|
||||
banan_install_headers(kernel)
|
||||
set_target_properties(kernel PROPERTIES OUTPUT_NAME banan-os.kernel)
|
||||
install(TARGETS kernel DESTINATION ${BANAN_BOOT})
|
||||
|
||||
if("${BANAN_ARCH}" STREQUAL "x86_64")
|
||||
set(ELF_FORMAT elf64-x86-64)
|
||||
elseif("${BANAN_ARCH}" STREQUAL "i686")
|
||||
set(ELF_FORMAT elf32-i386)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT font/prefs.psf.o
|
||||
COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && objcopy -O ${ELF_FORMAT} -B i386 -I binary font/prefs.psf ${CMAKE_CURRENT_BINARY_DIR}/font/prefs.psf.o
|
||||
|
|
|
@ -48,7 +48,7 @@ namespace Kernel::ACPI::AML
|
|||
AML_ERROR("IndexOp index is out of buffer bounds");
|
||||
return ParseResult::Failure;
|
||||
}
|
||||
auto buffer_field = MUST(BAN::RefPtr<BufferField>::create(NameSeg(""sv), buffer, index.value() * 8, 8));
|
||||
auto buffer_field = MUST(BAN::RefPtr<BufferField>::create(NameSeg(""_sv), buffer, index.value() * 8, 8));
|
||||
result = MUST(BAN::RefPtr<AML::Reference>::create(buffer_field));
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ namespace Kernel::ACPI::AML
|
|||
static BAN::RefPtr<Integer> Ones;
|
||||
};
|
||||
|
||||
const bool constant;
|
||||
uint64_t value;
|
||||
const bool constant;
|
||||
|
||||
Integer(uint64_t value, bool constant = false)
|
||||
: Node(Node::Type::Integer)
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Kernel::ACPI::AML
|
|||
|
||||
[[nodiscard]] BAN::Optional<uint64_t> as_integer();
|
||||
[[nodiscard]] virtual BAN::RefPtr<AML::Node> evaluate() { AML_TODO("evaluate, type {}", static_cast<uint8_t>(type)); return nullptr; }
|
||||
[[nodiscard]] virtual bool store(BAN::RefPtr<AML::Node> source) { AML_TODO("store, type {}", static_cast<uint8_t>(type)); return false; }
|
||||
[[nodiscard]] virtual bool store(BAN::RefPtr<AML::Node>) { AML_TODO("store, type {}", static_cast<uint8_t>(type)); return false; }
|
||||
|
||||
virtual void debug_print(int indent) const = 0;
|
||||
};
|
||||
|
|
|
@ -41,20 +41,20 @@ namespace Kernel::ACPI::AML
|
|||
switch (object->type)
|
||||
{
|
||||
case AML::Node::Type::Device:
|
||||
object_type_sv = "Device"sv;
|
||||
object_type_sv = "Device"_sv;
|
||||
object_name_sv = static_cast<AML::Device*>(object.ptr())->name.sv();
|
||||
break;
|
||||
case AML::Node::Type::Processor:
|
||||
object_type_sv = "Processor"sv;
|
||||
object_type_sv = "Processor"_sv;
|
||||
object_name_sv = static_cast<AML::Processor*>(object.ptr())->name.sv();
|
||||
break;
|
||||
case AML::Node::Type::ThermalZone:
|
||||
object_type_sv = "ThermalZone"sv;
|
||||
object_type_sv = "ThermalZone"_sv;
|
||||
object_name_sv = static_cast<AML::ThermalZone*>(object.ptr())->name.sv();
|
||||
break;
|
||||
default:
|
||||
object_type_sv = "Unknown"sv;
|
||||
object_name_sv = "????"sv;
|
||||
object_type_sv = "Unknown"_sv;
|
||||
object_name_sv = "????"_sv;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ namespace Kernel::ACPI::AML
|
|||
PackageElement(BAN::RefPtr<AML::Package> parent)
|
||||
: Node(Node::Type::PackageElement)
|
||||
, parent(parent)
|
||||
, unresolved_name(unresolved_name)
|
||||
{
|
||||
resolved = false;
|
||||
initialized = false;
|
||||
|
|
|
@ -82,18 +82,18 @@ namespace Kernel::ACPI::AML
|
|||
BAN::StringView region_space_name;
|
||||
switch (region_space)
|
||||
{
|
||||
case RegionSpace::SystemMemory: region_space_name = "SystemMemory"sv; break;
|
||||
case RegionSpace::SystemIO: region_space_name = "SystemIO"sv; break;
|
||||
case RegionSpace::PCIConfig: region_space_name = "PCIConfig"sv; break;
|
||||
case RegionSpace::EmbeddedController: region_space_name = "EmbeddedController"sv; break;
|
||||
case RegionSpace::SMBus: region_space_name = "SMBus"sv; break;
|
||||
case RegionSpace::SystemCMOS: region_space_name = "SystemCMOS"sv; break;
|
||||
case RegionSpace::PCIBarTarget: region_space_name = "PCIBarTarget"sv; break;
|
||||
case RegionSpace::IPMI: region_space_name = "IPMI"sv; break;
|
||||
case RegionSpace::GeneralPurposeIO: region_space_name = "GeneralPurposeIO"sv; break;
|
||||
case RegionSpace::GenericSerialBus: region_space_name = "GenericSerialBus"sv; break;
|
||||
case RegionSpace::PlatformCommunicationChannel: region_space_name = "PlatformCommunicationChannel"sv; break;
|
||||
default: region_space_name = "Unknown"sv; break;
|
||||
case RegionSpace::SystemMemory: region_space_name = "SystemMemory"_sv; break;
|
||||
case RegionSpace::SystemIO: region_space_name = "SystemIO"_sv; break;
|
||||
case RegionSpace::PCIConfig: region_space_name = "PCIConfig"_sv; break;
|
||||
case RegionSpace::EmbeddedController: region_space_name = "EmbeddedController"_sv; break;
|
||||
case RegionSpace::SMBus: region_space_name = "SMBus"_sv; break;
|
||||
case RegionSpace::SystemCMOS: region_space_name = "SystemCMOS"_sv; break;
|
||||
case RegionSpace::PCIBarTarget: region_space_name = "PCIBarTarget"_sv; break;
|
||||
case RegionSpace::IPMI: region_space_name = "IPMI"_sv; break;
|
||||
case RegionSpace::GeneralPurposeIO: region_space_name = "GeneralPurposeIO"_sv; break;
|
||||
case RegionSpace::GenericSerialBus: region_space_name = "GenericSerialBus"_sv; break;
|
||||
case RegionSpace::PlatformCommunicationChannel: region_space_name = "PlatformCommunicationChannel"_sv; break;
|
||||
default: region_space_name = "Unknown"_sv; break;
|
||||
}
|
||||
AML_DEBUG_PRINT_INDENT(indent);
|
||||
AML_DEBUG_PRINT("OperationRegion(");
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Kernel
|
|||
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { return "debug"sv; }
|
||||
virtual BAN::StringView name() const override { return "debug"_sv; }
|
||||
|
||||
protected:
|
||||
DebugDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace Kernel
|
|||
virtual bool is_partition() const { return false; }
|
||||
virtual bool is_storage_device() const { return false; }
|
||||
|
||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t) { return BAN::Error::from_errno(EINVAL); }
|
||||
virtual BAN::ErrorOr<BAN::UniqPtr<MemoryRegion>> mmap_region(PageTable&, off_t offset, size_t len, AddressRange, MemoryRegion::Type, PageTable::flags_t) { (void)offset; (void)len; return BAN::Error::from_errno(EINVAL); }
|
||||
|
||||
virtual dev_t rdev() const override = 0;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Kernel
|
|||
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { return "null"sv; }
|
||||
virtual BAN::StringView name() const override { return "null"_sv; }
|
||||
|
||||
protected:
|
||||
NullDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Kernel
|
|||
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { return "zero"sv; }
|
||||
virtual BAN::StringView name() const override { return "zero"_sv; }
|
||||
|
||||
protected:
|
||||
ZeroDevice(mode_t mode, uid_t uid, gid_t gid, dev_t rdev)
|
||||
|
|
|
@ -53,12 +53,12 @@ namespace Kernel
|
|||
uint32_t first_fat_sector() const { return m_bpb.reserved_sector_count; }
|
||||
|
||||
private:
|
||||
const FAT::BPB m_bpb;
|
||||
const Type m_type;
|
||||
|
||||
BAN::RefPtr<BlockDevice> m_block_device;
|
||||
BAN::RefPtr<FATInode> m_root_inode;
|
||||
|
||||
const FAT::BPB m_bpb;
|
||||
const Type m_type;
|
||||
|
||||
BAN::HashMap<ino_t, BAN::WeakPtr<FATInode>> m_inode_cache;
|
||||
|
||||
BAN::Vector<uint8_t> m_fat_two_sector_buffer;
|
||||
|
|
|
@ -155,7 +155,7 @@ namespace Kernel
|
|||
virtual bool can_write_impl() const = 0;
|
||||
virtual bool has_error_impl() const = 0;
|
||||
|
||||
virtual BAN::ErrorOr<long> ioctl_impl(int request, void* arg) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
virtual BAN::ErrorOr<long> ioctl_impl(int, void*) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
|
||||
protected:
|
||||
mutable PriorityMutex m_mutex;
|
||||
|
|
|
@ -14,9 +14,9 @@ namespace Kernel
|
|||
mode_t mode { 0 };
|
||||
uid_t uid { 0 };
|
||||
gid_t gid { 0 };
|
||||
timespec atime { 0 };
|
||||
timespec ctime { 0 };
|
||||
timespec mtime { 0 };
|
||||
timespec atime { 0, 0 };
|
||||
timespec ctime { 0, 0 };
|
||||
timespec mtime { 0, 0 };
|
||||
nlink_t nlink { 0 };
|
||||
size_t size { 0 };
|
||||
blkcnt_t blocks { 0 };
|
||||
|
|
|
@ -154,7 +154,7 @@ namespace Kernel
|
|||
#endif
|
||||
TaskStateSegment m_tss;
|
||||
const GDTR m_gdtr {
|
||||
.size = m_gdt.size() * sizeof(SegmentDescriptor) - 1,
|
||||
.size = static_cast<uint16_t>(m_gdt.size() * sizeof(SegmentDescriptor) - 1),
|
||||
.address = reinterpret_cast<uintptr_t>(m_gdt.data())
|
||||
};
|
||||
};
|
||||
|
|
|
@ -72,8 +72,8 @@ namespace Kernel
|
|||
private:
|
||||
BAN::Array<GateDescriptor, 0x100> m_idt;
|
||||
IDTR m_idtr {
|
||||
.size = m_idt.size() * sizeof(GateDescriptor) - 1,
|
||||
.offset = reinterpret_cast<uint64_t>(m_idt.data())
|
||||
.size = static_cast<uint16_t>(m_idt.size() * sizeof(GateDescriptor) - 1),
|
||||
.offset = reinterpret_cast<uintptr_t>(m_idt.data())
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Kernel::Input
|
|||
static BAN::ErrorOr<PS2Mouse*> create(PS2Controller&);
|
||||
virtual void send_initialize() override;
|
||||
|
||||
virtual void command_timedout(uint8_t* command_data, uint8_t command_size) final override {}
|
||||
virtual void command_timedout(uint8_t* command_data, uint8_t command_size) final override { (void)command_data; (void)command_size; }
|
||||
|
||||
virtual void handle_byte(uint8_t) final override;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Kernel
|
|||
|
||||
protected:
|
||||
Interruptable() = default;
|
||||
~Interruptable() {}
|
||||
virtual ~Interruptable() {}
|
||||
|
||||
private:
|
||||
int m_irq { -1 };
|
||||
|
|
|
@ -35,18 +35,6 @@ namespace Kernel
|
|||
NetworkLayer() = default;
|
||||
};
|
||||
|
||||
static uint16_t calculate_internet_checksum(BAN::ConstByteSpan packet, const PseudoHeader& pseudo_header)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
for (size_t i = 0; i < sizeof(pseudo_header) / sizeof(uint16_t); i++)
|
||||
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(&pseudo_header)[i]);
|
||||
for (size_t i = 0; i < packet.size() / sizeof(uint16_t); i++)
|
||||
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(packet.data())[i]);
|
||||
if (packet.size() % 2)
|
||||
checksum += (uint16_t)packet[packet.size() - 1] << 8;
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum >> 16) + (checksum & 0xFFFF);
|
||||
return ~(uint16_t)checksum;
|
||||
}
|
||||
uint16_t calculate_internet_checksum(BAN::ConstByteSpan packet, const PseudoHeader& pseudo_header);
|
||||
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ namespace Kernel
|
|||
BAN::ErrorOr<void> add_packet(BAN::ConstByteSpan);
|
||||
|
||||
bool is_bound() const { return !m_bound_path.empty(); }
|
||||
bool is_bound_to_unused() const { return m_bound_path == "X"sv; }
|
||||
bool is_bound_to_unused() const { return m_bound_path == "X"_sv; }
|
||||
|
||||
bool is_streaming() const;
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace Kernel
|
|||
Debug::dump_stack_trace();
|
||||
}
|
||||
asm volatile("ud2");
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -132,7 +132,7 @@ acpi_release_global_lock:
|
|||
if (!access_type.has_value())
|
||||
return {};
|
||||
|
||||
auto op_region = MUST(BAN::RefPtr<AML::OpRegion>::create(""sv, address_space_id, (uint64_t)address, 0xFFFFFFFF));
|
||||
auto op_region = MUST(BAN::RefPtr<AML::OpRegion>::create(""_sv, address_space_id, (uint64_t)address, 0xFFFFFFFF));
|
||||
|
||||
auto field_rules = AML::FieldRules {
|
||||
.access_type = access_type.value(),
|
||||
|
@ -141,7 +141,7 @@ acpi_release_global_lock:
|
|||
.access_attrib = AML::FieldRules::AccessAttrib::Normal,
|
||||
.access_length = 0
|
||||
};
|
||||
auto field_element = MUST(BAN::RefPtr<AML::FieldElement>::create(""sv, register_bit_offset, register_bit_width, field_rules));
|
||||
auto field_element = MUST(BAN::RefPtr<AML::FieldElement>::create(""_sv, register_bit_offset, register_bit_width, field_rules));
|
||||
field_element->op_region = op_region;
|
||||
|
||||
auto result = field_element->as_integer();
|
||||
|
@ -156,7 +156,7 @@ acpi_release_global_lock:
|
|||
if (!access_type.has_value())
|
||||
return {};
|
||||
|
||||
auto op_region = MUST(BAN::RefPtr<AML::OpRegion>::create(""sv, address_space_id, (uint64_t)address, 0xFFFFFFFF));
|
||||
auto op_region = MUST(BAN::RefPtr<AML::OpRegion>::create(""_sv, address_space_id, (uint64_t)address, 0xFFFFFFFF));
|
||||
|
||||
auto field_rules = AML::FieldRules {
|
||||
.access_type = access_type.value(),
|
||||
|
@ -165,7 +165,7 @@ acpi_release_global_lock:
|
|||
.access_attrib = AML::FieldRules::AccessAttrib::Normal,
|
||||
.access_length = 0
|
||||
};
|
||||
auto field_element = MUST(BAN::RefPtr<AML::FieldElement>::create(""sv, register_bit_offset, register_bit_width, field_rules));
|
||||
auto field_element = MUST(BAN::RefPtr<AML::FieldElement>::create(""_sv, register_bit_offset, register_bit_width, field_rules));
|
||||
field_element->op_region = op_region;
|
||||
|
||||
return field_element->store(MUST(BAN::RefPtr<AML::Integer>::create(value)));
|
||||
|
@ -214,7 +214,7 @@ acpi_release_global_lock:
|
|||
|
||||
{
|
||||
ASSERT(!s_global_lock);
|
||||
const auto* fadt = static_cast<const FADT*>(ACPI::get().get_header("FACP"sv, 0));
|
||||
const auto* fadt = static_cast<const FADT*>(ACPI::get().get_header("FACP"_sv, 0));
|
||||
ASSERT(fadt);
|
||||
|
||||
uintptr_t facs_addr = fadt->firmware_ctrl;
|
||||
|
@ -679,7 +679,7 @@ acpi_release_global_lock:
|
|||
return;
|
||||
|
||||
auto name = path.sv().substring(path.size() - 4);
|
||||
if (name.substring(0, 2) != "_L"sv && name.substring(0, 2) != "_E"sv)
|
||||
if (name.substring(0, 2) != "_L"_sv && name.substring(0, 2) != "_E"_sv)
|
||||
return;
|
||||
|
||||
auto index = hex_sv_to_int(name.substring(2));
|
||||
|
|
|
@ -41,7 +41,7 @@ namespace Kernel::ACPI
|
|||
LockGuard _(m_object_mutex);
|
||||
|
||||
// Base must be non-empty absolute path
|
||||
ASSERT(relative_base.prefix == "\\"sv || relative_base.path.empty());
|
||||
ASSERT(relative_base.prefix == "\\"_sv || relative_base.path.empty());
|
||||
|
||||
// Do absolute path lookup
|
||||
if (!relative_path.prefix.empty() || relative_path.path.size() != 1 || mode == FindMode::ForceAbsolute)
|
||||
|
@ -50,7 +50,7 @@ namespace Kernel::ACPI
|
|||
MUST(absolute_path.push_back('\\'));
|
||||
|
||||
// Resolve root and parent references
|
||||
if (relative_path.prefix == "\\"sv)
|
||||
if (relative_path.prefix == "\\"_sv)
|
||||
;
|
||||
else
|
||||
{
|
||||
|
@ -76,7 +76,7 @@ namespace Kernel::ACPI
|
|||
if (absolute_path.back() == '.')
|
||||
absolute_path.pop_back();
|
||||
|
||||
if (!check_existence || absolute_path == "\\"sv || m_objects.contains(absolute_path))
|
||||
if (!check_existence || absolute_path == "\\"_sv || m_objects.contains(absolute_path))
|
||||
return absolute_path;
|
||||
return {};
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ namespace Kernel::ACPI
|
|||
if (!canonical_path.has_value())
|
||||
return nullptr;
|
||||
|
||||
if (canonical_path->sv() == "\\"sv)
|
||||
if (canonical_path->sv() == "\\"_sv)
|
||||
return this;
|
||||
|
||||
auto it = m_objects.find(canonical_path.value());
|
||||
|
@ -191,28 +191,28 @@ namespace Kernel::ACPI
|
|||
BAN::RefPtr<AML::Namespace> AML::Namespace::create_root_namespace()
|
||||
{
|
||||
ASSERT(!s_root_namespace);
|
||||
s_root_namespace = MUST(BAN::RefPtr<Namespace>::create(NameSeg("\\"sv)));
|
||||
s_root_namespace->scope = AML::NameString("\\"sv);
|
||||
s_root_namespace = MUST(BAN::RefPtr<Namespace>::create(NameSeg("\\"_sv)));
|
||||
s_root_namespace->scope = AML::NameString("\\"_sv);
|
||||
|
||||
Integer::Constants::Zero = MUST(BAN::RefPtr<Integer>::create(0, true));
|
||||
Integer::Constants::One = MUST(BAN::RefPtr<Integer>::create(1, true));
|
||||
Integer::Constants::Ones = MUST(BAN::RefPtr<Integer>::create(0xFFFFFFFFFFFFFFFF, true));
|
||||
|
||||
AML::ParseContext context;
|
||||
context.scope = AML::NameString("\\"sv);
|
||||
context.scope = AML::NameString("\\"_sv);
|
||||
|
||||
// Add predefined namespaces
|
||||
#define ADD_PREDEFIED_NAMESPACE(NAME) \
|
||||
ASSERT(s_root_namespace->add_named_object(context, AML::NameString("\\" NAME), MUST(BAN::RefPtr<AML::Device>::create(NameSeg(NAME)))));
|
||||
ADD_PREDEFIED_NAMESPACE("_GPE"sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_PR"sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_SB"sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_SI"sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_TZ"sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_GPE"_sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_PR"_sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_SB"_sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_SI"_sv);
|
||||
ADD_PREDEFIED_NAMESPACE("_TZ"_sv);
|
||||
#undef ADD_PREDEFIED_NAMESPACE
|
||||
|
||||
// Add \_OSI that returns true for Linux compatibility
|
||||
auto osi = MUST(BAN::RefPtr<AML::Method>::create(NameSeg("_OSI"sv), 1, false, 0));
|
||||
auto osi = MUST(BAN::RefPtr<AML::Method>::create(NameSeg("_OSI"_sv), 1, false, 0));
|
||||
osi->override_function = [](AML::ParseContext& context) -> BAN::RefPtr<AML::Node> {
|
||||
ASSERT(context.method_args[0]);
|
||||
auto arg = context.method_args[0]->evaluate();
|
||||
|
@ -234,7 +234,7 @@ namespace Kernel::ACPI
|
|||
ASSERT(this == s_root_namespace.ptr());
|
||||
|
||||
AML::ParseContext context;
|
||||
context.scope = AML::NameString("\\"sv);
|
||||
context.scope = AML::NameString("\\"_sv);
|
||||
context.aml_data = BAN::ConstByteSpan(reinterpret_cast<const uint8_t*>(&header), header.length).slice(sizeof(header));
|
||||
|
||||
while (context.aml_data.size() > 0)
|
||||
|
|
|
@ -94,7 +94,7 @@ namespace Kernel::ACPI
|
|||
AML_DEBUG_PRINTLN("Initializing {}", scope->scope);
|
||||
#endif
|
||||
|
||||
if (auto reg = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_REG"sv), Namespace::FindMode::ForceAbsolute))
|
||||
if (auto reg = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_REG"_sv), Namespace::FindMode::ForceAbsolute))
|
||||
{
|
||||
bool embedded_controller = false;
|
||||
Namespace::for_each_child(scope->scope,
|
||||
|
@ -135,7 +135,7 @@ namespace Kernel::ACPI
|
|||
bool run_ini = true;
|
||||
bool init_children = true;
|
||||
|
||||
if (auto sta = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_STA"sv), Namespace::FindMode::ForceAbsolute))
|
||||
if (auto sta = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_STA"_sv), Namespace::FindMode::ForceAbsolute))
|
||||
{
|
||||
auto result = evaluate_or_invoke(sta);
|
||||
if (!result.has_value())
|
||||
|
@ -150,7 +150,7 @@ namespace Kernel::ACPI
|
|||
|
||||
if (run_ini)
|
||||
{
|
||||
auto ini = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_INI"sv), Namespace::FindMode::ForceAbsolute);
|
||||
auto ini = Namespace::root_namespace()->find_object(scope->scope, AML::NameString("_INI"_sv), Namespace::FindMode::ForceAbsolute);
|
||||
if (ini)
|
||||
{
|
||||
if (ini->type != AML::Node::Type::Method)
|
||||
|
|
|
@ -132,7 +132,7 @@ namespace Kernel
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const MADT* madt = (const MADT*)ACPI::ACPI::get().get_header("APIC"sv, 0);
|
||||
const MADT* madt = (const MADT*)ACPI::ACPI::get().get_header("APIC"_sv, 0);
|
||||
if (madt == nullptr)
|
||||
{
|
||||
dprintln("Could not find MADT header");
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<BAN::String> Credentials::find_username() const
|
||||
{
|
||||
auto inode = TRY(VirtualFileSystem::get().file_from_absolute_path(*this, "/etc/passwd"sv, O_RDONLY)).inode;
|
||||
auto inode = TRY(VirtualFileSystem::get().file_from_absolute_path(*this, "/etc/passwd"_sv, O_RDONLY)).inode;
|
||||
|
||||
BAN::String line;
|
||||
off_t offset = 0;
|
||||
|
|
|
@ -436,8 +436,8 @@ done:
|
|||
auto inode = inode_or_error.release_value();
|
||||
BAN::ScopeGuard cleanup([&] { inode->cleanup_from_fs(); });
|
||||
|
||||
TRY(inode->link_inode_to_directory(*inode, "."sv));
|
||||
TRY(inode->link_inode_to_directory(*this, ".."sv));
|
||||
TRY(inode->link_inode_to_directory(*inode, "."_sv));
|
||||
TRY(inode->link_inode_to_directory(*this, ".."_sv));
|
||||
|
||||
TRY(link_inode_to_directory(*inode, name));
|
||||
|
||||
|
@ -569,7 +569,7 @@ needs_new_block:
|
|||
if (entry.inode)
|
||||
{
|
||||
BAN::StringView entry_name(entry.name, entry.name_len);
|
||||
if (entry_name != "."sv && entry_name != ".."sv)
|
||||
if (entry_name != "."_sv && entry_name != ".."_sv)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -608,12 +608,12 @@ needs_new_block:
|
|||
{
|
||||
BAN::StringView entry_name(entry.name, entry.name_len);
|
||||
|
||||
if (entry_name == "."sv)
|
||||
if (entry_name == "."_sv)
|
||||
{
|
||||
m_inode.links_count--;
|
||||
sync();
|
||||
}
|
||||
else if (entry_name == ".."sv)
|
||||
else if (entry_name == ".."_sv)
|
||||
{
|
||||
auto parent = TRY(Ext2Inode::create(m_fs, entry.inode));
|
||||
parent->m_inode.links_count--;
|
||||
|
|
|
@ -212,9 +212,10 @@ namespace Kernel
|
|||
return valid_entry_count;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<size_t> FATInode::read_impl(off_t offset, BAN::ByteSpan buffer)
|
||||
BAN::ErrorOr<size_t> FATInode::read_impl(off_t s_offset, BAN::ByteSpan buffer)
|
||||
{
|
||||
ASSERT(offset >= 0);
|
||||
ASSERT(s_offset >= 0);
|
||||
uint32_t offset = s_offset;
|
||||
|
||||
if (offset >= m_entry.file_size)
|
||||
return 0;
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace Kernel
|
|||
LockGuard _(m_mutex);
|
||||
if (!mode().ifdir())
|
||||
return BAN::Error::from_errno(ENOTDIR);
|
||||
if (name == "."sv || name == ".."sv)
|
||||
if (name == "."_sv || name == ".."_sv)
|
||||
return BAN::Error::from_errno(EINVAL);
|
||||
return unlink_impl(name);
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ namespace Kernel
|
|||
return BAN::Error::from_errno(ENOMEM);
|
||||
auto inode = BAN::RefPtr<ProcPidInode>::adopt(inode_ptr);
|
||||
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_meminfo, fs, 0400, uid, gid)), "meminfo"sv));
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_cmdline, fs, 0400, uid, gid)), "cmdline"sv));
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_environ, fs, 0400, uid, gid)), "environ"sv));
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_meminfo, fs, 0400, uid, gid)), "meminfo"_sv));
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_cmdline, fs, 0400, uid, gid)), "cmdline"_sv));
|
||||
TRY(inode->link_inode(*MUST(ProcROInode::create_new(process, &Process::proc_environ, fs, 0400, uid, gid)), "environ"_sv));
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
@ -27,9 +27,9 @@ namespace Kernel
|
|||
|
||||
void ProcPidInode::cleanup()
|
||||
{
|
||||
(void)TmpDirectoryInode::unlink_impl("meminfo"sv);
|
||||
(void)TmpDirectoryInode::unlink_impl("cmdline"sv);
|
||||
(void)TmpDirectoryInode::unlink_impl("environ"sv);
|
||||
(void)TmpDirectoryInode::unlink_impl("meminfo"_sv);
|
||||
(void)TmpDirectoryInode::unlink_impl("cmdline"_sv);
|
||||
(void)TmpDirectoryInode::unlink_impl("environ"_sv);
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<ProcROInode>> ProcROInode::create_new(Process& process, size_t (Process::*callback)(off_t, BAN::ByteSpan) const, TmpFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
|
||||
|
|
|
@ -342,8 +342,8 @@ namespace Kernel
|
|||
return BAN::Error::from_errno(ENOMEM);
|
||||
|
||||
auto inode = BAN::RefPtr<TmpDirectoryInode>::adopt(inode_ptr);
|
||||
TRY(inode->link_inode(*inode, "."sv));
|
||||
TRY(inode->link_inode(*inode, ".."sv));
|
||||
TRY(inode->link_inode(*inode, "."_sv));
|
||||
TRY(inode->link_inode(*inode, ".."_sv));
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
@ -358,8 +358,8 @@ namespace Kernel
|
|||
return BAN::Error::from_errno(ENOMEM);
|
||||
|
||||
auto inode = BAN::RefPtr<TmpDirectoryInode>::adopt(inode_ptr);
|
||||
TRY(inode->link_inode(*inode, "."sv));
|
||||
TRY(inode->link_inode(parent, ".."sv));
|
||||
TRY(inode->link_inode(*inode, "."_sv));
|
||||
TRY(inode->link_inode(parent, ".."_sv));
|
||||
|
||||
return inode;
|
||||
}
|
||||
|
@ -381,9 +381,9 @@ namespace Kernel
|
|||
|
||||
bool is_empty = true;
|
||||
for_each_valid_entry([&](TmpDirectoryEntry& entry) {
|
||||
if (entry.name_sv() == "."sv)
|
||||
if (entry.name_sv() == "."_sv)
|
||||
dot_ino = entry.ino;
|
||||
else if (entry.name_sv() == ".."sv)
|
||||
else if (entry.name_sv() == ".."_sv)
|
||||
dotdot_ino = entry.ino;
|
||||
else
|
||||
{
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Kernel
|
|||
ASSERT(!s_instance);
|
||||
s_instance = MUST(BAN::RefPtr<VirtualFileSystem>::create());
|
||||
|
||||
ASSERT(root_path.size() >= 5 && root_path.substring(0, 5) == "/dev/"sv);;
|
||||
ASSERT(root_path.size() >= 5 && root_path.substring(0, 5) == "/dev/"_sv);;
|
||||
root_path = root_path.substring(5);
|
||||
|
||||
auto root_inode = MUST(DevFileSystem::get().root_inode()->find_inode(root_path));
|
||||
|
@ -26,12 +26,12 @@ namespace Kernel
|
|||
s_instance->m_root_fs = MUST(FileSystem::from_block_device(static_cast<BlockDevice*>(root_inode.ptr())));
|
||||
|
||||
Credentials root_creds { 0, 0, 0, 0 };
|
||||
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"sv));
|
||||
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"_sv));
|
||||
|
||||
MUST(s_instance->mount(root_creds, &ProcFileSystem::get(), "/proc"sv));
|
||||
MUST(s_instance->mount(root_creds, &ProcFileSystem::get(), "/proc"_sv));
|
||||
|
||||
auto tmpfs = MUST(TmpFileSystem::create(1024, 0777, 0, 0));
|
||||
MUST(s_instance->mount(root_creds, tmpfs, "/tmp"sv));
|
||||
MUST(s_instance->mount(root_creds, tmpfs, "/tmp"_sv));
|
||||
}
|
||||
|
||||
VirtualFileSystem& VirtualFileSystem::get()
|
||||
|
@ -109,16 +109,16 @@ namespace Kernel
|
|||
const auto& path_part = path_parts.back();
|
||||
auto orig = inode;
|
||||
|
||||
if (path_part.empty() || path_part == "."sv)
|
||||
if (path_part.empty() || path_part == "."_sv)
|
||||
{
|
||||
|
||||
}
|
||||
else if (path_part == ".."sv)
|
||||
else if (path_part == ".."_sv)
|
||||
{
|
||||
if (auto* mount_point = mount_from_root_inode(inode))
|
||||
inode = TRY(mount_point->host.inode->find_inode(".."sv));
|
||||
inode = TRY(mount_point->host.inode->find_inode(".."_sv));
|
||||
else
|
||||
inode = TRY(inode->find_inode(".."sv));
|
||||
inode = TRY(inode->find_inode(".."_sv));
|
||||
|
||||
if (!canonical_path.empty())
|
||||
{
|
||||
|
|
|
@ -244,7 +244,7 @@ namespace Kernel::Input
|
|||
// FIXME: Initialise USB Controllers
|
||||
|
||||
// Determine if the PS/2 Controller Exists
|
||||
auto* fadt = static_cast<const ACPI::FADT*>(ACPI::ACPI::get().get_header("FACP"sv, 0));
|
||||
auto* fadt = static_cast<const ACPI::FADT*>(ACPI::ACPI::get().get_header("FACP"_sv, 0));
|
||||
if (fadt && fadt->revision > 1 && !(fadt->iapc_boot_arch & (1 << 1)))
|
||||
{
|
||||
dwarnln_if(DEBUG_PS2, "No PS/2 available");
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#include <kernel/Networking/NetworkLayer.h>
|
||||
|
||||
namespace Kernel
|
||||
{
|
||||
|
||||
uint16_t calculate_internet_checksum(BAN::ConstByteSpan packet, const PseudoHeader& pseudo_header)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
for (size_t i = 0; i < sizeof(pseudo_header) / sizeof(uint16_t); i++)
|
||||
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(&pseudo_header)[i]);
|
||||
for (size_t i = 0; i < packet.size() / sizeof(uint16_t); i++)
|
||||
checksum += BAN::host_to_network_endian(reinterpret_cast<const uint16_t*>(packet.data())[i]);
|
||||
if (packet.size() % 2)
|
||||
checksum += (uint16_t)packet[packet.size() - 1] << 8;
|
||||
while (checksum >> 16)
|
||||
checksum = (checksum >> 16) + (checksum & 0xFFFF);
|
||||
return ~(uint16_t)checksum;
|
||||
}
|
||||
|
||||
}
|
|
@ -65,7 +65,7 @@ namespace Kernel
|
|||
|
||||
int fd = TRY(get_free_fd());
|
||||
// FIXME: path?
|
||||
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(inode, ""sv, 0, flags));
|
||||
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(inode, ""_sv, 0, flags));
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ namespace Kernel
|
|||
auto socket = TRY(NetworkManager::get().create_socket(sock_domain, sock_type, 0777, m_credentials.euid(), m_credentials.egid()));
|
||||
|
||||
int fd = TRY(get_free_fd());
|
||||
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(socket, "no-path"sv, 0, O_RDWR));
|
||||
m_open_files[fd] = TRY(BAN::RefPtr<OpenFileDescription>::create(socket, "no-path"_sv, 0, O_RDWR));
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
@ -150,8 +150,8 @@ namespace Kernel
|
|||
TRY(get_free_fd_pair(fds));
|
||||
|
||||
auto pipe = TRY(Pipe::create(m_credentials));
|
||||
m_open_files[fds[0]] = TRY(BAN::RefPtr<OpenFileDescription>::create(pipe, ""sv, 0, O_RDONLY));
|
||||
m_open_files[fds[1]] = TRY(BAN::RefPtr<OpenFileDescription>::create(pipe, ""sv, 0, O_WRONLY));
|
||||
m_open_files[fds[0]] = TRY(BAN::RefPtr<OpenFileDescription>::create(pipe, ""_sv, 0, O_RDONLY));
|
||||
m_open_files[fds[1]] = TRY(BAN::RefPtr<OpenFileDescription>::create(pipe, ""_sv, 0, O_WRONLY));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -118,7 +118,7 @@ namespace Kernel
|
|||
TRY(process->m_cmdline.push_back({}));
|
||||
TRY(process->m_cmdline.back().append(path));
|
||||
|
||||
process->m_loadable_elf = TRY(load_elf_for_exec(credentials, path, "/"sv, process->page_table()));
|
||||
process->m_loadable_elf = TRY(load_elf_for_exec(credentials, path, "/"_sv, process->page_table()));
|
||||
if (!process->m_loadable_elf->is_address_space_free())
|
||||
{
|
||||
dprintln("Could not load ELF address space");
|
||||
|
@ -1942,7 +1942,7 @@ namespace Kernel
|
|||
{
|
||||
LockGuard _(m_process_lock);
|
||||
|
||||
if (path.empty() || path == "."sv)
|
||||
if (path.empty() || path == "."_sv)
|
||||
return m_working_directory;
|
||||
|
||||
BAN::String absolute_path;
|
||||
|
|
|
@ -30,11 +30,11 @@ namespace Kernel
|
|||
s_tty = this;
|
||||
clear();
|
||||
|
||||
auto inode_or_error = DevFileSystem::get().root_inode()->find_inode("tty"sv);
|
||||
auto inode_or_error = DevFileSystem::get().root_inode()->find_inode("tty"_sv);
|
||||
if (inode_or_error.is_error())
|
||||
{
|
||||
if (inode_or_error.error().get_error_code() == ENOENT)
|
||||
DevFileSystem::get().add_inode("tty"sv, MUST(TmpSymlinkInode::create_new(DevFileSystem::get(), 0666, 0, 0, s_tty->name())));
|
||||
DevFileSystem::get().add_inode("tty"_sv, MUST(TmpSymlinkInode::create_new(DevFileSystem::get(), 0666, 0, 0, s_tty->name())));
|
||||
else
|
||||
dwarnln("{}", inode_or_error.error());
|
||||
return;
|
||||
|
@ -82,7 +82,7 @@ namespace Kernel
|
|||
Process::create_kernel(
|
||||
[](void*)
|
||||
{
|
||||
auto file_or_error = VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, "/dev/input0"sv, O_RDONLY);
|
||||
auto file_or_error = VirtualFileSystem::get().file_from_absolute_path({ 0, 0, 0, 0 }, "/dev/input0"_sv, O_RDONLY);
|
||||
if (file_or_error.is_error())
|
||||
{
|
||||
dprintln("no input device found");
|
||||
|
|
|
@ -131,7 +131,7 @@ namespace Kernel
|
|||
|
||||
BAN::ErrorOr<void> HPET::initialize(bool force_pic)
|
||||
{
|
||||
auto* header = static_cast<const ACPI::HPET*>(ACPI::ACPI::get().get_header("HPET"sv, 0));
|
||||
auto* header = static_cast<const ACPI::HPET*>(ACPI::ACPI::get().get_header("HPET"_sv, 0));
|
||||
if (header == nullptr)
|
||||
return BAN::Error::from_errno(ENODEV);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ struct ParsedCommandLine
|
|||
{
|
||||
bool force_pic = false;
|
||||
bool disable_serial = false;
|
||||
BAN::StringView console = "tty0"sv;
|
||||
BAN::StringView console = "tty0"_sv;
|
||||
BAN::StringView root;
|
||||
};
|
||||
|
||||
|
@ -215,7 +215,7 @@ static void init2(void*)
|
|||
|
||||
TTY::initialize_devices();
|
||||
|
||||
MUST(Process::create_userspace({ 0, 0, 0, 0 }, "/usr/bin/init"sv));
|
||||
MUST(Process::create_userspace({ 0, 0, 0, 0 }, "/usr/bin/init"_sv));
|
||||
}
|
||||
|
||||
extern "C" void ap_main()
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(libc CXX ASM)
|
||||
|
||||
set(LIBC_SOURCES
|
||||
arpa/inet.cpp
|
||||
assert.cpp
|
||||
ctype.cpp
|
||||
dirent.cpp
|
||||
fcntl.cpp
|
||||
grp.cpp
|
||||
malloc.cpp
|
||||
netdb.cpp
|
||||
printf_impl.cpp
|
||||
pwd.cpp
|
||||
scanf_impl.cpp
|
||||
signal.cpp
|
||||
stdio.cpp
|
||||
stdlib.cpp
|
||||
string.cpp
|
||||
strings.cpp
|
||||
stropts.cpp
|
||||
sys/banan-os.cpp
|
||||
sys/mman.cpp
|
||||
sys/select.cpp
|
||||
sys/socket.cpp
|
||||
sys/stat.cpp
|
||||
sys/wait.cpp
|
||||
termios.cpp
|
||||
time.cpp
|
||||
unistd.cpp
|
||||
math.cpp
|
||||
icxxabi.cpp
|
||||
|
||||
../BAN/BAN/Assert.cpp
|
||||
)
|
||||
|
||||
add_custom_target(libc-headers
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory_if_different ${CMAKE_CURRENT_SOURCE_DIR}/include/ ${BANAN_INCLUDE}/
|
||||
DEPENDS sysroot
|
||||
)
|
||||
|
||||
add_custom_target(crtx
|
||||
COMMAND ${CMAKE_C_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crt0.S -o crt0.o
|
||||
COMMAND ${CMAKE_C_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crti.S -o crti.o
|
||||
COMMAND ${CMAKE_C_COMPILER} -c ${CMAKE_CURRENT_SOURCE_DIR}/arch/${BANAN_ARCH}/crtn.S -o crtn.o
|
||||
)
|
||||
|
||||
add_custom_target(crtx-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy crt0.o ${BANAN_LIB}/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy crti.o ${BANAN_LIB}/
|
||||
COMMAND ${CMAKE_COMMAND} -E copy crtn.o ${BANAN_LIB}/
|
||||
DEPENDS crtx
|
||||
)
|
||||
|
||||
add_library(libc ${LIBC_SOURCES})
|
||||
add_dependencies(libc headers crtx-install)
|
||||
|
||||
target_compile_options(libc PRIVATE -O2 -g -Wstack-usage=512 -fno-tree-loop-distribute-patterns)
|
||||
target_compile_options(libc PUBLIC -Wall -Wextra -Werror -Wno-error=stack-usage=)
|
||||
|
||||
add_custom_target(libc-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libc.a ${BANAN_LIB}/
|
||||
DEPENDS libc
|
||||
BYPRODUCTS ${BANAN_LIB}/libc.a
|
||||
)
|
||||
|
||||
set(CMAKE_STATIC_LIBRARY_PREFIX "")
|
|
@ -1,10 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
CURRENT_DIR=$(dirname $(realpath $0))
|
||||
pushd "$CURRENT_DIR" >/dev/null
|
||||
cd $(dirname $(realpath $0))
|
||||
|
||||
if [ ! -f installed ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
while read port; do
|
||||
${port}/build.sh
|
||||
done < installed
|
||||
|
||||
popd >/dev/null
|
||||
|
|
|
@ -112,7 +112,7 @@ index 0000000..9161771
|
|||
+
|
||||
+void DG_Init()
|
||||
+{
|
||||
+ s_window = MUST(LibGUI::Window::create(DOOMGENERIC_RESX, DOOMGENERIC_RESY, "DOOM"sv));
|
||||
+ s_window = MUST(LibGUI::Window::create(DOOMGENERIC_RESX, DOOMGENERIC_RESY, "DOOM"_sv));
|
||||
+ s_window->set_key_event_callback(
|
||||
+ [](LibGUI::EventPacket::KeyEvent event)
|
||||
+ {
|
||||
|
|
|
@ -7,6 +7,9 @@ source $BANAN_SCRIPT_DIR/config.sh
|
|||
FAKEROOT_FILE="$BANAN_BUILD_DIR/fakeroot-context"
|
||||
|
||||
run_fakeroot() {
|
||||
if [ ! -f $FAKEROOT_FILE ]; then
|
||||
touch $FAKEROOT_FILE
|
||||
fi
|
||||
fakeroot -i $FAKEROOT_FILE -s $FAKEROOT_FILE -- /bin/bash -c '$@' bash $@
|
||||
}
|
||||
|
||||
|
@ -44,9 +47,14 @@ build_toolchain () {
|
|||
|
||||
create_image () {
|
||||
build_target bootloader
|
||||
build_target install-sysroot
|
||||
build_target install
|
||||
|
||||
$BANAN_ROOT_DIR/ports/build.sh
|
||||
build_target package-sysroot
|
||||
|
||||
pushd $BANAN_SYSROOT >/dev/null
|
||||
run_fakeroot tar cf ${BANAN_SYSROOT_TAR} *
|
||||
popd >/dev/null
|
||||
|
||||
$BANAN_SCRIPT_DIR/image.sh "$1"
|
||||
}
|
||||
|
||||
|
@ -106,8 +114,12 @@ case $1 in
|
|||
build_target clean
|
||||
rm -f $FAKEROOT_FILE
|
||||
rm -rf $BANAN_SYSROOT
|
||||
rm -f $BANAN_SYSROOT.tar
|
||||
rm -f $BANAN_DISK_IMAGE_PATH
|
||||
;;
|
||||
distclean)
|
||||
rm -rf $BANAN_BUILD_DIR
|
||||
;;
|
||||
*)
|
||||
build_target $1
|
||||
;;
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(userspace CXX)
|
||||
|
||||
set(USERSPACE_PROJECTS
|
||||
cat
|
||||
cat-mmap
|
||||
|
@ -18,7 +14,6 @@ set(USERSPACE_PROJECTS
|
|||
ls
|
||||
meminfo
|
||||
mkdir
|
||||
mmap-shared-test
|
||||
nslookup
|
||||
poweroff
|
||||
resolver
|
||||
|
@ -34,6 +29,7 @@ set(USERSPACE_PROJECTS
|
|||
test
|
||||
test-framebuffer
|
||||
test-globals
|
||||
test-mmap-shared
|
||||
test-mouse
|
||||
test-popen
|
||||
test-sort
|
||||
|
@ -48,19 +44,18 @@ set(USERSPACE_PROJECTS
|
|||
yes
|
||||
)
|
||||
|
||||
foreach(USERSPACE_PROJECT ${USERSPACE_PROJECTS})
|
||||
add_subdirectory(${USERSPACE_PROJECT})
|
||||
endforeach()
|
||||
add_subdirectory(libraries)
|
||||
|
||||
add_custom_target(userspace)
|
||||
add_custom_target(userspace-install DEPENDS userspace)
|
||||
|
||||
add_subdirectory(aoc2023)
|
||||
#add_subdirectory(aoc2023)
|
||||
|
||||
foreach(USERSPACE_PROJECT ${USERSPACE_PROJECTS})
|
||||
target_compile_options(${USERSPACE_PROJECT} PRIVATE -g)
|
||||
add_dependencies(userspace ${USERSPACE_PROJECT})
|
||||
add_dependencies(userspace-install ${USERSPACE_PROJECT}-install)
|
||||
|
||||
target_link_options(${USERSPACE_PROJECT} PRIVATE -nolibc)
|
||||
foreach(project ${USERSPACE_PROJECTS})
|
||||
add_subdirectory(${project})
|
||||
add_dependencies(${project} crtx-install)
|
||||
add_dependencies(userspace ${project})
|
||||
# This is to allow cmake to link when libc updates
|
||||
target_link_options(${project} PRIVATE -nolibc)
|
||||
# Default compile options
|
||||
target_compile_options(${project} PRIVATE -g -O2)
|
||||
endforeach()
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(Shell CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(Shell ${SOURCES})
|
||||
target_compile_options(Shell PUBLIC -O2 -g)
|
||||
target_link_libraries(Shell PUBLIC libc ban)
|
||||
banan_link_library(Shell ban)
|
||||
banan_link_library(Shell libc)
|
||||
|
||||
add_custom_target(Shell-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/Shell ${BANAN_BIN}/
|
||||
DEPENDS Shell
|
||||
)
|
||||
install(TARGETS Shell)
|
||||
|
|
|
@ -36,7 +36,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
|
|||
ASSERT(command[i] == '$');
|
||||
|
||||
if (++i >= command.size())
|
||||
return "$"sv;
|
||||
return "$"_sv;
|
||||
|
||||
if (command[i] == '?')
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
|
|||
|
||||
if (const char* value = getenv(name.data()))
|
||||
return BAN::StringView(value);
|
||||
return ""sv;
|
||||
return ""_sv;
|
||||
}
|
||||
else if (command[i] == '{')
|
||||
{
|
||||
|
@ -75,7 +75,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
|
|||
|
||||
if (const char* value = getenv(name.data()))
|
||||
return BAN::StringView(value);
|
||||
return ""sv;
|
||||
return ""_sv;
|
||||
}
|
||||
else if (command[i] == '[')
|
||||
{
|
||||
|
@ -156,7 +156,7 @@ BAN::Optional<BAN::String> parse_dollar(BAN::StringView command, size_t& i)
|
|||
return output;
|
||||
}
|
||||
|
||||
BAN::String temp = "$"sv;
|
||||
BAN::String temp = "$"_sv;
|
||||
MUST(temp.push_back(command[i]));
|
||||
return temp;
|
||||
}
|
||||
|
@ -288,16 +288,16 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
}
|
||||
BAN::ScopeGuard _([fout, should_close] { if (should_close) fclose(fout); });
|
||||
|
||||
if (args.front() == "clear"sv)
|
||||
if (args.front() == "clear"_sv)
|
||||
{
|
||||
fprintf(fout, "\e[H\e[2J");
|
||||
fflush(fout);
|
||||
}
|
||||
else if (args.front() == "exit"sv)
|
||||
else if (args.front() == "exit"_sv)
|
||||
{
|
||||
clean_exit();
|
||||
}
|
||||
else if (args.front() == "export"sv)
|
||||
else if (args.front() == "export"_sv)
|
||||
{
|
||||
bool first = false;
|
||||
for (const auto& arg : args)
|
||||
|
@ -316,7 +316,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
ERROR_RETURN("setenv", 1);
|
||||
}
|
||||
}
|
||||
else if (args.front() == "source"sv)
|
||||
else if (args.front() == "source"_sv)
|
||||
{
|
||||
if (args.size() != 2)
|
||||
{
|
||||
|
@ -325,13 +325,13 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
}
|
||||
return source_script(args[1]);
|
||||
}
|
||||
else if (args.front() == "env"sv)
|
||||
else if (args.front() == "env"_sv)
|
||||
{
|
||||
char** current = environ;
|
||||
while (*current)
|
||||
fprintf(fout, "%s\n", *current++);
|
||||
}
|
||||
else if (args.front() == "start-gui"sv)
|
||||
else if (args.front() == "start-gui"_sv)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
|
@ -340,12 +340,12 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
execl("/bin/Terminal", "Terminal", NULL);
|
||||
waitpid(pid, nullptr, 0);
|
||||
}
|
||||
else if (args.front() == "page-fault-test"sv)
|
||||
else if (args.front() == "page-fault-test"_sv)
|
||||
{
|
||||
volatile int* ptr = nullptr;
|
||||
*ptr = 0;
|
||||
}
|
||||
else if (args.front() == "kill-test"sv)
|
||||
else if (args.front() == "kill-test"_sv)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
|
@ -366,7 +366,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
else if (args.front() == "signal-test"sv)
|
||||
else if (args.front() == "signal-test"_sv)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid == 0)
|
||||
|
@ -400,7 +400,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
else if (args.front() == "printf-test"sv)
|
||||
else if (args.front() == "printf-test"_sv)
|
||||
{
|
||||
fprintf(fout, " 0.0: %f\n", 0.0f);
|
||||
fprintf(fout, " 123.0: %f\n", 123.0f);
|
||||
|
@ -409,7 +409,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
fprintf(fout, "+INF: %f\n", INFINITY);
|
||||
fprintf(fout, "-INF: %f\n", -INFINITY);
|
||||
}
|
||||
else if (args.front() == "cd"sv)
|
||||
else if (args.front() == "cd"_sv)
|
||||
{
|
||||
if (args.size() > 2)
|
||||
{
|
||||
|
@ -432,7 +432,7 @@ BAN::Optional<int> execute_builtin(BAN::Vector<BAN::String>& args, int fd_in, in
|
|||
if (chdir(path.data()) == -1)
|
||||
ERROR_RETURN("chdir", 1);
|
||||
}
|
||||
else if (args.front() == "time"sv)
|
||||
else if (args.front() == "time"_sv)
|
||||
{
|
||||
args.remove(0);
|
||||
|
||||
|
@ -783,7 +783,7 @@ int source_shellrc()
|
|||
if (char* home = getenv("HOME"))
|
||||
{
|
||||
BAN::String path(home);
|
||||
MUST(path.append("/.shellrc"sv));
|
||||
MUST(path.append("/.shellrc"_sv));
|
||||
if (exists(path))
|
||||
return source_script(path);
|
||||
}
|
||||
|
@ -816,7 +816,7 @@ BAN::String get_prompt()
|
|||
{
|
||||
const char* raw_prompt = getenv("PS1");
|
||||
if (raw_prompt == nullptr)
|
||||
return "$ "sv;
|
||||
return "$ "_sv;
|
||||
|
||||
BAN::String prompt;
|
||||
for (int i = 0; raw_prompt[i]; i++)
|
||||
|
@ -962,7 +962,7 @@ int main(int argc, char** argv)
|
|||
tcsetattr(0, TCSANOW, &new_termios);
|
||||
|
||||
BAN::Vector<BAN::String> buffers, history;
|
||||
MUST(buffers.emplace_back(""sv));
|
||||
MUST(buffers.emplace_back(""_sv));
|
||||
size_t index = 0;
|
||||
size_t col = 0;
|
||||
|
||||
|
@ -1073,7 +1073,7 @@ int main(int argc, char** argv)
|
|||
last_return = parse_and_execute_command(buffers[index]);
|
||||
MUST(history.push_back(buffers[index]));
|
||||
buffers = history;
|
||||
MUST(buffers.emplace_back(""sv));
|
||||
MUST(buffers.emplace_back(""_sv));
|
||||
}
|
||||
print_prompt();
|
||||
index = buffers.size() - 1;
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(Terminal CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
Terminal.cpp
|
||||
)
|
||||
|
||||
add_executable(Terminal ${SOURCES})
|
||||
target_compile_options(Terminal PUBLIC -O2 -g)
|
||||
target_link_libraries(Terminal PUBLIC libc ban libfont libgui libinput)
|
||||
banan_include_headers(Terminal ban)
|
||||
banan_link_library(Terminal libc)
|
||||
banan_link_library(Terminal libfont)
|
||||
banan_link_library(Terminal libgui)
|
||||
banan_link_library(Terminal libinput)
|
||||
|
||||
add_custom_target(Terminal-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/Terminal ${BANAN_BIN}/
|
||||
DEPENDS Terminal
|
||||
)
|
||||
install(TARGETS Terminal)
|
||||
|
|
|
@ -87,11 +87,11 @@ void Terminal::run()
|
|||
signal(SIGCHLD, [](int) { s_shell_exited = true; });
|
||||
start_shell();
|
||||
|
||||
m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"sv));
|
||||
m_window = MUST(LibGUI::Window::create(600, 400, "Terminal"_sv));
|
||||
m_window->fill(m_bg_color);
|
||||
m_window->invalidate();
|
||||
|
||||
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"sv));
|
||||
m_font = MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv));
|
||||
|
||||
m_window->set_key_event_callback([&](LibGUI::EventPacket::KeyEvent event) { on_key_event(event); });
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(WindowServer CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
Framebuffer.cpp
|
||||
|
@ -10,10 +6,11 @@ set(SOURCES
|
|||
)
|
||||
|
||||
add_executable(WindowServer ${SOURCES})
|
||||
target_compile_options(WindowServer PUBLIC -O2 -g)
|
||||
target_link_libraries(WindowServer PUBLIC libc ban libfont libgui libimage libinput)
|
||||
banan_include_headers(WindowServer ban)
|
||||
banan_include_headers(WindowServer libgui)
|
||||
banan_link_library(WindowServer libc)
|
||||
banan_link_library(WindowServer libfont)
|
||||
banan_link_library(WindowServer libimage)
|
||||
banan_link_library(WindowServer libinput)
|
||||
|
||||
add_custom_target(WindowServer-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/WindowServer ${BANAN_BIN}/
|
||||
DEPENDS WindowServer
|
||||
)
|
||||
install(TARGETS WindowServer)
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
WindowServer(Framebuffer& framebuffer)
|
||||
: m_framebuffer(framebuffer)
|
||||
, m_cursor({ framebuffer.width / 2, framebuffer.height / 2 })
|
||||
, m_font(MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"sv)))
|
||||
, m_font(MUST(LibFont::Font::load("/usr/share/fonts/lat0-16.psfu"_sv)))
|
||||
{
|
||||
invalidate(m_framebuffer.area());
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ Config parse_config()
|
|||
auto variable = parts[0];
|
||||
auto value = parts[1];
|
||||
|
||||
if (variable == "bg"sv)
|
||||
if (variable == "bg"_sv)
|
||||
{
|
||||
auto image = LibImage::Image::load_from_file(value);
|
||||
if (image.is_error())
|
||||
|
@ -156,7 +156,7 @@ int main()
|
|||
atexit([]() { tty_ctrl(STDIN_FILENO, TTY_CMD_SET, TTY_FLAG_ENABLE_INPUT); });
|
||||
|
||||
MUST(LibInput::KeyboardLayout::initialize());
|
||||
MUST(LibInput::KeyboardLayout::get().load_from_file("/usr/share/keymaps/us.keymap"sv));
|
||||
MUST(LibInput::KeyboardLayout::get().load_from_file("/usr/share/keymaps/us.keymap"_sv));
|
||||
|
||||
int keyboard_fd = open("/dev/input0", O_RDONLY);
|
||||
if (keyboard_fd == -1)
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023 CXX)
|
||||
|
||||
set(AOC2023_PROJECTS
|
||||
day1
|
||||
day2
|
||||
|
@ -30,20 +26,21 @@ set(AOC2023_PROJECTS
|
|||
full
|
||||
)
|
||||
|
||||
set(BANAN_AOC2023_BIN ${BANAN_BIN}/aoc2023)
|
||||
set(BANAN_AOC2023_BIN ${CMAKE_INSTALL_BINDIR}/aoc2023)
|
||||
set(BANAN_AOC2023_INPUT ${BANAN_SHARE}/aoc2023)
|
||||
|
||||
set(CMAKE_INSTALL_BINDIR ${BANAN_AOC2023_BIN})
|
||||
|
||||
add_custom_target(aoc2023)
|
||||
add_custom_target(aoc2023_always
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${BANAN_AOC2023_BIN}
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${BANAN_AOC2023_INPUT}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/input/* ${BANAN_AOC2023_INPUT}/
|
||||
)
|
||||
add_custom_target(aoc2023-install DEPENDS aoc2023 aoc2023_always)
|
||||
|
||||
file(GLOB_RECURSE input_files "input/*")
|
||||
foreach(file ${input_files})
|
||||
install(FILES ${file} DESTINATION ${BANAN_AOC2023_INPUT})
|
||||
endforeach()
|
||||
|
||||
foreach(AOC2023_PROJECT ${AOC2023_PROJECTS})
|
||||
add_subdirectory(${AOC2023_PROJECT})
|
||||
add_dependencies(aoc2023 aoc2023_${AOC2023_PROJECT})
|
||||
endforeach()
|
||||
|
||||
add_dependencies(userspace aoc2023)
|
||||
add_dependencies(userspace-install aoc2023-install)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day-template CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day-template ${SOURCES})
|
||||
target_compile_options(aoc2023_day-template PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day-template PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day-template ban)
|
||||
banan_link_library(aoc2023_day-template libc)
|
||||
|
||||
add_dependencies(aoc2023_day-template libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day-template-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day-template ${BANAN_AOC2023_BIN}/day-template
|
||||
DEPENDS aoc2023_day-template
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day-template)
|
||||
add_dependencies(aoc2023-install aoc2023_day-template-install)
|
||||
install(TARGETS aoc2023_day-template)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day1 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day1 ${SOURCES})
|
||||
target_compile_options(aoc2023_day1 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day1 PUBLIC libc)
|
||||
banan_include_headers(aoc2023_day1 ban)
|
||||
banan_link_library(aoc2023_day1 libc)
|
||||
|
||||
add_dependencies(aoc2023_day1 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day1-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day1 ${BANAN_AOC2023_BIN}/day1
|
||||
DEPENDS aoc2023_day1
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day1)
|
||||
add_dependencies(aoc2023-install aoc2023_day1-install)
|
||||
install(TARGETS aoc2023_day1)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day10 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day10 ${SOURCES})
|
||||
target_compile_options(aoc2023_day10 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day10 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day10 ban)
|
||||
banan_link_library(aoc2023_day10 libc)
|
||||
|
||||
add_dependencies(aoc2023_day10 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day10-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day10 ${BANAN_AOC2023_BIN}/day10
|
||||
DEPENDS aoc2023_day10
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day10)
|
||||
add_dependencies(aoc2023-install aoc2023_day10-install)
|
||||
install(TARGETS aoc2023_day10)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day11 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day11 ${SOURCES})
|
||||
target_compile_options(aoc2023_day11 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day11 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day11 ban)
|
||||
banan_link_library(aoc2023_day11 libc)
|
||||
|
||||
add_dependencies(aoc2023_day11 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day11-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day11 ${BANAN_AOC2023_BIN}/day11
|
||||
DEPENDS aoc2023_day11
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day11)
|
||||
add_dependencies(aoc2023-install aoc2023_day11-install)
|
||||
install(TARGETS aoc2023_day11)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day12 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day12 ${SOURCES})
|
||||
target_compile_options(aoc2023_day12 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day12 PUBLIC libc ban)
|
||||
banan_link_library(aoc2023_day12 ban)
|
||||
banan_link_library(aoc2023_day12 libc)
|
||||
|
||||
add_dependencies(aoc2023_day12 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day12-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day12 ${BANAN_AOC2023_BIN}/day12
|
||||
DEPENDS aoc2023_day12
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day12)
|
||||
add_dependencies(aoc2023-install aoc2023_day12-install)
|
||||
install(TARGETS aoc2023_day12)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day13 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day13 ${SOURCES})
|
||||
target_compile_options(aoc2023_day13 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day13 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day13 ban)
|
||||
banan_link_library(aoc2023_day13 libc)
|
||||
|
||||
add_dependencies(aoc2023_day13 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day13-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day13 ${BANAN_AOC2023_BIN}/day13
|
||||
DEPENDS aoc2023_day13
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day13)
|
||||
add_dependencies(aoc2023-install aoc2023_day13-install)
|
||||
install(TARGETS aoc2023_day13)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day14 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day14 ${SOURCES})
|
||||
target_compile_options(aoc2023_day14 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day14 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day14 ban)
|
||||
banan_link_library(aoc2023_day14 libc)
|
||||
|
||||
add_dependencies(aoc2023_day14 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day14-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day14 ${BANAN_AOC2023_BIN}/day14
|
||||
DEPENDS aoc2023_day14
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day14)
|
||||
add_dependencies(aoc2023-install aoc2023_day14-install)
|
||||
install(TARGETS aoc2023_day14)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day15 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day15 ${SOURCES})
|
||||
target_compile_options(aoc2023_day15 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day15 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day15 ban)
|
||||
banan_link_library(aoc2023_day15 libc)
|
||||
|
||||
add_dependencies(aoc2023_day15 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day15-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day15 ${BANAN_AOC2023_BIN}/day15
|
||||
DEPENDS aoc2023_day15
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day15)
|
||||
add_dependencies(aoc2023-install aoc2023_day15-install)
|
||||
install(TARGETS aoc2023_day15)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day16 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day16 ${SOURCES})
|
||||
target_compile_options(aoc2023_day16 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day16 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day16 ban)
|
||||
banan_link_library(aoc2023_day16 libc)
|
||||
|
||||
add_dependencies(aoc2023_day16 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day16-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day16 ${BANAN_AOC2023_BIN}/day16
|
||||
DEPENDS aoc2023_day16
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day16)
|
||||
add_dependencies(aoc2023-install aoc2023_day16-install)
|
||||
install(TARGETS aoc2023_day16)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day17 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day17 ${SOURCES})
|
||||
target_compile_options(aoc2023_day17 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day17 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day17 ban)
|
||||
banan_link_library(aoc2023_day17 libc)
|
||||
|
||||
add_dependencies(aoc2023_day17 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day17-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day17 ${BANAN_AOC2023_BIN}/day17
|
||||
DEPENDS aoc2023_day17
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day17)
|
||||
add_dependencies(aoc2023-install aoc2023_day17-install)
|
||||
install(TARGETS aoc2023_day17)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day18 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day18 ${SOURCES})
|
||||
target_compile_options(aoc2023_day18 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day18 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day18 ban)
|
||||
banan_link_library(aoc2023_day18 libc)
|
||||
|
||||
add_dependencies(aoc2023_day18 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day18-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day18 ${BANAN_AOC2023_BIN}/day18
|
||||
DEPENDS aoc2023_day18
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day18)
|
||||
add_dependencies(aoc2023-install aoc2023_day18-install)
|
||||
install(TARGETS aoc2023_day18)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day19 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day19 ${SOURCES})
|
||||
target_compile_options(aoc2023_day19 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day19 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day19 ban)
|
||||
banan_link_library(aoc2023_day19 libc)
|
||||
|
||||
add_dependencies(aoc2023_day19 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day19-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day19 ${BANAN_AOC2023_BIN}/day19
|
||||
DEPENDS aoc2023_day19
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day19)
|
||||
add_dependencies(aoc2023-install aoc2023_day19-install)
|
||||
install(TARGETS aoc2023_day19)
|
||||
|
|
|
@ -168,9 +168,9 @@ bool is_accepted(const Item& item, const BAN::String& name, const Workflows& wor
|
|||
{
|
||||
if (!satifies_rule(item, rule))
|
||||
continue;
|
||||
if (rule.target == "A"sv)
|
||||
if (rule.target == "A"_sv)
|
||||
return true;
|
||||
if (rule.target == "R"sv)
|
||||
if (rule.target == "R"_sv)
|
||||
return false;
|
||||
return is_accepted(item, rule.target, workflows);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ i64 puzzle1(FILE* fp)
|
|||
BAN::Vector<Item> accepted;
|
||||
|
||||
for (const auto& item : items)
|
||||
if (is_accepted(item, "in"sv, workflows))
|
||||
if (is_accepted(item, "in"_sv, workflows))
|
||||
MUST(accepted.push_back(item));
|
||||
|
||||
i64 result = 0;
|
||||
|
@ -243,7 +243,7 @@ i64 puzzle2(FILE* fp)
|
|||
values_sorted[2][ai],
|
||||
values_sorted[3][si]
|
||||
}};
|
||||
if (!is_accepted(item, "in"sv, workflows))
|
||||
if (!is_accepted(item, "in"_sv, workflows))
|
||||
continue;
|
||||
|
||||
i64 x_count = values_sorted[0][xi + 1] - values_sorted[0][xi];
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day2 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day2 ${SOURCES})
|
||||
target_compile_options(aoc2023_day2 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day2 PUBLIC libc)
|
||||
banan_include_headers(aoc2023_day2 ban)
|
||||
banan_link_library(aoc2023_day2 libc)
|
||||
|
||||
add_dependencies(aoc2023_day2 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day2-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day2 ${BANAN_AOC2023_BIN}/day2
|
||||
DEPENDS aoc2023_day2
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day2)
|
||||
add_dependencies(aoc2023-install aoc2023_day2-install)
|
||||
install(TARGETS aoc2023_day2)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day20 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day20 ${SOURCES})
|
||||
target_compile_options(aoc2023_day20 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day20 PUBLIC libc ban)
|
||||
banan_link_library(aoc2023_day20 ban)
|
||||
banan_link_library(aoc2023_day20 libc)
|
||||
|
||||
add_dependencies(aoc2023_day20 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day20-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day20 ${BANAN_AOC2023_BIN}/day20
|
||||
DEPENDS aoc2023_day20
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day20)
|
||||
add_dependencies(aoc2023-install aoc2023_day20-install)
|
||||
install(TARGETS aoc2023_day20)
|
||||
|
|
|
@ -30,6 +30,8 @@ struct Module
|
|||
BAN::String name;
|
||||
BAN::Vector<BAN::String> targets;
|
||||
|
||||
virtual ~Module() {}
|
||||
|
||||
virtual void handle_signal(const Signal& signal, BAN::Queue<Signal>& signal_queue) = 0;
|
||||
};
|
||||
|
||||
|
@ -137,7 +139,7 @@ i64 puzzle1(FILE* fp)
|
|||
|
||||
for (size_t i = 0; i < 1000; i++)
|
||||
{
|
||||
MUST(signal_queue.push({ "broadcaster"sv, ""sv, false }));
|
||||
MUST(signal_queue.push({ "broadcaster"_sv, ""_sv, false }));
|
||||
while (!signal_queue.empty())
|
||||
{
|
||||
auto signal = signal_queue.front();
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day21 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day21 ${SOURCES})
|
||||
target_compile_options(aoc2023_day21 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day21 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day21 ban)
|
||||
banan_link_library(aoc2023_day21 libc)
|
||||
|
||||
add_dependencies(aoc2023_day21 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day21-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day21 ${BANAN_AOC2023_BIN}/day21
|
||||
DEPENDS aoc2023_day21
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day21)
|
||||
add_dependencies(aoc2023-install aoc2023_day21-install)
|
||||
install(TARGETS aoc2023_day21)
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day22 ${SOURCES})
|
||||
banan_include_headers(aoc2023_day22 ban)
|
||||
banan_link_library(aoc2023_day22 libc)
|
||||
|
||||
install(TARGETS aoc2023_day22)
|
|
@ -0,0 +1,191 @@
|
|||
#include <BAN/HashSet.h>
|
||||
#include <BAN/Sort.h>
|
||||
#include <BAN/Vector.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h>
|
||||
|
||||
using i8 = int8_t;
|
||||
using i16 = int16_t;
|
||||
using i32 = int32_t;
|
||||
using i64 = int64_t;
|
||||
|
||||
using u8 = uint8_t;
|
||||
using u16 = uint16_t;
|
||||
using u32 = uint32_t;
|
||||
using u64 = uint64_t;
|
||||
|
||||
struct Position
|
||||
{
|
||||
i64 x, y, z;
|
||||
|
||||
bool operator==(const Position& other) const
|
||||
{
|
||||
return x == other.x && y == other.y && z == other.z;
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr bool rectangle_contains(const Position& c1, const Position& c2, const Position& p)
|
||||
{
|
||||
ASSERT(c1.x <= c2.x);
|
||||
ASSERT(c1.y <= c2.y);
|
||||
return (c1.x <= p.x && p.x <= c2.x) && (c1.y <= p.y && p.y <= c2.y);
|
||||
}
|
||||
|
||||
struct Brick
|
||||
{
|
||||
Position corners[2];
|
||||
BAN::HashSet<Brick*> supporting;
|
||||
BAN::HashSet<Brick*> supported_by;
|
||||
|
||||
bool supports(const Brick& other) const
|
||||
{
|
||||
if (corners[1].z + 1 != other.corners[0].z)
|
||||
return false;
|
||||
|
||||
for (i32 i = 0; i < 4; i++)
|
||||
if (rectangle_contains(corners[0], corners[1], { other.corners[i / 2].x, other.corners[i % 2].y, 0 }))
|
||||
return true;
|
||||
|
||||
for (i32 i = 0; i < 4; i++)
|
||||
if (rectangle_contains(other.corners[0], other.corners[1], { corners[i / 2].x, corners[i % 2].y, 0 }))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
i64 parse_i64(BAN::StringView str)
|
||||
{
|
||||
i64 result = 0;
|
||||
for (char c : str)
|
||||
{
|
||||
ASSERT(isdigit(c));
|
||||
result = (result * 10) + (c - '0');
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
BAN::Vector<Brick> parse_bricks(FILE* fp)
|
||||
{
|
||||
BAN::Vector<Brick> bricks;
|
||||
|
||||
char buffer[64];
|
||||
while (fgets(buffer, sizeof(buffer), fp))
|
||||
{
|
||||
BAN::StringView line(buffer);
|
||||
ASSERT(line.back() == '\n');
|
||||
line = line.substring(0, line.size() - 1);
|
||||
if (line.empty())
|
||||
break;
|
||||
|
||||
auto corner_strs = MUST(line.split('~'));
|
||||
ASSERT(corner_strs.size() == 2);
|
||||
|
||||
Brick brick;
|
||||
for (i32 i = 0; i < 2; i++)
|
||||
{
|
||||
auto coords = MUST(corner_strs[i].split(','));
|
||||
ASSERT(coords.size() == 3);
|
||||
brick.corners[i].x = parse_i64(coords[0]);
|
||||
brick.corners[i].y = parse_i64(coords[1]);
|
||||
brick.corners[i].z = parse_i64(coords[2]);
|
||||
}
|
||||
ASSERT(brick.corners[0].x <= brick.corners[1].x);
|
||||
ASSERT(brick.corners[0].y <= brick.corners[1].y);
|
||||
ASSERT(brick.corners[0].z <= brick.corners[1].z);
|
||||
MUST(bricks.push_back(brick));
|
||||
}
|
||||
|
||||
return bricks;
|
||||
}
|
||||
|
||||
i64 puzzle1(FILE* fp)
|
||||
{
|
||||
auto brick_comp = [](const Brick& b1, const Brick& b2) { return b1.corners[0].z < b2.corners[0].z; };
|
||||
|
||||
auto bricks = parse_bricks(fp);
|
||||
BAN::sort::sort(bricks.begin(), bricks.end(), brick_comp);
|
||||
|
||||
// Simulate brick falling
|
||||
for (size_t i = 0; i < bricks.size();)
|
||||
{
|
||||
bool can_fall = bricks[i].corners[0].z > 1;
|
||||
for (size_t j = 0; j < i && can_fall; j++)
|
||||
if (bricks[j].supports(bricks[i]))
|
||||
can_fall = false;
|
||||
|
||||
if (!can_fall)
|
||||
i++;
|
||||
else
|
||||
{
|
||||
bricks[i].corners[0].z--;
|
||||
bricks[i].corners[1].z--;
|
||||
for (; i > 0; i--)
|
||||
{
|
||||
if (brick_comp(bricks[i - 1], bricks[i]))
|
||||
break;
|
||||
BAN::swap(bricks[i - 1], bricks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store brick supporting structures
|
||||
for (size_t i = 0; i < bricks.size(); i++)
|
||||
{
|
||||
for (size_t j = 0; j < bricks.size(); j++)
|
||||
{
|
||||
if (i == j)
|
||||
continue;
|
||||
if (bricks[i].supports(bricks[j]))
|
||||
{
|
||||
MUST(bricks[i].supporting.insert(&bricks[j]));
|
||||
MUST(bricks[j].supported_by.insert(&bricks[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
i64 result = 0;
|
||||
for (const auto& brick : bricks)
|
||||
{
|
||||
bool disintegratable = true;
|
||||
for (const auto* support : brick.supporting)
|
||||
if (support->supported_by.size() <= 1)
|
||||
disintegratable = false;
|
||||
result += disintegratable;
|
||||
}
|
||||
|
||||
// OFF BY 7
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
i64 puzzle2(FILE* fp)
|
||||
{
|
||||
(void)fp;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* file_path = "/usr/share/aoc2023/day22_input.txt";
|
||||
|
||||
if (argc >= 2)
|
||||
file_path = argv[1];
|
||||
|
||||
FILE* fp = fopen(file_path, "r");
|
||||
if (fp == nullptr)
|
||||
{
|
||||
perror("fopen");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("puzzle1: %" PRId64 "\n", puzzle1(fp));
|
||||
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("puzzle2: %" PRId64 "\n", puzzle2(fp));
|
||||
|
||||
fclose(fp);
|
||||
}
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day23 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day23 ${SOURCES})
|
||||
target_compile_options(aoc2023_day23 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day23 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day23 ban)
|
||||
banan_link_library(aoc2023_day23 libc)
|
||||
|
||||
add_dependencies(aoc2023_day23 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day23-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day23 ${BANAN_AOC2023_BIN}/day23
|
||||
DEPENDS aoc2023_day23
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day23)
|
||||
add_dependencies(aoc2023-install aoc2023_day23-install)
|
||||
install(TARGETS aoc2023_day23)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day24 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day24 ${SOURCES})
|
||||
target_compile_options(aoc2023_day24 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day24 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day24 ban)
|
||||
banan_link_library(aoc2023_day24 libc)
|
||||
|
||||
add_dependencies(aoc2023_day24 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day24-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day24 ${BANAN_AOC2023_BIN}/day24
|
||||
DEPENDS aoc2023_day24
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day24)
|
||||
add_dependencies(aoc2023-install aoc2023_day24-install)
|
||||
install(TARGETS aoc2023_day24)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day25 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day25 ${SOURCES})
|
||||
target_compile_options(aoc2023_day25 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day25 PUBLIC libc ban)
|
||||
banan_link_library(aoc2023_day25 ban)
|
||||
banan_link_library(aoc2023_day25 libc)
|
||||
|
||||
add_dependencies(aoc2023_day25 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day25-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day25 ${BANAN_AOC2023_BIN}/day25
|
||||
DEPENDS aoc2023_day25
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day25)
|
||||
add_dependencies(aoc2023-install aoc2023_day25-install)
|
||||
install(TARGETS aoc2023_day25)
|
||||
|
|
|
@ -21,6 +21,9 @@ using u64 = uint64_t;
|
|||
|
||||
struct Component
|
||||
{
|
||||
Component(BAN::String name)
|
||||
: name(BAN::move(name))
|
||||
{}
|
||||
BAN::String name;
|
||||
BAN::Vector<BAN::String> connections;
|
||||
};
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day3 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day3 ${SOURCES})
|
||||
target_compile_options(aoc2023_day3 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day3 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day3 ban)
|
||||
banan_link_library(aoc2023_day3 libc)
|
||||
|
||||
add_dependencies(aoc2023_day3 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day3-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day3 ${BANAN_AOC2023_BIN}/day3
|
||||
DEPENDS aoc2023_day3
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day3)
|
||||
add_dependencies(aoc2023-install aoc2023_day3-install)
|
||||
install(TARGETS aoc2023_day3)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day4 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day4 ${SOURCES})
|
||||
target_compile_options(aoc2023_day4 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day4 PUBLIC libc ban)
|
||||
banan_link_library(aoc2023_day4 ban)
|
||||
banan_link_library(aoc2023_day4 libc)
|
||||
|
||||
add_dependencies(aoc2023_day4 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day4-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day4 ${BANAN_AOC2023_BIN}/day4
|
||||
DEPENDS aoc2023_day4
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day4)
|
||||
add_dependencies(aoc2023-install aoc2023_day4-install)
|
||||
install(TARGETS aoc2023_day4)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day5 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day5 ${SOURCES})
|
||||
target_compile_options(aoc2023_day5 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day5 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day5 ban)
|
||||
banan_link_library(aoc2023_day5 libc)
|
||||
|
||||
add_dependencies(aoc2023_day5 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day5-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day5 ${BANAN_AOC2023_BIN}/day5
|
||||
DEPENDS aoc2023_day5
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day5)
|
||||
add_dependencies(aoc2023-install aoc2023_day5-install)
|
||||
install(TARGETS aoc2023_day5)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day6 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day6 ${SOURCES})
|
||||
target_compile_options(aoc2023_day6 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day6 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day6 ban)
|
||||
banan_link_library(aoc2023_day6 libc)
|
||||
|
||||
add_dependencies(aoc2023_day6 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day6-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day6 ${BANAN_AOC2023_BIN}/day6
|
||||
DEPENDS aoc2023_day6
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day6)
|
||||
add_dependencies(aoc2023-install aoc2023_day6-install)
|
||||
install(TARGETS aoc2023_day6)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day7 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day7 ${SOURCES})
|
||||
target_compile_options(aoc2023_day7 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day7 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day7 ban)
|
||||
banan_link_library(aoc2023_day7 libc)
|
||||
|
||||
add_dependencies(aoc2023_day7 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day7-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day7 ${BANAN_AOC2023_BIN}/day7
|
||||
DEPENDS aoc2023_day7
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day7)
|
||||
add_dependencies(aoc2023-install aoc2023_day7-install)
|
||||
install(TARGETS aoc2023_day7)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day8 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day8 ${SOURCES})
|
||||
target_compile_options(aoc2023_day8 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day8 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day8 ban)
|
||||
banan_link_library(aoc2023_day8 libc)
|
||||
|
||||
add_dependencies(aoc2023_day8 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day8-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day8 ${BANAN_AOC2023_BIN}/day8
|
||||
DEPENDS aoc2023_day8
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day8)
|
||||
add_dependencies(aoc2023-install aoc2023_day8-install)
|
||||
install(TARGETS aoc2023_day8)
|
||||
|
|
|
@ -45,8 +45,8 @@ i64 puzzle1(FILE* fp)
|
|||
}
|
||||
}
|
||||
|
||||
u32 current = coord_to_u32("AAA"sv);
|
||||
u32 target = coord_to_u32("ZZZ"sv);
|
||||
u32 current = coord_to_u32("AAA"_sv);
|
||||
u32 target = coord_to_u32("ZZZ"_sv);
|
||||
|
||||
i64 steps = 0;
|
||||
for (; current != target; steps++)
|
||||
|
|
|
@ -1,22 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023_day9 CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023_day9 ${SOURCES})
|
||||
target_compile_options(aoc2023_day9 PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023_day9 PUBLIC libc ban)
|
||||
banan_include_headers(aoc2023_day9 ban)
|
||||
banan_link_library(aoc2023_day9 libc)
|
||||
|
||||
add_dependencies(aoc2023_day9 libc-install ban-install)
|
||||
|
||||
add_custom_target(aoc2023_day9-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023_day9 ${BANAN_AOC2023_BIN}/day9
|
||||
DEPENDS aoc2023_day9
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023_day9)
|
||||
add_dependencies(aoc2023-install aoc2023_day9-install)
|
||||
install(TARGETS aoc2023_day9)
|
||||
|
|
|
@ -1,20 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(aoc2023-full CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(aoc2023-full ${SOURCES})
|
||||
target_compile_options(aoc2023-full PUBLIC -O2 -g)
|
||||
target_link_libraries(aoc2023-full PUBLIC libc)
|
||||
add_executable(aoc2023_full ${SOURCES})
|
||||
banan_include_headers(aoc2023_full ban)
|
||||
banan_link_library(aoc2023_full libc)
|
||||
|
||||
add_custom_target(aoc2023-full-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/aoc2023-full ${BANAN_AOC2023_BIN}/full
|
||||
DEPENDS aoc2023-full
|
||||
DEPENDS aoc2023_always
|
||||
)
|
||||
|
||||
add_dependencies(aoc2023 aoc2023-full)
|
||||
add_dependencies(aoc2023-install aoc2023-full-install)
|
||||
install(TARGETS aoc2023_full)
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(cat-mmap CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(cat-mmap ${SOURCES})
|
||||
target_compile_options(cat-mmap PUBLIC -O2 -g)
|
||||
target_link_libraries(cat-mmap PUBLIC libc)
|
||||
banan_link_library(cat-mmap libc)
|
||||
|
||||
add_custom_target(cat-mmap-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cat-mmap ${BANAN_BIN}/
|
||||
DEPENDS cat-mmap
|
||||
)
|
||||
install(TARGETS cat-mmap)
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(cat CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(cat ${SOURCES})
|
||||
target_compile_options(cat PUBLIC -O2 -g)
|
||||
target_link_libraries(cat PUBLIC libc)
|
||||
banan_link_library(cat libc)
|
||||
|
||||
add_custom_target(cat-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cat ${BANAN_BIN}/
|
||||
DEPENDS cat
|
||||
)
|
||||
install(TARGETS cat)
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(chmod CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(chmod ${SOURCES})
|
||||
target_compile_options(chmod PUBLIC -O2 -g)
|
||||
target_link_libraries(chmod PUBLIC libc)
|
||||
banan_link_library(chmod libc)
|
||||
|
||||
add_custom_target(chmod-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/chmod ${BANAN_BIN}/
|
||||
DEPENDS chmod
|
||||
)
|
||||
install(TARGETS chmod)
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(cp CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(cp ${SOURCES})
|
||||
target_compile_options(cp PUBLIC -O2 -g)
|
||||
target_link_libraries(cp PUBLIC libc ban)
|
||||
banan_include_headers(cp ban)
|
||||
banan_link_library(cp libc)
|
||||
|
||||
add_custom_target(cp-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/cp ${BANAN_BIN}/
|
||||
DEPENDS cp
|
||||
)
|
||||
install(TARGETS cp)
|
||||
|
|
|
@ -7,27 +7,22 @@ PROGRAM_NAME=$1
|
|||
mkdir $PROGRAM_NAME
|
||||
|
||||
cat > $PROGRAM_NAME/CMakeLists.txt << EOF
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project($PROGRAM_NAME CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable($PROGRAM_NAME \${SOURCES})
|
||||
target_compile_options($PROGRAM_NAME PUBLIC -O2 -g)
|
||||
target_link_libraries($PROGRAM_NAME PUBLIC libc)
|
||||
banan_link_library($PROGRAM_NAME ban)
|
||||
banan_link_library($PROGRAM_NAME libc)
|
||||
|
||||
add_custom_target($PROGRAM_NAME-install
|
||||
COMMAND \${CMAKE_COMMAND} -E copy \${CMAKE_CURRENT_BINARY_DIR}/$PROGRAM_NAME \${BANAN_BIN}/
|
||||
DEPENDS $PROGRAM_NAME
|
||||
)
|
||||
install(TARGETS $PROGRAM_NAME)
|
||||
EOF
|
||||
|
||||
cat > $PROGRAM_NAME/main.cpp << EOF
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
printf("Hello World\n");
|
||||
}
|
||||
EOF
|
||||
|
|
|
@ -1,16 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(dd CXX)
|
||||
|
||||
set(SOURCES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
add_executable(dd ${SOURCES})
|
||||
target_compile_options(dd PUBLIC -O2 -g)
|
||||
target_link_libraries(dd PUBLIC libc)
|
||||
banan_link_library(dd libc)
|
||||
|
||||
add_custom_target(dd-install
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/dd ${BANAN_BIN}/
|
||||
DEPENDS dd
|
||||
)
|
||||
install(TARGETS dd)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue