wok view linld/stuff/src/_BEG.ASM @ rev 19571

linld: large image support with VCPI
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Dec 22 21:06:17 2016 +0100 (2016-12-22)
parents 31c5cbbd9380
children 38eb1fe036b4
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,_BSS
11 assume cs:DGROUP,ds:DGROUP
13 segment _TEXT byte public use16 'CODE'
15 org 100h
16 global _text_start:byte
17 label _text_start byte
19 ;***************************************************************
20 ; clear bss
21 ;***************************************************************
22 mov bx,offset _bss_start
23 clearbss:
24 mov [byte bx],0 ; clear bss + heap + sp
25 inc bx
26 jne clearbss
27 cld
29 ;***************************************************************
30 ; check CPU
31 ;***************************************************************
33 ; Check for oldies
34 mov bh, 0F0h
35 pushf
36 push bx ; < 286 : flags[12..15] are forced 1
37 popf ; = 286 : flags[12..15] are forced 0
38 pushf ; > 286 : only flags[15] is forced 0
39 pop dx
40 popf
41 add dh,bh ; NS=386+, NC=286
42 mov bx,offset msg_badcpu
43 ifndef NO386
44 js no_vcpi ;it is a 86/186/286, not a 386+
45 else
46 js endcpu
47 endif
48 ; Check for vm
49 smsw ax ;SMSW cannot be trapped! :-)
50 and al,1 ;MSW_PE
51 ; We're in vm
52 jz check_rm_paging
54 ;***************************************************************
55 ; checks for vcpi
56 ;***************************************************************
57 label check_vcpi near
58 push ds
59 ; Check whether it is safe to call 67h (we trust only known EMM managers)
60 push 0
61 pop ds
62 mov ds,[word 67h*4+2]
63 cmp [dword 10+4],'0XXX'
64 jne skip
65 mov eax,'XMME'
66 xor eax,[dword 10]
67 ; QMME also works (as told by <J.S.Peatfield@damtp.cambridge.ac.uk>)
68 shl eax,8
69 skip:
70 pop ds
71 jne no_vcpi
73 ; Check emm manager status and version
74 ;mov ah,40h ; get status
75 ;int 67h
76 ;test ah,ah
77 ;jnz no_vcpi
78 mov ah,46h ; get version
79 int 67h
80 test ah,ah
81 jnz no_vcpi
82 cmp al,40h ; version must be >= 4.0
83 jb no_vcpi
84 ; Check vcpi manager status
85 ;;mov ax,5A01h ; ALLOCATE RAW PAGES
86 ;;mov bx,4
87 ;;int 67h
88 ;;test ah,ah
89 ;;jnz no_vcpi
90 ;;push dx ;$ save handle
91 mov ax,0DE00h ; check for vcpi present
92 int 67h
93 test ah,ah
94 jnz no_vcpi
95 is386vcpi:
96 inc [_vcpi]
97 extrn prepare_vcpi:near
98 call prepare_vcpi
99 ; get_vcpi_interface() || die("VCPI: low 640k: need 1:1 mapping");
100 ;extrn _get_vcpi_interface:near
101 ;call _get_vcpi_interface
102 mov bx,offset msg_badmapping
103 jnz endcpu
104 no_vcpi:
105 ;;pop dx ;$ handle
106 ;;mov ax,4500h ; DEALLOCATE PAGES
107 ;;int 67h
108 extrn die:near
109 godie:
110 jmp near die
111 check_rm_paging:
112 ; It's a 386 in real mode, chk for paging (crazy but possible)
113 mov edx,cr0
114 shl edx,1 ;CR0_PG to CF
115 jc no_vcpi
116 endcpu:
118 ;***************************************************************
119 ; build argv & argc
120 ;***************************************************************
121 extrn _heap_top:word
122 mov di,[_heap_top]
123 ;xor ax,ax
124 ;push ax ; envp (already cleared)
125 ;mov [word di],ax ; argv[0] = 0 (idem)
126 mov si,80h
127 lodsb
128 cmp al,7Eh
129 jbe alok
130 mov al,7Eh
131 alok:
132 cbw
133 xchg ax,bx
134 mov [bx+si],bh ; set eos
135 argbuild:
136 mov bx,2 ; argc * 2
137 argeos:
138 mov dl,1 ; look for a start of string
139 mov [byte si-1],bh ; mark eos
140 mov ah,20h ; space will be eos
141 arglp:
142 lodsb
143 cmp al,0h
144 je argdone
145 cmp al,20h
146 jb argeos
147 cmp al,ah
148 je argeos
149 cmp al,27h
150 je isargstr
151 cmp al,22h
152 je isargstr
153 or dl,dl
154 je arglp ; not start of string
155 dec si
156 jmp newarg
157 isargstr:
158 mov ah,al ; expected eos
159 newarg:
160 mov [word bx+di],si ; argv[argc++] = si
161 inc bx
162 inc bx
163 dec dx
164 jmp arglp
165 argdone:
166 ;mov [word bx+di],0 ; argv[argc] = 0
167 lea ax,[bx+di+2]
168 mov [_heap_top],ax
169 push di ; argv
170 shr bx,1
171 push bx ; argc
172 ifndef filearg
173 mov bx,[di+2] ; argv[1]
174 cmp [byte bx],'@'
175 jne argend
176 inc bx
177 extrn open:near
178 call near open
179 jc argend
180 pop bx ; trash argc, argv >> 1Kb !
181 global read_cmdline:near
182 read_cmdline:
183 push di
184 push ax
185 extrn _read:near
186 call near _read
187 pop bx ; fd for close
188 pop si ; si=buffer=argv
189 add di,ax
190 pop ax ; trash sizemax=argv
191 extrn close:near
192 call near close
193 jmp argbuild
194 argend:
195 endif
197 ;***************************************************************
198 extrn _main:near
199 call _main
201 ;***************************************************************
202 global exit:near
203 exit:
204 mov ah,4Ch
205 int 21h
206 ends _TEXT
208 segment _DATA byte public use16 'DATA'
209 global _data_start:byte
210 label _data_start byte
211 msg_badcpu db "I need 386+ CPU in real mode or under VCPI manager"
212 global _vcpi:byte
213 _vcpi db 0
214 msg_badmapping db "VCPI: low 640k: need 1:1 mapping",0
216 ends _DATA
218 segment _BSS byte public use16 'BSS'
219 global _bss_start:byte
220 label _bss_start byte
221 ends _BSS
223 end _text_start
225 ;###### END OF FILE ############################################