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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [memalloc/] [common/] [v2_0/] [src/] [heapgen.tcl] - Blame information for rev 600

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

Line No. Rev Author Line
1 27 unneback
#!/bin/bash
2
# restart using a Tcl shell \
3
    exec sh -c 'for tclshell in tclsh tclsh83 cygtclsh80 ; do \
4
            ( echo | $tclshell ) 2> /dev/null && exec $tclshell "`( cygpath -w \"$0\" ) 2> /dev/null || echo $0`" "$@" ; \
5
        done ; \
6
        echo "heapgen.tcl: cannot find Tcl shell" ; exit 1' "$0" "$@"
7
 
8
#===============================================================================
9
#
10
#    heapgen.tcl
11
#
12
#    Script to generate memory pool instantiations based on the memory map
13
#
14
#===============================================================================
15
#####ECOSGPLCOPYRIGHTBEGIN####
16
## -------------------------------------------
17
## This file is part of eCos, the Embedded Configurable Operating System.
18
## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
19
##
20
## eCos is free software; you can redistribute it and/or modify it under
21
## the terms of the GNU General Public License as published by the Free
22
## Software Foundation; either version 2 or (at your option) any later version.
23
##
24
## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
25
## WARRANTY; without even the implied warranty of MERCHANTABILITY or
26
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
27
## for more details.
28
##
29
## You should have received a copy of the GNU General Public License along
30
## with eCos; if not, write to the Free Software Foundation, Inc.,
31
## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
32
##
33
## As a special exception, if other files instantiate templates or use macros
34
## or inline functions from this file, or you compile this file and link it
35
## with other works to produce a work based on this file, this file does not
36
## by itself cause the resulting work to be covered by the GNU General Public
37
## License. However the source code for this file must still be made available
38
## in accordance with section (3) of the GNU General Public License.
39
##
40
## This exception does not invalidate any other reasons why a work based on
41
## this file might be covered by the GNU General Public License.
42
##
43
## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
44
## at http://sources.redhat.com/ecos/ecos-license/
45
## -------------------------------------------
46
#####ECOSGPLCOPYRIGHTEND####
47
#===============================================================================
48
######DESCRIPTIONBEGIN####
49
#
50
# Author(s):    jlarmour
51
# Contributors: 
52
# Date:         2000-06-13
53
# Purpose:      Generate memory pool instantiations based on the memory map
54
#               along with information in a header file to allow access from
55
#               C source
56
# Description:
57
# Usage:
58
#
59
#####DESCRIPTIONEND####
60
#===============================================================================
61
 
62
set debug 0
63
 
64
proc dputs { args } {
65
    global debug
66
    if { $debug > 0 } {
67
        puts -nonewline "DEBUG: "
68
        foreach i $args {
69
          puts -nonewline $i
70
        }
71
        puts ""
72
    }
73
}
74
 
75
proc tcl_path { posix_path } {
76
    global tcl_platform
77
    if { $tcl_platform(platform) == "windows" } {
78
        return [ exec cygpath -w $posix_path ]
79
    } else {
80
        return $posix_path
81
    }
82
}
83
 
84
dputs "argc=" $argc
85
dputs "argv=" $argv
86
 
87
if { $argc != 2 } {
88
    error "Usage: heapgen.tcl installdir builddir"
89
}
90
 
91
set installdir [ tcl_path [ lindex $argv 0 ] ]
92
set builddir   [ tcl_path [ lindex $argv 1 ] ]
93
 
94
dputs "builddir=" $builddir
95
dputs "installdir=" $installdir
96
dputs "pwd=" [pwd]
97
 
98
# Fetch relevant config data placed in the generated file heapgeninc.tcl
99
source [ file join $builddir heapgeninc.tcl ]
100
 
101
dputs "memlayout_h=" $memlayout_h
102
 
103
# ----------------------------------------------------------------------------
104
# Get heap information
105
 
106
# trim brackets
107
set ldi_name [ string trim $memlayout_ldi "<>" ]
108
dputs $ldi_name
109
# prefix full leading path including installdir
110
set ldifile [open [ file join $installdir include $ldi_name ] r]
111
 
