source: SVN/cambria/redboot/packages/services/memalloc/common/current/src/heapgen.tcl @ 1

Last change on this file since 1 was 1, checked in by Tim Harvey, 2 years ago

restored latest version of files from server backup

Signed-off-by: Tim Harvey <tharvey@…>

File size: 7.2 KB
Line 
1#!/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
62set debug 0
63
64proc 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
75proc 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
84dputs "argc=" $argc
85dputs "argv=" $argv
86
87if { $argc != 2 } {
88    error "Usage: heapgen.tcl installdir builddir"
89}
90
91set installdir [ tcl_path [ lindex $argv 0 ] ]
92set builddir   [ tcl_path [ lindex $argv 1 ] ]
93
94dputs "builddir=" $builddir
95dputs "installdir=" $installdir
96dputs "pwd=" [pwd]
97
98# Fetch relevant config data placed in the generated file heapgeninc.tcl
99source [ file join $builddir heapgeninc.tcl ]
100
101dputs "memlayout_h=" $memlayout_h
102
103# ----------------------------------------------------------------------------
104# Get heap information
105
106# trim brackets
107set ldi_name [ string trim $memlayout_ldi "<>" ]
108dputs $ldi_name 
109# prefix full leading path including installdir
110set 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"
114set heaps ""
115while { [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}
132close $ldifile
133
134set heapcount [ llength $heaps ]
135set 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
143set hfile [ open [ file join $builddir heaps.hxx ] w]
144puts $hfile "#ifndef CYGONCE_PKGCONF_HEAPS_HXX"
145puts $hfile "#define CYGONCE_PKGCONF_HEAPS_HXX"
146puts $hfile "/* <pkgconf/heaps.hxx> */\n"
147puts $hfile "/* This is a generated file - do not edit! */\n"
148# Allow CYGMEM_HEAP_COUNT to be available to the implementation header file
149puts $hfile [ format "#define CYGMEM_HEAP_COUNT %d" $heapcount ]
150puts $hfile [ concat "#include " $malloc_impl_h ]
151puts $hfile ""
152puts $hfile [ format "extern %s *cygmem_memalloc_heaps\[ %d \];" \
153        $malloc_impl_class $heapcount1 ]
154puts $hfile "\n#endif"
155puts $hfile "/* EOF <pkgconf/heaps.hxx> */"
156close $hfile
157
158# ----------------------------------------------------------------------------
159# Generate C file in the current directory (ie. the build directory)
160# that instantiates the pools
161
162set cfile [ open [ file join $builddir heaps.cxx ] w ]
163puts $cfile "/* heaps.cxx */\n"
164puts $cfile "/* This is a generated file - do not edit! */\n"
165puts $cfile "#include <pkgconf/heaps.hxx>"
166puts $cfile [ concat "#include " $memlayout_h ]
167puts $cfile "#include <cyg/infra/cyg_type.h>"
168puts $cfile "#include <cyg/hal/hal_intr.h>"
169puts $cfile [ concat "#include " $malloc_impl_h ]
170puts $cfile ""
171
172foreach 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
189puts $cfile ""
190puts $cfile [ format "%s *cygmem_memalloc_heaps\[ %d \] = { " \
191        $malloc_impl_class $heapcount1 ]
192foreach heap $heaps {
193    puts $cfile [ format "    &cygmem_pool_%s," $heap ]
194}
195puts $cfile "    NULL\n};"
196
197puts $cfile "\n/* EOF heaps.cxx */"
198close $cfile
199
200# ----------------------------------------------------------------------------
201# EOF heapgen.tcl
Note: See TracBrowser for help on using the repository browser.