source: xtideuniversalbios/trunk/Assembly_Library/Src/Util/Memory.asm@ 557

Last change on this file since 557 was 526, checked in by krille_n_@…, 12 years ago

Changes:

  • Update of the copyright notices to include the year 2013.
File size: 4.6 KB
RevLine 
[41]1; Project name : Assembly Library
2; Description : Functions for memory access.
3
[376]4;
[445]5; XTIDE Universal BIOS and Associated Tools
[526]6; Copyright (C) 2009-2010 by Tomi Tilli, 2011-2013 by XTIDE Universal BIOS Team.
[376]7;
8; This program is free software; you can redistribute it and/or modify
9; it under the terms of the GNU General Public License as published by
10; the Free Software Foundation; either version 2 of the License, or
11; (at your option) any later version.
[445]12;
[376]13; This program is distributed in the hope that it will be useful,
14; but WITHOUT ANY WARRANTY; without even the implied warranty of
15; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
[445]16; GNU General Public License for more details.
[376]17; Visit http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
[445]18;
[376]19
[41]20; Section containing code
21SECTION .text
22
23;--------------------------------------------------------------------
[46]24; OPTIMIZE_STRING_OPERATION
[41]25; Parameters
[46]26; %1: Repeat instruction
27; %2: String instruction without size (for example MOVS and not MOVSB or MOVSW)
28; CX: Number of BYTEs to operate
29; DS:SI: Ptr to source data
30; ES:DI: Ptr to destination
[41]31; Returns:
[46]32; SI, DI: Updated by number of bytes operated
33; Corrupts registers:
[41]34; Nothing
[46]35;--------------------------------------------------------------------
36%macro OPTIMIZE_STRING_OPERATION 2
37 push cx
38
39 shr cx, 1 ; Operate with WORDs for performance
[103]40 jz %%HandleRemainingByte
[46]41 %1 %2w
42%%HandleRemainingByte:
43 jnc SHORT %%OperationCompleted
44 %2b
45
46ALIGN JUMP_ALIGN
47%%OperationCompleted:
48 pop cx
49%endmacro
50
51
52;--------------------------------------------------------------------
53; Memory_CopyCXbytesFromDSSItoESDI
54; Parameters
55; CX: Number of bytes to copy
56; DS:SI: Ptr to source data
57; ES:DI: Ptr to destination buffer
58; Returns:
59; SI, DI: Updated by number of bytes copied
[41]60; Corrupts registers:
[46]61; Nothing
[41]62;--------------------------------------------------------------------
[131]63%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]64ALIGN JUMP_ALIGN
[46]65Memory_CopyCXbytesFromDSSItoESDI:
66 OPTIMIZE_STRING_OPERATION rep, movs
67 ret
[131]68%endif
[41]69
[46]70
[41]71;--------------------------------------------------------------------
[46]72; Memory_ZeroSSBPwithSizeInCX
[41]73; Parameters
[46]74; CX: Number of bytes to zero
[41]75; SS:BP: Ptr to buffer to zero
76; Returns:
77; Nothing
78; Corrupts registers:
79; Nothing
80;--------------------------------------------------------------------
[489]81%ifdef INCLUDE_MENU_LIBRARY
[41]82ALIGN JUMP_ALIGN
[46]83Memory_ZeroSSBPwithSizeInCX:
[50]84 push es
85 push di
[41]86 push ax
[105]87 call Registers_CopySSBPtoESDI
[46]88 call Memory_ZeroESDIwithSizeInCX
[41]89 pop ax
[50]90 pop di
91 pop es
[41]92 ret
[489]93%endif
[41]94
[526]95
[41]96;--------------------------------------------------------------------
[46]97; Memory_ZeroESDIwithSizeInCX
[41]98; Parameters
[46]99; CX: Number of bytes to zero
100; ES:DI: Ptr to destination buffer
[41]101; Returns:
[50]102; DI: Updated by number of BYTEs stored
[41]103; Corrupts registers:
104; AX
105;--------------------------------------------------------------------
106ALIGN JUMP_ALIGN
[46]107Memory_ZeroESDIwithSizeInCX:
[41]108 xor ax, ax
[46]109 ; Fall to Memory_StoreCXbytesFromAccumToESDI
[41]110
111;--------------------------------------------------------------------
[46]112; Memory_StoreCXbytesFromAccumToESDI
[41]113; Parameters
114; AX: Word to use to fill buffer
[46]115; CX: Number of BYTEs to store
116; ES:DI: Ptr to destination buffer
[41]117; Returns:
[50]118; DI: Updated by number of BYTEs stored
[41]119; Corrupts registers:
120; Nothing
121;--------------------------------------------------------------------
122ALIGN JUMP_ALIGN
[46]123Memory_StoreCXbytesFromAccumToESDI:
124 OPTIMIZE_STRING_OPERATION rep, stos
[41]125 ret
126
127
128;--------------------------------------------------------------------
129; Memory_ReserveCXbytesFromStackToDSSI
130; Parameters
131; CX: Number of bytes to reserve
132; Returns:
133; DS:SI: Ptr to reserved buffer
134; Corrupts registers:
135; AX
136;--------------------------------------------------------------------
[194]137%ifndef EXCLUDE_FROM_XTIDE_UNIVERSAL_BIOS
[41]138ALIGN JUMP_ALIGN
139Memory_ReserveCXbytesFromStackToDSSI:
140 pop ax
141 push ss
142 pop ds
143 sub sp, cx
144 mov si, sp
145 jmp ax
[194]146%endif
[440]147
148
149;--------------------------------------------------------------------
150; Memory_SumCXbytesFromESSItoAL
151; Parameters
152; CX: Number of bytes to sum (0=65536)
153; ES:SI: Ptr to buffer containing the bytes to sum
154; Returns:
155; AL: Sum of bytes
[445]156; ZF: Set if result is zero
157; Cleared if result is non-zero
[440]158; Corrupts registers:
159; CX
160;--------------------------------------------------------------------
[445]161%ifndef EXCLUDE_FROM_XTIDECFG
[440]162ALIGN JUMP_ALIGN
163Memory_SumCXbytesFromESSItoAL:
164 push si
[445]165 dec si
[440]166 xor al, al
167ALIGN JUMP_ALIGN
168.AddNextByteToAL:
[445]169 inc si
[440]170 add al, [es:si]
171 loop .AddNextByteToAL
172 pop si
173 ret
[445]174%endif
Note: See TracBrowser for help on using the repository browser.