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

Subversion Repositories or1k

[/] [or1k/] [tags/] [start/] [gdb-5.0/] [utils/] [amd-udi/] [mondfe/] [asm.c] - Blame information for rev 106

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

Line No. Rev Author Line
1 106 markom
static char _[] = " @(#)asm.c   5.23 93/10/26 10:17:03, Srini, AMD";
2
/******************************************************************************
3
 * Copyright 1991 Advanced Micro Devices, Inc.
4
 *
5
 * This software is the property of Advanced Micro Devices, Inc  (AMD)  which
6
 * specifically  grants the user the right to modify, use and distribute this
7
 * software provided this notice is not removed or altered.  All other rights
8
 * are reserved by AMD.
9
 *
10
 * AMD MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS
11
 * SOFTWARE.  IN NO EVENT SHALL AMD BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL
12
 * DAMAGES IN CONNECTION WITH OR ARISING FROM THE FURNISHING, PERFORMANCE, OR
13
 * USE OF THIS SOFTWARE.
14
 *
15
 * So that all may benefit from your experience, please report  any  problems
16
 * or  suggestions about this software to the 29K Technical Support Center at
17
 * 800-29-29-AMD (800-292-9263) in the USA, or 0800-89-1131  in  the  UK,  or
18
 * 0031-11-1129 in Japan, toll free.  The direct dial number is 512-462-4118.
19
 *
20
 * Advanced Micro Devices, Inc.
21
 * 29K Support Products
22
 * Mail Stop 573
23
 * 5900 E. Ben White Blvd.
24
 * Austin, TX 78741
25
 * 800-292-9263
26
 *****************************************************************************
27
 *      Engineer: Srini Subramanian.
28
 *****************************************************************************
29
 * This module supports the assemble command to assemble 29K instructions
30
 * in memory.
31
 *****************************************************************************
32
 */
33
 
34
 
35
#include <stdio.h>
36
#include "opcodes.h"
37
#include "memspcs.h"
38
#include "main.h"
39
#include "monitor.h"
40
#include "macros.h"
41
#include "miniint.h"
42
#include "error.h"
43
 
44
#ifdef  MSDOS
45
#include <string.h>
46
#define strcasecmp      stricmp
47
#else
48
#include <string.h>
49
#endif
50
 
51
 
52
/*
53
** There are approximately 23 different instruction formats for the
54
** Am29000.  Instructions are assembled using one of these formats.
55
**
56
** Note:  Opcodes in the "switch" statement are sorted in numerical
57
**        order.
58
**
59
*/
60
 
61
 
62
int     get_addr_29k_m PARAMS((char *, struct addr_29k_t *, INT32));
63
int     addr_29k_ok PARAMS((struct addr_29k_t *));
64
void    convert32 PARAMS((BYTE *));
65
int     set_data PARAMS((BYTE *, BYTE *, int));
66
 
67
int  asm_instr PARAMS((struct instr_t *, char **, int));
68
 
69
int  asm_arith_logic PARAMS((struct instr_t *, struct addr_29k_t *, int));
70
int  asm_load_store PARAMS((struct instr_t *, struct addr_29k_t *, int));
71
int  asm_vector PARAMS((struct instr_t *, struct addr_29k_t *, int));
72
int  asm_no_parms PARAMS((struct instr_t *, struct addr_29k_t *, int));
73
int  asm_one_parms PARAMS((struct instr_t *, struct addr_29k_t *, int));
74
int  asm_float PARAMS((struct instr_t *, struct addr_29k_t *, int));
75
int  asm_call_jmp PARAMS((struct instr_t *, struct addr_29k_t *, int));
76
int  asm_calli_jmpi PARAMS((struct instr_t *, struct addr_29k_t *, int));
77
int  asm_class PARAMS((struct instr_t *, struct addr_29k_t *, int));
78
int  asm_clz PARAMS((struct instr_t *, struct addr_29k_t *, int));
79
int  asm_const PARAMS((struct instr_t *, struct addr_29k_t *, int));
80
int  asm_consth PARAMS((struct instr_t *, struct addr_29k_t *, int));
81
int  asm_convert PARAMS((struct instr_t *, struct addr_29k_t *, int));
82
int  asm_div0 PARAMS((struct instr_t *, struct addr_29k_t *, int));
83
int  asm_exhws PARAMS((struct instr_t *, struct addr_29k_t *, int));
84
int  asm_jmp PARAMS((struct instr_t *, struct addr_29k_t *, int));
85
int  asm_jmpi PARAMS((struct instr_t *, struct addr_29k_t *, int));
86
int  asm_mfsr PARAMS((struct instr_t *, struct addr_29k_t *, int));
87
int  asm_mtsr PARAMS((struct instr_t *, struct addr_29k_t *, int));
88
int  asm_mtsrim PARAMS((struct instr_t *, struct addr_29k_t *, int));
89
int  asm_mftlb PARAMS((struct instr_t *, struct addr_29k_t *, int));
90
int  asm_mttlb PARAMS((struct instr_t *, struct addr_29k_t *, int));
91
int  asm_sqrt PARAMS((struct instr_t *, struct addr_29k_t *, int));
92
int  asm_emulate PARAMS((struct instr_t *, struct addr_29k_t *, int));
93
 
94
extern  void    Mini_poll_kbd PARAMS((char  *cmd_buffer, int size, int mode));
95
extern  int     Mini_cmdfile_input PARAMS((char  *cmd_buffer, int size));
96
extern  int     tokenize_cmd PARAMS((char *, char **));
97
extern  void    lcase_tokens PARAMS((char **, int));
98
extern  INT32   do_assemble PARAMS(( struct addr_29k_t  addr_29k,
99
                                     char       *token[],
100
                                     int        token_count));
101
#ifndef XRAY
102
 
103
extern  char    cmd_buffer[];
104
 
105
#define MAX_ASM_TOKENS  15
106
static  char    *asm_token[MAX_ASM_TOKENS];
107
static  int     asm_token_count;
108
 
109
/*
110
** This function is used to assemble an instruction.  The command
111
** takes as parameters an array of strings (*token[]) and a
112
** count (token_count) which gives the number of tokens in the
113
** array.  These tokens should have the following values:
114
**
115
** token[0] - 'a' (the assemble command)
116
** token[1] - <address> (the address to assemble instruction at)
117
** token[2] - <opcode>  (the 29K opcode nmemonic)
118
** token[3] to token[n] - parameters to the assembly instruction.
119
**
120
*/
121
 
122
INT32
123
asm_cmd(token, token_count)
124
   char   *token[];
125
   int     token_count;
126
   {
127
   INT32                result;
128
   struct addr_29k_t    addr_29k;
129
   int          asm_done;
130
 
131
   /*
132
   ** Parse parameters
133
   */
134
 
135
   if ((token_count < 2) || (token_count > 9)) {
136
      return (EMSYNTAX);
137
   } else if (token_count == 2) {
138
      /* Get address of assembly */
139
      result = get_addr_29k_m(token[1], &addr_29k, I_MEM);
140
      if (result != 0)
141
         return (result);
142
      result = addr_29k_ok(&addr_29k);
143
      if (result != 0)
144
         return (result);
145
      asm_done = 0;
146
      fprintf(stderr, "0x%08lx:\t", addr_29k.address);
147
      do {
148
        if (io_config.cmd_file_io == TRUE) {
149
             if (Mini_cmdfile_input(cmd_buffer, BUFFER_SIZE) == SUCCESS) {
150
               fprintf(stderr, "%s", cmd_buffer);
151
             } else {
152
               Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BLOCK); /* block */
153
             }
154
        } else {
155
             Mini_poll_kbd(cmd_buffer, BUFFER_SIZE, BLOCK); /* block */
156
        }
157
        if (io_config.log_file)  /* make a log file */
158
#ifdef  MSDOS
159
            fprintf(io_config.log_file, "%s\n", cmd_buffer);
160
#else
161
            fprintf(io_config.log_file, "%s", cmd_buffer);
162
#endif
163
        if (io_config.echo_mode == (INT32) TRUE)
164
#ifdef  MSDOS
165
            fprintf(io_config.echo_file, "%s\n", cmd_buffer);
166
#else
167
            fprintf(io_config.echo_file, "%s", cmd_buffer);
168
#endif
169
        asm_token_count = tokenize_cmd(cmd_buffer, asm_token);
170
        lcase_tokens(asm_token, asm_token_count);
171
        if (strcmp(token[0], ".") == 0)
172
          asm_done = 1;
173
        else {
174
          result= do_assemble(addr_29k, &asm_token[0], asm_token_count);
175
          if (result != SUCCESS)
176
            warning (result);
177
          else
178
            addr_29k.address = addr_29k.address + 4;
179
          fprintf(stderr, "0x%08lx:\t", addr_29k.address);
180
        }
181
      } while (asm_done != 1);
182
   } else {
183
      /* Get address of assembly */
184
      result = get_addr_29k_m(token[1], &addr_29k, I_MEM);
185
      if (result != 0)
186
         return (result);
187
      result = addr_29k_ok(&addr_29k);
188
      if (result != 0)
189
         return (result);
190
      return (do_assemble(addr_29k, &token[2], (token_count-2)));
191
   }
192
   return (SUCCESS);
193
}
194
 
195
 
196
INT32
197
do_assemble(addr_29k, token, token_count)
198
struct addr_29k_t       addr_29k;
199
char                    *token[];
200
int                     token_count;
201
{
202
   INT32    result;
203
   struct instr_t    instr;
204
 
205
   INT32        retval;
206
   BYTE         *write_data;
207
   INT32        bytes_ret;
208
   INT32        hostendian;     /* for UDI conformant */
209
 
210
   /* Initialize instr */
211
   instr.op = 0;
212
   instr.c  = 0;
213
   instr.a  = 0;
214
   instr.b  = 0;
215
 
216
   /* Assemble instruction */
217
   result = asm_instr(&instr, &(token[0]), token_count);
218
 
219
   if (result != 0)
220
      return (EMSYNTAX);
221
 
222
   /* Will the data overflow the message buffer?  done in TIP */
223
   write_data = (BYTE *) &instr;
224
 
225
   hostendian = FALSE;
226
   if ((retval = Mini_write_req (addr_29k.memory_space,
227
                                 addr_29k.address,
228
                                 1, /* count */
229
                                 (INT16) sizeof(INST32),  /* size */
230
                                 &bytes_ret,
231
                                 write_data,
232
                                 hostendian)) != SUCCESS) {
233
      return(FAILURE);
234
   };
235
   return (SUCCESS);
236
}
237
#endif
238
 
239
/*
240
** This function is used to assemble a single Am29000 instruction.
241
** The token[] array contains the lower-case tokens for a single
242
** assembler instruction.  The token_count contains the number of
243
** tokens in the array.  This number should be at least 1 (as in the
244
** cases of instructions like IRET) and at most 5 (for instructions
245
** like LOAD).
246
*/
247
 
248
#ifdef XRAY
249
  extern struct t_inst_table {
250
        char  *inst_mnem;
251
        unsigned char   oprn_fmt;
252
} inst_table[];
253
#endif
254
 
255
int
256
asm_instr(instr, token, token_count)
257
   struct   instr_t *instr;
258
   char    *token[];
259
   int      token_count;
260
   {
261
   int    i;
262
   int    result;
263
   struct addr_29k_t parm[10];
264
   char   temp_opcode[20];
265
   char  *temp_ptr;
266
   int    opcode_found;
267
   static char  *str_0x40="0x40";
268
   static char  *str_gr1="gr1";
269
 
270
 
271
   /* Is token_count valid, and is the first token a string? */
272
   if ((token_count < 1) ||
273
       (token_count > 7) ||
274
       (strcmp(token[0], "") == 0))
275
      return (EMSYNTAX);
276
 
277
   /* Get opcode */
278
 
279
   /*
280
   ** Note:  Since the opcode_name[] string used in the disassembler
281
   ** uses padded strings, we cannot do a strcmp().  We canot do a
282
   ** strncmp() of the length of token[0] either, since "and" will
283
   ** match up (for instance) with "andn".  So we copy the string,
284
   ** null terminate at the first pad character (space), and then
285
   ** compare.  This is inefficient, but necessary.
286
   */
287
 
288
   i=0;
289
   opcode_found = FALSE;
290
   while ((i<256) && (opcode_found != TRUE)) {
291
#ifdef XRAY
292
      result = strcasecmp(token[0], inst_table[i].inst_mnem);
293
#else
294
      temp_ptr = strcpy(temp_opcode, opcode_name[i]);
295
 
296
      if (strcmp(temp_ptr, "") != 0)
297
         temp_ptr = strtok(temp_opcode, " ");
298
      result = strcmp(token[0], temp_ptr);
299
#endif
300
 
301
      if (result == 0) {
302
         opcode_found = TRUE;
303
         instr->op = (BYTE) i;
304
         }
305
      i = i + 1;
306
      }  /* end while */
307
 
308
   /* Check for a NOP */
309
   if ((opcode_found == FALSE) &&
310
       (strcasecmp(token[0], "nop") == 0)) {
311
      opcode_found = TRUE;
312
      instr->op = ASEQ0;
313
      /* Fake up tokens to give "aseq 0x40,gr1,gr1" */
314
      token_count = 4;
315
      token[1] = str_0x40;
316
      token[2] = str_gr1;
317
      token[3] = str_gr1;
318
      }
319
 
320
   if (opcode_found == FALSE)
321
      return (EMSYNTAX);
322
 
323
   if ((strcasecmp(token[0], "iretinv") == 0) ||
324
       (strcasecmp(token[0], "inv") == 0) ) {
325
       /* iretinv and inv instructions */
326
      for (i=1; i<token_count; i=i+1) {
327
         result = get_addr_29k_m(token[i], &(parm[i-1]), GENERIC_SPACE);
328
         if (result != 0)
329
            return (result);
330
      }
331
   } else {
332
   /* Make the other tokens into addr_29k */
333
   for (i=1; i<token_count; i=i+1) {
334
      result = get_addr_29k_m(token[i], &(parm[i-1]), I_MEM);
335
      if (result != 0)
336
         return (result);
337
      /* Check if register values are legal */
338
      if (ISREG(parm[i-1].memory_space)) {
339
         result = addr_29k_ok(&(parm[i-1]));
340
         if (result != 0)
341
            return (EMBADREG);
342
         }
343
      /* Set bit 7 if a LOCAL_REG */
344
      if (parm[i-1].memory_space == LOCAL_REG)
345
         parm[i-1].address = (parm[i-1].address | 0x80);
346
      }
347
   }
348
 
349
 
350
   switch (instr->op) {
351
 
352
      /* Opcodes 0x00 to 0x0F */
353
      case ILLEGAL_00:  result = EMSYNTAX;
354
                        break;
355
      case CONSTN:      result = asm_const(instr, parm, 2);
356
                        break;
357
      case CONSTH:      result = asm_consth(instr, parm, 2);
358
                        break;
359
      case CONST:       result = asm_const(instr, parm, 2);
360
                        break;
361
      case MTSRIM:      result = asm_mtsrim(instr, parm, 2);
362
                        break;
363
      case CONSTHZ:     result = asm_const(instr, parm, 2);
364
                        break;
365
      case LOADL0:      result = asm_load_store(instr, parm, 4);
366
                        break;
367
      case LOADL1:      result = asm_load_store(instr, parm, 4);
368
                        break;
369
      case CLZ0:        result = asm_clz(instr, parm, 2);
370
                        break;
371
      case CLZ1:        result = asm_clz(instr, parm, 2);
372
                        break;
373
      case EXBYTE0:     result = asm_arith_logic(instr, parm, 3);
374
                        break;
375
      case EXBYTE1:     result = asm_arith_logic(instr, parm, 3);
376
                        break;
377
      case INBYTE0:     result = asm_arith_logic(instr, parm, 3);
378
                        break;
379
      case INBYTE1:     result = asm_arith_logic(instr, parm, 3);
380
                        break;
381
      case STOREL0:     result = asm_load_store(instr, parm, 4);
382
                        break;
383
      case STOREL1:     result = asm_load_store(instr, parm, 4);
384
                        break;
385
 
386
      /* Opcodes 0x10 to 0x1F */
387
      case ADDS0:       result = asm_arith_logic(instr, parm, 3);
388
                        break;
389
      case ADDS1:       result = asm_arith_logic(instr, parm, 3);
390
                        break;
391
      case ADDU0:       result = asm_arith_logic(instr, parm, 3);
392
                        break;
393
      case ADDU1:       result = asm_arith_logic(instr, parm, 3);
394
                        break;
395
      case ADD0:        result = asm_arith_logic(instr, parm, 3);
396
                        break;
397
      case ADD1:        result = asm_arith_logic(instr, parm, 3);
398
                        break;
399
      case LOAD0:       result = asm_load_store(instr, parm, 4);
400
                        break;
401
      case LOAD1:       result = asm_load_store(instr, parm, 4);
402
                        break;
403
      case ADDCS0:      result = asm_arith_logic(instr, parm, 3);
404
                        break;
405
      case ADDCS1:      result = asm_arith_logic(instr, parm, 3);
406
                        break;
407
      case ADDCU0:      result = asm_arith_logic(instr, parm, 3);
408
                        break;
409
      case ADDCU1:      result = asm_arith_logic(instr, parm, 3);
410
                        break;
411
      case ADDC0:       result = asm_arith_logic(instr, parm, 3);
412
                        break;
413
      case ADDC1:       result = asm_arith_logic(instr, parm, 3);
414
                        break;
415
      case STORE0:      result = asm_load_store(instr, parm, 4);
416
                        break;
417
      case STORE1:      result = asm_load_store(instr, parm, 4);
418
                        break;
419
 
420
      /* Opcodes 0x20 to 0x2F */
421
      case SUBS0:       result = asm_arith_logic(instr, parm, 3);
422
                        break;
423
      case SUBS1:       result = asm_arith_logic(instr, parm, 3);
424
                        break;
425
      case SUBU0:       result = asm_arith_logic(instr, parm, 3);
426
                        break;
427
      case SUBU1:       result = asm_arith_logic(instr, parm, 3);
428
                        break;
429
      case SUB0:        result = asm_arith_logic(instr, parm, 3);
430
                        break;
431
      case SUB1:        result = asm_arith_logic(instr, parm, 3);
432
                        break;
433
      case LOADSET0:    result = asm_load_store(instr, parm, 4);
434
                        break;
435
      case LOADSET1:    result = asm_load_store(instr, parm, 4);
436
                        break;
437
      case SUBCS0:      result = asm_arith_logic(instr, parm, 3);
438
                        break;
439
      case SUBCS1:      result = asm_arith_logic(instr, parm, 3);
440
                        break;
441
      case SUBCU0:      result = asm_arith_logic(instr, parm, 3);
442
                        break;
443
      case SUBCU1:      result = asm_arith_logic(instr, parm, 3);
444
                        break;
445
      case SUBC0:       result = asm_arith_logic(instr, parm, 3);
446
                        break;
447
      case SUBC1:       result = asm_arith_logic(instr, parm, 3);
448
                        break;
449
      case CPBYTE0:     result = asm_arith_logic(instr, parm, 3);
450
                        break;
451
      case CPBYTE1:     result = asm_arith_logic(instr, parm, 3);
452
                        break;
453
 
454
 
455
      /* Opcodes 0x30 to 0x3F */
456
      case SUBRS0:      result = asm_arith_logic(instr, parm, 3);
457
                        break;
458
      case SUBRS1:      result = asm_arith_logic(instr, parm, 3);
459
                        break;
460
      case SUBRU0:      result = asm_arith_logic(instr, parm, 3);
461
                        break;
462
      case SUBRU1:      result = asm_arith_logic(instr, parm, 3);
463
                        break;
464
      case SUBR0:       result = asm_arith_logic(instr, parm, 3);
465
                        break;
466
      case SUBR1:       result = asm_arith_logic(instr, parm, 3);
467
                        break;
468
      case LOADM0:      result = asm_load_store(instr, parm, 4);
469
                        break;
470
      case LOADM1:      result = asm_load_store(instr, parm, 4);
471
                        break;
472
      case SUBRCS0:     result = asm_arith_logic(instr, parm, 3);
473
                        break;
474
      case SUBRCS1:     result = asm_arith_logic(instr, parm, 3);
475
                        break;
476
      case SUBRCU0:     result = asm_arith_logic(instr, parm, 3);
477
                        break;
478
      case SUBRCU1:     result = asm_arith_logic(instr, parm, 3);
479
                        break;
480
      case SUBRC0:      result = asm_arith_logic(instr, parm, 3);
481
                        break;
482
      case SUBRC1:      result = asm_arith_logic(instr, parm, 3);
483
                        break;
484
      case STOREM0:     result = asm_load_store(instr, parm, 4);
485
                        break;
486
      case STOREM1:     result = asm_load_store(instr, parm, 4);
487
                        break;
488
 
489
      /* Opcodes 0x40 to 0x4F */
490
      case CPLT0:       result = asm_arith_logic(instr, parm, 3);
491
                        break;
492
      case CPLT1:       result = asm_arith_logic(instr, parm, 3);
493
                        break;
494
      case CPLTU0:      result = asm_arith_logic(instr, parm, 3);
495
                        break;
496
      case CPLTU1:      result = asm_arith_logic(instr, parm, 3);
497
                        break;
498
      case CPLE0:       result = asm_arith_logic(instr, parm, 3);
499
                        break;
500
      case CPLE1:       result = asm_arith_logic(instr, parm, 3);
501
                        break;
502
      case CPLEU0:      result = asm_arith_logic(instr, parm, 3);
503
                        break;
504
      case CPLEU1:      result = asm_arith_logic(instr, parm, 3);
505
                        break;
506
      case CPGT0:       result = asm_arith_logic(instr, parm, 3);
507
                        break;
508
      case CPGT1:       result = asm_arith_logic(instr, parm, 3);
509
                        break;
510
      case CPGTU0:      result = asm_arith_logic(instr, parm, 3);
511
                        break;
512
      case CPGTU1:      result = asm_arith_logic(instr, parm, 3);
513
                        break;
514
      case CPGE0:       result = asm_arith_logic(instr, parm, 3);
515
                        break;
516
      case CPGE1:       result = asm_arith_logic(instr, parm, 3);
517
                        break;
518
      case CPGEU0:      result = asm_arith_logic(instr, parm, 3);
519
                        break;
520
      case CPGEU1:      result = asm_arith_logic(instr, parm, 3);
521
                        break;
522
 
523
      /* Opcodes 0x50 to 0x5F */
524
      case ASLT0:       result = asm_vector(instr, parm, 3);
525
                        break;
526
      case ASLT1:       result = asm_vector(instr, parm, 3);
527
                        break;
528
      case ASLTU0:      result = asm_vector(instr, parm, 3);
529
                        break;
530
      case ASLTU1:      result = asm_vector(instr, parm, 3);
531
                        break;
532
      case ASLE0:       result = asm_vector(instr, parm, 3);
533
                        break;
534
      case ASLE1:       result = asm_vector(instr, parm, 3);
535
                        break;
536
      case ASLEU0:      result = asm_vector(instr, parm, 3);
537
                        break;
538
      case ASLEU1:      result = asm_vector(instr, parm, 3);
539
                        break;
540
      case ASGT0:       result = asm_vector(instr, parm, 3);
541
                        break;
542
      case ASGT1:       result = asm_vector(instr, parm, 3);
543
                        break;
544
      case ASGTU0:      result = asm_vector(instr, parm, 3);
545
                        break;
546
      case ASGTU1:      result = asm_vector(instr, parm, 3);
547
                        break;
548
      case ASGE0:       result = asm_vector(instr, parm, 3);
549
                        break;
550
      case ASGE1:       result = asm_vector(instr, parm, 3);
551
                        break;
552
      case ASGEU0:      result = asm_vector(instr, parm, 3);
553
                        break;
554
      case ASGEU1:      result = asm_vector(instr, parm, 3);
555
                        break;
556
 
557
      /* Opcodes 0x60 to 0x6F */
558
      case CPEQ0:       result = asm_arith_logic(instr, parm, 3);
559
                        break;
560
      case CPEQ1:       result = asm_arith_logic(instr, parm, 3);
561
                        break;
562
      case CPNEQ0:      result = asm_arith_logic(instr, parm, 3);
563
                        break;
564
      case CPNEQ1:      result = asm_arith_logic(instr, parm, 3);
565
                        break;
566
      case MUL0:        result = asm_arith_logic(instr, parm, 3);
567
                        break;
568
      case MUL1:        result = asm_arith_logic(instr, parm, 3);
569
                        break;
570
      case MULL0:       result = asm_arith_logic(instr, parm, 3);
571
                        break;
572
      case MULL1:       result = asm_arith_logic(instr, parm, 3);
573
                        break;
574
      case DIV0_OP0:    result = asm_div0(instr, parm, 2);
575
                        break;
576
      case DIV0_OP1:    result = asm_div0(instr, parm, 2);
577
                        break;
578
      case DIV_OP0:     result = asm_arith_logic(instr, parm, 3);
579
                        break;
580
      case DIV_OP1:     result = asm_arith_logic(instr, parm, 3);
581
                        break;
582
      case DIVL0:       result = asm_arith_logic(instr, parm, 3);
583
                        break;
584
      case DIVL1:       result = asm_arith_logic(instr, parm, 3);
585
                        break;
586
      case DIVREM0:     result = asm_arith_logic(instr, parm, 3);
587
                        break;
588
      case DIVREM1:     result = asm_arith_logic(instr, parm, 3);
589
                        break;
590
 
591
      /* Opcodes 0x70 to 0x7F */
592
      case ASEQ0:       result = asm_vector(instr, parm, 3);
593
                        break;
594
      case ASEQ1:       result = asm_vector(instr, parm, 3);
595
                        break;
596
      case ASNEQ0:      result = asm_vector(instr, parm, 3);
597
                        break;
598
      case ASNEQ1:      result = asm_vector(instr, parm, 3);
599
                        break;
600
      case MULU0:       result = asm_arith_logic(instr, parm, 3);
601
                        break;
602
      case MULU1:       result = asm_arith_logic(instr, parm, 3);
603
                        break;
604
      case ILLEGAL_76:  result = EMSYNTAX;
605
                        break;
606
      case ILLEGAL_77:  result = EMSYNTAX;
607
                        break;
608
      case INHW0:       result = asm_arith_logic(instr, parm, 3);
609
                        break;
610
      case INHW1:       result = asm_arith_logic(instr, parm, 3);
611
                        break;
612
      case EXTRACT0:    result = asm_arith_logic(instr, parm, 3);
613
                        break;
614
      case EXTRACT1:    result = asm_arith_logic(instr, parm, 3);
615
                        break;
616
      case EXHW0:       result = asm_arith_logic(instr, parm, 3);
617
                        break;
618
      case EXHW1:       result = asm_arith_logic(instr, parm, 3);
619
                        break;
620
      case EXHWS:       result = asm_exhws(instr, parm, 2);
621
                        break;
622
      case ILLEGAL_7F:  result = EMSYNTAX;
623
                        break;
624
 
625
      /* Opcodes 0x80 to 0x8F */
626
      case SLL0:        result = asm_arith_logic(instr, parm, 3);
627
                        break;
628
      case SLL1:        result = asm_arith_logic(instr, parm, 3);
629
                        break;
630
      case SRL0:        result = asm_arith_logic(instr, parm, 3);
631
                        break;
632
      case SRL1:        result = asm_arith_logic(instr, parm, 3);
633
                        break;
634
      case ILLEGAL_84:  result = EMSYNTAX;
635
                        break;
636
      case ILLEGAL_85:  result = EMSYNTAX;
637
                        break;
638
      case SRA0:        result = asm_arith_logic(instr, parm, 3);
639
                        break;
640
      case SRA1:        result = asm_arith_logic(instr, parm, 3);
641
                        break;
642
      case IRET:
643
                        result = asm_no_parms(instr, parm, 0);
644
                        break;
645
      case HALT_OP:     result = asm_no_parms(instr, parm, 0);
646
                        break;
647
      case ILLEGAL_8A:  result = EMSYNTAX;
648
                        break;
649
      case ILLEGAL_8B:  result = EMSYNTAX;
650
                        break;
651
      case IRETINV:
652
                        if (token_count > 1)
653
                            result = asm_one_parms(instr, parm, 1);
654
                        else
655
                            result = asm_no_parms(instr, parm, 0);
656
                        break;
657
      case ILLEGAL_8D:  result = EMSYNTAX;
658
                        break;
659
      case ILLEGAL_8E:  result = EMSYNTAX;
660
                        break;
661
      case ILLEGAL_8F:  result = EMSYNTAX;
662
                        break;
663
 
664
      /* Opcodes 0x90 to 0x9F */
665
      case AND_OP0:     result = asm_arith_logic(instr, parm, 3);
666
                        break;
667
      case AND_OP1:     result = asm_arith_logic(instr, parm, 3);
668
                        break;
669
      case OR_OP0:      result = asm_arith_logic(instr, parm, 3);
670
                        break;
671
      case OR_OP1:      result = asm_arith_logic(instr, parm, 3);
672
                        break;
673
      case XOR_OP0:     result = asm_arith_logic(instr, parm, 3);
674
                        break;
675
      case XOR_OP1:     result = asm_arith_logic(instr, parm, 3);
676
                        break;
677
      case XNOR0:       result = asm_arith_logic(instr, parm, 3);
678
                        break;
679
      case XNOR1:       result = asm_arith_logic(instr, parm, 3);
680
                        break;
681
      case NOR0:        result = asm_arith_logic(instr, parm, 3);
682
                        break;
683
      case NOR1:        result = asm_arith_logic(instr, parm, 3);
684
                        break;
685
      case NAND0:       result = asm_arith_logic(instr, parm, 3);
686
                        break;
687
      case NAND1:       result = asm_arith_logic(instr, parm, 3);
688
                        break;
689
      case ANDN0:       result = asm_arith_logic(instr, parm, 3);
690
                        break;
691
      case ANDN1:       result = asm_arith_logic(instr, parm, 3);
692
                        break;
693
      case SETIP:       result = asm_float(instr, parm, 3);
694
                        break;
695
      case INV:
696
                          if (token_count > 1)
697
                            result = asm_one_parms(instr, parm, 1);
698
                          else
699
                            result = asm_no_parms(instr, parm, 0);
700
                        break;
701
 
702
      /* Opcodes 0xA0 to 0xAF */
703
      case JMP0:        result = asm_jmp(instr, parm, 1);
704
                        break;
705
      case JMP1:        result = asm_jmp(instr, parm, 1);
706
                        break;
707
      case ILLEGAL_A2:  result = EMSYNTAX;
708
                        break;
709
      case ILLEGAL_A3:  result = EMSYNTAX;
710
                        break;
711
      case JMPF0:       result = asm_call_jmp(instr, parm, 2);
712
                        break;
713
      case JMPF1:       result = asm_call_jmp(instr, parm, 2);
714
                        break;
715
      case ILLEGAL_A6:  result = EMSYNTAX;
716
                        break;
717
      case ILLEGAL_A7:  result = EMSYNTAX;
718
                        break;
719
      case CALL0:       result = asm_call_jmp(instr, parm, 2);
720
                        break;
721
      case CALL1:       result = asm_call_jmp(instr, parm, 2);
722
                        break;
723
      case ORN_OP0:     result = EMSYNTAX;
724
                        break;
725
      case ORN_OP1:     result = EMSYNTAX;
726
                        break;
727
      case JMPT0:       result = asm_call_jmp(instr, parm, 2);
728
                        break;
729
      case JMPT1:       result = asm_call_jmp(instr, parm, 2);
730
                        break;
731
      case ILLEGAL_AE:  result = EMSYNTAX;
732
                        break;
733
      case ILLEGAL_AF:  result = EMSYNTAX;
734
                        break;
735
 
736
      /* Opcodes 0xB0 to 0xBF */
737
      case ILLEGAL_B0:  result = EMSYNTAX;
738
                        break;
739
      case ILLEGAL_B1:  result = EMSYNTAX;
740
                        break;
741
      case ILLEGAL_B2:  result = EMSYNTAX;
742
                        break;
743
      case ILLEGAL_B3:  result = EMSYNTAX;
744
                        break;
745
      case JMPFDEC0:    result = asm_call_jmp(instr, parm, 2);
746
                        break;
747
      case JMPFDEC1:    result = asm_call_jmp(instr, parm, 2);
748
                        break;
749
      case MFTLB:       result = asm_mftlb(instr, parm, 2);
750
                        break;
751
      case ILLEGAL_B7:  result = EMSYNTAX;
752
                        break;
753
      case ILLEGAL_B8:  result = EMSYNTAX;
754
                        break;
755
      case ILLEGAL_B9:  result = EMSYNTAX;
756
                        break;
757
      case ILLEGAL_BA:  result = EMSYNTAX;
758
                        break;
759
      case ILLEGAL_BB:  result = EMSYNTAX;
760
                        break;
761
      case ILLEGAL_BC:  result = EMSYNTAX;
762
                        break;
763
      case ILLEGAL_BD:  result = EMSYNTAX;
764
                        break;
765
      case MTTLB:       result = asm_mttlb(instr, parm, 2);
766
                        break;
767
      case ILLEGAL_BF:  result = EMSYNTAX;
768
                        break;
769
 
770
      /* Opcodes 0xC0 to 0xCF */
771
      case JMPI:        result = asm_jmpi(instr, parm, 1);
772
                        break;
773
      case ILLEGAL_C1:  result = EMSYNTAX;
774
                        break;
775
      case ILLEGAL_C2:  result = EMSYNTAX;
776
                        break;
777
      case ILLEGAL_C3:  result = EMSYNTAX;
778
                        break;
779
      case JMPFI:       result = asm_calli_jmpi(instr, parm, 2);
780
                        break;
781
      case ILLEGAL_C5:  result = EMSYNTAX;
782
                        break;
783
      case MFSR:        result = asm_mfsr(instr, parm, 2);
784
                        break;
785
      case ILLEGAL_C7:  result = EMSYNTAX;
786
                        break;
787
      case CALLI:       result = asm_calli_jmpi(instr, parm, 2);
788
                        break;
789
      case ILLEGAL_C9:  result = EMSYNTAX;
790
                        break;
791
      case ILLEGAL_CA:  result = EMSYNTAX;
792
                        break;
793
      case ILLEGAL_CB:  result = EMSYNTAX;
794
                        break;
795
      case JMPTI:       result = asm_calli_jmpi(instr, parm, 2);
796
                        break;
797
      case ILLEGAL_CD:  result = EMSYNTAX;
798
                        break;
799
      case MTSR:        result = asm_mtsr(instr, parm, 2);
800
                        break;
801
      case ILLEGAL_CF:  result = EMSYNTAX;
802
                        break;
803
 
804
      /* Opcodes 0xD0 to 0xDF */
805
      case ILLEGAL_D0:  result = EMSYNTAX;
806
                        break;
807
      case ILLEGAL_D1:  result = EMSYNTAX;
808
                        break;
809
      case ILLEGAL_D2:  result = EMSYNTAX;
810
                        break;
811
      case ILLEGAL_D3:  result = EMSYNTAX;
812
                        break;
813
      case ILLEGAL_D4:  result = EMSYNTAX;
814
                        break;
815
      case ILLEGAL_D5:  result = EMSYNTAX;
816
                        break;
817
      case ILLEGAL_D6:  result = EMSYNTAX;
818
                        break;
819
      case EMULATE:     result = asm_emulate(instr, parm, 3);
820
                        break;
821
      case ILLEGAL_D8:  result = EMSYNTAX;
822
                        break;
823
      case ILLEGAL_D9:  result = EMSYNTAX;
824
                        break;
825
      case ILLEGAL_DA:  result = EMSYNTAX;
826
                        break;
827
      case ILLEGAL_DB:  result = EMSYNTAX;
828
                        break;
829
      case ILLEGAL_DC:  result = EMSYNTAX;
830
                        break;
831
      case ILLEGAL_DD:  result = EMSYNTAX;
832
                        break;
833
      case MULTM:       result = asm_float(instr, parm, 3);
834
                        break;
835
      case MULTMU:      result = asm_float(instr, parm, 3);
836
                        break;
837
 
838
      /* Opcodes 0xE0 to 0xEF */
839
      case MULTIPLY:    result = asm_float(instr, parm, 3);
840
                        break;
841
      case DIVIDE:      result = asm_float(instr, parm, 3);
842
                        break;
843
      case MULTIPLU:    result = asm_float(instr, parm, 3);
844
                        break;
845
      case DIVIDU:      result = asm_float(instr, parm, 3);
846
                        break;
847
      case CONVERT:     result = asm_convert(instr, parm, 6);
848
                        break;
849
      case SQRT:        result = asm_sqrt(instr, parm, 3);
850
                        break;
851
      case CLASS:       result = asm_class(instr, parm, 3);
852
                        break;
853
      case ILLEGAL_E7:  result = EMSYNTAX;
854
                        break;
855
      case ILLEGAL_E8:  result = EMSYNTAX;
856
                        break;
857
      case ILLEGAL_E9:  result = EMSYNTAX;
858
                        break;
859
      case FEQ:         result = asm_float(instr, parm, 3);
860
                        break;
861
      case DEQ:         result = asm_float(instr, parm, 3);
862
                        break;
863
      case FGT:         result = asm_float(instr, parm, 3);
864
                        break;
865
      case DGT:         result = asm_float(instr, parm, 3);
866
                        break;
867
      case FGE:         result = asm_float(instr, parm, 3);
868
                        break;
869
      case DGE:         result = asm_float(instr, parm, 3);
870
                        break;
871
 
872
      /* Opcodes 0xF0 to 0xFF */
873
      case FADD:        result = asm_float(instr, parm, 3);
874
                        break;
875
      case DADD:        result = asm_float(instr, parm, 3);
876
                        break;
877
      case FSUB:        result = asm_float(instr, parm, 3);
878
                        break;
879
      case DSUB:        result = asm_float(instr, parm, 3);
880
                        break;
881
      case FMUL:        result = asm_float(instr, parm, 3);
882
                        break;
883
      case DMUL:        result = asm_float(instr, parm, 3);
884
                        break;
885
      case FDIV:        result = asm_float(instr, parm, 3);
886
                        break;
887
      case DDIV:        result = asm_float(instr, parm, 3);
888
                        break;
889
      case ILLEGAL_F8:  result = EMSYNTAX;
890
                        break;
891
      case FDMUL:       result = asm_float(instr, parm, 3);
892
                        break;
893
      case ILLEGAL_FA:  result = EMSYNTAX;
894
                        break;
895
      case ILLEGAL_FB:  result = EMSYNTAX;
896
                        break;
897
      case ILLEGAL_FC:  result = EMSYNTAX;
898
                        break;
899
      case ILLEGAL_FD:  result = EMSYNTAX;
900
                        break;
901
      case ILLEGAL_FE:  result = EMSYNTAX;
902
                        break;
903
      case ILLEGAL_FF:  result = EMSYNTAX;
904
                        break;
905
      }  /* end switch */
906
 
907
   return (result);
908
 
909
   }  /* End asm_instr() */
