Added target for userspace stdlib.
This commit is contained in:
parent
99b1252f5d
commit
c43e8ebd6c
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,6 +1,9 @@
|
||||
# Log files
|
||||
*.log
|
||||
|
||||
# Variant Folder for Stdlib
|
||||
.stdlib_variant
|
||||
|
||||
# Staging Folder
|
||||
staging/
|
||||
|
||||
|
@ -3,7 +3,9 @@
|
||||
#define BAD_APPLE_OS_EXCEPTION_INCLUDED
|
||||
|
||||
#include <cstdlib>
|
||||
#if defined(__baos_kernel_source__)
|
||||
#include "os/panic.hpp"
|
||||
#endif
|
||||
|
||||
#if defined(__cpp_exceptions)
|
||||
#define __ba_throw throw
|
||||
@ -32,7 +34,13 @@ private:
|
||||
public:
|
||||
[[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);
|
||||
#else
|
||||
// TODO!!!
|
||||
std::abort();
|
||||
__builtin_unreachable();
|
||||
#endif
|
||||
}
|
||||
|
||||
ExceptionAbortHelper& operator()(const char* file, int line) noexcept
|
||||
|
@ -85,7 +85,7 @@ struct type_identity
|
||||
};
|
||||
|
||||
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>
|
||||
struct integral_constant
|
||||
|
@ -1,13 +1,37 @@
|
||||
|
||||
Import('env')
|
||||
|
||||
stdlib_sources = Split('''
|
||||
shared_sources = Split('''
|
||||
src/assert.cpp
|
||||
src/stdio.cpp
|
||||
src/stdlib.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')
|
||||
|
30
targets/_any/stdlib/src/crt0.s
Normal file
30
targets/_any/stdlib/src/crt0.s
Normal 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
|
@ -2,13 +2,14 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <stdarg.h>
|
||||
#include "os/tty.hpp"
|
||||
#include "os/tools/printf_helper.hpp"
|
||||
#include "os/tools/ringbuffer.hpp"
|
||||
|
||||
#if defined(__baos_kernel_source__)
|
||||
#include "os/serial.hpp"
|
||||
#include "os/tty.hpp"
|
||||
#else
|
||||
#include "os/syscall.hpp"
|
||||
#endif
|
||||
@ -103,10 +104,14 @@ class StdinFile : public __file
|
||||
public:
|
||||
bool underflow() noexcept override
|
||||
{
|
||||
#if defined(__baos_kernel_source__)
|
||||
for (char chr : tty::readLine()) {
|
||||
mBuffer.append(chr);
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
return false; // TODO!!!
|
||||
#endif
|
||||
}
|
||||
};
|
||||
StdinFile gStdin;
|
||||
|
Loading…
x
Reference in New Issue
Block a user