📄 dsmlib.c
字号:
break; case (REG|IMM): pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->ibuf; break; case (MODRM|IMM): case (MODRM|I8): case (MODRM|MMXRM|I8): pY->pOpr0 = pY->mbuf; pY->pOpr1 = pY->ibuf; break; case (MODRM|REG): case (MODRM|MMXREG): case (MODRM|SREG3): case (MODRM|EEE): case (MODRM|MMXREG|MMXRM): if ( (pX->pI->flag & DISR) || (pX->pI->flag & MMXRM) || (pX->pI->flag & MMXREG)) { if (pX->d) { pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->mbuf; } else { pY->pOpr0 = pY->mbuf; pY->pOpr1 = pY->rbuf; } } else { if ((pX->pI->type == itTestRManR) || (pX->pI->type == itBtR) || (pX->pI->type == itBtcR) || (pX->pI->type == itBtrR) || (pX->pI->type == itBtsR) || (pX->pI->type == itArpl)) { pY->pOpr0 = pY->mbuf; pY->pOpr1 = pY->rbuf; } else { pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->mbuf; } } break; case (MODRM|REG|I8): case (MODRM|REG|IMM): if ((pX->pI->type == itShldRMbyI) || (pX->pI->type == itShrdRMbyI)) { pY->pOpr0 = pY->mbuf; pY->pOpr1 = pY->rbuf; pY->pOpr2 = pY->ibuf; } else { pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->mbuf; pY->pOpr2 = pY->ibuf; } break; case (MODRM|REG|CL): pY->pOpr0 = pY->mbuf; pY->pOpr1 = pY->rbuf; pY->pOpr2 = "CL"; break; case (IMM|AX): pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->ibuf; break; case (MODRM|AX): pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->mbuf; break; case (MODRM|CL): pY->pOpr0 = pY->mbuf; pY->pOpr1 = "CL"; break; case (DIS|AX): if (pX->d) { pY->pOpr0 = pY->dbuf; pY->pOpr1 = pY->rbuf; } else { pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->dbuf; } break; case OFFSEL: case D16L8: pY->pOpr0 = pY->ibuf; pY->pOpr1 = pY->dbuf; break; case (FD|ST): if (pX->fd) { pY->pOpr0 = pY->rbuf; pY->pOpr1 = "ST"; } else { pY->pOpr0 = "ST"; pY->pOpr1 = pY->rbuf; } break; case (PORT|AX): if (pX->pI->type == itInF) { pY->pOpr0 = pY->rbuf; pY->pOpr1 = pY->ibuf; } else { pY->pOpr0 = pY->ibuf; pY->pOpr1 = pY->rbuf; } break; case (REG|AX): pY->pOpr0 = pY->ibuf; pY->pOpr1 = pY->rbuf; break; case AX: if (pX->pI->type == itInV) { pY->pOpr0 = pY->rbuf; pY->pOpr1 = "DX"; } else if (pX->pI->type == itOutV) { pY->pOpr0 = "DX"; pY->pOpr1 = pY->rbuf; } else pY->pOpr0 = pY->rbuf; break; case 0: break; default: printf ("dsmPrint error 0 flag=0x%x, ", flag); } /* tune up for the special case */ if ((pY->pOpr0 == pY->mbuf) && (pY->mbuf[0] == 0)) pY->pOpr0 = (char *)&pY->addr; if ((pY->pOpr1 == pY->mbuf) && (pY->mbuf[0] == 0)) pY->pOpr1 = (char *)&pY->addr; if ((pY->pOpr2 == pY->mbuf) && (pY->mbuf[0] == 0)) pY->pOpr2 = (char *)&pY->addr; /* tune up for "+(no-x1)" */ if (pY->mbuf[0] != 0) { pS = pY->mbuf; pD = pY->temp; for (ix = 0 ; ix < (int) (strlen (pY->mbuf)) ; ix++) { if ((*pS == '(') && (*(pS+1) == 'n') && (*(pS+2) == 'o')) { pS += 7; pD -= 1; } *pD++ = *pS++; if (*pS == 0) break; } bcopy (pY->temp, pY->mbuf, DSM_BUFSIZE32); } /* tune up for "+-" */ bzero ((char *)pY->temp, DSM_BUFSIZE32); if (pY->mbuf[0] != 0) { pS = pY->mbuf; pD = pY->temp; for (ix = 0 ; ix < (int) (strlen (pY->mbuf)) ; ix++) { if ((*pS == '+') && (*(pS+1) == '-')) pS += 1; *pD++ = *pS++; if (*pS == 0) break; } bcopy (pY->temp, pY->mbuf, DSM_BUFSIZE32); } /* print out the instruction */ printf ("%-12s ", pY->pOpc); if (pY->pOpr0 != 0) { if (pY->pOpr0 == (char *)&pY->addr) (*prtAddress) ((int)pX->pD + pY->len + pY->addr); else printf ("%s", pY->pOpr0); } if (pY->pOpr1 != 0) { printf (", "); if (pY->pOpr1 == (char *)&pY->addr) (*prtAddress) ((int)pX->pD + pY->len + pY->addr); else printf ("%s", pY->pOpr1); } if (pY->pOpr2 != 0) { printf (", "); if (pY->pOpr2 == (char *)&pY->addr) (*prtAddress) ((int)pX->pD + pY->len + pY->addr); else printf ("%s", pY->pOpr2); } printf ("\n"); return; }/********************************************************************************* nPrtAddress - print addresses as numbers** RETURNS: N/A*/LOCAL void nPrtAddress ( int address ) { printf ("%#x", address); }/**************************************************************************** dsmData - disassemble and print a byte as data** This routine disassembles and prints a single byte as data (that is,* as a .BYTE assembler directive) on standard out. The disassembled data will* be prepended with the address passed as a parameter.* * RETURNS : The number of words occupied by the data (always 1).*/int dsmData ( FAST UCHAR *pD, /* pointer to the data */ int address /* address prepended to data */ ) { FORMAT_X formatx; FORMAT_Y formaty; bzero ((char *)&formatx, sizeof (FORMAT_X)); bzero ((char *)&formaty, sizeof (FORMAT_Y)); formatx.pD = (char *)pD; formaty.len = 1; dsmPrint (&formatx, &formaty, nPrtAddress); return (1); }/********************************************************************************* dsmInst - disassemble and print a single instruction** This routine disassembles and prints a single instruction on standard* output. The function passed as parameter <prtAddress> is used to print any* operands that might be construed as addresses. The function could be a* subroutine that prints a number or looks up the address in a* symbol table. The disassembled instruction will be prepended with the* address passed as a parameter.* * If <prtAddress> is zero, dsmInst() will use a default routine that prints * addresses as hex numbers.** ADDRESS PRINTING ROUTINE* Many assembly language operands are addresses. In order to print these* addresses symbolically, dsmInst() calls a user-supplied routine, passed as a* parameter, to do the actual printing. The routine should be declared as:* .CS* void prtAddress (address)* int address; %* address to print *%* .CE* When called, the routine prints the address on standard out in either* numeric or symbolic form. For example, the address-printing routine used* by l() looks up the address in the system symbol table and prints the* symbol associated with it, if there is one. If not, it prints the address* as a hex number.* * If the <prtAddress> argument to dsmInst is NULL, a default print routine is* used, which prints the address as a hexadecimal number.* * The directive .DATA.H (DATA SHORT) is printed for unrecognized instructions.* * The effective address mode is not checked since when the instruction with* invalid address mode executed, an exception would happen.* * INCLUDE FILE: dsmLib.h* * INTERNAL * The instruction type is defined by the format of instruction's argument * list. So the order of argument list table should not be changed. The * default value of size field is defined with a special bit set in the size * offset field. To distinguish FPU instructions, a special bit is set in * the type field in the instruction table.** RETURNS: The number of bytes occupied by the instruction.*/int dsmInst ( FAST UCHAR *pD, /* Pointer to the instruction */ int address, /* Address prepended to instruction */ VOIDFUNCPTR prtAddress /* Address printing function */ ) { FORMAT_X formatx; FORMAT_Y formaty; if (prtAddress == NULL) prtAddress = nPrtAddress; bzero ((char *)&formatx, sizeof (FORMAT_X)); bzero ((char *)&formaty, sizeof (FORMAT_Y)); dsmFind (pD, &formatx, &formaty); dsmPrint (&formatx, &formaty, prtAddress); if (instKeeper != NULL) { formatx.pI->pOpc = instKeeper; instKeeper = NULL; } return ((formaty.len == 0) ? 1 : formaty.len); }/********************************************************************************* dsmNbytes - determine the size of an instruction** This routine reports the size, in bytes, of an instruction.** RETURNS: The size of the instruction, or 0 if the instruction is unrecognized.*/int dsmNbytes ( FAST UCHAR *pD /* Pointer to the instruction */ ) { FORMAT_X formatx; FORMAT_Y formaty; bzero ((char *)&formatx, sizeof (FORMAT_X)); bzero ((char *)&formaty, sizeof (FORMAT_Y)); dsmFind (pD, &formatx, &formaty); if (instKeeper != NULL) { formatx.pI->pOpc = instKeeper; instKeeper = NULL; } return (formaty.len); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -