Index: minilibc/strlen_x86.asm |
— | — | @@ -1,67 +0,0 @@ |
2 | | -; DXGL
|
3 | | -; Copyright (C) 2012 William Feely
|
4 | | -
|
5 | | -; This library is free software; you can redistribute it and/or
|
6 | | -; modify it under the terms of the GNU Lesser General Public
|
7 | | -; License as published by the Free Software Foundation; either
|
8 | | -; version 2.1 of the License, or (at your option) any later version.
|
9 | | -
|
10 | | -; This library is distributed in the hope that it will be useful,
|
11 | | -; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | | -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | | -; Lesser General Public License for more details.
|
14 | | -
|
15 | | -; You should have received a copy of the GNU Lesser General Public
|
16 | | -; License along with this library; if not, write to the Free Software
|
17 | | -; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | | -
|
19 | | -.model flat, c
|
20 | | -.code
|
21 | | -INCLUDE common.inc
|
22 | | -
|
23 | | -strlen PROC string:ptr byte
|
24 | | - push ecx
|
25 | | - push ebx
|
26 | | - push esi
|
27 | | - mov eax, string
|
28 | | - and eax, 3
|
29 | | - jnz aligned_loop
|
30 | | -unaligned_loop:
|
31 | | - mov ecx, 0
|
32 | | - mov esi, string
|
33 | | - test byte ptr [esi],0
|
34 | | - jz return
|
35 | | - dec eax
|
36 | | - inc esi
|
37 | | - inc ecx
|
38 | | - jz aligned_loop
|
39 | | - jmp unaligned_loop
|
40 | | -aligned_loop:
|
41 | | - mov eax, dword ptr [esi]
|
42 | | - mov ebx, eax
|
43 | | - and ebx, 0FFh
|
44 | | - jz return
|
45 | | - inc ecx
|
46 | | - mov ebx, eax
|
47 | | - and ebx, 0FF00h
|
48 | | - jz return
|
49 | | - inc ecx
|
50 | | - mov ebx, eax
|
51 | | - and ebx, 0FF0000h
|
52 | | - jz return
|
53 | | - inc ecx
|
54 | | - mov ebx, eax
|
55 | | - and ebx, 0FF000000h
|
56 | | - jz return
|
57 | | - inc ecx
|
58 | | - add esi, 4
|
59 | | - jmp aligned_loop
|
60 | | -return:
|
61 | | - mov eax, ecx
|
62 | | - pop esi
|
63 | | - pop ebx
|
64 | | - pop ecx
|
65 | | - ret
|
66 | | -strlen ENDP
|
67 | | -
|
68 | | -end |
\ No newline at end of file |
Index: minilibc/strcpy_x86.asm |
— | — | @@ -1,35 +0,0 @@ |
2 | | -; DXGL
|
3 | | -; Copyright (C) 2012 William Feely
|
4 | | -
|
5 | | -; This library is free software; you can redistribute it and/or
|
6 | | -; modify it under the terms of the GNU Lesser General Public
|
7 | | -; License as published by the Free Software Foundation; either
|
8 | | -; version 2.1 of the License, or (at your option) any later version.
|
9 | | -
|
10 | | -; This library is distributed in the hope that it will be useful,
|
11 | | -; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | | -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | | -; Lesser General Public License for more details.
|
14 | | -
|
15 | | -; You should have received a copy of the GNU Lesser General Public
|
16 | | -; License along with this library; if not, write to the Free Software
|
17 | | -; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | | -
|
19 | | -.model flat, c
|
20 | | -.code
|
21 | | -INCLUDE common.inc
|
22 | | -
|
23 | | -strcpy PROC dest:ptr byte, src:ptr byte
|
24 | | - push src
|
25 | | - call strlen
|
26 | | - add esp, 4
|
27 | | - push eax
|
28 | | - push src
|
29 | | - push dest
|
30 | | - call memcpy
|
31 | | - add esp, 12
|
32 | | - mov eax, dest
|
33 | | - ret
|
34 | | -strcpy ENDP
|
35 | | -
|
36 | | -end |
\ No newline at end of file |
Index: minilibc/strncpy_x86.asm |
— | — | @@ -1,41 +0,0 @@ |
2 | | -; DXGL
|
3 | | -; Copyright (C) 2012 William Feely
|
4 | | -
|
5 | | -; This library is free software; you can redistribute it and/or
|
6 | | -; modify it under the terms of the GNU Lesser General Public
|
7 | | -; License as published by the Free Software Foundation; either
|
8 | | -; version 2.1 of the License, or (at your option) any later version.
|
9 | | -
|
10 | | -; This library is distributed in the hope that it will be useful,
|
11 | | -; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 | | -; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13 | | -; Lesser General Public License for more details.
|
14 | | -
|
15 | | -; You should have received a copy of the GNU Lesser General Public
|
16 | | -; License along with this library; if not, write to the Free Software
|
17 | | -; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | | -
|
19 | | -.model flat, c
|
20 | | -.code
|
21 | | -INCLUDE common.inc
|
22 | | -
|
23 | | -strncpy PROC dest:ptr byte, src:ptr byte, count:dword
|
24 | | - push src
|
25 | | - call strlen
|
26 | | - add esp, 4
|
27 | | - cmp eax, count
|
28 | | - jl shortstring
|
29 | | - push count
|
30 | | - jmp longstring
|
31 | | -shortstring:
|
32 | | - push eax
|
33 | | -longstring:
|
34 | | - push src
|
35 | | - push dest
|
36 | | - call memcpy
|
37 | | - add esp, 12
|
38 | | - mov eax, dest
|
39 | | - ret
|
40 | | -strncpy ENDP
|
41 | | -
|
42 | | -end |
\ No newline at end of file |
Index: minilibc/common.c |
— | — | @@ -17,5 +17,4 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 |
|
21 | | -int errno;
|
22 | 21 | const char itoachars[37] = "0123456789abcdefghijklmnopqrstuvwxyz"; |
\ No newline at end of file |
Index: minilibc/common.h |
— | — | @@ -17,6 +17,7 @@ |
18 | 18 |
|
19 | 19 | #include <stdio.h>
|
20 | 20 | #include <stdlib.h>
|
| 21 | +#include <errno.h>
|
21 | 22 |
|
22 | 23 | extern const char itoachars[37];
|
23 | 24 |
|
Index: minilibc/common.inc |
— | — | @@ -17,5 +17,4 @@ |
18 | 18 |
|
19 | 19 | EXTERN C itoachars:ptr byte
|
20 | 20 | EXTERN C memset_ptr:ptr dword
|
21 | | -EXTERN C strlen:proc
|
22 | 21 | EXTERN C memcpy:proc |
\ No newline at end of file |
Index: minilibc/errno.c |
— | — | @@ -16,7 +16,6 @@ |
17 | 17 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | | -#include <errno.h>
|
21 | 20 |
|
22 | 21 | static int errorno;
|
23 | 22 |
|
Index: minilibc/memory.c |
— | — | @@ -0,0 +1,55 @@ |
| 2 | +// DXGL
|
| 3 | +// Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +// This library is free software; you can redistribute it and/or
|
| 6 | +// modify it under the terms of the GNU Lesser General Public
|
| 7 | +// License as published by the Free Software Foundation; either
|
| 8 | +// version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +// This library is distributed in the hope that it will be useful,
|
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +// Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +// You should have received a copy of the GNU Lesser General Public
|
| 16 | +// License along with this library; if not, write to the Free Software
|
| 17 | +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +#include "common.h"
|
| 20 | +#include <Windows.h>
|
| 21 | +
|
| 22 | +void *malloc(size_t size)
|
| 23 | +{
|
| 24 | + void *ptr;
|
| 25 | + ptr = HeapAlloc(GetProcessHeap(),0,size);
|
| 26 | + if(!ptr)
|
| 27 | + {
|
| 28 | + _set_errno(ENOMEM);
|
| 29 | + return NULL;
|
| 30 | + }
|
| 31 | + return ptr;
|
| 32 | +}
|
| 33 | +
|
| 34 | +void *realloc(void *memblock, size_t size)
|
| 35 | +{
|
| 36 | + void *ptr;
|
| 37 | + if(!size)
|
| 38 | + {
|
| 39 | + free(memblock);
|
| 40 | + return NULL;
|
| 41 | + }
|
| 42 | + if(!memblock) ptr = HeapAlloc(GetProcessHeap(),0,size);
|
| 43 | + else ptr = HeapReAlloc(GetProcessHeap(),0,memblock,size);
|
| 44 | + if(!ptr)
|
| 45 | + {
|
| 46 | + _set_errno(ENOMEM);
|
| 47 | + return NULL;
|
| 48 | + }
|
| 49 | + return ptr;
|
| 50 | +}
|
| 51 | +
|
| 52 | +void free(void *memblock)
|
| 53 | +{
|
| 54 | + if(!memblock) return;
|
| 55 | + if(HeapFree(GetProcessHeap(),0,memblock)) errno = EINVAL;
|
| 56 | +} |
\ No newline at end of file |
Index: minilibc/minilibc.vcxproj |
— | — | @@ -99,15 +99,9 @@ |
100 | 100 | <CustomBuild Include="rtcapi_x86.asm">
|
101 | 101 | <FileType>Document</FileType>
|
102 | 102 | </CustomBuild>
|
103 | | - <CustomBuild Include="strlen_x86.asm">
|
| 103 | + <CustomBuild Include="string_x86.asm">
|
104 | 104 | <FileType>Document</FileType>
|
105 | 105 | </CustomBuild>
|
106 | | - <CustomBuild Include="strcpy_x86.asm">
|
107 | | - <FileType>Document</FileType>
|
108 | | - </CustomBuild>
|
109 | | - <CustomBuild Include="strncpy_x86.asm">
|
110 | | - <FileType>Document</FileType>
|
111 | | - </CustomBuild>
|
112 | 106 | </ItemGroup>
|
113 | 107 | <ItemGroup>
|
114 | 108 | <ClCompile Include="common.c">
|
— | — | @@ -118,6 +112,7 @@ |
119 | 113 | <ClCompile Include="exit.c" />
|
120 | 114 | <ClCompile Include="file.c" />
|
121 | 115 | <ClCompile Include="init.c" />
|
| 116 | + <ClCompile Include="memory.c" />
|
122 | 117 | <ClCompile Include="memset.c" />
|
123 | 118 | </ItemGroup>
|
124 | 119 | <ItemGroup>
|
Index: minilibc/minilibc.vcxproj.filters |
— | — | @@ -33,15 +33,9 @@ |
34 | 34 | <CustomBuild Include="rtcapi_x86.asm">
|
35 | 35 | <Filter>Source Files</Filter>
|
36 | 36 | </CustomBuild>
|
37 | | - <CustomBuild Include="strlen_x86.asm">
|
| 37 | + <CustomBuild Include="string_x86.asm">
|
38 | 38 | <Filter>Source Files</Filter>
|
39 | 39 | </CustomBuild>
|
40 | | - <CustomBuild Include="strcpy_x86.asm">
|
41 | | - <Filter>Source Files</Filter>
|
42 | | - </CustomBuild>
|
43 | | - <CustomBuild Include="strncpy_x86.asm">
|
44 | | - <Filter>Source Files</Filter>
|
45 | | - </CustomBuild>
|
46 | 40 | </ItemGroup>
|
47 | 41 | <ItemGroup>
|
48 | 42 | <ClCompile Include="exit.c">
|
— | — | @@ -62,6 +56,9 @@ |
63 | 57 | <ClCompile Include="errno.c">
|
64 | 58 | <Filter>Source Files</Filter>
|
65 | 59 | </ClCompile>
|
| 60 | + <ClCompile Include="memory.c">
|
| 61 | + <Filter>Source Files</Filter>
|
| 62 | + </ClCompile>
|
66 | 63 | </ItemGroup>
|
67 | 64 | <ItemGroup>
|
68 | 65 | <ClInclude Include="common.h">
|
Index: minilibc/string_x86.asm |
— | — | @@ -0,0 +1,99 @@ |
| 2 | +; DXGL
|
| 3 | +; Copyright (C) 2012 William Feely
|
| 4 | +
|
| 5 | +; This library is free software; you can redistribute it and/or
|
| 6 | +; modify it under the terms of the GNU Lesser General Public
|
| 7 | +; License as published by the Free Software Foundation; either
|
| 8 | +; version 2.1 of the License, or (at your option) any later version.
|
| 9 | +
|
| 10 | +; This library is distributed in the hope that it will be useful,
|
| 11 | +; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 | +; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
| 13 | +; Lesser General Public License for more details.
|
| 14 | +
|
| 15 | +; You should have received a copy of the GNU Lesser General Public
|
| 16 | +; License along with this library; if not, write to the Free Software
|
| 17 | +; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
| 18 | +
|
| 19 | +.model flat, c
|
| 20 | +.code
|
| 21 | +INCLUDE common.inc
|
| 22 | +
|
| 23 | +strcpy PROC dest:ptr byte, src:ptr byte
|
| 24 | + push src
|
| 25 | + call strlen
|
| 26 | + add esp, 4
|
| 27 | + push eax
|
| 28 | + push src
|
| 29 | + push dest
|
| 30 | + call memcpy
|
| 31 | + add esp, 12
|
| 32 | + mov eax, dest
|
| 33 | + ret
|
| 34 | +strcpy ENDP
|
| 35 | +
|
| 36 | +strlen PROC string:ptr byte
|
| 37 | + push ecx
|
| 38 | + push ebx
|
| 39 | + push esi
|
| 40 | + mov eax, string
|
| 41 | + and eax, 3
|
| 42 | + jnz aligned_loop
|
| 43 | +unaligned_loop:
|
| 44 | + mov ecx, 0
|
| 45 | + mov esi, string
|
| 46 | + test byte ptr [esi],0
|
| 47 | + jz return
|
| 48 | + dec eax
|
| 49 | + inc esi
|
| 50 | + inc ecx
|
| 51 | + jz aligned_loop
|
| 52 | + jmp unaligned_loop
|
| 53 | +aligned_loop:
|
| 54 | + mov eax, dword ptr [esi]
|
| 55 | + mov ebx, eax
|
| 56 | + and ebx, 0FFh
|
| 57 | + jz return
|
| 58 | + inc ecx
|
| 59 | + mov ebx, eax
|
| 60 | + and ebx, 0FF00h
|
| 61 | + jz return
|
| 62 | + inc ecx
|
| 63 | + mov ebx, eax
|
| 64 | + and ebx, 0FF0000h
|
| 65 | + jz return
|
| 66 | + inc ecx
|
| 67 | + mov ebx, eax
|
| 68 | + and ebx, 0FF000000h
|
| 69 | + jz return
|
| 70 | + inc ecx
|
| 71 | + add esi, 4
|
| 72 | + jmp aligned_loop
|
| 73 | +return:
|
| 74 | + mov eax, ecx
|
| 75 | + pop esi
|
| 76 | + pop ebx
|
| 77 | + pop ecx
|
| 78 | + ret
|
| 79 | +strlen ENDP
|
| 80 | +
|
| 81 | +strncpy PROC dest:ptr byte, src:ptr byte, count:dword
|
| 82 | + push src
|
| 83 | + call strlen
|
| 84 | + add esp, 4
|
| 85 | + cmp eax, count
|
| 86 | + jl shortstring
|
| 87 | + push count
|
| 88 | + jmp longstring
|
| 89 | +shortstring:
|
| 90 | + push eax
|
| 91 | +longstring:
|
| 92 | + push src
|
| 93 | + push dest
|
| 94 | + call memcpy
|
| 95 | + add esp, 12
|
| 96 | + mov eax, dest
|
| 97 | + ret
|
| 98 | +strncpy ENDP
|
| 99 | +
|
| 100 | +end |
\ No newline at end of file |