- Actually add libcntpr. Yup, I messed this up badly.

svn path=/trunk/; revision=26099
This commit is contained in:
Alex Ionescu 2007-03-14 20:30:32 +00:00
parent 1d6bb4a345
commit 7b13eab23c
134 changed files with 7027 additions and 0 deletions

View file

@ -0,0 +1,66 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Stack checker
* FILE: lib/ntdll/rtl/i386/chkstk.s
* PROGRAMER: KJK::Hyperion <noog@libero.it>
*/
.globl __chkstk
.globl __alloca_probe
/*
_chkstk() is called by all stack allocations of more than 4 KB. It grows the
stack in areas of 4 KB each, trying to access each area. This ensures that the
guard page for the stack is hit, and the stack growing triggered
*/
__chkstk:
__alloca_probe:
/* EAX = size to be allocated */
/* save the ECX register */
pushl %ecx
/* ECX = top of the previous stack frame */
leal 8(%esp), %ecx
/* probe the desired memory, page by page */
cmpl $0x1000, %eax
jge .l_MoreThanAPage
jmp .l_LessThanAPage
.l_MoreThanAPage:
/* raise the top of the stack by a page and probe */
subl $0x1000, %ecx
testl %eax, 0(%ecx)
/* loop if still more than a page must be probed */
subl $0x1000, %eax
cmpl $0x1000, %eax
jge .l_MoreThanAPage
.l_LessThanAPage:
/* raise the top of the stack by EAX bytes (size % 4096) and probe */
subl %eax, %ecx
testl %eax, 0(%ecx)
/* EAX = top of the stack */
movl %esp, %eax
/* allocate the memory */
movl %ecx, %esp
/* restore ECX */
movl 0(%eax), %ecx
/* restore the return address */
movl 4(%eax), %eax
pushl %eax
/* return */
ret
/* EOF */

View file

@ -0,0 +1,468 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS CRT
* FILE: lib/crt/misc/i386/seh.S
* PURPOSE: SEH Support for the CRT
* PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#include <ndk/asm.h>
.intel_syntax noprefix
#define DISPOSITION_DISMISS 0
#define DISPOSITION_CONTINUE_SEARCH 1
#define DISPOSITION_COLLIDED_UNWIND 3
/* GLOBALS *******************************************************************/
.globl __global_unwind2
.globl __local_unwind2
.globl __abnormal_termination
.globl __except_handler2
.globl __except_handler3
/* FUNCTIONS *****************************************************************/
.func unwind_handler
_unwind_handler:
/* Check if we were unwinding and continue search if not */
mov ecx, [esp+4]
test dword ptr [ecx+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
mov eax, DISPOSITION_CONTINUE_SEARCH
jz unwind_handler_return
/* We have a collision, do a local unwind */
mov eax, [esp+20]
push ebp
mov ebp, [eax+16]
mov edx, [eax+40]
push edx
mov edx, [eax+36]
push edx
call __local_unwind2
add esp, 8
pop ebp
/* Set new try level */
mov eax, [esp+8]
mov edx, [esp+16]
mov [edx], eax
/* Return collided unwind */
mov eax, DISPOSITION_COLLIDED_UNWIND
unwind_handler_return:
ret
.endfunc
.func _global_unwind2
__global_unwind2:
/* Create stack and save all registers */
push ebp
mov ebp, esp
push ebx
push esi
push edi
push ebp
/* Call unwind */
push 0
push 0
push glu_return
push [ebp+8]
call _RtlUnwind@16
glu_return:
/* Restore registers and return */
pop ebp
pop esi
pop edi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc
.func _abnormal_termination
__abnormal_termination:
/* Assume false */
xor eax, eax
/* Check if the handler is the unwind handler */
mov ecx, fs:0
cmp dword ptr [ecx+4], offset _unwind_handler
jne short ab_return
/* Get the try level */
mov edx, [ecx+12]
mov edx, [edx+12]
/* Compare it */
cmp [ecx+8], edx
jne ab_return
/* Return true */
mov eax, 1
/* Return */
ab_return:
ret
.endfunc
.func _local_unwind2
__local_unwind2:
/* Save volatiles */
push ebx
push esi
push edi
/* Get the exception registration */
mov eax, [esp+16]
/* Setup SEH to protect the unwind */
push ebp
push eax
push -2
push offset _unwind_handler
push fs:0
mov fs:0, esp
unwind_loop:
/* Get the exception registration and try level */
mov eax, [esp+36]
mov ebx, [eax+8]
mov esi, [eax+12]
/* Validate the unwind */
cmp esi, -1
je unwind_return
cmp dword ptr [esp+40], -1
je unwind_ok
cmp esi, [esp+40]
jbe unwind_return
unwind_ok:
/* Get the new enclosing level and save it */
lea esi, [esi+esi*2]
mov ecx, [ebx+esi*4]
mov [esp+8], ecx
mov [eax+12], ecx
/* Check the filter type */
cmp dword ptr [ebx+esi*4+4], 0
jnz __NLG_Return2
/* FIXME: NLG Notification */
/* Call the handler */
call dword ptr [ebx+esi*4+8]
__NLG_Return2:
/* Unwind again */
jmp unwind_loop
unwind_return:
/* Cleanup SEH */
pop fs:0
add esp, 16
pop edi
pop esi
pop ebx
ret
.endfunc
.func _except_handler2
__except_handler2:
/* Setup stack and save volatiles */
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
push ebp
/* Clear direction flag */
cld
/* Get exception registration and record */
mov ebx, [ebp+12]
mov eax, [ebp+8]
/* Check if this is an unwind */
test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
jnz except_unwind2
/* Save exception pointers structure */
mov [ebp-8], eax
mov eax, [ebp+16]
mov [ebp-4], eax
lea eax, [ebp-8]
mov [ebx+20], eax
/* Get the try level and scope table */
mov esi, [ebx+12]
mov esi, [ebx+8]
except_loop2:
/* Validate try level */
cmp esi, -1
je except_search2
/* Check if this is the termination handler */
lea ecx, [esi+esi*2]
cmp dword ptr [edi+ecx*4+4], 0
jz except_continue2
/* Save registers and call filter, then restore them */
push esi
push ebp
mov ebp, [ebx+16]
call dword ptr [edi+ecx*4+4]
pop ebp
pop esi
/* Restore ebx and check the result */
mov ebx, [ebp+12]
or eax, eax
jz except_continue2
jz except_dismiss2
/* So this is an accept, call the termination handlers */
mov edi, [ebx+8]
push ebx
call __global_unwind2
add esp, 4
/* Restore ebp */
mov ebp, [ebx+16]
/* Do local unwind */
push esi
push ebx
call __local_unwind2
add esp, 8
/* Set new try level */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4]
mov [ebx+12], eax
/* Call except handler */
call [edi+ecx*4+8]
except_continue2:
/* Reload try level and except again */
mov edi, [ebx+8]
lea ecx, [esi+esi*2]
mov esi, [edi+ecx*4]
jmp except_loop2
except_dismiss2:
/* Dismiss it */
mov eax, DISPOSITION_DISMISS
jmp except_return2
except_search2:
/* Continue searching */
mov eax, DISPOSITION_CONTINUE_SEARCH
jmp except_return2
/* Do local unwind */
except_unwind2:
push ebp
mov ebp, [ebx+16]
push -1
push ebx
call __local_unwind2
add esp, 8
/* Retore EBP and set return disposition */
pop ebp
mov eax, DISPOSITION_CONTINUE_SEARCH
except_return2:
/* Restore registers and stack */
pop ebp
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc
.func _except_handler3
__except_handler3:
/* Setup stack and save volatiles */
push ebp
mov ebp, esp
sub esp, 8
push ebx
push esi
push edi
push ebp
/* Clear direction flag */
cld
/* Get exception registration and record */
mov ebx, [ebp+12]
mov eax, [ebp+8]
/* Check if this is an unwind */
test dword ptr [eax+4], EXCEPTION_EXIT_UNWIND + EXCEPTION_UNWINDING
jnz except_unwind3
/* Save exception pointers structure */
mov [ebp-8], eax
mov eax, [ebp+16]
mov [ebp-4], eax
lea eax, [ebp-8]
mov [ebx-4], eax
/* Get the try level and scope table */
mov esi, [ebx+12]
mov esi, [ebx+8]
/* FIXME: Validate the SEH exception */
except_loop3:
/* Validate try level */
cmp esi, -1
je except_search3
/* Check if this is the termination handler */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4+4]
or eax, eax
jz except_continue3
/* Save registers clear them all */
push esi
push ebp
lea ebp, [ebx+16]
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
/* Call the filter and restore our registers */
call eax
pop ebp
pop esi
/* Restore ebx and check the result */
mov ebx, [ebp+12]
or eax, eax
jz except_continue3
jz except_dismiss3
/* So this is an accept, call the termination handlers */
mov edi, [ebx+8]
push ebx
call __global_unwind2
add esp, 4
/* Restore ebp */
lea ebp, [ebx+16]
/* Do local unwind */
push esi
push ebx
call __local_unwind2
add esp, 8
/* FIXME: Do NLG Notification */
/* Set new try level */
lea ecx, [esi+esi*2]
mov eax, [edi+ecx*4]
mov [ebx+12], eax
/* Clear registers and call except handler */
mov eax, [edi+ecx*4+8]
xor ebx, ebx
xor ecx, ecx
xor edx, edx
xor esi, esi
xor edi, edi
call eax
except_continue3:
/* Reload try level and except again */
mov edi, [ebx+8]
lea ecx, [esi+esi*2]
mov esi, [edi+ecx*4]
jmp except_loop3
except_dismiss3:
/* Dismiss it */
mov eax, DISPOSITION_DISMISS
jmp except_return3
except_search3:
/* Continue searching */
mov eax, DISPOSITION_CONTINUE_SEARCH
jmp except_return3
/* Do local unwind */
except_unwind3:
push ebp
mov ebp, [ebx+16]
push -1
push ebx
call __local_unwind2
add esp, 8
/* Retore EBP and set return disposition */
pop ebp
mov eax, DISPOSITION_CONTINUE_SEARCH
except_return3:
/* Restore registers and stack */
pop ebp
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
.endfunc
//
//
// REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME REMOVE ME
//
//
.func RtlpGetStackLimits@8
.globl _RtlpGetStackLimits@8
_RtlpGetStackLimits@8:
/* Get the current thread */
mov eax, [fs:KPCR_CURRENT_THREAD]
/* Get the stack limits */
mov ecx, [eax+KTHREAD_STACK_LIMIT]
mov edx, [eax+KTHREAD_INITIAL_STACK]
sub edx, SIZEOF_FX_SAVE_AREA
/* Return them */
mov eax, [esp+4]
mov [eax], ecx
mov eax, [esp+8]
mov [eax], edx
/* return */
ret 8
.endfunc

View file

@ -0,0 +1,22 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS System Libraries
* FILE: lib/sdk/libcntpr/libcntpr.h
* PURPOSE: NT Private CRT
* PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
*/
/* INCLUDES ******************************************************************/
#ifndef _LIBCNT_
#define _LIBCNT_
//
// C Headers
//
#include <stdlib.h>
#include <stdio.h>
#endif /* _LIBCNT_ */
/* EOF */

View file

