summaryrefslogtreecommitdiff
path: root/lib/simulator/engine/engine_control.tcl
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
committerAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
commit47aa8b00b2b11df13a100489e0f904a4947177ef (patch)
treeb35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/simulator/engine/engine_control.tcl
parent5b8466f7fae0e071c0f4eda13051c93313910028 (diff)
Import Upstream version 1.4.7
Diffstat (limited to 'lib/simulator/engine/engine_control.tcl')
-rw-r--r--[-rwxr-xr-x]lib/simulator/engine/engine_control.tcl174
1 files changed, 98 insertions, 76 deletions
diff --git a/lib/simulator/engine/engine_control.tcl b/lib/simulator/engine/engine_control.tcl
index efa00c9..6b76b5a 100755..100644
--- a/lib/simulator/engine/engine_control.tcl
+++ b/lib/simulator/engine/engine_control.tcl
@@ -2,7 +2,7 @@
# Part of MCU 8051 IDE ( http://mcu8051ide.sf.net )
############################################################################
-# Copyright (C) 2007-2009 by Martin Ošmera #
+# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
@@ -21,6 +21,11 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _ENGINE_CONTROL_TCL ] } {
+set _ENGINE_CONTROL_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Part of simulator engine functionality.
@@ -36,7 +41,7 @@
public method simulator_return_from_SP {intr__sub} {
if {$intr__sub} {
simulator_cancel_interrupt [lindex $inter_in_p_flags end]
- } {
+ } else {
ins_ret
$this move_simulator_line $Line($pc)
}
@@ -88,17 +93,17 @@ public method simulator_resize_code_memory {new_size} {
## Get list of decimal address of implemented SFR
# @return List - Implemented special function registers
-public method simulator_get_avaliable_sfr {} {
- return $avaliable_sfr
+public method simulator_get_available_sfr {} {
+ return $available_sfr
}
-## Determinate whether the specified SFR is avaliable on the target MCU or not
+## Determinate whether the specified SFR is available on the target MCU or not
# @parm Int sfr_addr - Address of SFR register
- # @return Bool - 1 == Avaliable; 0 == Not avaliable
-public method simulator_is_sfr_avaliable {sfr_addr} {
- if {[lsearch -ascii -exact $avaliable_sfr $sfr_addr] == -1} {
+ # @return Bool - 1 == available; 0 == Not available
+public method simulator_is_sfr_available {sfr_addr} {
+ if {[lsearch -ascii -exact $available_sfr $sfr_addr] == -1} {
return 0
- } {
+ } else {
return 1
}
}
@@ -146,8 +151,9 @@ public method master_reset {mode} {
set wdt_prescaler_val 0 ;# Int: Value of Watchdog prescaler
set watchdog_value 0 ;# Int: Value of watchdog timer
set eeprom_WR 0 ;# Bool: Data EEPROM write cycle in progress
-
- simulator_Sbar {} 0 $this ;# Clear simulator status bar
+ if {$::GUI_AVAILABLE} {
+ simulator_Sbar {} 0 $this ;# Clear simulator status bar
+ }
set interrupt_on_next 0 ;# Bool: Engage interrupt routine on the next instruction cycle
set interrupts_in_progress {} ;# Priority flags of interrupts which are in progress
set inter_in_p_flags {} ;# Interrupt flags of interrupts which are in progress
@@ -208,44 +214,44 @@ public method master_reset {mode} {
foreach item $reset_reg_values_1 {
set reg [lindex $item 0]
switch -- $reg {
- {T2CON} {if {!$feature_avaliable(t2)} {continue}}
- {RCAP2L} {if {!$feature_avaliable(t2)} {continue}}
- {RCAP2H} {if {!$feature_avaliable(t2)} {continue}}
- {TL2} {if {!$feature_avaliable(t2)} {continue}}
- {TH2} {if {!$feature_avaliable(t2)} {continue}}
- {T2MOD} {if {!$feature_avaliable(t2mod)} {continue}}
- {AUXR} {if {!$feature_avaliable(auxr)} {continue}}
- {SCON} {if {!$feature_avaliable(uart)} {continue}}
- {P0} {if {!$feature_avaliable(p0)} {continue}}
- {P1} {if {!$feature_avaliable(p1)} {continue}}
- {P2} {if {!$feature_avaliable(p2)} {continue}}
- {P3} {if {!$feature_avaliable(p3)} {continue}}
- {P4} {if {!$feature_avaliable(p4)} {continue}}
- {ACSR} {if {!$feature_avaliable(acomparator)} {continue}}
- {SADEN} {if {!$feature_avaliable(euart)} {continue}}
- {SADDR} {if {!$feature_avaliable(euart)} {continue}}
- {IPH} {if {!$feature_avaliable(iph)} {continue}}
- {WDTCON} {if {!$feature_avaliable(wdtcon)} {continue}}
+ {T2CON} {if {!$feature_available(t2)} {continue}}
+ {RCAP2L} {if {!$feature_available(t2)} {continue}}
+ {RCAP2H} {if {!$feature_available(t2)} {continue}}
+ {TL2} {if {!$feature_available(t2)} {continue}}
+ {TH2} {if {!$feature_available(t2)} {continue}}
+ {T2MOD} {if {!$feature_available(t2mod)} {continue}}
+ {AUXR} {if {!$feature_available(auxr)} {continue}}
+ {SCON} {if {!$feature_available(uart)} {continue}}
+ {P0} {if {!$feature_available(p0)} {continue}}
+ {P1} {if {!$feature_available(p1)} {continue}}
+ {P2} {if {!$feature_available(p2)} {continue}}
+ {P3} {if {!$feature_available(p3)} {continue}}
+ {P4} {if {!$feature_available(p4)} {continue}}
+ {ACSR} {if {!$feature_available(acomparator)} {continue}}
+ {SADEN} {if {!$feature_available(euart)} {continue}}
+ {SADDR} {if {!$feature_available(euart)} {continue}}
+ {IPH} {if {!$feature_available(iph)} {continue}}
+ {WDTCON} {if {!$feature_available(wdtcon)} {continue}}
{EECON} {if {!$eeprom_size} {continue}}
- {SPCR} {if {!$feature_avaliable(spi)} {continue}}
- {SPSR} {if {!$feature_avaliable(spi)} {continue}}
+ {SPCR} {if {!$feature_available(spi)} {continue}}
+ {SPSR} {if {!$feature_available(spi)} {continue}}
{DP1H} {
- if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} {
+ if {!$feature_available(ddp) || $feature_available(hddptr)} {
continue
}
}
{DP1L} {
- if {!$feature_avaliable(ddp) || $feature_avaliable(hddptr)} {
+ if {!$feature_available(ddp) || $feature_available(hddptr)} {
continue
}
}
{CLKREG} {
- if {!$feature_avaliable(clkreg) && !$feature_avaliable(ckcon)} {
+ if {!$feature_available(clkreg) && !$feature_available(ckcon)} {
continue
}
}
{AUXR1} {
- if {!$feature_avaliable(ddp) || $feature_avaliable(wdtcon)} {
+ if {!$feature_available(ddp) || $feature_available(wdtcon)} {
continue
}
}
@@ -256,10 +262,10 @@ public method master_reset {mode} {
}
# Restore bits which are not affected by reset
- if {$feature_avaliable(pof) && $controllers_conf(POF)} {
+ if {$feature_available(pof) && $controllers_conf(POF)} {
set sfr($symbol(PCON)) [expr {$sfr($symbol(PCON)) | 16}]
}
- if {$feature_avaliable(x2reset) && $controllers_conf(X2)} {
+ if {$feature_available(x2reset) && $controllers_conf(X2)} {
set sfr($symbol(CLKREG)) [expr {$sfr($symbol(CLKREG)) | 1}]
}
@@ -275,17 +281,19 @@ public method master_reset {mode} {
}
# Synchronize with special GUI controls
- $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle
- $this interrupt_monitor_reset ;# Reset interrupt monitor
- $this subprograms_clear ;# Clear list subprograms
- $this stopwatch_refresh ;# Stopwatch
- $this stack_monitor_reset ;# clear stack monitor
+ if {$::GUI_AVAILABLE} {
+ $this simulator_GUI_cancel_write_to_eeprom ;# Abort data EEPROM write cycle
+ $this interrupt_monitor_reset ;# Reset interrupt monitor
+ $this subprograms_clear ;# Clear list subprograms
+ $this stopwatch_refresh ;# Stopwatch
+ $this stack_monitor_reset ;# clear stack monitor
+ }
# Reset PALE (Peripheral Astraction Layer Engine)
$this pale_reset
for {set i 0} {$i < 5} {incr i} {
set j 0
- foreach bit [split $feature_avaliable(port$i) {}] {
+ foreach bit [split $feature_available(port$i) {}] {
if {$bit == 0} {
$this pale_SLSF [list $i $j] 6
}
@@ -344,10 +352,10 @@ public method stepback {} {
simulator_set_special [lindex $stepback_spec $stepback_length]
set opcode [getCode $pc]
- if {[lsearch ${CompilerConsts::defined_OPCODE} $opcode] == -1} {
+ if {[lsearch ${::CompilerConsts::defined_OPCODE} $opcode] == -1} {
incr run_statistics(4) -1
- } {
- incr run_statistics(4) -[lindex $CompilerConsts::Opcode($opcode) 2]
+ } else {
+ incr run_statistics(4) -[lindex $::CompilerConsts::Opcode($opcode) 2]
}
incr run_statistics(0) [expr {int(($overall_time - $overall_time_org) * (12000000.0 / $clock_kHz))}]
@@ -394,14 +402,17 @@ public method stepback {} {
$this stack_monitor_pop
}
}
- if {[llength $interrupts_in_progress]} {
- simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this
- } {
- simulator_Sbar {} 0 $this
+ if {$::GUI_AVAILABLE} {
+ if {[llength $interrupts_in_progress]} {
+ simulator_Sbar [mc "Interrupt at vector 0x%s " [format %X [intr2vector [lindex $interrupts_in_progress end]]]] 1 $this
+ } else {
+ simulator_Sbar {} 0 $this
+ }
+
+ $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}]
+ $this interrupt_monitor_reevaluate
+ $this stopwatch_refresh
}
- $this graph_stepback [expr {int(($overall_time_org - $overall_time) * 2)}]
- $this interrupt_monitor_reevaluate
- $this stopwatch_refresh
if {$eeprom_size} {
for {set i 0} {$i < 32} {incr i} {
::X::sync_eeprom_write_buffer $i $this
@@ -411,11 +422,13 @@ public method stepback {} {
if {$eeprom_WR} {
eeprom_controller [expr {int(($overall_time_org - $overall_time) * (-2))}]
- } {
- foreach reg $eeprom_prev {
- ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this
+ } else {
+ if {$::GUI_AVAILABLE} {
+ foreach reg $eeprom_prev {
+ ::X::sync_eeprom_clear_bg_hg [lindex $reg 0] $this
+ }
+ $this simulator_GUI_cancel_write_to_eeprom
}
- $this simulator_GUI_cancel_write_to_eeprom
}
$this Simulator_sync_PC_etc
@@ -426,7 +439,7 @@ public method stepback {} {
$this Simulator_GUI_sync S 224
if {!$stepback_length} {
return 0
- } {
+ } else {
return 1
}
}
@@ -449,7 +462,7 @@ public method step {} {
return $Line($pc)
# Invalid OP code
- } {
+ } else {
bell
$this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]]
incr_pc 1
@@ -469,7 +482,7 @@ public method sim_stepover {} {
set stepover_in_progress 0
# Engage
- } {
+ } else {
# Local variables
set current_line 0 ;# Current line in source code
set stepover_in_progress 1 ;# Bool: "Step over" mode flag
@@ -486,7 +499,7 @@ public method sim_stepover {} {
if {$code($pc) != {}} {
set sync_ena 1 ;# Enable synchronization
- while 1 {
+ while {1} {
# Conditionaly abort simulation
if {$break} {
set break 0
@@ -536,7 +549,7 @@ public method sim_stepover {} {
return $Line($pc)
# No OP code
- } {
+ } else {
incr_pc 1
bell
$this sim_txt_output [mc "No instruction found at 0x%s" [NumSystem::dec2hex $pc]]
@@ -562,7 +575,7 @@ public method sim_run {} {
set run_in_progress 0 ;# Bool: "Run" mode flag
# Engage
- } {
+ } else {
set sync_ena 0 ;# Disabled synchronizations
# Local variables
@@ -570,9 +583,10 @@ public method sim_run {} {
set simulation_in_progress 1 ;# Bool: Simulator engaged
set idx 0 ;# Instruction index (GUI is updated after each 1000)
set ::X::critical_procedure_in_progress 0
+ set time_ms [clock milliseconds] ;# Int: High res. system timer, used here for regular GUI updates
# Infinitely execute program instructions until break
- while 1 {
+ while {1} {
incr idx
# Conditionaly abort simulation
if {$break} {
@@ -600,15 +614,19 @@ public method sim_run {} {
# Execute instruction
instruction_cycle
- # Run update command after each 25 instructions
- if {!($idx % 25)} {
- update
- }
- # Update GUI after each 100 instructions
- if {$idx >= 100} {
- set idx 0
- $this Simulator_sync_PC_etc
- update
+ if {$::GUI_AVAILABLE} {
+ if {([clock milliseconds] - $time_ms) > $GUI_UPDATE_INT} {
+ set idx 0
+ $this Simulator_sync_PC_etc
+ update
+ set time_ms [clock milliseconds]
+ }
+ } else {
+ # Stop after 1000 instructions
+ if {$idx >= 1000} {
+ set idx 0
+ set break 1
+ }
}
# Handle breakpoints
@@ -648,13 +666,13 @@ public method sim_animate {} {
set animation_in_progress 0 ;# Bool: "Animation" mode flag
# Engage
- } {
+ } else {
set animation_in_progress 1 ;# Bool: "Animation" mode flag
set simulation_in_progress 1 ;# Bool: Simulator engaged
set ::X::critical_procedure_in_progress 0
# Infinitely execute program instructions until break
- while 1 {
+ while {1} {
# Conditionaly abort simulation
if {$break} {
set simulation_in_progress 0
@@ -748,8 +766,8 @@ public method Simulator_shutdown {} {
# @return void
public method Simulator_initiate {} {
set sync_ena 1
- simulator_system_power_on
master_reset -
+ simulator_system_power_on
# Reset watchdog
set watchdog_value 0
@@ -757,3 +775,7 @@ public method Simulator_initiate {} {
set break 0
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard