summaryrefslogtreecommitdiff
path: root/lib/simulator/engine/engine_memory_management.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/simulator/engine/engine_memory_management.tcl')
-rw-r--r--[-rwxr-xr-x]lib/simulator/engine/engine_memory_management.tcl85
1 files changed, 56 insertions, 29 deletions
diff --git a/lib/simulator/engine/engine_memory_management.tcl b/lib/simulator/engine/engine_memory_management.tcl
index acf2978..e3a5828 100755..100644
--- a/lib/simulator/engine/engine_memory_management.tcl
+++ b/lib/simulator/engine/engine_memory_management.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_MEMORY_MANAGEMENT_TCL ] } {
+set _ENGINE_MEMORY_MANAGEMENT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Part of simulator engine functionality.
@@ -40,11 +45,11 @@ private method getNextOperand {} {
bell
$this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]]
return [undefined_octet]
- } {
+ } else {
if {$code($pc) == {}} {
$this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]]
return 255
- } {
+ } else {
return $code($pc)
}
}
@@ -59,11 +64,11 @@ private method getLastOperand {} {
bell
$this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s" [NumSystem::dec2hex $pc]]
set result [undefined_octet]
- } {
+ } else {
if {$code($pc) == {}} {
$this sim_txt_output [mc "Incomplete instruction (undefined operand/value missing in memory) at 0x%s. Using 0FFh as operand !" [NumSystem::dec2hex $pc]]
set result 255
- } {
+ } else {
set result $code($pc)
}
}
@@ -92,7 +97,7 @@ public method setBit {addr value} {
if {${::Simulator::reverse_run_steps}} {
if {$regAddr < 128} {
stepback_reg_change I $regAddr
- } {
+ } else {
stepback_reg_change S $regAddr
}
}
@@ -114,7 +119,7 @@ public method setBit {addr value} {
} elseif {([expr {$ram($regAddr) & $mask}] == 0) && $value} {
set ram($regAddr) [expr {$ram($regAddr) ^ $mask}]
}
- } {
+ } else {
set sfr_val [read_sfr $regAddr]
if {([expr {$sfr_val & $mask}] > 0) && !$value} {
write_sfr $regAddr [expr {$sfr_val ^ $mask}]
@@ -125,7 +130,7 @@ public method setBit {addr value} {
if {$regAddr > 127} {
evaluate_sfr $regAddr
- } {
+ } else {
if {$sync_ena} {
$this Simulator_sync_reg $regAddr
}
@@ -161,19 +166,19 @@ public method getBitByReg {regAddr bitNumber} {
if {$regAddr < 0x80} {
if {[expr {$ram($regAddr) & $mask}] == 0} {
return 0
- } {
+ } else {
return 1
}
- } {
- if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} {
+ } else {
+ if {[lsearch -ascii -exact $PORT_LATCHES $regAddr] != -1} {
set byte [read_sfr $regAddr]
- } {
- set byte $sfr($regAddr)
- }
+ } else {
+ set byte $sfr($regAddr)
+ }
if {[expr {$byte & $mask}] == 0} {
return 0
- } {
+ } else {
return 1
}
}
@@ -187,7 +192,7 @@ public method getRegOfBit {addr} {
if {$addr > 127} {
set reg [expr {$reg * 8}]
- } {
+ } else {
incr reg 32
}
@@ -247,7 +252,9 @@ private method check_address_validity {location address} {
}
internal_shutdown
- $this invalid_addressing_dialog $location $address
+ if {$::GUI_AVAILABLE} {
+ $this invalid_addressing_dialog $location $address
+ }
set address_error 1
return 1
}
@@ -255,8 +262,10 @@ private method check_address_validity {location address} {
## Check if the specified address at the given location is implemented in this MCU
# @parm Char location - Memory type
# D == IDATA direct addressing or SFR
+ # S == SFR only
# I == IDATA indirect addressing (or operations on stack)
# B == Bit area
+ # J == Special Function Bits only
# X == XDATA
# C == CODE
# E == ERAM
@@ -269,7 +278,12 @@ public method simulator_address_range {location address} {
if {$address < 128 && $address < $iram_size} {
return 1
}
- if {[lsearch $avaliable_sfr $address] != -1} {
+ if {[lsearch $available_sfr $address] != -1} {
+ return 1
+ }
+ }
+ {S} { ;# SFR only
+ if {[lsearch $available_sfr $address] != -1} {
return 1
}
}
@@ -286,7 +300,15 @@ public method simulator_address_range {location address} {
if {$reg_addr < 128 && $reg_addr < $iram_size} {
return 1
}
- if {[lsearch $avaliable_sfr $reg_addr] != -1} {
+ if {[lsearch $available_sfr $reg_addr] != -1} {
+ return 1
+ }
+ }
+ {J} { ;# Special Function Bits only
+ if {[lsearch $restricted_bits $address] != -1} {
+ return 0
+ }
+ if {[lsearch $available_sfr [getRegOfBit $address]] != -1} {
return 1
}
}
@@ -316,7 +338,8 @@ public method simulator_address_range {location address} {
## Write value to SFR
# - It does not check address validity !
- # - Purpose is to write zero to unimplemented bits
+ # - Purpose is to write zero to unimplemented bits and handle special funtions
+ # triggered by write to specific SFR
# @parm Int addr - Target address (128..255)
# @parm Int value - New value (0.255)
# @return void
@@ -341,15 +364,15 @@ private method write_sfr {addr value} {
# Interrupts configuration related SFR -- skip next interrupt
if {$addr == $symbol(IP) || $addr == $symbol(IE) || $addr == $symbol(IPH)} {
set skip_interrupt 1
- } {
+ } else {
set skip_interrupt 0
}
# Write specified value into the SFR
- if {[lsearch $incomplite_regs $addr] == -1} {
+ if {[lsearch $incomplete_regs $addr] == -1} {
set sfr($addr) $value
- } {
- set sfr($addr) [expr {$value & $incomplite_regs_mask($addr)}]
+ } else {
+ set sfr($addr) [expr {$value & $incomplete_regs_mask($addr)}]
}
}
@@ -361,7 +384,7 @@ private method write_sfr {addr value} {
private method read_sfr {addr} {
# Port latch
set port_number [lsearch -ascii -exact $PORT_LATCHES $addr]
- if {!$rmw_instruction && $port_number != -1} {
+ if {!$rmw_instruction && $port_number != -1 && [$this pale_is_enabled]} {
set result [$this pale_RRPV $port_number]
# Write only register
@@ -373,15 +396,19 @@ private method read_sfr {addr} {
return [undefined_octet]
# Fully implemeneted register
- } elseif {[lsearch $incomplite_regs $addr] == -1} {
+ } elseif {[lsearch $incomplete_regs $addr] == -1} {
return $sfr($addr)
# Partialy implemented register
- } {
+ } else {
return [expr {
- ($incomplite_regs_mask($addr) & $sfr($addr))
+ ($incomplete_regs_mask($addr) & $sfr($addr))
+
- (($incomplite_regs_mask($addr) ^ 0x0FF) & [undefined_octet])
+ (($incomplete_regs_mask($addr) ^ 0x0FF) & [undefined_octet])
}]
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard