Parcourir la source

removed oudated files

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7984 8c9fc860-2736-0410-a75d-ab315db34111
eth.guenter il y a 7 ans
Parent
commit
a7117f16cb

+ 0 - 20
UnixAos/boot/Makefile.darwin

@@ -1,20 +0,0 @@
-#
-
-CC      = gcc -m32
-CFLAGS  = -DDARWIN -I/usr/X11R6/include
-LDFLAGS = -lpthread -L/usr/X11R6/lib -lX11 -lXext -lm
-
-
-
-aos.darwin:	aos.o Threads.darwin.o 
-	$(CC) -o aos.darwin aos.o Threads.darwin.o  $(LDFLAGS) \
-		-arch i386 -framework CoreServices
-	rm -f *.o 
-
-aos.o:	aos.c
-	$(CC) -c $(CFLAGS) aos.c
-
-Threads.darwin.o:	Threads.h Threads.darwin.c
-	$(CC) -c $(CFLAGS) Threads.darwin.c 
-
-

+ 0 - 18
UnixAos/boot/Makefile.linux

@@ -1,18 +0,0 @@
-#
-
-CC      = gcc -m32
-CFLAGS  = -DLINUX 
-LDFLAGS = -lpthread -ldl -lX11 -lrt -lm
-
-
-aos.linux:	aos.o Threads.linux.o
-	$(CC) -s -o aos.linux aos.o Threads.linux.o $(LDFLAGS)
-	rm -f *.o 
-
-aos.o:	aos.c
-	$(CC) -c $(CFLAGS) aos.c
-
-Threads.linux.o:	Threads.h Threads.linux.c
-	$(CC) -c $(CFLAGS) Threads.linux.c 
-
-

+ 0 - 19
UnixAos/boot/Makefile.solaris

@@ -1,19 +0,0 @@
-#
-
-CC=gcc  -m32
-CFLAGS  = -DSOLARIS
-LDFLAGS = -lthread -lX11 -ldl -lrt -lm
-
-all:	aos.solaris 
-	rm -f *.o
-
-aos.solaris:	aos.o Threads.solaris.o
-	$(CC) -s -o aos.solaris aos.o Threads.solaris.o $(LDFLAGS)
-
-aos.o:	aos.c
-	$(CC) -c $(CFLAGS) aos.c
-
-Threads.solaris.o:	Threads.h Threads.solaris.c
-	$(CC) -c $(CFLAGS) Threads.solaris.c 
-
-

+ 17 - 21
UnixAos/boot/OberonLoader.c

@@ -32,8 +32,9 @@
 typedef void (*OberonProc)();
 typedef void *addr;
 typedef unsigned int uint;
+typedef unsigned long ulong;
 
