sysroot and cross-compiler based build WIP

This commit is contained in:
Justin C. Miller
2019-01-17 00:51:45 -08:00
parent 591ca7c83c
commit 523d0b3b8c
17 changed files with 664 additions and 14 deletions

4
.gitignore vendored
View File

@@ -5,3 +5,7 @@ tags
.gdbinit .gdbinit
popcorn.log popcorn.log
.waf-* .waf-*
*.o
*.a
sysroot
.sconsign*

53
SConstruct Normal file
View File

@@ -0,0 +1,53 @@
from os.path import join
import SCons.Node
def target_from_source_nosplit(node, prefix, suffix, splitext):
return node.dir.Entry(prefix + node.name + suffix)
SCons.Node._target_from_source_map['nosplit'] = target_from_source_nosplit
SCons.Node._target_from_source_map[1] = target_from_source_nosplit
def RGlob(path, pattern):
from os import walk
from itertools import chain
return list(chain.from_iterable([Glob(join(d, pattern)) for d, _, _ in walk(path)]))
def subdirs(path):
from os import listdir
from os.path import isdir, join
return [d for d in listdir(path) if isdir(join(path, d))]
SetOption('implicit_cache', 1)
Decider('MD5-timestamp')
VariantDir('src', 'build', duplicate=0)
env = SConscript('scons/default_env.scons')
target = SConscript('scons/target_env.scons', 'env')
libs = {}
for lib in subdirs('src/libraries'):
libs[lib] = SConscript(join('src/libraries', lib, 'SConscript'), 'target RGlob')
kernel = target.Clone()
kernel.Append(CCFLAGS = [
'-mno-sse',
'-mno-red-zone',
])
kernel.Append(
CPPPATH = [
'src/kernel',
'src/libraries/elf/include',
'src/libraries/initrd/include',
'src/libraries/kutil/include',
],
ASFLAGS = ['-I', 'src/kernel/'],
LIBS = libs.values() + ['c'],
LINKFLAGS = ['-T', File('#src/arch/x86_64/kernel.ld').abspath],
)
kernel.Program(
'popcorn.elf',
RGlob('src/kernel', '*.cpp') +
RGlob('src/kernel', '*.s'))
# vim: ft=python et

85
scons/default_env.scons Normal file
View File

@@ -0,0 +1,85 @@
from subprocess import check_output
target = 'x86_64-elf'
version = check_output("git describe --always", shell=True).strip()
git_sha = check_output("git rev-parse --short HEAD", shell=True).strip()
major, minor, patch_dirty = version.split(".")
dirty = 'dirty' in patch_dirty
patch = patch_dirty.split('-')[0]
defines = {
'GIT_VERSION': r'\"{}\"'.format(version),
'GIT_VERSION_WIDE': r'L\"{}\"'.format(version),
'VERSION_MAJOR': major,
'VERSION_MINOR': minor,
'VERSION_PATCH': patch,
'VERSION_GITSHA': '0x{}{}'.format({True:1}.get(dirty, 0), git_sha),
}
warnings = [
'format=2',
'init-self',
'float-equal',
'inline',
'missing-format-attribute',
'missing-include-dirs',
'switch',
'undef',
'disabled-optimization',
'pointer-arith',
'no-attributes',
'no-sign-compare',
'no-multichar',
'no-div-by-zero',
'no-endif-labels',
'no-pragmas',
'no-format-extra-args',
'no-unused-result',
'no-deprecated-declarations',
'no-unused-function',
'error'
]
asflags = ['-felf64']
asflags += ['-D{}={}'.format(k,v) for k, v in defines.items()]
ccflags = [
'--sysroot={}'.format(Dir('#sysroot').abspath),
]
ccflags += ['-W{}'.format(opt) for opt in warnings]
env = Environment(
#CC = File('#sysroot/bin/' + target + '-gcc').abspath,
#CXX = File('#sysroot/bin/' + target + '-g++').abspath,
LINK = File('#sysroot/bin/' + target + '-ld').abspath,
CC = File('#sysroot/bin/clang').abspath,
CXX = File('#sysroot/bin/clang++').abspath,
#LINK = File('#sysroot/bin/ld.lld').abspath,
AS = File('#sysroot/bin/nasm').abspath,
ASFLAGS = asflags,
CXXFLAGS = [
'-std=c++14',
'-isystem', Dir('#sysroot/include/c++/v1').abspath,
],
CFLAGS = ['-std=c11'],
CCFLAGS = ccflags,
CPPPATH = ['src/include'],
CPPDEFINES = defines,
LINKFLAGS = ['-static'],
LIBPATH = ['#sysroot/lib'],
#CCCOMSTR = ' compile $TARGET',
#CXXCOMSTR = ' compile $TARGET',
#ASCOMSTR = ' assemble $TARGET',
#LINKCOMSTR = ' link $TARGET',
ARCOMSTR = ' archive $TARGET',
RANLIBCOMSTR = ' ranlib $TARGET',
)
Return('env')
# vim: ft=python et

