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