| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "macro-assembler.h" | 30 #include "macro-assembler.h" |
| 31 | 31 |
| 32 namespace v8 { | 32 namespace v8 { |
| 33 namespace internal { | 33 namespace internal { |
| 34 | 34 |
| 35 Register no_reg = { -1 }; | 35 Register no_reg = { -1 }; |
| 36 Register rax = { 0 }; |
| 37 Register rcx = { 1 }; |
| 38 Register rsi = { 7 }; |
| 36 | 39 |
| 37 | 40 |
| 38 // Safe default is no features. | 41 // Safe default is no features. |
| 39 uint64_t CpuFeatures::supported_ = 0; | 42 uint64_t CpuFeatures::supported_ = 0; |
| 40 uint64_t CpuFeatures::enabled_ = 0; | 43 uint64_t CpuFeatures::enabled_ = 0; |
| 41 | 44 |
| 42 void CpuFeatures::Probe() { | 45 void CpuFeatures::Probe() { |
| 43 // TODO(X64): UNIMPLEMENTED | 46 // TODO(X64): UNIMPLEMENTED |
| 44 } | 47 } |
| 45 | 48 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 235 |
| 233 // Emit updated ModRM byte containing the given register. | 236 // Emit updated ModRM byte containing the given register. |
| 234 pc_[0] = (adr.buf_[0] & ~0x38) | ((reg.code() && 0x7) << 3); | 237 pc_[0] = (adr.buf_[0] & ~0x38) | ((reg.code() && 0x7) << 3); |
| 235 | 238 |
| 236 // Emit the rest of the encoded operand. | 239 // Emit the rest of the encoded operand. |
| 237 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; | 240 for (unsigned i = 1; i < length; i++) pc_[i] = adr.buf_[i]; |
| 238 pc_ += length; | 241 pc_ += length; |
| 239 } | 242 } |
| 240 | 243 |
| 241 | 244 |
| 242 void Assembler::int3() { | 245 void Assembler::add(Register dst, const Operand& src) { |
| 243 EnsureSpace ensure_space(this); | 246 EnsureSpace ensure_space(this); |
| 244 last_pc_ = pc_; | 247 last_pc_ = pc_; |
| 245 EMIT(0xCC); | 248 emit_rex_64(dst, src); |
| 249 EMIT(0x03); |
| 250 emit_operand(dst, src); |
| 251 } |
| 252 |
| 253 |
| 254 void Assembler::add(Register dst, Register src) { |
| 255 EnsureSpace ensure_space(this); |
| 256 last_pc_ = pc_; |
| 257 emit_rex_64(dst, src); |
| 258 EMIT(0x03); |
| 259 EMIT(0xC0 | (src.code() & 0x7) << 3 | (dst.code() & 0x7)); |
| 260 } |
| 261 |
| 262 |
| 263 void Assembler::dec(Register dst) { |
| 264 EnsureSpace ensure_space(this); |
| 265 last_pc_ = pc_; |
| 266 emit_rex_64(rcx, dst); |
| 267 EMIT(0xFF); |
| 268 EMIT(0xC8 | (dst.code() & 0x7)); |
| 269 } |
| 270 |
| 271 |
| 272 void Assembler::dec(const Operand& dst) { |
| 273 EnsureSpace ensure_space(this); |
| 274 last_pc_ = pc_; |
| 275 emit_rex_64(rax, dst); |
| 276 EMIT(0xFF); |
| 277 emit_operand(rcx, dst); |
| 246 } | 278 } |
| 247 | 279 |
| 248 | 280 |
| 249 void Assembler::hlt() { | 281 void Assembler::hlt() { |
| 250 EnsureSpace ensure_space(this); | 282 EnsureSpace ensure_space(this); |
| 251 last_pc_ = pc_; | 283 last_pc_ = pc_; |
| 252 EMIT(0xF4); | 284 EMIT(0xF4); |
| 253 } | 285 } |
| 254 | 286 |
| 255 | 287 |
| 256 void Assembler::nop() { | 288 void Assembler::inc(Register dst) { |
| 257 EnsureSpace ensure_space(this); | 289 EnsureSpace ensure_space(this); |
| 258 last_pc_ = pc_; | 290 last_pc_ = pc_; |
| 259 EMIT(0x90); | 291 emit_rex_64(rax, dst); |
| 292 EMIT(0xFF); |
| 293 EMIT(0xC0 | (dst.code() & 0x7)); |
| 260 } | 294 } |
| 261 | 295 |
| 262 | 296 |
| 263 void Assembler::ret(int imm16) { | 297 void Assembler::inc(const Operand& dst) { |
| 264 EnsureSpace ensure_space(this); | 298 EnsureSpace ensure_space(this); |
| 265 last_pc_ = pc_; | 299 last_pc_ = pc_; |
| 266 ASSERT(is_uint16(imm16)); | 300 emit_rex_64(rax, dst); |
| 267 if (imm16 == 0) { | 301 EMIT(0xFF); |
| 268 EMIT(0xC3); | 302 emit_operand(rax, dst); |
| 269 } else { | 303 } |
| 270 EMIT(0xC2); | 304 |
| 271 EMIT(imm16 & 0xFF); | 305 |
| 272 EMIT((imm16 >> 8) & 0xFF); | 306 void Assembler::int3() { |
| 273 } | 307 EnsureSpace ensure_space(this); |
| 308 last_pc_ = pc_; |
| 309 EMIT(0xCC); |
| 274 } | 310 } |
| 275 | 311 |
| 276 | 312 |
| 277 void Assembler::mov(Register dst, const Operand& src) { | 313 void Assembler::mov(Register dst, const Operand& src) { |
| 278 EnsureSpace ensure_space(this); | 314 EnsureSpace ensure_space(this); |
| 279 last_pc_ = pc_; | 315 last_pc_ = pc_; |
| 280 emit_rex_64(dst, src); | 316 emit_rex_64(dst, src); |
| 281 EMIT(0x8B); | 317 EMIT(0x8B); |
| 282 emit_operand(dst, src); | 318 emit_operand(dst, src); |
| 283 } | 319 } |
| 284 | 320 |
| 285 | 321 |
| 286 void Assembler::mov(Register dst, Register src) { | 322 void Assembler::mov(Register dst, Register src) { |
| 287 EnsureSpace ensure_space(this); | 323 EnsureSpace ensure_space(this); |
| 288 last_pc_ = pc_; | 324 last_pc_ = pc_; |
| 289 emit_rex_64(dst, src); | 325 emit_rex_64(dst, src); |
| 290 EMIT(0x89); | 326 EMIT(0x89); |
| 291 EMIT(0xC0 | (src.code() & 0x7) << 3 | (dst.code() & 0x7)); | 327 EMIT(0xC0 | (src.code() & 0x7) << 3 | (dst.code() & 0x7)); |
| 292 } | 328 } |
| 293 | 329 |
| 330 |
| 331 void Assembler::nop() { |
| 332 EnsureSpace ensure_space(this); |
| 333 last_pc_ = pc_; |
| 334 EMIT(0x90); |
| 335 } |
| 336 |
| 337 void Assembler::pop(Register dst) { |
| 338 EnsureSpace ensure_space(this); |
| 339 last_pc_ = pc_; |
| 340 if (dst.code() & 0x8) { |
| 341 emit_rex_64(rax, dst); |
| 342 } |
| 343 EMIT(0x58 | (dst.code() & 0x7)); |
| 344 } |
| 345 |
| 346 |
| 347 void Assembler::pop(const Operand& dst) { |
| 348 EnsureSpace ensure_space(this); |
| 349 last_pc_ = pc_; |
| 350 emit_rex_64(rax, dst); // Could be omitted in some cases. |
| 351 EMIT(0x8F); |
| 352 emit_operand(rax, dst); |
| 353 } |
| 354 |
| 355 |
| 356 void Assembler::push(Register src) { |
| 357 EnsureSpace ensure_space(this); |
| 358 last_pc_ = pc_; |
| 359 if (src.code() & 0x8) { |
| 360 emit_rex_64(rax, src); |
| 361 } |
| 362 EMIT(0x50 | (src.code() & 0x7)); |
| 363 } |
| 364 |
| 365 |
| 366 void Assembler::push(const Operand& src) { |
| 367 EnsureSpace ensure_space(this); |
| 368 last_pc_ = pc_; |
| 369 emit_rex_64(rsi, src); // Could be omitted in some cases. |
| 370 EMIT(0xFF); |
| 371 emit_operand(rsi, src); |
| 372 } |
| 373 |
| 374 |
| 375 void Assembler::ret(int imm16) { |
| 376 EnsureSpace ensure_space(this); |
| 377 last_pc_ = pc_; |
| 378 ASSERT(is_uint16(imm16)); |
| 379 if (imm16 == 0) { |
| 380 EMIT(0xC3); |
| 381 } else { |
| 382 EMIT(0xC2); |
| 383 EMIT(imm16 & 0xFF); |
| 384 EMIT((imm16 >> 8) & 0xFF); |
| 385 } |
| 386 } |
| 387 |
| 294 } } // namespace v8::internal | 388 } } // namespace v8::internal |
| 295 | 389 |
| 296 | 390 |
| 297 // TODO(x64): Implement and move these to their correct cc-files: | 391 // TODO(x64): Implement and move these to their correct cc-files: |
| 298 #include "ast.h" | 392 #include "ast.h" |
| 299 #include "bootstrapper.h" | 393 #include "bootstrapper.h" |
| 300 #include "codegen-inl.h" | 394 #include "codegen-inl.h" |
| 301 #include "cpu.h" | 395 #include "cpu.h" |
| 302 #include "debug.h" | 396 #include "debug.h" |
| 303 #include "disasm.h" | 397 #include "disasm.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 UNIMPLEMENTED(); | 667 UNIMPLEMENTED(); |
| 574 return NULL; | 668 return NULL; |
| 575 } | 669 } |
| 576 | 670 |
| 577 byte* JavaScriptFrame::GetCallerStackPointer() const { | 671 byte* JavaScriptFrame::GetCallerStackPointer() const { |
| 578 UNIMPLEMENTED(); | 672 UNIMPLEMENTED(); |
| 579 return NULL; | 673 return NULL; |
| 580 } | 674 } |
| 581 | 675 |
| 582 } } // namespace v8::internal | 676 } } // namespace v8::internal |
| OLD | NEW |