OpenCores
URL https://opencores.org/ocsvn/openmsp430/openmsp430/trunk

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [tools/] [bin/] [openmsp430-minidebug.tcl] - Blame information for rev 119

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 olivier.gi
#!/usr/bin/wish
2
#------------------------------------------------------------------------------
3
# Copyright (C) 2001 Authors
4
#
5
# This source file may be used and distributed without restriction provided
6
# that this copyright statement is not removed from the file and that any
7
# derivative work contains the original copyright notice and the associated
8
# disclaimer.
9
#
10
# This source file is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU Lesser General Public License as published
12
# by the Free Software Foundation; either version 2.1 of the License, or
13
# (at your option) any later version.
14
#
15
# This source is distributed in the hope that it will be useful, but WITHOUT
16
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18
# License for more details.
19
#
20
# You should have received a copy of the GNU Lesser General Public License
21
# along with this source; if not, write to the Free Software Foundation,
22
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23
#
24
#------------------------------------------------------------------------------
25
# 
26
# File Name: minidebug.tcl
27
# 
28 14 olivier.gi
# Author(s):
29
#             - Olivier Girard,    olgirard@gmail.com
30
#
31 2 olivier.gi
#------------------------------------------------------------------------------
32 14 olivier.gi
# $Rev: 110 $
33
# $LastChangedBy: olivier.girard $
34
# $LastChangedDate: 2011-05-19 22:33:51 +0200 (Thu, 19 May 2011) $
35
#------------------------------------------------------------------------------
36 2 olivier.gi
 
37
###############################################################################
38
#                                                                             #
39
#                            GLOBAL VARIABLES                                 #
40
#                                                                             #
41
###############################################################################
42
 
43
global serial_baudrate
44
global serial_device
45
global serial_status
46 110 olivier.gi
global omsp_info
47 2 olivier.gi
global cpu_status
48
global reg
49
global mem
50 110 olivier.gi
global mem_sizes
51 87 olivier.gi
global sr
52
global codeSelect
53
global binFileType
54 110 olivier.gi
global brkpt
55
global color
56 2 olivier.gi
 
57 110 olivier.gi
# Color definitions
58
set color(PC)             "\#c1ffc1"
59
set color(Brk0_active)    "\#ba55d3"
60
set color(Brk0_disabled)  "\#dda0dd"
61
set color(Brk1_active)    "\#ff7256"
62
set color(Brk1_disabled)  "\#ffc1c1"
63
set color(Brk2_active)    "\#ffff30"
64
set color(Brk2_disabled)  "\#ffffe0"
65
 
66 2 olivier.gi
# Initializations
67 87 olivier.gi
set codeSelect    2
68 2 olivier.gi
set serial_status 0
69
set cpu_status    1
70 110 olivier.gi
for {set i 0} {$i<3} {incr i} {
71
    set brkpt(addr_$i)  0x0000
72
    set brkpt(data_$i)  0x0000
73
    set brkpt(en_$i)    0
74
}
75 2 olivier.gi
for {set i 0} {$i<16} {incr i} {
76
    set reg($i)         0x0000
77
    set mem(address_$i) [format "0x%04x" [expr 0x0200+$i*2]]
78
    set mem(data_$i)    0x0000
79
}
80
 
81
###############################################################################
82
#                                                                             #
83
#                            SOURCE LIBRARIES                                 #
84
#                                                                             #
85
###############################################################################
86
 
87
# Get library path
88
set current_file [info script]
89
if {[file type $current_file]=="link"} {
90
    set current_file [file readlink $current_file]
91
}
92
set lib_path [file dirname $current_file]/../lib/tcl-lib
93
 
94
# Source library
95
source $lib_path/dbg_functions.tcl
96
source $lib_path/combobox.tcl
97
package require combobox 2.3
98
catch {namespace import combobox::*}
99
 
100
 
101
###############################################################################
102
#                                                                             #
103
#                                    FUNCTIONS                                #
104
#                                                                             #
105
###############################################################################
106
 
