Explorar el Código

added Makefile and OberonLoader.c

git-svn-id: https://svn.inf.ethz.ch/svn/lecturers/a2/trunk@7419 8c9fc860-2736-0410-a75d-ab315db34111
eth.guenter hace 7 años
padre
commit
e0c7e3e1fe

+ 0 - 82
UnixAos/boot/A2Loader.c

@@ -1,82 +0,0 @@
-/* 
-   G.F. 31.01.2017
-
-   Loader for the statically linked A2 core.
-
-   Compile command:
-      gcc -m32 A2Loader.c -ldl -o A2Loader.elf
-
-   The command 'A2Loader.elf -h' shows the needed
-   displacement of the A2 core.
-
-   The A2 core has to be appended to the binary of this 
-   program by the A2 command:
-      SolarisELF.Build Solaris32G.elf ~
-
-*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <dlfcn.h>
-
-#define Offset 10*1024		/* beginning of the A2 core */
-#define Bufsize 2*1024*1024
-
-typedef void (*OberonProc)();
-typedef void *addr;
-
-typedef struct {  /* cf. Glue.EntryPoint */
-    char id[32];		/* must match coreID */
-    void *displacement;		/* must match address of buf */
-    OberonProc entry;		/* Glue.Init0 */
-    addr *dlopenaddr;
-    addr *dlcloseaddr;
-    addr *dlsymaddr;
-    int  *argc;
-    addr *argv;
-    addr *env;
-} *A2Header;
-
-char *coreID = "Oberon32G.core";
-
-int main( int argc, char *argv[], char *env[] ) {
-   int r, n, fd;
-   size_t fsize;
-   struct stat sb;
-   void *buf;
-   A2Header header;
-   char path[64];
-   addr a;
-
-   r = posix_memalign( &buf, 64*1024, Bufsize );
-   if ((argc == 2) && (strcmp(argv[1], "-h") == 0)) {
-      printf("Core displacement must be 0x%x\n", buf );
-      exit( 0 );
-   }
-   r = mprotect( buf, Bufsize, PROT_READ+PROT_WRITE+PROT_EXEC );
-   a = realpath( argv[0], path );
-   fd = open( path, O_RDONLY );
-   r = fstat( fd, &sb );
-   fsize = sb.st_size;
-   r = lseek( fd, Offset, SEEK_SET );
-   n = read( fd, buf, fsize - Offset );
-   header = (A2Header)buf;
-   if (strcmp(header->id, coreID) != 0) {
-      printf( "bad headerId: %s, expected: %s\n", header->id, coreID );
-      exit( 2 );
-   }
-   if (header->displacement != buf) {
-      printf( "bad displacement: %x, expected: %x\n", header->displacement, buf );
-      exit( 3 );
-   }
-   *(header->dlopenaddr) = dlopen;
-   *(header->dlcloseaddr) = dlclose;
-   *(header->dlsymaddr) = dlsym;
-   *(header->argc) = argc;
-   *(header->argv) = argv;
-   *(header->env) = env;
-   header->entry();
-}

BIN
UnixAos/boot/A2Loader.elf


+ 3 - 0
UnixAos/boot/Makefile

@@ -0,0 +1,3 @@
+
+OberonLoader:	OberonLoader.c
+	gcc -m32 OberonLoader.c -ldl -lc -o OberonLoader

+ 1 - 4
UnixAos/boot/Makefile.solaris

@@ -4,12 +4,9 @@ CC=gcc  -m32
 CFLAGS  = -DSOLARIS
 LDFLAGS = -lthread -lX11 -ldl -lrt -lm
 
-all:	A2Loader.elf aos.solaris 
+all:	aos.solaris 
 	rm -f *.o
 
-A2Loader.elf:	A2Loader.c
-	$(CC) -ldl -o A2Loader.elf A2Loader.c
-
 aos.solaris:	aos.o Threads.solaris.o
 	$(CC) -s -o aos.solaris aos.o Threads.solaris.o $(LDFLAGS)
 

+ 124 - 0
UnixAos/boot/OberonLoader.c

@@ -0,0 +1,124 @@
+/* 
+   G.F. 31.01.2017
+
+   Loader for statically linked oberon binaries.
+
+   Compile command:
+      gcc -m32 OberonLoader.c -ldl -o OberonLoader
+
+   The filename of the statically linked oberon binary is 'oberon.bin'.
+   The oberon binary may be joined with the loader to create a Unix program:
+   This is done in A2 by the following command:
+
+      UnixBinary.Build oberon.bin ->  <program name> ~
+
+*/
+#include <stdlib.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <string.h>
+#include <dlfcn.h>
+
+#define Offset 10*1024	/* startpos of oberon.bin if it is appended to the loader binary */
+#define Bufsize 2*1024*1024
+
+typedef void (*OberonProc)();
+typedef void *addr;
+typedef unsigned int uint;
+
+typedef struct {  /* cf. Generic.Unix.I386.Glue.Mod */
+    /* Oberon --> loader: */
+    char id[24];		/* must match coreID */
+    int  codesize;	
+    int  relocations;		/* if base = 0 */
+    addr base;			/* must be 0 or match the address of buf */
+    OberonProc entry;		/* Glue.Init0 */
+    /* loader --> Oberon: */
+    addr *dlopenaddr;
+    addr *dlcloseaddr;
+    addr *dlsymaddr;
+    int  *argc;
+    addr *argv;
+    addr *env;
+} *Header;
+
+char *coreID = "Oberon32G.binary";
+
+addr buf;
+int fd;
+
+uint ReadInteger( ) {
+   union {
+      char buf[4];
+      uint i;
+   } u;
+   read( fd, &u.buf, 4 );
+   return (u.i);
+}
+
+
+void Relocate( uint relocations ) {
+   addr *a;
+   uint i;
+
+   for (i=0; i<relocations; i++) {
+      a = buf + ReadInteger();
+      *a = buf+(uint)(*a);
+   }
+}
+
+
+int main( int argc, char *argv[], char *env[] ) {
+   int r, n, binsize, relocations;
+   size_t fsize;
+   struct stat sb;
+   Header header;
+   char path[64];
+   addr a;
+   uint binpos;
+
+   r = posix_memalign( &buf, 64*1024, Bufsize );
+   a = realpath( argv[0], path );
+   fd = open( path, O_RDONLY );
+   r = fstat( fd, &sb );
+   fsize = sb.st_size;
+   if (fsize > Offset) {
+      binpos = Offset;
+      r = lseek( fd, binpos, SEEK_SET );
+   } else {
+      binpos = 0;
+      fd = open( "oberon.bin", O_RDONLY );
+   }
+   n = read( fd, buf, 256 );
+   header = (Header)buf;
+   if (strcmp(header->id, coreID) != 0) {
+      printf( "bad headerId: %s, expected: %s\n", header->id, coreID );
+      exit( 2 );
+   }
+   if ((header->base != 0) & (header->base != buf)) {
+      printf( "bad displacement: %x, expected: %x\n", header->base, buf );
+      exit( 3 );
+   }
+   binsize = header->codesize;
+   relocations = header->relocations;
+
+   r = lseek( fd, binpos, SEEK_SET );
+   n = read( fd, buf, binsize );
+
+
+   Relocate( relocations );
+
+   *(header->dlopenaddr) = dlopen;
+   *(header->dlcloseaddr) = dlclose;
+   *(header->dlsymaddr) = dlsym;
+   *(header->argc) = argc;
+   *(header->argv) = argv;
+   *(header->env) = env;
+
+   header->entry();
+   return (0);
+}

BIN
UnixAos/boot/aos.darwin


BIN
UnixAos/boot/aos.linux