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