From: michaelh Date: Mon, 17 Jul 2000 04:13:19 +0000 (+0000) Subject: * Changed banked for nonbanked X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ceb51fdca1654e42f6c9c085afc976381f206644;p=fw%2Fsdcc * Changed banked for nonbanked * Added %F and %I to asm.c for filename and increasing int * Fixed add and sub for the z80 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@302 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.lex b/src/SDCC.lex index babc6261..ab71ecef 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -117,7 +117,7 @@ struct options save_options ; "if" { count(); return(IF); } "int" { count(); return(INT); } "interrupt" { count(); return(INTERRUPT);} -"banked" { count(); TKEYWORD(BANKED);} +"nonbanked" { count(); TKEYWORD(NONBANKED);} "long" { count(); return(LONG); } "near" { count(); TKEYWORD(DATA);} "pdata" { count(); TKEYWORD(PDATA); } diff --git a/src/SDCC.y b/src/SDCC.y index 1d547ce8..2a322895 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -77,7 +77,7 @@ value *cenum = NULL ; /* current enumeration type chain*/ %token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN %token XOR_ASSIGN OR_ASSIGN %token TYPEDEF EXTERN STATIC AUTO REGISTER CODE EEPROM INTERRUPT SFR AT SBIT -%token REENTRANT USING XDATA DATA IDATA PDATA VAR_ARGS CRITICAL BANKED +%token REENTRANT USING XDATA DATA IDATA PDATA VAR_ARGS CRITICAL NONBANKED %token CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE CONST VOLATILE VOID BIT %token STRUCT UNION ENUM ELIPSIS RANGE FAR _XDATA _CODE _GENERIC _NEAR _PDATA _IDATA _EEPROM %token CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN @@ -165,9 +165,9 @@ using_reentrant_interrupt $$->class = SPECIFIER ; SPEC_CRTCL($$) = 1; } - | BANKED {$$ = newLink (); + | NONBANKED {$$ = newLink (); $$->class = SPECIFIER ; - SPEC_BANKED($$) = 1; + SPEC_NONBANKED($$) = 1; } | Interrupt_storage { diff --git a/src/SDCCmem.c b/src/SDCCmem.c index e19ed96f..3d19be24 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -6,10 +6,10 @@ /* memory segments */ memmap *xstack= NULL ; /* xternal stack data */ -memmap *istack= NULL; /* internal stack */ -memmap *code = NULL; /* code segment */ +memmap *istack= NULL; /* internal stack */ +memmap *code = NULL; /* code segment */ memmap *data = NULL; /* internal data upto 128 */ -memmap *xdata = NULL; /* external data */ +memmap *xdata = NULL; /* external data */ memmap *idata = NULL; /* internal data upto 256 */ memmap *bit = NULL; /* bit addressable space */ memmap *statsg= NULL; /* the constant data segment */ diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 06683574..b8ee1189 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -420,7 +420,7 @@ link *mergeSpec ( link *dest, link *src ) SPEC_BLEN(dest) |= SPEC_BLEN(src); SPEC_BSTR(dest) |= SPEC_BSTR(src); SPEC_TYPEDEF(dest) |= SPEC_TYPEDEF(src); - SPEC_BANKED(dest) |= SPEC_BANKED(src); + SPEC_NONBANKED(dest) |= SPEC_NONBANKED(src); if ( IS_STRUCT(dest) && SPEC_STRUCT(dest) == NULL ) SPEC_STRUCT(dest) = SPEC_STRUCT(src); diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 504609c6..edcb02cf 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -101,7 +101,7 @@ typedef struct specifier { unsigned _typedef :1 ; /* is typedefed */ unsigned _isregparm:1 ; /* is the first parameter */ unsigned _isenum :1 ; /* is an enumerated type */ - unsigned banked :1 ; /* function has banked attribute */ + unsigned nonbanked :1 ; /* function has the nonbanked attribute */ unsigned _IntNo ; /* 1=Interrupt svc routine */ short _regbank ; /* register bank 2b used */ unsigned _addr ; /* address of symbol */ @@ -279,7 +279,7 @@ typedef struct symbol { #define SPEC_STRUCT(x) x->select.s.v_struct #define SPEC_TYPEDEF(x) x->select.s._typedef #define SPEC_REGPARM(x) x->select.s._isregparm -#define SPEC_BANKED(x) x->select.s.banked +#define SPEC_NONBANKED(x) x->select.s.nonbanked /* type check macros */ #define IS_DECL(x) ( x && x->class == DECLARATOR ) @@ -326,7 +326,9 @@ typedef struct symbol { #define IS_LITERAL(x) (IS_SPEC(x) && x->select.s.sclass == S_LITERAL) #define IS_ISR(x) (IS_SPEC(x) && SPEC_INTRTN(x)) #define IS_REGPARM(x) (IS_SPEC(x) && SPEC_REGPARM(x)) -#define IS_BANKED(x) (IS_SPEC(x) && SPEC_BANKED(x)) +#define IS_NONBANKED(x) (IS_SPEC(x) && SPEC_NONBANKED(x)) +/* Note that !IS_BANKED is not IS_NONBANKED */ +#define IS_BANKED(x) (IS_SPEC(x) && !SPEC_NONBANKED(x) && !SPEC_STAT(x)) /* forward declaration for the global vars */ extern bucket *SymbolTab[] ; diff --git a/src/asm.c b/src/asm.c index 2766b987..733e3383 100644 --- a/src/asm.c +++ b/src/asm.c @@ -12,6 +12,7 @@ static va_list _iprintf(char *pInto, const char *szFormat, va_list ap) { char *pStart = pInto; char *sz = gc_strdup(szFormat); + static int count; while (*sz) { if (*sz == '%') { @@ -26,6 +27,16 @@ static va_list _iprintf(char *pInto, const char *szFormat, va_list ap) pInto = pStart + strlen(pStart); sz++; break; + case 'F': + strcpy(pInto, srcFileName); + pInto = pStart + strlen(pStart); + sz++; + break; + case 'I': + sprintf(pInto, "%u", ++count); + pInto = pStart + strlen(pStart); + sz++; + break; default: { /* Scan out the arg and pass it on to sprintf */ @@ -155,8 +166,8 @@ static const ASM_MAPPING _asxxxx_mapping[] = { { "immedword", "#0x%04X" }, { "immedbyte", "#0x%02X" }, { "hashedstr", "#%s" }, - { "lsbimmeds", "#>%s" }, - { "msbimmeds", "#<%s" }, + { "lsbimmeds", "#<%s" }, + { "msbimmeds", "#>%s" }, { "module", ".module %s" }, { "global", ".globl %s" }, { "fileprelude", "" }, diff --git a/src/z80/gen.c b/src/z80/gen.c index 431eb1bc..c22a8105 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -844,9 +844,19 @@ static void fetchPairLong(PAIR_ID pairId, asmop *aop, int offset) else { /* we need to get it byte by byte */ if (pairId == PAIR_HL && IS_GB && requiresHL(aop)) { aopGet(aop, offset, FALSE); - emit2("!ldahli"); - emit2("ld h,!*hl"); - emit2("ld l,a"); + switch (aop->size) { + case 1: + emit2("ld l,!*hl"); + emit2("ld h,!immedbyte", 0); + break; + case 2: + emit2("!ldahli"); + emit2("ld h,!*hl"); + emit2("ld l,a"); + break; + default: + emit2("; WARNING: mlh woosed out. This code is invalid."); + } } else if (IS_Z80 && aop->type == AOP_IY) { /* Instead of fetching relative to IY, just grab directly @@ -1629,6 +1639,24 @@ static int _opUsesPair(operand *op, iCode *ic, PAIR_ID pairId) return ret; } +/* This is quite unfortunate */ +static void setArea(int inHome) +{ + static int lastArea = 0; + + if (lastArea != inHome) { + if (inHome) { + const char *sz = port->mem.code_name; + port->mem.code_name = "HOME"; + emit2("!area", CODE_NAME); + port->mem.code_name = sz; + } + else + emit2("!area", CODE_NAME); + lastArea = inHome; + } +} + /** Emit the code for a call statement */ static void emitCall(iCode *ic, bool ispcall) @@ -1798,7 +1826,6 @@ static void emitCall(iCode *ic, bool ispcall) static void genCall (iCode *ic) { link *detype = getSpec(operandType(IC_LEFT(ic))); - if (IS_BANKED(detype)) emit2("; call to a banked function"); emitCall(ic, FALSE); } @@ -1836,6 +1863,8 @@ static void genFunction (iCode *ic) link *fetype; nregssaved = 0; + setArea(IS_NONBANKED(sym->etype)); + /* create the function header */ emit2("!functionheader", sym->name); /* PENDING: portability. */ @@ -1847,7 +1876,6 @@ static void genFunction (iCode *ic) /* if critical function then turn interrupts off */ if (SPEC_CRTCL(fetype)) emit2("!di"); - if (SPEC_BANKED(fetype)) emit2("; Iam banked"); /* if this is an interrupt service routine then save acc, b, dpl, dph */ @@ -2227,7 +2255,10 @@ static void genPlus (iCode *ic) if (AOP_TYPE(IC_LEFT(ic)) == AOP_STK || AOP_TYPE(IC_RIGHT(ic)) == AOP_STK || AOP_TYPE(IC_RESULT(ic)) == AOP_STK) { - if (size == 2) { + if ((AOP_SIZE(IC_LEFT(ic)) == 2 || + AOP_SIZE(IC_RIGHT(ic)) == 2) && + (AOP_SIZE(IC_LEFT(ic)) <= 2 && + AOP_SIZE(IC_RIGHT(ic)) <= 2)) { if (getPairId(AOP(IC_RIGHT(ic))) == PAIR_BC) { /* Swap left and right */ operand *t = IC_RIGHT(ic); @@ -2389,7 +2420,10 @@ static void genMinus (iCode *ic) if (AOP_TYPE(IC_LEFT(ic)) == AOP_STK || AOP_TYPE(IC_RIGHT(ic)) == AOP_STK || AOP_TYPE(IC_RESULT(ic)) == AOP_STK) { - if (size == 2) { + if ((AOP_SIZE(IC_LEFT(ic)) == 2 || + AOP_SIZE(IC_RIGHT(ic)) == 2) && + (AOP_SIZE(IC_LEFT(ic)) <= 2 && + AOP_SIZE(IC_RIGHT(ic)) <= 2)) { PAIR_ID left = getPairId(AOP(IC_LEFT(ic))); PAIR_ID right = getPairId(AOP(IC_RIGHT(ic))); @@ -4822,6 +4856,6 @@ void genZ80Code (iCode *lic) peepHole (&lineHead); /* now do the actual printing */ - printLine (lineHead,codeOutFile); + printLine (lineHead, codeOutFile); return; } diff --git a/src/z80/main.c b/src/z80/main.c index 935e1f07..c4981344 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -14,13 +14,20 @@ static char _gbz80_defaultRules[] = Z80_OPTS z80_opts; +typedef enum { + /* Must be first */ + ASM_TYPE_ASXXXX, + ASM_TYPE_RGBDS, + ASM_TYPE_ISAS +} ASM_TYPE; + static struct { - bool fsetAsmType; + ASM_TYPE asmType; } _G; static char *_keywords[] = { "sfr", - "banked", + "nonbanked", NULL }; @@ -72,11 +79,36 @@ static int _process_pragma(const char *sz) { if (_startsWith(sz, "bank=")) { char buffer[128]; - sprintf(buffer, "%s", sz+5); + strcpy(buffer, sz+5); _chomp(buffer); - if (!strcmp(buffer, "BASE")) { + if (isdigit(buffer[0])) { + + } + else if (!strcmp(buffer, "BASE")) { strcpy(buffer, "HOME"); } + if (isdigit(buffer[0])) { + /* Arg was a bank number. Handle in an ASM independent + way. */ + char num[128]; + strcpy(num, sz+5); + _chomp(num); + + switch (_G.asmType) { + case ASM_TYPE_ASXXXX: + sprintf(buffer, "CODE_%s", num); + break; + case ASM_TYPE_RGBDS: + sprintf(buffer, "CODE,BANK[%s]", num); + break; + case ASM_TYPE_ISAS: + /* PENDING: what to use for ISAS? */ + sprintf(buffer, "CODE,BANK(%s)", num); + break; + default: + wassert(0); + } + } gbz80_port.mem.code_name = gc_strdup(buffer); code->sname = gbz80_port.mem.code_name; return 0; @@ -161,19 +193,18 @@ static bool _parseOptions(int *pargc, char **argv, int *i) gbz80_port.assembler.cmd = _gbz80_rgbasmCmd; gbz80_port.linker.cmd = _gbz80_rgblinkCmd; gbz80_port.linker.do_link = _gbz80_rgblink; - _G.fsetAsmType = TRUE; + _G.asmType = ASM_TYPE_RGBDS; return TRUE; } else if (!strcmp(argv[*i], "--asm=asxxxx")) { - asm_addTree(&_asxxxx_gb); - _G.fsetAsmType = TRUE; + _G.asmType = ASM_TYPE_ASXXXX; return TRUE; } else if (!strcmp(argv[*i], "--asm=isas")) { asm_addTree(&_isas_gb); /* Munge the function prefix */ gbz80_port.fun_prefix = ""; - _G.fsetAsmType = TRUE; + _G.asmType = ASM_TYPE_ISAS; return TRUE; } } @@ -185,7 +216,7 @@ static void _finaliseOptions(void) { port->mem.default_local_map = data; port->mem.default_globl_map = data; - if (!_G.fsetAsmType && IS_GB) + if (_G.asmType == ASM_TYPE_ASXXXX && IS_GB) asm_addTree(&_asxxxx_gb); } diff --git a/src/z80/mappings.i b/src/z80/mappings.i index 8a507fdd..987d4e60 100644 --- a/src/z80/mappings.i +++ b/src/z80/mappings.i @@ -113,7 +113,7 @@ static const ASM_MAPPING _rgbds_mapping[] = { { "functionlabeldef", "%s:" }, { "zero", "$00" }, { "one", "$01" }, - { "area", "SECTION \"%s\",%C" }, + { "area", "SECTION \"%s_%F_%I\",%C" }, { "areacode", "SECTION \"CODE\",%C" }, { "areadata", "SECTION \"DATA\",BSS" }, { "ascii", "DB \"%s\"" },