--- p3sim_orig 2008-06-02 14:37:37.000000000 +0100 +++ web/p3sim 2008-06-02 13:50:34.000000000 +0100 @@ -9,11 +9,29 @@ #| Tcl script that launches the simulator. #| #| History: 17/mar/01 - JCM - created. +#| 23/may/08 - njsg +#| 02/jun/08 - njsg #| #| Copyright (c) 2001 Guilherme Arroz, egsa@alfa.ist.utl.pt #| Jose' Monteiro, jcm@inesc.pt #| Arlindo Oliveira, aml@inesc.pt #| Technical University of Lisbon, Portugal +#| +#| Changes by njsg +#| - command-line switches for usage information and ROM loading +#| - memory reset function ("Debug" menu) +#| - in the dialog for writing memory (debug menu), using -1 as address +#| results in filling all the memory with the specified value +#| - in the same dialog: decimal and binary handling code - if you enter a +#| d-terminated number, it will be converted from decimal to hexadecimal. +#| A b-terminated one is read as binary. Bottom line: if you want to enter +#| an hexadecimal value ending in b or d, use B or D instead or append +#| an h. +#| - keystroke to quit: C-q +#| - keystroke to do a step: C-i +#| - dialog which enables the user to request n steps to be done at once +#| ("Comandos" > "Instruções...") +#| #+------------------------------------------------------------------------*/ #!/home/ac/bin/p3SimTcl @@ -22,6 +40,86 @@ # utils.tcl # + + +proc donStep {stepnum} { + for {set i 1} {$i <= $stepnum} {incr i} { + doStep + } +} + + +proc dostepwin {} { + global regNum systemRegisters + if {[catch { toplevel .stepWin}] > 0} {return} + + frame .stepWin.stepn + label .stepWin.stepn.label -text "Número de instruções:" + entry .stepWin.stepn.val + button .stepWin.dosteps -text "Executar" -relief raised -command { + donStep [.stepWin.stepn.val get] + destroy .stepWin + } + + pack .stepWin.stepn.label .stepWin.stepn.val -side left -fill both -expand 1 + pack .stepWin.stepn .stepWin.dosteps -expand 1 -fill both +} + + + +proc gethnum {strnum} { + set hex [string range $strnum 0 [expr [string length $strnum]-2]] + switch [string index $strnum [expr [string length $strnum]-1]] { + h {} + b {set hex [format %x [bin2dec $hex]]} + d {set hex [format %x $hex]} + default {set hex $strnum} + } + set hex +} + +# bin2dec: integer (bin) -> integer (dec) +proc bin2dec {binnum} { + set res 0 + for {set i [expr [string length $binnum] - 1];set j 1} {$i >= 0} {set i [expr $i - 1]; set j [expr $j * 2 ]} { + set res [expr $res + [expr [string index $binnum $i] * $j]] + } + set res +} + +# displayUsage: displays the usage information +proc displayUsage {} { + puts "Simulator for the CISC uP described in Chapter 12" + puts "of \"Introducao aos Sistemas Digitais e Microprocessadores\"," + puts "by G. Arroz, J. Monteiro and A. Oliveira." + puts "IST Press, 2005" + puts "2008-06-02" + puts "" + puts " -A path - load path as Map ROM A" + puts " -B path - load path as Map ROM B" + puts " -C path - load path as Control ROM" + puts " \[-P\] path - load path as program" + puts " -H|--help - display this usage info" + exit +} + +# clrmem: clear main memory +proc clrmem {} { + fillmem 0 +} + +# fillmem: sets every memory word to the specified value +proc fillmem {value} { + set val [gethnum $value] + for {set i 0} {$i <= 65535} {incr i} { + setMemoryValue [format %x $i] $val + } + resetStats + resetPC + redisplay +} + + proc dpos {w {x 300} {y 300}} { wm geometry $w +$x+$y } @@ -420,6 +518,19 @@ pack .escreveRegisto.set .escreveRegisto.done -expand 1 -fill both } + +# setMemoryValueAux: wrapper for setMemoryValue, if the address is '-1', +# invokes fillmem instead of setMemoryValue +proc setMemoryValueAux {pos val} { + if {$pos == -1} { + fillmem $val + } else { + setMemoryValue $pos [gethnum $val] + } + redisplay +} + + proc setMemory {} { global regNum systemRegisters if {[catch { toplevel .escreveMemoria}] > 0} {return} @@ -431,7 +542,7 @@ label .escreveMemoria.value.label -text "Valor" entry .escreveMemoria.value.val button .escreveMemoria.set -text "Guarda" -relief raised -command { - setMemoryValue [.escreveMemoria.position.val get] [.escreveMemoria.value.val get] + setMemoryValueAux [.escreveMemoria.position.val get] [.escreveMemoria.value.val get] redisplay } button .escreveMemoria.done -command {destroy .escreveMemoria; redisplay} -text "Fecha" @@ -775,6 +886,9 @@ Colaboração: Guilherme Arroz Jose Monteiro Arlindo Oliveira Fausto Ferreira egsa@tagus.ist.utl.pt jcm@inesc-id.pt aml@inesc-id.pt fmpf@algos.inesc-id.pt + + Modified version, changes by njsg. (2008-06-02) + (The changes list is at the beginning of source code) } @@ -1257,7 +1371,7 @@ } -accelerator "Ctrl+B" .menu.file.menu add separator -.menu.file.menu add command -label "Sai" -command {destroy .} +.menu.file.menu add command -label "Sai" -command {destroy .} -accelerator "Ctrl+Q" menu .menu.definitions.menu .menu.definitions.menu add command -label "Define IVAD" -command {setIVAD} @@ -1265,7 +1379,8 @@ .menu.definitions.menu add command -label "Zona de Programa" -command {setProgView} menu .menu.command.menu -.menu.command.menu add command -label "Instrução" -command {doStep } +.menu.command.menu add command -label "Instrução" -command {doStep } -accelerator "Ctrl+I" +.menu.command.menu add command -label "Instruções..." -command {dostepwin } # NOTA: Dá erro devido ao resetLCD !!! #.menu.command.menu add command -label "Corre" -command { resetPC; resetLCD; resetStats; switchProcRunStatus } -accelerator "Ctrl+R" #.menu.command.menu add command -label "Reinícia" -command { resetPC; resetLCD; resetStats} @@ -1279,6 +1394,7 @@ .menu.debug.menu add command -label "Pontos de Paragem" -command {viewBreakPoints} .menu.debug.menu add command -label "Escreve Registo" -command {setRegister} .menu.debug.menu add command -label "Escreve Memória" -command {setMemory} +.menu.debug.menu add command -label "Limpa Memória" -command {clrmem} menu .menu.view.menu .menu.view.menu add checkbutton -label "Ver Controlo" -variable internalViewControl -command {toggleInternalView $internalViewControl} -accelerator "Ctrl+K" @@ -1371,6 +1487,17 @@ } +# Sai +bind all { + destroy . +} + +# Executa uma instrução +bind all { + doStep +} + + #================================================== menu .menu.help.menu @@ -1453,9 +1580,29 @@ place .interface_IO.board.switch_$i -y 255 -x [expr 8 + ($i-1) * 30] } +for {set i 0} {$i < $argc} {incr i} { + switch -- [lindex $argv $i] { + -A {incr i + loadMapRom [lindex $argv $i] A + } + -B {incr i + loadMapRom [lindex $argv $i] B + } + -C {incr i + loadControlRom [lindex $argv $i] + } + -P {incr i + loadProgram [lindex $argv $i] + } + -H {displayUsage} + --help {displayUsage} + default {loadProgram [lindex $argv $i]} + } +} +redisplay -if {$argc == 1} { - loadProgram [lindex $argv 0] - redisplay -} +#if {$argc == 1} { +# loadProgram [lindex $argv 0] +# redisplay +#}