910
 
911
 
912
 
913
 
914
/*
915
** The following functions are used to convert instruction
916
** parameters as an arrays of addr_29k_t memory space / address
917
** pairs into a 32 bit Am29000 binary instruction.
918
** All of the Am29000 instruction formats are supported below.
919
*/
920
 
921
 
922
/*
923
** Formats:   <nmemonic>, RC, RA, (RB or I)
924
** Examples:  ADD, OR, SLL, all arithmetic and
925
**            logic instructions
926
**
927
*/
928
 
929
int
930
asm_arith_logic(instr, parm, parm_count)
931
   struct   instr_t    *instr;
932
   struct   addr_29k_t *parm;
933
   int      parm_count;
934
   {
935
   if (parm_count != 3)
936
      return (EMSYNTAX);
937
 
938
   if (ISGENERAL(parm[0].memory_space) &&
939
       ISGENERAL(parm[1].memory_space) &&
940
       ISGENERAL(parm[2].memory_space)) {
941
      /* Make sure M flag is cleared */
942
      instr->op = (BYTE) (instr->op & 0xfe);
943
      instr->c = (BYTE) (parm[0].address & 0xff);
944
      instr->a = (BYTE) (parm[1].address & 0xff);
945
      instr->b = (BYTE) (parm[2].address & 0xff);
946
      }
947
   else
948
   if (ISGENERAL(parm[0].memory_space) &&
949
       ISGENERAL(parm[1].memory_space) &&
950
       ISMEM(parm[2].memory_space)) {
951
      /* Make sure M flag is set */
952
      instr->op = (BYTE) (instr->op | 0x01);
953
      instr->c = (BYTE) (parm[0].address & 0xff);
954
      instr->a = (BYTE) (parm[1].address & 0xff);
955
      instr->b = (BYTE) (parm[2].address & 0xff);
956
      }
957
   else
958
      return(EMSYNTAX);
959
 
960
   return (0);
961
   }  /* end asm_arith_logic() */
962
 
963
 
964
 
965
/*
966
** Formats:   <nmemonic>, VN, RA, (RB or I)
967
** Examples:  ASSEQ, ASLE, ASLT, all trap assertion
968
**            instructions
969
**
970
*/
971
 
972
int
973
asm_vector(instr, parm, parm_count)
974
   struct   instr_t    *instr;
975
   struct   addr_29k_t *parm;
976
   int      parm_count;
977
   {
978
   if (parm_count != 3)
979
      return (EMSYNTAX);
980
 
981
   if (ISMEM(parm[0].memory_space) &&
982
       ISGENERAL(parm[1].memory_space) &&
983
       ISGENERAL(parm[2].memory_space)) {
984
      /* Make sure M flag is cleared */
985
      instr->op = (BYTE) (instr->op & 0xfe);
986
      instr->c = (BYTE) (parm[0].address & 0xff);
987
      instr->a = (BYTE) (parm[1].address & 0xff);
988
      instr->b = (BYTE) (parm[2].address & 0xff);
989
      }
990
   else
991
   if (ISMEM(parm[0].memory_space) &&
992
       ISGENERAL(parm[1].memory_space) &&
993
       ISMEM(parm[2].memory_space)) {
994
      /* Make sure M flag is set */
995
      instr->op = (BYTE) (instr->op | 0x01);
996
      instr->c = (BYTE) (parm[0].address & 0xff);
997
      instr->a = (BYTE) (parm[1].address & 0xff);
998
      instr->b = (BYTE) (parm[2].address & 0xff);
999
      }
1000
   else
1001
      return(EMSYNTAX);
1002
 
1003
   return (0);
1004
   }  /* end asm_vector() */
1005
 
1006
 
1007
 
1008
/*
1009
** Formats:   <nmemonic>, CE, CNTL, RA, (RB or I)
1010
** Examples:  LOAD, LOADM, STORE, all load and store
1011
**            instructions
1012
**
1013
*/
1014
 
1015
int
1016
asm_load_store(instr, parm, parm_count)
1017
   struct   instr_t    *instr;
1018
   struct   addr_29k_t *parm;
1019
   int      parm_count;