107
proc connect_openMSP430 {} {
108
    global serial_status
109
    global reg
110
    global mem
111 110 olivier.gi
    global brkpt
112
    global mem_sizes
113
    global color
114
    global omsp_info
115 2 olivier.gi
 
116
    set serial_status [GetDevice]
117
 
118
    if {$serial_status} {
119 110 olivier.gi
        set mem_sizes [GetCPU_ID_SIZE]
120 2 olivier.gi
 
121 110 olivier.gi
        if {[lindex $mem_sizes 0]==-1 | [lindex $mem_sizes 1]==-1} {
122
            .ctrl.connect.info.l1.con     configure -text "Connection problem" -fg red
123 87 olivier.gi
 
124
        } else {
125
 
126
            # Disable connection section
127 110 olivier.gi
            .ctrl.connect.serial.p1       configure -state disabled
128
            .ctrl.connect.serial.p2       configure -state disabled
129
            .ctrl.connect.serial.connect  configure -state disabled
130
            if {$omsp_info(alias)==""} {
131
                .ctrl.connect.info.l1.con configure -text "Connected" -fg "\#00ae00"
132
            } else {
133
                .ctrl.connect.info.l1.con configure -text "Connected to $omsp_info(alias)" -fg "\#00ae00"
134
            }
135
            .ctrl.connect.info.l1.more    configure -state normal
136 87 olivier.gi
 
137
            # Activate ELF file section
138
            .ctrl.load.ft.l               configure -state normal
139
            .ctrl.load.ft.file            configure -state normal
140
            .ctrl.load.ft.browse          configure -state normal
141
            .ctrl.load.fb.read            configure -state normal
142
            .ctrl.load.fb.l               configure -state normal
143
 
144
            # Activate CPU control section
145 110 olivier.gi
            .ctrl.cpu.cpu.l1              configure -state normal
146
            .ctrl.cpu.cpu.reset           configure -state normal
147
            .ctrl.cpu.cpu.run             configure -state normal
148
            .ctrl.cpu.cpu.l2              configure -state normal
149
            .ctrl.cpu.cpu.l3              configure -state normal
150 87 olivier.gi
            if {[IsHalted]} {
151 110 olivier.gi
                .ctrl.cpu.cpu.step        configure -state normal
152
                .ctrl.cpu.cpu.run         configure -text "Run"
153
                .ctrl.cpu.cpu.l3          configure -text "Stopped" -fg "\#cdad00"
154 87 olivier.gi
                set cpu_status 0
155
            } else {
156 110 olivier.gi
                .ctrl.cpu.cpu.step        configure -state disabled
157
                .ctrl.cpu.cpu.run         configure -text "Stop"
158
                .ctrl.cpu.cpu.l3          configure -text "Running" -fg "\#00ae00"
159 87 olivier.gi
                set cpu_status 1
160
            }
161
 
162 110 olivier.gi
            # Activate CPU Breakpoints section
163
            .ctrl.cpu.brkpt.l1                configure -state normal
164
            for {set i 0} {$i<3} {incr i} {
165
                set brkpt(addr_$i)  [format "0x%04x" [expr 0x10000-[lindex $mem_sizes 0]]]
166
                .ctrl.cpu.brkpt.addr$i        configure -state normal
167
                .ctrl.cpu.brkpt.addr$i        configure -bg $color(Brk$i\_disabled)
168
                .ctrl.cpu.brkpt.addr$i        configure -readonlybackground $color(Brk$i\_active)
169
                .ctrl.cpu.brkpt.chk$i         configure -state normal
170
            }
171
 
172 87 olivier.gi
            # Activate CPU status register section
173 110 olivier.gi
            .ctrl.cpu.reg_stat.l1             configure -state normal
174
            .ctrl.cpu.reg_stat.v              configure -state normal
175
            .ctrl.cpu.reg_stat.scg1           configure -state normal
176
            .ctrl.cpu.reg_stat.oscoff         configure -state normal
177
            .ctrl.cpu.reg_stat.cpuoff         configure -state normal
178
            .ctrl.cpu.reg_stat.gie            configure -state normal
179
            .ctrl.cpu.reg_stat.n              configure -state normal
180
            .ctrl.cpu.reg_stat.z              configure -state normal
181
            .ctrl.cpu.reg_stat.c              configure -state normal
182 87 olivier.gi
 
183
            # Activate CPU registers and memory section
184 110 olivier.gi
            .ctrl.cpu.reg_mem.reg.title.e     configure -state normal
185
            .ctrl.cpu.reg_mem.mem.title.l     configure -state normal
186
            .ctrl.cpu.reg_mem.mem.title.e     configure -state normal
187
            .ctrl.cpu.reg_mem.reg.refresh     configure -state normal
188
            .ctrl.cpu.reg_mem.mem.refresh     configure -state normal
189 87 olivier.gi
            for {set i 0} {$i<16} {incr i} {
190 110 olivier.gi
                .ctrl.cpu.reg_mem.reg.f$i.l$i        configure -state normal
191
                .ctrl.cpu.reg_mem.reg.f$i.e$i        configure -state normal
192
                .ctrl.cpu.reg_mem.mem.f$i.addr_e$i   configure -state normal
193
                .ctrl.cpu.reg_mem.mem.f$i.data_e$i   configure -state normal
194 87 olivier.gi
            }
195 110 olivier.gi
            .ctrl.cpu.reg_mem.reg.f0.e0              configure -bg $color(PC)
196 87 olivier.gi
            refreshReg
197
            refreshMem
198
 
199
            # Activate Load TCL script section
200
            .ctrl.tclscript.ft.l          configure -state normal
201
            .ctrl.tclscript.ft.file       configure -state normal
202
            .ctrl.tclscript.ft.browse     configure -state normal
203
            .ctrl.tclscript.fb.read       configure -state normal
204
 
205
            # Activate the code debugger section
206
            .code.rb.txt                  configure -state normal
207
            .code.rb.none                 configure -state normal
208
            .code.rb.asm                  configure -state normal
209
            .code.rb.mix                  configure -state normal
210 2 olivier.gi
        }
211
 
212
    } else {
213 110 olivier.gi
        .ctrl.connect.info.l1.con         configure -text "Connection problem" -fg red
214 2 olivier.gi
    }
215
}
216
 
217 110 olivier.gi
proc displayMore  { } {
218 2 olivier.gi
 
219 110 olivier.gi
    global omsp_info
220
 
221
    # Destroy windows if already existing
222
    if {[lsearch -exact [winfo children .] .omsp_extra_info]!=-1} {
223
        destroy .omsp_extra_info
224
    }
225
 
226
    # Create master window
227
    toplevel    .omsp_extra_info
228
    wm title    .omsp_extra_info "openMSP430 extra info"
229
    wm geometry .omsp_extra_info +380+200
230
    wm resizable .omsp_extra_info 0 0
231
 
232
    # Title
233
    set title "openMSP430"
234
    if {$omsp_info(alias)!=""} {
235
        set title $omsp_info(alias)
236
    }
237
    label  .omsp_extra_info.title  -text "$title"   -anchor center -fg "\#00ae00" -font {-weight bold -size 16}
238
    pack   .omsp_extra_info.title  -side top -padx {20 20} -pady {20 10}
239
 
240
    # Add extra info
241
    frame     .omsp_extra_info.extra
242
    pack      .omsp_extra_info.extra         -side top  -padx 10  -pady {10 10}
243
    scrollbar .omsp_extra_info.extra.yscroll -orient vertical   -command {.omsp_extra_info.extra.text yview}
244
    pack      .omsp_extra_info.extra.yscroll -side right -fill both
245
    text      .omsp_extra_info.extra.text    -wrap word -height 20 -font TkFixedFont -yscrollcommand {.omsp_extra_info.extra.yscroll set}
246
    pack      .omsp_extra_info.extra.text    -side right
247
 
248
    # Create OK button
249
    button .omsp_extra_info.okay -text "OK" -font {-weight bold}  -command {destroy .omsp_extra_info}
250
    pack   .omsp_extra_info.okay -side bottom -expand true -fill x -padx 5 -pady {0 10}
251
 
252
 
253
    # Fill the text widget will configuration info
254
    .omsp_extra_info.extra.text tag configure bold -font {-family TkFixedFont -weight bold}
255
    .omsp_extra_info.extra.text insert end         "Configuration\n\n" bold
256
    .omsp_extra_info.extra.text insert end [format "CPU Version                : %5s\n" $omsp_info(cpu_ver)]
257
    .omsp_extra_info.extra.text insert end [format "User Version               : %5s\n" $omsp_info(user_ver)]
258
    if {$omsp_info(cpu_ver)==1} {
259
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" --]
260
    } elseif {$omsp_info(asic)==0} {
261
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" FPGA]
262
    } elseif {$omsp_info(asic)==1} {
263
    .omsp_extra_info.extra.text insert end [format "Implementation             : %5s\n" ASIC]
264
    }
265
    if {$omsp_info(mpy)==1} {
266
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" Yes]
267
    } elseif {$omsp_info(mpy)==0} {
268
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" No]
269
    } else {
270
    .omsp_extra_info.extra.text insert end [format "Hardware Multiplier support: %5s\n" --]
271
    }
272
    .omsp_extra_info.extra.text insert end [format "Program memory size        : %5s B\n" $omsp_info(pmem_size)]
273
    .omsp_extra_info.extra.text insert end [format "Data memory size           : %5s B\n" $omsp_info(dmem_size)]
274
    .omsp_extra_info.extra.text insert end [format "Peripheral address space   : %5s B\n" $omsp_info(per_size)]
275
    if {$omsp_info(alias)==""} {
276
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" None]
277
    } else {
278
    .omsp_extra_info.extra.text insert end [format "Alias                      : %5s\n\n\n" $omsp_info(alias)]
279
    }
280
 
281
    .omsp_extra_info.extra.text insert end         "Extra Info\n\n" bold
282
 
283
    if {$omsp_info(alias)!=""} {
284
 
285
        set aliasEXTRA  [lsort -increasing [array names omsp_info -glob "extra,*"]]
286
        if {[llength $aliasEXTRA]} {
287
 
288
            foreach currentEXTRA $aliasEXTRA {
289
                regexp {^.+,.+,(.+)$} $currentEXTRA whole_match extraATTR
290
                .omsp_extra_info.extra.text insert end     [format "%-15s: %s\n" $extraATTR  $omsp_info($currentEXTRA)]
291
            }
292
            .omsp_extra_info.extra.text insert end         "\n\n"
293
        }
294
    } else {
295
        .omsp_extra_info.extra.text insert end  "No alias found in 'omsp_alias.xml' file"
296
    }
297 87 olivier.gi
}
298
 
