Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / assembler / assembler / MacroAssemblerARM.cpp
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  * vim: set ts=8 sw=4 et tw=79:
3  *
4  * ***** BEGIN LICENSE BLOCK *****
5  * Copyright (C) 2009 University of Szeged
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY UNIVERSITY OF SZEGED ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL UNIVERSITY OF SZEGED OR
21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  * 
29  * ***** END LICENSE BLOCK ***** */
30
31 #include "assembler/wtf/Platform.h"
32
33 #if ENABLE_ASSEMBLER && WTF_CPU_ARM_TRADITIONAL
34
35 #include "MacroAssemblerARM.h"
36
37 #if WTF_PLATFORM_LINUX || WTF_PLATFORM_ANDROID
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <fcntl.h>
41 #include <unistd.h>
42 #include <elf.h>
43
44 // lame check for kernel version
45 // see bug 586550
46 #include <linux/version.h>
47 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
48 #include <asm/procinfo.h>
49 #else
50 #include <asm/hwcap.h>
51 #endif
52
53 #endif
54
55 namespace JSC {
56
57 static bool isVFPPresent()
58 {
59 #if WTF_PLATFORM_LINUX
60     int fd = open("/proc/self/auxv", O_RDONLY);
61     if (fd > 0) {
62         Elf32_auxv_t aux;
63         while (read(fd, &aux, sizeof(Elf32_auxv_t))) {
64             if (aux.a_type == AT_HWCAP) {
65                 close(fd);
66                 return aux.a_un.a_val & HWCAP_VFP;
67             }
68         }
69         close(fd);
70     }
71 #endif
72
73     return false;
74 }
75
76 const bool MacroAssemblerARM::s_isVFPPresent = isVFPPresent();
77
78 #if WTF_CPU_ARMV5_OR_LOWER
79 /* On ARMv5 and below, natural alignment is required. */
80 void MacroAssemblerARM::load32WithUnalignedHalfWords(BaseIndex address, RegisterID dest)
81 {
82     ARMWord op2;
83
84     ASSERT(address.scale >= 0 && address.scale <= 3);
85     op2 = m_assembler.lsl(address.index, static_cast<int>(address.scale));
86
87     if (address.offset >= 0 && address.offset + 0x2 <= 0xff) {
88         m_assembler.add_r(ARMRegisters::S0, address.base, op2);
89         m_assembler.ldrh_u(dest, ARMRegisters::S0, ARMAssembler::getOp2Byte(address.offset));
90         m_assembler.ldrh_u(ARMRegisters::S0, ARMRegisters::S0, ARMAssembler::getOp2Byte(address.offset + 0x2));
91     } else if (address.offset < 0 && address.offset >= -0xff) {
92         m_assembler.add_r(ARMRegisters::S0, address.base, op2);
93         m_assembler.ldrh_d(dest, ARMRegisters::S0, ARMAssembler::getOp2Byte(-address.offset));
94         m_assembler.ldrh_d(ARMRegisters::S0, ARMRegisters::S0, ARMAssembler::getOp2Byte(-address.offset - 0x2));
95     } else {
96         m_assembler.ldr_un_imm(ARMRegisters::S0, address.offset);
97         m_assembler.add_r(ARMRegisters::S0, ARMRegisters::S0, op2);
98         m_assembler.ldrh_r(dest, address.base, ARMRegisters::S0);
99         m_assembler.add_r(ARMRegisters::S0, ARMRegisters::S0, ARMAssembler::OP2_IMM | 0x2);
100         m_assembler.ldrh_r(ARMRegisters::S0, address.base, ARMRegisters::S0);
101     }
102     m_assembler.orr_r(dest, dest, m_assembler.lsl(ARMRegisters::S0, 16));
103 }
104 #endif
105
106 }
107
108 #endif // ENABLE(ASSEMBLER) && CPU(ARM_TRADITIONAL)