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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gen_or1k_isa/] [sources/] [gen_or1k_isa.c] - Blame information for rev 14

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

Line No. Rev Author Line
1 14 lampret
 
2
#include <stdio.h>
3
 
4
#define NO_RELOC 20
5
#define RELOC_32 1
6
#define RELOC_8 2
7
#define RELOC_CONST 3
8
#define RELOC_CONSTH 4
9
 
10
#include "or1.h"
11
#include "or1k_isadesc.h"
12
 
13
/* types of data in encoding field. */
14
typedef enum { opcode, reserved, operand } encfld_types;
15
 
16
/* encoding transformed for TeX output */
17
struct {
18
        int bitpos[33];
19
        int fldcnt;
20
        int insn_size;
21
        struct {
22
                encfld_types type;
23
                int value;
24
                int bitsize;
25
        } field[50];
26
} decoded;
27
 
28
void print_encoding()
29
{
30
        int i, j;
31
 
32
        printf("\\vspace{10mm}\n");
33
        printf("{\\centering \\begin{tabular}{");
34
 
35
        /* organization of the table */
36
        for(i = 1; i <= decoded.fldcnt; i++) {
37
                printf("|");
38
                for(j = 0; j < decoded.field[i].bitsize; j++)
39
                        printf("c");
40
        }
41
        printf("|}\n\\hline\n");
42
 
43
        /* print first row of the table */
44
        for(i = decoded.insn_size - 1; i > 0; i--)
45
                if (decoded.bitpos[i])
46
                        printf("%d&\n", i);
47
                else
48
                        printf("&\n");
49
        printf("0\\\\\n\\hline\n");
50
 
51
        /* print second row of the table */
52
        for(i = 1; i <= decoded.fldcnt; i++) {
53
                if (decoded.field[i].type == opcode) {
54
                        printf("\\multicolumn{%d}{", decoded.field[i].bitsize);
55
                        printf("%s", (i == 1 ? "|":""));
56
                        printf("c|}{opcode 0x%x}", decoded.field[i].value);
57
                } else if (decoded.field[i].type == operand) {
58
                        printf("\\multicolumn{%d}{", decoded.field[i].bitsize);
59
                        printf("%s", (i == 1 ? "|":""));
60
                        printf("c|}{%c}", decoded.field[i].value);
61
                } else if (decoded.field[i].type == reserved) {
62
                        printf("\\multicolumn{%d}{", decoded.field[i].bitsize);
63
                        printf("%s", (i == 1 ? "|":""));
64
                        printf("c|}{reserved}", decoded.field[i].value);
65
                }
66
                if (i == decoded.fldcnt)
67
                        printf("\\\\\n");
68
                else
69
                        printf("&\n");
70
        }
71
        printf("\n\\hline\n");
72
 
73
        /* print third row of the table */
74
        for(i = 1; i < decoded.fldcnt; i++) {
75
                printf("\\multicolumn{%d}", decoded.field[i].bitsize);
76
                printf("{%sc|}{%d bits}&\n", (i == 1 ? "|":""), decoded.field[i].bitsize);
77
        }
78
        printf("\\multicolumn{%d}", decoded.field[i].bitsize);
79
        printf("{%sc|}{%d bits}\\\\\n", (i == 1 ? "|":""), decoded.field[i].bitsize);
80
        printf("\n\\hline\n");
81
        printf("\\end{tabular}\\par}\n");
82
 
83
}
84
 
