annotate dspanal/coffout.c @ 325:7df08926a4e7

frbl2test: better message for Hello response
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 06 Mar 2020 01:59:20 +0000
parents 493f73198267
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
308
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdint.h>
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdlib.h>
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include "coffout.h"
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 static FILE *outF;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 static void
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 write16(val)
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 unsigned val;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 putc(val, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 putc(val >> 8, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 }
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static void
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 write32(val)
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned val;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 {
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 putc(val, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 putc(val >> 8, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 putc(val >> 16, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 putc(val >> 24, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 emit_coff_output(filename, sections, nsect)
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 char *filename;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 struct coff_section *sections;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 unsigned nsect;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 {
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 uint32_t dataptr;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 unsigned n;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char section_name[32];
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 outF = fopen(filename, "w");
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 if (!outF) {
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 perror(filename);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 exit(1);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 write16(0x00C1);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 write16(nsect);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 write16(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 write16(0x0117);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 write16(0x0098);
309
493f73198267 dspanal: char2coff works now
Mychaela Falconia <falcon@freecalypso.org>
parents: 308
diff changeset
49 dataptr = 0x16 + 0x28 * nsect;
308
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 for (n = 0; n < nsect; n++) {
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 sprintf(section_name, "chunk%03u", n);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 fwrite(section_name, 1, 8, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 write32(sections[n].addr);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 write32(sections[n].addr);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 write32(sections[n].size);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 write32(dataptr);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 dataptr += sections[n].size << 1;
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 write32(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 write16(sections[n].flags);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 putc(0, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 putc(sections[n].mempage, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 for (n = 0; n < nsect; n++)
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 fwrite(sections[n].data, 2, sections[n].size, outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 fclose(outF);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 return(0);
f8344bc4fd61 dspanal: char2coff utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 }