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

Subversion Repositories i650

[/] [i650/] [trunk/] [utils/] [ibm650_soap2/] [ibm650_soap2/] [soap2.h] - Blame information for rev 29

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 eightycc
//////////////////////////////////////////////////////////////////////////////////
2
// IBM 650 Reconstruction in Verilog (i650)
3
// 
4
// This file is part of the IBM 650 Reconstruction in Verilog (i650) project
5
// http:////www.opencores.org/project,i650
6
//
7
// Description: An implementation of SOAP 2 for the IBM 650.
8
// 
9
// Additional Comments: .
10
//
11
// Copyright (c) 2015 Robert Abeles
12
//
13
// This source file is free software; you can redistribute it
14
// and/or modify it under the terms of the GNU Lesser General
15
// Public License as published by the Free Software Foundation;
16
// either version 2.1 of the License, or (at your option) any
17
// later version.
18
//
19
// This source is distributed in the hope that it will be
20
// useful, but WITHOUT ANY WARRANTY; without even the implied
21
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
22
// PURPOSE.  See the GNU Lesser General Public License for more
23
// details.
24
//
25
// You should have received a copy of the GNU Lesser General
26
// Public License along with this source; if not, download it
27
// from http://www.opencores.org/lgpl.shtml
28
//////////////////////////////////////////////////////////////////////////////////
29
 
30
#ifndef ibm650_soap2_soap2_h
31
#define ibm650_soap2_soap2_h
32
 
33
#include <string>
34
#include <iostream>
35
#include <fstream>
36
#include <sstream>
37
#include <iomanip>
38
#include <vector>
39
#include <map>
40
#include "ibm_codec.h"
41
 
42
using namespace std;
43
 
44
struct region {
45
    u_int8_t  code;
46
    u_int32_t start;
47
 
48
    region(u_int8_t c, u_int32_t s) : code(c), start(s) {}
49
};
50
 
51
struct symbol {
52
    string            name;
53
    u_int32_t         location;
54
    vector<u_int32_t> ref_line;
55
 
56
    symbol(string n, u_int32_t l, u_int32_t r) : name(n), location(l) {
57
        ref_line.push_back(r);
58
    }
59
    void add_ref(u_int32_t r) {ref_line.push_back(r);}
60
};
61
 
62
enum {
63
    real_op,
64
    alias_op,
65
    unused_op,
66
    pseudo_op,
67
    final_op
68
};
69
 
70
enum {
71
    pseudo_alf = 1000,
72
    pseudo_bla,
73
    pseudo_blr,
74
    pseudo_bop,
75
    pseudo_equ,
76
    pseudo_hed,
77
    pseudo_pat,
78
    pseudo_rbr,
79
    pseudo_reg,
80
    pseudo_rel,
81
    pseudo_req,
82
    pseudo_syn
83
};
84
 
85
enum {
86
    asmflag_c = 0x0001,
87
    asmflag_e = 0x0002,
88
    asmflag_p = 0x0004,
89
    asmflag_k = 0x0008
90
};
91
 
92
struct opcode {
93
    string    op;
94
    u_int32_t code;
95
    u_int32_t group;
96
    u_int32_t d_even;
97
    u_int32_t d_odd;
98
    u_int32_t i_even;
99
    u_int32_t i_odd;
100
    u_int32_t type;
101
    string    alias;
102
 
103
    opcode(const string& o, u_int32_t c, u_int32_t g,u_int32_t de, u_int32_t dodd, u_int32_t ie, u_int32_t io, u_int32_t t)
104
     : op(o)
105
     , code(c)
106
     , group(g)
107
     , d_even(de)
108
     , d_odd(dodd)
109
     , i_even(ie)
110
     , i_odd(io)
111
     , type(t)
112
    {}
113
 
114
    opcode(const string& o, const string& a) : op(o), alias(a), type(alias_op) {}
115
 
116
    inline bool opt_A() const {return (8 == (group / 100));}
117
    inline bool opt_B() const {return (8 == ((group / 10) % 10));}
118
    inline bool opt_C() const {return (8 == (group % 10));}
119
};
120
 
121
enum fieldtype {
122
    field_blank,
123
    field_symbolic,
124
    field_numeric,
125
    field_region,
126
    field_error
127
};
128
 
129
struct asmfield {
130
    string    src;
131
    fieldtype type;
132
    u_int32_t nval;
133
    string    symbol;
134
    u_int8_t  region;
135
 
136
    asmfield(const string&, u_int8_t);
137
};
138
 
139
class biq_number {
140
    u_int64_t val;
141
 
142
  public:
143
    biq_number(const biq_number &n) {val = n.val;}
144
    biq_number(bool s, u_int64_t v) {
145
        val = (((s)? 1LL : 0LL) << 63) | (v % 10000000000LL);
146
    }
147
    biq_number() : val(0) {}
148
    bool sign() const {return (val & 0x8000000000000000LL);}
149
    u_int64_t value() const {return (val & 0x7fffffffffffffffLL);}
150
    void set_sign(bool s) {
151
        val = (val & 0x7fffffffffffffffLL) | (((s)? 1LL : 0LL) << 63);
152
    }
153
    void set_value(u_int64_t v) {
154
        val = (val & 0x8000000000000000LL) | (v % 10000000000LL);
155
    }
156
};
157
 
