Added options to compile stdlib and init executable.
This commit is contained in:
parent
c2a40a8104
commit
3ec4fa78b4
14
SConstruct
14
SConstruct
@ -11,30 +11,18 @@ AddOption(
|
||||
action = 'store',
|
||||
default = 'x86_64'
|
||||
)
|
||||
AddOption(
|
||||
'--target',
|
||||
dest = 'target',
|
||||
type = 'choice',
|
||||
choices = ('os', 'stdlib'),
|
||||
nargs = 1,
|
||||
action = 'store',
|
||||
default = 'os'
|
||||
)
|
||||
|
||||
arch = GetOption('arch')
|
||||
target = GetOption('target')
|
||||
|
||||
env = Environment(tools = ['default', 'compilation_db'], ENV = os.environ) # TODO inheriting the environment is not a best practice
|
||||
env.Append(CCFLAGS = ['-g', '-O0', '-fno-stack-protector'])
|
||||
env.Append(CPPDEFINES = ['BASTL_EXTENSIONS=1'])
|
||||
env['BUILD_TARGET'] = target
|
||||
env['TARGET_ARCH'] = arch
|
||||
# env.Append(CCFLAGS = ['-O2'])
|
||||
|
||||
env['ISO_FILES'] = []
|
||||
env = SConscript('targets/_any/SConscript', exports = 'env')
|
||||
if env['BUILD_TARGET'] == 'os':
|
||||
env = SConscript(f'targets/{arch}/SConscript', exports = 'env')
|
||||
env = SConscript(f'targets/{arch}/SConscript', exports = 'env')
|
||||
|
||||
comp_db = env.CompilationDatabase(target = '#compile_commands.json')
|
||||
env.Default(comp_db)
|
||||
|
@ -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
|
||||
|
@ -42,7 +42,6 @@ prog_kernel = kernel_env.Program(
|
||||
source = kernel_sources
|
||||
)
|
||||
kernel_env.Depends(prog_kernel, [crti_o, crtn_o] + kernel_sources)
|
||||
kernel_env.Default(prog_kernel)
|
||||
|
||||
x86_64_iso_files = [
|
||||
{
|
||||
@ -80,7 +79,6 @@ prog_loader = uefi_env.Program(
|
||||
target = loader_target,
|
||||
source = loader_sources
|
||||
)
|
||||
uefi_env.Default(prog_loader)
|
||||
|
||||
### Bootable Image
|
||||
def runcmd(*args, **kwargs):
|
||||
@ -125,7 +123,8 @@ cmd_iso = env.Command(
|
||||
source = [cmd_image],
|
||||
action = build_iso
|
||||
)
|
||||
env.Default(cmd_iso)
|
||||
alias_os = env.Alias('os', [cmd_iso])
|
||||
env.Default(alias_os)
|
||||
|
||||
# finally update the environment
|
||||
env.Append(ISO_FILES = x86_64_iso_files)
|
||||
|
Loading…
x
Reference in New Issue
Block a user