Changeset 2081 for rtcg/trunk/src/newasm.c
- Timestamp:
- 01/19/10 14:59:03 (2 years ago)
- Files:
-
- 1 modified
-
rtcg/trunk/src/newasm.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
rtcg/trunk/src/newasm.c
r2079 r2081 2 2 #include <stdlib.h> 3 3 #include <string.h> 4 5 #include <debug.h> 6 7 #include <x86/modrm.h> 4 8 5 9 #include "asm.h" … … 84 88 case INSTR_SUB: 85 89 { 86 int modRm=instruction[1];87 88 90 unsigned char mod, reg, rm; 89 91 90 AsmModRm( modRm, &mod, ®, &rm);91 92 if (modRm & 0x80)92 AsmModRm(instruction[1], &mod, ®, &rm); 93 94 switch (mod) 93 95 { 94 instruction+=3; 95 96 ins->operandTypes=(INSTR_REG << DEST_SHIFT) | INSTR_IMM; 97 ins->regDest = reg; 98 ins->imSrc = 0; 99 }else{ 100 instruction+=5; 101 ins->operandTypes=(INSTR_MEMR << DEST_SHIFT) | INSTR_IMM; 102 ins->regDest=ASM_REG_ESP; 103 ins->disp=8; 104 ins->imSrc=0; 96 case MOD_REG_MEM: 97 ins->operandTypes = (INSTR_REG << DEST_SHIFT) | 98 INSTR_MEMR; 99 100 ins->regDest = reg; 101 ins->imSrc = (int)instruction[3]; 102 103 instruction += AsmModRmBytes(instruction[1]); 104 instruction++; /* FIX */ 105 106 break; 107 108 case MOD_REG_MEM_BYTE: 109 break; 110 111 case MOD_REG_MEM_WORD: 112 break; 113 114 case MOD_REG: 115 instruction += 3; 116 ins->operandTypes=(INSTR_REG << DEST_SHIFT) | INSTR_IMM; 117 ins->regDest = reg; 118 119 /* FIXME: Check for different sizes of operand */ 120 ins->imSrc = (int)instruction[2]; 121 break; 122 123 default: 124 instruction+=5; 125 ins->operandTypes=(INSTR_MEMR << DEST_SHIFT) | INSTR_IMM; 126 ins->regDest=ASM_REG_ESP; 127 ins->disp=8; 128 ins->imSrc=0; 105 129 } 106 130 … … 171 195 172 196 ins->operandTypes=(INSTR_REG << DEST_SHIFT) | INSTR_IMM; 173 197 198 /* FIXME: May be wrong */ 174 199 memcpy(&ins->imSrc, &instruction[1], 4); 175 200 ins->regDest=ASM_REG_EAX; … … 196 221 } 197 222 198 if (curr == curr->next)199 break;200 201 printf("curr = %#X, next = %#X\n", curr, curr->next);202 223 curr=curr->next; 203 224 } 204 225 } 205 226 227 /* 228 * AsmClearDeadCode 229 * 230 * If there are no references to a block, delete it. This may happen 231 * because an if test now returns a constant value 232 */ 233 206 234 void AsmClearDeadCode(struct AsmContext* context) 207 235 { 236 TRACE_ENTER(); 237 208 238 struct AsmBlock* curr=context->head; 209 239 … … 219 249 free(curr->prev); 220 250 } 251 252 TRACE_EXIT(); 221 253 } 222 254 223 255 void AsmAddConstantsBlock(struct AsmContext* context, struct AsmBlock* block, unsigned long* regValues[]) 224 256 { 257 TRACE_ENTER(); 258 225 259 int i; 226 260 struct AsmInstruction* testIns=NULL; 227 261 228 /* TODO: Better solution? */229 262 unsigned long* stack[16]; 230 263 int currP=0; … … 261 294 { 262 295 int param=(ins->disp >> *regValues[ASM_REG_ESP])-1; 263 printf("disp = %d, param %d, % d\n", ins->disp, param, *regValues[ASM_REG_ESP]);296 printf("disp = %d, param %d, %lu\n", ins->disp, param, *regValues[ASM_REG_ESP]); 264 297 265 298 regValues[ins->regDest]=&context->params[param]; … … 341 374 342 375 out: 376 TRACE_EXIT(); 343 377 return; 344 378 } … … 346 380 void AsmAddConstants(struct AsmContext* context) 347 381 { 382 TRACE_ENTER(); 383 348 384 unsigned long* regValues[8]; 349 385 int paramOffset=2; 350 351 regValues[ASM_REG_ESP]= ¶mOffset;386 387 regValues[ASM_REG_ESP]=(unsigned long*)¶mOffset; 352 388 353 389 AsmAddConstantsBlock(context, context->head, regValues); 390 391 TRACE_EXIT(); 354 392 } 355 393 … … 454 492 } 455 493 494 /* Main function */ 456 495 void* AsmGenerate(struct AsmContext* context) 457 496 { … … 464 503 /* Dead code elimination. Remove blocks with no references. */ 465 504 AsmClearDeadCode(context); 466 467 505 AsmMergeBlocks(context); 468 469 506 AsmRemoveUnused(context); 470 507 471 length =AsmWriteCode(context, out);508 length = AsmWriteCode(context, out); 472 509 473 510 printf("Function length: %u bytes.\n", length); … … 475 512 AsmPrintCode(out, length); 476 513 477 /* Check if we're at the end of the function. */478 479 // free(out);480 481 514 return out; 482 515 }
