Add RISC-V support.
[openocd.git] / src / helper / startup.tcl
blob4ca2cabc26b91df3491aeba99871e597e4f113b6
1 # Defines basic Tcl procs that must exist for OpenOCD scripts to work.
3 # Embedded into OpenOCD executable
7 # We need to explicitly redirect this to the OpenOCD command
8 # as Tcl defines the exit proc
9 proc exit {} {
10 ocd_throw exit
13 # All commands are registered with an 'ocd_' prefix, while the "real"
14 # command is a wrapper that calls this function. Its primary purpose is
15 # to discard 'handler' command output,
16 proc ocd_bouncer {name args} {
17 set cmd [format "ocd_%s" $name]
18 set type [eval ocd_command type $cmd $args]
19 set errcode error
20 if {$type == "native"} {
21 return [eval $cmd $args]
22 } else {if {$type == "simple"} {
23 set errcode [catch {eval $cmd $args}]
24 if {$errcode == 0} {
25 return ""
26 } else {
27 # 'classic' commands output error message as part of progress output
28 set errmsg ""
30 } else {if {$type == "group"} {
31 catch {eval ocd_usage $name $args}
32 set errmsg [format "%s: command requires more arguments" \
33 [concat $name " " $args]]
34 } else {
35 set errmsg [format "invalid subcommand \"%s\"" $args]
36 }}}
37 return -code $errcode $errmsg
40 # Try flipping / and \ to find file if the filename does not
41 # match the precise spelling
42 proc find {filename} {
43 if {[catch {ocd_find $filename} t]==0} {
44 return $t
46 if {[catch {ocd_find [string map {\ /} $filename} t]==0} {
47 return $t
49 if {[catch {ocd_find [string map {/ \\} $filename} t]==0} {
50 return $t
52 # make sure error message matches original input string
53 return -code error "Can't find $filename"
55 add_usage_text find "<file>"
56 add_help_text find "print full path to file according to OpenOCD search rules"
58 # Find and run a script
59 proc script {filename} {
60 uplevel #0 [list source [find $filename]]
62 add_help_text script "filename of OpenOCD script (tcl) to run"
63 add_usage_text script "<file>"
65 #########