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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [synth/] [arch/] [current/] [host/] [console.tcl] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
# {{{  Banner                                                   
2
 
3
# ============================================================================
4
# 
5
#      console.tcl
6
# 
7
#      Console output support for the eCos synthetic target I/O auxiliary
8
# 
9
# ============================================================================
10
# ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                         
11
# -------------------------------------------                               
12
# This file is part of the eCos host tools.                                 
13
# Copyright (C) 2002 Free Software Foundation, Inc.                         
14
#
15
# This program is free software; you can redistribute it and/or modify      
16
# it under the terms of the GNU General Public License as published by      
17
# the Free Software Foundation; either version 2 or (at your option) any    
18
# later version.                                                            
19
#
20
# This program is distributed in the hope that it will be useful, but       
21
# WITHOUT ANY WARRANTY; without even the implied warranty of                
22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
23
# General Public License for more details.                                  
24
#
25
# You should have received a copy of the GNU General Public License         
26
# along with this program; if not, write to the                             
27
# Free Software Foundation, Inc., 51 Franklin Street,                       
28
# Fifth Floor, Boston, MA  02110-1301, USA.                                 
29
# -------------------------------------------                               
30
# ####ECOSHOSTGPLCOPYRIGHTEND####                                           
31
# ============================================================================
32
# #####DESCRIPTIONBEGIN####
33
# 
34
#  Author(s):   bartv
35
#  Contact(s):  bartv
36
#  Date:        2002/08/07
37
#  Version:     0.01
38
#  Description:
39
#      Implementation of the console device. This script should only ever
40
#      be run from inside the ecosynth auxiliary.
41
# 
42
# ####DESCRIPTIONEND####
43
# ============================================================================
44
 
45
# }}}
46
 
47
# The console device is pretty simple. There can only ever be one
48
# instance of the console, and it does not take any initialization
49
# data from the target or from command-line arguments. It does
50
# look for entries in the target definition file, to set up
51
# colours for console output, and to install additional regexp-based
52
# filters. The only type of request that can go to the console device
53
# is to write some text.
54
 