@ -0,0 +1,153 @@
<module name="libcntpr" type="staticlibrary">
<define name="__USE_W32API" />
<define name="__NO_CTYPE_INLINES" />
<define name="NO_RTL_INLINES" />
<define name="_NTSYSTEM_" />
<define name="_NTDLLBUILD_" />
<define name="_SEH_NO_NATIVE_NLG" />
<define name="__MINGW_IMPORT">"extern __attribute__ ((dllexport))"</define>
<include base="libcntpr">.</include>
<directory name="except">
<if property="ARCH" value="i386">
<directory name="i386">
<file>chkstk_asm.s</file>
<file>seh.s</file>
</directory>
</if>
</directory>
<directory name="math">
<if property="ARCH" value="i386">
<directory name="i386">
<file>alldiv_asm.s</file>
<file>alldvrm_asm.s</file>
<file>allmul_asm.s</file>
<file>allrem_asm.s</file>
<file>allshl_asm.s</file>
<file>allshr_asm.s</file>
<file>atan_asm.s</file>
<file>aulldiv_asm.s</file>
<file>aulldvrm_asm.s</file>
<file>aullrem_asm.s</file>
<file>aullshr_asm.s</file>
<file>ceil_asm.s</file>
<file>cos_asm.s</file>
<file>fabs_asm.s</file>
<file>floor_asm.s</file>
<file>ftol_asm.s</file>
<file>log_asm.s</file>
<file>pow_asm.s</file>
<file>sin_asm.s</file>
<file>sqrt_asm.s</file>
<file>tan_asm.s</file>
</directory>
</if>
<file>abs.c</file>
<file>bsearch.c</file>
<file>labs.c</file>
<file>rand.c</file>
</directory>
<directory name="mem">
<if property="ARCH" value="i386">
<directory name="i386">
<file>memchr_asm.s</file>
<file>memcpy_asm.s</file>
<file>memmove_asm.s</file>
<file>memset_asm.s</file>
</directory>
</if>
<ifnot property="ARCH" value="i386">
<file>memchr.c</file>
<file>memcpy.c</file>
<file>memmove.c</file>
<file>memset.c</file>
</ifnot>
<file>memccpy.c</file>
<file>memcmp.c</file>
<file>memicmp.c</file>
</directory>
<directory name="string">
<if property="ARCH" value="i386">
<directory name="i386">
<file>strcat_asm.s</file>
<file>strchr_asm.s</file>
<file>strcmp_asm.s</file>
<file>strcpy_asm.s</file>
<file>strlen_asm.s</file>
<file>strncat_asm.s</file>
<file>strncmp_asm.s</file>
<file>strncpy_asm.s</file>
<file>strnlen_asm.s</file>
<file>strrchr_asm.s</file>
<file>wcscat_asm.s</file>
<file>wcschr_asm.s</file>
<file>wcscmp_asm.s</file>
<file>wcscpy_asm.s</file>
<file>wcslen_asm.s</file>
<file>wcsncat_asm.s</file>
<file>wcsncmp_asm.s</file>
<file>wcsncpy_asm.s</file>
<file>wcsnlen_asm.s</file>
<file>wcsrchr_asm.s</file>
</directory>
</if>
<ifnot property="ARCH" value="i386">
<file>strcat.c</file>
<file>strchr.c</file>
<file>strcmp.c</file>
<file>strcpy.c</file>
<file>strlen.c</file>
<file>strncat.c</file>
<file>strncmp.c</file>
<file>strncpy.c</file>
<file>strnlen.c</file>
<file>strrchr.c</file>
<file>wcscat.c</file>
<file>wcschr.c</file>
<file>wcscmp.c</file>
<file>wcscpy.c</file>
<file>wcslen.c</file>
<file>wcsncat.c</file>
<file>wcsncmp.c</file>
<file>wcsncpy.c</file>
<file>wcsnlen.c</file>
<file>wcsrchr.c</file>
</ifnot>
<file>ctype.c</file>
<file>strcspn.c</file>
<file>stricmp.c</file>
<file>strnicmp.c</file>
<file>strlwr.c</file>
<file>strrev.c</file>
<file>strset.c</file>
<file>strstr.c</file>
<file>strupr.c</file>
<file>strpbrk.c</file>
<file>strspn.c</file>
<file>wstring.c</file>
<file>wcsrev.c</file>
<file>wcsnset.c</file>
<file>atoi64.c</file>
<file>atoi.c</file>
<file>atol.c</file>
<file>itoa.c</file>
<file>itow.c</file>
<file>lfind.c</file>
<file>mbstowcs.c</file>
<file>splitp.c</file>
<file>strtol.c</file>
<file>strtoul.c</file>
<file>wcstol.c</file>
<file>wcstombs.c</file>
<file>wcstoul.c</file>
<file>wtoi64.c</file>
<file>wtoi.c</file>
<file>wtol.c</file>
<file>sscanf.c</file>
</directory>
<pch>libcntpr.h</pch>
</module>

View file

@ -0,0 +1,10 @@
#include <string.h>
/*
* @implemented
*/
int
abs(int j)
{
return j<0 ? -j : j;
}

View file

@ -0,0 +1,27 @@
#include <string.h>
/*
* @implemented
*/
void *
bsearch(const void *key, const void *base0, size_t nelem,
size_t size, int (*cmp)(const void *ck, const void *ce))
{
const char *base = base0;
int lim, cmpval;
const void *p;
for (lim = nelem; lim != 0; lim >>= 1)
{
p = base + (lim >> 1) * size;
cmpval = (*cmp)(key, p);
if (cmpval == 0)
return (void*)((size_t)p);
if (cmpval > 0)
{ /* key > p: move right */
base = (const char *)p + size;
lim--;
} /* else move left */
}
return 0;
}

View file

@ -0,0 +1,225 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/alldiv_asm.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __alldiv
.globl __fltused
/* DATA ********************************************************************/
__fltused:
.long 0x9875
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// lldiv - signed long divide
//
// Purpose:
// Does a signed long divide of the arguments. Arguments are
// not changed.
//
// Entry:
// Arguments are passed on the stack:
// 1st pushed: divisor (QWORD)
// 2nd pushed: dividend (QWORD)
//
// Exit:
// EDX:EAX contains the quotient (dividend/divisor)
// NOTE: this routine removes the parameters from the stack.
//
// Uses:
// ECX
//
__alldiv:
push edi
push esi
push ebx
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a/b will
// generate a call to lldiv(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// | EDI |
// |---------------|
// | ESI |
// |---------------|
// ESP---->| EBX |
// -----------------
//
#define DVNDLO [esp + 16] // stack address of dividend (a)
#define DVNDHI [esp + 20] // stack address of dividend (a)
#define DVSRLO [esp + 24] // stack address of divisor (b)
#define DVSRHI [esp + 28] // stack address of divisor (b)
// Determine sign of the result (edi = 0 if result is positive, non-zero
// otherwise) and make operands positive.
xor edi,edi // result sign assumed positive
mov eax,DVNDHI // hi word of a
or eax,eax // test to see if signed
jge short L1 // skip rest if a is already positive
inc edi // complement result sign flag
mov edx,DVNDLO // lo word of a
neg eax // make a positive
neg edx
sbb eax,0
mov DVNDHI,eax // save positive value
mov DVNDLO,edx
L1:
mov eax,DVSRHI // hi word of b
or eax,eax // test to see if signed
jge short L2 // skip rest if b is already positive
inc edi // complement the result sign flag
mov edx,DVSRLO // lo word of a
neg eax // make b positive
neg edx
sbb eax,0
mov DVSRHI,eax // save positive value
mov DVSRLO,edx
L2:
//
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
// NOTE - eax currently contains the high order word of DVSR
//
or eax,eax // check to see if divisor < 4194304K
jnz short L3 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // eax <- high order bits of quotient
mov ebx,eax // save high bits of quotient
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // eax <- low order bits of quotient
mov edx,ebx // edx:eax <- quotient
jmp short L4 // set sign, restore stack and return
//
// Here we do it the hard way. Remember, eax contains the high word of DVSR
//
L3:
mov ebx,eax // ebx:ecx <- divisor
mov ecx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
L5:
shr ebx,1 // shift divisor right one bit
rcr ecx,1
shr edx,1 // shift dividend right one bit
rcr eax,1
or ebx,ebx
jnz short L5 // loop until divisor < 4194304K
div ecx // now divide, ignore remainder
mov esi,eax // save quotient
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mul dword ptr DVSRHI // QUOT * DVSRHI
mov ecx,eax
mov eax,DVSRLO
mul esi // QUOT * DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short L6 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
// subtract one (1) from the quotient.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short L6 // if result > original, do subtract
jb short L7 // if result < original, we are ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short L7 // if less or equal we are ok, else subtract
L6:
dec esi // subtract 1 from quotient
L7:
xor edx,edx // edx:eax <- quotient
mov eax,esi
//
// Just the cleanup left to do. edx:eax contains the quotient. Set the sign
// according to the save value, cleanup the stack, and return.
//
L4:
dec edi // check to see if result is negative
jnz short L8 // if EDI == 0, result should be negative
neg edx // otherwise, negate the result
neg eax
sbb edx,0
//
// Restore the saved registers and return.
//
L8:
pop ebx
pop esi
pop edi
ret 16

View file

@ -0,0 +1,247 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/alldvrm.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __alldvrm
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
__alldvrm:
push edi
push esi
push ebp
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a/b will
// generate a call to alldvrm(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// | EDI |
// |---------------|
// | ESI |
// |---------------|
// ESP---->| EBP |
// -----------------
//
#undef DVNDLO
#undef DVNDHI
#undef DVSRLO
#undef DVSRHI
#define DVNDLO [esp + 16] // stack address of dividend (a)
#define DVNDHI [esp + 20] // stack address of dividend (a)
#define DVSRLO [esp + 24] // stack address of divisor (b)
#define DVSRHI [esp + 28] // stack address of divisor (b)
// Determine sign of the quotient (edi = 0 if result is positive, non-zero
// otherwise) and make operands positive.
// Sign of the remainder is kept in ebp.
xor edi,edi // result sign assumed positive
xor ebp,ebp // result sign assumed positive
mov eax,DVNDHI // hi word of a
or eax,eax // test to see if signed
jge short ....L1 // skip rest if a is already positive
inc edi // complement result sign flag
inc ebp // complement result sign flag
mov edx,DVNDLO // lo word of a
neg eax // make a positive
neg edx
sbb eax,0
mov DVNDHI,eax // save positive value
mov DVNDLO,edx
....L1:
mov eax,DVSRHI // hi word of b
or eax,eax // test to see if signed
jge short ....L2 // skip rest if b is already positive
inc edi // complement the result sign flag
mov edx,DVSRLO // lo word of a
neg eax // make b positive
neg edx
sbb eax,0
mov DVSRHI,eax // save positive value
mov DVSRLO,edx
....L2:
//
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
// NOTE - eax currently contains the high order word of DVSR
//
or eax,eax // check to see if divisor < 4194304K
jnz short ....L3 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // eax <- high order bits of quotient
mov ebx,eax // save high bits of quotient
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // eax <- low order bits of quotient
mov esi,eax // ebx:esi <- quotient
//
// Now we need to do a multiply so that we can compute the remainder.
//
mov eax,ebx // set up high word of quotient
mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR
mov ecx,eax // save the result in ecx
mov eax,esi // set up low word of quotient
mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR
add edx,ecx // EDX:EAX = QUOT * DVSR
jmp short ....L4 // complete remainder calculation
//
// Here we do it the hard way. Remember, eax contains the high word of DVSR
//
....L3:
mov ebx,eax // ebx:ecx <- divisor
mov ecx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
....L5:
shr ebx,1 // shift divisor right one bit
rcr ecx,1
shr edx,1 // shift dividend right one bit
rcr eax,1
or ebx,ebx
jnz short ....L5 // loop until divisor < 4194304K
div ecx // now divide, ignore remainder
mov esi,eax // save quotient
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mul dword ptr DVSRHI // QUOT * DVSRHI
mov ecx,eax
mov eax,DVSRLO
mul esi // QUOT * DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short ....L6 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
// subtract one (1) from the quotient.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short ....L6 // if result > original, do subtract
jb short ....L7 // if result < original, we are ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short ....L7 // if less or equal we are ok, else subtract
....L6:
dec esi // subtract 1 from quotient
sub eax,DVSRLO // subtract divisor from result
sbb edx,DVSRHI
....L7:
xor ebx,ebx // ebx:esi <- quotient
....L4:
//
// Calculate remainder by subtracting the result from the original dividend.
// Since the result is already in a register, we will do the subtract in the
// opposite direction and negate the result if necessary.
//
sub eax,DVNDLO // subtract dividend from result
sbb edx,DVNDHI
//
// Now check the result sign flag to see if the result is supposed to be positive
// or negative. It is currently negated (because we subtracted in the 'wrong'
// direction), so if the sign flag is set we are done, otherwise we must negate
// the result to make it positive again.
//
dec ebp // check result sign flag
jns short ....L9 // result is ok, set up the quotient
neg edx // otherwise, negate the result
neg eax
sbb edx,0
//
// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx.
//
....L9:
mov ecx,edx
mov edx,ebx
mov ebx,ecx
mov ecx,eax
mov eax,esi
//
// Just the cleanup left to do. edx:eax contains the quotient. Set the sign
// according to the save value, cleanup the stack, and return.
//
dec edi // check to see if result is negative
jnz short ....L8 // if EDI == 0, result should be negative
neg edx // otherwise, negate the result
neg eax
sbb edx,0
//
// Restore the saved registers and return.
//
....L8:
pop ebp
pop esi
pop edi
ret 16

View file

@ -0,0 +1,116 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/allmul.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __allmul
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// llmul - long multiply routine
//
// Purpose:
// Does a long multiply (same for signed/unsigned)
// Parameters are not changed.
//
// Entry:
// Parameters are passed on the stack:
// 1st pushed: multiplier (QWORD)
// 2nd pushed: multiplicand (QWORD)
//
// Exit:
// EDX:EAX - product of multiplier and multiplicand
// NOTE: parameters are removed from the stack
//
// Uses:
// ECX
//
__allmul:
#define ALO [esp + 4] // stack address of a
#define AHI [esp + 8] // stack address of a
#define BLO [esp + 12] // stack address of b
#define BHI [esp + 16] // stack address of b
//
// AHI, BHI : upper 32 bits of A and B
// ALO, BLO : lower 32 bits of A and B
//
// ALO * BLO
// ALO * BHI
// + BLO * AHI
// ---------------------
//
mov eax,AHI
mov ecx,BHI
or ecx,eax //test for both hiwords zero.
mov ecx,BLO
jnz short hard //both are zero, just mult ALO and BLO
mov eax,AHI
mul ecx
ret 16 // callee restores the stack
hard:
push ebx
// must redefine A and B since esp has been altered
#define A2LO [esp + 4] // stack address of a
#define A2HI [esp + 8] // stack address of a
#define B2LO [esp + 12] // stack address of b
#define B2HI [esp + 16] // stack address of b
mul ecx //eax has AHI, ecx has BLO, so AHI * BLO
mov ebx,eax //save result
mov eax,A2LO
mul dword ptr B2HI //ALO * BHI
add ebx,eax //ebx = ((ALO * BHI) + (AHI * BLO))
mov eax,A2LO //ecx = BLO
mul ecx //so edx:eax = ALO*BLO
add edx,ebx //now edx has all the LO*HI stuff
pop ebx
ret 16 // callee restores the stack

View file

