Changeset 2085 for Whitix/branches
- Timestamp:
- 05/20/10 16:05:25 (2 years ago)
- Location:
- Whitix/branches/netchannel
- Files:
-
- 27 modified
-
arch/i386/kernel/idtstubs.S (modified) (1 diff)
-
arch/i386/kernel/ints.c (modified) (4 diffs)
-
arch/i386/kernel/process.c (modified) (4 diffs)
-
include/error.h (modified) (1 diff)
-
include/sched.h (modified) (1 diff)
-
include/sys.h (modified) (1 diff)
-
include/task.h (modified) (3 diffs)
-
include/timer.h (modified) (1 diff)
-
include/wait.h (modified) (1 diff)
-
kernel/Makefile (modified) (1 diff)
-
kernel/main.c (modified) (2 diffs)
-
kernel/process.c (modified) (3 diffs)
-
kernel/sched.c (modified) (2 diffs)
-
kernel/thread.c (modified) (3 diffs)
-
kernel/timer.c (modified) (2 diffs)
-
user/burn/builtins.c (modified) (1 diff)
-
user/burn/main.c (modified) (1 diff)
-
user/libc/include/syscalls.h (modified) (1 diff)
-
user/libc/include/sysdefs.h (modified) (1 diff)
-
user/linker/Makefile (modified) (1 diff)
-
user/net/telnet.c (modified) (1 diff)
-
user/posix/file/file.c (modified) (2 diffs)
-
user/posix/socket/socket.c (modified) (1 diff)
-
user/sdk/include/net/socket.h (modified) (1 diff)
-
user/sdk/network/Makefile (modified) (1 diff)
-
user/sdk/network/socket.c (modified) (1 diff)
-
user/sdk/network/tcp_options.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
Whitix/branches/netchannel/arch/i386/kernel/idtstubs.S
r559 r2085 217 217 int $0x30 218 218 endi386ExitThread: 219 220 .globl i386RetFromEvent 221 .globl endi386RetFromEvent 222 223 i386RetFromEvent: 224 mov $64, %eax /* SysEventReturn syscall number */ 225 xor %ecx, %ecx 226 lea (%esp), %edx 227 int $0x30 228 endi386RetFromEvent: -
Whitix/branches/netchannel/arch/i386/kernel/ints.c
r2084 r2085 268 268 } 269 269 270 void 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 270 298 /*********************************************************************** 271 299 * … … 284 312 DWORD irq=curr.irq; 285 313 314 /* FIXME: Unreliable, since we can be interrupted. */ 286 315 if (currThread) 287 316 currThread->currContext=&curr; … … 298 327 299 328 case 0x30: 300 curr.eax =IrqSysCall(curr.eax,curr.edx,curr.ecx);329 curr.eax = IrqSysCall(curr.eax,curr.edx,curr.ecx); 301 330 break; 302 331 … … 307 336 if (thrNeedSchedule && PreemptCanSchedule()) 308 337 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 33 33 void i386ExitThread(); 34 34 void endi386ExitThread(); 35 void i386RetFromEvent(); 36 void endi386RetFromEvent(); 37 35 38 DWORD exitCode=0xF8000000; 39 DWORD retFromEvent; 36 40 37 41 struct TSS* tss=(struct TSS*)(TSS_ADDR); … … 56 60 int ThrArchInit() 57 61 { 62 int exitCodeSz = (DWORD)endi386ExitThread-(DWORD)i386ExitThread; 63 int retEventSz = (DWORD)endi386RetFromEvent - (DWORD)i386RetFromEvent; 64 58 65 /* Setup up the TSS, only needed for ss0 and esp0 */ 59 66 tss->bitmap=0x8000; /* Bitmap offset. Past limit, so every IO instruction in userspace will produce a GPF. */ … … 64 71 /* Copy the exit code over to a user accessable page of memory. Add procesor-specific syscall method code into the page soon. */ 65 72 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); 67 77 68 78 return 0; … … 85 95 86 96 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; 87 98 88 99 IrqSaveFlags(flags); -
Whitix/branches/netchannel/include/error.h
r2084 r2085 44 44 #define EISDIR 17 /* Is a directory - cannot read or write to it */ 45 45 #define EINVAL 18 /* Invalid value */ 46 #define EINTR 19 /* Operation interrupted by signal*/46 #define EINTR 19 /* Operation interrupted by event */ 47 47 48 48 /* Network errors */ -
Whitix/branches/netchannel/include/sched.h
r1309 r2085 49 49 void ThrSetPriority(struct Thread* thread, int priority); 50 50 void ThrSuspendThread(struct Thread* thread); 51 void ThrSuspendThreadInt(struct Thread* thread); 51 52 void ThrResumeThread(struct Thread* thread); 52 53 char* ThrGetProcName(DWORD pid); -
Whitix/branches/netchannel/include/sys.h
r1694 r2085 44 44 #define SYS_SHUTDOWN_BASE 57 45 45 #define SYS_IO_BASE 58 46 #define SYS_TIMER_BASE 61 47 #define SYS_EVENT_BASE 64 46 48 47 #define SYSCALL_MAX 6 249 #define SYSCALL_MAX 65 48 50 49 51 #define SysEntry(addr, bytes) { (DWORD)addr, bytes } -
Whitix/branches/netchannel/include/task.h
r1701 r2085 29 29 struct JournalHandle; 30 30 31 #define THR_USED_MATH 1 31 #define THR_USED_MATH 1 32 #define THR_NEED_RESTORE 2 32 33 33 34 struct Thread 34 35 { 35 36 DWORD currStack; 37 38 /* Event handling functions */ 39 void (*eventFunc)(void* data); 40 void* eventData; 41 DWORD eventStack; 42 DWORD oldEip; 43 36 44 struct Process* parent; 37 45 DWORD state,entry,esp3; … … 53 61 /* Thread defines go here */ 54 62 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 58 67 59 68 struct Process … … 61 70 struct ListHead next,sibling,children; 62 71 int exitCode, state; 72 73 /* Resource lists */ 63 74 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 */ 66 80 struct VNode *cwd,*root,*exec; 67 81 char* name; -
Whitix/branches/netchannel/include/timer.h
r2084 r2085 36 36 void Sleep(int milliSeconds); 37 37 38 /* Parameters for the system calls */ 39 #define TIMER_USER_PERIODIC 0x01 40 41 struct UserTimerSpec 42 { 43 DWORD secs, usecs; 44 }; 45 46 struct UserTimer 47 { 48 int flags; 49 void* data; 50 void (*func)(void* data); 51 }; 52 53 struct KeTimer 54 { 55 struct UserTimer uInfo; 56 struct Timer timer; 57 struct Thread* thread; 58 }; 59 60 struct Process; 61 int TimerProcessRemove(struct Process* current); 62 38 63 #endif -
Whitix/branches/netchannel/include/wait.h
r2084 r2085 77 77 }while(0) 78 78 79 #define WAIT_ON_INTERRUPTIBLE(waitQueue, condition) \ 80 do { \ 81 } while(0) 82 79 83 #define SLEEP_ON(waitQueue) \ 80 84 do { \ -
Whitix/branches/netchannel/kernel/Makefile
r1676 r2085 1 1 DEPTH=../ 2 2 OBJS = 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 4 4 5 5 build: $(OBJS) -
Whitix/branches/netchannel/kernel/main.c
r2084 r2085 47 47 extern int KeyboardInit(); 48 48 extern int ConsoleInit(); 49 extern int TimerInit(); 50 extern int EventInit(); 49 51 50 52 void KernelMain() … … 56 58 ShutdownInit(); 57 59 UserCodeInit(); 60 TimerInit(); 61 EventInit(); 58 62 59 63 /* Set up the device-related subsystems. */ -
Whitix/branches/netchannel/kernel/process.c
r2084 r2085 6 6 #include <i386/process.h> 7 7 #include <malloc.h> 8 #include <event.h> 8 9 #include <keobject.h> 9 10 #include <user_acc.h> 10 11 #include <print.h> 12 #include <timer.h> 11 13 #include <fs/icfs.h> 12 14 #include <fs/vfs.h> … … 236 238 237 239 repeat: 238 waitEntry.thread =currThread;240 waitEntry.thread = currThread; 239 241 WaitAddToQueue(¤t->waitQueue, &waitEntry); 240 ThrSuspendThread (currThread);242 ThrSuspendThreadInt(currThread); 241 243 ThrSchedule(); 244 245 if (EventWaiting(currThread)) 246 return -EINTR; 242 247 243 248 /* Is it the right one? */ … … 361 366 MmapProcessRemove(current); 362 367 LoadReleaseFsContext(); 368 TimerProcessRemove(current); 363 369 364 370 /* Now get rid of the memory manager - leaving kernel memory pages intact */ -
Whitix/branches/netchannel/kernel/sched.c
r2084 r2085 19 19 #include <sched.h> 20 20 #include <error.h> 21 #include <print.h> 21 22 #include <i386/process.h> 22 23 #include <slab.h> … … 96 97 thread=curr; 97 98 } 99 100 if ((curr->eventFunc != NULL) && curr->state == THR_INTERRUPTIBLE) 101 ThrResumeThread(curr); 98 102 } 99 103 -
Whitix/branches/netchannel/kernel/thread.c
r1677 r2085 142 142 143 143 if (thread == currThread) 144 ArchSwitchStackCall(exitStack +PAGE_SIZE/4,_ThrFreeThread,thread);144 ArchSwitchStackCall(exitStack + (PAGE_SIZE >> 2),_ThrFreeThread,thread); 145 145 else{ 146 146 MemFree((void*)(thread->currStack)); … … 233 233 ***********************************************************************/ 234 234 235 void Thr SuspendThread(struct Thread* thread)235 void ThrDoSuspendThread(struct Thread* thread, int state) 236 236 { 237 237 if (thread == idleTask) 238 238 KernelPanic("Idle task being suspended - driver sleeping in interrupt?"); 239 239 240 SpinLockIrq(&thrListLock); 241 240 242 if (LIKELY(thread->state == THR_RUNNING)) 241 243 { 242 SpinLockIrq(&thrListLock);243 244 --nrRunning; 244 thread->state=THR_PAUSED; 245 SpinUnlockIrq(&thrListLock); 246 } 245 thread->state = state; 246 } 247 248 SpinUnlockIrq(&thrListLock); 249 } 250 251 void ThrSuspendThread(struct Thread* thread) 252 { 253 ThrDoSuspendThread(thread, THR_PAUSED); 247 254 } 248 255 249 256 SYMBOL_EXPORT(ThrSuspendThread); 250 257 258 void ThrSuspendThreadInt(struct Thread* thread) 259 { 260 ThrDoSuspendThread(thread, THR_INTERRUPTIBLE); 261 } 262 263 SYMBOL_EXPORT(ThrSuspendThreadInt); 264 251 265 /*********************************************************************** 252 266 * 253 267 * FUNCTION: ThrResumeThread 254 268 * 255 * DESCRIPTION: Resume a paused thread, and signal scheduling if it's of 256 * a higher priority. 269 * DESCRIPTION: Resume a paused thread. 257 270 * 258 271 * PARAMETERS: thread - the thread in question. … … 268 281 ThrStartThread(thread); 269 282 if (thread->quantums >= currThread->quantums) 270 thrNeedSchedule =true;283 thrNeedSchedule = true; 271 284 } 272 285 } -
Whitix/branches/netchannel/kernel/timer.c
r2084 r2085 23 23 #include <error.h> 24 24 #include <task.h> 25 #include <sys.h> 25 26 #include <malloc.h> 27 #include <event.h> 28 #include <print.h> 26 29 27 30 LIST_HEAD(timerList); … … 185 188 SYMBOL_EXPORT(Sleep); 186 189 190 #define KE_TIMER_ALLOC_STEP 10 191 192 void TimerWakeup(void* data) 193 { 194 struct KeTimer* timer = (struct KeTimer*)data; 195 196 EventFire(timer->thread, timer->uInfo.func, timer->uInfo.data); 197 } 198 187 199 /* Kernel system calls for timers */ 188 int SysTimerCreate() 189 { 190 return 0; 191 } 192 193 int SysTimerDestroy() 194 { 195 return 0; 196 } 200 int SysTimerCreate(struct UserTimer* timerDesc) 201 { 202 int i; 203 struct KeTimer* curr; 204 205 SpinLock(¤t->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(¤t->timerListLock); 231 232 return i; 233 } 234 235 struct 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 243 int 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 267 int SysTimerDestroy(int timer) 268 { 269 KePrint("SysTimerDestroy(%d)\n", timer); 270 return 0; 271 } 272 273 int TimerProcessRemove(struct Process* process) 274 { 275 if (process->timers) 276 { 277 KePrint("Free timers\n"); 278 } 279 280 return 0; 281 } 282 283 static struct SysCall timerSysCallTable[]= 284 { 285 SysEntry(SysTimerCreate, 4), 286 SysEntry(SysTimerModify, 12), 287 SysEntry(SysTimerDestroy, 4), 288 SysEntryEnd() 289 }; 290 291 int TimerInit() 292 { 293 SysRegisterRange(SYS_TIMER_BASE, timerSysCallTable); 294 return 0; 295 } -
Whitix/branches/netchannel/user/burn/builtins.c
r1381 r2085 560 560 // SysClose(fd); 561 561 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 } 564 570 565 571 // if (redirOut) -
Whitix/branches/netchannel/user/burn/main.c
r2084 r2085 445 445 ConsSetTabSetup(&context, TabCompletionSetup); 446 446 ConsSetBufferUpdate(&context, BurnTokenUpdate); 447 447 448 448 printf("Burn shell V%d.%d\n---------------\nType 'help intro' for an introduction to the shell\n", 449 449 MAJOR_BURN_VERSION, MINOR_BURN_VERSION); -
Whitix/branches/netchannel/user/libc/include/syscalls.h
r2084 r2085 18 18 { 19 19 unsigned long seconds,useconds; 20 }; 21 22 struct UserTimer 23 { 24 int flags; 25 void* data; 26 void (*func)(void* data); 27 }; 28 29 struct UserTimerSpec 30 { 31 unsigned long seconds, useconds; 20 32 }; 21 33 -
Whitix/branches/netchannel/user/libc/include/sysdefs.h
r2084 r2085 80 80 SYSCALL(58,int,SysIoAccess,4,(int on)); 81 81 82 /* Channel system calls */ 82 83 SYSCALL(59, int, SysChannelCreate, 16, (int family, void* src, void* dest, void* 83 84 options)); 84 85 SYSCALL(60, int, SysChannelControl, 12, (int fd, unsigned long code, void* data)); 86 87 /* Timer system calls */ 88 SYSCALL(61, int, SysTimerCreate, 4, (struct UserTimer* timer)); 89 SYSCALL(62, int, SysTimerModify, 12, (int timer, struct UserTimerSpec* newSpec, struct UserTimerSpec* oldSpec)); 90 SYSCALL(63, int, SysTimerDestroy, 4, (int timer)); 91 92 /* Event system calls */ 93 SYSCALL(64, int, SysEventReturn, 0, ()); -
Whitix/branches/netchannel/user/linker/Makefile
r2084 r2085 19 19 $(CC) $(BASE_CFLAGS) -c $*.S -o $*.o 20 20 21 liblinker.so: $(OBJS) 21 liblinker.so: $(OBJS) ../libc/rtl/syscall.o 22 22 gcc $(BASE_LDFLAGS) $(LINKER_LDFLAGS) -shared $(OBJS) ../libc/rtl/syscall.o -o liblinker.so 23 23 -
Whitix/branches/netchannel/user/net/telnet.c
r2084 r2085 96 96 } 97 97 98 // printf("offset = %d, ret = %d\n", offset, ret);99 98 100 99 if (ret > 0) -
Whitix/branches/netchannel/user/posix/file/file.c
r1362 r2085 10 10 #include <syscalls.h> 11 11 12 #include "internal.h" 13 12 14 /* Sanity check these functions */ 13 15 … … 89 91 int close(int fd) 90 92 { 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; 92 107 } 93 108 -
Whitix/branches/netchannel/user/posix/socket/socket.c
r2084 r2085 11 11 #include "../file/internal.h" 12 12 13 static int PosixSocketClose(struct PosixFile* file) 14 { 15 Socket* socket = (Socket*)PosixFilePriv(file); 16 17 return SocketClose(socket); 18 } 19 13 20 /* POSIX file operations */ 14 21 struct PosixFileType socketType = 15 22 { 23 .close = PosixSocketClose, 16 24 }; 17 25 -
Whitix/branches/netchannel/user/sdk/include/net/socket.h
r2084 r2085 52 52 } 53 53 54 static inline void SocketFree(Socket* socket) 55 { 56 free(socket); 57 } 58 54 59 /* General functions. */ 55 60 int 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 1 CFLAGS = -Wall -I../include -I../../libc/include -nostdlib -ffreestanding -fno-builtin -fPIC -m32 -O3 2 2 3 3 OBJS = 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 11 11 if (type == NET_TYPE_STREAM) 12 12 { 13 _TcpSocketCreate(socket); 14 return 0; 13 return _TcpSocketCreate(socket); 15 14 }else{ 16 _UdpSocketCreate(socket); 17 return 0; 15 return _UdpSocketCreate(socket); 18 16 } 19 17 -
Whitix/branches/netchannel/user/sdk/network/tcp_options.h
r2084 r2085 27 27 void* TcpOptionAdd(struct TcpHeaderBuild* build, int type); 28 28 int TcpFinishHeader(struct TcpHeaderBuild* build); 29 int TcpParseOptions(struct TcpSocketInfo* info, struct TcpHeader* header );29 int TcpParseOptions(struct TcpSocketInfo* info, struct TcpHeader* header, ushort packetLength); 30 30 31 31 #endif