299 110 olivier.gi
proc highlightLine { line tagNameNew tagNameOld type } {
300
    .code.text tag remove $tagNameOld 1.0     end
301
    .code.text tag remove $tagNameNew 1.0     end
302
 
303
    switch -exact -- $type {
304
        "0"     {.code.text tag add    $tagNameNew $line.0 $line.4}
305
        "1"     {.code.text tag add    $tagNameNew $line.2 $line.4}
306
        "2"     {.code.text tag add    $tagNameNew $line.3 $line.4}
307
        default {.code.text tag add    $tagNameNew $line.4 [expr $line+1].0}
308
    }
309
}
310
 
311
proc highlightCode   { } {
312 87 olivier.gi
    global codeSelect
313 110 olivier.gi
    global reg
314
    global brkpt
315
    global color
316 87 olivier.gi
 
317
    if {$codeSelect!=1} {
318 110 olivier.gi
 
319
        # Update PC
320
        regsub {0x} $reg(0) {} pc_val
321 87 olivier.gi
        set code_match [.code.text search "$pc_val:" 1.0 end]
322
        set code_line 1
323
        regexp {(\d+).(\d+)} $code_match whole_match code_line code_column
324 110 olivier.gi
        highlightLine $code_line highlightPC highlightPC 3
325
        .code.text see    $code_line.0
326
 
327
        # Some pre-processing
328
        set brkType(0) 0
329
        if {$brkpt(addr_0)==$brkpt(addr_1)} {
330
            set brkType(1) 1
331
        } else {
332
            set brkType(1) 0
333
        }
334
        if {$brkType(1)==1} {
335
            if {$brkpt(addr_1)==$brkpt(addr_2)} {
336
                set brkType(2) 2
337
            } else {
338
                set brkType(2) 0
339
            }
340
        } else {
341
            if {$brkpt(addr_0)==$brkpt(addr_2)} {
342
                set brkType(2) 1
343
            } else {
344
                if {$brkpt(addr_1)==$brkpt(addr_2)} {
345
                    set brkType(2) 1
346
                } else {
347
                    set brkType(2) 0
348
                }
349
            }
350
        }
351
 
352
        # Update Breakpoints if required
353
        for {set i 0} {$i<3} {incr i} {
354
            regsub {0x} $brkpt(addr_$i) {} brkpt_val
355
            set code_match [.code.text search "$brkpt_val:" 1.0 end]
356
            set code_line 1
357
            regexp {(\d+).(\d+)} $code_match whole_match code_line code_column
358
            if {$brkpt(en_$i)==1} {
359
                highlightLine $code_line "highlightBRK${i}_ACT" "highlightBRK${i}_DIS" $brkType($i)
360
            } else {
361
                highlightLine $code_line "highlightBRK${i}_DIS" "highlightBRK${i}_ACT" $brkType($i)
362
            }
363
        }
364
 
365 87 olivier.gi
     }
366
}
367
 
368
proc updateCodeView { bin_file_name } {
369
    global codeSelect
370
    global reg
371
    global binFileType
372 110 olivier.gi
    global brkpt
373 87 olivier.gi
 
374
    set temp_elf_file "[clock clicks].elf"
375
    if {[catch {exec msp430-objcopy -I $binFileType -O elf32-msp430 $bin_file_name $temp_elf_file} debug_info]} {
376
        .ctrl.load.fb.l configure -text "$debug_info" -fg red
377
        return 0
378 2 olivier.gi
    }
379 87 olivier.gi
    if {[string eq $binFileType "ihex"]} {
380
        set dumpOpt "-D"
381
    } else {
382
        set dumpOpt "-d"
383
    }
384
 
385
    if {$codeSelect==1} {
386
        set debug_info ""
387 110 olivier.gi
        clearBreakpoints
388
        for {set i 0} {$i<3} {incr i} {
389
            set brkpt(en_$i) 0
390
            updateBreakpoint $i
391
        }
392 87 olivier.gi
 
393
    } elseif {$codeSelect==2} {
394
        if {[catch {exec msp430-objdump $dumpOpt $temp_elf_file} debug_info]} {
395
            .ctrl.load.fb.l configure -text "$debug_info" -fg red
396
            return 0
397
        }
398
    } elseif {$codeSelect==3} {
399
        if {[catch {exec msp430-objdump $dumpOpt\S $temp_elf_file} debug_info]} {
400
            .ctrl.load.fb.l configure -text "$debug_info" -fg red
401
            return 0
402
        }
403
    }
404
    file delete $temp_elf_file
405
 
406
    .code.text configure -state normal
407
    .code.text delete 1.0 end
408
    .code.text insert end $debug_info
409 110 olivier.gi
    highlightCode
410 87 olivier.gi
    .code.text configure -state disabled
411
    return 1
412 2 olivier.gi
}
413
 
