/
op_saj.go
243 lines (206 loc) · 6.27 KB
/
op_saj.go
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
package procbuilder
import (
"errors"
"strconv"
"github.com/BondMachineHQ/BondMachine/pkg/bmline"
"github.com/BondMachineHQ/BondMachine/pkg/bmmeta"
"github.com/BondMachineHQ/BondMachine/pkg/bmreqs"
)
// The Saj opcode is both a basic instruction and a template for other instructions.
type Saj struct{}
func (op Saj) Op_get_name() string {
return "saj"
}
func (op Saj) Op_get_desc() string {
return "Change the execution mode and jump to the address specified in the instruction"
}
func (op Saj) Op_show_assembler(arch *Arch) string {
opbits := arch.Opcodes_bits()
result := ""
switch arch.Modes[0] {
case "ha":
result = "j [" + strconv.Itoa(int(arch.O)) + "(Location)] // Change and Jump to a program location [" + strconv.Itoa(opbits+int(arch.O)) + "]\n"
case "vn":
result = "j [" + strconv.Itoa(int(arch.L)) + "(Location)] // Change and Jump to a program location [" + strconv.Itoa(opbits+int(arch.L)) + "]\n"
case "hy":
if arch.O > arch.L {
result = "j [" + strconv.Itoa(int(arch.O)) + "(Location)] // Change and Jump to a program location [" + strconv.Itoa(opbits+int(arch.O)) + "]\n"
} else {
result = "j [" + strconv.Itoa(int(arch.L)) + "(Location)] // Change and Jump to a program location [" + strconv.Itoa(opbits+int(arch.L)) + "]\n"
}
}
return result
}
func (op Saj) Op_get_instruction_len(arch *Arch) int {
opbits := arch.Opcodes_bits()
switch arch.Modes[0] {
case "ha":
return opbits + int(arch.O) // The bits for the opcode + bits for a location
case "vn":
return opbits + int(arch.L) // The bits for the opcode + bits for a location
case "hy":
if arch.O > arch.L {
return opbits + int(arch.O) // The bits for the opcode + bits for a location
} else {
return opbits + int(arch.L) // The bits for the opcode + bits for a location
}
}
return 0
}
func (op Saj) OpInstructionVerilogHeader(conf *Config, arch *Arch, flavor string, pname string) string {
// TODO
return ""
}
func (op Saj) Op_instruction_verilog_state_machine(conf *Config, arch *Arch, rg *bmreqs.ReqRoot, flavor string) string {
rom_word := arch.Max_word()
opbits := arch.Opcodes_bits()
locationBits := arch.O
switch arch.Modes[0] {
case "ha":
locationBits = arch.O
case "vn":
locationBits = arch.L
case "hy":
if arch.O > arch.L {
locationBits = arch.O
} else {
locationBits = arch.L
}
}
result := ""
result += " SAJ: begin\n"
result += " if (exec_mode == 1'b0) begin\n"
result += " exec_mode <= 1'b1;\n"
result += " vn_state <= FETCH;\n"
result += " end else begin\n"
result += " exec_mode <= 1'b0;\n"
result += " end\n"
if locationBits == 1 {
result += " _pc <= #1 current_instruction[" + strconv.Itoa(rom_word-opbits-1) + "];\n"
result += " $display(\"SAJ \", current_instruction[" + strconv.Itoa(rom_word-opbits-1) + "]);\n"
} else {
result += " _pc <= #1 current_instruction[" + strconv.Itoa(rom_word-opbits-1) + ":" + strconv.Itoa(rom_word-opbits-int(locationBits)) + "];\n"
result += " $display(\"SAJ \", current_instruction[" + strconv.Itoa(rom_word-opbits-1) + ":" + strconv.Itoa(rom_word-opbits-int(locationBits)) + "]);\n"
}
result += " end\n"
return result
}
func (op Saj) Op_instruction_verilog_footer(arch *Arch, flavor string) string {
// TODO
return ""
}
func (op Saj) Assembler(arch *Arch, words []string) (string, error) {
opbits := arch.Opcodes_bits()
rom_word := arch.Max_word()
locationBits := arch.O
switch arch.Modes[0] {
case "ha":
locationBits = arch.O
case "vn":
locationBits = arch.L
case "hy":
if arch.O > arch.L {
locationBits = arch.O
} else {
locationBits = arch.L
}
}
if len(words) != 1 {
return "", Prerror{"Wrong arguments number"}
}
result := ""
if partial, err := Process_number(words[0]); err == nil {
result += zeros_prefix(int(locationBits), partial)
} else {
return "", Prerror{err.Error()}
}
for i := opbits + int(locationBits); i < rom_word; i++ {
result += "0"
}
return result, nil
}
func (op Saj) Disassembler(arch *Arch, instr string) (string, error) {
locationBits := arch.O
switch arch.Modes[0] {
case "ha":
locationBits = arch.O
case "vn":
locationBits = arch.L
case "hy":
if arch.O > arch.L {
locationBits = arch.O
} else {
locationBits = arch.L
}
}
value := get_id(instr[:locationBits])
result := strconv.Itoa(value)
return result, nil
}
// The simulation does nothing
func (op Saj) Simulate(vm *VM, instr string) error {
// TODO
vm.Pc = vm.Pc + 1
return nil
}
// The random genaration does nothing
func (op Saj) Generate(arch *Arch) string {
// TODO
return ""
}
func (op Saj) Required_shared() (bool, []string) {
// TODO
return false, []string{}
}
func (op Saj) Required_modes() (bool, []string) {
return false, []string{}
}
func (op Saj) Forbidden_modes() (bool, []string) {
return false, []string{}
}
func (op Saj) Op_instruction_internal_state(arch *Arch, flavor string) string {
return ""
}
func (Op Saj) Op_instruction_verilog_reset(arch *Arch, flavor string) string {
return ""
}
func (Op Saj) Op_instruction_verilog_default_state(arch *Arch, flavor string) string {
return ""
}
func (Op Saj) Op_instruction_verilog_internal_state(arch *Arch, flavor string) string {
return ""
}
func (Op Saj) Op_instruction_verilog_extra_modules(arch *Arch, flavor string) ([]string, []string) {
return []string{}, []string{}
}
func (Op Saj) AbstractAssembler(arch *Arch, words []string) ([]UsageNotify, error) {
result := make([]UsageNotify, 0)
return result, nil
}
func (Op Saj) Op_instruction_verilog_extra_block(arch *Arch, flavor string, level uint8, blockname string, objects []string) string {
result := ""
switch blockname {
default:
result = ""
}
return result
}
func (Op Saj) HLAssemblerMatch(arch *Arch) []string {
result := make([]string, 2)
result[0] = "saj::*--type=number"
result[1] = "saj::*--type=revsymbol"
return result
}
func (Op Saj) HLAssemblerNormalize(arch *Arch, rg *bmreqs.ReqRoot, node string, line *bmline.BasmLine) (*bmline.BasmLine, error) {
switch line.Operation.GetValue() {
case "saj":
return line, nil
}
return nil, errors.New("HL Assembly normalize failed")
}
func (Op Saj) ExtraFiles(arch *Arch) ([]string, []string) {
return []string{}, []string{}
}
func (Op Saj) HLAssemblerInstructionMetadata(arch *Arch, line *bmline.BasmLine) (*bmmeta.BasmMeta, error) {
return nil, nil
}