forked from ozaki-r/arm-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm-js.html
399 lines (382 loc) · 14.1 KB
/
arm-js.html
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
<!--
/*!
* Javascript ARMv7 Emulator
*
* Copyright 2012, Ryota Ozaki
* Dual licensed under the MIT or GPL Version 2 licenses.
*/
-->
<html>
<head>
<meta charset="UTF-8">
<script src="js/jquery-1.7.2.js"></script>
<script src="js/jquery-ui-1.8.18.custom.min.js"></script>
<script src="js/symbols.js"></script>
<script src="js/display.js"></script>
<script src="js/logger.js"></script>
<script src="js/tracer.js"></script>
<script src="js/utils.js"></script>
<script src="js/bitops.js"></script>
<script src="js/number64.js"></script>
<script src="js/JSONlocalStorage.js"></script>
<script src="js/option.js"></script>
<script src="js/parameter.js"></script>
<script src="js/simpleterm/term.js"></script>
<script src="js/filesystem.js"></script>
<script src="js/armv7-mmu.js"></script>
<script src="js/armv7-cp15.js"></script>
<script src="js/armv7-cpu.js"></script>
<script src="js/9p.js"></script>
<script src="js/virtio.js"></script>
<script src="js/vexpress.js"></script>
<style>
.term {
font-family: courier,fixed,swiss,monospace,sans-serif;
font-size: 14px;
color: #f0f0f0;
background: #000000;
}
.termReverse {
color: #000000;
background: #00ff00;
}
#note {
font-size: 12px;
}
#copyright {
font-size: 10px;
}
#clipboard {
font-size: 12px;
}
#display {
font-family: courier,fixed,swiss,monospace,sans-serif;
font-size: 12px;
height: 60%;
overflow: scroll;
}
</style>
<link href="css/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" />
<style>
.ui-widget-content {
font-size: normal;
}
.tab {
font-size: 12px;
}
.ui-widget button, .ui-widget label {
font-size: 12px;
}
</style>
</head>
<body>
<script>
bitops = new BitOps();
options = new Options();
display = new Display("display", options);
logger = new Logger(display, options);
tracer = new Tracer(display, options);
btracer = new BranchTracer(display, options);
$(document).ready(function() {
var parameters = new Parameters();
var configurations = new Configurations();
configurations.read_saved_values(display);
configurations.register_handlers();
var system = new VersatileExpress(configurations, options);
function term_handler(str) {
//system.keyboard.receive_char(str.charCodeAt(0));
system.uart0.input_char(str.charCodeAt(0));
}
var term = new Term(80, 20, term_handler);
system.uart0.write_to_terminal = term.write.bind(term);
var fsAvailable = false;
function system_state_changed_cb() {
if (system.is_booted) {
$("#stack").removeAttr("disabled");
$("#show_page_tables").removeAttr("disabled");
$("#dump_phymem").removeAttr("disabled");
$("#dump_virmem").removeAttr("disabled");
if (system.is_running)
$("#step").attr("disabled", "disabled");
else
$("#step").removeAttr("disabled");
if (fsAvailable && !system.is_running) {
$("#save").removeAttr("disabled");
$("#restore").removeAttr("disabled");
} else {
$("#save").attr("disabled", "disabled");
$("#restore").attr("disabled", "disabled");
}
} else {
if (fsAvailable)
$("#restore").removeAttr("disabled");
$("#save").attr("disabled", "disabled");
$("#step").attr("disabled", "disabled");
$("#stack").attr("disabled", "disabled");
$("#show_page_tables").attr("disabled", "disabled");
$("#dump_phymem").attr("disabled", "disabled");
$("#dump_virmem").attr("disabled", "disabled");
}
if (!system.is_booted)
$("#controller").html("Boot");
else if (!system.is_running)
$("#controller").html("Restart");
else
$("#controller").html("Stop");
}
system.set_state_changed_cb(system_state_changed_cb);
$("#controller").click(function() {
if (!system.is_booted) {
system.boot(parameters);
} else {
if (system.is_running)
system.stop();
else
system.restart();
}
});
$("#step").click(function() {
system.stop_after = 1;
system.restart();
});
$("#save").click(function() {
system.save();
});
$("#restore").click(function() {
system.restore();
logger.reset();
tracer.reset();
btracer.reset();
$("#controller").html("Restart");
});
$("#show_logs").click(function() {
display.wipe();
logger.dump();
});
$("#show_traces").click(function() {
display.wipe();
tracer.dump();
});
$("#show_branch_traces").click(function() {
display.wipe();
btracer.dump();
});
$("#dump").click(function() {
system.dump();
});
$("#stack").click(function() {
system.dump_stack();
});
$("#show_options").click(function() {
display.wipe();
options.dump(display);
});
$("#show_page_tables").click(function() {
system.dump_page_tables();
});
$("#test").click(function() {
bitops.test();
TestNumber64();
});
$("#test_terminal").click(function() {
system.test_terminal();
});
$("#save_options").click(function() {
options.save_to_localStorage();
});
$("#save_parameters").click(function() {
parameters.save_to_localStorage();
configurations.save_to_localStorage();
});
$("#dump_phymem").click(function() {
system.dump_phymem(parseInt($('#phymem_addr').val(), 16));
});
$("#dump_virmem").click(function() {
system.dump_virmem(parseInt($('#virmem_addr').val(), 16));
});
$("#dump_io").click(function() {
system.dump_io();
});
$("#show_counted_instructions").click(function() {
var reversed = new Array();
for (var name in system.inst_counter) {
if (!reversed[system.inst_counter[name]])
reversed[system.inst_counter[name]] = new Array();
reversed[system.inst_counter[name]].push(name);
}
var sorted = new Array(system.inst_counter.length);
for (var name in system.inst_counter) {
sorted.push(system.inst_counter[name]);
}
sorted.sort(function(a, b) { return b - a; });
var output = "";
var done = new Array();
for (var i in sorted) {
if (done[sorted[i]])
continue;
output += sorted[i] + ": " + reversed[sorted[i]].join(", ") + "\n";
done[sorted[i]] = true;
}
display.wipe();
display.log(output);
});
term.open();
options.read_saved_values(display);
options.register_handlers();
parameters.read_saved_values(display);
parameters.register_handlers();
prev = 0.0;
elapsed_time = 0;
function update_instruction_display() {
var display = document.getElementById('inst_counter');
display.innerHTML = system.n_instructions.toString();
if (system.is_running) {
if (prev != 0.0) {
display = document.getElementById('kips');
var kips = (system.n_instructions - prev) / 1000;
display.innerHTML = kips.toFixed(1);
}
prev = system.n_instructions;
display = document.getElementById('elapsed_time');
elapsed_time += 1;
display.innerHTML = elapsed_time.toString();
} else {
display = document.getElementById('kips');
var kips = 0.0;
display.innerHTML = kips.toFixed(1);
prev = system.n_instructions;
}
}
// Test if HTML5 FileSystem is available
fsTestAvailability(50 * 1024 * 1024, function() {
system.enable_virtio_9p();
fsAvailable = true;
system_state_changed_cb();
}, function() {
system_state_changed_cb();
});
setInterval(update_instruction_display, 1000);
});
</script>
<script>
$(function() {
$('#ui-tabs').tabs();
});
</script>
<div id=header>
<button id="controller" type="button">Boot</button>
<button id="step" type="button" disabled>Execute one instruction</button>
/
<button id="save" type="button" disabled>Save system</button>
<button id="restore" type="button" disabled>Restore system</button>
</div>
<div><span id="kips">0.0</span> KIPS / <span id="inst_counter">0</span> instructions executed / <span id="elapsed_time">0</span> sec elapsed</div>
<div id="ui-tabs">
<ul>
<li class="tab"><a href="#tab-1">Emulator Terminal</a></li>
<li class="tab"><a href="#tab-2">Emulator Parameters</a></li>
<li class="tab"><a href="#tab-3">Debug Console</a></li>
<li class="tab"><a href="#tab-4">Debug Options</a></li>
</ul>
<div id="tab-1">
<div id=terminal tabindex=0></div>
</div>
<div id="tab-2">
<fieldset id="configuration">
<legend><label>Machine Configuration</label></legend>
<ul style="list-style-type: none;">
<li><label>Memory Size: <input type=number id=memory_size min=20> MB</label></li>
</ul>
</fieldset>
<fieldset id="boot_parameters">
<legend><label>Boot Parameters</label></legend>
<ul style="list-style-type: none;">
<li><label>Kernel Image: <input type=text id=Image_url size=60></label></li>
<li><label>Kernel cmdline: <input type=text id=cmdline size=60></label></li>
<li><label>Initrd: <input type=text id=initrd_url size=60></label></li>
<li><label>Initrd compressed size: <input type=number id=initrd_size min=0> Byte</label></li>
<li><label>Initrd cpio size: <input type=number id=initrd_decomp_size min=0> Byte</label></li>
<li><label>DTB: <input type=text id=dtb_url size=60></label></li>
</ul>
</fieldset>
<button id="save_parameters" type="button">Save</button>
</div>
<div id="tab-3">
<button id="show_logs" class="button" type="button">Show logs</button>
<button id="show_traces" class="button" type="button">Show traces</button>
<button id="show_branch_traces" class="button" type="button">Show branch traces</button>
<button id="dump" class="button" type="button">Show states</button>
<button id="show_options" class="button" type="button">Show options</button>
<button id="show_counted_instructions" class="button" type="button">Show counted instructions</button>
<button id="test" class="button" type="button">Test</button>
<button id="test_terminal" class="button" type="button">Test terminal</button>
<br />
<button id="stack" class="button" type="button" disabled>Show stack</button>
<button id="show_page_tables" class="button" type="button" disabled>Show page tables</button>
<label>PhyAddr: <input type=text id=phymem_addr placeholder="c0001234" pattern="^(0x)?[0-9a-fA-F]+$"></label>
<button id="dump_phymem" class="button" type="button" disabled>Dump phymem</button>
<label>VirAddr: <input type=text id=virmem_addr placeholder="c0001234" pattern="^(0x)?[0-9a-fA-F]+$"></label>
<button id="dump_virmem" class="button" type="button" disabled>Dump virmem</button>
<button id="dump_io" class="button" type="button">Dump I/O regions</button>
<br />
<label><input type=checkbox id=update_current_function>Current function: <input type=text id=function></label>
<label>Show activities at: <input type=text id=show_act_on_viraddr placeholder="c0001234" pattern="^(0x)?[0-9a-fA-F]+$"></label>
<label>(Symbol <input type=text id=show_act_on_symbol pattern="^[a-zA-Z_][\w_]+$"></label>)</li>
<pre id="display"></pre>
</div>
<div id="tab-4" style="width: 50%">
<fieldset id="option_stopper">
<legend>
<label><input type=checkbox id=enable_stopper>Stop at</label>
</legend>
<ul style="list-style-type: none;">
<li><label>Tick: <input type=number id=stop_counter min=0></label></li>
<li><label>Instruction: <input type=text id=stop_instruction placeholder="e320f000" pattern="^(0x)?[0-9a-fA-F]+$"></label></li>
<li><label>Address: <input type=text id=stop_address placeholder="c0001234" pattern="^(0x)?[0-9a-fA-F]+$"></label>
<label>(Function <input type=text id=stop_address_name pattern="^[a-zA-Z_][\w_]+$"></label>)</li>
<li><label><input type=checkbox id=stop_at_every_branch>Every branch</label></li>
<li><label><input type=checkbox id=stop_at_every_funccall>Every function call</label></li>
</ul>
</fieldset>
<fieldset id="option_logger">
<legend>
<label><input type=checkbox id=enable_logger>Logger</label>
</legend>
<ul style="list-style-type: none;">
<li><label>Log size: <input type=number id=log_size min=0 max=10000 step=1000></label></li>
<li><label><input type=checkbox id=logger_buffering>Buffering outputs</label></li>
</ul>
</fieldset>
<fieldset id="option_tracer">
<legend>
<label><input type=checkbox id=enable_tracer>Tracer</label>
</legend>
<ul style="list-style-type: none;">
<li><label>Trace size: <input type=number id=trace_size min=0 max=10000 step=1000></label></li>
<li><label>Trace check size: <input type=number id=trace_check_size min=0 max=1000 step=5></label></li>
<li><label><input type=checkbox id=tracer_buffering>Buffering outputs</label></li>
</ul>
</fieldset>
<fieldset id="option_branch_tracer">
<legend>
<label><input type=checkbox id=enable_branch_tracer>Branch tracer</label>
</legend>
<ul style="list-style-type: none;">
<li><label>Trace size: <input type=number id=branch_trace_size min=0 max=10000 step=1000></label></li>
<li><label><input type=checkbox id=branch_tracer_buffering>Buffering outputs</label></li>
</ul>
</fieldset>
<fieldset id="option_others">
<legend>
<label>Others</label>
</legend>
<ul style="list-style-type: none;">
<li><label><input type=checkbox id=suppress_interrupts>Suppress interrupts</label></li>
<li><label><input type=checkbox id=enable_instruction_counting>Enable instruction counting</label></li>
</ul>
</fieldset>
<button id="save_options" type="button">Save</button>
</div>
</div>
</body>
</html>