Subversion Repositories Kolibri OS

Rev

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

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