Rev 6240 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6240 | Rev 6242 | ||
---|---|---|---|
Line 9... | Line 9... | ||
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
Line 13... | Line 13... | ||
13 | 13 | ||
- | 14 | $Revision: 6242 $ |
|
- | 15 | ||
- | 16 | align 4 |
|
- | 17 | system_shutdown: ; shut down the system |
|
- | 18 | ||
- | 19 | cmp byte [BOOT_VARS+0x9030], 1 |
|
- | 20 | jne @F |
|
- | 21 | ret |
|
- | 22 | @@: |
|
- | 23 | call stop_all_services |
|
- | 24 | ||
- | 25 | yes_shutdown_param: |
|
- | 26 | ; Shutdown other CPUs, if initialized |
|
- | 27 | cmp [ap_initialized], 0 |
|
- | 28 | jz .no_shutdown_cpus |
|
- | 29 | mov edi, [LAPIC_BASE] |
|
- | 30 | add edi, 300h |
|
- | 31 | mov esi, smpt+4 |
|
- | 32 | mov ebx, [cpu_count] |
|
- | 33 | dec ebx |
|
- | 34 | .shutdown_cpus_loop: |
|
- | 35 | lodsd |
|
- | 36 | push esi |
|
- | 37 | xor esi, esi |
|
- | 38 | inc esi |
|
- | 39 | shl eax, 24 |
|
- | 40 | mov [edi+10h], eax |
|
- | 41 | ; assert INIT IPI |
|
- | 42 | mov dword [edi], 0C500h |
|
- | 43 | call delay_ms |
|
- | 44 | @@: |
|
- | 45 | test dword [edi], 1000h |
|
- | 46 | jnz @b |
|
- | 47 | ; deassert INIT IPI |
|
- | 48 | mov dword [edi], 8500h |
|
- | 49 | call delay_ms |
|
- | 50 | @@: |
|
- | 51 | test dword [edi], 1000h |
|
- | 52 | jnz @b |
|
- | 53 | ; don't send STARTUP IPI: let other CPUs be in wait-for-startup state |
|
- | 54 | pop esi |
|
- | 55 | dec ebx |
|
- | 56 | jnz .shutdown_cpus_loop |
|
- | 57 | .no_shutdown_cpus: |
|
- | 58 | ||
- | 59 | cli |
|
- | 60 | call IRQ_mask_all |
|
- | 61 | ||
- | 62 | mov eax, [OS_BASE + 0x9030] |
|
- | 63 | cmp al, SYSTEM_RESTART |
|
- | 64 | jne @F |
|
- | 65 | ||
- | 66 | ; load kernel.mnt to _CLEAN_ZONE |
|
- | 67 | mov ebx, kernel_file_load |
|
- | 68 | pushad |
|
- | 69 | call file_system_lfn |
|
- | 70 | popad |
|
- | 71 | @@: |
|
- | 72 | mov esi, OS_BASE+restart_code_start ; move kernel re-starter to 0x5000:0 |
|
- | 73 | mov edi, OS_BASE+0x50000 |
|
- | 74 | mov ecx, (restart_code_end - restart_code_start)/4 |
|
- | 75 | rep movsd |
|
- | 76 | ||
- | 77 | call create_trampoline_pgmap |
|
- | 78 | mov cr3, eax |
|
- | 79 | jmp @F |
|
- | 80 | org $-OS_BASE |
|
- | 81 | @@: |
|
- | 82 | ||
- | 83 | ;disable paging |
|
- | 84 | ||
- | 85 | mov eax, cr0 |
|
- | 86 | and eax, 0x7FFFFFFF |
|
- | 87 | mov cr0, eax |
|
- | 88 | mov eax, cr3 |
|
- | 89 | mov cr3, eax |
|
- | 90 | ||
- | 91 | cmp byte [0x9030], SYSTEM_SHUTDOWN |
|
- | 92 | jne no_acpi_power_off |
|
- | 93 | ||
- | 94 | ; system_power_off |
|
- | 95 | ||
- | 96 | mov ebx, [acpi_fadt_base-OS_BASE] |
|
- | 97 | cmp dword [ebx], 'FACP' |
|
- | 98 | jne no_acpi_power_off |
|
- | 99 | mov esi, [acpi_dsdt_base-OS_BASE] |
|
- | 100 | cmp dword [esi], 'DSDT' |
|
- | 101 | jne no_acpi_power_off |
|
- | 102 | mov eax, [esi+4] ; DSDT length |
|
- | 103 | sub eax, 36+4 |
|
- | 104 | jbe no_acpi_power_off |
|
- | 105 | add esi, 36 |
|
- | 106 | .scan_dsdt: |
|
- | 107 | cmp dword [esi], '_S5_' |
|
- | 108 | jnz .scan_dsdt_cont |
|
- | 109 | cmp byte [esi+4], 12h ; DefPackage opcode |
|
- | 110 | jnz .scan_dsdt_cont |
|
- | 111 | mov dl, [esi+6] |
|
- | 112 | cmp dl, 4 ; _S5_ package must contain 4 bytes |
|
- | 113 | ; ...in theory; in practice, VirtualBox has 2 bytes |
|
- | 114 | ja .scan_dsdt_cont |
|
- | 115 | cmp dl, 1 |
|
- | 116 | jb .scan_dsdt_cont |
|
- | 117 | lea esi, [esi+7] |
|
- | 118 | xor ecx, ecx |
|
- | 119 | cmp byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx |
|
- | 120 | jz @f |
|
- | 121 | cmp byte [esi], 0xA |
|
- | 122 | jnz no_acpi_power_off |
|
- | 123 | inc esi |
|
- | 124 | mov cl, [esi] |
|
- | 125 | @@: |
|
- | 126 | inc esi |
|
- | 127 | cmp dl, 2 |
|
- | 128 | jb @f |
|
- | 129 | cmp byte [esi], 0 |
|
- | 130 | jz @f |
|
- | 131 | cmp byte [esi], 0xA |
|
- | 132 | jnz no_acpi_power_off |
|
- | 133 | inc esi |
|
- | 134 | mov ch, [esi] |
|
- | 135 | @@: |
|
- | 136 | jmp do_acpi_power_off |
|
- | 137 | .scan_dsdt_cont: |
|
- | 138 | inc esi |
|
- | 139 | dec eax |
|
- | 140 | jnz .scan_dsdt |
|
- | 141 | jmp no_acpi_power_off |
|
- | 142 | do_acpi_power_off: |
|
- | 143 | mov edx, [ebx+48] |
|
- | 144 | test edx, edx |
|
- | 145 | jz .nosmi |
|
- | 146 | mov al, [ebx+52] |
|
- | 147 | out dx, al |
|
- | 148 | mov edx, [ebx+64] |
|
- | 149 | @@: |
|
- | 150 | in ax, dx |
|
- | 151 | test al, 1 |
|
- | 152 | jz @b |
|
- | 153 | .nosmi: |
|
- | 154 | and cx, 0x0707 |
|
- | 155 | shl cx, 2 |
|
- | 156 | or cx, 0x2020 |
|
- | 157 | mov edx, [ebx+64] |
|
- | 158 | in ax, dx |
|
- | 159 | and ax, 203h |
|
- | 160 | or ah, cl |
|
- | 161 | out dx, ax |
|
- | 162 | mov edx, [ebx+68] |
|
- | 163 | test edx, edx |
|
- | 164 | jz @f |
|
- | 165 | in ax, dx |
|
- | 166 | and ax, 203h |
|
- | 167 | or ah, ch |
|
- | 168 | out dx, ax |
|
- | 169 | @@: |
|
- | 170 | jmp $ |
|
- | 171 | ||
- | 172 | no_acpi_power_off: |
|
- | 173 | jmp 0x50000 |
|
- | 174 | ||
- | 175 | align 4 |
|
- | 176 | restart_code_start: |
|
- | 177 | org 0x50000 |
|
- | 178 | ||
- | 179 | cmp byte [0x9030], SYSTEM_RESTART |
|
- | 180 | jne @F |
|
- | 181 | ||
- | 182 | mov esi, _CLEAN_ZONE-OS_BASE |
|
- | 183 | mov edi, 0x10000 |
|
- | 184 | mov ecx, 0x31000/4 |
|
- | 185 | cld |
|
- | 186 | rep movsd |
|
Line 14... | Line -... | ||
14 | $Revision: 6240 $ |
- | |
15 | - | ||
16 | use32 |
187 | @@: |
17 | become_real: |
188 | |
18 | xor ebx, ebx |
189 | xor ebx, ebx |
19 | xor edx, edx |
190 | xor edx, edx |
20 | xor ecx, ecx |
191 | xor ecx, ecx |
21 | xor esi, esi |
192 | xor esi, esi |
22 | xor edi, edi |
- | |
23 | xor ebp, ebp |
193 | xor edi, edi |
24 | cli |
194 | xor ebp, ebp |
25 | ltr bx |
195 | lidt [.idt] |
- | 196 | lgdt [.gdt] |
|
- | 197 | jmp 8:@f |
|
- | 198 | align 8 |
|
- | 199 | .gdt: |
|
- | 200 | ; selector 0 - not used |
|
- | 201 | dw 23 |
|
- | 202 | dd .gdt |
|
- | 203 | dw 0 |
|
- | 204 | ; selector 8 - code from 5000:0000 to 1000:FFFF |
|
- | 205 | dw 0FFFFh |
|
- | 206 | dw 0 |
|
- | 207 | db 5 |
|
- | 208 | db 10011011b |
|
- | 209 | db 00000000b |
|
- | 210 | db 0 |
|
- | 211 | ; selector 10h - data from 1000:0000 to 1000:FFFF |
|
- | 212 | dw 0FFFFh |
|
- | 213 | dw 0 |
|
- | 214 | db 1 |
|
- | 215 | db 10010011b |
|
- | 216 | db 00000000b |
|
- | 217 | db 0 |
|
- | 218 | .idt: |
|
- | 219 | dw 256*4 |
|
26 | lgdt [realmode_gdt-OS_BASE] |
220 | dd 0 |
27 | jmp 8:@f |
221 | org $ - 0x50000 |
28 | use16 |
222 | use16 |
29 | @@: |
223 | @@: |
30 | mov ax, 10h |
224 | mov ax, 10h |
31 | mov ds, ax |
225 | mov ds, ax |
32 | mov es, ax |
226 | mov es, ax |
33 | mov fs, ax |
227 | mov fs, ax |
- | 228 | mov gs, ax |
|
34 | mov gs, ax |
229 | mov ss, ax |
35 | mov ss, ax |
230 | |
36 | mov eax, cr0 |
231 | mov eax, cr0 |
37 | and eax, not 80000001h |
232 | and eax, not 80000001h |
Line -... | Line 233... | ||
- | 233 | mov cr0, eax |
|
38 | mov cr0, eax |
234 | jmp 0x5000:.real_mode |
Line 39... | Line 235... | ||
39 | jmp 0x1000:pr_mode_exit |
235 | |
- | 236 | align 4 |
|
40 | 237 | .real_mode: |
|
41 | pr_mode_exit: |
238 | |
42 | 239 | ; setup stack |
|
Line 43... | Line -... | ||
43 | ; setup stack |
- | |
44 | mov ax, (TMP_STACK_TOP and 0xF0000) shr 4 |
- | |
45 | mov ss, ax |
- | |
46 | mov esp, TMP_STACK_TOP and 0xFFFF |
- | |
47 | - | ||
48 | ;setup ds |
240 | |
49 | push cs |
241 | mov ax, (TMP_STACK_TOP and 0xF0000) shr 4 |
50 | pop ds |
242 | mov ss, ax |
51 | - | ||
52 | lidt [old_ints_h] |
243 | mov esp, TMP_STACK_TOP and 0xFFFF |
53 | ;remap IRQs |
- | |
Line 54... | Line 244... | ||
54 | mov al, 0x11 |
244 | |
55 | out 0x20, al |
245 | ;remap IRQs |
56 | call rdelay |
- | |
57 | out 0xA0, al |
246 | mov al, 0x11 |
58 | call rdelay |
247 | out 0x20, al |
59 | - | ||
Line 60... | Line 248... | ||
60 | mov al, 0x08 |
248 | out 0xA0, al |
61 | out 0x21, al |
249 | |
62 | call rdelay |
- | |
63 | mov al, 0x70 |
250 | mov al, 0x08 |
64 | out 0xA1, al |
251 | out 0x21, al |
65 | call rdelay |
- | |
Line 66... | Line 252... | ||
66 | 252 | mov al, 0x70 |
|
67 | mov al, 0x04 |
253 | out 0xA1, al |
68 | out 0x21, al |
- | |
69 | call rdelay |
254 | |
70 | mov al, 0x02 |
- | |
Line 71... | Line 255... | ||
71 | out 0xA1, al |
255 | mov al, 0x04 |
72 | call rdelay |
256 | out 0x21, al |
73 | - | ||
74 | mov al, 0x01 |
257 | mov al, 0x02 |
75 | out 0x21, al |
258 | out 0xA1, al |
76 | call rdelay |
- | |
Line -... | Line 259... | ||
- | 259 | ||
- | 260 | mov al, 0x01 |
|
- | 261 | out 0x21, al |
|
- | 262 | out 0xA1, al |
|
77 | out 0xA1, al |
263 | |
- | 264 | mov al, 0xB8 |
|
78 | call rdelay |
265 | out 0x21, al |
79 | 266 | mov al, 0xBD |
|
80 | mov al, 0xB8 |
267 | out 0xA1, al |
81 | out 0x21, al |
268 | |
82 | call rdelay |
269 | mov al, 00110100b |
83 | mov al, 0xBD |
- | |
84 | out 0xA1, al |
- | |
Line 85... | Line -... | ||
85 | sti |
- | |
86 | - | ||
87 | temp_3456: |
- | |
88 | xor ax, ax |
- | |
89 | mov es, ax |
- | |
90 | mov al, byte [es:0x9030] |
- | |
91 | cmp al, 1 |
- | |
92 | jl nbw |
- | |
93 | cmp al, 4 |
- | |
94 | jle nbw32 |
270 | out 43h, al |
95 | - | ||
96 | nbw: |
- | |
97 | in al, 0x60 |
- | |
98 | cmp al, 6 |
- | |
99 | jae nbw |
- | |
100 | mov bl, al |
- | |
101 | nbw2: |
- | |
102 | in al, 0x60 |
- | |
103 | cmp al, bl |
- | |
104 | je nbw2 |
- | |
105 | cmp al, 240;ax,240 |
- | |
106 | jne nbw31 |
- | |
107 | mov al, bl |
- | |
108 | dec ax |
- | |
109 | jmp nbw32 |
- | |
110 | nbw31: |
271 | mov al, 0xFF |
111 | add bl, 128 |
- | |
112 | cmp al, bl |
- | |
Line 113... | Line -... | ||
113 | jne nbw |
- | |
114 | sub al, 129 |
- | |
115 | - | ||
116 | nbw32: |
- | |
117 | - | ||
118 | dec ax |
- | |
119 | dec ax ; 2 = power off |
272 | out 40h, al |
120 | jnz no_apm_off |
273 | out 40h, al |
Line 121... | Line -... | ||
121 | call APM_PowerOff |
- | |
122 | jmp $ |
- | |
123 | no_apm_off: |
- | |
124 | - | ||
125 | if ~ defined extended_primary_loader ; kernel restarting is not supported |
274 | |
126 | dec ax ; 3 = reboot |
275 | xor ax, ax |
127 | jnz restart_kernel ; 4 = restart kernel |
276 | mov ds, ax |
128 | end if |
277 | mov al, [0x9030] |
129 | push 0x40 |
278 | cmp al, SYSTEM_RESTART |
130 | pop ds |
279 | je .restart |
Line 172... | Line 321... | ||
172 | mov ax, 0x5307 |
321 | mov ax, 0x5307 |
173 | mov bx, 1 |
322 | mov bx, 1 |
174 | mov cx, 3 |
323 | mov cx, 3 |
175 | int 0x15 |
324 | int 0x15 |
176 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
325 | ;!!!!!!!!!!!!!!!!!!!!!!!! |
177 | ret |
- | |
178 | - | ||
179 | if ~ defined extended_primary_loader |
- | |
180 | restart_kernel: |
- | |
181 | - | ||
182 | mov ax, 0x0003 ; set text mode for screen |
- | |
183 | int 0x10 |
- | |
184 | jmp 0x5000:0000 |
- | |
185 | - | ||
186 | restart_kernel_5001: |
- | |
187 | cli |
- | |
188 | - | ||
189 | push ds |
- | |
190 | pop es |
- | |
191 | xor si, si |
- | |
192 | xor di, di |
- | |
193 | - | ||
194 | push 0x7100 |
- | |
195 | pop ds |
- | |
196 | mov cx, 0x4000 |
- | |
197 | rep movsd |
- | |
198 | - | ||
199 | push 0x8100 |
- | |
200 | pop ds |
- | |
201 | push 0x2000 |
- | |
202 | pop es |
- | |
203 | mov cx, 0x4000 |
- | |
204 | rep movsd |
- | |
205 | - | ||
206 | push 0x9100 |
- | |
207 | pop ds |
- | |
208 | push 0x3000 |
- | |
209 | pop es |
- | |
210 | mov cx, 0x4000 |
- | |
211 | rep movsd |
- | |
212 | xchg bx, bx |
- | |
213 | push 0xA100 |
- | |
214 | pop ds |
- | |
215 | push 0x4000 |
- | |
216 | pop es |
326 | jmp $ |
217 | mov cx, 0x800 |
- | |
218 | rep movsd |
- | |
219 | - | ||
220 | wbinvd ; write and invalidate cache |
- | |
Line 221... | Line -... | ||
221 | - | ||
222 | mov al, 00110100b |
- | |
223 | out 43h, al |
- | |
224 | jcxz $+2 |
- | |
225 | mov al, 0xFF |
- | |
226 | out 40h, al |
- | |
227 | jcxz $+2 |
- | |
228 | out 40h, al |
- | |
229 | jcxz $+2 |
327 | |
Line 230... | Line 328... | ||
230 | sti |
328 | .restart: |
231 | 329 | ||
232 | ; (hint by Black_mirror) |
330 | ; (hint by Black_mirror) |
233 | ; We must read data from keyboard port, |
331 | ; We must read data from keyboard port, |
234 | ; because there may be situation when previous keyboard interrupt is lost |
332 | ; because there may be situation when previous keyboard interrupt is lost |
- | 333 | ; (due to return to real mode and IRQ reprogramming) |
|
- | 334 | ; and next interrupt will not be generated (as keyboard waits for handling) |
|
- | 335 | ||
- | 336 | mov cx, 16 |
|
- | 337 | @@: |
|
- | 338 | in al, 0x64 |
|
235 | ; (due to return to real mode and IRQ reprogramming) |
339 | test al, 1 |
- | 340 | jz @F |
|
- | 341 | in al, 0x60 |
|
Line 236... | Line 342... | ||
236 | ; and next interrupt will not be generated (as keyboard waits for handling) |
342 | loop @B |
237 | in al, 0x60 |
343 | @@: |
238 | 344 | ||
239 | ; bootloader interface |
345 | ; bootloader interface |
240 | push 0x1000 |
346 | push 0x1000 |
241 | pop ds |
347 | pop ds |
242 | mov si, kernel_restart_bootblock |
- | |
Line -... | Line 348... | ||
- | 348 | mov si, kernel_restart_bootblock |
|
- | 349 | mov ax, 'KL' |
|
- | 350 | jmp 0x1000:0000 |
|
- | 351 | ||
- | 352 | align 4 |
|
- | 353 | org restart_code_start + $ |