@ -0,0 +1,230 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/allrem.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __allrem
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// llrem - signed long remainder
//
// Purpose:
// Does a signed long remainder of the arguments. Arguments are
// not changed.
//
// Entry:
// Arguments are passed on the stack:
// 1st pushed: divisor (QWORD)
// 2nd pushed: dividend (QWORD)
//
// Exit:
// EDX:EAX contains the remainder (dividend%divisor)
// NOTE: this routine removes the parameters from the stack.
//
// Uses:
// ECX
//
__allrem :
push ebx
push edi
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a%b will
// generate a call to lrem(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// | EBX |
// |---------------|
// ESP---->| EDI |
// -----------------
//
#undef DVNDLO
#undef DVNDHI
#undef DVSRLO
#undef DVSRHI
#define DVNDLO [esp + 12] // stack address of dividend (a)
#define DVNDHI [esp + 16] // stack address of dividend (a)
#define DVSRLO [esp + 20] // stack address of divisor (b)
#define DVSRHI [esp + 24] // stack address of divisor (b)
// Determine sign of the result (edi = 0 if result is positive, non-zero
// otherwise) and make operands positive.
xor edi,edi // result sign assumed positive
mov eax,DVNDHI // hi word of a
or eax,eax // test to see if signed
jge short .L1 // skip rest if a is already positive
inc edi // complement result sign flag bit
mov edx,DVNDLO // lo word of a
neg eax // make a positive
neg edx
sbb eax,0
mov DVNDHI,eax // save positive value
mov DVNDLO,edx
.L1:
mov eax,DVSRHI // hi word of b
or eax,eax // test to see if signed
jge short .L2 // skip rest if b is already positive
mov edx,DVSRLO // lo word of b
neg eax // make b positive
neg edx
sbb eax,0
mov DVSRHI,eax // save positive value
mov DVSRLO,edx
.L2:
//
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
// NOTE - eax currently contains the high order word of DVSR
//
or eax,eax // check to see if divisor < 4194304K
jnz short .L3 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // edx <- remainder
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // edx <- final remainder
mov eax,edx // edx:eax <- remainder
xor edx,edx
dec edi // check result sign flag
jns short .L4 // negate result, restore stack and return
jmp short .L8 // result sign ok, restore stack and return
//
// Here we do it the hard way. Remember, eax contains the high word of DVSR
//
.L3:
mov ebx,eax // ebx:ecx <- divisor
mov ecx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
.L5:
shr ebx,1 // shift divisor right one bit
rcr ecx,1
shr edx,1 // shift dividend right one bit
rcr eax,1
or ebx,ebx
jnz short .L5 // loop until divisor < 4194304K
div ecx // now divide, ignore remainder
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mov ecx,eax // save a copy of quotient in ECX
mul dword ptr DVSRHI
xchg ecx,eax // save product, get quotient in EAX
mul dword ptr DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short .L6 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
// subtract the original divisor from the result.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short .L6 // if result > original, do subtract
jb short .L7 // if result < original, we are ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short .L7 // if less or equal we are ok, else subtract
.L6:
sub eax,DVSRLO // subtract divisor from result
sbb edx,DVSRHI
.L7:
//
// Calculate remainder by subtracting the result from the original dividend.
// Since the result is already in a register, we will do the subtract in the
// opposite direction and negate the result if necessary.
//
sub eax,DVNDLO // subtract dividend from result
sbb edx,DVNDHI
//
// Now check the result sign flag to see if the result is supposed to be positive
// or negative. It is currently negated (because we subtracted in the 'wrong'
// direction), so if the sign flag is set we are done, otherwise we must negate
// the result to make it positive again.
//
dec edi // check result sign flag
jns short .L8 // result is ok, restore stack and return
.L4:
neg edx // otherwise, negate the result
neg eax
sbb edx,0
//
// Just the cleanup left to do. edx:eax contains the quotient.
// Restore the saved registers and return.
//
.L8:
pop edi
pop ebx
ret 16

View file

@ -0,0 +1,95 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/allshl.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __allshl
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// llshl - long shift left
//
// Purpose:
// Does a Long Shift Left (signed and unsigned are identical)
// Shifts a long left any number of bits.
//
// Entry:
// EDX:EAX - long value to be shifted
// CL - number of bits to shift by
//
// Exit:
// EDX:EAX - shifted value
//
// Uses:
// CL is destroyed.
//
__allshl:
//
// Handle shifts of 64 or more bits (all get 0)
//
cmp cl, 64
jae short RETZERO
//
// Handle shifts of between 0 and 31 bits
//
cmp cl, 32
jae short MORE32
shld edx,eax,cl
shl eax,cl
ret
//
// Handle shifts of between 32 and 63 bits
//
MORE32:
mov edx,eax
xor eax,eax
and cl,31
shl edx,cl
ret
//
// return 0 in edx:eax
//
RETZERO:
xor eax,eax
xor edx,edx
ret

View file

@ -0,0 +1,96 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/allshr.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __allshr
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// llshr - long shift right
//
// Purpose:
// Does a signed Long Shift Right
// Shifts a long right any number of bits.
//
// Entry:
// EDX:EAX - long value to be shifted
// CL - number of bits to shift by
//
// Exit:
// EDX:EAX - shifted value
//
// Uses:
// CL is destroyed.
//
__allshr:
//
// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
// depends only on the high order bit of edx).
//
cmp cl,64
jae short .RETSIGN
//
// Handle shifts of between 0 and 31 bits
//
cmp cl, 32
jae short .MORE32
shrd eax,edx,cl
sar edx,cl
ret
//
// Handle shifts of between 32 and 63 bits
//
.MORE32:
mov eax,edx
sar edx,31
and cl,31
sar eax,cl
ret
//
// Return double precision 0 or -1, depending on the sign of edx
//
.RETSIGN:
sar edx,31
mov eax,edx
ret

View file

@ -0,0 +1,51 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/atan.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _atan
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_atan:
push ebp
mov ebp,esp
fld qword ptr [ebp+8] // Load real from stack
fld1 // Load constant 1
fpatan // Take the arctangent
pop ebp
ret

View file

@ -0,0 +1,180 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/aulldiv_asm.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __aulldiv
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// ulldiv - unsigned long divide
//
// Purpose:
// Does a unsigned long divide of the arguments. Arguments are
// not changed.
//
// Entry:
// Arguments are passed on the stack:
// 1st pushed: divisor (QWORD)
// 2nd pushed: dividend (QWORD)
//
// Exit:
// EDX:EAX contains the quotient (dividend/divisor)
// NOTE: this routine removes the parameters from the stack.
//
// Uses:
// ECX
//
__aulldiv:
push ebx
push esi
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a/b will
// generate a call to uldiv(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// | EBX |
// |---------------|
// ESP---->| ESI |
// -----------------
//
#undef DVNDLO
#undef DVNDHI
#undef DVSRLO
#undef DVSRHI
#define DVNDLO [esp + 12] // stack address of dividend (a)
#define DVNDHI [esp + 16] // stack address of dividend (a)
#define DVSRLO [esp + 20] // stack address of divisor (b)
#define DVSRHI [esp + 24] // stack address of divisor (b)
//
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
mov eax,DVSRHI // check to see if divisor < 4194304K
or eax,eax
jnz short ..L1 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // get high order bits of quotient
mov ebx,eax // save high bits of quotient
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // get low order bits of quotient
mov edx,ebx // edx:eax <- quotient hi:quotient lo
jmp short ..L2 // restore stack and return
//
// Here we do it the hard way. Remember, eax contains DVSRHI
//
..L1:
mov ecx,eax // ecx:ebx <- divisor
mov ebx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
..L3:
shr ecx,1 // shift divisor right one bit// hi bit <- 0
rcr ebx,1
shr edx,1 // shift dividend right one bit// hi bit <- 0
rcr eax,1
or ecx,ecx
jnz short ..L3 // loop until divisor < 4194304K
div ebx // now divide, ignore remainder
mov esi,eax // save quotient
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mul dword ptr DVSRHI // QUOT * DVSRHI
mov ecx,eax
mov eax,DVSRLO
mul esi // QUOT * DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short ..L4 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
// subtract one (1) from the quotient.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short ..L4 // if result > original, do subtract
jb short ..L5 // if result < original, we are ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short ..L5 // if less or equal we are ok, else subtract
..L4:
dec esi // subtract 1 from quotient
..L5:
xor edx,edx // edx:eax <- quotient
mov eax,esi
//
// Just the cleanup left to do. edx:eax contains the quotient.
// Restore the saved registers and return.
//
..L2:
pop esi
pop ebx
ret 16

View file

@ -0,0 +1,205 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/aulldvrm.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __aulldvrm
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
__aulldvrm:
// ulldvrm - unsigned long divide and remainder
//
// Purpose:
// Does a unsigned long divide and remainder of the arguments. Arguments
// are not changed.
//
// Entry:
// Arguments are passed on the stack:
// 1st pushed: divisor (QWORD)
// 2nd pushed: dividend (QWORD)
//
// Exit:
// EDX:EAX contains the quotient (dividend/divisor)
// EBX:ECX contains the remainder (divided % divisor)
// NOTE: this routine removes the parameters from the stack.
//
// Uses:
// ECX
//
push esi
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a/b will
// generate a call to aulldvrm(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// ESP---->| ESI |
// -----------------
//
#undef DVNDLO
#undef DVNDHI
#undef DVSRLO
#undef DVSRHI
#define DVNDLO [esp + 8] // stack address of dividend (a)
#define DVNDHI [esp + 8] // stack address of dividend (a)
#define DVSRLO [esp + 16] // stack address of divisor (b)
#define DVSRHI [esp + 20] // stack address of divisor (b)
//
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
mov eax,DVSRHI // check to see if divisor < 4194304K
or eax,eax
jnz short .....L1 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // get high order bits of quotient
mov ebx,eax // save high bits of quotient
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // get low order bits of quotient
mov esi,eax // ebx:esi <- quotient
//
// Now we need to do a multiply so that we can compute the remainder.
//
mov eax,ebx // set up high word of quotient
mul dword ptr DVSRLO // HIWORD(QUOT) * DVSR
mov ecx,eax // save the result in ecx
mov eax,esi // set up low word of quotient
mul dword ptr DVSRLO // LOWORD(QUOT) * DVSR
add edx,ecx // EDX:EAX = QUOT * DVSR
jmp short .....L2 // complete remainder calculation
//
// Here we do it the hard way. Remember, eax contains DVSRHI
//
.....L1:
mov ecx,eax // ecx:ebx <- divisor
mov ebx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
.....L3:
shr ecx,1 // shift divisor right one bit// hi bit <- 0
rcr ebx,1
shr edx,1 // shift dividend right one bit// hi bit <- 0
rcr eax,1
or ecx,ecx
jnz short .....L3 // loop until divisor < 4194304K
div ebx // now divide, ignore remainder
mov esi,eax // save quotient
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mul dword ptr DVSRHI // QUOT * DVSRHI
mov ecx,eax
mov eax,DVSRLO
mul esi // QUOT * DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short .....L4 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we are ok, otherwise
// subtract one (1) from the quotient.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short .....L4 // if result > original, do subtract
jb short .....L5 // if result < original, we are ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short .....L5 // if less or equal we are ok, else subtract
.....L4:
dec esi // subtract 1 from quotient
sub eax,DVSRLO // subtract divisor from result
sbb edx,DVSRHI
.....L5:
xor ebx,ebx // ebx:esi <- quotient
.....L2:
//
// Calculate remainder by subtracting the result from the original dividend.
// Since the result is already in a register, we will do the subtract in the
// opposite direction and negate the result.
//
sub eax,DVNDLO // subtract dividend from result
sbb edx,DVNDHI
neg edx // otherwise, negate the result
neg eax
sbb edx,0
//
// Now we need to get the quotient into edx:eax and the remainder into ebx:ecx.
//
mov ecx,edx
mov edx,ebx
mov ebx,ecx
mov ecx,eax
mov eax,esi
//
// Just the cleanup left to do. edx:eax contains the quotient.
// Restore the saved registers and return.
//
pop esi
ret 16

View file

