changeset 152:d3f97de63622

merge from menikon branch
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Mon, 16 Dec 2019 21:55:29 +0900
parents 06449f2ae0c7 (current diff) 124c59d99fc9 (diff)
children 49d8aba0002a
files src/impl/PipeRead.h src/interface/SysRead.h
diffstat 11 files changed, 81 insertions(+), 533 deletions(-) [+]
line wrap: on
line diff
--- a/src/CMakeLists.txt	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/CMakeLists.txt	Mon Dec 16 21:55:29 2019 +0900
@@ -126,6 +126,8 @@
   SOURCES
 	string.c arm.c asm.S bio.c buddy.c console.cbc exec.c file.cbc fs.c log.c main.c memide.c pipe.cbc proc.cbc spinlock.cbc 
 	start.c swtch.S syscall.cbc sysfile.cbc sysproc.c trap_asm.S trap.c vm.c device/picirq.c device/timer.c device/uart.c 
-  SingleLinkedStack.cbc sys_read_impl.cbc
+  SingleLinkedStack.cbc sys_open_impl.cbc
          entry.S 
 )
+
+# sys_read_impl.cbc
\ No newline at end of file
--- a/src/context.h	Mon Dec 16 21:38:50 2019 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,524 +0,0 @@
-/* Context definition for llrb example */
-// #ifdef CBC_CONTEXT_H  does not work well
-#define CBC_CONTEXT_H
-// #include <stdlib.h>
-// #include <pthread.h>
-#ifdef USE_CUDAWorker
-#include <cuda.h>
-#include <driver_types.h>
-#include <cuda_runtime.h>
-#include "helper_cuda.h"
-#endif
-
-#ifndef NULL
-# if defined __GNUG__ && \
-    (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8))
-#  define NULL (__null)
-# else
-#  if !defined(__cplusplus)
-#   define NULL ((void*)0)
-#  else
-#   define NULL (0)
-#  endif
-# endif
-#endif
-
-#ifdef XV6KERNEL
-extern void*           kmalloc (int order);
-#define calloc(a,b)  kmalloc((a)*(b))
-#define free(a)  kfree(a)
-#else
-#define calloc(a,b)  malloc((a)*(b))
-#define free(a)  free(a)
-#endif
-
-#define ALLOCATE_SIZE 20000000
-#define NEW(type) (type*)(calloc(1, sizeof(type)))
-#define NEWN(n, type) (type*)(calloc(n, sizeof(type)))
-
-#define ALLOC_DATA(cbc_context, dseg) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    meta->type = D_##dseg;\
-    meta->size = sizeof(dseg);\
-    meta->len = 1;\
-    cbc_context->heap += sizeof(Meta);\
-    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(dseg); (dseg *)cbc_context->data[D_##dseg]; })
-
-#define ALLOC_DATA_TYPE(cbc_context, dseg, t) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    meta->type = D_##t;\
-    meta->size = sizeof(t);\
-    meta->len = 1;\
-    cbc_context->heap += sizeof(Meta);\
-    cbc_context->data[D_##dseg] = cbc_context->heap; cbc_context->heap += sizeof(t); (t *)cbc_context->data[D_##dseg]; })
-
-#define ALLOCATE(cbc_context, t) ({ \
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(t); \
-    meta->type = D_##t; \
-    meta->size = sizeof(t);     \
-    meta->len = 1;\
-    data; })
-
-#define ALLOCATE_ARRAY(cbc_context, t, length) ({ \
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(t)*length; \
-    meta->type = D_##t; \
-    meta->size = sizeof(t)*length; \
-    meta->len = length; \
-    data;   })
-
-#define ALLOCATE_PTR_ARRAY(cbc_context, dseg, length) ({\
-    Meta* meta = (Meta*)cbc_context->heap;\
-    cbc_context->heap += sizeof(Meta);\
-    union Data* data = cbc_context->heap; \
-    cbc_context->heap += sizeof(dseg *)*length; \
-    meta->type = D_##dseg; \
-    meta->size = sizeof(dseg *)*length; \
-    meta->len = length; \
-    data; })
-
-#define ALLOCATE_DATA_GEAR(cbc_context, t) ({ \
-        union Data* data = ALLOCATE(cbc_context, t); \
-        Meta* meta = GET_META(data); \
-        meta->wait = createSynchronizedQueue(cbc_context); \
-        data; })
-
-#define ALLOC(cbc_context, t) (&ALLOCATE(cbc_context, t)->t)
-
-#define GET_META(dseg) ((Meta*)(((void*)dseg) - sizeof(Meta)))
-#define GET_TYPE(dseg) (GET_META(dseg)->type)
-#define GET_SIZE(dseg) (GET_META(dseg)->size)
-#define GET_LEN(dseg) (GET_META(dseg)->len)
-#define GET_WAIT_LIST(dseg) (GET_META(dseg)->wait)
-
-#define Gearef(cbc_context, t) (&(cbc_context)->data[D_##t]->t)
-
-// (SingleLinkedStack *)cbc_context->data[D_Stack]->Stack.stack->Stack.stack
-
-#define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name)
-
-#include "c/enumCode.h"
-
-enum Relational {
-    EQ,
-    GT,
-    LT,
-};
-
-#include "c/enumData.h"
-#define NDIRECT 12 //fs.h
-
-struct Context {
-    enum Code next;
-    struct Worker* worker;
-    struct TaskManager* taskManager;
-    int codeNum;
-    __code (**code) (struct Context*);
-    union Data **data;
-    void* heapStart;
-    void* heap;
-    long heapLimit;
-    int dataNum;
-
-    // task parameter
-    int idgCount; //number of waiting dataGear
-    int idg;
-    int maxIdg;
-    int odg;
-    int maxOdg;
-    int gpu; // GPU task
-    struct Context* task;
-    struct Element* taskList;
-#ifdef USE_CUDAWorker
-    int num_exec;
-    CUmodule module;
-    CUfunction function;
-#endif
-    /* multi dimension parameter */
-    int iterate;
-    struct Iterator* iterator;
-    enum Code before;
-};
-
-typedef int Int;
-#ifndef USE_CUDAWorker
-typedef unsigned long long CUdeviceptr;
-#endif
-union Data {
-    struct Meta {
-        enum DataType type;
-        long size;
-        long len;
-        struct Queue* wait; // tasks waiting this dataGear
-    } Meta;
-    struct Context Context;
-    struct Timer {
-        union Data* timer;
-        enum Code start;
-        enum Code end;
-        enum Code next;
-    } Timer;
-    struct TimerImpl {
-        double time;
-    } TimerImpl;
-    struct LoopCounter {
-        int i;
-    } LoopCounter;
-    struct TaskManager {
-        union Data* taskManager;
-        enum Code spawn;      // start NEW cbc_context on the worker
-        enum Code spawnTasks; // start NEW tasks on the worker
-        enum Code shutdown;
-        enum Code incrementTaskCount;
-        enum Code decrementTaskCount;
-        enum Code next;
-        enum Code next1;
-        enum Code setWaitTask;
-        struct Context* task;
-        struct Element* taskList;
-        union Data* data;
-    } TaskManager;
-    struct TaskManagerImpl {
-        enum Code next;
-        int numWorker;
-        int sendCPUWorkerIndex;
-        int sendGPUWorkerIndex;
-        int taskCount;
-        // pthread_mutex_t mutex;
-        struct Queue* activeQueue;
-        struct Worker** workers;
-        struct Element* taskList;
-        int loopCounter;
-        int cpu;
-        int gpu;
-        int io;
-        int maxCPU;
-    } TaskManagerImpl;
-    struct Worker {
-        union Data* worker;
-        enum Code taskReceive;
-        enum Code shutdown;
-        enum Code next;
-        struct Queue* tasks;
-        // pthread_t thread;
-        struct TaskManager* taskManager;
-        struct Context* task;
-    } Worker;
-    struct CPUWorker {
-        // pthread_mutex_t mutex;
-        // pthread_cond_t cond;
-        struct Context* cbc_context;
-        int id;
-        int loopCounter;
-    } CPUWorker;
-#ifdef USE_CUDAWorker
-    struct CUDAWorker {
-        CUdevice device;
-        CUcbc_context cuCtx;
-        struct Context* cbc_context;
-        int id;
-        int loopCounter;
-        int deviceNum;
-        struct Queue* tasks;
-        int runFlag;
-        enum Code next;
-        int numStream;
-        struct Executor* executor;
-        CUstream *stream;
-    } CUDAWorker;
-#else
-    struct CUDAWorker {
-    } CUDAWorker;
-#endif
-    struct Main {
-        enum Code code;
-        enum Code next;
-        struct Queue* args;
-    } Main;
-    // Queue Interface
-    struct Queue {
-        union Data* queue;
-        union Data* data;
-        enum Code whenEmpty;
-        enum Code clear;
-        enum Code put;
-        enum Code take;
-        enum Code isEmpty;
-        enum Code next;
-    } Queue;
-    struct SingleLinkedQueue {
-        struct Element* top;
-        struct Element* last;
-    } SingleLinkedQueue;
-    struct SynchronizedQueue {
-        struct Element* top;
-        struct Element* last;
-        struct Atomic* atomic;
-    } SynchronizedQueue;
-    // Stack Interface
-    struct Stack {
-        union Data* stack;
-        union Data* data;
-        union Data* data1;
-        enum Code whenEmpty;
-        enum Code clear;
-        enum Code push;
-        enum Code pop;
-        enum Code pop2;
-        enum Code isEmpty;
-        enum Code get;
-        enum Code get2;
-        enum Code next;
-    } Stack;
-    // Stack implementations
-    struct SingleLinkedStack {
-        struct Element* top;
-    } SingleLinkedStack;
-    struct ArrayStack {
-        int size;
-        int limit;
-        struct Element* array;
-    } ArrayStack;
-    // Stack implementation end
-    struct Element {
-        union Data* data;
-        struct Element* next;
-    } Element;
-    struct Array {
-        int prefix;
-        Int* array;
-    } Array;
-    struct Tree {
-        union Data* tree;
-        struct Node* node;
-        enum Code put;
-        enum Code get;
-        enum Code remove;
-        enum Code clear;
-        enum Code next;
-    } Tree;
-    struct RedBlackTree {
-        struct Node* root;
-        struct Node* current; // reading node of original tree
-        struct Node* previous; // parent of reading node of original tree
-        struct Node* newNode; // writing node of new tree
-        struct Node* parent;
-        struct Node* grandparent;
-        struct Stack* nodeStack;
-        enum Code findNodeNext;
-        int result;
-    } RedBlackTree;
-    struct RotateTree {
-        enum Code next;
-        struct RedBlackTree* traverse;
-        struct Tree* tree;
-    } RotateTree;
-    struct Node {
-        int key; // comparable data segment
-        union Data* value;
-        struct Node* left;
-        struct Node* right;
-        // need to balancing
-        enum Color {
-            Red,
-            Black,
-            // Red eq 0,Black eq 1. enum name convert intager.
-        } color;
-    } Node;
-    struct Atomic {
-        union Data* atomic;
-        union Data** ptr;
-        union Data* oldData;
-        union Data* newData;
-        enum Code checkAndSet;
-        enum Code next;
-        enum Code fail;
-    } Atomic;
-    struct AtomicReference {
-    } AtomicReference;
-    struct Semaphore {
-        union Data* semaphore;
-        enum Code p;
-        enum Code v;
-        enum Code next;
-    } Semaphore;
-    struct SemaphoreImpl {
-        int value;
-        struct Lock* lock;
-        struct Queue* waitThreadQueue;
-    } SemaphoreImpl;
-    struct Allocate {
-        enum Code next;
-        long size;
-    } Allocate;
-    struct Integer {
-        int value;
-    } Integer;
-    struct UInteger {
-        unsigned int value;
-    } UInteger;
-    struct SortArray {
-        struct Integer *array; //Array arrayじゃできない?
-        int loopCounter;
-        int block;
-        int first;
-        int prefix;
-    } SortArray;
-    struct Iterator {
-        union Data* iterator;
-        struct Context* task;
-        int numGPU;
-        enum Code exec;
-        enum Code barrier;
-        enum Code whenWait;
-        enum Code next;
-    } Iterator;
-    struct MultiDimIterator {
-        int x;
-        int y;
-        int z;
-        int count;
-        int counterX;
-        int counterY;
-        int counterZ;
-    } MultiDimIterator;
-    struct MultiDim {
-        int x;
-        int y;
-        int z;
-    } MultiDim;
-    struct Executor {
-        union Data* executor;
-        struct Context* task;
-        enum Code read;
-        enum Code exec;
-        enum Code write;
-        enum Code next;
-    } Executor;
-#ifdef USE_CUDAWorker
-    struct CUDAExecutor {
-        CUdeviceptr** kernelParams;
-        struct CUDABuffer* buffer;
-        int maxThreadPerBlock;
-        int maxThreadPerBlockX;
-        int maxThreadPerBlockY;
-        int maxThreadPerBlockZ;
-        struct Timer* timer;
-    } CUDAExecutor;
-    struct CUDABuffer {
-        int inputLen;
-        int outputLen;
-        union Data** inputData;
-        union Data** outputData;
-    } CUDABuffer;
-    CUdeviceptr CUdeviceptr;
-#else
-    struct CUDAExecutor {
-    } CUDAExecutor;
-    struct CUDABuffer {
-    } CUDABuffer;
-    CUdeviceptr CUdeviceptr;
-#endif
-    Int Int;
-    struct Memory {
-        union Data* adr;
-        int length;
-        union Data* body;
-        int hash;
-    } Memory;
-    struct Buffer {
-        union Data* buffer;
-        union Data* data;
-        enum Code put;
-        enum Code take;
-        enum Code next;
-    } Buffer;
-    struct BoundedBuffer {
-        struct Element* top;
-        struct Element* last;
-        struct Semaphore* fullCount;
-        struct Semaphore* emptyCount;
-        struct Semaphore* lock;
-    } BoundedBuffer;
-    struct Lock {
-        union Data* lock;
-        enum Code doLock;
-        enum Code doUnlock;
-        enum Code next;
-    } Lock;
-    struct LockImpl {
-        Int* lock;
-        struct Queue* waitThreadQueue;
-        struct Atomic* atomic;
-        struct Context* lockContext;
-    } LockImpl;
-    struct SpinLock {
-        volatile Int* lock;
-        struct Atomic* atomic;
-        struct Context* lockContext;
-    } SpinLock;
-    /* CbCxv6 cbc_context*/
-    struct Uinteger {
-        unsigned int value;
-    } Uinteger;
-    struct Short {
-       short value;
-    } Short;
-    struct String {
-      char* string;
-    } String;
-    struct CbCPipe {
-        struct pipe *p;
-    } CbCPipe;
-    struct PipeRead {
-        struct CbCPipe *pipe;
-        struct String *addr; 
-        struct Integer* i;
-    } PipeRead;
-    struct SysRead {
-        union  Data* sys_read;
-        struct UInteger* num;
-        int n;
-        struct String *p;
-        enum Code read;
-        enum Code next;
-    } SysRead;
-    struct FileRead {
-        struct file *f;
-    } FileRead;
-}; // union Data end       this is necessary for cbc_context generator
-
-/*
-        struct cbc_console_arg {
-            int n;
-            int target;
-            char* dst;
-            struct inode *ip;
-            struct file *f;
-            int num;
-            struct pipe *p;
-            char *addr;
-            int i;
-            __code (*next)(int ret);
-        } cbc_console_arg;
-*/
-
-typedef union Data Data;
-
-#include "c/typedefData.h"
-
-#include "c/extern.h"
-
-extern __code start_code(struct Context* cbc_context);
-extern __code exit_code(struct Context* cbc_context);
-extern __code meta(struct Context* cbc_context, enum Code next);
-//extern __code par_meta(struct Context* cbc_context, enum Code spawns, enum Code next);
-extern __code parGotoMeta(struct Context* cbc_context, enum Code next);
-extern void initContext(struct Context* cbc_context);
-
-// #endif
--- a/src/file.h	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/file.h	Mon Dec 16 21:55:29 2019 +0900
@@ -10,6 +10,8 @@
 } file;
 */
 // in-memory copy of an inode
