This commit is contained in:
Russ Cox 2005-11-04 15:57:52 +00:00
parent e10503f019
commit f493c9c544
3 changed files with 44 additions and 60 deletions

View File

@ -102,14 +102,16 @@
orl B, %edi;\ orl B, %edi;\
xorl C, %edi;\ xorl C, %edi;\
#define DATA 8 #define STACKSIZE 20
#define LEN 12
#define STATE 16
#define EDATA (-4) #define DATA (STACKSIZE+8)
#define OLDEBX (-8) #define LEN (STACKSIZE+12)
#define OLDESI (-12) #define STATE (STACKSIZE+16)
#define OLDEDI (-16)
#define EDATA (STACKSIZE-4)
#define OLDEBX (STACKSIZE-8)
#define OLDESI (STACKSIZE-12)
#define OLDEDI (STACKSIZE-16)
.text .text
@ -120,6 +122,7 @@
/* Prelude */ /* Prelude */
pushl %ebp pushl %ebp
subl $(STACKSIZE), %esp
movl %ebx, OLDEBX(%esp) movl %ebx, OLDEBX(%esp)
movl %esi, OLDESI(%esp) movl %esi, OLDESI(%esp)
movl %edi, OLDEDI(%esp) movl %edi, OLDEDI(%esp)
@ -130,7 +133,7 @@
movl DATA(%esp), %ebp movl DATA(%esp), %ebp
mainloop: 0:
movl STATE(%esp), %esi movl STATE(%esp), %esi
movl (%esi), %eax movl (%esi), %eax
movl 4(%esi), %ebx movl 4(%esi), %ebx
@ -229,13 +232,13 @@ mainloop:
movl EDATA(%esp), %edi movl EDATA(%esp), %edi
cmpl %edi, %ebp cmpl %edi, %ebp
jb mainloop jb 0b
/* Postlude */ /* Postlude */
movl OLDEBX(%esp), %ebx movl OLDEBX(%esp), %ebx
movl OLDESI(%esp), %esi movl OLDESI(%esp), %esi
movl OLDEDI(%esp), %edi movl OLDEDI(%esp), %edi
movl %esp, %ebp addl $(STACKSIZE), %esp
leave popl %ebp
ret ret

View File

