Did some stuff to prepare future interrupt handling

This commit is contained in:
Morten Delenk 2016-08-20 21:55:07 +02:00
parent ed9f968dd4
commit a381d2d189
No known key found for this signature in database
GPG key ID: 3F818D0F65DCB490
9 changed files with 182 additions and 60 deletions

View file

@ -1,9 +1,9 @@
all: loader.bin firm.bin all: loader.bin mtgos.firm
$(MAKE) -C modules $(MAKE) -C modules
loader.bin: loader.bin:
$(MAKE) -C boot $(MAKE) -C boot
mv boot/loader.bin . mv boot/loader.bin .
firm.bin: mtgos.firm:
$(MAKE) -C kernel $(MAKE) -C kernel
mv kernel/mtgos.elf . mv kernel/mtgos.elf .
objcopy -O binary mtgos.elf mtgos.bin objcopy -O binary mtgos.elf mtgos.bin

View file

@ -17,11 +17,55 @@ _start:
mov $kernel_stack, %esp mov $kernel_stack, %esp
push %ebx push %ebx
push %eax 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 call init
_exit: _exit:
cli cli
hlt hlt
jmp _exit 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 .section .bss
.space 8192 .space 8192
kernel_stack: kernel_stack:

View file

@ -110,22 +110,35 @@ gdt:
.byte 0x98 .byte 0x98
.byte 0xCF .byte 0xCF
.byte 0x00 .byte 0x00
//data //data kernel
.word 0xFFFF .word 0xFFFF
.word 0x0000 .word 0x0000
.byte 0x00 .byte 0x00
.byte 0x92 .byte 0x92
.byte 0xCF .byte 0xCF
.byte 00 .byte 00
//64-bit code //64-bit code kernel
.int 0 .int 0
.byte 0 .byte 0
.byte 0x98 .byte 0x98
.byte 0x20 .byte 0x20
.byte 0 .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: gdtr:
.word 4 * 8 .word 6 * 8
.int gdt .int gdt
pmfill: pmfill:
.int pagedirPT + 0x7 .int pagedirPT + 0x7

BIN
firm.bin Normal file

Binary file not shown.

16
include/interrupts.h Normal file
View 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
};
}

View file

