OpenCores
URL https://opencores.org/ocsvn/zipcpu/zipcpu/trunk

Subversion Repositories zipcpu

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /zipcpu
    from Rev 45 to Rev 46
    Reverse comparison

Rev 45 → Rev 46

/trunk/sw/zasm/test.S
84,6 → 84,8
#define TRAP_TEST
#define MPY_TEST
#define PUSH_TEST
#define PIPELINE_STACK_TEST
#define MEM_PIPELINE_TEST
test:
#ifdef DO_TEST_ASSEMBLER
; We start out by testing our assembler. We give it some instructions, which
520,7 → 522,6
trap.ne r11
#endif
 
#define PIPELINE_STACK_TEST
#ifdef PIPELINE_STACK_TEST
ldi $0x0f000,r11 // Mark our test
LDI 1,R0
546,6 → 547,11
CMP 7,R6
trap.ne R11
#endif
 
#ifdef MEM_PIPELINE_TEST
JSR(mem_pipeline_test,R0)
#endif // MEM_PIPELINE_TEST
 
// Return success / Test the trap interrupt
clr r11
trap r11
622,6 → 628,45
LOD 1(SP),PC
#endif // PIPELINE_STACK_TEST
 
#ifdef MEM_PIPELINE_TEST
mem_pipeline_test:
SUB 4,SP
STO R0,1(SP)
STO R1,2(SP)
LDI 0x10000,R11
;
; Test #1 ... Let's start by writing a value to memory
LDI -1,R0
CLR R1
STO R0,3(SP)
LOD 3(SP),R1
CMP R1,R0
MOV.NZ R11,CC
 
; Test #2, reading and then writing a value from memory
NOP
NOP
CLR R0
CLR R1
LOD 3(SP),R0 ; This should load back up our -1 value
STO R0,4(SP)
; Insist that the pipeline clear
LOD 3(SP),R0
; Now let's try loading into R1
NOP
NOP
NOP
NOP
LOD 4(SP),R1
CMP R1,R0
MOV.NZ R11,CC
LOD 1(SP),R0
LOD 2(SP),R1
ADD 4,SP
RETN
#endif
 
fill 512,0
stack: // Must point to a valid word initially
word 0
/trunk/sw/zasm/zasm.y
505,8 → 505,6
if (NULL != getenv("ZIPINC"))
inclist = getenv("ZIPINC");
 
printf("Original INCLIST = %s\n", inclist.c_str());
 
master_input_filename = NULL;
 
// Find what directory zasm is in, so that we can find zpp when
538,10 → 536,10
} else if (argn+skp+1<argc) {
if (inclist.size() != 0) {
inclist += std::string(":");
inclist += &argv[argn+skp+1][2];
inclist += argv[argn+skp+1];
} else
inclist = &argv[argn+skp+1][2];
argn++;
inclist = argv[argn+skp+1];
skp++;
}
} else if (argv[argn+skp][1] == 'd')
yydebug = 1;
551,7 → 549,10
}
 
skp++;
} argv[argn] = argv[argn+skp];
argn--;
} else {
argv[argn] = argv[argn+skp];
}
} argc -= skp;
 
if (zout_fname) {
562,7 → 563,6
}
}
}
printf("New INCLIST = %s\n", inclist.c_str());
 
if (preprocess_only) {
objcode.open("/dev/null");
/trunk/sw/zasm/asmdata.cpp
425,7 → 425,10
BLD_BRANCH(op_brv,ZIPC_V)
break;
case OP_CLR:
in = zp.op_clr(m_opb);
if((m_cond == zp.ZIPC_ALWAYS))
in = zp.op_clr(m_opb);
else
in = zp.op_clrf(m_cond, m_opb);
break;
case OP_TRAP:
if((m_opb == zp.ZIP_Rnone)&&(m_cond == zp.ZIPC_ALWAYS))
439,6 → 442,7
in = zp.op_trap(m_cond, 0);
}
break;
case OP_RETN: in = zp.op_retn(m_cond); break;
case OP_HALT: in = zp.op_halt(m_cond); break;
case OP_RTU: in = zp.op_rtu(m_cond); break;
case OP_BUSY: in = zp.op_busy(m_cond); break;
607,7 → 611,8
} SYMTABLE_ENTRY(const char *str, AST *v) : m_recursion_check(0), m_name(str), m_value(v) {
trim(m_name);
} ~SYMTABLE_ENTRY(void) {
delete m_value;
if (m_value)
delete m_value;
}
 
