rev |
line source |
pascal@19515
|
1 ;***************************************************************
|
pascal@19515
|
2 ;****** This file is distributed under GPL
|
pascal@19515
|
3 ;***************************************************************
|
pascal@19515
|
4 ideal
|
pascal@19515
|
5 %crefref
|
pascal@19515
|
6 %noincl
|
pascal@19515
|
7 %nomacs
|
pascal@19636
|
8 ifdef NO386
|
pascal@19636
|
9 p8086
|
pascal@19636
|
10 else
|
pascal@19515
|
11 p386
|
pascal@19636
|
12 endif
|
pascal@19515
|
13
|
pascal@19903
|
14 group DGROUP _TEXT,_DATA,_BSS
|
pascal@19515
|
15 assume cs:DGROUP,ds:DGROUP
|
pascal@19515
|
16
|
pascal@19903
|
17 segment _DATA byte public use16 'DATA'
|
pascal@19903
|
18
|
pascal@19903
|
19 overflow db "Loaded too close to 9000:0",0
|
pascal@19903
|
20
|
pascal@19903
|
21 ends _DATA
|
pascal@19903
|
22
|
pascal@19515
|
23 segment _BSS byte public use16 'BSS'
|
pascal@19515
|
24
|
pascal@19899
|
25 global _imgs:dword
|
pascal@19515
|
26
|
pascal@19515
|
27 ends _BSS
|
pascal@19515
|
28
|
pascal@19515
|
29
|
pascal@19515
|
30 segment _TEXT byte public use16 'CODE'
|
pascal@19515
|
31
|
pascal@19905
|
32 ;***************************************************************
|
pascal@20473
|
33 ;void dos_shutdown()
|
pascal@20473
|
34 ;***************************************************************
|
pascal@20473
|
35
|
pascal@20473
|
36 macro dos_shutdown
|
pascal@20481
|
37 xor di,di
|
pascal@20481
|
38 mov ds,di
|
pascal@20473
|
39 ifndef NO386
|
pascal@20481
|
40 push [dword di+4] ; save step
|
pascal@20481
|
41 mov [word di+4],offset step19
|
pascal@20473
|
42 else
|
pascal@20473
|
43 mov ax,offset step19
|
pascal@20481
|
44 xchg ax,[word di+4]
|
pascal@20481
|
45 push [word di+6]
|
pascal@20473
|
46 push ax ; save step
|
pascal@20473
|
47 endif
|
pascal@20473
|
48 mov [word cs:sssp],sp
|
pascal@20481
|
49 ;cmp [byte di+7],0F0h
|
pascal@20473
|
50 ;jnc notdos
|
pascal@20481
|
51 mov [di+6],cs
|
pascal@20473
|
52 pushf
|
pascal@20473
|
53 pushf
|
pascal@20473
|
54 pop ax
|
pascal@20473
|
55 inc ah ; set TF
|
pascal@20473
|
56 push ax
|
pascal@20473
|
57 popf
|
pascal@20481
|
58 call [dword di+4*19h]
|
pascal@20473
|
59 notdos:
|
pascal@20473
|
60 ifndef NO386
|
pascal@20473
|
61 lss sp,[dword cs:sssp]
|
pascal@20473
|
62 else
|
pascal@20473
|
63 lds ax,[dword cs:sssp]
|
pascal@20473
|
64 push ds
|
pascal@20473
|
65 pop ss
|
pascal@20473
|
66 xchg ax,sp
|
pascal@20473
|
67 endif
|
pascal@20481
|
68 xor di,di
|
pascal@20481
|
69 mov ds,di
|
pascal@20473
|
70 ifndef NO386
|
pascal@20481
|
71 pop [dword di+4] ; restore step
|
pascal@20473
|
72 else
|
pascal@20481
|
73 pop [word di+4] ; restore step
|
pascal@20481
|
74 pop [word di+6]
|
pascal@20473
|
75 endif
|
pascal@20473
|
76 endm
|
pascal@20473
|
77 macro step19code
|
pascal@20473
|
78 step19:
|
pascal@20481
|
79 push di
|
pascal@20473
|
80 push ds
|
pascal@20481
|
81 mov di,sp
|
pascal@20481
|
82 lds di,[dword ss:di+4] ; read cs:ip
|
pascal@20481
|
83 cmp [word di],19CDh ; int 19h ?
|
pascal@20473
|
84 pop ds
|
pascal@20481
|
85 pop di
|
pascal@20473
|
86 je notdos
|
pascal@20473
|
87 iret
|
pascal@20473
|
88 endm
|
pascal@20473
|
89
|
pascal@20473
|
90
|
pascal@20473
|
91 ;***************************************************************
|
pascal@19905
|
92 ;void boot_kernel();
|
pascal@19905
|
93 ;****** Never returns
|
pascal@19905
|
94 ;***************************************************************
|
pascal@19903
|
95 global _boot_kernel:near
|
pascal@19905
|
96 proc _boot_kernel near
|
pascal@19905
|
97
|
pascal@20142
|
98 p8086
|
pascal@19903
|
99 extrn _heap_top:word
|
pascal@20475
|
100 global sssp
|
pascal@19903
|
101 ifdef NO386
|
pascal@20475
|
102 sssp:
|
pascal@19903
|
103 extrn _topseg:near
|
pascal@19903
|
104 call near _topseg
|
pascal@20475
|
105 mov [word sssp+2],ax
|
pascal@19903
|
106 xchg ax,bx
|
pascal@20473
|
107 mov ax,[_heap_top]
|
pascal@19903
|
108 mov cl,4
|
pascal@19903
|
109 shr ax,cl
|
pascal@19903
|
110 else
|
pascal@20142
|
111 p386
|
pascal@20473
|
112 mov ax,[_heap_top]
|
pascal@20475
|
113 ;shr ax,4
|
pascal@20475
|
114 db 0C1h,0E8h
|
pascal@20475
|
115 sssp:
|
pascal@20475
|
116 db 4
|
pascal@20475
|
117 mov bx,9000h
|
pascal@19903
|
118 endif
|
pascal@20473
|
119 mov es,bx
|
pascal@19903
|
120 mov dx,cs
|
pascal@19903
|
121 add ax,dx
|
pascal@19903
|
122 cmp ax,bx
|
pascal@19905
|
123 jb @@nooverflow
|
pascal@19903
|
124 ; Oops! We can stomp on our toes... better stop now
|
pascal@19903
|
125 mov bx,offset overflow
|
pascal@19903
|
126 extrn die:near
|
pascal@20427
|
127 call near die
|
pascal@19905
|
128 @@nooverflow:
|
pascal@20473
|
129 ;cli ; we start doing destructive things to DOS
|
pascal@19571
|
130 push es
|
pascal@19571
|
131 pop ss
|
pascal@19571
|
132 mov sp,0A000h
|
pascal@19900
|
133 extrn _csip:dword
|
pascal@19900
|
134 push [dword _csip]
|
pascal@19636
|
135 extrn _rm_size:word
|
pascal@19636
|
136 mov si,offset _rm_size ; _rm_size, _pm_high, _rm_buf
|
pascal@19636
|
137 lodsw
|
pascal@19636
|
138 xchg ax,cx ; _rm_size
|
pascal@19636
|
139 lodsb ; _pm_high
|
pascal@19636
|
140 mov si,[si] ; _rm_buf
|
pascal@19571
|
141 xor di,di
|
pascal@19571
|
142 ;cld
|
pascal@19571
|
143 rep
|
pascal@19571
|
144 movsb
|
pascal@19571
|
145 extrn _cmdline:word
|
pascal@19571
|
146 mov si,[_cmdline]
|
pascal@19571
|
147 mov di,8000h
|
pascal@19571
|
148 mov ch,10h ; 4k
|
pascal@19571
|
149 rep
|
pascal@19571
|
150 movsb
|
pascal@20481
|
151 ifdef NO386
|
pascal@20481
|
152 add bh,9
|
pascal@20481
|
153 endif
|
pascal@19636
|
154 cmp al,cl ; load high ?
|
pascal@20473
|
155 ifdef noelks
|
pascal@19905
|
156 jne @@isbzimage
|
pascal@20473
|
157 else
|
pascal@20473
|
158 jne @@isbzimagez
|
pascal@20473
|
159 endif
|
pascal@19637
|
160 ifdef NO386
|
pascal@19637
|
161 push bx ; topseg()+0x0900
|
pascal@19637
|
162 else
|
pascal@19905
|
163 push 9800h+(4096/16) ; 4096 bytes for cmdline
|
pascal@19637
|
164 endif
|
pascal@19515
|
165 ; finish loading
|
pascal@19515
|
166 extrn @last_ditch$qv:near
|
pascal@19515
|
167 push cs
|
pascal@19515
|
168 call @last_ditch$qv
|
pascal@19515
|
169 ; self move
|
pascal@19571
|
170 ;cld
|
pascal@19538
|
171 pop es ; min 2048 bytes for stack
|
pascal@20481
|
172 mov cx,offset movedend
|
pascal@19538
|
173 xor si,si ; A000 -9000 -0800(>movedend)
|
pascal@19515
|
174 xor di,di ; set ZF
|
pascal@19515
|
175 rep
|
pascal@19515
|
176 movsb
|
pascal@20477
|
177 mov ax,[word _imgs+2+2] ; get pm->fallback high word
|
pascal@20477
|
178
|
pascal@20477
|
179 ; prepare memcpy32 size & srcofs param to move zImage pm
|
pascal@20477
|
180 mov dx,8
|
pascal@20477
|
181 cmp ax,dx ; buf > 80000h ?
|
pascal@20477
|
182 ja @@bufhigh
|
pascal@20477
|
183 sub dx,ax
|
pascal@20477
|
184 inc dx ; up to 90000h-1
|
pascal@20477
|
185 @@bufhigh:
|
pascal@20477
|
186 push dx ; size hi
|
pascal@20477
|
187 push cx ; size lo=up to 512k
|
pascal@20477
|
188 push ax ; src ofs ho = pm.fallback
|
pascal@20477
|
189
|
pascal@19515
|
190 push es
|
pascal@20481
|
191 dos_shutdown ; clear di
|
pascal@20475
|
192 call near @@isbzimage ; pop cs ; ds=es=ss
|
pascal@19538
|
193 ;in al,70h
|
pascal@19538
|
194 ;or al,80h ; disable NMI
|
pascal@19538
|
195 ;out 70h,al
|
pascal@20477
|
196
|
pascal@20481
|
197 push di ; src ofs lo
|
pascal@20481
|
198 push di ; src seg=0
|
pascal@19636
|
199 ifdef NO386
|
pascal@20481
|
200 inc di
|
pascal@20481
|
201 push di ; dst ofs hi
|
pascal@20481
|
202 dec di
|
pascal@19636
|
203 else
|
pascal@20477
|
204 push 1 ; dst ofs hi
|
pascal@19636
|
205 endif
|
pascal@20481
|
206 push di ; dst ofs lo : 64k
|
pascal@19515
|
207 extrn _memcpy32:near
|
pascal@19515
|
208 call _memcpy32
|
pascal@19538
|
209 add sp,14
|
pascal@19515
|
210
|
pascal@19515
|
211 ifndef noelks
|
pascal@19515
|
212 ifndef NO386
|
pascal@19515
|
213 cmp [dword 1E6h],'SKLE'
|
pascal@20473
|
214 jne @@notelks
|
pascal@20481
|
215 xor si,si
|
pascal@19515
|
216 else
|
pascal@20481
|
217 mov si,1E6h
|
pascal@20481
|
218 lodsw
|
pascal@20481
|
219 cmp ax,'LE'
|
pascal@19905
|
220 jne @@notelks
|
pascal@20481
|
221 lodsw
|
pascal@20481
|
222 xor ax,'SK'
|
pascal@20473
|
223 jne @@notelks
|
pascal@20481
|
224 xchg ax,si
|
pascal@19515
|
225 endif
|
pascal@20481
|
226 push es
|
pascal@20481
|
227 pop ss
|
pascal@20481
|
228 mov cx,120h ; CS=0120
|
pascal@20481
|
229 push cx
|
pascal@20481
|
230 push si ; IP=0000
|
pascal@20481
|
231 mov cl,0 ; DS=ES=SS=0100
|
pascal@20475
|
232 mov es,cx
|
pascal@20475
|
233 mov ch,05h ; 500h mini
|
pascal@19515
|
234 rep
|
pascal@20481
|
235 @@isbzimagez:
|
pascal@19515
|
236 movsw
|
pascal@19905
|
237 @@notelks:
|
pascal@19515
|
238 endif
|
pascal@19905
|
239 @@isbzimage:
|
pascal@19515
|
240 push ss
|
pascal@19515
|
241 pop ds
|
pascal@20475
|
242 push ss
|
pascal@20475
|
243 pop es
|
pascal@19636
|
244 ifndef NO386
|
pascal@19515
|
245 push ss
|
pascal@19515
|
246 pop fs
|
pascal@19515
|
247 push ss
|
pascal@19515
|
248 pop gs
|
pascal@19636
|
249 endif
|
pascal@19515
|
250 assume nothing
|
pascal@19515
|
251 assume cs:DGROUP
|
pascal@19515
|
252 retf
|
pascal@19515
|
253
|
pascal@20473
|
254 step19code
|
pascal@20477
|
255
|
pascal@20477
|
256 endp _boot_kernel
|
pascal@20477
|
257
|
pascal@19515
|
258 movedend:
|
pascal@19515
|
259
|
pascal@19515
|
260 ends _TEXT
|
pascal@19515
|
261
|
pascal@19515
|
262 end
|
pascal@19515
|
263
|
pascal@19515
|
264 ;###### END OF FILE ############################################
|