wok view linld/stuff/src/MEMCPY32.ASM @ rev 19546

linld/tazboot: default conf in tazboot.cmd
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Dec 06 18:49:44 2016 +0100 (2016-12-06)
parents 7f92b23984dc
children e428345df29a
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 p386
10 group DGROUP _TEXT,_DATA
11 assume cs:DGROUP,ds:DGROUP
13 segment _DATA byte public use16 'DATA'
14 ends _DATA
16 segment _TEXT byte public use16 'CODE'
18 ;***************************************************************
19 ;void dos_shutdown()
20 ;***************************************************************
21 global dos_shutdown:near
22 proc dos_shutdown near
24 dos_shutdown:
25 ifndef NO386
26 ;pusha
27 else
28 ;push bp si di
29 endif
30 xor bx,bx
31 mov ds,bx
32 ifndef NO386
33 push [dword bx+4] ; save step
34 mov ax,sp
35 push ss
36 push ax
37 pop [dword cs:sssp]
38 else
39 push [word bx+6]
40 push [word bx+4] ; save step
41 mov [word cs:sssp],sp
42 mov [word cs:sssp+2],ss
43 endif
44 ;cmp [byte bx+7],0F0h
45 ;jnc notdos
46 mov [word bx+4],offset step19
47 mov [bx+6],cs
48 pushf
49 pop ax
50 inc ah ; set TF
51 push ax
52 popf
53 jmp small [dword bx+4*19h]
54 doiret:
55 iret
56 sssp:
57 dd 0
58 step19:
59 push bx
60 push ds
61 mov bx,sp
62 lds bx,[dword ss:bx+4] ; read cs:ip
63 cmp [word bx],19CDh ; int 19h ?
64 pop ds
65 pop bx
66 jne doiret
67 notdos:
68 ifndef NO386
69 lss sp,[dword cs:sssp]
70 else
71 lds bx,[dword cs:sssp]
72 push ds
73 pop ss
74 mov sp,bx
75 endif
76 xor bx,bx
77 mov ds,bx
78 ifndef NO386
79 pop [dword bx+4] ; restore step
80 ;popa
81 else
82 pop [word bx+4] ; restore step
83 pop [word bx+6]
84 ;pop di si bp
85 endif
86 push cs
87 pop ds
88 ret
90 endp dos_shutdown
93 ;***************************************************************
94 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
95 ;***************************************************************
96 ;****** Uses: Flags
97 ;***************************************************************
98 global _memcpy32:near
99 proc _memcpy32 near
101 ; rm32,imm16 helper
102 macro addzx_e rm,i
103 db 66h
104 add rm,i
105 dw 0
106 endm
107 arg dstofs :dword, \
108 srcseg :word, \
109 srcofs :dword, \
110 sz :dword = PARAM_SIZE
112 local GDTR :pword, \
113 oldGDTR :pword = TEMP_SIZE
115 ;****** Init ***************************************************
116 push bp
117 mov bp,sp
118 sub sp,TEMP_SIZE
119 pushf
120 cld
121 push ds es
123 ifndef NO386
125 pushad
126 movzx esi,[srcseg]
127 shl esi,4
128 add [srcofs],esi
129 mov esi,[srcofs]
130 mov edi,[dstofs]
132 ifndef pm_only
133 mov eax,esi
134 or eax,edi
135 shr eax,20 ; >1mb ?
136 jnz pmcopy
137 mov eax,esi
138 shr eax,4
139 mov edx,edi
140 shr edx,4
141 @@movlp:
142 mov ds,ax
143 mov es,dx
144 inc ax
145 inc dx
146 xor ecx,ecx
147 mov cl,0Fh
148 and si,cx
149 and di,cx
150 inc cx
151 sub [sz],ecx
152 rep movsb
153 ja @@movlp
154 jmp done
155 endif
156 pmcopy:
157 else
159 push si
160 xor bx,bx
161 xor dx,dx
162 xor si,si
163 mov ax,[bp+si+8] ; srcseg
164 call near N_LXLSH@4
165 add [bp+si+10],ax ; srcofs lo
166 adc [bp+si+10+2],dx ; srcofs hi
167 @@2flat:
168 mov ax,[bp+si+10] ; srcofs, dstofs lo
169 mov dx,[bp+si+10+2] ; srcofs, dstofs hi
170 call near N_LXURSH@4
171 or bx,dx ; >=1mb flag
172 push ax ; srcseg, dstseg
173 xor si,-6
174 jnz @@2flat
175 pop dx ; dstseg
176 pop ax ; srcseg
177 or bx,bx ; <1mb ?
178 jnz pmcopy
179 push di
180 @@movlp:
181 mov ds,ax
182 mov es,dx
183 inc ax
184 inc dx
185 mov cl,0Fh
186 mov si,cx
187 mov di,cx
188 and si,[word srcofs]
189 and di,[word dstofs]
190 inc cx
191 sub [word sz],cx
192 rep movsb
193 jae @@movlp
194 dec [word sz+2]
195 jns @@movlp ; mov 1-16 more bytes...
196 pop di si
197 jmp done16
198 pmcopy:
199 pop si
200 pushad
201 mov esi,[srcofs]
202 mov edi,[dstofs]
204 endif
206 mov ecx,[sz]
207 jecxz done
209 smsw ax
210 test al,1
211 jz @@real_mode
212 ; Note: bp points to std stack frame now. bp will be passed to
213 ; pm routine. This allows params to be passed on stack
214 extrn do_memcpy_vcpi:near
215 push offset do_memcpy_vcpi
216 extrn call_pm_routine:near
217 call near call_pm_routine ; Call pm copy routine via vcpi pm
218 pop ax
219 jmp done
220 @@real_mode:
221 mov dx,-1
223 with_movsw:
224 cmp esi,edi
225 jae @@do_copy
226 add esi,ecx ;src<dst: we must do
227 dec esi ; copy backwards to avoid
228 add edi,ecx ; overwrite bug
229 dec edi ;
230 std ;
231 @@do_copy:
232 cli
233 sgdt [oldGDTR]
235 ;****** Load gdtr **********************************************
236 mov eax,cs
237 shl eax,4
238 addzx_e ax,<offset GDT>
239 mov [word GDTR],dx ;GDT limit = 0FFFFh
240 mov [dword GDTR+2],eax ;GDT base
241 lgdt [GDTR]
243 ;****** Go into pm *********************************************
244 mov eax,cr0
245 or al,01h ;CR0_PE on
246 mov cr0,eax
247 jmp short $+2 ;*Required*!
248 ;3+ NOPs also work fine (chkd on 386)
249 ;****** Move data **********************************************
250 push 0008h
251 pop ds ;base=0, lim = 4gb
252 push ds ;
253 pop es ;
254 db 66h ;operand width override for ecx
255 db 67h ;address width override for esi/edi
256 rep movsb
258 ;****** Return to rm *******************************************
259 dec ax ;CR0_PE off
260 mov cr0,eax ;ds/es limits are *not* reset to 64kb
261 ; but who cares :-)
262 jmp short $+2
264 ;****** Return *************************************************
265 lgdt [oldGDTR]
266 done:
267 popad
268 done16:
269 pop es ds
270 popf
271 mov sp,bp
272 pop bp
273 ret
275 ;****** Const data *********************************************
276 org $-8 ;save 8 bytes - they are unused anyway
277 ;0000: unused
278 GDT dd ?,?
279 ;0008: Data seg [0,FFFFFFFF]
280 ; lim_lo base_lo
281 dw 1111111111111111b, 0000000000000000b
282 db 00000000b,10010010b,10001111b,00000000b
283 ; base_med P S D A G ??l_hi base_hi
284 ; Pl E W D
286 endp _memcpy32
288 ifdef NO386
289 global N_LXURSH@:near
290 global N_LXURSH@4:near
291 proc N_LXURSH@4 near
293 mov cl,4
294 N_LXURSH@:
295 mov ch,0
296 @@loop:
297 shr dx,1
298 rcr ax,1
299 loop @@loop
300 ret
302 endp N_LXURSH@4
304 global N_LXLSH@:near
305 global N_LXLSH@4:near
306 proc N_LXLSH@4 near
308 mov cl,4
309 N_LXLSH@:
310 mov ch,0
311 @@loop:
312 shl ax,1
313 rcl dx,1
314 loop @@loop
315 ret
317 endp N_LXLSH@4
319 endif
321 ends _TEXT
323 end
325 ;###### END OF FILE ############################################