claymation / osxp

EFI boot loader for running Windows XP on Intel Macs, from the 2006 Windows On Mac hacker challenge

This URL has Read+Write access

osxp / thunk.c
100644 73 lines (63 sloc) 1.408 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* EFI library includes */
#include <EfiBind.h>
#include <EfiTypes.h>
#include <EfiCommon.h>
#include <EfiApi.h>
#include <EfiDriverLib.h>
#include <EfiDevicePath.h>
 
#include "OSXP.h"
#include "thunk.h"
 
/* A stack for real mode code to use. */
UINT16 RealStack[2048];
 
SegmentDescriptor RealGDT[] = {
  { // Selector 0x00 - NULL
    0, // LimitLow
    0, // BaseLow
    0, // BaseMid
    0, // Attribute
    0, // LimitHi
    0 // BaseHi
  },
  { // Selector 0x08 - NULL
    0, // LimitLow
    0, // BaseLow
    0, // BaseMid
    0, // Attribute
    0, // LimitHi
    0 // BaseHi
  },
  { // Selector 0x10 - Real Code
    0xffff, // LimitLow
    0x0000, // BaseLow
    0x00, // BaseMid
    0x9a, // Attribute
    0x0f, // LimitHi
    0x00 // BaseHi
  },
  { // Selector 0x18 - Real Data
    0xffff, // LimitLow
    0x0000, // BaseLow
    0x00, // BaseMid
    0x92, // Attribute
    0x8f, // LimitHi
    0x00 // BaseHi
  }
};
 
SystemTableRegister ProtectedIDTR;
SystemTableRegister ProtectedGDTR;
UINT32 ProtectedESP;
 
SystemTableRegister RealIDTR = {
    0x3FFF, // Limit
    0x0 // Base
};
 
SystemTableRegister RealGDTR = {
    sizeof(RealGDT) - 1, // Limit
    (UINT32) &RealGDT // Base
};
 
EFI_TPL ProtectedTPL;
 
void ThunkMBR()
{
    ProtectedTPL = gBS->RaiseTPL(EFI_TPL_HIGH_LEVEL);
    asmThunk();
    gBS->RestoreTPL(ProtectedTPL);
}