<commit_before>/* **********************************************************
 * Copyright (c) 2014-2015 Google, Inc.  All rights reserved.
 * **********************************************************/

/*
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of VMware, Inc. nor the names of its contributors may be
 *   used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

/* file "emit_utils.c"
 * The ARM processors does not maintain cache consistency in hardware,
 * so we need be careful about getting stale cache entries.
 */

#include "../globals.h"
#include "arch.h"
#include "instr.h"
#include "instr_create.h"
#include "instrlist.h"
#include "instrument.h" /* for dr_insert_call() */

/* shorten code generation lines */
#define APP    instrlist_meta_append
#define PRE    instrlist_meta_preinsert
#define OPREG  opnd_create_reg

/***************************************************************************/
/*                               EXIT STUB                                 */
/***************************************************************************/

byte *
insert_relative_target(byte *pc, cache_pc target, bool hot_patch)
{
    /* FIXME i#1551: NYI on ARM.
     * We may want to refactor the calling code to remove this and only
     * use patch_branch().
     */
    ASSERT_NOT_IMPLEMENTED(false);
    return NULL;
}

byte *
insert_relative_jump(byte *pc, cache_pc target, bool hot_patch)
{
    /* FIXME i#1551: NYI on ARM */
    ASSERT_NOT_IMPLEMENTED(false);
    return NULL;
}

static byte *
insert_spill_reg(byte *pc, fragment_t *f, reg_id_t src)
{
    /* str src, [r10, #r0-slot] */
    if (FRAG_IS_THUMB(f->flags)) {
        *(ushort *)pc = 0xf8c0 | (dr_reg_stolen - DR_REG_R0);
        pc += THUMB_SHORT_INSTR_SIZE;
        *(ushort *)pc = ((src - DR_REG_R0) << 12) | TLS_REG0_SLOT;
        pc += THUMB_SHORT_INSTR_SIZE;
    } else {
        *(uint *)pc = 0xe5800000 | ((src - DR_REG_R0) << 12) |
            ((dr_reg_stolen - DR_REG_R0) << 16) | TLS_REG0_SLOT;
        pc += ARM_INSTR_SIZE;
    }
    return pc;
}

static byte *
insert_ldr_tls_to_pc(byte *pc, fragment_t *f, uint offs)
{
    /* ldr pc, [r10, #offs] */
    if (FRAG_IS_THUMB(f->flags)) {
        *(ushort*)pc = 0xf8d0 | (dr_reg_stolen - DR_REG_R0);
        pc += THUMB_SHORT_INSTR_SIZE;
        *(ushort*)pc = 0xf000 | offs;
        return pc + THUMB_SHORT_INSTR_SIZE;
    } else {
        *(uint*)pc =
            0xe590f000 | ((dr_reg_stolen - DR_REG_R0) << 16) | offs;
        return pc + ARM_INSTR_SIZE;
    }
}
<commit_msg>i#1551 Port DynamoRIO to ARM: fixed insert_spill_reg bug - fixed insert_spill_reg bug to spill reg to the right slot<commit_after>/* **********************************************************
 * Copyright (c) 2014-2015 Google, Inc.  All rights reserved.
 * **********************************************************/

/*
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * * Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * * Neither the name of VMware, Inc. nor the names of its contributors may be
 *   used to endorse or promote products derived from this software without
 *   specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

/* file "emit_utils.c"
 * The ARM processors does not maintain cache consistency in hardware,
 * so we need be careful about getting stale cache entries.
 */

#include "../globals.h"
#include "arch.h"
#include "instr.h"
#include "instr_create.h"
#include "instrlist.h"
#include "instrument.h" /* for dr_insert_call() */

/* shorten code generation lines */
#define APP    instrlist_meta_append
#define PRE    instrlist_meta_preinsert
#define OPREG  opnd_create_reg

/***************************************************************************/
/*                               EXIT STUB                                 */
/***************************************************************************/

byte *
insert_relative_target(byte *pc, cache_pc target, bool hot_patch)
{
    /* FIXME i#1551: NYI on ARM.
     * We may want to refactor the calling code to remove this and only
     * use patch_branch().
     */
    ASSERT_NOT_IMPLEMENTED(false);
    return NULL;
}

byte *
insert_relative_jump(byte *pc, cache_pc target, bool hot_patch)
{
    /* FIXME i#1551: NYI on ARM */
    ASSERT_NOT_IMPLEMENTED(false);
    return NULL;
}

static byte *
insert_spill_reg(byte *pc, fragment_t *f, reg_id_t src)
{
    ushort slot;
    ASSERT(src >= DR_REG_R0 && src <= DR_REG_R4);
    slot = TLS_REG0_SLOT + (src - DR_REG_R0) * sizeof(reg_t);
    /* str src, [r10, #src-slot] */
    if (FRAG_IS_THUMB(f->flags)) {
        *(ushort *)pc = 0xf8c0 | (dr_reg_stolen - DR_REG_R0);
        pc += THUMB_SHORT_INSTR_SIZE;
        *(ushort *)pc = ((src - DR_REG_R0) << 12) | slot;
        pc += THUMB_SHORT_INSTR_SIZE;
    } else {
        *(uint *)pc = 0xe5800000 | ((src - DR_REG_R0) << 12) |
            ((dr_reg_stolen - DR_REG_R0) << 16) | slot;
        pc += ARM_INSTR_SIZE;
    }
    return pc;
}

static byte *
insert_ldr_tls_to_pc(byte *pc, fragment_t *f, uint offs)
{
    /* ldr pc, [r10, #offs] */
    if (FRAG_IS_THUMB(f->flags)) {
        *(ushort*)pc = 0xf8d0 | (dr_reg_stolen - DR_REG_R0);
        pc += THUMB_SHORT_INSTR_SIZE;
        *(ushort*)pc = 0xf000 | offs;
        return pc + THUMB_SHORT_INSTR_SIZE;
    } else {
        *(uint*)pc =
            0xe590f000 | ((dr_reg_stolen - DR_REG_R0) << 16) | offs;
        return pc + ARM_INSTR_SIZE;
    }
}

{'fraction_non_alphanumeric': 0.15541819099280937, 'fraction_numerical': 0.016273495647786046, 'mean_word_length': 3.40199888950583, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7526674', 'n_tokens_mistral': 2538, 'n_tokens_neox': 2327, 'n_words': 820}