Changeset 2085 for Whitix/branches

Show
Ignore:
Timestamp:
05/20/10 16:05:25 (2 years ago)
Author:
mwhitworth
Message:

Add to TCP/IP stack.

Location:
Whitix/branches/netchannel
Files:
27 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/netchannel/arch/i386/kernel/idtstubs.S

    r559 r2085  
    217217int $0x30 
    218218endi386ExitThread: 
     219 
     220.globl i386RetFromEvent 
     221.globl endi386RetFromEvent 
     222 
     223i386RetFromEvent: 
     224mov $64, %eax /* SysEventReturn syscall number */ 
     225xor %ecx, %ecx 
     226lea (%esp), %edx 
     227int $0x30 
     228endi386RetFromEvent: 
  • Whitix/branches/netchannel/arch/i386/kernel/ints.c

    r2084 r2085  
    268268} 
    269269 
     270void IrqDoEvent(struct Context* curr) 
     271{ 
     272        if (curr->cs != 0x08) 
     273        { 
     274                PreemptDisable(); 
     275 
     276                DWORD* esp; 
     277 
     278                currThread->oldEip = curr->eip; 
     279                currThread->esp3 = curr->esp3; 
     280                curr->esp3 = currThread->eventStack; 
     281                curr->eip = (DWORD)currThread->eventFunc; 
     282 
     283                /* Push onto stack */ 
     284                esp = (DWORD*)curr->esp3; 
     285 
     286                extern DWORD retFromEvent; 
     287                *--esp = (DWORD)currThread->eventData; 
     288                *--esp = retFromEvent; 
     289 
     290                curr->esp3 = (DWORD)esp; 
     291                currThread->eventFunc = NULL; 
     292                currThread->eventData = NULL; 
     293                 
     294                PreemptFastEnable(); 
     295        } 
     296} 
     297 
    270298/*********************************************************************** 
    271299 * 
     
    284312        DWORD irq=curr.irq; 
    285313 
     314        /* FIXME: Unreliable, since we can be interrupted. */ 
    286315        if (currThread) 
    287316                currThread->currContext=&curr; 
     
    298327 
    299328                case 0x30: 
    300                         curr.eax=IrqSysCall(curr.eax,curr.edx,curr.ecx); 
     329                        curr.eax = IrqSysCall(curr.eax,curr.edx,curr.ecx); 
    301330                        break; 
    302331 
     
    307336        if (thrNeedSchedule && PreemptCanSchedule()) 
    308337                ThrSchedule(); 
    309 } 
    310  
     338 
     339        if (currThread && (currThread->flags & THR_NEED_RESTORE)) 
     340        { 
     341                curr.eip = currThread->oldEip; 
     342                curr.esp3 = currThread->esp3; 
     343                currThread->flags &= ~(THR_NEED_RESTORE); 
     344        } 
     345 
     346        if (currThread && currThread->eventFunc) 
     347                IrqDoEvent(&curr); 
     348} 
     349 
  • Whitix/branches/netchannel/arch/i386/kernel/process.c

    r2084 r2085  
    3333void i386ExitThread(); 
    3434void endi386ExitThread(); 
     35void i386RetFromEvent(); 
     36void endi386RetFromEvent(); 
     37 
    3538DWORD exitCode=0xF8000000; 
     39DWORD retFromEvent; 
    3640 
    3741struct TSS* tss=(struct TSS*)(TSS_ADDR); 
     
    5660int ThrArchInit() 
    5761{ 
     62        int exitCodeSz = (DWORD)endi386ExitThread-(DWORD)i386ExitThread; 
     63        int retEventSz = (DWORD)endi386RetFromEvent - (DWORD)i386RetFromEvent; 
     64 
    5865        /* Setup up the TSS, only needed for ss0 and esp0 */ 
    5966        tss->bitmap=0x8000; /* Bitmap offset. Past limit, so every IO instruction in userspace will produce a GPF. */ 
     
    6471        /* Copy the exit code over to a user accessable page of memory. Add procesor-specific syscall method code into the page soon. */ 
    6572        VirtMemMapPage(0xF8000000, PageAlloc()->physAddr, PAGE_PRESENT | PAGE_RW | PAGE_USER); 
    66         memcpy((void*)exitCode, i386ExitThread, (DWORD)endi386ExitThread-(DWORD)i386ExitThread); 
     73        memcpy((void*)exitCode, i386ExitThread, exitCodeSz); 
     74        memcpy((void*)(exitCode + exitCodeSz), i386RetFromEvent, retEventSz); 
     75 
     76        retFromEvent = (DWORD)(exitCode + exitCodeSz); 
    6777 
    6878        return 0; 
     
    8595 
    8696        ret->esp3=*stackP; /* User stack */ 
     97        ret->eventStack = MMapDo(ret->parent, NULL, 0, 0x1000, PAGE_RW | PAGE_PRESENT | PAGE_USER, 0, MMAP_PRIVATE, NULL)+0x1000; 
    8798 
    8899        IrqSaveFlags(flags); 
  • Whitix/branches/netchannel/include/error.h

    r2084 r2085  
    4444#define EISDIR          17 /* Is a directory - cannot read or write to it */ 
    4545#define EINVAL          18 /* Invalid value */ 
    46 #define EINTR           19 /* Operation interrupted by signal */ 
     46#define EINTR           19 /* Operation interrupted by event */ 
    4747 
    4848/* Network errors */ 
  • Whitix/branches/netchannel/include/sched.h

    r1309 r2085  
    4949void ThrSetPriority(struct Thread* thread, int priority); 
    5050void ThrSuspendThread(struct Thread* thread); 
     51void ThrSuspendThreadInt(struct Thread* thread); 
    5152void ThrResumeThread(struct Thread* thread); 
    5253char* ThrGetProcName(DWORD pid); 
  • Whitix/branches/netchannel/include/sys.h

    r1694 r2085  
    4444#define SYS_SHUTDOWN_BASE               57 
    4545#define SYS_IO_BASE                             58 
     46#define SYS_TIMER_BASE                  61 
     47#define SYS_EVENT_BASE                  64 
    4648 
    47 #define SYSCALL_MAX             62 
     49#define SYSCALL_MAX             65 
    4850 
    4951#define SysEntry(addr, bytes) { (DWORD)addr, bytes } 
  • Whitix/branches/netchannel/include/task.h

    r1701 r2085  
    2929struct JournalHandle; 
    3030 
    31 #define THR_USED_MATH 1 
     31#define THR_USED_MATH           1 
     32#define THR_NEED_RESTORE        2 
    3233 
    3334struct Thread 
    3435{ 
    3536        DWORD currStack; 
     37 
     38        /* Event handling functions */ 
     39        void (*eventFunc)(void* data); 
     40        void* eventData; 
     41        DWORD eventStack; 
     42        DWORD oldEip; 
     43 
    3644        struct Process* parent; 
    3745        DWORD state,entry,esp3; 
     
    5361/* Thread defines go here */ 
    5462 
    55 #define THR_RUNNING 1 
    56 #define THR_PAUSED  2 
    57 #define THR_DYING   4 
     63#define THR_RUNNING             1 
     64#define THR_PAUSED              2 
     65#define THR_INTERRUPTIBLE       4 
     66#define THR_DYING               8 
    5867 
    5968struct Process 
     
    6170        struct ListHead next,sibling,children; 
    6271        int exitCode, state; 
     72         
     73        /* Resource lists */ 
    6374        struct File* files; /* Dynamically allocated */ 
    64         Spinlock fileListLock; 
    65         int numFds; 
     75        struct KeTimer** timers; 
     76        Spinlock fileListLock, timerListLock; 
     77        int numFds, numTimers; 
     78 
     79        /* Filesystem contexts */ 
    6680        struct VNode *cwd,*root,*exec; 
    6781        char* name; 
  • Whitix/branches/netchannel/include/timer.h

    r2084 r2085  
    3636void Sleep(int milliSeconds); 
    3737 
     38/* Parameters for the system calls */ 
     39#define TIMER_USER_PERIODIC             0x01 
     40 
     41struct UserTimerSpec 
     42{ 
     43        DWORD secs, usecs; 
     44}; 
     45 
     46struct UserTimer 
     47{ 
     48        int flags; 
     49        void* data; 
     50        void (*func)(void* data); 
     51}; 
     52 
     53struct KeTimer 
     54{ 
     55        struct UserTimer uInfo; 
     56        struct Timer timer; 
     57        struct Thread* thread; 
     58}; 
     59 
     60struct Process; 
     61int TimerProcessRemove(struct Process* current); 
     62 
    3863#endif 
  • Whitix/branches/netchannel/include/wait.h

    r2084 r2085  
    7777}while(0) 
    7878 
     79#define WAIT_ON_INTERRUPTIBLE(waitQueue, condition) \ 
     80do { \ 
     81} while(0) 
     82 
    7983#define SLEEP_ON(waitQueue) \ 
    8084do { \ 
  • Whitix/branches/netchannel/kernel/Makefile

    r1676 r2085  
    11DEPTH=../ 
    22OBJS = main.o sched.o sys.o reboot.o panic.o wait.o module.o print.o symbols.o timer.o preempt.o \ 
    3         thread.o process.o startup.o tasklet.o 
     3        thread.o process.o startup.o tasklet.o event.o 
    44 
    55build: $(OBJS) 
  • Whitix/branches/netchannel/kernel/main.c

    r2084 r2085  
    4747extern int KeyboardInit(); 
    4848extern int ConsoleInit(); 
     49extern int TimerInit(); 
     50extern int EventInit(); 
    4951 
    5052void KernelMain() 
     
    5658        ShutdownInit(); 
    5759        UserCodeInit(); 
     60        TimerInit(); 
     61        EventInit(); 
    5862         
    5963        /* Set up the device-related subsystems. */ 
  • Whitix/branches/netchannel/kernel/process.c

    r2084 r2085  
    66#include <i386/process.h> 
    77#include <malloc.h> 
     8#include <event.h> 
    89#include <keobject.h> 
    910#include <user_acc.h> 
    1011#include <print.h> 
     12#include <timer.h> 
    1113#include <fs/icfs.h> 
    1214#include <fs/vfs.h> 
     
    236238 
    237239repeat: 
    238         waitEntry.thread=currThread; 
     240        waitEntry.thread = currThread; 
    239241        WaitAddToQueue(&current->waitQueue, &waitEntry); 
    240         ThrSuspendThread(currThread); 
     242        ThrSuspendThreadInt(currThread); 
    241243        ThrSchedule(); 
     244 
     245        if (EventWaiting(currThread)) 
     246                return -EINTR; 
    242247 
    243248        /* Is it the right one? */ 
     
    361366        MmapProcessRemove(current); 
    362367        LoadReleaseFsContext(); 
     368        TimerProcessRemove(current); 
    363369 
    364370        /* Now get rid of the memory manager - leaving kernel memory pages intact */ 
  • Whitix/branches/netchannel/kernel/sched.c

    r2084 r2085  
    1919#include <sched.h> 
    2020#include <error.h> 
     21#include <print.h> 
    2122#include <i386/process.h> 
    2223#include <slab.h> 
     
    9697                        thread=curr; 
    9798                } 
     99 
     100                if ((curr->eventFunc != NULL) && curr->state == THR_INTERRUPTIBLE) 
     101                        ThrResumeThread(curr); 
    98102        } 
    99103                 
  • Whitix/branches/netchannel/kernel/thread.c

    r1677 r2085  
    142142 
    143143        if (thread == currThread) 
    144                 ArchSwitchStackCall(exitStack+PAGE_SIZE/4,_ThrFreeThread,thread); 
     144                ArchSwitchStackCall(exitStack + (PAGE_SIZE >> 2),_ThrFreeThread,thread); 
    145145        else{ 
    146146                MemFree((void*)(thread->currStack)); 
     
    233233 ***********************************************************************/ 
    234234 
    235 void ThrSuspendThread(struct Thread* thread) 
     235void ThrDoSuspendThread(struct Thread* thread, int state) 
    236236{ 
    237237        if (thread == idleTask) 
    238238                KernelPanic("Idle task being suspended - driver sleeping in interrupt?"); 
    239239 
     240        SpinLockIrq(&thrListLock); 
     241 
    240242        if (LIKELY(thread->state == THR_RUNNING)) 
    241243        { 
    242                 SpinLockIrq(&thrListLock); 
    243244                --nrRunning; 
    244                 thread->state=THR_PAUSED; 
    245                 SpinUnlockIrq(&thrListLock); 
    246         } 
     245                thread->state = state; 
     246        } 
     247 
     248        SpinUnlockIrq(&thrListLock); 
     249} 
     250 
     251void ThrSuspendThread(struct Thread* thread) 
     252{ 
     253        ThrDoSuspendThread(thread, THR_PAUSED); 
    247254} 
    248255 
    249256SYMBOL_EXPORT(ThrSuspendThread); 
    250257 
     258void ThrSuspendThreadInt(struct Thread* thread) 
     259{ 
     260        ThrDoSuspendThread(thread, THR_INTERRUPTIBLE); 
     261} 
     262 
     263SYMBOL_EXPORT(ThrSuspendThreadInt); 
     264 
    251265/*********************************************************************** 
    252266 * 
    253267 * FUNCTION:    ThrResumeThread 
    254268 * 
    255  * DESCRIPTION: Resume a paused thread, and signal scheduling if it's of 
    256  *                              a higher priority. 
     269 * DESCRIPTION: Resume a paused thread. 
    257270 * 
    258271 * PARAMETERS:  thread - the thread in question. 
     
    268281                ThrStartThread(thread); 
    269282                if (thread->quantums >= currThread->quantums) 
    270                         thrNeedSchedule=true; 
     283                        thrNeedSchedule = true; 
    271284        } 
    272285} 
  • Whitix/branches/netchannel/kernel/timer.c

    r2084 r2085  
    2323#include <error.h> 
    2424#include <task.h> 
     25#include <sys.h> 
    2526#include <malloc.h> 
     27#include <event.h> 
     28#include <print.h> 
    2629 
    2730LIST_HEAD(timerList); 
     
    185188SYMBOL_EXPORT(Sleep); 
    186189 
     190#define KE_TIMER_ALLOC_STEP             10 
     191 
     192void TimerWakeup(void* data) 
     193{ 
     194        struct KeTimer* timer = (struct KeTimer*)data; 
     195 
     196        EventFire(timer->thread, timer->uInfo.func, timer->uInfo.data); 
     197} 
     198 
    187199/* Kernel system calls for timers */ 
    188 int SysTimerCreate() 
    189 { 
    190         return 0; 
    191 } 
    192  
    193 int SysTimerDestroy() 
    194 { 
    195         return 0; 
    196 } 
     200int SysTimerCreate(struct UserTimer* timerDesc) 
     201{ 
     202        int i; 
     203        struct KeTimer* curr; 
     204 
     205        SpinLock(&current->timerListLock); 
     206 
     207        if (!current->timers) 
     208        { 
     209                current->numTimers = KE_TIMER_ALLOC_STEP; 
     210                current->timers = (struct KeTimer**)MemAlloc(sizeof(struct KeTimer) * KE_TIMER_ALLOC_STEP); 
     211        } 
     212 
     213        for (i = 0; i < current->numTimers; i++) 
     214                if (!current->timers[i]) 
     215                        break; 
     216 
     217        if (i == current->numTimers) 
     218        { 
     219                KePrint("TODO: Extend array\n"); 
     220        } 
     221 
     222        current->timers[i] = (struct KeTimer*)MemAlloc(sizeof(struct KeTimer)); 
     223        curr = current->timers[i]; 
     224 
     225        curr->thread = currThread; 
     226        memcpy(&curr->uInfo, timerDesc, sizeof(struct UserTimer)); 
     227        curr->timer.func = TimerWakeup; 
     228        curr->timer.data = curr; 
     229 
     230        SpinUnlock(&current->timerListLock); 
     231 
     232        return i; 
     233} 
     234 
     235struct KeTimer* TimerGet(struct Process* process, int timer) 
     236{ 
     237        if (timer < 0 || timer > process->numTimers) 
     238                return NULL; 
     239 
     240        return process->timers[timer]; 
     241} 
     242 
     243int SysTimerModify(int tid, struct UserTimerSpec* newValue, struct UserTimerSpec* oldValue) 
     244{ 
     245        struct KeTimer* timer; 
     246 
     247        timer = TimerGet(current, tid); 
     248 
     249        if (oldValue) 
     250        { 
     251                KePrint("oldValue != NULL\n"); 
     252                return -ENOTIMPL; 
     253        } 
     254 
     255        if (!newValue) 
     256                return -EFAULT; 
     257 
     258        /* TODO: Check if timer is already on list */ 
     259 
     260        timer->timer.expires = newValue->secs * 1000; 
     261        /* useconds */ 
     262        TimerAdd(&timer->timer); 
     263 
     264        return 0; 
     265} 
     266 
     267int SysTimerDestroy(int timer) 
     268{ 
     269        KePrint("SysTimerDestroy(%d)\n", timer); 
     270        return 0; 
     271} 
     272 
     273int TimerProcessRemove(struct Process* process) 
     274{ 
     275        if (process->timers) 
     276        { 
     277                KePrint("Free timers\n"); 
     278        } 
     279 
     280        return 0; 
     281} 
     282 
     283static struct SysCall timerSysCallTable[]= 
     284{ 
     285        SysEntry(SysTimerCreate, 4), 
     286        SysEntry(SysTimerModify, 12), 
     287        SysEntry(SysTimerDestroy, 4), 
     288        SysEntryEnd() 
     289}; 
     290 
     291int TimerInit() 
     292{ 
     293        SysRegisterRange(SYS_TIMER_BASE, timerSysCallTable); 
     294        return 0; 
     295} 
  • Whitix/branches/netchannel/user/burn/builtins.c

    r1381 r2085  
    560560//                      SysClose(fd); 
    561561                return 1; 
    562         }else 
    563                 SysWaitForProcessFinish(pid,NULL); 
     562        }else{ 
     563                int ret; 
     564                 
     565                do 
     566                { 
     567                        ret = SysWaitForProcessFinish(pid,NULL); 
     568                } while (ret == -EINTR); 
     569        } 
    564570 
    565571//      if (redirOut) 
  • Whitix/branches/netchannel/user/burn/main.c

    r2084 r2085  
    445445    ConsSetTabSetup(&context, TabCompletionSetup); 
    446446    ConsSetBufferUpdate(&context, BurnTokenUpdate); 
    447      
     447 
    448448        printf("Burn shell V%d.%d\n---------------\nType 'help intro' for an introduction to the shell\n", 
    449449         MAJOR_BURN_VERSION, MINOR_BURN_VERSION); 
  • Whitix/branches/netchannel/user/libc/include/syscalls.h

    r2084 r2085  
    1818{ 
    1919        unsigned long seconds,useconds; 
     20}; 
     21 
     22struct UserTimer 
     23{ 
     24        int flags; 
     25        void* data; 
     26        void (*func)(void* data); 
     27}; 
     28 
     29struct UserTimerSpec 
     30{ 
     31        unsigned long seconds, useconds; 
    2032}; 
    2133 
  • Whitix/branches/netchannel/user/libc/include/sysdefs.h

    r2084 r2085  
    8080SYSCALL(58,int,SysIoAccess,4,(int on)); 
    8181 
     82/* Channel system calls */ 
    8283SYSCALL(59, int, SysChannelCreate, 16, (int family, void* src, void* dest, void* 
    8384                        options)); 
    8485SYSCALL(60, int, SysChannelControl, 12, (int fd, unsigned long code, void* data)); 
     86 
     87/* Timer system calls */ 
     88SYSCALL(61, int, SysTimerCreate, 4, (struct UserTimer* timer)); 
     89SYSCALL(62, int, SysTimerModify, 12, (int timer, struct UserTimerSpec* newSpec, struct UserTimerSpec* oldSpec)); 
     90SYSCALL(63, int, SysTimerDestroy, 4, (int timer)); 
     91 
     92/* Event system calls */ 
     93SYSCALL(64, int, SysEventReturn, 0, ()); 
  • Whitix/branches/netchannel/user/linker/Makefile

    r2084 r2085  
    1919        $(CC) $(BASE_CFLAGS) -c $*.S -o $*.o 
    2020 
    21 liblinker.so: $(OBJS) 
     21liblinker.so: $(OBJS) ../libc/rtl/syscall.o 
    2222        gcc $(BASE_LDFLAGS) $(LINKER_LDFLAGS) -shared $(OBJS) ../libc/rtl/syscall.o -o liblinker.so      
    2323 
  • Whitix/branches/netchannel/user/net/telnet.c

    r2084 r2085  
    9696        } 
    9797 
    98 //      printf("offset = %d, ret = %d\n", offset, ret); 
    9998 
    10099        if (ret > 0) 
  • Whitix/branches/netchannel/user/posix/file/file.c

    r1362 r2085  
    1010#include <syscalls.h> 
    1111 
     12#include "internal.h" 
     13 
    1214/* Sanity check these functions */ 
    1315 
     
    8991int close(int fd) 
    9092{ 
    91         return SysClose(fd); 
     93        struct PosixFile* file = PosixHandleToFile(fd); 
     94        int ret = -1; 
     95 
     96        if (file && file->type && file->type->close) 
     97        { 
     98                ret = file->type->close(file); 
     99 
     100                if (ret == 0) 
     101                { 
     102                        printf("close: free entry in table.\n"); 
     103                } 
     104        } 
     105         
     106        return ret; 
    92107} 
    93108 
  • Whitix/branches/netchannel/user/posix/socket/socket.c

    r2084 r2085  
    1111#include "../file/internal.h" 
    1212 
     13static int PosixSocketClose(struct PosixFile* file) 
     14{ 
     15        Socket* socket = (Socket*)PosixFilePriv(file); 
     16 
     17        return SocketClose(socket); 
     18} 
     19 
    1320/* POSIX file operations */ 
    1421struct PosixFileType socketType = 
    1522{ 
     23        .close = PosixSocketClose, 
    1624}; 
    1725 
  • Whitix/branches/netchannel/user/sdk/include/net/socket.h

    r2084 r2085  
    5252} 
    5353 
     54static inline void SocketFree(Socket* socket) 
     55{ 
     56        free(socket); 
     57} 
     58 
    5459/* General functions. */ 
    5560int SocketCreate(Socket* socket, int domain, int type, int protocol); 
  • Whitix/branches/netchannel/user/sdk/network/Makefile

    r2084 r2085  
    1 CFLAGS = -Wall -I../include -I../../libc/include -nostdlib -ffreestanding -fno-builtin -fPIC -m32  
     1CFLAGS = -Wall -I../include -I../../libc/include -nostdlib -ffreestanding -fno-builtin -fPIC -m32 -O3 
    22 
    33OBJS = byteorder.o ipv4.o udp.o memory.o dns.o icmp.o tcp.o tcp_options.o channels.o init.o socket.o 
  • Whitix/branches/netchannel/user/sdk/network/socket.c

    r2084 r2085  
    1111        if (type == NET_TYPE_STREAM) 
    1212        { 
    13                 _TcpSocketCreate(socket); 
    14                 return 0; 
     13                return _TcpSocketCreate(socket); 
    1514        }else{ 
    16                 _UdpSocketCreate(socket); 
    17                 return 0; 
     15                return _UdpSocketCreate(socket); 
    1816        } 
    1917 
  • Whitix/branches/netchannel/user/sdk/network/tcp_options.h

    r2084 r2085  
    2727void* TcpOptionAdd(struct TcpHeaderBuild* build, int type); 
    2828int TcpFinishHeader(struct TcpHeaderBuild* build); 
    29 int TcpParseOptions(struct TcpSocketInfo* info, struct TcpHeader* header); 
     29int TcpParseOptions(struct TcpSocketInfo* info, struct TcpHeader* header, ushort packetLength); 
    3030 
    3131#endif