414 87 olivier.gi
proc loadProgram {bin_file_name} {
415 2 olivier.gi
    global cpu_status
416
    global reg
417
    global mem
418 110 olivier.gi
    global mem_sizes
419 87 olivier.gi
    global binFileType
420 110 olivier.gi
    global brkpt
421 2 olivier.gi
 
422 87 olivier.gi
    # Detect the file format depending on the fil extention
423
    #--------------------------------------------------------
424
    set binFileType [file extension $bin_file_name]
425
    set binFileType [string tolower $binFileType]
426
    regsub {\.} $binFileType {} binFileType
427
 
428
    if {![string eq $binFileType "ihex"] & ![string eq $binFileType "hex"] & ![string eq $binFileType "elf"]} {
429
        .ctrl.load.fb.l configure -text "[string toupper $binFileType] file format not supported\"" -fg red
430
        return 0
431
    }
432
 
433
    # Check if the file exists
434
    #----------------------------------------
435
    if {![file exists $bin_file_name]} {
436
        .ctrl.load.fb.l configure -text "[string toupper $binFileType] file doesn't exists: \"$bin_file_name\"" -fg red
437
        return 0
438
    }
439
    if {[string eq $binFileType "hex"]} {
440
        set binFileType "ihex"
441
    }
442
    if {[string eq $binFileType "elf"]} {
443
        set binFileType "elf32-msp430"
444
    }
445
 
446
 
447
    # Create and read debug informations
448
    #----------------------------------------
449
 
450
    updateCodeView $bin_file_name
451
 
452 2 olivier.gi
    # Create and read binary executable file
453
    #----------------------------------------
454
 
455
    # Generate binary file
456
    set bin_file "[clock clicks].bin"
457 87 olivier.gi
    if {[catch {exec msp430-objcopy -I $binFileType -O binary $bin_file_name $bin_file} errMsg]} {
458
        .ctrl.load.fb.l configure -text "$errMsg" -fg red
459 77 olivier.gi
        return 0
460
    }
461
 
462
    # Wait until bin file is present on the filesystem
463
    set timeout 100
464
    for {set i 0} {$i <= $timeout} {incr i} {
465
        after 500
466
        if {[file exists $bin_file]} {
467
            break
468
        }
469
    }
470
    if {$i>=$timeout} {
471 87 olivier.gi
        .ctrl.load.fb.l configure -text "Timeout: ELF to BIN file conversion problem with \"msp430-objcopy\" executable" -fg red
472 77 olivier.gi
        return 0
473
    }
474 2 olivier.gi
 
475
    # Read file
476
    set fp [open $bin_file r]
477
    fconfigure $fp -translation binary
478
    binary scan [read $fp] H* hex_data yop
479
    close $fp
480
 
481
    # Cleanup
482
    file delete $bin_file
483
 
484
    # Get program size
485
    set hex_size  [string length $hex_data]
486
    set byte_size [expr $hex_size/2]
487
    set word_size [expr $byte_size/2]
488
 
489 77 olivier.gi
    # Make sure ELF program size is the same as the available program memory
490 110 olivier.gi
    if {[lindex $mem_sizes 0] != [expr $hex_size/2]} {
491
        .ctrl.load.fb.l configure -text "ERROR: ELF program size ([expr $hex_size/2] B) is different than the available program memory ([lindex $mem_sizes 0] B)" -fg red
492 77 olivier.gi
        return 0
493
    }
494
 
495 2 olivier.gi
    # Format data
496
    for {set i 0} {$i < $hex_size} {set i [expr $i+4]} {
497
        set hex_msb "[string index $hex_data [expr $i+2]][string index $hex_data [expr $i+3]]"
498
        set hex_lsb "[string index $hex_data [expr $i+0]][string index $hex_data [expr $i+1]]"
499
        lappend DataArray "0x$hex_msb$hex_lsb"
500
    }
501
 
502
    # Load program to openmsp430 target
503
    #-----------------------------------
504
 
505
    # Reset & Stop CPU
506
    ExecutePOR_Halt
507
 
508 35 olivier.gi
    # Load Program Memory
509 2 olivier.gi
    set StartAddr [format "0x%04x" [expr 0x10000-$byte_size]]
510 110 olivier.gi
    .ctrl.load.fb.l configure -text "Load..." -fg "\#cdad00"
511 2 olivier.gi
    update
512
    WriteMemQuick $StartAddr $DataArray
513
 
514
    # Check Data
515 110 olivier.gi
    .ctrl.load.fb.l configure -text "Verify..." -fg "\#cdad00"
516 2 olivier.gi
    update
517 77 olivier.gi
    if {[VerifyMem $StartAddr $DataArray 1]} {
518 110 olivier.gi
        .ctrl.load.fb.l configure -text "Done" -fg "\#00ae00"
519 2 olivier.gi
    } else {
520 87 olivier.gi
        .ctrl.load.fb.l configure -text "ERROR" -fg red
521 2 olivier.gi
    }
522
    update
523
 
524 110 olivier.gi
    # Re-initialize breakpoints
525
    for {set i 0} {$i<3} {incr i} {
526
        .ctrl.cpu.brkpt.addr$i  configure -state normal
527
        set brkpt(en_$i)    0
528
    }
529
 
530 87 olivier.gi
    # Reset & Stop CPU
531
    ExecutePOR_Halt
532 110 olivier.gi
    .ctrl.cpu.cpu.step  configure -state normal
533
    .ctrl.cpu.cpu.run   configure -text "Run"
534
    .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
535 87 olivier.gi
    set cpu_status 0
536 2 olivier.gi
    refreshReg
537
    refreshMem
538
}
539
 
540
proc runCPU {} {
541
    global cpu_status
542
    global reg
543
    global mem
544
 
545
    if {$cpu_status} {
546
        HaltCPU
547 110 olivier.gi
        .ctrl.cpu.cpu.step  configure -state normal
548
        .ctrl.cpu.cpu.run   configure -text "Run"
549
        .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
550 2 olivier.gi
        set cpu_status 0
551
    } else {
552 110 olivier.gi
        clearBreakpoints
553
        StepCPU
554
        setBreakpoints
555 2 olivier.gi
        ReleaseCPU
556 110 olivier.gi
        .ctrl.cpu.cpu.step  configure -state disabled
557
        .ctrl.cpu.cpu.run   configure -text "Stop"
558
        .ctrl.cpu.cpu.l3    configure -text "Running" -fg "\#00ae00"
559 2 olivier.gi
        set cpu_status 1
560
    }
561
    refreshReg
562
    refreshMem
563
}
564
 
565
proc resetCPU {} {
566
    global cpu_status
567
    global reg
568
    global mem
569
 
570
    if {$cpu_status} {
571
        ExecutePOR
572
    } else {
573
        ExecutePOR_Halt
574
    }
575
    refreshReg
576
    refreshMem
577
}
578
 
579 87 olivier.gi
proc singleStepCPU {} {
580
    global cpu_status
581
    global reg
582
    global mem
583
 
584
    if {$cpu_status==0} {
585 110 olivier.gi
        clearBreakpoints
586 87 olivier.gi
        StepCPU
587 110 olivier.gi
        setBreakpoints
588 87 olivier.gi
    }
589
    refreshReg
590
    refreshMem
591
}
592
 
593
proc statRegUpdate {} {
594
    global cpu_status
595
    global reg
596
    global mem
597
    global sr
598
 
599
    set tmp_reg [expr ($sr(v)      * 0x0100) |  \
600
                      ($sr(scg1)   * 0x0080) |  \
601
                      ($sr(oscoff) * 0x0020) |  \
602
                      ($sr(cpuoff) * 0x0010) |  \
603
                      ($sr(gie)    * 0x0008) |  \
604
                      ($sr(n)      * 0x0004) |  \
605
                      ($sr(z)      * 0x0002) |  \
606
                      ($sr(c)      * 0x0001)]
607
 
608
    set reg(2) [format "0x%04x" $tmp_reg]
609
 
610
    write2Reg 2
611
}
612
 
