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 $path = "/usr/share/gpasm" if ($path eq '');
34 # Read the symbols at the end of this file.
39 if (/^\s*alias\s+(\S+)\s+(\S+)/) {
41 # Set an alias for a special function register.
42 # Some MPASM include files are not entirely consistent
46 } elsif (/^\s*address\s+(\S+)\s+(\S+)/) {
48 # Set a default address for a special function register.
49 # Some MPASM include files don't specify the address
53 foreach $device (split(/[,\s]+/, $devices)) {
54 $addr{"p$device", "$1"} = $2;
56 } elsif (/^\s*bitmask\s+(\S+)\s+/) {
58 # Set the bitmask that will be used in the 'memmap' pragma.
61 foreach $register (split(/\s+/, $')) {
62 $bitmask{"$register"} = $bitmask;
64 } elsif (/^\s*ram\s+(\S+)\s+(\S+)\s+(\S+)/) {
68 foreach $device (split(/[,\s]+/, $devices)) {
69 $ram{"p$device"} .= "#pragma memmap $lo $hi RAM $bitmask$'";
71 } elsif (/^\s*processor\s+/) {
74 } elsif (/^\s*(\S+)/) {
77 foreach $key (split) {
78 eval "\$type{'$key'} = $type;";
81 foreach $key (split) {
82 eval "\$type{'$key'} = $type;";
88 # Read the linker file.
90 # $linkFile = "$path/lkr/" . lc $processor . ".lkr";
91 # open(LINK, "<$linkFile")
92 # || die "$programName: Error: Cannot open linker file $linkFile ($!)\n";
94 # if (/^(\S+)\s+NAME=(\S+)\s+START=(\S+)\s+END=(\S+)\s+(PROTECTED)?/) {
99 # $protected = 1 if ($5 =~ /protected/i);
101 # if ($type =~ /(SHAREBANK)|(DATABANK)/i) {
102 # $ram{"p$processor"} .=
103 # sprintf("#pragma memmap %7s %7s RAM 0x000\t// $name\n",
106 # } elsif (/^SECTION\s+NAME=(\S+)\s+ROM=(\S+)\s+/) {
113 $defaultType = 'other';
114 $includeFile = "$path/header/p" . lc $processor . ".inc";
115 open(HEADER, "<$includeFile")
116 || die "$programName: Error: Cannot open include file $includeFile ($!)\n";
119 if (/^;-* (\S+) Bits/i) {
120 if (defined($alias{$1})) {
121 $defaultType = "bits $alias{$1}";
123 $defaultType = "bits $1";
127 } elsif (/^;-* Register Files/i) {
128 $defaultType = 'sfr';
137 # Convert ASM comments to C style.
140 } elsif (/^\s*IFNDEF __(\S+)/) {
146 } elsif (/^\s*(\S+)\s+EQU\s+H'(.+)'/) {
148 # Useful bit of information.
156 if (defined($type{"p$processor", "$name"})) {
157 $type = $type{"p$processor", "$name"};
158 } elsif (defined($type{"$name"})) {
159 $type = $type{"$name"};
161 $type = $defaultType;
164 if (defined($bitmask{"p$processor", "$name"})) {
165 $bitmask = $bitmask{"p$processor", "$name"};
166 # } elsif (defined($bitmask{"$name"})) {
167 # $bitmask = $bitmask{"$name"};
172 if ($type eq 'sfr') {
174 # A special function register.
176 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
178 $name, $name, $bitmask, $name);
179 if (defined $addr{"p$processor", "$name"}) {
180 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
182 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
184 $body .= sprintf("sfr at %-30s %s;$rest\n", "${name}_ADDR", $name);
185 $addr{"p$processor", "$name"} = "0x$value";
186 } elsif ($type eq 'volatile') {
188 # A location that can change without
189 # direct program manipulation.
191 $pragmas .= sprintf("#pragma memmap %s_ADDR %s_ADDR "
193 $name, $name, $bitmask, $name);
194 $body .= sprintf("data at %-30s %s;$rest\n", "${name}_ADDR volatile char", $name);
195 if (defined $addr{"p$processor", "$name"}) {
196 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $addr{"p$processor", "$name"});
198 $addresses .= sprintf("#define %s_ADDR\t0x%s\n", $name, $value);
200 } elsif ($type =~ /^bits/) {
201 ($junk, $register) = split(/\s/, $type);
203 $addr = $addr{"$register"};
204 $body .= "BIT_AT(${register}_ADDR,$bit)\t$name;$rest\n";
207 # Other registers, bits and/or configurations.
209 if ($type eq 'other') {
213 $body .= sprintf("#define %-20s 0x%s$rest\n", $name, $value);
216 # A symbol that isn't defined in the data
217 # section at the end of the file. Let's
218 # add a comment so that we can add it later.
220 $body .= sprintf("#define %-20s 0x%s$rest\n",
229 } elsif (/__MAXRAM\s+H'([0-9a-fA-F]+)'/) {
230 $maxram .= "//\n// Memory organization.\n//\n"
231 . sprintf("#pragma maxram 0x%s\n\n", $1);
233 . $ram{"p$processor"} . "\n"
238 # Anything else we'll just comment out.
245 // Register Declarations for Microchip $processor Processor
248 // This header file was automatically generated by:
250 //\t$programName V$version
252 //\tCopyright (c) 2002, Kevin L. Pauba, All Rights Reserved
254 //\tSDCC is licensed under the GNU Public license (GPL) v2. Note that
255 //\tthis license covers the code to the compiler and other executables,
256 //\tbut explicitly does not cover any code or objects generated by sdcc.
257 //\tWe have not yet decided on a license for the run time libraries, but
258 //\tit will not put any requirements on code linked against it. See:
260 //\thttp://www.gnu.org/copyleft/gpl/html
262 //\tSee http://sdcc.sourceforge.net/ for the latest information on sdcc.
265 #ifndef P${processor}_H
266 #define P${processor}_H
269 #define BIT_AT(base,bitno) bit at ((base<<3)+bitno)
273 // Register addresses.
286 inc2h.pl - A utility to convert MPASM include files to header files
287 suitable for the SDCC compiler.
289 License: Copyright (c) 2002 Kevin L. Pauba
291 SDCC is licensed under the GNU Public license (GPL) v2; see
292 http://www.gnu.org/copyleft/gpl.html See http://sdcc.sourceforge.net/
293 for the latest information on sdcc.
295 Usage: $programName processor [path]
299 processor The name of the processor (16f84, 16f877, etc.)
301 path The path to the parent of the "header" and "lkr"
302 directories. The default is "/usr/share/gpasm".
304 The header file will be written to the standard output.
314 # processor <processor_name>
315 # address <register_name> <hex_address>
316 # bitmask <bitmask> <register_list>
317 # ram <lo_address> <hi_address> <bitmask>
318 # sfr <register_list>
319 # volatile <address_list>
323 alias OPTION_REG OPTION
330 bitmask 0x080 INDF PCL STATUS FSR PCLATH INTCON
332 processor 16F873, 16F874, 16F877, 16F627, 16F628, 16F876
333 bitmask 0x180 INDF PCL STATUS FSR PCLATH INTCON
334 bitmask 0x100 TMR0 OPTION_REG PORTB TRISB
340 ram 0x000C 0x004f 0x080
342 processor 16F627, 16F628
343 ram 0x0020 0x006f 0x000
344 ram 0x0070 0x007f 0x180
345 ram 0x00a0 0x00ef 0x000
346 ram 0x0120 0x014f 0x000
348 processor 16F876, 16F877
349 ram 0x0020 0x006f 0x000
350 ram 0x0070 0x007f 0x180
351 ram 0x00a0 0x00ef 0x000
352 ram 0x0110 0x016f 0x000
353 ram 0x0190 0x01ef 0x000
355 processor 16F873, 16F874
356 ram 0x0020 0x007f 0x100
357 ram 0x00a0 0x00ff 0x100