00001 // Copyright 2006-2008 the V8 project authors. All rights reserved. 00002 // Redistribution and use in source and binary forms, with or without 00003 // modification, are permitted provided that the following conditions are 00004 // met: 00005 // 00006 // * Redistributions of source code must retain the above copyright 00007 // notice, this list of conditions and the following disclaimer. 00008 // * Redistributions in binary form must reproduce the above 00009 // copyright notice, this list of conditions and the following 00010 // disclaimer in the documentation and/or other materials provided 00011 // with the distribution. 00012 // * Neither the name of Google Inc. nor the names of its 00013 // contributors may be used to endorse or promote products derived 00014 // from this software without specific prior written permission. 00015 // 00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00017 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00018 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00019 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00020 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00021 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00022 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00024 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00026 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 00028 // CPU specific code for arm independent of OS goes here. 00029 #if defined(__arm__) 00030 #include <sys/syscall.h> // for cache flushing. 00031 #endif 00032 00033 #include "v8.h" 00034 00035 #include "cpu.h" 00036 00037 namespace v8 { namespace internal { 00038 00039 void CPU::Setup() { 00040 // Nothing to do. 00041 } 00042 00043 00044 void CPU::FlushICache(void* start, size_t size) { 00045 #if !defined (__arm__) 00046 // Not generating ARM instructions for C-code. This means that we are 00047 // building an ARM emulator based target. No I$ flushes are necessary. 00048 #else 00049 // Ideally, we would call 00050 // syscall(__ARM_NR_cacheflush, start, 00051 // reinterpret_cast<intptr_t>(start) + size, 0); 00052 // however, syscall(int, ...) is not supported on all platforms, especially 00053 // not when using EABI, so we call the __ARM_NR_cacheflush syscall directly. 00054 00055 register uint32_t beg asm("a1") = reinterpret_cast<uint32_t>(start); 00056 register uint32_t end asm("a2") = 00057 reinterpret_cast<uint32_t>(start) + size; 00058 register uint32_t flg asm("a3") = 0; 00059 #ifdef __ARM_EABI__ 00060 register uint32_t scno asm("r7") = __ARM_NR_cacheflush; 00061 #if defined (__arm__) && !defined(__thumb__) 00062 // __arm__ may be defined in thumb mode. 00063 asm volatile( 00064 "swi 0x0" 00065 : "=r" (beg) 00066 : "0" (beg), "r" (end), "r" (flg), "r" (scno)); 00067 #else 00068 asm volatile( 00069 "@ Enter ARM Mode \n\t" 00070 "adr r3, 1f \n\t" 00071 "bx r3 \n\t" 00072 ".ALIGN 4 \n\t" 00073 ".ARM \n" 00074 "1: swi 0x0 \n\t" 00075 "@ Enter THUMB Mode\n\t" 00076 "adr r3, 2f+1 \n\t" 00077 "bx r3 \n\t" 00078 ".THUMB \n" 00079 "2: \n\t" 00080 : "=r" (beg) 00081 : "0" (beg), "r" (end), "r" (flg), "r" (scno) 00082 : "r3"); 00083 #endif 00084 #else 00085 #if defined (__arm__) && !defined(__thumb__) 00086 // __arm__ may be defined in thumb mode. 00087 asm volatile( 00088 "swi %1" 00089 : "=r" (beg) 00090 : "i" (__ARM_NR_cacheflush), "0" (beg), "r" (end), "r" (flg)); 00091 #else 00092 // Do not use the value of __ARM_NR_cacheflush in the inline assembly 00093 // below, because the thumb mode value would be used, which would be 00094 // wrong, since we switch to ARM mode before executing the swi instruction 00095 asm volatile( 00096 "@ Enter ARM Mode \n\t" 00097 "adr r3, 1f \n\t" 00098 "bx r3 \n\t" 00099 ".ALIGN 4 \n\t" 00100 ".ARM \n" 00101 "1: swi 0x9f0002 \n" 00102 "@ Enter THUMB Mode\n\t" 00103 "adr r3, 2f+1 \n\t" 00104 "bx r3 \n\t" 00105 ".THUMB \n" 00106 "2: \n\t" 00107 : "=r" (beg) 00108 : "0" (beg), "r" (end), "r" (flg) 00109 : "r3"); 00110 #endif 00111 #endif 00112 #endif 00113 } 00114 00115 00116 void CPU::DebugBreak() { 00117 #if !defined (__arm__) 00118 UNIMPLEMENTED(); // when building ARM emulator target 00119 #else 00120 asm volatile("bkpt 0"); 00121 #endif 00122 } 00123 00124 } } // namespace v8::internal