1020
   {
1021
   int  ce;
1022
   int  cntl;
1023
 
1024
   if (parm_count != 4)
1025
      return (EMSYNTAX);
1026
 
1027
   if (ISMEM(parm[0].memory_space) &&
1028
       ISMEM(parm[1].memory_space) &&
1029
       ISGENERAL(parm[2].memory_space) &&
1030
       ISGENERAL(parm[3].memory_space)) {
1031
      /* Make sure M flag is cleared */
1032
      instr->op = (BYTE) (instr->op & 0xfe);
1033
      if (parm[0].address > 1)
1034
         return (EMSYNTAX);
1035
      if (parm[1].address > 0x7f)
1036
         return (EMSYNTAX);
1037
      ce =   (int) ((parm[0].address << 7) & 0x80);
1038
      cntl = (int)  (parm[1].address & 0x7f);
1039
      instr->c = (BYTE) (ce | cntl);
1040
      instr->a = (BYTE) (parm[2].address & 0xff);
1041
      instr->b = (BYTE) (parm[3].address & 0xff);
1042
      }
1043
   else
1044
   if (ISMEM(parm[0].memory_space) &&
1045
       ISMEM(parm[1].memory_space) &&
1046
       ISGENERAL(parm[2].memory_space) &&
1047
       ISMEM(parm[3].memory_space)) {
1048
      /* Make sure M flag is set */
1049
      instr->op = (BYTE) (instr->op | 0x01);
1050
      if (parm[0].address > 1)
1051
         return (EMSYNTAX);
1052
      if (parm[1].address > 0x7f)
1053
         return (EMSYNTAX);
1054
      if (parm[3].address > 0xff)
1055
         return (EMSYNTAX);
1056
      ce =   (int) ((parm[0].address << 7) & 0x80);
1057
      cntl = (int)  (parm[1].address & 0x7f);
1058
      instr->c = (BYTE) (ce | cntl);
1059
      instr->a = (BYTE) (parm[2].address & 0xff);
1060
      instr->b = (BYTE) (parm[3].address & 0xff);
1061
      }
1062
   else
1063
      return(EMSYNTAX);
1064
 
1065
   return (0);
1066
   }  /* end asm_load_store() */
1067
 
1068
 
1069
 
1070
/*
1071
** Formats:   <nmemonic>
1072
** Examples:  HALT, INV, IRET
1073
*/
1074
/*ARGSUSED*/
1075
 
1076
int
1077
asm_no_parms(instr, parm, parm_count)
1078
   struct   instr_t    *instr;
1079
   struct   addr_29k_t *parm;
1080
   int      parm_count;
1081
   {
1082
   if (parm_count != 0)
1083
      return (EMSYNTAX);
1084
 
1085
   /* Put zeros in the "reserved" fields */
1086
   instr->c = 0;
1087
   instr->a = 0;
1088
   instr->b = 0;
1089
 
1090
   return (0);
1091
   }  /* end asm_no_parms() */
1092
 
1093
 
1094
int
1095
asm_one_parms(instr, parm, parm_count)
1096
   struct   instr_t    *instr;
1097
   struct   addr_29k_t *parm;
1098
   int      parm_count;
1099
   {
1100
   if (parm_count != 1)
1101
      return (EMSYNTAX);
1102
 
1103
   instr->c = (BYTE) (parm[0].address & 0x3);
1104
 
1105
   /* Put zeros in the "reserved" fields */
1106
   instr->a = 0;
1107
   instr->b = 0;
1108
 
1109
   return (0);
1110
   } /* end asm_one_parms */
1111
 
1112
 
1113
/*
1114
** Formats:   <nmemonic>, RC, RA, RB
1115
** Examples:  DADD, FADD, all floating point
1116
**            instructions
1117
**
1118
*/
1119
 
1120
int
1121
asm_float(instr, parm, parm_count)
1122
   struct   instr_t    *instr;
1123
   struct   addr_29k_t *parm;
1124
   int      parm_count;
1125
   {
1126
   if (parm_count != 3)
1127
      return (EMSYNTAX);
1128
 
1129
   if (ISGENERAL(parm[0].memory_space) &&
1130
       ISGENERAL(parm[1].memory_space) &&
1131
       ISGENERAL(parm[2].memory_space)) {
1132
      instr->c = (BYTE) (parm[0].address & 0xff);
1133
      instr->a = (BYTE) (parm[1].address & 0xff);
1134
      instr->b = (BYTE) (parm[2].address & 0xff);
1135
      }
1136
   else
1137
      return(EMSYNTAX);
1138
 
1139
   return (0);
1140
   }  /* end asm_float() */
1141
 
1142
 
1143
 
1144
/*
1145
** Formats:   <nmemonic> RA, <target>
1146
** Examples:  CALL, JMPF, JMPFDEC, JMPT
1147
**
1148
** Note:  This function is used only with the CALL,
1149
**        JMPF, JMPFDEC and JMPT operations.
1150
*/
1151
 
1152
int
1153
asm_call_jmp(instr, parm, parm_count)
1154
   struct   instr_t    *instr;
1155
   struct   addr_29k_t *parm;
1156
   int      parm_count;
1157
   {
1158
   if (parm_count != 2)
1159
      return (EMSYNTAX);
1160
 
1161
   if (ISGENERAL(parm[0].memory_space) &&
1162
       ISMEM(parm[1].memory_space)) {
1163
      /* Make sure M flag is set */
1164
      if (parm[1].memory_space != PC_RELATIVE)
1165
         instr->op = (BYTE) (instr->op | 0x01);
1166
      else
1167
         instr->op = (BYTE) instr->op ;
1168
      instr->c = (BYTE) ((parm[1].address >> 10) & 0xff);
1169
      instr->a = (BYTE) (parm[0].address & 0xff);
1170
      instr->b = (BYTE) ((parm[1].address >> 2) & 0xff);
1171
      }
1172
   else
1173
      return(EMSYNTAX);
1174
 
1175
   return (0);
1176
   }  /* end asm_call_jmp() */
1177
 
1178
 
1179
 
1180
 
1181
/*
1182
** Formats:   <nmemonic> RA, RB
1183
** Examples:  CALLI, JMPFI, JMPTI
1184
**
1185
** Note:  This function is used only with the CALLI,
1186
**        JMPFI and JMPTI (but not JMPI) operations.
1187
*/
1188
 
1189
int
1190
asm_calli_jmpi(instr, parm, parm_count)
1191
   struct   instr_t    *instr;
1192
   struct   addr_29k_t *parm;
1193
   int      parm_count;
1194
   {
1195
   if (parm_count != 2)
1196
      return (EMSYNTAX);
1197
 
1198
   if (ISGENERAL(parm[0].memory_space) &&
1199
       ISREG(parm[1].memory_space)) {
1200
      instr->c = 0;
1201
      instr->a = (BYTE) (parm[0].address & 0xff);
1202
      instr->b = (BYTE) (parm[1].address & 0xff);
1203
      }
1204
   else
1205
      return(EMSYNTAX);
1206
 
1207
   return (0);
1208
   }  /* end asm_calli_jmpi() */
1209
 
1210
 
1211
 
1212
/*
1213
** Formats:   <nmemonic> RC, RB, FS
1214
** Examples:  CLASS
1215
**
1216
** Note:  This function is used only with the CLASS
1217
**        operation.
1218
*/
1219
 
1220
int
1221
asm_class(instr, parm, parm_count)
1222
   struct   instr_t    *instr;
1223
   struct   addr_29k_t *parm;
1224
   int      parm_count;
1225
   {
1226
   if (parm_count != 3)
1227
      return (EMSYNTAX);
1228
 
1229
   if (ISGENERAL(parm[0].memory_space) &&
1230
       ISGENERAL(parm[1].memory_space) &&
1231
       ISMEM(parm[2].memory_space)) {
1232
      if (parm[2].address > 0x03)
1233
         return (EMSYNTAX);
1234
      instr->c = (BYTE) (parm[0].address & 0xff);
1235
      instr->a = (BYTE) (parm[1].address & 0xff);
1236
      instr->b = (BYTE) (parm[2].address & 0x03);
1237
      }
1238
   else
1239
      return(EMSYNTAX);
1240
 
1241
   return (0);
1242
   }  /* end asm_class() */
1243
 
1244
 
1245
/*
1246
** Formats:   <nmemonic> RC, (RB or I)
1247
** Examples:  CLZ
1248
**
1249
** Note:  This function is used only with the CLZ
1250
**        operation.
1251
*/
1252
 
1253
int
1254
asm_clz(instr, parm, parm_count)
1255
   struct   instr_t    *instr;
1256
   struct   addr_29k_t *parm;
1257
   int      parm_count;
