1 #ifndef ASM_X86_INTERNAL_H
2 #warning Do not include this file directly
3 #else
4
asm_sbbl(struct assembler_state_t * state,uint32_t src,uint32_t * dst)5 static inline void asm_sbbl(struct assembler_state_t *state, uint32_t src, uint32_t *dst)
6 {
7 uint32_t tmp = *dst - src;
8 int of = 0;
9 int cf = 1;
10
11 if (read_cf(state->eflags))
12 {
13 tmp--;
14 src++;
15 if (src==0x00000000)
16 {
17 write_cf(state->eflags, 1);
18 cf=0;
19 }
20
21 if (src==0x80000000)
22 of = 1;
23 }
24
25 if (cf)
26 write_cf(state->eflags, tmp > *dst);
27
28 if ((*dst & 0x80000000) != (src & 0x80000000))
29 write_of(state->eflags, ((src & 0x80000000) == (tmp & 0x80000000)) ^ of); /* signed overflow */
30 else
31 write_of(state->eflags, of);
32
33 write_sf(state->eflags, tmp & 0x80000000);
34 write_zf(state->eflags, !tmp);
35 #ifdef X86_PF
36 asm_update_pf(state->eflags, tmp);
37 #endif
38 #ifdef X86_AF
39 asm_updae_af(state->eflags, tmp, *dst);
40 #endif
41
42 *dst = tmp;
43 }
asm_sbbw(struct assembler_state_t * state,uint16_t src,uint16_t * dst)44 static inline void asm_sbbw(struct assembler_state_t *state, uint16_t src, uint16_t *dst)
45 {
46 uint16_t tmp = *dst - src;
47 int of = 0;
48 int cf = 1;
49
50 if (read_cf(state->eflags))
51 {
52 tmp--;
53 src++;
54 if (src==0x0000)
55 {
56 write_cf(state->eflags, 1);
57 cf=0;
58 }
59
60 if (src==0x8000)
61 of = 1;
62 }
63
64 if (cf)
65 write_cf(state->eflags, tmp > *dst);
66
67 if ((*dst & 0x8000) != (src & 0x8000))
68 write_of(state->eflags, ((src & 0x8000) == (tmp & 0x8000)) ^ of); /* signed overflow */
69 else
70 write_of(state->eflags, of);
71
72 write_sf(state->eflags, tmp & 0x8000);
73 write_zf(state->eflags, !tmp);
74 #ifdef X86_PF
75 asm_update_pf(state->eflags, tmp);
76 #endif
77 #ifdef X86_AF
78 asm_updae_af(state->eflags, tmp, *dst);
79 #endif
80
81 *dst = tmp;
82 }
asm_sbbb(struct assembler_state_t * state,uint8_t src,uint8_t * dst)83 static inline void asm_sbbb(struct assembler_state_t *state, uint8_t src, uint8_t *dst)
84 {
85 uint8_t tmp = *dst - src;
86 int of = 0;
87 int cf = 1;
88
89 if (read_cf(state->eflags))
90 {
91 tmp--;
92 src++;
93 if (src==0x00)
94 {
95 write_cf(state->eflags, 1);
96 cf=0;
97 }
98
99 if (src==0x80)
100 of = 1;
101 }
102
103 if (cf)
104 write_cf(state->eflags, tmp > *dst);
105
106 if ((*dst & 0x80) != (src & 0x80))
107 write_of(state->eflags, ((src & 0x80) == (tmp & 0x80)) ^ of); /* signed overflow */
108 else
109 write_of(state->eflags, of);
110
111 write_sf(state->eflags, tmp & 0x80);
112 write_zf(state->eflags, !tmp);
113 #ifdef X86_PF
114 asm_update_pf(state->eflags, tmp);
115 #endif
116 #ifdef X86_AF
117 asm_updae_af(state->eflags, tmp, *dst);
118 #endif
119
120 *dst = tmp;
121 }
122 #endif
123