Botan: src/utils/asm_x86_32/asm_x86_32.h Source File

Botan 1.10.12

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

asm_x86_32.h
Go to the documentation of this file.
1 /*
2 * Assembly Macros for 32-bit x86
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Distributed under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_ASM_MACROS_X86_32_H__
9 #define BOTAN_ASM_MACROS_X86_32_H__
10
11 /*
12 * General/Global Macros
13 */
14 #define ALIGN .p2align 4,,15
15
16 #define START_LISTING(FILENAME) \
17 .file #FILENAME; \
18 .text; \
19 ALIGN;
20
21 #if defined(__ELF__)
22 .section .note.GNU-stack,"",%progbits
23 #endif
24
25 /*
26 * Function Definitions
27 */
28 #define START_FUNCTION(func_name) \
29 ALIGN; \
30 .global func_name; \
31 .type func_name,@function; \
32 func_name:
33
34 #define END_FUNCTION(func_name) \
35 ret
36
37 /*
38 * Loop Control
39 */
40 #define START_LOOP(LABEL) \
41 ALIGN; \
42 LABEL##_LOOP:
43
44 #define LOOP_UNTIL_EQ(REG, NUM, LABEL) \
45 cmpl IMM(NUM), REG; \
46 jne LABEL##_LOOP
47
48 #define LOOP_UNTIL_LT(REG, NUM, LABEL) \
49 cmpl IMM(NUM), REG; \
50 jge LABEL##_LOOP
51
52 /*
53 Conditional Jumps
54 */
55 #define JUMP_IF_ZERO(REG, LABEL) \
56 cmpl IMM(0), REG; \
57 jz LABEL
58
59 #define JUMP_IF_LT(REG, NUM, LABEL) \
60 cmpl IMM(NUM), REG; \
61 jl LABEL
62
63 /*
64 * Register Names
65 */
66 #define EAX %eax
67 #define EBX %ebx
68 #define ECX %ecx
69 #define EDX %edx
70 #define EBP %ebp
71 #define EDI %edi
72 #define ESI %esi
73 #define ESP %esp
74
75 /*
76 * Memory Access Operations
77 */
78 #define ARRAY1(REG, NUM) (NUM)(REG)
79 #define ARRAY4(REG, NUM) 4*(NUM)(REG)
80 #define ARRAY4_INDIRECT(BASE, OFFSET, NUM) 4*(NUM)(BASE,OFFSET,4)
81 #define ARG(NUM) 4*(PUSHED) + ARRAY4(ESP, NUM)
82
83 #define ASSIGN(TO, FROM) movl FROM, TO
84 #define ASSIGN_BYTE(TO, FROM) movzbl FROM, TO
85
86 #define PUSH(REG) pushl REG
87 #define POP(REG) popl REG
88
89 #define SPILL_REGS() \
90 PUSH(EBP) ; \
91 PUSH(EDI) ; \
92 PUSH(ESI) ; \
93 PUSH(EBX)
94
95 #define RESTORE_REGS() \
96 POP(EBX) ; \
97 POP(ESI) ; \
98 POP(EDI) ; \
99 POP(EBP)
100
101 /*
102 * ALU Operations
103 */
104 #define IMM(VAL) $VAL
105
106 #define ADD(TO, FROM) addl FROM, TO
107 #define ADD_IMM(TO, NUM) ADD(TO, IMM(NUM))
108 #define ADD_W_CARRY(TO1, TO2, FROM) addl FROM, TO1; adcl IMM(0), TO2;
109 #define SUB_IMM(TO, NUM) subl IMM(NUM), TO
110 #define ADD2_IMM(TO, FROM, NUM) leal NUM(FROM), TO
111 #define ADD3_IMM(TO, FROM, NUM) leal NUM(TO,FROM,1), TO
112 #define MUL(REG) mull REG
113
114 #define SHL_IMM(REG, SHIFT) shll IMM(SHIFT), REG
115 #define SHR_IMM(REG, SHIFT) shrl IMM(SHIFT), REG
116 #define SHL2_3(TO, FROM) leal 0(,FROM,8), TO
117
118 #define XOR(TO, FROM) xorl FROM, TO
119 #define AND(TO, FROM) andl FROM, TO
120 #define OR(TO, FROM) orl FROM, TO
121 #define NOT(REG) notl REG
122 #define ZEROIZE(REG) XOR(REG, REG)
123
124 #define ROTL_IMM(REG, NUM) roll IMM(NUM), REG
125 #define ROTR_IMM(REG, NUM) rorl IMM(NUM), REG
126 #define BSWAP(REG) bswapl REG
127
128 #endif