├── .gitignore
├── BUILD.go
├── CMakeLists.txt
├── LICENSE
├── LICENSE.RUNTIME
├── MODULE
├── README.md
├── boot
├── bootinfo.hh
├── linux-x86_64
│ ├── BUILD.go
│ ├── CMakeLists.txt
│ ├── crt0.S
│ ├── crt1.S
│ ├── crt4.S
│ ├── io.cc
│ ├── kernel.ld
│ ├── setup.cc
│ ├── syscall.h
│ └── toolchain.cmake
├── raspi3
│ ├── BUILD.go
│ ├── CMakeLists.txt
│ ├── crt0.S
│ ├── io.cc
│ ├── kernel.ld
│ ├── setup.cc
│ └── toolchain.cmake
└── x86_64
│ ├── BUILD.go
│ ├── CMakeLists.txt
│ ├── crt0.S
│ ├── crt1.S
│ ├── crt4.S
│ ├── io.cc
│ ├── kernel.ld
│ ├── multiboot.cc
│ ├── setup.cc
│ └── toolchain.cmake
├── build-cross-compiler.sh
├── build-dbt-cross-compiler
├── BUILD-go
│ ├── aarch64-elf
│ │ └── TEMPLATE-BUILD.go
│ └── x86_64-elf
│ │ └── TEMPLATE-BUILD.go
└── build-dbt-cross-compiler.sh
├── cmake
└── Kernel.cmake
├── io
├── BUILD.go
├── CMakeLists.txt
├── io.cc
├── io.hh
├── memory.hh
├── printf.cc
└── printf.hh
├── libruncxx
├── BUILD.go
├── CMakeLists.txt
├── dtors.cc
├── eh_alloc.cc
├── eh_globals.cc
├── exit.cc
├── guard.cc
├── memory.cc
└── string.cc
├── libsupcxx
├── include
│ ├── BUILD.go
│ ├── bits
│ │ ├── c++config.h
│ │ ├── exception.h
│ │ └── hash_bytes.h
│ ├── cfloat
│ ├── ciso646
│ ├── climits
│ ├── cstdalign
│ ├── cstdarg
│ ├── cstdbool
│ ├── cstddef
│ ├── cstdint
│ ├── cstdlib
│ ├── cstring
│ ├── exception
│ ├── initializer_list
│ ├── limits
│ ├── new
│ ├── type_traits
│ └── typeinfo
└── src
│ ├── BUILD.go
│ ├── CMakeLists.txt
│ ├── array_type_info.cc
│ ├── bad_alloc.cc
│ ├── bad_array_new.cc
│ ├── bad_cast.cc
│ ├── bad_typeid.cc
│ ├── class_type_info.cc
│ ├── cstring.cc
│ ├── cxxabi.h
│ ├── cxxabi_forced.h
│ ├── cxxabi_init_exception.h
│ ├── del_op.cc
│ ├── del_opnt.cc
│ ├── del_ops.cc
│ ├── del_opv.cc
│ ├── del_opvnt.cc
│ ├── del_opvs.cc
│ ├── dyncast.cc
│ ├── eh_aux_runtime.cc
│ ├── eh_call.cc
│ ├── eh_catch.cc
│ ├── eh_exception.cc
│ ├── eh_personality.cc
│ ├── eh_term_handler.cc
│ ├── eh_terminate.cc
│ ├── eh_throw.cc
│ ├── eh_unex_handler.cc
│ ├── enum_type_info.cc
│ ├── exception_defines.h
│ ├── function_type_info.cc
│ ├── fundamental_type_info.cc
│ ├── hash_bytes.cc
│ ├── new_handler.cc
│ ├── new_op.cc
│ ├── new_opnt.cc
│ ├── new_opv.cc
│ ├── new_opvnt.cc
│ ├── pbase_type_info.cc
│ ├── pmem_type_info.cc
│ ├── pointer_type_info.cc
│ ├── pure.cc
│ ├── si_class_type_info.cc
│ ├── tinfo.cc
│ ├── tinfo.h
│ ├── unwind-cxx.h
│ └── vmi_class_type_info.cc
├── patches
└── qemu
│ └── 0001-hw-i386-multiboot.c-Don-t-refuse-to-boot-ELF64-binar.patch
└── tests
├── BUILD.go
├── CMakeLists.txt
├── test-00-global-ctors-dtors.cc
├── test-01-initializers-operators.cc
├── test-02-virtuals.cc
├── test-03-heap.cc
├── test-04-rtti.cc
├── test-05-local-statics.cc
├── test-06-trivial-exception.cc
├── test-07-throw-clean-up-rethrow.cc
├── test-08-ccompat.cc
├── test-09-numeric-limits.cc
└── test-10-type-traits.cc
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | build
3 | DEPS
4 | BUILD
5 |
--------------------------------------------------------------------------------
/BUILD.go:
--------------------------------------------------------------------------------
1 | package libsupcxx
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | "libsupcxx/io"
6 | "libsupcxx/libruncxx"
7 | libsupcxx_src "libsupcxx/libsupcxx/src"
8 | )
9 |
10 | var CommonLibs = []cc.Dep{
11 | libruncxx.Lib,
12 | libsupcxx_src.Lib,
13 | io.Lib,
14 | }
15 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | cmake_minimum_required(VERSION 3.8)
3 |
4 | # Includes in this project are meant for dbt, so they are relative to dbt's DEPS directory,
5 | # where all modules, including the main project, would have their own folder.
6 | # So every include to files in this project is prefixed by the name of the project folder.
7 | # For example, to include io/io.hh we use #include "libsupxx/io/io.hh"
8 | #
9 | # To make CMake understand this structure, we recreate the DEPS folder inside CMake's
10 | # ${CMAKE_BINARY_DIR} folder. This is NOT in the same place as dbt's DEPS or BUILD folder,
11 | # so CMake and dbt are kept separate, and can be used at the same time.
12 |
13 | # Make the CMAKE_DEPS folder (full path ${DBT_INCLUDE_ROOT}) where we recreate dbt's DEPS
14 | set(DBT_INCLUDE_ROOT ${CMAKE_BINARY_DIR}/CMAKE_DEPS)
15 | file(MAKE_DIRECTORY ${DBT_INCLUDE_ROOT})
16 |
17 | # This project's dbt name (its main directory name, not necessarily CMake's PROJECT_NAME)
18 | get_filename_component(
19 | DBT_PROJECT_NAME
20 | ${CMAKE_SOURCE_DIR} NAME
21 | )
22 |
23 | # Symlink this project's source dir in CMAKE_DEPS (${DBT_INCLUDE_ROOT})
24 | execute_process(
25 | COMMAND ln -sfn ${CMAKE_SOURCE_DIR} ${DBT_INCLUDE_ROOT}/${DBT_PROJECT_NAME}
26 | )
27 |
28 | # Copy or symlink any other dependencies in the same ${DBT_INCLUDE_ROOT} folder
29 | # (there aren't any here)
30 |
31 |
32 | set(PLATFORM_NAME "x86_64" CACHE STRING "Platform name defaulting to 'x86_64'")
33 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/boot/${PLATFORM_NAME}/toolchain.cmake)
34 |
35 | set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
36 | set(CMAKE_BUILD_TYPE Debug CACHE STRING "" FORCE)
37 | enable_language(C CXX ASM)
38 |
39 | include(Kernel)
40 |
41 | project(libsupxx)
42 |
43 | # Make includes relative to the CMAKE_DEPS folder, but include stdlib headers normally
44 | include_directories(
45 | ${DBT_INCLUDE_ROOT}
46 | ${CMAKE_SOURCE_DIR}/libsupcxx/include
47 | )
48 |
49 | add_subdirectory(tests)
50 | add_subdirectory(io)
51 | add_subdirectory(libsupcxx/src)
52 | add_subdirectory(libruncxx)
53 | add_subdirectory(boot/${PLATFORM_NAME})
54 |
--------------------------------------------------------------------------------
/LICENSE.RUNTIME:
--------------------------------------------------------------------------------
1 | GCC RUNTIME LIBRARY EXCEPTION
2 |
3 | Version 3.1, 31 March 2009
4 |
5 | Copyright (C) 2009 Free Software Foundation, Inc.
6 |
7 | Everyone is permitted to copy and distribute verbatim copies of this
8 | license document, but changing it is not allowed.
9 |
10 | This GCC Runtime Library Exception ("Exception") is an additional
11 | permission under section 7 of the GNU General Public License, version
12 | 3 ("GPLv3"). It applies to a given file (the "Runtime Library") that
13 | bears a notice placed by the copyright holder of the file stating that
14 | the file is governed by GPLv3 along with this Exception.
15 |
16 | When you use GCC to compile a program, GCC may combine portions of
17 | certain GCC header files and runtime libraries with the compiled
18 | program. The purpose of this Exception is to allow compilation of
19 | non-GPL (including proprietary) programs to use, in this way, the
20 | header files and runtime libraries covered by this Exception.
21 |
22 | 0. Definitions.
23 |
24 | A file is an "Independent Module" if it either requires the Runtime
25 | Library for execution after a Compilation Process, or makes use of an
26 | interface provided by the Runtime Library, but is not otherwise based
27 | on the Runtime Library.
28 |
29 | "GCC" means a version of the GNU Compiler Collection, with or without
30 | modifications, governed by version 3 (or a specified later version) of
31 | the GNU General Public License (GPL) with the option of using any
32 | subsequent versions published by the FSF.
33 |
34 | "GPL-compatible Software" is software whose conditions of propagation,
35 | modification and use would permit combination with GCC in accord with
36 | the license of GCC.
37 |
38 | "Target Code" refers to output from any compiler for a real or virtual
39 | target processor architecture, in executable form or suitable for
40 | input to an assembler, loader, linker and/or execution
41 | phase. Notwithstanding that, Target Code does not include data in any
42 | format that is used as a compiler intermediate representation, or used
43 | for producing a compiler intermediate representation.
44 |
45 | The "Compilation Process" transforms code entirely represented in
46 | non-intermediate languages designed for human-written code, and/or in
47 | Java Virtual Machine byte code, into Target Code. Thus, for example,
48 | use of source code generators and preprocessors need not be considered
49 | part of the Compilation Process, since the Compilation Process can be
50 | understood as starting with the output of the generators or
51 | preprocessors.
52 |
53 | A Compilation Process is "Eligible" if it is done using GCC, alone or
54 | with other GPL-compatible software, or if it is done without using any
55 | work based on GCC. For example, using non-GPL-compatible Software to
56 | optimize any GCC intermediate representations would not qualify as an
57 | Eligible Compilation Process.
58 |
59 | 1. Grant of Additional Permission.
60 |
61 | You have permission to propagate a work of Target Code formed by
62 | combining the Runtime Library with Independent Modules, even if such
63 | propagation would otherwise violate the terms of GPLv3, provided that
64 | all Target Code was generated by Eligible Compilation Processes. You
65 | may then convey such a combination under terms of your choice,
66 | consistent with the licensing of the Independent Modules.
67 |
68 | 2. No Weakening of GCC Copyleft.
69 |
70 | The availability of this Exception does not imply any general
71 | presumption that third-party software is unaffected by the copyleft
72 | requirements of the license of GCC.
73 |
74 |
--------------------------------------------------------------------------------
/MODULE:
--------------------------------------------------------------------------------
1 | version: 2
2 | dependencies:
3 | aarch64-elf-gcc:
4 | url: https://storage.googleapis.com/gcc-toolchains/aarch64-elf-gcc-11.1.0-binutils-2.31.1-x86_64.tar.gz
5 | version: origin/master
6 | dbt-rules:
7 | url: https://github.com/daedaleanai/dbt-rules.git
8 | version: v1.2.0
9 | x86_64-elf-gcc:
10 | url: https://storage.googleapis.com/gcc-toolchains/x86_64-elf-gcc-11.1.0-binutils-2.31.1-x86_64.tar.gz
11 | version: origin/master
12 | pinneddependencies:
13 | aarch64-elf-gcc:
14 | url: https://storage.googleapis.com/gcc-toolchains/aarch64-elf-gcc-11.1.0-binutils-2.31.1-x86_64.tar.gz
15 | version: origin/master
16 | hash: 353c3d9604774af10afefd1ac7e13f485e126408556506ab53d56a7a288ff0db
17 | dbt-rules:
18 | url: https://github.com/daedaleanai/dbt-rules.git
19 | version: v1.2.0
20 | hash: 7e96939c08ec3960fa1def9fb4323a707b42d67d
21 | x86_64-elf-gcc:
22 | url: https://storage.googleapis.com/gcc-toolchains/x86_64-elf-gcc-11.1.0-binutils-2.31.1-x86_64.tar.gz
23 | version: origin/master
24 | hash: 8f6bb9068ed1ba02d15c0aef8fb3e9d7e99ab91d206be6181ff9b5d145ffc6d1
25 |
--------------------------------------------------------------------------------
/boot/bootinfo.hh:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 |
26 | enum class MemoryType : uint32_t { INACCESSIBLE, RAM, DEVICE };
27 |
28 | struct MemoryRegion {
29 | uint64_t start;
30 | uint64_t end;
31 | uint64_t offset; //!< Offset to be used in the device context (ie. when assigning BARs)
32 | MemoryType type;
33 | };
34 |
35 | struct [[gnu::packed]] BootInfo {
36 | const char *cmdline;
37 | MemoryRegion memoryMap[32];
38 | uint32_t numMemoryRegions;
39 | };
40 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/BUILD.go:
--------------------------------------------------------------------------------
1 | package linux_x86_64
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | "dbt-rules/RULES/core"
6 | "dbt-rules/RULES/util"
7 |
8 | "libsupcxx"
9 | "libsupcxx/libsupcxx/include"
10 |
11 | gcc "x86_64-elf-gcc"
12 | )
13 |
14 | var bootToolchain = gcc.Toolchain.NewWithStdLib(
15 | append(gcc.Toolchain.Includes, include.Headers...),
16 | libsupcxx.CommonLibs,
17 | in("kernel.ld"),
18 | "linux-x86_64-libsupcxx",
19 | )
20 |
21 | var crt2 = util.CopyFile{
22 | From: gcc.CrtBegin,
23 | To: out("crt2.o"),
24 | }
25 |
26 | var crt3 = util.CopyFile{
27 | From: gcc.CrtEnd,
28 | To: out("crt3.o"),
29 | }
30 |
31 | var bootFirst = cc.Library{
32 | Out: out("libboot_first.a"),
33 | Srcs: ins(
34 | "crt0.S",
35 | "crt1.S",
36 | "setup.cc",
37 | "io.cc",
38 | ),
39 | Objs: []core.Path{crt2.To},
40 | AlwaysLink: true,
41 | Toolchain: bootToolchain,
42 | }
43 |
44 | var bootLast = cc.Library{
45 | Out: out("libboot_last.a"),
46 | Srcs: ins(
47 | "crt4.S",
48 | ),
49 | Objs: []core.Path{crt3.To},
50 | AlwaysLink: true,
51 | Toolchain: bootToolchain,
52 | }
53 |
54 | var Toolchain = cc.RegisterToolchain(bootToolchain.NewWithStdLib(
55 | bootToolchain.Includes,
56 | append(bootToolchain.StdDeps(), bootLast, bootFirst),
57 | bootToolchain.LinkerScript,
58 | bootToolchain.Name(),
59 | ))
60 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_gcc_object(CRT2 crtbegin.o crt2.o)
3 | add_gcc_object(CRT3 crtend.o crt3.o)
4 |
5 | add_library(
6 | boot_first STATIC
7 | crt0.S
8 | crt1.S
9 | ${CRT2}
10 | setup.cc
11 | )
12 |
13 | add_library(
14 | boot_last STATIC
15 | ${CRT3}
16 | crt4.S
17 | io.cc
18 | )
19 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/crt0.S:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | //------------------------------------------------------------------------------
25 | // This will be run in a hosted, but freestanding, Linux environment
26 | //------------------------------------------------------------------------------
27 |
28 | #include "libsupcxx/boot/linux-x86_64/syscall.h"
29 | .section .text
30 |
31 | .global _start
32 | .type _start, @function
33 |
34 | .global _syscall
35 | .type _syscall, @function
36 |
37 | _start:
38 | // We need to get argc, argv, and envp from the stack for _systemSetup.
39 | // Linux gives us the stack as:
40 | // ($rsp) argc -- argv[0] -- argv[1] -- ... -- argv[argc - 1] -- envp
41 | mov (%rsp), %rdi // put argc in rdi
42 | lea 8(%rsp), %rsi // put argv in rsi
43 | lea 8(%rsi, %rdi, 8), %rdx // put envp in rdx
44 |
45 | // Set up end of the stack frame linked list - gdb and exception handling
46 | // really like it ;)
47 | mov $0, %rbp
48 | pushq %rbp // rip=0
49 | pushq %rbp // ebp=0
50 | mov %rsp, %rbp
51 |
52 | // Call _systemSetup(envp) to initialise the heap and populate bootInfo
53 | call _systemSetup
54 |
55 | // Run the global constructors
56 | call _init
57 |
58 | // Get the commandline string pointer and start main
59 | mov bootInfo, %rdi
60 | call main
61 |
62 | // Run the global destructors
63 | call _fini
64 |
65 | // exit(0) (main does not return anything)
66 | mov $0, %rdi
67 | mov $SYS_exit, %rax
68 | syscall // syscall and exit. no return from this
69 | hlt // if we return from exit(), something has gone wrong
70 |
71 |
72 | // C-callable syscalls.
73 | // Usage: _syscall(, [syscall_args])
74 | _syscall:
75 | // Convert C varargs to syscall argument format
76 | movq %rdi, %rax
77 | movq %rsi, %rdi
78 | movq %rdx, %rsi
79 | movq %rcx, %rdx
80 | movq %r8, %r10
81 | movq %r9, %r8
82 | movq 8(%rsp), %r9
83 |
84 | syscall
85 | retq
86 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/crt1.S:
--------------------------------------------------------------------------------
1 |
2 | .section .init
3 | .global _init
4 | .type _init, @function
5 | _init:
6 | pushq %rbp
7 | movq %rsp, %rbp
8 |
9 | .section .fini
10 | .global _fini
11 | .type _fini, @function
12 | _fini:
13 | pushq %rbp
14 | movq %rsp, %rbp
15 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/crt4.S:
--------------------------------------------------------------------------------
1 |
2 | .section .init
3 | popq %rbp
4 | ret
5 |
6 | .section .fini
7 | popq %rbp
8 | ret
9 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/io.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2021 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/boot/linux-x86_64/syscall.h"
25 | #include
26 |
27 | extern "C" uint64_t _syscall(uint64_t syscall, ...);
28 |
29 | extern "C" void _putChar(char c) {
30 | _syscall(SYS_write, STDOUT_FILENO, &c, 1);
31 | }
32 |
33 | extern "C" void abort() {
34 | _syscall(SYS_exit, 1);
35 | }
36 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/setup.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2021 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/boot/bootinfo.hh"
25 | #include "libsupcxx/boot/linux-x86_64/syscall.h"
26 |
27 | #include
28 | #include
29 |
30 | // The length of the heap to allocate can be specified by an environment
31 | // variable
32 | static const char *ENV_HEAPLEN = "LIBSUPCXX_HEAPLEN";
33 | static const size_t HEAPLEN_DEFAULT = 1 << 26; // 64 MiB
34 |
35 | static const char *MMAP_ERR_MSG = "libsupcxx setup error\n";
36 |
37 | extern "C" uint64_t _syscall(uint64_t syscall, ...);
38 |
39 | BootInfo bootInfo;
40 |
41 | // Similar to standard getenv, but takes envp as argument
42 | extern "C" const char *_getenv(const char **envp, const char *name) {
43 | size_t len = strlen(name);
44 | for (const char **env = envp; *env; ++env) {
45 | if (strncmp(*env, name, len) == 0) {
46 | return *env + len + 1;
47 | }
48 | }
49 | return nullptr;
50 | }
51 |
52 | // The length of the heap to be allocated (from env or default)
53 | extern "C" size_t _heapLen(const char **envp) {
54 | const char *env = _getenv(envp, ENV_HEAPLEN);
55 | if (env) {
56 | return strtoul(env, nullptr, 0);
57 | }
58 | return HEAPLEN_DEFAULT;
59 | }
60 |
61 | // Add the cmdline (argv's elements, space-separated) to the start of the heap
62 | extern "C" void _addCmdLine(size_t argc, const char **argv, char *heap) {
63 | char *end = heap;
64 | for (size_t i = 0; i < argc; ++i) {
65 | size_t len = strlen(argv[i]);
66 | strncpy(end, argv[i], len);
67 | if (i == argc - 1) {
68 | end[len] = '\0';
69 | } else {
70 | end[len] = ' ';
71 | }
72 | end = &end[len + 1];
73 | }
74 | return;
75 | }
76 |
77 | // Called by start, allocates heap and populates bootInfo
78 | extern "C" void _systemSetup(size_t argc, const char **argv,
79 | const char **envp) {
80 | size_t heapLen = _heapLen(envp);
81 | int64_t mmapReturn =
82 | _syscall(SYS_mmap, // mmap(
83 | nullptr, // addr, (let the kernel choose)
84 | heapLen, // length, (from environment / default)
85 | PROT_READ | PROT_WRITE, // prot, (rw)
86 | MAP_PRIVATE | MAP_ANONYMOUS, // flags, (not file-mapped)
87 | -1, // fd, (not file-mapped)
88 | 0 // offset (none)
89 | );
90 |
91 | // Check for failure. Unlike mmap, SYS_mmap can return a range of errno's
92 | if (mmapReturn >= -4095 && mmapReturn <= -1) {
93 | _syscall(SYS_write, STDOUT_FILENO, MMAP_ERR_MSG, strlen(MMAP_ERR_MSG));
94 | _syscall(SYS_exit, 1);
95 | }
96 |
97 | char *allocated = (char *)mmapReturn;
98 |
99 | // Copy the command line at the start of the allocated memory
100 | _addCmdLine(argc, argv, (char *)allocated);
101 |
102 | // There is only one memory region, i.e. what's been allocated
103 | bootInfo.numMemoryRegions = 1;
104 | bootInfo.cmdline = (const char *)allocated;
105 | bootInfo.memoryMap[0].start = (uint64_t)allocated;
106 | bootInfo.memoryMap[0].end = (uint64_t)(allocated + heapLen);
107 | bootInfo.memoryMap[0].offset = 0;
108 | bootInfo.memoryMap[0].type = MemoryType::RAM;
109 | }
110 |
--------------------------------------------------------------------------------
/boot/linux-x86_64/toolchain.cmake:
--------------------------------------------------------------------------------
1 |
2 | include(CMakeForceCompiler)
3 | set(CMAKE_SYSTEM_NAME Generic)
4 | set(CMAKE_SYSTEM_VERSION 1)
5 | set(CMAKE_C_FLAGS "-ffreestanding" CACHE STRING "" FORCE)
6 | set(CMAKE_CXX_FLAGS "-ffreestanding -std=c++14 -mno-red-zone" CACHE STRING "" FORCE)
7 | set(CMAKE_ASM_FLAGS "-ffreestanding " CACHE STRING "" FORCE)
8 | set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -nostdlib -Wl,-T,${CMAKE_SOURCE_DIR}/boot/linux-x86_64/kernel.ld -z max-page-size=0x1000" CACHE STRING "" FORCE)
9 | set(CMAKE_C_COMPILER x86_64-elf-gcc)
10 | set(CMAKE_CXX_COMPILER x86_64-elf-g++)
11 | set(CMAKE_OBJCOPY x86_64-elf-objcopy CACHE STRING "" FORCE)
12 |
--------------------------------------------------------------------------------
/boot/raspi3/BUILD.go:
--------------------------------------------------------------------------------
1 | package raspi3
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | "dbt-rules/RULES/core"
6 | "dbt-rules/RULES/util"
7 |
8 | "libsupcxx"
9 | "libsupcxx/libsupcxx/include"
10 |
11 | gcc "aarch64-elf-gcc"
12 | )
13 |
14 | var bootToolchain = gcc.Toolchain.NewWithStdLib(
15 | append(gcc.Toolchain.Includes, include.Headers...),
16 | libsupcxx.CommonLibs,
17 | in("kernel.ld"),
18 | "raspi3-libsupcxx",
19 | )
20 |
21 | var crt2 = util.CopyFile{
22 | From: gcc.CrtBegin,
23 | To: out("crt2.o"),
24 | }
25 |
26 | var crt3 = util.CopyFile{
27 | From: gcc.CrtEnd,
28 | To: out("crt3.o"),
29 | }
30 |
31 | var bootFirst = cc.Library{
32 | Out: out("libboot_first.a"),
33 | Srcs: ins(
34 | "crt0.S",
35 | "setup.cc",
36 | ),
37 | Objs: []core.Path{crt2.To},
38 | AlwaysLink: true,
39 | Toolchain: bootToolchain,
40 | }
41 |
42 | var bootLast = cc.Library{
43 | Out: out("libboot_last.a"),
44 | Srcs: ins("io.cc"),
45 | Objs: []core.Path{crt3.To},
46 | AlwaysLink: true,
47 | Toolchain: bootToolchain,
48 | }
49 |
50 | var Toolchain = cc.RegisterToolchain(bootToolchain.NewWithStdLib(
51 | bootToolchain.Includes,
52 | append(bootToolchain.StdDeps(), bootLast, bootFirst),
53 | bootToolchain.LinkerScript,
54 | bootToolchain.Name(),
55 | ))
56 |
--------------------------------------------------------------------------------
/boot/raspi3/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_gcc_object(CRT2 crtbegin.o crt2.o)
3 | add_gcc_object(CRT3 crtend.o crt3.o)
4 |
5 | add_library(
6 | boot_first STATIC
7 | crt0.S
8 | ${CRT2}
9 | setup.cc
10 | )
11 |
12 | add_library(
13 | boot_last STATIC
14 | ${CRT3}
15 | io.cc
16 | )
17 |
--------------------------------------------------------------------------------
/boot/raspi3/crt0.S:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | //------------------------------------------------------------------------------
25 | // The stack - grows downwards on Aarch64 and needs to be 16 bytes aligned
26 | //------------------------------------------------------------------------------
27 | .section .bss
28 | .align 16
29 | stackBottom:
30 | .skip 131072 // 128 KiB
31 | stackTop:
32 |
33 | .section .rodata
34 |
35 | .global _initIo
36 | .global bootInfo
37 |
38 | .section .boot
39 | .global _start
40 | .type _start, @function
41 |
42 | _start:
43 | mrs x1, mpidr_el1 // Mrs moves contents of a coprocesor register to an ARM
44 | // register. Move the contents of the Multiprocessor
45 | // Affinity Register to x1 (Cortex-A53 spec section 4.3.2)
46 | and x1, x1, #0x3 // x1 = x1 & 0x3 - the first two bits indicate the current
47 | // core id
48 | cbz x1, run_el2 // Don't get into the infinit loop below if we're running
49 | // on core #0
50 | loop:
51 | wfe // Wait for event - an interrupt or whatever
52 | b loop // Handled the interrupt? Fine. Wait for another one.
53 |
54 | //------------------------------------------------------------------------------
55 | // Hypervisor mode (EL2)
56 | //------------------------------------------------------------------------------
57 | run_el2:
58 | // Set up the stack for EL1
59 | ldr x1, =stackTop
60 | msr sp_el1, x1
61 |
62 | // Provides the values of the virtualization versions of the processor id
63 | // registers. These are the value returned by non-secure EL1 reads of of
64 | // midr_el1 and mpidr_el1.
65 | mrs x0, midr_el1
66 | mrs x1, mpidr_el1
67 | msr vpidr_el2, x0
68 | msr vmpidr_el2, x1
69 |
70 | // Disable trapping to hypervisor for accesses to CPACR, Trace functionality
71 | // and registers associated with Advanced SIMD and Floating-point execution.
72 | mov x0, #0x33ff
73 | msr cptr_el2, x0
74 |
75 | // Don't trap floating point to EL1 from EL0 or EL1
76 | mov x0, #3 << 20
77 | msr cpacr_el1, x0
78 |
79 | // Make EL1 AArch64
80 | mov x0, #(1 << 31)
81 | msr hcr_el2, x0
82 |
83 | // Set up the system for EL1 - Res1 bits to 1, res0 bits to 0 and all other
84 | // bits to 0. Movk - move 16-bit immediate into register, keeping other bits
85 | // unchanged, do logical shift left (lsl).
86 | mov x0, #0x0800
87 | movk x0, #0x30d0, lsl #16
88 | msr sctlr_el1, x0
89 |
90 | // Set up the saved program status register, these will get set up as the
91 | // program status when the exception returns. We take the stack pointer from
92 | // sp_el1.
93 | mov x0, #0x5
94 | msr spsr_el2, x0
95 |
96 | // Where to jump on return
97 | ldr x0, =run_el1
98 | msr elr_el2, x0
99 | eret
100 |
101 | //------------------------------------------------------------------------------
102 | // OS Mode (EL1)
103 | //------------------------------------------------------------------------------
104 | run_el1:
105 | // Clear the frame pointer and the link register (eor == xor)
106 | eor x30, x30, x30
107 | eor x29, x29, x29
108 |
109 | // Clear bss
110 | ldr x1, =__bssStart
111 | ldr x2, =__bssEnd
112 | bssLoopStart:
113 | cmp x1, x2
114 | b.ge bssLoopEnd
115 | str xzr, [x1], #8
116 | b bssLoopStart
117 | bssLoopEnd:
118 |
119 | bl _initIo
120 |
121 | ldr x0, =bootInfo
122 | bl _systemSetup
123 |
124 | bl _init
125 |
126 | ldr x1, =bootInfo
127 | ldr x0, [x1]
128 | bl main
129 |
130 | bl _fini
131 |
132 | b loop
133 |
--------------------------------------------------------------------------------
/boot/raspi3/io.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 |
26 | // See:
27 | // https://www.raspberrypi.org/app/uploads/2012/02/BCM2835-ARM-Peripherals.pdf
28 | // https://github.com/dwelch67/raspberrypi/blob/master/uart01/uart01.c
29 | // Although the base seems to be at 0x3f000000 for the BCM2837 on RPi3.
30 | #define AUXENB (*(volatile uint32_t*)0x3f215004)
31 | #define AUX_MU_CNTL_REG (*(volatile uint32_t*)0x3f215060)
32 | #define AUX_MU_LCR_REG (*(volatile uint32_t*)0x3f21504c)
33 | #define AUX_MU_IIR_REG (*(volatile uint32_t*)0x3f215048)
34 | #define AUX_MU_BAUD (*(volatile uint32_t*)0x3f215068)
35 | #define GPFSEL1 (*(volatile uint32_t*)0x3f200004)
36 | #define GPFSEL2 (*(volatile uint32_t*)0x3f200008)
37 | #define GPPUD (*(volatile uint32_t*)0x3f200094)
38 | #define GPPUDCLK0 (*(volatile uint32_t*)0x3f200098)
39 | #define AUX_MU_LSR_REG (*(volatile uint32_t*)0x3f215054)
40 | #define AUX_MU_IO_REG (*(volatile uint32_t*)0x3f215040)
41 |
42 | #define DO_NOTHING(X) { \
43 | for(register uint64_t tmp = 0; tmp < X; ++tmp) { \
44 | asm volatile("nop"); \
45 | } \
46 | }
47 |
48 | extern "C" void _initIo() {
49 | // UART
50 | AUXENB |= 0x1; // enable mini UART and any related registers
51 | AUX_MU_CNTL_REG = 0; // disable RX and TX, we also don't want any of the
52 | // "fancy features"
53 | AUX_MU_LCR_REG = 0x3; // 8-bit mode
54 | AUX_MU_BAUD = 270; // baud_rate = (system_clock_freq)/(8*(boud_reg+1))
55 | // 115200 baud => reg = 270 because clock is 250MHz
56 |
57 | // GPIO
58 | register uint32_t tmp = GPFSEL1;
59 | tmp &= ~(7 << 12); // clear alt selection for gpio14 - we only TX
60 | tmp |= 2 << 12; // alt5 for gpio14 - MiniUART
61 | GPFSEL1 = tmp;
62 |
63 | GPPUD = 0; // disable pull ups/downs
64 | DO_NOTHING(150); // do nothing for a couple of cycles to provide the
65 | // required set up time for the control signal
66 | GPPUDCLK0 = 1 << 14; // clock the control signal into gpio14
67 | DO_NOTHING(150); // do nothing to provide the required hold time for
68 | // the control signal
69 | GPPUDCLK0 = 0; // remove the clock
70 |
71 | AUX_MU_CNTL_REG = 0x2; // Enable TX
72 |
73 | // JTAG
74 | tmp = GPFSEL2;
75 | tmp &= 0xff00003f; // clear alternative selection for gpios 22 through 27
76 | tmp |= 0x006db6c0; // alternative function 4-JTAG for gpios 22 through 27
77 | GPFSEL2 = tmp;
78 | GPPUD = 0; // disable pull ups/downs
79 | DO_NOTHING(150); // do nothing for a couple of cycles to provide the
80 | // required set up time for the control signal
81 | GPPUDCLK0 = 0x0fc00000; // clock the control signal into gpios 22 through 27
82 | DO_NOTHING(150); // do nothing to provide the required hold time for
83 | // the control signal
84 | GPPUDCLK0 = 0; // remove the clock
85 | }
86 |
87 | extern "C" void _putChar(char c) {
88 | // Busy wait for some space in the TX FIFO
89 | while ((AUX_MU_LSR_REG & 0x20) == 0) {
90 | DO_NOTHING(10);
91 | }
92 |
93 | AUX_MU_IO_REG = c;
94 |
95 | // Put the carriage return after a new line
96 | if (c == '\n') {
97 | _putChar('\r');
98 | }
99 | }
100 |
101 | extern "C" void abort() {
102 | // not really abort but will do
103 | while(true) {
104 | asm volatile("wfe");
105 | }
106 | }
107 |
--------------------------------------------------------------------------------
/boot/raspi3/kernel.ld:
--------------------------------------------------------------------------------
1 | /*------------------------------------------------------------------------------
2 | | Copyright (C) 2019 Daedalean AG
3 | |
4 | | This library is free software; you can redistribute it and/or modify it
5 | | under the terms of the GNU General Public License as published by the
6 | | Free Software Foundation; either version 3, or (at your option)
7 | | any later version.
8 | |
9 | | This library is distributed in the hope that it will be useful,
10 | | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | | GNU General Public License for more details.
13 | |
14 | | Under Section 7 of GPL version 3, you are granted additional
15 | | permissions described in the GCC Runtime Library Exception, version
16 | | 3.1, as published by the Free Software Foundation.
17 | |
18 | | You should have received a copy of the GNU General Public License and
19 | | a copy of the GCC Runtime Library Exception along with this program;
20 | | see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | | .
22 | *----------------------------------------------------------------------------*/
23 |
24 | SECTIONS
25 | {
26 | /*----------------------------------------------------------------------------
27 | | 512KB both VMA and LMA - that's where the bootloader will put us.
28 | *--------------------------------------------------------------------------*/
29 | . = 0x80000;
30 |
31 | /*----------------------------------------------------------------------------
32 | | The code
33 | *--------------------------------------------------------------------------*/
34 | .text :
35 | {
36 | SORT(*libboot_first.a:crt0*)(.boot)
37 | *(.text*)
38 | *(.gnu.linkonce.t*)
39 | }
40 | /*----------------------------------------------------------------------------
41 | | Read-only data
42 | *--------------------------------------------------------------------------*/
43 | .rodata : ALIGN(16)
44 | {
45 | *libboot_first.a:crt2*(.eh_frame)
46 | EXCLUDE_FILE(*libboot_last.a:crt3*) *(.eh_frame)
47 | SORT(*libboot_last.a:crt3*)(.eh_frame)
48 | *(.gcc_except_table)
49 |
50 | /* These need to be 8-byte aligned */
51 | . = ALIGN(8);
52 | __initArrayBegin = .;
53 | *(SORT(.init_array*))
54 | __initArrayEnd = .;
55 |
56 | . = ALIGN(8);
57 | __finiArrayBegin = .;
58 | *(SORT(.fini_array*))
59 | __finiArrayEnd = .;
60 |
61 | *(.rodata*)
62 | *(.gnu.linkonce.r*)
63 | }
64 |
65 | /*----------------------------------------------------------------------------
66 | | Read-write data (initialized)
67 | +--------------------------------------------------------------------------*/
68 | .data : ALIGN(16)
69 | {
70 | *(.data*)
71 | *(.gnu.linkonce.d*)
72 | *(.got.plt)
73 | }
74 |
75 | /*----------------------------------------------------------------------------
76 | | Read-write data (uninitialized) and stack
77 | *--------------------------------------------------------------------------*/
78 | .bss : ALIGN(16)
79 | {
80 | __bssStart = .;
81 | *(COMMON)
82 | *(.bss)
83 | __bssEnd = .;
84 | }
85 |
86 | /*----------------------------------------------------------------------------
87 | | The linker will add other stuff as needed
88 | +--------------------------------------------------------------------------*/
89 |
90 | /*----------------------------------------------------------------------------
91 | | We need to know where the kernel ends in case we choose the same region
92 | | for the heap.
93 | *--------------------------------------------------------------------------*/
94 | __kernelEnd = .;
95 | }
96 |
--------------------------------------------------------------------------------
/boot/raspi3/toolchain.cmake:
--------------------------------------------------------------------------------
1 |
2 | include(CMakeForceCompiler)
3 | set(CMAKE_SYSTEM_NAME Generic)
4 | set(CMAKE_SYSTEM_VERSION 1)
5 | set(CFLAGS "-mcpu=cortex-a53")
6 | set(CMAKE_C_FLAGS "-ffreestanding" CACHE STRING "" FORCE)
7 | set(CMAKE_CXX_FLAGS "-ffreestanding -std=c++14" CACHE STRING "" FORCE)
8 | set(CMAKE_ASM_FLAGS "-ffreestanding " CACHE STRING "" FORCE)
9 | set(CMAKE_EXE_LINKER_FLAGS "-ffreestanding -nostdlib -Wl,-T,${CMAKE_SOURCE_DIR}/boot/raspi3/kernel.ld" CACHE STRING "" FORCE)
10 | set(CMAKE_C_COMPILER aarch64-elf-gcc)
11 | set(CMAKE_CXX_COMPILER aarch64-elf-g++)
12 | set(CMAKE_OBJCOPY aarch64-elf-objcopy CACHE STRING "" FORCE)
13 |
--------------------------------------------------------------------------------
/boot/x86_64/BUILD.go:
--------------------------------------------------------------------------------
1 | package x86_64
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | "dbt-rules/RULES/core"
6 | "dbt-rules/RULES/util"
7 |
8 | "libsupcxx"
9 | "libsupcxx/libsupcxx/include"
10 |
11 | gcc "x86_64-elf-gcc"
12 | )
13 |
14 | var bootToolchain = gcc.Toolchain.NewWithStdLib(
15 | append(gcc.Toolchain.Includes, include.Headers...),
16 | libsupcxx.CommonLibs,
17 | in("kernel.ld"),
18 | "x86_64-libsupcxx",
19 | )
20 |
21 | var crt2 = util.CopyFile{
22 | From: gcc.CrtBegin,
23 | To: out("crt2.o"),
24 | }
25 |
26 | var crt3 = util.CopyFile{
27 | From: gcc.CrtEnd,
28 | To: out("crt3.o"),
29 | }
30 |
31 | var bootFirst = cc.Library{
32 | Out: out("libboot_first.a"),
33 | Srcs: ins(
34 | "crt0.S",
35 | "crt1.S",
36 | "multiboot.cc",
37 | "setup.cc",
38 | ),
39 | Objs: []core.Path{crt2.To},
40 | AlwaysLink: true,
41 | Toolchain: bootToolchain,
42 | }
43 |
44 | var bootLast = cc.Library{
45 | Out: out("libboot_last.a"),
46 | Srcs: ins(
47 | "io.cc",
48 | "crt4.S",
49 | ),
50 | Objs: []core.Path{crt3.To},
51 | AlwaysLink: true,
52 | Toolchain: bootToolchain,
53 | }
54 |
55 | var Toolchain = cc.RegisterToolchain(bootToolchain.NewWithStdLib(
56 | bootToolchain.Includes,
57 | append(bootToolchain.StdDeps(), bootLast, bootFirst),
58 | bootToolchain.LinkerScript,
59 | bootToolchain.Name(),
60 | ))
61 |
--------------------------------------------------------------------------------
/boot/x86_64/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_gcc_object(CRT2 crtbegin.o crt2.o)
3 | add_gcc_object(CRT3 crtend.o crt3.o)
4 |
5 | add_library(
6 | boot_first STATIC
7 | crt0.S
8 | crt1.S
9 | ${CRT2}
10 | multiboot.cc
11 | setup.cc
12 | )
13 |
14 | add_library(
15 | boot_last STATIC
16 | ${CRT3}
17 | crt4.S
18 | io.cc
19 | )
20 |
--------------------------------------------------------------------------------
/boot/x86_64/crt1.S:
--------------------------------------------------------------------------------
1 |
2 | .section .init
3 | .global _init
4 | .type _init, @function
5 | _init:
6 | pushq %rbp
7 | movq %rsp, %rbp
8 |
9 | .section .fini
10 | .global _fini
11 | .type _fini, @function
12 | _fini:
13 | pushq %rbp
14 | movq %rsp, %rbp
15 |
--------------------------------------------------------------------------------
/boot/x86_64/crt4.S:
--------------------------------------------------------------------------------
1 |
2 | .section .init
3 | popq %rbp
4 | ret
5 |
6 | .section .fini
7 | popq %rbp
8 | ret
9 |
--------------------------------------------------------------------------------
/boot/x86_64/io.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 | #include
26 |
27 | namespace {
28 | const size_t VGA_WIDTH = 80;
29 | const size_t VGA_HEIGHT = 25;
30 |
31 | // COM1 == 0x03f8
32 | // COM2 == 0x02f8
33 | const unsigned short COM_PORT = 0x03f8;
34 |
35 | // Hardware text mode color constants.
36 | enum class VgaColor {
37 | BLACK = 0,
38 | BLUE = 1,
39 | GREEN = 2,
40 | CYAN = 3,
41 | RED = 4,
42 | MAGENTA = 5,
43 | BROWN = 6,
44 | LIGHT_GREY = 7,
45 | DARK_GREY = 8,
46 | LIGHT_BLUE = 9,
47 | LIGHT_GREEN = 10,
48 | LIGHT_CYAN = 11,
49 | LIGHT_RED = 12,
50 | LIGHT_MAGENTA = 13,
51 | LIGHT_BROWN = 14,
52 | WHITE = 15,
53 | };
54 |
55 | inline constexpr uint8_t vgaEntryColor(VgaColor fg, VgaColor bg) {
56 | return (uint8_t)fg | (uint8_t)bg << 4;
57 | }
58 |
59 | inline constexpr uint16_t vgaEntry(uint8_t character, uint8_t color) {
60 | return (uint16_t)character | (uint16_t)color << 8;
61 | }
62 |
63 | inline constexpr size_t vgaIndex(size_t x, size_t y) {
64 | return y * VGA_WIDTH + x;
65 | }
66 |
67 | volatile uint16_t *vgaTerminal = (uint16_t*)0xb8000;
68 | size_t vgaTerminalRow = 0;
69 | size_t vgaTerminalColumn = 0;
70 | uint8_t vgaTerminalColor = vgaEntryColor(VgaColor::LIGHT_GREY, VgaColor::BLACK);
71 |
72 | void vgaTerminalPutEntryAt(char c, uint8_t color, size_t x, size_t y) {
73 | vgaTerminal[vgaIndex(x, y)] = vgaEntry(c, color);
74 | }
75 |
76 | unsigned char inb(uint16_t port) {
77 | unsigned char ret;
78 | asm volatile(
79 | "inb %1, %0"
80 | : "=a" (ret)
81 | : "dN" (port));
82 | return ret;
83 | }
84 |
85 | void outb(uint16_t port, uint8_t data) {
86 | asm volatile(
87 | "outb %1, %0"
88 | :
89 | : "dN" (port), "a" (data));
90 | }
91 |
92 | void putCharSerial(char c) {
93 | while ((inb(COM_PORT + 5) & 0x20) == 0) {};
94 | outb(COM_PORT, c);
95 |
96 | if (c == '\n') {
97 | putCharSerial('\r');
98 | }
99 | }
100 |
101 | extern "C" void putCharVga(char c) {
102 | // newline
103 | if (c == '\n') {
104 | vgaTerminalColumn = 0;
105 | ++vgaTerminalRow;
106 | if (vgaTerminalRow == VGA_HEIGHT) {
107 | vgaTerminalRow = 0;
108 | }
109 | return;
110 | }
111 |
112 | // regular character
113 | vgaTerminalPutEntryAt(c, vgaTerminalColor, vgaTerminalColumn, vgaTerminalRow);
114 | ++vgaTerminalColumn;
115 | if (vgaTerminalColumn == VGA_WIDTH) {
116 | vgaTerminalColumn = 0;
117 | ++vgaTerminalRow;
118 | if (vgaTerminalRow == VGA_HEIGHT) {
119 | vgaTerminalRow = 0;
120 | }
121 | }
122 | }
123 | }
124 |
125 |
126 | extern "C" void _initIo() {
127 | // Initialize the VGA buffer
128 | for (size_t y = 0; y < VGA_HEIGHT; ++y) {
129 | for (size_t x = 0; x < VGA_WIDTH; ++x) {
130 | vgaTerminal[vgaIndex(x, y)] = vgaEntry(' ', vgaTerminalColor);
131 | }
132 | }
133 |
134 | // Initialize serial
135 | outb(COM_PORT + 1, 0x00); // Disable all interrupts
136 | outb(COM_PORT + 3, 0x80); // Enable DLAB (set baud rate divisor)
137 | outb(COM_PORT + 0, 0x01); // Set divisor to 1 (lo byte) 115200 baud
138 | outb(COM_PORT + 1, 0x00); // (hi byte)
139 | outb(COM_PORT + 3, 0x03); // 8 bits, no parity, one stop bit
140 | outb(COM_PORT + 2, 0xC7); // Enable FIFO, clear them, with 14-byte threshold
141 | outb(COM_PORT + 4, 0x0B); // IRQs enabled, RTS/DSR set
142 | }
143 |
144 | extern "C" void _putChar(char c) {
145 | putCharVga(c);
146 | putCharSerial(c);
147 | }
148 |
149 | extern "C" void abort() {
150 | asm volatile("hlt");
151 | }
152 |
--------------------------------------------------------------------------------
/boot/x86_64/multiboot.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/boot/bootinfo.hh"
25 | #include
26 |
27 | #define MULTIBOOT_MEMORY_AVAILABLE 1
28 |
29 | struct [[gnu::packed]] MbMmapEntry {
30 | uint32_t size;
31 | uint64_t addr;
32 | uint64_t len;
33 | uint32_t type;
34 | };
35 |
36 | struct MbInfo {
37 | uint32_t stuff1[4];
38 | uint32_t cmdline;
39 | uint32_t stuff2[6];
40 | uint32_t mmapLength;
41 | uint32_t mmapAddr;
42 | };
43 |
44 | BootInfo bootInfo;
45 |
46 | // This variable does not exist, but it's address is known to the linker. See
47 | // the linker script for details.
48 | extern uint32_t __kernelEnd;
49 |
50 | // We know what we're doing, don't warn please
51 | #pragma GCC diagnostic push
52 | #pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
53 |
54 | // Populate bootInfo from MbInfo
55 | extern "C" void _parseMultiboot(uint32_t magic, MbInfo *info) {
56 | // Populate cmdline
57 | bootInfo.cmdline = (char *)info->cmdline;
58 |
59 | // We only populate one entry in bootInfo.memoryMap with the largest
60 | // usable memory region we can find. Here we find it
61 | MbMmapEntry *mmap = (MbMmapEntry *)info->mmapAddr;
62 | bool hasLargest = false;
63 | uint64_t addr = 0;
64 | uint64_t len = 0;
65 |
66 | for (uint32_t i = 0; i < info->mmapLength; ++i) {
67 | if (mmap[i].addr < 0x1000) {
68 | continue;
69 | }
70 |
71 | if (mmap[i].type != MULTIBOOT_MEMORY_AVAILABLE) {
72 | continue;
73 | // TODO: non-available regions are DEVICES.
74 | // We should add them as DEVICE MemoryRegions
75 | }
76 |
77 | if (!hasLargest || len < mmap[i].len) {
78 | hasLargest = true;
79 | addr = mmap[i].addr;
80 | len = mmap[i].len;
81 | }
82 | }
83 |
84 | if (!hasLargest) {
85 | bootInfo.numMemoryRegions = 0;
86 | return;
87 | }
88 |
89 | // setUpHeap will align any MemoryRegion's start to 4K, but we also
90 | // align the boundaries to 2MB on x86_64
91 | uint64_t memEnd = addr + len;
92 |
93 | uint8_t shift = 21;
94 | uint32_t add = 0x00200000;
95 |
96 | addr = (((addr-1)>>shift)<= memEnd) {
99 | bootInfo.numMemoryRegions = 0;
100 | return;
101 | }
102 |
103 | memEnd = (((memEnd-1)>>shift)<$TEMPFILE 2>&1;
20 | if [ $? -ne 0 ]; then
21 | echo -e "\033[1;5;31merror\033[0m";
22 | cat $TEMPFILE;
23 | rm $TEMPFILE;
24 | exit 1;
25 | fi
26 | rm $TEMPFILE;
27 | echo "done";
28 | }
29 |
30 | if [ $# -ne 2 ]; then
31 | echo "[i] Usage: $0 installation_prefix target";
32 | echo "[i] ie: $0 /home/lj/Apps/cross-compiler/x86_64-elf x86_64-elf";
33 | exit 1;
34 | fi
35 |
36 | PREFIX=$1;
37 | TARGET=$2;
38 |
39 | highlight "[i] Installation parameters:";
40 | echo "[i] Installation prefix: ${PREFIX}";
41 | echo "[i] Installation target: ${TARGET}";
42 | echo;
43 | highlight "[i] For the build to succeed you need to have the following packages installed:";
44 | echo "[i] ]==> sudo apt-get install build-essential libgmp-dev libmpc-dev libmpfr-dev texinfo";
45 | echo;
46 |
47 | read -p "[?] Do you want to continue? (y/n) " -n 1 -r;
48 | echo;
49 | echo;
50 |
51 | if [ x"$REPLY" != xy ]; then
52 | echo "[i] Bye.";
53 | exit 0;
54 | fi
55 |
56 | TEMPDIR=`mktemp -d`;
57 |
58 | (
59 | echo "[i] Working in ${TEMPDIR}";
60 | cd ${TEMPDIR};
61 |
62 | progress "[i] Donwloading binutils" wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}.tar.bz2;
63 | progress "[i] Downloading gcc" wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCCVER}/gcc-${GCCVER}.tar.xz;
64 | progress "[i] Downloading gdb" wget https://ftp.gnu.org/gnu/gdb/gdb-${GDBVER}.tar.xz;
65 |
66 | progress "[i] Unpacking binutils" tar jxf binutils-${BINUTILSVER}.tar.bz2;
67 | mkdir binutils-build;
68 | cd binutils-build;
69 | progress "[i] Configuring binutils" ../binutils-${BINUTILSVER}/configure --target=${TARGET} --prefix=${PREFIX} \
70 | --with-sysroot --disable-nls --disable-werror;
71 | progress "[i] Building binutils" make -j 4;
72 | progress "[i] Installing binutils" make install;
73 |
74 | cd ..;
75 | progress "[i] Unpacking gcc" tar xf gcc-${GCCVER}.tar.xz;
76 | mkdir gcc-build;
77 | cd gcc-build;
78 | export PATH=${PREFIX}/bin:$PATH;
79 | progress "[i] Configuring gcc" ../gcc-${GCCVER}/configure --target=${TARGET} --prefix=${PREFIX} \
80 | --disable-nls --enable-languages=c,c++ --without-headers;
81 | progress "[i] Building gcc" make -j4 all-gcc;
82 | progress "[i] Building libgcc" make -j4 all-target-libgcc;
83 | progress "[i] Installing gcc" make install-gcc;
84 | progress "[i] Installing libgcc" make install-target-libgcc;
85 | progress "[i] Installing unwind-pe.h" cp ../gcc-${GCCVER}/libgcc/unwind-pe.h ${PREFIX}/lib/gcc/${TARGET}/${GCCVER}/include
86 |
87 | cd ..;
88 | progress "[i] Unpacking gdb" tar xf gdb-${GDBVER}.tar.xz;
89 | mkdir gdb-build;
90 | cd gdb-build;
91 | progress "[i] Configuring gdb" ../gdb-${GDBVER}/configure --target=${TARGET} --prefix=${PREFIX}
92 | progress "[i] Building gdb" make -j 4;
93 | progress "[i] Installing gdb" make install;
94 |
95 | echo;
96 | highlight "[i] Installation successfull. Add the following to your shell profile:";
97 | echo "[i] export PATH=${PREFIX}/bin:\$PATH";
98 | )
99 |
--------------------------------------------------------------------------------
/build-dbt-cross-compiler/BUILD-go/aarch64-elf/TEMPLATE-BUILD.go:
--------------------------------------------------------------------------------
1 | package aarch64
2 |
3 | import "dbt-rules/RULES/cc"
4 |
5 | var Toolchain = cc.GccToolchain{
6 | Ar: in("bin/aarch64-elf-ar"),
7 | As: in("bin/aarch64-elf-as"),
8 | Cc: in("bin/aarch64-elf-gcc"),
9 | Cpp: in("bin/aarch64-elf-gcc -E"),
10 | Cxx: in("bin/aarch64-elf-g++"),
11 | Objcopy: in("bin/aarch64-elf-objcopy"),
12 | Ld: in("bin/aarch64-elf-ld"),
13 |
14 | Includes: ins(
15 | "lib/gcc/aarch64-elf/GCC_VER/include",
16 | "lib/gcc/aarch64-elf/GCC_VER/include-fixed",
17 | ),
18 |
19 | CompilerFlags: []string{
20 | "-std=c++14",
21 | "-nostdinc",
22 | "-fdiagnostics-color=always",
23 | "-Wall",
24 | "-Wunused-but-set-parameter",
25 | "-Wno-free-nonheap-object",
26 | "-Wno-int-to-pointer-cast",
27 | "-fno-omit-frame-pointer",
28 | "-Wno-builtin-macro-redefined",
29 | "-D__DATE__=\"redacted\"",
30 | "-D__TIMESTAMP__=\"redacted\"",
31 | "-D__TIME__=\"redacted\"",
32 | "-ffreestanding",
33 | },
34 |
35 | LinkerFlags: []string{
36 | "-ffreestanding",
37 | "-nostdlib",
38 | "-lgcc",
39 | },
40 |
41 | ArchName: "aarch64",
42 | TargetName: "elf64-littleaarch64",
43 | }
44 |
45 | var CrtBegin = in("lib/gcc/aarch64-elf/GCC_VER/crtbegin.o")
46 | var CrtEnd = in("lib/gcc/aarch64-elf/GCC_VER/crtend.o")
47 |
--------------------------------------------------------------------------------
/build-dbt-cross-compiler/BUILD-go/x86_64-elf/TEMPLATE-BUILD.go:
--------------------------------------------------------------------------------
1 | package x86_64
2 |
3 | import "dbt-rules/RULES/cc"
4 |
5 | var Toolchain = cc.GccToolchain{
6 | Ar: in("bin/x86_64-elf-ar"),
7 | As: in("bin/x86_64-elf-as"),
8 | Cc: in("bin/x86_64-elf-gcc"),
9 | Cpp: in("bin/x86_64-elf-gcc -E"),
10 | Cxx: in("bin/x86_64-elf-g++"),
11 | Objcopy: in("bin/x86_64-elf-objcopy"),
12 | Ld: in("bin/x86_64-elf-ld"),
13 |
14 | Includes: ins(
15 | "lib/gcc/x86_64-elf/GCC_VER/include",
16 | "lib/gcc/x86_64-elf/GCC_VER/include-fixed",
17 | ),
18 |
19 | CompilerFlags: []string{
20 | "-std=c++14",
21 | "-nostdinc",
22 | "-fdiagnostics-color=always",
23 | "-Wall",
24 | "-Wunused-but-set-parameter",
25 | "-Wno-free-nonheap-object",
26 | "-Wno-int-to-pointer-cast",
27 | "-fno-omit-frame-pointer",
28 | "-Wno-builtin-macro-redefined",
29 | "-D__DATE__=\"redacted\"",
30 | "-D__TIMESTAMP__=\"redacted\"",
31 | "-D__TIME__=\"redacted\"",
32 | "-ffreestanding",
33 | "-mno-red-zone",
34 | },
35 |
36 | LinkerFlags: []string{
37 | "-ffreestanding",
38 | "-nostdlib",
39 | "-lgcc",
40 | "-z",
41 | "max-page-size=0x1000",
42 | },
43 |
44 | ArchName: "i386",
45 | TargetName: "elf64-x86-64",
46 | }
47 |
48 | var CrtBegin = in("lib/gcc/x86_64-elf/GCC_VER/crtbegin.o")
49 | var CrtEnd = in("lib/gcc/x86_64-elf/GCC_VER/crtend.o")
50 |
--------------------------------------------------------------------------------
/build-dbt-cross-compiler/build-dbt-cross-compiler.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | GCCVER=11.1.0
4 | BINUTILSVER=2.31.1
5 | HOST=`uname -m`
6 |
7 | function error() {
8 | echo -e "\033[1;31m$@\\033[0m";
9 | }
10 |
11 | function highlight() {
12 | echo -e "\033[1;32m$@\\033[0m";
13 | }
14 |
15 | function progress() {
16 | echo -n "$1... "
17 | shift
18 | TEMPFILE=`mktemp`
19 | eval $@ >$TEMPFILE 2>&1
20 | if [ $? -ne 0 ]; then
21 | echo -e "\033[1;5;31merror\033[0m"
22 | cat $TEMPFILE
23 | rm $TEMPFILE
24 | exit 1
25 | fi
26 | rm $TEMPFILE
27 | echo "done"
28 | }
29 |
30 | if [ $# -ne 1 ]; then
31 | echo "[i] Usage: $0 target"
32 | echo "[i] ie: $0 x86_64-elf"
33 | exit 1
34 | fi
35 |
36 | TARGET=$1;
37 |
38 | SCRIPT_DIR=`dirname "$0"`
39 | BUILD_GO=`readlink -f "${SCRIPT_DIR}/BUILD-go/${TARGET}/TEMPLATE-BUILD.go"`
40 |
41 | if [ ! -f "${BUILD_GO}" ]; then
42 | error "[e] Could not find dbt build file ${BUILD_GO}. Is the target ${TARGET} supported?"
43 | exit 1
44 | fi
45 |
46 | OUT_NAME="$TARGET-gcc-$GCCVER-binutils-$BINUTILSVER-$HOST"
47 | OUT_TAR=`readlink -f "${OUT_NAME}.tar.gz"`
48 |
49 | highlight "[i] Package parameters:"
50 | echo "[i] Cross compiler target: ${TARGET}"
51 | echo "[i] GCC version: ${GCCVER}"
52 | echo "[i] Binutils version: ${BINUTILSVER}"
53 | echo "[i] Compiling packages for: ${HOST}"
54 | echo "[i] Output package: ${OUT}"
55 | echo
56 | echo
57 |
58 | highlight "[i] For the build to succeed you need to have the following packages installed:"
59 | echo "[i] ]==> sudo apt-get install build-essential libgmp-dev libmpc-dev libmpfr-dev"
60 | echo
61 |
62 | read -p "[?] Do you want to continue? (y/n) " -n 1 -r
63 | echo
64 |
65 | if [ x"$REPLY" != xy ]; then
66 | echo "[i] Bye."
67 | exit 0
68 | fi
69 |
70 | TEMPDIR=`mktemp -d`
71 | PREFIX="${TEMPDIR}/${OUT_NAME}"
72 |
73 | (
74 | echo "[i] Working in ${TEMPDIR}"
75 | cd $TEMPDIR
76 | mkdir out
77 | echo
78 |
79 | highlight "[i] Downloading packages"
80 | progress "[i] Donwloading binutils" \
81 | wget http://ftp.gnu.org/gnu/binutils/binutils-${BINUTILSVER}.tar.bz2
82 | progress "[i] Downloading gcc" \
83 | wget ftp://ftp.fu-berlin.de/unix/languages/gcc/releases/gcc-${GCCVER}/gcc-${GCCVER}.tar.xz
84 | highlight "[i] Downloads done"
85 | echo
86 |
87 | highlight "[i] Binutils"
88 | progress "[i] Unpacking binutils" tar jxf binutils-${BINUTILSVER}.tar.bz2
89 | mkdir binutils-build
90 | cd binutils-build
91 | progress "[i] Configuring binutils" ../binutils-${BINUTILSVER}/configure --target=${TARGET} --prefix=${PREFIX} \
92 | --with-sysroot --disable-nls --disable-werror
93 | progress "[i] Building binutils" make -j 4
94 | progress "[i] Adding binutils" make install
95 | export PATH=${PREFIX}/bin:$PATH
96 | cd ..
97 | highlight "[i] Binutils done"
98 | echo
99 |
100 | highlight "[i] GCC"
101 | progress "[i] Unpacking gcc" tar xf gcc-${GCCVER}.tar.xz;
102 | mkdir gcc-build
103 | cd gcc-build
104 | progress "[i] Configuring gcc" ../gcc-${GCCVER}/configure --target=${TARGET} --prefix=${PREFIX} \
105 | --disable-nls --enable-languages=c,c++ --without-headers
106 | progress "[i] Building gcc" make -j4 all-gcc
107 | progress "[i] Building libgcc" make -j4 all-target-libgcc
108 | progress "[i] Adding gcc" make install-gcc
109 | progress "[i] Adding libgcc" make install-target-libgcc
110 | progress "[i] Adding unwind-pe.h" cp ../gcc-${GCCVER}/libgcc/unwind-pe.h \
111 | ${PREFIX}/lib/gcc/${TARGET}/${GCCVER}/include
112 | cd ..
113 | highlight "[i] GCC done"
114 | echo
115 |
116 |
117 | progress "[i] Adding BUILD.go" cp ${BUILD_GO} ${PREFIX}/BUILD.go
118 | sed -i -e "s/GCC_VER/${GCCVER}/g" ${PREFIX}/BUILD.go
119 | progress "[i] Making package" tar -czvf ${OUT_TAR} ${OUT_NAME}
120 | highlight "[i] Package ${OUT_TAR} created successfully"
121 | )
122 |
--------------------------------------------------------------------------------
/cmake/Kernel.cmake:
--------------------------------------------------------------------------------
1 | #-------------------------------------------------------------------------------
2 | # Copyright (C) 2018-2019 Daedalean AG
3 | #
4 | # This library is free software; you can redistribute it and/or modify it
5 | # under the terms of the GNU General Public License as published by the
6 | # Free Software Foundation; either version 3, or (at your option)
7 | # any later version.
8 | #
9 | # This library is distributed in the hope that it will be useful,
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | # GNU General Public License for more details.
13 | #
14 | # Under Section 7 of GPL version 3, you are granted additional
15 | # permissions described in the GCC Runtime Library Exception, version
16 | # 3.1, as published by the Free Software Foundation.
17 | #
18 | # You should have received a copy of the GNU General Public License and
19 | # a copy of the GCC Runtime Library Exception along with this program;
20 | # see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | # .
22 | #-------------------------------------------------------------------------------
23 |
24 | macro(add_gcc_object variable obj name)
25 | execute_process(
26 | COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -print-file-name=${obj}
27 | OUTPUT_VARIABLE OBJ_COMP
28 | )
29 |
30 | string(STRIP ${OBJ_COMP} OBJ_COMP)
31 |
32 | set(${variable} ${CMAKE_CURRENT_BINARY_DIR}/${name}${CMAKE_C_OUTPUT_EXTENSION})
33 |
34 | add_custom_command(
35 | OUTPUT ${${variable}}
36 | COMMAND ${CMAKE_COMMAND} -E copy_if_different ${OBJ_COMP} ${${variable}}
37 | DEPENDS ${OBJ_COMP}
38 | COMMENT "Importing ${OBJ_COMP} as ${name}"
39 | )
40 | endmacro(add_gcc_object)
41 |
42 | function(add_kernel)
43 | set(oneValueArgs NAME)
44 | set(multiValueArgs LIBS)
45 | cmake_parse_arguments(add_kernel "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
46 |
47 | add_custom_command(
48 | OUTPUT ${add_kernel_NAME}-fake.c
49 | COMMAND ${CMAKE_COMMAND} -E touch ${add_kernel_NAME}-fake.c
50 | )
51 |
52 | add_executable(
53 | ${add_kernel_NAME}.elf
54 | ${add_kernel_NAME}-fake.c
55 | )
56 |
57 | target_link_libraries(
58 | ${add_kernel_NAME}.elf
59 | -Wl,--whole-archive
60 | boot_first
61 | -Wl,--no-whole-archive
62 | ${add_kernel_LIBS}
63 | supcxx
64 | gcc
65 | runcxx
66 | -Wl,--whole-archive
67 | boot_last
68 | -Wl,--no-whole-archive
69 | )
70 |
71 | add_custom_command(
72 | OUTPUT ${add_kernel_NAME}.hex
73 | COMMAND ${CMAKE_OBJCOPY} -O binary ${add_kernel_NAME}.elf ${add_kernel_NAME}.hex
74 | DEPENDS ${add_kernel_NAME}.elf
75 | COMMENT "Creating raw binary ${add_kernel_NAME}.hex")
76 |
77 | add_custom_target(${add_kernel_NAME}.hex-target ALL DEPENDS ${add_kernel_NAME}.hex)
78 | endfunction(add_kernel)
79 |
--------------------------------------------------------------------------------
/io/BUILD.go:
--------------------------------------------------------------------------------
1 | package io
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | )
6 |
7 | var Lib = cc.Library{
8 | Out: out("libio.a"),
9 | Srcs: ins(
10 | "printf.cc",
11 | "io.cc",
12 | ),
13 | AlwaysLink: true,
14 | }.MultipleToolchains()
15 |
--------------------------------------------------------------------------------
/io/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_library(
3 | io STATIC
4 | printf.cc
5 | io.cc
6 | )
7 |
--------------------------------------------------------------------------------
/io/io.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2016 Lukasz Janyst
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/io/io.hh"
25 |
26 | extern "C" void _putChar(char c);
27 |
28 | namespace io {
29 | void putString(const char *str) {
30 | if (!str) {
31 | return;
32 | }
33 | for (; *str; ++str) {
34 | _putChar(*str);
35 | }
36 | }
37 |
38 | void putString(const char *str, size_t size) {
39 | if (!str) {
40 | return;
41 | }
42 | for (size_t i = 0; i < size; ++i) {
43 | _putChar(str[i]);
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/io/io.hh:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #pragma once
25 |
26 | #include
27 | #include
28 |
29 | namespace io {
30 |
31 | void putString(const char *str);
32 |
33 | void putString(const char *str, size_t size);
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/io/memory.hh:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 |
26 |
27 | namespace io {
28 | struct Region {
29 | void *address;
30 | size_t size;
31 | };
32 | extern "C" void *malloc(size_t size);
33 | extern "C" void free(void *ptr);
34 | } // namespace io
35 |
--------------------------------------------------------------------------------
/io/printf.hh:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #pragma once
25 |
26 | #include
27 | #include
28 |
29 | namespace io {
30 |
31 | int printf(const char *format, ...);
32 | int vprintf(const char *format, va_list va);
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/libruncxx/BUILD.go:
--------------------------------------------------------------------------------
1 | package libruncxx
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | )
6 |
7 | var Lib = cc.Library{
8 | Out: out("libruncxx.a"),
9 | Srcs: ins(
10 | "dtors.cc",
11 | "memory.cc",
12 | "guard.cc",
13 | "string.cc",
14 | "eh_alloc.cc",
15 | "eh_globals.cc",
16 | "exit.cc",
17 | ),
18 | AlwaysLink: true,
19 | }.MultipleToolchains()
20 |
--------------------------------------------------------------------------------
/libruncxx/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_library(
3 | runcxx STATIC
4 | dtors.cc
5 | memory.cc
6 | guard.cc
7 | string.cc
8 | eh_alloc.cc
9 | eh_globals.cc
10 | exit.cc
11 | )
12 |
--------------------------------------------------------------------------------
/libruncxx/dtors.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 |
26 | namespace {
27 | // Maximum number of global destructors that the runtime can keep on the
28 | // record. There's no heap memory at this point, and we want to keep things
29 | // simple, so we're stuck with whatever we preconfigure here.
30 | const size_t GLIBCXX_NUM_GLOBAL_DTORS = 100;
31 | }
32 |
33 | namespace {
34 | struct DtorEntry {
35 | void (*dtor)(void*);
36 | void *arg;
37 | };
38 |
39 | size_t numDtors = 0;
40 | DtorEntry dtors[GLIBCXX_NUM_GLOBAL_DTORS];
41 | } // namespace
42 |
43 | namespace __cxxabiv1 {
44 | extern "C" {
45 |
46 | int __cxa_atexit(void (*dtor)(void*), void *arg, void *dsoHandle) noexcept {
47 | if (numDtors == GLIBCXX_NUM_GLOBAL_DTORS) {
48 | return -1;
49 | }
50 |
51 | dtors[numDtors].dtor = dtor;
52 | dtors[numDtors].arg = arg;
53 | // this is a kernel, we don't care about any DSO contex - ignore dsoHandle
54 | ++numDtors;
55 | return 0;
56 | }
57 |
58 | int __cxa_finalize(void *dtor) {
59 | // If we get a nullptr here, we call all of the destructors
60 | if (dtor == nullptr) {
61 | for (int i = numDtors - 1; i >= 0; --i) {
62 | dtors[i].dtor(dtors[i].arg);
63 | }
64 | numDtors = 0;
65 | return 0;
66 | }
67 |
68 | // If we got a pointer we search for the destructor and call it if found
69 | for (size_t i = numDtors - 1; i >= 0; --i) {
70 | if (dtors[i].dtor == dtor) {
71 | dtors[i].dtor(dtors[i].arg);
72 | dtors[i].dtor = nullptr;
73 | }
74 | }
75 |
76 | // Elliminate all the nullptrs set in the previous loop
77 | size_t j = 0;
78 | for (size_t i = 0; i < numDtors; ++i) {
79 | if (dtors[i].dtor == nullptr) {
80 | continue;
81 | }
82 | dtors[j].dtor = dtors[i].dtor;
83 | dtors[j].arg = dtors[i].arg;
84 | ++j;
85 | }
86 | numDtors = j;
87 |
88 | return 0;
89 | }
90 |
91 | namespace {
92 | // register the destructor with the runtime
93 | [[gnu::destructor]] void call_cxa_finalize() {
94 | __cxxabiv1::__cxa_finalize(nullptr);
95 | }
96 | } // namespace
97 |
98 | } // extern "C"
99 | } // namespace __cxxabiv1
100 |
--------------------------------------------------------------------------------
/libruncxx/eh_alloc.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
25 | #include
26 | #include
27 | #include
28 |
29 | extern "C" void *malloc(size_t);
30 | extern "C" void free(void *);
31 |
32 | // C++ throws the std::bad_alloc exception when it fails to allocate memory.
33 | // We need to keep all exception objects out of the stack because the stack
34 | // gets unwound when processing an exception. We therefore stash some memory
35 | // so that we always have enough to at least throw std::bad_alloc.
36 | //
37 | // See: https://itanium-cxx-abi.github.io/cxx-abi/abi-eh.html#cxx-allocate
38 | namespace {
39 | const uint16_t OBJ_SIZE = 1024;
40 | const uint16_t NUM_OBJS = 8;
41 |
42 | char emergencyPool[NUM_OBJS][OBJ_SIZE];
43 | bool emergencyAllocated[NUM_OBJS] = {false};
44 | } // namespace
45 |
46 | namespace __cxxabiv1 {
47 | extern "C" void *__cxa_allocate_exception(size_t thrownSize) noexcept {
48 | // The ABI requires us to have a preamble for all the exception metadata
49 | thrownSize += sizeof(__cxa_refcounted_exception);
50 | void *ret = malloc(thrownSize);
51 |
52 | if (!ret && thrownSize <= OBJ_SIZE) {
53 | for (uint32_t i = 0; i < NUM_OBJS; ++i) {
54 | if (!emergencyAllocated[i]) {
55 | emergencyAllocated[i] = true;
56 | ret = (void*)emergencyPool[i];
57 | break;
58 | }
59 | }
60 | }
61 |
62 | if (!ret) {
63 | std::terminate();
64 | }
65 | // The preamble is one thing, but we need to return the pointer to the actual
66 | // exception.
67 | return (void*)((char*)ret + sizeof(__cxa_refcounted_exception));
68 | }
69 |
70 | extern "C" void __cxa_free_exception(void *vptr) noexcept {
71 | // We allocated the object with the preamble, so we need to adjust the pointer
72 | char *ptr = (char*)vptr - sizeof(__cxa_refcounted_exception);
73 | bool freed = false;
74 | for (uint32_t i = 0; i < NUM_OBJS; ++i) {
75 | if (emergencyPool[i] == ptr) {
76 | emergencyAllocated[i] = 0;
77 | freed = true;
78 | }
79 | }
80 |
81 | if (!freed) {
82 | free(ptr);
83 | }
84 | }
85 |
86 | } // namespace __cxxabiv1
87 |
--------------------------------------------------------------------------------
/libruncxx/eh_globals.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | namespace __cxxabiv1 {
25 | struct __cxa_exception;
26 | struct __cxa_eh_globals {
27 | __cxa_exception *caughtExceptions;
28 | unsigned int uncaughtExceptions;
29 | };
30 | }
31 |
32 | namespace {
33 | __cxxabiv1::__cxa_eh_globals globals;
34 | }
35 |
36 | namespace __cxxabiv1 {
37 | extern "C" __cxa_eh_globals *__cxa_get_globals_fast() noexcept {
38 | return &globals;
39 | }
40 |
41 | extern "C" __cxa_eh_globals *__cxa_get_globals() noexcept {
42 | return &globals;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/libruncxx/exit.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/libsupcxx/src/cxxabi.h"
25 |
26 | extern "C" void abort();
27 |
28 | extern "C" void exit() noexcept {
29 | __cxxabiv1::__cxa_finalize(nullptr);
30 | abort();
31 | }
32 |
33 | typedef void (*atExitFn)(void*);
34 |
35 | extern "C" int atexit(void (*fn)()) noexcept {
36 | return __cxxabiv1::__cxa_atexit((atExitFn)fn, 0, 0);
37 | }
38 |
--------------------------------------------------------------------------------
/libruncxx/guard.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 | #include "libsupcxx/libsupcxx/src/exception_defines.h"
26 | #include "libsupcxx/libsupcxx/src/cxxabi.h"
27 |
28 | #if __cpp_exceptions
29 | namespace __gnu_cxx {
30 | recursive_init_error::~recursive_init_error() noexcept { }
31 | }
32 | #endif
33 |
34 | // See: https://itanium-cxx-abi.github.io/cxx-abi/abi.html#once-ctor
35 | // The implementation below is not really compliant, because the GNU library
36 | // uses the second byte of the guard to either throw an exception or abort if
37 | // the initializer is called recursively.
38 | namespace __cxxabiv1 {
39 | extern "C" int __cxa_guard_acquire(uint64_t *guard) {
40 | if ((*guard) & 0x01) {
41 | return 0;
42 | }
43 | if ((*guard) & 0x0100) {
44 | _GLIBCXX_THROW_OR_ABORT(__gnu_cxx::recursive_init_error());
45 | }
46 | *guard |= 0x0100;
47 | return 1;
48 | }
49 |
50 | extern "C" void __cxa_guard_release(uint64_t *guard) noexcept {
51 | *guard |= 0x01;
52 | }
53 |
54 | extern "C" void __cxa_guard_abort(uint64_t *guard) noexcept {
55 | }
56 | } // namespace __cxxabiv1
57 |
--------------------------------------------------------------------------------
/libruncxx/memory.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include "libsupcxx/io/memory.hh"
25 | #include "libsupcxx/boot/bootinfo.hh"
26 |
27 | #include
28 | #include
29 |
30 | // This variable does not exist, but its address is known to the linker. See the
31 | // linker script for details.
32 | extern uint32_t __kernelEnd;
33 |
34 | namespace {
35 | struct MemChunk {
36 | MemChunk *next;
37 | uint64_t size;
38 | };
39 |
40 | static MemChunk *head = 0;
41 | const uint64_t MEMCHUNK_USED = 0x8000000000000000;
42 | }
43 |
44 | extern "C" void *malloc(size_t size) {
45 | // We don't allocate chunks this big
46 | if (head == 0 || size > 0x7fffffffffffffff) {
47 | return nullptr;
48 | }
49 |
50 | // Allocating anything less than 8 bytes is kind of pointless, the
51 | // book-keeping overhead is too big. We will also align to 8 bytes.
52 | // AArch64 platforms refuse to cooperate otherwise.
53 | uint64_t allocSize = (((size-1)>>3)<<3)+8;
54 |
55 | // Try to find a suitable chunk that is unused
56 | MemChunk *chunk = head;
57 | while (chunk) {
58 | if (!(chunk->size & MEMCHUNK_USED) && chunk->size >= allocSize) {
59 | break;
60 | }
61 | chunk = chunk->next;
62 | }
63 |
64 | if (!chunk) {
65 | return nullptr;
66 | }
67 |
68 | // Split the chunk if it's big enough to contain one more header and enough
69 | // bytes to handle another chunk of size 8 bytes.
70 | if (chunk->size >= allocSize + sizeof(MemChunk) + 8) {
71 | MemChunk *newChunk = (MemChunk *)((char *)chunk + sizeof(MemChunk) + allocSize);
72 | newChunk->size = chunk->size - allocSize - sizeof(MemChunk);
73 | newChunk->next = chunk->next;
74 | chunk->next = newChunk;
75 | chunk->size = allocSize;
76 | }
77 |
78 | // Mark the chunk as used and return the memory
79 | chunk->size |= MEMCHUNK_USED;
80 | return (char*)chunk + sizeof(MemChunk);
81 | }
82 |
83 | extern "C" void free(void *ptr) {
84 | if (!ptr) {
85 | return;
86 | }
87 |
88 | MemChunk *chunk = (MemChunk *)((char *)ptr - sizeof(MemChunk));
89 | chunk->size &= ~MEMCHUNK_USED;
90 | }
91 |
92 | extern BootInfo bootInfo;
93 |
94 | namespace {
95 | [[gnu::constructor]] void setUpHeap() {
96 | MemChunk fakeHead;
97 | MemChunk *cursor = &fakeHead;
98 | uint64_t kernelEnd = (uint64_t)&__kernelEnd;
99 |
100 | for (uint16_t i = 0; i < bootInfo.numMemoryRegions; ++i) {
101 | uint64_t start = bootInfo.memoryMap[i].start;
102 | uint64_t end = bootInfo.memoryMap[i].end;
103 | const MemoryType type = bootInfo.memoryMap[i].type;
104 |
105 | // We can only put the heap in RAM
106 | if (type != MemoryType::RAM) {
107 | continue;
108 | }
109 |
110 | uint64_t size = end - start;
111 |
112 | // Check if this RAM segment contains the kernel
113 | if (start < kernelEnd && end >= kernelEnd) {
114 | start = kernelEnd;
115 | }
116 |
117 | // Check if this RAM segment contains the kernel commandline. We assume that
118 | // it may be located immediately after the kernel or at the beginning of the
119 | // chunk. We also assume that the commandline fits the page.
120 | uint64_t cmdlineAddr = (uint64_t)bootInfo.cmdline;
121 | if (start <= cmdlineAddr && end > cmdlineAddr) {
122 | start = (uint64_t)bootInfo.cmdline + 0x1000;
123 | }
124 |
125 | // Align the start to 4K
126 | start -= 1;
127 | start >>= 12;
128 | start <<= 12;
129 | start += 0x1000;
130 | if (end >= start) {
131 | size = end - start;
132 | } else {
133 | size = 0;
134 | }
135 |
136 | // We only care if it's at least a Megabyte
137 | if (size < 0x00100000) {
138 | continue;
139 | }
140 |
141 | cursor->next = (MemChunk *)start;
142 | cursor = cursor->next;
143 | cursor->next = 0;
144 | cursor->size = size - sizeof(MemChunk);
145 | }
146 | head = fakeHead.next;
147 | }
148 | }
149 |
--------------------------------------------------------------------------------
/libruncxx/string.cc:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2018-2019 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #include
25 |
26 | extern "C" size_t strlen(const char *str) {
27 | size_t len;
28 | for (len = 0; *str; ++str, ++len) {};
29 | return len;
30 | }
31 |
32 | extern "C" void *memcpy(void *dest, const void *src, size_t n) {
33 | char *d = (char*)dest;
34 | const char *s = (const char*)src;
35 | for (size_t i = 0; i < n; ++i) {
36 | *d++ = *s++;
37 | }
38 | return dest;
39 | }
40 |
41 | extern "C" void *memset(void *s, int c, size_t n) {
42 | char *data = (char*)s;
43 | for (size_t i = 0; i < n; ++i) {
44 | data[i] = c;
45 | }
46 | return s;
47 | }
48 |
49 | extern "C" char *strchr(const char *s, int c) {
50 | do {
51 | if (*s == c) {
52 | return (char*)s;
53 | }
54 | } while (*s++);
55 | return 0;
56 | }
57 |
--------------------------------------------------------------------------------
/libsupcxx/include/BUILD.go:
--------------------------------------------------------------------------------
1 | package include
2 |
3 | var Headers = ins(".")
4 |
--------------------------------------------------------------------------------
/libsupcxx/include/bits/c++config.h:
--------------------------------------------------------------------------------
1 | // Predefined symbols and macros -*- C++ -*-
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file bits/c++config.h
26 | * This is an internal header file, included by other library headers.
27 | * Do not attempt to use it directly. @headername{iosfwd}
28 | */
29 |
30 | #ifndef _GLIBCXX_CXX_CONFIG_H
31 | #define _GLIBCXX_CXX_CONFIG_H 1
32 |
33 | // The major release number for the GCC release the C++ library belongs to.
34 | #define _GLIBCXX_RELEASE 8
35 |
36 | // The datestamp of the C++ library in compressed ISO date format.
37 | #define __GLIBCXX__ 20180726
38 |
39 | #endif // _GLIBCXX_CXX_CONFIG_H
40 |
41 | // End of prewritten config; the settings discovered at configure time follow.
42 |
--------------------------------------------------------------------------------
/libsupcxx/include/bits/exception.h:
--------------------------------------------------------------------------------
1 | // Exception Handling support header for -*- C++ -*-
2 |
3 | // Copyright (C) 2016-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file bits/exception.h
27 | * This is an internal header file, included by other library headers.
28 | * Do not attempt to use it directly.
29 | */
30 |
31 | #ifndef __EXCEPTION_H
32 | #define __EXCEPTION_H 1
33 |
34 | #pragma GCC system_header
35 |
36 | #pragma GCC visibility push(default)
37 |
38 | extern "C++" {
39 |
40 | namespace std
41 | {
42 | /**
43 | * @defgroup exceptions Exceptions
44 | * @ingroup diagnostics
45 | *
46 | * Classes and functions for reporting errors via exception classes.
47 | * @{
48 | */
49 |
50 | /**
51 | * @brief Base class for all library exceptions.
52 | *
53 | * This is the base class for all exceptions thrown by the standard
54 | * library, and by certain language expressions. You are free to derive
55 | * your own %exception classes, or use a different hierarchy, or to
56 | * throw non-class data (e.g., fundamental types).
57 | */
58 | class exception
59 | {
60 | public:
61 | exception() noexcept { }
62 | virtual ~exception() noexcept;
63 |
64 | /** Returns a C-style character string describing the general cause
65 | * of the current error. */
66 | virtual const char*
67 | what() const noexcept;
68 | };
69 | } // namespace std
70 |
71 | }
72 |
73 | #pragma GCC visibility pop
74 |
75 | #endif
76 |
--------------------------------------------------------------------------------
/libsupcxx/include/bits/hash_bytes.h:
--------------------------------------------------------------------------------
1 | // Declarations for hash functions. -*- C++ -*-
2 |
3 | // Copyright (C) 2010-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file bits/hash_bytes.h
26 | * This is an internal header file, included by other library headers.
27 | * Do not attempt to use it directly. @headername{functional}
28 | */
29 |
30 | #ifndef _HASH_BYTES_H
31 | #define _HASH_BYTES_H 1
32 |
33 | #pragma GCC system_header
34 |
35 | #include
36 |
37 | namespace std
38 | {
39 | // Hash function implementation for the nontrivial specialization.
40 | // All of them are based on a primitive that hashes a pointer to a
41 | // byte array. The actual hash algorithm is not guaranteed to stay
42 | // the same from release to release -- it may be updated or tuned to
43 | // improve hash quality or speed.
44 | size_t
45 | _Hash_bytes(const void* __ptr, size_t __len, size_t __seed);
46 |
47 | // A similar hash primitive, using the FNV hash algorithm. This
48 | // algorithm is guaranteed to stay the same from release to release.
49 | // (although it might not produce the same values on different
50 | // machines.)
51 | size_t
52 | _Fnv_hash_bytes(const void* __ptr, size_t __len, size_t __seed);
53 | } // namespace
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/libsupcxx/include/cfloat:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cfloat
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c float.h,
30 | * and its contents are (mostly) the same as that header, but are all
31 | * contained in the namespace @c std (except for names which are defined
32 | * as macros in C).
33 | */
34 |
35 | //
36 | // ISO C++ 14882: 18.2.2 Implementation properties: C library
37 | //
38 |
39 | #pragma GCC system_header
40 |
41 | #include
42 |
43 | #ifndef _GLIBCXX_CFLOAT
44 | #define _GLIBCXX_CFLOAT 1
45 |
46 | # ifndef DECIMAL_DIG
47 | # define DECIMAL_DIG __DECIMAL_DIG__
48 | # endif
49 | # ifndef FLT_EVAL_METHOD
50 | # define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
51 | # endif
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/libsupcxx/include/ciso646:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 2001-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file ciso646
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c iso646.h,
30 | * which is empty in C++.
31 | */
32 | #ifndef _GLIBCXX_CISO646
33 | #define _GLIBCXX_CISO646
34 |
35 | #pragma GCC system_header
36 |
37 | #include
38 | #endif
39 |
--------------------------------------------------------------------------------
/libsupcxx/include/climits:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/climits
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c limits.h,
30 | * and its contents are (mostly) the same as that header, but are all
31 | * contained in the namespace @c std (except for names which are defined
32 | * as macros in C).
33 | */
34 |
35 | //
36 | // ISO C++ 14882: 18.2.2 Implementation properties: C library
37 | //
38 |
39 | #pragma GCC system_header
40 |
41 | #include
42 |
43 | #ifndef _GLIBCXX_CLIMITS
44 | #define _GLIBCXX_CLIMITS 1
45 |
46 | #ifndef LLONG_MIN
47 | #define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
48 | #endif
49 |
50 | #ifndef LLONG_MAX
51 | #define LLONG_MAX __LONG_LONG_MAX__
52 | #endif
53 |
54 | #ifndef ULLONG_MAX
55 | #define ULLONG_MAX (__LONG_LONG_MAX__ * 2ULL + 1)
56 | #endif
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstdalign:
--------------------------------------------------------------------------------
1 | // -*- C++ -*-
2 |
3 | // Copyright (C) 2011-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cstdalign
26 | * This is a Standard C++ Library header.
27 | */
28 |
29 | #pragma GCC system_header
30 |
31 | #ifndef _GLIBCXX_CSTDALIGN
32 | #define _GLIBCXX_CSTDALIGN 1
33 |
34 | // alignas is a keyword from C++11 onwards. The standard requires the
35 | // __alignas_is_defined backwards compatibility macro to always be 1, however
36 | // stdalign.h defines it only for C, not for C++.
37 | // #include
38 |
39 | #define __alignas_is_defined 1
40 |
41 | #endif
42 |
43 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstdarg:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cstdarg
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c stdarg.h,
30 | * and its contents are (mostly) the same as that header, but are all
31 | * contained in the namespace @c std (except for names which are defined
32 | * as macros in C).
33 | */
34 |
35 | //
36 | // ISO C++ 14882: 20.4.6 C library
37 | //
38 |
39 | #pragma GCC system_header
40 |
41 | #undef __need___va_list
42 | #include
43 | #include
44 |
45 | #ifndef _GLIBCXX_CSTDARG
46 | #define _GLIBCXX_CSTDARG 1
47 |
48 | // Adhere to section 17.4.1.2 clause 5 of ISO 14882:1998
49 | #ifndef va_end
50 | #define va_end(ap) va_end (ap)
51 | #endif
52 |
53 | namespace std
54 | {
55 | using ::va_list;
56 | } // namespace std
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstdbool:
--------------------------------------------------------------------------------
1 | // -*- C++ -*-
2 |
3 | // Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cstdbool
26 | * This is a Standard C++ Library header.
27 | */
28 |
29 | #pragma GCC system_header
30 |
31 | #ifndef _GLIBCXX_CSTDBOOL
32 | #define _GLIBCXX_CSTDBOOL 1
33 |
34 | #include
35 |
36 | #endif
37 |
38 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstddef:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file cstddef
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c stddef.h,
30 | * and its contents are (mostly) the same as that header, but are all
31 | * contained in the namespace @c std (except for names which are defined
32 | * as macros in C).
33 | */
34 |
35 | //
36 | // ISO C++ 14882: 18.1 Types
37 | //
38 |
39 | #ifndef _GLIBCXX_CSTDDEF
40 | #define _GLIBCXX_CSTDDEF 1
41 |
42 | #pragma GCC system_header
43 |
44 | #undef __need_wchar_t
45 | #undef __need_ptrdiff_t
46 | #undef __need_size_t
47 | #undef __need_NULL
48 | #undef __need_wint_t
49 | #include
50 |
51 | namespace std
52 | {
53 | using ::size_t;
54 | using ::ptrdiff_t;
55 | using ::nullptr_t;
56 | using ::max_align_t;
57 | }
58 |
59 | #endif // _GLIBCXX_CSTDDEF
60 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstdint:
--------------------------------------------------------------------------------
1 | // -*- C++ -*-
2 |
3 | // Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cstdint
26 | * This is a Standard C++ Library header.
27 | */
28 |
29 | #ifndef _GLIBCXX_CSTDINT
30 | #define _GLIBCXX_CSTDINT 1
31 |
32 | #pragma GCC system_header
33 |
34 | #include
35 |
36 | namespace std
37 | {
38 | using ::int8_t;
39 | using ::int16_t;
40 | using ::int32_t;
41 | using ::int64_t;
42 |
43 | using ::int_fast8_t;
44 | using ::int_fast16_t;
45 | using ::int_fast32_t;
46 | using ::int_fast64_t;
47 |
48 | using ::int_least8_t;
49 | using ::int_least16_t;
50 | using ::int_least32_t;
51 | using ::int_least64_t;
52 |
53 | using ::intmax_t;
54 | using ::intptr_t;
55 |
56 | using ::uint8_t;
57 | using ::uint16_t;
58 | using ::uint32_t;
59 | using ::uint64_t;
60 |
61 | using ::uint_fast8_t;
62 | using ::uint_fast16_t;
63 | using ::uint_fast32_t;
64 | using ::uint_fast64_t;
65 |
66 | using ::uint_least8_t;
67 | using ::uint_least16_t;
68 | using ::uint_least32_t;
69 | using ::uint_least64_t;
70 |
71 | using ::uintmax_t;
72 | using ::uintptr_t;
73 | } // namespace std
74 |
75 | #endif // _GLIBCXX_CSTDINT
76 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstdlib:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- forwarding header.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file include/cstdlib
26 | * This is a Standard C++ Library file. You should @c \#include this file
27 | * in your programs, rather than any of the @a *.h implementation files.
28 | *
29 | * This is the C++ version of the Standard C Library header @c stdlib.h,
30 | * and its contents are (mostly) the same as that header, but are all
31 | * contained in the namespace @c std (except for names which are defined
32 | * as macros in C).
33 | */
34 |
35 | //
36 | // ISO C++ 14882: 20.4.6 C library
37 | //
38 |
39 | #pragma GCC system_header
40 |
41 | #ifndef _GLIBCXX_CSTDLIB
42 | #define _GLIBCXX_CSTDLIB 1
43 |
44 | // The C standard does not require a freestanding implementation to
45 | // provide . However, the C++ standard does still require
46 | // -- but only the functionality mentioned in
47 | // [lib.support.start.term].
48 |
49 | #define EXIT_SUCCESS 0
50 | #define EXIT_FAILURE 1
51 |
52 | namespace std
53 | {
54 | extern "C" [[noreturn]] void abort(void) noexcept;
55 | extern "C" int atexit(void (*)(void)) noexcept;
56 | extern "C" [[noreturn]] void exit(int) noexcept;
57 | } // namespace std
58 |
59 | #endif
60 |
--------------------------------------------------------------------------------
/libsupcxx/include/cstring:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | // Copyright (C) 2021 Daedalean AG
3 | //
4 | // This library is free software; you can redistribute it and/or modify it
5 | // under the terms of the GNU General Public License as published by the
6 | // Free Software Foundation; either version 3, or (at your option)
7 | // any later version.
8 | //
9 | // This library is distributed in the hope that it will be useful,
10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | // GNU General Public License for more details.
13 | //
14 | // Under Section 7 of GPL version 3, you are granted additional
15 | // permissions described in the GCC Runtime Library Exception, version
16 | // 3.1, as published by the Free Software Foundation.
17 | //
18 | // You should have received a copy of the GNU General Public License and
19 | // a copy of the GCC Runtime Library Exception along with this program;
20 | // see the files LICENSE and LICENSE.RUNTIME respectively. If not, see
21 | // .
22 | //------------------------------------------------------------------------------
23 |
24 | #pragma once
25 |
26 | #include
27 |
28 | extern "C" size_t strlen(const char *str);
29 | extern "C" char *strncpy(char *dest, const char *src, size_t num);
30 | extern "C" char *memcpy(void *dest, const void *src, size_t num);
31 | extern "C" char *memset(void *dest, int c, size_t num);
32 | extern "C" int strncmp(const char *s1, const char *s2, size_t n);
33 | const char *strstr(const char *haystack, const char *needle);
34 | unsigned long strtoul(const char *nptr, const char **endptr, int base);
35 |
--------------------------------------------------------------------------------
/libsupcxx/include/exception:
--------------------------------------------------------------------------------
1 | // Exception Handling support header for -*- C++ -*-
2 |
3 | // Copyright (C) 1995-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file exception
27 | * This is a Standard C++ Library header.
28 | */
29 |
30 | #ifndef __EXCEPTION__
31 | #define __EXCEPTION__
32 |
33 | #pragma GCC system_header
34 |
35 | #pragma GCC visibility push(default)
36 |
37 | #include
38 |
39 | extern "C++" {
40 |
41 | namespace std
42 | {
43 | /** If an %exception is thrown which is not listed in a function's
44 | * %exception specification, one of these may be thrown. */
45 | class bad_exception : public exception
46 | {
47 | public:
48 | bad_exception() noexcept { }
49 |
50 | // This declaration is not useless:
51 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
52 | virtual ~bad_exception() noexcept;
53 |
54 | // See comment in eh_exception.cc.
55 | virtual const char*
56 | what() const noexcept;
57 | };
58 |
59 | /// If you write a replacement %terminate handler, it must be of this type.
60 | typedef void (*terminate_handler) ();
61 |
62 | /// If you write a replacement %unexpected handler, it must be of this type.
63 | typedef void (*unexpected_handler) ();
64 |
65 | /// Takes a new handler function as an argument, returns the old function.
66 | terminate_handler set_terminate(terminate_handler) noexcept;
67 |
68 | /// Return the current terminate handler.
69 | terminate_handler get_terminate() noexcept;
70 |
71 | /** The runtime will call this function if %exception handling must be
72 | * abandoned for any reason. It can also be called by the user. */
73 | [[noreturn]] void terminate() noexcept;
74 |
75 | /// Takes a new handler function as an argument, returns the old function.
76 | unexpected_handler set_unexpected(unexpected_handler) noexcept;
77 |
78 | /// Return the current unexpected handler.
79 | unexpected_handler get_unexpected() noexcept;
80 |
81 | /** The runtime will call this function if an %exception is thrown which
82 | * violates the function's %exception specification. */
83 | [[noreturn]] void unexpected();
84 |
85 | /** [18.6.4]/1: 'Returns true after completing evaluation of a
86 | * throw-expression until either completing initialization of the
87 | * exception-declaration in the matching handler or entering @c unexpected()
88 | * due to the throw; or after entering @c terminate() for any reason
89 | * other than an explicit call to @c terminate(). [Note: This includes
90 | * stack unwinding [15.2]. end note]'
91 | *
92 | * 2: 'When @c uncaught_exception() is true, throwing an
93 | * %exception can result in a call of @c terminate()
94 | * (15.5.1).'
95 | */
96 | [[gnu::pure]] bool uncaught_exception() noexcept;
97 | // @} group exceptions
98 | } // namespace std
99 | } // extern "C++"
100 |
101 | #pragma GCC visibility pop
102 |
103 | #endif
104 |
--------------------------------------------------------------------------------
/libsupcxx/include/initializer_list:
--------------------------------------------------------------------------------
1 | // std::initializer_list support -*- C++ -*-
2 |
3 | // Copyright (C) 2008-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file initializer_list
27 | * This is a Standard C++ Library header.
28 | */
29 |
30 | #ifndef _INITIALIZER_LIST
31 | #define _INITIALIZER_LIST
32 |
33 | #include
34 |
35 | #pragma GCC system_header
36 |
37 | #pragma GCC visibility push(default)
38 |
39 | namespace std
40 | {
41 | /// initializer_list
42 | template
43 | class initializer_list
44 | {
45 | public:
46 | typedef _E value_type;
47 | typedef const _E& reference;
48 | typedef const _E& const_reference;
49 | typedef size_t size_type;
50 | typedef const _E* iterator;
51 | typedef const _E* const_iterator;
52 |
53 | private:
54 | iterator _M_array;
55 | size_type _M_len;
56 |
57 | // The compiler can call a private constructor.
58 | constexpr initializer_list(const_iterator __a, size_type __l)
59 | : _M_array(__a), _M_len(__l) { }
60 |
61 | public:
62 | constexpr initializer_list() noexcept
63 | : _M_array(0), _M_len(0) { }
64 |
65 | // Number of elements.
66 | constexpr size_type
67 | size() const noexcept { return _M_len; }
68 |
69 | // First element.
70 | constexpr const_iterator
71 | begin() const noexcept { return _M_array; }
72 |
73 | // One past the last element.
74 | constexpr const_iterator
75 | end() const noexcept { return begin() + size(); }
76 | };
77 |
78 | /**
79 | * @brief Return an iterator pointing to the first element of
80 | * the initializer_list.
81 | * @param __ils Initializer list.
82 | */
83 | template
84 | constexpr const _Tp*
85 | begin(initializer_list<_Tp> __ils) noexcept
86 | { return __ils.begin(); }
87 |
88 | /**
89 | * @brief Return an iterator pointing to one past the last element
90 | * of the initializer_list.
91 | * @param __ils Initializer list.
92 | */
93 | template
94 | constexpr const _Tp*
95 | end(initializer_list<_Tp> __ils) noexcept
96 | { return __ils.end(); }
97 | }
98 |
99 | #pragma GCC visibility pop
100 |
101 | #endif // _INITIALIZER_LIST
102 |
--------------------------------------------------------------------------------
/libsupcxx/include/new:
--------------------------------------------------------------------------------
1 | // The -*- C++ -*- dynamic memory management header.
2 |
3 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
4 |
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file new
27 | * This is a Standard C++ Library header.
28 | *
29 | * The header @c new defines several functions to manage dynamic memory and
30 | * handling memory allocation errors; see
31 | * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more.
32 | */
33 |
34 | #ifndef _NEW
35 | #define _NEW
36 |
37 | #pragma GCC system_header
38 |
39 | #include
40 | #include
41 |
42 | #pragma GCC visibility push(default)
43 |
44 | extern "C++" {
45 |
46 | namespace std
47 | {
48 | /**
49 | * @brief Exception possibly thrown by @c new.
50 | * @ingroup exceptions
51 | *
52 | * @c bad_alloc (or classes derived from it) is used to report allocation
53 | * errors from the throwing forms of @c new. */
54 | class bad_alloc : public exception
55 | {
56 | public:
57 | bad_alloc() noexcept { }
58 |
59 | // This declaration is not useless:
60 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
61 | virtual ~bad_alloc() noexcept;
62 |
63 | // See comment in eh_exception.cc.
64 | virtual const char* what() const noexcept;
65 | };
66 |
67 | class bad_array_new_length : public bad_alloc
68 | {
69 | public:
70 | bad_array_new_length() noexcept { }
71 |
72 | // This declaration is not useless:
73 | // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
74 | virtual ~bad_array_new_length() noexcept;
75 |
76 | // See comment in eh_exception.cc.
77 | virtual const char* what() const noexcept;
78 | };
79 |
80 | struct nothrow_t
81 | {
82 | explicit nothrow_t() = default;
83 | };
84 |
85 | extern const nothrow_t nothrow;
86 |
87 | /** If you write your own error handler to be called by @c new, it must
88 | * be of this type. */
89 | typedef void (*new_handler)();
90 |
91 | /// Takes a replacement handler as the argument, returns the
92 | /// previous handler.
93 | new_handler set_new_handler(new_handler) noexcept;
94 |
95 | /// Return the current new handler.
96 | new_handler get_new_handler() noexcept;
97 | } // namespace std
98 |
99 | //@{
100 | /** These are replaceable signatures:
101 | * - normal single new and delete (no arguments, throw @c bad_alloc on error)
102 | * - normal array new and delete (same)
103 | * - @c nothrow single new and delete (take a @c nothrow argument, return
104 | * @c NULL on error)
105 | * - @c nothrow array new and delete (same)
106 | *
107 | * Placement new and delete signatures (take a memory address argument,
108 | * does nothing) may not be replaced by a user's program.
109 | */
110 | [[gnu::externally_visible]] void* operator new(std::size_t);
111 | [[gnu::externally_visible]] void* operator new[](std::size_t);
112 | [[gnu::externally_visible]] void operator delete(void*) noexcept;
113 | [[gnu::externally_visible]] void operator delete[](void*) noexcept;
114 | #if __cpp_sized_deallocation
115 | [[gnu::externally_visible]] void operator delete(void*, std::size_t) noexcept;
116 | [[gnu::externally_visible]] void operator delete[](void*, std::size_t) noexcept;
117 | #endif
118 | [[gnu::externally_visible]] void* operator new(std::size_t, const std::nothrow_t&) noexcept;
119 | [[gnu::externally_visible]] void* operator new[](std::size_t, const std::nothrow_t&) noexcept;
120 | [[gnu::externally_visible]] void operator delete(void*, const std::nothrow_t&) noexcept;
121 | [[gnu::externally_visible]] void operator delete[](void*, const std::nothrow_t&) noexcept;
122 |
123 | // Default placement versions of operator new.
124 | inline void* operator new(std::size_t, void* __p) noexcept
125 | { return __p; }
126 | inline void* operator new[](std::size_t, void* __p) noexcept
127 | { return __p; }
128 |
129 | // Default placement versions of operator delete.
130 | inline void operator delete (void*, void*) noexcept { }
131 | inline void operator delete[](void*, void*) noexcept { }
132 | //@}
133 | } // extern "C++"
134 |
135 | #pragma GCC visibility pop
136 |
137 | #endif
138 |
--------------------------------------------------------------------------------
/libsupcxx/src/BUILD.go:
--------------------------------------------------------------------------------
1 | package src
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | )
6 |
7 | var Lib = cc.Library{
8 | Out: out("libsupcxx.a"),
9 | Srcs: ins(
10 | "del_op.cc",
11 | "del_opnt.cc",
12 | "del_ops.cc",
13 | "del_opv.cc",
14 | "del_opvnt.cc",
15 | "del_opvs.cc",
16 | "new_op.cc",
17 | "new_opnt.cc",
18 | "new_opv.cc",
19 | "new_opvnt.cc",
20 | "new_handler.cc",
21 |
22 | "pure.cc",
23 |
24 | "dyncast.cc",
25 | "eh_aux_runtime.cc",
26 | "hash_bytes.cc",
27 | "tinfo.cc",
28 |
29 | "array_type_info.cc",
30 | "class_type_info.cc",
31 | "enum_type_info.cc",
32 | "function_type_info.cc",
33 | "fundamental_type_info.cc",
34 | "pbase_type_info.cc",
35 | "pmem_type_info.cc",
36 | "pointer_type_info.cc",
37 | "si_class_type_info.cc",
38 | "vmi_class_type_info.cc",
39 |
40 | "bad_alloc.cc",
41 | "bad_cast.cc",
42 | "bad_typeid.cc",
43 | "bad_array_new.cc",
44 | "eh_exception.cc",
45 | "eh_terminate.cc",
46 | "eh_term_handler.cc",
47 | "eh_unex_handler.cc",
48 | "eh_personality.cc",
49 | "eh_throw.cc",
50 | "eh_catch.cc",
51 | "eh_call.cc",
52 |
53 | "cstring.cc",
54 | ),
55 | AlwaysLink: true,
56 | }.MultipleToolchains()
57 |
--------------------------------------------------------------------------------
/libsupcxx/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | add_library(
3 | supcxx STATIC
4 |
5 | # heap
6 | del_op.cc
7 | del_opnt.cc
8 | del_ops.cc
9 | del_opv.cc
10 | del_opvnt.cc
11 | del_opvs.cc
12 | new_op.cc
13 | new_opnt.cc
14 | new_opv.cc
15 | new_opvnt.cc
16 | new_handler.cc
17 |
18 | # heap objects with pure virtuals, but not stack objects
19 | pure.cc
20 |
21 | # rtti
22 | dyncast.cc
23 | eh_aux_runtime.cc
24 | hash_bytes.cc
25 | tinfo.cc
26 |
27 | array_type_info.cc
28 | class_type_info.cc
29 | enum_type_info.cc
30 | function_type_info.cc
31 | fundamental_type_info.cc
32 | pbase_type_info.cc
33 | pmem_type_info.cc
34 | pointer_type_info.cc
35 | si_class_type_info.cc
36 | vmi_class_type_info.cc
37 |
38 | # exceptions
39 | bad_alloc.cc
40 | bad_cast.cc
41 | bad_typeid.cc
42 | bad_array_new.cc
43 | eh_exception.cc
44 | eh_terminate.cc
45 | eh_term_handler.cc
46 | eh_unex_handler.cc
47 | eh_personality.cc
48 | eh_throw.cc
49 | eh_catch.cc
50 | eh_call.cc
51 |
52 | cstring.cc
53 | )
54 |
--------------------------------------------------------------------------------
/libsupcxx/src/array_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __array_type_info::
29 | ~__array_type_info ()
30 | {}
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/libsupcxx/src/bad_alloc.cc:
--------------------------------------------------------------------------------
1 | // Implementation file for the -*- C++ -*- dynamic memory management header.
2 |
3 | // Copyright (C) 2010-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | std::bad_alloc::~bad_alloc() noexcept { }
29 |
30 | const char*
31 | std::bad_alloc::what() const noexcept
32 | {
33 | return "std::bad_alloc";
34 | }
35 |
--------------------------------------------------------------------------------
/libsupcxx/src/bad_array_new.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2013-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include
25 |
26 | namespace std
27 | {
28 |
29 | bad_array_new_length::~bad_array_new_length() noexcept { }
30 |
31 | const char*
32 | bad_array_new_length::what() const noexcept
33 | { return "std::bad_array_new_length"; }
34 |
35 | } // namespace std
36 |
--------------------------------------------------------------------------------
/libsupcxx/src/bad_cast.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include
25 |
26 | namespace std {
27 |
28 | bad_cast::~bad_cast() noexcept { }
29 |
30 | const char*
31 | bad_cast::what() const noexcept
32 | {
33 | return "std::bad_cast";
34 | }
35 |
36 | } // namespace std
37 |
--------------------------------------------------------------------------------
/libsupcxx/src/bad_typeid.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include
25 |
26 | namespace std {
27 |
28 | bad_typeid::~bad_typeid() noexcept { }
29 |
30 | const char*
31 | bad_typeid::what() const noexcept
32 | {
33 | return "std::bad_typeid";
34 | }
35 |
36 | } // namespace std
37 |
--------------------------------------------------------------------------------
/libsupcxx/src/class_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __class_type_info::
29 | ~__class_type_info ()
30 | {}
31 |
32 | bool __class_type_info::
33 | __do_catch (const type_info *thr_type,
34 | void **thr_obj,
35 | unsigned outer) const
36 | {
37 | if (*this == *thr_type)
38 | return true;
39 | if (outer >= 4)
40 | // Neither `A' nor `A *'.
41 | return false;
42 | return thr_type->__do_upcast (this, thr_obj);
43 | }
44 |
45 | bool __class_type_info::
46 | __do_upcast (const __class_type_info *dst_type,
47 | void **obj_ptr) const
48 | {
49 | __upcast_result result (__vmi_class_type_info::__flags_unknown_mask);
50 |
51 | __do_upcast (dst_type, *obj_ptr, result);
52 | if (!contained_public_p (result.part2dst))
53 | return false;
54 | *obj_ptr = const_cast (result.dst_ptr);
55 | return true;
56 | }
57 |
58 | __class_type_info::__sub_kind __class_type_info::
59 | __do_find_public_src (ptrdiff_t,
60 | const void *obj_ptr,
61 | const __class_type_info *,
62 | const void *src_ptr) const
63 | {
64 | if (src_ptr == obj_ptr)
65 | // Must be our type, as the pointers match.
66 | return __contained_public;
67 | return __not_contained;
68 | }
69 |
70 | bool __class_type_info::
71 | __do_dyncast (ptrdiff_t,
72 | __sub_kind access_path,
73 | const __class_type_info *dst_type,
74 | const void *obj_ptr,
75 | const __class_type_info *src_type,
76 | const void *src_ptr,
77 | __dyncast_result &__restrict result) const
78 | {
79 | if (obj_ptr == src_ptr && *this == *src_type)
80 | {
81 | // The src object we started from. Indicate how we are accessible from
82 | // the most derived object.
83 | result.whole2src = access_path;
84 | return false;
85 | }
86 | if (*this == *dst_type)
87 | {
88 | result.dst_ptr = obj_ptr;
89 | result.whole2dst = access_path;
90 | result.dst2src = __not_contained;
91 | return false;
92 | }
93 | return false;
94 | }
95 |
96 | bool __class_type_info::
97 | __do_upcast (const __class_type_info *dst, const void *obj,
98 | __upcast_result &__restrict result) const
99 | {
100 | if (*this == *dst)
101 | {
102 | result.dst_ptr = obj;
103 | result.base_type = nonvirtual_base_type;
104 | result.part2dst = __contained_public;
105 | return true;
106 | }
107 | return false;
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/libsupcxx/src/cxxabi_forced.h:
--------------------------------------------------------------------------------
1 | // cxxabi.h subset for cancellation -*- C++ -*-
2 |
3 | // Copyright (C) 2007-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file bits/cxxabi_forced.h
27 | * This is an internal header file, included by other library headers.
28 | * Do not attempt to use it directly. @headername{cxxabi.h}
29 | */
30 |
31 | #ifndef _CXXABI_FORCED_H
32 | #define _CXXABI_FORCED_H 1
33 |
34 | #pragma GCC system_header
35 |
36 | #pragma GCC visibility push(default)
37 |
38 | namespace __cxxabiv1
39 | {
40 | /**
41 | * @brief Thrown as part of forced unwinding.
42 | * @ingroup exceptions
43 | *
44 | * A magic placeholder class that can be caught by reference to
45 | * recognize forced unwinding.
46 | */
47 | class __forced_unwind
48 | {
49 | virtual ~__forced_unwind() noexcept;
50 |
51 | // Prevent catch by value.
52 | virtual void __pure_dummy() = 0;
53 | };
54 | }
55 |
56 | #pragma GCC visibility pop
57 |
58 | #endif // __CXXABI_FORCED_H
59 |
--------------------------------------------------------------------------------
/libsupcxx/src/cxxabi_init_exception.h:
--------------------------------------------------------------------------------
1 | // ABI Support -*- C++ -*-
2 |
3 | // Copyright (C) 2016-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | /** @file bits/cxxabi_init_exception.h
27 | * This is an internal header file, included by other library headers.
28 | * Do not attempt to use it directly.
29 | */
30 |
31 | #ifndef _CXXABI_INIT_EXCEPTION_H
32 | #define _CXXABI_INIT_EXCEPTION_H 1
33 |
34 | #pragma GCC system_header
35 |
36 | #pragma GCC visibility push(default)
37 |
38 | #include
39 |
40 | #ifdef __cplusplus
41 |
42 | namespace std
43 | {
44 | class type_info;
45 | }
46 |
47 | namespace __cxxabiv1
48 | {
49 | struct __cxa_refcounted_exception;
50 |
51 | extern "C"
52 | {
53 | // Allocate memory for the primary exception plus the thrown object.
54 | void*
55 | __cxa_allocate_exception(size_t) noexcept;
56 |
57 | void
58 | __cxa_free_exception(void*) noexcept;
59 |
60 | // Initialize exception (this is a GNU extension)
61 | __cxa_refcounted_exception*
62 | __cxa_init_primary_exception(void *object, std::type_info *tinfo,
63 | void (*dest) (void *)) noexcept;
64 | }
65 | } // namespace __cxxabiv1
66 |
67 | #endif
68 |
69 | #pragma GCC visibility pop
70 |
71 | #endif // _CXXABI_INIT_EXCEPTION_H
72 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_op.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | namespace std
27 | {
28 | extern "C" void free(void*);
29 | } // namespace
30 |
31 | #include
32 |
33 | // The sized deletes are defined in other files.
34 | #pragma GCC diagnostic ignored "-Wsized-deallocation"
35 |
36 | void operator delete(void *ptr) noexcept
37 | {
38 | std::free(ptr);
39 | }
40 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_opnt.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | namespace std
27 | {
28 | extern "C" void free(void*);
29 | } // namespace
30 |
31 | #include
32 |
33 | void operator delete (void *ptr, const std::nothrow_t&) noexcept
34 | {
35 | std::free(ptr);
36 | }
37 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_ops.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #pragma GCC diagnostic ignored "-Wsized-deallocation"
27 |
28 | #include
29 |
30 | void operator delete(void *ptr, std::size_t) noexcept
31 | {
32 | ::operator delete (ptr);
33 | }
34 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_opv.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | // The sized deletes are defined in other files.
29 | #pragma GCC diagnostic ignored "-Wsized-deallocation"
30 |
31 | void operator delete[] (void *ptr) noexcept
32 | {
33 | ::operator delete (ptr);
34 | }
35 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_opvnt.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | void operator delete[] (void *ptr, const std::nothrow_t&) noexcept
29 | {
30 | ::operator delete (ptr);
31 | }
32 |
--------------------------------------------------------------------------------
/libsupcxx/src/del_opvs.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #pragma GCC diagnostic ignored "-Wsized-deallocation"
27 | #include
28 |
29 | void operator delete[] (void *ptr, std::size_t) noexcept
30 | {
31 | ::operator delete[] (ptr);
32 | }
33 |
--------------------------------------------------------------------------------
/libsupcxx/src/dyncast.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 |
29 | // this is the external interface to the dynamic cast machinery
30 | /* sub: source address to be adjusted; nonnull, and since the
31 | * source object is polymorphic, *(void**)sub is a virtual pointer.
32 | * src: static type of the source object.
33 | * dst: destination type (the "T" in "dynamic_cast(v)").
34 | * src2dst_offset: a static hint about the location of the
35 | * source subobject with respect to the complete object;
36 | * special negative values are:
37 | * -1: no hint
38 | * -2: src is not a public base of dst
39 | * -3: src is a multiple public base type but never a
40 | * virtual base type
41 | * otherwise, the src type is a unique public nonvirtual
42 | * base type of dst at offset src2dst_offset from the
43 | * origin of dst. */
44 | extern "C" void *
45 | __dynamic_cast (const void *src_ptr, // object started from
46 | const __class_type_info *src_type, // type of the starting object
47 | const __class_type_info *dst_type, // desired target type
48 | ptrdiff_t src2dst) // how src and dst are related
49 | {
50 | const void *vtable = *static_cast (src_ptr);
51 | const vtable_prefix *prefix =
52 | adjust_pointer (vtable,
53 | -offsetof (vtable_prefix, origin));
54 | const void *whole_ptr =
55 | adjust_pointer (src_ptr, prefix->whole_object);
56 | const __class_type_info *whole_type = prefix->whole_type;
57 | __class_type_info::__dyncast_result result;
58 |
59 | // If the whole object vptr doesn't refer to the whole object type, we're
60 | // in the middle of constructing a primary base, and src is a separate
61 | // base. This has undefined behavior and we can't find anything outside
62 | // of the base we're actually constructing, so fail now rather than
63 | // segfault later trying to use a vbase offset that doesn't exist.
64 | const void *whole_vtable = *static_cast (whole_ptr);
65 | const vtable_prefix *whole_prefix =
66 | adjust_pointer (whole_vtable,
67 | -offsetof (vtable_prefix, origin));
68 | if (whole_prefix->whole_type != whole_type)
69 | return NULL;
70 |
71 | whole_type->__do_dyncast (src2dst, __class_type_info::__contained_public,
72 | dst_type, whole_ptr, src_type, src_ptr, result);
73 | if (!result.dst_ptr)
74 | return NULL;
75 | if (contained_public_p (result.dst2src))
76 | // Src is known to be a public base of dst.
77 | return const_cast (result.dst_ptr);
78 | if (contained_public_p (__class_type_info::__sub_kind (result.whole2src & result.whole2dst)))
79 | // Both src and dst are known to be public bases of whole. Found a valid
80 | // cross cast.
81 | return const_cast (result.dst_ptr);
82 | if (contained_nonvirtual_p (result.whole2src))
83 | // Src is known to be a non-public nonvirtual base of whole, and not a
84 | // base of dst. Found an invalid cross cast, which cannot also be a down
85 | // cast
86 | return NULL;
87 | if (result.dst2src == __class_type_info::__unknown)
88 | result.dst2src = dst_type->__find_public_src (src2dst, result.dst_ptr,
89 | src_type, src_ptr);
90 | if (contained_public_p (result.dst2src))
91 | // Found a valid down cast
92 | return const_cast (result.dst_ptr);
93 | // Must be an invalid down cast, or the cross cast wasn't bettered
94 | return NULL;
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_aux_runtime.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- Common throw conditions.
2 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 | //
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include
26 | #include
27 | #include "libsupcxx/libsupcxx/src/exception_defines.h"
28 |
29 | #include "libsupcxx/libsupcxx/src/cxxabi.h"
30 |
31 | extern "C" void
32 | __cxxabiv1::__cxa_bad_cast ()
33 | { _GLIBCXX_THROW_OR_ABORT(std::bad_cast()); }
34 |
35 | extern "C" void
36 | __cxxabiv1::__cxa_bad_typeid ()
37 | { _GLIBCXX_THROW_OR_ABORT(std::bad_typeid()); }
38 |
39 | extern "C" void
40 | __cxxabiv1::__cxa_throw_bad_array_new_length ()
41 | { _GLIBCXX_THROW_OR_ABORT(std::bad_array_new_length()); }
42 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_call.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- Helpers for calling unextected and terminate
2 | // Copyright (C) 2001-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
26 |
27 | using namespace __cxxabiv1;
28 |
29 | // Helper routine for when the exception handling code needs to call
30 | // terminate.
31 |
32 | extern "C" void
33 | __cxa_call_terminate(_Unwind_Exception* ue_header) noexcept
34 | {
35 |
36 | if (ue_header)
37 | {
38 | // terminate is classed as a catch handler.
39 | __cxa_begin_catch(ue_header);
40 |
41 | // Call the terminate handler that was in effect when we threw this
42 | // exception. */
43 | if (__is_gxx_exception_class(ue_header->exception_class))
44 | {
45 | __cxa_exception* xh;
46 |
47 | xh = __get_exception_header_from_ue(ue_header);
48 | __terminate(xh->terminateHandler);
49 | }
50 | }
51 | /* Call the global routine if we don't have anything better. */
52 | std::terminate();
53 | }
54 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_catch.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- Exception handling routines for catching.
2 | // Copyright (C) 2001-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
26 |
27 | using namespace __cxxabiv1;
28 |
29 | extern "C" void *
30 | __cxxabiv1::__cxa_get_exception_ptr(void *exc_obj_in) noexcept
31 | {
32 | _Unwind_Exception *exceptionObject
33 | = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
34 |
35 | return __gxx_caught_object(exceptionObject);
36 | }
37 |
38 | extern "C" void *
39 | __cxxabiv1::__cxa_begin_catch (void *exc_obj_in) noexcept
40 | {
41 | _Unwind_Exception *exceptionObject
42 | = reinterpret_cast <_Unwind_Exception *>(exc_obj_in);
43 | __cxa_eh_globals *globals = __cxa_get_globals ();
44 | __cxa_exception *prev = globals->caughtExceptions;
45 | __cxa_exception *header = __get_exception_header_from_ue (exceptionObject);
46 | void* objectp;
47 |
48 | // Foreign exceptions can't be stacked here. If the exception stack is
49 | // empty, then fine. Otherwise we really have no choice but to terminate.
50 | // Note that this use of "header" is a lie. It's fine so long as we only
51 | // examine header->unwindHeader though.
52 | if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
53 | {
54 | if (prev != 0)
55 | std::terminate ();
56 |
57 | // Remember for end_catch and rethrow.
58 | globals->caughtExceptions = header;
59 |
60 | // ??? No sensible value to return; we don't know what the
61 | // object is, much less where it is in relation to the header.
62 | return 0;
63 | }
64 |
65 | int count = header->handlerCount;
66 | // Count is less than zero if this exception was rethrown from an
67 | // immediately enclosing region.
68 | if (count < 0)
69 | count = -count + 1;
70 | else
71 | count += 1;
72 | header->handlerCount = count;
73 | globals->uncaughtExceptions -= 1;
74 |
75 | if (header != prev)
76 | {
77 | header->nextException = prev;
78 | globals->caughtExceptions = header;
79 | }
80 |
81 | objectp = __gxx_caught_object(exceptionObject);
82 |
83 | return objectp;
84 | }
85 |
86 |
87 | extern "C" void
88 | __cxxabiv1::__cxa_end_catch ()
89 | {
90 | __cxa_eh_globals *globals = __cxa_get_globals_fast ();
91 | __cxa_exception *header = globals->caughtExceptions;
92 |
93 | // A rethrow of a foreign exception will be removed from the
94 | // the exception stack immediately by __cxa_rethrow.
95 | if (!header)
96 | return;
97 |
98 | // A foreign exception couldn't have been stacked (see above),
99 | // so by definition processing must be complete.
100 | if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
101 | {
102 | globals->caughtExceptions = 0;
103 | _Unwind_DeleteException (&header->unwindHeader);
104 | return;
105 | }
106 |
107 | int count = header->handlerCount;
108 | if (count < 0)
109 | {
110 | // This exception was rethrown. Decrement the (inverted) catch
111 | // count and remove it from the chain when it reaches zero.
112 | if (++count == 0)
113 | globals->caughtExceptions = header->nextException;
114 | }
115 | else if (--count == 0)
116 | {
117 | // Handling for this exception is complete. Destroy the object.
118 | globals->caughtExceptions = header->nextException;
119 | _Unwind_DeleteException (&header->unwindHeader);
120 | return;
121 | }
122 | else if (count < 0)
123 | // A bug in the exception handling library or compiler.
124 | std::terminate ();
125 |
126 | header->handlerCount = count;
127 | }
128 |
129 |
130 | bool
131 | std::uncaught_exception() noexcept
132 | {
133 | #if __cpp_exceptions
134 | __cxa_eh_globals *globals = __cxa_get_globals ();
135 | return globals->uncaughtExceptions != 0;
136 | #else
137 | return false;
138 | #endif
139 | }
140 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_exception.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- std::exception implementation.
2 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include
26 | #include "libsupcxx/libsupcxx/src/cxxabi.h"
27 |
28 | std::exception::~exception() noexcept { }
29 |
30 | std::bad_exception::~bad_exception() noexcept
31 | { }
32 |
33 | abi::__forced_unwind::~__forced_unwind() noexcept { }
34 |
35 | abi::__foreign_exception::~__foreign_exception() noexcept { }
36 |
37 | const char*
38 | std::exception::what() const noexcept
39 | {
40 | // NB: Another elegant option would be returning typeid(*this).name()
41 | // and not overriding what() in bad_exception, bad_alloc, etc. In
42 | // that case, however, mangled names would be returned, PR 14493.
43 | return "std::exception";
44 | }
45 |
46 | const char*
47 | std::bad_exception::what() const noexcept
48 | {
49 | return "std::bad_exception";
50 | }
51 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_term_handler.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- std::terminate handler
2 | // Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
26 |
27 | /* The current installed user handler. */
28 | std::terminate_handler __cxxabiv1::__terminate_handler = __builtin_abort;
29 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_terminate.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- std::terminate, std::unexpected and friends.
2 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include
26 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
27 | #include "libsupcxx/libsupcxx/src/exception_defines.h"
28 |
29 | using namespace __cxxabiv1;
30 |
31 | void
32 | __cxxabiv1::__terminate (std::terminate_handler handler) noexcept
33 | {
34 | __try
35 | {
36 | handler ();
37 | __builtin_abort ();
38 | }
39 | __catch(...)
40 | { __builtin_abort (); }
41 | }
42 |
43 | void
44 | std::terminate () noexcept
45 | {
46 | __terminate (get_terminate ());
47 | }
48 |
49 | void
50 | __cxxabiv1::__unexpected (std::unexpected_handler handler)
51 | {
52 | handler();
53 | std::terminate ();
54 | }
55 |
56 | void
57 | std::unexpected ()
58 | {
59 | __unexpected (get_unexpected ());
60 | }
61 |
62 | std::terminate_handler
63 | std::set_terminate (std::terminate_handler func) noexcept
64 | {
65 | std::terminate_handler old = __terminate_handler;
66 | __terminate_handler = func;
67 | return old;
68 | }
69 |
70 | std::terminate_handler
71 | std::get_terminate () noexcept
72 | {
73 | return __terminate_handler;
74 | }
75 |
76 | std::unexpected_handler
77 | std::set_unexpected (std::unexpected_handler func) noexcept
78 | {
79 | std::unexpected_handler old = __unexpected_handler;
80 | __unexpected_handler = func;
81 | return old;
82 | }
83 |
84 | std::unexpected_handler
85 | std::get_unexpected () noexcept
86 | {
87 | return __unexpected_handler;
88 | }
89 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_throw.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- Exception handling routines for throwing.
2 | // Copyright (C) 2001-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
26 |
27 | using namespace __cxxabiv1;
28 |
29 | static void
30 | __gxx_exception_cleanup (_Unwind_Reason_Code code, _Unwind_Exception *exc)
31 | {
32 | // This cleanup is set only for primaries.
33 | __cxa_refcounted_exception *header
34 | = __get_refcounted_exception_header_from_ue (exc);
35 |
36 | // We only want to be called through _Unwind_DeleteException.
37 | // _Unwind_DeleteException in the HP-UX IA64 libunwind library
38 | // returns _URC_NO_REASON and not _URC_FOREIGN_EXCEPTION_CAUGHT
39 | // like the GCC _Unwind_DeleteException function does.
40 | if (code != _URC_FOREIGN_EXCEPTION_CAUGHT && code != _URC_NO_REASON)
41 | __terminate (header->exc.terminateHandler);
42 |
43 | --header->referenceCount;
44 | if (!header->referenceCount)
45 | {
46 | if (header->exc.exceptionDestructor)
47 | header->exc.exceptionDestructor (header + 1);
48 |
49 | __cxa_free_exception (header + 1);
50 | }
51 | }
52 |
53 | extern "C" __cxa_refcounted_exception*
54 | __cxxabiv1::
55 | __cxa_init_primary_exception(void *obj, std::type_info *tinfo,
56 | void (*dest) (void *)) noexcept
57 | {
58 | __cxa_refcounted_exception *header
59 | = __get_refcounted_exception_header_from_obj (obj);
60 | header->referenceCount = 0;
61 | header->exc.exceptionType = tinfo;
62 | header->exc.exceptionDestructor = dest;
63 | header->exc.unexpectedHandler = std::get_unexpected ();
64 | header->exc.terminateHandler = std::get_terminate ();
65 | __GXX_INIT_PRIMARY_EXCEPTION_CLASS(header->exc.unwindHeader.exception_class);
66 | header->exc.unwindHeader.exception_cleanup = __gxx_exception_cleanup;
67 |
68 | return header;
69 | }
70 |
71 | extern "C" void
72 | __cxxabiv1::__cxa_throw (void *obj, std::type_info *tinfo,
73 | void (*dest) (void *))
74 | {
75 | __cxa_eh_globals *globals = __cxa_get_globals ();
76 | globals->uncaughtExceptions += 1;
77 |
78 | // Definitely a primary.
79 | __cxa_refcounted_exception *header =
80 | __cxa_init_primary_exception(obj, tinfo, dest);
81 | header->referenceCount = 1;
82 |
83 | _Unwind_RaiseException (&header->exc.unwindHeader);
84 |
85 | // Some sort of unwinding error. Note that terminate is a handler.
86 | __cxa_begin_catch (&header->exc.unwindHeader);
87 |
88 | std::terminate ();
89 | }
90 |
91 | extern "C" void
92 | __cxxabiv1::__cxa_rethrow ()
93 | {
94 | __cxa_eh_globals *globals = __cxa_get_globals ();
95 | __cxa_exception *header = globals->caughtExceptions;
96 |
97 | globals->uncaughtExceptions += 1;
98 |
99 | // Watch for luser rethrowing with no active exception.
100 | if (header)
101 | {
102 | // Tell __cxa_end_catch this is a rethrow.
103 | if (!__is_gxx_exception_class(header->unwindHeader.exception_class))
104 | globals->caughtExceptions = 0;
105 | else
106 | {
107 | header->handlerCount = -header->handlerCount;
108 | }
109 |
110 | _Unwind_Resume_or_Rethrow (&header->unwindHeader);
111 |
112 | // Some sort of unwinding error. Note that terminate is a handler.
113 | __cxa_begin_catch (&header->unwindHeader);
114 | }
115 |
116 | std::terminate ();
117 | }
118 |
--------------------------------------------------------------------------------
/libsupcxx/src/eh_unex_handler.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*- std::unexpected handler
2 | // Copyright (C) 2002-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/unwind-cxx.h"
26 |
27 | /* The current installed user handler. */
28 | std::unexpected_handler __cxxabiv1::__unexpected_handler = std::terminate;
29 |
30 |
--------------------------------------------------------------------------------
/libsupcxx/src/enum_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __enum_type_info::
29 | ~__enum_type_info ()
30 | {}
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/libsupcxx/src/exception_defines.h:
--------------------------------------------------------------------------------
1 | // -fno-exceptions Support -*- C++ -*-
2 |
3 | // Copyright (C) 2001-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of the GNU ISO C++ Library. This library is free
6 | // software; you can redistribute it and/or modify it under the
7 | // terms of the GNU General Public License as published by the
8 | // Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // This library is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | /** @file bits/exception_defines.h
26 | * This is an internal header file, included by other library headers.
27 | * Do not attempt to use it directly. @headername{exception}
28 | */
29 |
30 | #ifndef _EXCEPTION_DEFINES_H
31 | #define _EXCEPTION_DEFINES_H 1
32 |
33 | #if ! __cpp_exceptions
34 | // Iff -fno-exceptions, transform error handling code to work without it.
35 | # define _GLIBCXX_THROW_OR_ABORT(_EXC) (__builtin_abort())
36 | # define __try if (true)
37 | # define __catch(X) if (false)
38 | # define __throw_exception_again
39 | #else
40 | // Else proceed normally.
41 | # define _GLIBCXX_THROW_OR_ABORT(_EXC) (throw (_EXC))
42 | # define __try try
43 | # define __catch(X) catch(X)
44 | # define __throw_exception_again throw
45 | #endif
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/libsupcxx/src/function_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __function_type_info::
29 | ~__function_type_info ()
30 | {}
31 |
32 | bool __function_type_info::
33 | __is_function_p () const
34 | {
35 | return true;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/libsupcxx/src/fundamental_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | // This has special meaning to the compiler, and will cause it
29 | // to emit the type_info structures for the fundamental types which are
30 | // mandated to exist in the runtime.
31 | __fundamental_type_info::
32 | ~__fundamental_type_info ()
33 | {}
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/libsupcxx/src/new_handler.cc:
--------------------------------------------------------------------------------
1 | // Implementation file for the -*- C++ -*- dynamic memory management header.
2 |
3 | // Copyright (C) 1996-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | const std::nothrow_t std::nothrow = std::nothrow_t{ };
29 |
30 | using std::new_handler;
31 | namespace
32 | {
33 | new_handler __new_handler;
34 | }
35 |
36 | new_handler
37 | std::set_new_handler (new_handler handler) noexcept
38 | {
39 | new_handler prev_handler;
40 | prev_handler = __new_handler;
41 | __new_handler = handler;
42 | return prev_handler;
43 | }
44 |
45 | new_handler
46 | std::get_new_handler () noexcept
47 | {
48 | new_handler handler;
49 | handler = __new_handler;
50 | return handler;
51 | }
52 |
--------------------------------------------------------------------------------
/libsupcxx/src/new_op.cc:
--------------------------------------------------------------------------------
1 | // Support routines for the -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include "libsupcxx/libsupcxx/src/exception_defines.h"
27 | #include
28 |
29 | using std::new_handler;
30 | using std::bad_alloc;
31 |
32 | extern "C" void *malloc(std::size_t);
33 |
34 | void *operator new(std::size_t sz)
35 | {
36 | void *p;
37 |
38 | /* malloc (0) is unpredictable; avoid it. */
39 | if (sz == 0)
40 | sz = 1;
41 |
42 | while (__builtin_expect ((p = malloc (sz)) == 0, false))
43 | {
44 | new_handler handler = std::get_new_handler ();
45 | if (! handler)
46 | _GLIBCXX_THROW_OR_ABORT(bad_alloc());
47 | handler ();
48 | }
49 |
50 | return p;
51 | }
52 |
--------------------------------------------------------------------------------
/libsupcxx/src/new_opnt.cc:
--------------------------------------------------------------------------------
1 | // Support routines for the -*- C++ -*- dynamic memory management.
2 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include "libsupcxx/libsupcxx/src/exception_defines.h"
26 | #include
27 |
28 | using std::new_handler;
29 | using std::bad_alloc;
30 |
31 | extern "C" void *malloc (std::size_t);
32 |
33 | void *operator new (std::size_t sz, const std::nothrow_t&) noexcept
34 | {
35 | void *p;
36 |
37 | /* malloc (0) is unpredictable; avoid it. */
38 | if (sz == 0)
39 | sz = 1;
40 |
41 | while (__builtin_expect ((p = malloc (sz)) == 0, false))
42 | {
43 | new_handler handler = std::get_new_handler ();
44 | if (! handler)
45 | return 0;
46 | __try
47 | {
48 | handler ();
49 | }
50 | __catch(const bad_alloc&)
51 | {
52 | return 0;
53 | }
54 | }
55 |
56 | return p;
57 | }
58 |
--------------------------------------------------------------------------------
/libsupcxx/src/new_opv.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | void *operator new[] (std::size_t sz)
29 | {
30 | return ::operator new(sz);
31 | }
32 |
--------------------------------------------------------------------------------
/libsupcxx/src/new_opvnt.cc:
--------------------------------------------------------------------------------
1 | // Boilerplate support routines for -*- C++ -*- dynamic memory management.
2 |
3 | // Copyright (C) 1997-2018 Free Software Foundation, Inc.
4 | //
5 | // This file is part of GCC.
6 | //
7 | // GCC is free software; you can redistribute it and/or modify
8 | // it under the terms of the GNU General Public License as published by
9 | // the Free Software Foundation; either version 3, or (at your option)
10 | // any later version.
11 | //
12 | // GCC is distributed in the hope that it will be useful,
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | // GNU General Public License for more details.
16 | //
17 | // Under Section 7 of GPL version 3, you are granted additional
18 | // permissions described in the GCC Runtime Library Exception, version
19 | // 3.1, as published by the Free Software Foundation.
20 |
21 | // You should have received a copy of the GNU General Public License and
22 | // a copy of the GCC Runtime Library Exception along with this program;
23 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 | // .
25 |
26 | #include
27 |
28 | void *operator new[] (std::size_t sz, const std::nothrow_t ¬hrow) noexcept
29 | {
30 | return ::operator new(sz, nothrow);
31 | }
32 |
--------------------------------------------------------------------------------
/libsupcxx/src/pbase_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __pbase_type_info::
29 | ~__pbase_type_info ()
30 | {}
31 |
32 | bool __pbase_type_info::
33 | __do_catch (const type_info *thr_type,
34 | void **thr_obj,
35 | unsigned outer) const
36 | {
37 | if (*this == *thr_type)
38 | return true; // same type
39 |
40 | #if __cpp_rtti
41 | if (*thr_type == typeid (nullptr))
42 | {
43 | // A catch handler for any pointer type matches nullptr_t.
44 | if (typeid (*this) == typeid(__pointer_type_info))
45 | {
46 | *thr_obj = nullptr;
47 | return true;
48 | }
49 | else if (typeid (*this) == typeid(__pointer_to_member_type_info))
50 | {
51 | if (__pointee->__is_function_p ())
52 | {
53 | using pmf_type = void (__pbase_type_info::*)();
54 | static const pmf_type pmf = nullptr;
55 | *thr_obj = const_cast(&pmf);
56 | return true;
57 | }
58 | else
59 | {
60 | using pm_type = int __pbase_type_info::*;
61 | static const pm_type pm = nullptr;
62 | *thr_obj = const_cast(&pm);
63 | return true;
64 | }
65 | }
66 | }
67 |
68 | if (typeid (*this) != typeid (*thr_type))
69 | return false; // not both same kind of pointers
70 | #endif
71 |
72 | if (!(outer & 1))
73 | // We're not the same and our outer pointers are not all const qualified
74 | // Therefore there must at least be a qualification conversion involved
75 | // But for that to be valid, our outer pointers must be const qualified.
76 | return false;
77 |
78 | const __pbase_type_info *thrown_type =
79 | static_cast (thr_type);
80 |
81 | unsigned tflags = thrown_type->__flags;
82 |
83 | const unsigned fqual_mask = __transaction_safe_mask|__noexcept_mask;
84 | unsigned throw_fqual = (tflags & fqual_mask);
85 | unsigned catch_fqual = (__flags & fqual_mask);
86 | if (throw_fqual & ~catch_fqual)
87 | /* Catch can perform a function pointer conversion. */
88 | tflags &= catch_fqual;
89 | if (catch_fqual & ~throw_fqual)
90 | /* But not the reverse. */
91 | return false;
92 |
93 | if (tflags & ~__flags)
94 | // We're less qualified.
95 | return false;
96 |
97 | if (!(__flags & __const_mask))
98 | outer &= ~1;
99 |
100 | return __pointer_catch (thrown_type, thr_obj, outer);
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/libsupcxx/src/pmem_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __pointer_to_member_type_info::
29 | ~__pointer_to_member_type_info ()
30 | {}
31 |
32 | bool __pointer_to_member_type_info::
33 | __pointer_catch (const __pbase_type_info *thr_type,
34 | void **thr_obj,
35 | unsigned outer) const
36 | {
37 | // This static cast is always valid, as our caller will have determined that
38 | // thr_type is really a __pointer_to_member_type_info.
39 | const __pointer_to_member_type_info *thrown_type =
40 | static_cast (thr_type);
41 |
42 | if (*__context != *thrown_type->__context)
43 | return false; // not pointers to member of same class
44 |
45 | return __pbase_type_info::__pointer_catch (thrown_type, thr_obj, outer);
46 | }
47 |
48 | }
49 |
--------------------------------------------------------------------------------
/libsupcxx/src/pointer_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __pointer_type_info::
29 | ~__pointer_type_info ()
30 | {}
31 |
32 | bool __pointer_type_info::
33 | __is_pointer_p () const
34 | {
35 | return true;
36 | }
37 |
38 | bool __pointer_type_info::
39 | __pointer_catch (const __pbase_type_info *thrown_type,
40 | void **thr_obj,
41 | unsigned outer) const
42 | {
43 | #if __cpp_rtti
44 | if (outer < 2 && *__pointee == typeid (void))
45 | {
46 | // conversion to void
47 | return !thrown_type->__pointee->__is_function_p ();
48 | }
49 | #endif
50 |
51 | return __pbase_type_info::__pointer_catch (thrown_type, thr_obj, outer);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/libsupcxx/src/pure.cc:
--------------------------------------------------------------------------------
1 | // -*- C++ -*-
2 | // Copyright (C) 2000-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 | //
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 | //
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | extern "C" void abort();
26 |
27 | namespace __cxxabiv1 {
28 | extern "C" void __cxa_pure_virtual (void)
29 | {
30 | // pure virtual function called
31 | abort();
32 | }
33 |
34 | extern "C" void __cxa_deleted_virtual (void)
35 | {
36 | // deleted virtual function called
37 | abort();
38 | }
39 |
40 | } // namespace __cxxabiv1
41 |
--------------------------------------------------------------------------------
/libsupcxx/src/si_class_type_info.cc:
--------------------------------------------------------------------------------
1 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
2 | //
3 | // This file is part of GCC.
4 | //
5 | // GCC is free software; you can redistribute it and/or modify
6 | // it under the terms of the GNU General Public License as published by
7 | // the Free Software Foundation; either version 3, or (at your option)
8 | // any later version.
9 |
10 | // GCC is distributed in the hope that it will be useful,
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | // GNU General Public License for more details.
14 |
15 | // Under Section 7 of GPL version 3, you are granted additional
16 | // permissions described in the GCC Runtime Library Exception, version
17 | // 3.1, as published by the Free Software Foundation.
18 |
19 | // You should have received a copy of the GNU General Public License and
20 | // a copy of the GCC Runtime Library Exception along with this program;
21 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 | // .
23 |
24 | #include "libsupcxx/libsupcxx/src/tinfo.h"
25 |
26 | namespace __cxxabiv1 {
27 |
28 | __si_class_type_info::
29 | ~__si_class_type_info ()
30 | {}
31 |
32 | __class_type_info::__sub_kind __si_class_type_info::
33 | __do_find_public_src (ptrdiff_t src2dst,
34 | const void *obj_ptr,
35 | const __class_type_info *src_type,
36 | const void *src_ptr) const
37 | {
38 | if (src_ptr == obj_ptr && *this == *src_type)
39 | return __contained_public;
40 | return __base_type->__do_find_public_src (src2dst, obj_ptr, src_type, src_ptr);
41 | }
42 |
43 | bool __si_class_type_info::
44 | __do_dyncast (ptrdiff_t src2dst,
45 | __sub_kind access_path,
46 | const __class_type_info *dst_type,
47 | const void *obj_ptr,
48 | const __class_type_info *src_type,
49 | const void *src_ptr,
50 | __dyncast_result &__restrict result) const
51 | {
52 | if (*this == *dst_type)
53 | {
54 | result.dst_ptr = obj_ptr;
55 | result.whole2dst = access_path;
56 | if (src2dst >= 0)
57 | result.dst2src = adjust_pointer (obj_ptr, src2dst) == src_ptr
58 | ? __contained_public : __not_contained;
59 | else if (src2dst == -2)
60 | result.dst2src = __not_contained;
61 | return false;
62 | }
63 | if (obj_ptr == src_ptr && *this == *src_type)
64 | {
65 | // The src object we started from. Indicate how we are accessible from
66 | // the most derived object.
67 | result.whole2src = access_path;
68 | return false;
69 | }
70 | return __base_type->__do_dyncast (src2dst, access_path, dst_type, obj_ptr,
71 | src_type, src_ptr, result);
72 | }
73 |
74 | bool __si_class_type_info::
75 | __do_upcast (const __class_type_info *dst, const void *obj_ptr,
76 | __upcast_result &__restrict result) const
77 | {
78 | if (__class_type_info::__do_upcast (dst, obj_ptr, result))
79 | return true;
80 |
81 | return __base_type->__do_upcast (dst, obj_ptr, result);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/libsupcxx/src/tinfo.cc:
--------------------------------------------------------------------------------
1 | // Methods for type_info for -*- C++ -*- Run Time Type Identification.
2 | // Copyright (C) 1994-2018 Free Software Foundation, Inc.
3 | //
4 | // This file is part of GCC.
5 | //
6 | // GCC is free software; you can redistribute it and/or modify
7 | // it under the terms of the GNU General Public License as published by
8 | // the Free Software Foundation; either version 3, or (at your option)
9 | // any later version.
10 |
11 | // GCC is distributed in the hope that it will be useful,
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | // GNU General Public License for more details.
15 |
16 | // Under Section 7 of GPL version 3, you are granted additional
17 | // permissions described in the GCC Runtime Library Exception, version
18 | // 3.1, as published by the Free Software Foundation.
19 |
20 | // You should have received a copy of the GNU General Public License and
21 | // a copy of the GCC Runtime Library Exception along with this program;
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 | // .
24 |
25 | #include
26 | #include "libsupcxx/libsupcxx/src/tinfo.h"
27 |
28 | std::type_info::
29 | ~type_info ()
30 | { }
31 |
32 | namespace std {
33 |
34 | // return true if this is a type_info for a pointer type
35 | bool type_info::
36 | __is_pointer_p () const
37 | {
38 | return false;
39 | }
40 |
41 | // return true if this is a type_info for a function type
42 | bool type_info::
43 | __is_function_p () const
44 | {
45 | return false;
46 | }
47 |
48 | // try and catch a thrown object.
49 | bool type_info::
50 | __do_catch (const type_info *thr_type, void **, unsigned) const
51 | {
52 | return *this == *thr_type;
53 | }
54 |
55 | // upcast from this type to the target. __class_type_info will override
56 | bool type_info::
57 | __do_upcast (const abi::__class_type_info *, void **) const
58 | {
59 | return false;
60 | }
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/patches/qemu/0001-hw-i386-multiboot.c-Don-t-refuse-to-boot-ELF64-binar.patch:
--------------------------------------------------------------------------------
1 | From 09910c4d743243421afeb473e02e81be315ec0c7 Mon Sep 17 00:00:00 2001
2 | From: Lukasz Janyst
3 | Date: Sat, 12 Jan 2019 09:16:50 +0100
4 | Subject: [PATCH] hw/i386/multiboot.c: Don't refuse to boot ELF64 binaries
5 |
6 | ---
7 | hw/i386/multiboot.c | 5 -----
8 | 1 file changed, 5 deletions(-)
9 |
10 | diff --git a/hw/i386/multiboot.c b/hw/i386/multiboot.c
11 | index 62340687e8..6e30f0243e 100644
12 | --- a/hw/i386/multiboot.c
13 | +++ b/hw/i386/multiboot.c
14 | @@ -194,11 +194,6 @@ int load_multiboot(FWCfgState *fw_cfg,
15 | int kernel_size;
16 | fclose(f);
17 |
18 | - if (((struct elf64_hdr*)header)->e_machine == EM_X86_64) {
19 | - error_report("Cannot load x86-64 image, give a 32bit one.");
20 | - exit(1);
21 | - }
22 | -
23 | kernel_size = load_elf(kernel_filename, NULL, NULL, &elf_entry,
24 | &elf_low, &elf_high, 0, I386_ELF_MACHINE,
25 | 0, 0);
26 | --
27 | 2.20.1
28 |
29 |
--------------------------------------------------------------------------------
/tests/BUILD.go:
--------------------------------------------------------------------------------
1 | package tests
2 |
3 | import (
4 | "dbt-rules/RULES/cc"
5 | )
6 |
7 | var Test00 = cc.Binary{
8 | Out: out("test-00-global-ctors-dtors.elf"),
9 | Srcs: ins("test-00-global-ctors-dtors.cc"),
10 | }
11 |
12 | var Test01 = cc.Binary{
13 | Out: out("test-01-initializers-operators.elf"),
14 | Srcs: ins("test-01-initializers-operators.cc"),
15 | }
16 |
17 | var Test02 = cc.Binary{
18 | Out: out("test-02-virtuals.elf"),
19 | Srcs: ins("test-02-virtuals.cc"),
20 | }
21 |
22 | var Test03 = cc.Binary{
23 | Out: out("test-03-heap.elf"),
24 | Srcs: ins("test-03-heap.cc"),
25 | }
26 |
27 | var Test04 = cc.Binary{
28 | Out: out("test-04-rtti.elf"),
29 | Srcs: ins("test-04-rtti.cc"),
30 | }
31 |
32 | var Test05 = cc.Binary{
33 | Out: out("test-05-local-statics.elf"),
34 | Srcs: ins("test-05-local-statics.cc"),
35 | }
36 |
37 | var Test06 = cc.Binary{
38 | Out: out("test-06-trivial-exception.elf"),
39 | Srcs: ins("test-06-trivial-exception.cc"),
40 | }
41 |
42 | var Test07 = cc.Binary{
43 | Out: out("test-07-throw-clean-up-rethrow.elf"),
44 | Srcs: ins("test-07-throw-clean-up-rethrow.cc"),
45 | }
46 |
47 | var Test08 = cc.Binary{
48 | Out: out("test-08-ccompat.elf"),
49 | Srcs: ins("test-08-ccompat.cc"),
50 | }
51 |
52 | var Test09 = cc.Binary{
53 | Out: out("test-09-numeric-limits.elf"),
54 | Srcs: ins("test-09-numeric-limits.cc"),
55 | }
56 |
57 | var Test10 = cc.Binary{
58 | Out: out("test-10-type-traits.elf"),
59 | Srcs: ins("test-10-type-traits.cc"),
60 | }
61 |
--------------------------------------------------------------------------------
/tests/CMakeLists.txt:
--------------------------------------------------------------------------------
1 |
2 | function(add_test name)
3 | add_library(${name} ${name}.cc)
4 | add_kernel(
5 | NAME ${name}
6 | LIBS ${name} io
7 | )
8 | endfunction()
9 |
10 | set(tests global-ctors-dtors)
11 | list(APPEND tests initializers-operators)
12 | list(APPEND tests virtuals)
13 | list(APPEND tests heap)
14 | list(APPEND tests rtti)
15 | list(APPEND tests local-statics)
16 | list(APPEND tests trivial-exception)
17 | list(APPEND tests throw-clean-up-rethrow)
18 | list(APPEND tests ccompat)
19 | list(APPEND tests numeric-limits)
20 | list(APPEND tests type-traits)
21 |
22 | list(LENGTH tests test_length)
23 | math(EXPR test_bound ${test_length}-1)
24 |
25 | foreach(i RANGE 0 ${test_bound})
26 | list(GET tests ${i} name)
27 | if(i LESS 10)
28 | add_test(test-0${i}-${name})
29 | else()
30 | add_test(test-${i}-${name})
31 | endif()
32 | endforeach()
33 |
--------------------------------------------------------------------------------
/tests/test-00-global-ctors-dtors.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | class TestGlobalCtorDtor {
5 | public:
6 | TestGlobalCtorDtor() {
7 | io::printf("Ctor called!\n");
8 | }
9 | ~TestGlobalCtorDtor() {
10 | io::printf("Dtor called!\n");
11 | }
12 | };
13 |
14 | TestGlobalCtorDtor tmp;
15 |
16 | void main(const char *cmdline) {
17 | io::printf("Hello, Kernel World!\nAnd Hello Again!\n");
18 | io::printf("Kernel commandline: %s\n", cmdline);
19 | }
20 |
--------------------------------------------------------------------------------
/tests/test-01-initializers-operators.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 |
6 | class Matrix {
7 | private:
8 | double matrix_[16];
9 | public:
10 | Matrix() {
11 | for(unsigned i = 0; i < 16; ++i) {
12 | matrix_[i] = 0;
13 | }
14 | }
15 |
16 | Matrix(std::initializer_list init) {
17 | int i = 0;
18 | for(auto &el : init) {
19 | matrix_[i++] = el;
20 | }
21 | }
22 |
23 | double operator() (unsigned int i, unsigned int j) const {
24 | return matrix_[i*4+j];
25 | }
26 |
27 | double &operator() (unsigned int i, unsigned int j) {
28 | return matrix_[i*4+j];
29 | }
30 |
31 | Matrix &operator=(const Matrix &rhs) {
32 | for(unsigned i = 0; i < 16; ++i) {
33 | matrix_[i] = rhs.matrix_[i];
34 | }
35 | return *this;
36 | }
37 |
38 | Matrix(const Matrix &rhs) {
39 | for(unsigned i = 0; i < 15; ++i) {
40 | matrix_[i] = rhs.matrix_[i];
41 | }
42 | }
43 | };
44 |
45 | Matrix operator * (const Matrix &lhs, const Matrix &rhs) {
46 | Matrix m;
47 | for(unsigned i = 0; i < 4; ++i) {
48 | for(unsigned j = 0; j < 4; ++j) {
49 | m(i, j) = 0;
50 | for(unsigned k = 0; k < 4; ++k) {
51 | m(i, j) += lhs(i, k) * rhs(k, j);
52 | }
53 | }
54 | }
55 | return m;
56 | }
57 |
58 | void printMatrix(const Matrix &a) {
59 | for (size_t i = 0; i < 4; ++i) {
60 | for(size_t j = 0; j < 4; ++j) {
61 | io::printf("%f ", a(i, j));
62 | }
63 | io::printf("\n");
64 | }
65 | }
66 |
67 | void main(const char *cmdline) {
68 | Matrix a = {
69 | 1, 2, 3, 4,
70 | 5, 6, 7, 8,
71 | 9, 10, 11, 12,
72 | 13, 14, 15, 16
73 | };
74 | io::printf("a =\n");
75 | printMatrix(a);
76 |
77 | Matrix b = {
78 | 2, 3, 4, 5,
79 | 6, 7, 8, 9,
80 | 10, 11, 12, 13,
81 | 14, 15, 16, 17
82 | };
83 | io::printf("b =\n");
84 | printMatrix(b);
85 |
86 | Matrix c = a * b;
87 | io::printf("a * b =\n");
88 | printMatrix(c);
89 | }
90 |
--------------------------------------------------------------------------------
/tests/test-02-virtuals.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | class IInterface {
5 | public:
6 | virtual void doStuff() = 0;
7 | };
8 |
9 | class Impl1: public IInterface {
10 | public:
11 | virtual void doStuff() override {
12 | io::printf("Do stuff #1\n");
13 | }
14 | };
15 |
16 | class Impl2: public IInterface {
17 | public:
18 | virtual void doStuff() override {
19 | io::printf("Do stuff #2\n");
20 | }
21 | };
22 |
23 | void doStuff(IInterface *a) {
24 | a->doStuff();
25 | }
26 |
27 | void main(const char *cmdline) {
28 | Impl1 a;
29 | Impl2 b;
30 |
31 | io::printf("Call doStuff(&a)\n");
32 | doStuff(&a);
33 | io::printf("Call doStuff(&b)\n");
34 | doStuff(&b);
35 | }
36 |
--------------------------------------------------------------------------------
/tests/test-03-heap.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 | #include "libsupcxx/io/memory.hh"
4 |
5 | #include
6 |
7 | class IInterface {
8 | public:
9 | virtual ~IInterface() {
10 | io::printf("IInterface destructor called\n");
11 | }
12 | virtual void doStuff() = 0;
13 | };
14 |
15 | class Impl1: public IInterface {
16 | private:
17 | int a_;
18 | public:
19 | Impl1(int a = 12) {
20 | a_ = a;
21 | }
22 | virtual ~Impl1() {
23 | io::printf("Impl1 destructor called\n");
24 | }
25 | virtual void doStuff() override {
26 | io::printf("Do stuff #1\n");
27 | }
28 | };
29 |
30 | class Impl2: public IInterface {
31 | public:
32 | virtual ~Impl2() {
33 | io::printf("Impl2 destructor called\n");
34 | }
35 | virtual void doStuff() override {
36 | io::printf("Do stuff #2\n");
37 | }
38 | };
39 |
40 | void main(const char *cmdline) {
41 | char *tmpc = (char*)io::malloc(12);
42 | io::free(tmpc);
43 |
44 | double *tmpd = new double[12];
45 | delete [] tmpd;
46 |
47 | io::printf("--- Object construct->destruct-parent ---\n");
48 | IInterface *a = new Impl1(42);
49 | IInterface *b = new Impl2;
50 |
51 | delete a;
52 | delete b;
53 |
54 | io::printf("--- Object array construct->destruct-parent ---\n");
55 | IInterface *interfaces = new Impl2[2];
56 | delete [] interfaces;
57 |
58 | io::printf("--- Object construct->destruct-parent (nothrow) ---\n");
59 | a = new (std::nothrow) Impl1(42);
60 | b = new (std::nothrow) Impl2;
61 |
62 | delete a;
63 | delete b;
64 |
65 | io::printf("--- Object array construct->destruct-parent (nothrow) ---\n");
66 | interfaces = new (std::nothrow) Impl2[2];
67 | delete [] interfaces;
68 |
69 | io::printf("--- Large array of basic types->destruct ---\n");
70 | uint64_t *large = new (std::nothrow) uint64_t[8000000];
71 | io::printf("Address: %p\n", large);
72 |
73 | for(size_t i = 0; i < 8000000; ++i) {
74 | large[i] = 0;
75 | }
76 | io::printf("Cleared up the memory\n");
77 | delete [] large;
78 | }
79 |
--------------------------------------------------------------------------------
/tests/test-04-rtti.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 |
6 | class IInterface {
7 | public:
8 | virtual ~IInterface() {}
9 | virtual void f() {};
10 | };
11 |
12 | class Impl1: public IInterface {
13 | };
14 |
15 | class Impl2: public IInterface {
16 | };
17 |
18 | template
19 | class Number {
20 | T value;
21 | public:
22 | Number(T n) {
23 | value = n;
24 | }
25 | T get_value() {
26 | return value;
27 | };
28 | };
29 |
30 | void main(const char *cmdline) {
31 | // builtins
32 | char c, *p;
33 | int i;
34 | long l;
35 | float f;
36 | double d;
37 |
38 | io::printf("--- builtins ---\n");
39 | io::printf("char's name: %s\n", typeid(c).name());
40 | io::printf("char *'s name: %s\n", typeid(p).name());
41 | io::printf("int's name: %s\n", typeid(i).name());
42 | io::printf("long's name: %s\n", typeid(l).name());
43 | io::printf("float's name: %s\n", typeid(f).name());
44 | io::printf("double's name: %s\n", typeid(d).name());
45 |
46 | // classes
47 | IInterface ib, *ptr;
48 | Impl1 i1;
49 | Impl2 i2;
50 |
51 | io::printf("--- polymorphic types ---\n");
52 | ptr = &ib;
53 | io::printf("*ptr(ib)'s name: %s\n", typeid(*ptr).name());
54 | ptr = &i1;
55 | io::printf("*ptr(i1)'s name: %s\n", typeid(*ptr).name());
56 | ptr = &i2;
57 | io::printf("*ptr(i2)'s name: %s\n", typeid(*ptr).name());
58 |
59 | Impl1 *ip1 = dynamic_cast(ptr);
60 | if (ip1) {
61 | io::printf("Impl2 ptr did cast to Impl1 ptr\n");
62 | } else {
63 | io::printf("Impl2 ptr did not cast to Impl1 ptr\n");
64 | }
65 |
66 | Impl2 *ip2 = dynamic_cast(ptr);
67 | if (ip2) {
68 | io::printf("Impl2 ptr did cast to Impl2 ptr\n");
69 | } else {
70 | io::printf("Impl2 ptr did not cast to Impl2 ptr\n");
71 | }
72 |
73 | if (typeid(IInterface) == typeid(Impl1)) {
74 | io::printf("Impl1 is the same as IInterface\n");
75 | } else {
76 | io::printf("Impl1 is not the same as IInterface\n");
77 | }
78 | if (typeid(Impl2) == typeid(Impl1)) {
79 | io::printf("Impl1 is the same as Impl2\n");
80 | } else {
81 | io::printf("Impl1 is not the same as Impl2\n");
82 | }
83 |
84 | // templates
85 | Number ni(10);
86 | Number nd(3.14);
87 |
88 | io::printf("--- templates ---\n");
89 | io::printf("ni's name: %s\n", typeid(ni).name());
90 | io::printf("nd's name: %s\n", typeid(nd).name());
91 | if (typeid(Number) == typeid(Number)) {
92 | io::printf("Number is the same as Number\n");
93 | } else {
94 | io::printf("Number is not the same as Number\n");
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/tests/test-05-local-statics.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | int recursiveInit(int i) {
5 | io::printf("recursiveInit(%d)!\n", i);
6 | static int s = recursiveInit(i+1); // recursive call – undefined
7 | return i+s;
8 | }
9 |
10 | int computeTheMeaningOfLife() {
11 | io::printf("Computing the meaning of life!\n");
12 | return 42;
13 | }
14 |
15 | int getTheMeaningOfLife() {
16 | io::printf("Getting the meaning of life!\n");
17 | static int theMeaningOfLife = computeTheMeaningOfLife();
18 | return theMeaningOfLife;
19 | }
20 |
21 | void main(const char *cmdline) {
22 | int theMeaningOfLife = getTheMeaningOfLife();
23 | io::printf("Answer to the Ultimate Question of Life, the Universe, and "
24 | "Everything: %d\n", theMeaningOfLife);
25 |
26 | theMeaningOfLife = getTheMeaningOfLife();
27 | io::printf("Answer to the Ultimate Question of Life, the Universe, and "
28 | "Everything: %d\n", theMeaningOfLife);
29 |
30 | recursiveInit(0);
31 | io::printf("You should not be seeing this\n");
32 | }
33 |
--------------------------------------------------------------------------------
/tests/test-06-trivial-exception.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | void main(const char *cmdline) {
5 | io::printf("A trivial exception test\n");
6 | try {
7 | io::printf("Throwing 42\n");
8 | throw 42;
9 | } catch (int e) {
10 | io::printf("Cought: %d\n", e);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/tests/test-07-throw-clean-up-rethrow.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 |
6 | class TestException: public std::exception {
7 | public:
8 | TestException() {
9 | io::printf("Construct test exception\n");
10 | }
11 | ~TestException() {
12 | io::printf("Destruct test exception\n");
13 | }
14 |
15 | virtual const char *what() const noexcept override {
16 | return "Test exception";
17 | }
18 | };
19 |
20 | void six() {
21 | throw TestException();
22 | }
23 |
24 | void five() {
25 | six();
26 | io::printf("If you see this, something has gone wrong (five)\n");
27 | }
28 |
29 | int four(int arg) {
30 | try {
31 | five();
32 | } catch (TestException &e) {
33 | io::printf("Exception caught in four: %s\n", e.what());
34 | io::printf("Rethrowing...\n");
35 | throw;
36 | }
37 | return 22 + arg;
38 | }
39 |
40 | int three() {
41 | return 10;
42 | }
43 |
44 | int two(int arg) {
45 | return arg + 12;
46 | }
47 |
48 | int one() {
49 | int ret = two(10);
50 | try {
51 | ret += three();
52 | ret += four(20);
53 | io::printf("If you see this, something has gone wrong (one)\n");
54 | } catch (TestException &e) {
55 | io::printf("Exception caught in one: %s\n", e.what());
56 | ret += 10;
57 | }
58 | return ret;
59 | }
60 |
61 | void main(const char *cmdline) {
62 | int test = one();
63 | io::printf("Test result: %d (expected 42)\n", test);
64 | }
65 |
--------------------------------------------------------------------------------
/tests/test-08-ccompat.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | void printArgs(int num, ...)
15 | {
16 | va_list ap;
17 | int i;
18 |
19 | io::printf("printArgs(%d", num);
20 | va_start(ap, num);
21 | for (i = 0; i < num; ++i) {
22 | io::printf(", %d", va_arg(ap, int));
23 | }
24 | va_end(ap);
25 | io::printf(")\n");
26 | }
27 |
28 | class CtorDtorTest {
29 | public:
30 | CtorDtorTest() {
31 | io::printf("Constructing global object\n");
32 | }
33 |
34 | ~CtorDtorTest() {
35 | io::printf("Destructing global object\n");
36 | }
37 | };
38 |
39 | CtorDtorTest tmp;
40 |
41 | void atExitFunc(void) {
42 | io::printf("At exit function called\n");
43 | }
44 |
45 | void main(const char *cmdline) {
46 | (void) tmp;
47 | io::printf("glibcxx datestamp: %u\n", __GLIBCXX__);
48 | io::printf("glibcxx release: %u\n", _GLIBCXX_RELEASE);
49 | io::printf("sizeof(std::size_t): %u\n", sizeof(std::size_t));
50 | io::printf("float eval method: %d\n", FLT_EVAL_METHOD);
51 | io::printf("ULLONG_MAX: %llu\n", ULLONG_MAX);
52 | io::printf("__alignas_is_defined: %d\n", __alignas_is_defined);
53 | printArgs(5, 1, 2, 3, 4, 5);
54 | io::printf("__bool_true_false_are_defined: %d\n", __bool_true_false_are_defined);
55 | io::printf("sizeof(std::uint8_t): %u\n", sizeof(std::uint8_t));
56 | std::atexit(atExitFunc);
57 | std::exit(0);
58 | }
59 |
--------------------------------------------------------------------------------
/tests/test-09-numeric-limits.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 | #include
6 |
7 | void main(const char *cmdline) {
8 | io::printf("Hello numeric_limits\n");
9 | io::printf("std::numeric_limits::max(): %llu\n",
10 | std::numeric_limits::max());
11 | io::printf("std::numeric_limits::digits: %d\n",
12 | std::numeric_limits::digits);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/tests/test-10-type-traits.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "libsupcxx/io/printf.hh"
3 |
4 | #include
5 | #include
6 |
7 | struct Test {
8 | std::uint16_t test = 42;
9 | };
10 |
11 | void main(const char *cmdline) {
12 | io::printf("Is int tivially assignable to const Test: %d!\n",
13 | std::is_trivially_assignable::value);
14 | io::printf("Is const Test& trivially assignable to Test&: %d!\n",
15 | std::is_trivially_assignable::value);
16 | }
17 |
--------------------------------------------------------------------------------