This repository was archived by the owner on Jan 4, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwepsim.sh
More file actions
executable file
·364 lines (323 loc) · 12.9 KB
/
wepsim.sh
File metadata and controls
executable file
·364 lines (323 loc) · 12.9 KB
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/usr/bin/env node
//
// Help
//
var ws_cl_ver = 'WepSIM-cl v1.9.1' ;
function ws_help_usage ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'For more details please use:\n' +
' ./wepsim.sh -h\n' +
'\n' +
'For common examples please use:\n' +
' ./wepsim.sh --examples basic\n' +
' ./wepsim.sh --examples help\n' +
' ./wepsim.sh --examples checker\n' +
' ./wepsim.sh --examples checkpoint\n' +
' ./wepsim.sh --examples more' ;
return o ;
}
function ws_help_examples_basic ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'Examples for running some work and show the...:\n' +
' * ...final state:\n' +
' ./wepsim.sh -a run -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm\n' +
' * ...modified state on each assembly instruction executed:\n' +
' ./wepsim.sh -a stepbystep -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm\n' +
' * ...modified state on each microinstruction executed:\n' +
' ./wepsim.sh -a microstepbymicrostep -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm\n' +
'\n' +
'In previous examples you can use the "-m ep -f <firmware> -s <assembly>" or some equivalent checkpoint:\n' +
' ./wepsim.sh -a run --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
' ./wepsim.sh -a stepbystep --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
'\n' +
'Example for running in an interactive mode...:\n' +
' ./wepsim.sh -a interactive --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
'' ;
return o ;
}
function ws_help_examples_help ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'Additional help:\n' +
' * Help about the cop signal:\n' +
' ./wepsim.sh -a help -m ep -s cop\n' +
' * Help about instructions:\n' +
' ./wepsim.sh -a help -m ep -f ./examples/microcode/mips/ep_base.mc\n' +
' * Help about hardware components:\n' +
' ./wepsim.sh -a help -m ep\n' +
' * Help about hardware components (filter by name):\n' +
' ./wepsim.sh -a help -m ep -p t1\n' +
'\n' +
'' ;
return o ;
}
function ws_help_examples_check ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'Examples to show the state at the end of some work:\n' +
' * Filter final state of execution:\n' +
' ./wepsim.sh -a run --checkpoint ./examples/checkpoint/tutorial_1.txt --purify "R0-R5;0x100-0x8000"\n' +
' * Show console output after execution:\n' +
' ./wepsim.sh -a show-console -m ep -f ./examples/microcode/mips/ep_os.mc -s ./examples/assembly/mips/s4e1.asm\n' +
'\n' +
'Examples for checks at the end of some work:\n' +
' * Check that your work meets the expected final state (so it works):\n' +
' ./wepsim.sh -a check -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm -r ./examples/checklist/mips/cl-s1e1.txt\n' +
'\n' +
'More examples of custom execution:\n' +
' * Run some example and limit the "instructions":\n' +
' ./wepsim.sh -a stepbystep --checkpoint ./examples/checkpoint/tutorial_1.txt --maxi 2048\n' +
' * Run some example and limit the "clock cycles":\n' +
' ./wepsim.sh -a stepbystep --checkpoint ./examples/checkpoint/tutorial_1.txt --maxc 10000\n' +
'\n' +
'In previous examples you can combine flags, for example: -a check with --purify R0-R31\n' +
'' ;
return o ;
}
function ws_help_examples_checkpoint ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'Examples for building a checkpoint file:\n' +
' * From assembly and microcode, and print it to standard output:\n' +
' ./wepsim.sh -a build-checkpoint -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm\n' +
'\n' +
'Examples for disassembling a checkpoint files:\n' +
' * Show assembly within checkpoint:\n' +
' ./wepsim.sh -a show-assembly --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
' * Show microcode within checkpoint:\n' +
' ./wepsim.sh -a show-microcode --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
'\n' +
' * Show mode used in the checkpoint:\n' +
' ./wepsim.sh -a show-mode --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
' * Show recorded session:\n' +
' ./wepsim.sh -a show-record --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
'' ;
return o ;
}
function ws_help_examples_more ()
{
var o = '\n' +
ws_cl_ver + '\n' +
'> WepSIM simulator interface for command line.\n' +
'\n' +
'More examples of custom execution:\n' +
' * Run some example and limit the "instructions":\n' +
' ./wepsim.sh -a stepbystep --checkpoint ./examples/checkpoint/tutorial_1.txt --maxi 2048\n' +
' * Run some example and limit the "clock cycles":\n' +
' ./wepsim.sh -a stepbystep --checkpoint ./examples/checkpoint/tutorial_1.txt --maxc 10000\n' +
'\n' +
' * Run some example and show a description for each microinstruction executed:\n' +
' ./wepsim.sh -a microstepverbalized -m ep -f ./examples/microcode/mips/ep_base.mc -s ./examples/assembly/mips/s1e1.asm --verbal text\n' +
'\n' +
'Example for developers:\n' +
' * Export hardware definition as JSON:\n' +
' ./wepsim.sh -a export-hardware -m ep > examples/hardware/ep/hw_def.json\n' +
' * Run in an interactive REPL interface (beta):\n' +
' ./wepsim.sh -a interactive --checkpoint ./examples/checkpoint/tutorial_1.txt\n' +
'' ;
return o ;
}
//
// Import
//
// filesystem
var fs = require('fs') ;
// websim
var ws = require('./min.wepsim_node.js') ;
// performance
performance = require('perf_hooks').performance ;
// arguments
var argv = require('yargs')
.usage(ws_help_usage())
.option('examples', {
alias: 'e',
type: 'string',
describe: 'basic | more',
nargs: 1,
demand: false,
default: ''
})
.option('action', {
alias: 'a',
type: 'string',
describe: 'run | stepbystep | microstepbymicrostep | check |' +
' show-console | microstepverbalized |' +
' show-record | show-microcode | show-assembly | build-checkpoint',
nargs: 1,
default: 'usage'
})
.option('mode', {
alias: 'm',
type: 'string',
describe: 'ep | poc',
nargs: 1,
demand: false,
default: 'ep'
})
.option('firmware', {
alias: 'f',
type: 'string',
describe: 'Firmware file',
nargs: 1,
demand: false,
default: ''
})
.option('assembly', {
alias: 's',
type: 'string',
describe: 'Assembly file',
nargs: 1,
demand: false,
default: ''
})
.option('checkpoint', {
alias: 'c',
type: 'string',
describe: 'Checkpoint file',
nargs: 1,
demand: false,
default: ''
})
.option('resultok', {
alias: 'r',
type: 'string',
describe: 'OK result file',
nargs: 1,
demand: false,
default: ''
})
.option('maxi', {
type: 'string',
describe: 'Maximum number of instructions to be executed',
nargs: 1,
demand: false,
default: '1000'
})
.option('maxc', {
type: 'string',
describe: 'Maximum number of clock cycles to be executed',
nargs: 1,
demand: false,
default: '1024'
})
.option('verbal', {
type: 'string',
describe: 'text | math',
nargs: 1,
demand: false,
default: 'text'
})
.option('idiom', {
type: 'string',
describe: 'en | es | it | pt | zh_cn | fr | hi | ja | kr | ru | sv | de',
nargs: 1,
demand: false,
default: 'en'
})
.option('purify', {
alias: 'p',
type: 'string',
describe: 'Filter output',
nargs: 1,
demand: false,
default: ''
})
.help('h')
.demandOption(['action'])
.argv ;
// interface
var clear = require('clear') ;
//
// Main: help
//
if ( (argv.examples !== "") || (argv.action === "usage") )
{
var o = ws_help_usage() + '\n' ;
if ("basic" == argv.examples) {
o = ws_help_examples_basic() ;
}
if ("help" == argv.examples) {
o = ws_help_examples_help() ;
}
else if ("checker" == argv.examples) {
o = ws_help_examples_check() ;
}
else if ("checkpoint" == argv.examples) {
o = ws_help_examples_checkpoint() ;
}
else if ("more" == argv.examples) {
o = ws_help_examples_more() ;
}
clear() ;
console.log(o) ;
return true ;
}
//
// Main
//
try
{
// 1) options
var options = {} ;
options.instruction_limit = parseInt(argv.maxi) ;
options.cycles_limit = parseInt(argv.maxc) ;
options.verbalize = (argv.verbal.toUpperCase() == "MATH") ? 'math' : 'text' ;
options.purify = argv.purify ;
// 2) workset
var data = {} ;
data.mode = argv.mode ;
data.action = argv.action.toUpperCase() ;
data.firmware = '' ;
data.assembly = '' ;
data.record = '' ;
data.result_ok = '' ;
data.idiom = argv.idiom ;
if (argv.checkpoint !== "")
{
var data_checkpoint = fs.readFileSync(argv.checkpoint, 'utf8') ;
var obj_checkpoint = ws.wepsim_nodejs_loadCheckpoint(data_checkpoint) ;
data.mode = obj_checkpoint.mode ;
data.firmware = obj_checkpoint.firmware ;
data.assembly = obj_checkpoint.assembly ;
data.record = obj_checkpoint.record ;
data.obj_chk = obj_checkpoint ;
data.str_chk = data_checkpoint ;
}
if (argv.firmware !== "")
{
data.firmware = fs.readFileSync(argv.firmware, 'utf8') ;
}
if (argv.assembly !== "") {
if (argv.action === "help")
data.assembly = argv.assembly ; // -a help -m ep -s **cop**
else data.assembly = fs.readFileSync(argv.assembly, 'utf8') ;
}
if (argv.resultok !== "") {
data.result_ok = fs.readFileSync(argv.resultok, 'utf8') ;
}
// 3) action
return ws.wepsim_nodejs_doAction(data, options) ;
}
catch (e)
{
console.log(ws_help_usage() + '\n\n' +
e.stack + '\n') ;
return false ;
}