@ -23,7 +23,7 @@ typedef size_t(*sizeof_type)();
* size_t size_of(); * size_t size_of();
* bool spawnAt(void*); * bool spawnAt(void*);
*/ */
extern "C" table_type getTable(); extern "C" table_type getTable(void*(*)(ModType));
/** /**
* \brief returns the type of the module * \brief returns the type of the module

View file

@ -51,6 +51,11 @@ void adjustVTable(uintptr_t** obj, uintptr_t mod, int vtableSize) {
(*obj)[i]+=mod; (*obj)[i]+=mod;
} }
} }
void* getModule(ModType mt) {
if(mt==ModType::output_text)
return (void*) &out;
return nullptr;
}
/** /**
* \function _start() * \function _start()
* \brief Initializes the kernel * \brief Initializes the kernel
@ -61,20 +66,13 @@ extern "C" void _start(void ** modtable) {
for(int i=0;i<1024;i++) { for(int i=0;i<1024;i++) {
if(!modtable[i]) if(!modtable[i])
break; break;
void(**(*fptr)(void*))() = load((Elf_Ehdr*) modtable[i]); void(**(*fptr)(void* (*)(ModType)))() = (void(**(*)(void* (*)(ModType)))()) load((Elf_Ehdr*) modtable[i]);
if(!fptr) if(!fptr)
continue; continue;
void(**table)()=fptr(modtable[i]); void(**table)()=fptr(&getModule);
#ifndef __LP64__ #ifndef __LP64__
//Relocate table //Relocate table
table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+0x1000); table=(void(**)())((uintptr_t)table+(uintptr_t)modtable[i]+PAGE_SIZE);
#endif
#ifdef ARM9
table = (void(**)())0x27FFFFE8;
#else
#ifdef ARM11
table = (void(**)())0x27FFFFF4;
#endif
#endif #endif
//Relocate table contents //Relocate table contents
uintptr_t* tbl=(uintptr_t*)table; uintptr_t* tbl=(uintptr_t*)table;
@ -82,8 +80,8 @@ extern "C" void _start(void ** modtable) {
tbl[1]+=(uintptr_t)modtable[i]+PAGE_SIZE; tbl[1]+=(uintptr_t)modtable[i]+PAGE_SIZE;
tbl[2]+=(uintptr_t)modtable[i]+PAGE_SIZE; tbl[2]+=(uintptr_t)modtable[i]+PAGE_SIZE;
ModType type=((getType_type)table[0])(); //Get module type ModType type=((getType_type)table[0])(); //Get module type
if(type!=ModType::output_text) switch(type) {
continue; case ModType::output_text: {
size_t size=((sizeof_type)table[1])(); //Get module size size_t size=((sizeof_type)table[1])(); //Get module size
((spawnAt_type)table[2])((void*)&out); //Spawn module ((spawnAt_type)table[2])((void*)&out); //Spawn module
adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1); adjustVTable((uintptr_t**) &out, (uintptr_t)modtable[i], 1);
@ -93,6 +91,14 @@ extern "C" void _start(void ** modtable) {
#else #else
out << "Here arm11!\n"; out << "Here arm11!\n";
#endif #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++) for(void(**i)()=&start_dtors;i<&end_dtors;i++)
(*i)(); //Calling destructors (*i)(); //Calling destructors

Binary file not shown.

View file

@ -13,12 +13,23 @@ static int x=0,y=0;
#define CHR_HEIGHT 8 #define CHR_HEIGHT 8
#define CHR_WIDTH 8 #define CHR_WIDTH 8
#define HEIGHT 29 #define HEIGHT 29
#define PXHEIGHT 240
#ifndef ARM9 #ifndef ARM9
#define WIDTH 50 #define WIDTH 50
#define PXWIDTH 400
#else #else
#define WIDTH 40 #define WIDTH 40
#define PXWIDTH 320
#endif #endif
#define BYTESPP 3 #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 MTGos {
namespace { namespace {
/** /**
@ -27,30 +38,73 @@ namespace {
*/ */
class Screen: public Base::Output { class Screen: public Base::Output {
public: public:
Screen() {} auto clrscr() -> void {
auto scroll() -> void { uint32_t* vmem = (uint32_t*)LFB;
#ifndef ARM9 for(int i=0;i<PXWIDTH*PXHEIGHT;i++) {
uint8_t* vmem = (uint8_t*)0x18300000; vmem[i]=0;
uint8_t* dmem = (uint8_t*)0x18346500; }
#else }
uint8_t* dmem = (uint8_t*)0x18300000; Screen() {
uint8_t* vmem = (uint8_t*)0x18346500; #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 #endif
for(int p=0;p<HEIGHT*WIDTH*CHR_HEIGHT*CHR_WIDTH*BYTESPP;p++) clrscr();
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++) auto scroll() -> void {
vmem[p]=0x00; 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--; y--;
} }
private: private:
virtual auto putChar(int c) -> void{ virtual auto putChar(int c) -> void{
#ifndef ARM9 uint32_t* vmem = (uint32_t*)LFB;
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
c&=0xFF; c&=0xFF;
switch(c) { switch(c) {
case '\n': case '\n':
@ -72,13 +126,9 @@ private:
for(int cx=0;cx<CHR_WIDTH;cx++) { for(int cx=0;cx<CHR_WIDTH;cx++) {
for(int cy=0;cy<CHR_HEIGHT;cy++) { for(int cy=0;cy<CHR_HEIGHT;cy++) {
if(font[c][cy]&(1<<cx)) { if(font[c][cy]&(1<<cx)) {
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP]=0xFF; vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)]=0xFFFFF00F;
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;
}else { }else {
vmem[((x*CHR_WIDTH+cx)*(HEIGHT+1)*8+HEIGHT*CHR_HEIGHT-(y*CHR_HEIGHT+cy))*BYTESPP]=0; vmem[CALCXY(x*CHR_WIDTH+cx,y*CHR_HEIGHT+cy)]=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;
} }
} }
} }
@ -95,17 +145,10 @@ private:
}; };
} }
} }
//void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt}; void(*tbl[3])()={(void(*)())&getType,(void(*)())&size_of,(void(*)())&spawnAt};
table_type getTable() { table_type getTable(void*(*)(ModType)) {
#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;
doCtors(); doCtors();
return (void(**)())&tbl;
#ifdef ARM9 #ifdef ARM9
return (void(**)())0x27FFFFE8; return (void(**)())0x27FFFFE8;
#else #else