1 |
879 |
markom |
/* insn.c -- OpenRISC Custom Unit Compiler, instruction support
|
2 |
|
|
* Copyright (C) 2002 Marko Mlinar, markom@opencores.org
|
3 |
|
|
*
|
4 |
|
|
* This file is part of OpenRISC 1000 Architectural Simulator.
|
5 |
|
|
*
|
6 |
|
|
* This program is free software; you can redistribute it and/or modify
|
7 |
|
|
* it under the terms of the GNU General Public License as published by
|
8 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
9 |
|
|
* (at your option) any later version.
|
10 |
|
|
*
|
11 |
|
|
* This program is distributed in the hope that it will be useful,
|
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
|
|
* GNU General Public License for more details.
|
15 |
|
|
*
|
16 |
|
|
* You should have received a copy of the GNU General Public License
|
17 |
|
|
* along with this program; if not, write to the Free Software
|
18 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
19 |
|
|
|
20 |
|
|
#include <stdio.h>
|
21 |
|
|
#include <stdlib.h>
|
22 |
|
|
#include <stdarg.h>
|
23 |
|
|
#include <assert.h>
|
24 |
|
|
#include "cuc.h"
|
25 |
|
|
#include "insn.h"
|
26 |
|
|
|
27 |
|
|
/* Table of known instructions. Watch out for indexes I_*! */
|
28 |
|
|
const cuc_known_insn known[II_LAST + 1] = {
|
29 |
|
|
{"add", 1, "assign \1 = \2 + \3;"},
|
30 |
|
|
{"sub", 0, "assign \1 = \2 - \3;"},
|
31 |
|
|
{"and", 1, "assign \1 = \2 & \3;"},
|
32 |
|
|
{"or", 1, "assign \1 = \2 | \3;"},
|
33 |
|
|
{"xor", 1, "assign \1 = \2 ^ \3;"},
|
34 |
|
|
{"mul", 1, "assign \1 = \2 * \3;"},
|
35 |
|
|
|
36 |
|
|
{"srl", 0, "assign \1 = \2 >> \3;"},
|
37 |
|
|
{"sll", 0, "assign \1 = \2 << \3;"},
|
38 |
|
|
{"sra", 0, "assign \1 = ({32{\2[31]}} << (6'd32-{1'b0, \3}))\n\
|
39 |
|
|
| \2 >> \3;"},
|
40 |
|
|
|
41 |
|
|
{"lb", 0, "always @(posedge clk or posedge rst)"},
|
42 |
|
|
{"lh", 0, "always @(posedge clk or posedge rst)"},
|
43 |
|
|
{"lw", 0, "always @(posedge clk or posedge rst)"},
|
44 |
|
|
{"sb", 0, "/* mem8[\2] = \1 */"},
|
45 |
|
|
{"sh", 0, "/* mem16[\2] = \1 */"},
|
46 |
|
|
{"sw", 0, "/* mem32[\2] = \1 */"},
|
47 |
|
|
|
48 |
|
|
{"sfeq", 1, "assign \1 = \2 == \3;"},
|
49 |
|
|
{"sfne", 1, "assign \1 = \2 != \3;"},
|
50 |
|
|
{"sfle", 0, "assign \1 = \2 <= \3;"},
|
51 |
|
|
{"sflt", 0, "assign \1 = \2 < \3;"},
|
52 |
|
|
{"sfgt", 0, "assign \1 = \2 > \3;"},
|
53 |
|
|
{"sfge", 0, "assign \1 = \2 >= \3;"},
|
54 |
|
|
{"sfor", 1, "assign \1 = \2 || \3;"},
|
55 |
|
|
{"bf", 0, ""},
|
56 |
|
|
|
57 |
|
|
{"lrbb", 0,"always @(posedge clk or posedge rst)"},
|
58 |
|
|
{"cmov", 0,"assign \1 = \4 ? \2 : \3;"},
|
59 |
|
|
{"reg", 0, "always @(posedge clk or posedge rst)"},
|
60 |
|
|
|
61 |
|
|
{"nop", 0, NULL}};
|
62 |
|
|
|
63 |
|
|
/* Find known instruction and attach them to insn */
|
64 |
|
|
void change_insn_type (cuc_insn *i, int index)
|
65 |
|
|
{
|
66 |
|
|
int j;
|
67 |
|
|
assert (index >= 0 && index <= II_LAST);
|
68 |
|
|
i->index = index;
|
69 |
|
|
if (i->index == II_NOP) {
|
70 |
|
|
for (j = 0; j < MAX_OPERANDS; j++) i->opt[j] = OPT_NONE;
|
71 |
|
|
i->type = 0;
|
72 |
|
|
i->dep = NULL;
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
/* Returns instruction name */
|
77 |
|
|
const char *cuc_insn_name (cuc_insn *ii) {
|
78 |
|
|
if (ii->index < 0 || ii->index > II_LAST) return "???";
|
79 |
|
|
else return known[ii->index].name;
|
80 |
|
|
}
|