KraKern

C++ Kernel
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/KraKern

commit aa53f4f04d51f42842430b19a9202a1b30a8fedc
parent 157d12791f76b66e8138052c8554e23bd9f8b5a7
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 12 Jan 2016 03:00:31 +0100

Add(Base): Some Code:

ASM start
Basic IO class

Diffstat:
A.ycm_extra_conf.py | 196+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.ycm_extra_conf.pyc | 0
AKraKern | 0
AMakefile | 50++++++++++++++++++++++++++++++++++++++++++++++++++
Aboot/x86/Makefile | 1+
Aboot/x86/linker.ld | 37+++++++++++++++++++++++++++++++++++++
Aboot/x86/start.asm | 48++++++++++++++++++++++++++++++++++++++++++++++++
Aboot/x86/start.o | 0
Aincludes/boot/boot.h | 35+++++++++++++++++++++++++++++++++++
Aincludes/core/Io.hpp | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aincludes/core/Kernel.hpp | 14++++++++++++++
Aincludes/core/base_lib.h | 17+++++++++++++++++
Aincludes/core/kern_types.h | 14++++++++++++++
Aincludes/core/os.h | 10++++++++++
Akern.img | 0
Akernel/Io.cpp | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Akernel/Io.o | 0
Akernel/Kernel.cpp | 7+++++++
Akernel/Kernel.o | 0
Akernel/Makefile | 1+
Akernel/main.cpp | 11+++++++++++
Akernel/main.o | 0
Alib/Makefile | 1+
Alib/baselib.cpp | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/baselib.o | 0
Alib/cxx.cpp | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alib/cxx.o | 0
Aqemu.sh | 2++
28 files changed, 809 insertions(+), 0 deletions(-)

diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py @@ -0,0 +1,196 @@ +# This file is NOT licensed under the GPLv3, which is the license for the rest +# of YouCompleteMe. +# +# Here's the license text for this file: +# +# This is free and unencumbered software released into the public domain. +# +# Anyone is free to copy, modify, publish, use, compile, sell, or +# distribute this software, either in source code form or as a compiled +# binary, for any purpose, commercial or non-commercial, and by any +# means. +# +# In jurisdictions that recognize copyright laws, the author or authors +# of this software dedicate any and all copyright interest in the +# software to the public domain. We make this dedication for the benefit +# of the public at large and to the detriment of our heirs and +# successors. We intend this dedication to be an overt act of +# relinquishment in perpetuity of all present and future rights to this +# software under copyright law. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +# For more information, please refer to <http://unlicense.org/> + +import os +import ycm_core + +# These are the compilation flags that will be used in case there's no +# compilation database set (by default, one is not set). +# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR. +flags = [ +'-Wall', +'-Wextra', +'-Werror', +'-Wc++98-compat', +'-Wno-long-long', +'-Wno-variadic-macros', +'-fexceptions', +'-DNDEBUG', +# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM +# source code needs it. +'-DUSE_CLANG_COMPLETER', +# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which +# language to use when compiling headers. So it will guess. Badly. So C++ +# headers will be compiled as C headers. You don't want that so ALWAYS specify +# a "-std=<something>". +# For a C project, you would set this to something like 'c99' instead of +# 'c++11'. +'-std=c++11', +# ...and the same thing goes for the magic -x option which specifies the +# language that the files to be compiled are written in. This is mostly +# relevant for c++ headers. +# For a C project, you would set this to 'c' instead of 'c++'. +'-x', +'c++', +'-isystem', +'../BoostParts', +'-isystem', +# This path will only work on OS X, but extra paths that don't exist are not +# harmful +'/System/Library/Frameworks/Python.framework/Headers', +'-isystem', +'../llvm/include', +'-isystem', +'../llvm/tools/clang/include', +'-I', +'.', +'-I', +'./ClangCompleter', +'-isystem', +'./tests/gmock/gtest', +'-isystem', +'./tests/gmock/gtest/include', +'-isystem', +'./tests/gmock', +'-isystem', +'./tests/gmock/include', +'-I', +'includes/core', +'-I', +'includes/boot', +'-fno-builtin', +'-fno-stack-protector', +'-nostdlib', +'-nodefaultlibs', +] + + +# Set this to the absolute path to the folder (NOT the file!) containing the +# compile_commands.json file to use that instead of 'flags'. See here for +# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html +# +# You can get CMake to generate this file for you by adding: +# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 ) +# to your CMakeLists.txt file. +# +# Most projects will NOT need to set this to anything; you can just change the +# 'flags' list of compilation flags. Notice that YCM itself uses that approach. +compilation_database_folder = '' + +if os.path.exists( compilation_database_folder ): + database = ycm_core.CompilationDatabase( compilation_database_folder ) +else: + database = None + +SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ] + +def DirectoryOfThisScript(): + return os.path.dirname( os.path.abspath( __file__ ) ) + + +def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): + if not working_directory: + return list( flags ) + new_flags = [] + make_next_absolute = False + path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] + for flag in flags: + new_flag = flag + + if make_next_absolute: + make_next_absolute = False + if not flag.startswith( '/' ): + new_flag = os.path.join( working_directory, flag ) + + for path_flag in path_flags: + if flag == path_flag: + make_next_absolute = True + break + + if flag.startswith( path_flag ): + path = flag[ len( path_flag ): ] + new_flag = path_flag + os.path.join( working_directory, path ) + break + + if new_flag: + new_flags.append( new_flag ) + return new_flags + + +def IsHeaderFile( filename ): + extension = os.path.splitext( filename )[ 1 ] + return extension in [ '.h', '.hxx', '.hpp', '.hh' ] + + +def GetCompilationInfoForFile( filename ): + # The compilation_commands.json file generated by CMake does not have entries + # for header files. So we do our best by asking the db for flags for a + # corresponding source file, if any. If one exists, the flags for that file + # should be good enough. + if IsHeaderFile( filename ): + basename = os.path.splitext( filename )[ 0 ] + for extension in SOURCE_EXTENSIONS: + replacement_file = basename + extension + if os.path.exists( replacement_file ): + compilation_info = database.GetCompilationInfoForFile( + replacement_file ) + if compilation_info.compiler_flags_: + return compilation_info + return None + return database.GetCompilationInfoForFile( filename ) + + +def FlagsForFile( filename, **kwargs ): + if database: + # Bear in mind that compilation_info.compiler_flags_ does NOT return a + # python list, but a "list-like" StringVec object + compilation_info = GetCompilationInfoForFile( filename ) + if not compilation_info: + return None + + final_flags = MakeRelativePathsInFlagsAbsolute( + compilation_info.compiler_flags_, + compilation_info.compiler_working_dir_ ) + + # NOTE: This is just for YouCompleteMe; it's highly likely that your project + # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR + # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. + try: + final_flags.remove( '-stdlib=libc++' ) + except ValueError: + pass + else: + relative_to = DirectoryOfThisScript() + final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) + + return { + 'flags': final_flags, + 'do_cache': True + } diff --git a/.ycm_extra_conf.pyc b/.ycm_extra_conf.pyc Binary files differ. diff --git a/KraKern b/KraKern Binary files differ. diff --git a/Makefile b/Makefile @@ -0,0 +1,50 @@ +ARCH = x86 +KERNEL = KraKern + +## Compilers +CC = g++ +ASM = nasm +LD = ld + +## Includes +INCS = -I includes/boot \ + -I includes/core + +## Flags +CFLAGS = -g -O2 -w $(INCS) -trigraphs -fno-builtin \ + -fno-exceptions -fno-stack-protector -O0 \ + -m32 -fno-rtti -nostdlib -nodefaultlibs + +LDFLAG = -melf_i386 -static -L ./ -T ./boot/$(ARCH)/linker.ld --entry=_start +ASMFLAGS = -f elf -o + +include ./boot/$(ARCH)/Makefile +include ./kernel/Makefile +include ./lib/Makefile + +all: $(KERNEL) + +$(KERNEL): $(OBJS) + $(LD) $(LDFLAG) -o $@ $^ + +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.s + $(CC) $(CFLAGS) -c $< -o $@ + +%.o: %.asm + $(ASM) $(ASMFLAGS) -c $< -o $@ + +install: + sudo mount /dev/loop1 /mnt + sudo cp $(KERNEL) /mnt/boot/. + sudo umount /mnt + +clean: + rm -f $(OBJS) + +fclean: clean + rm -f $(KERNEL) + +re: fclean all diff --git a/boot/x86/Makefile b/boot/x86/Makefile @@ -0,0 +1 @@ +OBJS += boot/x86/start.o diff --git a/boot/x86/linker.ld b/boot/x86/linker.ld @@ -0,0 +1,37 @@ +OUTPUT_FORMAT(elf32-i386) +OUTPUT_ARCH(i386) +ENTRY (_start) + +SECTIONS{ + . = 0x00100000; + + .text :{ + *(.text) + } + + .data ALIGN (0x1000) : { + start_ctors = .; + *(.ctor*) + end_ctors = .; + start_dtors = .; + *(.dtor*) + end_dtors = .; + *(.data) + } + + + .rodata ALIGN (0x1000) : { + *(.rodata) + } + + .data ALIGN (0x1000) : { + *(.data) + } + + .bss : { + sbss = .; + *(COMMON) + *(.bss) + ebss = .; + } +} diff --git a/boot/x86/start.asm b/boot/x86/start.asm @@ -0,0 +1,48 @@ +global _start, _kmain +extern kmain, start_ctors, end_ctors, start_dtors, end_dtors + + +%define MULTIBOOT_HEADER_MAGIC 0x1BADB002 +%define MULTIBOOT_HEADER_FLAGS 0x00000003 +%define CHECKSUM -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) + +;-- Entry point +_start: + jmp start + +;-- Multiboot header -- +align 4 + +multiboot_header: +dd MULTIBOOT_HEADER_MAGIC +dd MULTIBOOT_HEADER_FLAGS +dd CHECKSUM +;--/Multiboot header -- + +start: + push ebx + +static_ctors_loop: + mov ebx, start_ctors + jmp .test +.body: + call [ebx] + add ebx,4 +.test: + cmp ebx, end_ctors + jb .body + + call kmain ; call kernel proper + +static_dtors_loop: + mov ebx, start_dtors + jmp .test +.body: + call [ebx] + add ebx,4 +.test: + cmp ebx, end_dtors + jb .body + + cli ; stop interrupts + hlt ; halt the CPU diff --git a/boot/x86/start.o b/boot/x86/start.o Binary files differ. diff --git a/includes/boot/boot.h b/includes/boot/boot.h @@ -0,0 +1,35 @@ +#ifndef __BOOT__ +# define __BOOT__ + +# include <kern_types.h> + +struct multiboot_info { + u32 flags; + u32 low_mem; + u32 high_mem; + u32 boot_device; + u32 cmdline; + u32 mods_count; + u32 mods_addr; + struct { + u32 num; + u32 size; + u32 addr; + u32 shndx; + } elf_sec; + unsigned long mmap_length; + unsigned long mmap_addr; + unsigned long drives_length; + unsigned long drives_addr; + unsigned long config_table; + unsigned long boot_loader_name; + unsigned long apm_table; + unsigned long vbe_control_info; + unsigned long vbe_mode_info; + unsigned long vbe_mode; + unsigned long vbe_interface_seg; + unsigned long vbe_interface_off; + unsigned long vbe_interface_len; +}; + +#endif diff --git a/includes/core/Io.hpp b/includes/core/Io.hpp @@ -0,0 +1,92 @@ +#ifndef __IO__ +# define __IO__ + +# include <os.h> +# include <kern_types.h> +# include <base_lib.h> + +// X86 Defines +# define RAM_SCREEN 0xB8000 +# define SIZE_SCREEN 0xFA0 +# define SCREENLIM 0xB8FA0 + +enum Color { + Black = 0, + Blue = 1, + Green = 2, + Cyan = 3, + Red = 4, + Magenta = 5, + Orange = 6, + LightGrey = 7, + DarkGrey = 8, + LightBlue = 9, + LightGreen =10, + LightCyan = 11, + LightRed = 12, + LightMagenta=13, + Yellow = 14, + White = 15 +}; + +class Io { + public: + Io(void); + ~Io(void); + + + // Assembly Interface + void obyte(u32 a, u8 v); + void oword(u32 a, u16 v); + void oline(u32 a, u32 v); + u8 ibyte(u32 a); + u16 iword(u32 a); + u32 iline(u32 a); + + void putctty(char c); + u32 read(char* buf,u32 count); + void putc(char c); + void set_color(char fcol,char bcol); + void setXY(char xc,char yc); + void clear(void); + void print(const char *s, ...); + u32 getX(void); + u32 getY(void); + void switch_tty(void); + void scrollup(unsigned int n); + void save_screen(void); + void load_screen(void); + + enum console_type { + BUFFERED, + GETCHAR + }; + + static Io *current_io; + static Io *last_io; + + private: + char *_real_screen; + char _screen[SIZE_SCREEN]; + + char _inbuf[512]; + int _keypos; + int _inlock; + int _keystate; + + char _fcolor; + char _bcolor; + char _x; + char _y; + char _kattr; + + static char *_vidmem; +}; + +# include <Kernel.hpp> +class Kernel; + + +extern Kernel kern; + +#endif diff --git a/includes/core/Kernel.hpp b/includes/core/Kernel.hpp @@ -0,0 +1,14 @@ +#ifndef __KERNEL__ +# define __KERNEL__ +# include <os.h> + +# include <Io.hpp> + +class Kernel { + public: + Kernel(void); + + Io __io; +}; + +#endif diff --git a/includes/core/base_lib.h b/includes/core/base_lib.h @@ -0,0 +1,17 @@ +#ifndef __LIB__ +# define __LIB__ +# include <kern_types.h> + +extern "C" { + u32 strlen(const char *s); + u32 strcmp(const char *s1, const char *s2); + u32 strncmp(const char *s1, const char *s2, u32 n); + u32 strcpy(char *dst, const char *src); + u32 strncpy(char *dst, const char *src, u32 n); + char *strcat(char *s1, char *s2); + void *memcpy(void *dst, const void *src, u32 n); + void *memset(void *dst, int c, u32 n); + void itoa(char *buf, u32 n, int base); +} + +#endif diff --git a/includes/core/kern_types.h b/includes/core/kern_types.h @@ -0,0 +1,14 @@ +#ifndef __TYPES__ +# define __TYPES__ + +typedef unsigned char u8; +typedef unsigned short u16; +typedef unsigned int u32; +typedef unsigned long long u64; + +typedef signed char s8; +typedef signed short s16; +typedef signed int s32; +typedef signed long long s64; + +#endif diff --git a/includes/core/os.h b/includes/core/os.h @@ -0,0 +1,10 @@ +#ifndef __OS__ +# define __OS__ + +# include <kern_types.h> +# include <base_lib.h> + +# define asm __asm__ +# define asmv __asm__ __volatile__ + +#endif diff --git a/kern.img b/kern.img Binary files differ. diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -0,0 +1,130 @@ +#include <Io.hpp> + +Io __io; +Io *Io::last_io = &__io; +Io *Io::current_io = &__io; +char *Io::_vidmem = (char *)RAM_SCREEN; + +Io::Io(void) { + this->_real_screen = (char *)RAM_SCREEN; +} + +Io::~Io(void) { + this->_real_screen = (char *)this->_screen; +} + +void Io::scrollup(u32 n) { + u8 *video, *tmp; + + for (video = (u8 *)this->_real_screen; video < (u8 *)SCREENLIM; video += 2) { + tmp = (u8 *)(video + n * 160); + if (tmp < (u8 *)SCREENLIM) { + *video = *tmp; + *(video + 1) = *(tmp + 1); + } else { + *video = 0x0; + *(video + 1) = 0x07; + } + this->_y -= n; + if (this->_y < 0) + this->_y = 0; + } +} + +void Io::save_screen(void) { + memcpy(this->_screen, (char *)RAM_SCREEN, SIZE_SCREEN); + this->_real_screen = (char *)this->_screen; +} + +void Io::load_screen(void) { + memcpy((char *)RAM_SCREEN, this->_screen, SIZE_SCREEN); + this->_real_screen = (char *)RAM_SCREEN; +} + +void Io::switch_tty(void) { + current_io->save_screen(); + load_screen(); + last_io = current_io; + current_io = this; +} + +void Io::putc(char c) { + u8 *video; + + this->_kattr = 0x07; + video = (u8 *)(this->_real_screen + 2 * this->_x + 160 * this->_y); + if (c == 10) { + this->_x = 0; + this->_y++; + } else if (c == 8 && this->_x) { + *(video + 1) = 0x0; + this->_x--; + } else if (c == 9) { + this->_x = this->_x + 8 - (this->_x % 8); + } else if (c == 13) { + this->_x = 0; + } else { + *video = c; + *(video + 1) = this->_kattr; + this->_x++; + if (this->_x > 79) { + this->_x = 0; + this->_y++; + } + } + if (this->_y > 24) + scrollup(this->_y - 24); +} + +void Io::clear(void) { + this->_x = 0; + this->_y = 0; + memset((char *)RAM_SCREEN, 0, SIZE_SCREEN); +} + +void Io::putctty(char c) { + if (this->_keystate == BUFFERED) { + if (c == 8 && this->_keypos > 0) { + this->_inbuf[this->_keypos--] = 0x0; + } else if (c == 10) { + this->_inbuf[this->_keypos++] = c; + this->_inbuf[this->_keypos] = 0x0; + this->_inlock = this->_keypos = 0; + } else { + this->_inbuf[this->_keypos++] = c; + } + } else if (this->_keystate == GETCHAR) { + this->_inbuf[0] = c; + this->_inbuf[1] = 0; + this->_inlock = this->_keypos = 0; + } +} + +u32 Io::read(char *buf, u32 count) { + if (count > 1) + this->_keystate = BUFFERED; + else + this->_keystate = GETCHAR; + asm("sti"); + this->_inlock = 1; + while (this->_inlock); + asm("cli"); + strncpy(buf, this->_inbuf, count); + return strlen(buf); +} + +// Output +void Io::obyte(u32 a, u8 v) { asmv("outb %%al, %%dx" :: "d" (a), "a" (v));; }; +void Io::oword(u32 a, u16 v) { asmv("outw %%ax, %%dx" :: "d" (a), "a" (v));; }; +void Io::oline(u32 a, u32 v) { asmv("outl %%ax, %%dx" :: "d" (a), "a" (v));; }; + +// Input +u8 Io::ibyte(u32 a) { u8 v; asmv("inb %%dx, %%al" : "=a" (v) : "d" (a)); return v; }; +u16 Io::iword(u32 a) { u16 v; asmv("inb %%dx, %%ax" : "=a" (v) : "d" (a)); return v; }; +u32 Io::iline(u32 a) { u32 v; asmv("inb %%dx, %%eax" : "=a" (v) : "d" (a)); return v; }; + +u32 Io::getX(void) { return (u32)this->_x; }; +u32 Io::getY(void) { return (u32)this->_y; }; + +void Io::set_color(char fcol, char bcol) { this->_fcolor = fcol; this->_bcolor = bcol; }; +void Io::setXY(char xc, char yc) { this->_x = xc; this->_y = yc; }; diff --git a/kernel/Io.o b/kernel/Io.o Binary files differ. diff --git a/kernel/Kernel.cpp b/kernel/Kernel.cpp @@ -0,0 +1,7 @@ +#include <Kernel.hpp> + +//Kernel kern; + +Kernel::Kernel(void) { + this->__io = Io(); +} diff --git a/kernel/Kernel.o b/kernel/Kernel.o Binary files differ. diff --git a/kernel/Makefile b/kernel/Makefile @@ -0,0 +1 @@ +OBJS += kernel/main.o kernel/Io.o kernel/Kernel.o diff --git a/kernel/main.cpp b/kernel/main.cpp @@ -0,0 +1,11 @@ +# include <os.h> +# include <boot.h> +# include <Io.hpp> +extern Io __io; + +extern "C" void kmain(multiboot_info *info) { + (void)info; + __io.clear(); + + return ; +} diff --git a/kernel/main.o b/kernel/main.o Binary files differ. diff --git a/lib/Makefile b/lib/Makefile @@ -0,0 +1 @@ +OBJS += lib/baselib.o lib/cxx.o diff --git a/lib/baselib.cpp b/lib/baselib.cpp @@ -0,0 +1,87 @@ +#include <os.h> + +extern "C" { + u32 strlen(const char *s) { + u32 i; + + for (i = 0; s[i]; i++); + return i; + } + + u32 strcmp(const char *s1, const char *s2) { + while (s1 && s2 && *s1 && *s2 && *s1 == *s2) { + s1++; + s2++; + } + return (u32)*s1 - *s2; + } + + u32 strncmp(const char *s1, const char *s2, u32 n) { + while (s1 && s2 && *s1 && *s2 && *s1 == *s2 && n--) { + s1++; + s2++; + } + return (u32)*s1 - *s2; + } + + u32 strcpy(char *dst, const char *src) { + u32 i; + + for (i = 0; src[i]; dst[i] = src[i], i++); + dst[i] = 0x0; + return i; + } + + u32 strncpy(char *dst, const char *src, u32 n) { + u32 i; + + for (i = 0; i < n && src[i]; dst[i] = src[i], i++); + if (i < n) + dst[i] = 0x0; + return i; + } + + char *strcat(char *s1, char *s2) { + return (char *)memcpy(s1 + strlen(s1), s2, strlen(s2)); + } + + char *strncat(char *s1, char *s2, u32 n) { + return (char *)memcpy(s1 + strlen(s1), s2, n); + } + + void *memcpy(void *dst, const void *src, u32 n) { + char *p = (char *)dst; + char *s = (char *)src; + + while (n--) + *p++ = *s++; + return dst; + } + + void *memset(void *dst, int c, u32 n) { + char *p = (char *)dst; + + while (n--) + *p++ = c; + return dst; + } + + void itoa(char *buf, u32 n, int base) { + u32 tmp; + int i, j; + + tmp = n; + i = 0; + do { + tmp = n % base; + buf[i++] = (tmp < 10) ? (tmp + '0') : (tmp + 'a' - 10); + } while (n /= base); + buf[i--] = 0; + + for (j = 0; j < i; j++, i--) { + tmp = buf[j]; + buf[j] = buf[i]; + buf[i] = tmp; + } + } +} diff --git a/lib/baselib.o b/lib/baselib.o Binary files differ. diff --git a/lib/cxx.cpp b/lib/cxx.cpp @@ -0,0 +1,56 @@ +# include <os.h> + +extern "C" +{ + int __cxa_atexit(void (*Destructor) (void *), void *Parameter, void *HomeDSO); + void __cxa_finalize(void *); + void __cxa_pure_virtual(); + void __stack_chk_guard_setup(); + void __attribute__((noreturn)) __stack_chk_fail(); + void _Unwind_Resume(); +} + +void *__dso_handle; +void *__stack_chk_guard(0); + + +namespace __cxxabiv1 +{ + __extension__ typedef int __guard __attribute__((mode(__DI__))); + + extern "C" + { + int __cxa_guard_acquire(__guard *Guard) { return ! *(char *) (Guard); } + void __cxa_guard_release(__guard *Guard) { *(char *) Guard = 1; } + void __cxa_guard_abort(__guard *) { } + } +} + + +int __cxa_atexit(void (*) (void *), void *, void *) +{ + return 0; +} + +void _Unwind_Resume(){ + +} + +void __cxa_finalize(void *) +{ + +} + +void __cxa_pure_virtual() +{ + +} + +void __stack_chk_guard_setup() +{ + unsigned char *Guard; + Guard = (unsigned char *) &__stack_chk_guard; + Guard[sizeof(__stack_chk_guard) - 1] = 255; + Guard[sizeof(__stack_chk_guard) - 2] = '\n'; + Guard[0] = 0; +} diff --git a/lib/cxx.o b/lib/cxx.o Binary files differ. diff --git a/qemu.sh b/qemu.sh @@ -0,0 +1,2 @@ +#!/bin/bash +kvm -m 1024 -s -hda ./kern.img -serial /dev/tty -redir tcp:2323::23