2
scons/no_split_env.scons Normal file
View File

@@ -0,0 +1,2 @@
# vim: ft=python et

47
scons/target_env.scons Normal file
View File

@@ -0,0 +1,47 @@
Import('env')
env = env.Clone()
env.Append(
CCFLAGS = [
'-nodefaultlibs',
'-nostdinc',
'-nostdlib',
#'-nolibc',
'-ffreestanding',
'-fno-omit-frame-pointer',
'-isystem', 'sysroot/include',
'-mcmodel=large',
'-fno-PIC',
],
LINKFLAGS = [
'-g',
'-nostdlib',
#'-znocombreloc',
#'-Bsymbolic',
'-nostartfiles',
],
LIBS = [
#'c++',
#'c++abi',
'unwind',
],
CXXFLAGS = [
#'-nostdlibinc',
'-fno-exceptions',
'-fno-rtti',
'-D_LIBCPP_NO_EXCEPTIONS',
'-D_LIBCPP_HAS_NO_THREADS',
'-D__ELF__',
'-mcmodel=large',
],
)
Return('env')
# vim: ft=python et

255
scripts/build_sysroot_clang.sh Executable file
View File

@@ -0,0 +1,255 @@
#!/usr/bin/env bash
TARGET="x86_64-elf"
NASM_VERSION="2.13.03"
BINUTILS_VERSION="2.31.1"
TOOLS="clang" # lld libunwind libcxxabi libcxx"
PROJECTS="compiler-rt libcxxabi libcxx libunwind"
#RUNTIMES="compiler-rt libcxxabi libcxx libunwind"
set -e
SYSROOT=$(realpath "$(dirname $0)/../sysroot")
WORK=$(realpath "$(dirname $0)/sysroot")
mkdir -p "${SYSROOT}"
mkdir -p "${WORK}"
export CC=clang
export CXX=clang++
if [[ ! -d "${WORK}/nasm-${NASM_VERSION}" ]]; then
echo "Downloading NASM..."
tarball="nasm-${NASM_VERSION}.tar.gz"
curl -sSOL "https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/${tarball}"
tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}"
fi
if [[ ! -d "${WORK}/binutils-${BINUTILS_VERSION}" ]]; then
echo "Downloading binutils..."
tarball="binutils-${BINUTILS_VERSION}.tar.gz"
curl -sSOL "https://ftp.gnu.org/gnu/binutils/${tarball}"
tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}"
fi
if [[ ! -d "${WORK}/llvm" ]]; then
echo "Downloading LLVM..."
git clone -q \
--branch release_70 \
--depth 1 \
"https://git.llvm.org/git/llvm.git" "${WORK}/llvm"
fi
for tool in ${TOOLS}; do
if [[ ! -d "${WORK}/llvm/tools/${tool}" ]]; then
echo "Downloading ${tool}..."
git clone -q \
--branch release_70 \
--depth 1 \
"https://git.llvm.org/git/${tool}.git" "${WORK}/llvm/tools/${tool}"
fi
done
if [[ ! -d "${WORK}/llvm/tools/clang/tools/extra" ]]; then
echo "Downloading clang-tools-extra..."
git clone -q \
--branch release_70 \
--depth 1 \
"https://git.llvm.org/git/clang-tools-extra.git" "${WORK}/llvm/tools/clang/tools/extra"
fi
for proj in ${PROJECTS}; do
if [[ ! -d "${WORK}/llvm/projects/${proj}" ]]; then
echo "Downloading ${proj}..."
git clone -q \
--branch release_70 \
--depth 1 \
"https://git.llvm.org/git/${proj}.git" "${WORK}/llvm/projects/${proj}"
fi
done
for proj in ${RUNTIMES}; do
if [[ ! -d "${WORK}/llvm/runtimes/${proj}" ]]; then
echo "Downloading ${proj}..."
git clone -q \
--branch release_70 \
--depth 1 \
"https://git.llvm.org/git/${proj}.git" "${WORK}/llvm/runtime/${proj}"
fi
done
if [[ ! -d "${WORK}/poplibc" ]]; then
echo "Downloading poplibc..."
git clone \
"https://github.com/justinian/poplibc.git" \
"${WORK}/poplibc"
else
echo "Updating poplibc..."
git -C "${WORK}/poplibc" pull
fi
mkdir -p "${WORK}/build/nasm"
pushd "${WORK}/build/nasm"
echo "Configuring NASM..."
"${WORK}/nasm-${NASM_VERSION}/configure" \
--quiet \
--config-cache \
--prefix="${SYSROOT}" \
--srcdir="${WORK}/nasm-${NASM_VERSION}"
echo "Building NASM..."
(make -j && make install) > nasm_build.log
popd
mkdir -p "${WORK}/build/binutils"
pushd "${WORK}/build/binutils"
echo "Configuring binutils..."
"${WORK}/binutils-${BINUTILS_VERSION}/configure" \
--quiet \
--target="${TARGET}" \
--prefix="${SYSROOT}" \
--with-sysroot \
--disable-nls \
--disable-werror
echo "Building binutils..."
(make -j && make install) > "${WORK}/build/binutils_build.log"
popd
mkdir -p "${WORK}/build/llvm"
pushd "${WORK}/build/llvm"
echo "Configuring LLVM..."
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCLANG_DEFAULT_RTLIB=compiler-rt \
-DCLANG_DEFAULT_STD_C=c11 \
-DCLANG_DEFAULT_STD_CXX=cxx14 \
-DCMAKE_C_COMPILER="clang" \
-DCMAKE_CXX_COMPILER="clang++" \
-DCMAKE_CXX_FLAGS="-Wno-unused-parameter -D_LIBCPP_HAS_NO_ALIGNED_ALLOCATION -D_LIBUNWIND_IS_BAREMETAL=1 -U_LIBUNWIND_SUPPORT_DWARF_UNWIND" \
-DCMAKE_INSTALL_PREFIX="${SYSROOT}" \
-DCMAKE_MAKE_PROGRAM=`which ninja` \
-DDEFAULT_SYSROOT="${SYSROOT}" \
-DLLVM_CONFIG_PATH="${SYSROOT}/bin/llvm-config" \
-DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-elf" \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_INSTALL_PREFIX="${SYSROOT}" \
-DCMAKE_MAKE_PROGRAM=`which ninja` \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS="${WORK}/llvm/projects/libcxxabi/include" \
-DLIBCXX_CXX_ABI_LIBRARY_PATH=lib \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
-DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON \
-DLIBCXX_ENABLE_SHARED=OFF \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
-DLIBCXX_ENABLE_THREADS=OFF \
-DLIBCXX_INCLUDE_BENCHMARKS=OFF \
-DLIBCXX_USE_COMPILER_RT=ON \
-DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF \
-DLIBCXXABI_ENABLE_THREADS=OFF \
-DLIBCXXABI_ENABLE_SHARED=OFF \
-DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON \
-DLIBCXXABI_LIBCXX_PATH="${WORK}/llvm/projects/libcxx" \
-DLIBCXXABI_USE_COMPILER_RT=ON \
-DLIBCXXABI_USE_LLVM_UNWINDER=ON \
-DLIBUNWIND_ENABLE_SHARED=OFF \
-DLIBUNWIND_ENABLE_THREADS=OFF \
-DLIBUNWIND_USE_COMPILER_RT=ON \
-DLLVM_CONFIG_PATH="${SYSROOT}/bin/llvm-config" \
-DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-elf" \
-DLLVM_ENABLE_LIBCXX=ON \
-DLLVM_ENABLE_PIC=OFF \
-DLLVM_ENABLE_THREADS=OFF \
-DLLVM_ENABLE_THREADS=OFF \
-DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
-DLLVM_TARGETS_TO_BUILD="X86" \
${WORK}/llvm > cmake_configure.log
echo "Building LLVM..."
ninja && ninja install
ninja cxx cxxabi compiler-rt
ninja install-compiler-rt install-cxx install-cxxabi
popd
pushd "${WORK}/poplibc"
echo "Building poplibc..."
export CC="${SYSROOT}/bin/clang"
export LD="${SYSROOT}/bin/${TARGET}-ld"
export AR="${SYSROOT}/bin/${TARGET}-ar"
make -j install PREFIX="${SYSROOT}"
popd
#
# mkdir -p ${WORK}/build/llvm
# pushd ${WORK}/build/llvm
#
# cmake -G Ninja \
# -DCLANG_DEFAULT_RTLIB=compiler-rt \
# -DCLANG_DEFAULT_STD_C=c11 \
# -DCLANG_DEFAULT_STD_CXX=cxx14 \
# -DCMAKE_ASM_COMPILER=nasm \
# -DCMAKE_C_COMPILER="clang" \
# -DCMAKE_CXX_COMPILER="clang++" \
# -DDEFAULT_SYSROOT="${SYSROOT}" \
# -DCMAKE_CXX_FLAGS="-v" \
# -DCMAKE_INSTALL_PREFIX="${SYSROOT}" \
# -DCMAKE_LINKER="${SYSROOT}/bin/ld.lld" \
# -DCMAKE_MAKE_PROGRAM=`which ninja` \
# -DCOMPILER_RT_ENABLE_LLD=ON \
# -DLIBCXX_CXX_ABI=libcxxabi \
# -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${WORK}/libcxxabi/include \
# -DLIBCXX_CXX_ABI_LIBRARY_PATH=lib \
# -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=OFF \
# -DLIBCXX_ENABLE_LLD=ON \
# -DLIBCXX_ENABLE_NEW_DELETE_DEFINITIONS=ON \
# -DLIBCXX_ENABLE_SHARED=OFF \
# -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=ON \
# -DLIBCXX_ENABLE_STATIC_UNWINDER=ON \
# -DLIBCXX_ENABLE_THREADS=OFF \
# -DLIBCXX_INCLUDE_BENCHMARKS=OFF \
# -DLIBCXX_USE_COMPILER_RT=ON \
# -DLIBCXXABI_ENABLE_LLD=ON \
# -DLIBCXXABI_ENABLE_NEW_DELETE_DEFINITIONS=OFF \
# -DLIBCXXABI_ENABLE_THREADS=OFF \
# -DLIBCXXABI_ENABLE_SHARED=OFF \
# -DLIBCXXABI_ENABLE_STATIC_UNWINDER=ON \
# -DLIBCXXABI_LIBCXX_PATH=${WORK}/libcxx \
# -DLIBCXXABI_USE_COMPILER_RT=ON \
# -DLIBCXXABI_USE_LLVM_UNWINDER=ON \
# -DLIBUNWIND_ENABLE_LLD=ON \
# -DLIBUNWIND_ENABLE_SHARED=OFF \
# -DLIBUNWIND_ENABLE_THREADS=OFF \
# -DLIBUNWIND_USE_COMPILER_RT=ON \
# -DLLVM_CONFIG_PATH="${SYSROOT}/bin/llvm-config" \
# -DLLVM_DEFAULT_TARGET_TRIPLE="x86_64-unknown-elf" \
# -DLLVM_ENABLE_LIBCXX=ON \
# -DLLVM_ENABLE_LLD=ON \
# -DLLVM_ENABLE_PIC=OFF \
# -DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi;libunwind;compiler-rt" \
# -DLLVM_ENABLE_THREADS=OFF \
# -DLLVM_ENABLE_THREADS=OFF \
# -DLLVM_INSTALL_BINUTILS_SYMLINKS=ON \
# -DLLVM_TARGETS_TO_BUILD="X86" \
# ${WORK}/llvm
#
# ninja && ninja install
# ninja unwind cxx cxxabi compiler-rt
# ninja install-compiler-rt install-unwind install-cxx install-cxxabi
# popd
#
#
#export CC="${SYSROOT}/bin/clang"
#export CXX="${SYSROOT}/bin/clang++"
#export LD="${SYSROOT}/bin/ld.lld"
## -DCOMPILER_RT_BAREMETAL_BUILD=ON \
## -DLIBCXXABI_BAREMETAL=ON \
## -DCMAKE_C_COMPILER="${SYSROOT}/bin/clang" \
## -DCMAKE_CXX_COMPILER="${SYSROOT}/bin/clang++" \
## -DDEFAULT_SYSROOT="${SYSROOT}" \