@ -0,0 +1,185 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/aullrem.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __aullrem
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// ullrem - unsigned long remainder
//
// Purpose:
// Does a unsigned long remainder of the arguments. Arguments are
// not changed.
//
// Entry:
// Arguments are passed on the stack:
// 1st pushed: divisor (QWORD)
// 2nd pushed: dividend (QWORD)
//
// Exit:
// EDX:EAX contains the remainder (dividend%divisor)
// NOTE: this routine removes the parameters from the stack.
//
// Uses:
// ECX
//
__aullrem:
push ebx
// Set up the local stack and save the index registers. When this is done
// the stack frame will look as follows (assuming that the expression a%b will
// generate a call to ullrem(a, b)):
//
// -----------------
// | |
// |---------------|
// | |
// |--divisor (b)--|
// | |
// |---------------|
// | |
// |--dividend (a)-|
// | |
// |---------------|
// | return addr** |
// |---------------|
// ESP---->| EBX |
// -----------------
//
#undef DVNDLO
#undef DVNDHI
#undef DVSRLO
#undef DVSRHI
#define DVNDLO [esp + 8] // stack address of dividend (a)
#define DVNDHI [esp + 8] // stack address of dividend (a)
#define DVSRLO [esp + 16] // stack address of divisor (b)
#define DVSRHI [esp + 20] // stack address of divisor (b)
// Now do the divide. First look to see if the divisor is less than 4194304K.
// If so, then we can use a simple algorithm with word divides, otherwise
// things get a little more complex.
//
mov eax,DVSRHI // check to see if divisor < 4194304K
or eax,eax
jnz short ...L1 // nope, gotta do this the hard way
mov ecx,DVSRLO // load divisor
mov eax,DVNDHI // load high word of dividend
xor edx,edx
div ecx // edx <- remainder, eax <- quotient
mov eax,DVNDLO // edx:eax <- remainder:lo word of dividend
div ecx // edx <- final remainder
mov eax,edx // edx:eax <- remainder
xor edx,edx
jmp short ...L2 // restore stack and return
//
// Here we do it the hard way. Remember, eax contains DVSRHI
//
...L1:
mov ecx,eax // ecx:ebx <- divisor
mov ebx,DVSRLO
mov edx,DVNDHI // edx:eax <- dividend
mov eax,DVNDLO
...L3:
shr ecx,1 // shift divisor right one bit// hi bit <- 0
rcr ebx,1
shr edx,1 // shift dividend right one bit// hi bit <- 0
rcr eax,1
or ecx,ecx
jnz short ...L3 // loop until divisor < 4194304K
div ebx // now divide, ignore remainder
//
// We may be off by one, so to check, we will multiply the quotient
// by the divisor and check the result against the orignal dividend
// Note that we must also check for overflow, which can occur if the
// dividend is close to 2**64 and the quotient is off by 1.
//
mov ecx,eax // save a copy of quotient in ECX
mul dword ptr DVSRHI
xchg ecx,eax // put partial product in ECX, get quotient in EAX
mul dword ptr DVSRLO
add edx,ecx // EDX:EAX = QUOT * DVSR
jc short ...L4 // carry means Quotient is off by 1
//
// do long compare here between original dividend and the result of the
// multiply in edx:eax. If original is larger or equal, we're ok, otherwise
// subtract the original divisor from the result.
//
cmp edx,DVNDHI // compare hi words of result and original
ja short ...L4 // if result > original, do subtract
jb short ...L5 // if result < original, we're ok
cmp eax,DVNDLO // hi words are equal, compare lo words
jbe short ...L5 // if less or equal we're ok, else subtract
...L4:
sub eax,DVSRLO // subtract divisor from result
sbb edx,DVSRHI
...L5:
//
// Calculate remainder by subtracting the result from the original dividend.
// Since the result is already in a register, we will perform the subtract in
// the opposite direction and negate the result to make it positive.
//
sub eax,DVNDLO // subtract original dividend from result
sbb edx,DVNDHI
neg edx // and negate it
neg eax
sbb edx,0
//
// Just the cleanup left to do. dx:ax contains the remainder.
// Restore the saved registers and return.
//
...L2:
pop ebx
ret 16

View file

@ -0,0 +1,96 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/uallshr.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __aullshr
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
//
// ullshr - long shift right
//
// Purpose:
// Does a unsigned Long Shift Right
// Shifts a long right any number of bits.
//
// Entry:
// EDX:EAX - long value to be shifted
// CL - number of bits to shift by
//
// Exit:
// EDX:EAX - shifted value
//
// Uses:
// CL is destroyed.
//
__aullshr:
//
// Handle shifts of 64 bits or more (if shifting 64 bits or more, the result
// depends only on the high order bit of edx).
//
cmp cl,64
jae short ..RETZERO
//
// Handle shifts of between 0 and 31 bits
//
cmp cl, 32
jae short ..MORE32
shrd eax,edx,cl
shr edx,cl
ret
//
// Handle shifts of between 32 and 63 bits
//
..MORE32:
mov eax,edx
xor edx,edx
and cl,31
shr eax,cl
ret
//
// return 0 in edx:eax
//
..RETZERO:
xor eax,eax
xor edx,edx
ret

View file

@ -0,0 +1,58 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/ceil.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _ceil
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_ceil:
push ebp
mov ebp,esp
sub esp,4 // Allocate temporary space
fld qword ptr [ebp+8] // Load real from stack
fstcw [ebp-2] // Save control word
fclex // Clear exceptions
mov word ptr [ebp-4],0xb63 // Rounding control word
fldcw [ebp-4] // Set new rounding control
frndint // Round to integer
fclex // Clear exceptions
fldcw [ebp-2] // Restore control word
mov esp,ebp // Deallocate temporary space
pop ebp
ret

View file

@ -0,0 +1,50 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/cos.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _cos
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_cos:
push ebp
mov ebp,esp // Point to the stack frame
fld qword ptr [ebp+8] // Load real from stack
fcos // Take the cosine
pop ebp
ret

View file

@ -0,0 +1,50 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/fabs.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _fabs
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_fabs:
push ebp
mov ebp,esp
fld qword ptr [ebp+8] // Load real from stack
fabs // Take the absolute value
pop ebp
ret

View file

@ -0,0 +1,58 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/floor.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _floor
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_floor:
push ebp
mov ebp,esp
sub esp,4 // Allocate temporary space
fld qword ptr [ebp+8] // Load real from stack
fstcw [ebp-2] // Save control word
fclex // Clear exceptions
mov word ptr [ebp-4],0x763 // Rounding control word
fldcw [ebp-4] // Set new rounding control
frndint // Round to integer
fclex // Clear exceptions
fldcw [ebp-2] // Restore control word
mov esp,ebp
pop ebp
ret

View file

@ -0,0 +1,74 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/ftol.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl __ftol
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
/*
* This routine is called by MSVC-generated code to convert from floating point
* to integer representation. The floating point number to be converted is
* on the top of the floating point stack.
*/
__ftol:
/* Set up stack frame */
push ebp
mov ebp, esp
/* Set "round towards zero" mode */
fstcw [ebp-2]
wait
mov ax, [ebp-2]
or ah, 0xC
mov [ebp-4], ax
fldcw [ebp-4]
/* Do the conversion */
fistp qword ptr [ebp-12]
/* Restore rounding mode */
fldcw [ebp-2]
/* Return value */
mov eax, [ebp-12]
mov edx, [ebp-8]
/* Remove stack frame and return*/
leave
ret

View file

@ -0,0 +1,52 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/log.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _log
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_log:
push ebp
mov ebp,esp
fld qword ptr [ebp+8] // Load real from stack
fldln2 // Load log base e of 2
fxch st(1) // Exchange st, st(1)
fyl2x // Compute the natural log(x)
pop ebp
ret

View file

@ -0,0 +1,140 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/pow.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _pow
/* DATA ********************************************************************/
fzero:
.long 0 // Floating point zero
.long 0 // Floating point zero
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_pow:
push ebp
mov ebp,esp
sub esp,12 // Allocate temporary space
push edi // Save register edi
push eax // Save register eax
mov dword ptr [ebp-12],0 // Set negation flag to zero
fld qword ptr [ebp+16] // Load real from stack
fld qword ptr [ebp+8] // Load real from stack
mov edi,offset flat:fzero // Point to real zero
fcom qword ptr [edi] // Compare x with zero
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
jb __fpow1 // Re-direct if x < 0
ja __fpow3 // Re-direct if x > 0
fxch // Swap st, st(1)
fcom qword ptr [edi] // Compare y with zero
fxch // Restore x as top of stack
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
ja __fpow3 // Re-direct if y > 0
fstp st(1) // Set new stack top and pop
mov eax,1 // Set domain error (EDOM)
jmp __fpow5 // End of case
__fpow1: fxch // Put y on top of stack
fld st // Duplicate y as st(1)
frndint // Round to integer
fxch // Put y on top of stack
fcomp // y = int(y) ?
fstsw ax // Get the FPU status word
mov al,ah // Move condition flags to AL
lahf // Load Flags into AH
and al, 0b01000101 // Isolate C0, C2 and C3
and ah, 0b10111010 // Turn off CF, PF and ZF
or ah,al // Set new CF, PF and ZF
sahf // Store AH into Flags
je __fpow2 // Proceed if y = int(y)
fstp st(1) // Set new stack top and pop
fldz // Set result to zero
fstp st(1) // Set new stack top and pop
mov eax,1 // Set domain error (EDOM)
jmp __fpow5 // End of case
__fpow2: fist dword ptr [ebp-12] // Store y as integer
and dword ptr [ebp-12],1 // Set bit if y is odd
fxch // Put x on top of stack
fabs // x = |x|
__fpow3: fldln2 // Load log base e of 2
fxch st(1) // Exchange st, st(1)
fyl2x // Compute the natural log(x)
fmulp // Compute y * ln(x)
fldl2e // Load log base 2(e)
fmulp st(1),st // Multiply x * log base 2(e)
fst st(1) // Push result
frndint // Round to integer
fsub st(1),st // Subtract
fxch // Exchange st, st(1)
f2xm1 // Compute 2 to the (x - 1)
fld1 // Load real number 1
faddp // 2 to the x
fscale // Scale by power of 2
fstp st(1) // Set new stack top and pop
test dword ptr [ebp-12],1 // Negation required ?
jz __fpow4 // No, re-direct
fchs // Negate the result
__fpow4: fstp qword ptr [ebp-8] // Save (double)pow(x, y)
fld qword ptr [ebp-8] // Load (double)pow(x, y)
fxam // Examine st
fstsw ax // Get the FPU status word
cmp ah,5 // Infinity ?
jne __fpow6 // No, end of case
mov eax,2 // Set range error (ERANGE)
// Get errno pointer offset
__fpow5: int 3
mov edi,0 // TODO: offset flat:__crt_errno
mov edi,[edi] // Get C errno variable pointer
mov dword ptr [edi],eax // Set errno
__fpow6: pop eax // Restore register eax
pop edi // Restore register edi
mov esp,ebp // Deallocate temporary space
pop ebp
ret

View file

@ -0,0 +1,50 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/sin.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _sin
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_sin:
push ebp // Save register bp
mov ebp,esp // Point to the stack frame
fld qword ptr [ebp+8] // Load real from stack
fsin // Take the sine
pop ebp // Restore register bp
ret

View file

@ -0,0 +1,50 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/sqrt.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _sqrt
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_sqrt:
push ebp
mov ebp,esp
fld qword ptr [ebp+8] // Load real from stack
fsqrt // Take the square root
pop ebp
ret

View file

@ -0,0 +1,53 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* PURPOSE: Run-Time Library
* FILE: lib/rtl/i386/tan.S
* PROGRAMER: Alex Ionescu (alex@relsoft.net)
* Eric Kohl (ekohl@rz-online.de)
*
* Copyright (C) 2002 Michael Ringgaard.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES// LOSS OF USE, DATA, OR PROFITS// OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
.globl _tan
.intel_syntax noprefix
/* FUNCTIONS ***************************************************************/
_tan:
push ebp
mov ebp,esp
sub esp,4 // Allocate temporary space
fld qword ptr [ebp+8] // Load real from stack
fptan // Take the tangent
fstp dword ptr [ebp-4] // Throw away the constant 1
mov esp,ebp // Deallocate temporary space
pop ebp
ret

View file

@ -0,0 +1,9 @@
#include <string.h>
/*
* @implemented
*/
long
labs(long j)
{
return j<0 ? -j : j;
}

View file

@ -0,0 +1,29 @@
#include <stdlib.h>
#if defined(__GNUC__)
static unsigned long long next = 0;
#else
static unsigned __int64 next = 0;
#endif
/*
* @implemented
*/
int rand(void)
{
#if defined(__GNUC__)
next = next * 0x5deece66dLL + 11;
#else
next = next * 0x5deece66di64 + 11;
#endif
return (int)((next >> 16) & RAND_MAX);
}
/*
* @implemented
*/
void srand(unsigned seed)
{
next = seed;
}

View file

@ -0,0 +1,31 @@
/* $Id$
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/string/i386/memchr.s
*/
/*
* void* memchr(const void* s, int c, size_t n)
*/
.globl _memchr
_memchr:
push %ebp
mov %esp,%ebp
push %edi
mov 0x8(%ebp),%edi
mov 0xc(%ebp),%eax
mov 0x10(%ebp),%ecx
cld
repne scasb
je .L1
mov $1,%edi
.L1:
mov %edi,%eax
dec %eax
pop %edi
leave
ret

View file

@ -0,0 +1,48 @@
/*
* void *memcpy (void *to, const void *from, size_t count)
*
* Some optimization research can be found in media/doc/memcpy_optimize.txt
*/
.globl _memcpy
_memcpy:
push %ebp
mov %esp,%ebp
push %esi
push %edi
mov 0x8(%ebp),%edi
mov 0xc(%ebp),%esi
mov 0x10(%ebp),%ecx
cld
cmp $16,%ecx
jb .L1
mov %ecx,%edx
test $3,%edi
je .L2
/*
* Make the destination dword aligned
*/
mov %edi,%ecx
and $3,%ecx
sub $5,%ecx
not %ecx
sub %ecx,%edx
rep movsb
mov %edx,%ecx
.L2:
shr $2,%ecx
rep movsl
mov %edx,%ecx
and $3,%ecx
.L1:
test %ecx,%ecx
je .L3
rep movsb
.L3:
pop %edi
pop %esi
mov 0x8(%ebp),%eax
leave
ret

View file