+
+/*
 struct inode {
     uint    dev;        // Device number
     uint    inum;       // Inode number
@@ -23,9 +25,13 @@
     uint    size;
     uint    addrs[NDIRECT+1];
 };
+*/
+
 #define I_BUSY 0x1
 #define I_VALID 0x2
 
+
+
 // table mapping major device number to
 // device functions
 struct devsw {
--- a/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/gearsTools/lib/Gears/Context/Template/XV6.pm	Mon Dec 16 21:55:29 2019 +0900
@@ -109,8 +109,13 @@
 
 #define GearImpl(cbc_context, intf, name) (Gearef(cbc_context, intf)->name->intf.name)
 
+#ifndef CBC_XV6_CONTEXT
+#define CBC_XV6_CONTEXT TRUE
+
 #include "c/enumCode.h"
 
+#include "types.h"
+
 enum Relational {
     EQ,
     GT,
@@ -120,6 +125,7 @@
 #include "c/enumData.h"
 #define NDIRECT 12 //fs.h
 
+
 struct Context {
     enum Code next;
     struct Worker* worker;
@@ -169,6 +175,7 @@
     struct Context Context;
 }; // union Data end       this is necessary for context generator
 typedef union Data Data;
+#endif
 EOF
 }
 
@@ -176,6 +183,9 @@
 sub emit_last_header {
   my($class, $out) = @_;
   print $out <<'EOF';
+
+
+
 #include "c/typedefData.h"
 
 #include "c/extern.h"
--- a/src/impl/FileRead.h	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/impl/FileRead.h	Mon Dec 16 21:55:29 2019 +0900
@@ -1,6 +1,3 @@
 typedef struct FileRead<Type, Isa> impl SysRead {
   struct file* f;
-  int r;
-  __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...));
-  __code next(...);
 } FileRead;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/impl/SysOpenImpl.h	Mon Dec 16 21:55:29 2019 +0900