158
class memory {
159
    vector<biq_number> mem;
160
 
161
public:
162
    memory(u_int32_t sz) : mem(sz) {}
163
 
164
    void load_7wd_deck(istream &);
165
    biq_number& operator[](unsigned ix) {ix %= mem.size(); return mem[ix];}
166
};
167
 
168
class memmap {
169
    u_int32_t size;
170
    u_int32_t origin;
171
    vector<int> allocmap;
172
    int32_t freectr;
173
 
174
public:
175
    memmap(u_int32_t s, u_int32_t o);
176
    void reserve(u_int32_t addr);
177
    void reserve(u_int32_t fwa, u_int32_t sz);
178
    void unreserve(u_int32_t addr);
179
    void unreserve(u_int32_t fwa, u_int32_t sz);
180
    void reset();
181
    int32_t optimum(u_int32_t rot);
182
    inline bool isfull() const {return (freectr <= 0);}
183
    inline bool isvalid(u_int32_t addr) const {return (addr >= origin) && (addr < (origin+size));}
184
    inline bool isvalid(u_int32_t fwa, u_int32_t sz) const { return (fwa >= origin) && ((fwa + sz - 1) < (origin+size));}
185
    void print_availtab(ostream &);
186
};
187
 
188
enum addr_type {
189
    addr_gs,
190
    addr_ias,
191
    addr_800X,
192
    addr_invalid
193
};
194
 
195
class soap2 {
196
    typedef map<string, symbol*>::iterator symiter;
197
    map<string, symbol*>   symboltab;   // symbol -> location
198
    typedef map<u_int8_t, region*>::iterator regiter;
199
    map<u_int8_t, region*> regiontab;   // character -> region
200
    memmap                 gsmap;       // general storage (drum) allocation map
201
    map<string, opcode*>   opcodetab;   // opcode lookup table
202
    typedef map<string, opcode*>::iterator opiter;
203
    vector<opcode*>        opbycodetab; // opcode indexed by opcode
204
    istream               &input_deck;
205
    istream               &check_deck;
206
    ostream               &output_deck;
207
    ostream               &listing;
208
    memory                 ibm_obj;
209
    ibm_codec              codec;
210
    int                    flags;
211
 
212
    void init_opcodetab();
213
 
214
    ostringstream    errors;
215
    u_int32_t cardnumber;
216
    u_int8_t  hed_char;
217
 
218
    int32_t   opt_addr;
219
    int32_t   opt_gs;
220
    int32_t   opt_ias;
221
    int32_t   opt_800x;
222
    int32_t   opt_b;
223
 
224
    // statement currently under assembly
225
    string    src;
226
    string    src_type;
227
    string    src_sign;
228
    string    src_loc;
229
    string    src_op;
230
    string    src_d;
231
    string    src_dtag;
232
    string    src_i;
233
    string    src_itag;
234
    string    src_comm;
235
    string    src_fcom;
236
 
237
    u_int32_t asm_loc;
238
    u_int32_t asm_op;
239
    u_int32_t asm_d;
240
    u_int32_t asm_i;
241
 
242
    opcode   *op;
243
 
244
    bool blank_loc;
245
    bool blank_op;
246
    bool blank_d;
247
    bool blank_i;
248
    bool punch_800x;
249
    bool bypass;
250
 
251
    enum opt_type {
252
        opt_d,
253
        opt_i,
254
    };
255
    u_int32_t find_optimal_wt(opt_type);
256
    u_int32_t find_optimal_800x(opt_type, u_int32_t);
257
 
258
    void process_loc();
259
    void process_loc_addr();
260
    void process_op();
261
    void process_d();
262
    void process_d_addr();
263
    void process_i();
264
    void process_i_addr();
265
 
266
    void assemble();
267
    void assemble_statement();
268
    void assemble_command();
269
    void assemble_comment();
270
    void assemble_relocate();
271
    void assemble_realop();
272
    void assemble_pseudo();
273
    void check_obj(ostream &);
274
 
275
    void punch_comment(ostream &);
276
    void punch_command(ostream &);
277
    void print_comment(ostream &);
278
    void print_command(ostream &);
279
 
280
    void print_symtab(ostream &);
281
    void print_availtab(ostream &);
282
    void print_regiontab(ostream &);
283
 
284
    void error_message(const string &);
285
 
286
public:
287
    soap2(int, int, istream &, ostream &, ostream &, istream &);
288
    inline u_int8_t ascii_to_650(int c) const {
289
      return codec.valid_code650_for_ascii(c)? codec.ascii_to_code650(c) : 0;
290
    }
291
};
292
 
293
#endif

powered by: WebSVN 2.1.0

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