x86_64 now loads

This commit is contained in:
Morten Delenk 2016-06-18 13:16:15 +02:00
parent 75e498aeaf
commit e818cdf660
11 changed files with 79 additions and 27 deletions

View file

@ -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))

View file

@ -1,4 +1,4 @@
arch = x86
arch = x86_64
#MODE = debug
MODE = release # enables optimization

View file

@ -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)

View file

@ -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);

View file

@ -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)

View file

@ -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

View file

@ -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();

View file

@ -3,7 +3,7 @@ OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:x86-64)
SECTIONS
{
. = 0x100000;
. = 0x200000;
kernel_start = .;
.text : {
*(multiboot)

44
settings Normal file
View file

@ -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

BIN
test.elf

Binary file not shown.

View file

@ -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: