X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=direct.c;h=b3f51f3c3b73356c638a0dc9b087cc20f67ab58d;hp=d535c4842b40870f794dfeb424e28093b96c6dea;hb=c38505ee4b2a0de59926107e52fb8bb84041a0e4;hpb=f3c7d186a15b89c39e360b9cc89545a0d24bd6a4 diff --git a/direct.c b/direct.c index d535c48..b3f51f3 100644 --- a/direct.c +++ b/direct.c @@ -1,7 +1,7 @@ // // RMAC - Reboot's Macro Assembler for all Atari computers // DIRECT.C - Directive Handling -// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends +// Copyright (C) 199x Landon Dyer, 2011-2020 Reboot and Friends // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986 // Source utilised with the kind permission of Landon Dyer // @@ -9,8 +9,10 @@ #include "direct.h" #include "6502.h" #include "amode.h" +#include "dsp56k.h" #include "error.h" #include "expr.h" +#include "fltpoint.h" #include "listing.h" #include "mach.h" #include "macro.h" @@ -20,16 +22,12 @@ #include "sect.h" #include "symbol.h" #include "token.h" -#include "math.h" -#include "sect.h" #define DEF_KW #include "kwtab.h" -// N.B.: It's perfectly fine to keep exprbuf as an array of TOKENS and to cast -// to a TOKENPTR where needed. But this works too. :-P -TOKEN _exprbuf[128]; // Expression buffer -TOKENPTR exprbuf = (TOKENPTR)_exprbuf; // Expression buffer point + +TOKEN exprbuf[128]; // Expression buffer SYM * symbolPtr[1000000]; // Symbol pointers table static long unused; // For supressing 'write' warnings char buffer[256]; // Scratch buffer for messages @@ -38,7 +36,6 @@ int largestAlign[3] = { 2, 2, 2 }; // Largest alignment value seen per section // Function prototypes int d_unimpl(void); int d_68000(void); -int d_68000(void); int d_68020(void); int d_68030(void); int d_68040(void); @@ -54,6 +51,7 @@ int d_abs(void); int d_comm(void); int d_dc(WORD); int d_ds(WORD); +int d_dsm(WORD); int d_dcb(WORD); int d_globl(void); int d_gpu(void); @@ -83,6 +81,7 @@ int d_cstruct(void); int d_prgflags(void); int d_opt(void); int d_dsp(void); +int d_objproc(void); void SetLargestAlignment(int); // Directive handler table @@ -153,7 +152,9 @@ int (*dirtab[])() = { d_68882, // 63 .68882 d_56001, // 64 .56001 d_nofpu, // 65 nofpu - d_opt, // 58 .opt + d_opt, // 66 .opt + d_objproc, // 67 .objproc + d_dsm, // 68 .dsm }; @@ -176,14 +177,14 @@ void SetLargestAlignment(int size) // int d_error(char *str) { - if (*tok.u32 == EOL) + if (*tok == EOL) return error("error directive encountered - aborting assembling"); else { - switch(*tok.u32) + switch(*tok) { case STRING: - return error(string[tok.u32[1]]); + return error(string[tok[1]]); break; default: return error("error directive encountered--aborting assembly"); @@ -197,14 +198,14 @@ int d_error(char *str) // int d_warn(char *str) { - if (*tok.u32 == EOL) + if (*tok == EOL) return warn("WARNING WARNING WARNING"); else { - switch(*tok.u32) + switch(*tok) { case STRING: - return warn(string[tok.u32[1]]); + return warn(string[tok[1]]); break; default: return warn("WARNING WARNING WARNING"); @@ -220,23 +221,26 @@ int d_org(void) { uint64_t address; - if (!rgpu && !rdsp && !m6502) - return error(".org permitted only in gpu/dsp and 6502 sections"); + if (!rgpu && !rdsp && !robjproc && !m6502 && !dsp56001) + return error(".org permitted only in GPU/DSP/OP, 56001 and 6502 sections"); - if (abs_expr(&address) == ERROR) + // M56K can leave the expression off the org for some reason :-/ + // (It's because the expression is non-standard, and so we have to look at + // it in isolation) + if (!dsp56001 && (abs_expr(&address) == ERROR)) { error("cannot determine org'd address"); return ERROR; } - if (rgpu | rdsp) + if (rgpu | rdsp | robjproc) { orgaddr = address; orgactive = 1; } - else + else if (m6502) { - // 6502. We also kludge `lsloc' so the listing generator doesn't try + // 6502. We also kludge 'lsloc' so the listing generator doesn't try // to spew out megabytes. if (address > 0xFFFF) return error(range_error); @@ -253,9 +257,97 @@ int d_org(void) chptr = scode->chptr + address; orgaddr = address; orgactive = 1; - at_eol(); } + else if (dsp56001) + { + // Only mark segments we actually wrote something + if (chptr != dsp_currentorg->start && dsp_written_data_in_current_org) + { + dsp_currentorg->end = chptr; + dsp_currentorg++; + } + + // Maybe we switched from a non-DSP section (TEXT, DATA, etc) and + // scode isn't initialised yet. Not that it's going to be a valid + // scenario, but if we try it anyhow it's going to lead to a crash. So + // let's fudge a value of 0 and get on with it. + orgaddr = (scode != NULL ? sloc : 0); + SaveSection(); + if (tok[1] != ':') + return error(syntax_error); + + int sectionToSwitch = 0; + + switch (tok[0]) + { + case KW_X: + dsp_currentorg->memtype = ORG_X; + sectionToSwitch = M56001X; + break; + + case KW_Y: + dsp_currentorg->memtype = ORG_Y; + sectionToSwitch = M56001Y; + break; + + case KW_P: + dsp_currentorg->memtype = ORG_P; + sectionToSwitch = M56001P; + break; + + case KW_L: + dsp_currentorg->memtype = ORG_L; + sectionToSwitch = M56001L; + break; + + default: + return error("unknown type in ORG"); + } + + if ((obj_format == LOD) || (obj_format == P56)) + SwitchSection(sectionToSwitch); + + tok += 2; + chcheck(3); // Ensure we got a valid address to write + dsp_currentorg->chunk = scode; // Mark down which chunk this org starts from (will be needed when outputting) + + if (*tok == EOL) + { + // Well, the user didn't specify an address at all so we'll have to + // use the last used address of that section (or 0 if there wasn't one) + address = orgaddr; + dsp_currentorg->start = chptr; + dsp_currentorg->orgadr = orgaddr; + } + else + { + if (abs_expr(&address) == ERROR) + { + error("cannot determine org'd address"); + return ERROR; + } + + dsp_currentorg->start = chptr; + dsp_currentorg->orgadr = (uint32_t)address; + sect[cursect].orgaddr = (uint32_t)address; + } + + if (address > DSP_MAX_RAM) + { + return error(range_error); + } + + dsp_written_data_in_current_org = 0; + + // Copied from 6502 above: kludge `lsloc' so the listing generator + // doesn't try to spew out megabytes. + lsloc = sloc = (int32_t)address; +// N.B.: It seems that by enabling this, even though it works elsewhere, will cause symbols to royally fuck up. Will have to do some digging to figure out why. +// orgactive = 1; + } + + ErrorIfNotAtEOL(); return 0; } @@ -276,47 +368,61 @@ int d_print(void) SYM * esym; // External symbol involved in expr. TOKEN r_expr[EXPRSIZE]; - while (*tok.u32 != EOL) + while (*tok != EOL) { - switch(*tok.u32) + switch (*tok) { case STRING: - sprintf(prntstr, "%s", string[tok.u32[1]]); + sprintf(prntstr, "%s", string[tok[1]]); printf("%s", prntstr); if (list_fd) unused = write(list_fd, prntstr, (LONG)strlen(prntstr)); - tok.u32 += 2; + tok += 2; break; case '/': formatting = 1; - if (tok.u32[1] != SYMBOL) + // "X" & "L" get tokenized now... :-/ Probably should look into preventing this kind of thing from happening (was added with DSP56K code) + if ((tok[1] != SYMBOL) && (tok[1] != KW_L) && (tok[1] != KW_X)) goto token_err; -// strcpy(prntstr, (char *)tok.u32[2]); - strcpy(prntstr, string[tok.u32[2]]); - - switch(prntstr[0]) + if (tok[1] == KW_L) { - case 'l': case 'L': wordlong = 1; break; - case 'w': case 'W': wordlong = 0; break; - case 'x': case 'X': outtype = 0; break; - case 'd': case 'D': outtype = 1; break; - case 'u': case 'U': outtype = 2; break; - default: - error("unknown print format flag"); - return ERROR; + wordlong = 1; + tok += 2; + } + else if (tok[1] == KW_X) + { + outtype = 0; + tok += 2; + } + else + { + strcpy(prntstr, string[tok[2]]); + + switch (prntstr[0]) + { + case 'l': case 'L': wordlong = 1; break; + case 'w': case 'W': wordlong = 0; break; + case 'x': case 'X': outtype = 0; break; + case 'd': case 'D': outtype = 1; break; + case 'u': case 'U': outtype = 2; break; + default: + error("unknown print format flag"); + return ERROR; + } + + tok += 3; } - tok.u32 += 3; break; case ',': - tok.u32++; + tok++; break; default: - if (expr((TOKENPTR)r_expr, &eval, &eattr, &esym) != OK) + if (expr(r_expr, &eval, &eattr, &esym) != OK) goto token_err; else { @@ -351,7 +457,7 @@ int d_print(void) return 0; token_err: - error("illegal print token"); + error("illegal print token [@ '%s']", prntstr); return ERROR; } @@ -370,13 +476,13 @@ int d_ccundef(void) return ERROR; } - if (*tok.u32 != SYMBOL) + if (*tok != SYMBOL) { error("syntax error; expected symbol"); return ERROR; } - ccname = lookup(string[tok.u32[1]], LABEL, 0); + ccname = lookup(string[tok[1]], LABEL, 0); // Make sure symbol is a valid ccdef if (!ccname || !(ccname->sattre & EQUATEDCC)) @@ -402,18 +508,18 @@ int d_equrundef(void) if (!rgpu && !rdsp) return error(".equrundef/.regundef must be defined in .gpu/.dsp section"); - while (*tok.u32 != EOL) + while (*tok != EOL) { // Skip preceeding or seperating commas (if any) - if (*tok.u32 == ',') - tok.u32++; + if (*tok == ',') + tok++; // Check we are dealing with a symbol - if (*tok.u32 != SYMBOL) + if (*tok != SYMBOL) return error("syntax error; expected symbol"); // Lookup and undef if equated register - regname = lookup(string[tok.u32[1]], LABEL, 0); + regname = lookup(string[tok[1]], LABEL, 0); if (regname && (regname->sattre & EQUATEDREG)) { @@ -424,7 +530,7 @@ int d_equrundef(void) } // Skip over symbol token and address - tok.u32 += 2; + tok += 2; } return 0; @@ -455,20 +561,20 @@ int d_incbin(void) // Check to see if we're in BSS, and, if so, throw an error if (scattr & SBSS) { - error("cannot include binary file \"%s\" in BSS section", string[tok.u32[1]]); + error("cannot include binary file \"%s\" in BSS section", string[tok[1]]); return ERROR; } - if (*tok.u32 != STRING) + if (*tok != STRING) { - error("syntax error; string missing"); + error("syntax error; file to include missing"); return ERROR; } // Attempt to open the include file in the current directory, then (if that // failed) try list of include files passed in the enviroment string or by // the "-d" option. - if ((fd = open(string[tok.u32[1]], _OPEN_INC)) < 0) + if ((fd = open(string[tok[1]], _OPEN_INC)) < 0) { for(i=0; nthpath("RMACPATH", i, buf1)!=0; i++) { @@ -478,13 +584,13 @@ int d_incbin(void) if (fd > 0 && buf1[fd - 1] != SLASHCHAR) strcat(buf1, SLASHSTRING); - strcat(buf1, string[tok.u32[1]]); + strcat(buf1, string[tok[1]]); if ((fd = open(buf1, _OPEN_INC)) >= 0) goto allright; } - return error("cannot open: \"%s\"", string[tok.u32[1]]); + return error("cannot open: \"%s\"", string[tok[1]]); } allright: @@ -493,14 +599,14 @@ allright: pos = lseek(fd, 0L, SEEK_SET); chcheck(size); - DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok.u32[1]], size); } + DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); } char * fileBuffer = (char *)malloc(size); bytesRead = read(fd, fileBuffer, size); if (bytesRead != size) { - error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok.u32[1]], size); + error("was only able to read %li bytes from binary file (%s, %li bytes)", bytesRead, string[tok[1]], size); return ERROR; } @@ -718,21 +824,21 @@ int symlist(int(* func)()) for(;;) { - if (*tok.u32 != SYMBOL) + if (*tok != SYMBOL) return error(em); - if ((*func)(string[tok.u32[1]]) != OK) + if ((*func)(string[tok[1]]) != OK) break; - tok.u32 += 2; + tok += 2; - if (*tok.u32 == EOL) + if (*tok == EOL) break; - if (*tok.u32 != ',') + if (*tok != ',') return error(em); - tok.u32++; + tok++; } return 0; @@ -750,11 +856,11 @@ int d_include(void) char buf[128]; char buf1[128]; - if (*tok.u32 == STRING) // Leave strings ALONE - fn = string[*++tok.u32]; - else if (*tok.u32 == SYMBOL) // Try to append ".s" to symbols + if (*tok == STRING) // Leave strings ALONE + fn = string[*++tok]; + else if (*tok == SYMBOL) // Try to append ".s" to symbols { - strcpy(buf, string[*++tok.u32]); + strcpy(buf, string[*++tok]); fext(buf, ".s", 0); fn = &buf[0]; } @@ -763,7 +869,7 @@ int d_include(void) // Make sure the user didn't try anything like: // .include equates.s - if (*++tok.u32 != EOL) + if (*++tok != EOL) return error("extra stuff after filename--enclose it in quotes"); // Attempt to open the include file in the current directory, then (if that @@ -802,7 +908,7 @@ int d_assert(void) WORD eattr; uint64_t eval; - for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok.u32) + for(; expr(exprbuf, &eval, &eattr, NULL)==OK; ++tok) { if (!(eattr & DEFINED)) return error("forward or undefined .assert"); @@ -810,11 +916,11 @@ int d_assert(void) if (!eval) return error("assert failure"); - if (*tok.u32 != ',') + if (*tok != ',') break; } - at_eol(); + ErrorIfNotAtEOL(); return 0; } @@ -860,7 +966,7 @@ int d_prgflags(void) { uint64_t eval; - if (*tok.u32 == EOL) + if (*tok == EOL) return error("PRGFLAGS requires value"); else if (abs_expr(&eval) == OK) { @@ -886,7 +992,7 @@ int d_abs(void) SaveSection(); - if (*tok.u32 == EOL) + if (*tok == EOL) eval = 0; else if (abs_expr(&eval) != OK) return 0; @@ -960,7 +1066,7 @@ int d_ds(WORD siz) uint64_t eval; - if (cursect != M6502) + if ((cursect & (M6502 | M56KPXYL)) == 0) { if ((siz != SIZB) && (sloc & 1)) // Automatic .even auto_even(); @@ -970,11 +1076,11 @@ int d_ds(WORD siz) return 0; // Check to see if the value being passed in is negative (who the hell does - // that?--nobody does; it's the code gremlins, or rum, that does it) - // N.B.: Since 'eval' is of type uint32_t, if it goes negative, it will have - // its high bit set. - if (eval & 0x80000000) - return error("negative sizes not allowed"); + // that?--nobody does; it's the code gremlins, or rum, what does it) + // N.B.: Since 'eval' is of type uint64_t, if it goes negative, it will + // have its high bit set. + if (eval & 0x8000000000000000) + return error("negative sizes not allowed in DS"); // In non-TDB section (BSS, ABS and M6502) just advance the location // counter appropriately. In TDB sections, deposit (possibly large) chunks @@ -990,18 +1096,86 @@ int d_ds(WORD siz) just_bss = 1; // No data deposited (8-bit CPU mode) } + else if (cursect & M56KPXYL) + { + // Change segment instead of marking blanks. + // Only mark segments we actually wrote something + if (chptr != dsp_currentorg->start && dsp_written_data_in_current_org) + { + dsp_currentorg->end = chptr; + dsp_currentorg++; + dsp_currentorg->memtype = dsp_currentorg[-1].memtype; + } + + listvalue((uint32_t)eval); + sloc += (uint32_t)eval; + + // And now let's create a new segment + dsp_currentorg->start = chptr; + dsp_currentorg->chunk = scode; // Mark down which chunk this org starts from (will be needed when outputting) + sect[cursect].orgaddr = sloc; + dsp_currentorg->orgadr = sloc; + dsp_written_data_in_current_org = 0; + + just_bss = 1; // No data deposited + } else { - dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), (TOKENPTR){NULL}); + dep_block(eval, siz, 0, (DEFINED | ABS), NULL); } - at_eol(); - return 0; + ErrorIfNotAtEOL(); + return OK; +} + + +// +// dsm[.siz] expression +// Define modulo storage +// Quoting the Motorola assembler manual: +// "The DSM directive reserves a block of memory the length of which in words is equal to +// the value of .If the runtime location counter is not zero, this directive first +// advances the runtime location counter to a base address that is a multiple of 2k, where +// 2k >= ." +// The kicker of course is written a few sentences after: +// "