diff --git a/src/bin/init/main.c b/src/bin/init/main.c index dcca8f0..db777dd 100644 --- a/src/bin/init/main.c +++ b/src/bin/init/main.c @@ -39,6 +39,7 @@ mpi_message_t myMsg; + /* Create a mailbox for this task */ /* if (mpi_createMbox("init") != 0x0) { diff --git a/src/sys/i386/i386_exec.c b/src/sys/i386/i386_exec.c index 9ee9200..9db4cca 100644 --- a/src/sys/i386/i386_exec.c +++ b/src/sys/i386/i386_exec.c @@ -192,14 +192,12 @@ /* Now We Must Create A Virtual Space For This Proccess To Run In */ _current->tss.cr3 = (uInt32) vmm_createVirtualSpace( _current->id ); kprintf( "_current->tss.cr3: 0x%X", _current->tss.cr3 ); - /* To Better Load This Application We Will Switch Over To Its VM Space */ asm volatile( "movl %0,%%eax \n" "movl %%eax,%%cr3 \n" : : "d" ((uInt32 *)(_current->tss.cr3)) ); - /* Lets Find The File */ tmpFd = fopen( file, "r" ); diff --git a/src/sys/i386/sched.c b/src/sys/i386/sched.c index 2040883..ee51b81 100644 --- a/src/sys/i386/sched.c +++ b/src/sys/i386/sched.c @@ -86,7 +86,7 @@ kTask_t *tmpTask = 0x0; kTask_t *delTask = 0x0; - if ( !spinTryLock( &schedulerSpinLock ) ) + if ( spinTryLock( &schedulerSpinLock ) ) return; tmpTask = _current->next; diff --git a/src/sys/i386/spinlock.c b/src/sys/i386/spinlock.c index aab0c16..6670f72 100644 --- a/src/sys/i386/spinlock.c +++ b/src/sys/i386/spinlock.c @@ -173,14 +173,14 @@ } -void spinUnlock(spinLock_t *lock) { +void spinUnlock(spinLock_t lock) { barrier(); lock->locked = 0x0; } void spinLock(spinLock_t lock) { while (1) { - if (!xchg_32(lock->locked, LOCKED)) + if (!xchg_32(&lock->locked, LOCKED)) return; while (lock->locked == 1) sched_yield(); diff --git a/src/sys/i386/sys_call.S b/src/sys/i386/sys_call.S index 0257e90..72161e8 100644 --- a/src/sys/i386/sys_call.S +++ b/src/sys/i386/sys_call.S @@ -46,6 +46,7 @@ push %ds push %es push %fs +push %gs mov $0x10,%eax mov %eax,%ds mov %eax,%es @@ -75,6 +76,7 @@ hlt _popFS: +pop %gs pop %fs pop %es pop %ds diff --git a/src/sys/i386/sys_call_new.S b/src/sys/i386/sys_call_new.S index d5783c4..863fad2 100644 --- a/src/sys/i386/sys_call_new.S +++ b/src/sys/i386/sys_call_new.S @@ -39,6 +39,7 @@ pushl %ds pushl %es pushl %fs +pushl %gs /* switch to kernel segments */ movl $0x10,%eax @@ -52,6 +53,7 @@ //MEXITCOUNT //jmp doreti +popl %gs popl %fs popl %es popl %ds diff --git a/src/sys/include/net/arch/sys_arch.h b/src/sys/include/net/arch/sys_arch.h index 10d50a0..439894a 100644 --- a/src/sys/include/net/arch/sys_arch.h +++ b/src/sys/include/net/arch/sys_arch.h @@ -13,7 +13,7 @@ }; struct sys_sem { - int signaled; + uint32_t signaled; ubthread_cond_t cond; ubthread_mutex_t mutex; }; @@ -29,14 +29,20 @@ struct sys_mbox { uint32_t head; uint32_t tail; - ubthread_mutex_t lock; - uint32_t size; + //MrOlsen (2017-12-28) - This will break because size is passable + void *msgs[SYS_MBOX_SIZE]; + + //struct ubthread_mutex *lock; struct sys_sem *empty; struct sys_sem *full; + struct sys_sem *lock; - void **queue; + int wait_send; + + //void **queue; + //uint32_t size; }; typedef struct sys_mbox sys_mbox_t; diff --git a/src/sys/include/net/net.h b/src/sys/include/net/net.h index 513a077..ab7541b 100644 --- a/src/sys/include/net/net.h +++ b/src/sys/include/net/net.h @@ -26,6 +26,8 @@ #include +struct netif lnc_netif; + int net_init(); #endif diff --git a/src/sys/include/net/sys.h b/src/sys/include/net/sys.h index ada5b1e..8143ba1 100644 --- a/src/sys/include/net/sys.h +++ b/src/sys/include/net/sys.h @@ -132,13 +132,13 @@ * @param count initial count of the semaphore * @return ERR_OK if successful, another err_t otherwise */ -err_t sys_sem_new(sys_sem_t *sem, u8_t count); +err_t sys_sem_new(sys_sem_t **sem, u8_t count); /** * @ingroup sys_sem * Signals a semaphore * @param sem the semaphore to signal */ -void sys_sem_signal(sys_sem_t *sem); +void sys_sem_signal(struct sys_sem **s); /** * @ingroup sys_sem * Wait for a semaphore for the specified timeout @@ -147,13 +147,13 @@ * @return time (in milliseconds) waited for the semaphore * or SYS_ARCH_TIMEOUT on timeout */ -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout); +uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout); /** * @ingroup sys_sem * Delete a semaphore * @param sem semaphore to delete */ -void sys_sem_free(sys_sem_t *sem); +void sys_sem_free(sys_sem_t **sem); /** Wait for a semaphore - forever/no timeout */ #define sys_sem_wait(sem) sys_arch_sem_wait(sem, 0) #ifndef sys_sem_valid @@ -200,7 +200,7 @@ * @param size (minimum) number of messages in this mbox * @return ERR_OK if successful, another err_t otherwise */ -err_t sys_mbox_new(sys_mbox_t *mbox, int size); +err_t sys_mbox_new(struct sys_mbox **mb, int size); /** * @ingroup sys_mbox * Post a message to an mbox - may not fail @@ -208,14 +208,14 @@ * @param mbox mbox to posts the message * @param msg message to post (ATTENTION: can be NULL) */ -void sys_mbox_post(sys_mbox_t *mbox, void *msg); +void sys_mbox_post(struct sys_mbox **mb, void *msg); /** * @ingroup sys_mbox * Try to post a message to an mbox - may fail if full or ISR * @param mbox mbox to posts the message * @param msg message to post (ATTENTION: can be NULL) */ -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg); +err_t sys_mbox_trypost(struct sys_mbox **mb, void *msg); /** * @ingroup sys_mbox * Wait for a new message to arrive in the mbox @@ -226,7 +226,7 @@ or SYS_ARCH_TIMEOUT on timeout * The returned time has to be accurate to prevent timer jitter! */ -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout); +uint32_t sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, uint32_t timeout); /* Allow port to override with a macro, e.g. special timeout for sys_arch_mbox_fetch() */ #ifndef sys_arch_mbox_tryfetch /** @@ -237,7 +237,7 @@ * @return 0 (milliseconds) if a message has been received * or SYS_MBOX_EMPTY if the mailbox is empty */ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg); +uint32_t sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg); #endif /** * For now, we map straight to sys_arch implementation. @@ -248,7 +248,7 @@ * Delete an mbox * @param mbox mbox to delete */ -void sys_mbox_free(sys_mbox_t *mbox); +void sys_mbox_free(struct sys_mbox **mb); #define sys_mbox_fetch(mbox, msg) sys_arch_mbox_fetch(mbox, msg, 0) #ifndef sys_mbox_valid /** diff --git a/src/sys/include/sys/_types.h b/src/sys/include/sys/_types.h index 9606b4f..6cfd882 100644 --- a/src/sys/include/sys/_types.h +++ b/src/sys/include/sys/_types.h @@ -27,13 +27,13 @@ #ifndef __TYPES_H #define __TYPES_H -typedef __signed char __int8_t; -typedef unsigned char __uint8_t; -typedef short __int16_t; -typedef unsigned short __uint16_t; -typedef int __int32_t; -typedef unsigned int __uint32_t; -typedef long long __int64_t; +typedef char __int8_t; +typedef unsigned char __uint8_t; +typedef short __int16_t; +typedef unsigned short __uint16_t; +typedef int __int32_t; +typedef unsigned int __uint32_t; +typedef long long __int64_t; typedef unsigned long long __uint64_t; typedef unsigned long __clock_t; diff --git a/src/sys/include/sys/types.h b/src/sys/include/sys/types.h index 2dbbc2c..fd73945 100644 --- a/src/sys/include/sys/types.h +++ b/src/sys/include/sys/types.h @@ -43,9 +43,17 @@ typedef __uint64_t uint64_t; typedef __uint64_t uquad_t; +/* unsigned integrals (deprecated) */ +typedef __uint8_t u_int8_t; +typedef __uint16_t u_int16_t; +typedef __uint32_t u_int32_t; +typedef __uint64_t u_int64_t; +typedef __uint64_t u_quad_t; + +typedef __int64_t quad_t; typedef __int64_t daddr_t; /* disk address */ -typedef __uint32_t u_daddr_t; /* unsigned disk address */ +typedef __uint32_t u_daddr_t; /* unsigned disk address */ typedef unsigned char uInt8; typedef unsigned short uInt16; @@ -55,13 +63,6 @@ typedef short Int16; typedef long Int32; -typedef __uint8_t u_int8_t; /* unsigned integrals (deprecated) */ -typedef __uint16_t u_int16_t; -typedef __uint32_t uint32_t; -typedef __uint64_t u_int64_t; -//typedef long long int quad_t; -typedef __uint64_t quad_t; -//typedef __uint32_t quad_t; typedef unsigned char u_char; typedef unsigned short u_short; @@ -126,12 +127,10 @@ #define _TIME_T_DECLARED #endif -/* MrOlsen (2016-01-11) NOTE: Note sure if i need this in here but will for now */ typedef uint32_t uintmax_t; typedef int32_t intmax_t; typedef int32_t ptrdiff_t; typedef uint32_t uintptr_t; -typedef uint32_t u_quad_t; #define __ULONG_MAX 0xffffffffUL #define __USHRT_MAX 0xffff /* max value for an unsigned short */ diff --git a/src/sys/include/ubixos/spinlock.h b/src/sys/include/ubixos/spinlock.h index f446253..3cf8e5d 100644 --- a/src/sys/include/ubixos/spinlock.h +++ b/src/sys/include/ubixos/spinlock.h @@ -34,7 +34,7 @@ #define LOCKED 1 #define UNLOCKED 0 -#define SPIN_LOCK_INITIALIZER {NULL, 0} +#define SPIN_LOCK_INITIALIZER {NULL, 0} #define LLOCK_FLAG (void *)1 //typedef volatile int spinLock_t; @@ -51,7 +51,7 @@ void spinLockInit(spinLock_t); void spinUnlock(spinLock_t); int spinTryLock(spinLock_t); -void spinLock(spinLock_t *); +void spinLock(spinLock_t); void spinLock_scheduler(spinLock_t *); /* Only use this spinlock in the sched. */ diff --git a/src/sys/include/ubixos/ubthread.h b/src/sys/include/ubixos/ubthread.h index d86915a..44f22f8 100644 --- a/src/sys/include/ubixos/ubthread.h +++ b/src/sys/include/ubixos/ubthread.h @@ -89,5 +89,6 @@ int ubthread_cond_timedwait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime); int ubthread_cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex); int ubthread_cond_signal(ubthread_cond_t *cond); +int ubthread_cond_broadcast(ubthread_cond_t *cond); #endif diff --git a/src/sys/init/main.c b/src/sys/init/main.c index 9828773..5cfcaf0 100644 --- a/src/sys/init/main.c +++ b/src/sys/init/main.c @@ -144,7 +144,7 @@ execThread(systemTask, (uInt32) sysTask + 0x2000, 0x0); kprintf("Thread Start!\n"); - execFile("sys:/bin/init", 0x0, 0x0, 0x0); /* OS Initializer */ + // execFile("sys:/bin/init", 0x0, 0x0, 0x0); /* OS Initializer */ //execFile( "sys:/bin/login", 0x0, 0x0, 0x0 ); /* OS Initializer */ irqEnable(0x0); diff --git a/src/sys/isa/atkbd.c b/src/sys/isa/atkbd.c index 900c3b2..371621e 100644 --- a/src/sys/isa/atkbd.c +++ b/src/sys/isa/atkbd.c @@ -214,7 +214,7 @@ void keyboardHandler() { int key = 0x0; - if ( !spinTryLock( &atkbdSpinLock ) ) + if ( spinTryLock( &atkbdSpinLock ) ) return; key = atkbd_scan(); @@ -288,7 +288,7 @@ case 0x3: //if (tty_foreground != 0x0) // endTask(tty_foreground->owner); - K_PANIC( "CTRL-C pressed\n" ); + //K_PANIC( "CTRL-C pressed\n" ); kprintf( "FreePages: [0x%X]\n", systemVitals->freePages ); break; case 0x9: @@ -350,7 +350,7 @@ */ /* - if (!spinTryLock(&atkbdSpinLock)) + if (spinTryLock(&atkbdSpinLock)) return(0x0); */ diff --git a/src/sys/kernel/gen_calls.c b/src/sys/kernel/gen_calls.c index 4e14314..10c1949 100644 --- a/src/sys/kernel/gen_calls.c +++ b/src/sys/kernel/gen_calls.c @@ -172,7 +172,7 @@ /* MrOlsen 2016-01-18 */ int sys_invalid( struct thread *td, void *args ) { kprintf( "Invalid System Call #[%i]\n", td->frame->tf_eax ); -kpanic("PID: %i, File: %s, Line: %i", _current->id, __FILE__, __LINE__); +//kpanic("PID: %i, File: %s, Line: %i", _current->id, __FILE__, __LINE__); return (0); } diff --git a/src/sys/kernel/ubthread.c b/src/sys/kernel/ubthread.c index ef3329c..cc4fc27 100644 --- a/src/sys/kernel/ubthread.c +++ b/src/sys/kernel/ubthread.c @@ -159,3 +159,11 @@ sched_yield(); return (0x0); } + +int ubthread_cond_broadcast(ubthread_cond_t *cond) { + ubthread_cond_t ubcond = *cond; + while (xchg_32(&ubcond->lock, FALSE)) + sched_yield(); + return (0x0); +} + diff --git a/src/sys/net/net/init.c b/src/sys/net/net/init.c index 457305d..2ca2577 100644 --- a/src/sys/net/net/init.c +++ b/src/sys/net/net/init.c @@ -48,11 +48,10 @@ //void netMainThread(); //static void tcpip_init_done(void *arg); +struct netif lnc_netif; int net_init() { -return(0); ip_addr_t ipaddr, netmask, gw; - struct netif netif; tcpip_init(NULL, NULL); @@ -60,11 +59,11 @@ IP4_ADDR(&ipaddr, 10, 50, 0, 7); IP4_ADDR(&netmask, 255, 255, 0, 0); - netif_add(&netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); - netif_set_default(&netif); + netif_add(&lnc_netif, &ipaddr, &netmask, &gw, NULL, ethernetif_init, tcpip_input); + netif_set_default(&lnc_netif); //netif_set_default(netif_add(&ipaddr, &netmask, &gw, ethernetif_init, tcpip_input)); -// sys_thread_new("lncThread", (void *) lnc_thread, 0x0, 0x1000, 0x0); + sys_thread_new("lncThread", (void *) lnc_thread, 0x0, 0x1000, 0x0); return(0x0); } diff --git a/src/sys/net/net/sys_arch.c b/src/sys/net/net/sys_arch.c index 7ed19b0..74c878e 100644 --- a/src/sys/net/net/sys_arch.c +++ b/src/sys/net/net/sys_arch.c @@ -22,7 +22,8 @@ static struct spinLock netThreadSpinlock = SPIN_LOCK_INITIALIZER; static struct sys_thread *threads = 0x0; -static uint16_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint16_t timeout); +static uint32_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint32_t timeout); +static void sys_sem_free_internal(struct sys_sem *sem); /* sys_arch layer initializer */ void sys_init() { @@ -30,93 +31,89 @@ gettimeofday(&starttime, &tz); } -/* Create a new semaphore */ -err_t sys_sem_new(sys_sem_t *sem, uint8_t count) { - sem->signaled = count; +static struct sys_sem *sys_sem_new_internal(uint8_t count) { + struct sys_sem *sem; - ubthread_cond_init(&(sem->cond), NULL); - ubthread_mutex_init(&(sem->mutex), NULL); + sem = (struct sys_sem *)kmalloc(sizeof(struct sys_sem)); + if (sem != NULL) { + sem->signaled = count; + ubthread_cond_init(&(sem->cond), NULL); + ubthread_mutex_init(&(sem->mutex), NULL); + } + return sem; +} + +/* Create a new semaphore */ +err_t sys_sem_new(sys_sem_t **sem, uint8_t count) { + sys_sem_t *newSem = 0x0; + + newSem = kmalloc(sizeof(struct sys_sem)); + newSem->signaled = count; + ubthread_cond_init(&(newSem->cond), NULL); + ubthread_mutex_init(&(newSem->mutex), NULL); + + if (*sem != 0) + kpanic("UH OH!"); + + *sem = newSem; return (ERR_OK); } /* Deallocate semaphore */ -void sys_sem_free(sys_sem_t *sem) { - ubthread_cond_destroy(&(sem->cond)); - ubthread_mutex_destroy(&(sem->mutex)); - //MrOlsen maybe not here - kfree(sem); +void sys_sem_free(struct sys_sem **sem) { + if ((sem != NULL) && (*sem != SYS_SEM_NULL)) { + sys_sem_free_internal(*sem); + } } /* Signal semaphore */ -void sys_sem_signal(sys_sem_t *sem) { - kprintf("L1"); +void sys_sem_signal(struct sys_sem **s) { + struct sys_sem *sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; + ubthread_mutex_lock(&(sem->mutex)); + sem->signaled++; - sem->signaled++; - if (sem->signaled > 1) - sem->signaled = 1; + if (sem->signaled > 1) { + sem->signaled = 1; + } - //ubthread_cond_signal(&(sem->cond)); - ubthread_mutex_unlock(&(sem->mutex)); + ubthread_cond_broadcast(&(sem->cond)); + ubthread_mutex_unlock(&(sem->mutex)); } -uint32_t _sys_arch_sem_wait(struct sys_sem *sem, uint32_t timeout) { - uint32_t time = sys_now(); +static void sys_sem_free_internal(struct sys_sem *sem) { + ubthread_cond_destroy(&(sem->cond)); + ubthread_mutex_destroy(&(sem->mutex)); + kfree(sem); +} + +uint32_t sys_arch_sem_wait(struct sys_sem **s, uint32_t timeout) { + uint32_t time_needed = 0; + struct sys_sem *sem; + LWIP_ASSERT("invalid sem", (s != NULL) && (*s != NULL)); + sem = *s; ubthread_mutex_lock(&(sem->mutex)); - while (sem->signaled <= 0) { if (timeout > 0) { - time = cond_wait(&(sem->cond), &(sem->mutex), timeout); - time = 0; -//kprintf("%s:%i\n", __FILE__, __LINE__); - if (time == 0) { -//kprintf("%s:%i\n", __FILE__, __LINE__); + time_needed = cond_wait(&(sem->cond), &(sem->mutex), timeout); + + if (time_needed == SYS_ARCH_TIMEOUT) { ubthread_mutex_unlock(&(sem->mutex)); -//kprintf("%s:%i\n", __FILE__, __LINE__); - return(0); + return SYS_ARCH_TIMEOUT; } - } - else { -//kprintf("%s:%i\n", __FILE__, __LINE__); - time = cond_wait(&(sem->cond), &(sem->mutex), 0); - timeout = 1; -//kprintf("%s:%i\n", __FILE__, __LINE__); + /* ubthread_mutex_unlock(&(sem->mutex)); + return time_needed; */ + } else { + cond_wait(&(sem->cond), &(sem->mutex), 0); } } sem->signaled--; - //kprintf("L3"); - ubthread_mutex_lock(&(sem->mutex)); - kprintf("L3.1"); - return (sys_now() - time); -} - -uint32_t sys_arch_sem_wait(struct sys_sem *sem, uint32_t timeout) { - uint32_t time = sys_now(); - uint32_t ret = 0x0; - - if (sem->signaled > 0) { - ubthread_mutex_lock(&(sem->mutex)); - sem->signaled--; - ubthread_mutex_unlock(&(sem->mutex)); - return (ret); - } - - while (sem->signaled <= 0) { - if (timeout > 0) { - sched_yield(); - ret = sys_now() - time; - } - else { - sched_yield(); - ret = SYS_ARCH_TIMEOUT; - } - } - ubthread_mutex_lock(&(sem->mutex)); - sem->signaled--; ubthread_mutex_unlock(&(sem->mutex)); - return (ret); + return time_needed; } int sys_sem_valid(sys_sem_t *sem) { @@ -149,129 +146,207 @@ ubthread_mutex_unlock(&(mutex->mutex)) ; } -err_t sys_mbox_new(sys_mbox_t *mbox, int size) { +err_t sys_mbox_new(struct sys_mbox **mb, int size) { + struct sys_mbox *mbox = 0x0; LWIP_ASSERT("mbox null", mbox); - ubthread_mutex_init(mbox->lock, NULL); + //MrOlsen (2017-12-28) - lock is not a pointer + + mbox = (struct sys_mbox *)kmalloc(sizeof(struct sys_mbox)); + + if (mbox == NULL) + return(ERR_MEM); + mbox->head = 0; mbox->tail = 0; - mbox->size = size; + mbox->wait_send = 0; + //mbox->size = size; - sys_sem_new(mbox->empty, size); - sys_sem_new(mbox->full, 0); + //Pass By Reference It's a Pointer + //ubthread_mutex_init(&mbox->lock, NULL); - mbox->queue = kmalloc(sizeof(void *) * size);//calloc(size, sizeof(void *)); + //Pass By Reference It's a Pointer + sys_sem_new(&mbox->lock, 1); + sys_sem_new(&mbox->empty, 0); + sys_sem_new(&mbox->full, 0); - if (!mbox->queue) { - kprintf("WTF: [%i]", size); - return ERR_MEM; - } + //mbox->queue = kmalloc(sizeof(void *) * size);//calloc(size, sizeof(void *)); + + //if (!mbox->queue) { + // kprintf("WTF: [%i]", size); + // return ERR_MEM; + //} return (ERR_OK); } -void sys_mbox_free(sys_mbox_t *mbox) { - kfree(mbox->queue); - mbox->queue = NULL; +void sys_mbox_free(struct sys_mbox **mb) { + if ((mb != NULL) && (*mb != SYS_MBOX_NULL)) { + struct sys_mbox *mbox = *mb; + sys_arch_sem_wait(&mbox->lock, 0); + + sys_sem_free_internal(mbox->full); + sys_sem_free_internal(mbox->empty); + sys_sem_free_internal(mbox->lock); + mbox->full = mbox->empty = mbox->lock = NULL; + kfree(mbox); + } + //kfree(mbox->queue); + //mbox->queue = NULL; } -void sys_mbox_post(sys_mbox_t * mbox, void *msg) { - sys_arch_sem_wait(&(mbox->empty), 0); - kprintf("L5"); - ubthread_mutex_lock(&mbox->lock); +void sys_mbox_post(struct sys_mbox **mb, void *msg) { + uint8_t head; + struct sys_mbox *mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; - mbox->queue[mbox->head] = msg; - mbox->head = (mbox->head + 1) % mbox->size; + sys_arch_sem_wait(&mbox->lock, 0); - ubthread_mutex_unlock(&mbox->lock); - //sem_post(&mbox->full); - sys_sem_signal(&(mbox->full)); -} + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_post: mbox %p msg %p\n", (void *)mbox, (void *)msg)); -err_t sys_mbox_trypost(sys_mbox_t * mbox, void *msg) { -uint32_t res; - -kprintf("%s:%i\n", __FILE__, __LINE__); -/* SHOULD BE TRY WAIT */ -res = sys_arch_sem_wait(&mbox->empty, 0x0); -kprintf("%s:%i\n", __FILE__, __LINE__); -if (res == ERR_NOT_READY) -return ERR_TIMEOUT; -kprintf("%s:%i\n", __FILE__, __LINE__); - - kprintf("L6"); -ubthread_mutex_lock(&mbox->lock); - -mbox->queue[mbox->head] = msg; -mbox->head = (mbox->head + 1) % mbox->size; - -ubthread_mutex_unlock(&mbox->lock); -sys_sem_signal(&(mbox->full)); -//sem_post(&mbox->full); - -return ERR_OK; -} - -uint32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, uint32_t timeout) { - - //status_t res; - uint32_t res; - - //lk_time_t start = current_time(); - - uint32_t start = sys_now(); - kprintf("Timeout1: %i]", timeout); - res = sys_arch_sem_wait(&(mbox->full), timeout ? timeout : INFINITE_TIME); - kprintf("Timeout2: %i]", timeout); - //res = sem_timedwait(&mbox->full, timeout ? timeout : INFINITE_TIME); - if (res == ERR_TIMED_OUT) { - //LTRACE_EXIT; - return SYS_ARCH_TIMEOUT; //timeout ? SYS_ARCH_TIMEOUT : 0; + while ((mbox->tail + 1) >= (mbox->head + SYS_MBOX_SIZE)) { + mbox->wait_send++; + sys_sem_signal(&mbox->lock); + sys_arch_sem_wait(&mbox->empty, 0); + sys_arch_sem_wait(&mbox->lock, 0); + mbox->wait_send--; } - kprintf("L7"); - ubthread_mutex_lock(&mbox->lock); + mbox->msgs[mbox->tail % SYS_MBOX_SIZE] = msg; - *msg = mbox->queue[mbox->tail]; - mbox->tail = (mbox->tail + 1) % mbox->size; + if (mbox->tail == mbox->head) { + head = 1; + } else { + head = 0; + } - ubthread_mutex_unlock(&mbox->lock); - sys_sem_signal(&(mbox->empty)); - //sem_post(&mbox->empty); + mbox->tail++; - return sys_now() - start; + if (head) { + sys_sem_signal(&mbox->full); + } + + sys_sem_signal(&mbox->lock); } -uint32_t sys_arch_mbox_tryfetch(sys_mbox_t * mbox, void **msg) { -//LTRACE_ENTRY; +err_t sys_mbox_trypost(struct sys_mbox **mb, void *msg) { + uint8_t head; + struct sys_mbox *mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; -//status_t res; - uint32_t res; + sys_arch_sem_wait(&mbox->lock, 0); -res = sys_arch_sem_wait(&(mbox->full), 0x0); -//res = sem_trywait(&mbox->full); -if (res == ERR_NOT_READY) { -//LTRACE_EXIT; -return SYS_MBOX_EMPTY; + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_trypost: mbox %p msg %p\n", + (void *)mbox, (void *)msg)); + + if ((mbox->tail + 1) >= (mbox->head + SYS_MBOX_SIZE)) { + sys_sem_signal(&mbox->lock); + return ERR_MEM; + } + + mbox->msgs[mbox->tail % SYS_MBOX_SIZE] = msg; + + if (mbox->tail == mbox->head) { + head = 1; + } else { + head = 0; + } + + mbox->tail++; + + if (head) { + sys_sem_signal(&mbox->full); + } + + sys_sem_signal(&mbox->lock); + + return ERR_OK; } - kprintf("L8"); -ubthread_mutex_lock(&mbox->lock); +uint32_t sys_arch_mbox_fetch(struct sys_mbox **mb, void **msg, uint32_t timeout) { + uint32_t time_needed = 0; + struct sys_mbox *mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; -*msg = mbox->queue[mbox->tail]; -mbox->tail = (mbox->tail + 1) % mbox->size; + /* The mutex lock is quick so we don't bother with the timeout + stuff here. */ + sys_arch_sem_wait(&mbox->lock, 0); -ubthread_mutex_unlock(&mbox->lock); -sys_sem_signal(&(mbox->empty)); -//sem_post(&mbox->empty); + while (mbox->head == mbox->tail) { + sys_sem_signal(&mbox->lock); -//LTRACE_EXIT; -return 0; + /* We block while waiting for a mail to arrive in the mailbox. We + must be prepared to timeout. */ + if (timeout != 0) { + time_needed = sys_arch_sem_wait(&mbox->full, timeout); + + if (time_needed == SYS_ARCH_TIMEOUT) { + return SYS_ARCH_TIMEOUT; + } + } else { + sys_arch_sem_wait(&mbox->full, 0); + } + + sys_arch_sem_wait(&mbox->lock, 0); + } + + if (msg != NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p msg %p\n", (void *)mbox, *msg)); + *msg = mbox->msgs[mbox->head % SYS_MBOX_SIZE]; + } + else{ + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_fetch: mbox %p, null msg\n", (void *)mbox)); + } + + mbox->head++; + + if (mbox->wait_send) { + sys_sem_signal(&mbox->empty); + } + + sys_sem_signal(&mbox->lock); + + return time_needed; +} + +uint32_t sys_arch_mbox_tryfetch(struct sys_mbox **mb, void **msg) { + struct sys_mbox *mbox; + LWIP_ASSERT("invalid mbox", (mb != NULL) && (*mb != NULL)); + mbox = *mb; + + sys_arch_sem_wait(&mbox->lock, 0); + + if (mbox->head == mbox->tail) { + sys_sem_signal(&mbox->lock); + return SYS_MBOX_EMPTY; + } + + if (msg != NULL) { + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p msg %p\n", (void *)mbox, *msg)); + *msg = mbox->msgs[mbox->head % SYS_MBOX_SIZE]; + } + else{ + LWIP_DEBUGF(SYS_DEBUG, ("sys_mbox_tryfetch: mbox %p, null msg\n", (void *)mbox)); + } + + mbox->head++; + + if (mbox->wait_send) { + sys_sem_signal(&mbox->empty); + } + + sys_sem_signal(&mbox->lock); + + return 0; } int sys_mbox_valid(sys_mbox_t *mbox) { - return mbox->queue != NULL; + return(0x0); + //return mbox->queue != NULL; } void sys_mbox_set_invalid(sys_mbox_t *mbox) { @@ -323,7 +398,7 @@ }; -static uint16_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint16_t timeout) { +static uint32_t cond_wait(ubthread_cond_t *cond, ubthread_mutex_t *mutex, uint32_t timeout) { unsigned int tdiff; unsigned long sec, usec; struct timeval rtime1, rtime2; @@ -409,114 +484,3 @@ uint32_t sys_now() { return (sys_unix_now()); } - -#ifdef _BALLS - -#define UMAX(a, b) ((a) > (b) ? (a) : (b)) - -struct sys_mbox_msg { - struct sys_mbox_msg *next; - void *msg; -}; - -struct sys_mbox *sys_mbox_new_BALLS() { - struct sys_mbox *mbox; - - mbox = kmalloc(sizeof(struct sys_mbox)); - memset(mbox, 0x0, sizeof(struct sys_mbox)); - mbox->first = mbox->last = 0; - mbox->mail = sys_sem_new_(0); - mbox->mutex = sys_sem_new_(1); - - return (mbox); -} - -uint32_t sys_arch_mbox_fetch_BALLS(struct sys_mbox *mbox, void **msg, uint32_t timeout) { - uint16_t time = 1; - - /* The mutex lock is quick so we don't bother with the timeout - stuff here. */ - //kprintf("sem wait0"); - sys_arch_sem_wait(mbox->mutex, 0); - //kprintf("sem wait1"); - - while (mbox->first == mbox->last) { - //kprintf("sem wait2"); - sys_sem_signal(mbox->mutex); - //kprintf("sem wait3"); - - /* We block while waiting for a mail to arrive in the mailbox. We - must be prepared to timeout. */ - if (timeout != 0) { - // kprintf("sem wait4"); - time = sys_arch_sem_wait(mbox->mail, timeout); - //kprintf("sem wait5"); - - /* If time == 0, the sem_wait timed out, and we return 0. */ - if (time == 0) { - return 0; - } - } - else { - //kprintf("sem wait6"); - sys_arch_sem_wait(mbox->mail, 0); - //kprintf("sem wait7"); - } - - //kprintf("sem wait8"); - sys_arch_sem_wait(mbox->mutex, 0); - // kprintf("sem wait9"); - } - //kprintf("sem wait10"); - - if (msg != NULL) { - //kprintf("sys_mbox_fetch: mbox %p msg %p\n", mbox, *msg); - *msg = mbox->msgs[mbox->first]; - } - - mbox->first++; - if (mbox->first == SYS_MBOX_SIZE) { - mbox->first = 0; - } - - sys_sem_signal(mbox->mutex); - - return (time); -} - -void sys_mbox_free_BALLS(struct sys_mbox *mbox) { - if (mbox != SYS_MBOX_NULL) { - sys_sem_wait(mbox->mutex); - sys_sem_free_(mbox->mail); - sys_sem_free_(mbox->mutex); - mbox->mail = mbox->mutex = NULL; - kfree(mbox); - } -} - -void sys_mbox_post_BALLS(struct sys_mbox *mbox, void *msg) { - uInt8 first; - - sys_sem_wait(mbox->mutex); - - //kprintf("sys_mbox_post: mbox %p msg %p\n", mbox, msg); - - mbox->msgs[mbox->last] = msg; - - if (mbox->last == mbox->first) - first = 1; - else - first = 0; - - mbox->last++; - - if (mbox->last == SYS_MBOX_SIZE) - mbox->last = 0; - - if (first) - sys_sem_signal(mbox->mail); - - sys_sem_signal(mbox->mutex); -} - -#endif diff --git a/src/sys/pci/lnc.c b/src/sys/pci/lnc.c index 2f0ddf4..eafeb3a 100644 --- a/src/sys/pci/lnc.c +++ b/src/sys/pci/lnc.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -248,8 +249,8 @@ void lnc_INT() { uint16_t csr0 = 0x0; - kprintf("\nINTR\n"); -// while ((csr0 = lnc_readCSR32(lnc, CSR0)) & INTR) { + //kprintf("\nINTR\n"); + //while ((csr0 = lnc_readCSR32(lnc, CSR0)) & INTR) { //kprintf("CSR0: [0x%X]\n", csr0); if (csr0 & ERR) { kprintf("Error: [0x%X]\n", csr0); @@ -293,7 +294,7 @@ tmpBuf->buffer = (void *)(lnc->rxBuffer + (lnc->rxPtr * lnc->bufferSize)); //(char *)kmalloc(length); // kprintf("RINT2\n"); - //ethernetif_input(netif_default); + ethernetif_input(&lnc_netif); //kprintf("RINT3\n"); //kprintf("RINT-LOOP[%i][0x%X][0x%X]", lnc->rxPtr,lnc->rxRing[lnc->rxPtr].md[1],plen); lnc->rxRing[lnc->rxPtr].md[1] = 0x80; diff --git a/src/sys/vmm/paging.c b/src/sys/vmm/paging.c index f203bf1..80292c0 100644 --- a/src/sys/vmm/paging.c +++ b/src/sys/vmm/paging.c @@ -206,7 +206,7 @@ destPageDirectoryIndex = PD_INDEX(dest); if ((pageDir[destPageDirectoryIndex] & PAGE_PRESENT) != PAGE_PRESENT) { - kprintf("Page Not Present: 0x%X, Source: 0x%X, Dest: 0x%X, dPDI: 0x%X\n", dest, source, dest, destPageDirectoryIndex); + //kprintf("Page Not Present: 0x%X, Source: 0x%X, Dest: 0x%X, dPDI: 0x%X\n", dest, source, dest, destPageDirectoryIndex); /* If Page Table Is Non Existant Then Set It Up */ /* UBU Why does the page table need to be user writable? */ pageDir[destPageDirectoryIndex] = (uint32_t) vmm_findFreePage(_current->id) | PAGE_DEFAULT;