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`" "$@" ; \
6 echo "heapgen.tcl: cannot find Tcl shell" ; exit 1' "$0" "$@"
8 #===============================================================================
12 # Script to generate memory pool instantiations based on the memory map
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.
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.
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
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.
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.
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.
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####
53 # Purpose: Generate memory pool instantiations based on the memory map
54 # along with information in a header file to allow access from
59 #####DESCRIPTIONEND####
60 #===============================================================================
67 puts -nonewline "DEBUG: "
75 proc tcl_path { posix_path } {
77 if { $tcl_platform(platform) == "windows" } {
78 return [ exec cygpath -w $posix_path ]
88 error "Usage: heapgen.tcl installdir builddir"
91 set installdir [ tcl_path [ lindex $argv 0 ] ]
92 set builddir [ tcl_path [ lindex $argv 1 ] ]
94 dputs "builddir=" $builddir
95 dputs "installdir=" $installdir
98 # Fetch relevant config data placed in the generated file heapgeninc.tcl
99 source [ file join $builddir heapgeninc.tcl ]
101 dputs "memlayout_h=" $memlayout_h
103 # ----------------------------------------------------------------------------
104 # Get heap information
107 set ldi_name [ string trim $memlayout_ldi "<>" ]
109 # prefix full leading path including installdir
110 set ldifile [open [ file join $installdir include $ldi_name ] r]
112 # now read the .ldi file and find the user-defined sections with the
115 while { [gets $ldifile line] >= 0} {
116 # Search for user-defined name beginning heap (possibly with leading
118 if [ regexp {^[ \t]+(CYG_LABEL_DEFN\(|)[ \t]*_*heap} $line ] {
119 set heapnamestart [ string first heap $line ]
120 set heapnameend1 [ string first ")" $line ]
122 set heapnameend2 [ string wordend $line $heapnamestart ]
123 if { $heapnameend1 < 0 } {
124 set $heapnameend1 $heapnameend2
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 ]
134 set heapcount [ llength $heaps ]
135 set heapcount1 [ expr 1 + $heapcount ]
137 # ----------------------------------------------------------------------------
138 # Generate header file
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
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 ]
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> */"
158 # ----------------------------------------------------------------------------
159 # Generate C file in the current directory (ie. the build directory)
160 # that instantiates the pools
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 ]
172 foreach heap $heaps {
173 puts $cfile "#ifdef HAL_MEM_REAL_REGION_TOP\n"
175 puts $cfile [ format "%s CYGBLD_ATTRIB_INIT_BEFORE(CYG_INIT_MEMALLOC) 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 ) " \
181 puts $cfile "#else\n"
183 puts $cfile [ format "%s CYGBLD_ATTRIB_INIT_BEFORE(CYG_INIT_MEMALLOC) cygmem_pool_%s ( (cyg_uint8 *)CYGMEM_SECTION_%s , CYGMEM_SECTION_%s_SIZE ) ;\n" \
184 $malloc_impl_class $heap $heap $heap ]
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 ]
195 puts $cfile " NULL\n};"
197 puts $cfile "\n/* EOF heaps.cxx */"
200 # ----------------------------------------------------------------------------