1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
/*************************************************
* Assembly Macros Header File *
* (C) 1999-2007 Jack Lloyd *
*************************************************/
#ifndef BOTAN_EXT_ASM_MACROS_H__
#define BOTAN_EXT_ASM_MACROS_H__
/*************************************************
* General/Global Macros *
*************************************************/
#define ALIGN .p2align 4,,15
#define START_LISTING(FILENAME) \
.file #FILENAME; \
.text; \
ALIGN;
/*************************************************
* Function Definitions *
*************************************************/
#define START_FUNCTION(func_name) \
ALIGN; \
.global func_name; \
.type func_name,@function; \
func_name:
#define END_FUNCTION(func_name) \
ret
/*************************************************
* Conditional Jumps *
*************************************************/
#define JUMP_IF_ZERO(REG, LABEL) \
cmp IMM(0), REG; \
jz LABEL
#define JUMP_IF_LT(REG, NUM, LABEL) \
cmp IMM(NUM), REG; \
jl LABEL
/*************************************************
* Register Names *
*************************************************/
#define R0 %rax
#define R1 %rbx
#define R2 %rcx
#define R3 %rdx
#define R4 %rsp
#define R5 %rbp
#define R6 %rsi
#define R7 %rdi
#define R8 %r8
#define R9 %r9
#define R10 %r10
#define R11 %r11
#define R12 %r12
#define R13 %r13
#define R14 %r14
#define R15 %r15
#define R16 %r16
#define ARG_1 R7
#define ARG_2 R6
#define ARG_3 R3
#define ARG_4 R2
#define ARG_5 R8
#define ARG_6 R9
#define TEMP_1 R10
#define TEMP_2 R11
#define TEMP_3 ARG_6
#define TEMP_4 ARG_5
#define TEMP_5 ARG_4
#define TEMP_6 ARG_3
#define TEMP_7 ARG_2
#define TEMP_8 ARG_1
#define TEMP_9 R0
/*************************************************
* Memory Access Operations *
*************************************************/
#define ARRAY8(REG, NUM) 8*(NUM)(REG)
#define ARRAY4(REG, NUM) 4*(NUM)(REG)
#define ASSIGN(TO, FROM) mov FROM, TO
/*************************************************
* ALU Operations *
*************************************************/
#define IMM(VAL) $VAL
#define ADD(TO, FROM) add FROM, TO
#define ADD_LAST_CARRY(REG) adc IMM(0), REG
#define ADD_IMM(TO, NUM) ADD(TO, IMM(NUM))
#define ADD_W_CARRY(TO1, TO2, FROM) add FROM, TO1; adc IMM(0), TO2;
#define SUB_IMM(TO, NUM) sub IMM(NUM), TO
#define MUL(REG) mul REG
#define XOR(TO, FROM) xor FROM, TO
#define AND(TO, FROM) and FROM, TO
#define OR(TO, FROM) or FROM, TO
#define NOT(REG) not REG
#define ZEROIZE(REG) XOR(REG, REG)
#define RETURN_VALUE_IS(V) ASSIGN(%rax, V)
#define ROTL_IMM(REG, NUM) rol IMM(NUM), REG
#define ROTR_IMM(REG, NUM) ror IMM(NUM), REG
#define ADD3_IMM(TO, FROM, NUM) lea NUM(TO,FROM,1), TO
#endif
|