Subversion Repositories Kolibri OS

Rev

Rev 46 | Rev 79 | 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:
379
;!!!!!!!!!!!!!!!!!!!!!!!!
380
mov ax,0x5300
381
xor bx,bx
382
int 0x15
383
push ax
384
 
385
mov ax,0x5301
386
xor bx,bx
387
int 0x15
388
 
389
mov ax,0x5308
390
mov bx,1
391
mov cx,bx
392
int 0x15
393
 
394
mov ax,0x530E
395
xor bx,bx
396
pop cx
397
int 0x15
398
 
399
mov ax,0x530D
400
mov bx,1
401
mov cx,bx
402
int 0x15
403
 
404
mov ax,0x530F
405
mov bx,1
406
mov cx,bx
407
int 0x15
408
 
409
mov ax,0x5307
410
mov bx,1
411
mov cx,3
412
int 0x15
413
;!!!!!!!!!!!!!!!!!!!!!!!!
61 halyavin 414
fwwritedone:
1 ha 415
        ret
416
 
61 halyavin 417
flm db 0
418
 
1 ha 419
floppy_write:   ; write diskette image to physical floppy
420
 
61 halyavin 421
        cmp  [flm-0x10000],byte 1
1 ha 422
        je   fwwritedone
61 halyavin 423
        mov  [flm-0x10000],byte 1
1 ha 424
 
61 halyavin 425
	xor	ax, ax		; reset drive
426
	xor	dx, dx
1 ha 427
        int     0x13
428
 
429
        mov     cx,0x0001               ; startcyl,startsector
61 halyavin 430
;        mov     dx,0x0000               ; starthead,drive
431
	xor	dx, dx
432
        mov	ax, 80*2               ; read no of sect
1 ha 433
 
434
      fwwrites:
61 halyavin 435
	push	ax
1 ha 436
 
437
        ; move 1mb+ -> 0:a000
438
 
61 halyavin 439
	pusha
1 ha 440
        mov     si,fwmovedesc -0x10000
441
        mov     cx,256*18
442
        mov     ah,0x87
61 halyavin 443
        push	ds
444
        pop	es
1 ha 445
        int     0x15
61 halyavin 446
        add	dword [fwmovedesc-0x10000+0x12], 512*18
1 ha 447
        popa
448
 
449
        xor     si,si
61 halyavin 450
        mov	es,si
1 ha 451
      fwnewwrite:
452
        mov     bx,0xa000               ; es:bx -> data area
453
        mov     ax,0x0300+18            ; read, no of sectors to read
454
        int     0x13
455
 
61 halyavin 456
	test	ah, ah
1 ha 457
        jz      fwgoodwrite
458
 
61 halyavin 459
	inc	si
1 ha 460
        cmp     si,10
461
        jnz     fwnewwrite
462
 
61 halyavin 463
; can't access diskette - return
464
	pop	ax
1 ha 465
        ret
466
 
467
      fwgoodwrite:
468
        inc     dh
469
        cmp     dh,2
470
        jnz     fwbb2
471
        mov     dh,0
472
        inc     ch
473
      fwbb2:
474
        pop     ax
475
        dec     ax
61 halyavin 476
        jnz     fwwrites
477
        ret
1 ha 478
 
479
      fwmovedesc:
480
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
481
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
482
        db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
483
        db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
484
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
485
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
486
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
487
        db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
488
 
489
use32
490
 
491
uglobal
492
  shutdownpos dd 0x0
493
endg
494
 
495
iglobal
61 halyavin 496
if lang eq en
1 ha 497
shutdowntext:
61 halyavin 498
    db   "IT'S SAFE TO POWER OFF COMPUTER OR      "
499
    db   '                                        '
500
    db   '1) SAVE RAMDISK TO FLOPPY               '
501
    db   '2) APM - POWEROFF                       '
502
    db   '3) REBOOT                               '
503
    db   '4) RESTART KERNEL                       '
504
else
505
shutdowntext:
1 ha 506
    db   "Безопасное выключение компьютера или    "
507
    db   '                                        '
508
    db   '1) Сохранить рамдиск на дискету         '
509
    db   '2) APM - выключение питания             '
510
    db   '3) Перезагрузка системы                 '
511
    db   '4) Рестарт ядра из ОЗУ                  '
61 halyavin 512
end if
1 ha 513
rosef:
514
    db 'ROSE    TXT'
515
endg