wok-current view linld/stuff/src/MEMCPY32.ASM @ rev 24022
linld: basic iso9660 support
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Mar 14 19:55:20 2021 +0000 (2021-03-14) |
parents | 61df94a0fa43 |
children | 6b6d14c9f7e9 |
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %PAGESIZE 1000
6 %crefref
7 %noincl
8 %nomacs
10 include "common.inc"
12 ifdef NO386
13 p8086
14 else
15 p386
16 endif
18 group DGROUP _TEXT
19 assume cs:DGROUP,ds:DGROUP
21 macro lcr0 reg
22 mov cr0,reg
23 jmp short $+2 ;*Required*!
24 ;3+ NOPs also work fine (chkd on 386)
25 endm
27 segment _TEXT byte public use16 'CODE'
29 ;***************************************************************
30 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
31 ;***************************************************************
32 ;****** Uses: Flags
33 ;***************************************************************
34 global memcpy32:near
35 proc memcpy32 near
37 arg dstofs :dword, \
38 srcseg :word, \
39 srcofs :dword, \
40 sz :dword = PARAM_SIZE
42 ;****** Init ***************************************************
44 ifndef NO386
46 enter 0,0
47 ;cld
48 pushf
49 push ds es
50 pushad ; struct declared in VCPI.ASM
51 mov cl,4
52 movzx esi,[srcseg]
53 shl esi,cl
54 add esi,[srcofs]
55 mov [srcofs],esi ; for memcpy_vcpi
56 mov edi,[dstofs]
58 ifndef pm_only
59 mov eax,esi
60 shr eax,cl
61 mov edx,edi
62 shr edx,cl
63 mov ecx,esi
64 or ecx,edi
65 shr ecx,20 ; >1mb ?
66 jnz @@pmcopy
67 @@movlp:
68 mov ds,ax
69 mov es,dx
70 inc ax
71 inc dx
72 mov cl,0Fh
73 and si,cx
74 and di,cx
75 inc cx
76 sub [sz],ecx
77 jae @@movpara
78 add ecx,[sz]
79 @@movpara:
80 rep movsb
81 ja @@movlp
82 jmp @@done
83 endif
84 @@pmcopy:
85 else
87 push bp
88 mov bp,sp
89 ;cld
90 pushf
91 push ds es
92 push si
93 xor bx,bx
94 xor si,si
95 mov ax,[srcseg]
96 extrn N_LXLSH@4:near
97 call near ptr N_LXLSH@4
98 add [word srcofs],ax
99 adc [word srcofs+2],dx
100 @@2flat:
101 les ax,[dword si+srcofs] ; srcofs, dstofs
102 mov dx,es
103 mov cl,4
104 @@loop:
105 shr dx,1
106 rcr ax,1
107 loop @@loop
108 or bx,dx ; >=1mb flag
109 push ax ; srcseg, dstseg
110 xor si,-6
111 jnz @@2flat
112 pop dx ; dstseg
113 pop ax ; srcseg
114 cmp bx,si ; <1mb ?
115 jne @@pmcopy
116 push di
117 @@movlp:
118 mov ds,ax
119 mov es,dx
120 inc ax
121 inc dx
122 mov cl,0Fh
123 mov si,cx
124 mov di,cx
125 and si,[word srcofs]
126 and di,[word dstofs]
127 inc cx
128 sub [word sz],cx
129 ;jae @@movpara
130 sbb [word sz+2],bx
131 jae @@movpara
132 add cx,[word sz]
133 ;stc
134 @@movpara:
135 rep movsb
136 jae @@movlp
137 pop di
138 jmp @@done16
139 @@pmcopy:
140 p386
141 pushad ; struct declared in VCPI.ASM
142 mov esi,[srcofs]
143 mov edi,[dstofs]
145 endif
147 mov ecx,[sz]
148 jecxz @@done
150 ifdef VCPI
151 smsw ax
152 and al,1 ;MSW_PE
153 jz @@real_mode
154 ; Note: bp points to std stack frame now. bp will be passed to
155 ; pm routine. This allows params to be passed on stack
156 extrn vcpi_pm_copy_routine:near
157 call near vcpi_pm_copy_routine ; Call pm copy routine via vcpi pm
158 jmp @@done
159 endif
160 @@real_mode:
161 cli
162 oldGDTR = (pword srcseg) ; don't need src seg/ofs anymore
163 sgdt [oldGDTR]
165 ;****** Load gdtr **********************************************
166 lgdt [GDTR]
168 ;****** Go into pm *********************************************
169 mov eax,cr0
170 inc ax ;CR0_PE on
171 lcr0 eax
172 ;****** Move data **********************************************
173 push 0008h
174 pop ds ;base=0, lim = 4gb
175 push ds ;
176 pop es ;
177 cmp esi,edi
178 jae @@do_copy
179 add esi,ecx ;src<dst: we must do
180 add edi,ecx ; copy backwards to avoid
181 std ; overwrite bug
182 db 67h ;address width override for esi/edi
183 cmpsb ; dec esi/edi
184 @@do_copy:
185 ;db 66h ;operand width override for ecx
186 db 67h ;address width override for esi/edi
187 rep movsb
188 ;cld
190 ;****** Return to rm *******************************************
191 dec ax ;CR0_PE off
192 lcr0 eax
193 ;****** Return *************************************************
194 lgdt [oldGDTR]
195 @@done:
196 popad
197 p8086
198 @@done16:
199 ifdef NO386
200 pop si
201 endif
202 pop es ds
203 popf ; restore I & D
204 ifndef NO386
205 p386
206 leave
207 else
208 pop bp
209 endif
210 ret 14
212 ;****** Const data *********************************************
214 ifdef VCPI
215 extrn gdt_memcpy
216 else
217 org $-8 ;save 8 bytes
218 ;0000: unused
219 gdt_memcpy dd ?,?
220 ;0008: Data seg [0,FFFFFFFF]
221 ; lim_lo base_lo
222 dw 1111111111111111b, 0000000000000000b
223 db 00000000b,10010010b,10001111b,00000000b
224 ; base_med P S D A G ??l_hi base_hi
225 ; Pl E W D
226 endif
227 label GDTR pword
228 gdt_limit dw 0ffffh
229 global gdt_base_memcpy:word
230 gdt_base_memcpy dw offset gdt_memcpy,0
232 endp memcpy32
234 global movedend:near
235 movedend:
237 ends _TEXT
239 end
241 ;###### END OF FILE ############################################