DXGL r277 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r276‎ | r277 | r278 >
Date:21:31, 20 October 2012
Author:admin
Status:new
Tags:
Comment:
minilibc: Add strlen, strcpy, and strncpy
Modified paths:
  • /minilibc/common.inc (modified) (history)
  • /minilibc/minilibc.vcxproj (modified) (history)
  • /minilibc/minilibc.vcxproj.filters (modified) (history)
  • /minilibc/strcpy_x86.asm (added) (history)
  • /minilibc/strlen_x86.asm (added) (history)
  • /minilibc/strncpy_x86.asm (added) (history)

Diff [purge]

Index: minilibc/common.inc
@@ -16,4 +16,6 @@
1717 ; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1818
1919 EXTERN C itoachars:ptr byte
20 -EXTERN C memset_ptr:ptr dword
\ No newline at end of file
 20+EXTERN C memset_ptr:ptr dword
 21+EXTERN C strlen:proc
 22+EXTERN C memcpy:proc
\ No newline at end of file
Index: minilibc/minilibc.vcxproj
@@ -102,6 +102,12 @@
103103 <CustomBuild Include="strlen_x86.asm">
104104 <FileType>Document</FileType>
105105 </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>
106112 </ItemGroup>
107113 <ItemGroup>
108114 <ClCompile Include="common.c">
Index: minilibc/minilibc.vcxproj.filters
@@ -36,6 +36,12 @@
3737 <CustomBuild Include="strlen_x86.asm">
3838 <Filter>Source Files</Filter>
3939 </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>
4046 </ItemGroup>
4147 <ItemGroup>
4248 <ClCompile Include="exit.c">
Index: minilibc/strcpy_x86.asm
@@ -0,0 +1,35 @@
 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/strlen_x86.asm
@@ -0,0 +1,67 @@
 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/strncpy_x86.asm
@@ -0,0 +1,41 @@
 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