150
scripts/build_sysroot_gcc.sh Executable file
View File

@@ -0,0 +1,150 @@
#!/usr/bin/env bash
TARGET="x86_64-elf"
NASM_VERSION="2.14.02"
GCC_VERSION="7.4.0"
BINUTILS_VERSION="2.31.1"
SYSROOT=$(realpath "$(dirname $0)/../sysroot")
WORK=$(realpath "$(dirname $0)/sysroot")
set -e
mkdir -p "${SYSROOT}"
mkdir -p "${WORK}"
function build_nasm() {
if [[ ! -d "${WORK}/nasm-${NASM_VERSION}" ]]; then
echo "Downloading NASM..."
tarball="nasm-${NASM_VERSION}.tar.gz"
curl -sSOL "https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/${tarball}"
tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}"
fi
mkdir -p "${WORK}/build/nasm"
pushd "${WORK}/build/nasm"
echo "Configuring NASM..."
"${WORK}/nasm-${NASM_VERSION}/configure" \
--quiet \
--config-cache \
--disable-werror \
--prefix="${SYSROOT}" \
--srcdir="${WORK}/nasm-${NASM_VERSION}"
echo "Building NASM..."
(make -j && make install) > "${WORK}/build/nasm_build.log"
popd
}
function build_binutils() {
if [[ ! -d "${WORK}/binutils-${BINUTILS_VERSION}" ]]; then
echo "Downloading binutils..."
tarball="binutils-${BINUTILS_VERSION}.tar.gz"
curl -sSOL "https://ftp.gnu.org/gnu/binutils/${tarball}"
tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}"
fi
mkdir -p "${WORK}/build/binutils"
pushd "${WORK}/build/binutils"
echo "Configuring binutils..."
"${WORK}/binutils-${BINUTILS_VERSION}/configure" \
--quiet \
--target="${TARGET}" \
--prefix="${SYSROOT}" \
--with-sysroot \
--disable-nls \
--disable-werror
echo "Building binutils..."
(make -j && make install) > "${WORK}/build/binutils_build.log"
popd
}
function build_gcc() {
if [[ ! -d "${WORK}/gcc-${GCC_VERSION}" ]]; then
echo "Downloading GCC..."
tarball="gcc-${GCC_VERSION}.tar.gz"
curl -sSOL "https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/${tarball}"
tar xzf "${tarball}" -C "${WORK}" && rm "${tarball}"
# no-red-zone support version of libgcc
echo "MULTILIB_OPTIONS += mno-red-zone" > "${WORK}/gcc-${GCC_VERSION}/gcc/config/i386/t-${TARGET}"
echo "MULTILIB_DIRNAMES += no-red-zone" >> "${WORK}/gcc-${GCC_VERSION}/gcc/config/i386/t-${TARGET}"
cat <<EOF >> "${WORK}/gcc-${GCC_VERSION}/gcc/config.gcc"
case \${target} in
${TARGET})
tmake_file="\${tmake_file} i386/t-${TARGET}"
;;
esac
EOF
fi
mkdir -p "${WORK}/build/gcc"
pushd "${WORK}/build/gcc"
echo "Configuring GCC..."
"${WORK}/gcc-${GCC_VERSION}/configure" \
--quiet \
--target="${TARGET}" \
--prefix="${SYSROOT}" \
--disable-nls \
--enable-languages=c,c++ \
--without-headers
echo "Building GCC..."
(make -j all-gcc && make -j all-target-libgcc && make install-gcc && make install-target-libgcc) > "${WORK}/build/gcc_build.log"
popd
}
function build_libstdcxx() {
mkdir -p "${WORK}/build/libstdcxx"
pushd "${WORK}/build/libstdcxx"
echo "Configuring libstdc++..."
"${WORK}/gcc-${GCC_VERSION}/libstdc++-v3/configure" \
--target="${TARGET}" \
--prefix="${SYSROOT}" \
--disable-nls \
--disable-multilib \
--with-newlib
--disable-libstdcxx-threads
echo "Building libstdc++..."
(make -j && make install) > "${WORK}/build/libstdcxx_build.log"
popd
}
function build_libc() {
if [[ ! -d "${WORK}/poplibc" ]]; then
echo "Downloading poplibc..."
git clone \
"https://github.com/justinian/poplibc.git" \
"${WORK}/poplibc"
else
echo "Updating poplibc..."
git -C "${WORK}/poplibc" pull
fi
pushd "${WORK}/poplibc"
echo "Building poplibc..."
make install PREFIX="${SYSROOT}"
popd
}
function update_links() {
for exe in `ls "${SYSROOT}/bin/${TARGET}-"*`; do
base=$(echo "$exe" | sed -e "s/${TARGET}-//")
ln -fs "${exe}" "${base}"
done
}
build_nasm
build_binutils
build_gcc
update_links
export PATH="${SYSROOT}/bin:${PATH}"
build_libc

