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