Skip to content

Commit

Permalink
Improvements to c-library, ported libpng + zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Meulengracht committed Apr 24, 2016
1 parent 4919322 commit 40a667e
Show file tree
Hide file tree
Showing 36 changed files with 7,963 additions and 4,707 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg
*.cod
47 changes: 37 additions & 10 deletions clib/include/setjmp.h
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
/* Saves registers & stack pointer & ip
*
*/
/* MollenOS
*
* Copyright 2011 - 2016, Philip Meulengracht
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ? , either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.If not, see <http://www.gnu.org/licenses/>.
*
*
* MollenOS C Library - SetJmp & LongJmp
*/

#ifndef __SETJMP_INC__
#define __SETJMP_INC__

//Includes
/* Includes */
#include <crtdefs.h>
#include <stdint.h>

//Defines
#define _JBLEN 16
/* Definitions */
#define _JBLEN 24
#define _JBTYPE int
typedef _JBTYPE jmp_buf[_JBLEN];

/* C++ Guard */
#ifdef __cplusplus
extern "C" {
#endif

//Functions
extern int setjmp(jmp_buf env);
extern void longjmp(jmp_buf env, int value);
/* Prototypes */

/* The save in time -> jump */
_CRT_EXTERN int _setjmp(jmp_buf env);
_CRT_EXTERN int _setjmp3(jmp_buf env, int nb_args, ...);

/* Shorthand */
#define setjmp(env) _setjmp(env)

/* Restore time-state -> jmp */
_CRT_EXTERN void longjmp(jmp_buf env, int value);

#ifdef __cplusplus
}
#endif

#endif
#endif //!__SETJMP_INC__
2 changes: 1 addition & 1 deletion clib/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ _CRT_EXTERN int fclose(FILE * stream);
_CRT_EXTERN FILE *fopen(const char * filename, const char * mode);
_CRT_EXTERN FILE *freopen(const char * filename, const char * mode, FILE * stream);
_CRT_EXTERN int remove(const char * filename);
_CRT_EXTERN int fflush(FILE * stream);

//Rename
//tmpfile
//tmpnam

//extern void setbuf (FILE * stream, char * buffer);
//extern int setvbuf(FILE * stream, char * buffer, int mode, size_t size);
//extern int fflush(FILE * stream);

