[FREELDR] Minor code maintenance.
[reactos.git] / boot / freeldr / freeldr / include / arch / pc / x86common.h
1
2 #ifndef HEX
3 #define HEX(y) 0x##y
4 #endif
5
6 /* Memory layout */
7 #ifdef _M_AMD64
8 #define PML4_ADDRESS HEX(1000) /* One page PML4 page table */
9 #define PDP_ADDRESS HEX(2000) /* One page PDP page table */
10 #define PD_ADDRESS HEX(3000) /* One page PD page table */
11 #endif
12 #define BIOSCALLBUFFER HEX(4000) /* Buffer to store temporary data for any Int386() call */
13 #define STACK16ADDR HEX(6F00) /* The 16-bit stack top will be at 0000:6F00 */
14 #define BSS_START HEX(6F00)
15 #define STACKLOW HEX(7000)
16 #define STACKADDR HEX(F000) /* The 32/64-bit stack top will be at 0000:F000, or 0xF000 */
17 #define FREELDR_BASE HEX(F800)
18 #define FREELDR_PE_BASE HEX(10000)
19 #define MEMORY_MARGIN HEX(88000) /* We need this much memory */
20
21 #define BIOSCALLBUFSEGMENT (BIOSCALLBUFFER/16) /* Buffer to store temporary data for any Int386() call */
22 #define BIOSCALLBUFOFFSET HEX(0000) /* Buffer to store temporary data for any Int386() call */
23 #define BIOSCALLBUFSIZE PAGE_SIZE /* max is sizeof(VESA_SVGA_INFO) = 512 */
24 #define MAX_FREELDR_PE_SIZE (MEMORY_MARGIN - FREELDR_PE_BASE - PAGE_SIZE)
25
26 /* MAX_DISKREADBUFFER_SIZE is later passed to INT 13h, AH=42h.
27 According to https://en.wikipedia.org/wiki/INT_13H#INT_13h_AH.3D42h:_Extended_Read_Sectors_From_Drive
28 some BIOSes can only read a maximum of 127 sectors. (0xFE00 / 512 = 127)
29 Confirmed when booting from USB on Dell Latitude D531 and Lenovo ThinkPad X61. */
30 #define MAX_DISKREADBUFFER_SIZE HEX(FE00)
31
32 /* These addresses specify the realmode "BSS section" layout */
33 #define BSS_RealModeEntry (BSS_START + 0)
34 #define BSS_CallbackReturn (BSS_START + 4)
35 #define BSS_RegisterSet (BSS_START + 8) /* size = 40 */
36 #define BSS_IntVector (BSS_START + 52)
37 #define BSS_PxeEntryPoint (BSS_START + 56)
38 #define BSS_PxeBufferSegment (BSS_START + 60)
39 #define BSS_PxeBufferOffset (BSS_START + 64)
40 #define BSS_PxeFunction (BSS_START + 68)
41 #define BSS_PxeResult (BSS_START + 72)
42 #define BSS_PnpBiosEntryPoint (BSS_START + 76)
43 #define BSS_PnpBiosDataSegment (BSS_START + 80)
44 #define BSS_PnpBiosBufferSegment (BSS_START + 84)
45 #define BSS_PnpBiosBufferOffset (BSS_START + 88)
46 #define BSS_PnpNodeSize (BSS_START + 92)
47 #define BSS_PnpNodeCount (BSS_START + 96)
48 #define BSS_PnpNodeNumber (BSS_START + 100)
49 #define BSS_PnpResult (BSS_START + 104)
50 #define BSS_BootDrive (BSS_START + 108) // 1 byte
51 #define BSS_BootPartition (BSS_START + 109) // 1 byte
52
53
54 /* Realmode function IDs */
55 #define FNID_Int386 0
56 #define FNID_Reboot 1
57 #define FNID_ChainLoadBiosBootSectorCode 2
58 #define FNID_PxeCallApi 3
59 #define FNID_PnpBiosGetDeviceNodeCount 4
60 #define FNID_PnpBiosGetDeviceNode 5
61 #define FNID_BootLinuxKernel 6
62
63 /* Flag Masks */
64 #define CR0_PE_SET HEX(00000001) /* OR this value with CR0 to enable pmode */
65 #define CR0_PE_CLR HEX(FFFFFFFE) /* AND this value with CR0 to disable pmode */
66
67 /* Defines needed for switching between real and protected mode */
68 //#ifdef _M_IX86
69 #define NULL_DESC HEX(00) /* NULL descriptor */
70 #define PMODE_CS HEX(08) /* PMode code selector, base 0 limit 4g */
71 #define PMODE_DS HEX(10) /* PMode data selector, base 0 limit 4g */
72 #define RMODE_CS HEX(18) /* RMode code selector, base 0 limit 64k */
73 #define RMODE_DS HEX(20) /* RMode data selector, base 0 limit 64k */
74 //#else
75 /* Long mode selectors */
76 #define LMODE_CS HEX(10)
77 #define LMODE_DS HEX(18)
78 #define CMODE_CS HEX(30)
79 //#endif
80
81 /* Makes "x" a global variable or label */
82 #define EXTERN(x) .global x; x: