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