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