Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
129 | mikedld | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; |
||
3 | ;; Shutdown for Menuet |
||
4 | ;; |
||
5 | ;; Distributed under General Public License |
||
6 | ;; See file COPYING for details. |
||
7 | ;; Copyright 2003 Ville Turjanmaa |
||
8 | ;; |
||
9 | |||
10 | |||
11 | system_shutdown: ; shut down the system |
||
12 | |||
13 | push 3 ; stop playing cd |
||
14 | pop eax |
||
15 | call sys_cd_audio |
||
16 | cld |
||
17 | |||
18 | mov al,[0x2f0000+0x9030] |
||
19 | cmp al,1 |
||
20 | jl no_shutdown_parameter |
||
21 | cmp al,4 |
||
22 | jle yes_shutdown_param |
||
23 | no_shutdown_parameter: |
||
24 | |||
25 | ; movzx ecx,word [0x2f0000+0x900A] |
||
26 | ; movzx esi,word [0x2f0000+0x900C] |
||
27 | ; imul ecx,esi ;[0xfe04] |
||
28 | ;; mov ecx,0x500000/4 ;3fff00/4 ; darken screen |
||
29 | ; push ecx |
||
30 | ; mov esi,[0xfe80] |
||
31 | ; cmp esi,32*0x100000 |
||
32 | ; jbe no_darken_screen |
||
33 | ; mov edi,16*0x100000 |
||
34 | ; push esi edi |
||
35 | ; sdnewpix: |
||
36 | ; lodsd |
||
37 | ; shr eax,1 |
||
38 | ; and eax,0x7f7f7f7f |
||
39 | ; stosd |
||
40 | ; loop sdnewpix |
||
41 | ; pop ecx |
||
42 | ; pop esi edi |
||
43 | ; rep movsd |
||
44 | ; no_darken_screen: |
||
45 | |||
46 | ; read shutdown code: |
||
47 | ; 1) display shutdown "window" |
||
48 | |||
49 | mov eax,[0xfe00] |
||
50 | shr eax,1 |
||
51 | lea esi,[eax+220] ; x end |
||
52 | sub eax,220 ; x start |
||
53 | |||
54 | mov ebx,[0xfe04] |
||
55 | shr ebx,1 |
||
56 | mov [shutdownpos],ebx |
||
57 | lea ebp,[ebx+105] ; y end |
||
58 | sub ebx,120 ; y start |
||
59 | |||
60 | xor edi,edi |
||
61 | inc edi ; force putpixel & dtext |
||
62 | mov ecx,0x0000ff |
||
63 | |||
64 | ; vertical loop begin |
||
65 | sdnewpix1: |
||
66 | push eax ; save x start |
||
67 | |||
68 | ; horizontal loop begin |
||
69 | sdnewpix2: |
||
70 | |||
71 | call [putpixel] |
||
72 | |||
73 | inc eax |
||
74 | cmp eax,esi |
||
75 | jnz sdnewpix2 |
||
76 | ; horizontal loop end |
||
77 | |||
78 | dec ecx ; color |
||
79 | pop eax ; restore x start |
||
80 | |||
81 | inc ebx ; advance y pos |
||
82 | cmp ebx,ebp |
||
83 | jnz sdnewpix1 |
||
84 | ; vertical loop end |
||
85 | |||
86 | ; 2) display text strings |
||
87 | ; a) version |
||
88 | mov eax,[0xfe00] |
||
89 | shr eax,1 |
||
90 | shl eax,16 |
||
91 | mov ax,word [shutdownpos] |
||
92 | push eax |
||
93 | sub eax,(220-27)*10000h + 105 |
||
94 | mov ebx,0xffff00 |
||
95 | mov ecx,version |
||
96 | push 34 |
||
97 | pop edx |
||
98 | call dtext |
||
99 | |||
100 | ; b) variants |
||
101 | add eax,105+33 |
||
102 | push 6 |
||
103 | pop esi |
||
104 | ; mov ebx,0xffffff |
||
105 | mov bl,0xFF |
||
106 | mov ecx,shutdowntext |
||
107 | mov dl,40 |
||
108 | newsdt: |
||
109 | call dtext |
||
110 | add eax,10 |
||
111 | add ecx,edx |
||
112 | dec esi |
||
113 | jnz newsdt |
||
114 | |||
115 | ; 3) load & display rose.txt |
||
116 | mov eax,rosef ; load rose.txt |
||
117 | xor ebx,ebx |
||
118 | push 2 |
||
119 | pop ecx |
||
120 | mov edx,0x90000 |
||
121 | push edx |
||
122 | push 12 |
||
123 | pop esi |
||
124 | push edi ; may be destroyed |
||
125 | call fileread |
||
126 | pop edi |
||
127 | |||
128 | pop ecx |
||
129 | inc ecx ; do not display stars from rose.txt |
||
130 | pop eax |
||
131 | add eax,20*10000h - 110 |
||
132 | |||
133 | mov ebx,0x00ff00 |
||
134 | push 27 |
||
135 | pop edx |
||
136 | |||
137 | nrl: |
||
138 | call dtext |
||
139 | sub ebx,0x050000 |
||
140 | add eax,8 |
||
141 | add ecx,31 |
||
142 | cmp cx,word 0x0001+25*31 |
||
143 | jnz nrl |
||
144 | |||
145 | call checkVga_N13 |
||
146 | |||
147 | yes_shutdown_param: |
||
148 | cli |
||
149 | |||
150 | mov eax,kernel ; load kernel.mnt to 0x8000:0 |
||
151 | push 12 |
||
152 | pop esi |
||
153 | xor ebx,ebx |
||
154 | or ecx,-1 |
||
155 | mov edx,0x80000 |
||
156 | call fileread |
||
157 | |||
158 | mov esi,restart_kernel_4000+0x10000 ; move kernel re-starter to 0x4000:0 |
||
159 | mov edi,0x40000 |
||
160 | mov ecx,1000 |
||
161 | rep movsb |
||
162 | |||
163 | mov eax,0x2F0000 ; restore 0x0 - 0xffff |
||
164 | xor ebx,ebx |
||
165 | mov ecx,0x10000 |
||
166 | call memmove |
||
167 | |||
168 | call restorefatchain |
||
169 | |||
170 | mov word [0x467+0],pr_mode_exit-0x10000 |
||
171 | mov word [0x467+2],0x1000 |
||
172 | |||
173 | mov al,0x0F |
||
174 | out 0x70,al |
||
175 | mov al,0x05 |
||
176 | out 0x71,al |
||
177 | |||
178 | mov al,0xFE |
||
179 | out 0x64,al |
||
180 | hlt |
||
181 | |||
182 | use16 |
||
183 | |||
184 | pr_mode_exit: |
||
185 | org $-0x10000 |
||
186 | |||
187 | ; setup stack |
||
188 | mov ax, 3000h |
||
189 | mov ss, ax |
||
190 | mov esp, 0EC00h |
||
191 | ; setup ds |
||
192 | push cs |
||
193 | pop ds |
||
194 | |||
195 | lidt [old_ints_h-0x10000] |
||
196 | ;remap IRQs |
||
197 | mov al,0x11 |
||
198 | out 0x20,al |
||
199 | call rdelay |
||
200 | out 0xA0,al |
||
201 | call rdelay |
||
202 | |||
203 | mov al,0x08 |
||
204 | out 0x21,al |
||
205 | call rdelay |
||
206 | mov al,0x70 |
||
207 | out 0xA1,al |
||
208 | call rdelay |
||
209 | |||
210 | mov al,0x04 |
||
211 | out 0x21,al |
||
212 | call rdelay |
||
213 | mov al,0x02 |
||
214 | out 0xA1,al |
||
215 | call rdelay |
||
216 | |||
217 | mov al,0x01 |
||
218 | out 0x21,al |
||
219 | call rdelay |
||
220 | out 0xA1,al |
||
221 | call rdelay |
||
222 | |||
223 | mov al,0 |
||
224 | out 0x21,al |
||
225 | call rdelay |
||
226 | out 0xA1,al |
||
227 | sti |
||
228 | |||
229 | temp_3456: |
||
230 | xor ax,ax |
||
231 | mov es,ax |
||
232 | mov al,byte [es:0x9030] |
||
233 | cmp al,1 |
||
234 | jl nbw |
||
235 | cmp al,4 |
||
236 | jle nbw32 |
||
237 | |||
238 | nbw: |
||
239 | in al,0x60 |
||
240 | call pause_key |
||
241 | cmp al,6 |
||
242 | jae nbw |
||
243 | mov bl,al |
||
244 | nbw2: |
||
245 | in al,0x60 |
||
246 | call pause_key |
||
247 | cmp al,bl |
||
248 | je nbw2 |
||
249 | cmp al,240 ;ax,240 |
||
250 | jne nbw31 |
||
251 | mov al,bl |
||
252 | dec ax |
||
253 | jmp nbw32 |
||
254 | nbw31: |
||
255 | add bl,128 |
||
256 | cmp al,bl |
||
257 | jne nbw |
||
258 | sub al,129 |
||
259 | |||
260 | nbw32: |
||
261 | |||
262 | dec ax ; 1 = write floppy |
||
263 | js nbw |
||
264 | jnz no_floppy_write |
||
265 | call floppy_write |
||
266 | jmp temp_3456 ;nbw |
||
267 | no_floppy_write: |
||
268 | |||
269 | dec ax ; 2 = power off |
||
270 | jnz no_apm_off |
||
271 | call APM_PowerOff |
||
272 | jmp $ |
||
273 | no_apm_off: |
||
274 | |||
275 | dec ax ; 3 = reboot |
||
276 | jnz restart_kernel ; 4 = restart kernel |
||
277 | push 0x40 |
||
278 | pop ds |
||
279 | mov word[0x0072],0x1234 |
||
280 | jmp 0xF000:0xFFF0 |
||
281 | |||
282 | pause_key: |
||
283 | mov cx,100 |
||
284 | pause_key_1: |
||
285 | loop pause_key_1 |
||
286 | ret |
||
287 | org $+0x10000 |
||
288 | old_ints_h: |
||
289 | dw 0x400 |
||
290 | dd 0 |
||
291 | dw 0 |
||
292 | org $-0x10000 |
||
293 | |||
294 | rdelay: |
||
295 | ret |
||
296 | |||
297 | iglobal |
||
298 | kernel db 'KERNEL MNT' |
||
299 | ; shutdown_parameter db 0 |
||
300 | endg |
||
301 | |||
302 | restart_kernel: |
||
303 | |||
304 | mov ax,0x0003 ; set text mode for screen |
||
305 | int 0x10 |
||
306 | |||
307 | jmp 0x4000:0000 |
||
308 | |||
309 | |||
310 | restart_kernel_4000: |
||
311 | cli |
||
312 | |||
313 | ; mov di,0x1000 ; load kernel image from 0x8000:0 -> 0x1000:0 |
||
314 | ; |
||
315 | ; new_kernel_block_move: |
||
316 | ; |
||
317 | ; mov ebx,0 |
||
318 | ; |
||
319 | ; new_kernel_byte_move: |
||
320 | ; |
||
321 | ; mov ax,di |
||
322 | ; add ax,0x7000 |
||
323 | ; mov es,ax |
||
324 | ; mov dl,[es:bx] |
||
325 | ; mov es,di |
||
326 | ; mov [es:bx],dl |
||
327 | ; |
||
328 | ; inc ebx |
||
329 | ; cmp ebx,65536 |
||
330 | ; jbe new_kernel_byte_move |
||
331 | ; |
||
332 | ; add di,0x1000 |
||
333 | ; cmp di,0x2000 |
||
334 | ; jbe new_kernel_block_move |
||
335 | push ds |
||
336 | pop es |
||
337 | mov cx, 0x8000 |
||
338 | push cx |
||
339 | mov ds, cx |
||
340 | xor si, si |
||
341 | xor di, di |
||
342 | rep movsw |
||
343 | push 0x9000 |
||
344 | pop ds |
||
345 | push 0x2000 |
||
346 | pop es |
||
347 | pop cx |
||
348 | rep movsw |
||
349 | |||
350 | wbinvd ; write and invalidate cache |
||
351 | |||
352 | ; mov ax,0x1000 |
||
353 | ; mov es,ax |
||
354 | ; mov ax,0x3000 |
||
355 | ; mov ss,ax |
||
356 | ; mov sp,0xec00 |
||
357 | ; restore timer |
||
358 | mov al, 00110100b |
||
359 | out 43h, al |
||
360 | jcxz $+2 |
||
361 | mov al, 0xFF |
||
362 | out 40h, al |
||
363 | jcxz $+2 |
||
364 | out 40h, al |
||
365 | jcxz $+2 |
||
366 | sti |
||
367 | |||
368 | ; bootloader interface |
||
369 | push 0x1000 |
||
370 | pop ds |
||
371 | mov si, .bootloader_block;-0x10000 |
||
372 | mov ax, 'KL' |
||
373 | jmp 0x1000:0000 |
||
374 | |||
375 | .bootloader_block: |
||
376 | db 1 ; version |
||
377 | dw 1 ; floppy image is in memory |
||
378 | dd 0 ; cannot save parameters |
||
379 | |||
380 | APM_PowerOff: |
||
381 | mov ax, 5304h |
||
382 | xor bx, bx |
||
383 | int 15h |
||
384 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
||
385 | mov ax,0x5300 |
||
386 | xor bx,bx |
||
387 | int 0x15 |
||
388 | push ax |
||
389 | |||
390 | mov ax,0x5301 |
||
391 | xor bx,bx |
||
392 | int 0x15 |
||
393 | |||
394 | mov ax,0x5308 |
||
395 | mov bx,1 |
||
396 | mov cx,bx |
||
397 | int 0x15 |
||
398 | |||
399 | mov ax,0x530E |
||
400 | xor bx,bx |
||
401 | pop cx |
||
402 | int 0x15 |
||
403 | |||
404 | mov ax,0x530D |
||
405 | mov bx,1 |
||
406 | mov cx,bx |
||
407 | int 0x15 |
||
408 | |||
409 | mov ax,0x530F |
||
410 | mov bx,1 |
||
411 | mov cx,bx |
||
412 | int 0x15 |
||
413 | |||
414 | mov ax,0x5307 |
||
415 | mov bx,1 |
||
416 | mov cx,3 |
||
417 | int 0x15 |
||
418 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
||
419 | fwwritedone: |
||
420 | ret |
||
421 | org $+0x10000 |
||
422 | flm db 0 |
||
423 | org $-0x10000 |
||
424 | |||
425 | floppy_write: ; write diskette image to physical floppy |
||
426 | |||
427 | cmp [flm-0x10000],byte 1 |
||
428 | je fwwritedone |
||
429 | mov [flm-0x10000],byte 1 |
||
430 | |||
431 | xor ax, ax ; reset drive |
||
432 | xor dx, dx |
||
433 | int 0x13 |
||
434 | |||
435 | mov cx,0x0001 ; startcyl,startsector |
||
436 | ; mov dx,0x0000 ; starthead,drive |
||
437 | xor dx, dx |
||
438 | mov ax, 80*2 ; read no of sect |
||
439 | |||
440 | fwwrites: |
||
441 | push ax |
||
442 | |||
443 | ; move 1mb+ -> 0:a000 |
||
444 | |||
445 | pusha |
||
446 | mov si,fwmovedesc -0x10000 |
||
447 | mov cx,256*18 |
||
448 | mov ah,0x87 |
||
449 | push ds |
||
450 | pop es |
||
451 | int 0x15 |
||
452 | add dword [fwmovedesc-0x10000+0x12], 512*18 |
||
453 | popa |
||
454 | |||
455 | xor si,si |
||
456 | mov es,si |
||
457 | fwnewwrite: |
||
458 | mov bx,0xa000 ; es:bx -> data area |
||
459 | mov ax,0x0300+18 ; read, no of sectors to read |
||
460 | int 0x13 |
||
461 | |||
462 | test ah, ah |
||
463 | jz fwgoodwrite |
||
464 | |||
465 | inc si |
||
466 | cmp si,10 |
||
467 | jnz fwnewwrite |
||
468 | |||
469 | ; can't access diskette - return |
||
470 | pop ax |
||
471 | ret |
||
472 | |||
473 | fwgoodwrite: |
||
474 | inc dh |
||
475 | cmp dh,2 |
||
476 | jnz fwbb2 |
||
477 | mov dh,0 |
||
478 | inc ch |
||
479 | fwbb2: |
||
480 | pop ax |
||
481 | dec ax |
||
482 | jnz fwwrites |
||
483 | ret |
||
484 | org $+0x10000 |
||
485 | fwmovedesc: |
||
486 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
487 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
488 | db 0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0 |
||
489 | db 0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0 |
||
490 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
491 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
492 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
493 | db 0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0 |
||
494 | org $-0x10000 |
||
495 | use32 |
||
496 | org $+0x10000 |
||
497 | uglobal |
||
498 | shutdownpos dd 0x0 |
||
499 | endg |
||
500 | |||
501 | iglobal |
||
502 | if lang eq en |
||
503 | shutdowntext: |
||
504 | db "IT'S SAFE TO POWER OFF COMPUTER OR " |
||
505 | db ' ' |
||
506 | db '1) SAVE RAMDISK TO FLOPPY ' |
||
507 | db '2) APM - POWEROFF ' |
||
508 | db '3) REBOOT ' |
||
509 | db '4) RESTART KERNEL ' |
||
510 | else |
||
511 | shutdowntext: |
||
512 | db "Безопасное выключение компьютера или " |
||
513 | db ' ' |
||
514 | db '1) Сохранить рамдиск на дискету ' |
||
515 | db '2) APM - выключение питания ' |
||
516 | db '3) Перезагрузка системы ' |
||
517 | db '4) Рестарт ядра из ОЗУ ' |
||
518 | end if |
||
519 | rosef: |
||
520 | db 'ROSE TXT' |
||
521 | endg |