Subversion Repositories Kolibri OS

Rev

Rev 61 | Rev 82 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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