Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
1065 Lrz 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;  Shutdown for Menuet                                         ;;
7
;;                                                              ;;
8
;;  Distributed under General Public License                    ;;
9
;;  See file COPYING for details.                               ;;
10
;;  Copyright 2003 Ville Turjanmaa                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
13
 
14
 
15
align 4
16
pr_mode_exit:
17
 
18
; setup stack
2434 Serge 19
        mov     ax, 0x3000
20
        mov     ss, ax
21
        mov     esp, 0x0EC00
1065 Lrz 22
; setup ds
23
        push    cs
2434 Serge 24
        pop     ds
1065 Lrz 25
 
2434 Serge 26
        lidt    [old_ints_h]
1065 Lrz 27
;remap IRQs
2434 Serge 28
        mov     al, 0x11
29
        out     0x20, al
30
        call    rdelay
31
        out     0xA0, al
32
        call    rdelay
1065 Lrz 33
 
2434 Serge 34
        mov     al, 0x08
35
        out     0x21, al
36
        call    rdelay
37
        mov     al, 0x70
38
        out     0xA1, al
39
        call    rdelay
1065 Lrz 40
 
2434 Serge 41
        mov     al, 0x04
42
        out     0x21, al
43
        call    rdelay
44
        mov     al, 0x02
45
        out     0xA1, al
46
        call    rdelay
1065 Lrz 47
 
2434 Serge 48
        mov     al, 0x01
49
        out     0x21, al
50
        call    rdelay
51
        out     0xA1, al
52
        call    rdelay
1065 Lrz 53
 
2434 Serge 54
        mov     al, 0xB8
55
        out     0x21, al
56
        call    rdelay
57
        mov     al, 0xBD
58
        out     0xA1, al
1065 Lrz 59
        sti
60
 
61
temp_3456:
2434 Serge 62
        xor     ax, ax
63
        mov     es, ax
64
        mov     al, byte [es:0x9030]
65
        cmp     al, 1
66
        jl      nbw
67
        cmp     al, 4
68
        jle     nbw32
1065 Lrz 69
 
70
nbw:
2434 Serge 71
        in      al, 0x60
72
        cmp     al, 6
73
        jae     nbw
74
        mov     bl, al
1065 Lrz 75
nbw2:
2434 Serge 76
        in      al, 0x60
77
        cmp     al, bl
78
        je      nbw2
79
        cmp     al, 240;ax,240
80
        jne     nbw31
81
        mov     al, bl
82
        dec     ax
83
        jmp     nbw32
1065 Lrz 84
nbw31:
2434 Serge 85
        add     bl, 128
86
        cmp     al, bl
87
        jne     nbw
88
        sub     al, 129
1065 Lrz 89
 
90
nbw32:
91
 
2434 Serge 92
        dec     ax
93
        dec     ax ; 2 = power off
94
        jnz     no_apm_off
95
        call    APM_PowerOff
96
        jmp     $
1065 Lrz 97
no_apm_off:
98
 
2434 Serge 99
        dec     ax ; 3 = reboot
100
        jnz     restart_kernel     ; 4 = restart kernel
101
        push    0x40
102
        pop     ds
103
        mov     word[0x0072], 0x1234
104
        jmp     0xF000:0xFFF0
1065 Lrz 105
 
106
 
107
rdelay:
108
        ret
109
 
110
APM_PowerOff:
111
        mov     ax, 5304h
112
        xor     bx, bx
113
        int     15h
114
;!!!!!!!!!!!!!!!!!!!!!!!!
2434 Serge 115
        mov     ax, 0x5300
116
        xor     bx, bx
117
        int     0x15
118
        push    ax
1065 Lrz 119
 
2434 Serge 120
        mov     ax, 0x5301
121
        xor     bx, bx
122
        int     0x15
1065 Lrz 123
 
2434 Serge 124
        mov     ax, 0x5308
125
        mov     bx, 1
126
        mov     cx, bx
127
        int     0x15
1065 Lrz 128
 
2434 Serge 129
        mov     ax, 0x530E
130
        xor     bx, bx
131
        pop     cx
132
        int     0x15
1065 Lrz 133
 
2434 Serge 134
        mov     ax, 0x530D
135
        mov     bx, 1
136
        mov     cx, bx
137
        int     0x15
1065 Lrz 138
 
2434 Serge 139
        mov     ax, 0x530F
140
        mov     bx, 1
141
        mov     cx, bx
142
        int     0x15
1065 Lrz 143
 
2434 Serge 144
        mov     ax, 0x5307
145
        mov     bx, 1
146
        mov     cx, 3
147
        int     0x15
1065 Lrz 148
;!!!!!!!!!!!!!!!!!!!!!!!!
149
        ret
150
 
151
restart_kernel:
152
 
2434 Serge 153
        mov     ax, 0x0003     ; set text mode for screen
1065 Lrz 154
        int     0x10
155
        jmp     0x4000:0000
156
 
157
restart_kernel_4000:
158
        cli
159
 
160
        push    ds
161
        pop     es
162
        mov     cx, 0x8000
163
        push    cx
164
        push    0x7000
165
        pop     ds
166
        xor     si, si
167
        xor     di, di
2434 Serge 168
        rep movsw
1065 Lrz 169
        pop     cx
170
        mov     ds, cx
171
        push    0x2000
172
        pop     es
2434 Serge 173
        rep movsw
1065 Lrz 174
        push    0x9000
175
        pop     ds
176
        push    0x3000
177
        pop     es
178
        mov     cx, 0xE000/2
2434 Serge 179
        rep movsw
1065 Lrz 180
 
181
        wbinvd  ; write and invalidate cache
182
 
2434 Serge 183
        mov     al, 00110100b
184
        out     43h, al
1065 Lrz 185
        jcxz    $+2
2434 Serge 186
        mov     al, 0xFF
187
        out     40h, al
1065 Lrz 188
        jcxz    $+2
2434 Serge 189
        out     40h, al
1065 Lrz 190
        jcxz    $+2
191
        sti
192
 
193
; (hint by Black_mirror)
194
; We must read data from keyboard port,
195
; because there may be situation when previous keyboard interrupt is lost
196
; (due to return to real mode and IRQ reprogramming)
197
; and next interrupt will not be generated (as keyboard waits for handling)
198
        in      al, 0x60
199
 
200
; bootloader interface
201
        push    0x1000
2434 Serge 202
        pop     ds
203
        mov     si, kernel_restart_bootblock
204
        mov     ax, 'KL'
1065 Lrz 205
        jmp     0x1000:0000
206