From f8300ed80f8c4e7ed7d4207399abf2f7e334452b Mon Sep 17 00:00:00 2001 From: tecodev Date: Tue, 10 Oct 2006 18:20:41 +0000 Subject: [PATCH] * src/pic/main.c (_pic14_parseOptions): added --stack-loc=NUM and --stack-siz=NUM options to configure the argument passing stack * src/pic/main.h: added stackLocation and stackSize to pic14_options_t * src/pic/device.c (mapRegister): catch out-of-memory SIGSEGVs, (pic14_getSharebankSize): obey --stack-siz=NUM, (pic14_getSharebankAddress): obey --stack-loc=NUM git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4405 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 +++++++++ src/pic/device.c | 29 +++++++++++++++++++++++------ src/pic/main.c | 38 ++++++++++++++++++++++++++++++++++++++ src/pic/main.h | 2 ++ 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index ee1638e9..47c3badd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-10-10 Raphael Neider + + * src/pic/main.c (_pic14_parseOptions): added --stack-loc=NUM and + --stack-siz=NUM options to configure the argument passing stack + * src/pic/main.h: added stackLocation and stackSize to pic14_options_t + * src/pic/device.c (mapRegister): catch out-of-memory SIGSEGVs, + (pic14_getSharebankSize): obey --stack-siz=NUM, + (pic14_getSharebankAddress): obey --stack-loc=NUM + 2006-10-08 Frieder Ferlemann * doc/sdccman.lyx: added to the manual diff --git a/src/pic/device.c b/src/pic/device.c index fa970737..9cfdb553 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -800,6 +800,8 @@ void mapRegister(regs *reg) for(i=0; isize; i++) { + assert(reg->address >= 0 && reg->address < maxRAMaddress); + alias = finalMapping[reg->address].alias; reg->alias = alias; @@ -1024,13 +1026,17 @@ int pic14_getHasSecondConfigReg(void) *-----------------------------------------------------------------*/ int pic14_getSharebankSize(void) { - return 16; + if (pic14_options.stackSize <= 0) { + // default size: 16 bytes + return 16; + } else { + return pic14_options.stackSize; + } } /*-----------------------------------------------------------------* * Query the highest byte address occupied by the sharebank of the * selected device. - * FIXME: Currently always returns 0x7f. * THINK: Might not be needed, if we assign all shareable objects to * a `udata_shr' section and let the linker do the rest... * Tried it, but yields `no target memory available' for pic16f877... @@ -1038,10 +1044,21 @@ int pic14_getSharebankSize(void) int pic14_getSharebankAddress(void) { int sharebankAddress = 0x7f; - /* If total RAM is less than 0x7f as with 16f84 then reduce - * sharebankAddress to fit */ - if ((unsigned)sharebankAddress > pic14_getMaxRam()) - sharebankAddress = (int)pic14_getMaxRam(); + if (pic14_options.stackLocation != 0) { + // permanent (?) workaround for pic16f84a-like devices with hardly + // any memory: + // 0x00-0x0B SFR + // 0x0C-0x4F memory, + // 0x50-0x7F unimplemented (reads as 0), + // 0x80-0x8B SFRs (partly mapped to 0x0?) + // 0x8c-0xCF mapped to 0x0C-0x4F + sharebankAddress = pic14_options.stackLocation + pic14_getSharebankSize() - 1; + } else { + /* If total RAM is less than 0x7f as with 16f84 then reduce + * sharebankAddress to fit */ + if ((unsigned)sharebankAddress > pic14_getMaxRam()) + sharebankAddress = (int)pic14_getMaxRam(); + } return sharebankAddress; } diff --git a/src/pic/main.c b/src/pic/main.c index dba9b231..71d8ad89 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -12,6 +12,7 @@ #include "SDCCmacro.h" #include "MySystem.h" #include "glue.h" +#include //#include "gen.h" @@ -51,10 +52,15 @@ static char *_pic14_keywords[] = pic14_options_t pic14_options; +#define ARG_STACKLOC "--stack-loc" +#define ARG_STACKSIZ "--stack-siz" + extern int debug_verbose; /* from pcode.c */ static OPTION _pic14_poptions[] = { { 0 , "--debug-xtra", &debug_verbose, "show more debug info in assembly output" }, { 0 , "--no-pcode-opt", &pic14_options.disable_df, "disable (slightly faulty) optimization on pCode" }, + { 0 , ARG_STACKLOC, &pic14_options.stackLocation, "sets the lowest address of the argument passing stack" }, + { 0 , ARG_STACKSIZ, &pic14_options.stackSize, "sets the size if the argument passing stack (default: 16, minimum: 4)" }, { 0 , NULL, NULL, NULL } }; @@ -153,6 +159,7 @@ static bool _pic14_parseOptions (int *pargc, char **argv, int *i) { char buf[128]; + int len; /* TODO: allow port-specific command line options to specify * segment names here. @@ -173,6 +180,37 @@ _pic14_parseOptions (int *pargc, char **argv, int *i) return 1; } + len = strlen(ARG_STACKLOC); + if (!strncmp(ARG_STACKLOC, argv[ *i ], len)) { + if (argv[*i][len] != '=' || argv[*i][len+1] == 0) { + printf("ERROR: no number entered for %s=num\n", ARG_STACKLOC); + exit(EXIT_FAILURE); + } + // extract number from "--stack-loc=0x70" + pic14_options.stackLocation = strtol(argv[ *i ] + len + 1, NULL, 0); + + if (errno) { + printf("ERROR: Could not parse number after %s=num\n", ARG_STACKLOC); + exit(EXIT_FAILURE); + } + return 1; + } + + len = strlen(ARG_STACKLOC); + if (!strncmp(ARG_STACKSIZ, argv[*i], len)) { + if (argv[*i][len] != '=' || argv[*i][len+1] == 0) { + printf("ERROR: no number entered for %s=num\n", ARG_STACKSIZ); + exit(EXIT_FAILURE); + } + // extract number from "--stack-size=16" + pic14_options.stackSize = strtol(argv[ *i ] + len + 1, NULL, 0); + if (errno) { + printf("ERROR: Could not parse number after %s=num\n", ARG_STACKLOC); + exit(EXIT_FAILURE); + } + return 1; + } + return FALSE; } diff --git a/src/pic/main.h b/src/pic/main.h index da5f40a1..b84b42a8 100644 --- a/src/pic/main.h +++ b/src/pic/main.h @@ -4,6 +4,8 @@ typedef struct { unsigned int isLibrarySource:1; int disable_df; + int stackLocation; + int stackSize; } pic14_options_t; extern pic14_options_t pic14_options; -- 2.47.2