/*******************************
* Formatted IO *
Expand Down
2 changes: 2 additions & 0 deletions clib/mscv/CLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<ClCompile Include="..\src\stdio\feof.c" />
<ClCompile Include="..\src\stdio\ferror.c" />
<ClCompile Include="..\src\stdio\fflags.c" />
<ClCompile Include="..\src\stdio\fflush.c" />
<ClCompile Include="..\src\stdio\fgetpos.c" />
<ClCompile Include="..\src\stdio\fopen.c" />
<ClCompile Include="..\src\stdio\fprintf.c" />
Expand Down Expand Up @@ -330,6 +331,7 @@
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<BufferSecurityCheck>false</BufferSecurityCheck>
<EnableEnhancedInstructionSet>NoExtensions</EnableEnhancedInstructionSet>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
Expand Down
3 changes: 3 additions & 0 deletions clib/mscv/CLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,9 @@
<ClCompile Include="..\src\string\strtoll.c">
<Filter>Source\string</Filter>
</ClCompile>
<ClCompile Include="..\src\stdio\fflush.c">
<Filter>Source\stdio\File</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<MASM Include="..\crt\alldvrm.S">
Expand Down
Binary file modified clib/mscv/CLib/CLib.tlog/cl.command.1.tlog
Binary file not shown.
124 changes: 61 additions & 63 deletions clib/mscv/CLib/atoi64.cod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ EXTRN __ctype:BYTE
; File c:\users\philip\documents\github\mollenos\clib\src\string\atoi64.c
; COMDAT _atoi64
_TEXT SEGMENT
_acc$ = -12 ; size = 8
_neg$1$ = -4 ; size = 4
_acc$1$ = 8 ; size = 4
_nptr$ = 8 ; size = 4
Expand All @@ -25,47 +24,52 @@ _atoi64 PROC ; COMDAT

00000 55 push ebp
00001 8b ec mov ebp, esp
00003 83 ec 0c sub esp, 12 ; 0000000cH
00003 51 push ecx

; 10 : char *s = (char *)nptr;

00006 8b 4d 08 mov ecx, DWORD PTR _nptr$[ebp]
00009 0f 57 c0 xorps xmm0, xmm0
00004 8b 4d 08 mov ecx, DWORD PTR _nptr$[ebp]
00007 53 push ebx
00008 56 push esi

; 11 : __int64 acc = 0;

0000c 66 0f 13 45 f4 movlpd QWORD PTR _acc$[ebp], xmm0
00009 33 f6 xor esi, esi
0000b 33 db xor ebx, ebx
0000d 89 75 08 mov DWORD PTR _acc$1$[ebp], esi

; 12 : int neg = 0;

00011 c7 45 fc 00 00
00 00 mov DWORD PTR _neg$1$[ebp], 0
00010 89 5d fc mov DWORD PTR _neg$1$[ebp], ebx

; 13 :
; 14 : if (nptr == NULL)

00018 85 c9 test ecx, ecx
0001a 75 08 jne SHORT $LN12@atoi64
00013 85 c9 test ecx, ecx
00015 75 0a jne SHORT $LN12@atoi64

; 15 : return 0;

0001c 33 c0 xor eax, eax
0001e 33 d2 xor edx, edx
00017 5e pop esi
00018 33 c0 xor eax, eax
0001a 33 d2 xor edx, edx
0001c 5b pop ebx

; 36 : }

00020 8b e5 mov esp, ebp
00022 5d pop ebp
00023 c3 ret 0
0001d 8b e5 mov esp, ebp
0001f 5d pop ebp
00020 c3 ret 0
$LN12@atoi64:

; 16 :
; 17 : while(isspace((int)*s))

00024 0f b6 01 movzx eax, BYTE PTR [ecx]
00027 f6 80 00 00 00
00021 0f b6 01 movzx eax, BYTE PTR [ecx]
00024 f6 80 00 00 00
00 20 test BYTE PTR __ctype[eax], 32 ; 00000020H
0002e 74 0e je SHORT $LN7@atoi64
0002b 74 11 je SHORT $LN7@atoi64
0002d 8d 49 00 npad 3
$LL8@atoi64:
00030 0f b6 41 01 movzx eax, BYTE PTR [ecx+1]

Expand All @@ -91,15 +95,15 @@ $LN7@atoi64:

; 22 : s++;

0004b eb 04 jmp SHORT $LN21@atoi64
0004b eb 04 jmp SHORT $LN20@atoi64
$LN6@atoi64:

; 23 : }
; 24 : else if (*s == '+')

0004d 3c 2b cmp al, 43 ; 0000002bH
0004f 75 01 jne SHORT $LN13@atoi64
$LN21@atoi64:
$LN20@atoi64:

; 25 : s++;

Expand All @@ -111,76 +115,70 @@ $LN13@atoi64:

00052 8a 11 mov dl, BYTE PTR [ecx]
00054 0f b6 c2 movzx eax, dl
00057 53 push ebx
00058 8b 5d f8 mov ebx, DWORD PTR _acc$[ebp+4]
0005b 56 push esi
0005c f6 80 00 00 00
00057 f6 80 00 00 00
00 04 test BYTE PTR __ctype[eax], 4
00063 8b 75 f4 mov esi, DWORD PTR _acc$[ebp]
00066 74 45 je SHORT $LN2@atoi64
00068 89 75 08 mov DWORD PTR _acc$1$[ebp], esi
0006b 57 push edi
0006c 8d 64 24 00 npad 4
0005e 74 3e je SHORT $LN2@atoi64
00060 57 push edi
$LL3@atoi64:

; 28 : {
; 29 : acc = 10 * acc + ((int)*s - '0');

00070 0f be c2 movsx eax, dl
00061 0f be c2 movsx eax, dl

; 30 : s++;

00073 8d 49 01 lea ecx, DWORD PTR [ecx+1]
00076 83 e8 30 sub eax, 48 ; 00000030H
00079 99 cdq
0007a 8b fa mov edi, edx
0007c 8b d6 mov edx, esi
0007e 8b f3 mov esi, ebx
00080 0f a4 d6 02 shld esi, edx, 2
00084 c1 e2 02 shl edx, 2
00087 01 55 08 add DWORD PTR _acc$1$[ebp], edx
0008a 8b 55 08 mov edx, DWORD PTR _acc$1$[ebp]
0008d 13 de adc ebx, esi
0008f 0f a4 d3 01 shld ebx, edx, 1
00093 03 d2 add edx, edx
00095 03 c2 add eax, edx
00097 8a 11 mov dl, BYTE PTR [ecx]
00099 8b f0 mov esi, eax
0009b 0f b6 c2 movzx eax, dl
0009e 13 df adc ebx, edi
000a0 89 75 08 mov DWORD PTR _acc$1$[ebp], esi
000a3 f6 80 00 00 00
00064 8d 49 01 lea ecx, DWORD PTR [ecx+1]
00067 83 e8 30 sub eax, 48 ; 00000030H
0006a 99 cdq
0006b 8b fa mov edi, edx
0006d 8b d6 mov edx, esi
0006f 8b f3 mov esi, ebx
00071 0f a4 d6 02 shld esi, edx, 2
00075 c1 e2 02 shl edx, 2
00078 01 55 08 add DWORD PTR _acc$1$[ebp], edx
0007b 8b 55 08 mov edx, DWORD PTR _acc$1$[ebp]
0007e 13 de adc ebx, esi
00080 0f a4 d3 01 shld ebx, edx, 1
00084 03 d2 add edx, edx
00086 03 c2 add eax, edx
00088 8a 11 mov dl, BYTE PTR [ecx]
0008a 8b f0 mov esi, eax
0008c 0f b6 c2 movzx eax, dl
0008f 13 df adc ebx, edi
00091 89 75 08 mov DWORD PTR _acc$1$[ebp], esi
00094 f6 80 00 00 00
00 04 test BYTE PTR __ctype[eax], 4
000aa 75 c4 jne SHORT $LL3@atoi64
000ac 5f pop edi
0009b 75 c4 jne SHORT $LL3@atoi64
0009d 5f pop edi
$LN2@atoi64:

; 31 : }
; 32 :
; 33 : if (neg)

000ad 83 7d fc 00 cmp DWORD PTR _neg$1$[ebp], 0
000b1 74 07 je SHORT $LN1@atoi64
0009e 83 7d fc 00 cmp DWORD PTR _neg$1$[ebp], 0
000a2 74 07 je SHORT $LN1@atoi64

; 34 : acc *= -1;

000b3 f7 de neg esi
000b5 83 d3 00 adc ebx, 0
000b8 f7 db neg ebx
000a4 f7 de neg esi
000a6 83 d3 00 adc ebx, 0
000a9 f7 db neg ebx
$LN1@atoi64:

; 35 : return acc;

000ba 8b c6 mov eax, esi
000bc 8b d3 mov edx, ebx
000be 5e pop esi
000bf 5b pop ebx
000ab 8b c6 mov eax, esi
000ad 8b d3 mov edx, ebx
000af 5e pop esi
000b0 5b pop ebx

; 36 : }

000c0 8b e5 mov esp, ebp
000c2 5d pop ebp
000c3 c3 ret 0
000b1 8b e5 mov esp, ebp
000b3 5d pop ebp
000b4 c3 ret 0
_atoi64 ENDP
_TEXT ENDS
END
Loading

0 comments on commit 40a667e

Please sign in to comment.