View File

@@ -33,5 +33,18 @@ SECTIONS
__bss_end = .; __bss_end = .;
} }
.eh_frame : {
__eh_frame_start = .;
KEEP(*(.eh_frame))
__eh_frame_end = .;
}
.eh_frame_hdr : {
KEEP(*(.eh_frame_hdr))
}
__eh_frame_hdr_start = SIZEOF(.eh_frame_hdr) > 0 ? ADDR(.eh_frame_hdr) : 0;
__eh_frame_hdr_end = SIZEOF(.eh_frame_hdr) > 0 ? . : 0;
kernel_end = ALIGN(4096); kernel_end = ALIGN(4096);
} }

View File

@@ -18,3 +18,9 @@ __kernel_assert(const char *file, unsigned line, const char *message)
__asm__ ( "int $0e7h" ); __asm__ ( "int $0e7h" );
while (1) __asm__ ("hlt"); while (1) __asm__ ("hlt");
} }
extern "C" [[noreturn]] void
__assert_fail(const char *message, const char *file, unsigned int line, const char *function)
{
__kernel_assert(file, line, message);
}

View File

@@ -3,7 +3,6 @@
#include "kutil/memory.h" #include "kutil/memory.h"
#include "console.h" #include "console.h"
#include "font.h" #include "font.h"
#include "memory.h"
#include "screen.h" #include "screen.h"
#include "serial.h" #include "serial.h"

