OLD | NEW |
(Empty) | |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are |
| 4 // met: |
| 5 // |
| 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. |
| 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
| 28 #include <stdlib.h> |
| 29 |
| 30 #include "v8.h" |
| 31 |
| 32 #include "macro-assembler.h" |
| 33 #include "factory.h" |
| 34 #include "platform.h" |
| 35 #include "serialize.h" |
| 36 #include "cctest.h" |
| 37 |
| 38 using v8::internal::byte; |
| 39 using v8::internal::OS; |
| 40 using v8::internal::Assembler; |
| 41 using v8::internal::rax; |
| 42 using v8::internal::rsi; |
| 43 using v8::internal::FUNCTION_CAST; |
| 44 using v8::internal::CodeDesc; |
| 45 |
| 46 |
| 47 // Test the x64 assembler by compiling some simple functions into |
| 48 // a buffer and executing them. These tests do not initialize the |
| 49 // V8 library, create a context, or use any V8 objects. |
| 50 // The AMD64 calling convention is used, with the first five arguments |
| 51 // in RSI, RDI, RDX, RCX, R8, and R9, and floating point arguments in |
| 52 // the XMM registers. The return value is in RAX. |
| 53 // This calling convention is used on Linux, with GCC, and on Mac OS, |
| 54 // with GCC. A different convention is used on 64-bit windows. |
| 55 |
| 56 typedef int (*F0)(); |
| 57 typedef int (*F1)(int x); |
| 58 typedef int (*F2)(int x, int y); |
| 59 |
| 60 #define __ assm. |
| 61 |
| 62 |
| 63 TEST(AssemblerX640) { |
| 64 // Allocate an executable page of memory. |
| 65 size_t actual_size; |
| 66 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 67 &actual_size, |
| 68 true)); |
| 69 CHECK(buffer); |
| 70 Assembler assm(buffer, actual_size); |
| 71 |
| 72 // Assemble a simple function that copies argument 2 and returns it. |
| 73 __ mov(rax, rsi); |
| 74 __ nop(); |
| 75 __ ret(0); |
| 76 |
| 77 CodeDesc desc; |
| 78 assm.GetCode(&desc); |
| 79 // Call the function from C++. |
| 80 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 81 CHECK_EQ(2, result); |
| 82 } |
| 83 |
| 84 #undef __ |
OLD | NEW |