extern void initStack(int base_address, int size);
extern regs *allocProcessorRegister(int rIdx, char * name, short po_type, int alias);
-extern regs *allocInternalRegister(int rIdx, char * name, short po_type, int alias);
+extern regs *allocInternalRegister(int rIdx, char * name, PIC_OPTYPE po_type, int alias);
extern void init_pic(char *);
void pCodeInitRegisters(void)
for(i=0; i<MAX_PIC14MNEMONICS; i++)
if(pic14Mnemonics[i])
- hTabAddItem(&pic14MnemonicsHash, mnem2key(pic14Mnemonics[i]->mnemonic), pic14Mnemonics[i]);
+ hTabAddItem(&pic14MnemonicsHash, mnem2key((unsigned char *)pic14Mnemonics[i]->mnemonic), pic14Mnemonics[i]);
pci = hTabFirstItem(pic14MnemonicsHash, &key);
while(pci) {
{
pCodeInstruction *pci;
- int key = mnem2key(mnem);
+ int key = mnem2key((unsigned char *)mnem);
if(!mnemonics_initialized)
pic14initMnemonics();
i = 0;
do {
hTabAddItem(&pic14pCodePeepCommandsHash,
- mnem2key(peepCommands[i].cmd), &peepCommands[i]);
+ mnem2key((unsigned char *)peepCommands[i].cmd), &peepCommands[i]);
i++;
} while (peepCommands[i].cmd);
{
peepCommand *pcmd;
- int key = mnem2key(cmd);
+ int key = mnem2key((unsigned char *)cmd);
pcmd = hTabFirstItemWK(pic14pCodePeepCommandsHash, key);
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
+#if 0
static void insertBankSwitch(pCodeInstruction *pci, int Set_Clear, int RP_BankBit)
{
pCode *new_pc;
insertPCodeInstruction(pci, PCI(new_pc));
}
-
+#endif
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
static void insertBankSel(pCodeInstruction *pci, const char *name)
{
pCode *new_pc;
- pCodeOp *pcop = popCopyReg(PCOR(pci->pcop));
+ pCodeOp *pcop;
+
+ // This is a NOP for single-banked devices.
+ if (pic14_getMaxRam() < 0x80) return;
+
+ pcop = popCopyReg(PCOR(pci->pcop));
pcop->type = PO_GPR_REGISTER; // Sometimes the type is set to legacy 8051 - so override it
if (pcop->name == 0)
pcop->name = strdup(name);
static int LastRegIdx = -1; /* If the previous register is the same one again then no need to change bank. */
static int BankSelect(pCodeInstruction *pci, int cur_bank, regs *reg)
{
+#if 1
+ /* Always insert BANKSELs rather than try to be clever:
+ * Too many bugs in optimized banksels... */
+ insertBankSel(pci, reg->name); // Let linker choose the bank selection
+ return 'L';
+#else
int bank;
int a = reg->alias>>7;
if ((a&3) == 3) {
LastRegIdx = reg->rIdx;
#endif
+ /* Optimized code---unfortunately this turns out to be buggy
+ * (at least on devices with more than two banks). */
if (reg->isFixed) {
bank = REG_BANK(reg);
} else if (reg->isExtern) {
} else {
bank = 'L'; // Unfixed local registers are allocated by the linker therefore its bank is unknown
}
- if ((cur_bank == 'L')&&(bank == 'L')) { // If current bank and new bank are both allocated locally by the linker, then assume it is in same bank.
- return 'L'; // Local registers are presumed to be in same linker assigned bank
- } else if ((bank == 'L')&&(cur_bank != 'L')) { // Reg is now local and linker to assign bank
- insertBankSel(pci, reg->name); // Let linker choose the bank selection
- } else if (bank == 'E') { // Reg is now extern and linker to assign bank
+ if (bank == 'E' || bank == 'L') { // Reg is now extern and linker to assign bank
insertBankSel(pci, reg->name); // Let linker choose the bank selection
} else if ((cur_bank == -1)||(cur_bank == 'L')||(cur_bank == 'E')) { // Current bank unknown and new register bank is known then can set bank bits
insertBankSwitch(pci, bank&1, PIC_RP0_BIT);
- if (getMaxRam()&0x100)
+ if (pic14_getMaxRam()&0x100)
insertBankSwitch(pci, bank&2, PIC_RP1_BIT);
} else { // Current bank and new register banks known - can set bank bits
switch((cur_bank^bank) & 3) {
break;
case 3:
insertBankSwitch(pci, bank&1, PIC_RP0_BIT);
- if (getMaxRam()&0x100)
+ if (pic14_getMaxRam()&0x100)
insertBankSwitch(pci, bank&2, PIC_RP1_BIT);
break;
}
}
return bank;
+#endif
}
/*-----------------------------------------------------------------*/
}
reg = getRegFromInstruction(pc);
+ if (!reg && isPCI(pc) &&
+ ((PCI(pc)->inCond | PCI(pc)->outCond) & PCC_REGISTER))
+ {
+ assert(!"Could not get register from instruction.");
+ }
if (reg) {
if (IsBankChange(pc,reg,&cur_bank))
return cur_bank;
void InitReuseReg(void)
{
/* Find end of statically allocated variables for start idx */
- unsigned maxIdx = 0x20; /* Start from begining of GPR. Note may not be 0x20 on some PICs */
+ /* Start from begining of GPR. Note may not be 0x20 on some PICs */
+ /* XXX: Avoid clashes with fixed registers, start late. */
+ unsigned maxIdx = 0x1000;
regs *r;
for (r = setFirstItem(dynDirectRegs); r; r = setNextItem(dynDirectRegs)) {
if (r->type != REG_SFR) {