@ -75,9 +75,10 @@ _sha1block:
* stack offsets * stack offsets
* void sha1block(uchar *DATA, int LEN, ulong *STATE) * void sha1block(uchar *DATA, int LEN, ulong *STATE)
*/ */
#define DATA 8 #define STACKSIZE (48+80*4)
#define LEN 12 #define DATA (STACKSIZE+8)
#define STATE 16 #define LEN (STACKSIZE+12)
#define STATE (STACKSIZE+16)
/* /*
* stack offsets for locals * stack offsets for locals
@ -89,20 +90,22 @@ _sha1block:
* ulong a = eax, b = ebx, c = ecx, d = edx, e = esi * ulong a = eax, b = ebx, c = ecx, d = edx, e = esi
* ulong tmp = edi * ulong tmp = edi
*/ */
#define WARRAY (-4-(80*4)) #define WARRAY (STACKSIZE-4-(80*4))
#define TMP1 (-8-(80*4)) #define TMP1 (STACKSIZE-8-(80*4))
#define TMP2 (-12-(80*4)) #define TMP2 (STACKSIZE-12-(80*4))
#define W15 (-16-(80*4)) #define W15 (STACKSIZE-16-(80*4))
#define W40 (-20-(80*4)) #define W40 (STACKSIZE-20-(80*4))
#define W60 (-24-(80*4)) #define W60 (STACKSIZE-24-(80*4))
#define W80 (-28-(80*4)) #define W80 (STACKSIZE-28-(80*4))
#define EDATA (-32-(80*4)) #define EDATA (STACKSIZE-32-(80*4))
#define OLDEBX (-36-(80*4)) #define OLDEBX (STACKSIZE-36-(80*4))
#define OLDESI (-40-(80*4)) #define OLDESI (STACKSIZE-40-(80*4))
#define OLDEDI (-44-(80*4)) #define OLDEDI (STACKSIZE-44-(80*4))
/* Prelude */ /* Prelude */
pushl %ebp pushl %ebp
subl $(STACKSIZE), %esp
mov %ebx, OLDEBX(%esp) mov %ebx, OLDEBX(%esp)
mov %esi, OLDESI(%esp) mov %esi, OLDESI(%esp)
mov %edi, OLDEDI(%esp) mov %edi, OLDEDI(%esp)
@ -120,7 +123,7 @@ _sha1block:
leal (WARRAY+80*4)(%esp), %edi /* aw80 */ leal (WARRAY+80*4)(%esp), %edi /* aw80 */
movl %edi, W80(%esp) movl %edi, W80(%esp)
mainloop: 0:
leal WARRAY(%esp), %ebp /* warray */ leal WARRAY(%esp), %ebp /* warray */
movl STATE(%esp), %edi /* state */ movl STATE(%esp), %edi /* state */
@ -133,7 +136,7 @@ mainloop:
movl DATA(%esp), %ebx /* data */ movl DATA(%esp), %ebx /* data */
loop1: 1:
BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi) BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi)
movl %esi,TMP2(%esp) movl %esi,TMP2(%esp)
BODY0(4,FN1,0x5a827999,%esi,%eax,TMP1(%esp),%ecx,%edx) BODY0(4,FN1,0x5a827999,%esi,%eax,TMP1(%esp),%ecx,%edx)
@ -147,7 +150,7 @@ loop1:
addl $20, %ebx addl $20, %ebx
addl $20, %ebp addl $20, %ebp
cmpl W15(%esp), %ebp /* w15 */ cmpl W15(%esp), %ebp /* w15 */
jb loop1 jb 1b
BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi) BODY0(0,FN1,0x5a827999,%eax,TMP1(%esp),%ecx,%edx,%esi)
addl $4, %ebx addl $4, %ebx
@ -161,7 +164,7 @@ loop1:
addl $20, %ebp addl $20, %ebp
loop2: 2:
BODY(0,FN24,0x6ed9eba1,%eax,%ebx,%ecx,%edx,%esi) BODY(0,FN24,0x6ed9eba1,%eax,%ebx,%ecx,%edx,%esi)
BODY(4,FN24,0x6ed9eba1,%esi,%eax,%ebx,%ecx,%edx) BODY(4,FN24,0x6ed9eba1,%esi,%eax,%ebx,%ecx,%edx)
BODY(8,FN24,0x6ed9eba1,%edx,%esi,%eax,%ebx,%ecx) BODY(8,FN24,0x6ed9eba1,%edx,%esi,%eax,%ebx,%ecx)
@ -170,9 +173,9 @@ loop2:
addl $20,%ebp addl $20,%ebp
cmpl W40(%esp), %ebp cmpl W40(%esp), %ebp
jb loop2 jb 2b
loop3: 3:
BODY(0,FN3,0x8f1bbcdc,%eax,%ebx,%ecx,%edx,%esi) BODY(0,FN3,0x8f1bbcdc,%eax,%ebx,%ecx,%edx,%esi)
BODY(4,FN3,0x8f1bbcdc,%esi,%eax,%ebx,%ecx,%edx) BODY(4,FN3,0x8f1bbcdc,%esi,%eax,%ebx,%ecx,%edx)
BODY(8,FN3,0x8f1bbcdc,%edx,%esi,%eax,%ebx,%ecx) BODY(8,FN3,0x8f1bbcdc,%edx,%esi,%eax,%ebx,%ecx)
@ -181,9 +184,9 @@ loop3:
addl $20, %ebp addl $20, %ebp
cmpl W60(%esp), %ebp /* w60 */ cmpl W60(%esp), %ebp /* w60 */
jb loop3 jb 3b
loop4: 4:
BODY(0,FN24,0xca62c1d6,%eax,%ebx,%ecx,%edx,%esi) BODY(0,FN24,0xca62c1d6,%eax,%ebx,%ecx,%edx,%esi)
BODY(4,FN24,0xca62c1d6,%esi,%eax,%ebx,%ecx,%edx) BODY(4,FN24,0xca62c1d6,%esi,%eax,%ebx,%ecx,%edx)
BODY(8,FN24,0xca62c1d6,%edx,%esi,%eax,%ebx,%ecx) BODY(8,FN24,0xca62c1d6,%edx,%esi,%eax,%ebx,%ecx)
@ -192,7 +195,7 @@ loop4:
addl $20, %ebp addl $20, %ebp
cmpl W80(%esp), %ebp /* w80 */ cmpl W80(%esp), %ebp /* w80 */
jb loop4 jb 4b
movl STATE(%esp), %edi /* state */ movl STATE(%esp), %edi /* state */
addl %eax, 0(%edi) addl %eax, 0(%edi)
@ -203,12 +206,12 @@ loop4:
movl EDATA(%esp), %edi /* edata */ movl EDATA(%esp), %edi /* edata */
cmpl %edi, DATA(%esp) /* data */ cmpl %edi, DATA(%esp) /* data */
jb mainloop jb 0b
/* Postlude */ /* Postlude */
mov OLDEBX(%esp), %ebx mov OLDEBX(%esp), %ebx
mov OLDESI(%esp), %esi mov OLDESI(%esp), %esi
mov OLDEDI(%esp), %edi mov OLDEDI(%esp), %edi
movl %esp, %ebp addl $(STACKSIZE), %esp
leave popl %ebp
ret ret

View File

@ -1,22 +0,0 @@
// could also use windozy InterlockedCompareExchange(p, 1, 0), but why
int
tas(long *p)
{
int v;
_asm {
mov eax, p
mov ebx, 1
xchg ebx, [eax]
mov v, ebx
}
switch(v) {
case 0:
case 1:
return v;
default:
print("canlock: corrupted 0x%lux\n", v);
return 1;
}
}