@ -0,0 +1,116 @@
/*
* $Id$
*/
/*
* void *memmove (void *to, const void *from, size_t count)
*/
.globl _memmove
_memmove:
push %ebp
mov %esp,%ebp
push %esi
push %edi
mov 8(%ebp),%edi
mov 12(%ebp),%esi
mov 16(%ebp),%ecx
cmp %esi,%edi
jbe .CopyUp
mov %ecx,%eax
add %esi,%eax
cmp %eax,%edi
jb .CopyDown
.CopyUp:
cld
cmp $16,%ecx
jb .L1
mov %ecx,%edx
test $3,%edi
je .L2
/*
* Make the destination dword aligned
*/
mov %edi,%ecx
and $3,%ecx
sub $5,%ecx
not %ecx
sub %ecx,%edx
rep movsb
mov %edx,%ecx
.L2:
shr $2,%ecx
rep movsl
mov %edx,%ecx
and $3,%ecx
.L1:
test %ecx,%ecx
je .L3
rep movsb
.L3:
mov 8(%ebp),%eax
pop %edi
pop %esi
leave
ret
.CopyDown:
std
add %ecx,%edi
add %ecx,%esi
cmp $16,%ecx
jb .L4
mov %ecx,%edx
test $3,%edi
je .L5
/*
* Make the destination dword aligned
*/
mov %edi,%ecx
and $3,%ecx
sub %ecx,%edx
dec %esi
dec %edi
rep movsb
mov %edx,%ecx
sub $3,%esi
sub $3,%edi
.L6:
shr $2,%ecx
rep movsl
mov %edx,%ecx
and $3,%ecx
je .L7
add $3,%esi
add $3,%edi
.L8:
rep movsb
.L7:
cld
mov 8(%ebp),%eax
pop %edi
pop %esi
leave
ret
.L5:
sub $4,%edi
sub $4,%esi
jmp .L6
.L4:
test %ecx,%ecx
je .L7
dec %esi
dec %edi
jmp .L8

View file

@ -0,0 +1,47 @@
/*
* $Id$
*/
/*
* void *memset (void *src, int val, size_t count)
*/
.globl _memset
_memset:
push %ebp
mov %esp,%ebp
push %edi
mov 0x8(%ebp),%edi
movzb 0xc(%ebp),%eax
mov 0x10(%ebp),%ecx
cld
cmp $16,%ecx
jb .L1
mov $0x01010101,%edx
mul %edx
mov %ecx,%edx
test $3,%edi
je .L2
mov %edi,%ecx
and $3,%ecx
sub $5,%ecx
not %ecx
sub %ecx,%edx
rep stosb
mov %edx,%ecx
.L2:
shr $2,%ecx
rep stosl
mov %edx,%ecx
and $3,%ecx
.L1:
test %ecx,%ecx
je .L3
rep stosb
.L3:
pop %edi
mov 0x8(%ebp),%eax
leave
ret

View file

@ -0,0 +1,25 @@
/*
* $Id$
*/
#include <string.h>
void *
_memccpy (void *to, const void *from,int c,size_t count)
{
char t;
size_t i;
char *dst=(char*)to;
const char *src=(const char*)from;
for ( i = 0; i < count; i++ )
{
dst[i] = t = src[i];
if ( t == '\0' )
break;
if ( t == c )
return &dst[i+1];
}
return NULL; /* didn't copy c */
}

View file

@ -0,0 +1,18 @@
/*
* $Id$
*/
#include <string.h>
void* memchr(const void *s, int c, size_t n)
{
if (n)
{
const char *p = s;
do {
if (*p++ == c)
return (void *)(p-1);
} while (--n != 0);
}
return 0;
}

View file

@ -0,0 +1,17 @@
/*
* $Id$
*/
#include <string.h>
int memcmp(const void *s1, const void *s2, size_t n)
{
if (n != 0) {
const unsigned char *p1 = s1, *p2 = s2;
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
return 0;
}

View file

@ -0,0 +1,16 @@
/*
* $Id$
*/
#include <string.h>
void* memcpy(void* to, const void* from, size_t count)
{
register char *f = (char *)from;
register char *t = (char *)to;
register int i = count;
while (i-- > 0)
*t++ = *f++;
return to;
}

View file

@ -0,0 +1,22 @@
#include <string.h>
#include <ctype.h>
/*
* @implemented
*/
int
_memicmp(const void *s1, const void *s2, size_t n)
{
if (n != 0)
{
const unsigned char *p1 = s1, *p2 = s2;
do {
if (toupper(*p1) != toupper(*p2))
return (*p1 - *p2);
p1++;
p2++;
} while (--n != 0);
}
return 0;
}

View file

@ -0,0 +1,40 @@
/*
* $Id$
*/
#include <string.h>
void * memmove(void *dest,const void *src,size_t count)
{
char *char_dest = (char *)dest;
char *char_src = (char *)src;
if ((char_dest <= char_src) || (char_dest >= (char_src+count)))
{
/* non-overlapping buffers */
while(count > 0)
{
*char_dest = *char_src;
char_dest++;
char_src++;
count--;
}
}
else
{
/* overlaping buffers */
char_dest = (char *)dest + count - 1;
char_src = (char *)src + count - 1;
while(count > 0)
{
*char_dest = *char_src;
char_dest--;
char_src--;
count--;
}
}
return dest;
}

View file

@ -0,0 +1,17 @@
/*
* $Id$
*/
#include <string.h>
void* memset(void* src, int val, size_t count)
{
char *char_src = (char *)src;
while(count>0) {
*char_src = val;
char_src++;
count--;
}
return src;
}

View file

@ -0,0 +1,11 @@
#include <string.h>
#include <stdlib.h>
/*
* @implemented
*/
int
atoi(const char *str)
{
return (int)strtol(str, 0, 10);
}

View file

@ -0,0 +1,36 @@
#include <string.h>
#include <ctype.h>
/*
* @implemented
*/
__int64
_atoi64 (const char *nptr)
{
int c;
__int64 value;
int sign;
while (isspace((int)*nptr))
++nptr;
c = (int)*nptr++;
sign = c;
if (c == '-' || c == '+')
c = (int)*nptr++;
value = 0;
while (isdigit(c))
{
value = 10 * value + (c - '0');
c = (int)*nptr++;
}
if (sign == '-')
return -value;
else
return value;
}
/* EOF */

View file

@ -0,0 +1,11 @@
#include <string.h>
#include <stdlib.h>
/*
* @implemented
*/
long
atol(const char *str)
{
return strtol(str, 0, 10);
}

View file

@ -0,0 +1,591 @@
#include <string.h>
#include <ctype.h>
#undef _pctype
#define upalpha ('A' - 'a')
unsigned short _ctype[] = {
0, /* <EOF>, 0xFFFF */
_CONTROL, /* CTRL+@, 0x00 */
_CONTROL, /* CTRL+A, 0x01 */
_CONTROL, /* CTRL+B, 0x02 */
_CONTROL, /* CTRL+C, 0x03 */
_CONTROL, /* CTRL+D, 0x04 */
_CONTROL, /* CTRL+E, 0x05 */
_CONTROL, /* CTRL+F, 0x06 */
_CONTROL, /* CTRL+G, 0x07 */
_CONTROL, /* CTRL+H, 0x08 */
_CONTROL | _SPACE, /* CTRL+I, 0x09 */
_CONTROL | _SPACE, /* CTRL+J, 0x0a */
_CONTROL | _SPACE, /* CTRL+K, 0x0b */
_CONTROL | _SPACE, /* CTRL+L, 0x0c */
_CONTROL | _SPACE, /* CTRL+M, 0x0d */
_CONTROL, /* CTRL+N, 0x0e */
_CONTROL, /* CTRL+O, 0x0f */
_CONTROL, /* CTRL+P, 0x10 */
_CONTROL, /* CTRL+Q, 0x11 */
_CONTROL, /* CTRL+R, 0x12 */
_CONTROL, /* CTRL+S, 0x13 */
_CONTROL, /* CTRL+T, 0x14 */
_CONTROL, /* CTRL+U, 0x15 */
_CONTROL, /* CTRL+V, 0x16 */
_CONTROL, /* CTRL+W, 0x17 */
_CONTROL, /* CTRL+X, 0x18 */
_CONTROL, /* CTRL+Y, 0x19 */
_CONTROL, /* CTRL+Z, 0x1a */
_CONTROL, /* CTRL+[, 0x1b */
_CONTROL, /* CTRL+\, 0x1c */
_CONTROL, /* CTRL+], 0x1d */
_CONTROL, /* CTRL+^, 0x1e */
_CONTROL, /* CTRL+_, 0x1f */
_SPACE | _BLANK, /* ` ', 0x20 */
_PUNCT, /* `!', 0x21 */
_PUNCT, /* 0x22 */
_PUNCT, /* `#', 0x23 */
_PUNCT, /* `$', 0x24 */
_PUNCT, /* `%', 0x25 */
_PUNCT, /* `&', 0x26 */
_PUNCT, /* 0x27 */
_PUNCT, /* `(', 0x28 */
_PUNCT, /* `)', 0x29 */
_PUNCT, /* `*', 0x2a */
_PUNCT, /* `+', 0x2b */
_PUNCT, /* `,', 0x2c */
_PUNCT, /* `-', 0x2d */
_PUNCT, /* `.', 0x2e */
_PUNCT, /* `/', 0x2f */
_DIGIT | _HEX, /* `0', 0x30 */
_DIGIT | _HEX, /* `1', 0x31 */
_DIGIT | _HEX, /* `2', 0x32 */
_DIGIT | _HEX, /* `3', 0x33 */
_DIGIT | _HEX, /* `4', 0x34 */
_DIGIT | _HEX, /* `5', 0x35 */
_DIGIT | _HEX, /* `6', 0x36 */
_DIGIT | _HEX, /* `7', 0x37 */
_DIGIT | _HEX, /* `8', 0x38 */
_DIGIT | _HEX, /* `9', 0x39 */
_PUNCT, /* `:', 0x3a */
_PUNCT, /* `;', 0x3b */
_PUNCT, /* `<', 0x3c */
_PUNCT, /* `=', 0x3d */
_PUNCT, /* `>', 0x3e */
_PUNCT, /* `?', 0x3f */
_PUNCT, /* `@', 0x40 */
_UPPER | _HEX, /* `A', 0x41 */
_UPPER | _HEX, /* `B', 0x42 */
_UPPER | _HEX, /* `C', 0x43 */
_UPPER | _HEX, /* `D', 0x44 */
_UPPER | _HEX, /* `E', 0x45 */
_UPPER | _HEX, /* `F', 0x46 */
_UPPER, /* `G', 0x47 */
_UPPER, /* `H', 0x48 */
_UPPER, /* `I', 0x49 */
_UPPER, /* `J', 0x4a */
_UPPER, /* `K', 0x4b */
_UPPER, /* `L', 0x4c */
_UPPER, /* `M', 0x4d */
_UPPER, /* `N', 0x4e */
_UPPER, /* `O', 0x4f */
_UPPER, /* `P', 0x50 */
_UPPER, /* `Q', 0x51 */
_UPPER, /* `R', 0x52 */
_UPPER, /* `S', 0x53 */
_UPPER, /* `T', 0x54 */
_UPPER, /* `U', 0x55 */
_UPPER, /* `V', 0x56 */
_UPPER, /* `W', 0x57 */
_UPPER, /* `X', 0x58 */
_UPPER, /* `Y', 0x59 */
_UPPER, /* `Z', 0x5a */
_PUNCT, /* `[', 0x5b */
_PUNCT, /* 0x5c */
_PUNCT, /* `]', 0x5d */
_PUNCT, /* `^', 0x5e */
_PUNCT, /* `_', 0x5f */
_PUNCT, /* 0x60 */
_LOWER | _HEX, /* `a', 0x61 */
_LOWER | _HEX, /* `b', 0x62 */
_LOWER | _HEX, /* `c', 0x63 */
_LOWER | _HEX, /* `d', 0x64 */
_LOWER | _HEX, /* `e', 0x65 */
_LOWER | _HEX, /* `f', 0x66 */
_LOWER, /* `g', 0x67 */
_LOWER, /* `h', 0x68 */
_LOWER, /* `i', 0x69 */
_LOWER, /* `j', 0x6a */
_LOWER, /* `k', 0x6b */
_LOWER, /* `l', 0x6c */
_LOWER, /* `m', 0x6d */
_LOWER, /* `n', 0x6e */
_LOWER, /* `o', 0x6f */
_LOWER, /* `p', 0x70 */
_LOWER, /* `q', 0x71 */
_LOWER, /* `r', 0x72 */
_LOWER, /* `s', 0x73 */
_LOWER, /* `t', 0x74 */
_LOWER, /* `u', 0x75 */
_LOWER, /* `v', 0x76 */
_LOWER, /* `w', 0x77 */
_LOWER, /* `x', 0x78 */
_LOWER, /* `y', 0x79 */
_LOWER, /* `z', 0x7a */
_PUNCT, /* `{', 0x7b */
_PUNCT, /* `|', 0x7c */
_PUNCT, /* `}', 0x7d */
_PUNCT, /* `~', 0x7e */
_CONTROL, /* 0x7f */
0, /* 0x80 */
0, /* 0x81 */
0, /* 0x82 */
0, /* 0x83 */
0, /* 0x84 */
0, /* 0x85 */
0, /* 0x86 */
0, /* 0x87 */
0, /* 0x88 */
0, /* 0x89 */
0, /* 0x8a */
0, /* 0x8b */
0, /* 0x8c */
0, /* 0x8d */
0, /* 0x8e */
0, /* 0x8f */
0, /* 0x90 */
0, /* 0x91 */
0, /* 0x92 */
0, /* 0x93 */
0, /* 0x94 */
0, /* 0x95 */
0, /* 0x96 */
0, /* 0x97 */
0, /* 0x98 */
0, /* 0x99 */
0, /* 0x9a */
0, /* 0x9b */
0, /* 0x9c */
0, /* 0x9d */
0, /* 0x9e */
0, /* 0x9f */
0, /* 0xa0 */
0, /* 0xa1 */
0, /* 0xa2 */
0, /* 0xa3 */
0, /* 0xa4 */
0, /* 0xa5 */
0, /* 0xa6 */
0, /* 0xa7 */
0, /* 0xa8 */
0, /* 0xa9 */
0, /* 0xaa */
0, /* 0xab */
0, /* 0xac */
0, /* 0xad */
0, /* 0xae */
0, /* 0xaf */
0, /* 0xb0 */
0, /* 0xb1 */
0, /* 0xb2 */
0, /* 0xb3 */
0, /* 0xb4 */
0, /* 0xb5 */
0, /* 0xb6 */
0, /* 0xb7 */
0, /* 0xb8 */
0, /* 0xb9 */
0, /* 0xba */
0, /* 0xbb */
0, /* 0xbc */
0, /* 0xbd */
0, /* 0xbe */
0, /* 0xbf */
0, /* 0xc0 */
0, /* 0xc1 */
0, /* 0xc2 */
0, /* 0xc3 */
0, /* 0xc4 */
0, /* 0xc5 */
0, /* 0xc6 */
0, /* 0xc7 */
0, /* 0xc8 */
0, /* 0xc9 */
0, /* 0xca */
0, /* 0xcb */
0, /* 0xcc */
0, /* 0xcd */
0, /* 0xce */
0, /* 0xcf */
0, /* 0xd0 */
0, /* 0xd1 */
0, /* 0xd2 */
0, /* 0xd3 */
0, /* 0xd4 */
0, /* 0xd5 */
0, /* 0xd6 */
0, /* 0xd7 */
0, /* 0xd8 */
0, /* 0xd9 */
0, /* 0xda */
0, /* 0xdb */
0, /* 0xdc */
0, /* 0xdd */
0, /* 0xde */
0, /* 0xdf */
0, /* 0xe0 */
0, /* 0xe1 */
0, /* 0xe2 */
0, /* 0xe3 */
0, /* 0xe4 */
0, /* 0xe5 */
0, /* 0xe6 */
0, /* 0xe7 */
0, /* 0xe8 */
0, /* 0xe9 */
0, /* 0xea */
0, /* 0xeb */
0, /* 0xec */
0, /* 0xed */
0, /* 0xee */
0, /* 0xef */
0, /* 0xf0 */
0, /* 0xf1 */
0, /* 0xf2 */
0, /* 0xf3 */
0, /* 0xf4 */
0, /* 0xf5 */
0, /* 0xf6 */
0, /* 0xf7 */
0, /* 0xf8 */
0, /* 0xf9 */
0, /* 0xfa */
0, /* 0xfb */
0, /* 0xfc */
0, /* 0xfd */
0, /* 0xfe */
0 /* 0xff */
};
unsigned short *_pctype = _ctype + 1;
unsigned short *_pwctype = _ctype + 1;
/*
* @implemented
*/
unsigned short **__p__pctype(void)
{
return &_pctype;
}
/*
* @implemented
*/
unsigned short **__p__pwctype(void)
{
return &_pwctype;
}
int _isctype (int c, int ctypeFlags)
{
return (_pctype[(unsigned char)(c & 0xFF)] & ctypeFlags);
}
/*
* @implemented
*/
int iswctype(wint_t wc, wctype_t wctypeFlags)
{
return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags);
}
/*
* obsolete
*
* @implemented
*/
int is_wctype(wint_t wc, wctype_t wctypeFlags)
{
return (_pwctype[(unsigned char)(wc & 0xFF)] & wctypeFlags);
}
/*
* @implemented
*/
int isalpha(int c)
{
return(_isctype(c, _ALPHA));
}
/*
* @implemented
*/
int isalnum(int c)
{
return(_isctype(c, _ALPHA | _DIGIT));
}
/*
* @implemented
*/
int iswalnum(wint_t c)
{
return iswctype(c, _ALPHA | _DIGIT);
}
/*
* @implemented
*/
int __isascii(int c)
{
return ((unsigned char)c <= 0x7f);
}
/*
* @implemented
*/
int iswascii(wint_t c)
{
return __isascii(c);
}
/*
* @implemented
*/
int iscntrl(int c)
{
return(_isctype(c, _CONTROL));
}
/*
* @implemented
*/
int __iscsym(int c)
{
return(isalnum(c)||(c == '_'));
}
/*
* @implemented
*/
int __iscsymf(int c)
{
return(isalpha(c)||(c == '_'));
}
/*
* @implemented
*/
int isdigit(int c)
{
return(_isctype(c, _DIGIT));
}
/*
* @implemented
*/
int isgraph(int c)
{
return (_isctype (c, _PUNCT | _ALPHA | _DIGIT));
}
/*
* @implemented
*/
int islower(int c)
{
return (_isctype (c, _LOWER));
}
/*
* @implemented
*/
int isprint(int c)
{
return (_isctype (c, _BLANK | _PUNCT | _ALPHA | _DIGIT));
}
/*
* @implemented
*/
int ispunct(int c)
{
return (_isctype (c, _PUNCT));
}
/*
* @implemented
*/
int isspace(int c)
{
return (_isctype (c, _SPACE));
}
/*
* @implemented
*/
int isupper(int c)
{
return (_isctype (c, _UPPER));
}
/*
* @implemented
*/
int isxdigit(int c)
{
return (_isctype (c, _HEX));
}
/*
* @implemented
*/
int iswalpha(wint_t c)
{
return (iswctype (c, _ALPHA));
}
/*
* @implemented
*/
int iswcntrl(wint_t c)
{
return iswctype(c, _CONTROL);
}
/*
* @implemented
*/
int iswdigit(wint_t c)
{
return (iswctype (c, _DIGIT));
}
/*
* @implemented
*/
int iswgraph(wint_t c)
{
return iswctype(c,_PUNCT | _ALPHA | _DIGIT);
}
/*
* @implemented
*/
int iswprint(wint_t c)
{
return iswctype((unsigned short)c,_BLANK | _PUNCT | _ALPHA | _DIGIT);
}
/*
* @implemented
*/
int iswpunct(wint_t c)
{
return iswctype(c, _PUNCT);
}
/*
* @implemented
*/
int iswlower(wint_t c)
{
return (iswctype (c, _LOWER));
}
/*
* @implemented
*/
int iswupper(wint_t c)
{
return iswctype(c, _UPPER);
}
/*
* @implemented
*/
int iswspace(wint_t c)
{
return (iswctype (c, _SPACE));
}
/*
* @implemented
*/
int iswxdigit(wint_t c)
{
return (iswctype (c, _HEX));
}
/*
* @implemented
*/
int __toascii(int c)
{
return((unsigned)(c) & 0x7f);
}
/*
* @implemented
*/
int _tolower(int c)
{
if (_isctype (c, _UPPER))
return (c - upalpha);
return(c);
}
/*
* @implemented
*/
int _toupper(int c)
{
if (_isctype (c, _LOWER))
return (c + upalpha);
return(c);
}
/*
* @implemented
*/
int tolower(int c)
{
if (_isctype (c, _UPPER))
return (c - upalpha);
return(c);
}
/*
* @implemented
*/
int toupper(int c)
{
if (_isctype (c, _LOWER))
return (c + upalpha);
return(c);
}
/*
* @implemented
*/
wchar_t towlower(wchar_t c)
{
if (iswctype (c, _UPPER))
return (c - upalpha);
return(c);
}
/*
* @implemented
*/
wchar_t towupper(wchar_t c)
{
if (iswctype (c, _LOWER))
return (c + upalpha);
return(c);
}
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcscat.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcschr.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcscmp.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcscpy.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcslen.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcsncat.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcsncmp.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcsncpy.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcsnlen.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include "tcsrchr.h"
/* EOF */

