gnupic: Re: sdcc feature request: some help needed (partial solution patch)


Previous by date: 1 May 2005 22:42:08 +0100 Re: [gnupic] - What programmer and software do you use?, Jan Wagemakers
Next by date: 1 May 2005 22:42:08 +0100 Re: [gnupic] - What programmer and software do you use?, Shaun
Previous in thread:
Next in thread:

Subject: re: sdcc feature request: some help needed (partial solution patch)
From: Peter ####@####.####
Date: 1 May 2005 22:42:08 +0100
Message-Id: <pgosx.giog@itpf.ibaa.uj.jvcmi>

Hi, this is in continuation to my feature request. I have studied the 
code and arrived at some conclusions on where the changes are to be made 
and how, but I would appreciate a 'guiding hand'. Please see below for 
details.

>---------- Forwarded message ----------
>Date: Fri, 29 Apr 2005 23:22:26 +0300 (IDT)
>From: Peter ####@####.####
>To: ####@####.####
>Subject: re: sdcc feature request
>
>I have a feature request:
>
>I would like code like:
>
>code char at 0x1234 foo[] = "abcd";
>
>to generate initialised data at the indicated absolute address. Assume 
>that the absolute address chosen will not collide with anything 
>generated by the compiler for a start. This does not happen currently, 
>and no error is raised. For example, compiling something like:

The output of a statement like:

 	code char at 0x1234 foo[] = "abcd";

should be:

 	.area CODE (ABS)
 	.org 0x1234
_foo:
 	.ascii "abcd"

or equivalent. Since there is no easy way to determine if the address is 
or will be used this is ignored and left to the user to fix for now 
(more exactly the linker should complain if the address is reused - it 
probably does, I did not check).

3. Implementation:

modify src/SDCCglue.c:emitStaticSeg() so it emits code as above for any 
static (?) symbol that has an absolute address in segment code 
(IS_STATIC && SPEC_ABSA && code) ( -- should check for *WHICH* storage 
class it is static in and only do it for code and eeprom (at89s8252 
f.ex.)).

Question: the same rule also appears in src/SDCCglue.c:emitRegularMap 
and there also nothing is emitted for an absolute address. Where should 
this be done ? Both places ? emitRegularMap can move symbols to the 
static seg. Hmm ? Should there be an extra segment for this type of data 
?

This initialised data should really be moved into a 'new' segment imho 
as switching the .area before and after each absolute segment emit in 
emitStaticSeg() as I implemented it now is a hack. It may break things 
(anything static with an address will be defined in code - this is not 
necessarily a bug it depends on what one understands under 'static 
initialised @address).

4. Tiny patch against sdcc-2.4.0 (patch name for archive purposes is 
sdcc-2.4.0-plp-icode-0.0.diff). This is a hack. It needs major cleaning 
up imho. It could break other things.

save as: sdcc-2.4.0-plp-icode-0.0.diff

apply as in: cd src/; patch SDCCglue.c <sdcc-2.4.0-plp-icode-0.0.diff

--snip--
1196a1197
>       int absflg = 0; // 1 if we print an absolute static symbol
1228a1230
> 
1231,1234c1233,1259
< 
< 	  fprintf (out, "%s\t=\t0x%04x\n",
< 		   sym->rname,
< 		   SPEC_ADDR (sym->etype));
---
> 
> 	  // plp 2005 
> 	  if( IS_STATIC(sym->etype) && 
> 	      SPEC_ADDR(sym->etype) ) 
> 	  {
> 		  //if(!absflg) // avoid printing unnecessarily
> 		  fprintf( out, "\t.area CODE\t(ABS)\n");
> 		  fprintf( out, "\t.org 0x%04X\n", SPEC_ADDR(sym->etype));
> 	  }
> 	  // plp 2005 : for now duplicate the code below, must clean up
> 	  // later
> 	  if (sym->ival) {
> 	  	fprintf (out, "%s:\n", sym->rname);
> 		noAlloc++;
> 		resolveIvalSym (sym->ival, sym->type);
> 		printIval (sym, sym->type, sym->ival, out);
> 		noAlloc--;
> 	        /* if sym is a simple string and sym->ival is a string, 
> 		   WE don't need it anymore */
> 	        if (IS_ARRAY(sym->type) && IS_CHAR(sym->type->next) &&
> 		  IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
> 		  list2val(sym->ival)->sym->isstrlit) 
> 		{
> 		    freeStringSymbol(list2val(sym->ival)->sym);
> 	        }
> 	  }
> 	  fprintf( out, "\t.area CSEG\t(CODE)\n");
--snap--

test program:

1.c:
--snip--
#include <8051.h>

code static char at 0x1234 foo[] = "abc";
code char bar = 'y';

void main(void)
{
         ;
}
--snap--

output assembly tail:

--snip--
         .area CSEG    (CODE)
         .area CODE      (ABS)
         .org 0x1234
_foo:
         .ascii "abc"
         .db 0x00
         .area CSEG      (CODE)
_bar:
         .db #0x79
         .area XINIT   (CODE)
--snap--

Previous by date: 1 May 2005 22:42:08 +0100 Re: [gnupic] - What programmer and software do you use?, Jan Wagemakers
Next by date: 1 May 2005 22:42:08 +0100 Re: [gnupic] - What programmer and software do you use?, Shaun
Previous in thread:
Next in thread:


Powered by ezmlm-browse 0.20.