613
 
614 2 olivier.gi
proc refreshReg {} {
615
    global reg
616
    global mem
617 87 olivier.gi
    global sr
618 2 olivier.gi
 
619 87 olivier.gi
    # Read register values
620 2 olivier.gi
    set new_vals [ReadRegAll]
621
    for {set i 0} {$i<16} {incr i} {
622
        set reg($i) [lindex $new_vals $i]
623
    }
624 87 olivier.gi
    set sr(c)      [expr $reg(2) & 0x0001]
625
    set sr(z)      [expr $reg(2) & 0x0002]
626
    set sr(n)      [expr $reg(2) & 0x0004]
627
    set sr(gie)    [expr $reg(2) & 0x0008]
628
    set sr(cpuoff) [expr $reg(2) & 0x0010]
629
    set sr(oscoff) [expr $reg(2) & 0x0020]
630
    set sr(scg1)   [expr $reg(2) & 0x0080]
631
    set sr(v)      [expr $reg(2) & 0x0100]
632
 
633
    # Update highlighted line in the code view
634 110 olivier.gi
    highlightCode
635 2 olivier.gi
}
636
 
637
proc write2Reg {reg_num} {
638
    global reg
639
    global mem
640
 
641
    WriteReg $reg_num $reg($reg_num)
642
    refreshReg
643
    refreshMem
644
}
645
 
646
proc refreshMem {} {
647
    global reg
648
    global mem
649
 
650
    for {set i 0} {$i<16} {incr i} {
651
        # Check if address lay in 16 or 8 bit space
652
        if {[expr $mem(address_$i)]>=[expr 0x100]} {
653
            set Format 0
654
        } else {
655
            set Format 1
656
        }
657
 
658
        # Read data
659
        set mem(data_$i) [ReadMem $Format $mem(address_$i)]
660
    }
661
}
662
 
663
proc write2Mem {mem_num} {
664
    global reg
665
    global mem
666
 
667
    # Check if address lay in 16 or 8 bit space
668
    if {[expr $mem(address_$mem_num)]>=[expr 0x100]} {
669
        set Format 0
670
    } else {
671
        set Format 1
672
    }
673
 
674
    WriteMem $Format $mem(address_$mem_num) $mem(data_$mem_num)
675
    refreshReg
676
    refreshMem
677
}
678
 
679 110 olivier.gi
proc updateBreakpoint {brkpt_num} {
680
    global brkpt
681
    global mem_sizes
682
 
683
    # Set the breakpoint
684
    if {$brkpt(en_$brkpt_num)==1} {
685
 
686
        # Make sure the specified address is an opcode
687
        regsub {0x} $brkpt(addr_$brkpt_num) {} brkpt_val
688
        set code_match [.code.text search "$brkpt_val:" 1.0 end]
689
        if {![string length $code_match]} {
690
            .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
691
            set brkpt(en_$brkpt_num) 0
692
 
693
        } else {
694
            set brkpt(data_$brkpt_num) [ReadMem 0 $brkpt(addr_$brkpt_num)]
695
 
696
            # Only set a breakpoint if there is not already one there :-P
697
            if {$brkpt(data_$brkpt_num)=="0x4343"} {
698
                .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
699
                set brkpt(en_$brkpt_num) 0
700
            } else {
701
                .ctrl.cpu.brkpt.addr$brkpt_num    configure -state readonly
702
                WriteMem 0 $brkpt(addr_$brkpt_num) 0x4343
703
            }
704
        }
705
 
706
    # Clear the breakpoint
707
    } else {
708
        .ctrl.cpu.brkpt.addr$brkpt_num    configure -state normal
709
        WriteMem 0 $brkpt(addr_$brkpt_num) $brkpt(data_$brkpt_num)
710
    }
711
 
712
    highlightCode
713
}
714
 
715
proc clearBreakpoints {} {
716
    global brkpt
717
    global mem_sizes
718
 
719
    for {set i 0} {$i<3} {incr i} {
720
        if {$brkpt(en_$i)==1} {
721
            WriteMem 0 $brkpt(addr_$i) $brkpt(data_$i)
722
        }
723
    }
724
}
725
 
726
proc setBreakpoints {} {
727
    global brkpt
728
    global mem_sizes
729
 
730
    for {set i 0} {$i<3} {incr i} {
731
        if {$brkpt(en_$i)==1} {
732
            set brkpt(data_$i) [ReadMem 0 $brkpt(addr_$i)]
733
            WriteMem 0 $brkpt(addr_$i) 0x4343
734
        }
735
    }
736
}
737
 
738
 
739
 
740 2 olivier.gi
###############################################################################
741
#                                                                             #
742
#                           CREATE GRAPHICAL INTERFACE                        #
743
#                                                                             #
744
###############################################################################
745
 
746
####################################
747
#   CREATE & PLACE MAIN WIDGETS    #
748
####################################
749
 
750 87 olivier.gi
wm title    . "openMSP430 mini debugger"
751
wm iconname . "openMSP430 mini debugger"
752 2 olivier.gi
 
753 87 olivier.gi
# Create the Main Menu
754 2 olivier.gi
frame  .menu
755 87 olivier.gi
pack   .menu              -side top    -padx 10      -pady 10      -fill x
756 2 olivier.gi
 
757 110 olivier.gi
# Create the CPU Control field
758 87 olivier.gi
frame  .ctrl
759 110 olivier.gi
pack   .ctrl              -side left   -padx {5 0}   -pady 10      -fill both
760 2 olivier.gi
 
761 87 olivier.gi
# Create the Code text field
762
frame  .code
763 110 olivier.gi
pack   .code              -side right  -padx 5       -pady 10      -fill both -expand true
764 87 olivier.gi
frame  .code.rb
765
pack   .code.rb           -side bottom -padx 10      -pady 10      -fill both
766
 
767 110 olivier.gi
# Create the connection frame
768
frame  .ctrl.connect        -bd 2 -relief ridge    ;# solid
769
pack   .ctrl.connect        -side top  -padx 10      -pady 0  -fill x
770
 
771 87 olivier.gi
# Create the Serial Menu
772 110 olivier.gi
frame  .ctrl.connect.serial
773
pack   .ctrl.connect.serial -side top  -padx 10      -pady {10 0}  -fill x
774 87 olivier.gi
 
775
# Create the memory size
776 110 olivier.gi
frame  .ctrl.connect.info
777
pack   .ctrl.connect.info   -side top  -padx 10      -pady {10 10} -fill x
778 87 olivier.gi
 