1258
   {
1259
   if (parm_count != 2)
1260
      return (EMSYNTAX);
1261
 
1262
   if (ISGENERAL(parm[0].memory_space) &&
1263
       ISGENERAL(parm[1].memory_space)) {
1264
      /* Make sure M flag is cleared */
1265
      instr->op = (BYTE) (instr->op & 0xfe);
1266
      instr->c = (BYTE) (parm[0].address & 0xff);
1267
      instr->a = 0;
1268
      instr->b = (BYTE) (parm[1].address & 0xff);
1269
      }
1270
   else
1271
   if (ISGENERAL(parm[0].memory_space) &&
1272
       ISMEM(parm[1].memory_space)) {
1273
      /* Check param1 */
1274
      if ((parm[1].address) > 0xff)
1275
         return(EMSYNTAX);
1276
      /* Make sure M flag is set */
1277
      instr->op = (BYTE) (instr->op | 0x01);
1278
      instr->c = (BYTE) (parm[0].address & 0xff);
1279
      instr->a = 0;
1280
      instr->b = (BYTE) (parm[1].address & 0xff);
1281
      }
1282
   else
1283
      return(EMSYNTAX);
1284
 
1285
   return (0);
1286
   }  /* end asm_clz() */
1287
 
1288
 
1289
 
1290
/*
1291
** Formats:   <nmemonic> RA, <const16>
1292
** Examples:  CONST, CONSTN
1293
**
1294
*/
1295
 
1296
int
1297
asm_const(instr, parm, parm_count)
1298
   struct   instr_t    *instr;
1299
   struct   addr_29k_t *parm;
1300
   int      parm_count;
1301
   {
1302
   if (parm_count != 2)
1303
      return (EMSYNTAX);
1304
 
1305
   if (ISGENERAL(parm[0].memory_space) &&
1306
       ISMEM(parm[1].memory_space)) {
1307
      instr->c = (BYTE) ((parm[1].address >> 8) & 0xff);
1308
      instr->a = (BYTE) (parm[0].address & 0xff);
1309
      instr->b = (BYTE) (parm[1].address & 0xff);
1310
      }
1311
   else
1312
      return(EMSYNTAX);
1313
 
1314
   return (0);
1315
   }  /* end asm_const() */
1316
 
1317
 
1318
 
1319
/*
1320
** Formats:   <nmemonic> RA, <const16>
1321
** Examples:  CONSTH
1322
**
1323
*/
1324
 
1325
int
1326
asm_consth(instr, parm, parm_count)
1327
   struct   instr_t    *instr;
1328
   struct   addr_29k_t *parm;
1329
   int      parm_count;
1330
   {
1331
   if (parm_count != 2)
1332
      return (EMSYNTAX);
1333
 
1334
   if (ISGENERAL(parm[0].memory_space) &&
1335
       ISMEM(parm[1].memory_space)) {
1336
      instr->c = (BYTE) ((parm[1].address >> 24) & 0xff);
1337
      instr->a = (BYTE) (parm[0].address & 0xff);
1338
      instr->b = (BYTE) ((parm[1].address >> 16) & 0xff);
1339
      }
1340
   else
1341
      return(EMSYNTAX);
1342
 
1343
   return (0);
1344
   }  /* end asm_consth() */
1345
 
1346
 
1347
 
1348
/*
1349
** Formats:   <nmemonic> RC, RA, UI, RND, FD, FS
1350
** Examples:  CONVERT
1351
**
1352
** Note:  This function is used only with the CONVERT
1353
**        operation.
1354
**
1355
** Note:  Some assembler examples show this operation with
1356
**        only five parameters.  It should have six.
1357
*/
1358
 
1359
int
1360
asm_convert(instr, parm, parm_count)
1361
   struct   instr_t    *instr;
1362
   struct   addr_29k_t *parm;
1363
   int      parm_count;
1364
   {
1365
   BYTE  ui;
1366
   BYTE  rnd;
1367
   BYTE  fd;
1368
   BYTE  fs;
1369
 
1370
   if (parm_count != 6)
1371
      return (EMSYNTAX);
1372
 
1373
   if (ISGENERAL(parm[0].memory_space) &&
1374
       ISGENERAL(parm[1].memory_space) &&
1375
       ISMEM(parm[2].memory_space) &&
1376
       ISMEM(parm[3].memory_space) &&
1377
       ISMEM(parm[4].memory_space) &&
1378
       ISMEM(parm[5].memory_space)) {
1379
      if (parm[2].address > 1)
1380
         return (EMSYNTAX);
1381
      if (parm[3].address > 0x07)
1382
         return (EMSYNTAX);
1383
      if (parm[4].address > 0x03)
1384
         return (EMSYNTAX);
1385
      if (parm[5].address > 0x03)
1386
         return (EMSYNTAX);
1387
      ui =  (BYTE) ((parm[2].address << 7) & 0x80);
1388
      rnd = (BYTE) ((parm[3].address << 4) & 0x70);
1389
      fd =  (BYTE) ((parm[4].address << 2) & 0x0c);
1390
      fs =  (BYTE) (parm[5].address & 0x03);
1391
      instr->c = (BYTE) (parm[0].address & 0xff);
1392
      instr->a = (BYTE) (parm[1].address & 0xff);
1393
      instr->b = (ui | rnd | fd | fs);
1394
      }
1395
   else
1396
      return(EMSYNTAX);
1397
 
1398
   return (0);
1399
   }  /* end asm_convert() */
1400
 
1401
 
1402
 
1403
/*
1404
** Formats:   <nmemonic> RC, RA
1405
** Examples:  DIV0
1406
**
1407
** Note:  This function is used only with the DIV0
1408
**        operation.
1409
*/
1410
 
1411
int
1412
asm_div0(instr, parm, parm_count)
1413
   struct   instr_t    *instr;
1414
   struct   addr_29k_t *parm;
1415
   int      parm_count;
1416
   {
1417
   if (parm_count != 2)
1418
      return (EMSYNTAX);
1419
 
1420
   if (ISGENERAL(parm[0].memory_space) &&
1421
       ISGENERAL(parm[1].memory_space)) {
1422
      /* Make sure M flag is cleared */
1423
      instr->op = (BYTE) (instr->op & 0xfe);
1424
      instr->c = (BYTE) (parm[0].address & 0xff);
1425
      instr->a = 0;
1426
      instr->b = (BYTE) (parm[1].address & 0xff);
1427
      }
1428
   else
1429
   if (ISGENERAL(parm[0].memory_space) &&
1430
       ISMEM(parm[1].memory_space)) {
1431
      /* Check immediate value */
1432
      if (parm[1].address > 0xff)
1433
         return (EMSYNTAX);
1434
      /* Make sure M flag is set */
1435
      instr->op = (BYTE) (instr->op | 0x01);
1436
      instr->c = (BYTE) (parm[0].address & 0xff);
1437
      instr->a = 0;
1438
      instr->b = (BYTE) (parm[1].address & 0xff);
1439
      }
1440
   else
1441
      return(EMSYNTAX);
1442
 
1443
   return (0);
1444
   }  /* end asm_div0() */
1445
 
1446
 
1447
/*
1448
** Formats:   <nmemonic> RC, RA
1449
** Examples:  EXHWS
1450
**
1451
** Note:  This function is used only with the EXHWS
1452
**        operation.
1453
*/
1454
 
1455
int
1456
asm_exhws(instr, parm, parm_count)
1457
   struct   instr_t    *instr;
1458
   struct   addr_29k_t *parm;
1459
   int      parm_count;
1460
   {
1461
   if (parm_count != 2)
1462
      return (EMSYNTAX);
1463
 
1464
   if (ISGENERAL(parm[0].memory_space) &&
1465
       ISGENERAL(parm[1].memory_space)){
1466
      instr->c = (BYTE) (parm[0].address & 0xff);
1467
      instr->a = (BYTE) (parm[1].address & 0xff);
1468
      instr->b = 0;
1469
      }
1470
   else
1471
      return(EMSYNTAX);
1472
 
1473
   return (0);
1474
   }  /* end asm_exhws() */
1475
 
1476
 
1477
 
1478
 
1479
/*
1480
** Formats:   <nmemonic>  <target>
1481
** Examples:  JMP
1482
**
1483
** Note:  This function is used only with the JMP
1484
**        operation.
1485
**
1486
** Note:  This function will only do absolute jumps.
1487
*/
1488
 
1489
int
1490
asm_jmp(instr, parm, parm_count)
1491
   struct   instr_t    *instr;
1492
   struct   addr_29k_t *parm;
1493
   int      parm_count;