85
void decode(struct or1_opcode *insn)
86
{
87
        int opc_pos = 0;
88
        char *enc;
89
        encfld_types last;
90
        char lastoperand;
91
        int tmp;
92
 
93
        if (!insn) {
94
                printf("internal error: insn pointer NULL\n");
95
                return;
96
        }
97
 
98
        memset(&decoded, 0, sizeof(decoded));
99
 
100
        if ((insn->name[0] == 'h') && (insn->name[1] == '.'))
101
                decoded.insn_size = opc_pos = 16;
102
        else
103
                decoded.insn_size = opc_pos = 32;
104
 
105
        last = -1;
106
 
107
        for (enc = insn->encoding; *enc != '\0'; )
108
                if ((*enc == '0') && (*(enc+1) == 'x')) {
109
                        int tmp = strtol(enc, NULL, 16);
110
                        if (last != opcode) {
111
                                decoded.bitpos[opc_pos] = 1;
112
                                decoded.bitpos[opc_pos - 1] = 1;
113
                                decoded.field[++decoded.fldcnt].type = opcode;
114
                        }
115
                        decoded.field[decoded.fldcnt].value <<= 4;
116
                        decoded.field[decoded.fldcnt].value += tmp;
117
                        decoded.field[decoded.fldcnt].bitsize += 4;
118
                        opc_pos -= 4;
119
                        enc += 3;
120
                        last = opcode;
121
                }
122
                else if (*enc == '0') {
123
                       if (last != opcode) {
124
                                decoded.bitpos[opc_pos] = 1;
125
                                decoded.bitpos[opc_pos - 1] = 1;
126
                                decoded.field[++decoded.fldcnt].type = opcode;
127
                        }
128
                        decoded.field[decoded.fldcnt].value <<= 1;
129
                        decoded.field[decoded.fldcnt].bitsize += 1;
130
                        opc_pos--;
131
                        enc++;
132
                        last = opcode;
133
                }
134
                else if (*enc == '-') {
135
                       if (last != reserved) {
136
                                decoded.bitpos[opc_pos] = 1;
137
                                decoded.bitpos[opc_pos - 1] = 1;
138
                                decoded.field[++decoded.fldcnt].type = reserved;
139
                        }
140
                        decoded.field[decoded.fldcnt].value <<= 1;
141
                        decoded.field[decoded.fldcnt].bitsize += 1;
142
                        opc_pos--;
143
                        enc++;
144
                        last = reserved;
145
                }
146
                else if (*enc == '1') {
147
                       if (last != opcode) {
148
                                decoded.bitpos[opc_pos] = 1;
149
                                decoded.bitpos[opc_pos - 1] = 1;
150
                                decoded.field[++decoded.fldcnt].type = opcode;
151
                        }
152
                        decoded.field[decoded.fldcnt].value <<= 1;
153
                        decoded.field[decoded.fldcnt].value += 1;
154
                        decoded.field[decoded.fldcnt].bitsize += 1;
155
                        opc_pos--;
156
                        enc++;
157
                        last = opcode;
158
                }
159
                else if (isalpha(*enc)) {
160
                       if ((last != operand) || (lastoperand != *enc)) {
161
                                decoded.bitpos[opc_pos] = 1;
162
                                decoded.bitpos[opc_pos - 1] = 1;
163
                                decoded.field[++decoded.fldcnt].type = operand;
164
                        }
165
                        decoded.field[decoded.fldcnt].value = *enc;
166
                        decoded.field[decoded.fldcnt].bitsize += 1;
167
                        opc_pos--;
168
                        lastoperand = *enc;
169
                        enc++;
170
                        last = operand;
171
                }
172
                else
173
                        enc++;
174
}
175
 
176
void print_header(struct or1_opcode *insn, struct or1k_isa *info)
177
{
178
        printf("\n\n\\newpage\n");
179
        printf("\\vspace{10mm}\n");
180
        /* printf("\\section{Appendix A}\n"); */
181
        printf("\\lyxline{\\small}\\vspace{-1\\parskip}\n");
182
        printf("\\vspace{10mm}\n");
183
        printf("{\\raggedright \\begin{tabular}{ccc}\n");
184
        printf("\\textbf{\\textcolor{white}{\\small Left}}\\textcolor{white}{\\small }&\n");
185
        printf("\\textcolor{white}{\\small }\\textbf{\\textcolor{white}{\\small Middle Middle\n");
186
        printf("Middle Middle Middle Middle Middle Middle}} \\textcolor{white}{\\small }&\n");
187
        printf("\\textcolor{white}{\\small }\\textbf{\\textcolor{white}{\\small Right}}\\\\\n");
188
        printf("\\textbf{\\huge %s}&\n", insn->name);
189
        printf("\\multicolumn{1}{c}{\\textbf{\\huge %s}}&\n", info->title);
190
        printf("\\textbf{\\huge %s}\\\\\n", insn->name);
191
        printf("\\end{tabular}\\par}\n\\bigskip{}\n\n");
192
}
193
 
194
struct or1k_isa *get_or1k_isa(char *name)
195
{
196
        int i;
197
 
198
        for (i = 0; strlen(or1k_isa_info[i].name); i++)
199
                if (strcmp(or1k_isa_info[i].name, name) == 0)
200
                        break;
201
 
202
        return &or1k_isa_info[i];
203
}
204
 
205
void transform_tex(char *input, char *output)
206
{
207
        while (*input != '\0') {
208
                if (*input == '[') {
209
                        *output++ = '{';
210
                        *output++ = '[';
211
                        *output++ = '}';
212
                } else if (*input == ']') {
213
                        *output++ = '{';
214
                        *output++ = ']';
215
                        *output++ = '}';
216
                } else if (*input == '\\') {
217
                        *output++ = '\\';
218
                        *output++ = '\\';
219
                } else
220
                        *output++ = *input;
221
                input++;
222
        }
223
        *output = '\0';
224
}
225
 
226
void print_body(struct or1_opcode *insn, struct or1k_isa *info)
227
{
228
        char tmp[2000];
229
 
230
        printf("\\vspace{15mm}\n");
231
 
232
        printf("{\\par\\raggedright \\textbf{\\LARGE Format:}\\LARGE \\par}\n");
233
        printf("\\vspace{5mm}\n");
234
        printf("\\begin{quotation}\n");
235
        printf("\\texttt{\\large %s\\ %s}{\\large \\par}\n", insn->name, insn->args);
236
        printf("\\end{quotation}\n");
237
        printf("\\vspace{10mm}\n");
238
 
239
        printf("\\textbf{\\LARGE Description:}{\\LARGE \\par}\n");
240
        printf("\\vspace{5mm}\n");
241
        printf("\\begin{quotation}\n");
242
        printf("\\texttt{\\large %s}{\\large \\par}\n", info->desc);
243
        printf("\\end{quotation}\n");
244
        printf("\\vspace{10mm}\n");
245
 
246
        printf("\\textbf{\\LARGE Operation:}{\\LARGE \\par}\n");
247
        printf("\\vspace{5mm}\n");
248
        printf("\\begin{quotation}\n");
249
        transform_tex(info->oper, tmp);
250
        printf("%s\n", tmp);
251
        printf("\\end{quotation}\n");
252
        printf("\\vspace{10mm}\n");
253
 
254
        printf("\\textbf{\\LARGE Notes:}{\\LARGE \\par}\n");
255
        printf("\\vspace{5mm}\n");
256
        printf("\\begin{quotation}\n");
257
        printf("\n");
258
        printf("\\end{quotation}\n");
259
        printf("\\vspace{10mm}\n");
260
 
261
        printf("\\vfill\n");
262
        printf("%s: \n", or1k_isa_classes[info->class].title);
263
        printf("{\\centering \\begin{tabular}{|c|c|c|}\n");
264
        printf("\\hline\n");
265
        printf("Architecture Level&\n");
266
        printf("Execution Mode&\n");
267
        printf("Implementation\\\\\n");
268
        printf("\\hline\n");
269
        printf("%s\n", or1k_isa_classes[info->class].table);
270
        printf("\\hline\n");
271
        printf("\\end{tabular}\\par}\n");
272
 
273
        printf("\n");
274
}
275
 
276
int main()
277
{
278
        int i;
279
        struct or1k_isa *info;
280
 
281
        printf("\n\\begin{document}\n\\vspace{50mm}");
282
        printf("\\section{OpenRISC 1000 Instruction Set}\n");
283
        printf("Draft, Do not distribute\n");
284
 
285
        for(i = 0; strlen(or1_opcodes[i].name); i++) {
286
 
287
                info = get_or1k_isa(or1_opcodes[i].name);
288
 
289
                print_header(&or1_opcodes[i], info);
290
                decode(&or1_opcodes[i]);
291
                print_encoding();
292
                print_body(&or1_opcodes[i], info);
293
        }
294
        printf("\n\\end{document}\n");
295
        return 0;
296
}

powered by: WebSVN 2.1.0

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