| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 static v8::Persistent<v8::Context> env; | 43 static v8::Persistent<v8::Context> env; |
| 44 | 44 |
| 45 static void InitializeVM() { | 45 static void InitializeVM() { |
| 46 if (env.IsEmpty()) { | 46 if (env.IsEmpty()) { |
| 47 env = v8::Context::New(); | 47 env = v8::Context::New(); |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 | 51 |
| 52 bool DisassembleAndCompare(byte* pc, const char* compare_string) { | 52 bool DisassembleAndCompare(byte* pc, const char* compare_string) { |
| 53 disasm::Disassembler disasm; | 53 disasm::NameConverter converter; |
| 54 disasm::Disassembler disasm(converter); |
| 54 EmbeddedVector<char, 128> disasm_buffer; | 55 EmbeddedVector<char, 128> disasm_buffer; |
| 55 | 56 |
| 56 disasm.InstructionDecode(disasm_buffer, pc); | 57 disasm.InstructionDecode(disasm_buffer, pc); |
| 57 | 58 |
| 58 if (strcmp(compare_string, disasm_buffer.start()) != 0) { | 59 if (strcmp(compare_string, disasm_buffer.start()) != 0) { |
| 59 fprintf(stderr, | 60 fprintf(stderr, |
| 60 "expected: \n" | 61 "expected: \n" |
| 61 "%s\n" | 62 "%s\n" |
| 62 "disassembled: \n" | 63 "disassembled: \n" |
| 63 "%s\n\n", | 64 "%s\n\n", |
| 64 compare_string, disasm_buffer.start()); | 65 compare_string, disasm_buffer.start()); |
| 65 return false; | 66 return false; |
| 66 } | 67 } |
| 67 return true; | 68 return true; |
| 68 } | 69 } |
| 69 | 70 |
| 70 | 71 |
| 72 // Setup V8 to a state where we can at least run the assembler and |
| 73 // disassembler. Declare the variables and allocate the data structures used |
| 74 // in the rest of the macros. |
| 71 #define SETUP() \ | 75 #define SETUP() \ |
| 72 InitializeVM(); \ | 76 InitializeVM(); \ |
| 73 Serializer::disable(); \ | 77 Serializer::disable(); \ |
| 74 v8::HandleScope scope; \ | 78 v8::HandleScope scope; \ |
| 75 byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \ | 79 byte *buffer = reinterpret_cast<byte*>(malloc(4*1024)); \ |
| 76 Assembler assm(buffer, 4*1024); \ | 80 Assembler assm(buffer, 4*1024); \ |
| 77 bool failure = false; | 81 bool failure = false; |
| 78 | 82 |
| 79 | 83 |
| 84 // This macro assembles one instruction using the preallocated assembler and |
| 85 // disassembles the generated instruction, comparing the output to the expected |
| 86 // value. If the comparison fails an error message is printed, but the test |
| 87 // continues to run until the end. |
| 80 #define COMPARE(asm_, compare_string) \ | 88 #define COMPARE(asm_, compare_string) \ |
| 81 { \ | 89 { \ |
| 82 int pc_offset = assm.pc_offset(); \ | 90 int pc_offset = assm.pc_offset(); \ |
| 83 byte *pc = &buffer[pc_offset]; \ | 91 byte *pc = &buffer[pc_offset]; \ |
| 84 assm.asm_; \ | 92 assm.asm_; \ |
| 85 if (!DisassembleAndCompare(pc, compare_string)) failure = true; \ | 93 if (!DisassembleAndCompare(pc, compare_string)) failure = true; \ |
| 86 } | 94 } |
| 87 | 95 |
| 88 | 96 |
| 89 #define OUTPUT() \ | 97 // Verify that all invocations of the COMPARE macro passed successfully. |
| 90 if (failure) { \ | 98 // Exit with a failure if at least one of the tests failed. |
| 99 #define VERIFY_RUN() \ |
| 100 if (failure) { \ |
| 91 V8_Fatal(__FILE__, __LINE__, "ARM Disassembler tests failed.\n"); \ | 101 V8_Fatal(__FILE__, __LINE__, "ARM Disassembler tests failed.\n"); \ |
| 92 } | 102 } |
| 93 | 103 |
| 94 | 104 |
| 95 TEST(Type0) { | 105 TEST(Type0) { |
| 96 SETUP(); | 106 SETUP(); |
| 97 | 107 |
| 98 COMPARE(and_(r0, r1, Operand(r2)), | 108 COMPARE(and_(r0, r1, Operand(r2)), |
| 99 "e0010002 and r0, r1, r2"); | 109 "e0010002 and r0, r1, r2"); |
| 100 COMPARE(and_(r1, r2, Operand(r3), LeaveCC), | 110 COMPARE(and_(r1, r2, Operand(r3), LeaveCC), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 242 |
| 233 COMPARE(mvn(r10, Operand(r1)), | 243 COMPARE(mvn(r10, Operand(r1)), |
| 234 "e1e0a001 mvn sl, r1"); | 244 "e1e0a001 mvn sl, r1"); |
| 235 COMPARE(mvn(r9, Operand(r2)), | 245 COMPARE(mvn(r9, Operand(r2)), |
| 236 "e1e09002 mvn r9, r2"); | 246 "e1e09002 mvn r9, r2"); |
| 237 COMPARE(mvn(r0, Operand(r3), SetCC), | 247 COMPARE(mvn(r0, Operand(r3), SetCC), |
| 238 "e1f00003 mvns r0, r3"); | 248 "e1f00003 mvns r0, r3"); |
| 239 COMPARE(mvn(r5, Operand(r4), SetCC, cc), | 249 COMPARE(mvn(r5, Operand(r4), SetCC, cc), |
| 240 "31f05004 mvnccs r5, r4"); | 250 "31f05004 mvnccs r5, r4"); |
| 241 | 251 |
| 242 OUTPUT(); | 252 VERIFY_RUN(); |
| 243 } | 253 } |
| 244 | 254 |
| 245 | 255 |
| 246 TEST(Type1) { | 256 TEST(Type1) { |
| 247 SETUP(); | 257 SETUP(); |
| 248 | 258 |
| 249 COMPARE(and_(r0, r1, Operand(0x00000000)), | 259 COMPARE(and_(r0, r1, Operand(0x00000000)), |
| 250 "e2010000 and r0, r1, #0"); | 260 "e2010000 and r0, r1, #0"); |
| 251 COMPARE(and_(r1, r2, Operand(0x00000001), LeaveCC), | 261 COMPARE(and_(r1, r2, Operand(0x00000001), LeaveCC), |
| 252 "e2021001 and r1, r2, #1"); | 262 "e2021001 and r1, r2, #1"); |
| 253 COMPARE(and_(r2, r3, Operand(0x00000010), SetCC), | 263 COMPARE(and_(r2, r3, Operand(0x00000010), SetCC), |
| 254 "e2132010 ands r2, r3, #16"); | 264 "e2132010 ands r2, r3, #16"); |
| 255 COMPARE(and_(r3, r4, Operand(0x00000100), LeaveCC, eq), | 265 COMPARE(and_(r3, r4, Operand(0x00000100), LeaveCC, eq), |
| 256 "02043c01 andeq r3, r4, #256"); | 266 "02043c01 andeq r3, r4, #256"); |
| 257 COMPARE(and_(r4, r5, Operand(0x00001000), SetCC, ne), | 267 COMPARE(and_(r4, r5, Operand(0x00001000), SetCC, ne), |
| 258 "12154a01 andnes r4, r5, #4096"); | 268 "12154a01 andnes r4, r5, #4096"); |
| 259 | 269 |
| 260 COMPARE(eor(r4, r5, Operand(0x00001000)), | 270 COMPARE(eor(r4, r5, Operand(0x00001000)), |
| 261 "e2254a01 eor r4, r5, #4096"); | 271 "e2254a01 eor r4, r5, #4096"); |
| 262 COMPARE(eor(r4, r4, Operand(0x00010000), LeaveCC), | 272 COMPARE(eor(r4, r4, Operand(0x00010000), LeaveCC), |
| 263 "e2244801 eor r4, r4, #65536"); | 273 "e2244801 eor r4, r4, #65536"); |
| 264 COMPARE(eor(r4, r3, Operand(0x00100000), SetCC), | 274 COMPARE(eor(r4, r3, Operand(0x00100000), SetCC), |
| 265 "e2334601 eors r4, r3, #1048576"); | 275 "e2334601 eors r4, r3, #1048576"); |
| 266 COMPARE(eor(r4, r2, Operand(0x01000000), LeaveCC, cs), | 276 COMPARE(eor(r4, r2, Operand(0x01000000), LeaveCC, cs), |
| 267 "22224401 eorcs r4, r2, #16777216"); | 277 "22224401 eorcs r4, r2, #16777216"); |
| 268 COMPARE(eor(r4, r1, Operand(0x10000000), SetCC, cc), | 278 COMPARE(eor(r4, r1, Operand(0x10000000), SetCC, cc), |
| 269 "32314201 eorccs r4, r1, #268435456"); | 279 "32314201 eorccs r4, r1, #268435456"); |
| 270 | 280 |
| 271 OUTPUT(); | 281 VERIFY_RUN(); |
| 272 } | 282 } |
| OLD | NEW |