-typedef struct {  /* cf. Generic.Unix.*.Glue.Mod */
+typedef struct {  /* cf. Unix.*.Glue.Mod */
     /* Oberon --> loader: */
     char id[24];		/* must match coreID */
     int  codesize;	
@@ -50,14 +51,14 @@ typedef struct {  /* cf. Generic.Unix.*.Glue.Mod */
 } *Header;
 
 #if defined(__LP64__) || defined(_LP64)
-   char *coreID = "Oberon64G.binary";	/* cf. Generic.Unix.AMD64.Glue.Mod */
+   char *coreID = "Oberon64G.binary";	/* cf. Unix.AMD64.Glue.Mod */
 #else
-   char *coreID = "Oberon32G.binary";	/* cf. Generic.Unix.I386.Glue.Mod */
+   char *coreID = "Oberon32G.binary";	/* cf. Unix.I386.Glue.Mod */
 #endif
 
-addr buf;
+addr heap;
+uint heapsize;
 int fd;
-uint bufsize;
 
 void cout( char c ) {
    char buf[8];
@@ -80,12 +81,8 @@ void Relocate( uint relocations ) {
    uint i;
 
    for (i=0; i<relocations; i++) {
-      a = buf + ReadInteger();
-#if defined(__LP64__) || defined(_LP64)
-      *a = buf+(ulong)(*a);
-#else
-      *a = buf+(uint)(*a);
-#endif
+      a = heap + ReadInteger();
+      *a += (ulong)heap;
    }
 }
 
@@ -118,8 +115,7 @@ int main( int argc, char *argv[], char *env[] ) {
    size_t fsize;
    struct stat sb;
    Header header;
-   char *path;
-   addr a;
+   char *path, *buf;
 
    fd = open( *argv, O_RDONLY );
    if (fd < 0) {
@@ -142,20 +138,20 @@ int main( int argc, char *argv[], char *env[] ) {
    }
    binsize = header->codesize;
    relocations = header->relocations;
+   free( buf );
 
-   bufsize = BlkSize;
-   while (bufsize < binsize) bufsize += BlkSize;
-   r = lseek( fd, Offset, SEEK_SET );
+   heapsize = BlkSize;
+   while (heapsize < binsize) heapsize += BlkSize;
 
-   free( buf );
-   r = posix_memalign( &buf, BlkSize, bufsize );
-   if (mprotect( buf, bufsize, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
+   r = lseek( fd, Offset, SEEK_SET );
+   r = posix_memalign( &heap, BlkSize, heapsize );
+   if (mprotect( heap, heapsize, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
       perror("mprotect");
-   n = read( fd, buf, binsize );
+   n = read( fd, heap, binsize );
 
    Relocate( relocations );
 
-   header = (Header)buf;
+   header = (Header)heap;
    *(header->dlopenaddr) = dlopen;
    *(header->dlcloseaddr) = dlclose;
    *(header->dlsymaddr) = dlsym;

+ 0 - 246
UnixAos/boot/Threads.darwin.c

@@ -1,246 +0,0 @@
-
-/*--------- threads support ------------------------- g.f. -----*/
-/*--------- lower half of the Oberon Threads module             */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include <signal.h>
-#include <semaphore.h>
-#include <errno.h>
-#include "Threads.h"
-
-
-extern int suid_root;
-extern int debug;
-
-extern void SetSigaltstack();
-
-static o_thr_t mainthread = 0;
-
-
-
-void 
-o_thrSleep(int ms) {
-
-    struct timespec sltime, rem;
-
-    sltime.tv_sec = ms/1000;
-    sltime.tv_nsec = 1000000*(ms%1000);
-    while (nanosleep( &sltime, &rem ) < 0 && errno == EINTR)
-    	sltime = rem;
-}
-
-
-o_mtx_t 
-o_mtxInit(int dummy) {
-    o_mtx_t mtx;
-
-    mtx = (o_mtx_t)malloc( sizeof(pthread_mutex_t) );
-    pthread_mutex_init( mtx, NULL );
-    return mtx;
-}
-
-
-
-void 
-o_mtxDestroy(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_destroy( mtx );
-    free( mtx );
-}
-
-
-
-void 
-o_mtxLock(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_lock( mtx );
-}
-
-
-
-void 
-o_mtxUnlock(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_unlock( mtx );
-}
-
-
-o_con_t 
-o_conInit(int dymmy) {
-    o_con_t	c;
-
-    c = (o_con_t)malloc( sizeof(pthread_cond_t) );
-    pthread_cond_init( c, NULL );
-    return c;
-}
-
-void 
-o_conDestroy(o_con_t c) {
-    
-    pthread_cond_destroy( c );
-    free( c );
-}
-
-void 
-o_conWait( o_con_t c, o_mtx_t m ) {
-    
-    pthread_cond_wait( c, m );
-}
-
-void 
-o_conSignal( o_con_t c ) {
-    
-    pthread_cond_signal( c );
-}
-
-
-static void *
-starter(void *p) {
-    o_thr_t me = pthread_self();
-    oberon_proc proc = (oberon_proc)p;
-    sigset_t old, new;
-    struct sched_param param;
-
-    SetSigaltstack();
-    sigfillset( &new );
-    sigdelset( &new, SIGILL );
-    sigdelset( &new, SIGTRAP );
-    sigdelset( &new, SIGFPE );
-    sigdelset( &new, SIGBUS );
-    sigdelset( &new, SIGSEGV );
-    sigdelset( &new, SIGTERM );
-    pthread_sigmask( SIG_SETMASK, &new, &old );
-
-    pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, NULL );
-    pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
-    param.sched_priority = 0;
-    pthread_setschedparam( me, SCHED_OTHER, &param );
-
-    proc();
-
-    pthread_exit( NULL );
-    return NULL;
-}
-
-
-
-o_thr_t 
-o_thrStart( oberon_proc p, int len ) {
-    
-    o_thr_t id;
-    pthread_attr_t attr;
-     
-    if (len < PTHREAD_STACK_MIN) len = PTHREAD_STACK_MIN;
-    pthread_attr_init( &attr );
-    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
-    pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
-    pthread_attr_setstacksize( &attr, len );
-    if (pthread_create( &id, &attr, starter, p ) != 0) return 0;
-    return id;
-}
-
-
-
-o_thr_t 
-o_thrThis(int dummy) {
-
-    return pthread_self();
-}
-
-
-
-void 
-o_thrYield(int dummy) {
-
-    o_thrSleep( 1 );
-}
-
-
-
-void 
-o_thrExit(int dummy) {
-    
-    pthread_exit( 0 );
-}
-
-
-void 
-o_thrSuspend(o_thr_t thr) {
-    mach_port_t mthread;
-
-    mthread = pthread_mach_thread_np(thr);
-    thread_suspend(mthread);
-}
-
-
-
-void 
-o_thrResume(o_thr_t thr) {
-    mach_port_t mthread;
-
-    mthread = pthread_mach_thread_np(thr);
-    thread_resume(mthread);
-}
-
-
-void 
-o_thrSetprio(o_thr_t thr, int prio) {
-
-    struct sched_param param;
-    int policy;
-
-
-    pthread_getschedparam( thr, &policy, &param );
-    param.sched_priority = prio;
-    if (pthread_setschedparam( thr, SCHED_OTHER, &param ) != 0)
-    	perror("pthread_setschedparam");
-}
-
-
-
-int 
-o_thrGetprio(o_thr_t thr) {
-
-    struct sched_param param;
-    int policy;
-
-    pthread_getschedparam( thr, &policy, &param );
-    return ( param.sched_priority );
-}
-
-
-
-void 
-o_thrKill(o_thr_t thr, int sig) {
-
-    pthread_kill( thr, sig );
-/*  if (thr != mainthread) {
-    	pthread_detach( thr );
-    	if (thr == pthread_self())
-    	    pthread_exit( 0 );
-    	else {
-    	    pthread_cancel( thr );
-        } 
-    }	*/
-}
-
-
-
-int 
-o_thrInitialize( int *low, int* high ) {
-    struct sched_param param;
-    
-    mainthread = pthread_self();
-    *high = sched_get_priority_max(SCHED_OTHER);
-    *low = sched_get_priority_min(SCHED_OTHER);
-    param.sched_priority = *high;
-    pthread_setschedparam( mainthread, SCHED_OTHER, &param );
-
-    return 1;
-}
-
-
-

+ 0 - 43
UnixAos/boot/Threads.h

@@ -1,43 +0,0 @@
-
-
-#ifdef SOLARIS
-# include <thread.h>
-  typedef mutex_t *	o_mtx_t;
-  typedef cond_t *	o_con_t;
-  typedef thread_t	o_thr_t;
-#else
-  /*** Linux | Darwin ***/
-# include <pthread.h>
-  typedef pthread_mutex_t *	o_mtx_t;
-  typedef pthread_cond_t *	o_con_t;
-  typedef pthread_t		o_thr_t;
-#endif
-
-typedef void (*oberon_proc)();  /* Oberon procedure to be started as a new thread */
-
-extern o_mtx_t	o_mtxInit( );
-extern void	o_mtxDestroy( o_mtx_t mtx );
-extern void	o_mtxLock(    o_mtx_t mtx );
-extern void	o_mtxUnlock(  o_mtx_t mtx );
-
-extern o_con_t	o_conInit( );
-extern void	o_conDestroy( o_con_t con );
-extern void	o_conWait(    o_con_t con, o_mtx_t mtx );
-extern void	o_conSignal(  o_con_t con );
-
-
-
-extern o_thr_t	o_thrStart( oberon_proc p, int len );
-extern o_thr_t	o_thrThis( );
-extern void	o_thrSleep( int ms );
-extern void	o_thrYield( );
-extern void	o_thrExit( );
-extern void	o_thrSuspend( o_thr_t thr );
-extern void	o_thrResume(  o_thr_t thr );
-extern void	o_thrSetprio( o_thr_t thr, int prio );
-extern int 	o_thrGetprio( o_thr_t thr );
-extern void	o_thrKill(    o_thr_t thr, int sig );
-
-extern int 	o_thrInitialize( int* low, int* high );
-
-

+ 0 - 293
UnixAos/boot/Threads.linux.c

@@ -1,293 +0,0 @@
-
-/*--------- threads support ------------------------- g.f. -----*/
-/*--------- lower half of the Oberon Threads module             */
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <limits.h>
-#include <signal.h>
-#include <semaphore.h>
-#include <errno.h>
-#include <bits/local_lim.h>
-#include "Threads.h"
-
-
-extern int suid_root;
-extern int debug;
-
-extern void SetSigaltstack();
-
-static o_thr_t mainthread = 0;
-
-static struct sched_param oldparam;
-static int oldpolicy;
-
-#define	T_SIGSUSPEND	SIGUSR1
-#define	T_SIGRESUME	SIGUSR2
-
-static struct sigaction sasuspend, saresume;
-static pthread_mutex_t suspend_mutex;
-static int suspend_done;
-static int resume_done;
-
-
-void 
-o_thrSleep(int ms) {
-
-    struct timespec sltime, rem;
-
-    sltime.tv_sec = ms/1000;
-    sltime.tv_nsec = 1000000*(ms%1000);
-    while (nanosleep( &sltime, &rem ) < 0 && errno == EINTR)
-    	sltime = rem;
-}
-
-
-o_mtx_t 
-o_mtxInit(int dummy) {
-    o_mtx_t mtx;
-
-    mtx = (o_mtx_t)malloc( sizeof(pthread_mutex_t) );
-    pthread_mutex_init( mtx, NULL );
-    return mtx;
-}
-
-
-
-void 
-o_mtxDestroy(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_destroy( mtx );
-    free( mtx );
-}
-
-
-
-void 
-o_mtxLock(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_lock( mtx );
-}
-
-
-
-void 
-o_mtxUnlock(o_mtx_t mtx) {
-    
-    (void)pthread_mutex_unlock( mtx );
-}
-
-
-o_con_t 
-o_conInit(int dymmy) {
-    o_con_t	c;
-
-    c = (o_con_t)malloc( sizeof(pthread_cond_t) );
-    pthread_cond_init( c, NULL );
-    return c;
-}
-
-void 
-o_conDestroy(o_con_t c) {
-    pthread_cond_destroy( c );
-    free( c );
-}
-
-void 
-o_conWait( o_con_t c, o_mtx_t m ) {
-    pthread_cond_wait( c, m );
-}
-
-void 
-o_conSignal( o_con_t c ) {
-    pthread_cond_signal( c );
-}
-
-
-static void *
-starter(void *p) {
-    o_thr_t me = pthread_self();
-    oberon_proc proc = (oberon_proc)p;
-    sigset_t old, new;
-    struct sched_param param;
-
-    SetSigaltstack();
-    sigfillset( &new );
-    sigdelset( &new, SIGILL );
-    sigdelset( &new, SIGTRAP );
-    sigdelset( &new, SIGFPE );
-    sigdelset( &new, SIGBUS );
-    sigdelset( &new, SIGSEGV );
-    sigdelset( &new, SIGTERM );
-    sigdelset( &new, T_SIGSUSPEND );
-    //sigdelset( &new, T_SIGRESUME );
-    pthread_sigmask( SIG_SETMASK, &new, &old );
-
-    pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, NULL );
-    pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
-    param.sched_priority = 0;
-    pthread_setschedparam( me, SCHED_OTHER, &param );
-
-    proc();
-
-    pthread_exit( NULL );
-    return NULL;
-}
-
-
-
-o_thr_t 
-o_thrStart( oberon_proc p, int len ) {
-    
-    o_thr_t id;
-    pthread_attr_t attr;
-     
-    if (len < PTHREAD_STACK_MIN) len = PTHREAD_STACK_MIN;
-    pthread_attr_init( &attr );
-    pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
-    pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
-    pthread_attr_setstacksize( &attr, len );
-    if (pthread_create( &id, &attr, starter, p ) != 0) return 0;
-    return id;
-}
-
-
-
-o_thr_t 
-o_thrThis(int dummy) {
-
-    return pthread_self();
-}
-
-
-
-void 
-o_thrYield(int dummy) {
-
-    o_thrSleep( 1 );
-}
-
-
-
-void 
-o_thrExit(int dummy) {
-    
-    pthread_exit( 0 );
-}
-
-
-
-void 
-o_thrSuspend(o_thr_t thr) {
-
-    pthread_mutex_lock( &suspend_mutex );
-    suspend_done = 0;
-    pthread_kill( thr, T_SIGSUSPEND );
-    while (suspend_done != 1) o_thrSleep( 1 );
-    pthread_mutex_unlock( &suspend_mutex );
-}
-
-
-static void 
-suspend_handler(int sig) {
-    sigset_t block;
-
-    sigfillset( &block );
-    sigdelset( &block, T_SIGRESUME );
-    suspend_done = 1;
-
-    sigsuspend( &block ); /* await T_SIGRESUME */
-
-    resume_done = 1;
-}
-
-
-
-static void 
-resume_handler(int sig) {
-}
-
-void 
-o_thrResume(o_thr_t thr) {
-    int n;
-
-    pthread_mutex_lock( &suspend_mutex );
-    resume_done = 0; n = 1;
-    pthread_kill( thr, T_SIGRESUME ); 
-    while (resume_done != 1 && n < 50) { o_thrSleep( 1 ); n++; }
-    pthread_mutex_unlock( &suspend_mutex );
-}
-
-
-
-void 
-o_thrSetprio(o_thr_t thr, int prio) {
-
-    struct sched_param param;
-    int policy;
-
-
-    pthread_getschedparam( thr, &policy, &param );
-    param.sched_priority = prio;
-    if (pthread_setschedparam( thr, SCHED_OTHER, &param ) != 0)
-    	perror("pthread_setschedparam");
-}
-
-
-
-int 
-o_thrGetprio(o_thr_t thr) {
-
-    struct sched_param param;
-    int policy;
-
-    pthread_getschedparam( thr, &policy, &param );
-    return ( param.sched_priority );
-}
-
-
-
-void 
-o_thrKill(o_thr_t thr, int sig) {
-
-    pthread_kill( thr, sig );
-/*  if (thr != mainthread) {
-    	pthread_detach( thr );
-    	if (thr == pthread_self())
-    	    pthread_exit( 0 );
-    	else {
-    	    pthread_cancel( thr );
-        } 
-    }	*/
-}
-
-
-
-int 
-o_thrInitialize( int *low, int* high ) {
-    struct sched_param param;
-    
-    pthread_mutex_init( &suspend_mutex, NULL );
-    mainthread = pthread_self();
-    *high = sched_get_priority_max(SCHED_OTHER);
-    *low = sched_get_priority_min(SCHED_OTHER);
-    param.sched_priority = *high;
-    pthread_setschedparam( mainthread, SCHED_OTHER, &param );
-
-    sigemptyset( &sasuspend.sa_mask );
-    sigaddset( &sasuspend.sa_mask, T_SIGRESUME );
-    sasuspend.sa_flags = 0;
-    sasuspend.sa_handler = suspend_handler;
-    sigaction( T_SIGSUSPEND, &sasuspend, NULL );
-
-    sigemptyset( &saresume.sa_mask );
-    saresume.sa_flags = 0;
-    saresume.sa_handler = resume_handler;
-    sigaction( T_SIGRESUME, &saresume, NULL );
-    
-    return 1;
-}
-
-
-

+ 0 - 178
UnixAos/boot/Threads.solaris.c

@@ -1,178 +0,0 @@
-
-/*--------- threads support ------------------------- g.f. -----*/
-/*--------- lower half of the Oberon Threads module             */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include "Threads.h"
-#define __EXTENSIONS__  1
-#include <pthread.h>
-#include <synch.h>
-#include <sched.h>
-
-extern int suid_root;
-static o_thr_t mainthread = 0;
-
-extern void SetSigaltstack();
-
-o_mtx_t o_mtxInit(int dummy) {
-    o_mtx_t mtx;
-
-    mtx = (o_mtx_t)malloc( sizeof(mutex_t) );
-    mutex_init( mtx, USYNC_THREAD, NULL );
-    return mtx;
-}
-
-void o_mtxDestroy(o_mtx_t mtx) {
-    mutex_destroy( mtx );
-    free( mtx );
-}
-
-
-void o_mtxLock(o_mtx_t mtx) {
-    mutex_lock( mtx );
-}
-
-
-void o_mtxUnlock(o_mtx_t mtx) {
-    mutex_unlock( mtx );
-}
-
-o_con_t o_conInit(int dummy) {
-    o_con_t	c;
-
-    c = (o_con_t)malloc( sizeof(cond_t) );
-    cond_init( c, USYNC_THREAD, NULL );
-    return c;
-}
-
-void o_conDestroy(o_con_t c) {
-    cond_destroy( c );
-    free( c );
-}
-
-void o_conWait( o_con_t c, o_mtx_t m ) {
-    cond_wait( c, m );
-}
-
-void o_conSignal( o_con_t c ) {
-   cond_signal( c );
-}
-
-void* starter( void* p ) {
-    sigset_t orig, new;
-    oberon_proc body = (oberon_proc)p;
-
-    SetSigaltstack();
-    sigfillset( &new );
-    sigdelset( &new, SIGILL );
-    sigdelset( &new, SIGTRAP );
-    sigdelset( &new, SIGEMT );
-    sigdelset( &new, SIGFPE );
-    sigdelset( &new, SIGBUS );
-    sigdelset( &new, SIGSEGV );
-    sigdelset( &new, SIGSYS );
-    sigdelset( &new, SIGPIPE );
-    sigdelset( &new, SIGALRM );
-    sigdelset( &new, SIGUSR1 );
-    thr_sigsetmask( SIG_SETMASK, &new, &orig );
-    pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, NULL );
-    pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL );
-    body();
-    thr_exit( 0 );
-}
-
-
-o_thr_t o_thrStart( oberon_proc p, int len ) {
-    o_thr_t id;
-    int	err;
-
-    if ((len != 0) && (len < 16*1024)) {
-        len =  16*1024;
-    }
-
-    err = thr_create( NULL, len, starter, p, THR_BOUND|THR_DETACHED, &id );
-    if (err != 0)
-        return 0;
-    return id;
-}
-
-
-o_thr_t o_thrThis(int dummy) {
-    return thr_self();
-}
-
-
-void o_thrSleep(int ms) {
-    struct timespec sltime, rem;
-
-    sltime.tv_sec = ms/1000;
-    sltime.tv_nsec = 1000000*(ms%1000);
-    nanosleep( &sltime, &rem );
-}
-
-
-void o_thrYield(int dummy) {
-    thr_yield( );
-}
-
-void o_thrExit(int dummy) {
-    thr_exit( 0 );
-}
-
-
-void o_thrSuspend(o_thr_t thr) {
-    thr_suspend( thr );
-}
-
-void o_thrResume(o_thr_t thr) {
-    thr_continue( thr );
-}
-
-
-void o_thrSetprio(o_thr_t thr, int prio) {
-    thr_setprio( thr, prio );
-}
-
-int o_thrGetprio(o_thr_t thr) {
-    int prio;
-
-    thr_getprio( thr, &prio );
-    return ( prio );
-}
-
-
-void o_thrKill(o_thr_t thr, int sig) {
-    thr_kill( thr, sig );
-/*    if (thr != mainthread) {
-        if (thr == thr_self())
-            thr_exit( 0 );
-        else 
-	    pthread_cancel( thr );
-    }  */
-}
-
-
-/* thr_initialize returns 0 (FALSE) if the program has
-   been compiled without threads suport. If the program
-   has no suid root privilleges, priorities are disabled
-   and low and high both return 0. */
-
-int o_thrInitialize( int *low, int* high ) {
-    int pl, ph, ret;
-    struct sched_param p;
-    pid_t pid;
-
-    pid = getpid();
-    sched_getparam( pid, &p );
-    ret = sched_setscheduler( pid, SCHED_OTHER, &p );
-    /*
-    pl = sched_get_priority_min( SCHED_OTHER );
-    ph = sched_get_priority_max( SCHED_OTHER );
-    */
-    mainthread = thr_self();
-    *low = 0;  *high = 100;
-    return 1;
-}
-

+ 0 - 486
UnixAos/boot/aos.c

@@ -1,486 +0,0 @@
-/*------------------------------------------------------
- * Oberon Boot File Loader RC, JS 27.4.93/2.12.93, HP-UX 9.0 Version
- *
- * Oberon Boot File Loader for Linux
- * derived from HP and Windows Boot Loader
- * MAD, 23.05.94
- * PR,  01.02.95  support for sockets added
- * PR,  05.02.95  support for V24 added
- * PR,  23.12.95  migration to shared ELF libraries
- * g.f. 01.11.99  added InstallTrap
- *		  added Threads support
- *		  removed cmd line parameter evaluation
- * g.f. 22.11.04  call to mprotect added
- * g.f. 03.04.07  Darwin/Intel version
- *
- *-----------------------------------------------------------*/
-
-#ifdef DARWIN
-#  undef 	__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
-#  define	__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__	1059
-#endif
-
-#ifdef LINUX
-#  define _use_valloc /* use the obsolete valloc function instead of posix_memalign */
-#endif
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <dlfcn.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <setjmp.h>	
-#ifdef DARWIN
-#  include <sys/ucontext.h>
-#  include <sys/_types.h>
-#  include <sys/signal.h>
-#endif
-#include <signal.h>
-#include <limits.h>
-#include "Threads.h"
-#include <sys/mman.h>
-#include <X11/Xlib.h>
-
-#define true 1
-#define false 0
-
-typedef void (*OberonProc)();
-
-typedef void*	address;
-typedef unsigned int ADDR32;
-
-FILE *fd;
-char *AOSPATH;
-char path[4096];
-char *dirs[255];
-char fullname[512];
-int nofdir;
-char defaultpath[] = ".:/usr/aos/obj:/usr/aos/system:/usr/aos/fonts/Oberon";
-#ifdef SOLARIS
-  char bootname[64] = "SolarisAosCore";
-#endif
-#ifdef LINUX
-  char bootname[64] = "LinuxAosCore";
-#endif
-#ifdef DARWIN
-  char bootname[64] = "DarwinAosCore";
-#endif
-
-size_t heapSize = 0x200000;
-size_t codeSize;
-address heapAdr, maxHeapAdr;
-int addrshift;
-unsigned int startOffset;
-int Argc;
-char **Argv;
-int debug;
-
-static stack_t sigstk;
-
-#define BLSIZE	4096
-#define SIGSTACKSIZE 64*BLSIZE
-
-typedef	void(*trap_t)(long, void*, void*, int);
-
-static trap_t	AosTrap;
-
-
-static void sighandler( int sig, siginfo_t *scp, void *ucp ) {
-	
-	if (debug | (AosTrap == NULL)) {
-	    printf("\nhandler for signal %d got called, ucp = %p\n", sig, ucp);
-	    if (AosTrap == NULL) exit(1);
-	}
-	AosTrap(0, ucp, scp, sig); /* rev. order: Oberon <--> C */
-}
-
-
-static void installHandler(int sig) {
-	struct sigaction act;
-	sigset_t mask;
-	sigemptyset(&mask);
-	act.sa_mask = mask;
-	if (sig == SIGSEGV)
-	    act.sa_flags = SA_SIGINFO|SA_ONSTACK|SA_NODEFER;
-	else 
-	    act.sa_flags = SA_SIGINFO|SA_NODEFER;
-	act.sa_sigaction = sighandler;
-	if (sigaction( sig, &act, NULL ) != 0) {
-		perror("sigaction");
-	}
-}
-
-
-void InitSignalHandler() {
-	int i;
-	
-	for (i = 1; i <= 15; i++) {
-	     if (i != 9) installHandler( i );
-	}
-}
-
-
-static void InstallTrap(trap_t p) {
-	
-	if (debug)
-		printf("Installing Aos Trap\n");
-	AosTrap = p;
-}
-
-
-void SetSigaltstack() {
-
-	if (sigaltstack(&sigstk, NULL) < 0)
-		perror("sigaltstack");
-}
-
-
-static void CreateSignalstack() {
-	sigstk.ss_sp = mmap( NULL, SIGSTACKSIZE, 
-			     PROT_READ | PROT_WRITE, 
-			     MAP_PRIVATE | MAP_ANON, 
-			     -1, 0);
-        if (sigstk.ss_sp == MAP_FAILED){
-		printf("mmap for signalstack failed\n" );
-		exit( 1 );
-	}
-	sigstk.ss_size = SIGSTACKSIZE;
-	sigstk.ss_flags = 0;
-	if (debug)
-		printf( "Signalstack created [%p ... %p]\n", 
-	 	        sigstk.ss_sp, sigstk.ss_sp + SIGSTACKSIZE );
-	SetSigaltstack();
-}
-
-
-
-void* o_dlopen(char *lib, int mode) {
-    void* handle;
-
-    if (debug&1) printf("o_dlopen: %s\n", lib);
-    if ((handle = dlopen(lib, mode)) == NULL) {
-        if (debug&1)
-	    printf("o_dlopen: %s not loaded, error = %s\n", lib, dlerror());
-    }
-    if (debug&1) printf("o_dlopen: handle = %p\n", handle);
-
-    return handle;
-}
-
-void o_dlclose(void* handle)	/* not necessary */
-{
-  dlclose(handle);
-}
-
-static int o_errno() {
-
-	return errno;
-}
-
-
-int o_stat(char* name, void* buf) {
-	return stat(name, (struct stat *) buf);
-}
-
-int o_lstat(char* name, void* buf) {
-	return lstat(name, (struct stat *) buf);
-}
-
-int o_fstat(int fd, void* buf) {
-	return fstat(fd, (struct stat *) buf);
-}
-
-int o_open(char* name, int flags, int mode) {
-	return open(name, flags, mode);
-}
-
-void *o_malloc( long size ) {
-	return malloc( size );
-}
-
-int o_posix_memalign(void** buf, long alignment, long size ) {
-#ifdef _use_valloc
-	*buf = valloc( size );
-	if (*buf != NULL) return 0; else return -1;
-#else
-	return posix_memalign( buf, alignment, size );
-#endif
-}
-
-int o_mprotect( void* addr, long len, int prot ) {
-	return mprotect( addr, len, prot );
-}
-
-int o_lseek( int fd, long pos, int whence ) {
-	return lseek( fd, pos, whence );
-}
-
-int o_cout( char c ) {
-	printf( "%c", c );
-}
-
-address o_paramtest(int p1, int p2, int p3, int p4, int p5, int p6, int p7, address p8){
-	printf("parameter test, p7=%d, p8=%p\n", p7, p8);
-	return (address)-8;
-}
-
-
-static void (*oberonXErrorHandler) (long p4, long p3, long err, long displ );
-static void (*oberonXIOErrorHandler) (long p4, long p3, long p2, long displ );
-
-static int X11ErrorHandler( Display *d, XErrorEvent *err ) {
-	printf( "X11ErrorHandler called\n" );
-	oberonXErrorHandler( 0, 0, (long)err, (long)d );
-}
-
-
-static int X11IOErrorHandler( Display *d ) {
-	printf( "X11IOErrorHandler called\n" );
-	oberonXIOErrorHandler( 0, 0, 0, (long)d );
-}
-
-
-void SetupXErrHandlers( void* XE, void* XIOE ) {
-	
-	if (debug)
-		printf( "Setup X11 ErrorHandlers\n" );
-	oberonXErrorHandler = XE;
-	oberonXIOErrorHandler = XIOE;
-	
-	XSetErrorHandler(X11ErrorHandler);
-	XSetIOErrorHandler(X11IOErrorHandler);	
-}
-
-
-void o_dlsym(void* handle, char* symbol, void** adr)
-{
-  if      (strcmp("dlopen",		symbol) == 0) *adr = o_dlopen;
-  else if (strcmp("dlclose",		symbol) == 0) *adr = o_dlclose;
-  else if (strcmp("debug",		symbol) == 0) *(int*)adr = debug;
-  else if (strcmp("heapAdr",		symbol) == 0) *adr = heapAdr;
-  else if (strcmp("heapSize",		symbol) == 0) *(size_t*)adr = heapSize;
-  else if (strcmp("argc",		symbol) == 0) *adr = &Argc;
-  else if (strcmp("argv",		symbol) == 0) *adr = Argv;
-  else if (strcmp("errno",		symbol) == 0) *adr = o_errno;
-  else if (strcmp("cout",		symbol) == 0) *adr = o_cout;
-  else if (strcmp("paramtest",		symbol) == 0) *adr = o_paramtest;
-  
-  else if (strcmp("open",		symbol) == 0) *adr = o_open;
-  else if (strcmp("stat",		symbol) == 0) *adr = o_stat;
-  else if (strcmp("lstat",		symbol) == 0) *adr = o_lstat;
-  else if (strcmp("fstat",		symbol) == 0) *adr = o_fstat;
-  else if (strcmp("lseek",		symbol) == 0) *adr = o_lseek;
-
-  else if (strcmp("malloc",		symbol) == 0) *adr = o_malloc;
-  else if (strcmp("posix_memalign",	symbol) == 0) *adr = o_posix_memalign;
-  else if (strcmp("mprotect",		symbol) == 0) *adr = o_mprotect;
-
-  else if (strcmp("InstallTrap",	symbol) == 0) *adr = InstallTrap;
-  else if (strcmp("InitXErrH", 		symbol) == 0) *adr = SetupXErrHandlers;
-#ifdef LINUX
-  else if (strcmp("sigsetjmp",		symbol) == 0) *adr = __sigsetjmp;
-  else if (strcmp("setjmp",		symbol) == 0) *adr = __sigsetjmp;
-#endif
-  else if (strcmp("mtxInit",   		symbol) == 0) *adr = o_mtxInit;
-  else if (strcmp("mtxDestroy", 	symbol) == 0) *adr = o_mtxDestroy;
-  else if (strcmp("mtxLock",    	symbol) == 0) *adr = o_mtxLock;
-  else if (strcmp("mtxUnlock",  	symbol) == 0) *adr = o_mtxUnlock;
-  else if (strcmp("conInit",  		symbol) == 0) *adr = o_conInit;
-  else if (strcmp("conDestroy", 	symbol) == 0) *adr = o_conDestroy;
-  else if (strcmp("conWait",  		symbol) == 0) *adr = o_conWait;
-  else if (strcmp("conSignal",  	symbol) == 0) *adr = o_conSignal;
-  else if (strcmp("thrStart",		symbol) == 0) *adr = o_thrStart;
-  else if (strcmp("thrThis",		symbol) == 0) *adr = o_thrThis;
-  else if (strcmp("thrSleep",		symbol) == 0) *adr = o_thrSleep;
-  else if (strcmp("thrYield",		symbol) == 0) *adr = o_thrYield;
-  else if (strcmp("thrExit",		symbol) == 0) *adr = o_thrExit;
-  else if (strcmp("thrSuspend",		symbol) == 0) *adr = o_thrSuspend;
-  else if (strcmp("thrResume",		symbol) == 0) *adr = o_thrResume;
-  else if (strcmp("thrGetPriority",	symbol) == 0) *adr = o_thrGetprio;
-  else if (strcmp("thrSetPriority",	symbol) == 0) *adr = o_thrSetprio;
-  else if (strcmp("thrKill",		symbol) == 0) *adr = o_thrKill;
-  else if (strcmp("thrInitialize",	symbol) == 0) *adr = o_thrInitialize;
-  else {
-    *adr = dlsym(handle, symbol);
-    if (*adr == 0) {
-      printf("o_dlsym: symbol %s not found\n", symbol); 
-    }
-  }
-}
-
-
-/*----- Files Reading primitives -----*/
-
-
-int Rint() {
-  unsigned char b[4]; int i;
-
-  /* read little endian integer */
-  for (i=0; i<4; i++) b[i] = fgetc(fd);
-  return *((int*)b);
-}
-
-address RAddress() {
-  unsigned char b[8]; int i;
-
-  /* read little endian address */
-  for (i=0; i<8; i++) b[i] = fgetc(fd);
-  return *((address*)b);
-}
-
-int RNum() {
-  int n, shift;
-  unsigned char x;
-
-  shift = 0; n = 0; x = fgetc(fd);
-  while (x >= 128) {
-    n += (x & 0x7f) << shift;
-    shift += 7;
-    x = fgetc(fd);
-  }
-  return n + (((x & 0x3f) - ((x >> 6) << 6)) << shift); 
-}
-
-int CheckAddr( int no, int ofs, address adr ){
-  if (adr >= heapAdr+startOffset & adr < maxHeapAdr) return 1;
-  else {
-    printf("bad relocation offset: no=%d, ofs=%x, pos=%p [%p...%p]\n", 
-            no, ofs, adr, heapAdr+startOffset, maxHeapAdr);
-    return 0;
-  }
-}
-
-void Assert( int no, int ofs, address adr ){
-  if (adr < heapAdr+startOffset || adr > maxHeapAdr)
-    printf("bad relocated pointer value: no=%d, ofs=%x, ptr=%p [%p...%p]\n", 
-            no, ofs, adr, heapAdr+startOffset, maxHeapAdr);
-}
-
-
-void Relocate() {
-  int no, len, ofs; ADDR32 *adr; ADDR32 val; 
-  
-  len = RNum(); no = 0;
-  if (debug) printf("relocate %d pointers\n", len);
-  while (len != 0) { 
-    ofs = RNum(); ++no;
-    adr = heapAdr + ofs;
-    if (CheckAddr(no, ofs, adr)) {
-      val = *adr;
-      val += addrshift;
-      *adr = val; 
-      Assert(no, ofs, (address)val); 
-    }
-    len--; 
-  } 
-}
-
-
-void Boot() {
-  address adr, fileHeapAdr, dlsymAdr;
-  size_t len, fileHeapSize;
-  int arch, d, notfound;  
-  OberonProc body;
-
-  if (sizeof(address)==8) strcat(bootname, ".amd64");
-  d = 0; notfound = 1;
-  while ((d < nofdir) && notfound) {
-    strcat(strcat(strcpy(fullname, dirs[d++]), "/"), bootname);
-    fd = fopen(fullname, "r");
-    if (fd != NULL) notfound = 0;
-  }
-  if (notfound) {
-    printf("Aos BootLoader: boot file %s not found\n", bootname);  
-    exit(-1);
-  }
-  arch = Rint();
-  if (arch != 8*sizeof(address)) {
-    printf("bootfile %s has wrong architecture, got %d, expected %d\n", 
-    	   bootname, arch, (int)(8*sizeof(address)) );
-    exit(-1);	
-  }
-  fileHeapAdr = RAddress(); 
-  fileHeapSize = Rint();
-  if (fileHeapSize > heapSize) {
-    printf("Aos BootLoader: heap too small\n");  
-    exit(-1);
-  }
-  adr = heapAdr; len = heapSize; 
-  while (len > 0) { 
-    *((int*)adr) = 0; 
-    len -= 4; adr += 4; 
-  } 
-  addrshift = heapAdr - fileHeapAdr;
-
-  
-  startOffset = Rint();
-  len = Rint();  /* used heap */
-  adr = heapAdr + startOffset;
-  while (len > 0) {
-    *(int*)adr = Rint(); adr += 4; len -= 4;
-  }
-  maxHeapAdr = adr - 32;
-  if (debug) printf("code loading done [%p .. %p]\n", heapAdr, adr);
-  body = (OberonProc)heapAdr + Rint();
-  dlsymAdr = heapAdr + Rint();
-  if (debug) printf("dlsymAdr, entrypoint: %p, %p\n", dlsymAdr, body);
-
-  Relocate();
-  *(address*)dlsymAdr = o_dlsym;
- 
-  fclose(fd);
-  if(mprotect((void*)heapAdr, heapSize, PROT_READ|PROT_WRITE|PROT_EXEC) != 0)
-     perror("mprotect");
-  if (debug) printf("jump to AOS entrypoint\n");
-  (*body)();
-}
-
-void InitPath() {
-  int pos;
-  char ch;
-  
-  if ((AOSPATH = getenv("AOSPATH")) == NULL) AOSPATH = defaultpath;
-  strcpy(path, AOSPATH);
-  pos = 0; nofdir = 0;
-  ch = path[pos++];
-  while (ch != '\0') {
-    while ((ch == ' ') || (ch == ':')) ch = path[pos++];
-    dirs[nofdir] = &path[pos-1];
-    while ((ch > ' ') && (ch != ':')) ch = path[pos++];
-    path[pos-1] = '\0';
-    nofdir ++;
-  }
-}
-
-
-int main(int argc, char *argv[])
-{
-  char* p;
-  void *a, *h;
-  
-  Argc = argc; Argv = argv;
-
-  debug = 0;
-  p = getenv("AOSDEBUG");
-  if (p != NULL) debug = atoi(p);
-  if (debug) {
-     printf( "UnixAos Boot Loader 06.01.2016\n" );
-     printf( "debug = %d\n", debug );
-  }
-  if (posix_memalign(&heapAdr, 4096, heapSize) != 0) {
-    printf("Aos BootLoader: cannot allocate initial heap space\n");  
-    exit(-1);
-  }
-
-  InitPath();
-  CreateSignalstack();
-  InitSignalHandler();
-  
-  Boot();
-  return 0;
-}
-