View file

@ -0,0 +1,59 @@
/* $Id$
*/
#ifndef __TCHAR_INC_S__
#define __TCHAR_INC_S__
#ifdef _UNICODE
#define _tcscat _wcscat
#define _tcschr _wcschr
#define _tcscmp _wcscmp
#define _tcscpy _wcscpy
#define _tcslen _wcslen
#define _tcsncat _wcsncat
#define _tcsncmp _wcsncmp
#define _tcsncpy _wcsncpy
#define _tcsnlen _wcsnlen
#define _tcsrchr _wcsrchr
#define _tscas scasw
#define _tlods lodsw
#define _tstos stosw
#define _tsize $2
#define _treg(_O_) _O_ ## x
#define _tdec(_O_) sub $2, _O_
#define _tinc(_O_) add $2, _O_
#else
#define _tcscat _strcat
#define _tcschr _strchr
#define _tcscmp _strcmp
#define _tcscpy _strcpy
#define _tcslen _strlen
#define _tcsncat _strncat
#define _tcsncmp _strncmp
#define _tcsncpy _strncpy
#define _tcsnlen _strnlen
#define _tcsrchr _strrchr
#define _tscas scasb
#define _tlods lodsb
#define _tstos stosb
#define _tsize $1
#define _treg(_O_) _O_ ## l
#define _tdec(_O_) dec _O_
#define _tinc(_O_) inc _O_
#endif
#endif
/* EOF */

View file

@ -0,0 +1,32 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcscat
_tcscat:
push %esi
push %edi
mov 0x0C(%esp), %edi
mov 0x10(%esp), %esi
xor %eax, %eax
mov $-1, %ecx
cld
repne _tscas
_tdec(%edi)
.L1:
_tlods
_tstos
test %_treg(a), %_treg(a)
jnz .L1
mov 0x0C(%esp), %eax
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,30 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcschr
_tcschr:
push %esi
mov 0x8(%esp), %esi
mov 0xC(%esp), %edx
cld
.L1:
_tlods
cmp %_treg(a), %_treg(d)
je .L2
test %_treg(a), %_treg(a)
jnz .L1
mov _tsize, %esi
.L2:
mov %esi, %eax
_tdec(%eax)
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,34 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcscmp
_tcscmp:
push %esi
push %edi
mov 0x0C(%esp), %esi
mov 0x10(%esp), %edi
xor %eax, %eax
cld
.L1:
_tlods
_tscas
jne .L2
test %eax, %eax
jne .L1
xor %eax, %eax
jmp .L3
.L2:
sbb %eax, %eax
or $1, %al
.L3:
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,27 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcscpy
_tcscpy:
push %esi
push %edi
mov 0x0C(%esp), %edi
mov 0x10(%esp), %esi
cld
.L1:
_tlods
_tstos
test %_treg(a), %_treg(a)
jnz .L1
mov 0x0C(%esp), %eax
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,29 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcslen
_tcslen:
push %edi
mov 0x8(%esp), %edi
xor %eax, %eax
test %edi,%edi
jz _tcslen_end
mov $-1, %ecx
cld
repne _tscas
not %ecx
dec %ecx
mov %ecx, %eax
_tcslen_end:
pop %edi
ret
/* EOF */

View file

@ -0,0 +1,42 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcsncat
_tcsncat:
push %esi
push %edi
mov 0x0C(%esp), %edi
mov 0x10(%esp), %esi
cld
xor %eax, %eax
mov $-1, %ecx
repne _tscas
_tdec(%edi)
mov 0x14(%esp),%ecx
.L1:
dec %ecx
js .L2
_tlods
_tstos
test %_treg(a), %_treg(a)
jne .L1
jmp .L3
.L2:
xor %eax, %eax
_tstos
.L3:
mov 0x0C(%esp), %eax
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,40 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcsncmp
_tcsncmp:
push %esi
push %edi
mov 0x0C(%esp), %esi /* s1 */
mov 0x10(%esp), %edi /* s2 */
mov 0x14(%esp), %ecx /* n */
xor %eax,%eax
cld
.L1:
dec %ecx
js .L2
_tlods
_tscas
jne .L3
test %eax, %eax
jne .L1
.L2:
xor %eax, %eax
jmp .L4
.L3:
sbb %eax, %eax
or $1, %al
.L4:
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,34 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcsncpy
_tcsncpy:
push %esi
push %edi
mov 0x0C(%esp), %edi /* s1 */
mov 0x10(%esp), %esi /* s2 */
mov 0x14(%esp), %ecx /* n */
xor %eax, %eax
cld
.L1:
dec %ecx
js .L2
_tlods
_tstos
test %_treg(a), %_treg(a)
jnz .L1
rep _tstos
.L2:
mov 0x0C(%esp), %eax
pop %edi
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,30 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcsnlen
_tcsnlen:
push %edi
mov 0x8(%esp), %edi
mov 0xC(%esp), %ecx
xor %eax, %eax
test %ecx, %ecx
jz .L1
mov %ecx, %edx
cld
repne _tscas
sete %al
sub %ecx, %edx
sub %eax, %edx
mov %edx, %eax
.L1:
pop %edi
ret
/* EOF */

View file

@ -0,0 +1,31 @@
/* $Id$
*/
#include "tchar.h"
.globl _tcsrchr
_tcsrchr:
push %esi
mov 0x8(%esp), %esi
mov 0xC(%esp), %edx
cld
mov _tsize, %ecx
.L1:
_tlods
cmp %_treg(a), %_treg(d)
jne .L2
mov %esi, %ecx
.L2:
test %_treg(a), %_treg(a)
jnz .L1
mov %ecx, %eax
_tdec(%eax)
pop %esi
ret
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcscat.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcschr.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcscmp.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcscpy.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcslen.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcsncat.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcsncmp.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcsncpy.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcsnlen.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#define _UNICODE
#include "tcsrchr.h"
/* EOF */

View file

