1 | ; $Id: pmode.inc 69500 2017-10-28 15:14:05Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; Enter and exit a minimal protected-mode environment.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2004-2017 Oracle Corporation
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | ; available from http://www.virtualbox.org. This file is free software;
|
---|
11 | ; you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | ; General Public License (GPL) as published by the Free Software
|
---|
13 | ; Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | ; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | ; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | ;
|
---|
17 |
|
---|
18 | ;; Caveats: May only be called from the F000 segment (16-bit). Does not
|
---|
19 | ;; switch stacks. Must be run with disabled interrupts(!), any exceptions
|
---|
20 | ;; will cause a crash. On return from pmode_enter, DS contains a selector
|
---|
21 | ;; which can address the entire 4GB address space.
|
---|
22 |
|
---|
23 | public pmode_enter
|
---|
24 | public pmode_exit
|
---|
25 | public pmbios_gdt_desc
|
---|
26 | public pmbios_gdt
|
---|
27 |
|
---|
28 | pmode_enter proc near
|
---|
29 |
|
---|
30 | push cs
|
---|
31 | pop ds
|
---|
32 | .386p
|
---|
33 | lgdt fword ptr [pmbios_gdt_desc]
|
---|
34 | mov eax, cr0
|
---|
35 | or al, 1
|
---|
36 | mov cr0, eax
|
---|
37 | ; jmp far ptr 20h:really_enter_pm
|
---|
38 | db 0EAh
|
---|
39 | dw really_enter_pm
|
---|
40 | dw 20h
|
---|
41 | really_enter_pm:
|
---|
42 | mov ax, 18h
|
---|
43 | mov ds, ax
|
---|
44 | ret
|
---|
45 |
|
---|
46 | pmode_enter endp
|
---|
47 |
|
---|
48 |
|
---|
49 | pmode_exit proc near
|
---|
50 |
|
---|
51 | mov ax, 40h ; Ensure RM limit/attributes
|
---|
52 | mov ds, ax ; (where base = selector << 4)
|
---|
53 |
|
---|
54 | mov eax, cr0
|
---|
55 | and al, 0FEh
|
---|
56 | mov cr0, eax
|
---|
57 | SET_DEFAULT_CPU_286
|
---|
58 | jmp far ptr really_exit_pm
|
---|
59 | really_exit_pm:
|
---|
60 | ret
|
---|
61 |
|
---|
62 | pmode_exit endp
|
---|
63 |
|
---|
64 |
|
---|
65 |
|
---|
66 | pmbios_gdt_desc:
|
---|
67 | dw 40h + 7 ; last selector plus 8 - 1
|
---|
68 | dw pmbios_gdt
|
---|
69 | dw 000Fh
|
---|
70 |
|
---|
71 | pmbios_gdt:
|
---|
72 | dw 0, 0, 0, 0
|
---|
73 | dw 0, 0, 0, 0
|
---|
74 | dw 0ffffh, 0, 9b00h, 00cfh ; 32-bit code (0x10)
|
---|
75 | dw 0ffffh, 0, 9300h, 00cfh ; 32-bit data (0x18)
|
---|
76 | dw 0ffffh, 0, 9b0fh, 0000h ; 16-bit code, base=0xf0000
|
---|
77 | dw 0ffffh, 0, 9300h, 0000h ; 16-bit data, base=0x0
|
---|
78 | dw 0, 0, 0, 0
|
---|
79 | dw 0, 0, 0, 0
|
---|
80 | dw 0ffffh, 400h, 9300h, 0000h ; 16-bit data, base=0x40
|
---|
81 |
|
---|