779 2 olivier.gi
# Create the Load executable field
780 110 olivier.gi
frame  .ctrl.load         -bd 2 -relief ridge    ;# solid
781
pack   .ctrl.load         -side top    -padx 10      -pady {10 10} -fill x
782 2 olivier.gi
 
783 110 olivier.gi
# Create the cpu field
784
frame  .ctrl.cpu          -bd 2 -relief ridge    ;# solid
785
pack   .ctrl.cpu          -side top    -padx 10      -pady {0 10} -fill x
786
 
787 2 olivier.gi
# Create the cpu control field
788 110 olivier.gi
frame  .ctrl.cpu.cpu
789
pack   .ctrl.cpu.cpu      -side top    -padx 10      -pady {20 10} -fill x
790 2 olivier.gi
 
791 110 olivier.gi
# Create the breakpoint control field
792
frame  .ctrl.cpu.brkpt
793
pack   .ctrl.cpu.brkpt        -side top    -padx 10      -pady {10 20} -fill x
794
 
795 87 olivier.gi
# Create the cpu status field
796 110 olivier.gi
frame  .ctrl.cpu.reg_stat
797
pack   .ctrl.cpu.reg_stat     -side top    -padx 10      -pady {10 10} -fill x
798 87 olivier.gi
 
799 2 olivier.gi
# Create the cpu registers/memory fields
800 110 olivier.gi
frame  .ctrl.cpu.reg_mem
801
pack   .ctrl.cpu.reg_mem      -side top    -padx 10      -pady {5 10}  -fill x
802
frame  .ctrl.cpu.reg_mem.reg
803
pack   .ctrl.cpu.reg_mem.reg  -side left   -padx {10 30}               -fill x
804
frame  .ctrl.cpu.reg_mem.mem
805
pack   .ctrl.cpu.reg_mem.mem  -side left   -padx {30 10}               -fill x
806 2 olivier.gi
 
807 87 olivier.gi
# Create the TCL script field
808 110 olivier.gi
frame  .ctrl.tclscript        -bd 2 -relief ridge    ;# solid
809
pack   .ctrl.tclscript        -side top    -padx 10      -pady {0 20} -fill x
810 2 olivier.gi
 
811 87 olivier.gi
 
812 2 olivier.gi
####################################
813 87 olivier.gi
#  CREATE THE CPU CONTROL SECTION  #
814 2 olivier.gi
####################################
815
 
816
# Exit button
817 87 olivier.gi
button .menu.exit      -text "Exit" -command {exit 0}
818 2 olivier.gi
pack   .menu.exit      -side left
819
 
820 110 olivier.gi
# openMSP430 label
821
label  .menu.omsp      -text "openMSP430 mini debugger" -anchor center -fg "\#6a5acd" -font {-weight bold -size 16}
822
pack   .menu.omsp      -side right -padx 20
823 2 olivier.gi
 
824
# Serial Port fields
825 110 olivier.gi
label    .ctrl.connect.serial.l1    -text "Serial Port:"  -anchor w
826
pack     .ctrl.connect.serial.l1    -side left
827 2 olivier.gi
set serial_device      [lindex [dbg_list_uart] end]
828 110 olivier.gi
combobox .ctrl.connect.serial.p1    -textvariable serial_device -editable true
829
eval     .ctrl.connect.serial.p1    list insert end [dbg_list_uart]
830
pack     .ctrl.connect.serial.p1    -side left -padx 5
831 2 olivier.gi
 
832 110 olivier.gi
label    .ctrl.connect.serial.l2    -text "  Baudrate:" -anchor w
833
pack     .ctrl.connect.serial.l2    -side left
834 2 olivier.gi
set serial_baudrate    115200
835 110 olivier.gi
combobox .ctrl.connect.serial.p2    -textvariable serial_baudrate -editable true
836
eval     .ctrl.connect.serial.p2    list insert end [list     9600    19200   38400  57600 115200 \
837
                                                    230400   460800  500000 576000 921600 \
838
                                                    1000000 1152000 2000000]
839
pack     .ctrl.connect.serial.p2    -side left -padx 5
840 2 olivier.gi
 
841 110 olivier.gi
button   .ctrl.connect.serial.connect -text "Connect" -width 9 -command {connect_openMSP430}
842
pack     .ctrl.connect.serial.connect -side right -padx 5
843 2 olivier.gi
 
844 110 olivier.gi
# CPU status & info
845
frame  .ctrl.connect.info.l1
846
pack   .ctrl.connect.info.l1      -side top    -padx 0      -pady {0 0} -fill x
847 2 olivier.gi
 
848 110 olivier.gi
label  .ctrl.connect.info.l1.cpu  -text "CPU Info:"       -anchor w
849
pack   .ctrl.connect.info.l1.cpu  -side left -padx "0 10"
850
label  .ctrl.connect.info.l1.con  -text "Disconnected"    -anchor w -fg Red
851
pack   .ctrl.connect.info.l1.con  -side left
852
button .ctrl.connect.info.l1.more -text "More..."         -width 9 -command {displayMore} -state disabled
853
pack   .ctrl.connect.info.l1.more -side right -padx 5
854
 
855
 
856 2 olivier.gi
# Load ELF file fields
857 87 olivier.gi
frame  .ctrl.load.ft
858 110 olivier.gi
pack   .ctrl.load.ft        -side top -fill x -padx "10 0" -pady "10 0"
859 87 olivier.gi
label  .ctrl.load.ft.l      -text "ELF file:"  -state disabled
860
pack   .ctrl.load.ft.l      -side left -padx "0 10"
861
entry  .ctrl.load.ft.file   -width 58 -relief sunken -textvariable bin_file_name -state disabled
862
pack   .ctrl.load.ft.file   -side left -padx 10
863 110 olivier.gi
button .ctrl.load.ft.browse -text "Browse" -width 9 -state disabled -command {set bin_file_name [tk_getOpenFile -filetypes {{{ELF/Intel-Hex Files} {.elf .ihex .hex}} {{All Files} *}}]}
864
pack   .ctrl.load.ft.browse -side right -padx {5 15}
865 87 olivier.gi
frame  .ctrl.load.fb
866 110 olivier.gi
pack   .ctrl.load.fb        -side top -fill x -padx "10 0" -pady "5 10"
867 87 olivier.gi
button .ctrl.load.fb.read   -text "Load ELF File !" -state disabled -command {loadProgram $bin_file_name}
868
pack   .ctrl.load.fb.read   -side left -padx 5 -fill x
869
label  .ctrl.load.fb.l      -text "Not loaded" -anchor w -fg Red  -state disabled
870
pack   .ctrl.load.fb.l      -side left
871 2 olivier.gi
 
