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
·303 lines (266 loc) · 10.4 KB
/
wepsim.sh
File metadata and controls
executable file
·303 lines (266 loc) · 10.4 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
#!/usr/bin/env node
//
// Help
//
var ws_cl_ver = 'WepSIM-cl v1.8.5' ;
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' +
' ./wepsim.sh --examples basic\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/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt\n' +
' * ...modified state on each assembly instruction executed:\n' +
' ./wepsim.sh -a stepbystep -m ep -f ./examples/microcode/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt\n' +
' * ...modified state on each microinstruction executed:\n' +
' ./wepsim.sh -a microstepbymicrostep -m ep -f ./examples/microcode/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt\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/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt -r ./examples/checklist/cl-ep_s1_e1.txt\n' +
' * Show console output after execution:\n' +
' ./wepsim.sh -a show-console -m ep -f ./examples/microcode/mc-ep_os.txt -s ./examples/assembly/asm-ep_s4_e1.txt\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 show-console --checkpoint ./examples/checkpoint/tutorial_1.txt\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/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt\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' +
'Additional help:\n' +
' * Help on signal:\n' +
' ./wepsim.sh -a help -m ep -f cop\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/mc-ep_base.txt -s ./examples/assembly/asm-ep_s1_e1.txt --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'
})
.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 ("checkpoint" == argv.examples) {
o = ws_help_examples_checkpoint() ;
}
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' ;
// 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 !== "")
{
if (argv.action === "help")
data.firmware = argv.firmware ; // -a help -m ep -f **cop**
else data.firmware = fs.readFileSync(argv.firmware, 'utf8') ;
}
if (argv.assembly !== "") {
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 ;
}