0.8.10.13:
[sbcl.git] / src / runtime / ppc-darwin-mkrospace.c
1 /* ppc-darwin-mkrospace.c - write a .o which makes sure we get our desired address range */
2
3 #include <stdlib.h>
4 #include <string.h>
5 #include <mach-o/loader.h>
6 #include <sys/types.h>
7 #include <sys/uio.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10 #include "runtime.h"
11 #include "sbcl.h"
12
13 struct simple_object_file
14 {
15   struct mach_header theheader;
16   struct segment_command thesegment;
17   struct section thesection;
18 };
19
20 int main(int argc, char** argv)
21 {
22   struct simple_object_file *theobj;
23   int fd;
24   theobj = (struct simple_object_file*) malloc(sizeof(struct simple_object_file));
25   theobj->theheader.magic = MH_MAGIC;
26   theobj->theheader.cputype = CPU_TYPE_POWERPC;
27   theobj->theheader.cpusubtype = CPU_SUBTYPE_POWERPC_ALL;
28   theobj->theheader.filetype = MH_OBJECT;
29   theobj->theheader.ncmds = 1;
30   theobj->theheader.sizeofcmds = sizeof(struct segment_command) + sizeof(struct section);
31   theobj->theheader.flags = MH_NOUNDEFS;
32   theobj->thesegment.cmd = LC_SEGMENT;
33   theobj->thesegment.cmdsize = sizeof(struct segment_command) + sizeof(struct section);
34   memcpy(theobj->thesegment.segname, "", sizeof(char));
35   theobj->thesegment.fileoff = sizeof(struct mach_header);
36   theobj->thesegment.vmaddr = READ_ONLY_SPACE_START;
37   theobj->thesegment.vmsize = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
38   theobj->thesegment.maxprot = VM_PROT_ALL;
39   theobj->thesegment.initprot = VM_PROT_ALL;
40   theobj->thesegment.nsects = 1;
41   theobj->thesegment.flags = 0;
42   memcpy(theobj->thesection.sectname, "core", 5);
43   memcpy(theobj->thesection.segname, "SBCLRO", 7);
44   theobj->thesection.addr = READ_ONLY_SPACE_START;
45   theobj->thesection.size = READ_ONLY_SPACE_END - READ_ONLY_SPACE_START;
46   theobj->thesection.offset = sizeof(struct mach_header) + sizeof(struct segment_command) + sizeof(struct section);
47   theobj->thesection.align = 0;
48   theobj->thesection.reloff = 0;
49   theobj->thesection.nreloc = 0;
50   theobj->thesection.flags = S_ZEROFILL | S_REGULAR | S_ATTR_SOME_INSTRUCTIONS;
51   theobj->thesection.reserved1 = 0;
52   theobj->thesection.reserved2 = 0;
53   fd = open("ppc-darwin-rospace.o", O_WRONLY | O_CREAT, 0644);
54   write(fd, theobj, sizeof(struct simple_object_file));
55   close(fd);
56   printf("-Wl,-segaddr,SBCLRO,0x%x\n",READ_ONLY_SPACE_START);
57   return 0;
58 }