ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 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 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
| 30 | #include "bootstrapper.h" |
| 31 | #include "codegen-inl.h" |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame^] | 32 | #include "macro-assembler-x64.h" |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
| 37 | MacroAssembler::MacroAssembler(void* buffer, int size) |
| 38 | : Assembler(buffer, size), |
| 39 | unresolved_(0), |
| 40 | generating_stub_(false), |
| 41 | allow_stub_calls_(true), |
| 42 | code_object_(Heap::undefined_value()) { |
| 43 | } |
| 44 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame^] | 45 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 46 | void MacroAssembler::TailCallRuntime(ExternalReference const& a, int b) { |
| 47 | UNIMPLEMENTED(); |
| 48 | } |
| 49 | |
ager@chromium.org | e2902be | 2009-06-08 12:21:35 +0000 | [diff] [blame^] | 50 | |
| 51 | void MacroAssembler::Set(Register dst, int64_t x) { |
| 52 | if (is_int32(x)) { |
| 53 | movq(dst, Immediate(x)); |
| 54 | } else if (is_uint32(x)) { |
| 55 | movl(dst, Immediate(x)); |
| 56 | } else { |
| 57 | movq(dst, x, RelocInfo::NONE); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | void MacroAssembler::Set(const Operand& dst, int64_t x) { |
| 63 | if (is_int32(x)) { |
| 64 | movq(kScratchRegister, Immediate(x)); |
| 65 | } else if (is_uint32(x)) { |
| 66 | movl(kScratchRegister, Immediate(x)); |
| 67 | } else { |
| 68 | movq(kScratchRegister, x, RelocInfo::NONE); |
| 69 | } |
| 70 | movq(dst, kScratchRegister); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void MacroAssembler::PushTryHandler(CodeLocation try_location, |
| 75 | HandlerType type) { |
| 76 | // The pc (return address) is already on TOS. |
| 77 | // This code pushes state, code, frame pointer and parameter pointer. |
| 78 | // Check that they are expected next on the stack, int that order. |
| 79 | ASSERT_EQ(StackHandlerConstants::kStateOffset, |
| 80 | StackHandlerConstants::kPCOffset - kPointerSize); |
| 81 | ASSERT_EQ(StackHandlerConstants::kCodeOffset, |
| 82 | StackHandlerConstants::kStateOffset - kPointerSize); |
| 83 | ASSERT_EQ(StackHandlerConstants::kFPOffset, |
| 84 | StackHandlerConstants::kCodeOffset - kPointerSize); |
| 85 | ASSERT_EQ(StackHandlerConstants::kPPOffset, |
| 86 | StackHandlerConstants::kFPOffset - kPointerSize); |
| 87 | |
| 88 | if (try_location == IN_JAVASCRIPT) { |
| 89 | if (type == TRY_CATCH_HANDLER) { |
| 90 | push(Immediate(StackHandler::TRY_CATCH)); |
| 91 | } else { |
| 92 | push(Immediate(StackHandler::TRY_FINALLY)); |
| 93 | } |
| 94 | push(Immediate(Smi::FromInt(StackHandler::kCodeNotPresent))); |
| 95 | push(rbp); |
| 96 | push(rdi); |
| 97 | } else { |
| 98 | ASSERT(try_location == IN_JS_ENTRY); |
| 99 | // The parameter pointer is meaningless here and ebp does not |
| 100 | // point to a JS frame. So we save NULL for both pp and ebp. We |
| 101 | // expect the code throwing an exception to check ebp before |
| 102 | // dereferencing it to restore the context. |
| 103 | push(Immediate(StackHandler::ENTRY)); |
| 104 | push(Immediate(Smi::FromInt(StackHandler::kCodeNotPresent))); |
| 105 | push(Immediate(0)); // NULL frame pointer |
| 106 | push(Immediate(0)); // NULL parameter pointer |
| 107 | } |
| 108 | movq(kScratchRegister, ExternalReference(Top::k_handler_address)); |
| 109 | // Cached TOS. |
| 110 | movq(rax, Operand(kScratchRegister, 0)); |
| 111 | // Link this handler. |
| 112 | movq(Operand(kScratchRegister, 0), rsp); |
| 113 | } |
| 114 | |
| 115 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 116 | } } // namespace v8::internal |