Skip to content

Commit 292323b

Browse files
X64: Fix bugs affecting Win64.
Increase stack space on Win64 sample and cctest executables. Review URL: http://codereview.chromium.org/264047 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3056 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent ac73189 commit 292323b

7 files changed

+47
-26
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
*.suo
1111
*.user
1212
*.xcodeproj
13+
*.idb
14+
*.pdb
15+
#*#
16+
*~
1317
d8
1418
d8_g
1519
shell

SConstruct

+3-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ CCTEST_EXTRA_FLAGS = {
373373
'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
374374
},
375375
'arch:x64': {
376-
'CPPDEFINES': ['V8_TARGET_ARCH_X64']
376+
'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
377+
'LINKFLAGS': ['/STACK:2091752']
377378
},
378379
}
379380
}
@@ -474,7 +475,7 @@ SAMPLE_FLAGS = {
474475
},
475476
'arch:x64': {
476477
'CPPDEFINES': ['V8_TARGET_ARCH_X64'],
477-
'LINKFLAGS': ['/MACHINE:X64']
478+
'LINKFLAGS': ['/MACHINE:X64', '/STACK:2091752']
478479
},
479480
'mode:debug': {
480481
'CCFLAGS': ['/Od'],

src/execution.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,8 @@ void StackGuard::ThreadLocal::Initialize() {
386386
if (initial_climit_ == kIllegalLimit) {
387387
// Takes the address of the limit variable in order to find out where
388388
// the top of stack is right now.
389-
intptr_t limit = reinterpret_cast<intptr_t>(&limit) - kLimitSize;
389+
uintptr_t limit = reinterpret_cast<uintptr_t>(&limit) - kLimitSize;
390+
ASSERT(reinterpret_cast<uintptr_t>(&limit) > kLimitSize);
390391
initial_jslimit_ = SimulatorStack::JsLimitFromCLimit(limit);
391392
jslimit_ = SimulatorStack::JsLimitFromCLimit(limit);
392393
initial_climit_ = limit;

src/execution.h

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ class StackGuard : public AllStatic {
216216
static void DisableInterrupts();
217217

218218
static const uintptr_t kLimitSize = kPointerSize * 128 * KB;
219+
219220
#ifdef V8_TARGET_ARCH_X64
220221
static const uintptr_t kInterruptLimit = V8_UINT64_C(0xfffffffffffffffe);
221222
static const uintptr_t kIllegalLimit = V8_UINT64_C(0xfffffffffffffff8);

src/platform-win32.cc

-1
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,6 @@ class Sampler::PlatformData : public Malloced {
17941794
context.ContextFlags = CONTEXT_FULL;
17951795
if (GetThreadContext(profiled_thread_, &context) != 0) {
17961796
#if V8_HOST_ARCH_X64
1797-
UNIMPLEMENTED();
17981797
sample.pc = context.Rip;
17991798
sample.sp = context.Rsp;
18001799
sample.fp = context.Rbp;

test/cctest/test-api.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,10 @@ THREADED_TEST(BigInteger) {
728728
LocalContext env;
729729
// We cannot add one to a Smi::kMaxValue without wrapping.
730730
if (i::kSmiValueSize < 32) {
731-
int32_t value = i::Smi::kMaxValue + 1;
731+
// The casts allow this to compile, even if Smi::kMaxValue is 2^31-1.
732+
// The code will not be run in that case, due to the "if" guard.
733+
int32_t value =
734+
static_cast<int32_t>(static_cast<uint32_t>(i::Smi::kMaxValue) + 1);
732735
CHECK(value > i::Smi::kMaxValue);
733736
CHECK(!i::Smi::IsValid(value));
734737
Local<v8::Integer> value_obj = v8::Integer::New(value);

test/cctest/test-assembler-x64.cc

+33-21
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ using v8::internal::Label;
4444
using v8::internal::rax;
4545
using v8::internal::rsi;
4646
using v8::internal::rdi;
47+
using v8::internal::rcx;
4748
using v8::internal::rdx;
4849
using v8::internal::rbp;
4950
using v8::internal::rsp;
@@ -53,20 +54,28 @@ using v8::internal::less_equal;
5354
using v8::internal::not_equal;
5455
using v8::internal::greater;
5556

56-
5757
// Test the x64 assembler by compiling some simple functions into
5858
// a buffer and executing them. These tests do not initialize the
5959
// V8 library, create a context, or use any V8 objects.
60-
// The AMD64 calling convention is used, with the first five arguments
61-
// in RSI, RDI, RDX, RCX, R8, and R9, and floating point arguments in
60+
// The AMD64 calling convention is used, with the first six arguments
61+
// in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in
6262
// the XMM registers. The return value is in RAX.
6363
// This calling convention is used on Linux, with GCC, and on Mac OS,
64-
// with GCC. A different convention is used on 64-bit windows.
64+
// with GCC. A different convention is used on 64-bit windows,
65+
// where the first four integer arguments are passed in RCX, RDX, R8 and R9.
6566

6667
typedef int (*F0)();
6768
typedef int (*F1)(int64_t x);
6869
typedef int (*F2)(int64_t x, int64_t y);
6970

71+
#ifdef _WIN64
72+
static const v8::internal::Register arg1 = rcx;
73+
static const v8::internal::Register arg2 = rdx;
74+
#else
75+
static const v8::internal::Register arg1 = rdi;
76+
static const v8::internal::Register arg2 = rsi;
77+
#endif
78+
7079
#define __ assm.
7180

7281

@@ -80,7 +89,7 @@ TEST(AssemblerX64ReturnOperation) {
8089
Assembler assm(buffer, actual_size);
8190

8291
// Assemble a simple function that copies argument 2 and returns it.
83-
__ movq(rax, rsi);
92+
__ movq(rax, arg2);
8493
__ nop();
8594
__ ret(0);
8695

@@ -105,9 +114,9 @@ TEST(AssemblerX64StackOperations) {
105114
// incorrect stack frames when debugging this function (which has them).
106115
__ push(rbp);
107116
__ movq(rbp, rsp);
108-
__ push(rsi); // Value at (rbp - 8)
109-
__ push(rsi); // Value at (rbp - 16)
110-
__ push(rdi); // Value at (rbp - 24)
117+
__ push(arg2); // Value at (rbp - 8)
118+
__ push(arg2); // Value at (rbp - 16)
119+
__ push(arg1); // Value at (rbp - 24)
111120
__ pop(rax);
112121
__ pop(rax);
113122
__ pop(rax);
@@ -132,8 +141,8 @@ TEST(AssemblerX64ArithmeticOperations) {
132141
Assembler assm(buffer, actual_size);
133142

134143
// Assemble a simple function that adds arguments returning the sum.
135-
__ movq(rax, rsi);
136-
__ addq(rax, rdi);
144+
__ movq(rax, arg2);
145+
__ addq(rax, arg1);
137146
__ ret(0);
138147

139148
CodeDesc desc;
@@ -154,8 +163,8 @@ TEST(AssemblerX64ImulOperation) {
154163

155164
// Assemble a simple function that multiplies arguments returning the high
156165
// word.
157-
__ movq(rax, rsi);
158-
__ imul(rdi);
166+
__ movq(rax, arg2);
167+
__ imul(arg1);
159168
__ movq(rax, rdx);
160169
__ ret(0);
161170

@@ -182,14 +191,16 @@ TEST(AssemblerX64MemoryOperands) {
182191
// Assemble a simple function that copies argument 2 and returns it.
183192
__ push(rbp);
184193
__ movq(rbp, rsp);
185-
__ push(rsi); // Value at (rbp - 8)
186-
__ push(rsi); // Value at (rbp - 16)
187-
__ push(rdi); // Value at (rbp - 24)
194+
195+
__ push(arg2); // Value at (rbp - 8)
196+
__ push(arg2); // Value at (rbp - 16)
197+
__ push(arg1); // Value at (rbp - 24)
198+
188199
const int kStackElementSize = 8;
189200
__ movq(rax, Operand(rbp, -3 * kStackElementSize));
190-
__ pop(rsi);
191-
__ pop(rsi);
192-
__ pop(rsi);
201+
__ pop(arg2);
202+
__ pop(arg2);
203+
__ pop(arg2);
193204
__ pop(rbp);
194205
__ nop();
195206
__ ret(0);
@@ -210,13 +221,14 @@ TEST(AssemblerX64ControlFlow) {
210221
CHECK(buffer);
211222
Assembler assm(buffer, actual_size);
212223

213-
// Assemble a simple function that copies argument 2 and returns it.
224+
// Assemble a simple function that copies argument 1 and returns it.
214225
__ push(rbp);
226+
215227
__ movq(rbp, rsp);
216-
__ movq(rax, rdi);
228+
__ movq(rax, arg1);
217229
Label target;
218230
__ jmp(&target);
219-
__ movq(rax, rsi);
231+
__ movq(rax, arg2);
220232
__ bind(&target);
221233
__ pop(rbp);
222234
__ ret(0);

0 commit comments

Comments
 (0)