static void do_unaligned_access(target_ulong addr, int is_write, int is_user,
                                uintptr_t retaddr)
{
    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
            !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
        do_restore_state(retaddr);
        HELPER(exception_cause_vaddr)(
                env->pc, LOAD_STORE_ALIGNMENT_CAUSE, addr);
    }
}
Beispiel #2
0
static void do_unaligned_access(CPUXtensaState *env,
        target_ulong addr, int is_write, int is_user, uintptr_t retaddr)
{
    XtensaCPU *cpu = xtensa_env_get_cpu(env);

    if (xtensa_option_enabled(env->config, XTENSA_OPTION_UNALIGNED_EXCEPTION) &&
            !xtensa_option_enabled(env->config, XTENSA_OPTION_HW_ALIGNMENT)) {
        cpu_restore_state(CPU(cpu), retaddr);
        HELPER(exception_cause_vaddr)(env,
                env->pc, LOAD_STORE_ALIGNMENT_CAUSE, addr);
    }
}
void HELPER(debug_exception)(uint32_t pc, uint32_t cause)
{
    unsigned level = env->config->debug_level;

    env->pc = pc;
    env->sregs[DEBUGCAUSE] = cause;
    env->sregs[EPC1 + level - 1] = pc;
    env->sregs[EPS2 + level - 2] = env->sregs[PS];
    env->sregs[PS] = (env->sregs[PS] & ~PS_INTLEVEL) | PS_EXCM |
        (level << PS_INTLEVEL_SHIFT);
    HELPER(exception)(EXC_DEBUG);
}
void HELPER(entry)(uint32_t pc, uint32_t s, uint32_t imm)
{
    int callinc = (env->sregs[PS] & PS_CALLINC) >> PS_CALLINC_SHIFT;
    if (s > 3 || ((env->sregs[PS] & (PS_WOE | PS_EXCM)) ^ PS_WOE) != 0) {
        qemu_log("Illegal entry instruction(pc = %08x), PS = %08x\n",
                pc, env->sregs[PS]);
        HELPER(exception_cause)(pc, ILLEGAL_INSTRUCTION_CAUSE);
    } else {
        env->regs[(callinc << 2) | (s & 3)] = env->regs[s] - (imm << 3);
        rotate_window(callinc);
        env->sregs[WINDOW_START] |=
            windowstart_bit(env->sregs[WINDOW_BASE], env);
    }
}
void HELPER(exception_cause)(uint32_t pc, uint32_t cause)
{
    uint32_t vector;

    env->pc = pc;
    if (env->sregs[PS] & PS_EXCM) {
        if (env->config->ndepc) {
            env->sregs[DEPC] = pc;
        } else {
            env->sregs[EPC1] = pc;
        }
        vector = EXC_DOUBLE;
    } else {
        env->sregs[EPC1] = pc;
        vector = (env->sregs[PS] & PS_UM) ? EXC_USER : EXC_KERNEL;
    }

    env->sregs[EXCCAUSE] = cause;
    env->sregs[PS] |= PS_EXCM;

    HELPER(exception)(vector);
}
Beispiel #6
0
void tlb_fill(CPUXtensaState *env,
        target_ulong vaddr, int is_write, int mmu_idx, uintptr_t retaddr)
{
    uint32_t paddr;
    uint32_t page_size;
    unsigned access;
    int ret = xtensa_get_physical_addr(env, true, vaddr, is_write, mmu_idx,
            &paddr, &page_size, &access);

    qemu_log("%s(%08x, %d, %d) -> %08x, ret = %d\n", __func__,
            vaddr, is_write, mmu_idx, paddr, ret);

    if (ret == 0) {
        tlb_set_page(env,
                vaddr & TARGET_PAGE_MASK,
                paddr & TARGET_PAGE_MASK,
                access, mmu_idx, page_size);
    } else {
        cpu_restore_state(env, retaddr);
        HELPER(exception_cause_vaddr)(env, env->pc, ret, vaddr);
    }
}
Beispiel #7
0
void monitor(const char *path) {
    fe_fmon fmon;
    fe_fmon_init_dir(&fmon, path, -1);
    fe_fmon_notify_callback(&fmon, callback);
    fe_fmon_event evt;
    for(;;) while(fe_fmon_poll(&fmon, &evt, -1)) {
        switch(evt.type) {
#define HELPER(type) \
        case FE_FMON_EVT_##type: fputs(#type, stdout); break
        HELPER(CREATE          );
        HELPER(ATTRIB          );
        HELPER(OPEN            );
        HELPER(READ            );
        HELPER(WRITE           );
        HELPER(EXTEND          );
        HELPER(CLOSE_WRITE     );
        HELPER(CLOSE_NOWRITE   );
        HELPER(FILESIZE        );
        HELPER(LAST_ACCESS_TIME);
        HELPER(LAST_WRITE_TIME );
        HELPER(MOVE            );
        HELPER(DELETE          );
#undef HELPER
        }
        if(evt.type==FE_FMON_EVT_MOVE)
            printf(": '%s' => '%s'\n", evt.path, evt.new_path);
        else
            printf(": '%s'\n", evt.path);
    }
}
void HELPER(exception_cause_vaddr)(uint32_t pc, uint32_t cause, uint32_t vaddr)
{
    env->sregs[EXCVADDR] = vaddr;
    HELPER(exception_cause)(pc, cause);
}
Beispiel #9
0
BOOL RSAKey::ExportKey(DWORD dwBlobType, DWORD dwFlags, BYTE *pbData, DWORD *pdwDataLen)
{
    DWORD dwByteLen1;
    DWORD dwByteLen2;
    DWORD dwDataLen;
    BOOL bPrivate;
    BLOBHEADER *pBlobHeader;
    RSAPUBKEY* pRSAPubKey;

    if ((dwBlobType != PUBLICKEYBLOB) && 
        ((dwBlobType != PRIVATEKEYBLOB) || (m_pPrivateExponent == NULL)))
    {
        SetLastError(NTE_BAD_TYPE);
        return FALSE;
    }

    bPrivate = (dwBlobType != PUBLICKEYBLOB);

    if (dwFlags != 0)
    {
        SetLastError(NTE_BAD_FLAGS);
        return FALSE;
    }

    dwByteLen1 = m_dwBitLen / 8;
    dwByteLen2 = dwByteLen1 / 2;

    dwDataLen = (pbData != NULL) ? *pdwDataLen : 0;
    *pdwDataLen = sizeof(BLOBHEADER) + sizeof(RSAPUBKEY) + 
        (bPrivate ? (2 * dwByteLen1 + 5 * dwByteLen2) : dwByteLen1);
    if (dwDataLen < *pdwDataLen)
    {
        if (pbData != NULL)
        {
            SetLastError(ERROR_MORE_DATA);
            return FALSE;
        }
        return TRUE;
    }

    pBlobHeader = (BLOBHEADER *)pbData;
    pbData += sizeof(BLOBHEADER);

    pBlobHeader->bType = (BYTE)dwBlobType;
    pBlobHeader->bVersion = 0x02;
    SET_UNALIGNED_VAL16(&pBlobHeader->reserved, 0x0000);
    SET_UNALIGNED_VAL32(&pBlobHeader->aiKeyAlg, CALG_RSA_SIGN);

    pRSAPubKey = (RSAPUBKEY*)pbData;
    pbData += sizeof(RSAPUBKEY);

    SET_UNALIGNED_VAL32(&pRSAPubKey->magic, bPrivate ? 0x32415352 : 0x31415352); // 'RSA2' : 'RSA1'
    SET_UNALIGNED_VAL32(&pRSAPubKey->bitlen, m_dwBitLen);

    BigNum::GetBytes(m_pExponent, (BYTE*)&pRSAPubKey->pubexp, sizeof(DWORD));

#define HELPER(m_pMember, size) \
    BigNum::GetBytes(m_pMember, pbData, dwByteLen##size); \
    pbData += dwByteLen##size;

    HELPER(m_pModulus, 1);

    if (dwBlobType == PUBLICKEYBLOB)
        return TRUE;

    HELPER(m_pPrime1, 2);
    HELPER(m_pPrime2, 2);
    HELPER(m_pExponent1, 2);
    HELPER(m_pExponent2, 2);
    HELPER(m_pCoefficient, 2);
    HELPER(m_pPrivateExponent, 1);
#undef HELPER

    return TRUE;
}
Beispiel #10
0
BOOL RSAKey::ImportKey(DWORD dwFlags, CONST BYTE *pbData, DWORD dwDataLen)
{            
    BOOL bPrivate;
    DWORD dwBitLen;
    DWORD dwByteLen1;
    DWORD dwByteLen2;
    DWORD dwBufferSize1;
    DWORD dwBufferSize2;
    BYTE *pb;
    BLOBHEADER *pBlobHeader;
    RSAPUBKEY* pRSAPubKey;

    _ASSERTE(dwDataLen >= sizeof(BLOBHEADER));
    pBlobHeader = (BLOBHEADER*)pbData;

    pbData += sizeof(BLOBHEADER);
    dwDataLen -= sizeof(BLOBHEADER);

    switch (pBlobHeader->bType)
    {
    case PUBLICKEYBLOB:
        bPrivate = FALSE;
        break;
    case PRIVATEKEYBLOB:
        bPrivate = TRUE;
        break;
    default:
        goto BadKey;
    }

    if (dwDataLen < sizeof(RSAPUBKEY))
    {
        goto BadKey;
    }
    pRSAPubKey = (RSAPUBKEY*)pbData;

    pbData += sizeof(RSAPUBKEY);
    dwDataLen -= sizeof(RSAPUBKEY);

    if (GET_UNALIGNED_VAL32(&pRSAPubKey->magic) != 
        (bPrivate ? 0x32415352U : 0x31415352U)) // 'RSA2' : 'RSA1'
    {
        goto BadKey;
    }

    dwBitLen = GET_UNALIGNED_VAL32(&pRSAPubKey->bitlen);

    if ((dwBitLen == 0) ||
        (dwBitLen % 16 != 0) ||
        (dwBitLen > 16384))
    {
        goto BadKey;
    }
    m_dwBitLen = dwBitLen;

    dwByteLen1 = dwBitLen / 8;
    dwByteLen2 = dwByteLen1 / 2;

    if (dwDataLen != (bPrivate ? (9 * dwByteLen2) : dwByteLen1))
    {
        goto BadKey;
    }

    dwBufferSize1 = BigNum::GetBufferSize(dwByteLen1);
    dwBufferSize2 = BigNum::GetBufferSize(dwByteLen2);

    m_dwSize = BigNum::GetBufferSize(sizeof(DWORD)) + 
            (bPrivate ? (2 * dwBufferSize1 + 5 * dwBufferSize2) : dwBufferSize1);
    pb = (BYTE*)malloc(m_dwSize);
    if (pb == NULL)
    {
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }
    m_pBlob = pb;

    m_pExponent = (BigNum*)pb;
    pb += BigNum::GetBufferSize(sizeof(DWORD));
    BigNum::SetBytes(m_pExponent, (BYTE*)&pRSAPubKey->pubexp, sizeof(DWORD));

#define HELPER(m_pMember, size) \
    m_pMember = (BigNum*)pb; \
    pb += dwBufferSize##size; \
    BigNum::SetBytes(m_pMember, pbData, dwByteLen##size); \
    pbData += dwByteLen##size;

    HELPER(m_pModulus, 1);

    if (!bPrivate)
        return TRUE;

    HELPER(m_pPrime1, 2);
    HELPER(m_pPrime2, 2);
    HELPER(m_pExponent1, 2);
    HELPER(m_pExponent2, 2);
    HELPER(m_pCoefficient, 2);
    HELPER(m_pPrivateExponent, 1);
#undef HELPER

    if (!CheckKey())
    {
        ClearStack();
        goto BadKey;
    }

    ClearStack();

    GetProvider()->SetSignatureKey(this);
    return TRUE;

BadKey:
    SetLastError(NTE_BAD_KEY);
    return FALSE;
}
Beispiel #11
0
BOOL RSAKey::GenKey(DWORD dwFlags)
{
    DWORD dwBitLen;
    DWORD dwByteLen1;
    DWORD dwByteLen2;
    DWORD dwBufferSize1;
    DWORD dwBufferSize2;
    BYTE *pb;

    dwBitLen = dwFlags >> 16;

    // use the default if not specified
    if (dwBitLen == 0)
        dwBitLen = 1024;

    if ((dwBitLen % 16 != 0) || 
        (dwBitLen > 16384))
    {
        SetLastError(NTE_BAD_FLAGS);
        return FALSE;
    }
    m_dwBitLen = dwBitLen;

    dwByteLen1 = dwBitLen / 8;
    dwByteLen2 = dwByteLen1 / 2;

    dwBufferSize1 = BigNum::GetBufferSize(dwByteLen1);
    dwBufferSize2 = BigNum::GetBufferSize(dwByteLen2);

    m_dwSize = BigNum::GetBufferSize(sizeof(DWORD)) + 
            (2 * dwBufferSize1 + 5 * dwBufferSize2);
    pb = (BYTE*)malloc(m_dwSize);
    if (pb == NULL)
    {
        SetLastError(ERROR_OUTOFMEMORY);
        return FALSE;
    }
    m_pBlob = pb;

    m_pExponent = (BigNum*)pb;
    pb += BigNum::GetBufferSize(sizeof(DWORD));

static const BYTE c_DefaultExponent[4] = { 1, 0, 1, 0 };
    BigNum::SetBytes(m_pExponent, c_DefaultExponent, sizeof(DWORD));

#define HELPER(m_pMember, size) \
    m_pMember = (BigNum*)pb; \
    pb += dwBufferSize##size;

    HELPER(m_pModulus, 1);

    HELPER(m_pPrime1, 2);
    HELPER(m_pPrime2, 2);
    HELPER(m_pExponent1, 2);
    HELPER(m_pExponent2, 2);
    HELPER(m_pCoefficient, 2);
    HELPER(m_pPrivateExponent, 1);
#undef HELPER

    if (!GenerateKey())
    {
        ClearStack();
        return FALSE;
    }

    if (!CheckKey())
    {                       
        SetLastError(E_UNEXPECTED);
        _ASSERTE(false);

        ClearStack();
        return FALSE;
    }        

    GetProvider()->SetSignatureKey(this);
    return TRUE;
}
Beispiel #12
0
Datei: hw.c Projekt: yoanlcq/FATE
    static void static_arm_features_fill(void) {
        #ifdef FE_HW_TARGET_ARM32
            fe_hw_arm32_features_struct *arm32 = (void*)&fe_hw_arm32_cpu_info;
        #else
            fe_hw_arm64_features_struct *arm64 = (void*)&fe_hw_arm64_cpu_info;
        #endif
        #ifdef FE_TARGET_ANDROID
            AndroidCpuFamily family = android_getCpuFamily();
            uint64_t feats          = android_getCpuFeatures();

            #ifdef FE_HW_TARGET_ARM32

                fe_dbg_assert(family == ANDROID_CPU_FAMILY_ARM);
                arm32->cpuid = android_getCpuIdArm();
                #define HELPER(CST,cst) \
    if(feats & ANDROID_CPU_ARM_FEATURE_##CST) arm32->has_##cst = true
                HELPER(ARMv7      , armv7      ); 
                HELPER(VFPv3      , vfpv3      ); 
                HELPER(NEON       , neon       ); 
                HELPER(LDREX_STREX, ldrex_strex); 
                HELPER(VFPv2      , vfpv2      ); 
                HELPER(VFP_D32    , vfp_d32    ); 
                HELPER(VFP_FP16   , vfp_fp16   ); 
                HELPER(VFP_FMA    , vfp_fma    ); 
                HELPER(NEON_FMA   , neon_fma   ); 
                HELPER(IDIV_ARM   , idiv_arm   ); 
                HELPER(IDIV_THUMB2, idiv_thumb2); 
                HELPER(iWMMXt     , iwmmxt     ); 
                HELPER(AES        , aes        ); 
                HELPER(PMULL      , pmull      ); 
                HELPER(SHA1       , sha1       ); 
                HELPER(SHA2       , sha2       ); 
                HELPER(CRC32      , crc32      );
                #undef HELPER

            #elif defined(FE_HW_TARGET_ARM64)

                fe_dbg_assert(family == ANDROID_CPU_FAMILY_ARM64);
                arm64->cpuid = android_getCpuIdArm();
                #define HELPER(CST,cst) \
    if(feats & ANDROID_CPU_ARM64_FEATURE_##CST) arm64->has_##cst = true
                HELPER(FP   , fp   );
                HELPER(ASIMD, asimd);
                HELPER(AES  , aes  );
                HELPER(PMULL, pmull);
                HELPER(SHA1 , sha1 );
                HELPER(SHA2 , sha2 );
                HELPER(CRC32, crc32);
                #undef HELPER

            #endif /* FE_HW_TARGET_ARM32 */

        #elif defined(FE_TARGET_IOS)

            /* On iOS, we don't have to check for cpu features support because
             * our app gets compiled twice into a fat binary - one part with
             * NEON support and the other part without.
             * The OS decides which part to use at lauch-time. 
             * See http://wanderingcoder.net/2010/07/19/ought-arm/
             */
            #ifdef FE_HW_TARGET_ARM_IWMMXT
                arm32->has_wmmx = true;
            #endif
            #ifdef FE_HW_TARGET_ARM_NEON
                arm32->has_neon = true;
            #endif

        #endif /* FE_TARGET_ANDROID */

    }
Beispiel #13
0
void debug_exception_env(CPUXtensaState *env, uint32_t cause)
{
    if (xtensa_get_cintlevel(env) < env->config->debug_level) {
        HELPER(debug_exception)(env, env->pc, cause);
    }
}
Beispiel #14
0
void HELPER(exception_cause_vaddr)(CPUXtensaState *env,
        uint32_t pc, uint32_t cause, uint32_t vaddr)
{
    env->sregs[EXCVADDR] = vaddr;
    HELPER(exception_cause)(env, pc, cause);
}
Beispiel #15
0
int main(int argc, char *argv[]) {

    if(alcIsExtensionPresent(NULL, "ALC_SOFT_loopback") == ALC_FALSE) {
        fputs("Your OpenAL implementation doesn't support the "
              "\"ALC_SOFT_loopback\" extension, required for this test. "
              "Sorry.\n", stderr);
        exit(EXIT_FAILURE);
    }
    ALCint alc_major, alc_minor;
    alcGetIntegerv(NULL, ALC_MAJOR_VERSION, 1, &alc_major);
    alcGetIntegerv(NULL, ALC_MINOR_VERSION, 1, &alc_minor);
    if(alc_major<1 || (alc_major==1 && alc_minor<1))
        fputs("Warning : ALC_SOFT_loopback has been written against "
              "the OpenAL 1.1 specification.\n", stderr);

#define HELPER(X) X = alcGetProcAddress(NULL, #X)
    HELPER(alcLoopbackOpenDeviceSOFT);
    HELPER(alcIsRenderFormatSupportedSOFT);
    HELPER(alcRenderSamplesSOFT);
#undef  HELPER
#define HELPER(X) X = alcGetEnumValue(NULL, #X)
    HELPER(ALC_BYTE_SOFT);
    HELPER(ALC_UNSIGNED_BYTE_SOFT);
    HELPER(ALC_SHORT_SOFT);
    HELPER(ALC_UNSIGNED_SHORT_SOFT);
    HELPER(ALC_INT_SOFT);
    HELPER(ALC_UNSIGNED_INT_SOFT);
    HELPER(ALC_FLOAT_SOFT);
    HELPER(ALC_MONO_SOFT);
    HELPER(ALC_STEREO_SOFT);
    HELPER(ALC_QUAD_SOFT);
    HELPER(ALC_5POINT1_SOFT);
    HELPER(ALC_6POINT1_SOFT);
    HELPER(ALC_7POINT1_SOFT);
    HELPER(ALC_FORMAT_CHANNELS_SOFT);
    HELPER(ALC_FORMAT_TYPE_SOFT);
#undef  HELPER

    ALCdevice *loopback_device = alcLoopbackOpenDeviceSOFT(NULL);
    if(!loopback_device) {
        fputs("Could not open loopback device.\n", stderr);
        exit(EXIT_FAILURE);
    }
    if(alcIsRenderFormatSupportedSOFT(loopback_device, 
            22050, ALC_STEREO_SOFT, ALC_SHORT_SOFT) == ALC_FALSE) 
    {
        fputs("The loopback device does not support the "
              "required render format.\n", stderr);
        alcCloseDevice(loopback_device);
        exit(EXIT_FAILURE);
    }

    ALCint attrlist[11] = {
        ALC_MONO_SOURCES, 0,
        ALC_STEREO_SOURCES, 255,
        ALC_FREQUENCY, 22050,
        ALC_FORMAT_CHANNELS_SOFT, ALC_STEREO_SOFT,
        ALC_FORMAT_TYPE_SOFT, ALC_SHORT_SOFT,
        0
    };
    ALCcontext *ctx = alcCreateContext(loopback_device, attrlist);
    alcMakeContextCurrent(ctx);
    alGetError(); /* Clear the error state */

    if(argc<=1) {
        fprintf(stderr, "Usage : %s <small_oggfile>\n", argv[0]);
        alcCloseDevice(loopback_device);
        exit(EXIT_FAILURE);
    }

    SF_INFO sndinfo;
    SNDFILE *snd = sf_open(argv[1], SFM_READ, &sndinfo);
    if(!snd) {
        fprintf(stderr, "Failed to open \"%s\" : %s\n", 
                argv[1], sf_strerror(snd));
        alcCloseDevice(loopback_device);
        exit(EXIT_FAILURE);
    }
    if(sndinfo.channels != 2) {
        fprintf(stderr, "The source sound file has %d channels "
                "(exactly 2 are required).\n", sndinfo.channels);
        alcCloseDevice(loopback_device);
        exit(EXIT_FAILURE);
    }
    short *data = malloc(sndinfo.frames*2*sizeof(short));
    printf("Reading from '%s'...\n", argv[1]);
    sf_readf_short(snd, data, sndinfo.frames);
    sf_close(snd);

    ALuint audio_buffer;
    alGenBuffers(1, &audio_buffer);
    alBufferData(audio_buffer, AL_FORMAT_STEREO16, data,
            sndinfo.frames*2*sizeof(short), sndinfo.samplerate);
    free(data);

    ALuint audio_source;
    alGenSources(1, &audio_source);
    alSourcei(audio_source, AL_BUFFER, audio_buffer);

    unsigned num_frames = sndinfo.frames;
    ALCshort *rendered_samples = malloc(num_frames*2*sizeof(ALCshort));
    sndinfo.samplerate = 22050;
    sndinfo.channels = 2;
    sndinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS | SF_ENDIAN_FILE;
    snd = sf_open("rendered.ogg", SFM_WRITE, &sndinfo);

    alSourcePlay(audio_source);

    puts("Rendering frames...");
    unsigned chunk_size = 4096, off;
    for(off=0 ; off<(num_frames-chunk_size)*2 ; off+=2*chunk_size)
        alcRenderSamplesSOFT(loopback_device, rendered_samples+off, chunk_size);

    puts("Writing to 'rendered.ogg'...");
    sf_write_short(snd, rendered_samples, off-s);
    sf_close(snd);
    free(rendered_samples);

    alDeleteSources(1, &audio_source);
    alDeleteBuffers(1, &audio_buffer);
    alcCloseDevice(loopback_device);
    alcMakeContextCurrent(NULL);
    alcDestroyContext(ctx);

    exit(EXIT_SUCCESS);
}
Beispiel #16
0
void HELPER(gvec_dup8)(void *d, uint32_t desc, uint32_t c)
{
    HELPER(gvec_dup32)(d, desc, 0x01010101 * (c & 0xff));
}