Fix tabbing.... Please fix your editors so they do tabbing correctly!!! (Spaces...
[IRC.git] / Robust / src / Runtime / runtime.h
index a0ad41f16e18e2c1219fb6c98dfa9631135c9e6d..1b70ea0023518ac83ae54474da0c046d561697df 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef RUNTIME
 #define RUNTIME
+#include <stdlib.h>
 #ifndef MULTICORE
 #include <setjmp.h>
 extern jmp_buf error_handler;
@@ -46,10 +47,10 @@ extern void * curr_heaptop;
 #define OBJECTARRAYINTERVAL 10
 
 #define ARRAYSET(array, type, index, value) \
-  ((type *)(& (& array->___length___)[1]))[index]=value
+  ((type *)(&(&array->___length___)[1]))[index]=value
 
 #define ARRAYGET(array, type, index) \
-  ((type *)(& (& array->___length___)[1]))[index]
+  ((type *)(&(&array->___length___)[1]))[index]
 
 #ifdef OPTIONAL
 #define OPTARG(x) , x
@@ -79,27 +80,34 @@ __attribute__((malloc)) void * allocate_new(void *, int type);
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
 #endif
 __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
+__attribute__((malloc)) struct ___String___ * NewStringShort(void *, const short *str,int length);
 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
 #elif defined MULTICORE_GC
 __attribute__((malloc)) void * allocate_new(void *, int type);
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(void *, int type, int length);
 __attribute__((malloc)) struct ___String___ * NewString(void *, const char *str,int length);
+__attribute__((malloc)) struct ___String___ * NewStringShort(void *, const short *str,int length);
 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(void *ptr, int index);
 #else
 __attribute__((malloc)) void * allocate_new(int type);
 __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int length);
 __attribute__((malloc)) struct ___String___ * NewString(const char *str,int length);
+__attribute__((malloc)) struct ___String___ * NewStringShort(const short *str,int length);
 __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index);
 #endif
 
 
 
 void initializeexithandler();
-void failedboundschk();
-void failednullptr();
+void failedboundschk(int num);
+void failednullptr(void * stackptr);
 void abort_task();
 void injectinstructionfailure();
+#ifdef MULTICORE
+void createstartupobject(int argc, char ** argv);
+#else
 void createstartupobject();
+#endif
 
 #ifdef PRECISE_GC
 #define VAR(name) ___params___->name
@@ -113,6 +121,18 @@ void createstartupobject();
 #define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
 #define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
 #define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(struct name ## _params * ___params___, rest, rest2, rest3)
+#elif defined MULTICORE_GC
+#define VAR(name) ___params___->name
+#define CALL00(name) name(struct name ## _params * ___params___)
+#define CALL01(name, alt) name(struct name ## _params * ___params___)
+#define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___)
+#define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest)
+#define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest)
+#define CALL22(name, rest, rest2, alt1, alt2) name(struct name ## _params * ___params___, rest, rest2)
+#define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2)
+#define CALL24(name, rest, rest2, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2)
+#define CALL34(name, rest, rest2, rest3, alt1, alt2, alt3, alt4) name(struct name ## _params * ___params___, rest, rest2, rest3)
+#define CALL35(name, rest, rest2, rest3, alt1, alt2, alt3, alt4, alt5) name(struct name ## _params * ___params___, rest, rest2, rest3)
 #else
 #define VAR(name) name
 #define CALL00(name) name()
@@ -137,6 +157,25 @@ inline void setupsmemmode(void);
 #endif
 #endif
 
+#ifdef THREADS
+#define MAXLOCKS 256
+
+struct lockpair {
+  struct ___Object___ *object;
+  int islastlock;
+};
+
+struct lockvector {
+  int index;
+  struct lockpair locks[MAXLOCKS];
+};
+
+#ifndef MAC
+extern __thread struct lockvector lvector;
+extern __thread int mythreadid;
+#endif
+#endif
+
 #ifdef TASK
 #ifndef MULTICORE
 #include "chash.h"
@@ -148,6 +187,7 @@ inline void setupsmemmode(void);
 #include "optionalstruct.h"
 #endif
 
+
 #ifdef OPTIONAL
 struct failedtasklist {
   struct taskdescriptor *task;
@@ -244,18 +284,16 @@ int enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr
 
 #if defined(__i386__)
 
-static __inline__ unsigned long long rdtsc(void)
-{
+static __inline__ unsigned long long rdtsc(void) {
   unsigned long long int x;
   __asm__ volatile (".byte 0x0f, 0x31" : "=A" (x));
   return x;
 }
 #elif defined(__x86_64__)
 
-static __inline__ unsigned long long rdtsc(void)
-{
+static __inline__ unsigned long long rdtsc(void) {
   unsigned hi, lo;
-  __asm__ __volatile__ ("rdtsc" : "=a"(lo), "=d"(hi));
+  __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
   return ( (unsigned long long)lo)|( ((unsigned long long)hi)<<32 );
 }
 
@@ -263,19 +301,18 @@ static __inline__ unsigned long long rdtsc(void)
 
 typedef unsigned long long int unsigned long long;
 
-static __inline__ unsigned long long rdtsc(void)
-{
+static __inline__ unsigned long long rdtsc(void) {
   unsigned long long int result=0;
   unsigned long int upper, lower,tmp;
-  __asm__ volatile(
-      "0:                  \n"
-      "\tmftbu   %0           \n"
-      "\tmftb    %1           \n"
-      "\tmftbu   %2           \n"
-      "\tcmpw    %2,%0        \n"
-      "\tbne     0b         \n"
-      : "=r"(upper),"=r"(lower),"=r"(tmp)
-                  );
+  __asm__ volatile (
+    "0:                  \n"
+    "\tmftbu   %0           \n"
+    "\tmftb    %1           \n"
+    "\tmftbu   %2           \n"
+    "\tcmpw    %2,%0        \n"
+    "\tbne     0b         \n"
+    : "=r" (upper),"=r" (lower),"=r" (tmp)
+    );
   result = upper;
   result = result<<32;
   result = result|lower;