diff --git a/src/sys/include/ubixos/sched.h b/src/sys/include/ubixos/sched.h index 5a20525..d3b7e76 100644 --- a/src/sys/include/ubixos/sched.h +++ b/src/sys/include/ubixos/sched.h @@ -30,10 +30,6 @@ #ifndef _SCHED_H #define _SCHED_H -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -41,7 +37,7 @@ #include -typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4 } tState; +typedef enum { PLACEHOLDER=-2,DEAD=-1,NEW=0,READY=1,RUNNING=2,IDLE=3,FORK=4,WAIT=5 } tState; struct osInfo { uInt8 timer; @@ -69,6 +65,7 @@ uInt16 nice; uInt32 timeSlice; tty_term *term; + pidType parent; } kTask_t; typedef struct prioQueue { @@ -84,9 +81,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); @@ -95,14 +92,14 @@ extern kTask_t *_current; extern kTask_t *_usedMath; -#ifdef __cplusplus -} -#endif - #endif /*** $Log$ + Revision 1.16 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.15 2004/07/29 21:32:16 reddawg My quick lunchs breaks worth of updates.... diff --git a/src/sys/include/ubixos/tty.h b/src/sys/include/ubixos/tty.h index 0e26265..3090fd6 100644 --- a/src/sys/include/ubixos/tty.h +++ b/src/sys/include/ubixos/tty.h @@ -31,27 +31,37 @@ #define _TTY_H #include +#include #define TTY_MAX_TERMS 5 typedef struct tty_termNode { - char *tty_buffer; - char *tty_pointer; - uInt8 tty_colour; - uInt16 current; - uInt16 tty_x; - uInt16 tty_y; + spinLock_t tty_spinLock; + char *tty_buffer; + char *tty_pointer; + uInt8 tty_colour; + uInt8 tty_stdin; + uInt16 tty_x; + uInt16 tty_y; + pidType pid; } tty_term; int tty_init(); -int tty_chang(uInt16); +int tty_change(uInt16); tty_term *tty_find(uInt16); int tty_print(char *,tty_term *); +int tty_backspace(); + +extern tty_term *tty_foreground; #endif /*** $Log$ + Revision 1.2 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.1 2004/08/03 21:44:24 reddawg ttys diff --git a/src/sys/isa/atkbd.c b/src/sys/isa/atkbd.c index a89ef50..41200ce 100644 --- a/src/sys/isa/atkbd.c +++ b/src/sys/isa/atkbd.c @@ -39,6 +39,7 @@ #include #include #include +#include #include static unsigned int keyMap = 0x0; @@ -247,13 +248,13 @@ if (((uInt)(keyboardMap[key][keyMap]) > 0) && ((uInt32)(keyboardMap[key][keyMap]) < 0xFF)) { switch ((uInt32)keyboardMap[key][keyMap]) { case 8: - backSpace(); + tty_backspace(); stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; stdinSize++; break; case 0x3: //endTask(_current->id); - //kprintf("CTRL-C pressed\n"); + //kprintf("CTRL-Cpressed\n"); break; default: stdinBuffer[stdinSize] = keyboardMap[key][keyMap]; @@ -264,8 +265,8 @@ else { switch ((keyboardMap[key][keyMap] >> 8)) { case 0x30: - tty_change(keyboardMap[key][keyMap] & 0xFF); - //kprintf("Changing Consoles[0x%X:0x%X]\n",_current->id,_current); + if ((tty_change(keyboardMap[key][keyMap] & 0xFF)) != 0x0) + kpanic("tty_change: Failed, File: %s, Line: %i\n",__FILE__,__LINE__); break; default: break; @@ -288,7 +289,9 @@ uInt8 retKey = 0x0; uInt32 i = 0x0; - while (stdinSize == 0); + if (stdinSize == 0x0) + return(0x0); + retKey = stdinBuffer[0]; stdinSize--; @@ -301,6 +304,9 @@ /*** $Log$ + Revision 1.19 2004/08/03 18:31:19 reddawg + virtual terms + Revision 1.18 2004/07/29 21:32:16 reddawg My quick lunchs breaks worth of updates.... diff --git a/src/sys/kernel/endtask.c b/src/sys/kernel/endtask.c index f16971a..b0c3091 100644 --- a/src/sys/kernel/endtask.c +++ b/src/sys/kernel/endtask.c @@ -47,13 +47,17 @@ if (_current->imageFd) fclose(_current->imageFd); //kprintf("FreePage: [0x%X]\n",systemVitals->freePages); + _current->term->pid = _current->parent; sched_setStatus(_current->id,DEAD); - schedYield(); + sched_yield(); return; } /*** $Log$ + Revision 1.12 2004/08/03 18:31:19 reddawg + virtual terms + Revision 1.11 2004/07/28 15:05:43 reddawg Major: Pages now have strict security enforcement. diff --git a/src/sys/kernel/exec.c b/src/sys/kernel/exec.c index a987a48..05faba4 100644 --- a/src/sys/kernel/exec.c +++ b/src/sys/kernel/exec.c @@ -137,9 +137,11 @@ /* Get A New Task For This Proccess */ _current = schedNewTask(); assert(_current); - _current->gid = 0x0; - _current->uid = 0x0; - _current->term = tty_find(console); + _current->gid = 0x0; + _current->uid = 0x0; + _current->term = tty_find(console); + _current->term->pid = _current->id; + if (_current->term == 0x0) kpanic("Error: invalid console\n"); @@ -420,6 +422,10 @@ /*** $Log$ + Revision 1.58 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.57 2004/08/02 17:38:24 reddawg Cleaned up self inflicted bug that messed up argc,argv diff --git a/src/sys/kernel/file.c b/src/sys/kernel/file.c index fba322b..a5ccd12 100644 --- a/src/sys/kernel/file.c +++ b/src/sys/kernel/file.c @@ -206,21 +206,34 @@ } void sysFgetc(int *ptr,userFileDescriptor *userFd) { - fileDescriptor *tmpFd = 0x0; - asm("sti"); - tmpFd = userFd->fd; if (userFd->fd == 0x0) { - /* - while (_current->term->current == 0x0) - schedYield(); - */ - if (_current->term->current == 0x0) - ptr[0] = '\0'; - else - ptr[0] = (int) getch(); + 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"); + } } else { - ptr[0] = (int) fgetc(tmpFd); + *ptr = (int) fgetc(userFd->fd); } } @@ -280,6 +293,10 @@ /*** $Log$ + Revision 1.11 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.10 2004/07/28 17:07:25 reddawg MPI: moved the syscalls diff --git a/src/sys/kernel/fork.c b/src/sys/kernel/fork.c index 3539d36..d508627 100644 --- a/src/sys/kernel/fork.c +++ b/src/sys/kernel/fork.c @@ -74,6 +74,8 @@ 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; @@ -113,6 +115,10 @@ /*** $Log$ + Revision 1.19 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.18 2004/08/02 18:50:13 reddawg Updates to make some variable volatile to make work with gcc 3.3. However there are still some issues but we have not caused new issues with gcc 2.95 diff --git a/src/sys/kernel/sched.c b/src/sys/kernel/sched.c index 6eb73cf..3d2b73a 100644 --- a/src/sys/kernel/sched.c +++ b/src/sys/kernel/sched.c @@ -141,27 +141,17 @@ 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) { + if (tmpTask->state > 0x0 && tmpTask->state != WAIT) { _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 */ @@ -172,12 +162,11 @@ /* Setting the timeslice this task is allowed to run */ systemVitals->quantum = _current->timeSlice; - - - if (_current->state > 0x0) { + + if (_current->state > 0x0 && _current->state != WAIT) { 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); @@ -185,6 +174,11 @@ ubixGDT[4].descriptor.access = '\x89'; asm("ljmp $0x20,$0\n"); } + else { + kprintf("FOOK WE BROKE!!!\n"); + goto schedStart; + } + return; } @@ -289,7 +283,7 @@ void schedEndTask(pidType pid) { endTask(_current->id); - schedYield(); + sched_yield(); } /************************************************************************ @@ -304,7 +298,7 @@ ************************************************************************/ void -schedYield() { +sched_yield() { sched(); } @@ -327,6 +321,9 @@ /*** $Log$ + Revision 1.26 2004/08/02 18:50:13 reddawg + Updates to make some variable volatile to make work with gcc 3.3. However there are still some issues but we have not caused new issues with gcc 2.95 + Revision 1.25 2004/08/01 20:24:51 reddawg Fixens diff --git a/src/sys/kernel/syscall.c b/src/sys/kernel/syscall.c index 3d24fbc..41780b5 100644 --- a/src/sys/kernel/syscall.c +++ b/src/sys/kernel/syscall.c @@ -160,7 +160,7 @@ } void sysSchedYield() { - schedYield(); + sched_yield(); } void sysStartSDE() { @@ -177,6 +177,9 @@ /*** $Log$ + Revision 1.24 2004/07/28 17:07:25 reddawg + MPI: moved the syscalls + Revision 1.23 2004/07/28 15:05:43 reddawg Major: Pages now have strict security enforcement. diff --git a/src/sys/kernel/systemtask.c b/src/sys/kernel/systemtask.c index 24810a2..ca15a3a 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"); - schedYield(); + sched_yield(); } kprintf("Rebooting NOW!!!\n"); while(inportByte(0x64) & 0x02); @@ -85,13 +85,16 @@ break; } } - schedYield(); + sched_yield(); } return; } /*** $Log$ + Revision 1.8 2004/07/28 17:07:25 reddawg + MPI: moved the syscalls + Revision 1.7 2004/07/20 22:29:55 reddawg assert: remade assert diff --git a/src/sys/kernel/tty.c b/src/sys/kernel/tty.c index 67907a2..5a169cb 100644 --- a/src/sys/kernel/tty.c +++ b/src/sys/kernel/tty.c @@ -34,9 +34,8 @@ #include #include -static tty_term *terms = 0x0; -static uInt16 tty_current = 0x0; -static spinLock_t tty_spinLock = SPIN_LOCK_INITIALIZER; +static tty_term *terms = 0x0; +tty_term *tty_foreground = 0x0; int tty_init() { int i = 0x0; @@ -47,38 +46,61 @@ if (terms == 0x0) kpanic("tty_init: Failed to allocate memory\n"); - for (i = 0;i < TTY_MAX_TERMS;i++) { + for (i = 0x0;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].current = 0x0; - terms[i].tty_colour = 0x0A + i; + 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[0].tty_pointer = (char *)0xB8000; - terms[0].current = 0x1; + + tty_foreground = &terms[0x0]; + tty_foreground->tty_stdin = 0x1; kprintf("tty0 - Initialized\n"); return(0x0); } int tty_change(uInt16 tty) { - 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; + + /* Copy text buffer to tty buffer */ + memcpy(tty_foreground->tty_buffer,(char *)0xB8000,(80*60*2)); + /* Copy tty buffer to text buffer */ + memcpy((char *)0xB8000,terms[tty].tty_buffer,(80*60*2)); + + /* + 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].current = 0x1; - tty_current = tty; + 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 */ return(0x0); } int tty_print(char *string,tty_term *term) { - unsigned int bufferOffset = 0x0, character = 0x0, i = 0x0; - spinLock(&tty_spinLock); + uInt16 bufferOffset = 0x0, i = 0x0; + char character = 0x0; + /* Aquire spinlock for term */ + spinLock(&term->tty_spinLock); /* We Need To Get The Y Position */ bufferOffset = term->tty_y; @@ -97,7 +119,9 @@ 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++) { @@ -109,21 +133,48 @@ } bufferOffset -= 160; } - } - bufferOffset >>= 1; /* Set the new cursor position */ + } + + /* Set Up new cursor position */ + bufferOffset >>= 1; term->tty_x = (bufferOffset & 0xFF); term->tty_y = (bufferOffset >> 8); - spinUnlock(&tty_spinLock); - + + spinUnlock(&term->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$ + Revision 1.2 2004/08/04 08:17:57 reddawg + tty: we have primative ttys try f1-f5 so it is easier to use and debug + ubixos + Revision 1.1 2004/08/03 21:44:24 reddawg ttys diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index fadc2c4..9dd8d02 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; - schedYield(); + sched_yield(); } ubmutex->locked = UNLOCKED; return(0x0); @@ -129,6 +129,9 @@ /*** $Log$ + Revision 1.7 2004/07/28 22:23:02 reddawg + make sure it still works before I goto bed + Revision 1.6 2004/06/15 12:24:07 reddawg Cleaned Up diff --git a/src/sys/sys/idt.c b/src/sys/sys/idt.c index fa99ad9..5c7eb1f 100644 --- a/src/sys/sys/idt.c +++ b/src/sys/sys/idt.c @@ -186,49 +186,41 @@ 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() { @@ -252,25 +244,21 @@ 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() { @@ -457,6 +445,9 @@ /*** $Log$ + Revision 1.27 2004/08/01 17:50:46 reddawg + Fixens + Revision 1.26 2004/07/31 21:52:17 reddawg a few changes diff --git a/src/sys/sys/video.c b/src/sys/sys/video.c index 24bf91c..8eac7b0 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); @@ -117,6 +117,9 @@ /*** $Log$ + Revision 1.7 2004/07/22 18:46:16 reddawg + Fixed up exec.c + Revision 1.6 2004/07/19 01:40:55 reddawg video: added spinLock protection diff --git a/src/sys/vfs/file.c b/src/sys/vfs/file.c index a63f4bb..b33e51f 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;tmpFd=tmpFd->next) { + for (tmpFd = fdTable;tmpFd != 0x0;tmpFd = tmpFd->next) { if (tmpFd == fd) { /* If Fd Is The First FD Then Reset fdTable */ if (tmpFd == fdTable) { @@ -59,12 +59,15 @@ } kfree(fd->buffer); kfree(fd); - systemVitals->openFiles--; + if (systemVitals) + systemVitals->openFiles--; return(1); } else { - tmpFd->prev->next = tmpFd->next; - tmpFd->next->prev = tmpFd->prev; + if (tmpFd->prev) + tmpFd->prev->next = tmpFd->next; + if (tmpFd->next) + tmpFd->next->prev = tmpFd->prev; kfree(fd->buffer); kfree(fd); systemVitals->openFiles--; @@ -266,6 +269,12 @@ /*** $Log$ + Revision 1.16 2004/07/28 15:05:43 reddawg + Major: + Pages now have strict security enforcement. + Many null dereferences have been resolved. + When apps loaded permissions set for pages rw and ro + Revision 1.15 2004/07/27 19:24:31 flameshadow chg: reduced the number of debugging statements in the kernel.