Added options to compile stdlib and init executable.
This commit is contained in:
@@ -11,5 +11,6 @@ env.Append(KERNEL_SOURCES = [env.File(f) for f in any_target_sources])
|
||||
env = SConscript('bastl/SConscript', exports = 'env')
|
||||
env = SConscript('kernel/SConscript', exports = 'env')
|
||||
env = SConscript('stdlib/SConscript', exports = 'env')
|
||||
env = SConscript('init/SConscript', exports = 'env')
|
||||
|
||||
Return('env')
|
||||
23
targets/_any/init/SConscript
Normal file
23
targets/_any/init/SConscript
Normal file
@@ -0,0 +1,23 @@
|
||||
|
||||
Import('env')
|
||||
|
||||
init_sources = Split('''
|
||||
src/main.cpp
|
||||
''')
|
||||
|
||||
init_env = env.Clone()
|
||||
init_env['AS'] = 'x86_64-elf-baos-as'
|
||||
init_env['CC'] = 'x86_64-elf-baos-gcc'
|
||||
init_env['CXX'] = 'x86_64-elf-baos-g++'
|
||||
init_env['LD'] = 'x86_64-elf-baos-g++'
|
||||
init_env.Append(CXXFLAGS = ['-fno-exceptions', '-fno-rtti', '-std=c++20'])
|
||||
init_env.Append(CPPPATH = ['#targets/_any/bastl/include', '#targets/_any/stdlib/include', '#targets/_any/kernel/include'])
|
||||
|
||||
prog_init = init_env.Program(
|
||||
target = f'#sysroot_{init_env["TARGET_ARCH"]}/bin/init',
|
||||
source = init_sources,
|
||||
LIBS = [init_env.File('#stdlib/libc.a')]
|
||||
)
|
||||
init_env.Alias('init', prog_init)
|
||||
|
||||
Return('env')
|
||||
8
targets/_any/init/src/main.cpp
Normal file
8
targets/_any/init/src/main.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
return 0;
|
||||
}
|
||||
@@ -16,24 +16,23 @@ stdlib_sources = Split(f'''
|
||||
|
||||
env.Append(KERNEL_SOURCES = [env.File(f) for f in stdlib_sources])
|
||||
|
||||
if env['BUILD_TARGET'] == 'stdlib':
|
||||
### Stdlib
|
||||
stdlib_env = env.Clone()
|
||||
stdlib_env['AS'] = 'x86_64-elf-baos-as'
|
||||
stdlib_env['CC'] = 'x86_64-elf-baos-gcc'
|
||||
stdlib_env['CXX'] = 'x86_64-elf-baos-g++'
|
||||
stdlib_env['LD'] = 'x86_64-elf-baos-g++'
|
||||
stdlib_env['OBJSUFFIX'] = f'.baos{stdlib_env["OBJSUFFIX"]}'
|
||||
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
|
||||
stdlib_env = env.Clone()
|
||||
stdlib_env['AS'] = 'x86_64-elf-baos-as'
|
||||
stdlib_env['CC'] = 'x86_64-elf-baos-gcc'
|
||||
stdlib_env['CXX'] = 'x86_64-elf-baos-g++'
|
||||
stdlib_env['LD'] = 'x86_64-elf-baos-g++'
|
||||
stdlib_env['OBJSUFFIX'] = f'.baos{stdlib_env["OBJSUFFIX"]}'
|
||||
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'])
|
||||
|
||||
lib_stdlib = stdlib_env.StaticLibrary(
|
||||
target = stdlib_env.File('#stdlib/libc.a'),
|
||||
source = stdlib_sources
|
||||
)
|
||||
crti_o = stdlib_env.Object(target = '#stdlib/crti.o', source = stdlib_env['CRTI_PATH'])
|
||||
crtn_o = stdlib_env.Object(target = '#stdlib/crtn.o', source = stdlib_env['CRTN_PATH'])
|
||||
crt0_o = stdlib_env.Object(target = '#stdlib/crt0.o', source = stdlib_env['CRT0_PATH'])
|
||||
stdlib_env.Default([lib_stdlib, crti_o, crtn_o, crt0_o])
|
||||
lib_stdlib = stdlib_env.StaticLibrary(
|
||||
target = stdlib_env.File('#stdlib/libc.a'),
|
||||
source = stdlib_sources
|
||||
)
|
||||
crti_o = stdlib_env.Object(target = '#stdlib/crti.o', source = stdlib_env['CRTI_PATH'])
|
||||
crtn_o = stdlib_env.Object(target = '#stdlib/crtn.o', source = stdlib_env['CRTN_PATH'])
|
||||
crt0_o = stdlib_env.Object(target = '#stdlib/crt0.o', source = stdlib_env['CRT0_PATH'])
|
||||
stdlib_env.Alias('stdlib', [lib_stdlib, crti_o, crtn_o, crt0_o])
|
||||
|
||||
Return('env')
|
||||
|
||||
@@ -2,9 +2,13 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(__baos_kernel_source__)
|
||||
#include "os/memory.hpp"
|
||||
#include "os/syscall.hpp"
|
||||
#include "os/tty.hpp"
|
||||
#else
|
||||
#include "os/syscall.hpp"
|
||||
#endif
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -39,16 +43,21 @@ extern "C"
|
||||
{
|
||||
void abort()
|
||||
{
|
||||
#if defined(__baos_kernel_source__)
|
||||
tty::write("Abort called!");
|
||||
__asm__ volatile("hlt");
|
||||
while(true) {};
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
exit(-1); // TODO
|
||||
#endif
|
||||
}
|
||||
|
||||
void exit(int exitCode) noexcept
|
||||
{
|
||||
#if !defined(__baos_kernel_source__)
|
||||
baos::doSyscall(baos::Syscall::EXIT, exitCode);
|
||||
__builtin_unreachable();
|
||||
#else
|
||||
abort(); // no exit in kernel!
|
||||
#endif
|
||||
@@ -93,6 +102,7 @@ void* malloc(size_t size) noexcept
|
||||
prevBlock = block;
|
||||
}
|
||||
|
||||
#if defined(__baos_kernel_source__)
|
||||
baos::PageRange pages = baos::allocatePages({
|
||||
.numPages = std::max(1ul, baos::bytesToPages(size, /* bigPages = */ true)),
|
||||
.bigPages = true
|
||||
@@ -108,6 +118,9 @@ void* malloc(size_t size) noexcept
|
||||
gNextBlock = newBlock;
|
||||
|
||||
return malloc(size);
|
||||
#else
|
||||
return nullptr; // TODO!
|
||||
#endif
|
||||
}
|
||||
|
||||
void free(void* memory) noexcept
|
||||
|
||||
Reference in New Issue
Block a user