Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: src/trusted/validator_ragel/unreviewed/decoder-test.c

Issue 9968039: Add ragel machine generators to SCONS (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <elf.h>
9 #include <inttypes.h>
10 #include <stdio.h> 8 #include <stdio.h>
11 #include <stdlib.h> 9 #include <stdlib.h>
12 #include <string.h> 10 #include <string.h>
13 #include "decoder.h" 11
12 #include "native_client/src/include/elf32.h"
13 #include "native_client/src/include/elf64.h"
14 #include "native_client/src/trusted/validator_ragel/unreviewed/decoder.h"
14 15
15 #undef TRUE 16 #undef TRUE
16 #define TRUE 1 17 #define TRUE 1
17 18
18 #undef FALSE 19 #undef FALSE
19 #define FALSE 0 20 #define FALSE 0
20 21
21 static void CheckBounds(unsigned char *data, size_t data_size, 22 static void CheckBounds(unsigned char *data, size_t data_size,
22 void *ptr, size_t inside_size) { 23 void *ptr, size_t inside_size) {
23 assert(data <= (unsigned char *) ptr); 24 assert(data <= (unsigned char *) ptr);
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 instruction->operands[i].name -= 8; 524 instruction->operands[i].name -= 8;
524 --rex_bits; 525 --rex_bits;
525 } 526 }
526 } 527 }
527 } 528 }
528 } 529 }
529 } else if (instruction->operands[i].name == REG_RM) { 530 } else if (instruction->operands[i].name == REG_RM) {
530 if ((instruction->rm.base >= REG_R8) && 531 if ((instruction->rm.base >= REG_R8) &&
531 (instruction->rm.base <= REG_R15)) { 532 (instruction->rm.base <= REG_R15)) {
532 ++rex_bits; 533 ++rex_bits;
533 } else if ((instruction->rm.base == REG_NONE) || 534 } else if ((instruction->rm.base == NO_REG) ||
534 (instruction->rm.base == REG_RIP)) { 535 (instruction->rm.base == REG_RIP)) {
535 ++maybe_rex_bits; 536 ++maybe_rex_bits;
536 } 537 }
537 if ((instruction->rm.index >= REG_R8) && 538 if ((instruction->rm.index >= REG_R8) &&
538 (instruction->rm.index <= REG_R15)) { 539 (instruction->rm.index <= REG_R15)) {
539 ++rex_bits; 540 ++rex_bits;
540 } 541 }
541 } 542 }
542 } 543 }
543 } 544 }
(...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 break; 1146 break;
1146 case REG_ST: 1147 case REG_ST:
1147 assert(operand_type == OperandST); 1148 assert(operand_type == OperandST);
1148 printf("%%st"); 1149 printf("%%st");
1149 break; 1150 break;
1150 case REG_RM: { 1151 case REG_RM: {
1151 if (instruction->rm.offset) { 1152 if (instruction->rm.offset) {
1152 printf("0x%"PRIx64, instruction->rm.offset); 1153 printf("0x%"PRIx64, instruction->rm.offset);
1153 } 1154 }
1154 if (((struct DecodeState *)userdata)->ia32_mode) { 1155 if (((struct DecodeState *)userdata)->ia32_mode) {
1155 if ((instruction->rm.base != REG_NONE) || 1156 if ((instruction->rm.base != NO_REG) ||
1156 (instruction->rm.index != REG_NONE) || 1157 (instruction->rm.index != NO_REG) ||
1157 (instruction->rm.scale != 0)) { 1158 (instruction->rm.scale != 0)) {
1158 printf("("); 1159 printf("(");
1159 } 1160 }
1160 switch (instruction->rm.base) { 1161 switch (instruction->rm.base) {
1161 case REG_RAX: printf("%%eax"); break; 1162 case REG_RAX: printf("%%eax"); break;
1162 case REG_RCX: printf("%%ecx"); break; 1163 case REG_RCX: printf("%%ecx"); break;
1163 case REG_RDX: printf("%%edx"); break; 1164 case REG_RDX: printf("%%edx"); break;
1164 case REG_RBX: printf("%%ebx"); break; 1165 case REG_RBX: printf("%%ebx"); break;
1165 case REG_RSP: printf("%%esp"); break; 1166 case REG_RSP: printf("%%esp"); break;
1166 case REG_RBP: printf("%%ebp"); break; 1167 case REG_RBP: printf("%%ebp"); break;
1167 case REG_RSI: printf("%%esi"); break; 1168 case REG_RSI: printf("%%esi"); break;
1168 case REG_RDI: printf("%%edi"); break; 1169 case REG_RDI: printf("%%edi"); break;
1169 case REG_NONE: break; 1170 case NO_REG: break;
1170 case REG_R8: 1171 case REG_R8:
1171 case REG_R9: 1172 case REG_R9:
1172 case REG_R10: 1173 case REG_R10:
1173 case REG_R11: 1174 case REG_R11:
1174 case REG_R12: 1175 case REG_R12:
1175 case REG_R13: 1176 case REG_R13:
1176 case REG_R14: 1177 case REG_R14:
1177 case REG_R15: 1178 case REG_R15:
1178 case REG_RIP: 1179 case REG_RIP:
1179 case REG_RM: 1180 case REG_RM:
(...skipping 14 matching lines...) Expand all
1194 case REG_RDX: printf(",%%edx,%d",1<<instruction->rm.scale); break; 1195 case REG_RDX: printf(",%%edx,%d",1<<instruction->rm.scale); break;
1195 case REG_RBX: printf(",%%ebx,%d",1<<instruction->rm.scale); break; 1196 case REG_RBX: printf(",%%ebx,%d",1<<instruction->rm.scale); break;
1196 case REG_RSP: printf(",%%esp,%d",1<<instruction->rm.scale); break; 1197 case REG_RSP: printf(",%%esp,%d",1<<instruction->rm.scale); break;
1197 case REG_RBP: printf(",%%ebp,%d",1<<instruction->rm.scale); break; 1198 case REG_RBP: printf(",%%ebp,%d",1<<instruction->rm.scale); break;
1198 case REG_RSI: printf(",%%esi,%d",1<<instruction->rm.scale); break; 1199 case REG_RSI: printf(",%%esi,%d",1<<instruction->rm.scale); break;
1199 case REG_RDI: printf(",%%edi,%d",1<<instruction->rm.scale); break; 1200 case REG_RDI: printf(",%%edi,%d",1<<instruction->rm.scale); break;
1200 case REG_RIZ: if ((instruction->rm.base != REG_RSP) || 1201 case REG_RIZ: if ((instruction->rm.base != REG_RSP) ||
1201 (instruction->rm.scale != 0)) 1202 (instruction->rm.scale != 0))
1202 printf(",%%eiz,%d",1<<instruction->rm.scale); 1203 printf(",%%eiz,%d",1<<instruction->rm.scale);
1203 break; 1204 break;
1204 case REG_NONE: break; 1205 case NO_REG: break;
1205 case REG_R8: 1206 case REG_R8:
1206 case REG_R9: 1207 case REG_R9:
1207 case REG_R10: 1208 case REG_R10:
1208 case REG_R11: 1209 case REG_R11:
1209 case REG_R12: 1210 case REG_R12:
1210 case REG_R13: 1211 case REG_R13:
1211 case REG_R14: 1212 case REG_R14:
1212 case REG_R15: 1213 case REG_R15:
1213 case REG_RM: 1214 case REG_RM:
1214 case REG_RIP: 1215 case REG_RIP:
1215 case REG_IMM: 1216 case REG_IMM:
1216 case REG_IMM2: 1217 case REG_IMM2:
1217 case REG_DS_RBX: 1218 case REG_DS_RBX:
1218 case REG_ES_RDI: 1219 case REG_ES_RDI:
1219 case REG_DS_RSI: 1220 case REG_DS_RSI:
1220 case REG_PORT_DX: 1221 case REG_PORT_DX:
1221 case REG_ST: 1222 case REG_ST:
1222 case JMP_TO: 1223 case JMP_TO:
1223 assert(FALSE); 1224 assert(FALSE);
1224 } 1225 }
1225 if ((instruction->rm.base != REG_NONE) || 1226 if ((instruction->rm.base != NO_REG) ||
1226 (instruction->rm.index != REG_NONE) || 1227 (instruction->rm.index != NO_REG) ||
1227 (instruction->rm.scale != 0)) { 1228 (instruction->rm.scale != 0)) {
1228 printf(")"); 1229 printf(")");
1229 } 1230 }
1230 } else { 1231 } else {
1231 if ((instruction->rm.base != REG_NONE) || 1232 if ((instruction->rm.base != NO_REG) ||
1232 (instruction->rm.index != REG_RIZ) || 1233 (instruction->rm.index != REG_RIZ) ||
1233 (instruction->rm.scale != 0)) { 1234 (instruction->rm.scale != 0)) {
1234 printf("("); 1235 printf("(");
1235 } 1236 }
1236 switch (instruction->rm.base) { 1237 switch (instruction->rm.base) {
1237 case REG_RAX: printf("%%rax"); break; 1238 case REG_RAX: printf("%%rax"); break;
1238 case REG_RCX: printf("%%rcx"); break; 1239 case REG_RCX: printf("%%rcx"); break;
1239 case REG_RDX: printf("%%rdx"); break; 1240 case REG_RDX: printf("%%rdx"); break;
1240 case REG_RBX: printf("%%rbx"); break; 1241 case REG_RBX: printf("%%rbx"); break;
1241 case REG_RSP: printf("%%rsp"); break; 1242 case REG_RSP: printf("%%rsp"); break;
1242 case REG_RBP: printf("%%rbp"); break; 1243 case REG_RBP: printf("%%rbp"); break;
1243 case REG_RSI: printf("%%rsi"); break; 1244 case REG_RSI: printf("%%rsi"); break;
1244 case REG_RDI: printf("%%rdi"); break; 1245 case REG_RDI: printf("%%rdi"); break;
1245 case REG_R8: printf("%%r8"); break; 1246 case REG_R8: printf("%%r8"); break;
1246 case REG_R9: printf("%%r9"); break; 1247 case REG_R9: printf("%%r9"); break;
1247 case REG_R10: printf("%%r10"); break; 1248 case REG_R10: printf("%%r10"); break;
1248 case REG_R11: printf("%%r11"); break; 1249 case REG_R11: printf("%%r11"); break;
1249 case REG_R12: printf("%%r12"); break; 1250 case REG_R12: printf("%%r12"); break;
1250 case REG_R13: printf("%%r13"); break; 1251 case REG_R13: printf("%%r13"); break;
1251 case REG_R14: printf("%%r14"); break; 1252 case REG_R14: printf("%%r14"); break;
1252 case REG_R15: printf("%%r15"); break; 1253 case REG_R15: printf("%%r15"); break;
1253 case REG_RIP: printf("%%rip"); print_rip = TRUE; break; 1254 case REG_RIP: printf("%%rip"); print_rip = TRUE; break;
1254 case REG_NONE: break; 1255 case NO_REG: break;
1255 case REG_RM: 1256 case REG_RM:
1256 case REG_RIZ: 1257 case REG_RIZ:
1257 case REG_IMM: 1258 case REG_IMM:
1258 case REG_IMM2: 1259 case REG_IMM2:
1259 case REG_DS_RBX: 1260 case REG_DS_RBX:
1260 case REG_ES_RDI: 1261 case REG_ES_RDI:
1261 case REG_DS_RSI: 1262 case REG_DS_RSI:
1262 case REG_PORT_DX: 1263 case REG_PORT_DX:
1263 case REG_ST: 1264 case REG_ST:
1264 case JMP_TO: 1265 case JMP_TO:
1265 assert(FALSE); 1266 assert(FALSE);
1266 } 1267 }
1267 switch (instruction->rm.index) { 1268 switch (instruction->rm.index) {
1268 case REG_RAX: printf(",%%rax,%d",1<<instruction->rm.scale); break; 1269 case REG_RAX: printf(",%%rax,%d",1<<instruction->rm.scale); break;
1269 case REG_RCX: printf(",%%rcx,%d",1<<instruction->rm.scale); break; 1270 case REG_RCX: printf(",%%rcx,%d",1<<instruction->rm.scale); break;
1270 case REG_RDX: printf(",%%rdx,%d",1<<instruction->rm.scale); break; 1271 case REG_RDX: printf(",%%rdx,%d",1<<instruction->rm.scale); break;
1271 case REG_RBX: printf(",%%rbx,%d",1<<instruction->rm.scale); break; 1272 case REG_RBX: printf(",%%rbx,%d",1<<instruction->rm.scale); break;
1272 case REG_RSP: printf(",%%rsp,%d",1<<instruction->rm.scale); break; 1273 case REG_RSP: printf(",%%rsp,%d",1<<instruction->rm.scale); break;
1273 case REG_RBP: printf(",%%rbp,%d",1<<instruction->rm.scale); break; 1274 case REG_RBP: printf(",%%rbp,%d",1<<instruction->rm.scale); break;
1274 case REG_RSI: printf(",%%rsi,%d",1<<instruction->rm.scale); break; 1275 case REG_RSI: printf(",%%rsi,%d",1<<instruction->rm.scale); break;
1275 case REG_RDI: printf(",%%rdi,%d",1<<instruction->rm.scale); break; 1276 case REG_RDI: printf(",%%rdi,%d",1<<instruction->rm.scale); break;
1276 case REG_R8: printf(",%%r8,%d",1<<instruction->rm.scale); break; 1277 case REG_R8: printf(",%%r8,%d",1<<instruction->rm.scale); break;
1277 case REG_R9: printf(",%%r9,%d",1<<instruction->rm.scale); break; 1278 case REG_R9: printf(",%%r9,%d",1<<instruction->rm.scale); break;
1278 case REG_R10: printf(",%%r10,%d",1<<instruction->rm.scale); break; 1279 case REG_R10: printf(",%%r10,%d",1<<instruction->rm.scale); break;
1279 case REG_R11: printf(",%%r11,%d",1<<instruction->rm.scale); break; 1280 case REG_R11: printf(",%%r11,%d",1<<instruction->rm.scale); break;
1280 case REG_R12: printf(",%%r12,%d",1<<instruction->rm.scale); break; 1281 case REG_R12: printf(",%%r12,%d",1<<instruction->rm.scale); break;
1281 case REG_R13: printf(",%%r13,%d",1<<instruction->rm.scale); break; 1282 case REG_R13: printf(",%%r13,%d",1<<instruction->rm.scale); break;
1282 case REG_R14: printf(",%%r14,%d",1<<instruction->rm.scale); break; 1283 case REG_R14: printf(",%%r14,%d",1<<instruction->rm.scale); break;
1283 case REG_R15: printf(",%%r15,%d",1<<instruction->rm.scale); break; 1284 case REG_R15: printf(",%%r15,%d",1<<instruction->rm.scale); break;
1284 case REG_RIZ: if (((instruction->rm.base != REG_NONE) && 1285 case REG_RIZ: if (((instruction->rm.base != NO_REG) &&
1285 (instruction->rm.base != REG_RSP) && 1286 (instruction->rm.base != REG_RSP) &&
1286 (instruction->rm.base != REG_R12)) || 1287 (instruction->rm.base != REG_R12)) ||
1287 (instruction->rm.scale != 0)) 1288 (instruction->rm.scale != 0))
1288 printf(",%%riz,%d",1<<instruction->rm.scale); 1289 printf(",%%riz,%d",1<<instruction->rm.scale);
1289 break; 1290 break;
1290 case REG_NONE: break; 1291 case NO_REG: break;
1291 case REG_RM: 1292 case REG_RM:
1292 case REG_RIP: 1293 case REG_RIP:
1293 case REG_IMM: 1294 case REG_IMM:
1294 case REG_IMM2: 1295 case REG_IMM2:
1295 case REG_DS_RBX: 1296 case REG_DS_RBX:
1296 case REG_ES_RDI: 1297 case REG_ES_RDI:
1297 case REG_DS_RSI: 1298 case REG_DS_RSI:
1298 case REG_PORT_DX: 1299 case REG_PORT_DX:
1299 case REG_ST: 1300 case REG_ST:
1300 case JMP_TO: 1301 case JMP_TO:
1301 assert(FALSE); 1302 assert(FALSE);
1302 } 1303 }
1303 if ((instruction->rm.base != REG_NONE) || 1304 if ((instruction->rm.base != NO_REG) ||
1304 (instruction->rm.index != REG_RIZ) || 1305 (instruction->rm.index != REG_RIZ) ||
1305 (instruction->rm.scale != 0)) { 1306 (instruction->rm.scale != 0)) {
1306 printf(")"); 1307 printf(")");
1307 } 1308 }
1308 } 1309 }
1309 } 1310 }
1310 break; 1311 break;
1311 case REG_IMM: { 1312 case REG_IMM: {
1312 printf("$0x%"PRIx64,instruction->imm[0]); 1313 printf("$0x%"PRIx64,instruction->imm[0]);
1313 break; 1314 break;
(...skipping 23 matching lines...) Expand all
1337 break; 1338 break;
1338 case JMP_TO: if (instruction->operands[0].type == OperandSize16bit) 1339 case JMP_TO: if (instruction->operands[0].type == OperandSize16bit)
1339 printf("0x%zx", ((end + instruction->rm.offset - 1340 printf("0x%zx", ((end + instruction->rm.offset -
1340 (((struct DecodeState *)userdata)->offset)) & 0xffff)); 1341 (((struct DecodeState *)userdata)->offset)) & 0xffff));
1341 else 1342 else
1342 printf("0x%zx", (end + instruction->rm.offset - 1343 printf("0x%zx", (end + instruction->rm.offset -
1343 (((struct DecodeState *)userdata)->offset))); 1344 (((struct DecodeState *)userdata)->offset)));
1344 break; 1345 break;
1345 case REG_RIP: 1346 case REG_RIP:
1346 case REG_RIZ: 1347 case REG_RIZ:
1347 case REG_NONE: 1348 case NO_REG:
1348 assert(FALSE); 1349 assert(FALSE);
1349 } 1350 }
1350 delimeter = ','; 1351 delimeter = ',';
1351 } 1352 }
1352 if (print_rip) { 1353 if (print_rip) {
1353 printf(" # 0x%8"PRIx64, 1354 printf(" # 0x%8"PRIx64,
1354 (uint64_t) (end + instruction->rm.offset - 1355 (uint64_t) (end + instruction->rm.offset -
1355 (((struct DecodeState *)userdata)->offset))); 1356 (((struct DecodeState *)userdata)->offset)));
1356 } 1357 }
1357 printf("\n"); 1358 printf("\n");
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 for (index = initial_index; index < argc; ++index) { 1495 for (index = initial_index; index < argc; ++index) {
1495 const char *filename = argv[index]; 1496 const char *filename = argv[index];
1496 int rc = DecodeFile(filename, repeat_count); 1497 int rc = DecodeFile(filename, repeat_count);
1497 if (rc != 0) { 1498 if (rc != 0) {
1498 printf("file '%s' can not be fully decoded\n", filename); 1499 printf("file '%s' can not be fully decoded\n", filename);
1499 return 1; 1500 return 1;
1500 } 1501 }
1501 } 1502 }
1502 return 0; 1503 return 0;
1503 } 1504 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698