112
# now read the .ldi file and find the user-defined sections with the
113
# prefix "heap"
114
set heaps ""
115
while { [gets $ldifile line] >= 0} {
116
    # Search for user-defined name beginning heap (possibly with leading
117
    # underscores
118
    if [ regexp {^[ \t]+(CYG_LABEL_DEFN\(|)[ \t]*_*heap} $line ] {
119
        set heapnamestart [ string first heap $line ]
120
        set heapnameend1 [ string first ")" $line ]
121
        incr heapnameend1 -1
122
        set heapnameend2 [ string wordend $line $heapnamestart ]
123
        if { $heapnameend1 < 0 } {
124
            set $heapnameend1 $heapnameend2
125
        }
126
        set heapnameend [ expr $heapnameend1 < $heapnameend2 ? $heapnameend1 : $heapnameend2 ]
127
        set heapname [ string range $line $heapnamestart $heapnameend ]
128
        set heaps [ concat $heaps $heapname ]
129
        dputs [ format "Found heap \"%s\"" $heapname ]
130
    }
131
}
132
close $ldifile
133
 
134
set heapcount [ llength $heaps ]
135
set heapcount1 [ expr 1 + $heapcount ]
136
 
137
# ----------------------------------------------------------------------------
138
# Generate header file
139
 
140
# Could have made it generate the header file straight into include/pkgconf,
141
# but that knowledge of the build system is best left in the make rules in CDL
142
 
143
set hfile [ open [ file join $builddir heaps.hxx ] w]
144
puts $hfile "#ifndef CYGONCE_PKGCONF_HEAPS_HXX"
145
puts $hfile "#define CYGONCE_PKGCONF_HEAPS_HXX"
146
puts $hfile "/* <pkgconf/heaps.hxx> */\n"
147
puts $hfile "/* This is a generated file - do not edit! */\n"
148
# Allow CYGMEM_HEAP_COUNT to be available to the implementation header file
149
puts $hfile [ format "#define CYGMEM_HEAP_COUNT %d" $heapcount ]
150
puts $hfile [ concat "#include " $malloc_impl_h ]
151
puts $hfile ""
152
puts $hfile [ format "extern %s *cygmem_memalloc_heaps\[ %d \];" \
153
        $malloc_impl_class $heapcount1 ]
154
puts $hfile "\n#endif"
155
puts $hfile "/* EOF <pkgconf/heaps.hxx> */"
156
close $hfile
157
 
158
# ----------------------------------------------------------------------------
159
# Generate C file in the current directory (ie. the build directory)
160
# that instantiates the pools
161
 
162
set cfile [ open [ file join $builddir heaps.cxx ] w ]
163
puts $cfile "/* heaps.cxx */\n"
164
puts $cfile "/* This is a generated file - do not edit! */\n"
165
puts $cfile "#include <pkgconf/heaps.hxx>"
166
puts $cfile [ concat "#include " $memlayout_h ]
167
puts $cfile "#include <cyg/infra/cyg_type.h>"
168
puts $cfile "#include <cyg/hal/hal_intr.h>"
169
puts $cfile [ concat "#include " $malloc_impl_h ]
170
puts $cfile ""
171
 
172
foreach heap $heaps {
173
    puts $cfile "#ifdef HAL_MEM_REAL_REGION_TOP\n"
174
 
175
    puts $cfile [ format "%s cygmem_pool_%s ( (cyg_uint8 *)CYGMEM_SECTION_%s ," \
176
            $malloc_impl_class $heap $heap ]
177
    puts $cfile [ format "    HAL_MEM_REAL_REGION_TOP( (cyg_uint8 *)CYGMEM_SECTION_%s + CYGMEM_SECTION_%s_SIZE ) - (cyg_uint8 *)CYGMEM_SECTION_%s ) " \
178
            $heap $heap $heap ]
179
    puts $cfile "        CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_MEMALLOC);\n"
180
 
181
    puts $cfile "#else\n"
182
 
183
    puts $cfile [ format "%s cygmem_pool_%s ( (cyg_uint8 *)CYGMEM_SECTION_%s , CYGMEM_SECTION_%s_SIZE ) CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_MEMALLOC);\n" \
184
            $malloc_impl_class $heap $heap $heap ]
185
 
186
    puts $cfile "#endif"
187
}
188
 
189
puts $cfile ""
190
puts $cfile [ format "%s *cygmem_memalloc_heaps\[ %d \] = { " \
191
        $malloc_impl_class $heapcount1 ]
192
foreach heap $heaps {
193
    puts $cfile [ format "    &cygmem_pool_%s," $heap ]
194
}
195
puts $cfile "    NULL\n};"
196
 
197
puts $cfile "\n/* EOF heaps.cxx */"
198
close $cfile
199
 
200
# ----------------------------------------------------------------------------
201
# EOF heapgen.tcl

powered by: WebSVN 2.1.0

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