diff --git a/src/sys/include/ubixos/sched.h b/src/sys/include/ubixos/sched.h index d3b7e76..0a72476 100644 --- a/src/sys/include/ubixos/sched.h +++ b/src/sys/include/ubixos/sched.h @@ -30,6 +30,10 @@ #ifndef _SCHED_H #define _SCHED_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -37,7 +41,7 @@ #include -typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4,WAIT=5 } tState; +typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4 } tState; struct osInfo { uInt8 timer; @@ -65,7 +69,6 @@ uInt16 nice; uInt32 timeSlice; tty_term *term; - pidType parent; } kTask_t; typedef struct prioQueue { @@ -81,9 +84,9 @@ int sched_init(); int sched_setStatus(pidType,tState); void sched(); -void sched_yield(); +void schedYield(); void schedEndTask(pidType pid); kTask_t *schedNewTask(); kTask_t *schedFindTask(uInt32 id); @@ -92,6 +95,10 @@ extern kTask_t *_current; extern kTask_t *_usedMath; +#ifdef __cplusplus +} +#endif + #endif /*** diff --git a/src/sys/include/ubixos/tty.h b/src/sys/include/ubixos/tty.h index 3090fd6..0077774 100644 --- a/src/sys/include/ubixos/tty.h +++ b/src/sys/include/ubixos/tty.h @@ -31,28 +31,22 @@ #define _TTY_H #include -#include #define TTY_MAX_TERMS 5 typedef struct tty_termNode { - spinLock_t tty_spinLock; - char *tty_buffer; - char *tty_pointer; - uInt8 tty_colour; - uInt8 tty_stdin; - uInt16 tty_x; - uInt16 tty_y; - pidType pid; + char *tty_buffer; + char *tty_pointer; + uInt8 tty_colour; + uInt16 current; + uInt16 tty_x; + uInt16 tty_y; } tty_term; int tty_init(); -int tty_change(uInt16); +int tty_chang(uInt16); tty_term *tty_find(uInt16); int tty_print(char *,tty_term *); -int tty_backspace(); - -extern tty_term *tty_foreground; #endif diff --git a/src/sys/isa/atkbd.c b/src/sys/isa/atkbd.c index 41200ce..f15b737 100644 --- a/src/sys/isa/atkbd.c +++ b/src/sys/isa/atkbd.c @@ -39,7 +39,6 @@ #include #include #include -#include #include static unsigned int keyMap = 0x0; @@ -248,13 +247,13 @@ if (((uInt)(keyboardMap[key][keyMap]) > 0) && ((uInt32)(keyboardMap[key][keyMap]) < 0xFF)) { switch ((uInt32)keyboardMap[key][keyMap]) { case 8: - tty_backspace(); + backSpace(); stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; stdinSize++; break; case 0x3: //endTask(_current->id); - //kprintf("CTRL-Cpressed\n"); + //kprintf("CTRL-C pressed\n"); break; default: stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; @@ -265,8 +264,8 @@ else { switch ((keyboardMap[key][keyMap] >> 8)) { case 0x30: - if ((tty_change(keyboardMap[key][keyMap] & 0xFF)) != 0x0) - kpanic("tty_change: Failed, File: %s, Line: %i\n",__FILE__,__LINE__); + tty_change(keyboardMap[key][keyMap] & 0xFF); + //kprintf("Changing Consoles[0x%X:0x%X]\n",_current->id,_current); break; default: break; @@ -289,9 +288,7 @@ uInt8 retKey = 0x0; uInt32 i = 0x0; - if (stdinSize == 0x0) - return(0x0); - + while (stdinSize == 0); retKey = stdinBuffer[0]; stdinSize--; diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index b0c3091..eade31f 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -47,9 +47,8 @@ if (_current->imageFd) fclose(_current->imageFd); //kprintf("FreePage: [0x%X]\n",systemVitals->freePages); - _current->term->pid = _current->parent; sched_setStatus(_current->id,DEAD); - sched_yield(); + schedYield(); return; } diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index 05faba4..47748ef 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -137,11 +137,9 @@ /* Get A New Task For This Proccess */ _current = schedNewTask(); assert(_current); - _current->gid = 0x0; - _current->uid = 0x0; - _current->term = tty_find(console); - _current->term->pid = _current->id; - + _current->gid = 0x0; + _current->uid = 0x0; + _current->term = tty_find(console); if (_current->term == 0x0) kpanic("Error: invalid console\n"); diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c index a5ccd12..74c55c6 100644 --- a/src/sys/kernel/file.c +++ b/src/sys/kernel/file.c @@ -206,34 +206,21 @@ } void sysFgetc(int *ptr,userFileDescriptor *userFd) { + fileDescriptor *tmpFd = 0x0; + asm("sti"); + tmpFd = userFd->fd; if (userFd->fd == 0x0) { - while (1) { - //kprintf("Meep:\n"); - if (_current->term->tty_stdin == 0x1) { - while ((*ptr = (int)getch()) == 0x0) { - while (_current->term->tty_stdin != 0x1) { - //signal(tty_foreground->pid,WAKE); - //kprintf("waking up: [%i]\n",tty_foreground->pid); - sched_setStatus(tty_foreground->pid,READY); - sched_setStatus(_current->id,WAIT); - //kprintf("sleeping: [%i]\n",_current->id); - sched_yield(); - } - } - return; - } - else { - //outportByte(0xE9,0x31 + _current->id); - //kprintf("sleeping: [%i]\n",_current->id); - sched_setStatus(_current->id,WAIT); - sched_yield(); - //kprintf("they woke up me: [%i:%i]\n",_current->id,_current->term->tty_stdin); - } - //kprintf("Moop:\n"); - } + /* + while (_current->term->current == 0x0) + schedYield(); + */ + if (_current->term->current == 0x0) + ptr[0] = '\0'; + else + ptr[0] = (int) getch(); } else { - *ptr = (int) fgetc(userFd->fd); + ptr[0] = (int) fgetc(tmpFd); } } diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index d508627..7420fa5 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -74,8 +74,6 @@ sprintf(newProcess->oInfo.cwd,_current->oInfo.cwd); newProcess->oInfo.vmStart = _current->oInfo.vmStart; newProcess->term = _current->term; - newProcess->term->pid = newProcess->id; - newProcess->parent = _current->id; newProcess->uid = _current->uid; newProcess->gid = _current->gid; newProcess->tss.back_link = 0x0; diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 3d2b73a..63e213c 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -141,17 +141,27 @@ void sched(){ uInt32 memAddr = 0x0; kTask_t *tmpTask = 0x0; -//kprintf("%i",_current->id); + schedStart: /* Yield the next task from the current prio queue */ for (tmpTask = _current->next; tmpTask; tmpTask = tmpTask->next) { - if (tmpTask->state > 0x0 && tmpTask->state != WAIT) { + if (tmpTask->state > 0x0) { _current = tmpTask; if (_current->state == FORK) _current->state = READY; break; } +/* + else if (tmpTask->state == DEAD) { + if (tmpTask == _current) + kpanic("unhandled situation"); + if (schedDeleteTask(tmpTask->id) != 0x0) { + kpanic("Error: schedDeleteTask");; + } + goto schedStart; + } +*/ } /* Finished all the tasks, restarting the list */ @@ -162,11 +172,12 @@ /* Setting the timeslice this task is allowed to run */ systemVitals->quantum = _current->timeSlice; - - if (_current->state > 0x0 && _current->state != WAIT) { + + + if (_current->state > 0x0) { if (_current->oInfo.v86Task == 0x1) irqDisable(0x0); - //asm("cli"); + asm("cli"); memAddr = (uInt32)&(_current->tss); ubixGDT[4].descriptor.baseLow = (memAddr & 0xFFFF); ubixGDT[4].descriptor.baseMed = ((memAddr >> 16) & 0xFF); @@ -174,11 +185,6 @@ ubixGDT[4].descriptor.access = '\x89'; asm("ljmp $0x20,$0\n"); } - else { - kprintf("FOOK WE BROKE!!!\n"); - goto schedStart; - } - return; } @@ -283,7 +289,7 @@ void schedEndTask(pidType pid) { endTask(_current->id); - sched_yield(); + schedYield(); } /************************************************************************ @@ -298,7 +304,7 @@ ************************************************************************/ void -sched_yield() { +schedYield() { sched(); } diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 41780b5..c891fc5 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -160,7 +160,7 @@ } void sysSchedYield() { - sched_yield(); + schedYield(); } void sysStartSDE() { diff --git a/src/sys/kernel/systemtask.c b/src/sys/kernel/systemtask.c index ca15a3a..16c38f4 100644 --- a/src/sys/kernel/systemtask.c +++ b/src/sys/kernel/systemtask.c @@ -57,7 +57,7 @@ counter = systemVitals->sysUptime + 5; while (systemVitals->sysUptime < counter) { //asm("hlt"); - sched_yield(); + schedYield(); } kprintf("Rebooting NOW!!!\n"); while(inportByte(0x64) & 0x02); @@ -85,7 +85,7 @@ break; } } - sched_yield(); + schedYield(); } return; } diff --git a/src/sys/kernel/tty.c b/src/sys/kernel/tty.c index 5a169cb..4074688 100644 --- a/src/sys/kernel/tty.c +++ b/src/sys/kernel/tty.c @@ -34,8 +34,9 @@ #include #include -static tty_term *terms = 0x0; -tty_term *tty_foreground = 0x0; +static tty_term *terms = 0x0; +static uInt16 tty_current = 0x0; +static spinLock_t tty_spinLock = SPIN_LOCK_INITIALIZER; int tty_init() { int i = 0x0; @@ -46,61 +47,38 @@ if (terms == 0x0) kpanic("tty_init: Failed to allocate memory\n"); - for (i = 0x0;i < TTY_MAX_TERMS;i++) { + for (i = 0;i < TTY_MAX_TERMS;i++) { terms[i].tty_buffer = (char *)kmalloc(80*60*2); if (terms[i].tty_buffer == 0x0) kpanic("tty_init: Failed to allocate buffer memory\n"); - terms[i].tty_pointer = terms[i].tty_buffer; - terms[i].tty_x = 0x0; - terms[i].tty_y = 0x0; - terms[i].tty_colour = 0x0A + i; - terms[i].tty_stdin = 0x0; - terms[i].tty_spinLock = SPIN_LOCK_INITIALIZER; + terms[i].tty_pointer = terms[i].tty_buffer; + terms[i].tty_x = 0x0; + terms[i].tty_y = 0x0; + terms[i].current = 0x0; + terms[i].tty_colour = 0x0A + i; } - terms[0].tty_pointer = (char *)0xB8000; - - tty_foreground = &terms[0x0]; - tty_foreground->tty_stdin = 0x1; + terms[0].current = 0x1; kprintf("tty0 - Initialized\n"); return(0x0); } int tty_change(uInt16 tty) { - - /* Copy text buffer to tty buffer */ - memcpy(tty_foreground->tty_buffer,(char *)0xB8000,(80*60*2)); - - /* Copy tty buffer to text buffer */ + memcpy(terms[tty_current].tty_buffer,(char *)0xB8000,(80*60*2)); memcpy((char *)0xB8000,terms[tty].tty_buffer,(80*60*2)); + terms[tty_current].tty_pointer = terms[tty_current].tty_buffer; + terms[tty_current].current = 0x0; - /* - Set tty_pointer to internal buffer so non foreground app can - still continue to write to a text buffer. - */ - tty_foreground->tty_pointer = tty_foreground->tty_buffer; - tty_foreground->tty_stdin = 0x0; - - /* - Set tty_pointer to the text buffer so it becomes the foreground - terminal. - */ terms[tty].tty_pointer = (char *)0xB8000; - terms[tty].tty_stdin = 0x1; - - /* Lastly set tty_current to tty so we know what now is the current tty */ - tty_foreground = &terms[tty]; - - /* Return 0x0 so we know all went well */ + terms[tty].current = 0x1; + tty_current = tty; return(0x0); } int tty_print(char *string,tty_term *term) { - uInt16 bufferOffset = 0x0, i = 0x0; - char character = 0x0; - /* Aquire spinlock for term */ - spinLock(&term->tty_spinLock); + unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; + spinLock(&tty_spinLock); /* We Need To Get The Y Position */ bufferOffset = term->tty_y; @@ -119,9 +97,7 @@ term->tty_pointer[bufferOffset++] = character; term->tty_pointer[bufferOffset++] = term->tty_colour; break; - } - - + } /* switch */ /* Check To See If We Are Out Of Bounds */ if (bufferOffset >= 160 * 25) { for (i = 0; i < 160 * 24; i++) { @@ -133,41 +109,18 @@ } bufferOffset -= 160; } - } - - /* Set Up new cursor position */ - bufferOffset >>= 1; + } + bufferOffset >>= 1; /* Set the new cursor position */ term->tty_x = (bufferOffset & 0xFF); term->tty_y = (bufferOffset >> 8); - - spinUnlock(&term->tty_spinLock); + spinUnlock(&tty_spinLock); + return(0x0); } tty_term *tty_find(uInt16 tty) { return(&terms[tty]); } - -int tty_backspace() { - uInt32 bufferOffset = 0x0; - - /* We Need To Get The Y Position */ - bufferOffset = tty_foreground->tty_y; - bufferOffset <<= 8; - - /* Then We Need To Add The X Position */ - bufferOffset += tty_foreground->tty_x; - bufferOffset <<= 1; - - tty_foreground->tty_pointer[bufferOffset--] = 0x20; - tty_foreground->tty_pointer[bufferOffset--] = tty_foreground->tty_colour; - tty_foreground->tty_pointer[bufferOffset] = 0x20; - - bufferOffset >>= 1; - tty_foreground->tty_x = (bufferOffset & 0xFF); - tty_foreground->tty_y = (bufferOffset >> 8); - return(0x0); - } /*** $Log$ diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index 9dd8d02..6c1e241 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -107,7 +107,7 @@ uInt32 enterTime = systemVitals->sysUptime+20; while (enterTime > systemVitals->sysUptime) { if (ubcond->locked == UNLOCKED) break; - sched_yield(); + schedYield(); } ubmutex->locked = UNLOCKED; return(0x0); diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index 5c7eb1f..34d4113 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -186,41 +186,49 @@ kpanic("Invalid Interrupt[%i]\n",_current->id); while (1); endTask(_current->id); + schedYield(); } void _int0() { kpanic("int0: Divide-by-Zero [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int1() { kpanic("int1: Debug exception [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int2() { kpanic("int2: unknown error [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int3() { kpanic("int3: Breakpoint [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int4(){ kpanic("int4: Overflow [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int5() { kpanic("int5: Bounds check [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int6() { kpanic("int6: Invalid opcode! [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int8() { @@ -244,21 +252,25 @@ void _int9() { kpanic("int9: Coprocessor Segment Overrun! [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int10() { kpanic("int10: Invalid TSS! [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int11() { kpanic("int11: Segment Not Present! [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int12() { kpanic("int12: Stack-Segment Fault! [%i]\n",_current->id); endTask(_current->id); + schedYield(); } void _int13() { diff --git a/src/sys/sys/video.c b/src/sys/sys/video.c index 8eac7b0..5fc9e66 100644 --- a/src/sys/sys/video.c +++ b/src/sys/sys/video.c @@ -60,7 +60,7 @@ kprint(char *string) { unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; - //spinLock(&videoSpinLock); + spinLock(&videoSpinLock); /* We Need To Get The Y Position */ outportByte(0x3D4, 0x0e); bufferOffset = inportByte(0x3D5); diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index b33e51f..b6839ba 100644 --- a/src/sys/vfs/file.c +++ b/src/sys/vfs/file.c @@ -49,7 +49,7 @@ fileDescriptor *tmpFd = 0x0; assert(fd); /* Search For File Descriptor */ - for (tmpFd = fdTable;tmpFd != 0x0;tmpFd = tmpFd->next) { + for (tmpFd=fdTable;tmpFd;tmpFd=tmpFd->next) { if (tmpFd == fd) { /* If Fd Is The First FD Then Reset fdTable */ if (tmpFd == fdTable) { @@ -59,15 +59,12 @@ } kfree(fd->buffer); kfree(fd); - if (systemVitals) - systemVitals->openFiles--; + systemVitals->openFiles--; return(1); } else { - if (tmpFd->prev) - tmpFd->prev->next = tmpFd->next; - if (tmpFd->next) - tmpFd->next->prev = tmpFd->prev; + tmpFd->prev->next = tmpFd->next; + tmpFd->next->prev = tmpFd->prev; kfree(fd->buffer); kfree(fd); systemVitals->openFiles--;