Added target for userspace stdlib.

This commit is contained in:
Patrick 2024-02-02 01:50:56 +01:00
parent 99b1252f5d
commit c43e8ebd6c
6 changed files with 74 additions and 4 deletions

3
.gitignore vendored
View File

@ -1,6 +1,9 @@
# Log files # Log files
*.log *.log
# Variant Folder for Stdlib
.stdlib_variant
# Staging Folder # Staging Folder
staging/ staging/

View File

@ -3,7 +3,9 @@
#define BAD_APPLE_OS_EXCEPTION_INCLUDED #define BAD_APPLE_OS_EXCEPTION_INCLUDED
#include <cstdlib> #include <cstdlib>
#if defined(__baos_kernel_source__)
#include "os/panic.hpp" #include "os/panic.hpp"
#endif
#if defined(__cpp_exceptions) #if defined(__cpp_exceptions)
#define __ba_throw throw #define __ba_throw throw
@ -32,7 +34,13 @@ private:
public: public:
[[noreturn]] ExceptionAbortHelper& operator=(const std::exception& ex) noexcept [[noreturn]] ExceptionAbortHelper& operator=(const std::exception& ex) noexcept
{ {
#if defined(__baos_kernel_source__)
panicf("Uncaught exception with message \"%s\" at %s:%d.", ex.what(), mFile, mLine); panicf("Uncaught exception with message \"%s\" at %s:%d.", ex.what(), mFile, mLine);
#else
// TODO!!!
std::abort();
__builtin_unreachable();
#endif
} }
ExceptionAbortHelper& operator()(const char* file, int line) noexcept ExceptionAbortHelper& operator()(const char* file, int line) noexcept

View File

@ -85,7 +85,7 @@ struct type_identity
}; };
template<typename T> template<typename T>
using type_identity_t = type_identity<T>::type; using type_identity_t = typename type_identity<T>::type;
template<typename T, T v> template<typename T, T v>
struct integral_constant struct integral_constant

View File

@ -1,13 +1,37 @@
Import('env') Import('env')
stdlib_sources = Split(''' shared_sources = Split('''
src/assert.cpp src/assert.cpp
src/stdio.cpp src/stdio.cpp
src/stdlib.cpp src/stdlib.cpp
src/string.cpp src/string.cpp
''') ''')
env.Append(KERNEL_SOURCES = [env.File(f) for f in stdlib_sources]) kernel_sources = shared_sources
env.Append(KERNEL_SOURCES = [env.File(f) for f in kernel_sources])
### Stdlib
stdlib_env = env.Clone()
stdlib_env['AS'] = 'x86_64-baos-elf-as'
stdlib_env['CC'] = 'x86_64-baos-elf-gcc'
stdlib_env['CXX'] = 'x86_64-baos-elf-g++'
stdlib_env['LD'] = 'x86_64-baos-elf-g++'
stdlib_env.Append(CXXFLAGS = ['-fno-exceptions', '-fno-rtti', '-std=c++20'])
stdlib_env.Append(CPPPATH = ['#targets/_any/bastl/include', '#targets/_any/stdlib/include', '#targets/_any/kernel/include'])
stdlib_sources = Split('''
src/crt0.s
''')
for src in shared_sources:
new_src = stdlib_env.File(f'#.stdlib_variant/{stdlib_env.File(src).name}').abspath
stdlib_env.Command(new_src, src, Copy("$TARGET", "$SOURCE"))
stdlib_sources.append(new_src)
lib_stdlib = stdlib_env.StaticLibrary(
target = stdlib_env.File('#stdlib.a'),
source = stdlib_sources
)
stdlib_env.Default(lib_stdlib)
Return('env') Return('env')

View File

@ -0,0 +1,30 @@
.section .text
.global _start
.type _start, @function
_start:
# set up end of stack-frame list
movq $0, %rbp
pushq %rbp
pushq %rbp
movq %rsp, %rbp
# preserve argc and argv
pushq %rsi
pushq %rdi
# init C library
call _init
# restore argc and argv
popq %rdi
popq %rsi
# call main
call main
# exit by calling exit
movl %eax, %edi # exit code (return value of main)
call exit
.size _start, . - _start

View File

@ -2,13 +2,14 @@
#include <stdio.h> #include <stdio.h>
#include <algorithm> #include <algorithm>
#include <string>
#include <stdarg.h> #include <stdarg.h>
#include "os/tty.hpp"
#include "os/tools/printf_helper.hpp" #include "os/tools/printf_helper.hpp"
#include "os/tools/ringbuffer.hpp" #include "os/tools/ringbuffer.hpp"
#if defined(__baos_kernel_source__) #if defined(__baos_kernel_source__)
#include "os/serial.hpp" #include "os/serial.hpp"
#include "os/tty.hpp"
#else #else
#include "os/syscall.hpp" #include "os/syscall.hpp"
#endif #endif
@ -103,10 +104,14 @@ class StdinFile : public __file
public: public:
bool underflow() noexcept override bool underflow() noexcept override
{ {
#if defined(__baos_kernel_source__)
for (char chr : tty::readLine()) { for (char chr : tty::readLine()) {
mBuffer.append(chr); mBuffer.append(chr);
} }
return true; return true;
#else
return false; // TODO!!!
#endif
} }
}; };
StdinFile gStdin; StdinFile gStdin;