diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemory.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemory.asm new file mode 100644 index 00000000000..f00011a3a69 --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemory.asm @@ -0,0 +1,49 @@ +; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlCompareMemory.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + + + BITS 32 + GLOBAL _RtlCompareMemory@12 ; [4] (no bug) + + SECTION .text + +; * +; * [4] ULONG STDCALL RtlCompareMemory(PVOID Source1, PVOID Source2, ULONG Length) +; * + +_RtlCompareMemory@12: + xor eax,eax ; count = 0 + mov ecx, dword [esp + 12 ] ; ecx = Length + cmp ecx,0 ; if (Length==0) goto .zero + je .zero + + push edi ; register that does not to be save eax,ecx,edx to + push ebx ; the stack for protetion + + mov edi, dword [esp + (4 + 8)] ; edi = Destination + mov edx, dword [esp + (8 + 8)] ; edx = Source + +.loop_1byte: + mov bl,byte [edi + eax ] ; if (src[count]!=des[count]) goto .pop_zero + cmp byte [edx + eax ],bl + jne .pop_zero + + inc eax ; count = count + 1 + dec ecx ; Length = Length - 1 + jnz .loop_1byte ; if (Length!=0) goto .loop_1byte + +.pop_zero: + pop ebx ; restore regiester + pop edi +.zero: + ret 12 ; return count diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemoryUlong.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemoryUlong.asm new file mode 100644 index 00000000000..0a0f43733f0 --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlCompareMemoryUlong.asm @@ -0,0 +1,50 @@ +; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlCompareMemoryUlong.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + + + BITS 32 + GLOBAL _RtlCompareMemoryUlong@12 ; [5] (no bug) + + SECTION .text +;* +;* [5] ULONG STDCALL RtlCompareMemoryUlong (PVOID Source, ULONG Length, ULONG Value) +;* + +_RtlCompareMemoryUlong@12: + xor eax,eax + mov ecx, dword [esp + 8 ] ; ecx = Length + shr ecx,2 ; Length / sizeof(ULONG) + jz .zero ; if (Length==0) goto .zero + + push edi ; register that does not to be save eax,ecx,edx to + push ebx ; the stack for protetion + + mov edi, dword [esp + (4 + 8)] ; edx = Destination + mov eax, dword [esp + (12 + 8)] ; ebx = value + mov ebx,ecx + cld + repe scasd + + inc ecx + mov eax,ebx + + sub eax,ecx + shl eax,2 + + pop ebx + pop edi + +.zero + ret 12 + + \ No newline at end of file diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemory.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemory.asm new file mode 100644 index 00000000000..7d5c44d639e --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemory.asm @@ -0,0 +1,36 @@ +; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlCompareMemory.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + + + BITS 32 + GLOBAL _RtlFillMemory@12 ; [4] (no bug) + + SECTION .text + +; * +; * [6] VOID STDCALL RtlFillMemory (PVOID Destination, ULONG Length, UCHAR Fill) +; * + +_RtlFillMemory@12: + mov ecx,dword [esp + 8 ] ; ecx = Length + cmp ecx,0 ; if (Length==0) goto .zero + je .zero + + mov edx, dword [esp + 4] ; edx = Destination + mov eax, dword [esp + 12] ; eax = fill +.loop: + mov byte [edx + ecx -1],al ; src[Length - 1] = fill + dec ecx ; Length = Length - 1 + jnz .loop ; if (Length!=0) goto .loop +.zero: + ret 12 ; return diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemoryUlong.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemoryUlong.asm new file mode 100644 index 00000000000..05509f18392 --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlFillMemoryUlong.asm @@ -0,0 +1,38 @@ +; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlMemoryUlong.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + + BITS 32 + GLOBAL _RtlFillMemoryUlong@12 ; (no bug) (max optimze code) + + SECTION .text + + + + +; * +; * VOID STDCALL RtlFillMemoryUlong (PVOID Destination, ULONG Length, ULONG Fill) +; * + +_RtlFillMemoryUlong@12: + mov ecx, dword [esp + 8 ] ; Length + shr ecx,2 ; Length = Length / sizeof(ULONG) + jz .zero ; if (Length==0) goto .zero + + push edi + mov edi, dword [esp + (4 + 4)] ; Destination + mov eax, dword [esp + (12 + 4)] ; Fill + cld + rep stosd ; while (Length>0) {Destination[Length-1]=Fill; Length = Length - 1} + pop edi +.zero: + ret 12 diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlMoveMemory.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlMoveMemory.asm new file mode 100644 index 00000000000..2ac15c4ee1a --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlMoveMemory.asm @@ -0,0 +1,69 @@ +; * base on ntdll/rtl/mem.c v 1.13 2003/07/11 13:50:23 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlMemory.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + BITS 32 + GLOBAL _RtlMoveMemory@12 ; (no bug) (max optimze code) + + SECTION .text + +; * +; * [1] VOID STDCALL RtlMoveMemory (PVOID Destination, CONST VOID *Source,ULONG Length); +; * + + + +_RtlMoveMemory@12: + mov ecx,dword [esp + 12 ] ; ecx = Length + cmp ecx,0 ; if (Length==0) goto .zero + je .zero + + pushad + mov edi, dword [esp + (4 + 32)] ; eax = Destination + mov esi, dword [esp + (8 + 32)] ; edx = Source + +; calc how many bytes it should handle same time + mov ebx,ecx ; temp_Length = Length + shr ecx,2 ; Length = Length / sizeof(ULONG) + jz .1byte ; if (Length==0) goto .1byte + + shl ecx,2 ; Length = Length * sizeof(ULONG) + sub ebx,ecx ; temp_Length = temp_Length - Length + jz .4bytes ; if (temp_Length==0) goto .4byte + +; move 4byte and 1byte + shr ecx,2 ; Length = Length / sizeof(ULONG) + cld ; clear d flag + rep movsd ; while (Length!=0) { (ULONG *) Destination[Length-1] = (ULONG *) Source[Length-1]; Legnth = Legnth - 1 } + mov ecx,ebx ; Length = temp_Length + rep movsb ; while (Length!=0) { (UCHAR *) Destination[Length-1] = (UCHAR *) Source[Length-1]; Legnth = Legnth - 1 } + popad ; restore regiester + ret 12 ; return + +; move 1byte +.1byte: + mov ecx,dword [esp + (12 +32) ] ; ecx = Length + cld ; clear d flag + rep movsb ; while (Length!=0) { (UCHAR *) Destination[Length-1] = (UCHAR *) Source[Length-1]; Legnth = Legnth - 1 } + + popad ; restore regiester + ret 12 ; return + +; move 4bytes +.4bytes: + shr ecx,2 ; Length = Length / sizeof(ULONG) + cld ; clear d flag + rep movsd ; while (Length!=0) { (ULONG *) Destination[Length-1] = (ULONG *) Source[Length-1]; Legnth = Legnth - 1 } + popad ; restore regiester +.zero: + ret 12 ; return + + diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlRandom.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlRandom.asm new file mode 100644 index 00000000000..2a69fd05220 --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlRandom.asm @@ -0,0 +1,249 @@ +; * base on ntdll/rtl/random.c v 1.1 2003/06/07 11:32:03 +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlRandom.asm +; * PURPOSE: Random number generator functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + BITS 32 + GLOBAL _RtlRandom@4 ; [1] (no bug) (max optimze code) + GLOBAL _RtlUniform@4 ; [2] (no bug) (max optimze code) + GLOBAL _SavedValue ; [3] (no bug) (max optimze code) + SECTION .text + +_RtlRandom@4: + ; load pointer + mov ecx,[esp+4] + mov eax,[ecx] + + ; Result = *Seed * 0xffffffed + 0x7fffffc3 ; take now 3 cycles + lea edx,[eax + eax * 8] + + lea eax,[eax + edx * 2 + 2147483709 ] ; + 2147483709 + neg eax + + cmp eax,-1 + je .RtlRandom_Rand1 + cmp eax, 2147483646 + je .RtlRandom_Rand1 + + cmp eax, 2147483647 + je .RtlRandom_Rand2 + + test eax,eax + jns .RtlRandom_Rand3 + + ; else { + mov edx,eax + and edx,1 + add eax,edx + and eax,2147483647 + mov [ecx],eax + jmp .RtlRandom_Seed + + +.RtlRandom_Rand1: + ; if (Result == 0xffffffff || Result == 0x7ffffffe) + add eax, 2 + and eax, 2147483647 + mov [ecx],eax + jmp .RtlRandom_Seed + +.RtlRandom_Rand2: + ; else if (Result == 0x7fffffff) + xor eax,eax + mov [ecx],eax + jmp .RtlRandom_Seed + +.RtlRandom_Rand3: + ; else if ((Result & 0x80000000) == 0) + mov edx,eax + xor edx,-1 ; not edx lock all clock until it finsish, but xor does not do that + and edx,1 + add eax,edx + mov [ecx],eax + +.RtlRandom_Seed: + mov eax,[ecx] + + ; Result = *Seed * 0xffffffed + 0x7fffffc3 ; take now 3 cycles + lea edx,[eax + eax * 8] + + lea eax,[eax + edx * 2 + 2147483709 ] ; + 2147483709 09-18 + neg eax + + cmp eax,-1 + je .RtlRandom_Seed1 + cmp eax, 2147483646 + je .RtlRandom_Seed1 + + cmp eax, 2147483647 + je .RtlRandom_Seed2 + + test eax,eax + jns .RtlRandom_Seed3 + + ; else { + mov edx,eax + and edx,1 + add eax,edx + and eax,2147483647 + + ; end + mov edx,[ecx] + mov [ecx],eax + + mov ecx,eax ; pos + and ecx, 0x7f ; pos = seed & 0x7f + mov eax,ecx; + mov eax, dword [_SavedValue + (ecx*4)] + mov dword [_SavedValue + (ecx*4)], edx + ret 4 + +.RtlRandom_Seed1: + ; if (Result == 0xffffffff || Result == 0x7ffffffe) + add eax, 2 + and eax, 2147483647 + + ; end + mov edx,[ecx] + mov [ecx],eax + + mov ecx,eax ; pos + and ecx, 0x7f ; pos = seed & 0x7f + mov eax,ecx; + mov eax, dword [_SavedValue + (ecx*4)] + mov dword [_SavedValue + (ecx*4)], edx + ret 4 + +.RtlRandom_Seed2: + ; else if (Result == 0x7fffffff) + xor eax,eax + + ; end + mov edx,[ecx] + mov [ecx],eax + + mov ecx,eax ; pos + and ecx, 0x7f ; pos = seed & 0x7f + mov eax,ecx; + mov eax, dword [_SavedValue + (ecx*4)] + mov dword [_SavedValue + (ecx*4)], edx + ret 4 + +.RtlRandom_Seed3: + ; else if ((Result & 0x80000000) == 0) + mov edx,eax + xor edx,-1 ; not edx lock all clock until it finsish, but xor does not do that + and edx,1 + add eax,edx + + ; end + mov edx,[ecx] + mov [ecx],eax + + mov ecx,eax ; pos + and ecx, 0x7f ; pos = seed & 0x7f + mov eax,ecx; + mov eax, dword [_SavedValue + (ecx*4)] + mov dword [_SavedValue + (ecx*4)], edx + ret 4 + + + + +; prototype: ULONG STDCALL RtlUniform (PULONG Seed) +_RtlUniform@4: + ; load pointer + mov ecx,[esp+4] + mov eax,[ecx] + + ; Result = *Seed * 0xffffffed + 0x7fffffc3 ; take now 3 cycles + lea edx,[eax + eax * 8] + + lea eax,[eax + edx * 2 + 2147483709 ] ; + 2147483709 09-18 + neg eax + + cmp eax,-1 + je .RtlUniform_jump1 + cmp eax, 2147483646 + je .RtlUniform_jump1 + + cmp eax, 2147483647 + je .RtlUniform_jump2 + + test eax,eax + jns .RtlUniform_jump3 + + ; else { + mov edx,eax + and edx,1 + add eax,edx + and eax,2147483647 + mov [ecx],eax + ret 4 + +.RtlUniform_jump1: + ; if (Result == 0xffffffff || Result == 0x7ffffffe) + add eax, 2 + and eax, 2147483647 + mov [ecx],eax + ret 4 + +.RtlUniform_jump2: + ; else if (Result == 0x7fffffff) + xor eax,eax + mov [ecx],eax + ret 4 + +.RtlUniform_jump3: + ; else if ((Result & 0x80000000) == 0) + mov edx,eax + xor edx,-1 ; not edx lock all clock until it finsish, but xor does not do that + and edx,1 + add eax,edx + mov [ecx],eax + ret 4 + + + SECTION .data +; SavedValue[128] +_SavedValue: + dd 0x4c8bc0aa, 0x4c022957, 0x2232827a, 0x2f1e7626 + dd 0x7f8bdafb, 0x5c37d02a, 0x0ab48f72, 0x2f0c4ffa + dd 0x290e1954, 0x6b635f23, 0x5d3885c0, 0x74b49ff8 + dd 0x5155fa54, 0x6214ad3f, 0x111e9c29, 0x242a3a09 + dd 0x75932ae1, 0x40ac432e, 0x54f7ba7a, 0x585ccbd5 + dd 0x6df5c727, 0x0374dad1, 0x7112b3f1, 0x735fc311 + dd 0x404331a9, 0x74d97781, 0x64495118, 0x323e04be + dd 0x5974b425, 0x4862e393, 0x62389c1d, 0x28a68b82 + dd 0x0f95da37, 0x7a50bbc6, 0x09b0091c, 0x22cdb7b4 + dd 0x4faaed26, 0x66417ccd, 0x189e4bfa, 0x1ce4e8dd + dd 0x5274c742, 0x3bdcf4dc, 0x2d94e907, 0x32eac016 + dd 0x26d33ca3, 0x60415a8a, 0x31f57880, 0x68c8aa52 + dd 0x23eb16da, 0x6204f4a1, 0x373927c1, 0x0d24eb7c + dd 0x06dd7379, 0x2b3be507, 0x0f9c55b1, 0x2c7925eb + dd 0x36d67c9a, 0x42f831d9, 0x5e3961cb, 0x65d637a8 + dd 0x24bb3820, 0x4d08e33d, 0x2188754f, 0x147e409e + dd 0x6a9620a0, 0x62e26657, 0x7bd8ce81, 0x11da0abb + dd 0x5f9e7b50, 0x23e444b6, 0x25920c78, 0x5fc894f0 + dd 0x5e338cbb, 0x404237fd, 0x1d60f80f, 0x320a1743 + dd 0x76013d2b, 0x070294ee, 0x695e243b, 0x56b177fd + dd 0x752492e1, 0x6decd52f, 0x125f5219, 0x139d2e78 + dd 0x1898d11e, 0x2f7ee785, 0x4db405d8, 0x1a028a35 + dd 0x63f6f323, 0x1f6d0078, 0x307cfd67, 0x3f32a78a + dd 0x6980796c, 0x462b3d83, 0x34b639f2, 0x53fce379 + dd 0x74ba50f4, 0x1abc2c4b, 0x5eeaeb8d, 0x335a7a0d + dd 0x3973dd20, 0x0462d66b, 0x159813ff, 0x1e4643fd + dd 0x06bc5c62, 0x3115e3fc, 0x09101613, 0x47af2515 + dd 0x4f11ec54, 0x78b99911, 0x3db8dd44, 0x1ec10b9b + dd 0x5b5506ca, 0x773ce092, 0x567be81a, 0x5475b975 + dd 0x7a2cde1a, 0x494536f5, 0x34737bb4, 0x76d9750b + dd 0x2a1f6232, 0x2e49644d, 0x7dddcbe7, 0x500cebdb + dd 0x619dab9e, 0x48c626fe, 0x1cda3193, 0x52dabe9d + \ No newline at end of file diff --git a/reactos/lib/ntdll/nasm/rtl/i386_RtlZeroMemory.asm b/reactos/lib/ntdll/nasm/rtl/i386_RtlZeroMemory.asm new file mode 100644 index 00000000000..572ec97ce64 --- /dev/null +++ b/reactos/lib/ntdll/nasm/rtl/i386_RtlZeroMemory.asm @@ -0,0 +1,65 @@ +; * +; * COPYRIGHT: See COPYING in the top level directory +; * PROJECT: ReactOS kernel +; * FILE: i386_RtlZeroMemory.asm +; * PURPOSE: Memory functions +; * PROGRAMMER: Magnus Olsen (magnusolsen@greatlord.com) +; * UPDATE HISTORY: +; * Created 20/07-2003 +; * + + + BITS 32 + GLOBAL _RtlZeroMemory@8 ; (no bug) (max optimze code) + SECTION .text + +; * +; * [1] VOID STDCALL RtlZeroMemory (PVOID Destination, ULONG Length); +; * + +_RtlZeroMemory@8: + + mov ecx,dword [esp + 8 ] ; Length + cmp ecx,0 ; if (Length==0) goto .zero + je .zero + + pushad ; Save all register on the stack + mov edi, dword [esp + (4 + 32)] ; Destination + xor eax,eax ; ZeroFillByte = 0 + + + +; code for take four byte each time it loop + mov ebx,ecx ; temp_Length = Length + shr ecx,2 ; Length = Length / sizeof(ULONG) + jz .1byte ; if (Length==0) goto .1byte + + shl ecx,2 ; Length = Length * sizeof(ULONG) + sub ebx,ecx ; temp_Length = temp_Length - Length; + jz .4bytes ; if (temp_Length==0) goto .4byte + +; move 4byte and 1byte + shr ecx,2 ; Length = Length / sizeof(ULONG) + cld ; clear d flag + rep stosd ; while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte; Legnth = Legnth - 1 } + mov ecx,ebx ; Length = temp_Length + rep stosb ; while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte; Legnth = Legnth - 1 } + popad ; restore register + ret 8 ; return + +; move 1byte +.1byte: + mov ecx,dword [esp + (12 +32) ] ; Length + cld ; clear d flag + rep stosb ; while (Length!=0) { (UCHAR *) Destination[Length-1]=ZeroFillByte; Legnth = Legnth - 1 } + popad ; restore register + ret 8 ; return + +; move 4bytes +.4bytes: + shr ecx,2 ; Length = Length / sizeof(ULONG) + cld ; clear d flag + rep stosd ; while (Length!=0) { (ULONG *) Destination[Length-1]=ZeroFillByte; Legnth = Legnth - 1 } + popad ; restore register +.zero: + ret 8 ; return