summaryrefslogtreecommitdiff
path: root/sdas/asrab/rabadr.c
blob: f357dba5fe1aab93c3c5f30c8b130a9fe0662f29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/* rabadr.c */

/*
 *  Copyright (C) 1989-2009  Alan R. Baldwin
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Alan R. Baldwin
 * 721 Berkeley St.
 * Kent, Ohio  44240
 * 
 * ported to the Rabbit2000 by
 * Ulrich Raich and Razaq Ijoduola
 * PS Division
 * CERN
 * CH-1211 Geneva-23
 * email: Ulrich dot Raich at cern dot ch
 */

/*
 * Extensions: P. Felber
 *
 * Altered by Leland Morrison to support rabbit 2000 
 *   and rabbit 4000 instruction sets (2011)
 */

#include "asxxxx.h"
#include "rab.h"

/*
 * Read an address specifier. Pack the
 * address information into the supplied
 * `expr' structure. Return the mode of
 * the address.
 *
 * This addr(esp) routine performs the following addressing decoding:
 *
 *      address         mode            flag            addr            base
 *      #n              S_IMMED         0               n               NULL
 *      label           s_type          ----            s_addr          s_area
 *      [REG]           S_IND+icode     0               0               NULL
 *      [label]         S_INDM          ----            s_addr          s_area
 *      offset[REG]     S_IND+icode     ----            offset          ----
 */
int
addr(esp)
struct expr *esp;
{
        int c, mode, indx;

        if ((c = getnb()) == '#') {
                expr(esp, 0);
                esp->e_mode = S_IMMED;
#if 0
                /* ljm - leading digit is used for offset for dd(ix|iy|sp) */
        } else if ((c == '-') || ((c >= '0') && (c <= '9'))) {
          unget(c);
          expr(esp, 0);
          esp->e_mode = S_IMMED;
#endif
        } else
        if (c == LFIND) {
          /* ljm comment -
           *      '(' number ')'   
           *  or  '(' register=[hl,ix,iy,sp,bc,de] ')'
           *     ref to memory, scan the next 'symbol' to see if
           *     it is a register or an absolute address
           */
                if ((indx = admode(R8)) != 0) {
                        mode = S_INDB;
                } else
                if ((indx = admode(R8X)) != 0) {
                        mode = S_R8X;
                        aerr();
                } else
                if ((indx = admode(R16X)) != 0) {
                        mode = S_R16X;
                        aerr();
                } else
                if ((indx = admode(R16)) != 0) {
                        mode = S_INDR;
                } else {
                        mode = S_INDM;
                        expr(esp, 0);
                        esp->e_mode = mode;
                }
                if (indx) {
                        esp->e_mode = (mode + indx)&0xFF;
                        esp->e_base.e_ap = NULL;
                }
                /* ljm comment -
                 *   flag an error if the closing paren is absent
                 */
                if ((c = getnb()) != RTIND) {
                        qerr();
                }
        } else {
                unget(c);
          /* ljm -
           *   cases:
           *     register
           *     symbol
           *     symbol(register)
           *     number
           *     number(register)
           *
           * scan the list(s) of registers to see if the
           * name matches the name of one of the processor
           * registers
           */
                if ((indx = admode(R8)) != 0) {
                        mode = S_R8;
                } else
                if ((indx = admode(R8X)) != 0) {
                        mode = S_R8X;
                } else
                if ((indx = admode(R16X)) != 0) {
                        mode = S_R16X;
                } else
                if ((indx = admode(R16)) != 0) {
                        mode = S_R16;
                } else
                if ((indx = admode(R32_JKHL)) != 0) {
                        mode = S_R32_JKHL;
                } else
                if ((indx = admode(R32_BCDE)) != 0) {
                        mode = S_R32_BCDE;
                } else
                if ((indx = admode(RXPC)) != 0) {
                        mode = S_RXPC;
                } else {
                        mode = S_USER;
                        expr(esp, 0);
                        esp->e_mode = mode;
                }
                if (indx) {
                        esp->e_addr = indx&0xFF;
                        esp->e_mode = mode;
                        esp->e_base.e_ap = NULL;
                }
                if ((c = getnb()) == LFIND) {
                        indx = admode(R16);
                        if ((indx&0xFF)==IX || (indx&0xFF)==IY ||
                            (indx&0xFF)==SP)
                        {
                          esp->e_mode = S_INDR + (indx&0xFF);
                        } else if ( (indx&0xFF)==HL ) {
                          esp->e_mode = S_IDHL_OFFSET;
                        } else {
                                aerr();
                        }
                        if ((c = getnb()) != RTIND)
                                qerr();
                } else {
                        unget(c);
                }
        }
        return (esp->e_mode);
}