872
# CPU Control
873 110 olivier.gi
label  .ctrl.cpu.cpu.l1     -text "CPU Control:" -anchor w  -state disabled
874
pack   .ctrl.cpu.cpu.l1     -side left
875
button .ctrl.cpu.cpu.reset  -text "Reset" -state disabled -command {resetCPU}
876
pack   .ctrl.cpu.cpu.reset  -side left -padx 5 -fill x
877
button .ctrl.cpu.cpu.run    -text "Stop"  -state disabled -command {runCPU}
878
pack   .ctrl.cpu.cpu.run    -side left -padx 5 -fill x
879
button .ctrl.cpu.cpu.step   -text "Step"  -state disabled -command {singleStepCPU}
880
pack   .ctrl.cpu.cpu.step   -side left -padx 5 -fill x
881
label  .ctrl.cpu.cpu.l2     -text "CPU Status:" -anchor w  -state disabled
882
pack   .ctrl.cpu.cpu.l2     -side left -padx "40 0"
883
label  .ctrl.cpu.cpu.l3     -text "--" -anchor w  -state disabled
884
pack   .ctrl.cpu.cpu.l3     -side left
885 2 olivier.gi
 
886 110 olivier.gi
# Breakpoints
887
label       .ctrl.cpu.brkpt.l1       -text "CPU Breakpoints:"    -anchor w  -state disabled
888
pack        .ctrl.cpu.brkpt.l1       -side left
889
entry       .ctrl.cpu.brkpt.addr0    -textvariable brkpt(addr_0) -relief sunken -state disabled  -width 10
890
pack        .ctrl.cpu.brkpt.addr0    -side left -padx "20 0"
891
bind        .ctrl.cpu.brkpt.addr0    <Return> "highlightCode"
892
checkbutton .ctrl.cpu.brkpt.chk0     -variable brkpt(en_0)       -state disabled -command "updateBreakpoint 0" -text "Enable"
893
pack        .ctrl.cpu.brkpt.chk0     -side left -padx "0"
894
entry       .ctrl.cpu.brkpt.addr1    -textvariable brkpt(addr_1) -relief sunken -state disabled  -width 10
895
pack        .ctrl.cpu.brkpt.addr1    -side left -padx "20 0"
896
bind        .ctrl.cpu.brkpt.addr1    <Return> "highlightCode"
897
checkbutton .ctrl.cpu.brkpt.chk1     -variable brkpt(en_1)       -state disabled -command "updateBreakpoint 1" -text "Enable"
898
pack        .ctrl.cpu.brkpt.chk1     -side left -padx "0"
899
entry       .ctrl.cpu.brkpt.addr2    -textvariable brkpt(addr_2) -relief sunken -state disabled  -width 10
900
pack        .ctrl.cpu.brkpt.addr2    -side left -padx "20 0"
901
bind        .ctrl.cpu.brkpt.addr2    <Return> "highlightCode"
902
checkbutton .ctrl.cpu.brkpt.chk2     -variable brkpt(en_2)       -state disabled -command "updateBreakpoint 2" -text "Enable"
903
pack        .ctrl.cpu.brkpt.chk2     -side left -padx "0"
904
 
905
 
906 87 olivier.gi
# CPU Status register
907 110 olivier.gi
label       .ctrl.cpu.reg_stat.l1     -text "Status register (r2/sr):" -anchor w -state disabled
908
pack        .ctrl.cpu.reg_stat.l1     -side left
909
checkbutton .ctrl.cpu.reg_stat.v      -variable sr(v)      -state disabled -command "statRegUpdate" -text "V"
910
pack        .ctrl.cpu.reg_stat.v      -side left -padx "0"
911
checkbutton .ctrl.cpu.reg_stat.scg1   -variable sr(scg1)   -state disabled -command "statRegUpdate" -text "SCG1"
912
pack        .ctrl.cpu.reg_stat.scg1   -side left -padx "0"
913
checkbutton .ctrl.cpu.reg_stat.oscoff -variable sr(oscoff) -state disabled -command "statRegUpdate" -text "OSCOFF"
914
pack        .ctrl.cpu.reg_stat.oscoff -side left -padx "0"
915
checkbutton .ctrl.cpu.reg_stat.cpuoff -variable sr(cpuoff) -state disabled -command "statRegUpdate" -text "CPUOFF"
916
pack        .ctrl.cpu.reg_stat.cpuoff -side left -padx "0"
917
checkbutton .ctrl.cpu.reg_stat.gie    -variable sr(gie)    -state disabled -command "statRegUpdate" -text "GIE"
918
pack        .ctrl.cpu.reg_stat.gie    -side left -padx "0"
919
checkbutton .ctrl.cpu.reg_stat.n      -variable sr(n)      -state disabled -command "statRegUpdate" -text "N"
920
pack        .ctrl.cpu.reg_stat.n      -side left -padx "0"
921
checkbutton .ctrl.cpu.reg_stat.z      -variable sr(z)      -state disabled -command "statRegUpdate" -text "Z"
922
pack        .ctrl.cpu.reg_stat.z      -side left -padx "0"
923
checkbutton .ctrl.cpu.reg_stat.c      -variable sr(c)      -state disabled -command "statRegUpdate" -text "C"
924
pack        .ctrl.cpu.reg_stat.c      -side left -padx "0"
925 2 olivier.gi
 
926
# CPU Registers
927 110 olivier.gi
frame  .ctrl.cpu.reg_mem.reg.title
928
pack   .ctrl.cpu.reg_mem.reg.title           -side top
929
label  .ctrl.cpu.reg_mem.reg.title.l         -text " " -width 8 -anchor w
930
pack   .ctrl.cpu.reg_mem.reg.title.l         -side left
931
label  .ctrl.cpu.reg_mem.reg.title.e         -text "Registers" -anchor w  -state disabled
932
pack   .ctrl.cpu.reg_mem.reg.title.e         -side left
933 2 olivier.gi
for {set i 0} {$i<16} {incr i} {
934
    switch $i {
935
        {0}     {set reg_label "r0 (pc):"}
936
        {1}     {set reg_label "r1 (sp):"}
937
        {2}     {set reg_label "r2 (sr):"}
938
        default {set reg_label "r$i:"}
939
    }
940 110 olivier.gi
    frame  .ctrl.cpu.reg_mem.reg.f$i
941
    pack   .ctrl.cpu.reg_mem.reg.f$i           -side top
942
    label  .ctrl.cpu.reg_mem.reg.f$i.l$i       -text $reg_label -width 8 -anchor w  -state disabled
943
    pack   .ctrl.cpu.reg_mem.reg.f$i.l$i       -side left
944
    entry  .ctrl.cpu.reg_mem.reg.f$i.e$i       -textvariable reg($i) -relief sunken -state disabled
945
    pack   .ctrl.cpu.reg_mem.reg.f$i.e$i       -side left
946
    bind   .ctrl.cpu.reg_mem.reg.f$i.e$i       <Return> "write2Reg $i"
947 2 olivier.gi
}
948 110 olivier.gi
button .ctrl.cpu.reg_mem.reg.refresh           -text "Refresh Registers"  -state disabled -command {refreshReg}
949
pack   .ctrl.cpu.reg_mem.reg.refresh           -side top -padx 5 -pady 10 -fill x -expand true
950 2 olivier.gi
 