View File

@@ -1,7 +1,6 @@
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "ahci/driver.h"
#include "kutil/assert.h" #include "kutil/assert.h"
#include "kutil/memory.h" #include "kutil/memory.h"
#include "acpi_tables.h" #include "acpi_tables.h"
@@ -10,7 +9,6 @@
#include "device_manager.h" #include "device_manager.h"
#include "interrupts.h" #include "interrupts.h"
#include "log.h" #include "log.h"
#include "memory.h"
#include "page_manager.h" #include "page_manager.h"

View File

@@ -3,17 +3,17 @@ extern g_gdtr
global idt_write global idt_write
idt_write: idt_write:
lidt [rel g_idtr] lidt [g_idtr]
ret ret
global idt_load global idt_load
idt_load: idt_load:
sidt [rel g_idtr] sidt [g_idtr]
ret ret
global gdt_write global gdt_write
gdt_write: gdt_write:
lgdt [rel g_gdtr] lgdt [g_gdtr]
mov ax, si ; second arg is data segment mov ax, si ; second arg is data segment
mov ds, ax mov ds, ax
mov es, ax mov es, ax
@@ -30,6 +30,6 @@ gdt_write:
global gdt_load global gdt_load
gdt_load: gdt_load:
sgdt [rel g_gdtr] sgdt [g_gdtr]
ret ret

View File

@@ -13,7 +13,6 @@
#include "io.h" #include "io.h"
#include "kernel_data.h" #include "kernel_data.h"
#include "log.h" #include "log.h"
#include "memory.h"
#include "page_manager.h" #include "page_manager.h"
#include "scheduler.h" #include "scheduler.h"
#include "screen.h" #include "screen.h"

View File

@@ -0,0 +1,12 @@
Import('target')
env = target.Clone()
env.Append(
CPPPATH = ['.', 'include', '#src/libraries/kutil/include'],
)
lib = env.Library('elf', Glob('*.cpp'))
Return('lib')
# vim: ft=python et

View File

@@ -0,0 +1,12 @@
Import('target')
env = target.Clone()
env.Append(
CPPPATH = ['.', 'include', '#src/libraries/kutil/include'],
)
lib = env.Library('initrd', Glob('*.cpp'))
Return('lib')
# vim: ft=python et

View File

@@ -0,0 +1,12 @@
Import('target')
env = target.Clone()
env.Append(
CPPPATH = ['.', 'include'],
)
lib = env.Library('kutil', Glob('*.cpp'))
Return('lib')
# vim: ft=python et

View File

@@ -1,12 +1,15 @@
#include "kutil/memory.h" #include "kutil/memory.h"
#include "kutil/memory_manager.h" #include "kutil/memory_manager.h"
#include "kutil/type_macros.h"
__weak void * operator new (size_t, void *p) noexcept { return p; } namespace std {
__weak void * operator new (size_t n) { return kutil::malloc(n); } enum class __attribute__ ((__type_visibility("default"))) align_val_t : size_t { };
__weak void * operator new[] (size_t n) { return kutil::malloc(n); } }
__weak void operator delete (void *p) noexcept { return kutil::free(p); }
__weak void operator delete[] (void *p) noexcept { return kutil::free(p); } void * operator new(size_t n, std::align_val_t) { return kutil::malloc(n); }
void * operator new (size_t n) { return kutil::malloc(n); }
void * operator new[] (size_t n) { return kutil::malloc(n); }
void operator delete (void *p) noexcept { return kutil::free(p); }
void operator delete[] (void *p) noexcept { return kutil::free(p); }
namespace kutil { namespace kutil {