From: SourceForge.net <no...@so...> - 2013-02-21 21:46:31
|
Bugs item #2024627, was opened at 2008-07-22 05:43 Message generated for change (Settings changed) made by borutr You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2024627&group_id=599 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: pic14 target Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Stefan Dimitrov (stedi) Assigned to: Raphael Neider (tecodev) >Summary: PIC14, Static variables problem Initial Comment: Using SDCC for PIC16F877 microcontroller. There is a bug with static variables. In generated assembly code, the 'main' procedure does not initialize static variables. Command: sdcc -S -mpic14 -p16f877a main.c SDCC version: msc51/gbz80/z80/avr/ds390/pic16/pic14/TININative/ xa51/ds400/hc08 2.0.8 #5117 (Mar 23 2008) (MINGW32) E-mail: stf...@ma... ---------------------------------------------------------------------- Comment By: Borut Ražem (borutr) Date: 2013-02-21 13:40 Message: Local static initializers for PIC14 target are handeled in file glue.c, function pic14printLocals(). Probably it would be enough to replace udata / res instructions with idata / db instructions? Borut ---------------------------------------------------------------------- Comment By: jpa (jpa-) Date: 2010-06-16 09:18 Message: Just a few things I found out after trying to debug this: Local static initializers work in the PIC16 port, but not in PIC14. I think the relevant place is in SDCCast.c:1322 (function gatherAutoInit) that has a special case for PIC16 port: /* if we are PIC16 port, * and this is a static, * and have initial value, * and not S_CODE, don't emit in gs segment, * but allow glue.c:pic16emitRegularMap to put symbol * in idata section */ if(TARGET_IS_PIC16 && IS_STATIC (sym->etype) && sym->ival && SPEC_SCLS(sym->etype) != S_CODE) { SPEC_SCLS (sym->etype) = S_DATA; continue; } Later in this function sym->ival is set to NULL. This causes that in pic/glue.c:1107 (emitSymbolSet) the variable is emitted as udata instead of idata. PIC16's version of ralloc.c is quite different from PIC14's version. Therefore I'm not sure whether PIC14 port needs a special case or not. This patch seems to fix the problem, but doubt remains whether is the correct solution or not: --- SDCCast.c (revision 5850) +++ SDCCast.c (working copy) @@ -1325,7 +1325,7 @@ * and not S_CODE, don't emit in gs segment, * but allow glue.c:pic16emitRegularMap to put symbol * in idata section */ - if(TARGET_IS_PIC16 && + if((TARGET_IS_PIC16 || TARGET_IS_PIC) && IS_STATIC (sym->etype) && sym->ival && SPEC_SCLS(sym->etype) != S_CODE) { SPEC_SCLS (sym->etype) = S_DATA; ---------------------------------------------------------------------- Comment By: jpa (jpa-) Date: 2010-06-11 10:23 Message: Hm, file attaching failed, here it is as text: #include <pic16f689.h> static char global_test = 10; /* This is initialized correctly */ void foo() { static char local_test = 20; /* This is not initialized at all */ PORTA = global_test; PORTC = local_test; } void main() { TRISA = 0; TRISC = 0; foo(); while(1); } ---------------------------------------------------------------------- Comment By: jpa (jpa-) Date: 2010-06-11 10:20 Message: I think I have the same problem. Global variables are initialized correctly, but local static variables are not. The local static variables are also marked in assembler output as udata. See the attached file sdcc-test.c, which I compiled using: sdcc -mpic14 -p16f689 sdcc-test.c I'm using: SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.9.0 #5416 (Jan 10 2010) (UNIX) ---------------------------------------------------------------------- Comment By: Stefan Dimitrov (stedi) Date: 2008-07-28 06:43 Message: Logged In: YES user_id=2155117 Originator: YES I don`t think this will be very usefull, but just in case here is the full source code of my program + Makefile used to generate the objects. As you will see, if I use 'dpos' as static variable, my 'display()' procedure does not work. File Added: static.rar ---------------------------------------------------------------------- Comment By: Stefan Dimitrov (stedi) Date: 2008-07-28 06:41 Message: Logged In: YES user_id=2155117 Originator: YES I don`t think this will be very usefull, but just in case here is the full source code of my program + Makefile used to generate the objects. As you will see, if I use 'dpos' as static variable, my 'display()' procedure does not work. File Added: static.rar ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2008-07-26 13:49 Message: Logged In: YES user_id=1115835 Originator: NO Oh, I realized your problem: Initializers for static variables are not emitted in the .asm file at all... This needs to be fixed. Thanks for the report! Workaround: Use initialized global variables for now: int foo(void) { static int bar = 42; return bar++; } becomes /*static*/ int __foo_bar = 42; int foo(void) { return __foo_bar++; } ---------------------------------------------------------------------- Comment By: Raphael Neider (tecodev) Date: 2008-07-26 13:35 Message: Logged In: YES user_id=1115835 Originator: NO main() never initializes static variables, __sdcc_gsinit_startup() from the library module idata.[co] does, if the project links against the libsdcc.lib (the default behaviour without -c or -S). Could you post more information about the problem? Do you observe runtime errors? Can you upload a failing source file? If there is a problem, just reopen this item and post more info. Kind regards, Raphael ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=100599&aid=2024627&group_id=599 |