@ -0,0 +1,161 @@
#include <string.h>
#include <stdlib.h>
#include <windows.h>
/*
* @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/
char *
_i64toa(__int64 value, char *string, int radix)
{
ULONGLONG val;
int negative;
char buffer[65];
char *pos;
int digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[64];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
memcpy(string, pos, &buffer[64] - pos + 1);
return string;
}
/*
* @implemented
* copy _i64toa from wine cvs 2006 month 05 day 21
*/
char *
_ui64toa(unsigned __int64 value, char *string, int radix)
{
char buffer[65];
char *pos;
int digit;
pos = &buffer[64];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
memcpy(string, pos, &buffer[64] - pos + 1);
return string;
}
/*
* @implemented
*/
char *
_itoa(int value, char *string, int radix)
{
return _ltoa(value, string, radix);
}
/*
* @implemented
*/
char *
_ltoa(long value, char *string, int radix)
{
unsigned long val;
int negative;
char buffer[33];
char *pos;
int digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[32];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
memcpy(string, pos, &buffer[32] - pos + 1);
return string;
}
/*
* @implemented
* copy it from wine 0.9.0 with small modifcations do check for NULL
*/
char *
_ultoa(unsigned long value, char *string, int radix)
{
char buffer[33];
char *pos;
int digit;
pos = &buffer[32];
*pos = '\0';
if (string == NULL)
{
return NULL;
}
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
memcpy(string, pos, &buffer[32] - pos + 1);
return string;
}

View file

@ -0,0 +1,163 @@
#include <string.h>
#include <windows.h>
/*
* @implemented
* from wine cvs 2006-05-21
*/
wchar_t *
_i64tow(__int64 value, wchar_t *string, int radix)
{
ULONGLONG val;
int negative;
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[64];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
if (string != NULL) {
memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
}
/*
* @implemented
*/
wchar_t *
_ui64tow(unsigned __int64 value, wchar_t *string, int radix)
{
WCHAR buffer[65];
PWCHAR pos;
WCHAR digit;
pos = &buffer[64];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
if (string != NULL) {
memcpy(string, pos, (&buffer[64] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
}
/*
* @implemented
* from wine cvs 2006-05-21
*/
wchar_t *
_itow(int value, wchar_t *string, int radix)
{
return _ltow(value, string, radix);
}
/*
* @implemented
* from wine cvs 2006-05-21
*/
wchar_t *
_ltow(long value, wchar_t *string, int radix)
{
unsigned long val;
int negative;
WCHAR buffer[33];
PWCHAR pos;
WCHAR digit;
if (value < 0 && radix == 10) {
negative = 1;
val = -value;
} else {
negative = 0;
val = value;
} /* if */
pos = &buffer[32];
*pos = '\0';
do {
digit = val % radix;
val = val / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (val != 0L);
if (negative) {
*--pos = '-';
} /* if */
if (string != NULL) {
memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
}
/*
* @implemented
* from wine cvs 2006-05-21
*/
wchar_t *
_ultow(unsigned long value, wchar_t *string, int radix)
{
WCHAR buffer[33];
PWCHAR pos;
WCHAR digit;
pos = &buffer[32];
*pos = '\0';
do {
digit = value % radix;
value = value / radix;
if (digit < 10) {
*--pos = '0' + digit;
} else {
*--pos = 'a' + digit - 10;
} /* if */
} while (value != 0L);
if (string != NULL) {
memcpy(string, pos, (&buffer[32] - pos + 1) * sizeof(WCHAR));
} /* if */
return string;
}

View file

@ -0,0 +1,20 @@
#include <string.h>
/*
* @implemented
*/
void *_lfind(const void *key, const void *base, size_t *nelp,
size_t width, int (*compar)(const void *, const void *))
{
const char* char_base = (const char *)base;
size_t i;
for (i = 0; i < *nelp; i++)
{
if (compar(key, char_base) == 0)
return (void *)((size_t)char_base);
char_base += width;
}
return NULL;
}

View file

@ -0,0 +1,60 @@
#define WIN32_NO_STATUS
#include <windows.h>
#include <ndk/umtypes.h>
#include <ndk/rtlfuncs.h>
#include <string.h>
/*
* @implemented
*/
int mbtowc (wchar_t *wchar, const char *mbchar, size_t count)
{
NTSTATUS Status;
ULONG Size;
if (wchar == NULL)
return 0;
Status = RtlMultiByteToUnicodeN (wchar,
sizeof(WCHAR),
&Size,
mbchar,
count);
if (!NT_SUCCESS(Status))
return -1;
return (int)Size;
}
/*
* @implemented
*/
size_t mbstowcs (wchar_t *wcstr, const char *mbstr, size_t count)
{
NTSTATUS Status;
ULONG Size;
ULONG Length;
Length = strlen (mbstr);
if (wcstr == NULL)
{
RtlMultiByteToUnicodeSize (&Size,
mbstr,
Length);
return (size_t)Size;
}
Status = RtlMultiByteToUnicodeN (wcstr,
count,
&Size,
mbstr,
Length);
if (!NT_SUCCESS(Status))
return -1;
return (size_t)Size;
}
/* EOF */

View file

@ -0,0 +1,547 @@
/*
* general implementation of scanf used by scanf, sscanf, fscanf,
* _cscanf, wscanf, swscanf and fwscanf
*
* Copyright 1996,1998 Marcus Meissner
* Copyright 1996 Jukka Iivonen
* Copyright 1997,2000, 2003 Uwe Bonnes
* Copyright 2000 Jon Griffiths
* Copyright 2002 Daniel Gudbjartsson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef WIDE_SCANF
#define _CHAR_ wchar_t
#define _EOF_ WEOF
#define _EOF_RET WEOF
#define _ISSPACE_(c) iswspace(c)
#define _ISDIGIT_(c) iswdigit(c)
#define _WIDE2SUPPORTED_(c) c /* No conversion needed (wide to wide) */
#define _CHAR2SUPPORTED_(c) c /* FIXME: convert char to wide char */
#define _CHAR2DIGIT_(c, base) wchar2digit((c), (base))
#define _BITMAPSIZE_ 256*256
#else /* WIDE_SCANF */
#define _CHAR_ char
#define _EOF_ EOF
#define _EOF_RET EOF
#define _ISSPACE_(c) isspace(c)
#define _ISDIGIT_(c) isdigit(c)
#define _WIDE2SUPPORTED_(c) c /* FIXME: convert wide char to char */
#define _CHAR2SUPPORTED_(c) c /* No conversion needed (char to char) */
#define _CHAR2DIGIT_(c, base) char2digit((c), (base))
#define _BITMAPSIZE_ 256
#endif /* WIDE_SCANF */
#ifdef CONSOLE
#define _GETC_(file) (consumed++, _getch())
#define _UNGETC_(nch, file) do { _ungetch(nch); consumed--; } while(0)
#define _FUNCTION_ int vcscanf(const char *format, va_list ap)
#else
#ifdef STRING
#undef _EOF_
#define _EOF_ 0
#define _GETC_(file) (consumed++, *file++)
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
#ifdef WIDE_SCANF
#define _FUNCTION_ int vswscanf(const wchar_t *file, const wchar_t *format, va_list ap)
#else /* WIDE_SCANF */
#define _FUNCTION_ int vsscanf(const char *file, const char *format, va_list ap)
#endif /* WIDE_SCANF */
#else /* STRING */
#ifdef WIDE_SCANF
#define _GETC_(file) (consumed++, fgetwc(file))
#define _UNGETC_(nch, file) do { ungetwc(nch, file); consumed--; } while(0)
#define _FUNCTION_ int vfwscanf(FILE* file, const wchar_t *format, va_list ap)
#else /* WIDE_SCANF */
#define _GETC_(file) (consumed++, fgetc(file))
#define _UNGETC_(nch, file) do { ungetc(nch, file); consumed--; } while(0)
#define _FUNCTION_ int vfscanf(FILE* file, const char *format, va_list ap)
#endif /* WIDE_SCANF */
#endif /* STRING */
#endif /* CONSOLE */
/*********************************************************************
* Implemented based on
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_format_specification_fields_.2d_.scanf_and_wscanf_functions.asp
* Extended by C. Scott Ananian <cananian@alumni.princeton.edu> to handle
* more types of format spec.
*/
_FUNCTION_ {
int rd = 0, consumed = 0;
int nch;
if (!*format) return 0;
nch = _GETC_(file);
if (nch == _EOF_) return _EOF_RET;
while (*format) {
/* a whitespace character in the format string causes scanf to read,
* but not store, all consecutive white-space characters in the input
* up to the next non-white-space character. One white space character
* in the input matches any number (including zero) and combination of
* white-space characters in the input. */
if (_ISSPACE_(*format)) {
/* skip whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
}
/* a format specification causes scanf to read and convert characters
* in the input into values of a specified type. The value is assigned
* to an argument in the argument list. Format specifications have
* the form %[*][width][{h | l | I64 | L}]type */
else if (*format == '%') {
int st = 0; int suppress = 0; int width = 0;
int base, number_signed;
int h_prefix = 0;
int l_prefix = 0;
int L_prefix = 0;
int w_prefix = 0;
int prefix_finished = 0;
int I64_prefix = 0;
format++;
/* look for leading asterisk, which means 'suppress assignment of
* this field'. */
if (*format=='*') {
format++;
suppress=1;
}
/* look for width specification */
while (_ISDIGIT_(*format)) {
width*=10;
width+=*format++ - '0';
}
if (width==0) width=-1; /* no width spec seen */
/* read prefix (if any) */
while (!prefix_finished) {
switch(*format) {
case 'h': h_prefix = 1; break;
case 'l': l_prefix = 1; break;
case 'w': w_prefix = 1; break;
case 'L': L_prefix = 1; break;
case 'I':
if (*(format + 1) == '6' &&
*(format + 2) == '4') {
I64_prefix = 1;
format += 2;
}
break;
default:
prefix_finished = 1;
}
if (!prefix_finished) format++;
}
/* read type */
switch(*format) {
case 'x':
case 'X': /* hexadecimal integer. */
base = 16; number_signed = 0;
goto number;
case 'o': /* octal integer */
base = 8; number_signed = 0;
goto number;
case 'u': /* unsigned decimal integer */
base = 10; number_signed = 0;
goto number;
case 'd': /* signed decimal integer */
base = 10; number_signed = 1;
goto number;
case 'i': /* generic integer */
base = 10; number_signed = 1;
number: {
/* read an integer */
ULONGLONG cur = 0;
int negative = 0;
int seendigit=0;
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* get sign */
if (number_signed && (nch == '-' ||
nch == '+')) {
negative = (nch=='-');
nch = _GETC_(file);
if (width>0) width--;
}
/* look for leading indication of base */
if (width!=0 && nch == '0') {
nch = _GETC_(file);
if (width>0) width--;
seendigit=1;
if (width!=0 && (nch=='x' || nch=='X')) {
if (base==0)
base=16;
if (base==16) {
nch = _GETC_(file);
if (width>0) width--;
seendigit=0;
}
} else if (base==0)
base = 8;
}
/* throw away leading zeros */
while (width!=0 && nch=='0') {
nch = _GETC_(file);
if (width>0) width--;
seendigit=1;
}
if (width!=0 && _CHAR2DIGIT_(nch, base)!=-1) {
cur = _CHAR2DIGIT_(nch, base);
nch = _GETC_(file);
if (width>0) width--;
seendigit=1;
}
/* read until no more digits */
while (width!=0 && (nch!=_EOF_) && _CHAR2DIGIT_(nch, base)!=-1) {
cur = cur*base + _CHAR2DIGIT_(nch, base);
nch = _GETC_(file);
if (width>0) width--;
seendigit=1;
}
/* okay, done! */
if (!seendigit) break; /* not a valid number */
st = 1;
if (!suppress) {
#define _SET_NUMBER_(type) *va_arg(ap, type*) = negative ? -cur : cur
if (number_signed) {
if (I64_prefix) _SET_NUMBER_(LONGLONG);
else if (l_prefix) _SET_NUMBER_(long int);
else if (h_prefix) _SET_NUMBER_(short int);
else _SET_NUMBER_(int);
} else {
if (negative) {
negative = 0;
}
if (I64_prefix) _SET_NUMBER_(ULONGLONG);
else if (l_prefix) _SET_NUMBER_(unsigned long int);
else if (h_prefix)
_SET_NUMBER_(unsigned short int);
else _SET_NUMBER_(unsigned int);
}
}
}
break;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G': { /* read a float */
long double cur = 0;
int negative = 0;
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* get sign. */
if (nch == '-' || nch == '+') {
negative = (nch=='-');
if (width>0) width--;
if (width==0) break;
nch = _GETC_(file);
}
/* get first digit. */
if ('.' != nch) {
if (!_ISDIGIT_(nch)) break;
cur = (nch - '0');
nch = _GETC_(file);
if (width>0) width--;
/* read until no more digits */
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
cur = cur*10 + (nch - '0');
nch = _GETC_(file);
if (width>0) width--;
}
} else {
cur = 0; /* MaxPayneDemo Fix: .8 -> 0.8 */
}
/* handle decimals */
if (width!=0 && nch == '.') {
float dec = 1;
nch = _GETC_(file);
if (width>0) width--;
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
dec /= 10;
cur += dec * (nch - '0');
nch = _GETC_(file);
if (width>0) width--;
}
}
/* handle exponent */
if (width!=0 && (nch == 'e' || nch == 'E')) {
int exponent = 0, negexp = 0;
float expcnt;
nch = _GETC_(file);
if (width>0) width--;
/* possible sign on the exponent */
if (width!=0 && (nch=='+' || nch=='-')) {
negexp = (nch=='-');
nch = _GETC_(file);
if (width>0) width--;
}
/* exponent digits */
while (width!=0 && (nch!=_EOF_) && _ISDIGIT_(nch)) {
exponent *= 10;
exponent += (nch - '0');
nch = _GETC_(file);
if (width>0) width--;
}
/* update 'cur' with this exponent. */
expcnt = negexp ? .1 : 10;
while (exponent!=0) {
if (exponent&1)
cur*=expcnt;
exponent/=2;
expcnt=expcnt*expcnt;
}
}
st = 1;
if (!suppress) {
if (L_prefix) _SET_NUMBER_(long double);
else if (l_prefix) _SET_NUMBER_(double);
else _SET_NUMBER_(float);
}
}
break;
/* According to
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_scanf_type_field_characters.asp
* 's' reads a character string in a call to fscanf
* and 'S' a wide character string and vice versa in a
* call to fwscanf. The 'h', 'w' and 'l' prefixes override
* this behaviour. 'h' forces reading char * but 'l' and 'w'
* force reading WCHAR. */
case 's':
if (w_prefix || l_prefix) goto widecharstring;
else if (h_prefix) goto charstring;
#ifdef WIDE_SCANF
else goto widecharstring;
#else /* WIDE_SCANF */
else goto charstring;
#endif /* WIDE_SCANF */
case 'S':
if (w_prefix || l_prefix) goto widecharstring;
else if (h_prefix) goto charstring;
#ifdef WIDE_SCANF
else goto charstring;
#else /* WIDE_SCANF */
else goto widecharstring;
#endif /* WIDE_SCANF */
charstring: { /* read a word into a char */
char*str = suppress ? NULL : va_arg(ap, char*);
char*sptr = str;
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* read until whitespace */
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
st++;
nch = _GETC_(file);
if (width>0) width--;
}
/* terminate */
if (!suppress) *sptr = 0;
}
break;
widecharstring: { /* read a word into a wchar_t* */
wchar_t*str =
suppress ? NULL : va_arg(ap, wchar_t*);
wchar_t*sptr = str;
/* skip initial whitespace */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
/* read until whitespace */
while (width!=0 && (nch!=_EOF_) && !_ISSPACE_(nch)) {
if (!suppress) *sptr++ = _WIDE2SUPPORTED_(nch);
st++;
nch = _GETC_(file);
if (width>0) width--;
}
/* terminate */
if (!suppress) *sptr = 0;
}
break;
/* 'c' and 'C work analogously to 's' and 'S' as described
* above */
case 'c':
if (w_prefix || l_prefix) goto widecharacter;
else if (h_prefix) goto character;
#ifdef WIDE_SCANF
else goto widecharacter;
#else /* WIDE_SCANF */
else goto character;
#endif /* WIDE_SCANF */
case 'C':
if (w_prefix || l_prefix) goto widecharacter;
else if (h_prefix) goto character;
#ifdef WIDE_SCANF
else goto character;
#else /* WIDE_SCANF */
else goto widecharacter;
#endif /* WIDE_SCANF */
character: { /* read single character into char */
if (nch!=_EOF_) {
if (!suppress) {
char*c = va_arg(ap, char*);
*c = _CHAR2SUPPORTED_(nch);
}
st = 1;
nch = _GETC_(file);
}
}
break;
widecharacter: { /* read single character into a wchar_t */
if (nch!=_EOF_) {
if (!suppress) {
wchar_t*c = va_arg(ap, wchar_t*);
*c = _WIDE2SUPPORTED_(nch);
}
nch = _GETC_(file);
st = 1;
}
}
break;
case 'n': {
if (!suppress) {
int*n = va_arg(ap, int*);
/*
*n = consumed - (nch!=_EOF_);
FIXME: The above is the Wine version and it doesnt work in ros
when %n is at end of input string (return one too many).
But does it fail in Wine too?? If so wine also needs fixin.
-Gunnar
*/
*n = consumed - 1;
}
/* This is an odd one: according to the standard,
* "Execution of a %n directive does not increment the
* assignment count returned at the completion of
* execution" even if it wasn't suppressed with the
* '*' flag. The Corrigendum to the standard seems
* to contradict this (comment out the assignment to
* suppress below if you want to implement these
* alternate semantics) but the windows program I'm
* looking at expects the behavior I've coded here
* (which happens to be what glibc does as well).
*/
suppress = 1;
st = 1;
}
break;
case '[': {
_CHAR_ *str = suppress ? NULL : va_arg(ap, _CHAR_*);
_CHAR_ *sptr = str;
RTL_BITMAP bitMask;
ULONG *Mask;
int invert = 0; /* Set if we are NOT to find the chars */
/* Init our bitmap */
Mask = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, _BITMAPSIZE_/8);
RtlInitializeBitMap(&bitMask, Mask, _BITMAPSIZE_);
/* Read the format */
format++;
if(*format == '^') {
invert = 1;
format++;
}
if(*format == ']') {
RtlSetBits(&bitMask, ']', 1);
format++;
}
while(*format && (*format != ']')) {
/* According to:
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore98/html/_crt_scanf_width_specification.asp
* "Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]." */
if((*format == '-') && (*(format + 1) != ']')) {
if ((*(format - 1)) < *(format + 1))
RtlSetBits(&bitMask, *(format - 1) +1 , *(format + 1) - *(format - 1));
else
RtlSetBits(&bitMask, *(format + 1) , *(format - 1) - *(format + 1));
format++;
} else
RtlSetBits(&bitMask, *format, 1);
format++;
}
/* read until char is not suitable */
while ((width != 0) && (nch != _EOF_)) {
if(!invert) {
if(RtlAreBitsSet(&bitMask, nch, 1)) {
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
} else
break;
} else {
if(RtlAreBitsClear(&bitMask, nch, 1)) {
if (!suppress) *sptr++ = _CHAR2SUPPORTED_(nch);
} else
break;
}
st++;
nch = _GETC_(file);
if (width>0) width--;
}
/* terminate */
if (!suppress) *sptr = 0;
RtlFreeHeap(RtlGetProcessHeap(), 0, Mask);
}
break;
default:
/* From spec: "if a percent sign is followed by a character
* that has no meaning as a format-control character, that
* character and the following characters are treated as
* an ordinary sequence of characters, that is, a sequence
* of characters that must match the input. For example,
* to specify that a percent-sign character is to be input,
* use %%." */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
if (nch==*format) {
suppress = 1; /* whoops no field to be read */
st = 1; /* but we got what we expected */
nch = _GETC_(file);
}
break;
}
if (st && !suppress) rd++;
else if (!st) break;
}
/* a non-white-space character causes scanf to read, but not store,
* a matching non-white-space character. */
else {
/* check for character match */
if (nch == *format) {
nch = _GETC_(file);
} else break;
}
format++;
}
if (nch!=_EOF_) {
_UNGETC_(nch, file);
}
return rd;
}
#undef _CHAR_
#undef _EOF_
#undef _EOF_RET
#undef _ISSPACE_
#undef _ISDIGIT_
#undef _CHAR2SUPPORTED_
#undef _WIDE2SUPPORTED_
#undef _CHAR2DIGIT_
#undef _GETC_
#undef _UNGETC_
#undef _FUNCTION_
#undef _BITMAPSIZE_

View file

@ -0,0 +1,50 @@
#include <string.h>
/*
* @implemented
*/
void _splitpath(const char* path, char* drive, char* dir, char* fname, char* ext)
{
const char* tmp_drive;
const char* tmp_dir;
const char* tmp_ext;
tmp_drive = strchr(path,':');
if (drive) {
if (tmp_drive) {
strncpy(drive,tmp_drive-1,2);
*(drive+2) = 0;
} else {
*drive = 0;
}
}
if (!tmp_drive) {
tmp_drive = path - 1;
}
tmp_dir = (char*)strrchr(path,'\\');
if (dir) {
if (tmp_dir) {
strncpy(dir,tmp_drive+1,tmp_dir-tmp_drive);
*(dir+(tmp_dir-tmp_drive)) = 0;
} else {
*dir =0;
}
}
tmp_ext = strrchr(path,'.');
if (!tmp_ext) {
tmp_ext = path+strlen(path);
}
if (ext) {
strcpy(ext,tmp_ext);
}
if (tmp_dir) {
strncpy(fname,tmp_dir+1,tmp_ext-tmp_dir-1);
*(fname+(tmp_ext-tmp_dir-1)) = 0;
} else {
strncpy(fname,tmp_drive+1,tmp_ext-tmp_drive-1);
*(fname+(tmp_ext-path))=0;
}
}

View file

@ -0,0 +1,39 @@
/**/
#define WIN32_NO_STATUS
#include <windows.h>
#include <ndk/umtypes.h>
#include <ndk/rtlfuncs.h>
#include <stdlib.h>
#include <stdarg.h>
#define EOF (-1)
/* helper function for *scanf. Returns the value of character c in the
* given base, or -1 if the given character is not a digit of the base.
*/
static int char2digit(char c, int base) {
if ((c>='0') && (c<='9') && (c<='0'+base-1)) return (c-'0');
if (base<=10) return -1;
if ((c>='A') && (c<='Z') && (c<='A'+base-11)) return (c-'A'+10);
if ((c>='a') && (c<='z') && (c<='a'+base-11)) return (c-'a'+10);
return -1;
}
/* vsscanf */
#undef WIDE_SCANF
#undef CONSOLE
#define STRING 1
#include "scanf.h"
int sscanf(const char *str, const char *format, ...)
{
va_list valist;
int res;
va_start(valist, format);
res = vsscanf(str, format, valist);
va_end(valist);
return res;
}
/*EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcscat.h"
/* EOF */

View file

@ -0,0 +1,8 @@
/* $Id$
*/
#define _XINT int
#include <string.h>
#include "tcschr.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcscmp.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcscpy.h"
/* EOF */

View file

@ -0,0 +1,9 @@
/* $Id$
*/
#define _x(_X_) (_X_)
#define _strxspn strcspn
#include <string.h>
#include "strxspn.h"
/* EOF */

View file

@ -0,0 +1,27 @@
#include <string.h>
#include <ctype.h>
/*
* @implemented
*/
int
_stricmp(const char *s1, const char *s2)
{
while (toupper(*s1) == toupper(*s2))
{
if (*s1 == 0)
return 0;
s1++;
s2++;
}
return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)(s2));
}
/*
* @implemented
*/
int
_strcmpi(const char *s1, const char *s2)
{
return _stricmp(s1,s2);
}

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcslen.h"
/* EOF */