SYMTABLE_ENTRY &operator=(AST *new_value) {
664,7 → 669,7
TBLT::iterator i = m_tbl.begin();
while(i != m_tbl.end()) {
delete (*i);
m_tbl.erase(i);
i = m_tbl.erase(i);
}
}
 
717,7 → 722,7
else
return global_context->isdefined(key);
} int stb_value(const char *key) {
if (file_context->isdefined(key))
if ((file_context)&&(file_context->isdefined(key)))
return file_context->value(key);
else
return global_context->value(key);
/trunk/sw/zasm/asmdata.h
68,7 → 68,7
// Single operand instructions that have no explicit conditions
OP_CLR, OP_TRAP, OP_NEG,
// BAREOPs that can have conditions
OP_HALT, OP_RTU, OP_BUSY,
OP_HALT, OP_RTU, OP_BUSY, OP_RETN,
// BAREOPs without conditions
OP_BREAK, OP_NOOP,
// Error condition--undefined operand
95,6 → 95,7
// 'N' a number
// 'I' an identifier
// 'A' ?? an address ?? would we need this?
virtual ~AST(void) {}
char m_node_type;
virtual bool isdefined(void) = 0;
virtual int eval(void) = 0;
193,6 → 194,12
AST_BRANCH(int op, AST *l, AST *r)
: m_op(op), m_left(l), m_right(r) { m_node_type = 'B';
}
~AST_BRANCH(void) {
if (m_left)
delete m_left;
if (m_right)
delete m_right;
}
 
bool isdefined(void) {
return ((m_left)&&(m_right)
199,7 → 206,7
&&(m_left->isdefined())
&&(m_right->isdefined()));
}
~AST_BRANCH(void) { delete m_left; delete m_right; }
 
int eval(void);
void reduce(void);
void dump(FILE *fp) {
/trunk/sw/zasm/zpp.l
504,7 → 504,7
void addmacro(const char *name, const char *str) {
TBLT::iterator i = lookup(name);
if (i == m_tbl.end()) {
fprintf(stderr, "INTERNAL ERR, %s NOT DEFINED!\n", name);
fprintf(stderr, "ADDMACRO::INTERNAL ERR, \'%s\' NOT DEFINED!\n", name);
} *(*i) += str;
}
523,7 → 523,7
const char *getdefn(const char *name) {
TBLT::iterator i = lookup(name);
if (i == m_tbl.end()) {
fprintf(stderr, "INTERNAL ERR, %s NOT DEFINED!\n", name);
fprintf(stderr, "GETDEFN::INTERNAL ERR, \'%s\' NOT DEFINED!\n", name);
return NULL;
} (*i)->getdefn().c_str();
}
541,6 → 541,21
SYMBOL_TABLE syms;
std::string last_define;
 
char *stb_trim(const char *str) {
// fprintf(stderr, "Checking whether %s needs to be expanded\n",str);
char *dup = strdup(str), *chr;
chr = strchr(dup, '(');
if (chr != NULL)
*chr = '\0';
// fprintf(stderr, "\tLooking it up by the name \'%s\'\n", dup);
 
// Now, let's trim our string
char *end = dup+strlen(dup)-1;
while((*dup)&&(end>dup)&&(isspace(*end)))
*end-- = '\0';
return dup;
}
 
void stb_define(const char *str) {
/*
if (last_define.size()>0) {
547,14 → 562,15
fprintf(stderr, "LAST-DEFINE(%s): %s\n", last_define.c_str(),
stb_getdefn(last_define.c_str()));
} */
 
if (syms.defined(str)) {
char *alt = stb_trim(str);
if (syms.defined(alt)) {
fprintf(stderr, "WARNING! Symbol \'%s\' is already defined!\n", str);
syms.undefine(str);
}
 
syms.define(str);
last_define = str;
syms.define(alt);
last_define = alt;
free(alt);
}
 
void stb_args(const char *args) {
570,23 → 586,18
}
 
bool stb_isdefined(const char *str) {
const char *ptr;
if ((ptr = strchr(str, '('))!=NULL) {
// fprintf(stderr, "Checking whether %s needs to be expanded\n",str);
char *dup = strdup(str), *chr;
chr = strchr(dup, '(');
*chr = '\0';
// fprintf(stderr, "\tLooking it up by the name \'%s\'\n", dup);
bool r = (syms.defined(dup));
free(dup);
return r;
} else {
return syms.defined(str);
}
char *dup = stb_trim(str);
bool r = (syms.defined(dup));
free(dup);
return r;
}
 
const char *stb_getdefn(const char *str) {
return syms.getdefn(str);
char *dup = stb_trim(str);
const char *r;
r = syms.getdefn(dup);
free(dup);
return r;
}
 
bool stb_current(const char *str) {
594,18 → 605,11
}
 
bool stb_hasargs(const char *str) {
const char *ptr;
if ((ptr = strchr(str, '('))!=NULL) {
char *dup = strdup(str), *chr;
chr = strchr(dup, '(');
*chr = '\0';
bool r = (syms.hasargs(dup));
// fprintf(stderr, "\t%s has %sarguments\n", dup, (r)?"":"no ");
free(dup);
return r;
} else {
return syms.hasargs(str);
}
char *dup = stb_trim(str);
bool r = (syms.hasargs(dup));
// fprintf(stderr, "\t%s has %sarguments\n", dup, (r)?"":"no ");
free(dup);
return r;
}
 
std::string stb_expand(const char *macro) {
/trunk/sw/zasm/zasm.l
71,11 → 71,11
"#line"[ \t]+[0-9]+[ \t]*$ { yylineno = atoi(&yytext[6]); return '\n';}
^"#line".*$ { printf("WARNING: Unmatched #line: %s\n", yytext); return '\n'; }
"#line".*$ { printf("WARNING: Unmatched #line, not at beginnning: %s\n", yytext); return '\n'; }
[uU][rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(26+yytext[3]-'0');return REG; }
[sS][rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[3]-'0');return REG; }
(?i:ur)1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(26+yytext[3]-'0');return REG; }
(?i:sr)1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[3]-'0');return REG; }
[rR]1[0-5] { yylval.u_reg=(ZPARSER::ZIPREG)(10+yytext[2]-'0');return REG; }
[uU][rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)(16+yytext[2]-'0');return REG; }
[sS][rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)( yytext[2]-'0');return REG; }
(?i:ur)[0-9] { yylval.u_reg=(ZPARSER::ZIPREG)(16+yytext[2]-'0');return REG; }
(?i:sr)[0-9] { yylval.u_reg=(ZPARSER::ZIPREG)( yytext[2]-'0');return REG; }
[rR][0-9] { yylval.u_reg=(ZPARSER::ZIPREG)( yytext[1]-'0');return REG; }
(?i:upc) { yylval.u_reg = ZPARSER::ZIP_uPC; return REG; }
(?i:spc) { yylval.u_reg = ZPARSER::ZIP_PC; return REG; }
86,26 → 86,27
(?i:usp) { yylval.u_reg = ZPARSER::ZIP_uSP; return REG; }
(?i:ssp) { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
(?i:sp) { yylval.u_reg = ZPARSER::ZIP_SP; return REG; }
[bB][rR][aA] { yylval.u_op = OP_BRA; return BRANCHOP; }
[bB][rR][zZ] { yylval.u_op = OP_BZ; return BRANCHOP; }
[bB][zZ] { yylval.u_op = OP_BZ; return BRANCHOP; }
[bB][nN][zZ] { yylval.u_op = OP_BNZ; return BRANCHOP; }
[bB][nN][eE] { yylval.u_op = OP_BNZ; return BRANCHOP; }
[bB][gG][eE] { yylval.u_op = OP_BGE; return BRANCHOP; }
[bB][gG][tT] { yylval.u_op = OP_BGT; return BRANCHOP; }
[bB][gG] { yylval.u_op = OP_BGT; return BRANCHOP; }
[bB][lL][tT] { yylval.u_op = OP_BLT; return BRANCHOP; }
[bB][nN] { yylval.u_op = OP_BLT; return BRANCHOP; }
[bB][rR][cC] { yylval.u_op = OP_BRC; return BRANCHOP; }
[bB][cC] { yylval.u_op = OP_BRC; return BRANCHOP; }
[bB][rR][vV] { yylval.u_op = OP_BRV; return BRANCHOP; }
[bB][vV] { yylval.u_op = OP_BRV; return BRANCHOP; }
(?i:gbl) { yylval.u_reg = ZPARSER::ZIP_R12; return REG; }
(?i:bra) { yylval.u_op = OP_BRA; return BRANCHOP; }
(?i:brz) { yylval.u_op = OP_BZ; return BRANCHOP; }
(?i:bz) { yylval.u_op = OP_BZ; return BRANCHOP; }
(?i:bnz) { yylval.u_op = OP_BNZ; return BRANCHOP; }
(?i:bne) { yylval.u_op = OP_BNZ; return BRANCHOP; }
(?i:bge) { yylval.u_op = OP_BGE; return BRANCHOP; }
(?i:bgt) { yylval.u_op = OP_BGT; return BRANCHOP; }
(?i:bg) { yylval.u_op = OP_BGT; return BRANCHOP; }
(?i:blt) { yylval.u_op = OP_BLT; return BRANCHOP; }
(?i:bn) { yylval.u_op = OP_BLT; return BRANCHOP; }
(?i:brc) { yylval.u_op = OP_BRC; return BRANCHOP; }
(?i:bc) { yylval.u_op = OP_BRC; return BRANCHOP; }
(?i:brv) { yylval.u_op = OP_BRV; return BRANCHOP; }
(?i:bv) { yylval.u_op = OP_BRV; return BRANCHOP; }
(?i:clr) { yylval.u_op = OP_CLR; return SINGLOP; }
(?i:clrf) {yylval.u_op = OP_CLRF;return SINGLOP; }
(?i:clrf) { yylval.u_op = OP_CLRF;return SINGLOP; }
(?i:int) { yylval.u_op = OP_TRAP;return SINGLOP; }
(?i:trap) {yylval.u_op = OP_TRAP;return SINGLOP; }
(?i:trap) { yylval.u_op = OP_TRAP;return SINGLOP; }
(?i:jmp) { yylval.u_op = OP_JMP; return SINGLOP; }
[lL][jJ][mM][pP] {yylval.u_op = OP_LJMP;return SINGLOP; }
(?i:ljmp) { yylval.u_op = OP_LJMP;return SINGLOP; }
(?i:neg) { yylval.u_op = OP_NEG; return SINGLOP; }
(?i:not) { yylval.u_op = OP_NOT; return SINGLOP; }
(?i:cmp) { yylval.u_op = OP_CMP; return DUALOP; }
112,8 → 113,10
(?i:tst) { yylval.u_op = OP_TST; return DUALOP; }
(?i:mov) { yylval.u_op = OP_MOV; return DUALOP; }
(?i:ldi) { yylval.u_op = OP_LDI; return LDIOP; }
[lL][dD][iI][hH][iI] { yylval.u_op =OP_LDIHI; return LDHLOP; }
[lL][dD][iI][lL][oO] { yylval.u_op =OP_LDILO; return LDHLOP; }
(?i:ldihi) { yylval.u_op =OP_LDIHI; return LDHLOP; }
(?i:lhi) { yylval.u_op =OP_LDIHI; return LDHLOP; }
(?i:ldilo) { yylval.u_op =OP_LDILO; return LDHLOP; }
(?i:llo) { yylval.u_op =OP_LDILO; return LDHLOP; }
(?i:mpyu) { yylval.u_op = OP_MPYU; return DUALOP; }
(?i:mpys) { yylval.u_op = OP_MPYS; return DUALOP; }
(?i:rol) { yylval.u_op = OP_ROL; return DUALOP; }
130,6 → 133,8
(?i:halt) { yylval.u_op = OP_HALT; return BAREOP; }
(?i:wait) { yylval.u_op = OP_HALT; return BAREOP; }
(?i:rtu) { yylval.u_op = OP_RTU; return BAREOP; }
(?i:retn) { yylval.u_op = OP_RETN; return BAREOP; }
(?i:ret) { yylval.u_op = OP_RETN; return BAREOP; }
(?i:nop) { yylval.u_op = OP_NOOP; return BAREOP; }
(?i:noop) { yylval.u_op = OP_NOOP; return BAREOP; }
(?i:break) { yylval.u_op = OP_BREAK; return BAREOP; }
154,9 → 159,9
"$"?[-]?0[0-7]+ { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"$"?[-]?[1-9][0-9]* { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL,10);return INT;}
"$"?[-]?[1-9A-Fa-f][0-9A-Fa-f]*h {yylval.u_ival=strtoul(yytext+(((*yytext)=='$')?1:0),NULL,16); return INT;}
"$"?[-]?[0-7]+o { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"\'"[^\\\']"\'" { printf("Match char, %s\n", yytext); yylval.u_ival = yytext[1]&0x0ff; return INT; }
"\'\\"[abnr\\]"\'" {
"$"?[-]?[0-7]+o { yylval.u_ival = strtoul(yytext+(((*yytext)=='$')?1:0),NULL, 8);return INT;}
"\'"[^\\\']"\'" { yylval.u_ival = yytext[1]&0x0ff; return INT; }
"\'\\"[abnr\\\'\"]"\'" {
yylval.u_ival = yytext[2];
if (yytext[2] == 'a') yylval.u_ival = '\a';
else if (yytext[2] == 'b') yylval.u_ival = '\b';
167,6 → 172,8
else if (yytext[2] == 'v') yylval.u_ival = '\v';
else if (yytext[2] == '0') yylval.u_ival = '\0';
else if (yytext[2] == '\\') yylval.u_ival = '\\';
else if (yytext[2] == '\'') yylval.u_ival = '\'';
else if (yytext[2] == '\"') yylval.u_ival = '\"';
return INT; }
"\'"[^\\\'][^\\\']"\'" { yylval.u_ival = ((yytext[1]&0x0ff)<<8)+(yytext[2]&0x0ff); return INT; }
"\'"[^\\\'][^\\\'][^\\\']"\'" { yylval.u_ival = ((yytext[1]&0x0ff)<<16)
/trunk/sw/zasm/sys.i
49,6 → 49,8
sys.bus.cache equ 0x002
sys.bus.ctrpic equ 0x003
sys.bus.tma equ 0x004
sys.bus.tmb equ 0x005
sys.bus.tmc equ 0x006
 
 
 
/trunk/sw/zasm/zopcodes.cpp
139,6 → 139,7
"ROL", 0xf0100000, 0x50000000, REGFIELD(24), REGFIELD(24), OPUNUSED, IMMFIELD(5,0), BITFIELD(3,21),
"ROL", 0xf0100000, 0x50100000, REGFIELD(24), REGFIELD(24), REGFIELD(16), IMMFIELD(5,0), BITFIELD(3,21),
//
"RETN", 0xff1fffff, 0x6f1d0001, OPUNUSED, OPUNUSED, OPUNUSED, OPUNUSED, BITFIELD(3,21),
"LOD", 0xf0100000, 0x60000000, REGFIELD(24), OPUNUSED, OPUNUSED, IMMFIELD(19,0), BITFIELD(3,21),
"LOD", 0xf0100000, 0x60100000, REGFIELD(24), OPUNUSED, REGFIELD(16), IMMFIELD(16,0), BITFIELD(3,21),
//
/trunk/sw/zasm/obj-pc/depends.txt
4,3 → 4,5
obj-pc/zdump.o: zdump.cpp zopcodes.h
obj-pc/zopcodes.o: zopcodes.cpp twoc.h zopcodes.h
obj-pc/zparser.o: zparser.cpp zparser.h zopcodes.h
obj-pc/zasm.tab.o: obj-pc/zasm.tab.c asmdata.h zopcodes.h zparser.h
obj-pc/zpp.o: obj-pc/zpp.cpp
/trunk/sw/zasm/zparser.h
224,6 → 224,8
{ return op_xor(cnd, 0, a, a); }
ZIPI op_clrf(ZIPREG a) const
{ return op_xor(ZIPC_ALWAYS, 0, a, a); }
ZIPI op_retn(ZIPCOND c) const
{ return op_lod(c, 1, ZIP_SP, ZIP_PC); }
ZIPI op_halt(ZIPCOND c) const {
return op_or(c, 0x10, ZIP_CC); }
ZIPI op_wait(ZIPCOND c) const {
/trunk/sw/zasm/Makefile
71,7 → 71,7
$(LEX) -o $@ zasm.l
$(OBJDIR)/zasm.lex.o: $(OBJDIR)/zasm.lex.cpp
$(CXX) -c -I. -I$(OBJDIR)/ $(CCFLAGS) $(OBJDIR)/zasm.lex.cpp -o $@
$(OBJDIR)/zasm.tab.o: $(OBJDIR)/zasm.tab.c
$(OBJDIR)/zasm.tab.o: $(OBJDIR)/zasm.tab.c $(OBJDIR)/zasm.tab.h
$(CXX) -c -I. -I$(OBJDIR)/ $(CCFLAGS) $(OBJDIR)/zasm.tab.c -o $@
$(OBJDIR)/asmdata.o: asmdata.cpp zopcodes.h zparser.h
$(CXX) -c -I. $(CCFLAGS) asmdata.cpp -o $@
103,6 → 103,8
define build-depends
@echo "Building dependency file(s)"
@$(CXX) -I $(OBJDIR)/ $(CCFLAGS) -MM *.cpp > xd.txt
@$(CXX) -I $(OBJDIR)/ -I. $(CCFLAGS) -MM $(OBJDIR)/zasm.tab.c >> xd.txt
@$(CXX) -I $(OBJDIR)/ -I. $(CCFLAGS) -MM $(OBJDIR)/zpp.cpp >> xd.txt
@sed -e 's/^.*.o: /$(OBJDIR)\/&/' < xd.txt > $(OBJDIR)/depends.txt
@rm xd.txt
endef

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.