X64: Create test JS-function and call it.

Review URL: http://codereview.chromium.org/123017


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2145 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
lrn@chromium.org 2009-06-11 13:17:46 +00:00
parent a8507cb43d
commit d39df3809c
4 changed files with 30 additions and 5 deletions

View File

@ -251,7 +251,7 @@ Object** RelocInfo::call_object_address() {
void Operand::set_modrm(int mod, Register rm) {
ASSERT((mod & -4) == 0);
buf_[0] = mod << 6 | (rm.code() & 0x7);
buf_[0] = (mod << 6) | (rm.code() & 0x7);
// Set REX.B to the high bit of rm.code().
rex_ |= (rm.code() >> 3);
}

View File

@ -81,7 +81,7 @@ Operand::Operand(Register base, int32_t disp): rex_(0) {
}
if (disp == 0 && !base.is(rbp) && !base.is(r13)) {
set_modrm(0, rsp);
set_modrm(0, base);
} else if (is_int8(disp)) {
set_modrm(1, base);
set_disp8(disp);

View File

@ -571,7 +571,8 @@ void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
ExternalReference entry(Builtins::JSEntryTrampoline);
__ load_rax(entry);
}
__ call(FieldOperand(rax, Code::kHeaderSize));
__ lea(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
__ call(kScratchRegister);
// Unlink this frame from the handler chain.
__ movq(kScratchRegister, ExternalReference(Top::k_handler_address));

View File

@ -63,14 +63,38 @@ void MacroAssembler::ConstructAndTestJSFunction() {
const int initial_buffer_size = 4 * KB;
char* buffer = new char[initial_buffer_size];
MacroAssembler masm(buffer, initial_buffer_size);
const uint64_t secret = V8_INT64_C(0xdeadbeefcafebabe);
#define __ ACCESS_MASM((&masm))
// Construct a simple JSfunction here, using Assembler and MacroAssembler
// commands.
__ int3();
__ movq(rax, secret, RelocInfo::NONE);
__ ret(0);
#undef __
CodeDesc desc;
masm.GetCode(&desc);
// TODO(X64): Create the function object and call it.
Code::Flags flags = Code::ComputeFlags(Code::FUNCTION);
Object* code = Heap::CreateCode(desc, NULL, flags, Handle<Object>::null());
if (!code->IsFailure()) {
Handle<Code> code_handle(Code::cast(code));
Handle<String> name =
Factory::NewStringFromAscii(Vector<const char>("foo", 3), NOT_TENURED);
Handle<JSFunction> function =
Factory::NewFunction(name,
JS_FUNCTION_TYPE,
JSObject::kHeaderSize,
code_handle,
true);
bool pending_exceptions;
Handle<Object> result =
Execution::Call(function,
Handle<Object>::cast(function),
0,
NULL,
&pending_exceptions);
CHECK(result->IsSmi());
CHECK(secret == reinterpret_cast<uint64_t>(*result));
}
}