/*
 * Enter admode() to search a specific addressing mode table
 * for a match. Return the addressing value on a match or
 * zero for no match.
 */
int
admode(sp)
struct adsym *sp;
{
        char *ptr;
        int i;
        char *ips;

        ips = ip;
        unget(getnb());

        i = 0;
        while ( *(ptr = &sp[i].a_str[0]) ) {
                if (srch(ptr)) {
                        return(sp[i].a_val);
                }
                i++;
        }
        ip = ips;
        return(0);
}

/*
 *      srch --- does string match ?
 */
int
srch(str)
char *str;
{
        char *ptr;
        ptr = ip;

        while (*ptr && *str) {
                if (ccase[*ptr & 0x007F] != ccase[*str & 0x007F])
                        break;
                ptr++;
                str++;
        }
        if (ccase[*ptr & 0x007F] == ccase[*str  & 0x007F]) {
                ip = ptr;
                return(1);
        }

        if (!*str) {
                if (!(ctype[*ptr & 0x007F] & LTR16)) {
                        ip = ptr;
                        return(1);
                }
        }
        return(0);
}

/*
 * Registers
 */

struct  adsym   R8[] = {
    {   "b",    B|0400  },
    {   "c",    C|0400  },
    {   "d",    D|0400  },
    {   "e",    E|0400  },
    {   "h",    H|0400  },
    {   "l",    L|0400  },
    {   "a",    A|0400  },
    {   "",     0000    }
};

struct  adsym   R8X[] = {
    {   "eir",  EIR|0400},
    {   "iir",  IIR|0400},
    {   "",     0000    }
};

struct  adsym   R8IP[] = {
    {   "ip",   IP|0400 },
    {   "",     0000    }
};

struct  adsym   R16[] = {
    {   "bc",   BC|0400 },
    {   "de",   DE|0400 },
    {   "hl",   HL|0400 },
    {   "sp",   SP|0400 },
    {   "ix",   IX|0400 },
    {   "iy",   IY|0400 },
    {   "",     0000    }
};

struct  adsym   R16X[] = {
    {   "af'",  AF|0400 },      /* af' must be first !!! */
    {   "af",   AF|0400 },
    {   "",     0000    }
};

struct  adsym   R32_BCDE[] = {
  {   "bcde",   BCDE|0400 },
  {   "",       0000      }
};

struct  adsym   R32_JKHL[] = {
  {   "jkhl",   JKHL|0400 },
  {   "",       0000      }
};

struct  adsym   RXPC[] = {
  {   "xpc",    1|0400  },
  {   "",       0000    }
};

/*
 * Conditional definitions
 */

struct  adsym   CND[] = {
    {   "NZ",   NZ|0400 },
    {   "Z",    Z |0400 },
    {   "NC",   NC|0400 },
    {   "C",    CS|0400 },
    {   "LZ",   PO|0400 },
    {   "LO",   PE|0400 },
    {   "P",    P |0400 },
    {   "M",    M |0400 },
    {   "",     0000    }
};

struct  adsym   ALT_CND[] = {
    {   "GT",   CC_GT|0400  },
    {   "GTU",  CC_GTU|0400 },
    {   "LT",   CC_LT|0400  },
    {   "V",    CC_V |0400  },
    {   "NZ",   CC_NZ|0400  },
    {   "Z",    CC_Z |0400  },
    {   "NC",   CC_NC|0400  },
    {   "C",    CC_C |0400  },
    {   "",     0000        }
};