3 # Copyright (c) 2002 Kevin L. Pauba
8 # SDCC is licensed under the GNU Public license (GPL) v2. Note that
9 # this license covers the code to the compiler and other executables,
10 # but explicitly does not cover any code or objects generated by sdcc.
11 # We have not yet decided on a license for the run time libraries, but
12 # it will not put any requirements on code linked against it. See:
14 # http://www.gnu.org/copyleft/gpl.html
16 # See http://sdcc.sourceforge.net/ for the latest information on sdcc.
20 ($junk, $file, $version, $date, $time, $programmer, $status)
21 = split(/\s+/, $rcsid);
22 ($programName) = ($file =~ /(\S+),v/);
24 if ($#ARGV < 0 || $#ARGV > 1 ) {
30 $processor = uc $processor;
31 # Nathan Hurst <njh@mail.csse.monash.edu.au>: find gputils on Debian
33 if ( -x "/usr/share/gputils") {
34 $path = "/usr/share/gputils";
35 } elsif ( -x "/usr/share/gpasm") {
36 $path = "/usr/share/gpasm";
38 die "Could not find gpasm includes.\n";
43 # Read the symbols at the end of this file.
48 if (/^\s*alias\s+(\S+)\s+(\S+)/) {
50 # Set an alias for a special function register.
51 # Some MPASM include files are not entirely consistent
55 } elsif (/^\s*address\s+(\S+)\s+(\S+)/) {
57 # Set a default address for a special function register.
58 # Some MPASM include files don't specify the address
62 foreach $device (split(/[,\s]+/, $devices)) {
63 $addr{"p$device", "$1"} = $2;
65 } elsif (/^\s*bitmask\s+(\S+)\s+/) {
67 # Set the bitmask that will be used in the 'memmap' pragma.
70 foreach $register (split(/\s+/, $')) {
71 $bitmask{"$register"} = $bitmask;
73 } elsif (/^\s*ram\s+(\S+)\s+(\S+)\s+(\S+)/) {
77 foreach $device (split(/[,\s]+/, $devices)) {
78 $ram{"p$device"} .= "#pragma memmap $lo $hi RAM $bitmask$'";
80 } elsif (/^\s*processor\s+/) {
83 } elsif (/^\s*(\S+)/) {
86 foreach $key (split) {
87 eval "\$type{'$key'} = $type;";
90 foreach $key (split) {
91 eval "\$type{'$key'} = $type;";
97 # Read the linker file.
99 # $linkFile = "$path/lkr/" . lc $processor . ".lkr";
100 # open(LINK, "<$linkFile")
101 # || die "$programName: Error: Cannot open linker file $linkFile ($!)\n";
103 # if (/^(\S+)\s+NAME=(\S+)\s+START=(\S+)\s+END=(\S+)\s+(PROTECTED)?/) {
108 # $protected = 1 if ($5 =~ /protected/i);
110 # if ($type =~ /(SHAREBANK)|(DATABANK)/i) {
111 # $ram{"p$processor"} .=
112 # sprintf("#pragma memmap %7s %7s RAM 0x000\t// $name\n",
115 # } elsif (/^SECTION\s+NAME=(\S+)\s+ROM=(\S+)\s+/) {
122 $defaultType = 'other';
123 $includeFile = "$path/header/p" . lc $processor . ".inc";
124 open(HEADER, "<$includeFile")
125 || die "$programName: Error: Cannot open include file $includeFile ($!)\n";
128 if (/^;-* (\S+) Bits/i) {
129 if (defined($alias{$1})) {
130 $defaultType = "bits $alias{$1}";
132 $defaultType = "bits $1";
136 } elsif (/^;-* Register Files/i) {
137 $defaultType = 'sfr';
146 # Convert ASM comments to C style.
149 } elsif (/^\s*IFNDEF __(\S+)/) {
155 } elsif (/^\s*(\S+)\s+EQU\s+H'(.+)'/) {
157 # Useful bit of information.
165 if (defined($type{"p$processor", "$name"})) {
166 $type = $type{"p$processor", "$name"};
167 } elsif (defined($type{"$name"})) {
168 $type = $type{"$name"};
170 $type = $defaultType;
173 if (defined($bitmask{"p$processor", "$name"})) {
174 $bitmask = $bitmask{"p$processor", "$name"};
175 # } elsif (defined($bitmask{"$name"})) {
176 # $bitmask = $bitmask{"$name"};
181 if ($type eq 'sfr') {
183 # A special function register.
185 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
187 $name, $name, $bitmask, $name);
188 if (defined $addr{"p$processor", "$name"}) {
189 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
191 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
193 $body .= sprintf("sfr at %-30s %s;$rest\n", "${name}_ADDR", $name);
194 $addr{"p$processor", "$name"} = "0x$value";
195 } elsif ($type eq 'volatile') {
197 # A location that can change without
198 # direct program manipulation.
200 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
202 $name, $name, $bitmask, $name);
203 $body .= sprintf("data at %-30s %s;$rest\n", "${name}_ADDR volatile char", $name);
204 if (defined $addr{"p$processor", "$name"}) {
205 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
207 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
209 } elsif ($type =~ /^bits/) {
210 ($junk, $register) = split(/\s/, $type);
212 $addr = $addr{"$register"};
213 $body .= "BIT_AT(${register}_ADDR,$bit)\t$name;$rest\n";
216 # Other registers, bits and/or configurations.
218 if ($type eq 'other') {
222 $body .= sprintf("#define %-20s 0x%s$rest\n", $name, $value);
225 # A symbol that isn't defined in the data
226 # section at the end of the file. Let's
227 # add a comment so that we can add it later.
229 $body .= sprintf("#define %-20s 0x%s$rest\n",
238 } elsif (/__MAXRAM\s+H'([0-9a-fA-F]+)'/) {
239 $maxram .= "//\n// Memory organization.\n//\n"
240 . sprintf("#pragma maxram 0x%s\n\n", $1);
242 . $ram{"p$processor"} . "\n"
247 # Anything else we'll just comment out.
254 // Register Declarations for Microchip $processor Processor
257 // This header file was automatically generated by:
259 //\t$programName V$version
261 //\tCopyright (c) 2002, Kevin L. Pauba, All Rights Reserved
263 //\tSDCC is licensed under the GNU Public license (GPL) v2. Note that
264 //\tthis license covers the code to the compiler and other executables,
265 //\tbut explicitly does not cover any code or objects generated by sdcc.
266 //\tWe have not yet decided on a license for the run time libraries, but
267 //\tit will not put any requirements on code linked against it. See:
269 //\thttp://www.gnu.org/copyleft/gpl/html
271 //\tSee http://sdcc.sourceforge.net/ for the latest information on sdcc.
274 #ifndef P${processor}_H
275 #define P${processor}_H
278 #define BIT_AT(base,bitno) bit at ((base<<3)+bitno)
282 // Register addresses.
295 inc2h.pl - A utility to convert MPASM include files to header files
296 suitable for the SDCC compiler.
298 License: Copyright (c) 2002 Kevin L. Pauba
300 SDCC is licensed under the GNU Public license (GPL) v2; see
301 http://www.gnu.org/copyleft/gpl.html See http://sdcc.sourceforge.net/
302 for the latest information on sdcc.
304 Usage: $programName processor [path]
308 processor The name of the processor (16f84, 16f877, etc.)
310 path The path to the parent of the "header" and "lkr"
311 directories. The default is "/usr/share/gpasm".
313 The header file will be written to the standard output.
323 # processor <processor_name>
324 # address <register_name> <hex_address>
325 # bitmask <bitmask> <register_list>
326 # ram <lo_address> <hi_address> <bitmask>
327 # sfr <register_list>
328 # volatile <address_list>
332 alias OPTION_REG OPTION
339 bitmask 0x080 INDF PCL STATUS FSR PCLATH INTCON
341 processor 16F873, 16F874, 16F877, 16F627, 16F628, 16F876
342 bitmask 0x180 INDF PCL STATUS FSR PCLATH INTCON
343 bitmask 0x100 TMR0 OPTION_REG PORTB TRISB
349 ram 0x000C 0x004f 0x080
351 processor 16F627, 16F628
352 ram 0x0020 0x006f 0x000
353 ram 0x0070 0x007f 0x180
354 ram 0x00a0 0x00ef 0x000
355 ram 0x0120 0x014f 0x000
357 processor 16F876, 16F877
358 ram 0x0020 0x006f 0x000
359 ram 0x0070 0x007f 0x180
360 ram 0x00a0 0x00ef 0x000
361 ram 0x0110 0x016f 0x000
362 ram 0x0190 0x01ef 0x000
364 processor 16F873, 16F874
365 ram 0x0020 0x007f 0x100
366 ram 0x00a0 0x00ff 0x100