55
namespace eval ::console {
56
 
57
    variable _pending_output ""
58
    variable filter_count 0
59
    array set filters [list]
60
 
61
    proc instantiate { id name data } {
62
        # There is only console so no name is expected, and the target
63
        # cannot provide any initialization data.
64
        if { ("" != $name) || ("" != $data) } {
65
            synth::report_error "The target has passed invalid data when instantiating the console device.\n"
66
            return ""
67
        }
68
 
69
        # There are no command line arguments to be processed and consumed.
70
 
71
        # Look for and consume target definition entries related to the console.
72
        # These are only actually applicable when running in GUI mode, but
73
        # should always be consumed.
74
        set console_appearance ""
75
 
76
        if { [synth::tdf_has_device "console"] } {
77
            if { [synth::tdf_has_option "console" "appearance"] } {
78
                set console_appearance [synth::tdf_get_option "console" "appearance"]
79
            }
80
 
81
            if { [synth::tdf_has_option "console" "filter"] } {
82
                set tdf_filters [synth::tdf_get_options "console" "filter"]
83
                foreach filter $tdf_filters {
84
                    if { 2 > [llength $filter] } {
85
                        set msg "Invalid entry in target definition file $synth::target_definition\n"
86
                        append msg "  Device console, option filter takes at least two arguments, a name and a regular expression.\n"
87
                        synth::report_error $msg
88
                    } else {
89
                        # Attempt some minimal validation of the regexp
90
                        set name [lindex $filter 0]
91
                        set regexp [lindex $filter 1]
92
                        set error ""
93
                        if { [catch { regexp -- $regexp "Hello world\n" } error] } {
94
                            set msg "Invalid entry in target definition file $synth::target_definition\n"
95
                            append msg "  Device console, filter $name, invalid regular expression\n    $error\n"
96
                            synth::report_error $msg
97
                        } else {
98
                            set ::console::filters($::console::filter_count,name)       $name
99
                            set ::console::filters($::console::filter_count,regexp)     $regexp
100
                            set ::console::filters($::console::filter_count,appearance) [lrange $filter 2 end]
101
                            incr ::console::filter_count
102
                        }
103
                    }
104
                }
105
            }
106
        }
107
 
108
        # If the GUI is enabled then set up a filter for the console, and
109
        # any additional filters specified in the target definition file
110
        # for e.g. trace output.
111
        if { $synth::flag_gui } {
112
            if { [synth::filter_exists "console" ] } {
113
                synth::report_warning "The console device script [info script] cannot create a filter for \"console\".\nThis filter already exists.\n"
114
            } elseif { "" == $console_appearance } {
115
                synth::filter_add "console"
116
            } else {
117
                array set parsed_options [list]
118
                set message ""
119
                if { ![synth::filter_parse_options $console_appearance parsed_options message] } {
120
                    synth::report_error \
121
                        "Invalid entry in target definition file $synth::target_definition\
122
                         \n  synth_device \"console\", entry \"appearance\"\n$message"
123
                } else {
124
                    synth::filter_add_parsed "console" parsed_options
125
                }
126
            }
127
 
128
            for { set i 0 } { $i < $::console::filter_count } { incr i } {
129
                set name $::console::filters($i,name)
130
                set appearance $::console::filters($i,appearance)
131
                array unset parsed_options
132
                array set parsed_options [list]
133
 
134
                if { [synth::filter_exists $name] } {
135
                    synth::report_warning "The console device script [info script] cannot create a filter for \"$name\".\nThis filter already exists.\n"
136
                } else {
137
                    set message ""
138
                    if { ![synth::filter_parse_options $appearance parsed_options message] } {
139
                        synth::report_error \
140
                                "Invalid entry in target definition file $synth::target_definition\
141
                                \n  synth_device \"console\", entry filter $name\n$message"
142
                    } else {
143
                        synth::filter_add_parsed $name parsed_options
144
                    }
145
                }
146
            }
147
        }
148
 
149
        # An instantiation function should return a handler for further requests
150
        # to this device instance.
151
        return console::handle_request
152
    }
153
 
154
    proc handle_request { id reqcode arg1 arg2 reqdata reqlen reply_len } {
155
        # Unfortunately the main eCos diagnostic code assumes it is
156
        # talking to a tty in raw mode, since typically the output
157
        # will go via the gdb output window. Hence it will have inserted
158
        # carriage returns which are best filtered out here.
159
        set reqdata [string map {"\r" " "} $reqdata]
160
 
161
        # The output should be processed one line at a time, to make it
162
        # easier to write the regexp filters.
163
        append console::_pending_output $reqdata
164
        while { -1 != [string first "\n" $console::_pending_output] } {
165
            set regexp_matched 0
166
            set index [string first "\n" $console::_pending_output]
167
            set line [string range $console::_pending_output 0 $index]
168
            set ::console::_pending_output [string range $console::_pending_output [expr $index + 1] end]
169
 
170
            for { set i 0 } { !$regexp_matched && ($i < $console::filter_count) } { incr i } {
171
                if { [regexp -- $console::filters($i,regexp) $line] } {
172
                    synth::output $line $console::filters($i,name)
173
                    set regexp_matched 1
174
                }
175
            }
176
            if { ! $regexp_matched } {
177
                synth::output $line "console"
178
            }
179
        }
180
    }
181
 
182
    # Deal with the case where eCos has exited after sending only part
183
    # of a line, which is still pending. In practice this has no
184
    # effect at present because the data is still buffered inside
185
    # eCos.
186
    proc _flush { arg_list } {
187
        if { "" != $console::_pending_output } {
188
            synth::output "$console::_pending_output\n" "console"
189
        }
190
    }
191
    synth::hook_add "ecos_exit" console::_flush
192
 
193
}
194
 
195
return console::instantiate

powered by: WebSVN 2.1.0

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