aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/uzlib/src/nasm
diff options
context:
space:
mode:
Diffstat (limited to 'test/monniaux/uzlib/src/nasm')
-rw-r--r--test/monniaux/uzlib/src/nasm/crc32.nas118
-rw-r--r--test/monniaux/uzlib/src/nasm/nasmlcm.inc326
-rw-r--r--test/monniaux/uzlib/src/nasm/tinfzlib.nas160
3 files changed, 604 insertions, 0 deletions
diff --git a/test/monniaux/uzlib/src/nasm/crc32.nas b/test/monniaux/uzlib/src/nasm/crc32.nas
new file mode 100644
index 00000000..bd91692b
--- /dev/null
+++ b/test/monniaux/uzlib/src/nasm/crc32.nas
@@ -0,0 +1,118 @@
+;;
+;; NASM assembler crc32
+;;
+;; Copyright (c) 1998-2003 by Joergen Ibsen / Jibz
+;; All Rights Reserved
+;;
+;; http://www.ibsensoftware.com/
+;;
+;; This software is provided 'as-is', without any express
+;; or implied warranty. In no event will the authors be
+;; held liable for any damages arising from the use of
+;; this software.
+;;
+;; Permission is granted to anyone to use this software
+;; for any purpose, including commercial applications,
+;; and to alter it and redistribute it freely, subject to
+;; the following restrictions:
+;;
+;; 1. The origin of this software must not be
+;; misrepresented; you must not claim that you
+;; wrote the original software. If you use this
+;; software in a product, an acknowledgment in
+;; the product documentation would be appreciated
+;; but is not required.
+;;
+;; 2. Altered source versions must be plainly marked
+;; as such, and must not be misrepresented as
+;; being the original software.
+;;
+;; 3. This notice may not be removed or altered from
+;; any source distribution.
+;;
+
+; CRC32 algorithm taken from the zlib source, which is
+; Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
+
+cpu 386
+
+bits 32
+
+%include "nasmlcm.inc"
+
+section lcmtext
+
+lcmglobal tinf_crc32,8
+
+lcmexport tinf_crc32,8
+
+; =============================================================
+
+lcmlabel tinf_crc32,8
+ ; tinf_crc32(const void *data,
+ ; unsigned int length);
+
+ .len$ equ 2*4 + 4 + 4
+ .dat$ equ 2*4 + 4
+
+ push esi
+ push edi
+
+ mov esi, [esp + .dat$] ; esi -> buffer
+ mov ecx, [esp + .len$] ; ecx = length
+
+ sub eax, eax ; crc = 0
+
+ test esi, esi
+ jz short .c_exit
+
+ test ecx, ecx
+ jz short .c_exit
+
+ dec eax ; crc = 0xffffffff
+
+%ifdef _OBJ_
+ mov edi, tinf_crc32tab wrt FLAT ; edi -> crctab
+%else
+ mov edi, tinf_crc32tab ; edi -> crctab
+%endif
+
+ .c_next_byte:
+ xor al, [esi]
+ inc esi
+
+ mov edx, 0x0f
+ and edx, eax
+
+ shr eax, 4
+
+ xor eax, [edi + edx*4]
+
+ mov edx, 0x0f
+ and edx, eax
+
+ shr eax, 4
+
+ xor eax, [edi + edx*4]
+
+ dec ecx
+ jnz short .c_next_byte
+
+ not eax
+
+ .c_exit:
+ pop edi
+ pop esi
+
+ lcmret 8
+
+; =============================================================
+
+section lcmdata
+
+tinf_crc32tab dd 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190
+ dd 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344
+ dd 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278
+ dd 0xbdbdf21c
+
+; =============================================================
diff --git a/test/monniaux/uzlib/src/nasm/nasmlcm.inc b/test/monniaux/uzlib/src/nasm/nasmlcm.inc
new file mode 100644
index 00000000..5cbe7e0d
--- /dev/null
+++ b/test/monniaux/uzlib/src/nasm/nasmlcm.inc
@@ -0,0 +1,326 @@
+;;
+;; NASM linker compatibility macros 2002.07.24
+;;
+;; Copyright (c) 2001-2003 by Joergen Ibsen / Jibz
+;; All Rights Reserved
+;;
+;; http://www.ibsensoftware.com/
+;;
+
+; define _ELF_ for ELF32 object files
+; define _OBJ_ for OMF object files
+; define _OBJ_ and _DLL_ for OMF object files for a dll (stdcall)
+; define _MSLIBS_ for MS style Win32 import libs (lcmwinextern)
+; default is DJGPP/WIN32 COFF object files
+
+; remember to do lcm*extern before lcmimport
+
+; ====================================================================
+;
+; There are differences between how the object formats that NASM
+; supports work, and what features they support. Similarly there
+; are differences between how complete and standard compliant the
+; support for these formats are in linkers.
+;
+; The NASM linker compatibility macros (nasmlcm) were put together
+; to ease my work by allowing a single source file to be assembled
+; for use with a number of compilers/linkers.
+;
+; Currently obj/omf, win32/coff, djgpp/coff and elf32 output formats
+; are supported. The following macros are available:
+;
+; lcmtext - section name for the code section
+; lcmdata - section name for the initialized data section
+; lcmbss - section name for the uninitialized data section
+;
+; lcmglobal - declare a function (two arguments) or data (one
+; argument) as global in the current format
+; lcmcglobal - same as lcmglobal, but uses C name decoration
+;
+; lcmextern - declare a function (two arguments) or data (one
+; argument) as extern in the current format
+; lcmcextern - same as lcmextern, but uses C name decoration
+; lcmdllextern - same as lcmextern, but uses dll name decoration
+; lcmwinextern - same as lcmextern, but uses name decoration for
+; calling Win32 Api functions (see _MSLIBS_)
+;
+; lcmimport - declares a function (two arguments) or data (one
+; argument) as imported in the current format
+; lcmexport - declares a function (two arguments) or data (one
+; argument) as exported in the current format
+;
+; lcmlabel - start label for a function in the current format
+; lcmclabel - start label for a function with C name decoration
+; lcmadjust - adjust stack after a function call in the current
+; format
+; lcmret - return from a function in the current format
+; lcmcret - return from a C function
+;
+; The following defines change the format and behaviour:
+;
+; _ELF_ - the lcm*global macro adds :function and :data type
+; specifiers
+;
+; _OBJ_ - section names are similar to those produced by
+; Borland tools to increase compatibility with
+; various OMF compatible linkers
+;
+; _DLL_ - functions are exported and imported with added
+; size specifiers (_SomeFunction@12), lcmret adjusts
+; stack (stdcall)
+;
+; _MSLIBS_ - the lcmwinextern macro prepends an underscore and
+; adds size specification for functions, allowing
+; the object file to be linked with MS libraries.
+;
+; ====================================================================
+
+%ifndef NASMLCM_INC_INCLUDED
+%define NASMLCM_INC_INCLUDED
+
+%ifdef _DLL_
+ %ifndef _OBJ_
+ %error "_DLL_ needs _OBJ_ defined!"
+ %endif
+%endif
+
+; --- define lcm- section names ---
+;
+; a number of linkers require omf objects where the section
+; names are equal to those produces by tasm.
+
+%ifdef _OBJ_
+
+ %define lcmtext _TEXT class=CODE public use32 align=4 FLAT
+ %define lcmdata _DATA class=DATA public use32 align=4
+ %define lcmbss _BSS class=BSS public use32 align=4 FLAT
+
+ group FLAT
+ group DGROUP _DATA
+
+%else ; _OBJ_
+
+ %define lcmtext .text
+ %define lcmdata .data
+ %define lcmbss .bss
+
+%endif ; _OBJ_
+
+; --- define lcmglobal and lcm*extern macros ---
+;
+; special handling of functions and data for ELF32
+
+%ifdef _ELF_
+
+ %macro lcmglobal 2
+ global %{1}:function
+ %endmacro
+ %macro lcmglobal 1
+ global %{1}:data
+ %endmacro
+
+ %define lcmcglobal lcmglobal
+
+ %macro lcmextern 1-2
+ extern %1
+ %endmacro
+
+ %macro lcmcextern 0
+ %error lcmcextern not supported in ELF format
+ %endmacro
+
+ %macro lcmdllextern 0
+ %error lcmdllextern not supported in ELF format
+ %endmacro
+
+%else ; _ELF_
+
+ %ifdef _DLL_
+
+ %macro lcmglobal 2
+ global _%1
+ global _%1@%2
+ %endmacro
+ %macro lcmglobal 1
+ global _%1
+ %define %1 _%1
+ %endmacro
+
+ %macro lcmcglobal 2
+ global _%1
+ %endmacro
+ %macro lcmcglobal 1
+ global _%1
+ %define %1 _%1
+ %endmacro
+
+ %macro lcmextern 2
+ extern _%1@%2
+ %define %1 _%1@%2
+ %endmacro
+ %macro lcmextern 1
+ extern _%1
+ %define %1 _%1
+ %endmacro
+
+ %else
+
+ %macro lcmglobal 2
+ global _%1
+ %endmacro
+ %macro lcmglobal 1
+ global _%1
+ %define %1 _%1
+ %endmacro
+
+ %define lcmcglobal lcmglobal
+
+ %macro lcmextern 1-2
+ extern _%1
+ %define %1 _%1
+ %endmacro
+
+ %endif
+
+ %macro lcmcextern 1-2
+ extern _%1
+ %define %1 _%1
+ %endmacro
+
+ %macro lcmdllextern 2
+ extern _%1@%2
+ %define %1 _%1@%2
+ %endmacro
+ %macro lcmdllextern 1
+ extern _%1
+ %define %1 _%1
+ %endmacro
+
+ %macro lcmwinextern 2
+ %ifdef _MSLIBS_
+ extern _%1@%2
+ %define %1 _%1@%2
+ %else
+ extern %1
+ %endif
+ %endmacro
+
+%endif ; _ELF_
+
+; --- define lcmimport and lcmexport ---
+;
+
+%ifdef _OBJ_
+
+ %macro lcmimport 2-3
+ import %1 %2 %3
+ %rotate 1
+ %endmacro
+
+ %ifdef _DLL_
+
+ %macro lcmexport 2
+ export _%1
+ export _%1@%2
+ %endmacro
+ %macro lcmexport 1
+ export _%1
+ %endmacro
+
+ %else
+
+ %macro lcmexport 1-2
+ %endmacro
+
+ %endif
+
+%else ; _OBJ_
+
+ %macro lcmimport 2-3
+ %endmacro
+
+ %macro lcmexport 1-2
+ %endmacro
+
+%endif ; _OBJ_
+
+; --- define lcmlabel, lcmadjust and lcmret macros ---
+;
+; we need special labels and stdcall calling convention when
+; assembling for a dll
+
+%ifdef _ELF_
+
+ %macro lcmlabel 2
+ %1:
+ %endmacro
+
+ %define lcmclabel lcmlabel
+
+ %macro lcmadjust 1
+ %if %1 < 128
+ add esp, byte %1
+ %else
+ add esp, %1
+ %endif
+ %endmacro
+
+ %macro lcmret 1
+ ret
+ %endmacro
+
+ %define lcmcret lcmret
+
+%else ; _ELF_
+
+ %ifdef _DLL_
+ %macro lcmlabel 2
+ _%1:
+ _%1@%2:
+ %endmacro
+
+ %macro lcmclabel 2
+ _%1:
+ %endmacro
+
+ %macro lcmadjust 1
+ %endmacro
+
+ %macro lcmret 1
+ %if %1 > 0
+ ret %1
+ %else
+ ret
+ %endif
+ %endmacro
+
+ %macro lcmcret 1
+ ret
+ %endmacro
+
+ %else
+
+ %macro lcmlabel 2
+ _%1:
+ %endmacro
+
+ %define lcmclabel lcmlabel
+
+ %macro lcmadjust 1
+ %if %1 < 128
+ add esp, byte %1
+ %else
+ add esp, %1
+ %endif
+ %endmacro
+
+ %macro lcmret 1
+ ret
+ %endmacro
+
+ %define lcmcret lcmret
+ %endif
+
+%endif ; _ELF_
+
+%endif ; NASMLCM_INC_INCLUDED
diff --git a/test/monniaux/uzlib/src/nasm/tinfzlib.nas b/test/monniaux/uzlib/src/nasm/tinfzlib.nas
new file mode 100644
index 00000000..1f9519eb
--- /dev/null
+++ b/test/monniaux/uzlib/src/nasm/tinfzlib.nas
@@ -0,0 +1,160 @@
+;;
+;; tinfzlib - tiny zlib uncompress
+;;
+;; Copyright (c) 2003 by Joergen Ibsen / Jibz
+;; All Rights Reserved
+;;
+;; http://www.ibsensoftware.com/
+;;
+;; This software is provided 'as-is', without any express
+;; or implied warranty. In no event will the authors be
+;; held liable for any damages arising from the use of
+;; this software.
+;;
+;; Permission is granted to anyone to use this software
+;; for any purpose, including commercial applications,
+;; and to alter it and redistribute it freely, subject to
+;; the following restrictions:
+;;
+;; 1. The origin of this software must not be
+;; misrepresented; you must not claim that you
+;; wrote the original software. If you use this
+;; software in a product, an acknowledgment in
+;; the product documentation would be appreciated
+;; but is not required.
+;;
+;; 2. Altered source versions must be plainly marked
+;; as such, and must not be misrepresented as
+;; being the original software.
+;;
+;; 3. This notice may not be removed or altered from
+;; any source distribution.
+;;
+
+TINF_OK equ 0
+TINF_DATA_ERROR equ (-3)
+
+cpu 386
+
+bits 32
+
+%include "nasmlcm.inc"
+
+section lcmtext
+
+lcmglobal tinf_zlib_uncompress,16
+
+lcmexport tinf_zlib_uncompress,16
+
+lcmextern tinf_uncompress,16
+lcmextern tinf_adler32,8
+
+; =============================================================
+
+lcmlabel tinf_zlib_uncompress,16
+ ; tinf_zlib_uncompress(void *dest,
+ ; unsigned int *destLen,
+ ; const void *source,
+ ; unsigned int sourceLen)
+
+ .slen$ equ 2*4 + 4 + 12
+ .src$ equ 2*4 + 4 + 8
+ .dlen$ equ 2*4 + 4 + 4
+ .dst$ equ 2*4 + 4
+
+ push esi
+ push ebx
+
+ mov esi, [esp + .src$] ; esi -> source
+
+ ; -- get header bytes --
+
+ movzx eax, word [esi] ; al = cmf, ah = flg,
+
+ ; -- check format --
+
+ ; check method is deflate
+ ; if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR;
+ mov cl, 0x0f
+ and cl, al
+ cmp cl, 8
+ jne short .return_error
+
+ ; check window size is valid
+ ; if ((cmf >> 4) > 7) return TINF_DATA_ERROR;
+ mov ch, al
+ shr ch, 4
+ cmp ch, cl ; cl = 8 from above
+ jae short .return_error
+
+ ; check there is no preset dictionary
+ ; if (flg & 0x20) return TINF_DATA_ERROR;
+ test ah, 0x20
+ jnz short .return_error
+
+ ; check checksum
+ ; if ((256*cmf + flg) % 31) return TINF_DATA_ERROR;
+ xchg al, ah
+ xor edx, edx
+ lea ebx, [edx + 31]
+ div ebx
+ test edx, edx
+ jnz short .return_error
+
+ ; -- get adler32 checksum --
+
+ mov ecx, [esp + .slen$] ; ecx = sourceLen
+ mov ebx, [esi + ecx - 4]
+
+ %ifdef BSWAP_OK
+ bswap ebx
+ %else ; BSWAP_OK
+ xchg bl, bh
+ rol ebx, 16
+ xchg bl, bh
+ %endif ; BSWAP_OK
+
+ ; -- inflate --
+
+ ; res = tinf_uncompress(dst, destLen, src + 2, sourceLen - 6);
+ lea eax, [ecx - 6]
+ push eax
+ lea eax, [esi + 2]
+ push eax
+ push dword [esp + 8 + .dlen$]
+ push dword [esp + 12 + .dst$]
+ call tinf_uncompress
+ add esp, byte 16
+
+ ; if (res != TINF_OK) return TINF_DATA_ERROR;
+ test eax, eax
+ jnz short .return_error
+
+ ; -- check adler32 checksum --
+
+ ; if (a32 != tinf_adler32(dst, *destLen)) return TINF_DATA_ERROR;
+ mov eax, [esp + .dlen$];
+ push dword [eax]
+ push dword [esp + 4 + .dst$]
+ call tinf_adler32
+ add esp, byte 8
+
+ sub eax, ebx
+ jz short .return_eax
+
+ .return_error:
+ mov eax, TINF_DATA_ERROR
+
+ .return_eax:
+ pop ebx
+ pop esi
+
+ lcmret 16
+
+; =============================================================
+
+%ifdef _OBJ_
+ section lcmdata
+%endif
+
+; =============================================================