951 87 olivier.gi
 
952 2 olivier.gi
# CPU Memory
953 110 olivier.gi
frame  .ctrl.cpu.reg_mem.mem.title
954
pack   .ctrl.cpu.reg_mem.mem.title             -side top
955
label  .ctrl.cpu.reg_mem.mem.title.l           -text "      Address      " -anchor w -width 20  -state disabled
956
pack   .ctrl.cpu.reg_mem.mem.title.l           -side left -fill x -expand true
957
label  .ctrl.cpu.reg_mem.mem.title.e           -text "        Data       " -anchor w -width 20  -state disabled
958
pack   .ctrl.cpu.reg_mem.mem.title.e           -side left -fill x -expand true
959 87 olivier.gi
for {set i 0} {$i<16} {incr i} {
960 110 olivier.gi
    frame  .ctrl.cpu.reg_mem.mem.f$i
961
    pack   .ctrl.cpu.reg_mem.mem.f$i           -side top
962 2 olivier.gi
 
963 110 olivier.gi
    entry  .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  -textvariable mem(address_$i) -relief sunken -state disabled  -width 20
964
    pack   .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  -side left
965
    bind   .ctrl.cpu.reg_mem.mem.f$i.addr_e$i  <Return> "refreshMem"
966
    entry  .ctrl.cpu.reg_mem.mem.f$i.data_e$i  -textvariable mem(data_$i)    -relief sunken -state disabled  -width 20
967
    pack   .ctrl.cpu.reg_mem.mem.f$i.data_e$i  -side left
968
    bind   .ctrl.cpu.reg_mem.mem.f$i.data_e$i  <Return> "write2Mem $i"
969 87 olivier.gi
}
970 110 olivier.gi
button .ctrl.cpu.reg_mem.mem.refresh -text "Refresh Memory"     -state disabled -command {refreshMem}
971
pack   .ctrl.cpu.reg_mem.mem.refresh -side top -padx 5 -pady 10 -fill x -expand true
972 87 olivier.gi
 
973
 
974
# Load TCL script fields
975
frame  .ctrl.tclscript.ft
976 110 olivier.gi
pack   .ctrl.tclscript.ft        -side top -padx {10 10} -pady {10 5} -fill x
977 87 olivier.gi
label  .ctrl.tclscript.ft.l      -text "TCL script:" -state disabled
978
pack   .ctrl.tclscript.ft.l      -side left -padx "0 10"
979
entry  .ctrl.tclscript.ft.file   -width 58 -relief sunken -textvariable tcl_file_name -state disabled
980
pack   .ctrl.tclscript.ft.file   -side left -padx 10
981 110 olivier.gi
button .ctrl.tclscript.ft.browse -text "Browse" -width 9 -state disabled -command {set tcl_file_name [tk_getOpenFile -filetypes {{{TCL Files} {.tcl}} {{All Files} *}}]}
982
pack   .ctrl.tclscript.ft.browse -side right -padx 5
983 87 olivier.gi
frame  .ctrl.tclscript.fb
984
pack   .ctrl.tclscript.fb        -side top -fill x
985
button .ctrl.tclscript.fb.read   -text "Source TCL script !" -state disabled -command {if {[file exists $tcl_file_name]} {source $tcl_file_name}}
986 110 olivier.gi
pack   .ctrl.tclscript.fb.read   -side left -padx 15 -pady {0 10} -fill x
987 87 olivier.gi
 
988
 
989
####################################
990
#  CREATE THE CODE SECTION         #
991
####################################
992
 
993
label       .code.rb.txt  -text "Code View:" -anchor w     -state disabled
994
pack        .code.rb.txt  -side left
995
radiobutton .code.rb.none -value "1" -text "None"          -state disabled -variable codeSelect  -command { updateCodeView $bin_file_name }
996
pack        .code.rb.none -side left
997
radiobutton .code.rb.asm  -value "2" -text "Assembler"     -state disabled -variable codeSelect  -command { updateCodeView $bin_file_name }
998
pack        .code.rb.asm  -side left
999
radiobutton .code.rb.mix  -value "3" -text "C & Assembler" -state disabled -variable codeSelect  -command { updateCodeView $bin_file_name }
1000
pack        .code.rb.mix  -side left
1001
 
1002
 
1003
scrollbar .code.xscroll -orient horizontal -command {.code.text xview}
1004
pack      .code.xscroll -side bottom -fill both
1005
 
1006
scrollbar .code.yscroll -orient vertical   -command {.code.text yview}
1007
pack      .code.yscroll -side right  -fill both
1008
 
1009
text      .code.text    -width 80 -borderwidth 2  -state disabled  -wrap none -setgrid true -font TkFixedFont \
1010
                        -xscrollcommand {.code.xscroll set} -yscrollcommand {.code.yscroll set}
1011
pack      .code.text    -side left   -fill both -expand true
1012
 
1013 110 olivier.gi
.code.text tag config highlightPC       -background $color(PC)
1014
.code.text tag config highlightBRK0_ACT -background $color(Brk0_active)
1015
.code.text tag config highlightBRK0_DIS -background $color(Brk0_disabled)
1016
.code.text tag config highlightBRK1_ACT -background $color(Brk1_active)
1017
.code.text tag config highlightBRK1_DIS -background $color(Brk1_disabled)
1018
.code.text tag config highlightBRK2_ACT -background $color(Brk2_active)
1019
.code.text tag config highlightBRK2_DIS -background $color(Brk2_disabled)
1020
 
1021
 
1022
#######################################
1023
#  PERIODICALLY CHECK THE CPU STATUS  #
1024
#######################################
1025
 
1026
while 1 {
1027
 
1028
    # Wait 1 second
1029
    set ::refresh_flag 0
1030
    after 1000 set ::refresh_flag 1
1031
    vwait refresh_flag
1032
 
1033
    # Check CPU status
1034
    if {$serial_status} {
1035
        if {$cpu_status} {
1036
            if {[IsHalted]} {
1037
                .ctrl.cpu.cpu.step  configure -state normal
1038
                .ctrl.cpu.cpu.run   configure -text "Run"
1039
                .ctrl.cpu.cpu.l3    configure -text "Stopped" -fg "\#cdad00"
1040
                set cpu_status 0
1041
                refreshReg
1042
                refreshMem
1043
            }
1044
        }
1045
    }
1046
}
1047
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.