Did some stuff to prepare future interrupt handling
This commit is contained in:
parent
ed9f968dd4
commit
a381d2d189
9 changed files with 182 additions and 60 deletions
6
Makefile
6
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
|
||||
find . -name '*.o' -delete
|
||||
|
|
|
@ -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:
|
|
@ -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
|
||||
|
|
BIN
firm.bin
Normal file
BIN
firm.bin
Normal file
Binary file not shown.
16
include/interrupts.h
Normal file
16
include/interrupts.h
Normal file
|
@ -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
|
||||
};
|
||||
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
modules/3ds/dsp/txt/.init.cpp.kate-swp
Normal file
BIN
modules/3ds/dsp/txt/.init.cpp.kate-swp
Normal file
Binary file not shown.
|
@ -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<PXWIDTH*PXHEIGHT;i++) {
|
||||
vmem[i]=0;
|
||||
}
|
||||
}
|
||||
Screen() {
|
||||
#ifdef ARM11
|
||||
// On ARM11, activate screens first
|
||||
//top screen lfb size: 0x5dc00
|
||||
//bottom screen lfb size: 0x4b000
|
||||
//lfb locations: 0x18000000 (left 1)
|
||||
//lfb locations: 0x18060000 (left 2)
|
||||
//lfb locations: 0x180C0000 (right 1)
|
||||
//lfb locations: 0x18120000 (right 2)
|
||||
//lfb locations: 0x18180000 (bottom 1)
|
||||
//lfb locations: 0x181D0000 (bottom 2)
|
||||
unsigned int *lfbs = (unsigned int*)0x18000000;
|
||||
unsigned int *fb_init=(unsigned int*)0x10400400;
|
||||
fb_init[0x70/4]&=~0x7;
|
||||
fb_init[0x170/4]&=~0x7;
|
||||
fb_init[0x68/4]=0x18000000; //Left eye
|
||||
fb_init[0x6C/4]=0x18060000; //Left eye
|
||||
fb_init[0x90/4]=960;
|
||||
fb_init[0x94/4]=0x180C0000; //Right eye
|
||||
fb_init[0x98/4]=0x18120000; //Right eye
|
||||
fb_init[0x168/4]=0x18180000;
|
||||
fb_init[0x16C/4]=0x181D0000;
|
||||
fb_init[0x190/4]=960;
|
||||
#endif
|
||||
for(int p=0;p<HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP;p++)
|
||||
vmem[p]=vmem[p+WIDTH*CHR_WIDTH*BYTESPP];
|
||||
for(int p=HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p<(HEIGHT*WIDTH+WIDTH)*CHR_HEIGHT*CHR_WIDTH*BYTESPP; p++)
|
||||
vmem[p]=0x00;
|
||||
clrscr();
|
||||
}
|
||||
auto scroll() -> void {
|
||||
uint32_t* vmem = (uint32_t*)LFB;
|
||||
for(int ly=0;ly<240;ly++) {
|
||||
for(int lx=0;lx<WIDTH*8;lx++) {
|
||||
if(ly<240-8) {
|
||||
vmem[CALCXY(lx,ly)]=vmem[CALCXY(lx,ly+8)];
|
||||
} else {
|
||||
vmem[CALCXY(lx,ly)]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* for(int x=0;x<WIDTH;x++) {
|
||||
for(int y=0;y<HEIGHT;y++) {
|
||||
for(int cx=0;cx<CHR_WIDTH;cx++) {
|
||||
for(int cy=0; cy < CHR_HEIGHT; cy++) {
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP]=vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy+8)*BYTESPP];
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP+1]=vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy+8)*BYTESPP+1];
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP+2]=vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy+8)*BYTESPP+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
int y=HEIGHT;
|
||||
for(int cx=0;cx<CHR_HEIGHT;cx++) {
|
||||
for(int cy=0; cy < CHR_WIDTH; cy++) {
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP]=0;
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP+1]=0;
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)*BYTESPP+2]=0;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
y--;
|
||||
}
|
||||
private:
|
||||
virtual auto putChar(int c) -> 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<CHR_WIDTH;cx++) {
|
||||
for(int cy=0;cy<CHR_HEIGHT;cy++) {
|
||||
if(font[c][cy]&(1<<cx)) {
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP]=0xFF;
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP+1]=0xFF;
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP+2]=0xFF;
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)]=0xFFFFF00F;
|
||||
}else {
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP]=0;
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP+1]=0;
|
||||
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP+2]=0;
|
||||
vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)]=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,17 +145,10 @@ private:
|
|||
};
|
||||
}
|
||||
}
|
||||
//void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
|
||||
table_type getTable() {
|
||||
#ifdef ARM9
|
||||
void(**tbl)() = (void(**)())0x27FFFFE8;
|
||||
#else
|
||||
void(**tbl)() = (void(**)())0x27FFFFF4;
|
||||
#endif
|
||||
tbl[0]=(void(*)())&getType;
|
||||
tbl[1]=(void(*)())&size_of;
|
||||
tbl[2]=(void(*)())&spawnAt;
|
||||
void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
|
||||
table_type getTable(void*(*)(ModType)) {
|
||||
doCtors();
|
||||
return (void(**)())&tbl;
|
||||
#ifdef ARM9
|
||||
return (void(**)())0x27FFFFE8;
|
||||
#else
|
||||
|
|
Loading…
Reference in a new issue