1 |
2 |
sinclairrf |
################################################################################
|
2 |
|
|
#
|
3 |
|
|
# Copyright 2012-2013, Sinclair R.F., Inc.
|
4 |
|
|
#
|
5 |
|
|
################################################################################
|
6 |
|
|
|
7 |
|
|
import math
|
8 |
|
|
import re
|
9 |
|
|
|
10 |
|
|
from ssbccPeripheral import SSBCCperipheral
|
11 |
|
|
from ssbccUtil import SSBCCException;
|
12 |
|
|
|
13 |
|
|
class monitor_stack(SSBCCperipheral):
|
14 |
|
|
"""
|
15 |
|
|
Simulation-specific peripheral to flag invalid stack operations and display
|
16 |
|
|
the execution history immediately before the invalid operation.\n
|
17 |
|
|
Invalid data stack operations are:
|
18 |
|
|
pushing onto a full data stack
|
19 |
|
|
dropping from an empty data stack
|
20 |
|
|
nipping from an almost empty data stack\n
|
21 |
|
|
Invalid return stack operations are:
|
22 |
|
|
pushing onto a full return stack
|
23 |
|
|
dropping values from an empty return stack
|
24 |
|
|
returns from a data entry on the return stack
|
25 |
|
|
non-return operations from an address entry on the return stack\n
|
26 |
|
|
Invalid data operations are:
|
27 |
|
|
swap on an empty or almost empty data stack
|
28 |
|
|
in-place operations on an empty or almost empty data stack\n
|
29 |
|
|
Usage:
|
30 |
|
|
PERIPHERAL monitor_stack \\
|
31 |
|
|
[history==n]\n
|
32 |
|
|
Where:
|
33 |
|
|
history=n
|
34 |
|
|
display the n most recent operations when a stack error is encountered
|
35 |
|
|
Note: Normally the last 50 instructions are displayed.
|
36 |
|
|
"""
|
37 |
|
|
|
38 |
|
|
def __init__(self,peripheralFile,config,param_list,loc):
|
39 |
|
|
# Use the externally provided file name for the peripheral
|
40 |
|
|
self.peripheralFile = peripheralFile;
|
41 |
|
|
# Get the parameters.
|
42 |
|
|
for param in param_list:
|
43 |
|
|
param_name = param_list[0];
|
44 |
|
|
param_arg = param_list[1:];
|
45 |
|
|
if param_name == 'history':
|
46 |
|
|
self.AddAttr(config,param,param_arg,r'[1-9]\d*$',loc,int);
|
47 |
|
|
else:
|
48 |
|
|
raise SSBCCException('Unrecognized parameter at %s: %s' % (loc,param,));
|
49 |
|
|
# Set optional parameters.
|
50 |
|
|
if not hasattr(self,'history'):
|
51 |
|
|
self.history = 50;
|
52 |
|
|
# Configure the system for this peripheral.
|
53 |
|
|
config.functions['display_trace'] = True;
|
54 |
|
|
|
55 |
|
|
def GenVerilog(self,fp,config):
|
56 |
|
|
body = self.LoadCore(self.peripheralFile,'.v');
|
57 |
|
|
outport_pure_strobe = '';
|
58 |
|
|
for ix in range(config.NOutports()):
|
59 |
|
|
thisPort = config.outports[ix][2:];
|
60 |
|
|
thisIsStrobe = True;
|
61 |
|
|
for jx in range(len(thisPort)):
|
62 |
|
|
signal = thisPort[jx];
|
63 |
|
|
signalType = signal[2];
|
64 |
|
|
if signalType == 'data':
|
65 |
|
|
thisIsStrobe = False;
|
66 |
|
|
elif signalType == 'strobe':
|
67 |
|
|
pass;
|
68 |
|
|
else:
|
69 |
|
|
raise Exception('Program Bug: Unrecognized outport signal type "%s"' % signalType);
|
70 |
|
|
if thisIsStrobe:
|
71 |
|
|
if len(outport_pure_strobe) > 0:
|
72 |
|
|
outport_pure_strobe += ' || ';
|
73 |
|
|
outport_pure_strobe += ('(s_T == 8\'h%02X)' % ix);
|
74 |
|
|
if len(outport_pure_strobe) == 0:
|
75 |
|
|
outport_pure_strobe = '1\'b0';
|
76 |
|
|
outport_pure_strobe = 'wire s__outport_pure_strobe = ' + outport_pure_strobe + ';';
|
77 |
|
|
for subs in (
|
78 |
|
|
(r'\\bix__', 'ix__monitor_stack__',),
|
79 |
|
|
(r'\\bs__', 's__monitor_stack__',),
|
80 |
|
|
(r'@CORENAME@', config.Get('outCoreName'),),
|
81 |
|
|
(r'@HISTORY@', str(self.history),),
|
82 |
|
|
(r'@LAST_INPORT@', '9\'h%03X' % config.NInports(),),
|
83 |
|
|
(r'@LAST_OUTPORT@', '9\'h%03X' % config.NOutports(),),
|
84 |
|
|
(r'@NINSTRUCTIONS@', str(config.Get('nInstructions')['length']),),
|
85 |
|
|
(r'@OUTPORT_PURE_STROBE@', outport_pure_strobe,),
|
86 |
|
|
):
|
87 |
|
|
body = re.sub(subs[0],subs[1],body);
|
88 |
|
|
for ixBank in range(4):
|
89 |
|
|
memParam = config.GetMemoryByBank(ixBank);
|
90 |
|
|
if memParam:
|
91 |
|
|
maxLength = memParam['maxLength'];
|
92 |
|
|
else:
|
93 |
|
|
maxLength = 0;
|
94 |
|
|
body = re.sub('@MEM_LIMIT_%d@' % ixBank, str(maxLength), body);
|
95 |
|
|
fp.write(body);
|