2 * Transform a Plan 9 386 bootable image to make it compatible with
3 * the Xen binary image loader:
5 * - pad the beginning of the text with zeroes so that the image can be loaded at
6 * guest 'physical' address 0
7 * - insert a Xen header
8 * - pad the end of the text so that data segment is page-aligned in the file
9 * - adjust the linenumber-pc table so Plan 9 debuggers won't be confused
20 #define KZERO 0x80000000
21 #define FLAG_VALID (1<<16)
22 #define FLAG_PAE (1<<14)
27 char buf[sizeof(long)];
30 for (i = sizeof(long)-1; i >= 0; i--) {
34 write(1, buf, sizeof(long));
40 char buf[sizeof(long)];
43 for (i = 0; i < sizeof(long); i++) {
47 write(1, buf, sizeof(long));
71 memset(buf, 0, sizeof buf);
82 * See /sys/src/cmd/8l/span.c:/^asmlc
84 void adjustlnpc(int v)
95 if (n == sizeof buf) {
106 main(int argc, char **argv)
112 long prepad, postpad;
116 if (argc > 1 && strcmp(argv[1], "-p") == 0)
121 newtxtsz = ((fhdr.txtsz+PLAN9HDR+PAGE-1)&~(PAGE-1)) - PLAN9HDR;
122 newentry = KZERO+PLAN9HDR;
123 prepad = fhdr.entry - newentry;
124 postpad = newtxtsz - fhdr.txtsz;
126 newlnpcsz = fhdr.lnpcsz;
128 newlnpcsz += (prepad+126)/127;
131 lput(4*11*11+7); /* magic */
132 lput(newtxtsz); /* sizes */
135 lput(fhdr.symsz); /* nsyms */
136 lput(newentry); /* va of entry */
137 lput(fhdr.sppcsz); /* sp offsets */
138 lput(newlnpcsz); /* line offsets */
141 rput(0x336EC578); /* magic */
142 rput(flags); /* flags */
143 rput(-(0x336EC578+flags)); /* checksum */
144 rput(newentry); /* header_addr */
145 rput(KZERO); /* load_addr */
146 rput(KZERO+newtxtsz+fhdr.datsz); /* load_end_addr */
147 rput(KZERO+newtxtsz+fhdr.datsz+fhdr.bsssz); /* bss_end_addr */
148 rput(fhdr.entry); /* entry_addr */
152 seek(0, fhdr.txtoff, 0);