Skip to content

Resolve "Create XS Standard Library" #382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Kernel/Applications/primes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/
#include <stddef.h>
#include <Library/Bitset.hpp>
#include <XS/Bitset.hpp>
#include <Scheduler/tasks.hpp>
#include <Applications/primes.hpp>
#include <Devices/Graphics/console.hpp>
Expand All @@ -20,7 +20,7 @@ namespace Apps {
#define PRIME_MAX_SQRT 4000
#define PRIME_MAX (PRIME_MAX_SQRT * PRIME_MAX_SQRT)
#define PRIMES_SIZE (PRIME_MAX / (sizeof(size_t) * CHAR_BIT))
static Bitset<PRIMES_SIZE> map(SIZE_MAX);
static XS::Bitset<PRIMES_SIZE> map(SIZE_MAX);

static size_t prime_current;

Expand Down
2 changes: 1 addition & 1 deletion Kernel/Bootloader/Arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
*/
#pragma once
#include <Library/LinkedList.hpp>
#include <XS/LinkedList.hpp>

#define MAX_ARGUMENT_LEN 32
#define KERNEL_PARAM(name, arg, callback) \
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Devices/Serial/rs232.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <Arch/Arch.hpp>
#include <Devices/Serial/rs232.hpp>
#include <Library/RingBuffer.hpp>
#include <XS/RingBuffer.hpp>
#include <Library/stdio.hpp>
#include <Library/string.hpp>
#include <Locking/RAII.hpp>
Expand All @@ -39,7 +39,7 @@
namespace RS232 {

static uint16_t rs_232_port_base;
static RingBuffer<char, 1024> ring;
static XS::RingBuffer<char, 1024> ring;
static Mutex mutex_rs232("rs232");

static int received();
Expand Down
4 changes: 2 additions & 2 deletions Kernel/Memory/Physical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#pragma once

#include <Arch/Memory.hpp>
#include <Library/Bitset.hpp>
#include <XS/Bitset.hpp>
#include <Memory/MemorySection.hpp>
#include <Logger.hpp>
#include <stddef.h>
Expand Down Expand Up @@ -103,7 +103,7 @@ class PhysicalManager {
}

private:
Bitset<MEM_BITMAP_SIZE> m_memory;
XS::Bitset<MEM_BITMAP_SIZE> m_memory;
};

}
4 changes: 2 additions & 2 deletions Kernel/Memory/paging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <Arch/Arch.hpp>
#include <Arch/Memory.hpp>
#include <Bootloader/Arguments.hpp>
#include <Library/Bitset.hpp>
#include <XS/Bitset.hpp>
#include <Locking/RAII.hpp>
#include <Library/stdio.hpp>
#include <Library/string.hpp>
Expand All @@ -30,7 +30,7 @@ namespace Memory {
static Mutex pagingLock("paging");

static Physical::PhysicalManager physical;
static Bitset<MEM_BITMAP_SIZE> mappedPages;
static XS::Bitset<MEM_BITMAP_SIZE> mappedPages;

static uintptr_t pageDirectoryAddress;
static struct Arch::Memory::Table* pageDirectoryVirtual[ARCH_PAGE_DIR_ENTRIES];
Expand Down
7 changes: 6 additions & 1 deletion Kernel/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ env = env.Clone()
linkerscript = env.File('Arch/$ARCH/linker.ld')
env.Append(
LINKSCRIPT=linkerscript,
CPPDEFINES={
'__xyris__': None,
'_kernel__': None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a leading underscore

},
CXXFLAGS=[
'-fanalyzer',
],
Expand Down Expand Up @@ -48,8 +52,9 @@ kernel = env.Program(
crtn,
]),
LIBS=[
# 'xs',
'gcc',
'alloc'
'alloc',
],
)

Expand Down
13 changes: 13 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ env = Environment(
'VER_NAME': '\\"$VERSION_NAME\\"',
},
CPPPATH=[
'#',
'#Kernel',
'#Thirdparty',
'#Libraries',
Expand Down Expand Up @@ -141,6 +142,17 @@ if 'docs' not in COMMAND_LINE_TARGETS:
kernel_targets_debug = []
kernel_targets_release = []
for target_env in kernel_environments:
# TODO: Uncomment as soon as there's source files in XS
#
# libxs = target_env.SConscript(
# 'XS/SConscript',
# variant_dir='$BUILD_DIR/libxs',
# duplicate=0,
# exports={
# 'env': target_env
# },
# )
# Default(libxs)
liballoc = target_env.SConscript(
'Libraries/liballoc/SConscript',
variant_dir='$BUILD_DIR/liballoc',
Expand Down Expand Up @@ -226,6 +238,7 @@ env = Environment(
'-ftest-coverage',
],
CPPPATH=[
'#',
'#Tests',
'#Kernel',
'#Thirdparty',
Expand Down
6 changes: 3 additions & 3 deletions Tests/test-lib/test-linkedlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
*/
#include <catch2/catch.hpp>
// Linked list is header-only template
#include <Library/LinkedList.hpp>
#include <XS/LinkedList.hpp>

TEST_CASE("linked list operations", "[linkedlist]") {
LinkedList::LinkedList<uint8_t> list;
XS::LinkedList<uint8_t> list;
// Ensure the constructor sets the head properly
SECTION("constructor") {
LinkedList::LinkedList<uint8_t> list2 = LinkedList::LinkedList<uint8_t>(0);
XS::LinkedList<uint8_t> list2 = XS::LinkedList<uint8_t>(0);
auto node = list2.Head();
REQUIRE(node != NULL);
REQUIRE(node->Data() == 0);
Expand Down
4 changes: 4 additions & 0 deletions Kernel/Library/Bitset.hpp → XS/Bitset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <stddef.h>
#include <stdint.h>

namespace XS {

template<size_t S>
class Bitset {
public:
Expand Down Expand Up @@ -164,3 +166,5 @@ class Bitset {
return bit % TypeSize();
}
};

} // !namespace XS
4 changes: 2 additions & 2 deletions Kernel/Library/LinkedList.hpp → XS/LinkedList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <stddef.h>
#include <stdint.h>

namespace LinkedList {
namespace XS {

template<typename T>
class LinkedListNode {
Expand Down Expand Up @@ -297,4 +297,4 @@ class LinkedList {
size_t count;
};

} // !namespace LinkedList
} // !namespace XS
8 changes: 6 additions & 2 deletions Kernel/Library/RingBuffer.hpp → XS/RingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
*/
#pragma once

#include <Library/errno.hpp> // FIXME: Refactor this out
#include <stdint.h>
#include <Library/errno.hpp>

template <typename T, size_t S>
namespace XS {

template<typename T, size_t S>
class RingBuffer {
public:
/**
Expand Down Expand Up @@ -181,3 +183,5 @@ class RingBuffer {
size_t length;
int error;
};

} // !namespace XS
12 changes: 12 additions & 0 deletions XS/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Import('env')

env = env.Clone()

sources = env.RecursiveGlob(root='.', extensions=['.cpp'])
libxs = env.StaticLibrary(
Flatten([
sources
])
)

Return('libxs')