forked from dmitryvk/sbcl-win32-threads
/
ppc-darwin-mkrospace.c
72 lines (65 loc) · 2.47 KB
/
ppc-darwin-mkrospace.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ppc-darwin-mkrospace.c - write a .o which makes sure we get our desired address range */
#include <stdlib.h>
#include <string.h>
#include <mach-o/loader.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "sbcl.h"
#include "runtime.h"
#include "ppc-darwin-spacelist.h"
struct simple_object_file
{
struct segment_command thesegment;
struct section thesection;
};
int main(int argc, char** argv)
{
struct mach_header *theheader;
struct simple_object_file *theobj;
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, 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);
return 0;
}