diff -ruN -U 10 kozos05/Makefile kozos06/Makefile --- kozos05/Makefile Mon Oct 22 23:07:29 2007 +++ kozos06/Makefile Mon Oct 22 23:07:29 2007 @@ -1,11 +1,11 @@ -OBJS += thread.o syscall.o main.o +OBJS += thread.o syscall.o outlog.o main.o TARGET ?= koz CC ?= gcc CFLAGS = #CFLAGS += -O CFLAGS += -g CFLAGS += -Wall CFLAGS += -static .SUFFIXES: .c .o diff -ruN -U 10 kozos05/kozos.h kozos06/kozos.h --- kozos05/kozos.h Mon Oct 22 23:07:29 2007 +++ kozos06/kozos.h Mon Oct 22 23:07:29 2007 @@ -9,15 +9,21 @@ int kz_run(kz_func func, char *name, int pri, int argc, char *argv[]); void kz_exit(); int kz_wait(); int kz_sleep(); int kz_wakeup(int id); int kz_getid(); int kz_chpri(int pri); int kz_send(int id, int size, char *p); int kz_recv(int *idp, char **pp); int kz_timer(int msec); +void *kz_memalloc(int size); +int kz_memfree(void *p); /* library */ void kz_start(kz_func func, char *name, int pri, int argc, char *argv[]); + +/* general thread */ +extern int outlog_id; +int outlog_main(int argc, char *argv[]); #endif diff -ruN -U 10 kozos05/outlog.c kozos06/outlog.c --- kozos05/outlog.c Thu Jan 1 09:00:00 1970 +++ kozos06/outlog.c Mon Oct 22 23:07:29 2007 @@ -0,0 +1,16 @@ +#include +#include + +#include "kozos.h" + +int outlog_id; + +int outlog_main(int argc, char *argv[]) +{ + char *p; + while (1) { + kz_recv(NULL, &p); + fprintf(stderr, "%s", p); + kz_memfree(p); + } +} diff -ruN -U 10 kozos05/syscall.c kozos06/syscall.c --- kozos05/syscall.c Mon Oct 22 23:07:29 2007 +++ kozos06/syscall.c Mon Oct 22 23:07:29 2007 @@ -89,10 +89,26 @@ return param.un.recv.ret; } int kz_timer(int msec) { kz_syscall_param_t param; param.un.timer.msec = msec; kz_syscall(KZ_SYSCALL_TYPE_TIMER, ¶m); return param.un.timer.ret; } + +void *kz_memalloc(int size) +{ + kz_syscall_param_t param; + param.un.memalloc.size = size; + kz_syscall(KZ_SYSCALL_TYPE_MEMALLOC, ¶m); + return param.un.memalloc.ret; +} + +int kz_memfree(void *p) +{ + kz_syscall_param_t param; + param.un.memfree.p = p; + kz_syscall(KZ_SYSCALL_TYPE_MEMFREE, ¶m); + return param.un.memfree.ret; +} diff -ruN -U 10 kozos05/syscall.h kozos06/syscall.h --- kozos05/syscall.h Mon Oct 22 23:07:29 2007 +++ kozos06/syscall.h Mon Oct 22 23:07:29 2007 @@ -7,20 +7,22 @@ KZ_SYSCALL_TYPE_RUN, KZ_SYSCALL_TYPE_EXIT, KZ_SYSCALL_TYPE_WAIT, KZ_SYSCALL_TYPE_SLEEP, KZ_SYSCALL_TYPE_WAKEUP, KZ_SYSCALL_TYPE_GETID, KZ_SYSCALL_TYPE_CHPRI, KZ_SYSCALL_TYPE_SEND, KZ_SYSCALL_TYPE_RECV, KZ_SYSCALL_TYPE_TIMER, + KZ_SYSCALL_TYPE_MEMALLOC, + KZ_SYSCALL_TYPE_MEMFREE, } kz_syscall_type_t; typedef struct { union { struct { kz_func func; char *name; int pri; int argc; char **argv; @@ -54,16 +56,24 @@ } send; struct { int *idp; char **pp; int ret; } recv; struct { int msec; int ret; } timer; + struct { + int size; + void *ret; + } memalloc; + struct { + char *p; + int ret; + } memfree; } un; } kz_syscall_param_t; void kz_syscall(kz_syscall_type_t type, kz_syscall_param_t *param); #endif diff -ruN -U 10 kozos05/thread.c kozos06/thread.c --- kozos05/thread.c Mon Oct 22 23:07:29 2007 +++ kozos06/thread.c Mon Oct 22 23:07:29 2007 @@ -271,20 +271,33 @@ sendmsg(timers->thp, 0, 0, NULL); tmp = timers; timers = timers->next; free(tmp); if (timers) { gettimeofday(&alarm_tm, NULL); ualarm(timers->msec * 1000, 0); } } +static void *thread_memalloc(int size) +{ + putcurrent(); + return malloc(size); +} + +static int thread_memfree(char *p) +{ + free(p); + putcurrent(); + return 0; +} + static void syscall_proc() { /* システムコールの実行中にcurrentが書き換わるのでポインタを保存しておく */ kz_syscall_param_t *p = current->syscall.param; getcurrent(); switch (current->syscall.type) { case KZ_SYSCALL_TYPE_RUN: p->un.run.ret = thread_run(p->un.run.func, p->un.run.name, p->un.run.pri, @@ -310,20 +323,26 @@ p->un.chpri.ret = thread_chpri(p->un.chpri.pri); break; case KZ_SYSCALL_TYPE_SEND: p->un.send.ret = thread_send(p->un.send.id, p->un.send.size, p->un.send.p); break; case KZ_SYSCALL_TYPE_RECV: p->un.recv.ret = thread_recv(p->un.recv.idp, p->un.recv.pp); break; case KZ_SYSCALL_TYPE_TIMER: p->un.timer.ret = thread_timer(p->un.timer.msec); + break; + case KZ_SYSCALL_TYPE_MEMALLOC: + p->un.memalloc.ret = thread_memalloc(p->un.memalloc.size); + break; + case KZ_SYSCALL_TYPE_MEMFREE: + p->un.memfree.ret = thread_memfree(p->un.memfree.p); break; default: break; } return; } static void dispatch() { int i;