On Thu, 21 May 2020, Basil Hussain wrote:
I'm trying to understand how to use the μCsim simulator interface - the
interface between the program running within the simulator, and the
simulator itself. My aim is to have the program that's running in the
sim measure the execution time (i.e. no. of cycles) of some of it's own
code.
It is an interesting idea, but right now you can not do it this way.
Simulator interface has a well defined (and very narrow) set of
commands that is available for simulated program. It is intentional
and developed to support sdcc test suite mainly.
These command listed as first half when you issue "info hw simif":
Known commands:
0x5f/_ if_detect: Detect existence of interface
0x69/i commands: Get information about known commands
0x76/v if_ver: Get version of simulator interface
...
you (in the simulator console) issue the command "info hw simif", in
addition to the simif command summary, it shows:
Configuration memory of simif
0x00 00000001 . Turn simif on/off (bool, RW)
0x01 00000000 . WR: sets running state, RD: check if simulation is running
Configuration memory is a different part, and can not be accessed from
simulated program. It can be used in simulator command line only, esp.
in expressions.
You can measure exec time of a part from simulator command line only.
I suggest to setup a breakpoint (somehow) at starting and one at the
ending point of the code part, for example:
0> b 0x8002
Breakpoint 1 at 0x008002: neg (0x00,SP) (cond="")
0> b 0x800a
Breakpoint 2 at 0x00800a: neg (0x00,SP) (cond="")
0>
You can use some dummy functions, compile with sdcc, read up symbol
file with ucsim, and use function names in break commands.
Define some variables to store tick counter at start and at the end:
0> var s1
0> var s2
Attach some expressions to breakpoints to remember tick counter (and
continue the execution):
0> command 1 s1=sim_ticks,sim_start=1
0> command 2 s2=sim_ticks,sim_start=1
Somehow stop the simulation, eg:
0> break 0x8016
Breakpoint 3 at 0x008016: neg (0x00,SP) (cond="")
0>
And go:
0> r
Simulation started, PC=0x008000
1
1
Stop at 0x008016: (104) Breakpoint
V-IHINZC Flags= 0x29 41 ) A= 0x00 0 .
0-101001 X= 0x0000 0 . Y= 0x0000 0 .
SP= 0x17ff [SP+1]= 00 0 . Limit= 0x1500
F? 0x08016 00 00 neg (0x00,SP)
F 0x008016
Simulated 6 ticks (7.500e-07 sec)
Host usage: 0.000015 sec, rate=0.050738
0>
Ticks between the two points are:
0> s2-s1
4
0>
Please note that tick counting in stm8 simulator is not realistic, it
is probably better to use virtual clocks (sim_vclk) instead.
Daniel
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user