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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [services/] [memalloc/] [common/] [current/] [src/] [heapgen.tcl] - Blame information for rev 838

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

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

powered by: WebSVN 2.1.0

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