diff --git a/Makefile b/Makefile index d98f48e..ad648b1 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,13 @@ -all: loader.bin firm.bin +all: loader.bin mtgos.firm $(MAKE) -C modules loader.bin: $(MAKE) -C boot mv boot/loader.bin . -firm.bin: +mtgos.firm: $(MAKE) -C kernel mv kernel/mtgos.elf . objcopy -O binary mtgos.elf mtgos.bin ./firmlink mtgos rm -rf mtgos.bin clean: - find . -name '*.o' -delete \ No newline at end of file + find . -name '*.o' -delete diff --git a/boot/x86/boot.S b/boot/x86/boot.S index 6d53da2..cb52bef 100644 --- a/boot/x86/boot.S +++ b/boot/x86/boot.S @@ -17,11 +17,55 @@ _start: mov $kernel_stack, %esp push %ebx push %eax + lgdt gdtr + mov $0x10, %eax + mov %ax, %ds + mov %ax, %es + mov %ax, %fs + mov %ax, %gs + mov %ax, %ss + ljmp $0x08,$_st +_st: call init _exit: cli hlt jmp _exit +.section .data +gdt: +//NULL-descriptor +.quad 0 +//code kernel +.word 0xFFFF +.word 0x0000 +.byte 0x00 +.byte 0x98 +.byte 0xCF +.byte 0x00 +//data kernel +.word 0xFFFF +.word 0x0000 +.byte 0x00 +.byte 0x92 +.byte 0xCF +.byte 00 +//code user +.word 0xFFFF +.word 0x0000 +.byte 0x00 +.byte 0xF8 +.byte 0xCF +.byte 0x00 +//data user +.word 0xFFFF +.word 0x0000 +.byte 0x00 +.byte 0xF2 +.byte 0xCF +.byte 00 +gdtr: + .word 5 * 8 + .int gdt .section .bss .space 8192 kernel_stack: \ No newline at end of file diff --git a/boot/x86_64/boot.S b/boot/x86_64/boot.S index 5db8ea1..99998e8 100644 --- a/boot/x86_64/boot.S +++ b/boot/x86_64/boot.S @@ -110,22 +110,35 @@ gdt: .byte 0x98 .byte 0xCF .byte 0x00 -//data +//data kernel .word 0xFFFF .word 0x0000 .byte 0x00 .byte 0x92 .byte 0xCF .byte 00 -//64-bit code +//64-bit code kernel .int 0 .byte 0 .byte 0x98 .byte 0x20 .byte 0 +//data user +.word 0xFFFF +.word 0x0000 +.byte 0x00 +.byte 0xF2 +.byte 0xCF +.byte 00 +//64-bit code user +.int 0 +.byte 0 +.byte 0xF8 +.byte 0x20 +.byte 0 gdtr: - .word 4 * 8 + .word 6 * 8 .int gdt pmfill: .int pagedirPT + 0x7 diff --git a/firm.bin b/firm.bin new file mode 100644 index 0000000..f23df60 Binary files /dev/null and b/firm.bin differ diff --git a/include/interrupts.h b/include/interrupts.h new file mode 100644 index 0000000..fce543d --- /dev/null +++ b/include/interrupts.h @@ -0,0 +1,16 @@ +#pragma once +namespace MTGos { +enum class IntType { + QUIT, //Quit from Keyboard + ILL, //Illegal Instruction + TRAP, // Breakpoint + ABRT, //Abort + BUS, //Data Abort + FPE, //Division by zero et al + KILL, //Shutdown + SEGV, //Segmentation fault + CONT, //Clock signal (called a multiple of 60 or 50Hz) + SYS //Syscall +}; + +} \ No newline at end of file diff --git a/include/moduleinterface.h b/include/moduleinterface.h index de96054..09fb492 100644 --- a/include/moduleinterface.h +++ b/include/moduleinterface.h @@ -23,7 +23,7 @@ typedef size_t(*sizeof_type)(); * size_t size_of(); * bool spawnAt(void*); */ -extern "C" table_type getTable(); +extern "C" table_type getTable(void*(*)(ModType)); /** * \brief returns the type of the module diff --git a/kernel/init.cpp b/kernel/init.cpp index ae1268d..286b296 100644 --- a/kernel/init.cpp +++ b/kernel/init.cpp @@ -51,6 +51,11 @@ void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) { (*obj)[i]+=mod; } } +void* getModule(ModType mt) { + if(mt==ModType::output_text) + return (void*) &out; + return nullptr; +} /** * \function _start() * \brief Initializes the kernel @@ -61,20 +66,13 @@ extern "C" void _start(void ** modtable) { for(int i=0;i<1024;i++) { if(!modtable[i]) break; - void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]); + void(**(*fptr)(void* (*)(ModType)))() = (void(**(*)(void* (*)(ModType)))()) load((Elf_Ehdr*) modtable[i]); if(!fptr) continue; - void(**table)()=fptr(modtable[i]); + void(**table)()=fptr(&getModule); #ifndef __LP64__ //Relocate table - table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000); -#endif -#ifdef ARM9 - table = (void(**)())0x27FFFFE8; -#else -#ifdef ARM11 - table = (void(**)())0x27FFFFF4; -#endif + table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+PAGE_SIZE); #endif //Relocate table contents uintptr_t* tbl=(uintptr_t*)table; @@ -82,17 +80,25 @@ extern "C" void _start(void ** modtable) { tbl[1]+=(uintptr_t)modtable[i]+PAGE_SIZE; tbl[2]+=(uintptr_t)modtable[i]+PAGE_SIZE; ModType type=((getType_type)table[0])(); //Get module type - if(type!=ModType::output_text) - continue; - size_t size=((sizeof_type)table[1])(); //Get module size - ((spawnAt_type)table[2])((void*)&out); //Spawn module - adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1); - out << "HI!\nbye!\n"; + switch(type) { + case ModType::output_text: { + size_t size=((sizeof_type)table[1])(); //Get module size + ((spawnAt_type)table[2])((void*)&out); //Spawn module + adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1); + out << "HI!\nbye!\n"; #ifdef ARM9 - out << "Here arm9!\n"; + out << "Here arm9!\n"; #else - out << "Here arm11!\n"; + out << "Here arm11!\n"; #endif + for(int i=0;i>=0;i++) { + out << i << " "; + } + break; } + case ModType::none: + default: + out << "This is not a module I can load!\n"; + } } for(void(**i)()=&start_dtors;i<&end_dtors;i++) (*i)(); //Calling destructors diff --git a/modules/3ds/dsp/txt/.init.cpp.kate-swp b/modules/3ds/dsp/txt/.init.cpp.kate-swp new file mode 100644 index 0000000..0c3f3a6 Binary files /dev/null and b/modules/3ds/dsp/txt/.init.cpp.kate-swp differ diff --git a/modules/3ds/dsp/txt/init.cpp b/modules/3ds/dsp/txt/init.cpp index 0c87c4c..da96eef 100644 --- a/modules/3ds/dsp/txt/init.cpp +++ b/modules/3ds/dsp/txt/init.cpp @@ -13,12 +13,23 @@ static int x=0,y=0; #define CHR_HEIGHT 8 #define CHR_WIDTH 8 #define HEIGHT 29 +#define PXHEIGHT 240 #ifndef ARM9 #define WIDTH 50 +#define PXWIDTH 400 #else #define WIDTH 40 +#define PXWIDTH 320 #endif #define BYTESPP 3 +#define CALCXY(x,y) ((x)*240+239-(y)) +#define TOPLFB 0x18000000 +#define BOTTOMLFB 0x18180000 +#ifdef ARM9 +#define LFB BOTTOMLFB +#else +#define LFB TOPLFB +#endif namespace MTGos { namespace { /** @@ -27,30 +38,73 @@ namespace { */ class Screen: public Base::Output { public: - Screen() {} - auto scroll() -> void { -#ifndef ARM9 - uint8_t* vmem = (uint8_t*)0x18300000; - uint8_t* dmem = (uint8_t*)0x18346500; -#else - uint8_t* dmem = (uint8_t*)0x18300000; - uint8_t* vmem = (uint8_t*)0x18346500; + auto clrscr() -> void { + uint32_t* vmem = (uint32_t*)LFB; + for(int i=0;i void { + uint32_t* vmem = (uint32_t*)LFB; + for(int ly=0;ly<240;ly++) { + for(int lx=0;lx void{ -#ifndef ARM9 - uint8_t* vmem = (uint8_t*)0x18300000; - uint8_t* dmem = (uint8_t*)0x18346500; -#else - uint8_t* dmem = (uint8_t*)0x18300000; - uint8_t* vmem = (uint8_t*)0x18346500; -#endif + uint32_t* vmem = (uint32_t*)LFB; c&=0xFF; switch(c) { case '\n': @@ -72,13 +126,9 @@ private: for(int cx=0;cx