From 2468645bf2211788c4ad9b3c02d6b94ea027bb1c Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Thu, 2 Jan 2014 23:53:18 -0800 Subject: [PATCH] Making functions naked for now, as it makes life way easier. --- src/alloy/backend/x64/x64_code_cache.cc | 12 +++++++++--- src/alloy/backend/x64/x64_emitter.cc | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/alloy/backend/x64/x64_code_cache.cc b/src/alloy/backend/x64/x64_code_cache.cc index aa14ad0ea..854e6f699 100644 --- a/src/alloy/backend/x64/x64_code_cache.cc +++ b/src/alloy/backend/x64/x64_code_cache.cc @@ -213,12 +213,17 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size) { size_t unwind_info_offset = offset; offset += UNWIND_INFO_SIZE; + // TODO(benvanik): take as parameters? + bool has_prolog = false; + uint8_t prolog_size = 4; + uint8_t stack_bytes = 16; + // http://msdn.microsoft.com/en-us/library/ddssxxy8.aspx UNWIND_INFO* unwind_info = (UNWIND_INFO*)(buffer + unwind_info_offset); unwind_info->Version = 1; unwind_info->Flags = 0; - unwind_info->SizeOfProlog = 4; - unwind_info->CountOfCodes = 1; + unwind_info->SizeOfProlog = has_prolog ? prolog_size : 0; + unwind_info->CountOfCodes = has_prolog ? 1 : 0; unwind_info->FrameRegister = 0; unwind_info->FrameOffset = 0; @@ -226,7 +231,8 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size) { auto& code_0 = unwind_info->UnwindCode[0]; code_0.CodeOffset = 4; // end of instruction + 1 == offset of next instruction code_0.UnwindOp = UWOP_ALLOC_SMALL; - code_0.OpInfo = 16; + code_0.OpInfo = stack_bytes; + XEASSERT(stack_bytes < 128); // Add entry. auto& fn_entry = fn_table[fn_table_count++]; diff --git a/src/alloy/backend/x64/x64_emitter.cc b/src/alloy/backend/x64/x64_emitter.cc index 2eed311e3..7d865b915 100644 --- a/src/alloy/backend/x64/x64_emitter.cc +++ b/src/alloy/backend/x64/x64_emitter.cc @@ -103,7 +103,7 @@ void* XbyakGenerator::Emplace(X64CodeCache* code_cache) { int XbyakGenerator::Emit(LIRBuilder* builder) { // Function prolog. // Must be 16b aligned. - // Windows is very strict about the form of this and the eiplog: + // Windows is very strict about the form of this and the epilog: // http://msdn.microsoft.com/en-us/library/tawsa7cb.aspx // TODO(benvanik): save off non-volatile registers so we can use them: // RBX, RBP, RDI, RSI, RSP, R12, R13, R14, R15 @@ -112,8 +112,12 @@ int XbyakGenerator::Emit(LIRBuilder* builder) { // IMPORTANT: any changes to the prolog must be kept in sync with // X64CodeCache, which dynamically generates exception information. // Adding or changing anything here must be matched! + const bool emit_prolog = false; const size_t stack_size = 16; - sub(rsp, stack_size); + if (emit_prolog) { + sub(rsp, stack_size); + // TODO(benvanik): save registers. + } // Body. auto block = builder->first_block(); @@ -145,8 +149,10 @@ int XbyakGenerator::Emit(LIRBuilder* builder) { // Function epilog. L("epilog"); - add(rsp, stack_size); - // TODO(benvanik): restore registers. + if (emit_prolog) { + add(rsp, stack_size); + // TODO(benvanik): restore registers. + } ret(); return 0;