From bd6b873b21bff3fdc161f53f25b5b884843ed9d9 Mon Sep 17 00:00:00 2001 From: michaelh Date: Mon, 24 Jan 2000 02:29:19 +0000 Subject: [PATCH] Added initial stack direction support. Didnt convert xstack but are straight forward. Works on z80. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@28 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 10 ++++++-- src/SDCCmem.c | 60 +++++++++++++++++++++++++++++++++++------------- src/SDCCmem.h | 4 ++-- src/mcs51/main.c | 2 +- src/port.h | 5 ++-- 5 files changed, 58 insertions(+), 23 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index f985dc55..99d536cf 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -3529,8 +3529,14 @@ ast *createFunction (symbol *name, ast *body ) processFuncArgs(currFunc,0); /* set the stack pointer */ - stackPtr = -1 - (IS_ISR(name->etype)) - (IS_RENT(name->etype) | options.stackAuto); - xstackPtr= -1; + /* PENDING: check this for the mcs51 */ + stackPtr = -port->stack.direction * port->stack.call_overhead; + if (IS_ISR(name->etype)) + stackPtr -= port->stack.direction * port->stack.isr_overhead; + if (IS_RENT(name->etype) || options.stackAuto) + stackPtr -= port->stack.direction * port->stack.reent_overhead; + + xstackPtr = -port->stack.direction * port->stack.call_overhead; fetype = getSpec(name->type); /* get the specifier for the function */ /* if this is a reentrant function then */ diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 6ba284b9..e284d32d 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -39,7 +39,7 @@ memmap *allocMap (char rspace, /* sfr space */ char bitaddr, /* bit addressable space*/ char codemap, /* this is code space */ unsigned sloc, /* starting location */ - char *name, /* 2 character name */ + const char *name, /* 2 character name */ char dbName ) { @@ -362,6 +362,7 @@ void allocParms ( value *val ) /* choose which stack 2 use */ /* use xternal stack */ if ( options.useXstack ) { + /* PENDING: stack direction support */ SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = xstack ; SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = xstackPtr - getSize(lval->type); @@ -369,11 +370,19 @@ void allocParms ( value *val ) } else { /* use internal stack */ SPEC_OCLS(lval->etype) = SPEC_OCLS(lval->sym->etype) = istack ; - SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = - stackPtr - ( SPEC_BANK(currFunc->etype) ? 1 : 0) - - getSize(lval->type) - - (IS_ISR(currFunc->etype) ? 4 : 0); - stackPtr -= getSize (lval->type); + if (port->stack.direction > 0) { + SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = + stackPtr - ( SPEC_BANK(currFunc->etype) ? port->stack.bank_overhead : 0) - + getSize(lval->type) - + (IS_ISR(currFunc->etype) ? port->stack.isr_overhead : 0); + stackPtr -= getSize (lval->type); + } + else { + /* This looks like the wrong order but it turns out OK... */ + /* PENDING: isr, bank overhead, ... */ + SPEC_STAK(lval->etype) = SPEC_STAK(lval->sym->etype) = lval->sym->stack = stackPtr; + stackPtr += getSize (lval->type); + } } allocIntoSeg(lval->sym); } @@ -473,14 +482,21 @@ void allocLocal ( symbol *sym ) sym->onStack = 1; if ( options.useXstack ) { + /* PENDING: stack direction for xstack */ SPEC_OCLS(sym->etype) = xstack ; SPEC_STAK(sym->etype) = sym->stack = (xstackPtr + 1); xstackPtr += getSize (sym->type) ; } else { SPEC_OCLS(sym->etype) = istack ; - SPEC_STAK(sym->etype) = sym->stack = ( stackPtr + 1); - stackPtr += getSize (sym->type) ; + if (port->stack.direction > 0) { + SPEC_STAK(sym->etype) = sym->stack = ( stackPtr + 1); + stackPtr += getSize (sym->type) ; + } + else { + stackPtr -= getSize (sym->type); + SPEC_STAK(sym->etype) = sym->stack = stackPtr; + } } allocIntoSeg(sym); return ; @@ -704,12 +720,18 @@ void redoStackOffsets () int size = getSize(sym->type); /* nothing to do with parameters so continue */ if ((sym->_isparm && !IS_REGPARM(sym->etype))) - continue ; + continue ; if ( IS_AGGREGATE(sym->type)) { + if (port->stack.direction > 0) { SPEC_STAK(sym->etype) = sym->stack = ( sPtr + 1); sPtr += size; - continue ; + } + else { + sPtr -= size; + SPEC_STAK(sym->etype) = sym->stack = sPtr; + } + continue; } /* if allocation not required then subtract @@ -720,8 +742,14 @@ void redoStackOffsets () continue ; } - SPEC_STAK(sym->etype) = sym->stack = ( sPtr + 1); - sPtr += size ; + if (port->stack.direction > 0) { + SPEC_STAK(sym->etype) = sym->stack = ( sPtr + 1); + sPtr += size ; + } + else { + sPtr -= size ; + SPEC_STAK(sym->etype) = sym->stack = sPtr; + } } /* do the same for the external stack */ @@ -732,12 +760,12 @@ void redoStackOffsets () int size = getSize(sym->type); /* nothing to do with parameters so continue */ if ((sym->_isparm && !IS_REGPARM(sym->etype))) - continue ; + continue ; if (IS_AGGREGATE(sym->type)) { - SPEC_STAK(sym->etype) = sym->stack = ( xsPtr + 1); - xsPtr += size ; - continue ; + SPEC_STAK(sym->etype) = sym->stack = ( xsPtr + 1); + xsPtr += size ; + continue ; } /* if allocation not required then subtract diff --git a/src/SDCCmem.h b/src/SDCCmem.h index 03961ad3..9ff8dfc1 100644 --- a/src/SDCCmem.h +++ b/src/SDCCmem.h @@ -9,7 +9,7 @@ struct set ; struct value ; typedef struct memmap{ unsigned char pageno;/* page no for this variable */ - char *sname; /* character prefix for map */ + const char *sname; /* character prefix for map */ char dbName ; /* debugger address space name */ int slbl ; /* label counter for space */ unsigned sloc ; /* starting location */ @@ -63,7 +63,7 @@ extern struct set *ovrSetSets; #define IN_CODESPACE(map) (map && map->codesp) /* forward decls for functions */ -memmap *allocMap (char,char,char,char,char,char,unsigned,char *,char ); +memmap *allocMap (char,char,char,char,char,char,unsigned, const char *,char ); void initMem ( ); void allocGlobal (struct symbol * ); void allocLocal (struct symbol * ); diff --git a/src/mcs51/main.c b/src/mcs51/main.c index 49cee9e0..bd0716fe 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -61,7 +61,7 @@ PORT mcs51_port = { "OSEG (OVR,DATA)" }, { - +1, 1, 4, 0, 0 + +1, 1, 4, 1, 1 }, /* mcs51 has an 8 bit mul */ { diff --git a/src/port.h b/src/port.h index b1503ae4..11ff318d 100644 --- a/src/port.h +++ b/src/port.h @@ -60,8 +60,9 @@ typedef struct { int isr_overhead; /** Standard overhead for a function call */ int call_overhead; - /** Initial SP offset */ - int start_sp; + /** Re-enterant space */ + int reent_overhead; + } stack; struct { /** One more than the smallest mul/div operation the processor can do nativley -- 2.39.5