1/*- 2 * Copyright (c) 2005, 2007 3 * Thorsten Glaser <tg@mirbsd.de> 4 * 5 * Provided that these terms and disclaimer and all copyright notices 6 * are retained or reproduced in an accompanying document, permission 7 * is granted to deal in this work without restriction, including un- 8 * limited rights to use, publicly perform, distribute, sell, modify, 9 * merge, give away, or sublicence. 10 * 11 * Advertising materials mentioning features or use of this work must 12 * display the following acknowledgement: 13 * This product includes material provided by Thorsten Glaser. 14 * 15 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 16 * the utmost extent permitted by applicable law, neither express nor 17 * implied; without malicious intent or gross negligence. In no event 18 * may a licensor, author or contributor be held liable for indirect, 19 * direct, other damage, loss, or other issues arising in any way out 20 * of dealing in the work, even if advised of the possibility of such 21 * damage or existence of a defect, except proven that it results out 22 * of said person's immediate fault when using the work as intended. 23 */ 24 25#ifdef _LIBMIRMAKE 26#ifdef __ELF__ 27#define _C_LABEL(name) name 28#else 29#ifdef __STDC__ 30#define _C_LABEL(name) _ ## name 31#else 32#define _C_LABEL(name) _/**/name 33#endif 34#endif 35#ifndef _ALIGN_TEXT 36#define _ALIGN_TEXT .p2align 2, 0x90 37#endif 38#define FTYPE(x) .type x,@function 39#define _ENTRY(name) \ 40 .text; _ALIGN_TEXT; .globl name; FTYPE(name); name: 41#define _PROF_PROLOGUE /* no profiling */ 42#define ENTRY(name) _ENTRY(_C_LABEL(name)); _PROF_PROLOGUE 43#define RCSID(x) .section .comment; \ 44 .ascii "@(""#)rcsid: "; \ 45 .asciz x; \ 46 .previous 47#else 48#include <machine/asm.h> 49#endif 50 51RCSID("$MirOS: src/lib/libc/hash/suma-i386.S,v 1.3 2008/04/06 23:51:38 tg Exp $") 52 53 .intel_syntax noprefix 54 .text 55 56/* 57 * EAX: in data 58 * EDX: in out CRC 59 * EBX: BL clobbered 60 */ 61#define UPDATE_ONE \ 62 mov bl,32 ; \ 638: rcl eax,1 ; \ 64 rcl edx,1 ; \ 65 jnc 9f ; \ 66 xor edx,0x04563521 ; \ 679: dec bl ; \ 68 jnz 8b 69 70 71/* void SUMAInit(SUMA_CTX *ctx) */ 72ENTRY(SUMAInit) 73 mov edx,[esp+4] 74 xor eax,eax 75 dec eax 76 mov [edx],eax 77 ret 78 79 80/* void SUMAUpdate(SUMA_CTX *ctx, const uint8_t *data, size_t len) */ 81ENTRY(SUMAUpdate) 82 push ebp 83 mov ebp,esp 84 push ebx 85 push esi 86 mov eax,[ebp+8] /* ctx */ 87 mov esi,[ebp+12] /* data */ 88 mov ecx,[ebp+16] /* len */ 89 jecxz 7f 90 mov edx,[eax] 91 cld 92 push ecx 93 shr ecx,2 94 jecxz 2f 951: lodsd 96 UPDATE_ONE 97 dec ecx 98 jnz 1b 992: pop ecx 100 and cl,3 101 jz 6f 102 xor eax,eax 103 lodsb 104 dec cl 105 je 3f 106 ror eax,8 107 lodsb 108 rol eax,8 109 dec cl 110 je 3f 111 ror eax,16 112 lodsb 113 rol eax,16 1143: UPDATE_ONE 1156: mov eax,[ebp+8] /* ctx */ 116 mov [eax],edx 1177: pop esi 118 pop ebx 119 pop ebp 120 ret 121 122 123/* void SUMAPad(SUMA_CTX *ctx) */ 124ENTRY(SUMAPad) 125 mov ecx,[esp+4] /* ctx */ 126 push ebx 127 mov edx,[ecx] 128 xor eax,eax 129 UPDATE_ONE 130 mov [ecx],edx 131 pop ebx 132 ret 133 134 135/* void SUMAFinal(uint8_t *dst, SUMA_CTX *ctx) */ 136ENTRY(SUMAFinal) 137 mov ecx,[esp+8] /* ctx */ 138 push ebx 139 mov edx,[ecx] 140 xor eax,eax 141 UPDATE_ONE 142 pop ebx 143 xor eax,eax 144 mov [ecx],eax 145 mov ecx,[esp+4] /* dst */ 146 bswap edx 147 mov [ecx],edx 148 ret 149