1494
   {
1495
   if (parm_count != 1)
1496
      return (EMSYNTAX);
1497
 
1498
   if (ISMEM(parm[0].memory_space)) {
1499
      /* Make sure M flag is set */
1500
      if (parm[0].memory_space != PC_RELATIVE)
1501
        instr->op = (BYTE) (instr->op | 0x01);
1502
      else
1503
        instr->op = (BYTE) instr->op ;
1504
      instr->c = (BYTE) ((parm[0].address >> 10) & 0xff);
1505
      instr->a = 0;
1506
      instr->b = (BYTE) ((parm[0].address >> 2) & 0xff);
1507
      }
1508
   else
1509
      return(EMSYNTAX);
1510
 
1511
   return (0);
1512
   }  /* end asm_jmp() */
1513
 
1514
 
1515
 
1516
/*
1517
** Formats:   <nmemonic> RB
1518
** Examples:  JMPI
1519
**
1520
** Note:  This function is used only with the JMPI
1521
**        operation.
1522
*/
1523
 
1524
int
1525
asm_jmpi(instr, parm, parm_count)
1526
   struct   instr_t    *instr;
1527
   struct   addr_29k_t *parm;
1528
   int      parm_count;
1529
   {
1530
   if (parm_count != 1)
1531
      return (EMSYNTAX);
1532
 
1533
   if (ISGENERAL(parm[0].memory_space)) {
1534
      instr->c = 0;
1535
      instr->a = 0;
1536
      instr->b = (BYTE) (parm[0].address & 0xff);
1537
      }
1538
   else
1539
      return(EMSYNTAX);
1540
 
1541
   return (0);
1542
   }  /* end asm_jmpi() */
1543
 
1544
 
1545
 
1546
/*
1547
** Formats:   <nmemonic> RC, SA
1548
** Examples:  MFSR
1549
**
1550
** Note:  This function is used only with the MFSR
1551
**        operation.
1552
*/
1553
 
1554
int
1555
asm_mfsr(instr, parm, parm_count)
1556
   struct   instr_t    *instr;
1557
   struct   addr_29k_t *parm;
1558
   int      parm_count;
1559
   {
1560
   if (parm_count != 2)
1561
      return (EMSYNTAX);
1562
 
1563
   if (ISGENERAL(parm[0].memory_space) &&
1564
       ISSPECIAL(parm[1].memory_space)) {
1565
      instr->c = (BYTE) (parm[0].address & 0xff);
1566
      instr->a = (BYTE) (parm[1].address & 0xff);
1567
      instr->b = 0;
1568
      }
1569
   else
1570
      return(EMSYNTAX);
1571
 
1572
   return (0);
1573
   }  /* end asm_mfsr() */
1574
 
1575
 
1576
 
1577
/*
1578
** Formats:   <nmemonic> SA, RB
1579
** Examples:  MTSR
1580
**
1581
** Note:  This function is used only with the MTSR
1582
**        operation.
1583
*/
1584
 
1585
int
1586
asm_mtsr(instr, parm, parm_count)
1587
   struct   instr_t    *instr;
1588
   struct   addr_29k_t *parm;
1589
   int      parm_count;
1590
   {
1591
   if (parm_count != 2)
1592
      return (EMSYNTAX);
1593
 
1594
   if (ISSPECIAL(parm[0].memory_space) &&
1595
       ISGENERAL(parm[1].memory_space)) {
1596
      instr->c = 0;
1597
      instr->a = (BYTE) (parm[0].address & 0xff);
1598
      instr->b = (BYTE) (parm[1].address & 0xff);
1599
      }
1600
   else
1601
      return(EMSYNTAX);
1602
 
1603
   return (0);
1604
   }  /* end asm_mtsr() */
1605
 
1606
 
1607
 
1608
 
1609
/*
1610
** Formats:   <nmemonic> SA, <const16>
1611
** Examples:  MTSRIM
1612
**
1613
** Note:  This function is used only with the MTSRIM
1614
**        operation.
1615
*/
1616
 
1617
int
1618
asm_mtsrim(instr, parm, parm_count)
1619
   struct   instr_t    *instr;
1620
   struct   addr_29k_t *parm;
1621
   int      parm_count;
1622
   {
1623
   if (parm_count != 2)
1624
      return (EMSYNTAX);
1625
 
1626
   if (ISSPECIAL(parm[0].memory_space) &&
1627
       ISMEM(parm[1].memory_space)) {
1628
      instr->c = (BYTE) ((parm[1].address >> 8) & 0xff);
1629
      instr->a = (BYTE) (parm[0].address & 0xff);
1630
      instr->b = (BYTE) (parm[1].address & 0xff);
1631
      }
1632
   else
1633
      return(EMSYNTAX);
1634
 
1635
   return (0);
1636
   }  /* end asm_mtsrim() */
1637
 
1638
 
1639
 
1640
 
1641
/*
1642
** Formats:   <nmemonic> RC, RA
1643
** Examples:  MFTLB
1644
**
1645
** Note:  This function is used only with the MFTLB
1646
**        operation.
1647
*/
1648
 
1649
int
1650
asm_mftlb(instr, parm, parm_count)
1651
   struct   instr_t    *instr;
1652
   struct   addr_29k_t *parm;
1653
   int      parm_count;
1654
   {
1655
   if (parm_count != 2)
1656
      return (EMSYNTAX);
1657
 
1658
   if (ISGENERAL(parm[0].memory_space) &&
1659
       ISGENERAL(parm[1].memory_space)) {
1660
      instr->c = (BYTE) (parm[0].address & 0xff);
1661
      instr->a = (BYTE) (parm[1].address & 0xff);
1662
      instr->b = 0;
1663
      }
1664
   else
1665
      return(EMSYNTAX);
1666
 
1667
   return (0);
1668
   }  /* end asm_mftlb() */
1669
 
1670
 
1671
/*
1672
** Formats:   <nmemonic> RA, RB
1673
** Examples:  MTTLB
1674
**
1675
** Note:  This function is used only with the MTTLB
1676
**        operation.
1677
*/
1678
 
1679
int
1680
asm_mttlb(instr, parm, parm_count)
1681
   struct   instr_t    *instr;
1682
   struct   addr_29k_t *parm;
1683
   int      parm_count;
1684
   {
1685
   if (parm_count != 2)
1686
      return (EMSYNTAX);
1687
 
1688
   if (ISGENERAL(parm[0].memory_space) &&
1689
       ISGENERAL(parm[1].memory_space)) {
1690
      instr->c = 0;
1691
      instr->a = (BYTE) (parm[0].address & 0xff);
1692
      instr->b = (BYTE) (parm[1].address & 0xff);
1693
      }
1694
   else
1695
      return(EMSYNTAX);
1696
 
1697
   return (0);
1698
   }  /* end asm_mttlb() */
1699
 
1700
 
1701
 
1702
 
1703
/*
1704
** Formats:   <nmemonic> RC, RA, FS
1705
** Examples:  SQRT
1706
**
1707
** Note:  This function is used only with the SQRT
1708
**        operation.
1709
*/
1710
 
1711
int
1712
asm_sqrt(instr, parm, parm_count)
1713
   struct   instr_t    *instr;
1714
   struct   addr_29k_t *parm;
1715
   int      parm_count;
1716
   {
1717
   if (parm_count != 3)
1718
      return (EMSYNTAX);
1719
 
1720
   if (ISGENERAL(parm[0].memory_space) &&
1721
       ISGENERAL(parm[1].memory_space) &&
1722
       ISMEM(parm[2].memory_space)) {
1723
      instr->c = (BYTE) (parm[0].address & 0xff);
1724
      instr->a = (BYTE) (parm[1].address & 0xff);
1725
      instr->b = (BYTE) (parm[2].address & 0x03);
1726
      }
1727
   else
1728
      return(EMSYNTAX);
1729
 
1730
   return (0);
1731
   }  /* end asm_sqrt() */
1732
 
1733
 
1734
 
1735
/*
1736
** Formats:   <nmemonic>, VN, RA, RB
1737
** Examples:  EMULATE
1738
**
1739
** Note:  This function is used only with the EMULATE
1740
**        operation.
1741
**
1742
*/
1743
 
1744
int
1745
asm_emulate(instr, parm, parm_count)
1746
   struct   instr_t    *instr;
1747
   struct   addr_29k_t *parm;
1748
   int      parm_count;
1749
   {
1750
   if (parm_count != 3)
1751
      return (EMSYNTAX);
1752
 
1753
   if (ISMEM(parm[0].memory_space) &&
1754
       ISGENERAL(parm[1].memory_space) &&
1755
       ISGENERAL(parm[2].memory_space)) {
1756
      instr->c = (BYTE) (parm[0].address & 0xff);
1757
      instr->a = (BYTE) (parm[1].address & 0xff);
1758
      instr->b = (BYTE) (parm[2].address & 0xff);
1759
      }
1760
   else
1761
      return(EMSYNTAX);
1762
 
1763
   return (0);
1764
   }  /* end asm_emulate() */
1765
 
1766
 
1767
 
1768
 
1769
 

powered by: WebSVN 2.1.0

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