View file

@ -0,0 +1,17 @@
#include <string.h>
#include <ctype.h>
/*
* @implemented
*/
char * _strlwr(char *x)
{
char *y=x;
while (*y) {
*y=tolower(*y);
y++;
}
return x;
}

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcsncat.h"
/* EOF */

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcsncmp.h"
/* EOF */

View file

@ -0,0 +1,6 @@
/* $Id$
*/
#include <string.h>
#include "tcsncpy.h"
/* EOF */

View file

@ -0,0 +1,20 @@
#include <string.h>
#include <ctype.h>
/*
* @implemented
*/
int _strnicmp(const char *s1, const char *s2, size_t n)
{
if (n == 0)
return 0;
do {
if (toupper(*s1) != toupper(*s2++))
return toupper(*(unsigned const char *)s1) - toupper(*(unsigned const char *)--s2);
if (*s1++ == 0)
break;
} while (--n != 0);
return 0;
}

View file

@ -0,0 +1,7 @@
/* $Id$
*/
#include <string.h>
#include "tcsnlen.h"
/* EOF */

View file

@ -0,0 +1,54 @@
/*
* $Id$
*/
#include <limits.h>
#include <string.h>
#define BIT_SIZE (CHAR_BIT * sizeof(unsigned long) / sizeof(char))
char* strpbrk(const char *s1, const char *s2)
{
if (*s2 == 0)
{
return 0;
}
if (*(s2+1) == 0)
{
return strchr(s1, *s2);
}
else if (*(s2+2) == 0)
{
char *s3, *s4;
s3 = strchr(s1, *s2);
s4 = strchr(s1, *(s2+1));
if (s3 == 0)
{
return s4;
}
else if (s4 == 0)
{
return s3;
}
return s3 < s4 ? s3 : s4;
}
else
{
unsigned long char_map[(1 << CHAR_BIT) / BIT_SIZE] = {0, };
const unsigned char* str = (const unsigned char*)s1;
while (*s2)
{
char_map[*(const unsigned char*)s2 / BIT_SIZE] |= (1 << (*(const unsigned char*)s2 % BIT_SIZE));
s2++;
}
while (*str)
{
if (char_map[*str / BIT_SIZE] & (1 << (*str % BIT_SIZE)))
{
return (char*)((size_t)str);
}
str++;
}
}
return 0;
}

View file

@ -0,0 +1,8 @@
/* $Id$
*/
#define _XINT int
#include <string.h>
#include "tcsrchr.h"
/* EOF */

View file

@ -0,0 +1,24 @@
#include <string.h>
/*
* @implemented
*/
char * _strrev(char *s)
{
char *e;
char a;
e = s;
while (*e)
e++;
while (s<e)
{
a = *s;
*s = *e;
*e = a;
s++;
e--;
}
return s;
}

View file

@ -0,0 +1,33 @@
#include <string.h>
/*
* @implemented
*/
char* _strnset(char* szToFill, int szFill, size_t sizeMaxFill)
{
char *t = szToFill;
int i = 0;
while (*szToFill != 0 && i < (int) sizeMaxFill)
{
*szToFill = szFill;
szToFill++;
i++;
}
return t;
}
/*
* @implemented
*/
char* _strset(char* szToFill, int szFill)
{
char *t = szToFill;
while (*szToFill != 0)
{
*szToFill = szFill;
szToFill++;
}
return t;
}

View file

@ -0,0 +1,9 @@
/* $Id$
*/
#define _x(_X_) (!(_X_))
#define _strxspn strspn
#include <string.h>
#include "strxspn.h"
/* EOF */

Some files were not shown because too many files have changed in this diff Show more