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

Fix loram dos boot
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Aug 01 15:16:29 2019 +0200 (2019-08-01)
parents af959ebf1305
children 6e3d30b3031f
line source
1 ;***************************************************************
2 ;****** This file is distributed under GPL
3 ;***************************************************************
4 ideal
5 %crefref
6 %noincl
7 %nomacs
8 ifdef NO386
9 p8086
10 else
11 p386
12 endif
14 group DGROUP _TEXT
15 assume cs:DGROUP,ds:DGROUP
17 segment _TEXT byte public use16 'CODE'
19 ;***************************************************************
20 ;void memcpy32(u32 dstofs,u16 srcseg,u32 srcofs,u32 size);
21 ;***************************************************************
22 ;****** Uses: Flags
23 ;***************************************************************
24 global memcpy32:near
25 proc memcpy32 near
27 ; rm32,imm16 helper
28 macro addzx_e rm,i
29 db 66h
30 add rm,i
31 dw 0
32 endm
33 arg dstofs :dword, \
34 srcseg :word, \
35 srcofs :dword, \
36 sz :dword = PARAM_SIZE
38 local GDTR :pword, \
39 oldGDTR :pword = TEMP_SIZE
41 ;****** Init ***************************************************
43 ifndef NO386
45 enter TEMP_SIZE,0
46 ;cld
47 pushf
48 push ds es
49 pushad ; struct declared in VCPI.ASM
50 mov cl,4
51 movzx esi,[srcseg]
52 shl esi,cl
53 add esi,[srcofs]
54 mov [srcofs],esi ; for memcpy_vcpi
55 mov edi,[dstofs]
57 ifndef pm_only
58 mov eax,esi
59 shr eax,cl
60 mov edx,edi
61 shr edx,cl
62 mov ecx,esi
63 or ecx,edi
64 shr ecx,20 ; >1mb ?
65 jnz @@pmcopy
66 @@movlp:
67 mov ds,ax
68 mov es,dx
69 inc ax
70 inc dx
71 mov cl,0Fh
72 and si,cx
73 and di,cx
74 inc cx
75 sub [sz],ecx
76 jae @@movpara
77 add ecx,[sz]
78 @@movpara:
79 rep movsb
80 ja @@movlp
81 jmp @@done
82 endif
83 @@pmcopy:
84 else
86 push bp
87 mov bp,sp
88 sub sp,TEMP_SIZE
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 dec bx ; <1mb ?
115 jns @@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],0
131 jae @@movpara
132 add cx,[word sz]
133 ;stc
134 @@movpara:
135 rep movsb
136 jae @@movlp
137 dec cx ; set S
138 pop di
139 @@pmcopy:
140 pop si
141 js @@done16
142 p386
143 pushad ; struct declared in VCPI.ASM
144 mov esi,[srcofs]
145 mov edi,[dstofs]
147 endif
149 mov ecx,[sz]
150 jecxz @@done
152 smsw ax
153 and al,1 ;MSW_PE
154 jz @@real_mode
155 ; Note: bp points to std stack frame now. bp will be passed to
156 ; pm routine. This allows params to be passed on stack
157 extrn vcpi_pm_copy_routine:near
158 call near vcpi_pm_copy_routine ; Call pm copy routine via vcpi pm
159 jmp @@done
160 @@real_mode:
161 cmp esi,edi
162 jae @@do_copy
163 add esi,ecx ;src<dst: we must do
164 dec esi ; copy backwards to avoid
165 add edi,ecx ; overwrite bug
166 dec edi ;
167 std ;
168 @@do_copy:
169 cli
170 sgdt [oldGDTR]
172 ;****** Load gdtr **********************************************
173 mov eax,cs
174 shl eax,4
175 addzx_e ax,<offset GDT>
176 or [word GDTR],-1 ;GDT limit = 0FFFFh
177 mov [dword GDTR+2],eax ;GDT base
178 lgdt [GDTR]
180 ;****** Go into pm *********************************************
181 mov eax,cr0
182 inc ax ;CR0_PE on
183 mov cr0,eax
184 jmp short $+2 ;*Required*!
185 ;3+ NOPs also work fine (chkd on 386)
186 ;****** Move data **********************************************
187 push 0008h
188 pop ds ;base=0, lim = 4gb
189 push ds ;
190 pop es ;
191 ;db 66h ;operand width override for ecx
192 db 67h ;address width override for esi/edi
193 rep movsb
194 ;cld
196 ;****** Return to rm *******************************************
197 dec ax ;CR0_PE off
198 mov cr0,eax ;ds/es limits are *not* reset to 64kb
199 ; but who cares :-)
200 jmp short $+2
202 ;****** Return *************************************************
203 lgdt [oldGDTR]
204 @@done:
205 popad
206 p8086
207 @@done16:
208 pop es ds
209 popf ; restore I & D
210 ifndef NO386
211 p386
212 leave
213 else
214 mov sp,bp
215 pop bp
216 endif
217 ret 14
219 ;****** Const data *********************************************
220 org $-8 ;save 8 bytes - they are unused anyway
221 ;0000: unused
222 GDT dd ?,?
223 ;0008: Data seg [0,FFFFFFFF]
224 ; lim_lo base_lo
225 dw 1111111111111111b, 0000000000000000b
226 db 00000000b,10010010b,10001111b,00000000b
227 ; base_med P S D A G ??l_hi base_hi
228 ; Pl E W D
230 endp memcpy32
232 ends _TEXT
234 end
236 ;###### END OF FILE ############################################