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 ) {
27 $processor = uc(shift);
30 if ($^O eq 'MSWin32') {
32 if (defined($path = $ENV{'GPUTILS_HEADER_PATH'}) || defined($path = $ENV{'GPUTILS_LKR_PATH'})) {
36 die "Could not find gpasm includes.\n";
42 # Nathan Hurst <njh@mail.csse.monash.edu.au>: find gputils on Debian
44 if ( -x "/usr/share/gputils") {
45 $path = "/usr/share/gputils";
46 } elsif ( -x "/usr/share/gpasm") {
47 $path = "/usr/share/gpasm";
49 die "Could not find gpasm includes.\n";
56 # Read the symbols at the end of this file.
61 if (/^\s*alias\s+(\S+)\s+(\S+)/) {
63 # Set an alias for a special function register.
64 # Some MPASM include files are not entirely consistent
68 } elsif (/^\s*address\s+(\S+)\s+(\S+)/) {
70 # Set a default address for a special function register.
71 # Some MPASM include files don't specify the address
75 foreach $device (split(/[,\s]+/, $devices)) {
76 $addr{"p$device", "$1"} = $2;
78 } elsif (/^\s*bitmask\s+(\S+)\s+/) {
80 # Set the bitmask that will be used in the 'memmap' pragma.
83 foreach $register (split(/\s+/, $')) {
84 $bitmask{"$register"} = $bitmask;
86 } elsif (/^\s*ram\s+(\S+)\s+(\S+)\s+(\S+)/) {
90 foreach $device (split(/[,\s]+/, $devices)) {
91 $ram{"p$device"} .= "#pragma memmap $lo $hi RAM $bitmask$'";
93 } elsif (/^\s*processor\s+/) {
96 } elsif (/^\s*(\S+)/) {
99 foreach $key (split) {
100 eval "\$type{'$key'} = $type;";
103 foreach $key (split) {
104 eval "\$type{'$key'} = $type;";
110 # Read the linker file.
112 # $linkFile = "$path/lkr/" . lc $processor . ".lkr";
113 # open(LINK, "<$linkFile")
114 # || die "$programName: Error: Cannot open linker file $linkFile ($!)\n";
116 # if (/^(\S+)\s+NAME=(\S+)\s+START=(\S+)\s+END=(\S+)\s+(PROTECTED)?/) {
121 # $protected = 1 if ($5 =~ /protected/i);
123 # if ($type =~ /(SHAREBANK)|(DATABANK)/i) {
124 # $ram{"p$processor"} .=
125 # sprintf("#pragma memmap %7s %7s RAM 0x000\t// $name\n",
128 # } elsif (/^SECTION\s+NAME=(\S+)\s+ROM=(\S+)\s+/) {
135 $defaultType = 'other';
136 $includeFile = $path.$path_delim.'header'.$path_delim.'p'.lc($processor).'.inc';
137 open(HEADER, "<$includeFile")
138 || die "$programName: Error: Cannot open include file $includeFile ($!)\n";
141 if (/^;-* (\S+) Bits/i) {
142 if (defined($alias{$1})) {
143 $defaultType = "bits $alias{$1}";
145 $defaultType = "bits $1";
149 } elsif (/^;-* Register Files/i) {
150 $defaultType = 'sfr';
159 # Convert ASM comments to C style.
162 } elsif (/^\s*IFNDEF __(\S+)/) {
168 } elsif (/^\s*(\S+)\s+EQU\s+H'(.+)'/) {
170 # Useful bit of information.
178 if (defined($type{"p$processor", "$name"})) {
179 $type = $type{"p$processor", "$name"};
180 } elsif (defined($type{"$name"})) {
181 $type = $type{"$name"};
183 $type = $defaultType;
186 if (defined($bitmask{"p$processor", "$name"})) {
187 $bitmask = $bitmask{"p$processor", "$name"};
188 # } elsif (defined($bitmask{"$name"})) {
189 # $bitmask = $bitmask{"$name"};
194 if ($type eq 'sfr') {
196 # A special function register.
198 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
200 $name, $name, $bitmask, $name);
201 if (defined $addr{"p$processor", "$name"}) {
202 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
204 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
206 $body .= sprintf("sfr at %-30s %s;$rest\n", "${name}_ADDR", $name);
207 $addr{"p$processor", "$name"} = "0x$value";
208 } elsif ($type eq 'volatile') {
210 # A location that can change without
211 # direct program manipulation.
213 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
215 $name, $name, $bitmask, $name);
216 $body .= sprintf("data at %-30s %s;$rest\n", "${name}_ADDR volatile char", $name);
217 if (defined $addr{"p$processor", "$name"}) {
218 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
220 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
222 } elsif ($type =~ /^bits/) {
223 ($junk, $register) = split(/\s/, $type);
225 $addr = $addr{"$register"};
226 $body .= "BIT_AT(${register}_ADDR,$bit)\t$name;$rest\n";
229 # Other registers, bits and/or configurations.
231 if ($type eq 'other') {
235 $body .= sprintf("#define %-20s 0x%s$rest\n", $name, $value);
238 # A symbol that isn't defined in the data
239 # section at the end of the file. Let's
240 # add a comment so that we can add it later.
242 $body .= sprintf("#define %-20s 0x%s$rest\n",
251 } elsif (/__MAXRAM\s+H'([0-9a-fA-F]+)'/) {
252 $maxram .= "//\n// Memory organization.\n//\n"
253 . sprintf("#pragma maxram 0x%s\n\n", $1);
255 . $ram{"p$processor"} . "\n"
260 # Anything else we'll just comment out.
267 // Register Declarations for Microchip $processor Processor
270 // This header file was automatically generated by:
272 //\t$programName V$version
274 //\tCopyright (c) 2002, Kevin L. Pauba, All Rights Reserved
276 //\tSDCC is licensed under the GNU Public license (GPL) v2. Note that
277 //\tthis license covers the code to the compiler and other executables,
278 //\tbut explicitly does not cover any code or objects generated by sdcc.
279 //\tWe have not yet decided on a license for the run time libraries, but
280 //\tit will not put any requirements on code linked against it. See:
282 //\thttp://www.gnu.org/copyleft/gpl/html
284 //\tSee http://sdcc.sourceforge.net/ for the latest information on sdcc.
287 #ifndef P${processor}_H
288 #define P${processor}_H
291 #define BIT_AT(base,bitno) sbit at ((base<<3)+bitno)
295 // Register addresses.
308 inc2h.pl - A utility to convert MPASM include files to header files
309 suitable for the SDCC compiler.
311 License: Copyright (c) 2002 Kevin L. Pauba
313 SDCC is licensed under the GNU Public license (GPL) v2; see
314 http://www.gnu.org/copyleft/gpl.html See http://sdcc.sourceforge.net/
315 for the latest information on sdcc.
317 Usage: $programName processor [path]
321 processor The name of the processor (16f84, 16f877, etc.)
323 path The path to the parent of the "header" and "lkr"
324 directories. The default is "/usr/share/gpasm".
326 The header file will be written to the standard output.
336 # processor <processor_name>
337 # address <register_name> <hex_address>
338 # bitmask <bitmask> <register_list>
339 # ram <lo_address> <hi_address> <bitmask>
340 # sfr <register_list>
341 # volatile <address_list>
345 alias OPTION_REG OPTION
352 bitmask 0x080 INDF PCL STATUS FSR PCLATH INTCON
354 processor 16F873, 16F874, 16F877, 16F627, 16F628, 16F876
355 bitmask 0x180 INDF PCL STATUS FSR PCLATH INTCON
356 bitmask 0x100 TMR0 OPTION_REG PORTB TRISB
362 ram 0x000C 0x004f 0x080
364 processor 16F627, 16F628
365 ram 0x0020 0x006f 0x000
366 ram 0x0070 0x007f 0x180
367 ram 0x00a0 0x00ef 0x000
368 ram 0x0120 0x014f 0x000
370 processor 16F876, 16F877
371 ram 0x0020 0x006f 0x000
372 ram 0x0070 0x007f 0x180
373 ram 0x00a0 0x00ef 0x000
374 ram 0x0110 0x016f 0x000
375 ram 0x0190 0x01ef 0x000
377 processor 16F873, 16F874
378 ram 0x0020 0x007f 0x100
379 ram 0x00a0 0x00ff 0x100