0.9.6.42:
[sbcl.git] / src / runtime / ppc-darwin-mkrospace.c
index 8faf381..683808f 100644 (file)
@@ -7,52 +7,66 @@
 #include <sys/uio.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include "runtime.h"
+#include <stdio.h>
+
 #include "sbcl.h"
+#include "runtime.h"
+
+#include "ppc-darwin-spacelist.h"
 
 struct simple_object_file
 {
-  struct mach_header theheader;
   struct segment_command thesegment;
   struct section thesection;
 };
 
 int main(int argc, char** argv)
 {
+  struct mach_header *theheader;
   struct simple_object_file *theobj;
-  int fd;
-  theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file));
-  theobj->theheader.magic = MH_MAGIC;
-  theobj->theheader.cputype = CPU_TYPE_POWERPC;
-  theobj->theheader.cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
-  theobj->theheader.filetype = MH_OBJECT;
-  theobj->theheader.ncmds = 1;
-  theobj->theheader.sizeofcmds = sizeof(struct segment_command) + sizeof(struct section);
-  theobj->theheader.flags = MH_NOUNDEFS;
-  theobj->thesegment.cmd = LC_SEGMENT;
-  theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section);
-  memcpy(theobj->thesegment.segname, "", sizeof(char));
-  theobj->thesegment.fileoff = sizeof(struct mach_header);
-  theobj->thesegment.vmaddr = READ_ONLY_SPACE_START;
-  theobj->thesegment.vmsize = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
-  theobj->thesegment.maxprot = VM_PROT_ALL;
-  theobj->thesegment.initprot = VM_PROT_ALL;
-  theobj->thesegment.nsects = 1;
-  theobj->thesegment.flags = 0;
-  memcpy(theobj->thesection.sectname, "core", 5);
-  memcpy(theobj->thesection.segname, "SBCLRO", 7);
-  theobj->thesection.addr = READ_ONLY_SPACE_START;
-  theobj->thesection.size = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
-  theobj->thesection.offset = sizeof(struct mach_header) + sizeof(struct segment_command) + sizeof(struct section);
-  theobj->thesection.align = 0;
-  theobj->thesection.reloff = 0;
-  theobj->thesection.nreloc = 0;
-  theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS;
-  theobj->thesection.reserved1 = 0;
-  theobj->thesection.reserved2 = 0;
+  int fd, i;
+
+  /* Produce the mach header */
+  theheader = (struct mach_header*) malloc(sizeof(struct mach_header));
+  theheader->magic = MH_MAGIC;
+  theheader->cputype = CPU_TYPE_POWERPC;
+  theheader->cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
+  theheader->filetype = MH_OBJECT;
+  theheader->ncmds = N_SEGMENTS_TO_PRODUCE;
+  theheader->sizeofcmds = N_SEGMENTS_TO_PRODUCE * (sizeof(struct segment_command) + sizeof(struct section));
+  theheader->flags = MH_NOUNDEFS;
+  printf("-Wl");
   fd = open("ppc-darwin-rospace.o", O_WRONLY | O_CREAT, 0644);
-  write(fd, theobj, sizeof(struct simple_object_file));
+  write(fd, theheader, sizeof(struct mach_header));
+
+  for (i = 0; i < N_SEGMENTS_TO_PRODUCE; i++) {
+    theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file));
+    theobj->thesegment.cmd = LC_SEGMENT;
+    theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section);
+    snprintf(theobj->thesegment.segname, 7, "SBCL%d", i);
+    theobj->thesegment.fileoff = sizeof(struct mach_header) + i * (sizeof(struct segment_command) + sizeof(struct section));
+    theobj->thesegment.vmaddr = space_start_locations[i];
+    theobj->thesegment.vmsize = 0;
+    theobj->thesegment.maxprot = VM_PROT_ALL;
+    theobj->thesegment.initprot = VM_PROT_ALL;
+    theobj->thesegment.nsects = 1;
+    theobj->thesegment.flags = 0;
+    snprintf(theobj->thesection.sectname, 7, "sect%d", i);
+    snprintf(theobj->thesection.segname, 7, "SBCL%d", i);
+    theobj->thesection.addr = space_start_locations[i];
+    theobj->thesection.size = 0;
+    theobj->thesection.offset = 0;
+    theobj->thesection.align = 0;
+    theobj->thesection.reloff = 0;
+    theobj->thesection.nreloc = 0;
+    theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS;
+    theobj->thesection.reserved1 = 0;
+    theobj->thesection.reserved2 = 0;
+    write(fd, theobj, sizeof(struct simple_object_file));
+    printf(",-segaddr,SBCL%d,0x%x", i, space_start_locations[i]);
+    free(theobj);
+  }
+  printf("\n");
   close(fd);
-  printf("-Wl,-segaddr,SBCLRO,0x%x\n",READ_ONLY_SPACE_START);
   return 0;
 }