diff --git a/Makefile b/Makefile index e83248e..7352c06 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ WORLD_LIB_SRC=${CURDIR}/lib WORLD_LIBEXEC_SRC=${CURDIR}/libexec WORLD_BIN_SRC=${CURDIR}/bin -WORLD_INC=${CURDIR}/include.new +WORLD_INC="-I${CURDIR}/include_old -I${CURDIR}/lib/objgfx40/" WORLD_FLAGS=_ARCH=${_ARCH} CC="cc" CXX="c++" AS="as" AR="ar" LD="ld" NM=nm OBJDUMP= OBJCOPY="objcopy" RANLIB=ranlib WMAKE= ${MAKE} ${WORLD_FLAGS} INCLUDE=${WORLD_INC} BUILD_DIR=${CURDIR}/build diff --git a/bin/Makefile b/bin/Makefile index e9f4071..ae5016e 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -2,6 +2,7 @@ # The System Makefile (C) 2002 The UbixOS Project all: init-bin login-bin shell-bin clock-bin cp-bin fdisk-bin format-bin disklabel-bin ubistry-bin ttyd-bin stat-bin +# muffin-bin # cat-bin # MrOlsen (2016-01-11) ERROR: weird it didnt like -elf rtld-elf-bin # MrOlsen (2016-01-11) NOTE: edit-bin diff --git a/lib/objgfx40/objgfx40.cpp b/lib/objgfx40/objgfx40.cpp index 3279417..7a425c3 100644 --- a/lib/objgfx40/objgfx40.cpp +++ b/lib/objgfx40/objgfx40.cpp @@ -2846,7 +2846,7 @@ } // ogSurface::ogGetLastError void ogSurface::ogGetPalette(ogRGBA8 _pal[256]) { - memcpy(_pal, pal, sizeof(_pal)); + memcpy(_pal, pal, sizeof(ogRGBA8) * 256); return; } // ogSurface::ogGetPalette @@ -3365,7 +3365,7 @@ if (dX1 > dX2) { xx = dX1; - dX1 = dX1; + //dX1 = dX1; dX2 = xx; } @@ -3560,7 +3560,7 @@ void ogSurface::ogSetPalette(const ogRGBA8 newPal[256]) { if (pal == NULL) return; - memcpy(pal, newPal, sizeof(pal)); + memcpy(pal, newPal, sizeof(ogRGBA8) * 256); return; } // ogSurface::ogSetPalette diff --git a/lib/objgfx40/ogFont.cpp b/lib/objgfx40/ogFont.cpp index edbb24a..4edab4d 100644 --- a/lib/objgfx40/ogFont.cpp +++ b/lib/objgfx40/ogFont.cpp @@ -4,6 +4,7 @@ extern "C" { #ifdef __UBIXOS_KERNEL__ #include +#include #else #include #include @@ -15,28 +16,15 @@ //using namespace std; typedef struct { - char ID[3]; - uint8_t version; - uint8_t width, height; - uint8_t numOfChars; - uint8_t startingChar; - uint8_t colourType; - uint8_t paddington[7]; + char ID[3]; + uint8_t version; + uint8_t width, height; + uint8_t numOfChars; + uint8_t startingChar; + uint8_t colourType; + uint8_t paddington[7]; } ogDPFHeader; -static -bool fileExists(const char *file) { -#ifdef __UBIXOS_KERNEL__ - fileDescriptor *f = fopen(file, "rb"); -#else - FILE *f = fopen(file, "rb"); -#endif - if (!f) - return false; - fclose(f); - return true; -} - ogBitFont::ogBitFont(void) { memset(fontDataIdx, 0, sizeof(fontDataIdx)); memset(charWidthTable, 0, sizeof(charWidthTable)); @@ -60,7 +48,7 @@ return; } // ogBitFont::ogBitFont -void ogBitFont::SetBGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { +void ogBitFont::SetBGColor(uint32_t red, uint32_t green, uint32_t blue, uint32_t alpha) { BGColour.red = red; BGColour.green = green; BGColour.blue = blue; @@ -68,7 +56,7 @@ return; } // ogBitFont::SetBGColor -void ogBitFont::SetFGColor(uInt32 red, uInt32 green, uInt32 blue, uInt32 alpha) { +void ogBitFont::SetFGColor(uint32_t red, uint32_t green, uint32_t blue, uint32_t alpha) { FGColour.red = red; FGColour.green = green; FGColour.blue = blue; @@ -95,7 +83,7 @@ } // ogBitFont::CenterTextX void ogBitFont::JustifyText(ogSurface& dest, ogTextAlign horiz, ogTextAlign vert, const char * textString) { - uInt32 x, y; + uint32_t x, y; switch (horiz) { case leftText: @@ -128,26 +116,26 @@ return; } // ogBitFont::JustifyText -bool ogBitFont::Load(const char* fontFile, uInt32 offset = 0) { +bool ogBitFont::Load(const char* fontFile, uint32_t offset = 0) { #ifdef __UBIXOS_KERNEL__ fileDescriptor * infile; #else FILE * infile; #endif ogDPFHeader header; - uInt32 lresult, size; - - if (!fileExists(fontFile)) - return false; + uint32_t lresult, size; delete[] fontData; infile = fopen(fontFile, "rb"); - fseek(infile, offset, SEEK_SET); + + //fseek(infile, offset, SEEK_SET); + lresult = fread(&header, sizeof(header), 1, infile); width = header.width; height = header.height; numOfChars = header.numOfChars; + if (numOfChars == 0) numOfChars = 256; startingChar = header.startingChar; @@ -156,18 +144,18 @@ memset(charWidthTable, 0, sizeof(charWidthTable)); memset(charHeightTable, 0, sizeof(charHeightTable)); - size = (((uInt32) width + 7) / 8) * (uInt32) height; - fontDataSize = size * (uInt32) numOfChars; + size = (((uint32_t) width + 7) / 8) * (uint32_t) height; + fontDataSize = size * (uint32_t) numOfChars; - for (int32 tmp = startingChar; tmp <= startingChar + numOfChars - 1; tmp++) { + for (int32 tmp = startingChar; tmp <= startingChar + (numOfChars - 1); tmp++) { charWidthTable[tmp] = width; charHeightTable[tmp] = height; fontDataIdx[tmp] = (size * (tmp - startingChar)); } // for tmp - fontData = new uInt8[fontDataSize]; + fontData = new uint8_t[fontDataSize]; - lresult = fread(fontData, 1, fontDataSize, infile); + lresult = fread(fontData, fontDataSize, 1, infile); fclose(infile); return true; @@ -175,7 +163,7 @@ /* bool - ogFont::LoadFrom(const char* FontFile, uInt32 Offset) { + ogFont::LoadFrom(const char* FontFile, uint32_t Offset) { return true; } // ogFont::LoadFrom @@ -186,8 +174,8 @@ } // ogFont::Save */ -uInt32 ogBitFont::TextHeight(const char * textString) { - uInt32 size, tmpsize; +uint32_t ogBitFont::TextHeight(const char * textString) { + uint32_t size, tmpsize; size = 0; const unsigned char * text = (const unsigned char *) textString; @@ -201,8 +189,8 @@ return size; } // ogBitFont::TextHeight -uInt32 ogBitFont::TextWidth(const char * textString) { - uInt32 size = 0; +uint32_t ogBitFont::TextWidth(const char * textString) { + uint32_t size = 0; const unsigned char * text = (const unsigned char *) textString; if (text != NULL) @@ -220,14 +208,16 @@ void ogBitFont::PutChar(ogSurface& dest, int32 x, int32 y, const char ch) { - uInt32 xx, xCount, yCount; - uInt32 BGC, FGC, tColour; - uInt8 * offset; - uInt8 bits = 0; + uint32_t xx, xCount, yCount; + uint32_t BGC, FGC, tColour; + uint8_t * offset; + uint8_t bits = 0; + const unsigned char c = (const unsigned char) ch; if (fontData == NULL) return; + if (!dest.ogAvail()) return; diff --git a/sys/i386/bioscall.c b/sys/i386/bioscall.c index 594c6a4..2d01a44 100644 --- a/sys/i386/bioscall.c +++ b/sys/i386/bioscall.c @@ -48,13 +48,13 @@ assert(newProcess); newProcess->tss.back_link = 0x0; - newProcess->tss.esp0 = (uint32_t)vmm_getFreeKernelPage(_current->id, 2) + (0x2000 - 0x4); + newProcess->tss.esp0 = 0xDEADBEAD;(uint32_t)vmm_getFreeKernelPage(newProcess->id, 2) + (0x2000 - 0x4); newProcess->tss.ss0 = 0x10; newProcess->tss.esp1 = 0x0; newProcess->tss.ss1 = 0x0; newProcess->tss.esp2 = 0x0; newProcess->tss.ss2 = 0x0; - newProcess->tss.cr3 = (uint32_t)_current->tss.cr3; //(uInt32)vmmCreateVirtualSpace(newProcess->id); + newProcess->tss.cr3 = kernelPageDirectory; //vmm_createVirtualSpace(newProcess->id); //(uint32_t)_current->tss.cr3; newProcess->tss.eip = offset & 0xFFFF; newProcess->tss.eflags = 2 | EFLAG_IF | EFLAG_VM; newProcess->tss.eax = eax & 0xFFFF; @@ -77,14 +77,13 @@ newProcess->tss.io_map = sizeof(struct tssStruct) - 8192; newProcess->oInfo.v86Task = 0x1; - - kprintf("EIP: [0x%X] 0x%X:0x%X", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); + newProcess->state = READY; while (newProcess->state > 0) - asm("nop"); - kprintf("EIP: [0x%X] 0x%X:0x%X!", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); + sched_yield(); + kprintf("EIP: [0x%X] 0x%X:0x%X!", tmpAddr, newProcess->tss.eip, newProcess->tss.cs); kprintf("CALL DONE: %i 0x%X 0x%X!", newProcess->state, newProcess->tss.esp, newProcess->tss.ss); return; diff --git a/sys/i386/i386_exec.c b/sys/i386/i386_exec.c index 7a16b87..e230aef 100644 --- a/sys/i386/i386_exec.c +++ b/sys/i386/i386_exec.c @@ -207,7 +207,7 @@ newProcess->files[0] = 0x0; - kprintf("EIP: 0x%X", tproc); + kprintf("EIP: 0x%X(%i)", tproc, newProcess->id); /* Set up default stack for thread here filled with arg list 3 times */ asm volatile( diff --git a/sys/i386/sched.c b/sys/i386/sched.c index 09eba04..c987b0d 100644 --- a/sys/i386/sched.c +++ b/sys/i386/sched.c @@ -127,7 +127,8 @@ if (_current->oInfo.v86Task == 0x1) { irqDisable(0x0); - kprintf("IRQ DISABLED"); + kprintf("IRQD(%i): 0x%X*0x%X:0x%X@, esp: 0x%X:0x%X, ebp: 0x%X:0x%X ds: 0x%X", _current->id, _current->tss.eflags, _current->tss.cs, _current->tss.eip, _current->tss.ss, _current->tss.esp, _current->tss.ss, _current->tss.ebp,_current->tss.ds); + kprintf("ss0: 0x%X, esp0: 0x%X", _current->tss.ss0, _current->tss.esp0); } asm("cli"); @@ -268,6 +269,7 @@ ************************************************************************/ void sched_yield() { + kprintf("sy %i", _current->id); sched(); } diff --git a/sys/i386/systemtask.c b/sys/i386/systemtask.c index d9d61ed..639d93b 100644 --- a/sys/i386/systemtask.c +++ b/sys/i386/systemtask.c @@ -113,7 +113,8 @@ kfree(tmpTask); } - videoBuffer[0] = systemVitals->sysTicks; + if (ogprintOff == 1) + videoBuffer[0] = systemVitals->sysTicks; sched_yield(); } diff --git a/sys/i386/trap.c b/sys/i386/trap.c index 82e6b7e..60f0c65 100644 --- a/sys/i386/trap.c +++ b/sys/i386/trap.c @@ -34,28 +34,6 @@ #include #include -#define KERNEL_STACK 0x2000 - -/* -#define TRAP_CODE(trap_nr, signr, str, trap_name, tsk) void do_##trap_name(struct trapframe *regs, long error_code) { \ - die_if_kernel(str, regs, error_code); \ -} - -TRAP_CODE(0, SIGFPE, "divide error", divide_error, _current) -TRAP_CODE(3, SIGTRAP, "int3", int3, _current) -TRAP_CODE(4, SIGSEGV, "overflow", overflow, _current) -TRAP_CODE(5, SIGSEGV, "bounds", bounds, _current) -TRAP_CODE(6, SIGILL, "invalid operand", invalid_op, _current) -TRAP_CODE(7, SIGSEGV, "device not available", device_not_available, _current) -TRAP_CODE(8, SIGSEGV, "double fault", double_fault, _current) -TRAP_CODE( 9, SIGFPE, "coprocessor segment overrun", coprocessor_segment_overrun, last_task_used_math) -TRAP_CODE(10, SIGSEGV, "invalid TSS", invalid_TSS, _current) -TRAP_CODE(11, SIGBUS, "segment not present", segment_not_present, _current) -TRAP_CODE(12, SIGBUS, "stack segment", stack_segment, _current) -TRAP_CODE(15, SIGSEGV, "reserved", reserved, _current) -TRAP_CODE(17, SIGSEGV, "alignment check", alignment_check, _current) -*/ - #define FIRST_TSS_ENTRY 6 #define VM_MASK 0x00020000 @@ -100,7 +78,6 @@ ss = 0x10; } - kprintf("0x%X str", str); kprintf("\n%s: 0x%X:%i, CPU %d, EIP: 0x%X, EFLAGS: 0x%X\n", str, regs->tf_err, regs->tf_trapno, 0x0, regs->tf_eip, regs->tf_eflags); kprintf("eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n", regs->tf_eax, regs->tf_ebx, regs->tf_ecx, regs->tf_edx); kprintf("esi: %08lx edi: %08lx ebp: %08lx esp: %08lx\n", regs->tf_esi, regs->tf_edi, regs->tf_ebp, esp); @@ -108,7 +85,7 @@ kprintf("cr0: 0x%X, cr2: 0x%X, cr3: 0x%X, cr4: 0x%X\n", rcr0(), rcr2(), rcr3(), rcr4()); store_TR(i); - kprintf("Process %s (pid: %i, process nr: %d, stackpage=%08lx)\nStack:", _current->name, _current->id, 0xffff & i, KERNEL_STACK); + kprintf("Process %s (pid: %i, process nr: %d, stackpage=%08lx)\nStack:", _current->name, _current->id, 0xffff & i, esp); stack = (unsigned long *) esp; @@ -128,18 +105,18 @@ trap_code = frame->tf_trapno; cr2 = rcr2(); - kprintf("CR2: 0x%X[0x%X]", cr2,_current->tss.ldt); + kprintf("CR2: 0x%X(0x%X)[0x%X]", cr2,_current->tss.eip,_current->tss.ldt); if (_current->id == 7) while(1) asm("nop"); if ((frame->tf_eflags & PSL_I) == 0) { if (SEL_GET_PL(frame->tf_cs) == SEL_PL_USER || (frame->tf_eflags & PSL_VM)) { + kpanic( "INT OFF! USER" ); die_if_kernel("TEST", frame, 0x100); - // kpanic( "INT OFF! USER" ); } else { + kpanic( "INT OFF! KERN[0x%X]", trap_code ); die_if_kernel("TEST", frame, 0x200); -// kpanic( "INT OFF! KERN[0x%X]", trap_code ); } } @@ -148,6 +125,7 @@ vmm_pageFault(frame, cr2); } else { + kpanic("TRAPCODE"); die_if_kernel("trapCode", frame, frame->tf_trapno); endTask(_current->id); sched_yield(); diff --git a/sys/include/sys/idt.h b/sys/include/sys/idt.h index 586fbfd..e5c114a 100644 --- a/sys/include/sys/idt.h +++ b/sys/include/sys/idt.h @@ -40,47 +40,8 @@ int idt_init(); void setVector(void *handler, unsigned char interrupt, unsigned short controlMajor); void setTaskVector(uInt8 interrupt, uInt16 controlMajor, uInt8 selector); -void intNull(); -void _int0(); -void _int1(); -void _int2(); -void _int3(); -void _int4(); -void _int5(); -void _int6(); -void _int7(); -void _int8(); -void _int9(); -void _int10(); -void _int11(); -void _int12(); -void _int13(); + void timerInt(); #endif - -/*** - $Log: idt.h,v $ - Revision 1.1.1.1 2006/06/01 12:46:15 reddawg - ubix2 - - Revision 1.2 2005/10/12 00:13:37 reddawg - Removed - - Revision 1.1.1.1 2005/09/26 17:23:52 reddawg - no message - - Revision 1.5 2004/09/07 21:54:38 reddawg - ok reverted back to old scheduling for now.... - - Revision 1.3 2004/07/09 13:16:41 reddawg - idt: idtInit to idt_init - Adjusted Startup Routines - - Revision 1.2 2004/05/21 15:12:17 reddawg - Cleaned up - - - END - ***/ diff --git a/sys/include/ubixos/sched.h b/sys/include/ubixos/sched.h index ac6313a..3388bec 100644 --- a/sys/include/ubixos/sched.h +++ b/sys/include/ubixos/sched.h @@ -56,6 +56,7 @@ uInt32 controlKeys; char *stdin; char cwd[1024]; /* current working dir */ + uint8_t gpf; }; typedef struct taskStruct { diff --git a/sys/init/main.c b/sys/init/main.c index 4dfcee3..812b870 100644 --- a/sys/init/main.c +++ b/sys/init/main.c @@ -84,7 +84,7 @@ ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss + dDpl3)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dCode + dRead + dBig + dBiglim + dDpl3)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), -ubixStandardDescriptor(0x4200, (sizeof(struct tssStruct)), (dTss)), +ubixStandardDescriptor(0x5200, (sizeof(struct tssStruct)), (dTss + dDpl3)), ubixStandardDescriptor(0x6200, (sizeof(struct tssStruct)), (dTss)), ubixStandardDescriptor(0x0000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl0)), ubixStandardDescriptor(0xBFC00000, 0xFFFFF, (dData + dWrite + dBig + dBiglim + dDpl3)), @@ -144,8 +144,8 @@ execThread(systemTask, 0x2000, 0x0); kprintf("Thread Start!\n"); - //execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */ - //kprintf("File Start!\n"); + execFile("sys:/bin/init", argv_init, envp_init, 0x0); /* OS Initializer */ + kprintf("File Start!\n"); kprintf("SDE Thread Start! [0x%X]\n", &sdeThread); execThread(&sdeThread, 0x2000,0x0); diff --git a/sys/lib/Makefile b/sys/lib/Makefile index fc308de..376e1ff 100644 --- a/sys/lib/Makefile +++ b/sys/lib/Makefile @@ -8,8 +8,7 @@ INCLUDES += -I../../lib/objgfx40/ # Objects -OBJS = strstr.o strlen.o strncpy.o assert.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o -#ogprintf.o +OBJS = strstr.o strlen.o strncpy.o assert.o sqrt.o atan.o divdi3.o libcpp.o strtok.o kmalloc.o kprintf.o vsprintf.o string.o net.o strtol.o ogprintf.o all: $(OBJS) diff --git a/sys/lib/kprintf.c b/sys/lib/kprintf.c index 906b880..4cf64d5 100644 --- a/sys/lib/kprintf.c +++ b/sys/lib/kprintf.c @@ -267,7 +267,10 @@ buf[retval] = '\0'; va_end(ap); - kprint(buf); + if (printOff == 0x0) + kprint(buf); + if (ogprintOff == 0x0) + ogPrintf(buf); return (retval); } diff --git a/sys/lib/ogprintf.cc b/sys/lib/ogprintf.cc index 4956823..8f9a224 100644 --- a/sys/lib/ogprintf.cc +++ b/sys/lib/ogprintf.cc @@ -26,22 +26,24 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +extern "C" { #include #include #include -extern "C" { #include static int screenRow = 0x0; static int screenCol = 0x1; - int ogPrintf(char *s) { + int ogPrintf(char *ch) { int i = 0x0; int bufHeight; ogSurface *screen = (ogDisplay_UbixOS *) systemVitals->screen; ogBitFont *font = (ogBitFont *) systemVitals->font; + char *s = 0; + s = ch; while ('\0' != s[i]) { switch (s[i]) { @@ -63,7 +65,8 @@ } break; default: - font->PutChar(*screen, screenCol * font->GetWidth(), screenRow * font->GetHeight(), s[i]); + //font->PutChar(*screen, screenCol * font->GetWidth(), screenRow * font->GetHeight(), (char)s[i]); + font->PutChar(*screen, screenCol * font->GetWidth(), screenRow * font->GetHeight(), 65); break; } /* switch */ ++screenCol; diff --git a/sys/sde/main.cc b/sys/sde/main.cc index 0d91cc5..2f44fc8 100644 --- a/sys/sde/main.cc +++ b/sys/sde/main.cc @@ -50,8 +50,7 @@ ogBitFont * font = new ogBitFont(); - - font->Load("ROM8X14.DPF", 0); + font->Load("/var/fonts/ROM8X8.DPF", 0); font->SetFGColor(255, 255, 255, 255); font->SetBGColor(0, 0, 0, 255); @@ -59,8 +58,6 @@ screen->ogCreate(800, 600, OG_PIXFMT_16BPP); screen->ogClear(screen->ogPack(122, 140, 163)); - //kprintf("HERE!"); - //while (1) asm("nop"); systemVitals->screen = screen; systemVitals->font = font; @@ -117,6 +114,7 @@ tmp = 0x0; break; default: + sched_yield(); break; } } diff --git a/sys/sde/ogDisplay_UbixOS.cc b/sys/sde/ogDisplay_UbixOS.cc index 1eab764..3f9b2a1 100755 --- a/sys/sde/ogDisplay_UbixOS.cc +++ b/sys/sde/ogDisplay_UbixOS.cc @@ -48,9 +48,7 @@ */ void initVESAMode(uInt16 mode) { - kprintf("Pre-initVESAMode\n"); biosCall(0x10, 0x4F02, mode, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0); - kprintf("Post-initVESAMode\n"); return; } @@ -68,9 +66,7 @@ } // ogDisplay_UbixOS::ogDisplay_UbixOS void ogDisplay_UbixOS::GetModeInfo(uInt16 mode) { - //kprintf("Pre-getModeInfo\n"); biosCall(0x10, 0x4F01, 0x0, mode, 0x0, 0x0, 0x0, 0x1120, 0x0); - //kprintf("Post-getModeInfo\n"); return; } // ogDisplay_UbixOS::GetModeInfo @@ -79,9 +75,7 @@ VESAInfo->VBESignature[1] = 'B'; VESAInfo->VBESignature[2] = 'E'; VESAInfo->VBESignature[3] = '2'; - kprintf("Pre-getVESAInfo\n"); biosCall(0x10, 0x4F00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1100, 0x0); - kprintf("Post-getVESAInfo\n"); return; } // ogDisplay_UbixOS::GetVESAInfo diff --git a/sys/sys/idt.c b/sys/sys/idt.c index 842e254..271e345 100644 --- a/sys/sys/idt.c +++ b/sys/sys/idt.c @@ -43,6 +43,54 @@ #define FP_TO_LINEAR(seg, off) ((void*) ((((uint16_t) (seg)) << 4) + ((uint16_t) (off)))) +static uint32_t gpfStack = 0x0; + +void intNull(); + +void _divideError(); +void __divideError(struct trapframe *); + +void _debug(); +void __debug(struct trapframe *); + +void _nmi(); +void __nmi(struct trapframe *); + +static void _int3(); +static void _int4(); +static void _int5(); +static void _int6(); +static void _int7(); + +void _doubleFault(); +void __doubleFault(struct trapframe *); + +static void _int9(); +static void _int10(); +static void _int11(); +static void _int12(); + +void _gpf(); +void __gpf(struct trapframe *); + +void _floatingPoint(); +void __floatingPoint(struct trapframe *); + +void _alignmentCheck(); +void __alignmentCheck(struct trapframe *); + +void _machineCheck(); +void __machineCheck(struct trapframe *); + +void _simd(); +void __simd(struct trapframe *); + +void _virtualization(); +void __virtualization(struct trapframe *); + +void _security(); +void __security(struct trapframe *); + static ubixDescriptorTable(ubixIDT, 256) {}; static struct { @@ -61,7 +109,7 @@ ************************************************************************/ int idt_init() { struct tssStruct *sfTSS = (struct tssStruct *) 0x6200; - struct tssStruct *gpfTSS = (struct tssStruct *) 0x4200; + struct tssStruct *gpfTSS = (struct tssStruct *) 0x5200; /* Load the IDT into the system */ asm volatile( @@ -75,32 +123,41 @@ : "r" ((char *)&loadidt) ); - /* for (int i = 0;i < 256;i++) setVector(intNull, i, dPresent + dTrap + dDpl3); - */ /* Set up the basic vectors for the reserved ints */ - setVector(_int0, 0, dPresent + dInt + dDpl0); - setVector(_int1, 1, dPresent + dInt + dDpl0); - setVector(_int2, 2, dPresent + dInt + dDpl0); + setVector(_divideError, 0, dPresent + dInt + dDpl0); + setVector(_debug, 1, dPresent + dInt + dDpl0); + setVector(_nmi, 2, dPresent + dInt + dDpl0); setVector(_int3, 3, dPresent + dInt + dDpl0); setVector(_int4, 4, dPresent + dInt + dDpl0); setVector(_int5, 5, dPresent + dInt + dDpl0); setVector(_int6, 6, dPresent + dTrap + dDpl0); setVector(_int7, 7, dPresent + dInt + dDpl0); - setTaskVector(8, dPresent + dTask + dDpl0, 0x40); + setVector(_doubleFault, 8, dPresent + dInt + dDpl0); + //setTaskVector(8, dPresent + dTask + dDpl0, 0x40); setVector(_int9, 9, dPresent + dInt + dDpl0); setVector(_int10, 10, dPresent + dInt + dDpl0); setVector(_int11, 11, dPresent + dInt + dDpl0); setVector(_int12, 12, dPresent + dInt + dDpl0); + //setVector(_gpf, 13, dPresent + dInt + dDpl0); setTaskVector(13, dPresent + dTask + dDpl0, 0x38); setVector(_vmm_pageFault, 14, dPresent + dInt + dDpl0); + setVector(_floatingPoint, 16, dPresent + dInt + dDpl0); + setVector(_alignmentCheck, 17, dPresent + dInt + dDpl0); + setVector(_machineCheck, 18, dPresent + dInt + dDpl0); + setVector(_simd, 19, dPresent + dInt + dDpl0); + setVector(_virtualization, 20, dPresent + dInt + dDpl0); + setVector(_security, 30, dPresent + dInt + dDpl0); setVector(_sys_call_posix, 0x80, dPresent + dTrap + dDpl3); setVector(_sys_call, 0x81, dPresent + dTrap + dDpl3); setVector(timerInt, 0x68, (dInt + dPresent + dDpl0)); memset(gpfTSS, 0x0, sizeof(struct tssStruct)); + + gpfStack = 0x1D000;//(uint32_t)vmm_getFreeKernelPage(sysID, 1) + (PAGE_SIZE - 0x4); + gpfTSS->back_link = 0x0; gpfTSS->esp0 = 0x0; gpfTSS->ss0 = 0x0; @@ -109,9 +166,9 @@ gpfTSS->esp2 = 0x0; gpfTSS->ss2 = 0x0; gpfTSS->cr3 = (unsigned int) kernelPageDirectory; - gpfTSS->eip = (unsigned int) &_int13; + gpfTSS->eip = (unsigned int) &_gpf; gpfTSS->eflags = 0x206; - gpfTSS->esp = vmm_getFreeKernelPage(sysID, 1) + (PAGE_SIZE - 0x4); //0x1D000; + gpfTSS->esp = gpfStack; //0x1D000; gpfTSS->ebp = 0x0; // 0x1D000; gpfTSS->esi = 0x0; gpfTSS->edi = 0x0; @@ -125,9 +182,10 @@ gpfTSS->trace_bitmap = 0x0000; gpfTSS->io_map = 0x8000; + /* memset(sfTSS, 0x0, sizeof(struct tssStruct)); sfTSS->cr3 = (unsigned int) kernelPageDirectory; - sfTSS->eip = (unsigned int) &_int8; + sfTSS->eip = (unsigned int) &__int8; sfTSS->eflags = 0x206; sfTSS->esp = 0x1C000; sfTSS->ebp = 0x1C000; @@ -138,6 +196,7 @@ sfTSS->fs = 0x10; sfTSS->gs = 0x10; sfTSS->io_map = 0x8000; + */ /* Print out information for the IDT */ kprintf("idt0 - Address: [0x%X]\n", &ubixIDT); @@ -175,68 +234,133 @@ } /* Null Intterupt Descriptor */ -void intNull() { - kprintf("Invalid Interrupt[%i]\n", _current->id); +void _intNull(struct trapframe *frame) { + die_if_kernel("invalid exception", frame, 0x0); } asm( - ".globl _int0 \n" - "_int0: \n" - " pushl $0x0 \n" - " pushl $0x6 \n" - " pushal \n" /* Save all registers */ - " push %ds \n" - " push %es \n" - " push %fs \n" - " push %gs \n" - " push %esp \n" - " call __int0 \n" - " pop %gs \n" - " pop %fs \n" - " pop %es \n" - " pop %ds \n" - " popal \n" - " iret \n" /* Exit interrupt */ + ".globl intNull \n" + "intNull: \n" + " pushl $0x0 \n" + " pushl $0x0 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call _intNull \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" ); -void __int0(struct trapframe *frame) { - kpanic("BALLS"); - die_if_kernel("Divid-by-Zer0", frame, 0); - kpanic("int0: Divide-by-Zero [%i]\n", _current->id); +void __divideError(struct trapframe *frame) { + die_if_kernel("Divid-by-Zero", frame, 0); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _divideError \n" + "_divideError: \n" + " pushl $0x0 \n" + " pushl $0x6 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call _divideError \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __debug(struct trapframe *frame) { + die_if_kernel("debug", frame, 0x2); endTask(_current->id); sched_yield(); } -void _int1() { - kpanic("int1: Debug exception [%i]\n", _current->id); +asm( + ".globl _debug \n" + "_debug: \n" + " pushl $0x0 \n" + " pushl $0x6 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call _debug \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __nmi(struct trapframe *frame) { + die_if_kernel("nmi", frame, 0x2); endTask(_current->id); sched_yield(); } -void _int2() { - kpanic("int2: unknown error [%i]\n", _current->id); - endTask(_current->id); - sched_yield(); -} +asm( + ".globl _nmi \n" + "_nmi: \n" + " pushl $0x0 \n" + " pushl $0x6 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call _nmi \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); -void _int3() { + +static void _int3() { kpanic("int3: Breakpoint [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int4() { +static void _int4() { kpanic("int4: Overflow [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int5() { +static void _int5() { kpanic("int5: Bounds check [%i]\n", _current->id); endTask(_current->id); sched_yield(); } +void __int6(struct trapframe *frame) { + die_if_kernel("invalid_opcode", frame, 6); + endTask(_current->id); + sched_yield(); +} + asm( ".globl _int6 \n" "_int6: \n" @@ -257,15 +381,15 @@ " iret \n" /* Exit interrupt */ ); -void __int6(struct trapframe *frame) { - die_if_kernel("invalid_opcode", frame, 6); +void __doubleFault(struct trapframe *frame) { + die_if_kernel("double fault", frame, 0x8); endTask(_current->id); sched_yield(); } asm( - ".globl _int8 \n" - "_int8: \n" + ".globl _doubleFault \n" + "_doubleFault: \n" " pushl $0x8 \n" " pushal \n" /* Save all registers */ " push %ds \n" @@ -273,7 +397,7 @@ " push %fs \n" " push %gs \n" " push %esp \n" - " call __int8 \n" + " call __doubleFault \n" " pop %gs \n" " pop %fs \n" " pop %es \n" @@ -282,60 +406,53 @@ " iret \n" /* Exit interrupt */ ); -void __int8(struct trapframe *frame) { - die_if_kernel("INT8 Double Fault", frame, 8); - endTask(_current->id); - sched_yield(); -} - -void _int9() { +static void _int9() { kpanic("int9: Coprocessor Segment Overrun! [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int10() { +static void _int10() { kpanic("int10: Invalid TSS! [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int11() { +static void _int11() { kpanic("int11: Segment Not Present! [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int12() { +static void _int12() { kpanic("int12: Stack-Segment Fault! [%i]\n", _current->id); endTask(_current->id); sched_yield(); } -void _int13() { +void __gpf(struct trapframe *frame) { uint8_t *ip = 0x0; uint16_t *stack = 0x0, *ivt = 0x0; uint32_t *stack32 = 0x0; bool isOperand32 = FALSE, isAddress32 = FALSE; - struct tssStruct *gpfTSS = (struct tssStruct *) 0x4200; - irqDisable(0x0); + struct tssStruct *gpfTSS = (struct tssStruct *) 0x5200; - gpfTSS->eip = (unsigned int) &_int13; - gpfTSS->esp = 0x1D000; - gpfTSS->ebp = 0x1D000; - gpfTSS->eflags = 0x206; - + gpfEnter: + kprintf("DF"); ip = FP_TO_LINEAR(_current->tss.cs, _current->tss.eip); - ivt = (uInt16 *) 0x0; - stack = (uInt16 *) FP_TO_LINEAR(_current->tss.ss, _current->tss.esp); - stack32 = (uInt32 *) stack; + + ivt = (uint16_t *) 0x0; + + stack = (uint16_t *) FP_TO_LINEAR(_current->tss.ss, _current->tss.esp); + stack32 = (uint32_t *) stack; gpfStart: switch (ip[0]) { case 0xCD: /* INT n */ switch (ip[1]) { case 0x69: kprintf("Exit Bios [0x%X]\n", _current->id); + //while (1) asm("hlt"); _current->state = DEAD; break; case 0x20: @@ -345,13 +462,14 @@ default: stack -= 3; _current->tss.esp = ((_current->tss.esp & 0xffff) - 6) & 0xffff; - stack[0] = (uInt16) (_current->tss.eip + 2); + stack[0] = (uint16_t) (_current->tss.eip + 2); stack[1] = _current->tss.cs; - stack[2] = (uInt16) _current->tss.eflags; + stack[2] = (uint16_t) _current->tss.eflags; if (_current->oInfo.v86If) stack[2] |= EFLAG_IF; else stack[2] &= ~EFLAG_IF; + _current->tss.cs = ivt[ip[1] * 2 + 1] & 0xFFFF; _current->tss.eip = ivt[ip[1] * 2] & 0xFFFF; break; @@ -361,12 +479,14 @@ isOperand32 = TRUE; ip++; _current->tss.eip = (uInt16) (_current->tss.eip + 1); + kprintf("0x66"); goto gpfStart; break; case 0x67: isAddress32 = TRUE; ip++; _current->tss.eip = (uInt16) (_current->tss.eip + 1); + kprintf("0x67"); goto gpfStart; break; case 0xF0: @@ -429,7 +549,7 @@ _current->tss.eflags = EFLAG_IF | EFLAG_VM | stack[2]; _current->oInfo.v86If = (stack[2] & EFLAG_IF) != 0; _current->tss.esp = ((_current->tss.esp & 0xffff) + 6) & 0xffff; - /* kprintf("iret [0x%X]\n",_current->id); */ + kprintf("iret [0x%X]\n",_current->id); break; case 0xEC: /* IN AL,DX */ _current->tss.eax = (_current->tss.eax & ~0xFF) | inportByte(_current->tss.edx); @@ -452,16 +572,195 @@ break; default: /* something wrong */ kprintf("NonHandled OpCode [0x%X:0x%X]\n", _current->id, ip[0]); - while (1) - asm("nop"); - _current->state = DEAD; + //_current->state = DEAD; break; } + kprintf("RET1"); irqEnable(0); - while (1) - asm("nop"); + sched_yield(); + kprintf("RET2"); + goto gpfEnter; } +asm( + ".globl _gpf \n" + "_gpf: \n" + " cli \n" + " pushl $0x13 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __gpf \n" + " add $0x4,%esp \n" + " mov %esp,%eax \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " sti \n" + " iret \n" /* Exit interrupt */ +); + + +void __floatingPoint(struct trapframe *frame) { + die_if_kernel("floating point", frame, 0x10); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _floatingPoint \n" + "_floatingPoint: \n" + " pushl $0x0 \n" + " pushl $0x10 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __floatingPoint \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __alignmentCheck(struct trapframe *frame) { + die_if_kernel("alignment check", frame, 0x11); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _alignmentCheck \n" + "_alignmentCheck: \n" + " pushl $0x11 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __alignmentCheck \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __machineCheck(struct trapframe *frame) { + die_if_kernel("machine check", frame, 0x12); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _machineCheck \n" + "_machineCheck: \n" + " pushl $0x0\n" + " pushl $0x12 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __machineCheck \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __simd(struct trapframe *frame) { + die_if_kernel("simd", frame, 0x13); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _simd \n" + "_simd: \n" + " iret\n" + " pushl $0x0\n" + " pushl $0x13 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __simd \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __virtualization(struct trapframe *frame) { + die_if_kernel("virtualization", frame, 0x14); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _virtualization \n" + "_virtualization: \n" + " pushl $0x0 \n" + " pushl $0x14 \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __virtualization \n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + +void __security(struct trapframe *frame) { + die_if_kernel("security exception", frame, 0x1E); + endTask(_current->id); + sched_yield(); +} + +asm( + ".globl _security \n" + "_security: \n" + " pushl $0x1E \n" + " pushal \n" /* Save all registers */ + " push %ds \n" + " push %es \n" + " push %fs \n" + " push %gs \n" + " push %esp \n" + " call __security\n" + " pop %gs \n" + " pop %fs \n" + " pop %es \n" + " pop %ds \n" + " popal \n" + " iret \n" +); + /* Removed static however this is the only place it's called from */ void mathStateRestore() { if (_usedMath != 0x0) { @@ -488,7 +787,6 @@ //Return } -void _int7(); asm( ".globl _int7 \n"