Rev 681 | Rev 2288 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 681 | Rev 748 | ||
---|---|---|---|
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: 681 $ |
14 | $Revision: 748 $ |
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 | call pause_key |
- | |
75 | cmp al,6 |
74 | cmp al,6 |
76 | jae nbw |
75 | jae nbw |
77 | mov bl,al |
76 | mov bl,al |
78 | nbw2: |
77 | nbw2: |
79 | in al,0x60 |
78 | in al,0x60 |
80 | call pause_key |
- | |
81 | cmp al,bl |
79 | cmp al,bl |
82 | je nbw2 |
80 | je nbw2 |
83 | cmp al,240 ;ax,240 |
81 | cmp al,240 ;ax,240 |
84 | jne nbw31 |
82 | jne nbw31 |
85 | mov al,bl |
83 | mov al,bl |
86 | dec ax |
84 | dec ax |
87 | jmp nbw32 |
85 | jmp nbw32 |
88 | nbw31: |
86 | nbw31: |
89 | add bl,128 |
87 | add bl,128 |
90 | cmp al,bl |
88 | cmp al,bl |
91 | jne nbw |
89 | jne nbw |
92 | sub al,129 |
90 | sub al,129 |
93 | 91 | ||
94 | nbw32: |
92 | nbw32: |
95 | - | ||
96 | dec ax ; 1 = write floppy |
93 | |
97 | js nbw |
- | |
98 | jnz no_floppy_write |
- | |
99 | call floppy_write |
- | |
100 | jmp temp_3456 ;nbw |
- | |
101 | no_floppy_write: |
- | |
102 | 94 | dec ax |
|
103 | dec ax ; 2 = power off |
95 | dec ax ; 2 = power off |
104 | jnz no_apm_off |
96 | jnz no_apm_off |
105 | call APM_PowerOff |
97 | call APM_PowerOff |
106 | jmp $ |
98 | jmp $ |
107 | no_apm_off: |
99 | no_apm_off: |
108 | 100 | ||
109 | dec ax ; 3 = reboot |
101 | dec ax ; 3 = reboot |
110 | jnz restart_kernel ; 4 = restart kernel |
102 | jnz restart_kernel ; 4 = restart kernel |
111 | push 0x40 |
103 | push 0x40 |
112 | pop ds |
104 | pop ds |
113 | mov word[0x0072],0x1234 |
105 | mov word[0x0072],0x1234 |
114 | jmp 0xF000:0xFFF0 |
106 | jmp 0xF000:0xFFF0 |
115 | - | ||
116 | pause_key: |
- | |
117 | mov cx,100 |
- | |
118 | pause_key_1: |
- | |
119 | loop pause_key_1 |
- | |
120 | ret |
107 | |
121 | 108 | ||
122 | rdelay: |
109 | rdelay: |
123 | ret |
110 | ret |
124 | - | ||
125 | floppy_write: ; write diskette image to physical floppy |
- | |
126 | - | ||
127 | cmp [flm],byte 1 |
- | |
128 | je fwwritedone |
- | |
129 | mov [flm],byte 1 |
- | |
130 | - | ||
131 | xor ax, ax ; reset drive |
- | |
132 | xor dx, dx |
- | |
133 | int 0x13 |
- | |
134 | - | ||
135 | mov cx,0x0001 ; startcyl,startsector |
- | |
136 | xor dx, dx ; starthead,drive |
- | |
137 | mov ax, 80*2 ; read no of sect |
- | |
138 | - | ||
139 | fwwrites: |
- | |
140 | push ax |
- | |
141 | - | ||
142 | ; move 1mb+ -> 0:a000 |
- | |
143 | - | ||
144 | pusha |
- | |
145 | mov si, fwmovedesc |
- | |
146 | mov cx,256*18 |
- | |
147 | mov ah,0x87 |
- | |
148 | push ds |
- | |
149 | pop es |
- | |
150 | int 0x15 |
- | |
151 | add dword [fwmovedesc+0x12], 512*18 |
- | |
152 | popa |
- | |
153 | - | ||
154 | xor si,si |
- | |
155 | mov es,si |
- | |
156 | fwnewwrite: |
- | |
157 | mov bx,0xa000 ; es:bx -> data area |
- | |
158 | mov ax,0x0300+18 ; read, no of sectors to read |
- | |
159 | int 0x13 |
- | |
160 | - | ||
161 | test ah, ah |
- | |
162 | jz fwgoodwrite |
- | |
163 | - | ||
164 | inc si |
- | |
165 | cmp si,10 |
- | |
166 | jnz fwnewwrite |
- | |
167 | - | ||
168 | ; can't access diskette - return |
- | |
169 | pop ax |
- | |
170 | ret |
- | |
171 | - | ||
172 | fwgoodwrite: |
- | |
173 | inc dh |
- | |
174 | cmp dh,2 |
- | |
175 | jnz fwbb2 |
- | |
176 | mov dh,0 |
- | |
177 | inc ch |
- | |
178 | fwbb2: |
- | |
179 | pop ax |
- | |
180 | dec ax |
- | |
181 | jnz fwwrites |
- | |
182 | ret |
- | |
183 | 111 | ||
184 | APM_PowerOff: |
112 | APM_PowerOff: |
185 | mov ax, 5304h |
113 | mov ax, 5304h |
186 | xor bx, bx |
114 | xor bx, bx |
187 | int 15h |
115 | int 15h |
188 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
116 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
189 | mov ax,0x5300 |
117 | mov ax,0x5300 |
190 | xor bx,bx |
118 | xor bx,bx |
191 | int 0x15 |
119 | int 0x15 |
192 | push ax |
120 | push ax |
193 | 121 | ||
194 | mov ax,0x5301 |
122 | mov ax,0x5301 |
195 | xor bx,bx |
123 | xor bx,bx |
196 | int 0x15 |
124 | int 0x15 |
197 | 125 | ||
198 | mov ax,0x5308 |
126 | mov ax,0x5308 |
199 | mov bx,1 |
127 | mov bx,1 |
200 | mov cx,bx |
128 | mov cx,bx |
201 | int 0x15 |
129 | int 0x15 |
202 | 130 | ||
203 | mov ax,0x530E |
131 | mov ax,0x530E |
204 | xor bx,bx |
132 | xor bx,bx |
205 | pop cx |
133 | pop cx |
206 | int 0x15 |
134 | int 0x15 |
207 | 135 | ||
208 | mov ax,0x530D |
136 | mov ax,0x530D |
209 | mov bx,1 |
137 | mov bx,1 |
210 | mov cx,bx |
138 | mov cx,bx |
211 | int 0x15 |
139 | int 0x15 |
212 | 140 | ||
213 | mov ax,0x530F |
141 | mov ax,0x530F |
214 | mov bx,1 |
142 | mov bx,1 |
215 | mov cx,bx |
143 | mov cx,bx |
216 | int 0x15 |
144 | int 0x15 |
217 | 145 | ||
218 | mov ax,0x5307 |
146 | mov ax,0x5307 |
219 | mov bx,1 |
147 | mov bx,1 |
220 | mov cx,3 |
148 | mov cx,3 |
221 | int 0x15 |
149 | int 0x15 |
222 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
150 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
223 | fwwritedone: |
- | |
224 | ret |
151 | ret |
225 | 152 | ||
226 | restart_kernel: |
153 | restart_kernel: |
227 | 154 | ||
228 | mov ax,0x0003 ; set text mode for screen |
155 | mov ax,0x0003 ; set text mode for screen |
229 | int 0x10 |
156 | int 0x10 |
230 | jmp 0x4000:0000 |
157 | jmp 0x4000:0000 |
231 | 158 | ||
232 | restart_kernel_4000: |
159 | restart_kernel_4000: |
233 | cli |
160 | cli |
234 | 161 | ||
235 | push ds |
162 | push ds |
236 | pop es |
163 | pop es |
237 | mov cx, 0x8000 |
164 | mov cx, 0x8000 |
238 | push cx |
165 | push cx |
239 | push 0x7000 |
166 | push 0x7000 |
240 | pop ds |
167 | pop ds |
241 | xor si, si |
168 | xor si, si |
242 | xor di, di |
169 | xor di, di |
243 | rep movsw |
170 | rep movsw |
244 | pop cx |
171 | pop cx |
245 | mov ds, cx |
172 | mov ds, cx |
246 | push 0x2000 |
173 | push 0x2000 |
247 | pop es |
174 | pop es |
248 | rep movsw |
175 | rep movsw |
249 | push 0x9000 |
176 | push 0x9000 |
250 | pop ds |
177 | pop ds |
251 | push 0x3000 |
178 | push 0x3000 |
252 | pop es |
179 | pop es |
253 | mov cx, 0xE000/2 |
180 | mov cx, 0xE000/2 |
254 | rep movsw |
181 | rep movsw |
255 | 182 | ||
256 | wbinvd ; write and invalidate cache |
183 | wbinvd ; write and invalidate cache |
257 | 184 | ||
258 | mov al, 00110100b |
185 | mov al, 00110100b |
259 | out 43h, al |
186 | out 43h, al |
260 | jcxz $+2 |
187 | jcxz $+2 |
261 | mov al, 0xFF |
188 | mov al, 0xFF |
262 | out 40h, al |
189 | out 40h, al |
263 | jcxz $+2 |
190 | jcxz $+2 |
264 | out 40h, al |
191 | out 40h, al |
265 | jcxz $+2 |
192 | jcxz $+2 |
266 | sti |
193 | sti |
267 | 194 | ||
268 | ; (hint by Black_mirror) |
195 | ; (hint by Black_mirror) |
269 | ; We must read data from keyboard port, |
196 | ; We must read data from keyboard port, |
270 | ; because there may be situation when previous keyboard interrupt is lost |
197 | ; because there may be situation when previous keyboard interrupt is lost |
271 | ; (due to return to real mode and IRQ reprogramming) |
198 | ; (due to return to real mode and IRQ reprogramming) |
272 | ; and next interrupt will not be generated (as keyboard waits for handling) |
199 | ; and next interrupt will not be generated (as keyboard waits for handling) |
273 | in al, 0x60 |
200 | in al, 0x60 |
274 | 201 | ||
275 | ; bootloader interface |
202 | ; bootloader interface |
276 | push 0x1000 |
203 | push 0x1000 |
277 | pop ds |
204 | pop ds |
278 | mov si, kernel_restart_bootblock |
205 | mov si, kernel_restart_bootblock |
279 | mov ax, 'KL' |
206 | mov ax, 'KL' |
280 | jmp 0x1000:0000 |
207 | jmp 0x1000:0000 |