/** * Record a trace, this is a blocking function. * Use the ext interupt 0 and 1. * Use the timer 1. */ uchar* recordTrace(int *size) { uchar charIndex = 0; uchar charBuffer; uint state = STATE_BEGINING; uchar i = 0; uchar t0 = (uchar) 0x00; uint tmpEtu = NO_ETU_CHANGE; uchar protocol; uchar convention; convention = CONVENTION_DIRECTE; protocol = PROTOCOL_T0; initialiseInterupt(); if(!waitForIO()) { reInit(); return NULL; } /* Configure the interupt on IO to answer on each falling edge*/ ConfigINT2(EXT_INT_ENABLE | FALLING_EDGE_INT | EXT_INT_PRI_1); /* Configure the warm reset to trigger on falling edge*/ ConfigINT1(EXT_INT_ENABLE | FALLING_EDGE_INT | EXT_INT_PRI_1); while( (STATE_TERMINATED != state)) { state = getState(); if( (isData() > 0) && dataIndex < DATA_SIZE) { charBuffer = 0x00; for(charIndex = 0 ; charIndex < 8 ; charIndex++ ) { if(CONVENTION_INVERSE == convention) { charBuffer ^= (getAcq() << (7-charIndex)); } else if(CONVENTION_DIRECTE == convention) { charBuffer ^= (getAcq() << charIndex); } } if(CONVENTION_INVERSE == convention) { charBuffer = 0xff ^ charBuffer; } dataArray[dataIndex] = charBuffer; dataIndex++; clearFlag(); if(STATE_TS == state) { if((uchar) 0x3b == charBuffer) { convention = CONVENTION_DIRECTE; } /* 0x03 is the way the byte 3f will be read with the tool * For information, by default the Direct convention is used * so we don't see directly the byte 3F but the byte 3f coded * in direct convention = 0x03 */ if((uchar) 0x03 == charBuffer) { convention = CONVENTION_INVERSE; dataArray[dataIndex-1] = 0x3f; } setState(STATE_T0); } else if(STATE_T0 == state) { t0 = charBuffer; setState(STATE_ATR); } /*Then we treats TAx, TBx, TCx, TDx,... and finaly hist bytes */ else if(0 < (t0 & 0x10) ) { t0 = t0 ^ 0x10; /* It's a TAx */ if(0 == i) /* It's Ta1*/ { /*Configuring the new ATR value*/ tmpEtu = computeEtu(charBuffer); } } else if(0 < (t0 & 0x20) ) { /*It's a TBx*/ t0 = t0 ^ 0x20; } else if(0 < (t0 & 0x40) ) { /*It's a TCx*/ t0 = t0 ^ 0x40; } else if(0 < (t0 & 0x80) ) { /*It's a TDx*/ t0 = t0 ^ 0x80; /* t0 is only compose of the historical bytes We verify if the TD bytes implies other bytes*/ t0 ^= (charBuffer & 0xf0); i++; /* We also verify if it's a T=1 protocol */ if( ((uchar) 0x01) == ((uchar) charBuffer ^ 0x01) ) { /*It's a t=1 card set the value to T=1*/ protocol = PROTOCOL_T1; } } else if(0 < (t0 & 0x0F)) { /* This is historical bytes */ t0--; if(t0 == 0) { if(PROTOCOL_T1 == protocol) { setState(STATE_ATR_CRC); } else { setState(STATE_PROCESSING); fixEtu(tmpEtu); } } } else if(STATE_ATR_CRC == state) { setState(STATE_PROCESSING); fixEtu(tmpEtu); } }/*end of if(isData() > 0 )*/ else if(STATE_RESET == getState()) { charIndex = 0; convention = CONVENTION_DIRECTE; warmAtrOffset = dataIndex; t0 = 0x00; setState(STATE_BEGINING); } if( !isData() && !PIN_VCC ) { setState(STATE_TERMINATED); } if(dataIndex >= DATA_SIZE ) { #ifdef DEBUG sendDataBuffer("Array overflow\n"); #endif setState(STATE_TERMINATED); } }//End of while /* Stop the interupt on IO */ ConfigINT0(EXT_INT_DISABLE); /* Stop the warm reset */ ConfigINT1(EXT_INT_DISABLE); #ifdef DEBUG sendDataBuffer("Trace recorded : \n"); #endif /* End of debug information */ *size = dataIndex; reInit(); return dataArray; }
void sysBpHandler(){ saveStateIn(sysbp_old, ¤tProcess->p_s); unsigned int cause = CAUSE_EXCCODE_GET(sysbp_old->CP15_Cause); unsigned int a0 = (*sysbp_old).a1; unsigned int a1 = (*sysbp_old).a2; unsigned int a2 = (*sysbp_old).a3; unsigned int a3 = (*sysbp_old).a4; /* Se l'eccezione è di tipo System call */ if(cause==EXC_SYSCALL){ /* Se il processo è in kernel mode gestisce adeguatamente */ if( (currentProcess->p_s.cpsr & STATUS_SYS_MODE) == STATUS_SYS_MODE){ /* Se è fra SYS1 e SYS8 richiama le funzioni adeguate */ switch(a0){ case CREATEPROCESS: createProcess((state_t *) a1); break; case TERMINATEPROCESS: terminateProcess(currentProcess); break; case VERHOGEN: verhogen((int *) a1); break; case PASSEREN: passeren((int *) a1); break; case SPECTRAPVEC: specExStVec((int) a1, (state_t *) a2, (state_t *) a3); break; case GETCPUTIME: getCPUTime(); break; case WAITCLOCK: waitForClock(); break; case WAITIO: waitForIO((int) a1, (int) a2, (int) a3); break; /* Altrimenti la gestione viene passata in alto */ default: useExStVec(SPECSYSBP); break; } /* Richiamo lo scheduler */ scheduler(); /* Se invece è in user mode */ } else if((currentProcess->p_s.cpsr & STATUS_USER_MODE) == STATUS_USER_MODE){ /* Se è una system call */ if(a0 >= CREATEPROCESS && a0 <= WAITIO){ /* Gestisco come fosse una program trap */ saveStateIn(sysbp_old, pgmtrap_old); /* Setto il registro cause a Reserved Instruction */ pgmtrap_old->CP15_Cause = CAUSE_EXCCODE_SET(pgmtrap_old->CP15_Cause, EXC_RESERVEDINSTR); /* Richiamo l'handler per le pgmtrap */ pgmHandler(); } else { useExStVec(SPECSYSBP); } } /* Altrimenti se l'eccezione è di tipo BreakPoint */ } else if(cause == EXC_BREAKPOINT){ useExStVec(SPECSYSBP); } PANIC(); }