Debian Codegraph @

sr_i386/auto_zlink.c

raw symbols SCIP
1 /****************************************************************
2 * *
3 * Copyright 2001, 2012 Fidelity Information Services, Inc *
4 * *
5 * This source code contains the intellectual property *
6 * of its copyright holder(s), and is made available *
7 * under a license. If you do not know the terms of *
8 * the license, please stop and do not read further. *
9 * *
10 ****************************************************************/
11
12 #include "mdef.h"
13
14 #include "gtm_string.h"
15
16 #include "i386.h"
17 #include "urx.h"
18 #include <rtnhdr.h>
19 #include "op.h"
20 #include <auto_zlink.h>
21
22 #define PEA_SZ 5
23 #define XFER_BYTE_SZ 3
24 #define XFER_LONG_SZ 6
25 #define INST_SZ 1
26
27 error_def(ERR_LABELUNKNOWN);
28 error_def(ERR_ROUTINEUNKNOWN);
29
30 rhdtyp *auto_zlink (unsigned char *pc, int4 **line)
31 {
32 char *adj_pc; /* address of PEA rtnref offset */
33 mstr rname;
34 mident_fixed rname_local;
35 urx_rtnref *rtnurx;
36 mval rtn;
37 rhdtyp *rhead;
38 union
39 {
40 ModR_M modrm;
41 unsigned char byte;
42 } modrm_byte_byte, modrm_byte_long;
43
44 /* ASSUMPTION -- The instruction previous to the current mpc is a transfer table jump.
45 * This is either a byte or a int4 displacement off of ebx, instruction
46 * size either 3 or 6 (prefix byte, ModR/M byte, 8- or 32-bit offset).
47 */
48 modrm_byte_byte.modrm.reg_opcode = I386_INS_CALL_Ev;
49 modrm_byte_byte.modrm.mod = I386_MOD32_BASE_DISP_8;
50 modrm_byte_byte.modrm.r_m = I386_REG_EBX;
51 modrm_byte_long.modrm.reg_opcode = I386_INS_CALL_Ev;
52 modrm_byte_long.modrm.mod = I386_MOD32_BASE_DISP_32;
53 modrm_byte_long.modrm.r_m = I386_REG_EBX;
54 if ((*(pc - XFER_BYTE_SZ) == I386_INS_Grp5_Prefix) && (*(pc - XFER_BYTE_SZ + 1) == modrm_byte_byte.byte))
55 {
56 assert(*(pc - XFER_BYTE_SZ - PEA_SZ) == I386_INS_PUSH_Iv);
57 adj_pc = (char *)pc - XFER_BYTE_SZ - PEA_SZ;
58 } else if ((*(pc - XFER_LONG_SZ) == I386_INS_Grp5_Prefix) && (*(pc - XFER_LONG_SZ + 1) == modrm_byte_long.byte))
59 {
60 assert(*(pc - XFER_LONG_SZ - PEA_SZ) == I386_INS_PUSH_Iv);
61 adj_pc = (char *)pc - XFER_LONG_SZ - PEA_SZ;
62 } else
63 GTMASSERT;
64 if (azl_geturxrtn(adj_pc + INST_SZ, &rname, &rtnurx))
65 {
66 assert((0 <= rname.len) && (MAX_MIDENT_LEN >= rname.len));
67 assert(rname.addr);
68 /* Copy rname into local storage because azl_geturxrtn sets rname.addr to an address that is
69 * freed during op_zlink and before the call to find_rtn_hdr.
70 */
71 memcpy(rname_local.c, rname.addr, rname.len);
72 rname.addr = rname_local.c;
73 assert(rtnurx);
74 assert(*(adj_pc - PEA_SZ) == I386_INS_PUSH_Iv);
75 assert(azl_geturxlab(adj_pc - PEA_SZ + INST_SZ, rtnurx));
76 assert(!find_rtn_hdr(&rname));
77 rtn.mvtype = MV_STR;
78 rtn.str.len = rname.len;
79 rtn.str.addr = rname.addr;
80 op_zlink (&rtn, 0);
81 if (0 != (rhead = find_rtn_hdr(&rname))) /* note the assignment */
82 {
83 *line = *(int4 **)(adj_pc - PEA_SZ + INST_SZ);
84 if (!(*line))
85 rts_error(VARLSTCNT(1) ERR_LABELUNKNOWN);
86 return rhead;
87 }
88 }
89 rts_error(VARLSTCNT(1) ERR_ROUTINEUNKNOWN);
90 return NULL;
91 }