Botan  1.11.15
src/lib/utils/asm_x86_64/asm_x86_64.h
Go to the documentation of this file.
00001 /*
00002 * Assembly Macros for 64-bit x86
00003 * (C) 1999-2008 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_ASM_MACROS_X86_64_H__
00009 #define BOTAN_ASM_MACROS_X86_64_H__
00010 
00011 /*
00012 * General/Global Macros
00013 */
00014 #define ALIGN .p2align 4,,15
00015 
00016 #define START_LISTING(FILENAME) \
00017    .file #FILENAME;             \
00018    .text;                       \
00019    ALIGN;
00020 
00021 #if defined(__ELF__)
00022 .section .note.GNU-stack,"",%progbits
00023 #endif
00024 
00025 /*
00026 * Function Definitions
00027 */
00028 #define START_FUNCTION(func_name) \
00029    ALIGN;                         \
00030    .global  func_name;            \
00031    .type    func_name,@function;  \
00032 func_name:
00033 
00034 #define END_FUNCTION(func_name) \
00035    ret
00036 
00037 /*
00038 * Conditional Jumps
00039 */
00040 #define JUMP_IF_ZERO(REG, LABEL) \
00041    cmp IMM(0), REG;              \
00042    jz LABEL
00043 
00044 #define JUMP_IF_LT(REG, NUM, LABEL) \
00045    cmp IMM(NUM), REG;               \
00046    jl LABEL
00047 
00048 /*
00049 * Register Names
00050 */
00051 #define R0  %rax
00052 #define R1  %rbx
00053 #define R2  %rcx
00054 #define R2_32  %ecx
00055 #define R3  %rdx
00056 #define R3_32  %edx
00057 #define R4  %rsp
00058 #define R5  %rbp
00059 #define R6  %rsi
00060 #define R6_32  %esi
00061 #define R7  %rdi
00062 #define R8  %r8
00063 #define R9  %r9
00064 #define R9_32  %r9d
00065 #define R10 %r10
00066 #define R11 %r11
00067 #define R12 %r12
00068 #define R13 %r13
00069 #define R14 %r14
00070 #define R15 %r15
00071 #define R16 %r16
00072 
00073 #define ARG_1 R7
00074 #define ARG_2 R6
00075 #define ARG_2_32 R6_32
00076 #define ARG_3 R3
00077 #define ARG_3_32 R3_32
00078 #define ARG_4 R2
00079 #define ARG_4_32 R2_32
00080 #define ARG_5 R8
00081 #define ARG_6 R9
00082 #define ARG_6_32 R9_32
00083 
00084 #define TEMP_1 R10
00085 #define TEMP_2 R11
00086 #define TEMP_3 ARG_6
00087 #define TEMP_4 ARG_5
00088 #define TEMP_5 ARG_4
00089 #define TEMP_5_32 ARG_4_32
00090 #define TEMP_6 ARG_3
00091 #define TEMP_7 ARG_2
00092 #define TEMP_8 ARG_1
00093 #define TEMP_9 R0
00094 
00095 /*
00096 * Memory Access Operations
00097 */
00098 #define ARRAY8(REG, NUM) 8*(NUM)(REG)
00099 #define ARRAY4(REG, NUM) 4*(NUM)(REG)
00100 
00101 #define ASSIGN(TO, FROM) mov FROM, TO
00102 
00103 /*
00104 * ALU Operations
00105 */
00106 #define IMM(VAL) $VAL
00107 
00108 #define ADD(TO, FROM) add FROM, TO
00109 #define ADD_LAST_CARRY(REG) adc IMM(0), REG
00110 #define ADD_IMM(TO, NUM) ADD(TO, IMM(NUM))
00111 #define ADD_W_CARRY(TO1, TO2, FROM) add FROM, TO1; adc IMM(0), TO2;
00112 #define SUB_IMM(TO, NUM) sub IMM(NUM), TO
00113 #define MUL(REG) mul REG
00114 
00115 #define XOR(TO, FROM) xor FROM, TO
00116 #define AND(TO, FROM) and FROM, TO
00117 #define OR(TO, FROM) or FROM, TO
00118 #define NOT(REG) not REG
00119 #define ZEROIZE(REG) XOR(REG, REG)
00120 
00121 #define RETURN_VALUE_IS(V) ASSIGN(%rax, V)
00122 
00123 #define ROTL_IMM(REG, NUM) rol IMM(NUM), REG
00124 #define ROTR_IMM(REG, NUM) ror IMM(NUM), REG
00125 #define ADD3_IMM(TO, FROM, NUM) lea NUM(TO,FROM,1), TO
00126 
00127 #endif