@@ -0,0 +1,3 @@
+typedef struct SysOpenImpl <Type, Isa> impl SysOpen {
+
+} SysOpenImpl;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/inode.h	Mon Dec 16 21:55:29 2019 +0900
@@ -0,0 +1,13 @@
+typedef struct inode <Impl> {
+    uint    dev;        // Device number
+    uint    inum;       // Inode number
+    int     ref;        // Reference count
+    int     flags;      // I_BUSY, I_VALID
+
+    short   type;       // copy of disk inode
+    short   major;
+    short   minor;
+    short   nlink;
+    uint    size;
+    uint    addrs[NDIRECT+1];
+} inode;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/interface/SysOpen.h	Mon Dec 16 21:55:29 2019 +0900
@@ -0,0 +1,12 @@
+typedef struct SysOpen<Type, Impl>{
+  union  Data* sys_open;
+   int fd;
+   int omode;
+   char* addr;
+   struct file* file;
+   struct inode* ip;
+
+   __code open(Impl* sys_open, int fd, int omode, char* addr, struct file* file, struct inode* ip, __code next(...));
+
+   __code next(...);
+} SysOpen;
--- a/src/proc.h	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/proc.h	Mon Dec 16 21:55:29 2019 +0900
@@ -3,6 +3,7 @@
 #define PROC_INCLUDE_
 #include "context.h"
 
