diff --git a/buildcrosscompiler.sh b/buildcrosscompiler.sh index b518946..dc2985b 100644 --- a/buildcrosscompiler.sh +++ b/buildcrosscompiler.sh @@ -21,13 +21,21 @@ function buildscript() { make install-target-libgcc 2>&1 > /dev/null cd .. rm -rf build-gcc + echo "[$(date +%c)] Building gdb for $1." | tee -a buildlog + mkdir build-gdb + cd build-gdb + ../gdb-7.11/configure --prefix=$CROSSPATH --target=$1 --disable-nls 2>&1 > /dev/null + make -j8 2>&1 > /dev/null + make install 2>&1 > /dev/null + cd .. + rm -rf build-gdb echo "[$(date +%c)] Cross-compiler for $1 was built." | tee -a buildlog } tempdir=$(mktemp -d) cd $tempdir echo "Temponary files are in $tempdir. Build log can be found under $tempdir/buildlog" | tee -a buildlog -echo "Downloading GCC, Binutils, MPC, MPFR and GMP" | tee -a buildlog -wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2 ftp://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2 ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.3.tar.xz ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.xz http://isl.gforge.inria.fr/isl-0.16.tar.xz http://www.bastoul.net/cloog/pages/download/cloog-0.18.4.tar.gz +echo "Downloading GCC, Binutils, MPC, MPFR, GMP, isl, cloog and gdb" | tee -a buildlog +wget ftp://ftp.gnu.org/gnu/gcc/gcc-6.1.0/gcc-6.1.0.tar.bz2 ftp://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.bz2 ftp://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz ftp://ftp.gnu.org/gnu/mpfr/mpfr-3.1.3.tar.xz ftp://ftp.gnu.org/gnu/gmp/gmp-6.1.0.tar.xz http://isl.gforge.inria.fr/isl-0.16.tar.xz http://www.bastoul.net/cloog/pages/download/cloog-0.18.4.tar.gz http://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.xz echo "Untaring..." 2>&1 | tee -a buildlog tar -xf gcc-6.1.0.tar.bz2 tar -xf binutils-2.26.tar.bz2 @@ -43,6 +51,7 @@ mv isl-0.16 isl tar -xf ../cloog-0.18.4.tar.gz mv cloog-0.18.4 cloog cd .. +tar -xf gdb-7.11.tar.xz echo "Preperation done. Beginning the compilation now." 2>&1 | tee -a buildlog buildscript i686-elf #x86 port buildscript arm-none-eabi #Little endian ARM ports (GBA (v4), DS(i) (v4, v5), 3DS/2DS (v4, v5, v6), pi (v6), pi2 (v7)) diff --git a/kernel.settings b/kernel.settings index b5291f4..ec7cbfe 100644 --- a/kernel.settings +++ b/kernel.settings @@ -1,4 +1,4 @@ -arch = x86 +arch = x86_64 #MODE = debug MODE = release # enables optimization diff --git a/kernel/Makefile b/kernel/Makefile index 7eb7436..45ffa7f 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -4,7 +4,7 @@ KERNSRCS = $(shell find kernel -name '*.cpp' -o -name '*.c') OBJS = $(addsuffix .o,$(basename $(SRCS))) OBJS += $(addsuffix .o,$(basename $(KERNSRCS))) LD = $(PREFIX)g++ -LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin $(ARCHFLAGS) -T kernel-$(arch).ld +LDFLAGS = -nostdlib -nodefaultlibs -nostdlib -fno-builtin $(ARCHFLAGS) -T kernel-$(arch).ld -z max-page-size=0x1000 -lgcc all: hal kernel $(LD) $(LDFLAGS) -o mtgos $(OBJS) diff --git a/kernel/hal/x86/include/idt.hpp b/kernel/hal/x86/include/idt.hpp index 0f60a15..621796f 100644 --- a/kernel/hal/x86/include/idt.hpp +++ b/kernel/hal/x86/include/idt.hpp @@ -9,7 +9,7 @@ #define IDT_RING_3 0x60 #define IDT_USED 0x80 #define SEG_KERNEL 0x08 -#define SEG_USER 0x18 /*NEVER USE!!*/ +#define SEG_USER 0x08 /*NEVER USE!!*/ #define SEG_DBL_FAULT 0x28 /*Only use for double fault handler!!*/ extern "C" { void loadIDT(void * ptr); diff --git a/kernel/hal/x86_64/Makefile b/kernel/hal/x86_64/Makefile index a6eda68..4462091 100644 --- a/kernel/hal/x86_64/Makefile +++ b/kernel/hal/x86_64/Makefile @@ -5,8 +5,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS))) CPP = $(PREFIX)g++ CC = $(PREFIX)gcc ASFLAGS = -m64 -CFLAGS = -m64 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../kernel/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie -CPPFLAGS = -m64 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../kernel/c_include -I../../kernel/include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder +CFLAGS = -m64 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../../kernel/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 +CPPFLAGS = -m64 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../../kernel/c_include -I../../kernel/include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie -Wno-reorder -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 all: $(OBJS) diff --git a/kernel/hal/x86_64/asm/snippets.S b/kernel/hal/x86_64/asm/snippets.S index e7d2604..5006c20 100644 --- a/kernel/hal/x86_64/asm/snippets.S +++ b/kernel/hal/x86_64/asm/snippets.S @@ -1,7 +1,7 @@ .global loadGDT //void _stdcall loadGDT(struct gdtp* ptr); loadGDT: - mov 0x8(%rsp), %rax // Load argument + mov %rdi, %rax // Load argument lgdt (%rax) //GDT is loaded now mov $0x10, %ax @@ -11,21 +11,19 @@ loadGDT: mov %ax, %gs mov %ax, %ss mov $0x10, %rax -.code32 - ljmp $8, $.1 //Hacky hack -.code64 + //ljmp $8, $.1 //Hell, I don't care. FFS, there is not a single method to load a GDT in long mode. .1: ret .global loadIDT //void _stdcall loadIDT(struct idtp* ptr); loadIDT: - mov 0x8(%rsp), %rax + mov %rdi, %rax lidt (%rax) ret .global enterPaging //void _stdcall enterPaging(uint32** pd); enterPaging: - mov 0x8(%rsp), %rax + mov %rdi, %rax mov %rax, %cr3 mov %cr4, %rax or $0x10, %rax @@ -271,7 +269,7 @@ intr_stub 212 intr_stub 213 intr_stub 214 intr_stub 215 -intr_stub 216 +intr_stub 4216 intr_stub 217 intr_stub 218 intr_stub 219 @@ -343,7 +341,7 @@ intr_common_handler: mov $0x10, %ax mov %ax, %ds mov %ax, %es - push %rsp + mov %rsp, %rax call handleINT mov %rax, %rsp mov $8, %rcx diff --git a/kernel/hal/x86_64/init/init.cpp b/kernel/hal/x86_64/init/init.cpp index b09d366..52e4bb3 100644 --- a/kernel/hal/x86_64/init/init.cpp +++ b/kernel/hal/x86_64/init/init.cpp @@ -25,15 +25,21 @@ namespace MTGosHAL { new (&debug) Serial(); debug << "Hello debugger! This is MTGos v00r01\nThese logs are probably very long, so please redirect the output to a file.\n"; + debug << "Init Screen output\n"; + new (&out) Screen(ebx); + new (&err) Screen(ebx); + out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n"; + err << BG_color::BLACK << FG_color::RED; + debug << "Init GDT\n"; new (&gdt) GDT(); gdt.setEntry(0, 0, 0, 0); - gdt.setEntry(1, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_64_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT); - gdt.setEntry(2, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_64_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT); - gdt.setEntry(3, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_64_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT | GDT_FLAG_RING3); - gdt.setEntry(4, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_64_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT | GDT_FLAG_RING3); + gdt.setEntry(1, 0, 0, 0x298); + gdt.setEntry(2, 0, 0, 0x292); + gdt.setEntry(3, 0, 0, 0x2F8); + gdt.setEntry(4, 0, 0, 0x2F2); gdt.setEntry(5, (uint64_t)tasks.tss, sizeof(tasks.tss), GDT_FLAG_RING3 | GDT_FLAG_TSS | GDT_FLAG_PRESENT); - gdt.setEntry(6, 0, 0xfffff, GDT_FLAG_RING3 | GDT_FLAG_TSS | GDT_FLAG_PRESENT); + gdt.setEntry(6, 0, 0, GDT_FLAG_RING3 | GDT_FLAG_TSS | GDT_FLAG_PRESENT); gdt.apply(); debug << "Init IDT\n"; @@ -49,11 +55,6 @@ namespace MTGosHAL { debug << "Init MM\n"; new (&mm) PMM(ebx); - debug << "Init Screen output\n"; - new (&out) Screen(ebx); - new (&err) Screen(ebx); - out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n"; - err << BG_color::BLACK << FG_color::RED; debug << "Init Keyboard\n"; new (&in) Keyboard(); diff --git a/kernel/kernel-x86_64.ld b/kernel/kernel-x86_64.ld index 0b6209c..2bbe9a1 100644 --- a/kernel/kernel-x86_64.ld +++ b/kernel/kernel-x86_64.ld @@ -3,7 +3,7 @@ OUTPUT_FORMAT(elf32-i386) OUTPUT_ARCH(i386:x86-64) SECTIONS { - . = 0x100000; + . = 0x200000; kernel_start = .; .text : { *(multiboot) diff --git a/settings b/settings new file mode 100644 index 0000000..42bbe72 --- /dev/null +++ b/settings @@ -0,0 +1,44 @@ +# configuration file generated by Bochs +plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1 +config_interface: textconfig +display_library: x +memory: host=1024, guest=1024 +romimage: file="/usr/share/bochs/BIOS-bochs-latest" +vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest" +boot: floppy, disk +floppy_bootsig_check: disabled=0 +# no floppya +# no floppyb +ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 +ata0-master: type=disk, path="/dev/sdc", mode=flat, cylinders=1024, heads=4, spt=63, model="Generic 1234", biosdetect=auto, translation=auto +ata0-slave: type=none +ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 +ata1-master: type=none +ata1-slave: type=none +ata2: enabled=0 +ata3: enabled=0 +pci: enabled=1, chipset=i440fx +vga: extension=vbe, update_freq=5, realtime=1 +cpu: count=1, ips=4000000, model=corei7_haswell_4770, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 +print_timestamps: enabled=0 +gdbstub: enabled=1, port=1234, text_base=0, data_base=0, bss_base=0 +port_e9_hack: enabled=0 +private_colormap: enabled=0 +clock: sync=none, time0=local, rtc_sync=0 +# no cmosimage +# no loader +log: - +logprefix: %t%e%d +debug: action=ignore +info: action=report +error: action=report +panic: action=ask +keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none +mouse: type=ps2, enabled=0, toggle=ctrl+mbutton +speaker: enabled=1, mode=system +parport1: enabled=1, file=none +parport2: enabled=0 +com1: enabled=1, mode=null +com2: enabled=0 +com3: enabled=0 +com4: enabled=0 diff --git a/test.elf b/test.elf index f2c6ab7..35e0021 100755 Binary files a/test.elf and b/test.elf differ diff --git a/user/x86/syscall.S b/user/x86/syscall.S index d3ef6cf..d0d1ddb 100644 --- a/user/x86/syscall.S +++ b/user/x86/syscall.S @@ -33,7 +33,7 @@ screenout_clear: int $0x30 pop %ebx ret - + .global screenout_setcolor // void * screenout_setcolor(void* handle, uint32_t BG, uint32_t FG) screenout_setcolor: