OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

[/] [zipcpu/] [trunk/] [sw/] [gas-zippatch.patch] - Blame information for rev 206

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 202 dgisselq
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/archures.c binutils-2.27-zip/bfd/archures.c
2
--- binutils-2.27/bfd/archures.c        2016-08-03 03:36:50.000000000 -0400
3
+++ binutils-2.27-zip/bfd/archures.c    2017-01-04 14:22:45.000000000 -0500
4
@@ -525,6 +525,8 @@
5
 .#define bfd_mach_nios2r2      2
6
 .  bfd_arch_visium,    {* Visium *}
7
 .#define bfd_mach_visium       1
8
+.  bfd_arch_zip,       {* ZipCPU *}
9
+.#define bfd_mach_zip          0
10
 .  bfd_arch_last
11
 .  };
12
 */
13
@@ -655,6 +657,7 @@
14
 extern const bfd_arch_info_type bfd_xgate_arch;
15
 extern const bfd_arch_info_type bfd_z80_arch;
16
 extern const bfd_arch_info_type bfd_z8k_arch;
17
+extern const bfd_arch_info_type bfd_zip_arch;
18
 
19
 static const bfd_arch_info_type * const bfd_archures_list[] =
20
   {
21
@@ -744,6 +747,7 @@
22
     &bfd_xgate_arch,
23
     &bfd_z80_arch,
24
     &bfd_z8k_arch,
25
+    &bfd_zip_arch,
26
 #endif
27
 
28
 };
29
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/bfd-in2.h binutils-2.27-zip/bfd/bfd-in2.h
30
--- binutils-2.27/bfd/bfd-in2.h 2016-08-03 03:36:50.000000000 -0400
31
+++ binutils-2.27-zip/bfd/bfd-in2.h     2017-01-04 22:04:11.000000000 -0500
32
@@ -2336,6 +2336,8 @@
33
 #define bfd_mach_nios2r2       2
34
   bfd_arch_visium,     /* Visium */
35
 #define bfd_mach_visium        1
36
+  bfd_arch_zip,        /* ZipCPU */
37
+#define bfd_mach_zip           0
38
   bfd_arch_last
39
   };
40
 
41
@@ -6335,6 +6337,22 @@
42
   BFD_RELOC_VISIUM_HI16_PCREL,
43
   BFD_RELOC_VISIUM_LO16_PCREL,
44
   BFD_RELOC_VISIUM_IM16_PCREL,
45
+
46
+/* ZipCPU - 32 bit absolute value for LJMP instruction  */
47
+  BFD_RELOC_ZIP_VALUE,
48
+
49
+/* ZipCPU - 18-bit PC-relative offset for BRA (ADD #x,PC) instructions  */
50
+  BFD_RELOC_ZIP_BRANCH,
51
+
52
+/* ZipCPU value relocations  */
53
+  BFD_RELOC_ZIP_OPB_IMM,
54
+  BFD_RELOC_ZIP_OPB_OFFSET,
55
+  BFD_RELOC_ZIP_OPB_PCREL,
56
+  BFD_RELOC_ZIP_MOV_OFFSET,
57
+  BFD_RELOC_ZIP_MOV_PCREL,
58
+  BFD_RELOC_ZIP_LDI,
59
+  BFD_RELOC_ZIP_LLO,
60
+  BFD_RELOC_ZIP_BREV,
61
   BFD_RELOC_UNUSED };
62
 
63
 typedef enum bfd_reloc_code_real bfd_reloc_code_real_type;
64
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/config.bfd binutils-2.27-zip/bfd/config.bfd
65
--- binutils-2.27/bfd/config.bfd        2016-08-03 03:36:50.000000000 -0400
66
+++ binutils-2.27-zip/bfd/config.bfd    2016-12-31 17:11:00.961307172 -0500
67
@@ -1742,6 +1742,10 @@
68
     targ_underscore=yes
69
     ;;
70
 
71
+  zip*)
72
+    targ_defvec=zip_elf32_vec
73
+    ;;
74
+
75
   *-*-ieee*)
76
     targ_defvec=ieee_vec
77
     ;;
78
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/configure binutils-2.27-zip/bfd/configure
79
--- binutils-2.27/bfd/configure 2016-08-03 04:33:36.000000000 -0400
80
+++ binutils-2.27-zip/bfd/configure     2016-12-31 17:12:22.360697343 -0500
81
@@ -14542,6 +14542,7 @@
82
     xtensa_elf32_le_vec)        tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
83
     z80_coff_vec)               tb="$tb coff-z80.lo reloc16.lo $coffgen" ;;
84
     z8k_coff_vec)               tb="$tb coff-z8k.lo reloc16.lo $coff" ;;
85
+    zip_elf32_vec)              tb="$tb elf32-zip.lo elf32.lo $elf" ;;
86
 
87
     # These appear out of order in targets.c
88
     srec_vec)                   tb="$tb srec.lo" ;;
89
@@ -14924,6 +14925,9 @@
90
   x86_64-*-netbsd* | x86_64-*-openbsd*)
91
        COREFILE=netbsd-core.lo
92
        ;;
93
+  zip*)
94
+       COREFILE=netbsd-core.lo
95
+       ;;
96
   esac
97
 
98
   case "$COREFILE" in
99
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/configure.ac binutils-2.27-zip/bfd/configure.ac
100
--- binutils-2.27/bfd/configure.ac      2016-08-03 03:36:50.000000000 -0400
101
+++ binutils-2.27-zip/bfd/configure.ac  2016-12-31 17:13:38.600136486 -0500
102
@@ -717,6 +717,7 @@
103
     xtensa_elf32_le_vec)        tb="$tb xtensa-isa.lo xtensa-modules.lo elf32-xtensa.lo elf32.lo $elf" ;;
104
     z80_coff_vec)               tb="$tb coff-z80.lo reloc16.lo $coffgen" ;;
105
     z8k_coff_vec)               tb="$tb coff-z8k.lo reloc16.lo $coff" ;;
106
+    zip_elf32_vec)              tb="$tb elf32-zip.lo elf32.lo $elf" ;;
107
 
108
     # These appear out of order in targets.c
109
     srec_vec)                   tb="$tb srec.lo" ;;
110
@@ -1092,6 +1093,9 @@
111
   x86_64-*-netbsd* | x86_64-*-openbsd*)
112
        COREFILE=netbsd-core.lo
113
        ;;
114
+  zip*)
115
+       COREFILE=netbsd-core.lo
116
+       ;;
117
   esac
118
 
119
   case "$COREFILE" in
120
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/cpu-zip.c binutils-2.27-zip/bfd/cpu-zip.c
121
--- binutils-2.27/bfd/cpu-zip.c 1969-12-31 19:00:00.000000000 -0500
122
+++ binutils-2.27-zip/bfd/cpu-zip.c     2017-01-04 14:26:27.000000000 -0500
123
@@ -0,0 +1,65 @@
124
+////////////////////////////////////////////////////////////////////////////////
125
+//
126
+// Filename:   tc-zip.c
127
+//
128
+// Project:    Zip CPU backend for GNU Binutils
129
+//
130
+// Purpose:    BFD support for the Zip CPU architecture.
131
+//
132
+//             This file is part of BFD, the Binary File Descriptor library.
133
+//
134
+// Creator:    Dan Gisselquist, Ph.D.
135
+//             Gisselquist Technology, LLC
136
+//
137
+////////////////////////////////////////////////////////////////////////////////
138
+//
139
+// Copyright (C) 2016-2017, Gisselquist Technology, LLC
140
+//
141
+// This program is free software (firmware): you can redistribute it and/or
142
+// modify it under the terms of  the GNU General Public License as published
143
+// by the Free Software Foundation, either version 3 of the License, or (at
144
+// your option) any later version.
145
+//
146
+// This program is distributed in the hope that it will be useful, but WITHOUT
147
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
148
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
149
+// for more details.
150
+//
151
+// You should have received a copy of the GNU General Public License along
152
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
153
+// target there if the PDF file isn't present.)  If not, see
154
+// <http://www.gnu.org/licenses/> for a copy.
155
+//
156
+// License:    GPL, v3, as defined and found on www.gnu.org,
157
+//             http://www.gnu.org/licenses/gpl.html
158
+//
159
+//
160
+////////////////////////////////////////////////////////////////////////////////
161
+#include "sysdep.h"
162
+#include "bfd.h"
163
+#include "libbfd.h"
164
+
165
+const bfd_arch_info_type
166
+bfd_zip_arch =
167
+{
168
+  32,                          // There's 32 bits_per_word.
169
+  32,                          // There's 34 bits_per_address.
170
+  8,                           // There's 32 bits_per_byte.
171
+  bfd_arch_zip,                        // One of enum bfd_architecture, defined
172
+                               // in archures.c and provided in
173
+                               // generated header files.
174
+  bfd_mach_zip,                        // Random BFD-internal number for this
175
+                               // machine, similarly listed in
176
+                               // archures.c.  Not emitted in output.
177
+  "zip",                       // The arch_name.
178
+  "zip",                       // The printable name is the same.
179
+  2,                           // Section alignment power; each section
180
+                               // is aligned to (only) 2^2 (i.e. 4) bytes.
181
+  TRUE,                                // This is the default "machine".
182
+  bfd_default_compatible,      // Architecture comparison function
183
+  bfd_default_scan,            // String to architecture conversion
184
+  bfd_arch_default_fill,       // Default fill.
185
+  NULL                         // Pointer to next bfd_arch_info_type in
186
+                               // the same family.
187
+};
188
+
189
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/doc/archures.texi binutils-2.27-zip/bfd/doc/archures.texi
190
--- binutils-2.27/bfd/doc/archures.texi 2016-08-03 04:36:22.000000000 -0400
191
+++ binutils-2.27-zip/bfd/doc/archures.texi     2016-12-31 17:14:43.103668704 -0500
192
@@ -492,6 +492,8 @@
193
 #define bfd_mach_nios2r2       2
194
   bfd_arch_visium,     /* Visium */
195
 #define bfd_mach_visium        1
196
+  bfd_mach_zip,
197
+#define bfd_mach_zip           0
198
   bfd_arch_last
199
   @};
200
 @end example
201
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/doc/bfd.info binutils-2.27-zip/bfd/doc/bfd.info
202
--- binutils-2.27/bfd/doc/bfd.info      2016-08-03 04:36:22.000000000 -0400
203
+++ binutils-2.27-zip/bfd/doc/bfd.info  2017-01-04 14:40:21.000000000 -0500
204
@@ -8466,6 +8466,8 @@
205
      #define bfd_mach_nios2r2       2
206
        bfd_arch_visium,     /* Visium */
207
      #define bfd_mach_visium        1
208
+       bfd_arch_zip,        /* ZipCPU */
209
+     #define bfd_mach_zip           0
210
        bfd_arch_last
211
        };
212
 
213
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/doc/reloc.texi binutils-2.27-zip/bfd/doc/reloc.texi
214
--- binutils-2.27/bfd/doc/reloc.texi    2016-08-03 04:36:22.000000000 -0400
215
+++ binutils-2.27-zip/bfd/doc/reloc.texi        2016-12-31 17:17:15.950640091 -0500
216
@@ -4214,6 +4214,19 @@
217
 @deffnx {} BFD_RELOC_VISIUM_IM16_PCREL
218
 Visium Relocations.
219
 @end deffn
220
+@deffn {} BFD_RELOC_ZIP_VALUE
221
+@deffnx {} BFD_RELOC_OPB_IMM
222
+@deffnx {} BFD_RELOC_OPB_OFFSET
223
+@deffnx {} BFD_RELOC_OPB_PCREL
224
+@deffnx {} BFD_RELOC_OPB_GOTREL
225
+@deffnx {} BFD_RELOC_MOV_OFFSET
226
+@deffnx {} BFD_RELOC_MOV_PCREL
227
+@deffnx {} BFD_RELOC_MOV_GOTREL
228
+@deffnx {} BFD_RELOC_ZIP_LDI
229
+@deffnx {} BFD_RELOC_ZIP_LLO
230
+@deffnx {} BFD_RELOC_ZIP_LHI
231
+ZipCPU relocations
232
+@end deffn
233
 
234
 @example
235
 
236
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/elf32-zip.c binutils-2.27-zip/bfd/elf32-zip.c
237
--- binutils-2.27/bfd/elf32-zip.c       1969-12-31 19:00:00.000000000 -0500
238
+++ binutils-2.27-zip/bfd/elf32-zip.c   2017-01-24 13:54:25.214097101 -0500
239
@@ -0,0 +1,1134 @@
240
+////////////////////////////////////////////////////////////////////////////////
241
+//
242
+// Filename:   tc-zip.c
243
+//
244
+// Project:    Zip CPU backend for GNU Binutils
245
+//
246
+// Purpose:    Zip-specific support for 32-bit ELF.
247
+//
248
+//     This file is part of BFD, the Binary File Descriptor library.
249
+//
250
+// Creator:    Dan Gisselquist, Ph.D.
251
+//             Gisselquist Technology, LLC
252
+//
253
+////////////////////////////////////////////////////////////////////////////////
254
+//
255
+// Copyright (C) 2016, Gisselquist Technology, LLC
256
+//
257
+// This program is free software (firmware): you can redistribute it and/or
258
+// modify it under the terms of  the GNU General Public License as published
259
+// by the Free Software Foundation, either version 3 of the License, or (at
260
+// your option) any later version.
261
+//
262
+// This program is distributed in the hope that it will be useful, but WITHOUT
263
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
264
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
265
+// for more details.
266
+//
267
+// You should have received a copy of the GNU General Public License along
268
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
269
+// target there if the PDF file isn't present.)  If not, see
270
+// <http://www.gnu.org/licenses/> for a copy.
271
+//
272
+// License:    GPL, v3, as defined and found on www.gnu.org,
273
+//             http://www.gnu.org/licenses/gpl.html
274
+//
275
+//
276
+////////////////////////////////////////////////////////////////////////////////
277
+#include "sysdep.h"
278
+#include "bfd.h"
279
+#include "bfdlink.h"
280
+#include "libbfd.h"
281
+#include "elf-bfd.h"
282
+#include "elf/zip.h"
283
+#include <limits.h>
284
+#include <stdint.h>
285
+
286
+#define        zip_relocation  bfd_elf_generic_reloc
287
+
288
+static bfd_reloc_status_type
289
+zip_brev_relocation(bfd *, arelent *, asymbol *, void *, asection *,
290
+               bfd *, char **error_messsage);
291
+static uint32_t zip_bitreverse(uint32_t v);
292
+
293
+/* Forward declarations.  */
294
+static reloc_howto_type zip_elf_howto_table [] =
295
+{
296
+  /* This reloc does nothing.  */
297
+  HOWTO (R_ZIP_NONE,           /* type */
298
+        0,                     /* rightshift */
299
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
300
+        32,                    /* bitsize */
301
+        FALSE,                 /* pc_relative */
302
+        0,                     /* bitpos */
303
+        complain_overflow_dont, /* complain_on_overflow */
304
+        zip_relocation,        /* special_function */
305
+        "R_ZIP_NONE",          /* name */
306
+        FALSE,                 /* partial_inplace */
307
+        0,                     /* src_mask */
308
+        0,                     /* dst_mask */
309
+        FALSE),                /* pcrel_offset */
310
+
311
+  /* A 32 bit absolute relocation.  */
312
+  HOWTO (R_ZIP_VALUE,          /* type */
313
+        0,                     /* rightshift */
314
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
315
+        32,                    /* bitsize */
316
+        FALSE,                 /* pc_relative */
317
+        0,                     /* bitpos */
318
+        complain_overflow_dont, /* complain_on_overflow */
319
+        zip_relocation,        /* special_function */
320
+        "R_ZIP_VALUE",         /* name */
321
+        FALSE,                 /* partial_inplace */
322
+        0x00000000,            /* src_mask */
323
+        0xffffffff,            /* dst_mask */
324
+        FALSE),                /* pcrel_offset */
325
+
326
+  HOWTO (R_ZIP_BREV,           /* type -- LDIHI, but with bitreverse */
327
+        0,                     /* rightshift */
328
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
329
+        16,                    /* bitsize */
330
+        FALSE,                 /* pc_relative */
331
+        0,                     /* bitpos */
332
+        complain_overflow_bitfield, /* complain_on_overflow */
333
+        zip_brev_relocation,    /* special_function--needed for the bitreverse */
334
+        "R_ZIP_BREV",          /* name */
335
+        FALSE,                 /* partial_inplace */
336
+        0,                     /* src_mask */
337
+        0x0003ffff,            /* dst_mask */
338
+        FALSE),                /* pcrel_offset */
339
+
340
+  HOWTO (R_ZIP_LLO,            /* type */
341
+        0,                     /* rightshift */
342
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
343
+        23,                    /* bitsize */
344
+        FALSE,                 /* pc_relative */
345
+        0,                     /* bitpos */
346
+        complain_overflow_dont, /* don't complain_on_overflow */
347
+        zip_relocation,         /* special_function */
348
+        "R_ZIP_LLO",           /* name */
349
+        FALSE,                 /* partial_inplace */
350
+        0,                     /* src_mask */
351
+        0x0000ffff,            /* dst_mask */
352
+        FALSE),                /* pcrel_offset */
353
+
354
+  HOWTO (R_ZIP_LDI,            /* type */
355
+        0,                     /* rightshift */
356
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
357
+        23,                    /* bitsize */
358
+        FALSE,                 /* pc_relative */
359
+        0,                     /* bitpos */
360
+        complain_overflow_signed, /* complain_on_overflow */
361
+        zip_relocation,         /* special_function */
362
+        "R_ZIP_LDI",           /* name */
363
+        FALSE,                 /* partial_inplace */
364
+        0,                     /* src_mask */
365
+        0x007fffff,            /* dst_mask */
366
+        FALSE),                /* pcrel_offset */
367
+
368
+  /* An 18 bit pc-relative relocation.  */
369
+  HOWTO (R_ZIP_BRANCH,         /* type */
370
+        0,                     /* rightshift */
371
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
372
+        18,                    /* bitsize */
373
+        TRUE,                  /* pc_relative */
374
+        0,                     /* bitpos */
375
+        complain_overflow_signed, /* complain_on_overflow */
376
+        zip_relocation,        /* special_function */
377
+        "R_ZIP_BRANCH",        /* name */
378
+        FALSE,                 /* partial_inplace */
379
+        0x00000000,            /* src_mask */
380
+        0x0003fffc,            /* dst_mask */
381
+        TRUE),         /* pcrel_offset */
382
+
383
+  /* An 18 bit operand B immediate.  */
384
+  HOWTO (R_ZIP_OPB_IMM,        /* type */
385
+        0,                     /* rightshift */
386
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
387
+        18,                    /* bitsize */
388
+        FALSE,                 /* pc_relative */
389
+        0,                     /* bitpos */
390
+        complain_overflow_signed, /* complain_on_overflow */
391
+        zip_relocation,        /* special_function */
392
+        "R_ZIP_OPB_IMM",       /* name */
393
+        FALSE,                 /* partial_inplace */
394
+        0x00000000,            /* src_mask */
395
+        0x0003ffff,            /* dst_mask */
396
+        FALSE),                        /* pcrel_offset */
397
+
398
+  /* An 18 bit relocation.  */
399
+  HOWTO (R_ZIP_OPB_OFFSET,     /* type */
400
+        0,                     /* rightshift */
401
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
402
+        14,                    /* bitsize */
403
+        FALSE,                 /* pc_relative */
404
+        0,                     /* bitpos */
405
+        complain_overflow_signed, /* complain_on_overflow */
406
+        zip_relocation,        /* special_function */
407
+        "R_ZIP_OPB_OFFSET",    /* name */
408
+        FALSE,                 /* partial_inplace */
409
+        0x00000000,            /* src_mask */
410
+        0x00003fff,            /* dst_mask-14 bits */
411
+        FALSE),                        /* pcrel_offset */
412
+
413
+  /* An 18 bit operand B immediate, but relative to the current PC.  */
414
+  HOWTO (R_ZIP_OPB_PCREL,      /* type */
415
+        2,                     /* rightshift */
416
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
417
+        14,                    /* bitsize */
418
+        TRUE,                  /* pc_relative */
419
+        0,                     /* bitpos */
420
+        complain_overflow_signed, /* complain_on_overflow */
421
+        zip_relocation,        /* special_function */
422
+        "R_ZIP_OPB_PCREL",     /* name */
423
+        FALSE,                 /* partial_inplace */
424
+        0x00000000,            /* src_mask */
425
+        0x00003fff,            /* dst_mask-14 bits */
426
+        TRUE),                 /* pcrel_offset */
427
+
428
+  /* An 18 bit operand B immediate, but relative to the Global Offset Table. */
429
+  //HOWTO (R_ZIP_OPB_GOTREL,   /* type */
430
+        //0,                   /* rightshift */
431
+        //2,                   /* size (0 = byte, 1 = short, 2 = long) */
432
+        //18,                  /* bitsize */
433
+        //FALSE,                       /* pc_relative */
434
+        //0,                   /* bitpos */
435
+        //complain_overflow_signed, /* complain_on_overflow */
436
+        //zip_relocation,      /* special_function */
437
+        //"R_ZIP_OPB_GOTREL",  /* name */
438
+        //FALSE,                       /* partial_inplace */
439
+        //0x00000000,          /* src_mask */
440
+        //0x0003ffff,          /* dst_mask-14 bits */
441
+        //FALSE),              /* pcrel_offset */
442
+
443
+  /* */
444
+  HOWTO (R_ZIP_MOV_OFFSET,     /* type */
445
+        0,                     /* rightshift */
446
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
447
+        13,                    /* bitsize */
448
+        FALSE,                 /* pc_relative */
449
+        0,                     /* bitpos */
450
+        complain_overflow_signed, /* complain_on_overflow */
451
+        zip_relocation,         /* special_function */
452
+        "R_ZIP_MOV_OFFSET",    /* name */
453
+        FALSE,                 /* partial_inplace */
454
+        0,                     /* src_mask */
455
+        0x00001fff,            /* dst_mask */
456
+        FALSE),                /* pcrel_offset */
457
+
458
+  /* */
459
+  HOWTO (R_ZIP_MOV_PCREL,      /* type */
460
+        2,                     /* rightshift */
461
+        2,                     /* size (0 = byte, 1 = short, 2 = long) */
462
+        13,                    /* bitsize */
463
+        TRUE,                  /* pc_relative */
464
+        0,                     /* bitpos */
465
+        complain_overflow_signed, /* complain_on_overflow */
466
+        zip_relocation,         /* special_function */
467
+        "R_ZIP_MOV_PCREL",     /* name */
468
+        FALSE,                 /* partial_inplace */
469
+        0,                     /* src_mask */
470
+        0x00001fff,            /* dst_mask */
471
+        TRUE)                  /* pcrel_offset */
472
+
473
+  /* */
474
+  //HOWTO (R_ZIP_MOV_GOTREL,   /* type */
475
+        //0,                   /* rightshift */
476
+        //2,                   /* size (0 = byte, 1 = short, 2 = long) */
477
+        //13,                  /* bitsize */
478
+        //FALSE,                       /* pc_relative */
479
+        //0,                   /* bitpos */
480
+        //complain_overflow_signed, /* complain_on_overflow */
481
+        //zip_relocation,       /* special_function */
482
+        //"R_ZIP_MOV_GOTREL",  /* name */
483
+        //FALSE,                       /* partial_inplace */
484
+        //0,                   /* src_mask */
485
+        //0x00001fff,          /* dst_mask */
486
+        //FALSE),              /* pcrel_offset */
487
+
488
+};
489
+
490
+/* This structure is used to map BFD reloc codes to Zip ELF relocations */
491
+
492
+struct elf_reloc_map
493
+{
494
+  bfd_reloc_code_real_type bfd_reloc_val;
495
+  unsigned int elf_reloc_val;
496
+};
497
+
498
+static const struct elf_reloc_map zip_reloc_map [] =
499
+{
500
+  { BFD_RELOC_NONE,            R_ZIP_NONE },
501
+  { BFD_RELOC_ZIP_VALUE,       R_ZIP_VALUE },
502
+  { BFD_RELOC_ZIP_BRANCH,      R_ZIP_BRANCH },
503
+  { BFD_RELOC_ZIP_OPB_IMM,     R_ZIP_OPB_IMM },
504
+  { BFD_RELOC_ZIP_OPB_OFFSET,  R_ZIP_OPB_OFFSET },
505
+  { BFD_RELOC_ZIP_MOV_OFFSET,  R_ZIP_MOV_OFFSET },
506
+  { BFD_RELOC_ZIP_LDI,         R_ZIP_LDI },
507
+  { BFD_RELOC_ZIP_LLO,         R_ZIP_LLO },
508
+  { BFD_RELOC_ZIP_BREV,                R_ZIP_BREV },
509
+  { BFD_RELOC_14,              R_ZIP_OPB_OFFSET },
510
+  { BFD_RELOC_16,              R_ZIP_LLO },
511
+  { BFD_RELOC_32,              R_ZIP_VALUE },
512
+  { BFD_RELOC_ZIP_OPB_PCREL,   R_ZIP_OPB_PCREL },
513
+  { BFD_RELOC_ZIP_MOV_PCREL,   R_ZIP_MOV_PCREL }
514
+  // { BFD_RELOC_ZIP_OPB_GOTREL,       R_ZIP_OPB_GOTREL },
515
+  // { BFD_RELOC_ZIP_MOV_GOTREL,       R_ZIP_MOV_GOTREL },
516
+};
517
+
518
+/* Given a BFD reloc code, return the howto structure for the corresponding
519
+ * Zip ELF relocation. */
520
+static reloc_howto_type *
521
+zip_elf_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
522
+                       bfd_reloc_code_real_type code)
523
+{
524
+  unsigned int i;
525
+
526
+  for (i = 0; i < sizeof (zip_reloc_map) / sizeof (zip_reloc_map[0]); i++)
527
+    if (zip_reloc_map [i].bfd_reloc_val == code)
528
+      return & zip_elf_howto_table [(int)zip_reloc_map[i].elf_reloc_val];
529
+
530
+  return NULL;
531
+}
532
+
533
+static reloc_howto_type *
534
+zip_elf_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
535
+{
536
+  unsigned int i;
537
+
538
+  for (i = 0;
539
+       i < sizeof (zip_elf_howto_table) / sizeof (zip_elf_howto_table[0]);
540
+       i++)
541
+    if (zip_elf_howto_table[i].name != NULL
542
+       && strcasecmp (zip_elf_howto_table[i].name, r_name) == 0)
543
+      return &zip_elf_howto_table[i];
544
+
545
+  return NULL;
546
+}
547
+
548
+/* Given an ELF reloc, fill in the howto field of a relent. */
549
+static void
550
+zip_elf_info_to_howto(bfd * abfd ATTRIBUTE_UNUSED,
551
+                        arelent * cache_ptr,
552
+                        Elf_Internal_Rela * dst)
553
+{
554
+       unsigned int r;
555
+
556
+       r = ELF32_R_TYPE(dst->r_info);
557
+       BFD_ASSERT (r < (unsigned int) R_ZIP_max);
558
+       cache_ptr->howto = &zip_elf_howto_table [r];
559
+}
560
+
561
+static bfd_boolean
562
+zip_elf_relocate_section(bfd *output_bfd,
563
+                       struct bfd_link_info *info,
564
+                       bfd *input_bfd,
565
+                       asection *input_section,
566
+                       bfd_byte *contents,
567
+                       Elf_Internal_Rela *relocs,
568
+                       Elf_Internal_Sym *local_syms,
569
+                       asection **local_sections)
570
+{
571
+       Elf_Internal_Shdr               *symtab_hdr;
572
+       struct  elf_link_hash_entry     **sym_hashes;
573
+       Elf_Internal_Rela               *rel, *relend;
574
+
575
+       symtab_hdr = &elf_tdata(input_bfd)->symtab_hdr;
576
+       sym_hashes = elf_sym_hashes(input_bfd);
577
+       relend     = relocs+input_section->reloc_count;
578
+
579
+       for(rel=relocs; rel<relend; rel++) {
580
+               reloc_howto_type                *howto;
581
+               unsigned long                   r_symndx;
582
+               Elf_Internal_Sym                *sym;
583
+               asection                        *sec;
584
+               struct elf_link_hash_entry      *h;
585
+               bfd_vma                         relocation;
586
+               bfd_reloc_status_type           r;
587
+               const char                      *name = NULL;
588
+               int                             r_type;
589
+
590
+               r_type = ELF32_R_TYPE(rel->r_info);
591
+               r_symndx = ELF32_R_SYM(rel->r_info);
592
+
593
+               if ((r_type < 0) || (r_type >= (int)R_ZIP_max))
594
+               {
595
+                       bfd_set_error(bfd_error_bad_value);
596
+                       return FALSE;
597
+               }
598
+
599
+               howto = zip_elf_howto_table + ELF32_R_TYPE(rel->r_info);
600
+               h = NULL;
601
+               sym = NULL;
602
+               sec = NULL;
603
+
604
+               if (r_symndx < symtab_hdr->sh_info)
605
+               {
606
+                       sym = local_syms + r_symndx;
607
+                       sec = local_sections[r_symndx];
608
+                       relocation = _bfd_elf_rela_local_sym(output_bfd, sym, &sec, rel);
609
+                       name = bfd_elf_string_from_elf_section
610
+                               (input_bfd, symtab_hdr->sh_link, sym->st_name);
611
+                       name = (name == NULL) ? bfd_section_name(input_bfd, sec)
612
+                                       : name;
613
+               } else {
614
+                       bfd_boolean unresolved_reloc, warned, ignored;
615
+
616
+                       RELOC_FOR_GLOBAL_SYMBOL(info, input_bfd, input_section,
617
+                               rel, r_symndx, symtab_hdr, sym_hashes, h, sec,
618
+                               relocation, unresolved_reloc, warned, ignored);
619
+               }
620
+
621
+               if ((sec != NULL)&&(discarded_section(sec))) {
622
+                       RELOC_AGAINST_DISCARDED_SECTION(info, input_bfd,
623
+                               input_section, rel, 1, relend, howto, 0,
624
+                               contents);
625
+               }
626
+
627
+               if (bfd_link_relocatable(info))
628
+                       continue;
629
+
630
+               if (howto->type == R_ZIP_BREV) {
631
+                       if (rel->r_offset > bfd_get_section_limit(input_bfd, input_section)) {
632
+                               r = bfd_reloc_outofrange;
633
+                       } else {
634
+                               uint32_t        brev_reloc;
635
+                               bfd_byte        *location;
636
+                               bfd_vma         insn;
637
+
638
+                               location = contents + rel->r_offset * bfd_octets_per_byte(input_bfd);
639
+
640
+                               relocation += rel->r_addend;
641
+                               brev_reloc= zip_bitreverse(relocation);
642
+                               insn = bfd_get_32(input_bfd, location);
643
+                               insn = ((insn & ~howto->dst_mask)
644
+                               |(((insn & howto->src_mask)+brev_reloc)&howto->dst_mask));
645
+                               bfd_put_32(input_bfd, insn, location);
646
+                               r = bfd_reloc_ok;
647
+                       }
648
+               } else {
649
+                       r = _bfd_final_link_relocate(howto, input_bfd,
650
+                               input_section,
651
+                               contents, rel->r_offset,
652
+                               relocation,
653
+                               rel->r_addend);
654
+               }
655
+
656
+
657
+               if (r != bfd_reloc_ok)
658
+               {
659
+                       const char *msg = NULL;
660
+
661
+                       switch(r)
662
+                       {
663
+                               case bfd_reloc_overflow:
664
+                                       info->callbacks->reloc_overflow(
665
+                                               info, (h?&h->root:NULL),
666
+                                               name, howto->name,
667
+                                               (bfd_vma)0, input_bfd,
668
+                                               input_section, rel->r_offset);
669
+                                       break;
670
+                               case bfd_reloc_undefined:
671
+                                       info->callbacks->undefined_symbol(
672
+                                               info, name, input_bfd,
673
+                                               input_section, rel->r_offset,
674
+                                               TRUE);
675
+                                       break;
676
+                               case bfd_reloc_outofrange:
677
+                                       msg = _("internal error: out of range error");
678
+                                       break;
679
+                               case bfd_reloc_notsupported:
680
+                                       msg = _("internal error: unsupported relocation");
681
+                                       break;
682
+                               case bfd_reloc_dangerous:
683
+                                       msg = _("internal error: dangerous relocation");
684
+                                       break;
685
+                               default:
686
+                                       msg = _("internal error: unknown error");
687
+                                       break;
688
+                       }
689
+
690
+                       if (msg)
691
+                               info->callbacks->warning(info, msg, name,
692
+                                       input_bfd, input_section,
693
+                                       rel->r_offset);
694
+
695
+                       if (!r)
696
+                               return FALSE;
697
+               }
698
+       }
699
+       return TRUE;
700
+}
701
+
702
+static uint32_t
703
+zip_bitreverse(uint32_t v) {
704
+       unsigned r = 0, b;
705
+
706
+       for(b=0; b<32; b++, v>>=1)
707
+               r = (r<<1)|(v&1);
708
+
709
+       return r;
710
+}
711
+
712
+static bfd_reloc_status_type
713
+zip_brev_relocation(bfd *abfd,
714
+               arelent *reloc_entry,
715
+               asymbol *symbol,
716
+               void *data,
717
+               asection *input_section,
718
+               bfd *output_bfd,
719
+               char **error_message)
720
+{
721
+       bfd_vma relocation;
722
+       bfd_size_type octets = reloc_entry->address * bfd_octets_per_byte(abfd);
723
+       bfd_vma output_base = 0;
724
+       reloc_howto_type *howto = reloc_entry->howto;
725
+
726
+       // If this isn't a final relocation, then just use the generic
727
+       // relocation function.
728
+       if (output_bfd != NULL) {
729
+               return zip_relocation(abfd, reloc_entry, symbol, data,
730
+                       input_section, output_bfd, error_message);
731
+       }
732
+
733
+       // Otherwise, we need to adjust our file itself with this value ...
734
+       // Check that our relocation lies within the file, and particularly
735
+       // the section we think it should.  (This should really be an assert...)
736
+       if (reloc_entry->address > bfd_get_section_limit(abfd, input_section))
737
+               return bfd_reloc_outofrange;
738
+
739
+       // Get symbol value
740
+       if (bfd_is_com_section(symbol->section))
741
+               relocation = 0;
742
+       else
743
+               relocation = symbol->value;
744
+
745
+       /* Convert input-section relative symbol value to absolute */
746
+       if ((!howto->partial_inplace)
747
+                       ||(symbol->section->output_section == NULL))
748
+               output_base = 0;
749
+       else
750
+               output_base = symbol->section->output_section->vma;
751
+
752
+       relocation += output_base + symbol->section->output_offset;
753
+
754
+       /* Add in supplied addend. */
755
+       relocation += reloc_entry->addend;
756
+
757
+       // BREV does not handle PC relative offsets
758
+
759
+       // Ignore overflow checking ... BREV handles the top 18 bits of a 32-bit
760
+       // number.  Overflow would mean overflowing the 32-bit address space--
761
+       // not possible.
762
+       //
763
+       // if howto->complain_on_overflow ...
764
+
765
+       // relocation >>= howto->rightshift;    // = 0
766
+       // relocation <<= howto->bitpos;        // = 0
767
+
768
+       // Logic (nearly) copied from reloc.c:bfd_perform_relocation
769
+       unsigned        insn = bfd_get_32(abfd, (bfd_byte *)data + octets);
770
+
771
+       // Here's why we are going through this pain!
772
+       insn = zip_bitreverse((unsigned)insn);
773
+
774
+       // Now we can continue as before....
775
+       insn = ((insn&(~howto->dst_mask))
776
+               |(((insn&howto->src_mask)+relocation)&howto->dst_mask));
777
+       bfd_put_32(abfd, (bfd_vma)insn, (bfd_byte *)data + octets);
778
+
779
+       return bfd_reloc_ok;
780
+}
781
+
782
+// Zip Defines
783
+#define        TARGET_BIG_SYM  zip_elf32_vec
784
+#define        TARGET_BIG_NAME "elf32-zip"
785
+
786
+#define        ELF_ARCH        bfd_arch_zip
787
+// #define ELF_TARGET_ID               ZIP_ELF_DATA
788
+#define        ELF_MACHINE_CODE        EM_ZIP
789
+
790
+#define        ELF_MAXPAGESIZE         0x1000
791
+#define        ARCH_SIZE               32
792
+
793
+
794
+#define bfd_elf32_bfd_define_common_symbol     bfd_generic_define_common_symbol
795
+
796
+
797
+#define        bfd_elf32_bfd_reloc_type_lookup zip_elf_reloc_type_lookup
798
+#define        bfd_elf32_bfd_reloc_name_lookup zip_elf_reloc_name_lookup
799
+#define        elf_info_to_howto_rel   0
800
+#define        elf_info_to_howto       zip_elf_info_to_howto
801
+#define        elf_backend_relocate_section    zip_elf_relocate_section
802
+#define        elf_backend_rela_normal         1
803
+
804
+// Default ELF32 defines from elf32-target.h that we would've normally included
805
+// here, had we not been a OCTETS_PER_BYTE=4 machine
806
+
807
+#define        bfd_elf32_close_and_cleanup _bfd_elf_close_and_cleanup
808
+#define bfd_elf32_bfd_free_cached_info _bfd_free_cached_info
809
+#define bfd_elf32_get_section_contents _bfd_generic_get_section_contents
810
+#define bfd_elf32_canonicalize_dynamic_symtab \
811
+  _bfd_elf_canonicalize_dynamic_symtab
812
+#define bfd_elf32_get_synthetic_symtab _bfd_elf_get_synthetic_symtab
813
+#define bfd_elf32_canonicalize_reloc   _bfd_elf_canonicalize_reloc
814
+#define bfd_elf32_find_nearest_line    _bfd_elf_find_nearest_line
815
+#define bfd_elf32_find_line            _bfd_elf_find_line
816
+#define bfd_elf32_find_inliner_info    _bfd_elf_find_inliner_info
817
+#define bfd_elf32_read_minisymbols     _bfd_elf_read_minisymbols
818
+#define bfd_elf32_minisymbol_to_symbol _bfd_elf_minisymbol_to_symbol
819
+#define bfd_elf32_get_dynamic_symtab_upper_bound \
820
+  _bfd_elf_get_dynamic_symtab_upper_bound
821
+#define bfd_elf32_get_lineno           _bfd_elf_get_lineno
822
+#define bfd_elf32_get_reloc_upper_bound _bfd_elf_get_reloc_upper_bound
823
+#define bfd_elf32_get_symbol_info      _bfd_elf_get_symbol_info
824
+#define bfd_elf32_get_symbol_version_string    _bfd_elf_get_symbol_version_string
825
+#define bfd_elf32_canonicalize_symtab  _bfd_elf_canonicalize_symtab
826
+#define bfd_elf32_get_symtab_upper_bound _bfd_elf_get_symtab_upper_bound
827
+#define bfd_elf32_make_empty_symbol    _bfd_elf_make_empty_symbol
828
+#define bfd_elf32_new_section_hook     _bfd_elf_new_section_hook
829
+#define bfd_elf32_set_arch_mach                _bfd_elf_set_arch_mach
830
+#define bfd_elf32_set_section_contents _bfd_elf_set_section_contents
831
+#define bfd_elf32_sizeof_headers       _bfd_elf_sizeof_headers
832
+#define bfd_elf32_write_object_contents _bfd_elf_write_object_contents
833
+#define bfd_elf32_write_corefile_contents _bfd_elf_write_corefile_contents
834
+
835
+#define bfd_elf32_get_section_contents_in_window \
836
+  _bfd_generic_get_section_contents_in_window
837
+
838
+#define elf_backend_can_refcount 0
839
+#define elf_backend_want_got_plt 0
840
+#define elf_backend_plt_readonly 0
841
+#define elf_backend_want_plt_sym 0
842
+#define elf_backend_plt_not_loaded 0
843
+#define elf_backend_plt_alignment 2
844
+#define elf_backend_want_dynbss 1
845
+#define elf_backend_want_p_paddr_set_to_zero 0
846
+#define elf_backend_default_execstack 1
847
+#define elf_backend_caches_rawsize 0
848
+#define elf_backend_extern_protected_data 0
849
+#define elf_backend_stack_align 4
850
+#define elf_backend_strtab_flags 0
851
+
852
+#define bfd_elf32_bfd_debug_info_start bfd_void
853
+#define bfd_elf32_bfd_debug_info_end   bfd_void
854
+#define bfd_elf32_bfd_debug_info_accumulate \
855
+  ((void (*) (bfd*, struct bfd_section *)) bfd_void)
856
+
857
+#define bfd_elf32_bfd_get_relocated_section_contents \
858
+  bfd_generic_get_relocated_section_contents
859
+
860
+#define bfd_elf32_bfd_relax_section bfd_generic_relax_section
861
+
862
+#define elf_backend_can_gc_sections 1
863
+#define elf_backend_can_refcount 0
864
+#define elf_backend_want_got_sym 1
865
+#define elf_backend_gc_keep            _bfd_elf_gc_keep
866
+#define elf_backend_gc_mark_dynamic_ref        bfd_elf_gc_mark_dynamic_ref_symbol
867
+#define elf_backend_gc_mark_hook       _bfd_elf_gc_mark_hook
868
+#define elf_backend_gc_mark_extra_sections _bfd_elf_gc_mark_extra_sections
869
+#define elf_backend_gc_sweep_hook      NULL
870
+#define bfd_elf32_bfd_gc_sections bfd_elf_gc_sections
871
+
872
+#ifndef bfd_elf32_bfd_merge_sections
873
+#define bfd_elf32_bfd_merge_sections _bfd_elf_merge_sections
874
+#endif
875
+
876
+#ifndef bfd_elf32_bfd_is_group_section
877
+#define bfd_elf32_bfd_is_group_section bfd_elf_is_group_section
878
+#endif
879
+
880
+#ifndef bfd_elf32_bfd_discard_group
881
+#define bfd_elf32_bfd_discard_group bfd_generic_discard_group
882
+#endif
883
+
884
+#ifndef bfd_elf32_section_already_linked
885
+#define bfd_elf32_section_already_linked _bfd_elf_section_already_linked
886
+#endif
887
+
888
+#ifndef bfd_elf32_bfd_define_common_symbol
889
+#define bfd_elf32_bfd_define_common_symbol bfd_generic_define_common_symbol
890
+#endif
891
+
892
+#ifndef bfd_elf32_bfd_lookup_section_flags
893
+#define bfd_elf32_bfd_lookup_section_flags bfd_elf_lookup_section_flags
894
+#endif
895
+
896
+#ifndef bfd_elf32_bfd_make_debug_symbol
897
+#define bfd_elf32_bfd_make_debug_symbol \
898
+  ((asymbol * (*) (bfd *, void *, unsigned long)) bfd_nullvoidptr)
899
+#endif
900
+
901
+#ifndef bfd_elf32_bfd_copy_private_symbol_data
902
+#define bfd_elf32_bfd_copy_private_symbol_data _bfd_elf_copy_private_symbol_data
903
+#endif
904
+
905
+#ifndef bfd_elf32_bfd_copy_private_section_data
906
+#define bfd_elf32_bfd_copy_private_section_data \
907
+  _bfd_elf_copy_private_section_data
908
+#endif
909
+#ifndef bfd_elf32_bfd_copy_private_header_data
910
+#define bfd_elf32_bfd_copy_private_header_data \
911
+  _bfd_elf_copy_private_header_data
912
+#endif
913
+#ifndef bfd_elf32_bfd_copy_private_bfd_data
914
+#define bfd_elf32_bfd_copy_private_bfd_data \
915
+  _bfd_elf_copy_private_bfd_data
916
+#endif
917
+#ifndef bfd_elf32_bfd_print_private_bfd_data
918
+#define bfd_elf32_bfd_print_private_bfd_data \
919
+  _bfd_elf_print_private_bfd_data
920
+#endif
921
+#ifndef bfd_elf32_bfd_merge_private_bfd_data
922
+#define bfd_elf32_bfd_merge_private_bfd_data \
923
+  ((bfd_boolean (*) (bfd *, bfd *)) bfd_true)
924
+#endif
925
+#ifndef bfd_elf32_bfd_set_private_flags
926
+#define bfd_elf32_bfd_set_private_flags \
927
+  ((bfd_boolean (*) (bfd *, flagword)) bfd_true)
928
+#endif
929
+#ifndef bfd_elf32_bfd_is_local_label_name
930
+#define bfd_elf32_bfd_is_local_label_name _bfd_elf_is_local_label_name
931
+#endif
932
+#ifndef bfd_elf32_bfd_is_target_special_symbol
933
+#define bfd_elf32_bfd_is_target_special_symbol \
934
+  ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
935
+#endif
936
+
937
+#ifndef bfd_elf32_get_dynamic_reloc_upper_bound
938
+#define bfd_elf32_get_dynamic_reloc_upper_bound \
939
+  _bfd_elf_get_dynamic_reloc_upper_bound
940
+#endif
941
+#ifndef bfd_elf32_canonicalize_dynamic_reloc
942
+#define bfd_elf32_canonicalize_dynamic_reloc _bfd_elf_canonicalize_dynamic_reloc
943
+#endif
944
+
945
+#define bfd_elf32_bfd_link_hash_table_create _bfd_elf_link_hash_table_create
946
+#define bfd_elf32_bfd_link_add_symbols bfd_elf_link_add_symbols
947
+#define bfd_elf32_bfd_final_link       bfd_elf_final_link
948
+
949
+#define bfd_elf32_bfd_link_just_syms   _bfd_elf_link_just_syms
950
+
951
+#define bfd_elf32_bfd_copy_link_hash_symbol_type \
952
+  _bfd_elf_copy_link_hash_symbol_type
953
+
954
+#define bfd_elf32_bfd_link_split_section _bfd_generic_link_split_section
955
+#define bfd_elf32_bfd_link_check_relocs _bfd_generic_link_check_relocs
956
+#define bfd_elf32_archive_p bfd_generic_archive_p
957
+#define bfd_elf32_write_archive_contents _bfd_write_archive_contents
958
+#define bfd_elf32_mkobject bfd_elf_make_object
959
+#define bfd_elf32_mkcorefile bfd_elf_mkcorefile
960
+#define bfd_elf32_mkarchive _bfd_generic_mkarchive
961
+#define bfd_elf32_print_symbol bfd_elf_print_symbol
962
+#define elf_symbol_leading_char 0
963
+
964
+#define elf_backend_arch_data NULL
965
+
966
+#ifndef ELF_TARGET_ID
967
+#define ELF_TARGET_ID  GENERIC_ELF_DATA
968
+#endif
969
+
970
+#ifndef ELF_OSABI
971
+#define ELF_OSABI ELFOSABI_NONE
972
+#endif
973
+
974
+#define ELF_COMMONPAGESIZE ELF_MAXPAGESIZE
975
+#define ELF_MINPAGESIZE ELF_COMMONPAGESIZE
976
+
977
+#if ELF_COMMONPAGESIZE > ELF_MAXPAGESIZE
978
+# error ELF_COMMONPAGESIZE > ELF_MAXPAGESIZE
979
+#endif
980
+#if ELF_MINPAGESIZE > ELF_COMMONPAGESIZE
981
+# error ELF_MINPAGESIZE > ELF_COMMONPAGESIZE
982
+#endif
983
+
984
+#ifndef ELF_DYNAMIC_SEC_FLAGS
985
+/* Note that we set the SEC_IN_MEMORY flag for these sections.  */
986
+#define ELF_DYNAMIC_SEC_FLAGS                  \
987
+  (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS     \
988
+   | SEC_IN_MEMORY | SEC_LINKER_CREATED)
989
+#endif
990
+
991
+#define elf_backend_collect FALSE
992
+#define elf_backend_type_change_ok FALSE
993
+
994
+#define elf_backend_sym_is_global      0
995
+#define elf_backend_object_p           0
996
+#define elf_backend_symbol_processing  0
997
+#define elf_backend_symbol_table_processing    0
998
+#define elf_backend_get_symbol_type 0
999
+#define elf_backend_archive_symbol_lookup _bfd_elf_archive_symbol_lookup
1000
+#define elf_backend_name_local_section_symbols 0
1001
+#define elf_backend_section_processing 0
1002
+#define elf_backend_section_from_shdr  _bfd_elf_make_section_from_shdr
1003
+#define elf_backend_section_flags      0
1004
+#define elf_backend_get_sec_type_attr  _bfd_elf_get_sec_type_attr
1005
+#define elf_backend_section_from_phdr  _bfd_elf_make_section_from_phdr
1006
+#define elf_backend_fake_sections      0
1007
+#define elf_backend_section_from_bfd_section   0
1008
+#define elf_backend_add_symbol_hook    0
1009
+#define elf_backend_link_output_symbol_hook 0
1010
+#define elf_backend_create_dynamic_sections 0
1011
+#define elf_backend_omit_section_dynsym _bfd_elf_link_omit_section_dynsym
1012
+#define elf_backend_relocs_compatible _bfd_elf_default_relocs_compatible
1013
+#define elf_backend_check_relocs       0
1014
+#define elf_backend_check_directives   0
1015
+#define elf_backend_notice_as_needed   _bfd_elf_notice_as_needed
1016
+#define elf_backend_adjust_dynamic_symbol 0
1017
+#define elf_backend_always_size_sections 0
1018
+#define elf_backend_size_dynamic_sections 0
1019
+#define elf_backend_init_index_section \
1020
+ ((void (*) (bfd *, struct bfd_link_info *)) bfd_void)
1021
+#define elf_backend_finish_dynamic_symbol      0
1022
+#define elf_backend_finish_dynamic_sections    0
1023
+#define elf_backend_begin_write_processing     0
1024
+#define elf_backend_final_write_processing     0
1025
+#define elf_backend_additional_program_headers 0
1026
+#define elf_backend_modify_segment_map 0
1027
+#ifndef elf_backend_modify_program_headers
1028
+#define elf_backend_modify_program_headers     0
1029
+#endif
1030
+#ifndef elf_backend_ecoff_debug_swap
1031
+#define elf_backend_ecoff_debug_swap   0
1032
+#endif
1033
+#ifndef elf_backend_bfd_from_remote_memory
1034
+#define elf_backend_bfd_from_remote_memory _bfd_elf32_bfd_from_remote_memory
1035
+#endif
1036
+#ifndef elf_backend_got_header_size
1037
+#define elf_backend_got_header_size    0
1038
+#endif
1039
+#ifndef elf_backend_got_elt_size
1040
+#define elf_backend_got_elt_size _bfd_elf_default_got_elt_size
1041
+#endif
1042
+#ifndef elf_backend_obj_attrs_vendor
1043
+#define elf_backend_obj_attrs_vendor           NULL
1044
+#endif
1045
+#ifndef elf_backend_obj_attrs_section
1046
+#define elf_backend_obj_attrs_section          NULL
1047
+#endif
1048
+#ifndef elf_backend_obj_attrs_arg_type
1049
+#define elf_backend_obj_attrs_arg_type         NULL
1050
+#endif
1051
+#ifndef elf_backend_obj_attrs_section_type
1052
+#define elf_backend_obj_attrs_section_type             SHT_GNU_ATTRIBUTES
1053
+#endif
1054
+#ifndef elf_backend_obj_attrs_order
1055
+#define elf_backend_obj_attrs_order            NULL
1056
+#endif
1057
+#define elf_backend_obj_attrs_handle_unknown   NULL
1058
+#define elf_backend_static_tls_alignment       1
1059
+#define elf_backend_post_process_headers       _bfd_elf_post_process_headers
1060
+#define elf_backend_print_symbol_all           NULL
1061
+#define elf_backend_output_arch_local_syms     NULL
1062
+#define elf_backend_output_arch_syms           NULL
1063
+#define elf_backend_copy_indirect_symbol  _bfd_elf_link_hash_copy_indirect
1064
+#define elf_backend_hide_symbol                _bfd_elf_link_hash_hide_symbol
1065
+#define elf_backend_fixup_symbol               NULL
1066
+#define elf_backend_merge_symbol_attribute     NULL
1067
+#define elf_backend_get_target_dtag            NULL
1068
+#define elf_backend_ignore_undef_symbol                NULL
1069
+#define elf_backend_emit_relocs                        _bfd_elf_link_output_relocs
1070
+#define elf_backend_count_relocs               NULL
1071
+#define elf_backend_count_additional_relocs    NULL
1072
+#define elf_backend_sort_relocs_p              NULL
1073
+#define elf_backend_grok_prstatus              NULL
1074
+#define elf_backend_grok_psinfo                        NULL
1075
+#define elf_backend_write_core_note            NULL
1076
+#define elf_backend_lookup_section_flags_hook  NULL
1077
+#define elf_backend_reloc_type_class           _bfd_elf_reloc_type_class
1078
+#define elf_backend_discard_info               NULL
1079
+#define elf_backend_ignore_discarded_relocs    NULL
1080
+#define elf_backend_action_discarded _bfd_elf_default_action_discarded
1081
+#define elf_backend_eh_frame_address_size _bfd_elf_eh_frame_address_size
1082
+#define elf_backend_can_make_relative_eh_frame _bfd_elf_can_make_relative
1083
+#define elf_backend_can_make_lsda_relative_eh_frame    _bfd_elf_can_make_relative
1084
+#define elf_backend_encode_eh_address          _bfd_elf_encode_eh_address
1085
+#define elf_backend_write_section              NULL
1086
+#define elf_backend_mips_irix_compat           NULL
1087
+#define elf_backend_mips_rtype_to_howto                NULL
1088
+
1089
+/* Previously, backends could only use SHT_REL or SHT_RELA relocation
1090
+   sections, but not both.  They defined USE_REL to indicate SHT_REL
1091
+   sections, and left it undefined to indicated SHT_RELA sections.
1092
+   For backwards compatibility, we still support this usage.  */
1093
+#ifndef USE_REL
1094
+#define USE_REL 0
1095
+#endif
1096
+
1097
+/* Use these in new code.  */
1098
+#define elf_backend_may_use_rel_p USE_REL
1099
+#define elf_backend_may_use_rela_p !USE_REL
1100
+#define elf_backend_default_use_rela_p !USE_REL
1101
+#define elf_backend_rela_plts_and_copies_p elf_backend_default_use_rela_p
1102
+
1103
+#ifndef elf_backend_rela_normal
1104
+#define elf_backend_rela_normal 0
1105
+#endif
1106
+
1107
+#define elf_backend_plt_sym_val NULL
1108
+#define elf_backend_relplt_name NULL
1109
+
1110
+#define ELF_MACHINE_ALT1 0
1111
+#define ELF_MACHINE_ALT2 0
1112
+
1113
+#ifndef elf_backend_size_info
1114
+#define elf_backend_size_info _bfd_elf32_size_info
1115
+#endif
1116
+
1117
+#define elf_backend_special_sections NULL
1118
+#define elf_backend_sign_extend_vma 0
1119
+#define elf_backend_link_order_error_handler _bfd_default_error_handler
1120
+#define elf_backend_common_definition _bfd_elf_common_definition
1121
+#define elf_backend_common_section_index _bfd_elf_common_section_index
1122
+#define elf_backend_common_section _bfd_elf_common_section
1123
+
1124
+#define elf_backend_merge_symbol NULL
1125
+#define elf_backend_hash_symbol _bfd_elf_hash_symbol
1126
+#define elf_backend_is_function_type _bfd_elf_is_function_type
1127
+#define elf_backend_maybe_function_sym _bfd_elf_maybe_function_sym
1128
+#define elf_backend_get_reloc_section _bfd_elf_get_reloc_section
1129
+#define elf_backend_copy_special_section_fields NULL
1130
+#define elf_backend_compact_eh_encoding NULL
1131
+#define elf_backend_cant_unwind_opcode 0
1132
+
1133
+#define elf_match_priority \
1134
+  (ELF_ARCH == bfd_arch_unknown ? 2 : ELF_OSABI == ELFOSABI_NONE ? 1 : 0)
1135
+
1136
+extern const struct elf_size_info _bfd_elf32_size_info;
1137
+
1138
+static struct elf_backend_data elf32_bed =
1139
+{
1140
+  ELF_ARCH,                    /* arch */
1141
+  ELF_TARGET_ID,               /* target_id */
1142
+  ELF_MACHINE_CODE,            /* elf_machine_code */
1143
+  ELF_OSABI,                   /* elf_osabi  */
1144
+  ELF_MAXPAGESIZE,             /* maxpagesize */
1145
+  ELF_MINPAGESIZE,             /* minpagesize */
1146
+  ELF_COMMONPAGESIZE,          /* commonpagesize */
1147
+  ELF_DYNAMIC_SEC_FLAGS,       /* dynamic_sec_flags */
1148
+  elf_backend_arch_data,
1149
+  elf_info_to_howto,
1150
+  elf_info_to_howto_rel,
1151
+  elf_backend_sym_is_global,
1152
+  elf_backend_object_p,
1153
+  elf_backend_symbol_processing,
1154
+  elf_backend_symbol_table_processing,
1155
+  elf_backend_get_symbol_type,
1156
+  elf_backend_archive_symbol_lookup,
1157
+  elf_backend_name_local_section_symbols,
1158
+  elf_backend_section_processing,
1159
+  elf_backend_section_from_shdr,
1160
+  elf_backend_section_flags,
1161
+  elf_backend_get_sec_type_attr,
1162
+  elf_backend_section_from_phdr,
1163
+  elf_backend_fake_sections,
1164
+  elf_backend_section_from_bfd_section,
1165
+  elf_backend_add_symbol_hook,
1166
+  elf_backend_link_output_symbol_hook,
1167
+  elf_backend_create_dynamic_sections,
1168
+  elf_backend_omit_section_dynsym,
1169
+  elf_backend_relocs_compatible,
1170
+  elf_backend_check_relocs,
1171
+  elf_backend_check_directives,
1172
+  elf_backend_notice_as_needed,
1173
+  elf_backend_adjust_dynamic_symbol,
1174
+  elf_backend_always_size_sections,
1175
+  elf_backend_size_dynamic_sections,
1176
+  elf_backend_init_index_section,
1177
+  elf_backend_relocate_section,
1178
+  elf_backend_finish_dynamic_symbol,
1179
+  elf_backend_finish_dynamic_sections,
1180
+  elf_backend_begin_write_processing,
1181
+  elf_backend_final_write_processing,
1182
+  elf_backend_additional_program_headers,
1183
+  elf_backend_modify_segment_map,
1184
+  elf_backend_modify_program_headers,
1185
+  elf_backend_gc_keep,
1186
+  elf_backend_gc_mark_dynamic_ref,
1187
+  elf_backend_gc_mark_hook,
1188
+  elf_backend_gc_mark_extra_sections,
1189
+  elf_backend_gc_sweep_hook,
1190
+  elf_backend_post_process_headers,
1191
+  elf_backend_print_symbol_all,
1192
+  elf_backend_output_arch_local_syms,
1193
+  elf_backend_output_arch_syms,
1194
+  elf_backend_copy_indirect_symbol,
1195
+  elf_backend_hide_symbol,
1196
+  elf_backend_fixup_symbol,
1197
+  elf_backend_merge_symbol_attribute,
1198
+  elf_backend_get_target_dtag,
1199
+  elf_backend_ignore_undef_symbol,
1200
+  elf_backend_emit_relocs,
1201
+  elf_backend_count_relocs,
1202
+  elf_backend_count_additional_relocs,
1203
+  elf_backend_sort_relocs_p,
1204
+  elf_backend_grok_prstatus,
1205
+  elf_backend_grok_psinfo,
1206
+  elf_backend_write_core_note,
1207
+  elf_backend_lookup_section_flags_hook,
1208
+  elf_backend_reloc_type_class,
1209
+  elf_backend_discard_info,
1210
+  elf_backend_ignore_discarded_relocs,
1211
+  elf_backend_action_discarded,
1212
+  elf_backend_eh_frame_address_size,
1213
+  elf_backend_can_make_relative_eh_frame,
1214
+  elf_backend_can_make_lsda_relative_eh_frame,
1215
+  elf_backend_encode_eh_address,
1216
+  elf_backend_write_section,
1217
+  elf_backend_mips_irix_compat,
1218
+  elf_backend_mips_rtype_to_howto,
1219
+  elf_backend_ecoff_debug_swap,
1220
+  elf_backend_bfd_from_remote_memory,
1221
+  elf_backend_plt_sym_val,
1222
+  elf_backend_common_definition,
1223
+  elf_backend_common_section_index,
1224
+  elf_backend_common_section,
1225
+  elf_backend_merge_symbol,
1226
+  elf_backend_hash_symbol,
1227
+  elf_backend_is_function_type,
1228
+  elf_backend_maybe_function_sym,
1229
+  elf_backend_get_reloc_section,
1230
+  elf_backend_copy_special_section_fields,
1231
+  elf_backend_link_order_error_handler,
1232
+  elf_backend_relplt_name,
1233
+  ELF_MACHINE_ALT1,
1234
+  ELF_MACHINE_ALT2,
1235
+  &elf_backend_size_info,
1236
+  elf_backend_special_sections,
1237
+  elf_backend_got_header_size,
1238
+  elf_backend_got_elt_size,
1239
+  elf_backend_obj_attrs_vendor,
1240
+  elf_backend_obj_attrs_section,
1241
+  elf_backend_obj_attrs_arg_type,
1242
+  elf_backend_obj_attrs_section_type,
1243
+  elf_backend_obj_attrs_order,
1244
+  elf_backend_obj_attrs_handle_unknown,
1245
+  elf_backend_compact_eh_encoding,
1246
+  elf_backend_cant_unwind_opcode,
1247
+  elf_backend_static_tls_alignment,
1248
+  elf_backend_stack_align,
1249
+  elf_backend_strtab_flags,
1250
+  elf_backend_collect,
1251
+  elf_backend_type_change_ok,
1252
+  elf_backend_may_use_rel_p,
1253
+  elf_backend_may_use_rela_p,
1254
+  elf_backend_default_use_rela_p,
1255
+  elf_backend_rela_plts_and_copies_p,
1256
+  elf_backend_rela_normal,
1257
+  elf_backend_sign_extend_vma,
1258
+  elf_backend_want_got_plt,
1259
+  elf_backend_plt_readonly,
1260
+  elf_backend_want_plt_sym,
1261
+  elf_backend_plt_not_loaded,
1262
+  elf_backend_plt_alignment,
1263
+  elf_backend_can_gc_sections,
1264
+  elf_backend_can_refcount,
1265
+  elf_backend_want_got_sym,
1266
+  elf_backend_want_dynbss,
1267
+  elf_backend_want_p_paddr_set_to_zero,
1268
+  elf_backend_default_execstack,
1269
+  elf_backend_caches_rawsize,
1270
+  elf_backend_extern_protected_data
1271
+};
1272
+
1273
+/* Forward declaration for use when initialising alternative_target field.  */
1274
+
1275
+#ifdef TARGET_BIG_SYM
1276
+const bfd_target TARGET_BIG_SYM =
1277
+{
1278
+  /* name: identify kind of target */
1279
+  TARGET_BIG_NAME,
1280
+
1281
+  /* flavour: general indication about file */
1282
+  bfd_target_elf_flavour,
1283
+
1284
+  /* byteorder: data is big endian */
1285
+  BFD_ENDIAN_BIG,
1286
+
1287
+  /* header_byteorder: header is also big endian */
1288
+  BFD_ENDIAN_BIG,
1289
+
1290
+  /* object_flags: mask of all file flags */
1291
+  (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | HAS_SYMS | HAS_LOCALS
1292
+   | DYNAMIC | WP_TEXT | D_PAGED | BFD_COMPRESS | BFD_DECOMPRESS
1293
+   | BFD_COMPRESS_GABI | BFD_CONVERT_ELF_COMMON | BFD_USE_ELF_STT_COMMON),
1294
+
1295
+  /* section_flags: mask of all section flags */
1296
+  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_READONLY
1297
+   | SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_EXCLUDE | SEC_SORT_ENTRIES
1298
+   | SEC_SMALL_DATA | SEC_MERGE | SEC_STRINGS | SEC_GROUP),
1299
+
1300
+   /* leading_symbol_char: is the first char of a user symbol
1301
+      predictable, and if so what is it */
1302
+  elf_symbol_leading_char,
1303
+
1304
+  /* ar_pad_char: pad character for filenames within an archive header
1305
+     FIXME:  this really has nothing to do with ELF, this is a characteristic
1306
+     of the archiver and/or os and should be independently tunable */
1307
+  '/',
1308
+
1309
+  /* ar_max_namelen: maximum number of characters in an archive header
1310
+     FIXME:  this really has nothing to do with ELF, this is a characteristic
1311
+     of the archiver and should be independently tunable.  The System V ABI,
1312
+     Chapter 7 (Formats & Protocols), Archive section sets this as 15.  */
1313
+  15,
1314
+
1315
+  elf_match_priority,
1316
+
1317
+  /* Routines to byte-swap various sized integers from the data sections */
1318
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1319
+    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1320
+    bfd_getb16, bfd_getb_signed_16, bfd_putb16,
1321
+
1322
+  /* Routines to byte-swap various sized integers from the file headers */
1323
+  bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1324
+    bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1325
+    bfd_getb16, bfd_getb_signed_16, bfd_putb16,
1326
+
1327
+  /* bfd_check_format: check the format of a file being read */
1328
+  { _bfd_dummy_target,         /* unknown format */
1329
+    bfd_elf32_object_p,                /* assembler/linker output (object file) */
1330
+    bfd_elf32_archive_p,       /* an archive */
1331
+    bfd_elf32_core_file_p      /* a core file */
1332
+  },
1333
+
1334
+  /* bfd_set_format: set the format of a file being written */
1335
+  { bfd_false,
1336
+    bfd_elf32_mkobject,
1337
+    bfd_elf32_mkarchive,
1338
+    bfd_elf32_mkcorefile
1339
+  },
1340
+
1341
+  /* bfd_write_contents: write cached information into a file being written */
1342
+  { bfd_false,
1343
+    bfd_elf32_write_object_contents,
1344
+    bfd_elf32_write_archive_contents,
1345
+    bfd_elf32_write_corefile_contents,
1346
+  },
1347
+
1348
+  BFD_JUMP_TABLE_GENERIC (bfd_elf32),
1349
+  BFD_JUMP_TABLE_COPY (bfd_elf32),
1350
+  BFD_JUMP_TABLE_CORE (bfd_elf32),
1351
+#ifdef bfd_elf32_archive_functions
1352
+  BFD_JUMP_TABLE_ARCHIVE (bfd_elf32_archive),
1353
+#else
1354
+  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_coff),
1355
+#endif
1356
+  BFD_JUMP_TABLE_SYMBOLS (bfd_elf32),
1357
+  BFD_JUMP_TABLE_RELOCS (bfd_elf32),
1358
+  BFD_JUMP_TABLE_WRITE (bfd_elf32),
1359
+  BFD_JUMP_TABLE_LINK (bfd_elf32),
1360
+  BFD_JUMP_TABLE_DYNAMIC (bfd_elf32),
1361
+
1362
+  /* Alternative endian target.  */
1363
+#ifdef TARGET_LITTLE_SYM
1364
+  & TARGET_LITTLE_SYM,
1365
+#else
1366
+  NULL,
1367
+#endif
1368
+
1369
+  /* backend_data: */
1370
+  &elf32_bed
1371
+};
1372
+#endif
1373
+
1374
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/libbfd.h binutils-2.27-zip/bfd/libbfd.h
1375
--- binutils-2.27/bfd/libbfd.h  2016-08-03 03:36:51.000000000 -0400
1376
+++ binutils-2.27-zip/bfd/libbfd.h      2017-01-04 22:04:11.000000000 -0500
1377
@@ -3125,6 +3125,16 @@
1378
   "BFD_RELOC_VISIUM_HI16_PCREL",
1379
   "BFD_RELOC_VISIUM_LO16_PCREL",
1380
   "BFD_RELOC_VISIUM_IM16_PCREL",
1381
+  "BFD_RELOC_ZIP_VALUE",
1382
+  "BFD_RELOC_ZIP_BRANCH",
1383
+  "BFD_RELOC_ZIP_OPB_IMM",
1384
+  "BFD_RELOC_ZIP_OPB_OFFSET",
1385
+  "BFD_RELOC_ZIP_OPB_PCREL",
1386
+  "BFD_RELOC_ZIP_MOV_OFFSET",
1387
+  "BFD_RELOC_ZIP_MOV_PCREL",
1388
+  "BFD_RELOC_ZIP_LDI",
1389
+  "BFD_RELOC_ZIP_LLO",
1390
+  "BFD_RELOC_ZIP_BREV",
1391
  "@@overflow: BFD_RELOC_UNUSED@@",
1392
 };
1393
 #endif
1394
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/Makefile.am binutils-2.27-zip/bfd/Makefile.am
1395
--- binutils-2.27/bfd/Makefile.am       2016-08-03 03:36:50.000000000 -0400
1396
+++ binutils-2.27-zip/bfd/Makefile.am   2016-12-31 17:26:07.151146300 -0500
1397
@@ -173,7 +173,8 @@
1398
        cpu-xstormy16.lo \
1399
        cpu-xtensa.lo \
1400
        cpu-z80.lo \
1401
-       cpu-z8k.lo
1402
+       cpu-z8k.lo \
1403
+       cpu-zip.lo
1404
 
1405
 ALL_MACHINES_CFILES = \
1406
        cpu-aarch64.c \
1407
@@ -260,7 +261,8 @@
1408
        cpu-xstormy16.c \
1409
        cpu-xtensa.c \
1410
        cpu-z80.c \
1411
-       cpu-z8k.c
1412
+       cpu-z8k.c \
1413
+       cpu-zip.c
1414
 
1415
 # The .o files needed by all of the 32 bit vectors that are configured into
1416
 # target_vector in targets.c if configured with --enable-targets=all.
1417
@@ -382,6 +384,7 @@
1418
        elf32-xgate.lo \
1419
        elf32-xstormy16.lo \
1420
        elf32-xtensa.lo \
1421
+       elf32-zip.lo \
1422
        elf32.lo \
1423
        elflink.lo \
1424
        elfxx-sparc.lo \
1425
@@ -574,6 +577,7 @@
1426
        elf32-xgate.c \
1427
        elf32-xstormy16.c \
1428
        elf32-xtensa.c \
1429
+       elf32-zip.c \
1430
        elf32.c \
1431
        elflink.c \
1432
        elfxx-sparc.c \
1433
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/Makefile.in binutils-2.27-zip/bfd/Makefile.in
1434
--- binutils-2.27/bfd/Makefile.in       2016-08-03 04:06:27.000000000 -0400
1435
+++ binutils-2.27-zip/bfd/Makefile.in   2017-01-04 14:29:55.000000000 -0500
1436
@@ -505,7 +505,8 @@
1437
        cpu-xstormy16.lo \
1438
        cpu-xtensa.lo \
1439
        cpu-z80.lo \
1440
-       cpu-z8k.lo
1441
+       cpu-z8k.lo \
1442
+       cpu-zip.lo
1443
 
1444
 ALL_MACHINES_CFILES = \
1445
        cpu-aarch64.c \
1446
@@ -592,7 +593,8 @@
1447
        cpu-xstormy16.c \
1448
        cpu-xtensa.c \
1449
        cpu-z80.c \
1450
-       cpu-z8k.c
1451
+       cpu-z8k.c \
1452
+       cpu-zip.c
1453
 
1454
 
1455
 # The .o files needed by all of the 32 bit vectors that are configured into
1456
@@ -715,6 +717,7 @@
1457
        elf32-xgate.lo \
1458
        elf32-xstormy16.lo \
1459
        elf32-xtensa.lo \
1460
+       elf32-zip.lo \
1461
        elf32.lo \
1462
        elflink.lo \
1463
        elfxx-sparc.lo \
1464
@@ -907,6 +910,7 @@
1465
        elf32-xgate.c \
1466
        elf32-xstormy16.c \
1467
        elf32-xtensa.c \
1468
+       elf32-zip.c \
1469
        elf32.c \
1470
        elflink.c \
1471
        elfxx-sparc.c \
1472
@@ -1437,6 +1441,7 @@
1473
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu-xtensa.Plo@am__quote@
1474
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu-z80.Plo@am__quote@
1475
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu-z8k.Plo@am__quote@
1476
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu-zip.Plo@am__quote@
1477
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/demo64.Plo@am__quote@
1478
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dwarf1.Plo@am__quote@
1479
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dwarf2.Plo@am__quote@
1480
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/merge.c binutils-2.27-zip/bfd/merge.c
1481
--- binutils-2.27/bfd/merge.c   2016-08-03 03:36:51.000000000 -0400
1482
+++ binutils-2.27-zip/bfd/merge.c       2017-01-02 14:48:54.000000000 -0500
1483
@@ -826,7 +826,7 @@
1484
   else
1485
     {
1486
       contents = NULL;
1487
-      pos = sec->output_section->filepos + sec->output_offset;
1488
+      pos = sec->output_section->filepos + sec->output_offset * bfd_octets_per_byte(output_bfd);
1489
       if (bfd_seek (output_bfd, pos, SEEK_SET) != 0)
1490
        return FALSE;
1491
     }
1492
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/reloc.c binutils-2.27-zip/bfd/reloc.c
1493
--- binutils-2.27/bfd/reloc.c   2016-08-03 03:36:51.000000000 -0400
1494
+++ binutils-2.27-zip/bfd/reloc.c       2017-01-04 22:03:52.000000000 -0500
1495
@@ -7697,7 +7697,32 @@
1496
   BFD_RELOC_VISIUM_IM16_PCREL
1497
 ENUMDOC
1498
   Visium Relocations.
1499
-
1500
+ENUM
1501
+  BFD_RELOC_ZIP_VALUE
1502
+ENUMDOC
1503
+  ZipCPU - 32 bit absolute value for LJMP instruction
1504
+ENUM
1505
+  BFD_RELOC_ZIP_BRANCH
1506
+ENUMDOC
1507
+  ZipCPU - 18-bit PC-relative offset for BRA (ADD #x,PC) instructions
1508
+ENUM
1509
+  BFD_RELOC_ZIP_OPB_IMM
1510
+ENUMX
1511
+  BFD_RELOC_ZIP_OPB_OFFSET
1512
+ENUMX
1513
+  BFD_RELOC_ZIP_OPB_PCREL
1514
+ENUMX
1515
+  BFD_RELOC_ZIP_MOV_OFFSET
1516
+ENUMX
1517
+  BFD_RELOC_ZIP_MOV_PCREL
1518
+ENUMX
1519
+  BFD_RELOC_ZIP_LDI
1520
+ENUMX
1521
+  BFD_RELOC_ZIP_LLO
1522
+ENUMX
1523
+  BFD_RELOC_ZIP_BREV
1524
+ENUMDOC
1525
+  ZipCPU value relocations
1526
 ENDSENUM
1527
   BFD_RELOC_UNUSED
1528
 CODE_FRAGMENT
1529
diff -Naur '--exclude=*.swp' binutils-2.27/bfd/targets.c binutils-2.27-zip/bfd/targets.c
1530
--- binutils-2.27/bfd/targets.c 2016-08-03 03:36:51.000000000 -0400
1531
+++ binutils-2.27-zip/bfd/targets.c     2016-12-31 17:37:14.021847080 -0500
1532
@@ -910,6 +910,7 @@
1533
 extern const bfd_target xtensa_elf32_le_vec;
1534
 extern const bfd_target z80_coff_vec;
1535
 extern const bfd_target z8k_coff_vec;
1536
+extern const bfd_target zip_elf32_vec;
1537
 
1538
 /* These are always included.  */
1539
 extern const bfd_target srec_vec;
1540
@@ -1441,6 +1442,8 @@
1541
        &z80_coff_vec,
1542
 
1543
        &z8k_coff_vec,
1544
+
1545
+       &zip_elf32_vec,
1546
 #endif /* not SELECT_VECS */
1547
 
1548
 /* Always support S-records, for convenience.  */
1549
diff -Naur '--exclude=*.swp' binutils-2.27/binutils/readelf.c binutils-2.27-zip/binutils/readelf.c
1550
--- binutils-2.27/binutils/readelf.c    2016-08-03 03:36:51.000000000 -0400
1551
+++ binutils-2.27-zip/binutils/readelf.c        2016-12-31 17:40:19.908241961 -0500
1552
@@ -154,6 +154,7 @@
1553
 #include "elf/xgate.h"
1554
 #include "elf/xstormy16.h"
1555
 #include "elf/xtensa.h"
1556
+#include "elf/zip.h"
1557
 
1558
 #include "getopt.h"
1559
 #include "libiberty.h"
1560
@@ -800,6 +801,7 @@
1561
     case EM_XTENSA_OLD:
1562
     case EM_MICROBLAZE:
1563
     case EM_MICROBLAZE_OLD:
1564
+    case EM_ZIP:
1565
       return TRUE;
1566
 
1567
     case EM_68HC05:
1568
@@ -1476,6 +1478,10 @@
1569
        case EM_ALTERA_NIOS2:
1570
          rtype = elf_nios2_reloc_type (type);
1571
          break;
1572
+
1573
+       case EM_ZIP:
1574
+         rtype = elf_zip_reloc_type (type);
1575
+         break;
1576
        }
1577
 
1578
       if (rtype == NULL)
1579
@@ -2339,6 +2345,7 @@
1580
     case EM_TILEGX:            return "Tilera TILE-Gx multicore architecture family";
1581
     case EM_CUDA:              return "NVIDIA CUDA architecture";
1582
     case EM_XGATE:             return "Motorola XGATE embedded processor";
1583
+    case EM_ZIP:               return "Gisselquist Technology ZipCPU";
1584
     default:
1585
       snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
1586
       return buff;
1587
@@ -11659,6 +11666,8 @@
1588
     case EM_XTENSA_OLD:
1589
     case EM_XTENSA:
1590
       return reloc_type == 1; /* R_XTENSA_32.  */
1591
+    case EM_ZIP:
1592
+      return reloc_type == 1; /* R_ZIP_32.  */
1593
     default:
1594
       {
1595
        static unsigned int prev_warn = 0;
1596
@@ -11735,6 +11744,8 @@
1597
     case EM_XTENSA_OLD:
1598
     case EM_XTENSA:
1599
       return reloc_type == 14; /* R_XTENSA_32_PCREL.  */
1600
+    case EM_ZIP:
1601
+      return FALSE; /*  */
1602
     default:
1603
       /* Do not abort or issue an error message here.  Not all targets use
1604
         pc-relative 32-bit relocs in their DWARF debug information and we
1605
@@ -11944,6 +11955,7 @@
1606
     case EM_TI_C6000:/* R_C6000_NONE.  */
1607
     case EM_X86_64:  /* R_X86_64_NONE.  */
1608
     case EM_XC16X:
1609
+    case EM_ZIP:
1610
       return reloc_type == 0;
1611
 
1612
     case EM_AARCH64:
1613
diff -Naur '--exclude=*.swp' binutils-2.27/config.sub binutils-2.27-zip/config.sub
1614
--- binutils-2.27/config.sub    2016-08-03 03:36:51.000000000 -0400
1615
+++ binutils-2.27-zip/config.sub        2017-01-11 14:20:34.804049801 -0500
1616
@@ -316,7 +316,7 @@
1617
        | visium \
1618
        | we32k \
1619
        | x86 | xc16x | xstormy16 | xtensa \
1620
-       | z8k | z80)
1621
+       | z8k | z80 )
1622
                basic_machine=$basic_machine-unknown
1623
                ;;
1624
        c54x)
1625
@@ -355,6 +355,14 @@
1626
        xscaleel)
1627
                basic_machine=armel-unknown
1628
                ;;
1629
+       zip-*-linux*)
1630
+               basic_machine=zip
1631
+               os=-linux
1632
+               ;;
1633
+       zip*)
1634
+               basic_machine=zip-unknown
1635
+               os=-elf
1636
+               ;;
1637
 
1638
        # We use `pc' rather than `unknown'
1639
        # because (1) that's what they normally are, and
1640
diff -Naur '--exclude=*.swp' binutils-2.27/configure binutils-2.27-zip/configure
1641
--- binutils-2.27/configure     2016-08-03 03:54:55.000000000 -0400
1642
+++ binutils-2.27-zip/configure 2017-01-08 20:37:33.566336786 -0500
1643
@@ -3548,6 +3548,9 @@
1644
   ft32-*-*)
1645
     noconfigdirs="$noconfigdirs ${libgcj}"
1646
     ;;
1647
+  zip*)
1648
+    noconfigdirs="$noconfigdirs ${libgcj}"
1649
+    ;;
1650
   *-*-lynxos*)
1651
     noconfigdirs="$noconfigdirs ${libgcj}"
1652
     ;;
1653
@@ -3575,6 +3578,9 @@
1654
     *-*-aix*)
1655
        noconfigdirs="$noconfigdirs target-libgo"
1656
        ;;
1657
+    zip*)
1658
+       noconfigdirs="$noconfigdirs target-libgo"
1659
+       ;;
1660
     esac
1661
 fi
1662
 
1663
@@ -3974,6 +3980,9 @@
1664
   vax-*-*)
1665
     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
1666
     ;;
1667
+  zip*)
1668
+    noconfigdirs="$noconfigdirs gdb gprof"
1669
+    ;;
1670
 esac
1671
 
1672
 # If we aren't building newlib, then don't build libgloss, since libgloss
1673
diff -Naur '--exclude=*.swp' binutils-2.27/configure.ac binutils-2.27-zip/configure.ac
1674
--- binutils-2.27/configure.ac  2016-08-03 04:37:38.000000000 -0400
1675
+++ binutils-2.27-zip/configure.ac      2017-01-08 20:41:54.836485336 -0500
1676
@@ -884,6 +884,9 @@
1677
   ft32-*-*)
1678
     noconfigdirs="$noconfigdirs ${libgcj}"
1679
     ;;
1680
+  zip*)
1681
+    noconfigdirs="$noconfigdirs ${libgcj}"
1682
+    ;;
1683
   *-*-lynxos*)
1684
     noconfigdirs="$noconfigdirs ${libgcj}"
1685
     ;;
1686
@@ -911,6 +914,9 @@
1687
     *-*-aix*)
1688
        noconfigdirs="$noconfigdirs target-libgo"
1689
        ;;
1690
+    zip*)
1691
+       noconfigdirs="$noconfigdirs target-libgo"
1692
+       ;;
1693
     esac
1694
 fi
1695
 
1696
@@ -1310,6 +1316,9 @@
1697
   vax-*-*)
1698
     noconfigdirs="$noconfigdirs target-newlib target-libgloss"
1699
     ;;
1700
+  zip*)
1701
+    noconfigdirs="$noconfigdirs ${libgcj} gdb sim gprof"
1702
+    ;;
1703
 esac
1704
 
1705
 # If we aren't building newlib, then don't build libgloss, since libgloss
1706
diff -Naur '--exclude=*.swp' binutils-2.27/gas/config/tc-zip.c binutils-2.27-zip/gas/config/tc-zip.c
1707
--- binutils-2.27/gas/config/tc-zip.c   1969-12-31 19:00:00.000000000 -0500
1708 206 dgisselq
+++ binutils-2.27-zip/gas/config/tc-zip.c       2017-03-15 23:03:15.801504568 -0400
1709
@@ -0,0 +1,3340 @@
1710 202 dgisselq
+////////////////////////////////////////////////////////////////////////////////
1711
+//
1712
+// Filename:   tc-zip.c
1713
+//
1714
+// Project:    Zip CPU backend for GNU Binutils
1715
+//
1716
+// Purpose:    This is the main file associated with the Zip Assembler.  By
1717
+//             that I mean that it handles all of the ZipCPU specifics.  The
1718
+//     rest of the files you find in this directory, mostly tc-cpuname.c and
1719
+//     such, handle other CPUs.  This one handles the ZipCPU.  The goal in
1720
+//     doing this is so that nothing else changes when changes need to be made
1721
+//     to a CPU, and that changes to the assembler in general shouldn't impact
1722
+//     the CPU specific processing.
1723
+//
1724
+//     I'll let you be the judge as to how well this file meets that goal.
1725
+//
1726
+// Creator:    Dan Gisselquist, Ph.D.
1727
+//             Gisselquist Technology, LLC
1728
+//
1729
+////////////////////////////////////////////////////////////////////////////////
1730
+//
1731
+// Copyright (C) 2016-2017, Gisselquist Technology, LLC
1732
+//
1733
+// This program is free software (firmware): you can redistribute it and/or
1734
+// modify it under the terms of  the GNU General Public License as published
1735
+// by the Free Software Foundation, either version 3 of the License, or (at
1736
+// your option) any later version.
1737
+//
1738
+// This program is distributed in the hope that it will be useful, but WITHOUT
1739
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
1740
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1741
+// for more details.
1742
+//
1743
+// You should have received a copy of the GNU General Public License along
1744
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
1745
+// target there if the PDF file isn't present.)  If not, see
1746
+// <http://www.gnu.org/licenses/> for a copy.
1747
+//
1748
+// License:    GPL, v3, as defined and found on www.gnu.org,
1749
+//             http://www.gnu.org/licenses/gpl.html
1750
+//
1751
+//
1752
+////////////////////////////////////////////////////////////////////////////////
1753
+#include "as.h"
1754
+
1755
+#include <stdlib.h>
1756
+#include <string.h>
1757
+#include <stdint.h>
1758
+#include <ctype.h>
1759
+
1760
+#include "frags.h"
1761
+#include "struc-symbol.h"
1762
+#include "symbols.h"
1763
+#include "config/tc-zip.h"
1764
+#include "elf/zip.h"
1765
+
1766
+// #define     ZIP_DEBUG
1767
+
1768
+const  char    comment_chars[] = ";#";
1769
+const  char    line_comment_chars[] = ";#";
1770
+// Characters which separate lines (newline need to be listed)
1771
+const  char    line_separator_chars[] = "";
1772
+
1773
+// Characters defining floating point numbers, such as 0f<floatingpt#>
1774
+const  char    FLT_CHARS[] = "fFrR";
1775
+
1776
+// Characters that may be used for an exponent in floating point numbers
1777
+const  char    EXP_CHARS[] = "eE";
1778
+
1779
+static int     cis_mergable = 0; // tc_check_label, tc_frob_label
1780
+
1781
+// zip_param_got is a flag that we'll set to know if we need to reference a
1782
+// global offset table.  Since nothing we've done has yet needed that table,
1783
+// we'll keep this undefined for now.
1784
+//
1785
+// static int  zip_param_got = 0;
1786
+static int     zip_param_cis = 1;
1787
+static int     zip_param_small = 0;
1788
+static int     zip_param_use_machine  = 1;
1789
+
1790
+typedef        struct  {
1791
+       int     m_known;
1792
+       int32_t m_value;
1793
+       symbolS *m_addsy, *m_subsy;
1794
+} MACHINEVALUE;
1795
+
1796
+typedef        struct  {
1797
+       MACHINEVALUE    r[ZIP_USER_REGS];
1798
+} MACHINEREGS;
1799
+
1800
+MACHINEREGS    zipm;
1801
+
1802
+static void zip_clear_machine(MACHINEREGS *pzipm);
1803
+
1804
+void   md_begin(void) {
1805
+       cis_mergable = FALSE;
1806
+       //
1807
+       record_alignment(text_section, 2);
1808
+       record_alignment(data_section, 2);
1809
+       //
1810
+       lex_type['['] = lex_type['A'];
1811
+       //
1812
+       zip_clear_machine(&zipm);
1813
+}
1814
+
1815
+void   md_end(void) { }
1816
+
1817
+void   zip_cons_align(int n) {
1818
+       int     lg;
1819
+       for(lg=0; ((1<<lg)<n)&&(lg<2); lg++)
1820
+               ;
1821
+       do_align(lg, NULL, 0, (1<<lg)-1);
1822
+}
1823
+
1824
+void   zip_flush_pending_output(void) {
1825
+       // If the Assembler is going to stuff things into our output stream,
1826
+       // then we need to make certain that any instructions that follow
1827
+       // dont try to merge with anything previous.  i.e., CIS = false.
1828
+       cis_mergable = FALSE;
1829
+}
1830
+
1831
+int    zip_address_bytes(void) { return 4; }
1832
+
1833
+const  pseudo_typeS    md_pseudo_table[] =
1834
+{
1835
+       { "word", cons, 4 },    // ZipCPU word size is 4, not 2
1836
+       { "long", cons, 8 },    // ZipCPU longs are 64-bits, not 32
1837
+       { "quad", cons,16 },    // ZipCPU QUAD-words are 128-bits, not 64
1838
+       { NULL, NULL, 0 }
1839
+};
1840
+
1841
+#define        ZIP_CC_SLEEP    0x010
1842
+#define        ZIP_CC_GIE      0x020
1843
+#define        ZIP_CC_STEP     0x040
1844
+
1845
+#define        SIM_OPCODE      0x77800000      // 0111.x111.1000. .... 0_111.x_111.10....
1846
+#define        NOOP_OPCODE     0x77c00000      // 0111.x111.1100. .... 0_111.x_111.11....
1847
+
1848
+typedef  struct {
1849
+       bfd_reloc_code_real_type        r_type;
1850
+       symbolS                         *r_sym;
1851
+       int                             r_pcrel;
1852
+       long                            r_fr_offset;
1853
+       fixS                            *r_fix;
1854
+       // Could also be char *name and bfd_reloc_code_real_type
1855
+} ZIPRELOC;
1856
+
1857
+// In case the instruction ...
1858
+#define        ZIP_MAX_NAUX    3 // Number of auxilliary instruction codes used
1859
+typedef        struct {
1860
+       int             i_naux;
1861
+       unsigned        i_code, // The actual machine language instruction
1862
+                       i_aux[ZIP_MAX_NAUX];
1863
+       ZIP_OPCODE      i_op;
1864
+       ZIP_CONDITION   i_cnd;
1865
+       ZIP_REG         i_areg; // = ZIP_RNONE for no register
1866
+       ZIP_REG         i_breg;
1867
+       int             i_imm;
1868
+       ZIPRELOC        *i_rp;
1869
+} ZIPIS;
1870
+
1871
+static ZIPIS *
1872
+zip_copy_insn(const ZIPIS *old) {
1873
+       ZIPIS *nw = (ZIPIS *)xmalloc(sizeof(ZIPIS));
1874
+
1875
+       memcpy((char *)nw, (char *)old, sizeof(ZIPIS));
1876
+
1877
+       return nw;
1878
+}
1879
+
1880
+static uint32_t
1881
+zip_brev(uint32_t v) {
1882
+       unsigned r=0, b;
1883
+
1884
+       for(b=0; b<32; b++, v>>=1)
1885
+               r = (r<<1)|(v&1);
1886
+
1887
+       return r;
1888
+}
1889
+
1890
+static const   int MACH_VUNKNOWN = 0, MACH_VKNOWN = 1, MACH_VUPPERKNOWN = 2,
1891
+                       MACH_VSYMKNOWN = 3;
1892
+
1893
+static void
1894
+zip_clear_machine(MACHINEREGS *pzipm) {
1895
+       int     i;
1896
+
1897
+#ifdef ZIP_DEBUG
1898
+       fprintf(stderr, "MACHINE, CLEAR\n");
1899
+#endif
1900
+       for(i=0; i<ZIP_USER_REGS; i++)
1901
+               pzipm->r[i].m_known = MACH_VUNKNOWN;
1902
+       for(i=0; i<ZIP_USER_REGS; i++)
1903
+               pzipm->r[i].m_addsy = NULL;
1904
+       for(i=0; i<ZIP_USER_REGS; i++)
1905
+               pzipm->r[i].m_subsy = NULL;
1906
+}
1907
+
1908
+static void
1909
+zip_advance_machine(MACHINEREGS *pzipm, ZIPIS *insn) {
1910
+       int             bval = insn->i_imm;
1911
+       int             bknown;
1912
+       MACHINEVALUE    *av, *bv;
1913
+
1914
+       if (!zip_param_use_machine) {
1915
+               // zip_clear_machine(pzipm);
1916
+               return;
1917
+       }
1918
+
1919
+       // The next three instructions don't change any machine values
1920
+       if((insn->i_op == ZIPO_SW)||(insn->i_op == ZIPO_SH)
1921
+               ||(insn->i_op==ZIPO_SB)
1922
+               ||(insn->i_op == ZIPO_CMP)||(insn->i_op == ZIPO_TST))
1923
+               return;
1924
+
1925
+       //
1926
+       // What remains to be done is to include symbols into the machine
1927
+       // state.  For now, we state that anything with a symbol becomes
1928
+       // unknown.
1929
+       //
1930
+       if ((insn->i_op == ZIPO_LJSR)||(insn->i_op == ZIPO_JSR)) {
1931
+               zip_clear_machine(pzipm);
1932
+               return;
1933
+       }
1934
+       if ((insn->i_rp)&&(insn->i_areg<ZIP_CC)) {
1935
+               bknown = MACH_VUNKNOWN;
1936
+               if((insn->i_op==ZIPO_LDI)&&(insn->i_cnd == ZIPC_ALWAYS)) {
1937
+                       pzipm->r[insn->i_areg].m_known = MACH_VSYMKNOWN;
1938
+                       pzipm->r[insn->i_areg].m_value = insn->i_imm;
1939
+                       pzipm->r[insn->i_areg].m_addsy = insn->i_rp->r_sym;
1940
+                       pzipm->r[insn->i_areg].m_subsy = NULL;
1941
+                       return;
1942
+               } else if ((insn->i_breg == ZIP_PC)&&(insn->i_op == ZIPO_MOV)
1943
+                               &&(insn->i_cnd == ZIPC_ALWAYS)) {
1944
+                       pzipm->r[insn->i_areg].m_known = MACH_VSYMKNOWN;
1945
+                       pzipm->r[insn->i_areg].m_value = insn->i_imm;
1946
+                       pzipm->r[insn->i_areg].m_addsy = insn->i_rp->r_sym;
1947
+                       pzipm->r[insn->i_areg].m_subsy = NULL;
1948
+                       return;
1949
+               }
1950
+       } else if (insn->i_rp) {
1951
+               bknown = MACH_VUNKNOWN;
1952
+       } else if (ZIP_RNONE == insn->i_breg)
1953
+               // B-Op is an immediate only
1954
+               bknown = MACH_VKNOWN;
1955
+       else if (insn->i_breg >= ZIP_CC)
1956
+               bknown = MACH_VUNKNOWN;
1957
+       else if (insn->i_imm == 0)
1958
+               bknown = (pzipm->r[insn->i_breg].m_known);
1959
+       else // If we have an immediate plus a value, can't know UPPER anymore
1960
+               bknown = (pzipm->r[insn->i_breg].m_known == MACH_VKNOWN)
1961
+                                       ? MACH_VKNOWN : MACH_VUNKNOWN;
1962
+
1963
+       if (insn->i_breg < ZIP_USER_REGS)
1964
+               bval += pzipm->r[insn->i_breg].m_value;
1965
+
1966
+       if (insn->i_areg >= ZIP_USER_REGS) {
1967
+#ifdef ZIP_DEBUG
1968
+               fprintf(stderr, "MACHINE, A-REG[%02x] out of bounds\n", insn->i_areg);
1969
+#endif
1970
+               return; // Nothing to do -- no change to machine
1971
+       } else if (insn->i_areg == ZIP_PC) {
1972
+#ifdef ZIP_DEBUG
1973
+               fprintf(stderr, "MACHINE, CLEAR ON JUMP\n");
1974
+#endif
1975
+               zip_clear_machine(pzipm);
1976
+               return;
1977
+       } else if ((insn->i_areg == ZIP_CC)&&(insn->i_op == ZIPO_AND)) {
1978
+#ifdef ZIP_DEBUG
1979
+               fprintf(stderr, "MACHINE, CLEAR ON ANDing to CC\n");
1980
+#endif
1981
+               zip_clear_machine(pzipm);
1982
+       } else if ((insn->i_areg == ZIP_CC)&&(
1983
+                       (insn->i_op == ZIPO_LDI)
1984
+                       ||(insn->i_op == ZIPO_LW)
1985
+                       ||(insn->i_op == ZIPO_CLR)
1986
+                       ||(insn->i_op == ZIPO_LDILO))) {
1987
+#ifdef ZIP_DEBUG
1988
+               fprintf(stderr, "MACHINE, CLEAR ON setting CC\n");
1989
+#endif
1990
+               zip_clear_machine(pzipm);
1991
+               return;
1992
+       } else if (insn->i_areg >= ZIP_CC) {
1993
+#ifdef ZIP_DEBUG
1994
+               fprintf(stderr, "MACHINE, Not tracking CC or PC changes\n");
1995
+#endif
1996
+               pzipm->r[insn->i_areg].m_known = MACH_VUNKNOWN;
1997
+               return;
1998
+       }
1999
+
2000
+       av = &pzipm->r[insn->i_areg];
2001
+       if (insn->i_breg < ZIP_CC)
2002
+               bv = &pzipm->r[insn->i_breg];
2003
+       else
2004
+               bv = NULL;
2005
+
2006
+       if (ZIPC_ALWAYS != insn->i_cnd) {
2007
+#ifdef ZIP_DEBUG
2008
+               fprintf(stderr, "MACHINE, CONDITIONAL\n");
2009
+#endif
2010
+               if ((ZIPO_LDILO == insn->i_op)
2011
+                               &&((av->m_known == MACH_VKNOWN)
2012
+                                       ||(av->m_known == MACH_VUPPERKNOWN)))
2013
+                       av->m_known = MACH_VUPPERKNOWN;
2014
+               else if ((ZIPO_LDI == insn->i_op)||(ZIPO_LDIn == insn->i_op))
2015
+                       ; // We'll catch this in a moment
2016
+               else
2017
+                       av->m_known = MACH_VUNKNOWN;
2018
+       } switch(insn->i_op) {
2019
+               case    ZIPO_SUB:
2020
+                       av->m_known = (av->m_known==MACH_VKNOWN)
2021
+                                       ? MACH_VKNOWN:MACH_VUNKNOWN;
2022
+                       av->m_value -= bval;
2023
+                       if (bknown != MACH_VKNOWN)
2024
+                               av->m_known = MACH_VUNKNOWN;
2025
+                       break;
2026
+               case    ZIPO_AND:
2027
+                       av->m_value &= bval;
2028
+                       if ((bknown == MACH_VUPPERKNOWN)&&(bval == 0)) {
2029
+                               if (av->m_known == MACH_VKNOWN)
2030
+                                       av->m_known = MACH_VUPPERKNOWN;
2031
+                               else if (av->m_known != MACH_VUPPERKNOWN)
2032
+                                       av->m_known = MACH_VUNKNOWN;
2033
+                       } else if (bknown != MACH_VKNOWN)
2034
+                               av->m_known = MACH_VUNKNOWN;
2035
+                       break;
2036
+               case    ZIPO_ADD:
2037
+                       av->m_value += bval;
2038
+                       if (bknown != MACH_VKNOWN)
2039
+                               av->m_known = MACH_VUNKNOWN;
2040
+                       break;
2041
+               case    ZIPO_OR:
2042
+                       av->m_value |= bval;
2043
+                       if (bknown == MACH_VUPPERKNOWN) {
2044
+                               if (av->m_known == MACH_VKNOWN)
2045
+                                       av->m_known = MACH_VUPPERKNOWN;
2046
+                               else if (av->m_known != MACH_VUPPERKNOWN)
2047
+                                       av->m_known = MACH_VUNKNOWN;
2048
+                       } else if (bknown != MACH_VKNOWN)
2049
+                               av->m_known = MACH_VUNKNOWN;
2050
+                       break;
2051
+               case    ZIPO_XOR:
2052
+                       av->m_value ^= bval;
2053
+                       if (bknown == MACH_VUPPERKNOWN) {
2054
+                               if (av->m_known == MACH_VKNOWN)
2055
+                                       av->m_known = MACH_VUPPERKNOWN;
2056
+                               else if (av->m_known != MACH_VUPPERKNOWN)
2057
+                                       av->m_known = MACH_VUNKNOWN;
2058
+                       } else if (bknown != MACH_VKNOWN)
2059
+                               av->m_known = MACH_VUNKNOWN;
2060
+                       break;
2061
+               case    ZIPO_LDI: case ZIPO_LDIn:
2062
+                       // Although the h/w instruction has no conditions, our
2063
+                       // decoding may have conditions until we finish
2064
+                       // working out what the actual result is.  Hence, we
2065
+                       // need to be aware of any conditions from above.
2066
+#ifdef ZIP_DEBUG
2067
+                       fprintf(stderr, "MACHINE, LDI -> %02x\n", insn->i_areg);
2068
+#endif
2069
+                       av->m_value = bval;
2070
+                       if (insn->i_cnd != ZIPC_ALWAYS) {
2071
+                               // if ((bknown)&&(bvalue == insn->i_imm))
2072
+                                       // pzipm->r[insn->i_areg].m_known = MACH_VKNOWN;
2073
+                       } else {
2074
+                               av->m_known = MACH_VKNOWN;
2075
+                       } break;
2076
+               case    ZIPO_LDILO:
2077
+#ifdef ZIP_DEBUG
2078
+                       fprintf(stderr, "MACHINE, LDILO -> %02x\n", insn->i_areg);
2079
+#endif
2080
+                       av->m_value &= ~0x0ffff;
2081
+                       av->m_value |= bval &0x0ffff;
2082
+                       if ((av->m_known == MACH_VUPPERKNOWN)
2083
+                                       &&(bknown == MACH_VKNOWN)
2084
+                                       &&(ZIPC_ALWAYS == insn->i_cnd))
2085
+                               av->m_known = MACH_VKNOWN;
2086
+                       break;
2087
+               case    ZIPO_BREV:
2088
+                       av->m_value = zip_brev(bval);
2089
+                       if (ZIPC_ALWAYS == insn->i_cnd)
2090
+                               av->m_known = (bknown == MACH_VKNOWN)?MACH_VKNOWN:MACH_VUNKNOWN;
2091
+                       else if ((bknown == MACH_VKNOWN)
2092
+                               &&(  (av->m_known == MACH_VKNOWN)
2093
+                                  ||(av->m_known == MACH_VUPPERKNOWN))
2094
+                               &&((((zip_brev(bval)^av->m_value)&0x0ffff)==0)))
2095
+                               av->m_known = MACH_VUPPERKNOWN;
2096
+                       break;
2097
+               case    ZIPO_MOV:
2098
+#ifdef ZIP_DEBUG
2099
+                       fprintf(stderr, "MACHINE, MOV -> %02x\n", insn->i_areg);
2100
+#endif
2101
+                       av->m_value = bval;
2102
+                       if (ZIPC_ALWAYS == insn->i_cnd) {
2103
+                               av->m_known = bknown;
2104
+                               if (bknown == MACH_VSYMKNOWN) {
2105
+                                       if (!bv) { av->m_known = MACH_VUNKNOWN;}
2106
+                                       else {
2107
+                                       av->m_value = bv->m_value + insn->i_imm;
2108
+                                       av->m_addsy = bv->m_addsy;
2109
+                                       av->m_subsy = bv->m_subsy;
2110
+                                       }
2111
+                               }
2112
+                       } else if (
2113
+                               ((av->m_known == MACH_VKNOWN)
2114
+                                 ||(av->m_known == MACH_VUPPERKNOWN))
2115
+                               &&((bknown == MACH_VKNOWN)
2116
+                                 ||(bknown == MACH_VUPPERKNOWN))
2117
+                               &&(((bval^av->m_value)&0xffff0000)==0))
2118
+                               av->m_known = MACH_VUPPERKNOWN;
2119
+                       else
2120
+                               av->m_known = MACH_VUNKNOWN;
2121
+                       av->m_value = bval;
2122
+                       break;
2123
+               case    ZIPO_CLR:
2124
+                       if (insn->i_cnd == ZIPC_ALWAYS)
2125
+                               av->m_known = MACH_VKNOWN;
2126
+                       else if ((av->m_value & 0xffff0000)==0) {
2127
+                               if (((av->m_known == MACH_VKNOWN)
2128
+                                       ||(av->m_known == MACH_VUPPERKNOWN))
2129
+                                       &&(((av->m_value ^ bval)&0xffff0000)==0))
2130
+                                       av->m_known = MACH_VUPPERKNOWN;
2131
+                               else
2132
+                                       av->m_known = MACH_VUNKNOWN;
2133
+                       } av->m_value = 0;
2134
+                       break;
2135
+               // Store's don't change any regs
2136
+               case    ZIPO_SW: case ZIPO_SH: case ZIPO_SB:
2137
+               case    ZIPO_SIM: case ZIPO_NOOP:
2138
+               case    ZIPO_SDUMP: case ZIPO_NDUMP:
2139
+               case    ZIPO_BREAK: case ZIPO_LOCK:
2140
+               case    ZIPO_CMP:  case ZIPO_TST:
2141
+                       // These don't change any registers
2142
+                       break;
2143
+               // Result of loading a byte or halfword always clears the upper
2144
+               // half word
2145
+               case    ZIPO_LB: case   ZIPO_LH:
2146
+                       if (insn->i_cnd == ZIPC_ALWAYS) {
2147
+                               av->m_known = MACH_VUPPERKNOWN;
2148
+                               av->m_value = 0;
2149
+                       } else
2150
+                               av->m_known = MACH_VUNKNOWN;
2151
+                       break;
2152
+               case    ZIPO_LW:
2153
+               default:
2154
+#ifdef ZIP_DEBUG
2155
+                       fprintf(stderr, "MACHINE, DEFAULT, %02x -> unknown\n", insn->i_areg);
2156
+#endif
2157
+                       av->m_known = MACH_VUNKNOWN;
2158
+                       break;
2159
+       }
2160
+
2161
+       pzipm->r[ZIP_CC].m_known = MACH_VUNKNOWN;
2162
+       pzipm->r[ZIP_PC].m_known = MACH_VUNKNOWN;
2163
+}
2164
+
2165
+#ifdef ZIP_DEBUG
2166
+static void
2167
+zip_debug_machine(MACHINEREGS *pzipm) {
2168
+       int     i;
2169
+       for(i=0; i<ZIP_USER_REGS; i++) {
2170
+               if (pzipm->r[i].m_known == MACH_VKNOWN)
2171
+                       fprintf(stderr, "MACH-KNOW[Y][%2x] = %08x\n",
2172
+                               i, pzipm->r[i].m_value);
2173
+               else if (pzipm->r[i].m_known == MACH_VUPPERKNOWN)
2174
+                       fprintf(stderr, "MACH-KNOW[U][%2x] = %04x\n",
2175
+                               i, (pzipm->r[i].m_value>>16)&0x0ffff);
2176
+       }
2177
+}
2178
+#endif
2179
+
2180
+
2181
+/*
2182
+ * Option processing
2183
+ *
2184
+ * While not yet implemented, we do have a need for multiple options.  These
2185
+ * include:
2186
+ *
2187
+ *     (not yet supported)
2188
+ *     -got    Use a global offset table to place unknown jump locations into.
2189
+ *
2190
+ *     (not yet supported)
2191
+ *     -relax  Implement only relaxed instructions.  This implies that all
2192
+ *             branches fit within 18-bits of the current PC, or equivalently
2193
+ *             that all of the code fits within 1MB.
2194
+ *
2195
+ *     (not yet supported)
2196
+ *     -no-relax       Don't relax any instructions.  That means that all
2197
+ *             branches will be implemented as LOD (PC),PC ; .int #Address
2198
+ *             and all conditional branches as LOD 1(PC),PC; BRA 1; .int #addr.
2199
+ *             This also implies LDI's of unknown values will always be
2200
+ *             converted to LDILO/LDIHI pairs and never converted back to
2201
+ *             LDI's--even when the final value is known.
2202
+ *
2203
+ *     -cis    Attempt to compress instructions into the CIS instruction
2204
+ *             set.
2205
+ *
2206
+ *     (Something for stating the starting address of the routine in memory...)
2207
+ *
2208
+ *     Other (not yet supported) long options
2209
+ *
2210
+ *     -nopipe Attempts to use a lock instruction will result in an error.
2211
+ *     -nomul  Attempts to use multiply instructions will result in an error.
2212
+ *     -nodiv  Attempts to use divide instructions will result in an error.
2213
+ *     -nofpu  Attempts to use floating point unit insn will cause an error.
2214
+ *
2215
+ *
2216
+ */
2217
+#define        OPTION_CIS      (OPTION_MD_BASE+1)
2218
+#define        OPTION_NOCIS    (OPTION_MD_BASE+2)
2219
+#define        OPTION_ZIPM     (OPTION_MD_BASE+3)
2220
+#define        OPTION_NOZIPM   (OPTION_MD_BASE+4)
2221
+#define        OPTION_GOT      (OPTION_MD_BASE+5)
2222
+#define        OPTION_SMALL    (OPTION_MD_BASE+6)      // No LW(PC),PC insns
2223
+
2224
+const char     *md_shortopts = "";
2225
+struct option  md_longopts[] =
2226
+{
2227
+       { "cis",   no_argument, NULL, OPTION_CIS },
2228
+       { "nocis", no_argument, NULL, OPTION_NOCIS },
2229
+       { "zipm",   no_argument, NULL, OPTION_ZIPM },
2230
+       { "nozipm", no_argument, NULL, OPTION_NOZIPM },
2231
+       { "small",  no_argument, NULL, OPTION_SMALL },
2232
+       // { "got",  no_argument, NULL, OPTION_GOT },
2233
+       { NULL, no_argument, NULL, 0}
2234
+};
2235
+size_t md_longopts_size = sizeof(md_longopts);
2236
+
2237
+/* We have no target specific options yet, so these next two fucntions are
2238
+ * are empty.
2239
+ */
2240
+int
2241
+md_parse_option(int c, const char *arg ATTRIBUTE_UNUSED)
2242
+{
2243
+       // printf("Option %d, %s\n", c, (arg)?arg : "(Null)");
2244
+       if (c==0)
2245
+               return 1;
2246
+       switch(c) {
2247
+               case 0: return 1;
2248
+               case OPTION_CIS:   zip_param_cis = 1; return 1; break;
2249
+               case OPTION_NOCIS: zip_param_cis = 0; return 1; break;
2250
+               case OPTION_ZIPM:   zip_param_use_machine = 1; return 1; break;
2251
+               case OPTION_NOZIPM: zip_param_use_machine = 0; return 1; break;
2252
+               // case OPTION_GOT : zip_param_got  = 1; return 1; break;
2253
+               default: break;
2254
+       }
2255
+       return 0; // We didn't handle this option
2256
+}
2257
+
2258
+void
2259
+md_show_usage(FILE *stream ATTRIBUTE_UNUSED)
2260
+{
2261
+       fprintf(stream, _("Zip CPU options:\n"));
2262
+       fprintf(stream, _("\n"
2263
+"-cis\t\tAttempt to compress instructions into two instructions per word.\n"));
2264
+       //fprintf(stream, _(
2265
+// "-got\t\tGenerate position independent code by referencing all symbols\n"
2266
+// "\t\tthrough a Global Offset Table.\n"));
2267
+}
2268
+
2269
+
2270
+symbolS *
2271
+md_undefined_symbol(char *name ATTRIBUTE_UNUSED)
2272
+{
2273
+//#warning "This is where other architectures check for any GOT references"
2274
+       return NULL;
2275
+}
2276
+
2277
+void
2278
+md_operand(expressionS *op ATTRIBUTE_UNUSED)
2279
+{
2280
+       /* Empty for now -- what is this for? */
2281
+}
2282
+
2283
+#ifdef ZIP_DEBUG
2284
+static void
2285
+zip_dump_sym(symbolS *sym)
2286
+{
2287
+       if (!sym) {
2288
+               fprintf(stderr, "SYM(NULL)");
2289
+       } else {
2290
+               fprintf(stderr, "Dumping symbol fields\n");
2291
+               fprintf(stderr, "SYM(%s) %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s - 0x%08x\n",
2292
+                       S_GET_NAME(sym),
2293
+                       (S_IS_LOCAL(sym))?"Local ":"",
2294
+                       (S_IS_DEFINED(sym))?"Defined ":"",
2295
+                       (S_IS_EXTERNAL(sym))?"extern ":"",
2296
+                       (S_IS_FUNCTION(sym))?"(func) ":"",
2297
+                       (S_IS_WEAK(sym))?"Weak ":"",
2298
+                       (S_IS_WEAKREFD(sym))?"(Weak Ref-D) ":"",
2299
+                       (S_IS_WEAKREFR(sym))?"(Weak Refr) ":"",
2300
+                       (S_IS_DEBUG(sym))?"DEBUG ":"",
2301
+                       (S_IS_VOLATILE(sym))?"Volatile ":"",
2302
+                       (S_IS_FORWARD_REF(sym))?"Fwd Ref ":"",
2303
+                       (S_IS_COMMON(sym))?"Common ":"",
2304
+                       (S_GET_SEGMENT(sym)==absolute_section)?"AbsoluteS ":"",
2305
+                       (S_GET_SEGMENT(sym)==expr_section)?"ExpressionS ":"",
2306
+                       (S_GET_SEGMENT(sym)==reg_section)?"RegisterS ":"",
2307
+                       (S_GET_SEGMENT(sym)==undefined_section)?"UndefinedS ":"",
2308
+                       (symbol_resolved_p(sym))?"Resolved ":"",
2309
+                       (unsigned)S_GET_VALUE(sym));
2310
+       }
2311
+}
2312
+
2313
+static void
2314
+zip_dump_insn(ZIPIS *insn) {
2315
+       fprintf(stderr, "INSN:DUMP ");
2316
+       switch(insn->i_op) {
2317
+               case ZIPO_SUB:   fprintf(stderr, "%7s", "SUB"); break;
2318
+               case ZIPO_AND:   fprintf(stderr, "%7s", "AND"); break;
2319
+               case ZIPO_ADD:   fprintf(stderr, "%7s", "ADD"); break;
2320
+               case ZIPO_OR:    fprintf(stderr, "%7s", "OR"); break;
2321
+               case ZIPO_XOR:   fprintf(stderr, "%7s", "XOR"); break;
2322
+               case ZIPO_LSR:   fprintf(stderr, "%7s", "LSR"); break;
2323
+               case ZIPO_LSL:   fprintf(stderr, "%7s", "LSL"); break;
2324
+               case ZIPO_ASR:   fprintf(stderr, "%7s", "ASR"); break;
2325
+               case ZIPO_LDI:   fprintf(stderr, "%7s", "LDI"); break;
2326
+               case ZIPO_MPYUHI:fprintf(stderr, "%7s", "MPYUHI");break;
2327
+               case ZIPO_MPYSHI:fprintf(stderr, "%7s", "MPYSHI");break;
2328
+               case ZIPO_LDILO: fprintf(stderr, "%7s", "LDILO"); break;
2329
+               case ZIPO_BREV:  fprintf(stderr, "%7s", "BREV");  break;
2330
+               case ZIPO_MOV:   fprintf(stderr, "%7s", "MOV");   break;
2331
+               case ZIPO_CMP:   fprintf(stderr, "%7s", "CMP");   break;
2332
+               case ZIPO_TST:   fprintf(stderr, "%7s", "TST");   break;
2333
+               case ZIPO_LW:    fprintf(stderr, "%7s", "LW");    break;
2334
+               case ZIPO_SW:    fprintf(stderr, "%7s", "SW");    break;
2335
+               case ZIPO_LH:    fprintf(stderr, "%7s", "LH");    break;
2336
+               case ZIPO_SH:    fprintf(stderr, "%7s", "SH");    break;
2337
+               case ZIPO_LB:    fprintf(stderr, "%7s", "LB");    break;
2338
+               case ZIPO_SB:    fprintf(stderr, "%7s", "SB");    break;
2339
+               case ZIPO_DIVU:  fprintf(stderr, "%7s", "DIVU");  break;
2340
+               case ZIPO_DIVS:  fprintf(stderr, "%7s", "DIVS");  break;
2341
+               case ZIPO_FPADD: fprintf(stderr, "%7s", "FPADD"); break;
2342
+               case ZIPO_FPSUB: fprintf(stderr, "%7s", "FPSUB"); break;
2343
+               //
2344
+               case ZIPO_NOOP:  fprintf(stderr, "%7s", "NOOP");  break;
2345
+               case ZIPO_BREAK: fprintf(stderr, "%7s", "BREAK"); break;
2346
+               case ZIPO_LOCK:  fprintf(stderr, "%7s", "LOCK");  break;
2347
+               case ZIPO_TRAP:  fprintf(stderr, "%7s", "TRAP");  break;
2348
+               case ZIPO_CLR:   fprintf(stderr, "%7s", "CLR");   break;
2349
+               case ZIPO_HALT:  fprintf(stderr, "%7s", "HALT");  break;
2350
+               case ZIPO_WAIT:  fprintf(stderr, "%7s", "WAIT");  break;
2351
+               case ZIPO_STEP:  fprintf(stderr, "%7s", "STEP");  break;
2352
+               case ZIPO_RTU:   fprintf(stderr, "%7s", "RTU");   break;
2353
+               case ZIPO_BRA:   fprintf(stderr, "%7s", "BRA");   break;
2354
+               case ZIPO_BUSY:  fprintf(stderr, "%7s", "BUSY");  break;
2355
+               case ZIPO_JMP:   fprintf(stderr, "%7s", "JMP");   break;
2356
+               case ZIPO_NOT:   fprintf(stderr, "%7s", "NOT");   break;
2357
+               case ZIPO_NEG:   fprintf(stderr, "%7s", "NEG");   break;
2358
+               //
2359
+               case ZIPO_SIM:   fprintf(stderr, "%7s", "SIM");   break;
2360
+               case ZIPO_SDUMP: fprintf(stderr, "%7s", "SDUMP"); break;
2361
+               case ZIPO_SEXIT: fprintf(stderr, "%7s", "SEXIT"); break;
2362
+               case ZIPO_SOUT:  fprintf(stderr, "%7s", "SOUT");  break;
2363
+               case ZIPO_NDUMP: fprintf(stderr, "%7s", "NDUMP"); break;
2364
+               case ZIPO_NEXIT: fprintf(stderr, "%7s", "NEXIT"); break;
2365
+               case ZIPO_NOUT:  fprintf(stderr, "%7s", "OUT");   break;
2366
+               //
2367
+               case ZIPO_LJMP: fprintf(stderr, "%7s", "LJMP"); break;
2368
+               case ZIPO_LJSR: fprintf(stderr, "%7s", "LJSR");   break;
2369
+               //
2370
+               case ZIPO_SEXTH:fprintf(stderr, "%7s", "SEXTH");   break;
2371
+               case ZIPO_SEXTB:fprintf(stderr, "%7s", "SEXTB");   break;
2372
+               default:
2373
+                       fprintf(stderr, "%d", insn->i_op); break;
2374
+       }
2375
+       switch(insn->i_cnd) {
2376
+               case ZIPC_Z: fprintf(stderr, "%-3s", ".Z"); break;
2377
+               case ZIPC_LT: fprintf(stderr, "%-3s", ".LT"); break;
2378
+               case ZIPC_C: fprintf(stderr, "%-3s", ".C"); break;
2379
+               case ZIPC_V: fprintf(stderr, "%-3s", ".V"); break;
2380
+               case ZIPC_NZ: fprintf(stderr, "%-3s", ".NE"); break;
2381
+               case ZIPC_GE: fprintf(stderr, "%-3s", ".GE"); break;
2382
+               case ZIPC_NC: fprintf(stderr, "%-3s", ".NC"); break;
2383
+               case ZIPC_ALWAYS:
2384
+               default:
2385
+                       break;
2386
+       } fprintf(stderr, " %d", (int)insn->i_cnd);
2387
+
2388
+       fprintf(stderr, "\n\tAREG = %d\n\tB = ", insn->i_areg);
2389
+       if (insn->i_rp) {
2390
+               if (insn->i_imm != 0)
2391
+                       fprintf(stderr, "$%d + ", insn->i_imm);
2392
+               fprintf(stderr, "%s ", (insn->i_rp->r_sym) ?
2393
+                       S_GET_NAME(insn->i_rp->r_sym) : "(null)");
2394
+       } else
2395
+               fprintf(stderr, "%d[%08x] (no sym)", insn->i_imm, insn->i_imm);
2396
+       if (insn->i_breg != ZIP_RNONE)
2397
+               fprintf(stderr, "+ R%d", insn->i_breg);
2398
+       fprintf(stderr, "\n");
2399
+       if (insn->i_rp)
2400
+               fprintf(stderr, "\t@%ld (offset w/in instruction frag)\n", insn->i_rp->r_fr_offset);
2401
+       fprintf(stderr, "\tINSN:CODE %08x", insn->i_code);
2402
+       {
2403
+               int     i;
2404
+               for(i=0; (i<insn->i_naux)&&(i<ZIP_MAX_NAUX); i++)
2405
+                       fprintf(stderr, ":%08x", insn->i_aux[i]);
2406
+       }
2407
+       fprintf(stderr, "\n\tDUMPED\n");
2408
+}
2409
+#endif
2410
+
2411
+static ZIP_CONDITION
2412
+zip_negate_condition(ZIP_CONDITION c) {
2413
+       switch(c) {
2414
+               case ZIPC_Z:    return ZIPC_NZ; break;
2415
+               case ZIPC_LT:   return ZIPC_GE; break;
2416
+               case ZIPC_C:    return ZIPC_NC; break;
2417
+               case ZIPC_NZ:   return ZIPC_Z; break;
2418
+               case ZIPC_GE:   return ZIPC_LT; break;
2419
+               case ZIPC_NC:   return ZIPC_C; break;
2420
+               case ZIPC_ALWAYS:       return ZIPC_ALWAYS; break;
2421
+               default:
2422
+                       break;
2423
+       } gas_assert((0)&&("Cannot negate condition\n"));
2424
+       return ZIPC_ALWAYS;
2425
+}
2426
+
2427
+static const char *zip_skip_white_spaces(const char *str) {
2428
+       if (!str)
2429
+               return NULL;
2430
+       while((*str)&&(isspace(*str)))
2431
+               str++;
2432
+       return str;
2433
+}
2434
+
2435
+static const char *
2436
+zip_parse_condition(const char *str, ZIP_CONDITION *condn) {
2437
+       if ((strcasecmp(str, "Z")==0)
2438
+                       ||(strcasecmp(str, "EQ")==0)) {
2439
+               *condn = ZIPC_Z;
2440
+       } else if ((strcasecmp(str, "LT")==0)
2441
+                       ||(strcasecmp(str, "N")==0)) {
2442
+               *condn = ZIPC_LT;
2443
+       } else if ((strcasecmp(str, "C")==0)
2444
+                       ||(strcasecmp(str, "LTU")==0)) {
2445
+               *condn = ZIPC_C;
2446
+       } else if (strcasecmp(str, "V")==0) {
2447
+               *condn = ZIPC_V;
2448
+       } else if((strcasecmp(str, "NZ")==0)
2449
+                       ||(strcasecmp(str, "NE")==0)) {
2450
+               *condn = ZIPC_NZ;
2451
+       } else if ((strcasecmp(str, "GE")==0)
2452
+                       ||(strcasecmp(str, "GTE")==0)) {
2453
+               *condn = ZIPC_GE;
2454
+       } else if ((strcasecmp(str, "NC")==0)
2455
+                       ||(strcasecmp(str, "GEU")==0)) {
2456
+               *condn = ZIPC_NC;
2457
+       } else {
2458
+               return "Unrecognized condition";
2459
+       }
2460
+
2461
+       return NULL;
2462
+}
2463
+
2464
+static const char *zip_parse_reg(const char *str, ZIP_REG *regid) {
2465
+       const char *ustr = str;
2466
+       int     userreg = 0;
2467
+
2468 206 dgisselq
+       if ((!str)||(str[0]=='\0'))
2469
+               return "No register given";
2470 202 dgisselq
+       ustr = zip_skip_white_spaces(str);
2471
+
2472
+       if (toupper(ustr[0]) == 'U') {
2473
+               ustr = str+1;
2474
+               userreg = 0x10;
2475
+       } else if ((toupper(ustr[0]) == 'S')&&(strcasecmp(ustr, "SP")!=0)) {
2476
+               ustr = str+1;
2477
+       }
2478
+
2479
+       /*
2480
+       if (strcasecmp(ustr, "GBL")==0) {
2481
+               *regid = userreg + 11;
2482
+               ustr += 3;
2483
+       } else
2484
+       */
2485
+       if (strcasecmp(ustr, "LR")==0) {
2486
+               *regid = userreg + 0;
2487
+               ustr += 2;
2488
+       } else if (strcasecmp(ustr, "FP")==0) {
2489
+               *regid = userreg + 12;
2490
+               ustr += 2;
2491
+       } else if (strcasecmp(ustr, "SP")==0) {
2492
+               *regid = userreg + 13;
2493
+               ustr += 2;
2494
+       } else if (strcasecmp(ustr, "CC")==0) {
2495
+               *regid = userreg + 14;
2496
+               ustr += 2;
2497
+       } else if (strcasecmp(ustr, "PC")==0) {
2498
+               *regid = userreg + 15;
2499
+               ustr += 2;
2500
+       } else if (('r' == tolower(ustr[0]))
2501
+                       &&(isdigit(ustr[1]))
2502
+                       &&((!isdigit(ustr[2]))
2503
+                               ||(!isdigit(ustr[3])))) {
2504
+               *regid = atoi(ustr+1);
2505
+               if ((*regid > 15)||(*regid < 0))
2506
+                       return "Register does not exist";
2507
+               *regid += userreg;
2508
+
2509
+               if (!isdigit(ustr[2]))
2510
+                       ustr+=2;
2511
+               else
2512
+                       ustr+=3;
2513
+       } else {
2514
+               *regid = ZIP_RNONE;
2515
+               return "Unknown register";
2516
+       }
2517
+
2518
+       // Registers names are terminated by something other than letters
2519
+       // and numbers.  Things like ')', ',', or '\0' should terminate a
2520
+       // register.  Here, we only double check that the register is not
2521
+       // terminated by another letter or a number.
2522
+       if ((*ustr)&&((isalpha(*ustr))||(isdigit(*ustr))))
2523
+               return "Unrecognized register";
2524
+
2525
+       return NULL;
2526
+}
2527
+
2528
+// Parse a 'B' operand
2529
+static const char *
2530
+zip_parse_bop(const char *bop, ZIPIS *insn) {
2531
+       // There are a couple forms for what we can expect in a B operand:
2532
+       //      The first three require no relocations ...
2533
+       //              1. A simple number
2534
+       //              2. Number + Register
2535
+       //              3. Number(Register)
2536
+       //              4. Register by itself
2537
+       //              Good form is to replace this number with the possibility
2538
+       //              of a constant expression ...  The number may be any of
2539
+       //              [+-](0[xX][0-9a-fA-F]+|(0[0-7]+)|(0-9)+)
2540
+       //      The next four may require a relocation
2541
+       //              4. Label + Register
2542
+       //              5. Label(Register)
2543
+       //              6. Label (Register is implied: PC, if moving or jumping
2544
+       //                      to the PC, or GBL if loading a value or if
2545
+       //                      the offset ends up being unknown)
2546
+       //              Good form allows an expression instead of a label,
2547
+       //              that can be evaluated at ... sometime.
2548
+       //              7. Number(Label)
2549
+       //
2550
+       // We will support:
2551
+       //      (Number|Label)?( "("Register")" | "+"Register )
2552
+       //
2553
+       char    lbl[512], *lblp = lbl;
2554
+       const char      *ptr;
2555
+       insn->i_imm = 0;
2556
+       *lblp = '\0';
2557
+
2558
+       if (strlen(bop)>sizeof(lbl)-1)
2559
+               as_fatal( _("Label length too long"));
2560
+       // printf("RAW-OP-B: %s %s\n", bop, (insn->i_rp)?"(i_rp != NULL)":"");
2561
+
2562
+       // Do we start with a number?
2563
+       {
2564
+               int     sgn = 0;
2565
+
2566
+               ptr = zip_skip_white_spaces(bop);
2567
+               if ('$' == *ptr)
2568
+                       ptr = zip_skip_white_spaces(ptr+1);
2569
+
2570
+               if ('+' == *ptr)
2571
+                       ptr++;
2572
+               else if ('-' == *ptr) {
2573
+                       sgn = 1;
2574
+                       ptr++;
2575
+               }
2576
+
2577
+               if ('$' == *ptr)
2578
+                       ptr = zip_skip_white_spaces(ptr+1);
2579
+               ptr = zip_skip_white_spaces(ptr);
2580
+               if ('$' == *ptr)
2581
+                       ptr = zip_skip_white_spaces(ptr+1);
2582
+
2583
+               if ((*ptr)&&(isdigit(*ptr))) {
2584
+                       char *end = (char *)ptr;
2585
+                       unsigned long v = strtoul(ptr, &end, 0);
2586
+                       // We start with a number
2587
+                       if (sgn)
2588
+                               insn->i_imm = (int)(-v);
2589
+                       else
2590
+                               insn->i_imm = (int)(v);
2591
+                       ptr = (const char *)end;
2592
+
2593
+                       // Permit a string of Num [[+-] Num]*
2594
+                       // This is necessary for the DI instructions within the
2595
+                       // compiler.
2596
+                       while( ((*ptr == '+')||(*ptr == '-'))
2597
+                               &&(isdigit(ptr[1])) ) {
2598
+                               sgn = (*ptr == '-');
2599
+                               v = strtoul(&ptr[1], &end, 0);
2600
+                               if (sgn) v = -v;
2601
+                               insn->i_imm += (int)v;
2602
+                               ptr = (const char *)end;
2603
+                       }
2604
+               } else if ((*ptr)&&(
2605
+                               (isalpha(*ptr))
2606
+                               ||('*'==*ptr)
2607
+                               ||('.'==*ptr)
2608
+                               ||('_'==*ptr))) {
2609
+                       // We start with an identifier
2610
+                       // printf("OP-B ( \'%s\' ) starts with an identifier (%c)\n",
2611
+                               // bop, *ptr);
2612
+
2613
+                       // Skip any compiler inserted prefix (if present)
2614
+                       if ('*' == *ptr)
2615
+                               ptr++;
2616
+                       while((*ptr)&&(
2617
+                                       (isalpha(*ptr))
2618
+                                       ||(isdigit(*ptr))
2619
+                                       ||('_' == *ptr)
2620
+                                       ||('$' == *ptr)
2621
+                                       ||('.' == *ptr)))
2622
+                               *lblp++ = *ptr++;
2623
+                       *lblp = '\0';
2624
+                       // printf("LBL was %s\n", lbl);
2625
+
2626
+                       // This could still be a register ... can't tell yet
2627
+                       if (sgn)
2628
+                               return "ERR: Not expecting a signed label!";
2629
+
2630
+                       ptr = zip_skip_white_spaces(ptr);
2631
+               }
2632
+       }
2633
+
2634
+       ptr = zip_skip_white_spaces(ptr);
2635
+
2636
+       const   char *err = NULL;
2637
+
2638
+       if ((*ptr == '+')&&(ptr[1] == '('))
2639
+               ptr++;
2640
+       if ((*ptr)&&(*ptr == '(')) {
2641
+               // Form #3: Number(register)
2642
+               char *end = strchr(ptr+1, ')');
2643
+               if (NULL == end)
2644
+                       return "Un-matched \'(\', cannot find \')\'";
2645
+               *end = '\0';
2646
+               // printf("Looking for a register in %s\n", ptr+1);
2647
+               err = zip_parse_reg(ptr+1, &insn->i_breg);
2648
+               if (err) {
2649
+                       // Must've been a symbol
2650
+                       if (lbl[0] != '\0') // Already have a symbol in this
2651
+                               return err;     // expression!
2652
+                       ptr++;
2653
+                       while((*ptr)&&(
2654
+                                       (isalpha(*ptr))
2655
+                                       ||(isdigit(*ptr))
2656
+                                       ||('_' == *ptr)
2657
+                                       ||('$' == *ptr)
2658
+                                       ||('.' == *ptr)))
2659
+                               *lblp++ = *ptr++;
2660
+                       *lblp = '\0';
2661
+                       insn->i_breg = ZIP_RNONE;
2662
+                       ptr = zip_skip_white_spaces(ptr);
2663
+                       if (*ptr != '\0')
2664
+                               return "ERR: Expression within parenthesis not supported";
2665
+                       err = NULL;
2666
+               }
2667
+               // printf("Found a register, %s -> %d\n", ptr+1, insn->i_breg);
2668
+       } else if ((*ptr)&&((*ptr == '+')||(*ptr == '-'))) {
2669
+               if ((*lbl)&&(zip_parse_reg(lbl, &insn->i_breg) == NULL)) {
2670
+                       // Register+Number
2671
+                       // Skip to the end to process what follows
2672
+                       *lbl = '\0'; // Label wasn't a symbol, so let's clear it
2673
+               } else {
2674
+                       // Number/label+Register
2675
+                       while((('+' == *ptr)||('-' == *ptr))
2676
+                                       &&(ptr[1])
2677
+                                       &&((isdigit(ptr[1]))
2678
+                                       ||((ptr[0] == '+')
2679
+                                               &&(ptr[1] == '-')
2680
+                                               &&(ptr[2])
2681
+                                               &&(isdigit(ptr[2]))))) {
2682
+                               char *end;
2683
+
2684
+                               if ((*ptr == '+')&&(isdigit(ptr[1])))
2685
+                                       insn->i_imm += strtoul(ptr, &end, 0);
2686
+                               else if ((*ptr == '+')&&(ptr[1] == '-')
2687
+                                               &&(isdigit(ptr[2])))
2688
+                                       insn->i_imm -= strtoul(ptr+2, &end, 0);
2689
+                               else if ((*ptr == '-')&&(isdigit(ptr[1])))
2690
+                                       insn->i_imm -= strtoul(ptr+1, &end, 0);
2691
+                               else {
2692
+                                       fprintf(stderr, "GAS: Cannot comprehend %s\n", ptr);
2693
+                                       gas_assert((0)&&("Should never get here"));
2694
+                               }
2695
+                               ptr = (const char *)end;
2696
+                       }
2697
+                       if (('+' == *ptr)&&((err = zip_parse_reg(ptr+1, &insn->i_breg))==NULL)) {
2698
+                               // Let's skip to the end of the register
2699
+                               ptr++;
2700
+                               while(isalpha(*ptr))
2701
+                                       ptr++;
2702
+                               while(isdigit(*ptr))
2703
+                                       ptr++;
2704
+                       } else if (('(' == *ptr)&&((err = zip_parse_reg(ptr+1, &insn->i_breg))==NULL)) {
2705
+                               ptr++;
2706
+                               while((*ptr)&&(')' != *ptr))
2707
+                                       ptr++;
2708
+                               ptr++;
2709
+                       } else {
2710
+                               // OOps!! Must've been a label + number
2711
+                               err = NULL;
2712
+                       }
2713
+               }
2714
+       } else if ((*lbl)&&(NULL == zip_parse_reg(lbl, &insn->i_breg))) {
2715
+               // Form: Register (only)
2716
+               insn->i_imm = 0;
2717
+               // printf("OP-B ( \'%s\' ) Had a register, %s -> %d\n", bop,
2718
+                       // lbl, insn->i_breg);
2719
+               *lbl = '\0';
2720
+       } else if (*lbl) {
2721
+               // Form: Label or Number (only)
2722
+               insn->i_breg = ZIP_RNONE;
2723
+       }
2724
+
2725
+       // Look for a +number at the end
2726
+       if ((*ptr)&&((*ptr == '+')||(*ptr == '-'))) {
2727
+               // printf("Looking at a plus: %s\n", ptr);
2728
+               int     sgn = (*ptr == '-')?1:0;
2729
+
2730
+               if (sgn) {
2731
+                       // printf("... I meant a minus\n");
2732
+                       ptr++;
2733
+               }
2734
+
2735
+               ptr = zip_skip_white_spaces(ptr);
2736
+               if ('$' == *ptr)
2737
+                       ptr = zip_skip_white_spaces(ptr+1);
2738
+
2739
+               if ('+' == *ptr)
2740
+                       ptr++;
2741
+               if ('-' == *ptr) {
2742
+                       sgn = !sgn;
2743
+                       ptr++;
2744
+               }
2745
+
2746
+               ptr = zip_skip_white_spaces(ptr);
2747
+               if ('$' == *ptr)
2748
+                       ptr = zip_skip_white_spaces(ptr+1);
2749
+               if ('-' == *ptr) {
2750
+                       sgn = !sgn;
2751
+                       ptr++;
2752
+               }
2753
+
2754
+               if ((*ptr)&&(isdigit(*ptr))) {
2755
+                       char *end = (char *)ptr;
2756
+
2757
+                       // printf("Parsing #: %s\n", ptr);
2758
+                       // While the following might make the most sense,
2759
+                       //    if (sgn) *--ptr = '-';
2760
+                       // the string is read-only, so we can't change it.
2761
+                       // Instead we do ...
2762
+                       unsigned long v = (sgn)?
2763
+                               -strtoul(ptr, &end, 0) : strtoul(ptr, &end, 0);
2764
+                       insn->i_imm += v;
2765
+                       ptr = (const char *)end;
2766
+               }
2767
+       }
2768
+
2769
+       if (*lbl) {
2770
+               // printf("i_rp = %s\n", (insn->i_rp)?"(Null)":"not NULL");
2771
+               symbolS *sym = symbol_find_or_make(lbl);
2772
+               sym->sy_flags.sy_used = TRUE;
2773
+               // segT seg = S_GET_SEGMENT(sym);
2774
+#ifdef ZIP_DEBUG
2775
+               zip_dump_sym(sym);
2776
+#endif
2777
+               if (insn->i_breg == ZIP_PC) {
2778
+                       // New pc-relative relocation,
2779
+                       // ???
2780
+                       // symbolP = symbol_create(FAKE_LABEL_NAME,
2781
+                               // absolute_section, 0 &zero_address_frag);
2782
+                       // symbol_set_value_expression(symbolP, expressionP);
2783
+                       // resolve_symbol_value(symbolP);
2784
+                       insn->i_rp =(ZIPRELOC *)xmalloc(sizeof(ZIPRELOC));
2785
+                       insn->i_rp->r_sym = sym;
2786
+                       insn->i_rp->r_pcrel = TRUE;
2787
+                       insn->i_rp->r_fr_offset = 0;
2788
+                       insn->i_rp->r_fix = NULL;
2789
+                       insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_PCREL;
2790
+                       // symbol_make(name??)
2791
+                       // symbol_find_or_make(name)
2792
+                       // symbol_relc_make_sym
2793
+                       // symbol_relc_make_value
2794
+                       // symbol_find(name)
2795
+                       // symbol_find_noref(name, noref)
2796
+                       // symbol_find_exact(name)
2797
+                       // symbol_find_exact_noref(name, noref)
2798
+                       // symbol_find_or_make(name)
2799
+                       // symbol_make(name)
2800
+                       // symbol_new(name, seg, value, frag)
2801
+                       //      preferred call over symbol create
2802
+                       //      calls symbol_create internal
2803
+                       // symbol_create(name, segment, value, frag)
2804
+                       //
2805
+                       // local_symbol_make(name, section, value, frag)
2806
+                       // symbol_clone(sym, int)
2807
+                       // symbol_temp_new(seg, value, frag)
2808
+                       // symbol_temp_new_now(void)
2809
+                       // symbol_temp_make(void)
2810
+                       // colon(void)
2811
+                       //      Called when symbol: starts a line
2812
+                       //      Calls symbol_new(name, now_seg, frag_now_fix(),
2813
+                       //              frag_now);
2814
+                       //              symbol_table_insert(symbolP)
2815
+                       //
2816
+                       // expr_build_dot returns a symbol pointing to the
2817
+                       //      current location ...
2818
+                       //
2819
+                       // Useful:
2820
+                       //      frag_now is current frag
2821
+                       //      S_SET_VALUE(symbolP, frag_now_fix()) ???
2822
+                       //      now_seg must be the current segment
2823
+                       //      S_SET_SETGMENT(symbolP, now_seg);
2824
+               /*
2825
+               } else if((zip_param_got)&&(insn->i_breg == ZIP_GBL)) {
2826
+                       // New GOT-relative relocation
2827
+                       insn->i_rp =(ZIPRELOC *)xmalloc(sizeof(ZIPRELOC));
2828
+                       insn->i_rp->r_sym = sym;
2829
+                       insn->i_rp->r_pcrel = FALSE;
2830
+                       insn->i_rp->r_fr_offset = 0;
2831
+                       insn->i_rp->r_fix = NULL;
2832
+               */
2833
+               } else {
2834
+                       insn->i_rp =(ZIPRELOC *)xmalloc(sizeof(ZIPRELOC));
2835
+                       insn->i_rp->r_sym = sym;
2836
+                       insn->i_rp->r_pcrel = FALSE;
2837
+                       insn->i_rp->r_fr_offset = 0;
2838
+                       insn->i_rp->r_fix = NULL;
2839
+                       if (insn->i_breg != ZIP_RNONE)
2840
+                               insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_OFFSET;
2841
+                       else
2842
+                               insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_IMM;
2843
+               }
2844
+       }
2845
+
2846
+       return  err;
2847
+}
2848
+
2849
+static int     fits_within(int nbits, int value) {
2850
+       // -2 fits_within two bits
2851
+       // -1 fits_within two bits
2852
+       //  1 fits_within two bits
2853
+       //  2 does not
2854
+       //
2855
+       if (value > 0)
2856
+               return (value <   (1l<<(nbits-1))) ? 1:0;
2857
+       else
2858
+               return (value >= -(1l<<(nbits-1))) ? 1:0;
2859
+}
2860
+
2861
+static const char *zip_parse(const char *line, ZIPIS *insn) {
2862
+       const char      *err = NULL, *opstr = NULL;
2863
+       char    *alt;
2864
+       int     i;
2865
+       char *cndp = NULL;
2866
+       // Two (possible) tokens left:
2867
+       //      the left of the comma, and the right of the comma
2868
+       const char      *left, *right, *eol;
2869
+       typedef enum    {
2870
+               TWO_OP,         // Standard for most instructions
2871
+               IMM_OP,         // Immediate operand only
2872
+               BACKWARDS_TWO,  // Only used by STO REG,Off(REG)
2873
+               NO_OP,          // Used by NOOP, BUSY, HALT, RTU, LOCK, etc
2874
+               ONE_OR_TWO_OP,  // Only used by TST
2875
+               MAYBE_ONE_IMM,  // Only used by BREAK, NOOP, SIM
2876
+               MAYBE_ONE_REG,  // Only used by SDUMP, NDUMP
2877
+               MAYBE_ONE_IMM_OR_REG,   // Only used by SEXIT, NEXIT, SOUT, NOUT
2878
+               MAYBE_OPB,      // Only used by TRAP
2879
+               ONE_REGISTER,   // Only used by CLR, CLRF, and NOT
2880
+               OP_ADDRESS,     // Only used by BRA, BRA.C, and LINK
2881
+               OP_B,           // Only used by JMP
2882
+               TWO_REGISTER,   // Only used by FP instructions
2883
+               ILLEGAL_FORM    // Never used, for debugging only
2884
+       } FORMTYPE;
2885
+
2886
+       FORMTYPE        insn_form = ILLEGAL_FORM; // Make sure we set this
2887
+
2888
+
2889
+
2890
+#ifdef ZIP_DEBUG
2891
+       fprintf(stderr, "**** Parsing %s\n", line);
2892
+#endif
2893
+
2894
+       insn->i_naux = 0;
2895
+       insn->i_op   = ZIPO_NOOP;
2896
+       insn->i_cnd  = ZIPC_ALWAYS;
2897
+       insn->i_areg = ZIP_RNONE;
2898
+       insn->i_breg = ZIP_RNONE;
2899
+       insn->i_imm  = 0;
2900
+       insn->i_rp   = NULL;
2901
+       insn->i_code = NOOP_OPCODE;
2902
+       for(i=0; i<ZIP_MAX_NAUX; i++)
2903
+               insn->i_aux[i]  = NOOP_OPCODE;
2904
+
2905
+       // The opcode is given between whitespace and a period, or whitespace
2906
+       // and whitespace
2907
+       alt = strdup(zip_skip_white_spaces(line));
2908
+       if ((*alt)=='[') {
2909
+               // Instruction starts with condition codes-- a feature we
2910
+               // needed to add in order to support GCC conditional execution
2911
+               // macro
2912
+               cndp = strtok(alt,"] \t")+1;
2913
+               if (!cndp)
2914
+                       return "Mismatched parenthesis--an attempt at a condition?";
2915
+               if (strlen(cndp) > 3)
2916
+                       return "Invalid condition (too long)";
2917
+
2918
+               opstr = strtok(NULL, " \t");
2919
+               if (!opstr)
2920
+                       return "Condition not followed by valid opcode";
2921
+       } else {
2922
+               opstr = strtok(alt, " \t"); // Get our opcode
2923
+               if (!opstr) {
2924
+                       free(alt);
2925
+                       return "Invalid Instruction";
2926
+               }
2927
+       }
2928
+       // See if our token contains a '.' within it
2929
+       //      GCC allows conditions beginning a line, as in ...
2930
+       //              (CND)   Opcode  B,A
2931
+       //      such a condition, if present, was detected above.
2932
+       //
2933
+       //      If not, we now look for a condition written in our original
2934
+       //      format of ...
2935
+       //              Opcode.CND B,A
2936
+       //      and we look for it here.
2937
+       //
2938
+       if (!cndp) {
2939
+               cndp = strchr(opstr, '.');
2940
+               // If we found such a condition, we need to fix the opstr
2941
+               // so that it no longer includes the condition.  Hence, let's
2942
+               // place a NULL within the alt string and push our condition
2943
+               // forward to the first non '.' value.
2944
+               if (cndp)
2945
+                       *cndp++ = '\0';
2946
+       }
2947
+       if (strcasecmp(opstr, "SUB")==0) {
2948
+               insn->i_op = ZIPO_SUB;
2949
+               insn_form = TWO_OP;
2950
+       } else if (strcasecmp(opstr, "AND")==0) {
2951
+               insn->i_op = ZIPO_AND;
2952
+               insn_form = TWO_OP;
2953
+       } else if (strcasecmp(opstr, "ADD")==0) {
2954
+               insn->i_op = ZIPO_ADD;
2955
+               insn_form = TWO_OP;
2956
+       } else if (strcasecmp(opstr, "OR")==0) {
2957
+               insn->i_op = ZIPO_OR;
2958
+               insn_form = TWO_OP;
2959
+       } else if (strcasecmp(opstr, "XOR")==0) {
2960
+               insn->i_op = ZIPO_XOR;
2961
+               insn_form = TWO_OP;
2962
+       } else if (strcasecmp(opstr, "LSR")==0) {
2963
+               insn->i_op = ZIPO_LSR;
2964
+               insn_form = TWO_OP;
2965
+       } else if (strcasecmp(opstr, "LSL")==0) {
2966
+               insn->i_op = ZIPO_LSL;
2967
+               insn_form = TWO_OP;
2968
+       } else if (strcasecmp(opstr, "ASR")==0) {
2969
+               insn->i_op = ZIPO_ASR;
2970
+               insn_form = TWO_OP;
2971
+       } else if (strcasecmp(opstr, "BREV")==0) {
2972
+               insn->i_op = ZIPO_BREV;                 // BREV b+Rb,Ra, or
2973
+               insn_form = ONE_OR_TWO_OP;              // BREV Rx -> BREV Rx,Rx
2974
+       } else if((strcasecmp(opstr, "LDILO")==0)
2975
+                       ||(strcasecmp(opstr, "LLO")==0)) {
2976
+               insn->i_op = ZIPO_LDILO;
2977
+               insn_form = TWO_OP;
2978
+       } else if (strcasecmp(opstr, "MPYUHI")==0) {    // MPUHI
2979
+               insn->i_op = ZIPO_MPYUHI;
2980
+               insn_form = TWO_OP;
2981
+       } else if (strcasecmp(opstr, "MPYSHI")==0) {    // MPSHI
2982
+               insn->i_op = ZIPO_MPYSHI;
2983
+               insn_form = TWO_OP;
2984
+       } else if (strcasecmp(opstr, "MPY")==0) {
2985
+               insn_form = TWO_OP;
2986
+               insn->i_op = ZIPO_MPY;
2987
+       } else if (strcasecmp(opstr, "MOV")==0) {
2988
+               insn->i_op = ZIPO_MOV;
2989
+               insn_form = TWO_OP;
2990
+       } else if (strcasecmp(opstr, "DIVU")==0) {
2991
+               insn->i_op = ZIPO_DIVU;
2992
+               insn_form = TWO_OP;
2993
+       } else if (strcasecmp(opstr, "DIVS")==0) {
2994
+               insn->i_op = ZIPO_DIVS;
2995
+               insn_form = TWO_OP;
2996
+       } else if (strcasecmp(opstr, "CMP")==0) {
2997
+               insn->i_op = ZIPO_CMP;
2998
+               insn_form = TWO_OP;
2999
+       } else if ((strcasecmp(opstr, "TST")==0)
3000
+               ||(strcasecmp(opstr, "TEST")==0)) {
3001
+               insn->i_op = ZIPO_TST;                  // TST b+Rb,Ra, or
3002
+               insn_form = ONE_OR_TWO_OP;              // TST Rx -> TST -1,Rx
3003
+       } else if (strcasecmp(opstr, "LW")==0) {
3004
+               insn->i_op = ZIPO_LW;
3005
+               insn_form = TWO_OP;
3006
+       } else if (strcasecmp(opstr, "SW")==0) {
3007
+               insn->i_op = ZIPO_SW;
3008
+               insn_form = BACKWARDS_TWO;
3009
+       } else if (strcasecmp(opstr, "LH")==0) {
3010
+               insn->i_op = ZIPO_LH;
3011
+               insn_form = TWO_OP;
3012
+       } else if (strcasecmp(opstr, "SH")==0) {
3013
+               insn->i_op = ZIPO_SH;
3014
+               insn_form = BACKWARDS_TWO;
3015
+       } else if (strcasecmp(opstr, "LB")==0) {
3016
+               insn->i_op = ZIPO_LB;
3017
+               insn_form = TWO_OP;
3018
+       } else if (strcasecmp(opstr, "SB")==0) {
3019
+               insn->i_op = ZIPO_SB;
3020
+               insn_form = BACKWARDS_TWO;
3021
+       } else if (strcasecmp(opstr, "LDI")==0) {
3022
+               insn->i_op = ZIPO_LDI;
3023
+               insn_form = IMM_OP;
3024
+       } else if (strcasecmp(opstr, "FPADD")==0) {
3025
+               insn->i_op = ZIPO_FPADD;
3026
+               insn_form = TWO_REGISTER;
3027
+       } else if (strcasecmp(opstr, "FPSUB")==0) {
3028
+               insn->i_op = ZIPO_FPSUB;
3029
+               insn_form = TWO_REGISTER;
3030
+       } else if (strcasecmp(opstr, "FPMUL")==0) {
3031
+               insn->i_op = ZIPO_FPMPY;
3032
+               insn_form = TWO_REGISTER;
3033
+       } else if (strcasecmp(opstr, "FPDIV")==0) {
3034
+               insn->i_op = ZIPO_FPDIV;
3035
+               insn_form = TWO_REGISTER;
3036
+       } else if (strcasecmp(opstr, "FPI2F")==0) {
3037
+               insn->i_op = ZIPO_FPI2F;
3038
+               insn_form = TWO_OP;
3039
+       } else if (strcasecmp(opstr, "FPF2I")==0) {
3040
+               insn->i_op = ZIPO_FPF2I;
3041
+               insn_form = TWO_REGISTER;
3042
+       } else if ((strcasecmp(opstr, "BRK")==0)
3043
+               ||(strcasecmp(opstr, "BREAK")==0)) {
3044
+               insn->i_op = ZIPO_BREAK;
3045
+               insn->i_imm= 0;
3046
+               insn_form = MAYBE_ONE_IMM;
3047
+       } else if (strcasecmp(opstr, "LOCK")==0) {
3048
+               insn->i_op = ZIPO_LOCK;
3049
+               insn_form = NO_OP;
3050
+       // Now for some derived instructions
3051
+       } else if (strcasecmp(opstr, "TRAP")==0) {
3052
+               insn->i_op = ZIPO_TRAP;
3053
+               insn_form = MAYBE_OPB;
3054
+       } else if (strcasecmp(opstr, "CLR")==0) {
3055
+               insn->i_op = ZIPO_CLR;
3056
+               insn_form = ONE_REGISTER;
3057
+       } else if (strcasecmp(opstr, "BRA")==0) {
3058
+               insn->i_op = ZIPO_BRA;
3059
+               insn_form = OP_ADDRESS;
3060
+       } else if (strcasecmp(opstr, "LJMP")==0) {
3061
+               insn->i_op = ZIPO_LJMP;
3062
+               insn->i_breg = ZIP_RNONE;
3063
+               insn->i_imm  = 0;
3064
+               insn_form = OP_ADDRESS;
3065
+       } else if (strcasecmp(opstr, "BZ")==0) {
3066
+               insn->i_op = ZIPO_BRA;
3067
+               insn->i_cnd = ZIPC_Z;
3068
+               insn_form = OP_ADDRESS;
3069
+       } else if (strcasecmp(opstr, "BLT")==0) {
3070
+               insn->i_op = ZIPO_BRA;
3071
+               insn->i_cnd = ZIPC_LT;
3072
+               insn_form = OP_ADDRESS;
3073
+       } else if (strcasecmp(opstr, "BC")==0) {
3074
+               insn->i_op = ZIPO_BRA;
3075
+               insn->i_cnd = ZIPC_C;
3076
+               insn_form = OP_ADDRESS;
3077
+       } else if (strcasecmp(opstr, "BV")==0) {
3078
+               insn->i_op = ZIPO_BRA;
3079
+               insn->i_cnd = ZIPC_V;
3080
+               insn_form = OP_ADDRESS;
3081
+       } else if (strcasecmp(opstr, "BNZ")==0) {
3082
+               insn->i_op = ZIPO_BRA;
3083
+               insn->i_cnd = ZIPC_NZ;
3084
+               insn_form = OP_ADDRESS;
3085
+       } else if (strcasecmp(opstr, "BGE")==0) {
3086
+               insn->i_op = ZIPO_BRA;
3087
+               insn->i_cnd = ZIPC_GE;
3088
+               insn_form = OP_ADDRESS;
3089
+       } else if (strcasecmp(opstr, "BNC")==0) {
3090
+               insn->i_op = ZIPO_BRA;
3091
+               insn->i_cnd = ZIPC_NC;
3092
+               insn_form = OP_ADDRESS;
3093
+       } else if (strcasecmp(opstr, "HALT")==0) {
3094
+               insn->i_op = ZIPO_HALT;
3095
+               insn->i_imm = ZIP_CC_SLEEP;
3096
+               insn->i_areg= ZIP_CC;
3097
+               insn_form = NO_OP;
3098
+       } else if (strcasecmp(opstr, "WAIT")==0) {
3099
+               insn->i_op = ZIPO_WAIT;
3100
+               insn->i_imm = ZIP_CC_SLEEP | ZIP_CC_GIE;
3101
+               insn->i_areg= ZIP_CC;
3102
+               insn_form = NO_OP;
3103
+       } else if (strcasecmp(opstr, "STEP")==0) {
3104
+               insn->i_op = ZIPO_STEP;
3105
+               insn->i_imm = ZIP_CC_STEP | ZIP_CC_GIE;
3106
+               insn->i_areg= ZIP_CC;
3107
+               insn_form = NO_OP;
3108
+       } else if ((strcasecmp(opstr, "RTU")==0)
3109
+                       ||(strcasecmp(opstr, "IRET")==0)) {
3110
+               insn->i_op = ZIPO_RTU;
3111
+               insn->i_imm = ZIP_CC_GIE;
3112
+               insn->i_areg = ZIP_CC;
3113
+               insn_form = NO_OP;
3114
+       } else if (strcasecmp(opstr, "BUSY")==0) {
3115
+               insn->i_op = ZIPO_BUSY;
3116
+               insn->i_imm= -4;
3117
+               insn->i_areg = ZIP_PC;
3118
+               insn->i_breg = ZIP_RNONE;
3119
+               insn_form = NO_OP;
3120
+       } else if (strcasecmp(opstr, "JMP")==0) {
3121
+               insn->i_op = ZIPO_JMP;
3122
+               insn->i_areg = ZIP_PC;
3123
+               insn_form = OP_B;
3124
+       } else if ((strcasecmp(opstr, "RETN")==0)
3125
+                       ||(strcasecmp(opstr, "RTN")==0)) {
3126
+               insn->i_op = ZIPO_JMP;
3127
+               insn->i_areg = ZIP_PC;
3128
+               insn->i_breg = ZIP_LR;
3129
+               insn->i_imm  = 0;
3130
+               insn_form = NO_OP;
3131
+       } else if (strcasecmp(opstr, "NOT")==0) {
3132
+               insn->i_op = ZIPO_NOT;
3133
+               insn->i_imm = -1;
3134
+               insn_form = ONE_REGISTER;
3135
+       } else if (strcasecmp(opstr, "NEG")==0) {
3136
+               insn->i_op = ZIPO_NEG;
3137
+               insn->i_imm = 0;
3138
+               insn_form = ONE_OR_TWO_OP;
3139
+       } else if (strcasecmp(opstr, "LJSR")==0) {
3140
+               insn->i_op   = ZIPO_LJSR;
3141
+               insn->i_breg = ZIP_RNONE;
3142
+               insn->i_imm  = 0;
3143
+               insn_form    = OP_ADDRESS;
3144
+       } else if (strcasecmp(opstr, "JSR")==0) {
3145
+               insn->i_op = ZIPO_JSR;
3146
+               insn->i_imm = 0;
3147
+               insn_form = OP_ADDRESS;
3148
+       } else if ((strcasecmp(opstr, "NOP")==0)
3149
+                       ||(strcasecmp(opstr, "NOOP")==0)) {
3150
+               insn->i_op = ZIPO_NOOP;
3151
+               insn_form = MAYBE_ONE_IMM;
3152
+       } else if (strcasecmp(opstr, "SIM")==0) {
3153
+               insn->i_op = ZIPO_SIM;
3154
+               insn->i_imm= 0;
3155
+               insn_form = MAYBE_ONE_IMM;
3156
+       } else if (strcasecmp(opstr, "SNOOP")==0) {
3157
+               insn->i_op = ZIPO_SIM;
3158
+               insn->i_imm= 0;
3159
+               insn_form = MAYBE_ONE_IMM;
3160
+       } else if (strcasecmp(opstr, "SDUMP")==0) {
3161
+               insn->i_op = ZIPO_SDUMP;
3162
+               insn->i_imm= 0;
3163
+               insn_form = MAYBE_ONE_REG;
3164
+       } else if (strcasecmp(opstr, "SEXIT")==0) {
3165
+               insn->i_op = ZIPO_SEXIT;
3166
+               insn->i_imm= 0;
3167
+               insn_form = MAYBE_ONE_IMM_OR_REG;
3168
+       } else if (strcasecmp(opstr, "SOUT")==0) {
3169
+               insn->i_op = ZIPO_SOUT;
3170
+               insn->i_imm= 0;
3171
+               insn_form = MAYBE_ONE_IMM_OR_REG;
3172
+       } else if (strcasecmp(opstr, "NDUMP")==0) {
3173
+               insn->i_op = ZIPO_NDUMP;
3174
+               insn->i_imm= 0;
3175
+               insn_form = MAYBE_ONE_REG;
3176
+       } else if (strcasecmp(opstr, "NEXIT")==0) {
3177
+               insn->i_op = ZIPO_NEXIT;
3178
+               insn->i_imm= 0;
3179
+               insn_form = MAYBE_ONE_IMM_OR_REG;
3180
+       } else if (strcasecmp(opstr, "SEXTB")==0) {
3181
+               insn->i_op = ZIPO_SEXTB;
3182
+               insn->i_imm= 0;
3183
+               insn_form = ONE_REGISTER;
3184
+       } else if (strcasecmp(opstr, "SEXTH")==0) {
3185
+               insn->i_op = ZIPO_SEXTH;
3186
+               insn->i_imm= 0;
3187
+               insn_form = ONE_REGISTER;
3188
+       } else if (strcasecmp(opstr, "NOUT")==0) {
3189
+               insn->i_op = ZIPO_NOUT;
3190
+               insn->i_imm= 0;
3191
+               insn_form = MAYBE_ONE_IMM_OR_REG;
3192
+       } else {
3193
+               free(alt);
3194
+               return "Unrecognized op-code";
3195
+       }
3196
+
3197
+       if (cndp) {
3198
+               // We have a condition
3199
+               if (insn->i_cnd != ZIPC_ALWAYS) {
3200
+                       err = "Instruction cannot take an additional condition";
3201
+               } else {
3202
+                       err = zip_parse_condition(cndp, &insn->i_cnd);
3203
+               }
3204
+       } if (err) {
3205
+               free(alt);
3206
+               return err;
3207
+       }
3208
+
3209
+       if (strchr(line, ',')!=NULL)
3210
+               left = strtok(NULL, ",");
3211
+       else
3212
+               left  = strtok(NULL, " \t,");
3213
+       right = (left)  ? strtok(NULL, " \t") : NULL;
3214
+       eol   = (right) ? strtok(NULL, " \t") : NULL;
3215
+       if (eol != NULL) {
3216
+               free(alt);
3217
+               return "Too many tokens on one line";
3218
+       }
3219
+
3220
+       switch(insn_form) {
3221
+               case TWO_OP:
3222
+                       err = zip_parse_bop(left,insn);
3223
+                       if (!err)
3224
+                               err = zip_parse_reg(right,&insn->i_areg);
3225
+                       break;
3226
+               case IMM_OP:
3227
+                       err = zip_parse_bop(left,insn);
3228
+                       if ((!err)&&(insn->i_breg == ZIP_RNONE))
3229
+                               err = zip_parse_reg(right,&insn->i_areg);
3230
+                       else if (!err)
3231
+                               err = "LDI can only load immediates, not registers";
3232
+                       break;
3233
+               case BACKWARDS_TWO:
3234
+                       err = zip_parse_reg(left,&insn->i_areg);
3235
+                       if (!err)
3236
+                               err = zip_parse_bop(right,insn);
3237
+                       break;
3238
+               case MAYBE_ONE_IMM:
3239
+                       if (NULL != right)
3240
+                               err = "Wrong number of operands!";
3241
+                       else if (left) {
3242
+                               err = zip_parse_bop(left,insn);
3243
+                               if ((!err)&&(insn->i_breg != ZIP_RNONE))
3244
+                                       err = "BREAK arguments can only be immediates";
3245
+                       }
3246
+                       break;
3247
+               case MAYBE_ONE_IMM_OR_REG:
3248
+                       if (NULL != right)
3249
+                               err = "Wrong number of operands!";
3250
+                       else if (left) {
3251
+                               err = zip_parse_bop(left,insn);
3252
+                               if ((!err)&&(insn->i_breg != ZIP_RNONE)
3253
+                                       &&(insn->i_imm != 0))
3254
+                                       err = "EXIT arguments can only be immediates or register, not both";
3255
+                       }
3256
+                       break;
3257
+               case MAYBE_ONE_REG:
3258
+                       if (NULL != right)
3259
+                               err = "Wrong number of operands!";
3260
+                       else if (left) {
3261
+                               err = zip_parse_bop(left,insn);
3262
+                               if ((!err)&&(insn->i_breg != ZIP_RNONE)&&(insn->i_imm))
3263
+                                       err = "xDUMP instructions can handle immediates or registers, not both";
3264
+                       } else {
3265
+                               insn->i_breg = ZIP_RNONE;
3266
+                               insn->i_imm  = 0;
3267
+                       } break;
3268
+               case NO_OP:
3269
+                       if ((NULL != left)||(NULL != right))
3270
+                               err = "Wrong number of operands!";
3271
+                       break;
3272
+               case ONE_OR_TWO_OP:
3273
+                       // This is a reference to the test instruction, which
3274
+                       // can either be
3275
+                       //      A. TEST a,Rx, or TEST Rx,.
3276
+                       // or   B. BRA  a,Rx, or BRA Rx,.
3277
+                       if (NULL != right) {
3278
+                               err = zip_parse_bop(left,insn);
3279
+                               if (!err)
3280
+                                       err = zip_parse_reg(right,&insn->i_areg);
3281
+                               if (!err)
3282
+                                       err = zip_parse_bop(left,insn);
3283
+                       } else {
3284
+                               zip_parse_reg(left, &insn->i_areg);
3285
+                               if (insn->i_op == ZIPO_BREV) {
3286
+                                       insn->i_breg = insn->i_areg;
3287
+                                       insn->i_imm = 0;
3288
+                               } else {
3289
+                                       insn->i_breg = ZIP_RNONE;
3290
+                                       insn->i_imm = -1;
3291
+                               }
3292
+                       } break;
3293
+               case ONE_REGISTER:
3294
+                       // CLR, CLRF, or NOT
3295
+                       insn->i_breg = ZIP_RNONE;
3296
+                       if (NULL != right)
3297
+                               err = "Instruction opcode expects only one operand";
3298
+                       else
3299
+                               err = zip_parse_reg(left,&insn->i_areg);
3300
+                       break;
3301
+               case OP_ADDRESS:
3302
+                       // JSR or BRA instruction
3303
+                       //      This is different from OP_B below, in that this
3304
+                       //      form implies a PC relative addressing, which
3305
+                       //      may not be clear from the operands given
3306
+                       if (NULL != right)
3307
+                               err = "Instruction opcode expects only one operand";
3308
+                       else {
3309 206 dgisselq
+                               if ((NULL == left)||(left[0] == '\0')) {
3310
+                                       err = "No address given";
3311
+                               } else if ((NULL == strchr(left,'('))
3312 202 dgisselq
+                                       &&(NULL == strchr(left,'+'))) {
3313
+                                       char    *longerstr = (char *)xmalloc(strlen(left)+6);
3314
+                                       // If not stated, assume PC relative
3315
+                                       strcpy(longerstr,left);
3316
+                                       strcat(longerstr, "(PC)");
3317
+                                       err = zip_parse_bop(longerstr, insn);
3318
+                                       free(longerstr);
3319
+                               } else
3320
+                                       err = zip_parse_bop(left, insn);
3321
+                       }
3322
+
3323
+                       break;
3324
+               case MAYBE_OPB:
3325
+                       // JMP or TRAP instruction
3326
+                       if (NULL != right)
3327
+                               err = "Instruction opcode expects only one operand";
3328
+                       else if (NULL == left) {
3329
+                               insn->i_breg = ZIP_RNONE;
3330
+                               insn->i_imm = 0;
3331
+                               break;
3332
+                       } // Fall through
3333
+               case OP_B: // Operand B only (A is implied)
3334
+                       // JMP or TRAP instruction
3335
+                       if (NULL != right)
3336
+                               err = "Instruction opcode expects only one operand";
3337
+                       else
3338
+                               err = zip_parse_bop(left, insn);
3339
+                       if (insn->i_op == ZIPO_JMP)
3340
+                               insn->i_areg = ZIP_PC;
3341
+                       else // if insn->i_op == TRAP
3342
+                               insn->i_areg = ZIP_CC;
3343
+                       break;
3344
+               case TWO_REGISTER:
3345
+                       // These are the floating point instructions, which
3346
+                       // can't handle immediate offsets.
3347
+                       err = zip_parse_reg(right, &insn->i_areg);
3348
+                       if (!err)
3349
+                               err = zip_parse_reg(left, &insn->i_breg);
3350
+                       break;
3351
+               default:        // case ILLEGAL_FORM
3352
+                       err = "Unknown instruction format!";
3353
+                       break;
3354
+       }
3355
+
3356
+       if (err)
3357
+               return (err);
3358
+
3359
+       switch(insn->i_op) {
3360
+               case ZIPO_SUB:  case ZIPO_AND: case ZIPO_ADD: case ZIPO_OR:
3361
+               case ZIPO_XOR:  case ZIPO_LSR: case ZIPO_LSL: case ZIPO_ASR:
3362
+               case ZIPO_BREV:
3363
+               case ZIPO_MPYUHI: case ZIPO_MPYSHI:
3364
+               case ZIPO_MPY:
3365
+                       break;
3366
+               case ZIPO_LDILO:
3367
+                       if (!fits_within(16, insn->i_imm))
3368
+                               gas_assert((insn->i_imm & (~0x0ffff))==0);
3369
+                       insn->i_imm &= 0x0ffff;
3370
+                       break;
3371
+               case ZIPO_DIVU: case ZIPO_DIVS:
3372
+                       if (0x0e == (insn->i_areg & 0x0f))
3373
+                               err = "Divide instructions cannot result in CC or PC regs";
3374
+                       else if (insn->i_rp)
3375
+                               err = "Relocations not applicable for divides";
3376
+                       break;
3377
+                       break;
3378
+               case ZIPO_MOV:
3379
+                       if (insn->i_breg == ZIP_RNONE)
3380
+                               insn->i_op = ZIPO_LDI;
3381
+                       break;
3382
+               case ZIPO_CMP: case ZIPO_TST:
3383
+                       break;
3384
+               case ZIPO_LW: case ZIPO_SW:
3385
+               case ZIPO_LH: case ZIPO_SH:
3386
+               case ZIPO_LB: case ZIPO_SB:
3387
+                       break;
3388
+               case ZIPO_LDI: case ZIPO_LDIn:
3389
+                       break;
3390
+               case ZIPO_FPADD: case ZIPO_FPSUB:
3391
+               case ZIPO_FPMPY: case ZIPO_FPDIV:
3392
+               case ZIPO_FPF2I: case ZIPO_FPI2F:
3393
+                       if (0x0e == (insn->i_areg & 0x0f))
3394
+                               err = "Floating point operations cannot result in CC or PC regs";
3395
+                       else if (insn->i_rp)
3396
+                               err = "Relocations not applicable for floating point ops";
3397
+                       break;
3398
+               case ZIPO_TRAP:
3399
+                       insn->i_areg = ZIP_CC;
3400
+                       if (insn->i_breg == ZIP_RNONE) {
3401
+                               if (insn->i_cnd == ZIPC_ALWAYS)
3402
+                                       insn->i_op = ZIPO_LDI;
3403
+                               else if (fits_within(16, insn->i_imm))
3404
+                                       insn->i_op = ZIPO_LDILO;
3405
+                               else if (fits_within(18, zip_brev(insn->i_imm)))
3406
+                                       insn->i_op = ZIPO_BREV;
3407
+                               else
3408
+                                       err = "TRAP immediate not supported";
3409
+                       } else
3410
+                               insn->i_op = ZIPO_MOV;
3411
+                       break;
3412
+               case ZIPO_CLR:
3413
+                       insn->i_op = ZIPO_LDI;
3414
+                       insn->i_imm = 0;
3415
+                       break;
3416
+               case ZIPO_JMP:
3417
+                       if (insn->i_breg != ZIP_RNONE)
3418
+                               insn->i_op = ZIPO_MOV;  // JMP A+Rx
3419
+                       else
3420
+                               insn->i_op = ZIPO_BRA;  // JMP lbl = BRA lbl
3421
+                       // Fall through
3422
+               case ZIPO_BRA: // Leave as ZIPO_BRA until we assemble it
3423
+                       insn->i_areg = ZIP_PC;
3424
+                       break;
3425
+               case ZIPO_HALT: case ZIPO_WAIT: case ZIPO_RTU: case ZIPO_STEP:
3426
+                       insn->i_op = ZIPO_OR;
3427
+                       break;
3428
+               case ZIPO_BUSY:
3429
+                       insn->i_op = ZIPO_ADD;
3430
+                       break;
3431
+               case ZIPO_NOT:
3432
+                       insn->i_op = ZIPO_XOR;
3433
+                       insn->i_imm  = -1;
3434
+                       insn->i_breg = ZIP_RNONE;
3435
+                       break;
3436
+               case ZIPO_NEG:
3437
+                       if (insn->i_breg == ZIP_RNONE) {
3438
+                               insn->i_breg = insn->i_areg;
3439
+                               // This would've been set to -1 by the ONE or
3440
+                               // TWO op code.  Here, we set it back to zero.
3441
+                               insn->i_imm  = 0;
3442
+                       }
3443
+                       // insn->i_op = ZIPO_NEG; /// Can't collapse this yet
3444
+                       break;
3445
+               case ZIPO_BREAK:
3446
+                       insn->i_op = ZIPO_BREAK;
3447
+                       insn->i_areg = ZIP_RNONE;
3448
+                       insn->i_breg = ZIP_RNONE;
3449
+                       // insn->i_imm  = ... whatever it was set to
3450
+                       break;
3451
+               case ZIPO_LOCK:
3452
+                       insn->i_op = ZIPO_LOCK;
3453
+                       insn->i_areg = ZIP_RNONE;
3454
+                       insn->i_breg = ZIP_RNONE;
3455
+                       insn->i_imm  = 0;
3456
+                       break;
3457
+               case ZIPO_SDUMP:
3458
+                       insn->i_op = ZIPO_SIM;
3459
+                       if (insn->i_breg != ZIP_RNONE) {
3460
+                               insn->i_imm = (int)insn->i_breg + 0x0200;
3461
+                               insn->i_breg = ZIP_RNONE;
3462
+                       } else
3463
+                               insn->i_imm = 0x2ff;
3464
+                       break;
3465
+               case ZIPO_NDUMP:
3466
+                       insn->i_op = ZIPO_NOOP;
3467
+                       if (insn->i_breg != ZIP_RNONE) {
3468
+                               insn->i_imm = (int)insn->i_breg + 0x0200;
3469
+                               insn->i_breg = ZIP_RNONE;
3470
+                       } else
3471
+                               insn->i_imm = 0x2ff;
3472
+                       break;
3473
+               case ZIPO_SEXIT:
3474
+                       insn->i_op = ZIPO_SIM;
3475
+                       if (insn->i_breg != ZIP_RNONE)
3476
+                               insn->i_imm = 0x300 + (insn->i_breg & 0x01f);
3477
+                       else
3478
+                               insn->i_imm = 0x100 + (insn->i_imm & 0x0ff);
3479
+                       insn->i_breg = ZIP_RNONE;
3480
+                       break;
3481
+               case ZIPO_NEXIT:
3482
+                       insn->i_op = ZIPO_NOOP;
3483
+                       if (insn->i_breg != ZIP_RNONE)
3484
+                               insn->i_imm = 0x300 + (insn->i_breg & 0x01f);
3485
+                       else
3486
+                               insn->i_imm = 0x100 + (insn->i_imm & 0x0ff);
3487
+                       insn->i_breg = ZIP_RNONE;
3488
+                       break;
3489
+               case ZIPO_SOUT:
3490
+                       insn->i_op = ZIPO_SIM;
3491
+                       if (insn->i_breg != ZIP_RNONE)
3492
+                               insn->i_imm = 0x220 + (insn->i_breg & 0x01f);
3493
+                       else
3494
+                               insn->i_imm = 0x400 + (insn->i_imm & 0x0ff);
3495
+                       insn->i_breg = ZIP_RNONE;
3496
+                       break;
3497
+               case ZIPO_NOUT:
3498
+                       insn->i_op = ZIPO_NOOP;
3499
+                       if (insn->i_breg != ZIP_RNONE)
3500
+                               insn->i_imm = 0x220 + (insn->i_breg & 0x01f);
3501
+                       else
3502
+                               insn->i_imm = 0x400 + (insn->i_imm & 0x0ff);
3503
+                       insn->i_breg = ZIP_RNONE;
3504
+                       break;
3505
+               case ZIPO_SIM:
3506
+               case ZIPO_NOOP:
3507
+                       break;
3508
+               case ZIPO_LJMP: case ZIPO_LJSR:
3509
+                       if (insn->i_breg == ZIP_PC)
3510
+                               insn->i_breg = ZIP_RNONE;
3511
+                       if (insn->i_breg != ZIP_RNONE) {
3512
+                               err = "Indirect long jumps and long JSRs are not supported";
3513
+                       } break;
3514
+               case ZIPO_JSR:
3515
+                       break;
3516
+               case ZIPO_SEXTB: case ZIPO_SEXTH:
3517
+                       break;
3518
+               default:
3519
+                       return "Internal error -- unrecognized internal opcode";
3520
+                       break;
3521
+       } if (err) {
3522
+               free(alt);
3523
+               return err;
3524
+       }
3525
+
3526
+       if ((insn->i_op != ZIPO_MOV)&&(
3527
+                       ((insn->i_areg != ZIP_RNONE)&&(insn->i_areg >= 0x10))
3528
+                       ||((insn->i_breg != ZIP_RNONE)&&(insn->i_breg >= 0x10)))) {
3529
+               if (insn->i_rp)
3530
+                       free(insn->i_rp);
3531
+               insn->i_rp = NULL;
3532
+               free(alt);
3533
+               return "Only MOV instructions can reference explicit user registers";
3534
+       }
3535
+
3536
+       free(alt);
3537
+
3538
+       // We do nothing more to build the opcode here --- all we are doing
3539
+       // is parsing.
3540
+       return err;
3541
+}
3542
+
3543
+#define        NOOPGROUP(OP,IMM) ((0x78000000)|((((OP)+0x1c-ZIPO_BREAK)&0x01f)<<22)|((IMM) & 0x003fffff))
3544
+#define        DBLREGOP(OP,CND,IMM,B,A) ((((OP)&0x01f)<<22)|(((A)&0x0f)<<27)   \
3545
+                       | (((CND)&0x07)<<19)|(1<<18)|(((B)&0x0f)<<14)   \
3546
+                       | ((IMM) & 0x03fff))
3547
+#define        SMPLMOV(CND,IMM,B,A)    (((ZIPO_MOV&0x01f)<<22)|(((A)&0x0f)<<27)        \
3548
+                       | (((CND)&0x07)<<19)|(((B)&0x0f)<<14)|((IMM) & 0x01fff))
3549
+#define        IMMOP(OP,CND,IMM,A)     ((((OP)&0x01f)<<22)|(((A)&0x0f)<<27)    \
3550
+                       | (((CND)&0x07)<<19)|((IMM) & 0x03ffff))
3551
+#define        LDIOP(IMM,A)    ((ZIPO_LDI<<22)|(((A)&0x0f)<<27)|((IMM) & 0x07fffff))
3552
+
3553
+
3554
+/*
3555
+ *     CIS support code
3556
+ *
3557
+ *     Assuming that the instruction (a) is not a CIS instruction, this looks
3558
+ *     up the immediate value encoded in the instruction.  The purpose is to
3559
+ *     determine whether or not this instruction can be merged with the
3560
+ *     previous (or next) instruction in CIS mode.
3561
+ *
3562
+ */
3563
+static int
3564
+zip_non_cis_immediate(const unsigned a)
3565
+{
3566
+       ZIP_OPCODE      op = (ZIP_OPCODE)((a>>22)&0x1f);
3567
+       int             imm;
3568
+
3569
+       switch(op) {
3570
+               case    ZIPO_MOV:
3571
+                       imm = (a & 0x01fff); if (a&0x1000) imm |= -0x1000; break;
3572
+               case    ZIPO_LDI:
3573
+                       imm = (a & 0x03fffff); break;
3574
+               case    ZIPO_LDIn:
3575
+                       imm = (a & 0x03fffff); imm |= -0x0200000; break;
3576
+/*
3577
+ * While this makes conceptual sense, it doesn't match the CPU.  Hence let's
3578
+ * comment it out and make certain things still work.
3579
+               case    ZIPO_LDILO:
3580
+#ifndef        LONG_MPY
3581
+               case ZIPO_LDIHI: // BREVx would rm LDIHI
3582
+#endif
3583
+                       imm = (a & 0x0ffff); break;
3584
+*/
3585
+               default:
3586
+                       if (a & 0x040000) {
3587
+                               imm = (a & 0x03fff);
3588
+                               if (a & 0x2000) imm |= -0x02000;
3589
+                       } else {
3590
+                               imm = (a & 0x03ffff);
3591
+                               if (a & 0x020000)
3592
+                                       imm |= -0x020000;
3593
+                       }
3594
+       }
3595
+
3596
+       return imm;
3597
+}
3598
+
3599
+static int
3600
+zip_can_merge(const unsigned a, const unsigned b)
3601
+{
3602
+       // Can't merge instructions if merging isnt turned on
3603
+       if (!zip_param_cis)
3604
+               return 0;
3605
+
3606
+       // 1. Can't merge anything that's already merged
3607
+       if ((a|b) & 0x80000000)
3608
+               return 0;
3609
+       ZIP_OPCODE      opa, opb;
3610
+       ZIP_CONDITION   ac, bc;
3611
+       int     imma, immb;
3612
+
3613
+       // Get the 5-bit operands for each
3614
+       opa = (a>>22)&0x1f;
3615
+       opb = (b>>22)&0x1f;
3616
+
3617
+       // 2. Can only merge if both are unconditional
3618
+       ac = ((a>>19)&0x07);
3619
+       bc = ((b>>19)&0x07);
3620
+       if ((opa != ZIPO_LDI)&&(opa != ZIPO_LDIn)&&(ac != ZIPC_ALWAYS))
3621
+               return 0;
3622
+       if ((opb != ZIPO_LDI)&&(opb != ZIPO_LDIn)&&(bc != ZIPC_ALWAYS))
3623
+               return 0;
3624
+
3625
+       // Only some instructions can be merged
3626
+       switch(opa) {
3627
+               case ZIPO_SUB: case ZIPO_AND: case ZIPO_ADD: case ZIPO_CMP:
3628
+               case ZIPO_LW:  case ZIPO_SW:  case ZIPO_LDI: case ZIPO_MOV:
3629
+               case ZIPO_LDIn:
3630
+                       break;
3631
+               default:
3632
+                       return 0;
3633
+       } switch(opb) {
3634
+               case ZIPO_SUB: case ZIPO_AND: case ZIPO_ADD: case ZIPO_CMP:
3635
+               case ZIPO_LW:  case ZIPO_SW:  case ZIPO_LDI: case ZIPO_MOV:
3636
+               case ZIPO_LDIn:
3637
+                       break;
3638
+               default:
3639
+                       return 0;
3640
+       }
3641
+
3642
+       // Prohibit moves to/from user regs to merge
3643
+       if ((opa == ZIPO_MOV)&&(a & 0x44000))
3644
+               return 0;
3645
+       if ((opb == ZIPO_MOV)&&(b & 0x44000))
3646
+               return 0;
3647 206 dgisselq
+
3648 202 dgisselq
+       imma = zip_non_cis_immediate(a);
3649
+       immb = zip_non_cis_immediate(b);
3650
+
3651
+       if (!fits_within(8,imma)) {
3652
+               // fprintf(stderr, "As immediate is out of range\n");
3653
+               return 0;
3654
+       } if (!fits_within(8,immb)) {
3655
+               // fprintf(stderr, "Bs immediate is out of range\n");
3656
+               return 0;
3657
+       }
3658
+
3659
+       // if abreg & 0x010, or bbreg & 0x010, then the register is being
3660
+       // used.
3661
+       int aareg = (a>>27)&0x00f;
3662
+       int abreg = (a>>14)&0x01f;
3663
+       int bbreg = (b>>14)&0x01f;
3664
+
3665
+       switch(opa) {
3666
+               case ZIPO_MOV:
3667
+                       if (!fits_within(3,imma))
3668
+                               return 0;
3669 206 dgisselq
+                       // Prohibit a MOV x(PC),Ry to move into a first
3670
+                       // instruction position.  While the CPU supports it,
3671
+                       // making sure x remains valid isn't yet supported
3672
+                       // here.
3673
+                       if ((ZIP_PC == aareg)||(ZIP_CC == aareg))
3674 202 dgisselq
+                               return 0;
3675
+                       break;
3676
+               case ZIPO_LDI: case ZIPO_LDIn:
3677
+                       if (!fits_within(8,imma))
3678
+                               return 0;
3679
+                       if (aareg == ZIP_CC)
3680
+                               return 0;
3681
+                       break;
3682
+               case ZIPO_ADD: case ZIPO_SUB: case ZIPO_AND:
3683
+                       if (aareg == ZIP_CC)
3684
+                               return 0;
3685
+               case ZIPO_CMP:
3686
+                       if ((abreg&0x10)==0) {
3687
+                               if (!fits_within(7,imma)) {
3688
+                                       return 0;
3689
+                               }
3690
+                       } else { // if (abreg&0x10)
3691
+                               if (!fits_within(3,imma))
3692
+                                       return 0;
3693
+                       } break;
3694
+               case ZIPO_LW: case ZIPO_SW:
3695
+                       if (aareg == ZIP_CC)
3696
+                               return 0;
3697
+                       if ((abreg&0x010)==0) {
3698
+                               return 0;
3699
+                       } else if (abreg== 0x10 + ZIP_SP) {
3700
+                               if (!fits_within(7,imma))
3701
+                                       return 0;
3702
+                       } else {
3703
+                               if (!fits_within(3,imma))
3704
+                                       return 0;
3705
+                       } break;
3706
+               default:
3707
+                       fprintf(stderr, "Unknown op, %d\n", opa);
3708
+                       return 0;
3709
+       }
3710
+
3711
+       switch(opb) {
3712
+               case ZIPO_MOV:
3713
+                       if (!fits_within(3,immb)) {
3714
+                               return 0;
3715
+                       } break;
3716
+               case ZIPO_LDI: case ZIPO_LDIn:
3717
+                       if (!fits_within(8,immb)) {
3718
+                               return 0;
3719
+                       } break;
3720
+               case ZIPO_ADD: case ZIPO_SUB: case ZIPO_CMP: case ZIPO_AND:
3721
+                       if ((bbreg&0x10)==0) {
3722
+                               if (!fits_within(7,immb))
3723
+                                       return 0;
3724
+                       } else { // if (bbreg&0x10)
3725
+                               if (!fits_within(3,immb))
3726
+                                       return 0;
3727
+                       } break;
3728
+               case ZIPO_LW: case ZIPO_SW:
3729
+                       if ((bbreg&0x010)==0) {
3730
+                               return 0;
3731
+                       } else if (bbreg== 0x10+ZIP_SP) {
3732
+                               if (!fits_within(7,immb))
3733
+                                       return 0;
3734
+                       } else {
3735
+                               if (!fits_within(3,immb))
3736
+                                       return 0;
3737
+                       } break;
3738
+               default:
3739
+                       return 0;
3740
+       }
3741
+
3742
+       return 1;
3743
+}
3744
+
3745
+static unsigned
3746
+zip_insn_merge(const unsigned a, const unsigned b)
3747
+{
3748
+       // 1. We already know we can merge these, so skip our can-merge checks
3749
+       ZIP_OPCODE      opa, opb;
3750
+       unsigned int    retv = 0;
3751
+
3752
+       // Get our two opcodes
3753
+       opa = (a>>22)&0x1f; opb = (b>>22)&0x1f;
3754
+
3755
+       // Truncate LDI opcodes back to their original values
3756
+       if (opa == 0x019) opa = 0x018;
3757
+       if (opb == 0x019) opb = 0x018;
3758
+       retv = 0x80008000;
3759
+
3760
+       // Start with the destination registers
3761
+       retv |= (a & 0x78000000);
3762
+       retv |= (b & 0x78000000) >> (27-11);
3763
+
3764
+       // Then the new OpCodes
3765
+       switch(opa) {
3766
+       case ZIPO_SUB:  retv |= (ZIPV_SUB<<24); break;
3767
+       case ZIPO_AND:  retv |= (ZIPV_AND<<24); break;
3768
+       case ZIPO_ADD:  retv |= (ZIPV_ADD<<24); break;
3769
+       case ZIPO_CMP:  retv |= (ZIPV_CMP<<24); break;
3770
+       case ZIPO_LW:   retv |= (ZIPV_LW <<24); break;
3771
+       case ZIPO_SW:   retv |= (ZIPV_SW <<24); break;
3772
+// 8e40
3773
+// 1.0001.110_0100_0000
3774
+       case ZIPO_LDI:  retv |= (ZIPV_LDI<<24); break;
3775
+       case ZIPO_MOV:  retv |= (ZIPV_MOV<<24); break;
3776
+       default: gas_assert(0);
3777
+       }
3778
+
3779
+       switch(opb) {
3780
+       case ZIPO_SUB:  retv |= (ZIPV_SUB<<8); break;
3781
+       case ZIPO_AND:  retv |= (ZIPV_AND<<8); break;
3782
+       case ZIPO_ADD:  retv |= (ZIPV_ADD<<8); break;
3783
+       case ZIPO_CMP:  retv |= (ZIPV_CMP<<8); break;
3784
+       case ZIPO_LW:   retv |= (ZIPV_LW <<8); break;
3785
+       case ZIPO_SW:   retv |= (ZIPV_SW <<8); break;
3786
+       case ZIPO_LDI:  retv |= (ZIPV_LDI<<8); break;
3787
+       case ZIPO_MOV:  retv |= (ZIPV_MOV<<8); break;
3788
+       default: gas_assert(0);
3789
+       }
3790
+
3791
+       // The new CIS has no condition codes
3792
+
3793
+       // Now for OpB, instruction A
3794
+       if (opa == ZIPO_LDI)
3795
+               retv |= (a & 0xff)<<16;
3796
+       else if (opa == ZIPO_MOV) {
3797
+               retv |= 1<<23;                  // Using a register? always4mov
3798
+               retv |= ((a>>14)&0x0f)<<19;     // OpB register
3799
+               retv |= (a & 0x7)<<16;          // Offset
3800
+       } else if(((opa == ZIPO_LW)||(opa == ZIPO_SW))
3801
+                       &&(((a>>14)&0x1f)==0x10 + ZIP_SP)) {
3802
+               // 7-bit immediate for loads or stores referencing the stack
3803
+               retv |= (a & 0x07f)<<16;
3804
+       } else if ((a>>18)&1) {
3805
+               // OpB ... with a register
3806
+               retv |= 1<<23;                  // Using a register?
3807
+               retv |= ((a>>14)&0x0f)<<19;     // OpB register
3808
+               retv |= (a&0x07)<<16;           // OpB constant
3809
+       } else {
3810
+               // OpB ... with constant offsets only
3811
+               retv |= (a&0x07f)<<16;
3812
+       }
3813
+
3814
+
3815
+       // Now for OpB, instruction B
3816
+       if (opb == ZIPO_LDI)
3817
+               retv |= (b & 0xff);
3818
+       else if (opb == ZIPO_MOV) {
3819
+               retv |= (1<<7);                 // Using a register? always4mov
3820
+               retv |= ((b>>14)&0x0f)<<3;      // OpB register
3821
+               retv |= (b & 0x7);              // Offset
3822
+       } else if(((opb == ZIPO_LW)||(opb == ZIPO_SW))
3823
+                       &&(((b>>14)&0x1f)==0x10 + ZIP_SP)) {
3824
+               retv |= (b & 0x07f);
3825
+       } else if ((b>>18)&1) {
3826
+               // OpB ... with a register
3827
+               retv |= 1<<7;                   // Using a register?
3828
+               retv |= ((b>>14)&0x0f)<<3;      // OpB register
3829
+               retv |= (b&0x07);               // OpB constant
3830
+       } else {
3831
+               // OpB ... with constant offsets only
3832
+               retv |= (b&0x07f);
3833
+       }
3834
+
3835
+       return retv;
3836
+}
3837
+
3838
+void
3839
+zip_check_label(symbolS *label ATTRIBUTE_UNUSED)
3840
+{
3841
+       // On any symbol, we need to make sure that we can jump to this
3842
+       // address, therefore we cannot merge the previous instruction with
3843
+       // another one that might follow.
3844
+       cis_mergable = FALSE;
3845
+       //
3846
+       // Likewise, our shadow virtual machine values may be ... unknown
3847
+       // upon any jump to this location.  Hence, we declare them unknown
3848
+       // here.
3849
+       zip_clear_machine(&zipm);
3850
+}
3851
+
3852
+// UNITS:
3853
+//     Offset  (target byte units)
3854
+//     Address (host byte units)
3855
+//     Sym     (target byte units)
3856
+//     Stretch (target byte units)
3857
+//
3858
+static void
3859
+zip_assemble_insn_words(fragS *fragP, segT seg, ZIPIS *insn, int relax_state,
3860
+               long stretch, MACHINEREGS *pzipm)
3861
+{
3862
+#ifdef ZIP_DEBUG
3863
+fprintf(stderr, "ZIP-ASSEMBLE-INSN-WORDS\n");
3864
+       zip_dump_insn(insn);
3865
+       if ((insn->i_rp)||(relax_state))
3866
+               zip_dump_sym(insn->i_rp->r_sym);
3867
+#endif
3868
+       unsigned long   symv = 0;
3869
+       int     sym_defined = 0, this_segment = 0, sym_known = 0;
3870
+       symbolS *sym = NULL;
3871
+       unsigned        immv = insn->i_imm;
3872
+
3873
+       if (insn->i_rp) {
3874
+               fragS   *sym_frag;
3875
+
3876
+               sym = insn->i_rp->r_sym;
3877
+               symv = ((sym)&&(S_IS_DEFINED(sym))) ? (S_GET_VALUE(sym)) : 0;
3878
+               sym_frag = symbol_get_frag(sym);
3879
+               this_segment = (S_GET_SEGMENT(sym) == seg);
3880
+
3881
+#ifdef ZIP_DEBUG
3882
+               fprintf(stderr, "SYMV(%s) = %08lx + %08lx -> %08lx\n",
3883
+                       S_GET_NAME(sym),
3884
+                       S_GET_VALUE(sym), fragP->fr_offset,
3885
+                       S_GET_VALUE(sym) + fragP->fr_offset);
3886
+#endif
3887
+               symv += fragP->fr_offset;
3888
+               // The immediate value has been included in the fragP->fr_offset
3889
+               // So, to keep us from applying it twice, we'll zero it here.
3890
+               immv = 0;
3891
+
3892
+#ifdef ZIP_DEBUG
3893
+               { int this_frag = (sym_frag == fragP);
3894
+               fprintf(stderr, "Determined symbol is %sin this frag, and %sin this segment\n", (this_frag)?"":"not ", (this_segment)?"":"not ");
3895
+               }
3896
+#endif
3897
+
3898
+               if ((stretch != 0)
3899
+                       &&( sym_frag->relax_marker != fragP->relax_marker)
3900
+                       &&(this_segment)) {
3901
+                       if ((stretch < 0)
3902
+                               ||(sym_frag->region == fragP->region))
3903
+                               symv += stretch;
3904
+                       else if (symv < fragP->fr_address)
3905
+                               symv = fragP->fr_next->fr_address;
3906
+               }
3907
+       }
3908
+
3909
+       // At this point, if the symbol is "defined" that only means that
3910
+       // the address is known--not that we can know it via GET_VALUE above
3911
+       // here.  There are a couple of possibilities: it could be a known
3912
+       // offset into a fragment, it could be a known offset into a segment,
3913
+       // it could be a known memory address, or it could be a known value.
3914
+       //
3915
+       // If the value is an offset into our current fragment, then we can
3916
+       // get at it via PC relative addressing.
3917
+       //
3918
+       // If the symbol is an offset into our current segment, often the
3919
+       // .text segment, we may also be able to get to it via PC relative
3920
+       // addressing.  However, we won't know until the fragment's are placed
3921
+       // together to create this segment.  This will be before writing
3922
+       // the file to disk.
3923
+       //
3924
+       // If the symbol is in the absolute segment, then we should try to
3925
+       // get to it via an absolute 32-bit offset reference--since we don't
3926
+       // know (and won't know until the final link) where we are currently
3927
+       // located within memory.
3928
+       //
3929
+       // The same is true of the undefined segment--we just don't know any
3930
+       // PC offsets to that segment.
3931
+       //
3932
+       // But if the address is to a GOT segment, we should be able to assume
3933
+       // it's offset from the beginning of that segment.
3934
+       //
3935
+       //
3936
+       if ((relax_state)&&(insn->i_rp))
3937
+               sym_defined = S_IS_DEFINED(insn->i_rp->r_sym);
3938
+
3939
+       /*
3940
+       sym_known = (sym_defined)&&
3941
+                       ((S_GET_SEGMENT(sym) == absolute_section)
3942
+                       ||(S_GET_SEGMENT(sym) == expr_section)
3943
+                       ||(this_frag)
3944
+                       ||((this_segment)&&(fragP->fr_address != 0))
3945
+                       );
3946
+       */
3947
+       sym_known = (sym_defined)&&(insn->i_rp->r_pcrel)&&(this_segment);
3948
+       if ((!sym_known)&&(sym_defined)&&(!S_FORCE_RELOC(sym, 0))) {
3949
+               if (this_segment)
3950
+                       sym_known = 1;
3951
+               else if (S_GET_SEGMENT(sym)==absolute_section)
3952
+                       sym_known = 1;
3953
+       }
3954
+#ifdef ZIP_DEBUG
3955
+       if (sym_known)
3956
+               fprintf(stderr, "%08lx@%08lx/%08lx - SYM(%s)-KNOWN %s%s%s%s%s\n",
3957
+                       (unsigned long)fragP->fr_literal,
3958
+                       fragP->fr_address,
3959
+                       (unsigned long)symv, S_GET_NAME(sym),
3960
+                       (S_GET_SEGMENT(sym) == absolute_section)?" abs":"",
3961
+                       (S_GET_SEGMENT(sym) == expr_section)?" expr":"",
3962
+                       (symbol_get_frag(sym)==fragP)?" this-frag ":"",
3963
+                       ((this_segment)&&(fragP->fr_address != 0))?" this-seg ":"",
3964
+                       insn->i_rp->r_pcrel?" (PC-REL)":" (ABS)");
3965
+       else if (insn->i_rp)
3966
+               fprintf(stderr, "%08lx@%08lx/%08lx - SYM(%s) -- not known (yet) %s%s%s%s%s%s\n",
3967
+                       (unsigned long)fragP->fr_literal, fragP->fr_address,
3968
+                       (unsigned long)symv, S_GET_NAME(sym),
3969
+                       (!sym_defined)?"-- not defined":"",
3970
+                       (S_GET_SEGMENT(sym) == absolute_section)?" abs":"",
3971
+                       (S_GET_SEGMENT(sym) == expr_section)?" expr":"",
3972
+                       (symbol_get_frag(sym)==fragP)?" this-frag ":"",
3973
+                       (this_segment)?" this-seg ":"",
3974
+                       ((this_segment)&&(fragP->fr_address != 0))?" this-off ":""
3975
+                       );
3976
+
3977
+       fprintf(stderr, "SYM-DEF %d,%d,%d,%d, IMM = %08x\n",
3978
+               sym_defined, sym_known,
3979
+               (insn->i_rp)&&(symbol_get_frag(insn->i_rp->r_sym)==fragP)?1:0,
3980
+               this_segment, insn->i_imm);
3981
+#endif
3982
+       switch(insn->i_op) {
3983
+       case ZIPO_LDI: // May or may not be conditional
3984
+               if ((sym_known)&&(this_segment)
3985 206 dgisselq
+                       &&(fits_within(15,immv+symv-fragP->fr_address-insn->i_rp->r_fr_offset-sizeof(uint32_t)))) {
3986 202 dgisselq
+                       // Turn this into a MOV x(PC),Rx
3987 206 dgisselq
+                       //
3988
+                       // Although moves can normally only handle 13 bits,
3989
+                       // when the immediate is an offset to the PC, the bottom
3990
+                       // two bits are always zero, and so the immediate
3991
+                       // gets an extra two free bits--hence the test for
3992
+                       // fitting into 15 bits above.
3993 202 dgisselq
+                       insn->i_breg = ZIP_PC;
3994
+                       insn->i_op = ZIPO_MOV;
3995
+                       insn->i_naux = 0;
3996
+                       zip_assemble_insn_words(fragP, seg, insn, relax_state,
3997
+                               stretch, pzipm);
3998
+                       // Tested--this works
3999
+                       return;
4000
+               }
4001
+
4002
+               // 0.111.x111.11
4003
+               insn->i_aux[0] = 0x7fc00000; // NOOP -- if never used.
4004
+               immv += symv;
4005 206 dgisselq
+               if ((!insn->i_rp)&&(insn->i_cnd == ZIPC_ALWAYS)
4006 202 dgisselq
+                               &&(fits_within(23, immv))) {
4007
+                       insn->i_naux = 0;
4008
+                       insn->i_code = LDIOP(immv,insn->i_areg);
4009
+               } else if (((!insn->i_rp)||(sym_known))
4010
+                               &&(fits_within(18, zip_brev(immv)))) {
4011
+                       // Can we do this with a BREV instruction using an
4012
+                       // immediate?  If so, we can then conditionally load
4013
+                       // the top 18 bist of any value ...
4014
+                       //
4015
+                       insn->i_naux = 0;
4016
+                       insn->i_code = IMMOP(ZIPO_BREV, insn->i_cnd,
4017
+                                       zip_brev(immv),
4018
+                                       insn->i_areg&0x0f);
4019
+                       if (insn->i_rp)
4020
+                               insn->i_rp->r_type = BFD_RELOC_NONE;
4021
+// 0000 1110 0000 0000 0000 0000 0100 0000
4022
+               } else if ((zip_param_use_machine)&&(pzipm)&&((!insn->i_rp)||(sym_known))
4023
+                       &&(pzipm->r[insn->i_areg].m_known)
4024
+                       &&(0==((immv^pzipm->r[insn->i_areg].m_value)
4025
+                                       & 0x0ffff0000))) {
4026
+                       // Replace LDI with LDILO
4027
+                       insn->i_naux = 0;
4028
+                       insn->i_code=IMMOP(ZIPO_LDILO, insn->i_cnd,
4029
+                                       (immv&0x0ffff), insn->i_areg);
4030
+
4031
+                       pzipm->r[insn->i_areg].m_value = immv;
4032
+                       if (ZIPC_ALWAYS == insn->i_cnd) {
4033
+                               // Henceforth, we only know the bottom 16bits
4034
+                               // of this register
4035
+                               pzipm->r[insn->i_areg].m_known = MACH_VUPPERKNOWN;
4036
+                       } else
4037
+                               pzipm->r[insn->i_areg].m_known = MACH_VKNOWN;
4038
+               } else {
4039
+                       //
4040
+                       // If the symbol isn't defined, then any immv value
4041
+                       // will work--we have to come back anyway.
4042
+                       //
4043
+                       int known_bypass = 0, i;
4044
+
4045
+                       if ((zip_param_use_machine)&&(pzipm)&&(
4046
+                                       ((!insn->i_rp)
4047
+                                               &&(!fits_within(4,immv)))
4048
+                                       ||((insn->i_rp)&&(sym_known)))) {
4049
+                               for(i=0; i<14; i++) {
4050
+                                       int offset = immv-pzipm->r[i].m_value;
4051
+                                       if ((pzipm->r[i].m_known==MACH_VKNOWN)
4052
+                                               &&(fits_within(13, offset))
4053
+                                               &&((insn->i_rp)
4054
+                                                       ||(!fits_within(4, immv)))
4055
+                                               ) {
4056
+                                               // Pick the closest value ... if
4057
+                                               // there's a choice
4058
+                                               if ((!known_bypass)
4059
+                                                       ||(abs(offset)<known_bypass))
4060
+                                                       continue;
4061
+                                               insn->i_naux = 0;
4062
+                                               insn->i_op = ZIPO_MOV;
4063
+                                               insn->i_breg = i;
4064
+                                               insn->i_imm = offset;
4065
+
4066
+                                               insn->i_code = SMPLMOV(
4067
+                                                       insn->i_cnd, offset,
4068
+                                                       i, insn->i_areg);
4069
+                                               known_bypass = abs(offset);
4070
+                                               if (known_bypass==0)
4071
+                                                       known_bypass = 1;
4072
+                                       }
4073
+                               } known_bypass = (known_bypass)?1:0;
4074
+                       } if (!known_bypass) {
4075
+                               // BREV Extension would modify this statement
4076
+                               insn->i_naux = 1;
4077
+                               insn->i_code = IMMOP(ZIPO_BREV, insn->i_cnd,
4078
+                                       zip_brev(immv)&0x01ffff, insn->i_areg);
4079
+                               insn->i_aux[0]=IMMOP(ZIPO_LDILO, insn->i_cnd,
4080
+                                       (immv&0x0ffff), insn->i_areg);
4081
+                               if (insn->i_rp)
4082
+                                       insn->i_rp->r_type = BFD_RELOC_ZIP_LDI;
4083
+                               else if ((zip_param_cis)&&(zip_can_merge(insn->i_code, insn->i_aux[0]))) {
4084
+                                       insn->i_code = zip_insn_merge(insn->i_code, insn->i_aux[0]);
4085
+                                       insn->i_naux = 0;
4086
+                               }
4087
+                       } else {
4088
+fprintf(stderr, "known-bypass\n");
4089
+                       }
4090
+               }
4091
+#ifdef ZIP_DEBUG
4092
+               fprintf(stderr, "LDI %04x:%04x,%d Instruction assembled into %08x : %08x\n",
4093
+                       (immv>>16)&0x0ffff,
4094
+                       immv & 0x0ffff, insn->i_areg,
4095
+                       insn->i_code, insn->i_aux[0]);
4096
+#endif
4097
+               break;
4098
+       case ZIPO_BRA: // Includes both conditional and unconditional branches
4099
+#ifdef ZIP_DEBUG
4100
+               fprintf(stderr, "ZIPO--BRA (ADDR = %08lx, OFFSET = %08lx)\n",
4101
+                               fragP->fr_address,
4102
+                               (insn->i_rp)?insn->i_rp->r_fr_offset:0);
4103
+#endif
4104
+               if (insn->i_rp)
4105
+                       immv += (int)(symv
4106
+                               - fragP->fr_address
4107
+                               - (insn->i_rp->r_fr_offset+sizeof(uint32_t)));
4108
+
4109
+#ifdef ZIP_DEBUG
4110
+               if (!fits_within(18,immv))
4111
+                       fprintf(stderr, "doesn't fit in 18 bits\n");
4112
+#endif
4113
+               if (zip_param_small) {
4114
+                       //
4115
+                       // We can fit (or so we are told), so short jump code
4116
+                       // to an unknown location ...
4117
+                       //
4118
+                       insn->i_naux = 0;
4119
+                       insn->i_aux[0] = NOOP_OPCODE;
4120
+                       insn->i_aux[1] = NOOP_OPCODE;
4121
+                       insn->i_code = IMMOP(ZIPO_ADD, insn->i_cnd,
4122
+                               immv, ZIP_PC); // Add value to PC
4123
+                       insn->i_rp->r_pcrel = TRUE;
4124
+                       // No relocation is required--we just did it
4125
+                       insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_PCREL;
4126
+                       // Tested--this works
4127
+               } else if ((!sym_known)||(!fits_within(18,immv))) {
4128
+                       insn->i_op = ZIPO_LJMP;
4129
+
4130
+                       zip_assemble_insn_words(fragP, seg, insn, relax_state, stretch, pzipm);
4131
+                       insn->i_op = ZIPO_BRA;
4132
+               } else {
4133
+                       //
4134
+                       // We can fit, so short jump code ...
4135
+                       //
4136
+                       insn->i_naux = 0;
4137
+                       insn->i_aux[0] = NOOP_OPCODE;
4138
+                       insn->i_aux[1] = NOOP_OPCODE;
4139
+                       insn->i_code = IMMOP(ZIPO_ADD, insn->i_cnd,
4140
+                               immv, ZIP_PC); // Add value to PC
4141
+                       insn->i_rp->r_pcrel = TRUE;
4142
+                       // No relocation is required--we just did it
4143
+                       insn->i_rp->r_type = BFD_RELOC_NONE;
4144
+               }
4145
+#ifdef ZIP_DEBUG
4146
+               fprintf(stderr, "BRA %08lx->%08x(%d,%d) assembled into(%d) %08x : %08x : %08x\n",
4147
+                       symv, immv, sym_defined, relax_state,
4148
+                       insn->i_naux, insn->i_code,
4149
+                       insn->i_aux[0], insn->i_aux[1]);
4150
+#endif
4151
+               break;
4152
+       case    ZIPO_LJMP:
4153
+               //
4154
+               // Long jump code
4155
+               //
4156
+               // I expect this to be true, since we should always
4157
+               // be branching (or jumping) to a location defined by a
4158
+               // symbol.
4159
+               if (insn->i_rp) {
4160
+                       insn->i_rp->r_pcrel = FALSE;
4161
+                       insn->i_rp->r_type = BFD_RELOC_ZIP_VALUE;
4162
+               } insn->i_breg = ZIP_RNONE;
4163
+#ifdef ZIP_DEBUG
4164
+               fprintf(stderr, "LJMP IMM = %08x = %d\n", immv, immv);
4165
+#endif
4166
+               if (insn->i_cnd == ZIPC_ALWAYS) {
4167
+                       insn->i_naux = 1;
4168
+                       insn->i_code=DBLREGOP(ZIPO_LW,ZIPC_ALWAYS,
4169
+                               0,ZIP_PC,ZIP_PC); // Load into PC register
4170
+                       insn->i_aux[0] = 0; // Value to load
4171
+               } else {
4172
+                       // A conditional long jump
4173
+                       insn->i_naux = 2;
4174
+                       insn->i_code=DBLREGOP(ZIPO_LW,insn->i_cnd,
4175
+                               1,ZIP_PC,ZIP_PC); // Conditional load to PC
4176
+                       insn->i_aux[0]=IMMOP(ZIPO_ADD,ZIPC_ALWAYS,
4177
+                               1,ZIP_PC); // Skip an instruction
4178
+                       insn->i_aux[1] = 0;
4179
+               } if (!insn->i_rp)
4180
+                       insn->i_aux[insn->i_naux-1] = immv;
4181
+               break;
4182
+       case ZIPO_MOV:
4183
+               //
4184
+               // We could go a little wild here:
4185
+               //      MOV val,Rx
4186
+               // Could be quietly compiled into
4187
+               //      LDI val,Rx      (if Rx is not a user register)
4188
+               // whereas
4189
+               //      MOV BIGVAL(Ry),Rx
4190
+               // could be quietly compiled into
4191
+               //      LDI BIGVAL,Rx
4192
+               //      ADD.Z Ry,Rx     (Note the contortions to avoid adjusting
4193
+               //      ADD.NZ Ry,Rx    ... the flag bits)
4194
+               // This would give us access to full 32-bit offsets ...
4195
+               // as long as neither Rx nor Ry was a user register.  On the
4196
+               // other hand, if we knew the flag bits would be set between
4197
+               // now and the next conditional instruction, we could do a
4198
+               //      LDI BIGVAL,Rx
4199
+               //      ADD Ry,Rx
4200
+               // and be okay with it.
4201
+               //
4202
+               // For now we just handle our normal 13 bit signed immediate
4203
+               //      offsets.
4204
+               //
4205
+               if (insn->i_rp) {
4206
+                       // MOV label(Rb),Ra
4207
+                       insn->i_rp->r_pcrel = (insn->i_breg == ZIP_PC);
4208
+                       immv += symv;
4209
+                       if (insn->i_breg == ZIP_PC) {
4210
+                               immv +=(int)(-fragP->fr_address
4211
+                                               -insn->i_rp->r_fr_offset-sizeof(uint32_t));
4212
+                               immv >>= 2;
4213
+                               if ((sym_known)&&(this_segment)) {
4214
+                                       // Tested--this works
4215
+                                       insn->i_rp->r_type = BFD_RELOC_NONE;
4216
+                               } else {
4217
+#ifdef ZIP_DEBUG
4218
+                                       fprintf(stderr, "ZIP_MOV_PCREL relocation needed for %s, pcrel = %d\n", S_GET_NAME(sym), insn->i_rp->r_pcrel);
4219
+#endif
4220
+                                       insn->i_rp->r_type = BFD_RELOC_ZIP_MOV_PCREL;
4221
+                               }
4222
+
4223
+
4224
+//                     } else if((zip_param_got)&&(insn->i_breg == ZIP_GBL)) {
4225
+//                             immv = symv;
4226
+//                             insn->i_rp->r_type = BFD_RELOC_ZIP_MOV_GOTREL;
4227
+//                             as_bad("MOV x(GOT),Ry not yet implemented");
4228
+                       } else {
4229
+                               // Do we really want to assume this is an
4230
+                               // address?
4231
+                               insn->i_rp->r_type = BFD_RELOC_ZIP_MOV_OFFSET;
4232
+                       }
4233
+               } else if ((zip_param_use_machine)&&(pzipm)
4234
+                               &&(insn->i_breg<ZIP_CC)&&(insn->i_areg<ZIP_CC)
4235
+                               &&(ZIPC_ALWAYS == insn->i_cnd)
4236
+                               &&(pzipm->r[insn->i_breg].m_known==MACH_VKNOWN)
4237
+                               &&(fits_within(4,pzipm->r[insn->i_breg].m_value
4238
+                                       +immv))) {
4239
+                       // MOV Rb,Ra
4240
+                       // turn this into an LDI instruction, rather than a
4241
+                       // move instruction
4242
+                       insn->i_op = ZIPO_LDI;
4243
+                       insn->i_imm += pzipm->r[insn->i_breg].m_value;
4244
+                       insn->i_breg = ZIP_RNONE;
4245
+
4246
+                       insn->i_code = LDIOP(insn->i_imm, insn->i_areg);
4247
+                       insn->i_naux = 0;
4248
+               }
4249
+               /*
4250
+               // Handle offsets greater than 13 bits --- up to 32 bits
4251
+               // Only works if we have no symbol in question, and when the
4252
+               // target isn't the PC register (or CC for that matter).
4253
+               else if ((!fits_within(13,insn->i_imm))
4254
+                               &&(insn->i_areg < ZIP_CC)
4255
+                               &&(insn->i_breg < ZIP_CC)) {
4256
+                       // Alternate instruction sequence:
4257
+                       //      but .... these make conditional insns from
4258
+                       //              unconditional!!
4259
+                       //      MOV.always A,Rx -> LDI A,Rx
4260
+                       //      MOV.always A(Ry),Rx -> LDI A,Rx, ADD Ry,Rx
4261
+                       // this works for conditional moves, since ADD.C
4262
+                       // doesn't set conditions
4263
+                       //      MOV.C A(Ry),Rx -> LDI.C A,Rx, ADD.C Ry,Rx
4264
+
4265
+                       return;
4266
+               }
4267
+               */
4268
+
4269
+               if (insn->i_op == ZIPO_MOV) { // If we haven't changed insns,
4270
+                       gas_assert(fits_within(13, insn->i_imm));
4271
+                       insn->i_code = SMPLMOV(insn->i_cnd, immv, insn->i_breg,
4272
+                                       insn->i_areg);
4273
+                       //
4274
+                       // Now for the extra two register bits only present
4275
+                       // in move instructions
4276
+                       //
4277
+                       insn->i_code |= (insn->i_areg&0x10)?0x40000:0;
4278
+                       insn->i_code |= (insn->i_breg&0x10)?0x02000:0;
4279
+               }
4280
+#ifdef ZIP_DEBUG
4281
+               fprintf(stderr, "MOV Instruction assembled into %08x\n", insn->i_code);
4282
+#endif
4283
+               break;
4284
+       case ZIPO_NEG:
4285
+               insn->i_naux = 1;
4286
+               if (insn->i_rp)
4287
+                       as_bad("NEG cannot handle symbols");
4288
+               gas_assert(fits_within(13, -1+insn->i_imm));
4289
+               insn->i_code = SMPLMOV(insn->i_cnd,
4290
+                       (-1+immv), insn->i_breg, insn->i_areg);
4291
+               insn->i_code &= 0xfffbdfff;
4292
+               insn->i_aux[0] = IMMOP(ZIPO_XOR, insn->i_cnd, -1,
4293
+                       insn->i_areg);
4294
+               // printf("NEG Instruction assembled into %08x:%08x\n",
4295
+                       // insn->i_code, insn->i_aux[0]);
4296
+               break;
4297
+       case ZIPO_BREAK: case ZIPO_LOCK: case ZIPO_SIM: case ZIPO_NOOP:
4298
+               if (insn->i_cnd != ZIPC_ALWAYS)
4299
+                       as_bad("NOOP/BREAK/LOCK/SIM instructions cannot handle conditions\n");
4300
+               insn->i_code = NOOPGROUP(insn->i_op, insn->i_imm);
4301
+               insn->i_naux = 0;
4302
+               break;
4303
+       case    ZIPO_SDUMP: case ZIPO_NDUMP: case ZIPO_SEXIT: case ZIPO_NEXIT:
4304
+       case    ZIPO_SOUT:  case ZIPO_NOUT:
4305
+               // These instructions *should*ve been turned into NOOP and SIM
4306
+               // instructions by now.  Getting here with them is therefore
4307
+               // an error.
4308
+               gas_assert(0);
4309
+       case ZIPO_SEXTB: {
4310
+               insn->i_naux = 1;
4311
+               insn->i_code   = IMMOP(ZIPO_LSL, insn->i_cnd, 24, insn->i_areg);
4312
+               insn->i_aux[0] = IMMOP(ZIPO_ASR, insn->i_cnd, 24, insn->i_areg);
4313
+               } break;
4314
+       case ZIPO_SEXTH: {
4315
+               insn->i_naux = 1;
4316
+               insn->i_code   = IMMOP(ZIPO_LSL, insn->i_cnd, 16, insn->i_areg);
4317
+               insn->i_aux[0] = IMMOP(ZIPO_ASR, insn->i_cnd, 16, insn->i_areg);
4318
+               } break;
4319
+       case ZIPO_JSR:
4320
+               if ((zip_param_cis)&&(insn->i_cnd == ZIPC_ALWAYS)
4321
+                               &&(insn->i_rp)) {
4322
+                       insn->i_op = ZIPO_LJSR;
4323
+                       zip_assemble_insn_words(fragP, seg, insn, relax_state, stretch, pzipm);
4324
+                       insn->i_op = ZIPO_JSR;
4325
+               } else if ((zip_param_cis)&&(insn->i_cnd == ZIPC_ALWAYS)
4326
+                               &&(insn->i_breg != ZIP_RNONE)
4327
+                               &&(insn->i_imm == 0)) {
4328
+                       // JSR (Register)
4329
+                       insn->i_naux = 0;
4330
+                       insn->i_code = 0x80008000
4331
+                               | (ZIPV_MOV<<24)
4332
+                               | 0x00f90000    // MOV OpB = PC+1
4333
+                               | 0x0f880       // MOV into PC
4334
+                               | ((insn->i_breg&0x0f)<<3)
4335
+                               | (ZIPV_MOV << 8); // The LW instruction
4336
+
4337
+                       gas_assert(!insn->i_rp);
4338
+               } else if ((!insn->i_rp)&&(insn->i_breg != ZIP_RNONE)) {
4339
+                       gas_assert(fits_within(13,immv));
4340
+                       // JSR offset+register, implemented as two moves
4341
+                       insn->i_naux = 1;
4342
+                       insn->i_code = SMPLMOV(insn->i_cnd, 1, ZIP_PC, ZIP_LR);
4343
+                       insn->i_aux[0] = SMPLMOV(insn->i_cnd, immv, insn->i_breg, ZIP_PC);
4344
+                       insn->i_aux[1] = NOOP_OPCODE;
4345
+               } else {
4346
+                       if (insn->i_rp)
4347
+                               immv += (int)(symv
4348
+                                       - fragP->fr_address
4349
+                                       - (insn->i_rp->r_fr_offset+sizeof(uint32_t)));
4350
+                       if ((zip_param_small)||((sym_known)&&(fits_within(18,immv-4)))) {
4351
+                               // MOV.C 1(PC),R0
4352
+                               // BRA.C _somewhere_
4353
+                               insn->i_naux = 1;
4354
+                               insn->i_code = SMPLMOV(insn->i_cnd, 1, ZIP_PC,
4355
+                                       ZIP_LR);
4356
+                               // Bias the branch by -4, since we're one word
4357
+                               // into this instruction
4358
+                               insn->i_aux[0] = IMMOP(ZIPO_ADD, insn->i_cnd,
4359
+                                       immv-4, ZIP_PC);
4360
+                               insn->i_aux[1] = NOOP_OPCODE;
4361
+                               insn->i_rp->r_pcrel = TRUE;
4362
+                               insn->i_rp->r_type = BFD_RELOC_NONE;
4363
+                       } else {
4364
+                               // If all else fails, call for a long JSR
4365
+                               insn->i_op = ZIPO_LJSR;
4366
+                               zip_assemble_insn_words(fragP, seg, insn,
4367
+                                       relax_state, stretch, pzipm);
4368
+                               insn->i_op = ZIPO_JSR;
4369
+                       }
4370
+               } break;
4371
+       case ZIPO_LJSR:
4372
+               if (insn->i_rp)
4373
+                       immv += (int)(symv
4374
+                               - fragP->fr_address
4375
+                               - (insn->i_rp->r_fr_offset+sizeof(uint32_t)));
4376
+               if (insn->i_rp) {
4377
+                       insn->i_rp->r_pcrel = FALSE;
4378
+                       insn->i_rp->r_type = BFD_RELOC_ZIP_VALUE;
4379
+               } insn->i_breg = ZIP_RNONE;
4380
+               if (insn->i_cnd == ZIPC_ALWAYS) {
4381
+                       if (zip_param_cis) {
4382
+                               insn->i_naux = 1;
4383
+                               insn->i_code = 0x80008000
4384
+                                       | (ZIPV_MOV<<24)
4385
+                                       | 0x00fa0000    // MOV OpB = PC+2
4386
+                                       | 0x0f8f8       // (LW) into PC
4387
+                                       | (ZIPV_LW << 8); // The LW instruction
4388
+                               insn->i_aux[0] = 0; // To be filled in with address value
4389
+                       } else { // If unconditional
4390
+                               // MOV 1(PC),R0
4391
+                               // LW (PC),PC
4392
+                               // _somewhere_
4393
+                               insn->i_naux = 2;
4394
+                               insn->i_code = SMPLMOV(insn->i_cnd, 2, ZIP_PC,
4395
+                                       ZIP_LR);
4396
+                               insn->i_aux[0] = DBLREGOP(ZIPO_LW,ZIPC_ALWAYS,
4397
+                                       0,ZIP_PC,ZIP_PC); // Load into PC register
4398
+                               insn->i_aux[1] = 0;
4399
+                       }
4400
+               } else {
4401
+                       // If conditional, naux = 3
4402
+                       // BRA.!cnd (for whatever condition) +3
4403
+                       // MOV 4(PC),R0
4404
+                       // LW (PC),PC
4405
+                       // address
4406
+                       insn->i_naux = 3;
4407
+                       insn->i_aux[2] = 0;
4408
+                       if (insn->i_cnd != ZIPC_V) {
4409
+                               ZIP_CONDITION cnd =
4410
+                                       zip_negate_condition(insn->i_cnd);
4411
+                               insn->i_code = IMMOP(ZIPO_ADD, cnd, 12, ZIP_PC);
4412
+                               insn->i_aux[0] = SMPLMOV(ZIPC_ALWAYS, 2, ZIP_PC,
4413
+                                       ZIP_LR);
4414
+                               insn->i_aux[1] = DBLREGOP(ZIPO_LW, ZIPC_ALWAYS,
4415
+                                       0,ZIP_PC,ZIP_PC); // Load into PC register
4416
+                       } else {
4417
+                               insn->i_code = SMPLMOV(ZIPC_V, 3, ZIP_PC,
4418
+                                       ZIP_LR);
4419
+                               insn->i_aux[0] = DBLREGOP(ZIPO_LW, ZIPC_V,
4420
+                                       0,ZIP_PC,ZIP_PC); // Load into PC register
4421
+                               insn->i_aux[1] = IMMOP(ZIPO_ADD, ZIPC_ALWAYS, 4, ZIP_PC);
4422
+                       }
4423
+               } if (!insn->i_rp)
4424
+                       insn->i_aux[insn->i_naux-1] = immv;
4425
+               break;
4426
+       default:
4427
+               if (insn->i_rp) {
4428
+                       insn->i_rp->r_pcrel = FALSE;
4429
+                       immv += symv;
4430
+                       if (insn->i_breg == ZIP_PC) {
4431
+                               immv+=(int)(-fragP->fr_address
4432
+                                               -insn->i_rp->r_fr_offset-sizeof(uint32_t));
4433
+                               insn->i_rp->r_pcrel= TRUE;
4434
+                               insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_PCREL;
4435
+                               if ((sym_known)&&(this_segment))
4436
+                                       insn->i_rp->r_type = BFD_RELOC_NONE;
4437
+//                     } else if((zip_param_got)&&(insn->i_breg == ZIP_GBL)) {
4438
+//                             as_bad("<OP> x(GOT),Ry not yet implemented");
4439
+//                             immv += symv;
4440
+//                             insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_GOTREL;
4441
+                       } else {
4442
+                               // Do we really want to assume this is an
4443
+                               // address?
4444
+                               immv += symv;
4445
+                               insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_OFFSET;
4446
+                       }
4447
+               } if (insn->i_breg != ZIP_RNONE) {
4448
+                       if (insn->i_breg == ZIP_PC)
4449
+                               immv >>= 2;
4450
+                       if (!fits_within(14, insn->i_imm)) {
4451
+                               fprintf(stderr, "ERR: (%d) 0x%08x does not fit within 18 bits!\n", insn->i_imm, insn->i_imm);
4452
+                               gas_assert(fits_within(14, insn->i_imm));
4453
+                       }
4454
+                       insn->i_code = DBLREGOP(insn->i_op, insn->i_cnd,
4455
+                               immv, insn->i_breg, insn->i_areg);
4456
+                       if (insn->i_rp) {
4457
+                               if (insn->i_breg == ZIP_PC) {
4458
+                                       insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_PCREL;
4459
+                                       insn->i_rp->r_pcrel = TRUE;
4460
+//                             } else if((zip_param_got)&&(insn->i_breg == ZIP_GBL)) {
4461
+//                                     insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_GOTREL;
4462
+                               } else
4463
+                                       insn->i_rp->r_type = BFD_RELOC_ZIP_OPB_OFFSET;
4464
+                       }
4465
+               } else {
4466
+                       if (!fits_within(18, insn->i_imm)) {
4467
+                               fprintf(stderr, "ERR: (%d) 0x%08x does not fit within 18 bits!\n", insn->i_imm, insn->i_imm);
4468
+                               gas_assert(fits_within(18, insn->i_imm));
4469
+                       }
4470
+                       insn->i_code = IMMOP(insn->i_op, insn->i_cnd,
4471
+                               immv, insn->i_areg);
4472
+                       if (insn->i_rp)
4473
+                               insn->i_rp->r_type  = BFD_RELOC_ZIP_OPB_IMM;
4474
+               }
4475
+#ifdef ZIP_DEBUG
4476
+               fprintf(stderr, "Instruction assembled into %08x%s\n", insn->i_code,
4477
+                       (insn->i_rp)?" w/ Symbol":"");
4478
+#endif
4479
+               break;
4480
+       }
4481
+}
4482
+
4483
+void
4484
+md_assemble(char *line) {
4485
+       const char *linep;
4486
+       char    *p;
4487
+
4488
+       linep = (char *)zip_skip_white_spaces(line);
4489
+       if ((strncasecmp(linep, "nstr", 4)==0)
4490
+               ||(strncasecmp(linep, "sstr", 4)==0)) {
4491
+               uint32_t        base;
4492
+               const char      *sbeg;
4493
+
4494
+               if ((linep[0] =='n')||(linep[0] == 'N'))
4495
+                       base = 0x0400 + NOOP_OPCODE;
4496
+               else
4497
+                       base = 0x0400 + SIM_OPCODE;
4498
+
4499
+               sbeg = strchr(line, '\"');
4500
+               if (!sbeg)
4501
+                       as_bad("String instruction with no quotes found");
4502
+               sbeg++;
4503
+               while(*sbeg != '\"') {
4504
+                       unsigned v = *sbeg++;
4505
+                       if (v == '\\') {
4506
+                               switch(*sbeg++) {
4507
+                               case 'a':       v = '\a'; break;
4508
+                               case 'b':       v = '\b'; break;
4509
+                               case 'f':       v = '\f'; break;
4510
+                               case 'n':       v = '\n'; break;
4511
+                               case 'r':       v = '\r'; break;
4512
+                               case 't':       v = '\t'; break;
4513
+                               case '\\':      v = '\\'; break;
4514
+                               case '\"':      v = '\"'; break;
4515
+                               case '\'':      v = '\''; break;
4516
+                               default: sbeg--;
4517
+                               }
4518
+                       }
4519
+                       p = frag_more(sizeof(uint32_t));
4520
+                       md_number_to_chars(p,base+(v&0x0ff),sizeof(uint32_t));
4521
+               }
4522
+
4523
+               return;
4524
+       }
4525
+
4526
+
4527
+       // Decode an instruction from op_str
4528
+       //      Determine the opcode
4529
+       //              any conditions
4530
+       //              the result register
4531
+       //              any immediate
4532
+       //              any "B" register
4533
+       ZIPIS   insnv, *insn = &insnv;
4534
+       const char *error = zip_parse(line, insn);
4535
+
4536
+#ifdef ZIP_DEBUG
4537
+       fprintf(stderr, "ZIP-ASSEMBLE %s\n", line);
4538
+#endif
4539
+
4540
+       if (error) {
4541
+               as_bad("%s \'%s\'", error, line);
4542
+               return;
4543
+       }
4544
+
4545
+       zip_assemble_insn_words(frag_now, now_seg, insn, 0, 0, &zipm);
4546
+       if (zip_param_use_machine)
4547
+               zip_advance_machine(&zipm, insn);
4548
+#ifdef ZIP_DEBUG
4549
+       zip_debug_machine(&zipm);
4550
+#endif
4551
+
4552
+       // Then, if the instruction is valid we ...
4553
+       //      for branches ...
4554
+       //        symbolS *symp = reloc->reloc_expression.X_add_symbol;
4555
+       //        offsetT offset = reloc->reloc_expression.X_add_number;
4556
+       //        char *f;
4557
+       //        f = frag_var(?, 4, 4, BRANCH_SUBTYPE, symp, offset, NULL);
4558
+       //        md_number_to_chars(f, insn->insn_code, 4); // ???
4559
+       //
4560
+       //
4561
+       if ((!insn->i_rp)&&(cis_mergable)&&(insn->i_naux == 0)
4562
+                       &&(frag_now_fix_octets()>=4)) {
4563
+               // ZIPI lcode = md_number_from_chars(p, 4);
4564
+               unsigned int    last_iword;
4565
+               char    *buf;
4566
+
4567
+               buf = &frag_now->fr_literal[frag_now_fix_octets() - 4];
4568
+               last_iword = (buf[3]&0x0ff)|((buf[2]&0x0ff)<<8)
4569
+                       |((buf[1]&0x0ff)<<16)|((buf[0]&0x0ff)<<24);
4570
+               if ((buf >= frag_now->fr_literal)
4571
+                               &&(zip_can_merge(last_iword,insn->i_code))) {
4572
+                       p = buf;
4573
+                       insn->i_code =zip_insn_merge(last_iword, insn->i_code);
4574
+                       md_number_to_chars(p, insn->i_code, sizeof(uint32_t));
4575
+               } else {
4576
+                       p = frag_more(sizeof(uint32_t)*(1+insn->i_naux));
4577
+                       md_number_to_chars(p, insn->i_code, sizeof(uint32_t));
4578
+               }
4579
+       } else {
4580
+               int     i;
4581
+               ZIPRELOC        *rp = insn->i_rp;
4582
+
4583
+               if ((insn->i_naux == 0)||(NULL == insn->i_rp)) {
4584
+                       // If we have no need of any symbols, we come here.
4585
+                       // If we have no need of any extra 4-byte instructions,
4586
+                       // we come here.
4587
+                       p = frag_more(sizeof(uint32_t)*(1+insn->i_naux));
4588
+
4589
+                       if (insn->i_rp) {
4590
+                               // Generate a fixup for when we finally
4591
+                               // know where this symbol links to
4592
+                               insn->i_rp->r_fr_offset =
4593
+                                       (p - frag_now->fr_literal);
4594
+                               insn->i_rp->r_fix = fix_new(frag_now,
4595
+                                       insn->i_rp->r_fr_offset, // where w/in frag?
4596
+                                       4,              // 1,2, or 4 usually ... ??
4597
+                                       insn->i_rp->r_sym, // Add symbol,
4598
+                                       insn->i_imm, // Fixed/known offset to the symbol
4599
+                                       insn->i_rp->r_pcrel, // T if PC-Relative reloc
4600
+                                       insn->i_rp->r_type); // Reloc type
4601
+                               insn->i_rp = NULL;
4602
+                       }
4603
+               } else {
4604
+                       // First, grow our fragment so we know we have the
4605
+                       // size we'll need.
4606
+                       frag_grow(sizeof(uint32_t)*(1+insn->i_naux));
4607
+
4608
+                       // Then p, the place where we'd get more from, is
4609
+                       // where our instruction will be installed.  We know
4610
+                       // there's room for it there now.
4611
+                       p = frag_more(0);
4612
+                       // Record where in the frag our relaxable instruction
4613
+                       // will be installed
4614
+                       insn->i_rp->r_fr_offset = ( p - frag_now->fr_literal );
4615
+                       // Now tell the assembler about what we've done.
4616
+                       // This'll close off the frag as well, so this is the
4617
+                       // last we'll see of this frag--even though frag_now
4618
+                       // may yet point to it (or not) for a while.
4619
+                       frag_var(rs_machine_dependent, // Relaxation type
4620
+                               sizeof(uint32_t)*(1+insn->i_naux),
4621
+                               sizeof(uint32_t)*(1+insn->i_naux),
4622
+                               rs_machine_dependent,   // Subtype
4623
+                               insn->i_rp->r_sym,      // Symbol
4624
+                               insn->i_imm,    // Offset (to be added to symbol)
4625
+                               (char *)zip_copy_insn(insn));   // Opcode
4626
+
4627
+               }
4628
+               md_number_to_chars(p, insn->i_code, sizeof(uint32_t));
4629
+               for(i=0; i< insn->i_naux; i++)
4630
+                       md_number_to_chars(&p[sizeof(uint32_t)*(1+i)], insn->i_aux[i], sizeof(uint32_t));
4631
+
4632
+               if (rp) {
4633
+                       cis_mergable = FALSE;
4634
+               } else {
4635
+                       cis_mergable = (zip_param_cis)&&(insn->i_naux == 0);
4636
+               }
4637
+       }
4638
+#ifdef ZIP_DEBUG
4639
+       zip_dump_insn(insn);
4640
+#endif
4641
+}
4642
+
4643
+/* Turn a string in input_line_pointer into a floating point constant
4644
+ * of type type, and store the appropriate bytes in *LITP.  The number of
4645
+ * LIITTLENUMS emitted is stored in *SIZEP.  An error message is returned, or
4646
+ * NULL on OK.
4647
+ */
4648
+const char     *
4649
+md_atof(int type, char *litP, int *sizeP) {
4650
+       int     prec;
4651
+       LITTLENUM_TYPE  words[4];
4652
+       char    *t;
4653
+       int     i;
4654
+
4655
+       switch(type) {
4656
+       case 'f':
4657
+               prec = 2; break;
4658
+       case 'd':
4659
+               prec = 4; break;
4660
+       default:
4661
+               *sizeP = 0;
4662
+               return _("Unsupported floating point format");
4663
+       }
4664
+
4665
+       t = atof_ieee(input_line_pointer, type, words);
4666
+       if (t)
4667
+               input_line_pointer = t;
4668
+
4669
+       *sizeP = prec * 2;
4670
+
4671
+       for(i=prec-1; i>= 0; i--) {
4672
+               md_number_to_chars(litP, (valueT)words[i], 2);
4673
+               litP += 2;
4674
+       }
4675
+
4676
+       return NULL;
4677
+}
4678
+#define        AS_BAD_FIX(FXP,STR) as_bad_where(FXP->fx_file,FXP->fx_line,_(STR))
4679
+
4680
+/* Apply a fixup to the object file
4681
+ *
4682
+ * This function will only be called once all of the details of the fixup are
4683
+ * known, before the object file heads to the linker (if at all).
4684
+ */
4685
+void
4686
+md_apply_fix(fixS *fixP, valueT *val, segT seg ATTRIBUTE_UNUSED)
4687
+{
4688
+       unsigned int    iword, mask, final_fix;
4689
+
4690
+       final_fix = (fixP->fx_addsy == NULL) ? TRUE : FALSE;
4691
+
4692
+       bfd_byte *buf = (bfd_byte *)&fixP->fx_frag->fr_literal[fixP->fx_where];
4693
+       iword = (buf[3]&0x0ff)|((buf[2]&0x0ff)<<8)
4694
+                       |((buf[1]&0x0ff)<<16)|((buf[0]&0x0ff)<<24);
4695
+       (*val) &= 0x0ffffffff;
4696
+
4697
+#ifdef ZIP_DEBUG
4698
+       fprintf(stderr, "MD-APPLY-FIX: FRAG=%08x@%08x+%08x(%d), IWORD = %08x Val=%08x (RTYP=%d->%s)%s%s, ADDEND=%08lx\n",
4699
+               ((unsigned)((unsigned long)fixP->fx_frag->fr_literal)),
4700
+               ((unsigned)((unsigned long)fixP->fx_frag->fr_address)),
4701
+               ((unsigned)((unsigned long)fixP->fx_where)),
4702
+               ((unsigned)((unsigned long)fixP->fx_size)),
4703
+               iword, (unsigned)(*val), fixP->fx_r_type,
4704
+               bfd_get_reloc_code_name(fixP->fx_r_type),
4705
+               (fixP->fx_pcrel)?" PC-Rel ":" std ",
4706
+               (fixP->fx_addsy)?"":"(Null Sym)",
4707
+               fixP->fx_offset);
4708
+#endif
4709
+       switch(fixP->fx_r_type) {
4710
+       case BFD_RELOC_NONE:
4711
+               fixP->fx_done = final_fix;
4712
+               break;
4713
+       case BFD_RELOC_ZIP_OPB_IMM:
4714
+               // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_OPB_IMM\n");
4715
+               mask = 0x3ffff; iword = (iword &(~mask))|((*val)&mask);
4716
+               (*val) &= 0x03ffff;
4717
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4718
+               fixP->fx_done = final_fix;
4719
+               break;
4720
+       case BFD_RELOC_ZIP_OPB_PCREL:
4721
+               {
4722
+               uint32_t        oval;
4723
+               oval = *val;
4724
+               oval = (*val>>2);
4725
+               oval &= 0x03fff;
4726
+               mask = 0x3fff; iword = (iword &(~mask))|((oval)&mask);
4727
+               *val = oval;
4728
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4729
+               fixP->fx_done = final_fix;
4730
+               } break;
4731
+       case BFD_RELOC_ZIP_OPB_OFFSET:
4732
+//     case BFD_RELOC_ZIP_OPB_GOTREL:
4733
+       case BFD_RELOC_14:
4734
+               // if (fixP->fx_r_type == BFD_RELOC_ZIP_OPB_OFFSET)
4735
+                       // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_OPB_OFFSET\n");
4736
+               // else if (fixP->fx_r_type == BFD_RELOC_ZIP_OPB_PCREL)
4737
+                       // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_OPB_PCREL\n");
4738
+               // else
4739
+                       // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_OPB_GOTREL\n");
4740
+               mask = 0x3fff; iword = (iword &(~mask))|((*val)&mask);
4741
+               (*val) &= 0x03fff;
4742
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4743
+               fixP->fx_done = final_fix;
4744
+               break;
4745
+       case BFD_RELOC_ZIP_MOV_PCREL:
4746
+               (*val) &= 0x07fff; (*val)>>=2;
4747
+               mask = 0x1fff; iword = (iword &(~mask))|((*val)&mask);
4748
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4749
+               fixP->fx_done = final_fix;
4750
+               break;
4751
+       case BFD_RELOC_ZIP_MOV_OFFSET:
4752
+       // case BFD_RELOC_ZIP_MOV_GOTREL:
4753
+#ifdef ZIP_DEBUG
4754
+               if (fixP->fx_r_type == BFD_RELOC_ZIP_MOV_OFFSET)
4755
+                       fprintf(stderr, "\tMD-APPLY-FIX: BFD_RELOC_ZIP_MOV_OFFSET\n");
4756
+               //else if (fixP->fx_r_type == BFD_RELOC_ZIP_MOV_PCREL)
4757
+               //      fprintf(stderr, "\tMD-APPLY-FIX: BFD_RELOC_ZIP_MOV_PCREL\n");
4758
+               // else
4759
+               //      fprintf(stderr, "\tMD-APPLY-FIX: BFD_RELOC_ZIP_MOV_GOTREL\n");
4760
+               fprintf(stderr, "Final-fix = %d\n", final_fix);
4761
+#endif
4762
+               mask = 0x1fff; iword = (iword &(~mask))|((*val)&mask);
4763
+               (*val) &= 0x01fff;
4764
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4765
+               fixP->fx_done = final_fix;
4766
+               break;
4767
+       case BFD_RELOC_ZIP_LDI:
4768
+               // If the value were known at build time, we wouldn't need
4769
+               // to drop the lower two address bits.  However, since we're
4770
+               // doing a fixup, we know val must reference an address,
4771
+               // hence we shift down two bits.
4772
+               // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_LDI\n");
4773
+               iword |= (*val)&0x03fffff;
4774
+               (*val) &= 0x03fffff;
4775
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4776
+               fixP->fx_done = final_fix;
4777
+               break;
4778
+       case BFD_RELOC_ZIP_LLO:
4779
+               // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_LLO\n");
4780
+               iword |= (*val)&0x0ffff;
4781
+               (*val) &= 0x0ffff;
4782
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4783
+               fixP->fx_done = final_fix;
4784
+               break;
4785
+       case BFD_RELOC_ZIP_BREV:
4786
+               // (*val) &= 0x0fffe0000;
4787
+               iword &= (~0x1ffff);
4788
+               iword |= zip_brev(*val)&0x01ffff;
4789
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4790
+               fixP->fx_done = final_fix;
4791
+               break;
4792
+#ifdef USE_R_ZIP_LHI
4793
+       case BFD_RELOC_ZIP_LHI:
4794
+               // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_LHI\n");
4795
+               iword |= ((*val)>>16)&0x0ffff;
4796
+               (*val) &= 0x0ffff0000;
4797
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4798
+               fixP->fx_done = final_fix;
4799
+               break;
4800
+#endif
4801
+       case BFD_RELOC_32:
4802
+       case BFD_RELOC_ZIP_VALUE:
4803
+               // printf("\tMD-APPLY-FIX: BFD_RELOC_ZIP_VALUE/32\n");
4804
+               iword = (*val);
4805
+               (*val) &= 0x0ffffffff;
4806
+               md_number_to_chars((char *)buf, iword, sizeof(uint32_t));
4807
+               fixP->fx_done = final_fix;
4808
+               break;
4809
+       case BFD_RELOC_16:
4810
+               iword = (*val)&0x0ffff;
4811
+               (*val) &= 0x0ffff;
4812
+               md_number_to_chars((char *)buf, iword, sizeof(uint16_t));
4813
+               fixP->fx_done = final_fix;
4814
+               break;
4815
+       case BFD_RELOC_8:
4816
+               iword = buf[0] & 0x0ff;
4817
+               iword |= (*val)&0x0ff; (*val) &= 0x0ff;
4818
+               md_number_to_chars((char *)buf, iword, sizeof(uint8_t));
4819
+               fixP->fx_done = final_fix;
4820
+               break;
4821
+       default:
4822
+               fprintf(stderr, "RELOC #\%d not supported\n", fixP->fx_r_type);
4823
+               // abort();
4824
+               break;
4825
+       }
4826
+}
4827
+
4828
+/* Generate a machine-dependent relocation. */
4829
+arelent *
4830
+tc_gen_reloc(asection *section ATTRIBUTE_UNUSED, fixS *fixP)
4831
+{
4832
+#ifdef ZIP_DEBUG
4833
+       fprintf(stderr, "Call to TC-GEN-RELOC(%s,FIX,%s,+%ld);\n", segment_name(section),
4834
+                       S_GET_NAME(fixP->fx_addsy),fixP->fx_offset);
4835
+#endif
4836
+
4837
+       arelent *relP;
4838
+
4839
+       relP = xmalloc(sizeof(arelent));
4840
+       gas_assert(relP != 0);
4841
+       relP->sym_ptr_ptr  = (asymbol **)xmalloc(sizeof(asymbol *));
4842
+       *relP->sym_ptr_ptr = symbol_get_bfdsym(fixP->fx_addsy);
4843
+       relP->address      = (fixP->fx_frag->fr_address + fixP->fx_where);
4844
+       // The addend value is added to the symbols value after the value is
4845
+       // is resolved.  It is useful for PC relative addressing, as well as
4846
+       // instructions giving offsets to symbols, such as LDI .x+50,R0.
4847
+       relP->addend = fixP->fx_offset;
4848
+       if (fixP->fx_r_type == BFD_RELOC_ZIP_OPB_PCREL)
4849
+               relP->addend -= 4;
4850 206 dgisselq
+       else if (fixP->fx_r_type == BFD_RELOC_ZIP_MOV_PCREL)
4851
+               relP->addend -= 4;
4852 202 dgisselq
+#ifdef ZIP_DEBUG
4853
+       fprintf(stderr, "ADDEND = %08lx\n", relP->addend);
4854
+#endif
4855
+       relP->howto = bfd_reloc_type_lookup(stdoutput, fixP->fx_r_type);
4856
+       if (! relP->howto) {
4857
+               const char *name;
4858
+               name = S_GET_NAME(fixP->fx_addsy);
4859
+               if (name == NULL)
4860
+                       name = _("<unknown>");
4861
+               as_fatal( _("Cannot generate relocation type for symbol %s, code %s"),
4862
+                       name, bfd_get_reloc_code_name(fixP->fx_r_type));
4863
+       }
4864
+#ifdef ZIP_DEBUG
4865
+       else {
4866
+               const char *name;
4867
+               name = S_GET_NAME(fixP->fx_addsy);
4868
+               if (name == NULL)
4869
+                       name = _("<unknown>");
4870
+               fprintf(stderr, "GENERATING-RELOC(%20s, %4d=0x%04x) for %s\n",
4871
+                       bfd_get_reloc_code_name(fixP->fx_r_type),
4872
+                       fixP->fx_r_type, fixP->fx_r_type, name);
4873
+       }
4874
+#endif
4875
+       return relP;
4876
+}
4877
+
4878
+// Size is estimated in host bytes (octets)
4879
+int
4880
+zip_estimate_size_before_relax(fragS *fragP, segT seg) {
4881
+       ZIPIS   *insn = (ZIPIS *)(fragP->fr_opcode);
4882
+       offsetT last_fix = fragP->fr_fix;
4883
+
4884
+       zip_assemble_insn_words(fragP, seg, insn, 1, 0, NULL);
4885
+
4886
+       // Goal is to estimate the total size of the fragment before any
4887
+       // relaxations.  We need to return the difference between that
4888
+       // new estimate of total size and the current value of fragP->fr_fix.
4889
+#ifdef ZIP_DEBUG
4890
+       fprintf(stderr, "(%s): SZ-ESTIMATE %3ld + %d*(1+%d) - %3ld = %3ld\n",
4891
+               S_GET_NAME(insn->i_rp->r_sym),
4892
+               insn->i_rp->r_fr_offset, OCTETS_PER_BYTE, insn->i_naux,
4893
+               fragP->fr_fix,
4894
+               insn->i_rp->r_fr_offset + (1+insn->i_naux)*sizeof(uint32_t) - fragP->fr_fix);
4895
+#endif
4896
+       // zip_dump_insn(insn);
4897
+       fragP->fr_fix =  insn->i_rp->r_fr_offset + (1+insn->i_naux) * sizeof(uint32_t);
4898
+       return fragP->fr_fix - last_fix;
4899
+}
4900
+
4901
+#define        RELAX_STATE(FRAG)       (FRAG->fr_subtype)
4902
+long
4903
+zip_relax_frag(segT seg, fragS *fragP, long stretch)
4904
+{
4905
+       ZIPIS   *insn = (ZIPIS *)(fragP->fr_opcode);
4906
+       char    *p =&fragP->fr_literal[insn->i_rp->r_fr_offset];
4907
+       long    growth;
4908
+       int     i, old_naux = insn->i_naux;
4909
+
4910
+#ifdef ZIP_DEBUG
4911
+       fprintf(stderr, "--- FIX --- @%08x/%08x, Sym %s (zip_relax_frag), stretch = %ld/offset = %08lx, addr=%08x\n",
4912
+                       (int)((long)(fragP->fr_literal)),
4913
+                       (unsigned)fragP->fr_address,
4914
+                       (insn->i_rp->r_sym)?  S_GET_NAME(insn->i_rp->r_sym)
4915
+                               :"(Null)",
4916
+                       stretch, insn->i_rp->r_fr_offset,
4917
+                       insn->i_imm);
4918
+       // zip_dump_insn(insn);
4919
+#endif
4920
+
4921
+       {
4922
+               fragS   *lclfP;
4923
+               for(lclfP = fragP; lclfP; lclfP = lclfP->fr_next)
4924
+                       gas_assert(lclfP->fr_type < 256);
4925
+       }
4926
+
4927
+       // We need to rebuild the instruction since we could relax it
4928
+       // multiple times
4929
+       zip_assemble_insn_words(fragP, seg, insn, 1, stretch, NULL);
4930
+       {
4931
+               fragS   *lclfP;
4932
+               for(lclfP = fragP; lclfP; lclfP = lclfP->fr_next)
4933
+                       gas_assert(lclfP->fr_type < 256);
4934
+       }
4935
+
4936
+       md_number_to_chars(p, insn->i_code, sizeof(uint32_t));
4937
+       {
4938
+               fragS   *lclfP;
4939
+               for(lclfP = fragP; lclfP; lclfP = lclfP->fr_next)
4940
+                       gas_assert(lclfP->fr_type < 256);
4941
+       }
4942
+
4943
+       for(i=0; i< insn->i_naux; i++)
4944
+               md_number_to_chars(&p[sizeof(uint32_t)*(1+i)], insn->i_aux[i],
4945
+                               sizeof(uint32_t));
4946
+
4947
+       {
4948
+               fragS   *lclfP;
4949
+               for(lclfP = fragP; lclfP; lclfP = lclfP->fr_next)
4950
+                       gas_assert(lclfP->fr_type < 256);
4951
+       }
4952
+
4953
+       // The change in size of this fragment
4954
+       growth = (insn->i_naux - old_naux) * sizeof(uint32_t);
4955
+#ifdef ZIP_DEBUG
4956
+       fprintf(stderr, "GROWING BY %3ld bytes (insn->i_naux = %d->%d, fr_fix was %ld)\n",
4957
+               growth, old_naux, insn->i_naux, fragP->fr_fix);
4958
+       gas_assert(fragP->fr_fix >= 0);
4959
+       gas_assert(fragP->fr_fix + growth>= 0);
4960
+#endif
4961
+       {
4962
+               fragS   *lclfP;
4963
+               for(lclfP = fragP; lclfP; lclfP = lclfP->fr_next)
4964
+                       gas_assert(lclfP->fr_type < 256);
4965
+       }
4966
+
4967
+       return growth;
4968
+}
4969
+
4970
+void
4971
+zip_convert_frag(bfd *headers ATTRIBUTE_UNUSED, segT segment ATTRIBUTE_UNUSED,
4972
+               fragS *fragP ATTRIBUTE_UNUSED)
4973
+{
4974
+       ZIPIS   *insn = (ZIPIS *)fragP->fr_opcode;
4975
+       // char *p = fragP->fr_literal+ insn->i_rp->r_fr_offset;
4976
+
4977
+#ifdef ZIP_DEBUG
4978
+       fprintf(stderr, "CVT-FRAG: ADDR = %08lx, FIX = %3ld, VAR = %3ld\n",
4979
+               fragP->fr_address, fragP->fr_fix, fragP->fr_var);
4980
+
4981
+       zip_dump_insn(insn);
4982
+#endif
4983
+
4984
+       if ((insn->i_rp)&&(insn->i_rp->r_type != BFD_RELOC_NONE)
4985
+                       &&(!insn->i_rp->r_fix)) {
4986
+               if (insn->i_op == ZIPO_LDI) {
4987
+                       if (insn->i_naux == 1) {
4988
+                               // BREV extension would go here
4989
+                               //
4990
+                               fix_new(fragP,
4991
+                                       insn->i_rp->r_fr_offset, // where w/in frag?
4992
+                                       4,              // 1,2, or 4 usually ... ??
4993
+                                       insn->i_rp->r_sym, // Add symbol,
4994
+                                       insn->i_imm,// Fixed/known offset to the symbol
4995
+                                       insn->i_rp->r_pcrel, // T if PC-Relative reloc
4996
+                                       BFD_RELOC_ZIP_BREV); // Reloc type
4997
+                               fix_new(fragP,
4998
+                                       (insn->i_rp->r_fr_offset+sizeof(uint32_t)), // where w/in frag?
4999
+                                       4,              // 1,2, or 4 usually ... ??
5000
+                                       insn->i_rp->r_sym, // Add symbol,
5001
+                                       insn->i_imm,// Fixed/known offset to the symbol
5002
+                                       insn->i_rp->r_pcrel, // T if PC-Relative reloc
5003
+                                       BFD_RELOC_ZIP_LLO); // Reloc type
5004
+                       } else {
5005
+                               insn->i_rp->r_fix = fix_new(fragP,
5006
+                                       (insn->i_rp->r_fr_offset), // where w/in frag?
5007
+                                       4,              // 1,2, or 4 usually ... ??
5008
+                                       insn->i_rp->r_sym, // Add symbol,
5009
+                                       insn->i_imm, // Fixed/known offset to the symbol
5010
+                                       insn->i_rp->r_pcrel, // T if PC-Relative reloc
5011
+                                       BFD_RELOC_ZIP_LDI); // Reloc type
5012
+                       }
5013
+               } else if ((insn->i_op == ZIPO_BRA)&&(insn->i_naux >= 1)) {
5014
+#ifdef ZIP_DEBUG
5015
+                       fprintf(stderr, "--- CVT-FRAG --- Creating a BRA fixup\n");
5016
+#endif
5017
+                       fix_new(fragP,
5018
+                               insn->i_rp->r_fr_offset +insn->i_naux*sizeof(uint32_t),
5019
+                               4,              // 1,2, or 4 usually ... ??
5020
+                               insn->i_rp->r_sym, // Add symbol,
5021
+                               insn->i_imm, // Fixed/known offset to the symbol
5022
+                               insn->i_rp->r_pcrel, // T if PC-Relative reloc
5023
+                               BFD_RELOC_ZIP_VALUE); // Reloc type
5024
+               } else if (insn->i_rp->r_type == BFD_RELOC_ZIP_VALUE) {
5025
+                               // Use the CIS LW (PC),PC method
5026
+                               fix_new(fragP,
5027
+                               insn->i_rp->r_fr_offset
5028
+                                       + insn->i_naux*sizeof(uint32_t),
5029
+                               4,              // 1,2, or 4 usually ... ??
5030
+                               insn->i_rp->r_sym, // Add symbol,
5031
+                               insn->i_imm, // Fixed/known offset to the symbol
5032
+                               insn->i_rp->r_pcrel, // T if PC-Relative reloc
5033
+                               BFD_RELOC_ZIP_VALUE); // Reloc type
5034
+               } else {
5035
+#ifdef ZIP_DEBUG
5036
+                       fprintf(stderr, "--- CVT-FRAG --- Creating a more generic fixup (%d)\n",
5037
+                               insn->i_rp->r_type);
5038
+#endif
5039
+                       fix_new(fragP,
5040
+                               // where w/in frag?
5041
+                               insn->i_rp->r_fr_offset+insn->i_naux * sizeof(uint32_t),
5042
+                               4,      // 1,2, or 4 usually ... ??
5043
+                               insn->i_rp->r_sym, // Add symbol,
5044
+                               insn->i_imm, // Fixed/known offset to the symbol
5045
+                               insn->i_rp->r_pcrel, // T if PC-Relative reloc
5046
+                               insn->i_rp->r_type); // Reloc type
5047
+               }
5048
+       }
5049
+}
5050
diff -Naur '--exclude=*.swp' binutils-2.27/gas/config/tc-zip.h binutils-2.27-zip/gas/config/tc-zip.h
5051
--- binutils-2.27/gas/config/tc-zip.h   1969-12-31 19:00:00.000000000 -0500
5052
+++ binutils-2.27-zip/gas/config/tc-zip.h       2017-03-03 09:35:34.527310651 -0500
5053
@@ -0,0 +1,191 @@
5054
+////////////////////////////////////////////////////////////////////////////////
5055
+//
5056
+// Filename:   tc-zip.h
5057
+//
5058
+// Project:    Zip CPU backend for GNU Binutils
5059
+//
5060
+// Purpose:
5061
+//
5062
+// Creator:    Dan Gisselquist, Ph.D.
5063
+//             Gisselquist Technology, LLC
5064
+//
5065
+////////////////////////////////////////////////////////////////////////////////
5066
+//
5067
+// Copyright (C) 2016-2017, Gisselquist Technology, LLC
5068
+//
5069
+// This program is free software (firmware): you can redistribute it and/or
5070
+// modify it under the terms of  the GNU General Public License as published
5071
+// by the Free Software Foundation, either version 3 of the License, or (at
5072
+// your option) any later version.
5073
+//
5074
+// This program is distributed in the hope that it will be useful, but WITHOUT
5075
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
5076
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5077
+// for more details.
5078
+//
5079
+// You should have received a copy of the GNU General Public License along
5080
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
5081
+// target there if the PDF file isn't present.)  If not, see
5082
+// <http://www.gnu.org/licenses/> for a copy.
5083
+//
5084
+// License:    GPL, v3, as defined and found on www.gnu.org,
5085
+//             http://www.gnu.org/licenses/gpl.html
5086
+//
5087
+//
5088
+////////////////////////////////////////////////////////////////////////////////
5089
+#ifndef        TC_ZIPCPU
5090
+#define        TC_ZIPCPU
5091
+
5092
+#define        TC_ZIP  1
5093
+
5094
+/* This macro, when defined as zero, means our target in little endian like a
5095
+ * PC.  A 1 would mean it was big endian.  Since the Zip CPU is big endian, we
5096
+ * set this to one here..
5097
+ */
5098
+#define        TARGET_BYTES_BIG_ENDIAN 1
5099
+
5100
+/* If WORKING_DOT_WORD is defined, GAS will not do broken word processing
5101
+ * (*note Broken Words ...).  Otherwise, you should set 'md_short_jump_size'
5102
+ * to the size of a short jump (a jump that is just long enough to jump
5103
+ * around a long jmp) and 'md_long_jump_size' to the size of a long jump
5104
+ * (a jump that can go anywhere in the function).  You should define
5105
+ * md_create_short_jump to create a short jump around a long jump, and define
5106
+ * md_create_long_jump to creat a long jump.  Here, we'll just skip these
5107
+ * and so we define WORKING_DOT_WORD.
5108
+ */
5109
+#define        WORKING_DOT_WORD
5110
+
5111
+/* TC_ADDRESS_BYTES ... Define this macro to specify the number of bytes used
5112
+ * to store an address.  Used to implement dc.a.  The target must have a reloc
5113
+ * for this size.
5114
+ */
5115
+#define        TC_ADDRESS_BYTES        zip_address_bytes
5116
+
5117
+/* TC_PREDICATE_START_CHAR ... I can't find this in the documentation, but I'm
5118
+ * guessing if a line begins with this character, the line beginning will be
5119
+ * taken care of specially.
5120
+ */
5121
+#define        TC_PREDICATE_START_CHAR '['
5122
+#define        TC_PREDICATE_END_CHAR   ']'
5123
+
5124
+
5125
+/* md_cons_align ... You may define this macro to do any special alignment
5126
+ * before a data allocation pseudo-op.
5127
+ *
5128
+ */
5129
+#define        md_cons_align(N)        zip_cons_align(N)
5130
+extern void    zip_cons_align(int);
5131
+
5132
+#define        md_flush_pending_output zip_flush_pending_output
5133
+extern void    zip_flush_pending_output(void);
5134
+
5135
+
5136
+/* This macro is the BFD target name to use when creating the output
5137
+* file.  This will normally depend upon the OBJ_FMT macro. */
5138
+#define TARGET_FORMAT "elf32-zip"
5139
+#define        TARGET_ARCH     bfd_arch_zip
5140
+
5141
+#define md_estimate_size_before_relax  zip_estimate_size_before_relax
5142
+#define        md_relax_frag                   zip_relax_frag
5143
+#define md_convert_frag                        zip_convert_frag
5144
+extern long zip_relax_frag(segT, fragS *, long);
5145
+extern int  zip_estimate_size_before_relax(fragS *, segT);
5146
+extern void zip_convert_frag(bfd *, segT, fragS *);
5147
+extern int     zip_address_bytes(void);
5148
+
5149
+/* These macros must be defined, but it will be a fatal assembler error if we
5150
+* ever hit them. */
5151
+// #define md_estimate_size_before_relax(A, B) (as_fatal (_("estimate size\n")),0)
5152
+#define md_pcrel_from(FIX) (((FIX)->fx_where+(FIX)->fx_frag->fr_address+4)>>OCTETS_PER_BYTE_POWER)
5153
+
5154
+// What do we need to define here to align on 32-bit boundaries?
5155
+#define        md_section_align(SEGMENT, SIZE) (SIZE)
5156
+
5157
+// Check label is called right after any label (lbl: ) is found in the
5158
+// assembly of the program.  We need to make certain this is called, so that
5159
+// in VLIW mode we don't try to merge an instruction pair into a new
5160
+// instruction sequence where the label calls for jumping into the middle
5161
+// of that sequence.
5162
+//
5163
+#define        tc_check_label  zip_check_label
5164
+extern void    zip_check_label(symbolS *);
5165
+
5166
+
5167
+extern void    md_assemble(char *op_str);
5168
+extern void    md_end(void);
5169
+extern void    md_begin(void);
5170
+// extern      symbolS *md_undefined_symbol(char *name);
5171
+// extern      void md_operand(expressionS *name);
5172
+
5173
+#if (TARGET_BYTES_BIG_ENDIAN==0)
5174
+#define        md_number_to_chars      number_to_chars_littleendian
5175
+#else
5176
+#define        md_number_to_chars      number_to_chars_bigendian
5177
+#endif
5178
+
5179
+
5180
+#define        GLOBAL_OFFSET_TABLE_NAME        "_GLOBAL_OFFSET_TABLE_"
5181
+
5182
+//     typedef uint32_t ZIPI, ZIPA;
5183
+//     typedef int     ZIPIMM;
5184
+
5185
+// LR = Link Register, R0
5186
+// FP = Frame Pointer, R12
5187
+// SP = Stack Pointer, R13
5188
+// CC = Condition Codes, R14
5189
+// PC = Program Counter, R15
5190
+typedef        enum {
5191
+       ZIP_LR=0, ZIP_R1, ZIP_R2, ZIP_R3, ZIP_R4, ZIP_R5, ZIP_R6, ZIP_R7,
5192
+       ZIP_R8, ZIP_R9, ZIP_R10, ZIP_R11, ZIP_FP,
5193
+               ZIP_SP, ZIP_CC, ZIP_PC,
5194
+       ZIP_uLR, ZIP_uR1, ZIP_uR2, ZIP_uR3, ZIP_uR4, ZIP_uR5, ZIP_uR6, ZIP_uR7,
5195
+       ZIP_uR8, ZIP_uR9, ZIP_uR10, ZIP_uR11, ZIP_uFP,
5196
+               ZIP_uSP, ZIP_uCC, ZIP_uPC,
5197
+       ZIP_RNONE=48
5198
+} ZIP_REG;
5199
+
5200
+#define        ZIP_USER_REGS   16
5201
+
5202
+typedef        enum {
5203
+       ZIPC_ALWAYS, ZIPC_Z,  ZIPC_LT,  ZIPC_C,
5204
+       ZIPC_V,      ZIPC_NZ, ZIPC_GE, ZIPC_NC
5205
+} ZIP_CONDITION;
5206
+
5207
+typedef        enum {
5208
+       // 16 ALU instructions
5209
+       ZIPO_SUB=0, ZIPO_AND, ZIPO_ADD, ZIPO_OR,        //  5'h000xx
5210
+       ZIPO_XOR, ZIPO_LSR, ZIPO_LSL, ZIPO_ASR,         //  5'h001xx
5211
+       ZIPO_BREV, ZIPO_LDILO, ZIPO_MPYUHI, ZIPO_MPYSHI,//  5'h010xx
5212
+       ZIPO_MPY, ZIPO_MOV, ZIPO_DIVU, ZIPO_DIVS,       //  5'h011xx
5213
+//
5214
+       ZIPO_CMP, ZIPO_TST,                             //  5'h1000x
5215
+       ZIPO_LW, ZIPO_SW, ZIPO_LH, ZIPO_SH, ZIPO_LB, ZIPO_SB,   //  5'h10xxw
5216
+       ZIPO_LDI, ZIPO_LDIn,                            //  5'h1100x
5217
+       ZIPO_FPADD=0x1a, ZIPO_FPSUB,                    //  5'h1101x
5218
+       ZIPO_FPMPY, ZIPO_FPDIV,                         //  5'h1110x
5219
+       ZIPO_FPI2F, ZIPO_FPF2I,                         //  5'h1111x
5220
+       // Pseudo-ops
5221
+       ZIPO_BREAK, ZIPO_LOCK, ZIPO_SIM, ZIPO_NOOP,
5222
+       ZIPO_TRAP, ZIPO_CLR,
5223
+       //
5224
+       ZIPO_BRA,  ZIPO_BLT,  ZIPO_BZ, ZIPO_BC,
5225
+       ZIPO_BV,   ZIPO_BGE,  ZIPO_BNZ, ZIPO_BNC,
5226
+       //
5227
+       ZIPO_HALT, ZIPO_WAIT, ZIPO_RTU, ZIPO_BUSY,
5228
+       ZIPO_STEP, ZIPO_JMP,  ZIPO_NOT, ZIPO_NEG,
5229
+       //
5230
+       ZIPO_SDUMP, ZIPO_NDUMP,
5231
+       ZIPO_SOUT,  ZIPO_NOUT,
5232
+       ZIPO_SEXIT, ZIPO_NEXIT,
5233
+       ZIPO_SEXTB, ZIPO_SEXTH,
5234
+       ZIPO_JSR,   ZIPO_LJSR, ZIPO_LJMP
5235
+} ZIP_OPCODE;
5236
+
5237
+typedef        enum {
5238
+       // 8 instructions
5239
+       ZIPV_SUB=0, ZIPV_AND, ZIPV_ADD, ZIPV_CMP,       // 3'h0xx
5240
+       ZIPV_LW, ZIPV_SW, ZIPV_LDI, ZIPV_MOV,           // 3'h1xx
5241
+} ZIP_VLIWCODE;
5242
+
5243
+#endif
5244
+
5245
diff -Naur '--exclude=*.swp' binutils-2.27/gas/configure.tgt binutils-2.27-zip/gas/configure.tgt
5246
--- binutils-2.27/gas/configure.tgt     2016-08-03 03:36:51.000000000 -0400
5247
+++ binutils-2.27-zip/gas/configure.tgt 2016-12-31 17:44:37.270167826 -0500
5248
@@ -112,6 +112,7 @@
5249
   x86_64*)             cpu_type=i386 arch=x86_64;;
5250
   xgate)               cpu_type=xgate ;;
5251
   xtensa*)             cpu_type=xtensa arch=xtensa ;;
5252
+  zip*)                        cpu_type=zip endian=big ;;
5253
   *)                   cpu_type=${cpu} ;;
5254
 esac
5255
 
5256
@@ -472,6 +473,8 @@
5257
 
5258
   z8k-*-coff | z8k-*-sim)              fmt=coff ;;
5259
 
5260
+  zip*)                                        fmt=elf ;;
5261
+
5262
   *-*-aout | *-*-scout)                        fmt=aout ;;
5263
   *-*-cloudabi*)                       fmt=elf ;;
5264
   *-*-dragonfly*)                      fmt=elf em=dragonfly ;;
5265
diff -Naur '--exclude=*.swp' binutils-2.27/gas/Makefile.am binutils-2.27-zip/gas/Makefile.am
5266
--- binutils-2.27/gas/Makefile.am       2016-08-03 03:36:51.000000000 -0400
5267
+++ binutils-2.27-zip/gas/Makefile.am   2016-12-31 17:45:17.941851449 -0500
5268
@@ -200,6 +200,7 @@
5269
        config/tc-xtensa.c \
5270
        config/tc-z80.c \
5271
        config/tc-z8k.c \
5272
+       config/tc-zip.c \
5273
        config/xtensa-relax.c
5274
 
5275
 TARGET_CPU_HFILES = \
5276
@@ -273,6 +274,7 @@
5277
        config/tc-xtensa.h \
5278
        config/tc-z80.h \
5279
        config/tc-z8k.h \
5280
+       config/tc-zip.h \
5281
        config/xtensa-relax.h
5282
 
5283
 # OBJ files in config
5284
diff -Naur '--exclude=*.swp' binutils-2.27/gas/Makefile.in binutils-2.27-zip/gas/Makefile.in
5285
--- binutils-2.27/gas/Makefile.in       2016-08-03 04:16:28.000000000 -0400
5286
+++ binutils-2.27-zip/gas/Makefile.in   2016-12-31 17:49:43.603837948 -0500
5287
@@ -494,6 +494,7 @@
5288
        config/tc-xtensa.c \
5289
        config/tc-z80.c \
5290
        config/tc-z8k.c \
5291
+       config/tc-zip.c \
5292
        config/xtensa-relax.c
5293
 
5294
 TARGET_CPU_HFILES = \
5295
@@ -567,6 +568,7 @@
5296
        config/tc-xtensa.h \
5297
        config/tc-z80.h \
5298
        config/tc-z8k.h \
5299
+       config/tc-zip.h \
5300
        config/xtensa-relax.h
5301
 
5302
 
5303
@@ -922,6 +924,7 @@
5304
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-xtensa.Po@am__quote@
5305
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-z80.Po@am__quote@
5306
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-z8k.Po@am__quote@
5307
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tc-zip.Po@am__quote@
5308
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/te-vms.Po@am__quote@
5309
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/write.Po@am__quote@
5310
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtensa-relax.Po@am__quote@
5311
@@ -1941,6 +1944,20 @@
5312
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5313
 @am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-z8k.obj `if test -f 'config/tc-z8k.c'; then $(CYGPATH_W) 'config/tc-z8k.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-z8k.c'; fi`
5314
 
5315
+tc-zip.o: config/tc-zip.c
5316
+@am__fastdepCC_TRUE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tc-zip.o -MD -MP -MF $(DEPDIR)/tc-zip.Tpo -c -o tc-zip.o `test -f 'config/tc-zip.c' || echo '$(srcdir)/'`config/tc-zip.c
5317
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/tc-zip.Tpo $(DEPDIR)/tc-zip.Po
5318
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='config/tc-zip.c' object='tc-zip.o' libtool=no @AMDEPBACKSLASH@
5319
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5320
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-zip.o `test -f 'config/tc-zip.c' || echo '$(srcdir)/'`config/tc-zip.c
5321
+
5322
+tc-zip.obj: config/tc-zip.c
5323
+@am__fastdepCC_TRUE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT tc-zip.obj -MD -MP -MF $(DEPDIR)/tc-zip.Tpo -c -o tc-zip.obj `if test -f 'config/tc-zip.c'; then $(CYGPATH_W) 'config/tc-zip.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-zip.c'; fi`
5324
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/tc-zip.Tpo $(DEPDIR)/tc-zip.Po
5325
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='config/tc-zip.c' object='tc-zip.obj' libtool=no @AMDEPBACKSLASH@
5326
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5327
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o tc-zip.obj `if test -f 'config/tc-zip.c'; then $(CYGPATH_W) 'config/tc-zip.c'; else $(CYGPATH_W) '$(srcdir)/config/tc-zip.c'; fi`
5328
+
5329
 xtensa-relax.o: config/xtensa-relax.c
5330
 @am__fastdepCC_TRUE@   $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT xtensa-relax.o -MD -MP -MF $(DEPDIR)/xtensa-relax.Tpo -c -o xtensa-relax.o `test -f 'config/xtensa-relax.c' || echo '$(srcdir)/'`config/xtensa-relax.c
5331
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/xtensa-relax.Tpo $(DEPDIR)/xtensa-relax.Po
5332
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip.exp binutils-2.27-zip/gas/testsuite/gas/zip/zip.exp
5333
--- binutils-2.27/gas/testsuite/gas/zip/zip.exp 1969-12-31 19:00:00.000000000 -0500
5334
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip.exp     2017-01-12 22:12:40.839206088 -0500
5335
@@ -0,0 +1,17 @@
5336
+# ZipCPU assembler testsuite
5337
+
5338
+if [istarget zip*] {
5339
+  run_dump_test "zip_insn_add"
5340
+  run_dump_test "zip_insn_bratest"
5341
+  run_dump_test "zip_insn_ctest"
5342
+  run_dump_test "zip_insn_lditest"
5343
+  run_dump_test "zip_insn_prologue"
5344
+  run_dump_test "zip_insn_prologuev"
5345
+  run_dump_test "zip_insn_specials"
5346
+  run_dump_test "zip_insn_optest"
5347
+  run_dump_test "zip_insn_mov"
5348
+  run_dump_test "zip_insn_vliw"
5349
+  # run_dump_test "zip_insn_fpu"
5350
+  # run_dump_test "zip_insn_jsr"
5351
+  # run_dump_test "zip_insn_jsrv"
5352
+}
5353
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_add.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_add.d
5354
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_add.d  1969-12-31 19:00:00.000000000 -0500
5355
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_add.d      2017-01-12 22:01:30.790982203 -0500
5356
@@ -0,0 +1,41 @@
5357
+#as: -novliw
5358
+#objdump: -dr
5359
+#name: Generic OpB instruction test
5360
+
5361
+.*: +file format elf32-zip
5362
+
5363
+
5364
+Disassembly of section .text:
5365
+
5366
+00000000 <add_insn_test>:
5367
+   0:  00 83 e0 00     ADD +\$-8192,R0
5368
+   4:  00 84 a0 00     ADD +\$-8192\+R2,R0
5369
+   8:  08 82 00 00     ADD +\$-131072,R1
5370
+   c:  00 80 1f ff     ADD +\$8191,R0
5371
+  10:  00 84 a0 01     ADD +\$-8191\+R2,R0
5372
+  14:  08 81 ff ff     ADD +\$131071,R1
5373
+  18:  18 80 00 01     ADD +\$1,R3
5374
+  1c:  18 85 00 01     ADD +\$1\+R4,R3
5375
+  20:  30 87 c0 01     ADD +\$4\+PC,R6
5376
+  24:  30 87 c0 01     ADD +\$4\+PC,R6
5377
+  28:  30 87 c0 01     ADD +\$4\+PC,R6
5378
+  2c:  30 87 c0 01     ADD +\$4\+PC,R6
5379
+  30:  50 88 00 04     ADD.Z +\$4,R10
5380
+  34:  50 a8 00 04     ADD.NZ +.4,R10
5381
+  38:  50 90 00 04     ADD.LT +.4,R10
5382
+  3c:  50 b0 00 04     ADD.GE +.4,R10
5383
+  40:  50 98 00 04     ADD.C +.4,R10
5384
+  44:  50 b8 00 04     ADD.NC +.4,R10
5385
+  48:  50 a0 00 04     ADD.V +.4,R10
5386
+  4c:  50 88 00 04     ADD.Z +.4,R10
5387
+  50:  58 a8 00 04     ADD.NZ +.4,R11
5388
+  54:  60 90 00 04     ADD.LT +.4,R12
5389
+  58:  68 b0 00 04     ADD.GE +.4,SP
5390
+  5c:  70 98 00 04     ADD.C +.4,CC
5391
+  60:  78 b8 00 04     BNC +@0x00000068.*$
5392
+  64:  68 a0 00 04     ADD.V +.4,SP
5393
+  68:  70 80 00 04     ADD +.4,CC
5394
+  6c:  78 80 00 04     BRA +@0x00000074.*$
5395
+  70:  78 89 ff ff     BZ +@0x00020073.*$
5396
+  74:  78 aa 00 00     BNZ +@0xfffe0078.*$
5397
+
5398
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_add.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_add.s
5399
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_add.s  1969-12-31 19:00:00.000000000 -0500
5400
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_add.s      2017-01-10 12:00:50.870044337 -0500
5401
@@ -0,0 +1,33 @@
5402
+       .text
5403
+
5404
+add_insn_test:
5405
+       add     -8192,R0
5406
+       add     -8192+R2,R0
5407
+       add     -131072,R1
5408
+       add     8191,R0
5409
+       add     -8191+R2,R0
5410
+       add     131071,R1
5411
+       add     1,R3
5412
+       add     1(R4),R3
5413
+       add     5+pc,R6
5414
+       add     5+r15,R6
5415
+       add     5+spc,R6
5416
+       add     5+sr15,R6
5417
+       add.z   4,R10
5418
+       add.nz  4,R10
5419
+       add.lt  4,R10
5420
+       add.ge  4,R10
5421
+       add.c   4,R10
5422
+       add.nc  4,R10
5423
+       add.v   4,R10
5424
+       [z]  add        4,R10
5425
+       [nz] add        4,R11
5426
+       [lt] add        4,R12
5427
+       [ge] add        4,R13
5428
+       [c]  add        4,R14
5429
+       [nc] add        4,R15
5430
+       [v]  add        4,sp
5431
+       add     4,cc
5432
+       add     4,pc
5433
+       add.z   131071,pc
5434
+       add.nz  -131072,pc
5435
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_bratest.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_bratest.d
5436
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_bratest.d      1969-12-31 19:00:00.000000000 -0500
5437
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_bratest.d  2017-01-10 10:46:16.957469423 -0500
5438
@@ -0,0 +1,22 @@
5439
+#as:
5440
+#objdump: -dr
5441
+#name: Local branch (BRA) and conditional branch testing
5442
+
5443
+.*: +file format elf32-zip
5444
+
5445
+
5446
+Disassembly of section .text:
5447
+
5448
+00000000 <bra_insn_test>:
5449
+   0:  78 80 00 20     BRA        \$32
5450
+   4:  78 88 00 1c     BZ         @0x00000024  // .. <bra_target>
5451
+   8:  78 a8 00 18     BNZ        @0x00000024  // .. <bra_target>
5452
+   c:  78 98 00 14     BC         @0x00000024  // .. <bra_target>
5453
+  10:  78 b8 00 10     BNC        @0x00000024  // .. <bra_target>
5454
+  14:  78 90 00 0c     BLT        @0x00000024  // .. <bra_target>
5455
+  18:  78 b0 00 08     BGE        @0x00000024  // .. <bra_target>
5456
+  1c:  78 a0 00 04     BV         @0x00000024  // .. <bra_target>
5457
+  20:  06 7f ff ff     LDI        \$-1,R0
5458
+
5459
+00000024 <bra_target>:
5460
+  24:  7f c0 00 00     NOOP
5461
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_bratest.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_bratest.s
5462
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_bratest.s      1969-12-31 19:00:00.000000000 -0500
5463
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_bratest.s  2017-01-09 10:28:54.983992877 -0500
5464
@@ -0,0 +1,14 @@
5465
+       .text
5466
+
5467
+bra_insn_test:
5468
+       bra     bra_target
5469
+       bz      bra_target
5470
+       bnz     bra_target
5471
+       bc      bra_target
5472
+       bnc     bra_target
5473
+       blt     bra_target
5474
+       bge     bra_target
5475
+       bv      bra_target
5476
+       ldi -1,r0
5477
+bra_target:
5478
+       noop
5479
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_ctest.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_ctest.d
5480
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_ctest.d        1969-12-31 19:00:00.000000000 -0500
5481
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_ctest.d    2017-01-16 11:02:02.344009430 -0500
5482
@@ -0,0 +1,39 @@
5483
+#as:
5484
+#objdump: -dr
5485
+#name: Conditional predicate test(s)
5486
+
5487
+.*: +file format elf32-zip
5488
+
5489
+
5490
+Disassembly of section .text:
5491
+
5492
+00000000 <conditional_tests>:
5493
+   0:  00 80 00 01     ADD +\$1,R0
5494
+   4:  00 88 00 01     ADD.Z +\$1,R0
5495
+   8:  00 88 00 01     ADD.Z +\$1,R0
5496
+   c:  00 a8 00 01     ADD.NZ +\$1,R0
5497
+  10:  00 a8 00 01     ADD.NZ +\$1,R0
5498
+  14:  00 b0 00 01     ADD.GE +\$1,R0
5499
+  18:  00 b0 00 01     ADD.GE +\$1,R0
5500
+  1c:  00 90 00 01     ADD.LT +\$1,R0
5501
+  20:  00 90 00 01     ADD.LT +\$1,R0
5502
+  24:  00 a0 00 01     ADD.V +\$1,R0
5503
+  28:  00 98 00 01     ADD.C +\$1,R0
5504
+  2c:  00 98 00 01     ADD.C +\$1,R0
5505
+  30:  00 b8 00 01     ADD.NC +\$1,R0
5506
+  34:  00 b8 00 01     ADD.NC +\$1,R0
5507
+  38:  00 80 00 01     ADD +\$1,R0
5508
+  3c:  00 88 00 01     ADD.Z +\$1,R0
5509
+  40:  28 8b ff e0     ADD.Z +\$-32,R5
5510
+  44:  00 88 00 01     ADD.Z +\$1,R0
5511
+  48:  00 a8 00 01     ADD.NZ +\$1,R0
5512
+  4c:  00 a8 00 01     ADD.NZ +\$1,R0
5513
+  50:  00 b0 00 01     ADD.GE +\$1,R0
5514
+  54:  00 b0 00 01     ADD.GE +\$1,R0
5515
+  58:  00 90 00 01     ADD.LT +\$1,R0
5516
+  5c:  00 90 00 01     ADD.LT +\$1,R0
5517
+  60:  00 a0 00 01     ADD.V  +\$1,R0
5518
+  64:  00 98 00 01     ADD.C  +\$1,R0
5519
+  68:  00 98 00 01     ADD.C  +\$1,R0
5520
+  6c:  00 b8 00 01     ADD.NC +\$1,R0
5521
+  70:  00 b8 00 01     ADD.NC +\$1,R0
5522
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_ctest.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_ctest.s
5523
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_ctest.s        1969-12-31 19:00:00.000000000 -0500
5524
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_ctest.s    2017-01-16 10:55:53.054697861 -0500
5525
@@ -0,0 +1,34 @@
5526
+       .text
5527
+
5528
+conditional_tests:
5529
+       add     1,R0
5530
+       add.z   1,R0
5531
+       add.eq  1,R0
5532
+       add.nz  1,R0
5533
+       add.ne  1,R0
5534
+       add.ge  1,R0
5535
+       add.gte 1,R0
5536
+       add.lt  1,R0
5537
+       add.n   1,R0
5538
+       add.v   1,R0
5539
+       add.c   1,R0
5540
+       add.ltu 1,R0
5541
+       add.nc  1,R0
5542
+       add.geu 1,R0
5543
+       ;
5544
+       add     1,R0
5545
+       [z]     add     1,R0
5546
+       [z]     add     -32,R5
5547
+       [EQ]    add     1,R0
5548
+       [nz]    add     1,R0
5549
+       [ne]    add     1,R0
5550
+       [ge]    add     1,R0
5551
+       [gte]   add     1,R0
5552
+       [lt]    add     1,R0
5553
+       [n]     add     1,R0
5554
+       [v]     add     1,R0
5555
+       [c]     add     1,R0
5556
+       [ltu]   add     1,R0
5557
+       [nc]    add     1,R0
5558
+       [geu]   add     1,R0
5559
+
5560
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_lditest.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_lditest.d
5561
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_lditest.d      1969-12-31 19:00:00.000000000 -0500
5562
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_lditest.d  2017-01-10 11:31:45.633275455 -0500
5563
@@ -0,0 +1,24 @@
5564
+#as: -nozipm
5565
+#objdump: -dr
5566
+#name: Load-Immediate test
5567
+
5568
+.*: +file format elf32-zip
5569
+
5570
+
5571
+Disassembly of section .text:
5572
+
5573
+00000000 <ldi_insn_test>:
5574
+   0:  06 00 00 00     CLR +R0
5575
+   4:  0a 08 00 00     CLR.Z +\$0,R1
5576
+   8:  16 00 20 00     LDI +\$8192,R2
5577
+   c:  1a 08 00 00     LDI.Z +0x00002000,R3.*
5578
+  10:  1a 48 20 00
5579
+  14:  22 29 ff ff     LDI.NZ +0xffffe000,R4.*
5580
+  18:  22 68 e0 00
5581
+  1c:  2a 03 fe 00     BREV +\$-512,R5
5582
+  20:  32 00 01 ff     LDI +0xff800001,R6.*
5583
+  24:  32 40 00 01
5584
+  28:  3a 00 01 ff     BREV +\$511,R7
5585
+  2c:  42 03 fe ff     BREV +\$-257,R8
5586
+  30:  4a 01 fe ff     LDI +0xff7ffffe,R9.*
5587
+  34:  4a 40 ff fe
5588
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_lditest.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_lditest.s
5589
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_lditest.s      1969-12-31 19:00:00.000000000 -0500
5590
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_lditest.s  2017-01-09 10:28:37.472119620 -0500
5591
@@ -0,0 +1,13 @@
5592
+       .text
5593
+
5594
+ldi_insn_test:
5595
+       ldi     0,R0
5596
+       ldi.z   0,r1
5597
+       ldi     8192,r2
5598
+       ldi.z   8192,r3
5599
+       ldi.nz  -8192,r4
5600
+       ldi     8388607,r5
5601
+       ldi     -8388607,r6
5602
+       ldi     -8388608,r7
5603
+       ldi     -8388609,r8
5604
+       ldi     -8388610,r9
5605
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_mov.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_mov.d
5606
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_mov.d  1969-12-31 19:00:00.000000000 -0500
5607
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_mov.d      2017-01-12 22:09:54.925246052 -0500
5608
@@ -0,0 +1,86 @@
5609
+#as: -novliw -nozipm
5610
+#objdump: -dr
5611
+#name: Mov instruction special test
5612
+
5613
+.*: +file format elf32-zip
5614
+
5615
+
5616
+Disassembly of section .text:
5617
+
5618
+00000000 <mov_insn_test>:
5619
+   0:  0b 40 10 00     MOV +\$-4096\+R0,R1
5620
+   4:  1b 40 90 01     MOV +\$-4095\+R2,R3
5621
+   8:  2b 41 0f ff     MOV +\$4095\+R4,R5
5622
+   c:  3b 41 80 00     MOV +R6,R7
5623
+
5624
+00000010 <mov_to_user>:
5625
+  10:  0b 44 10 00     MOV +\$-4096\+R0,uR1
5626
+  14:  1b 44 90 01     MOV +\$-4095\+R2,uR3
5627
+  18:  2b 45 0f ff     MOV +\$4095\+R4,uR5
5628
+  1c:  3b 45 80 00     MOV +R6,uR7
5629
+
5630
+00000020 <mov_from_user>:
5631
+  20:  0b 40 30 00     MOV +\$-4096\+uR0,R1
5632
+  24:  1b 40 b0 01     MOV +\$-4095\+uR2,R3
5633
+  28:  2b 41 2f ff     MOV +\$4095\+uR4,R5
5634
+  2c:  3b 41 a0 00     MOV +uR6,R7
5635
+
5636
+00000030 <mov_user_to_user>:
5637
+  30:  0b 44 30 00     MOV +\$-4096\+uR0,uR1
5638
+  34:  1b 44 b0 01     MOV +\$-4095\+uR2,uR3
5639
+  38:  2b 45 2f ff     MOV +\$4095\+uR4,uR5
5640
+  3c:  3b 45 a0 00     MOV +uR6,uR7
5641
+
5642
+00000040 <move_from_upc>:
5643
+  40:  0b 47 f0 00     MOV +\$-4096\+uPC,uR1
5644
+  44:  1b 47 f0 01     MOV +\$-4095\+uPC,uR3
5645
+  48:  2b 47 ef ff     MOV +\$4095\+uPC,uR5
5646
+  4c:  3b 47 e0 00     MOV +uPC,uR7
5647
+
5648
+00000050 <move_from_usp>:
5649
+  50:  0b 47 70 00     MOV +\$-4096\+uSP,uR1
5650
+  54:  1b 47 70 01     MOV +\$-4095\+uSP,uR3
5651
+  58:  2b 47 6f ff     MOV +\$4095\+uSP,uR5
5652
+  5c:  3b 47 60 00     MOV +uSP,uR7
5653
+
5654
+00000060 <move_from_ucc>:
5655
+  60:  0b 47 b0 00     MOV +\$-4096\+uCC,uR1
5656
+  64:  1b 47 b0 01     MOV +\$-4095\+uCC,uR3
5657
+  68:  2b 47 af ff     MOV +\$4095\+uCC,uR5
5658
+  6c:  3b 47 a0 00     MOV +uCC,uR7
5659
+
5660
+00000070 <move_to_upc>:
5661
+  70:  7b 44 10 00     MOV +\$-4096\+R0,uPC
5662
+  74:  7b 44 90 01     MOV +\$-4095\+R2,uPC
5663
+  78:  7b 45 0f ff     MOV +\$4095\+R4,uPC
5664
+  7c:  7b 45 80 00     MOV +R6,uPC
5665
+
5666
+00000080 <move_to_usp>:
5667
+  80:  6b 44 10 00     MOV +\$-4096\+R0,uSP
5668
+  84:  6b 44 90 01     MOV +\$-4095\+R2,uSP
5669
+  88:  6b 45 0f ff     MOV +\$4095\+R4,uSP
5670
+  8c:  6b 45 80 00     MOV +R6,uSP
5671
+
5672
+00000090 <move_to_ucc>:
5673
+  90:  73 44 10 00     MOV +\$-4096\+R0,uCC
5674
+  94:  73 44 90 01     MOV +\$-4095\+R2,uCC
5675
+  98:  73 45 0f ff     MOV +\$4095\+R4,uCC
5676
+  9c:  73 45 80 00     MOV +R6,uCC
5677
+
5678
+000000a0 <move_to_pc>:
5679
+  a0:  7b 40 10 00     JMP +\$-4096\+R0
5680
+  a4:  7b 40 90 01     JMP +\$-4095\+R2
5681
+  a8:  7b 41 0f ff     JMP +\$4095\+R4
5682
+  ac:  7b 41 80 00     JMP +R6
5683
+
5684
+000000b0 <move_to_sp>:
5685
+  b0:  6b 40 10 00     MOV +\$-4096\+R0,SP
5686
+  b4:  6b 40 90 01     MOV +\$-4095\+R2,SP
5687
+  b8:  6b 41 0f ff     MOV +\$4095\+R4,SP
5688
+  bc:  6b 41 80 00     MOV +R6,SP
5689
+
5690
+000000c0 <move_to_cc>:
5691
+  c0:  73 40 10 00     MOV +\$-4096\+R0,CC
5692
+  c4:  73 40 90 01     MOV +\$-4095\+R2,CC
5693
+  c8:  73 41 0f ff     MOV +\$4095\+R4,CC
5694
+  cc:  73 41 80 00     MOV +R6,CC
5695
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_mov.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_mov.s
5696
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_mov.s  1969-12-31 19:00:00.000000000 -0500
5697
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_mov.s      2017-01-12 16:45:17.027962005 -0500
5698
@@ -0,0 +1,93 @@
5699
+       .text
5700
+
5701
+mov_insn_test:
5702
+       mov     -4096+R0,R1
5703
+       mov     -4095+R2,R3
5704
+       mov     4095+R4,R5
5705
+       mov     R6,R7
5706
+       ;
5707
+mov_to_user:
5708
+       ;
5709
+       mov     -4096+R0,uR1
5710
+       mov     -4095+R2,uR3
5711
+       mov     4095+R4,uR5
5712
+       mov     R6,uR7
5713
+       ;
5714
+mov_from_user:
5715
+       ;
5716
+       mov     -4096+uR0,R1
5717
+       mov     -4095+uR2,R3
5718
+       mov     4095+uR4,R5
5719
+       mov     uR6,R7
5720
+       ;
5721
+mov_user_to_user:
5722
+       ;
5723
+       mov     -4096+uR0,uR1
5724
+       mov     -4095+uR2,uR3
5725
+       mov     4095+uR4,uR5
5726
+       mov     uR6,uR7
5727
+       ;
5728
+       ;
5729
+move_from_upc:
5730
+       ;
5731
+       mov     -4096+upc,uR1
5732
+       mov     -4095+upc,uR3
5733
+       mov     4095+upc,uR5
5734
+       mov     upc,uR7
5735
+       ;
5736
+move_from_usp:
5737
+       ;
5738
+       mov     -4096+usp,uR1
5739
+       mov     -4095+usp,uR3
5740
+       mov     4095+usp,uR5
5741
+       mov     usp,uR7
5742
+       ;
5743
+move_from_ucc:
5744
+       ;
5745
+       mov     -4096+ucc,uR1
5746
+       mov     -4095+ucc,uR3
5747
+       mov     4095+ucc,uR5
5748
+       mov     ucc,uR7
5749
+       ;
5750
+move_to_upc:
5751
+       ;
5752
+       mov     -4096+r0,upc
5753
+       mov     -4095+r2,upc
5754
+       mov     4095+r4,upc
5755
+       mov     r6,upc
5756
+       ;
5757
+move_to_usp:
5758
+       ;
5759
+       mov     -4096+r0,usp
5760
+       mov     -4095+r2,usp
5761
+       mov     4095+r4,usp
5762
+       mov     r6,usp
5763
+       ;
5764
+move_to_ucc:
5765
+       ;
5766
+       mov     -4096+r0,ucc
5767
+       mov     -4095+r2,ucc
5768
+       mov     4095+r4,ucc
5769
+       mov     r6,ucc
5770
+       ;
5771
+move_to_pc:
5772
+       ;
5773
+       mov     -4096+r0,pc
5774
+       mov     -4095+r2,pc
5775
+       mov     4095+r4,pc
5776
+       mov     r6,pc
5777
+       ;
5778
+move_to_sp:
5779
+       ;
5780
+       mov     -4096+r0,sp
5781
+       mov     -4095+r2,sp
5782
+       mov     4095+r4,sp
5783
+       mov     r6,sp
5784
+       ;
5785
+move_to_cc:
5786
+       ;
5787
+       mov     -4096+r0,cc
5788
+       mov     -4095+r2,cc
5789
+       mov     4095+r4,cc
5790
+       mov     r6,cc
5791
+       ;
5792
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_optest.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_optest.d
5793
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_optest.d       1969-12-31 19:00:00.000000000 -0500
5794
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_optest.d   2017-01-12 22:12:11.497444662 -0500
5795
@@ -0,0 +1,98 @@
5796
+#as: -novliw -nozipm
5797
+#objdump: -dr
5798
+#name: OpCode generation test
5799
+
5800
+.*: +file format elf32-zip
5801
+
5802
+
5803
+Disassembly of section .text:
5804
+
5805
+00000000 <optest>:
5806
+   0:  00 00 00 04     SUB +\$4,R0
5807
+   4:  08 40 00 04     AND +\$4,R1
5808
+   8:  10 80 00 04     ADD +\$4,R2
5809
+   c:  19 00 00 04     XOR +\$4,R3
5810
+  10:  20 c0 00 04     OR +\$4,R4
5811
+  14:  29 40 00 04     LSR +\$4,R5
5812
+  18:  31 80 00 04     LSL +\$4,R6
5813
+  1c:  39 c0 00 04     ASR +\$4,R7
5814
+  20:  02 40 00 03     LDILO +\$3,R0
5815
+  24:  0a 00 00 02     BREV +\$2,R1
5816
+  28:  12 80 00 03     MPYUHI +\$3,R2
5817
+  2c:  1a c0 00 03     MPYSHI +\$3,R3
5818
+  30:  23 00 00 03     MPY +\$3,R4
5819
+  34:  2b 80 00 07     DIVU +\$7,R5
5820
+  38:  33 c0 00 09     DIVS +\$9,R6
5821
+  3c:  04 00 00 05     CMP +\$5,R0
5822
+  40:  0c 40 00 05     TST +\$5,R1
5823
+  44:  1c 43 ff ff     TST +\$-1,R3
5824
+  48:  24 43 ff ff     TST +\$-1,R4
5825
+  4c:  14 40 00 04     TST +\$4,R2
5826
+  50:  0d 84 00 04     LB +4\(R0\),R1
5827
+  54:  15 c4 40 04     SB +R2,\$4\(R1\)
5828
+  58:  1d 04 80 04     LH +4\(R2\),R3
5829
+  5c:  25 44 c0 04     SH +R4,\$4\(R3\)
5830
+  60:  2c 85 00 04     LW +4\(R4\),R5
5831
+  64:  34 c5 40 04     SW +R6,\$4\(R5\)
5832
+  68:  17 80 00 07     FPI2F +\$7,R2
5833
+  6c:  17 84 40 03     FPI2F +\$3\+R1,R2
5834
+  70:  16 84 c0 00     FPADD +R3,R2
5835
+  74:  27 05 c0 00     FPMPY +R7,R4
5836
+  78:  4f 45 80 00     FPDIV +R6,R9
5837
+  7c:  57 c6 00 00     FPF2I +R8,R10
5838
+  80:  00 07 00 07     SUB +\$7\+R12,R0
5839
+  84:  08 47 00 07     AND +\$7\+R12,R1
5840
+  88:  10 87 00 07     ADD +\$7\+R12,R2
5841
+  8c:  19 07 00 07     XOR +\$7\+R12,R3
5842
+  90:  20 c7 00 07     OR +\$7\+R12,R4
5843
+  94:  29 47 00 07     LSR +\$7\+R12,R5
5844
+  98:  31 87 00 07     LSL +\$7\+R12,R6
5845
+  9c:  39 c7 00 07     ASR +\$7\+R12,R7
5846
+  a0:  00 07 3f fd     SUB +\$-3\+R12,R0
5847
+  a4:  08 47 3f fd     AND +\$-3\+R12,R1
5848
+  a8:  10 87 3f fd     ADD +\$-3\+R12,R2
5849
+  ac:  19 07 3f fd     XOR +\$-3\+R12,R3
5850
+  b0:  20 c7 3f fd     OR +\$-3\+R12,R4
5851
+  b4:  29 47 3f fd     LSR +\$-3\+R12,R5
5852
+  b8:  31 87 3f fd     LSL +\$-3\+R12,R6
5853
+  bc:  39 c7 3f fd     ASR +\$-3\+R12,R7
5854
+  c0:  02 47 01 66     LDILO +\$358\+R12,R0
5855
+  c4:  0a 04 7e 9a     BREV +\$-358\+R1,R1
5856
+  c8:  12 84 7e 9a     MPYUHI +\$-358\+R1,R2
5857
+  cc:  1a c4 7e 9a     MPYSHI +\$-358\+R1,R3
5858
+  d0:  23 04 7e 9a     MPY +\$-358\+R1,R4
5859
+  d4:  2b 84 7e 9a     DIVU +\$-358\+R1,R5
5860
+  d8:  33 c4 7e 9a     DIVS +\$-358\+R1,R6
5861
+  dc:  04 04 bf ed     CMP +\$-19\+R2,R0
5862
+  e0:  0c 44 bf ed     TST +\$-19\+R2,R1
5863
+  e4:  0d 80 01 04     LB +\(\$260\),R1
5864
+  e8:  15 c0 01 06     SB +R2,\(\$262\)
5865
+  ec:  1d 00 01 10     LH +\(\$272\),R3
5866
+  f0:  25 40 01 12     SH +R4,\(\$274\)
5867
+  f4:  2c 80 01 19     LW +\(\$281\),R5
5868
+  f8:  34 c0 01 ab     SW +R6,\(\$427\)
5869
+  fc:  00 02 00 00     SUB +\$-131072,R0
5870
+ 100:  00 02 00 00     SUB +\$-131072,R0
5871
+ 104:  08 42 00 00     AND +\$-131072,R1
5872
+ 108:  10 82 00 00     ADD +\$-131072,R2
5873
+ 10c:  19 02 00 00     XOR +\$-131072,R3
5874
+ 110:  20 c2 00 00     OR +\$-131072,R4
5875
+ 114:  29 42 00 00     LSR +\$-131072,R5
5876
+ 118:  31 82 00 00     LSL +\$-131072,R6
5877
+ 11c:  39 c2 00 00     ASR +\$-131072,R7
5878
+ 120:  02 40 14 85     LDILO +\$5253,R0
5879
+ 124:  0a 02 00 00     BREV +\$-131072,R1
5880
+ 128:  12 82 00 00     MPYUHI +\$-131072,R2
5881
+ 12c:  1a c2 00 00     MPYSHI +\$-131072,R3
5882
+ 130:  23 02 00 00     MPY +\$-131072,R4
5883
+ 134:  2b 82 00 00     DIVU +\$-131072,R5
5884
+ 138:  33 c2 00 00     DIVS +\$-131072,R6
5885
+ 13c:  04 02 00 00     CMP +\$-131072,R0
5886
+ 140:  0c 42 00 00     TST +\$-131072,R1
5887
+ 144:  0d 82 00 00     LB +\(\$-131072\),R1
5888
+ 148:  15 c2 00 00     SB +R2,\(\$-131072\)
5889
+ 14c:  1d 02 00 00     LH +\(\$-131072\),R3
5890
+ 150:  25 42 00 00     SH +R4,\(\$-131072\)
5891
+ 154:  2c 82 00 00     LW +\(\$-131072\),R5
5892
+ 158:  34 c2 00 00     SW +R6,\(\$-131072\)
5893
+ 15c:  17 82 00 00     FPI2F +\$-131072,R2
5894
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_optest.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_optest.s
5895
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_optest.s       1969-12-31 19:00:00.000000000 -0500
5896
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_optest.s   2017-01-12 16:28:47.212542071 -0500
5897
@@ -0,0 +1,119 @@
5898
+       .text
5899
+
5900
+optest:
5901
+       sub     4,R0
5902
+       and     4,R1
5903
+       add     4,R2
5904
+       xor     4,R3
5905
+       or      4,R4
5906
+       lsr     4,R5
5907
+       lsl     4,R6
5908
+       asr     4,R7
5909
+       ;
5910
+       ldilo   3,R0
5911
+       brev    2,R1
5912
+       mpyuhi  3,R2
5913
+       mpyshi  3,R3
5914
+       mpy     3,R4
5915
+       divu    7,R5
5916
+       divs    9,r6
5917
+       ; mov   R1,R2
5918
+
5919
+       ;
5920
+       cmp     5,R0
5921
+       test    5,R1
5922
+       test    R3
5923
+       tst     R4
5924
+       tst     4,R2
5925
+       ;
5926
+       lb      4(r0),r1
5927
+       sb      r2,4(r1)
5928
+       lh      4(r2),r3
5929
+       sh      r4,4(r3)
5930
+       lw      4(r4),r5
5931
+       sw      r6,4(r5)
5932
+       ; ldi
5933
+       fpi2f   7,r2
5934
+       fpi2f   3(r1),r2
5935
+       fpadd   r3,r2
5936
+       ; fpmpy r7,r4
5937
+       fpmul   r7,r4
5938
+       fpdiv   r6,r9
5939
+       fpf2i   r8,r10
5940
+       ;
5941
+       ;
5942
+; Now repeat, with Reg + Imm
5943
+       sub     7(r12),R0
5944
+       and     7(r12),R1
5945
+       add     7(r12),R2
5946
+       xor     7(r12),R3
5947
+       or      7(r12),R4
5948
+       lsr     7(r12),R5
5949
+       lsl     7(r12),R6
5950
+       asr     7(r12),R7
5951
+       ;
5952
+       sub     -3+r12,R0
5953
+       and     -3+r12,R1
5954
+       add     -3+r12,R2
5955
+       xor     -3+r12,R3
5956
+       or      -3+r12,R4
5957
+       lsr     -3+r12,R5
5958
+       lsl     -3+r12,R6
5959
+       asr     -3+r12,R7
5960
+       ;
5961
+       ldilo   358+r12,R0
5962
+       brev    -358+r1,R1
5963
+       mpyuhi  -358+r1,R2
5964
+       mpyshi  -358+r1,R3
5965
+       mpy     -358+r1,R4
5966
+       divu    -358+r1,R5
5967
+       divs    -358+r1,r6
5968
+       ; mov   R1,R2
5969
+
5970
+       ;
5971
+       cmp     -19+r2,R0
5972
+       test    -19+r2,R1
5973
+       ;
5974
+       lb      0x104,r1
5975
+       sb      r2,0x106
5976
+       lh      0x110,r3
5977
+       sh      r4,0x112
5978
+       lw      0x119,r5
5979
+       sw      r6,0x1ab
5980
+       ; ldi
5981
+       ; floating point --- already done
5982
+
5983
+
5984
+; Ops with the minimum integer
5985
+       sub     -0x20000,R0
5986
+       sub     -131072,R0
5987
+       and     -131072,R1
5988
+       add     -131072,R2
5989
+       xor     -0x20000,R3
5990
+       or      -131072,R4
5991
+       lsr     -131072,R5
5992
+       lsl     -131072,R6
5993
+       asr     -131072,R7
5994
+       ;
5995
+       ldilo   0x21485,R0
5996
+       brev    -0x20000,R1
5997
+       mpyuhi  -0x20000,R2
5998
+       mpyshi  -0x20000,R3
5999
+       mpy     -0x20000,R4
6000
+       divu    -0x20000,R5
6001
+       divs    -0x20000,r6
6002
+       ; mov   R1,R2
6003
+
6004
+       ;
6005
+       cmp     -0x20000,R0
6006
+       test    -0x20000,R1
6007
+       ;
6008
+       lb      -0x20000,r1
6009
+       sb      r2,-0x20000
6010
+       lh      -0x20000,r3
6011
+       sh      r4,-0x20000
6012
+       lw      -0x20000,r5
6013
+       sw      r6,-0x20000
6014
+       ; ldi
6015
+       fpi2f   -0x20000,r2
6016
+       ;
6017
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologue.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologue.d
6018
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologue.d     1969-12-31 19:00:00.000000000 -0500
6019
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologue.d 2017-01-10 11:09:36.301473902 -0500
6020
@@ -0,0 +1,32 @@
6021
+#as: -novliw
6022
+#objdump: -dr
6023
+#name: Prologue test - Non-thumb
6024
+
6025
+.*: +file format elf32-zip
6026
+
6027
+
6028
+Disassembly of section .text:
6029
+
6030
+00000000 <some_function>:
6031
+   0:  68 00 00 30     SUB +\$48,SP
6032
+   4:  04 c7 40 00     SW +R0,\(SP\)
6033
+   8:  2c c7 40 04     SW +R5,\$4\(SP\)
6034
+   c:  34 c7 40 08     SW +R6,\$8\(SP\)
6035
+  10:  3c c7 40 0c     SW +R7,\$12\(SP\)
6036
+  14:  44 c7 40 10     SW +R8,\$16\(SP\)
6037
+  18:  4c c7 40 14     SW +R9,\$20\(SP\)
6038
+  1c:  54 c7 40 18     SW +R10,\$24\(SP\)
6039
+  20:  5c c7 40 1c     SW +R11,\$28\(SP\)
6040
+  24:  64 c7 40 20     SW +R12,\$32\(SP\)
6041
+  28:  38 84 80 00     ADD +R2,R7
6042
+  2c:  04 87 40 00     LW +\(SP\),R0
6043
+  30:  04 87 40 04     LW +4\(SP\),R0
6044
+  34:  04 87 40 08     LW +8\(SP\),R0
6045
+  38:  04 87 40 0c     LW +12\(SP\),R0
6046
+  3c:  04 87 40 10     LW +16\(SP\),R0
6047
+  40:  04 87 40 14     LW +20\(SP\),R0
6048
+  44:  04 87 40 18     LW +24\(SP\),R0
6049
+  48:  04 87 40 1c     LW +28\(SP\),R0
6050
+  4c:  04 87 40 20     LW +32\(SP\),R0
6051
+  50:  68 80 00 30     ADD +\$48,SP
6052
+  54:  7b 40 00 00     RTN +
6053
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologue.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologue.s
6054
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologue.s     1969-12-31 19:00:00.000000000 -0500
6055
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologue.s 2017-01-09 07:25:40.495644200 -0500
6056
@@ -0,0 +1,24 @@
6057
+some_function:
6058
+       SUB     48,SP
6059
+       SW      R0,(SP)
6060
+       SW      R5,4(SP)
6061
+       SW      R6,8(SP)
6062
+       SW      R7,12(SP)
6063
+       SW      R8,16(SP)
6064
+       SW      R9,20(SP)
6065
+       SW      R10,24(SP)
6066
+       SW      R11,28(SP)
6067
+       SW      R12,32(SP)
6068
+       ADD     R2,R7
6069
+       LW      (SP),R0
6070
+       LW      4(SP),R0
6071
+       LW      8(SP),R0
6072
+       LW      12(SP),R0
6073
+       LW      16(SP),R0
6074
+       LW      20(SP),R0
6075
+       LW      24(SP),R0
6076
+       LW      28(SP),R0
6077
+       LW      32(SP),R0
6078
+       ADD     48,SP
6079
+       RETN
6080
+
6081
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologuev.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologuev.d
6082
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologuev.d    1969-12-31 19:00:00.000000000 -0500
6083
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologuev.d        2017-01-12 21:58:59.513900839 -0500
6084
@@ -0,0 +1,21 @@
6085
+#as: -nozipm -vliw
6086
+#objdump: -dr
6087
+#name: Prologue test - thumb
6088
+
6089
+.*: +file format elf32-zip
6090
+
6091
+
6092
+Disassembly of section .text:
6093
+
6094
+00000000 <some_function>:
6095
+   0:  e8 30 85 00     SUB +\$48,SP +| SW +R0,\(SP\)
6096
+   4:  ad 04 b5 08     SW +R5,\$4\(SP\) +| SW +R6,$8\(SP\)
6097
+   8:  bd 0c c5 10     SW +R7,\$12\(SP\) +| SW +R8,$16\(SP\)
6098
+   c:  cd 14 d5 18     SW +R9,\$20\(SP\) +| SW +R10,$24\(SP\)
6099
+  10:  dd 1c e5 20     SW +R11,\$28\(SP\) +| SW +R12,$32\(SP\)
6100
+  14:  ba 90 84 00     ADD +R2,R7 +| LW +\(SP\),R0
6101
+  18:  84 04 84 08     LW +4\(SP\),R0 +| LW +8\(SP\),R0
6102
+  1c:  84 0c 84 10     LW +12\(SP\),R0 +| LW +16\(SP\),R0
6103
+  20:  84 14 84 18     LW +20\(SP\),R0 +| LW +24\(SP\),R0
6104
+  24:  84 1c 84 20     LW +28\(SP\),R0 +| LW +32\(SP\),R0
6105
+  28:  ea 30 ff 80     ADD +\$48,SP +| MOV +R0,PC
6106
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologuev.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologuev.s
6107
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_prologuev.s    1969-12-31 19:00:00.000000000 -0500
6108
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_prologuev.s        2017-01-10 11:29:18.612449601 -0500
6109
@@ -0,0 +1,24 @@
6110
+some_function:
6111
+       SUB     48,SP
6112
+       SW      R0,(SP)
6113
+       SW      R5,4(SP)
6114
+       SW      R6,8(SP)
6115
+       SW      R7,12(SP)
6116
+       SW      R8,16(SP)
6117
+       SW      R9,20(SP)
6118
+       SW      R10,24(SP)
6119
+       SW      R11,28(SP)
6120
+       SW      R12,32(SP)
6121
+       ADD     R2,R7
6122
+       LW      (SP),R0
6123
+       LW      4(SP),R0
6124
+       LW      8(SP),R0
6125
+       LW      12(SP),R0
6126
+       LW      16(SP),R0
6127
+       LW      20(SP),R0
6128
+       LW      24(SP),R0
6129
+       LW      28(SP),R0
6130
+       LW      32(SP),R0
6131
+       ADD     48,SP
6132
+       RETN
6133
+
6134
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_specials.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_specials.d
6135
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_specials.d     1969-12-31 19:00:00.000000000 -0500
6136
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_specials.d 2017-01-24 08:03:32.892847657 -0500
6137
@@ -0,0 +1,41 @@
6138
+#as:
6139
+#objdump: -dr
6140
+#name: Special instruction(s) test
6141
+
6142
+.*: +file format elf32-zip
6143
+
6144
+
6145
+Disassembly of section .text:
6146
+
6147
+00000000 <specials_test>:
6148
+   0:  7f 00 00 00     BRK
6149
+   4:  7f 00 00 11     BRK        \$17
6150
+   8:  7f c0 00 00     NOOP
6151
+   c:  7f c0 02 ff     NDUMP *$
6152
+  10:  7f c0 02 07     NDUMP      R7
6153
+  14:  7f c0 02 03     NDUMP      R3
6154
+  18:  7f c0 02 14     NDUMP      uR4
6155
+  1c:  7f c0 01 00     NEXIT
6156
+  20:  7f c0 01 00     NEXIT
6157
+  24:  7f c0 01 fc     NEXIT      \$-4
6158
+  28:  7f c0 01 f0     NEXIT      \$-16
6159
+  2c:  7f c0 03 07     NEXIT      R7
6160
+  30:  7f c4 00 23     NSIM       \$262179
6161
+  34:  7f 80 00 00     SIM +$
6162
+  38:  7f 80 02 ff     SDUMP *$
6163
+  3c:  7f 80 02 07     SDUMP      R7
6164
+  40:  7f 80 02 03     SDUMP      R3
6165
+  44:  7f 80 02 14     SDUMP      uR4
6166
+  48:  7f 80 01 17     SEXIT      \$23
6167
+  4c:  7f 80 01 e9     SEXIT      \$-23
6168
+  50:  7f 80 01 00     SEXIT
6169
+  54:  7f 80 03 0f     SEXIT      PC
6170
+  58:  7f 80 03 0e     SEXIT      CC
6171
+  5c:  7f 84 00 23     SIM        \$262179
6172
+  60:  7f 87 0f 23     SIM        \$462627
6173
+  64:  7f 80 04 61     SOUT       \$97
6174
+  68:  7f c0 04 62     NOUT       \$98
6175
+  6c:  7f 80 02 22     SOUT       R2
6176
+  70:  7f c0 02 27     NOUT       R7
6177
+  74:  7f 80 02 33     SOUT       uR3
6178
+  78:  7f c0 02 38     NOUT       uR8
6179
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_specials.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_specials.s
6180
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_specials.s     1969-12-31 19:00:00.000000000 -0500
6181
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_specials.s 2017-01-19 07:18:13.405003668 -0500
6182
@@ -0,0 +1,35 @@
6183
+       .text
6184
+
6185
+specials_test:
6186
+       break
6187
+       break   17
6188
+       noop
6189
+       ndump
6190
+       ndump   R7
6191
+       ndump   sR3
6192
+       ndump   uR4
6193
+       nexit
6194
+       nexit   0
6195
+       nexit   -4
6196
+       nexit   240
6197
+       nexit   R7
6198
+       noop    0x40023
6199
+       snoop
6200
+       sdump
6201
+       sdump   R7
6202
+       sdump   sR3
6203
+       sdump   uR4
6204
+       sexit   23
6205
+       sexit   -23
6206
+       sexit   0
6207
+       sexit   PC
6208
+       sexit   CC
6209
+       snoop   0x40023
6210
+       sim     0x70f23
6211
+       sout    'a'
6212
+       nout    'b'
6213
+       sout    R2
6214
+       nout    R7
6215
+       sout    uR3
6216
+       nout    uR8
6217
+
6218
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_vliw.d binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_vliw.d
6219
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_vliw.d 1969-12-31 19:00:00.000000000 -0500
6220
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_vliw.d     2017-01-12 21:50:28.719237156 -0500
6221
@@ -0,0 +1,77 @@
6222
+#as: -vliw
6223
+#objdump: -dr
6224
+#name: Thumb instruction set test
6225
+
6226
+.*: +file format elf32-zip
6227
+
6228
+
6229
+Disassembly of section .text:
6230
+
6231
+00000000 <vliw_merge_test>:
6232
+   0:  82 01 8a 01     ADD +\$1,R0 +| ADD +$1,R1
6233
+   4:  10 88 00 01     ADD.Z +\$1,R2
6234
+   8:  18 a8 00 01     ADD.NZ +\$1,R3
6235
+   c:  20 a0 00 01     ADD.V +\$1,R4
6236
+  10:  00 80 00 7f     ADD +\$127,R0
6237
+  14:  00 80 00 80     ADD +\$128,R0
6238
+  18:  00 80 00 81     ADD +\$129,R0
6239
+  1c:  82 3e 82 3f     ADD +\$62,R0 +| ADD +\$63,R0 *
6240
+  20:  00 80 00 40     ADD +\$64,R0
6241
+  24:  00 80 00 41     ADD +\$65,R0
6242
+  28:  82 88 82 89     ADD +R1,R0 +| ADD +\$1+R1,R0 *
6243
+  2c:  82 89 82 8a     ADD +\$1\+R1,R0 +| ADD +\$2\+R1,R0 *
6244
+  30:  82 8a 82 8a     ADD +\$2\+R1,R0 +| ADD +\$2\+R1,R0 *
6245
+  34:  00 84 40 03     ADD +\$3\+R1,R0
6246
+  38:  00 84 40 04     ADD +\$4\+R1,R0
6247
+  3c:  00 84 40 05     ADD +\$5\+R1,R0
6248
+  40:  00 84 7f fb     ADD +\$-5\+R1,R0
6249
+  44:  82 8c 82 8d     ADD +\$-4\+R1,R0 +| ADD +$-3+R1,R0 *
6250
+  48:  82 8e 82 8f     ADD +\$-2\+R1,R0 +| ADD +$-1+R1,R0 *
6251
+  4c:  82 88 84 88     ADD +R1,R0 +| LW +(R1),R0 *
6252
+  50:  94 89 9c 8a     LW  +1\(R1\),R2 +| LW +2(R1),R3 *
6253
+  54:  24 84 40 03     LW  +3\(R1\),R4
6254
+  58:  2c 84 40 04     LW  +4\(R1\),R5
6255
+  5c:  84 00 94 01     LW  +\(SP\),R0 +| LW +1\(SP\),R2 *
6256
+  60:  9c 02 a4 03     LW  +2\(SP\),R3 +| LW +3\(SP\),R4 *
6257
+  64:  ac 04 b4 3d     LW +4\(SP\),R5 +| LW +61\(SP\),R6 *
6258
+  68:  bc 3e c4 3f     LW +62\(SP\),R7 +| LW +63\(SP\),R8 *
6259
+  6c:  4c 87 40 40     LW +64\(SP\),R9
6260
+  70:  54 87 40 41     LW +65\(SP\),R10
6261
+  74:  54 c7 7f bf     SW +R10,\$-65\(SP\)
6262
+  78:  cd 40 c5 41     SW +R9,\$-64\(SP\) +| SW +R8,$-63\(SP\) *
6263
+  7c:  bd 42 b5 43     SW +R7,\$-62\(SP\) +| SW +R6,$-61\(SP\) *
6264
+  80:  b5 44 87 f8     SW +R6,\$-60\(SP\) +| MOV +PC,R0 *
6265
+  84:  8f f9 97 fa     MOV +\$4\+PC,R1 +| MOV +$8\+PC,R2 *
6266
+  88:  97 fa 9f fb     MOV +\$8\+PC,R2 +| MOV +$12\+PC,R3 *
6267
+  8c:  23 43 c0 04     MOV +0x000000a0,R4.*$
6268
+  90:  2b 43 c0 05     MOV +0x000000a8,R5.*$
6269
+  94:  33 43 df fb     MOV +0x00000084,R6.*$
6270
+  98:  bf fc c7 fd     MOV +\$-16\+PC,R7 +| MOV +$-12\+PC,R8 *
6271
+  9c:  cf fe 87 ff     MOV +\$-8\+PC,R9 +| MOV +$-4\+PC,R0 *
6272
+  a0:  13 43 c0 00     MOV +0x000000a4,R2.*$
6273
+
6274
+000000a4 <vliw_ldi_test>:
6275
+  a4:  86 00 8e 40     CLR +R0 +| LDI +\$64,R1
6276
+  a8:  16 00 00 7f     LDI +\$127,R2
6277
+  ac:  1e 00 00 80     LDI +\$128,R3
6278
+  b0:  26 00 00 81     LDI +\$129,R4
6279
+  b4:  2e 00 00 82     LDI +\$130,R5
6280
+  b8:  36 7f ff 7e     LDI +\$-130,R6
6281
+  bc:  3e 7f ff 7f     LDI +\$-129,R7
6282
+  c0:  c6 80 ce 81     LDI +\$-128,R8 +| LDI +\$-127,R9
6283
+  c4:  d6 82 de 83     LDI +\$-126,R10 +| LDI +\$-125,R11
6284
+
6285
+000000c8 <vliw_op_test>:
6286
+  c8:  88 80 99 90     SUB +R0,R1 +| AND +R2,R3 *$
6287
+  cc:  aa a0 bb b0     ADD +R4,R5 +| CMP +R6,uR7 *$
6288
+  d0:  c4 b8 cd d0     LW +\(R7\),R8 +| SW +R9,\$-48\(SP\) *$
6289
+  d4:  de 7c 9f 89     LDI +\$124,R11 +| MOV +$1+R1,R3 *$
6290
+  d8:  c8 05 88 80     SUB +\$5,R9 +| SUB +R0,R1 *$
6291
+  dc:  99 90 aa a0     AND +R2,R3 +| ADD +R4,R5 *$
6292
+  e0:  bb b0 c4 b8     CMP +R6,uR7 +| LW +(R7),R8 *$
6293
+  e4:  cd d0 de 7c     SW +R9,\$-48\(SP\) +| LDI +\$124,R11 *$
6294
+  e8:  9f 89 c8 0e     MOV +\$1\+R1,R3 +| SUB +\$14,R9 *$
6295
+  ec:  99 11 aa 13     AND +\$17,R3 +| ADD +\$19,R5 *$
6296
+  f0:  bb 3f c4 18     CMP +\$63\+R7,R7 +| LW         24\(SP\),R8 *$
6297
+  f4:  cd 1c de 7c     SW +R9,\$28\(SP\) +| LDI +\$124,R11 *$
6298
+  f8:  1b 40 40 01     MOV +\$1\+R1,R3
6299
diff -Naur '--exclude=*.swp' binutils-2.27/gas/testsuite/gas/zip/zip_insn_vliw.s binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_vliw.s
6300
--- binutils-2.27/gas/testsuite/gas/zip/zip_insn_vliw.s 1969-12-31 19:00:00.000000000 -0500
6301
+++ binutils-2.27-zip/gas/testsuite/gas/zip/zip_insn_vliw.s     2017-01-12 16:55:54.690241718 -0500
6302
@@ -0,0 +1,110 @@
6303
+       .text
6304
+
6305
+vliw_merge_test:
6306
+       ; Simple: are merges enabled?
6307
+       add     1,R0
6308
+       add     1,R1
6309
+       ; These should not merge with any neighbor
6310
+       add.z   1,R2
6311
+       add.nz  1,R3
6312
+       add.v   1,R4
6313
+       add     127,R0
6314
+       add     128,R0
6315
+       add     129,R0
6316
+       add     62,R0
6317
+       add     63,R0
6318
+       add     64,R0
6319
+       add     65,R0
6320
+       add     0(R1),R0
6321
+       add     1(R1),R0
6322
+       add     1(R1),R0
6323
+       add     2(R1),R0
6324
+       add     2(R1),R0
6325
+       add     2(R1),R0
6326
+       add     3(R1),R0
6327
+       add     4(R1),R0
6328
+       add     5(R1),R0
6329
+       add     -5(R1),R0
6330
+       add     -4(R1),R0
6331
+       add     -3(R1),R0
6332
+       add     -2(R1),R0
6333
+       add     -1(R1),R0
6334
+       add     0(R1),R0
6335
+       lw      (r1),r0
6336
+       lw      1(r1),r2
6337
+       lw      2(r1),r3
6338
+       lw      3(r1),r4
6339
+       lw      4(r1),r5
6340
+       lw      (sp),r0
6341
+       lw      1(sp),r2
6342
+       lw      2(sp),r3
6343
+       lw      3(sp),r4
6344
+       lw      4(sp),r5
6345
+       lw      61(sp),r6
6346
+       lw      62(sp),r7
6347
+       lw      63(sp),r8
6348
+       lw      64(sp),r9
6349
+       lw      65(sp),r10
6350
+       sw      r10,-65(sp)
6351
+       sw      r9,-64(sp)
6352
+       sw      r8,-63(sp)
6353
+       sw      r7,-62(sp)
6354
+       sw      r6,-61(sp)
6355
+       sw      r6,-60(sp)
6356
+       mov     (PC),R0
6357
+       mov     1(PC),R1
6358
+       mov     2(PC),R2
6359
+       mov     2(PC),R2
6360
+       mov     3(PC),R3
6361
+       mov     4(PC),R4
6362
+       mov     5(PC),R5
6363
+       mov     -5(PC),R6
6364
+       mov     -4(PC),R7
6365
+       mov     -3(PC),R8
6366
+       mov     -2(PC),R9
6367
+       mov     -1(PC),R0
6368
+       mov     0(PC),R2
6369
+       # LDI's
6370
+vliw_ldi_test:
6371
+       LDI     0,R0
6372
+       LDI     64,R1
6373
+       LDI     127,R2
6374
+       LDI     128,R3
6375
+       LDI     129,R4
6376
+       LDI     130,R5
6377
+       LDI     -130,R6
6378
+       LDI     -129,R7
6379
+       LDI     -128,R8
6380
+       LDI     -127,R9
6381
+       LDI     -126,R10
6382
+       LDI     -125,R11
6383
+vliw_op_test:
6384
+       sub     r0,r1
6385
+       and     r2,r3
6386
+       add     r4,r5
6387
+       cmp     r6,r7
6388
+       lw      (r7),r8
6389
+       sw      r9,(r10)
6390
+       ldi     124,r11
6391
+       mov     1+r1,r3
6392
+       # and with a touch of offset
6393
+       sub     5,r9
6394
+       sub     r0,r1
6395
+       and     r2,r3
6396
+       add     r4,r5
6397
+       cmp     r6,r7
6398
+       lw      (r7),r8
6399
+       sw      r9,(r10)
6400
+       ldi     124,r11
6401
+       mov     1+r1,r3
6402
+       # And now, so that they all have immediates instead of register
6403
+       sub     14,r9
6404
+       and     17,r3
6405
+       add     19,r5
6406
+       cmp     63,r7
6407
+       lw      24(sp),r8
6408
+       sw      r9,28(sp)
6409
+       ldi     124,r11
6410
+       mov     1+r1,r3
6411
+
6412
+
6413
diff -Naur '--exclude=*.swp' binutils-2.27/gas/write.c binutils-2.27-zip/gas/write.c
6414
--- binutils-2.27/gas/write.c   2016-08-03 03:36:51.000000000 -0400
6415
+++ binutils-2.27-zip/gas/write.c       2016-12-31 17:51:52.470985149 -0500
6416
@@ -2676,7 +2676,7 @@
6417
 
6418
              case rs_org:
6419
                {
6420
-                 addressT target = offset;
6421
+                 addressT target = offset * OCTETS_PER_BYTE;
6422
                  addressT after;
6423
 
6424
                  if (symbolP)
6425
diff -Naur '--exclude=*.swp' binutils-2.27/include/dis-asm.h binutils-2.27-zip/include/dis-asm.h
6426
--- binutils-2.27/include/dis-asm.h     2016-08-03 03:36:53.000000000 -0400
6427
+++ binutils-2.27-zip/include/dis-asm.h 2016-12-31 17:52:29.022758231 -0500
6428
@@ -318,10 +318,12 @@
6429
 extern int print_insn_rl78_g10         (bfd_vma, disassemble_info *);
6430
 extern int print_insn_rl78_g13         (bfd_vma, disassemble_info *);
6431
 extern int print_insn_rl78_g14         (bfd_vma, disassemble_info *);
6432
+extern int print_insn_zip              (bfd_vma, disassemble_info *);
6433
 
6434
 extern disassembler_ftype arc_get_disassembler (bfd *);
6435
 extern disassembler_ftype cris_get_disassembler (bfd *);
6436
 extern disassembler_ftype rl78_get_disassembler (bfd *);
6437
+extern disassembler_ftype zip_get_disassembler (bfd *);
6438
 
6439
 extern void print_aarch64_disassembler_options (FILE *);
6440
 extern void print_i386_disassembler_options (FILE *);
6441
diff -Naur '--exclude=*.swp' binutils-2.27/include/elf/common.h binutils-2.27-zip/include/elf/common.h
6442
--- binutils-2.27/include/elf/common.h  2016-08-03 03:36:53.000000000 -0400
6443
+++ binutils-2.27-zip/include/elf/common.h      2016-12-31 17:53:58.942198950 -0500
6444
@@ -411,6 +411,9 @@
6445
 /* Old constant that might be in use by some software. */
6446
 #define EM_OPENRISC            EM_OR1K
6447
 
6448
+/* ZipCPU vs instruction set -- Use this until we get an official number */
6449
+#define EM_ZIP                 0xdad1
6450
+
6451
 /* See the above comment before you add a new EM_* value here.  */
6452
 
6453
 /* Values for e_version.  */
6454
diff -Naur '--exclude=*.swp' binutils-2.27/include/elf/zip.h binutils-2.27-zip/include/elf/zip.h
6455
--- binutils-2.27/include/elf/zip.h     1969-12-31 19:00:00.000000000 -0500
6456
+++ binutils-2.27-zip/include/elf/zip.h 2017-01-18 18:19:33.764898333 -0500
6457
@@ -0,0 +1,58 @@
6458
+////////////////////////////////////////////////////////////////////////////////
6459
+//
6460
+// Filename:   zip.h
6461
+//
6462
+// Project:    Zip CPU backend for GNU Binutils
6463
+//
6464
+// Purpose:
6465
+//
6466
+// Creator:    Dan Gisselquist, Ph.D.
6467
+//             Gisselquist Technology, LLC
6468
+//
6469
+////////////////////////////////////////////////////////////////////////////////
6470
+//
6471
+// Copyright (C) 2016-2017, Gisselquist Technology, LLC
6472
+//
6473
+// This program is free software (firmware): you can redistribute it and/or
6474
+// modify it under the terms of  the GNU General Public License as published
6475
+// by the Free Software Foundation, either version 3 of the License, or (at
6476
+// your option) any later version.
6477
+//
6478
+// This program is distributed in the hope that it will be useful, but WITHOUT
6479
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
6480
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6481
+// for more details.
6482
+//
6483
+// You should have received a copy of the GNU General Public License along
6484
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
6485
+// target there if the PDF file isn't present.)  If not, see
6486
+// <http://www.gnu.org/licenses/> for a copy.
6487
+//
6488
+// License:    GPL, v3, as defined and found on www.gnu.org,
6489
+//             http://www.gnu.org/licenses/gpl.html
6490
+//
6491
+//
6492
+////////////////////////////////////////////////////////////////////////////////
6493
+#ifndef        _ELF_ZIP_H
6494
+#define        _ELF_ZIP_H
6495
+
6496
+#include "elf/reloc-macros.h"
6497
+
6498
+/* Relocations.  */
6499
+START_RELOC_NUMBERS(elf_zip_reloc_type)
6500
+  RELOC_NUMBER (R_ZIP_NONE,        0)
6501
+  RELOC_NUMBER (R_ZIP_VALUE,       1)
6502
+  RELOC_NUMBER (R_ZIP_BREV,        2)
6503
+  RELOC_NUMBER (R_ZIP_LLO,         3)
6504
+  RELOC_NUMBER (R_ZIP_LDI,         4)
6505
+  RELOC_NUMBER (R_ZIP_BRANCH,      5)
6506
+  RELOC_NUMBER (R_ZIP_OPB_IMM,     6)
6507
+  RELOC_NUMBER (R_ZIP_OPB_OFFSET,  7)
6508
+  RELOC_NUMBER (R_ZIP_OPB_PCREL,   8)
6509
+  RELOC_NUMBER (R_ZIP_MOV_OFFSET,  9)
6510
+  RELOC_NUMBER (R_ZIP_MOV_PCREL,  10)
6511
+  // RELOC_NUMBER (R_ZIP_OPB_GOTREL, 11)
6512
+  // RELOC_NUMBER (R_ZIP_MOV_GOTREL, 12)
6513
+END_RELOC_NUMBERS(R_ZIP_max)
6514
+
6515
+#endif /* _ELF_ZIP_H */
6516
diff -Naur '--exclude=*.swp' binutils-2.27/ld/configure.tgt binutils-2.27-zip/ld/configure.tgt
6517
--- binutils-2.27/ld/configure.tgt      2016-08-03 03:36:54.000000000 -0400
6518
+++ binutils-2.27-zip/ld/configure.tgt  2016-12-31 17:55:04.013793303 -0500
6519
@@ -816,6 +816,8 @@
6520
                        ;;
6521
 z8k-*-coff)            targ_emul=z8002; targ_extra_emuls=z8001
6522
                        ;;
6523
+zip*)                  targ_emul=elf32zip;
6524
+                       ;;
6525
 *-*-ieee*)             targ_emul=vanilla
6526
                        ;;
6527
 *-tandem-none)         targ_emul=st2000
6528
diff -Naur '--exclude=*.swp' binutils-2.27/ld/emulparams/elf32zip.sh binutils-2.27-zip/ld/emulparams/elf32zip.sh
6529
--- binutils-2.27/ld/emulparams/elf32zip.sh     1969-12-31 19:00:00.000000000 -0500
6530
+++ binutils-2.27-zip/ld/emulparams/elf32zip.sh 2017-01-05 08:22:45.000000000 -0500
6531
@@ -0,0 +1,50 @@
6532
+################################################################################
6533
+#
6534
+# Filename:    elf32zip.sh
6535
+#
6536
+# Project:     Zip CPU backend for GNU Binutils
6537
+#
6538
+# Purpose:     This is a simple shell script providing some variables used
6539
+#              later and elsewhere by the ZipCPU linker.  Some things to note
6540
+#      are: 1) the TEXT_START_ADDR is set for the Basys-3 board I am using and
6541
+#      will likely need to change as your platform changes, 2) there currently
6542
+#      aren't any "pages" since the ZipCPU doesn't yet support a memory
6543
+#      management unit, 3) the ENTRY point only works if a separate loader
6544
+#      is loading the ZipCPU into RAM.  In all other cases, place your startup
6545
+#      code directly at the top of the .start segment, and set the ZipCPU
6546
+#      to run from there.  It'll start then at the first address loaded in
6547
+#      memory.
6548
+#
6549
+# Creator:     Dan Gisselquist, Ph.D.
6550
+#              Gisselquist Technology, LLC
6551
+#
6552
+################################################################################
6553
+#
6554
+# Copyright (C) 2016, Gisselquist Technology, LLC
6555
+#
6556
+# This program is free software (firmware): you can redistribute it and/or
6557
+# modify it under the terms of  the GNU General Public License as published
6558
+# by the Free Software Foundation, either version 3 of the License, or (at
6559
+# your option) any later version.
6560
+#
6561
+# This program is distributed in the hope that it will be useful, but WITHOUT
6562
+# ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
6563
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6564
+# for more details.
6565
+#
6566
+# License:     GPL, v3, as defined and found on www.gnu.org,
6567
+#              http://www.gnu.org/licenses/gpl.html
6568
+#
6569
+#
6570
+################################################################################
6571
+
6572
+SCRIPT_NAME=elf
6573
+TEMPLATE_NAME=elf32
6574
+ARCH=zip
6575
+OUTPUT_FORMAT="elf32-zip"
6576
+ENTRY="_start"
6577
+TEXT_START_ADDR="0x08000"
6578
+MAXPAGESIZE=0x01000
6579
+COMMONPAGESIZE=0x1000
6580
+EMBEDDED=yes
6581
+
6582
diff -Naur '--exclude=*.swp' binutils-2.27/ld/Makefile.am binutils-2.27-zip/ld/Makefile.am
6583
--- binutils-2.27/ld/Makefile.am        2016-08-03 03:36:54.000000000 -0400
6584
+++ binutils-2.27-zip/ld/Makefile.am    2016-12-31 17:57:39.684819835 -0500
6585
@@ -286,6 +286,7 @@
6586
        eelf32xc16xs.c \
6587
        eelf32xstormy16.c \
6588
        eelf32xtensa.c \
6589
+       eelf32zip.c \
6590
        eelf_i386.c \
6591
        eelf_i386_be.c \
6592
        eelf_i386_chaos.c \
6593
@@ -1309,6 +1310,9 @@
6594
   $(BFDDIR)/elf-bfd.h $(BFDDIR)/libbfd.h $(INCDIR)/elf/xtensa.h \
6595
   $(srcdir)/scripttempl/elfxtensa.sc ${GEN_DEPENDS}
6596
 
6597
+eelf32zip.c: $(srcdir)/emulparams/elf32zip.sh $(ELF_DEPS) \
6598
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
6599
+
6600
 eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
6601
   $(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
6602
 
6603
diff -Naur '--exclude=*.swp' binutils-2.27/ld/Makefile.in binutils-2.27-zip/ld/Makefile.in
6604
--- binutils-2.27/ld/Makefile.in        2016-08-03 03:36:54.000000000 -0400
6605
+++ binutils-2.27-zip/ld/Makefile.in    2016-12-31 17:59:30.788122513 -0500
6606
@@ -654,6 +654,7 @@
6607
        eelf32xc16xs.c \
6608
        eelf32xstormy16.c \
6609
        eelf32xtensa.c \
6610
+       eelf32zip.c \
6611
        eelf_i386.c \
6612
        eelf_i386_be.c \
6613
        eelf_i386_chaos.c \
6614
@@ -1314,6 +1315,7 @@
6615
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32xc16xs.Po@am__quote@
6616
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32xstormy16.Po@am__quote@
6617
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32xtensa.Po@am__quote@
6618
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf32zip.Po@am__quote@
6619
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_aix.Po@am__quote@
6620
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64.Po@am__quote@
6621
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/eelf64_ia64_fbsd.Po@am__quote@
6622
@@ -2897,6 +2899,9 @@
6623
   $(BFDDIR)/elf-bfd.h $(BFDDIR)/libbfd.h $(INCDIR)/elf/xtensa.h \
6624
   $(srcdir)/scripttempl/elfxtensa.sc ${GEN_DEPENDS}
6625
 
6626
+eelf32zip.c: $(srcdir)/emulparams/elf32zip.sh $(ELF_DEPS) \
6627
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
6628
+
6629
 eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
6630
   $(ELF_X86_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
6631
 
6632
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/configure binutils-2.27-zip/opcodes/configure
6633
--- binutils-2.27/opcodes/configure     2016-08-03 04:33:39.000000000 -0400
6634
+++ binutils-2.27-zip/opcodes/configure 2017-01-05 08:50:32.000000000 -0500
6635
@@ -12685,7 +12685,7 @@
6636
        bfd_xtensa_arch)        ta="$ta xtensa-dis.lo" ;;
6637
        bfd_z80_arch)           ta="$ta z80-dis.lo" ;;
6638
        bfd_z8k_arch)           ta="$ta z8k-dis.lo" ;;
6639
-
6640
+       bfd_zip_arch)           ta="$ta zip-dis.lo zip-opc.lo" ;;
6641
        "")                     ;;
6642
        *)              as_fn_error "*** unknown target architecture $arch" "$LINENO" 5 ;;
6643
        esac
6644
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/configure.ac binutils-2.27-zip/opcodes/configure.ac
6645
--- binutils-2.27/opcodes/configure.ac  2016-08-03 03:36:54.000000000 -0400
6646
+++ binutils-2.27-zip/opcodes/configure.ac      2017-01-05 08:49:53.000000000 -0500
6647
@@ -353,7 +353,7 @@
6648
        bfd_xtensa_arch)        ta="$ta xtensa-dis.lo" ;;
6649
        bfd_z80_arch)           ta="$ta z80-dis.lo" ;;
6650
        bfd_z8k_arch)           ta="$ta z8k-dis.lo" ;;
6651
-
6652
+       bfd_zip_arch)           ta="$ta zip-dis.lo zip-opc.lo" ;;
6653
        "")                     ;;
6654
        *)              AC_MSG_ERROR(*** unknown target architecture $arch) ;;
6655
        esac
6656
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/disassemble.c binutils-2.27-zip/opcodes/disassemble.c
6657
--- binutils-2.27/opcodes/disassemble.c 2016-08-03 03:36:54.000000000 -0400
6658
+++ binutils-2.27-zip/opcodes/disassemble.c     2016-12-31 18:02:03.139162969 -0500
6659
@@ -98,6 +98,7 @@
6660
 #define ARCH_xtensa
6661
 #define ARCH_z80
6662
 #define ARCH_z8k
6663
+#define ARCH_zip
6664
 #define INCLUDE_SHMEDIA
6665
 #endif
6666
 
6667
@@ -495,6 +496,11 @@
6668
        disassemble = print_insn_z8002;
6669
       break;
6670
 #endif
6671
+#ifdef ARCH_zip
6672
+    case bfd_arch_zip:
6673
+       disassemble = zip_get_disassembler(abfd);
6674
+       break;
6675
+#endif
6676
 #ifdef ARCH_vax
6677
     case bfd_arch_vax:
6678
       disassemble = print_insn_vax;
6679
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/Makefile.am binutils-2.27-zip/opcodes/Makefile.am
6680
--- binutils-2.27/opcodes/Makefile.am   2016-08-03 03:36:54.000000000 -0400
6681
+++ binutils-2.27-zip/opcodes/Makefile.am       2017-01-05 08:28:32.000000000 -0500
6682
@@ -86,7 +86,9 @@
6683
        w65-opc.h \
6684
        xc16x-desc.h xc16x-opc.h \
6685
        xstormy16-desc.h xstormy16-opc.h \
6686
-       z8k-opc.h
6687
+       z8k-opc.h \
6688
+       zip-opc.h \
6689
+       zip-dis.h
6690
 
6691
 # C source files that correspond to .o's ending up in libopcodes
6692
 # for all machines.
6693
@@ -269,7 +271,9 @@
6694
        xgate-dis.c \
6695
        xgate-opc.c \
6696
        z80-dis.c \
6697
-       z8k-dis.c
6698
+       z8k-dis.c \
6699
+       zip-dis.c \
6700
+       zip-opc.c
6701
 
6702
 # C source files that correspond to .o's ending up in libopcodes.
6703
 LIBOPCODES_CFILES = \
6704
@@ -346,7 +350,6 @@
6705
        touch stamp-lib
6706
 
6707
 libopcodes.a: stamp-lib ; @true
6708
-
6709
 POTFILES = $(HFILES) $(CFILES)
6710
 po/POTFILES.in: @MAINT@ Makefile
6711
        for f in $(POTFILES); do echo $$f; done | LC_ALL=C sort > tmp \
6712
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/Makefile.in binutils-2.27-zip/opcodes/Makefile.in
6713
--- binutils-2.27/opcodes/Makefile.in   2016-08-03 03:36:54.000000000 -0400
6714
+++ binutils-2.27-zip/opcodes/Makefile.in       2017-01-05 08:28:04.000000000 -0500
6715
@@ -386,7 +386,9 @@
6716
        w65-opc.h \
6717
        xc16x-desc.h xc16x-opc.h \
6718
        xstormy16-desc.h xstormy16-opc.h \
6719
-       z8k-opc.h
6720
+       z8k-opc.h \
6721
+       zip-opc.h \
6722
+       zip-dis.h
6723
 
6724
 
6725
 # C source files that correspond to .o's ending up in libopcodes
6726
@@ -570,7 +572,9 @@
6727
        xgate-dis.c \
6728
        xgate-opc.c \
6729
        z80-dis.c \
6730
-       z8k-dis.c
6731
+       z8k-dis.c \
6732
+       zip-dis.c \
6733
+       zip-opc.c
6734
 
6735
 
6736
 # C source files that correspond to .o's ending up in libopcodes.
6737
@@ -974,6 +978,8 @@
6738
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xtensa-dis.Plo@am__quote@
6739
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/z80-dis.Plo@am__quote@
6740
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/z8k-dis.Plo@am__quote@
6741
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zip-dis.Plo@am__quote@
6742
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/zip-opc.Plo@am__quote@
6743
 
6744
 .c.o:
6745
 @am__fastdepCC_TRUE@   $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
6746
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/zip-dis.c binutils-2.27-zip/opcodes/zip-dis.c
6747
--- binutils-2.27/opcodes/zip-dis.c     1969-12-31 19:00:00.000000000 -0500
6748
+++ binutils-2.27-zip/opcodes/zip-dis.c 2017-03-03 09:34:03.983308793 -0500
6749
@@ -0,0 +1,474 @@
6750
+////////////////////////////////////////////////////////////////////////////////
6751
+//
6752
+// Filename:   zip-dis.c
6753
+//
6754
+// Project:    Zip CPU backend for GNU Binutils
6755
+//
6756
+// Purpose:
6757
+//
6758
+// Creator:    Dan Gisselquist, Ph.D.
6759
+//             Gisselquist Technology, LLC
6760
+//
6761
+////////////////////////////////////////////////////////////////////////////////
6762
+//
6763
+// Copyright (C) 2016-2017, Gisselquist Technology, LLC
6764
+//
6765
+// This program is free software (firmware): you can redistribute it and/or
6766
+// modify it under the terms of  the GNU General Public License as published
6767
+// by the Free Software Foundation, either version 3 of the License, or (at
6768
+// your option) any later version.
6769
+//
6770
+// This program is distributed in the hope that it will be useful, but WITHOUT
6771
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
6772
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6773
+// for more details.
6774
+//
6775
+// You should have received a copy of the GNU General Public License along
6776
+// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
6777
+// target there if the PDF file isn't present.)  If not, see
6778
+// <http://www.gnu.org/licenses/> for a copy.
6779
+//
6780
+// License:    GPL, v3, as defined and found on www.gnu.org,
6781
+//             http://www.gnu.org/licenses/gpl.html
6782
+//
6783
+//
6784
+////////////////////////////////////////////////////////////////////////////////
6785
+#include "config.h"
6786
+
6787
+#include <stdio.h>
6788
+#include <stdint.h>
6789
+#include <ctype.h>
6790
+#include <strings.h>
6791
+#include <string.h>
6792
+#include <assert.h>
6793
+
6794
+#include "zip-opc.h"
6795
+#include "zip-dis.h"
6796
+
6797
+static inline  int
6798
+TWOWORD_LOAD(uint32_t one, uint32_t two) {
6799
+       // BREV followed by LODILO
6800
+       if (((one&0x87c40000)==0x02000000)&&((two&0x87c40000)==0x02400000)
6801
+               // Must be to the same register too, and on the same condition
6802
+               &&(((one^two)&0xf8380000)==0))
6803
+               return 1;
6804
+       return 0;
6805
+}
6806
+
6807
+static inline  int
6808
+OFFSET_PC_MOV(uint32_t ins) {
6809
+       // 0.xxxx.01101.ccc.0.1111.0.iiiiiiiiiiiii
6810
+       // 0xxx.x011.01cc.c011.110i.iiii.iiii.iiii
6811
+       //
6812
+       return ((ins & 0x87c7e000)==0x0343c000);
6813
+}
6814
+
6815
+static inline  int
6816
+TWOWORD_LJMP(uint32_t iword) {
6817
+       // LJMP a long jump instruction, for which the address of the target
6818
+       // is found in the next word
6819
+       if (iword==0x7c87c000)
6820
+               return 1;
6821
+       // Now, the CIS form ... an
6822
+       // Unconditional LJMP in the second half word
6823
+       if ((iword&0x80007fff)==0x80007cf8)
6824
+               return 1;
6825
+       return 0;
6826
+}
6827
+
6828
+
6829
+static inline  int
6830
+TWOWORD_JSR(uint32_t iword, uint32_t nxtword) {
6831
+       // First word moves the return address to R0
6832
+       if (iword != 0x0343c001)
6833
+               return 0;
6834
+       // Second word is a BRA statement to ... anywhere
6835
+       // 0.1111.00010.ccc.0.iiiiiiiiiiiiiiiiii
6836
+       // 0111.1000.10cc.c0ii.iiii.iiii.iiii.iiii
6837
+       if ((nxtword&0xffc40000) == 0x78800000)
6838
+               return 1;
6839
+       return 0;
6840
+}
6841
+
6842
+static inline  int
6843
+THREEWORD_LJSR(uint32_t iword, uint32_t nxtword) {
6844
+       // First word moves the return address to R0
6845
+       if (iword!=0x0343c002)
6846
+               return 0;
6847
+       // Second word is an LJMP statement
6848
+       if (nxtword==0x7c87c000)
6849
+               return 1;
6850
+       return 0;
6851
+}
6852
+
6853
+static inline  int
6854
+TWOWORD_CIS_JSR(uint32_t iword) {
6855
+       // MOV 2(PC) | LOD (PC),PC
6856
+       //
6857
+       // 1.0000.111.1.1111.010
6858
+       //                      1.1111.100.1.1111.000
6859
+       if (iword == 0x87fafcf8)
6860
+               return 1;
6861
+       return 0;
6862
+}
6863
+
6864
+static inline  int
6865
+CIS_JSR(uint32_t iword __attribute__((unused)) ) {
6866
+       if (TWOWORD_CIS_JSR(iword))
6867
+               return 1;
6868
+       // MOV 1(PC) | MOV Rx,PC
6869
+       //
6870
+       // 1.0000.111.1.1111.001
6871
+       //                      1.1111.111.1.xxxx.000
6872
+       if ((iword&0xffffff87) == 0x87f9ff80)
6873
+               return 1;
6874
+       return 0;
6875
+}
6876
+
6877
+static inline  int
6878
+POSSIBLE_TWOWORD_BEGINNING(uint32_t iword) {
6879
+       // Unconditional LJMP
6880
+       if (TWOWORD_LJMP(iword))
6881
+               return 1;
6882
+       // MOV 1(PC),PC
6883
+       if (iword == 0x0343c001)
6884
+               return 1;
6885
+       // MOV 2(PC),PC
6886
+       if (iword == 0x0343c002)
6887
+               return 1;
6888
+       if (TWOWORD_CIS_JSR(iword))
6889
+               return 1;
6890
+       // The conditional LJMP is three words, which we don't handle ...
6891
+       // Any BREV command could be the beginning of a twoword instruction
6892
+       //
6893
+       // Of course, the point here is to determine whether we should (or need
6894
+       // to) read a second word from our read-memory function.  Reading a
6895
+       // second word, given that the first is a BREV, isn't a problem since a
6896
+       // program can't end on/with a BREV instruction.
6897
+       //
6898
+       // BREV #,Rx
6899
+       if ((iword&0x87c40000)==0x02000000)
6900
+               return 1;
6901
+       return 0;
6902
+}
6903
+
6904
+static uint32_t
6905
+zip_bitreverse(uint32_t v) {
6906
+       uint32_t r=0, b;
6907
+       for(b=0; b<32; b++, v>>=1)
6908
+               r = (r<<1)|(v&1);
6909
+       return r;
6910
+}
6911
+
6912
+static inline  uint32_t
6913
+TWOWORD_VALUE(uint32_t one, uint32_t two) {
6914
+       return ((two&0x0ffff)|(zip_bitreverse(one&0x0ffff)));
6915
+}
6916
+
6917
+static long
6918
+zip_sbits(const long val, const int bits) {
6919
+       long    r;
6920
+
6921
+       r = val & ((1l<<bits)-1);
6922
+       if (r & (1l << (bits-1)))
6923
+               r |= (-1l << bits);
6924
+       return r;
6925
+}
6926
+
6927
+static unsigned long
6928
+zip_ubits(const long val, const int bits) {
6929
+       unsigned long r = val & ((1l<<bits)-1);
6930
+       return r;
6931
+}
6932
+
6933
+static int
6934
+zip_getbits(const ZIPI ins, const int which)
6935
+{
6936
+       if (which & 0x40000000) {
6937
+               return zip_sbits(ins>>(which & 0x03f), (which>>8)&0x03f);
6938
+       } else { // if (which &0x03f)
6939
+               return zip_ubits(ins>>(which & 0x03f), (which>>8)&0x03f)
6940
+                       + ((which>>16)&0x0ff);
6941
+       }
6942
+}
6943
+
6944
+static void
6945
+zipi_to_halfstring(const uint32_t addr, const ZIPI ins, const ZIPI nxtword, char *line, const ZOPCODE *listp, uint32_t *refaddr)
6946
+{
6947
+       *refaddr = 0;
6948
+
6949
+       if ((TWOWORD_LOAD(ins,nxtword))&&(listp==zip_oplist)) {
6950
+               int cv = zip_getbits(ins, ZIP_BITFIELD(3,19)); // The condition
6951
+               int dv = zip_getbits(ins, ZIP_REGFIELD(27)); // The destination
6952
+
6953
+               *refaddr = TWOWORD_VALUE(ins,nxtword);
6954
+
6955
+               sprintf(line, "%s%s", "LDI", zip_ccstr[cv]);
6956
+               sprintf(line, "%-11s", line);
6957
+               sprintf(line, "%s0x%08x", line, *refaddr);
6958
+               sprintf(&line[strlen(line)], ",%s", zip_regstr[dv]);
6959
+
6960
+               return;
6961
+       } else if (TWOWORD_JSR(ins, nxtword)) {
6962
+               int cv = zip_getbits(nxtword, ZIP_BITFIELD(3,19));
6963
+               int iv = zip_sbits(nxtword, 18);
6964
+
6965
+               *refaddr = iv + addr + 8;
6966
+               sprintf(line, "%s%s", "JSR", zip_ccstr[cv]);
6967
+               sprintf(line, "%-11s", line);
6968
+               sprintf(line, "%s0x%08x", line, *refaddr);
6969
+
6970
+               return;
6971
+       } else if (TWOWORD_CIS_JSR(ins)) {
6972
+               *refaddr = nxtword;
6973
+               sprintf(line, "%-11s", "JSR");
6974
+               sprintf(line, "%s0x%08x", line, *refaddr);
6975
+               return;
6976
+       } else if (CIS_JSR(ins)) {
6977
+               int ra = zip_getbits(ins, ZIP_REGFIELD(3));
6978
+               sprintf(line, "%-11s%s", "JSR", zip_regstr[ra]);
6979
+               return;
6980
+       } else if (OFFSET_PC_MOV(ins)) {
6981
+               int     cv = zip_getbits(ins, ZIP_BITFIELD(3,19));
6982
+               int     dv = zip_getbits(ins, ZIP_REGFIELD(27));
6983
+               int     iv = zip_sbits(ins, 13);
6984
+               uint32_t        ref;
6985
+
6986
+               ref = (iv<<2) + addr + 4;
6987
+
6988
+               sprintf(line, "%s%s", "MOV", zip_ccstr[cv]);
6989
+               sprintf(line, "%-11s", line);
6990
+               sprintf(line, "%s0x%08x", line, ref);
6991
+               sprintf(line, "%s,%s", line, zip_regstr[dv]);
6992
+
6993
+               *refaddr = ref;
6994
+               return;
6995
+       }
6996
+
6997
+       int     i;
6998
+       for(i=0; i<nzip_oplist; i++) {
6999
+               if (((~zip_oplist[i].s_mask)&zip_oplist[i].s_val)!=0) {
7000
+                       printf("Instruction %d, %s, fails consistency check\n",
7001
+                               i, zip_oplist[i].s_opstr);
7002
+                       printf("%08x & %08x = %08x != %08x\n",
7003
+                               zip_oplist[i].s_mask,
7004
+                               zip_oplist[i].s_val,
7005
+                               (~zip_oplist[i].s_mask)&zip_oplist[i].s_val,
7006
+                               0);
7007
+                       assert(((~zip_oplist[i].s_mask)&zip_oplist[i].s_val)==0);
7008
+               }
7009
+       } line[0] = '\0';
7010
+       for(i=0; (listp[i].s_mask != 0); i++) {
7011
+               // printf("%2d: %6s %08x & %08x == %08x\n",
7012
+                       // i, zip_oplist[i].s_opstr, ins,
7013
+                       // zip_oplist[i].s_mask, zip_oplist[i].s_val);
7014
+               if ((ins & listp[i].s_mask) == listp[i].s_val) {
7015
+                       // Write the opcode onto our line
7016
+                       sprintf(line, "%s", listp[i].s_opstr);
7017
+                       if (listp[i].s_cf != ZIP_OPUNUSED) {
7018
+                               int bv = zip_getbits(ins, listp[i].s_cf);
7019
+                               strcat(line, zip_ccstr[bv]);
7020
+                       } sprintf(line, "%-11s", line); // Pad it to 11 chars
7021
+
7022
+                       int     ra = -1, rb = -1, rr = -1, imv = 0;
7023
+
7024
+                       if (listp[i].s_result != ZIP_OPUNUSED)
7025
+                               rr = zip_getbits(ins, listp[i].s_result);
7026
+                       if (listp[i].s_ra != ZIP_OPUNUSED)
7027
+                               ra = zip_getbits(ins, listp[i].s_ra);
7028
+                       if (listp[i].s_rb != ZIP_OPUNUSED)
7029
+                               rb = zip_getbits(ins, listp[i].s_rb);
7030
+                       if (listp[i].s_i != ZIP_OPUNUSED)
7031
+                               imv = zip_getbits(ins, listp[i].s_i);
7032
+
7033
+                       if ((listp[i].s_rb != ZIP_OPUNUSED)&&(rb == 15))
7034
+                               imv <<= 2;
7035
+
7036
+                       // Treat stores special
7037
+                       if ((strncasecmp("SW",listp[i].s_opstr, 2)==0)
7038
+                               ||(strncasecmp("SH",listp[i].s_opstr, 2)==0)
7039
+                               ||(strncasecmp("SB",listp[i].s_opstr, 2)==0)) {
7040
+                               strcat(line, zip_regstr[ra]);
7041
+                               strcat(line, ",");
7042
+
7043
+                               if (listp[i].s_i != ZIP_OPUNUSED) {
7044
+                                       if (listp[i].s_rb == ZIP_OPUNUSED)
7045
+                                               sprintf(&line[strlen(line)],
7046
+                                                       "($%d)", imv);
7047
+                                       else if (imv != 0)
7048
+                                               sprintf(&line[strlen(line)],
7049
+                                                       "$%d", imv);
7050
+                               } if (listp[i].s_rb != ZIP_OPUNUSED) {
7051
+                                       sprintf(&line[strlen(line)],
7052
+                                               "(%s)", zip_regstr[rb]);
7053
+                               }
7054
+                       // Treat long jumps special
7055
+                       } else if (strncasecmp("LJMP",listp[i].s_opstr, 3)==0) {
7056
+                               sprintf(&line[strlen(line)], "@0x%08x", nxtword);
7057
+                               *refaddr = nxtword;
7058
+                       // Treat relative jumps (branches) specially as well
7059
+                       } else if ((toupper(listp[i].s_opstr[0]=='B'))
7060
+                               &&(strcasecmp(listp[i].s_opstr,"BUSY")!=0)
7061
+                               &&(strcasecmp(listp[i].s_opstr,"BREV")!=0)
7062
+                               &&(strcasecmp(listp[i].s_opstr,"BRK")!=0)
7063
+                               &&(addr != 0)) {
7064
+                               // Branch instruction: starts with B and isn't
7065
+                               // BREV (bit reverse), BRK (break), or
7066
+                               // BUSY
7067
+                               uint32_t target = addr;
7068
+
7069
+                               target += zip_getbits(ins, listp[i].s_i)+4;
7070
+                               sprintf(&line[strlen(line)], "@0x%08x", target);
7071
+                               *refaddr = target;
7072
+                       } else {
7073
+                               int memop = 0;
7074
+                               if (('L'==toupper(listp[i].s_opstr[0]))
7075
+                                       &&(('W'==toupper(listp[i].s_opstr[1]))
7076
+                                        ||('H'==toupper(listp[i].s_opstr[1]))
7077
+                                        ||('B'==toupper(listp[i].s_opstr[1])))
7078
+                                       &&(!listp[i].s_opstr[2]))
7079
+                                       memop = 1;
7080
+
7081
+                               if (listp[i].s_i != ZIP_OPUNUSED) {
7082
+                                       if((memop)&&(listp[i].s_rb == ZIP_OPUNUSED))
7083
+                                               sprintf(&line[strlen(line)],
7084
+                                                       "($%d)", imv);
7085
+                                       else if((memop)&&(imv != 0))
7086
+                                               sprintf(&line[strlen(line)],
7087
+                                                       "%d", imv);
7088
+                                       else if((!memop)&&((imv != 0)||(listp[i].s_rb == ZIP_OPUNUSED)))
7089
+                                               sprintf(&line[strlen(line)],
7090
+                                                       "$%d%s", imv,
7091
+                                                       (listp[i].s_rb!=ZIP_OPUNUSED)?"+":"");
7092
+                               } if (listp[i].s_rb != ZIP_OPUNUSED) {
7093
+                                       if (memop)
7094
+                                               sprintf(&line[strlen(line)],
7095
+                                                       "(%s)", zip_regstr[rb]);
7096
+                                       else
7097
+                                               strcat(line, zip_regstr[rb]);
7098
+                               } if(((listp[i].s_i != ZIP_OPUNUSED)||(listp[i].s_rb != ZIP_OPUNUSED))
7099
+                                       &&((listp[i].s_ra != ZIP_OPUNUSED)||(listp[i].s_result != ZIP_OPUNUSED)))
7100
+                                       strcat(line, ",");
7101
+
7102
+                               if (listp[i].s_ra != ZIP_OPUNUSED) {
7103
+                                       strcat(line, zip_regstr[ra]);
7104
+                               } else if (listp[i].s_result != ZIP_OPUNUSED) {
7105
+                                       strcat(line, zip_regstr[rr]);
7106
+                               }
7107
+                       }
7108
+                       break;
7109
+               }
7110
+       } if (line[0] == '\0') {
7111
+               sprintf(line, "ILL %08x", ins);
7112
+       }
7113
+}
7114
+
7115
+static void
7116
+zipi_to_double_string(const uint32_t addr, const ZIPI ins, const ZIPI nxtword, char *la, char *lb, uint32_t *refaddr) {
7117
+       zipi_to_halfstring(addr, ins, nxtword, la, zip_oplist, refaddr);
7118
+       if (lb) {
7119
+               if ((ins & 0x80000000)&&(!CIS_JSR(ins))) {
7120
+                       zipi_to_halfstring(addr, ins, nxtword,
7121
+                                       lb, zip_opbottomlist, refaddr);
7122
+                       *refaddr = 0;
7123
+               } else lb[0] = '\0';
7124
+       }
7125
+}
7126
+
7127
+static int
7128
+print_zip_insn(bfd_vma vma, disassemble_info *info)
7129
+{
7130
+       ZIPI    iword, nxtword;
7131
+       char    astr[80], bstr[80];
7132
+       unsigned char ibytes[12];
7133
+       uint32_t        refaddr = 0;
7134
+
7135
+       // Deal with misalignment ...
7136
+       if ((vma & 3)!=0) {
7137
+               int     consumed = 0;
7138
+
7139
+               // Consume up to four bytes, after a zero (possibly multiple),
7140
+               // though, align ourselves
7141
+               (*info->read_memory_func)(vma, ibytes, 4, info);
7142
+               while((consumed<4)&&(ibytes[consumed]!=0))
7143
+                       consumed++;
7144
+               while((consumed<4)&&(ibytes[consumed]==0))
7145
+                       consumed++;
7146
+               if (consumed <= 1)
7147
+                       consumed = 1;
7148
+               return consumed;
7149
+       }
7150
+
7151
+       // Always read the first word
7152
+       (*info->read_memory_func)(vma, ibytes, 4, info);
7153
+       iword  = (ibytes[0]<<24)|(ibytes[1]<<16)|(ibytes[2]<<8)|(ibytes[3]);
7154
+       // Only if we know we have a second do we read the second
7155
+       if ((POSSIBLE_TWOWORD_BEGINNING(iword))
7156
+               // We also test for reading past the end of the buffer
7157
+               &&((*info->read_memory_func)(vma, ibytes, 8, info) ==0)) {
7158
+               nxtword= (ibytes[4]<<24)|(ibytes[5]<<16)|(ibytes[6]<<8)|(ibytes[7]);
7159
+       } else {
7160
+               const int NOOP_CODE = 0x76000000;
7161
+               nxtword = NOOP_CODE;
7162
+       }
7163
+
7164
+       bstr[0] = '\0';
7165
+
7166
+       if (THREEWORD_LJSR(iword,nxtword)) {
7167
+               sprintf(astr, "%-11s", "LJSR");
7168
+               if ((*info->read_memory_func)(vma, ibytes, 12, info) ==0)
7169
+                       refaddr = (ibytes[8]<<24)|(ibytes[9]<<16)|(ibytes[10]<<8)|(ibytes[11]);
7170
+               sprintf(&astr[strlen(astr)], "@0x%08x", refaddr);
7171
+       } else if (TWOWORD_CIS_JSR(iword)) {
7172
+               refaddr = nxtword;
7173
+               sprintf(astr, "%-11s0x%08x", "JSR", refaddr);
7174
+       } else
7175
+               zipi_to_double_string(vma, iword, nxtword, astr, bstr,&refaddr);
7176
+
7177
+       if (bstr[0])
7178
+               sprintf(astr, "%-25s | %s", astr,bstr);
7179
+
7180
+       // Remove any trailing spaces
7181
+       unsigned ln = strlen(astr);
7182
+       while((ln > 0)&&(isspace(astr[ln-1])))
7183
+               astr[--ln] = '\0';
7184
+
7185
+       (*info->fprintf_func)(info->stream, "%s", astr);
7186
+
7187
+       if ((info->print_address_func)&&(refaddr != 0)) {
7188
+               if (ln < 25)
7189
+                       (*info->fprintf_func)(info->stream, "%*s", 25-ln, "");
7190
+
7191
+               (*info->fprintf_func)(info->stream, " // ");
7192
+               (*info->print_address_func)(refaddr, info);
7193
+       }
7194
+
7195
+       // Normal LOD (PC),PC = 0x7c87c000
7196
+       //      1'b0, 4'hf, 5'h12, 3'h0, 1'b1, 4'hf, 14'h00
7197
+       //      0111 1100 1000 0111 1100 0000 0000 0000
7198
+       // or CIS  x | LOD (PC),PC
7199
+       //      1'b1, 4'hx 5'hx 1'b0 2'bx 5'hx 4'hf 5'h12 1'b1 4'hf
7200
+       //      1xxx xxxx xx0x xxxx xx11 1110 0101 1111
7201
+       //      0x80203fff mask, val = 0x80003e5f
7202
+       if (THREEWORD_LJSR(iword,nxtword))
7203
+               return 12;
7204
+       if (TWOWORD_LJMP(iword))
7205
+               return 8;
7206
+       // Two word load: Destination registers and conditional execution bits
7207
+       // must match as well.
7208
+       if (TWOWORD_LOAD(iword,nxtword))
7209
+               return 8;
7210
+       if (TWOWORD_JSR(iword,nxtword))
7211
+               return 8;
7212
+       if (TWOWORD_CIS_JSR(iword))
7213
+               return 8;
7214
+       return 4;
7215
+}
7216
+
7217
+
7218
+disassembler_ftype
7219
+zip_get_disassembler(bfd *abfd ATTRIBUTE_UNUSED)
7220
+{
7221
+       return print_zip_insn;
7222
+}
7223
+
7224
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/zip-dis.h binutils-2.27-zip/opcodes/zip-dis.h
7225
--- binutils-2.27/opcodes/zip-dis.h     1969-12-31 19:00:00.000000000 -0500
7226
+++ binutils-2.27-zip/opcodes/zip-dis.h 2016-12-31 18:10:03.512012534 -0500
7227
@@ -0,0 +1,45 @@
7228
+////////////////////////////////////////////////////////////////////////////////
7229
+//
7230
+// Filename:   zip-dis.h
7231
+//
7232
+// Project:    Zip CPU backend for GNU Binutils
7233
+//
7234
+// Purpose:
7235
+//
7236
+// Creator:    Dan Gisselquist, Ph.D.
7237
+//             Gisselquist Technology, LLC
7238
+//
7239
+////////////////////////////////////////////////////////////////////////////////
7240
+//
7241
+// Copyright (C) 2016, Gisselquist Technology, LLC
7242
+//
7243
+// This program is free software (firmware): you can redistribute it and/or
7244
+// modify it under the terms of  the GNU General Public License as published
7245
+// by the Free Software Foundation, either version 3 of the License, or (at
7246
+// your option) any later version.
7247
+//
7248
+// This program is distributed in the hope that it will be useful, but WITHOUT
7249
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
7250
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7251
+// for more details.
7252
+//
7253
+// You should have received a copy of the GNU General Public License along
7254
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
7255
+// target there if the PDF file isn't present.)  If not, see
7256
+// <http://www.gnu.org/licenses/> for a copy.
7257
+//
7258
+// License:    GPL, v3, as defined and found on www.gnu.org,
7259
+//             http://www.gnu.org/licenses/gpl.html
7260
+//
7261
+//
7262
+////////////////////////////////////////////////////////////////////////////////
7263
+#ifndef        ZIP_DIS_H
7264
+#define        ZIP_DIS_H
7265
+
7266
+#include "config.h"
7267
+#include "dis-asm.h"
7268
+
7269
+extern disassembler_ftype
7270
+zip_get_disassembler(bfd *abfd);
7271
+
7272
+#endif
7273
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/zip-opc.c binutils-2.27-zip/opcodes/zip-opc.c
7274
--- binutils-2.27/opcodes/zip-opc.c     1969-12-31 19:00:00.000000000 -0500
7275
+++ binutils-2.27-zip/opcodes/zip-opc.c 2017-03-06 14:00:55.404955681 -0500
7276
@@ -0,0 +1,362 @@
7277
+////////////////////////////////////////////////////////////////////////////////
7278
+//
7279
+// Filename:   zip-opc.c
7280
+//
7281
+// Project:    Zip CPU backend for GNU Binutils
7282
+//
7283
+// Purpose:
7284
+//
7285
+// Creator:    Dan Gisselquist, Ph.D.
7286
+//             Gisselquist Technology, LLC
7287
+//
7288
+////////////////////////////////////////////////////////////////////////////////
7289
+//
7290
+// Copyright (C) 2015-2017, Gisselquist Technology, LLC
7291
+//
7292
+// This program is free software (firmware): you can redistribute it and/or
7293
+// modify it under the terms of  the GNU General Public License as published
7294
+// by the Free Software Foundation, either version 3 of the License, or (at
7295
+// your option) any later version.
7296
+//
7297
+// This program is distributed in the hope that it will be useful, but WITHOUT
7298
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
7299
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7300
+// for more details.
7301
+//
7302
+// You should have received a copy of the GNU General Public License along
7303
+// with this program.  (It's in the $(ROOT)/doc directory.  Run make with no
7304
+// target there if the PDF file isn't present.)  If not, see
7305
+// <http://www.gnu.org/licenses/> for a copy.
7306
+//
7307
+// License:    GPL, v3, as defined and found on www.gnu.org,
7308
+//             http://www.gnu.org/licenses/gpl.html
7309
+//
7310
+//
7311
+////////////////////////////////////////////////////////////////////////////////
7312
+#include "zip-opc.h"
7313
+
7314
+const  char    *zip_regstr[49] = {
7315
+       "R0", "R1", "R2", "R3",
7316
+       "R4", "R5", "R6", "R7",
7317
+       "R8", "R9", "R10","R11",
7318
+       "R12","SP", "CC", "PC",
7319
+       "uR0", "uR1", "uR2", "uR3",
7320
+       "uR4", "uR5", "uR6", "uR7",
7321
+       "uR8", "uR9", "uR10", "uR11",
7322
+       "uR12", "uSP", "uCC", "uPC",
7323
+       "sR0", "sR1", "sR2", "sR3",
7324
+       "sR4", "sR5", "sR6", "sR7",
7325
+       "sR8", "sR9", "sR10","sR11",
7326
+       "sR12","sSP", "sCC", "sPC", "rILL"
7327
+};
7328
+
7329
+const  char    *zip_ccstr[8] = {
7330
+       "",  ".Z",  ".LT", ".C",
7331
+       ".V",".NZ", ".GE", ".NC"
7332
+};
7333
+
7334
+static const ZOPCODE   zip_oplist_raw[] = {
7335
+       // Special case instructions.  These are general instructions, but with
7336
+       // special opcodes
7337
+       // Conditional branches
7338
+       //      0.1111.0111.ccc.0.111.10iiiii--
7339
+       //      0111 1011 11cc c011 110i iiii iiii iiii
7340
+       { "BUSY", 0xffc7fffc, 0x7883fffc, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7341
+       { "BZ",  0xfffc0000, 0x78880000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7342
+       { "BLT", 0xfffc0000, 0x78900000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7343
+       { "BC",  0xfffc0000, 0x78980000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7344
+       { "BV",  0xfffc0000, 0x78a00000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7345
+       { "BNZ",  0xfffc0000, 0x78a80000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7346
+       { "BGE",  0xfffc0000, 0x78b00000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7347
+       { "BNC",  0xfffc0000, 0x78b80000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_OPUNUSED },
7348
+       { "BRA",  0xffc40000, 0x78800000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7349
+       // Changes/updates to CC, based upon LDI
7350
+       { "TRAP", 0xfffffff0, 0x76000000, ZIP_OPUNUSED,ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7351
+       { "TRAP", 0xff800000, 0x76000000, ZIP_OPUNUSED,ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7352
+       // BREV based traps
7353
+       { "TRAP", 0xffc7ffff, 0x72000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7354
+       // LDILO based traps
7355
+       { "TRAP",0xffc4ffff, 0x72400000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7356
+       { "TRAP",0xffc40000, 0x72400000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7357
+       // CLR -- a LDI of zero
7358
+       //      0.rrrr.1100.iiiiiii--
7359
+       //      0rrr r110 0...
7360
+       { "CLR",  0x87ffffff, 0x06000000, ZIP_REGFIELD(27),ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7361
+       // BREV based clears
7362
+       { "CLR", 0x87c7ffff, 0x02000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7363
+       // HALT
7364
+       //      0.1110.00011.ccc.0.0000000000010
7365
+       //      0111.0000.11cc.c000.0000.0000.0000.0010
7366
+       { "HALT", 0xffc7ffff, 0x70c00010, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7367
+       // The "wait" instruction is identical, with the only difference being
7368
+       // the interrrupt context of the processor.  Well, almost.  To
7369
+       // facilitate waits from supervisor mode, the wait instruction
7370
+       // explicitly forces the CPU into user mode.
7371
+       { "WAIT", 0xffc7ffff, 0x70c00030, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7372
+       // 1.0011.11000.000.0000...... 5f ? A carefully chosen illegal insn ??
7373
+       // "INT", 0xff10007f, 0x9e00005f, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19),
7374
+       // Return to user space
7375
+       { "RTU", 0xffc7ffff, 0x70c00020, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7376
+       // The return instruction: JMP R0 (possibly conditional) = MOV R0,PC
7377
+       { "RTN", 0xffc7ffff, 0x7b400000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7378
+       // JMP (possibly a conditional jump, if not covered by branches above)
7379
+       // 0.1111.01101.ccc.a.rrrr.biiiiiiiiiiiiiiii
7380
+       // 0111.1011.01cc.c0rr.rrbi.iiii.iiii.iiii              MOV x,PC
7381
+       { "JMP",  0xffc40000, 0x7b400000, ZIP_OPUNUSED,ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(13,0), ZIP_BITFIELD(3,19) },
7382
+       // 0.1111.1100.ii.iiii.iiii.iiii.iiii.iiii.iiii
7383
+       // 0111.1110.0iii.iiii.iiii.iiii.iiii.iiii              LDI x,PC
7384
+       { "JMPI", 0xff800000, 0x7e000000, ZIP_REGFIELD(27),ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(23,0), ZIP_OPUNUSED },
7385
+       // 0.1111.10010.000.1.1111.000000000000000
7386
+       // 0111.1100.1000.0111.11ii.iiii.iiii.iiii              LOD (PC),PC
7387
+       { "LJMP", 0xffffffff, 0x7c87c000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7388
+       // NOT : XOR w/ -1
7389
+       //      0.rrrr.00100.ccc.0111.11111111111
7390
+       //      0rrr.r001.00cc.c011.f.f.f.f
7391
+       // { "NOT", 0x87c7ffff, 0x0103ffff, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7392
+       // General instructions
7393
+       // 0rrr.rooo.oocc.cxrr.rrii.iiii.iiii.iiii
7394
+       { "SUB", 0x87c40000, 0x00000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7395
+       { "SUB", 0x87c40000, 0x00040000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7396
+       //
7397
+       { "AND", 0x87c40000, 0x00400000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7398
+       { "AND", 0x87c40000, 0x00440000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7399
+       //
7400
+       { "ADD", 0x87c40000, 0x00800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7401
+       { "ADD", 0x87c40000, 0x00840000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7402
+       //
7403
+       { "OR", 0x87c40000, 0x00c00000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7404
+       { "OR", 0x87c40000, 0x00c40000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7405
+       //
7406
+       { "XOR", 0x87c40000, 0x01000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7407
+       { "XOR", 0x87c40000, 0x01040000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7408
+       //
7409
+       { "LSR", 0x87c40000, 0x01400000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7410
+       { "LSR", 0x87c40000, 0x01440000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7411
+       //
7412
+       { "LSL", 0x87c40000, 0x01800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7413
+       { "LSL", 0x87c40000, 0x01840000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7414
+       //
7415
+       { "ASR", 0x87c40000, 0x01c00000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7416
+       { "ASR", 0x87c40000, 0x01c40000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7417
+       //
7418
+       { "BREV",0x87c40000, 0x02000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7419
+       { "BREV",0x87c40000, 0x02040000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7420
+       //
7421
+       { "LDILO",0x87c40000, 0x02400000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7422
+       { "LDILO",0x87c40000, 0x02440000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7423
+       //
7424
+       //
7425
+       { "MPYUHI", 0x87c40000, 0x02800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7426
+       { "MPYUHI", 0x87c40000, 0x02840000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7427
+       //
7428
+       { "MPYSHI", 0x87c40000, 0x02c00000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7429
+       { "MPYSHI", 0x87c40000, 0x02c40000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7430
+       //
7431
+       { "MPY", 0x87c40000, 0x03000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7432
+       { "MPY", 0x87c40000, 0x03040000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7433
+       //
7434
+       { "MOV", 0x87c42000, 0x03400000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(13,0), ZIP_BITFIELD(3,19) },
7435
+       { "MOV", 0x87c42000, 0x03440000, ZIP_URGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(13,0), ZIP_BITFIELD(3,19) },
7436
+       { "MOV", 0x87c42000, 0x03402000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_URGFIELD(14), ZIP_IMMFIELD(13,0), ZIP_BITFIELD(3,19) },
7437
+       { "MOV", 0x87c42000, 0x03442000, ZIP_URGFIELD(27), ZIP_OPUNUSED, ZIP_URGFIELD(14), ZIP_IMMFIELD(13,0), ZIP_BITFIELD(3,19) },
7438
+       //
7439
+       { "DIVU", 0x87c40000, 0x03800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7440
+       { "DIVU", 0x87c40000, 0x03840000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7441
+       //
7442
+       { "DIVS", 0x87c40000, 0x03c00000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7443
+       { "DIVS", 0x87c40000, 0x03c40000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7444
+       //
7445
+       { "CMP", 0x87c40000, 0x04000000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7446
+       { "CMP", 0x87c40000, 0x04040000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7447
+       { "TST", 0x87c40000, 0x04400000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7448
+       { "TST", 0x87c40000, 0x04440000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7449
+       //
7450
+       { "LW", 0x87c40000, 0x04800000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7451
+       { "LW", 0x87c40000, 0x04840000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7452
+       //
7453
+       { "SW", 0x87c40000, 0x04c00000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7454
+       { "SW", 0x87c40000, 0x04c40000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7455
+       //
7456
+       { "LH", 0x87c40000, 0x05000000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7457
+       { "LH", 0x87c40000, 0x05040000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7458
+       //
7459
+       { "SH", 0x87c40000, 0x05400000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7460
+       { "SH", 0x87c40000, 0x05440000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7461
+       //
7462
+       { "LB", 0x87c40000, 0x05800000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7463
+       { "LB", 0x87c40000, 0x05840000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7464
+       //
7465
+       { "SB", 0x87c40000, 0x05c00000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7466
+       { "SB", 0x87c40000, 0x05c40000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7467
+       //
7468
+       // 0rrr.r101.1
7469
+       { "LDI",  0x87800000, 0x06000000, ZIP_REGFIELD(27),ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(23,0), ZIP_OPUNUSED },
7470
+       // 0111.x111.00.xxxxxxxx
7471
+       { "BREAK", 0xf7ffffff, 0x77000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7472
+       { "BREAK", 0xf7c00000, 0x77000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(22,0), ZIP_OPUNUSED },
7473
+       { "LOCK",  0xf7ffffff, 0x77400000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7474
+       { "LOCK",  0xf7c00000, 0x77400000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(22,0), ZIP_OPUNUSED },
7475
+       // 0.111x.00000.xxx.xxx.xxxx.xxxx.xxxx.xxxx
7476
+       // 0111.x111.11.xxx.xxx.xxxx.xxxx.xxxx.xxxx
7477
+       // SNOOP = SIM w/ no argument(s)
7478
+       { "SIM",  0xf7ffffff, 0x77800000, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7479
+       { "SEXIT",0xf7ffffff, 0x77800100, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7480
+       { "SEXIT",0xf7fffff0, 0x77800310, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7481
+       { "SEXIT",0xf7ffffe0, 0x77800300, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7482
+       { "SEXIT",0xf7ffff00, 0x77800100, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD( 8,0), ZIP_OPUNUSED },
7483
+       { "SDUMP",0xf7ffffff, 0x778002ff, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7484
+       { "SDUMP",0xf7fffff0, 0x77800200, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7485
+       { "SDUMP",0xf7fffff0, 0x77800210, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7486
+       { "SOUT", 0xf7fffff0, 0x77800230, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7487
+       { "SOUT", 0xf7ffffe0, 0x77800220, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7488
+       { "SOUT", 0xf7ffff00, 0x77800400, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD( 8,0), ZIP_OPUNUSED },
7489
+       { "SDUMP",0xf7ffff00, 0x77800200, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD( 8,0), ZIP_OPUNUSED },
7490
+       { "SIM",  0xf7c00000, 0x77800000, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD(22,0), ZIP_OPUNUSED },
7491
+       { "NOOP", 0xf7ffffff, 0x77c00000, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7492
+       { "NEXIT",0xf7ffffff, 0x77c00100, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7493
+       { "NEXIT",0xf7ffff00, 0x77c00100, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD( 8,0), ZIP_OPUNUSED },
7494
+       { "NEXIT",0xf7fffff0, 0x77c00310, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7495
+       { "NEXIT",0xf7ffffe0, 0x77c00300, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7496
+       { "NDUMP",0xf7ffffff, 0x77c002ff, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7497
+       { "NDUMP",0xf7fffff0, 0x77c00200, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7498
+       { "NDUMP",0xf7fffff0, 0x77c00210, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7499
+
7500
+       { "NOUT", 0xf7fffff0, 0x77c00230, ZIP_OPUNUSED, ZIP_URGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7501
+       { "NOUT", 0xf7ffffe0, 0x77c00220, ZIP_OPUNUSED, ZIP_REGFIELD(0), ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7502
+       { "NOUT", 0xf7ffff00, 0x77c00400, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD( 8,0), ZIP_OPUNUSED },
7503
+       { "NDUMP",0xf7ffff00, 0x77c00200, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_OPUNUSED,       ZIP_OPUNUSED },
7504
+       { "NSIM", 0xf7c00000, 0x77c00000, ZIP_OPUNUSED, ZIP_OPUNUSED,    ZIP_OPUNUSED, ZIP_IMMFIELD(22,0), ZIP_OPUNUSED },
7505
+       //
7506
+       //
7507
+       // 0rrr.r11f.ffcc.cxrr.rrii.iiii.iiii.iiii
7508
+       { "FPADD",0x87c43fff, 0x06840000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7509
+       { "FPSUB",0x87c43fff, 0x06c40000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7510
+       { "FPMPY",0x87c43fff, 0x07040000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7511
+       { "FPDIV",0x87c43fff, 0x07440000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(14), ZIP_OPUNUSED, ZIP_BITFIELD(3,19) },
7512
+       { "FPI2F",0x87c40000, 0x07800000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(18,0), ZIP_BITFIELD(3,19) },
7513
+       { "FPI2F",0x87c40000, 0x07840000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7514
+       { "FPF2I",0x87c40000, 0x07c40000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(14), ZIP_IMMFIELD(14,0), ZIP_BITFIELD(3,19) },
7515
+       //
7516
+       //
7517
+       //
7518
+       //
7519
+       //
7520
+       //      16-bit instructions, high side
7521
+       //
7522
+       //
7523
+       //      1.1111.00010.xcc.0iiii.xxxx.xxxxx.xxxxx
7524
+       //      1111.1000.10xc.c0ii.iixx.xxxx.xxxx.xxxx
7525
+       // Mask, val, result, Ra, Rb, I, condition (no conditions for OP_UNDER_TEST)
7526
+       // BRA: 1.1111.011.0.sssssss
7527
+       { "BRA", 0xff800000, 0xf9000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7528
+       // CLR: 1.rrrr.110.00000000
7529
+       { "CLR", 0x87ff0000, 0x86000000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7530
+       // RTN: 1.1111.111.0.0000.000, MOV R0,Pc
7531
+       { "RTN", 0xffff0000, 0xff800000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7532
+       // JMP: 1.1111.111.0.rrrrsss
7533
+       { "JMP", 0xff800000, 0xff000000, ZIP_REGFIELD(27),ZIP_OPUNUSED, ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7534
+       // LJSR: 1.000_0.011_.0.111_1.001 ?.1111.110.1.1111.000
7535
+       // { "LJSR",0xffffffff, 0x83797ef8, ZIP_REGFIELD(27),ZIP_OPUNUSED, ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7536
+       //
7537
+       // 1.rrrr.000.0.sssssss
7538
+       // 1rrr.r000.0sss.ssss
7539
+       { "SUB", 0x87800000, 0x80000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7540
+       // 1.rrrr.000.1.rrrrsss
7541
+       { "SUB", 0x87800000, 0x80800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7542
+       //
7543
+       // 1.rrrr.001.0.sssssss
7544
+       // 1.rrrr.001.1.rrrrsss
7545
+       { "AND", 0x87800000, 0x81000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7546
+       { "AND", 0x87800000, 0x81800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7547
+       //
7548
+       // 1.rrrr.010.0.sssssss
7549
+       // 1.rrrr.010.1.rrrrsss
7550
+       { "ADD", 0x87800000, 0x82000000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7551
+       { "ADD", 0x87800000, 0x82800000, ZIP_REGFIELD(27), ZIP_REGFIELD(27), ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7552
+       //
7553
+       // 1.rrrr.011.a.rrrrsss
7554
+       { "CMP", 0x87800000, 0x83000000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(19), ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7555
+       { "CMP", 0x87800000, 0x83800000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7556
+       //
7557
+       // 1.rrrr.100.0.sssssss
7558
+       // 1.rrrr.100.1.rrrrsss
7559
+       { "LW", 0x87800000, 0x84000000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_SP, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7560
+       { "LW", 0x87800000, 0x84800000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7561
+       // 1.rrrr.101.ssssssss
7562
+       { "SW", 0x87800000, 0x85000000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_SP, ZIP_IMMFIELD(7,16), ZIP_OPUNUSED },
7563
+       // 1.rrrr.110.0.sssssss
7564
+       { "SW", 0x87800000, 0x85800000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7565
+       // 1.rrrr.110.iiiiiiii
7566
+       { "LDI", 0x87000000, 0x86000000, ZIP_REGFIELD(27), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(8,16), ZIP_OPUNUSED },
7567
+       // 1.rrrr.111.1.sssssss
7568
+       { "MOV", 0x87800000, 0x87800000, ZIP_OPUNUSED, ZIP_REGFIELD(27), ZIP_REGFIELD(19), ZIP_IMMFIELD(3,16), ZIP_OPUNUSED },
7569
+       //
7570
+       // 1.rrrr.111.1.rrrrsss
7571
+       // Illegal instruction !!
7572
+       { "ILLV", 0x80000000, 0x80000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(32,16), ZIP_OPUNUSED },
7573
+       // Global illegal instruction
7574
+       { "ILL", 0x00000000, 0x00000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(32,0), ZIP_OPUNUSED }
7575
+};
7576
+
7577
+static const ZOPCODE   zip_opbottomlist_raw[] = {
7578
+       //
7579
+       //
7580
+       //
7581
+       //      16-bit instructions, low side ... treat these as special
7582
+       //
7583
+       //
7584
+       // Mask, val, result, Ra, Rb, I, condition (no conditions for OP_UNDER_TEST)
7585
+       // BRA: 1.xxx_xxxx_xxxx_xxxx_?.111_1.011.0.sssssss
7586
+       { "BRA", 0x80007f80, 0x80007900, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7587
+       // CLR: 1.xxx_xxxx_xxxx_xxxx_?.rrr_r.101.0000_0000
7588
+       { "CLR", 0x800007ff, 0x80000600, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7589
+       // RTN: 1.1111.111.0.0000.000, MOV R0,Pc
7590
+       { "RTN", 0x80007fff, 0x80007f80, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED },
7591
+       // JMP: 1.1111.111.0.rrrrsss
7592
+       { "JMP", 0x80007f80, 0x80007f00, ZIP_REGFIELD(11),ZIP_OPUNUSED, ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7593
+       // LJMP: 1.xxx_xxxx_xxxx_xxxx_?.111_1.100._1.111_1.000
7594
+       { "LJMP", 0x80007fff, 0x80007cf8, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7595
+       //
7596
+       // 1.rrrr.000.0.sssssss
7597
+       { "SUB", 0x80000780, 0x80000000, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7598
+       // 1.rrrr.000.1.rrrrsss
7599
+       { "SUB", 0x80000780, 0x80000080, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7600
+       //
7601
+       // 1.rrrr.001.0.sssssss
7602
+       // 1.rrrr.001.1.rrrrsss
7603
+       { "AND", 0x80000780, 0x80000100, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7604
+       { "AND", 0x80000780, 0x80000180, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7605
+       //
7606
+       // 1.rrrr.010.0.sssssss
7607
+       // 1.rrrr.010.1.rrrrsss
7608
+       { "ADD", 0x80000780, 0x80000200, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7609
+       { "ADD", 0x80000780, 0x80000280, ZIP_REGFIELD(11), ZIP_REGFIELD(11), ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7610
+       //
7611
+       // 1.rrrr.011.a.rrrrsss
7612
+       { "CMP", 0x80000780, 0x80000300, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7613
+       { "CMP", 0x80000780, 0x80000380, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7614
+       //
7615
+       // 1.rrrr.100.0.sssssss
7616
+       // 1.rrrr.100.1.rrrrsss
7617
+       { "LW", 0x80000780, 0x80000400, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_SP, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7618
+       { "LW", 0x80000780, 0x80000480, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7619
+       // 1.rrrr.101.ssssssss
7620
+       { "SW", 0x80000780, 0x80000500, ZIP_OPUNUSED, ZIP_REGFIELD(11), ZIP_SP, ZIP_IMMFIELD(7,0), ZIP_OPUNUSED },
7621
+       { "SW", 0x80000780, 0x80000580, ZIP_OPUNUSED, ZIP_REGFIELD(11), ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7622
+       // 1.rrr_r.110.ssssssss
7623
+       { "LDI", 0x80000700, 0x80000600, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(8,0), ZIP_OPUNUSED },
7624
+       // 1.rrr_r.111_.x.rrr_rsss
7625
+       { "MOV", 0x80000780, 0x80000780, ZIP_REGFIELD(11), ZIP_OPUNUSED, ZIP_REGFIELD(3), ZIP_IMMFIELD(3,0), ZIP_OPUNUSED },
7626
+       //
7627
+       //
7628
+       // Illegal instruction !!
7629
+       { "ILLV",       0x80000000, 0x80000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(15,0), ZIP_OPUNUSED },
7630
+       { "ILL",        0x00000000, 0x00000000, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_OPUNUSED, ZIP_IMMFIELD(15,0), ZIP_OPUNUSED }
7631
+};
7632
+
7633
+const ZOPCODE  *zip_oplist = zip_oplist_raw,
7634
+               *zip_opbottomlist = zip_opbottomlist_raw;
7635
+
7636
+const int      nzip_oplist = (sizeof(zip_oplist_raw)/sizeof(ZOPCODE));
7637
+const int      nzip_opbottom = (sizeof(zip_opbottomlist_raw)/sizeof(ZOPCODE));
7638
+
7639
diff -Naur '--exclude=*.swp' binutils-2.27/opcodes/zip-opc.h binutils-2.27-zip/opcodes/zip-opc.h
7640
--- binutils-2.27/opcodes/zip-opc.h     1969-12-31 19:00:00.000000000 -0500
7641
+++ binutils-2.27-zip/opcodes/zip-opc.h 2017-02-10 17:48:01.761470841 -0500
7642
@@ -0,0 +1,77 @@
7643
+////////////////////////////////////////////////////////////////////////////////
7644
+//
7645
+// Filename:   zip-opc.h
7646
+//
7647
+// Project:    Zip CPU backend for GNU Binutils
7648
+//
7649
+// Purpose:
7650
+//
7651
+// Creator:    Dan Gisselquist, Ph.D.
7652
+//             Gisselquist Technology, LLC
7653
+//
7654
+////////////////////////////////////////////////////////////////////////////////
7655
+//
7656
+// Copyright (C) 2016, Gisselquist Technology, LLC
7657
+//
7658
+// This program is free software (firmware): you can redistribute it and/or
7659
+// modify it under the terms of  the GNU General Public License as published
7660
+// by the Free Software Foundation, either version 3 of the License, or (at
7661
+// your option) any later version.
7662
+//
7663
+// This program is distributed in the hope that it will be useful, but WITHOUT
7664
+// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
7665
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7666
+// for more details.
7667
+//
7668
+// You should have received a copy of the GNU General Public License along
7669
+// with this program.  (It's in the $(ROOT)/doc directory, run make with no
7670
+// target there if the PDF file isn't present.)  If not, see
7671
+// <http://www.gnu.org/licenses/> for a copy.
7672
+//
7673
+// License:    GPL, v3, as defined and found on www.gnu.org,
7674
+//             http://www.gnu.org/licenses/gpl.html
7675
+//
7676
+//
7677
+////////////////////////////////////////////////////////////////////////////////
7678
+#ifndef        ZIP_OPC_H
7679
+#define        ZIP_OPC_H
7680
+
7681
+#include <stdint.h>
7682
+
7683
+// MACROS used in the instruction definition list.
7684
+#define        ZIP_OPUNUSED    -1
7685
+#define        ZIP_BITFIELD(LN,MN)     (((LN&0x0ff)<<8)+(MN&0x0ff)) // A generic bitfield
7686
+#define        ZIP_REGFIELD(MN)        (0x00000400 +(MN&0x0ff)) // Normal register field
7687
+#define        ZIP_URGFIELD(MN)        (0x0100400 +(MN&0x0ff)) // User register field
7688
+#define        ZIP_IMMFIELD(LN,MN)     (0x40000000 + (((LN&0x0ff)<<8)+(MN&0x0ff))) // Sgn extnd
7689
+#define        ZIP_SP  0xd0000
7690
+
7691
+typedef        uint32_t        ZIPI;   // A Zip CPU instruction
7692
+
7693
+typedef        struct {
7694
+       char    s_opstr[8];     // OPCode name
7695
+       ZIPI    s_mask,         // Bits that must match 4 this pattern to match
7696
+               s_val;          // What those masked bits must be
7697
+       //
7698
+       // The following describe not the value, but the bits where there
7699
+       // respective vaules will be found within the instruction.  For example,
7700
+       // an instruction with no immediate will have an s_i value of -1
7701
+       // (ZIP_OPUNUSED), whereas an instruction with an immediate value of -1
7702
+       // might have an s_i value of ZIP_BITFIELD(14,0), or 0x0400.  The
7703
+       // opcode itself will tell you what the value is--not this structure
7704
+       // describing the opcode.
7705
+       //
7706
+       int     s_result,       // Register where the result will be placed
7707
+               s_ra,           // A register, often the result
7708
+               s_rb,           // B register, source operand (if used)
7709
+               s_i,            // Immediate value, added to B if B is used
7710
+               s_cf;           // Condition flags.
7711
+} ZOPCODE;
7712
+
7713
+extern const   char    *zip_regstr[49], *zip_ccstr[8];
7714
+
7715
+extern const ZOPCODE   *zip_oplist, *zip_opbottomlist;
7716
+extern const int       nzip_oplist, nzip_opbottom;
7717
+
7718
+
7719
+#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.