+
 // Per-CPU state, now we only support one CPU
 struct cpu {
     uchar           id;             // index into cpus[] below
@@ -20,7 +21,6 @@
 extern struct cpu cpus[NCPU];
 extern int ncpu;
 
-
 extern struct cpu* cpu;
 extern struct proc* proc;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sys_open_impl.cbc	Mon Dec 16 21:55:29 2019 +0900
@@ -0,0 +1,30 @@
+#include "../context.h"
+#interface "SysOpen.h"
+
+// ----
+// typedef struct SysOpenImpl <Type, Isa> impl SysOpen {
+//
+// } SysOpenImpl;
+// ----
+
+SysOpen* createSysOpenImpl(struct Context* cbc_context) {
+    struct SysOpen* sys_open  = new SysOpen();
+    struct SysOpenImpl* sys_open_impl = new SysOpenImpl();
+    sys_open->sys_open = (union Data*)sys_open_impl;
+    sys_open->fd  = 0;
+    sys_open->omode  = 0;
+    sys_open->addr = NULL;
+    sys_open->file = NULL;
+    sys_open->ip = NULL;
+    sys_open->open = C_openSysOpenImpl;
+    sys_open->next = C_nextSysOpenImpl;
+    return sys_open;
+}
+__code openSysOpenImpl(struct SysOpenImpl* sys_open, int fd, int omode, char* addr, struct file* file, struct inode* ip, __code next(...)) {
+
+  goto next(...);
+}
+
+__code nextSysOpenImpl(...) {
+
+}
--- a/src/usr/CMakeLists.txt	Mon Dec 16 21:38:50 2019 +0900
+++ b/src/usr/CMakeLists.txt	Mon Dec 16 21:55:29 2019 +0900
@@ -57,17 +57,16 @@
             list(APPEND _Gears_CBC_SOURCES ${j})
         else()
             set(j ${i})
-            file(COPY "${CMAKE_SOURCE_DIR}/context.h" DESTINATION "${CMAKE_BINARY_DIR}/usr/${_Gears_TARGET}.dir")
             list(APPEND _Gears_CSOURCES ${j})
         endif()
     endforeach(i)
 
     add_custom_command (
-          OUTPUT    ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c
+          OUTPUT    CMakeFiles/${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c
           DEPENDS   ${_Gears_CBC_SOURCES}
-          COMMAND  "cd" "${_Gears_TARGET}.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} "-w" ${CMAKE_SOURCE_DIR}/usr/${_Gears_CSOURCES}
+          COMMAND  "cd" "CMakeFiles/${_Gears_TARGET}.dir" ";" "perl" "${CMAKE_SOURCE_DIR}/gearsTools/generate_context.pl" "-o" ${_Gears_TARGET} "-w" ${CMAKE_SOURCE_DIR}/usr/${_Gears_CSOURCES}
     )
-    add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} ${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c )
+    add_executable(${_Gears_TARGET} ${_Gears_CBC_SOURCES} ${_Gears_CSOURCES} CMakeFiles/${_Gears_TARGET}.dir/c/${_Gears_TARGET}-context.c )
     target_link_libraries(${_Gears_TARGET} ulib)
 endmacro()