1;; @file
2;  This is the code that goes from real-mode to protected mode.
3;  It consumes the reset vector, configures the stack.
4;
5; Copyright (c) 2015 - 2019, Intel Corporation. All rights reserved.<BR>
6; SPDX-License-Identifier: BSD-2-Clause-Patent
7;;
8
9;
10; Define assembler characteristics
11;
12
13extern   ASM_PFX(TempRamInitApi)
14
15SECTION .text
16
17%macro RET_ESI  0
18
19  movd    esi, mm7                      ; restore ESP from MM7
20  jmp     esi
21
22%endmacro
23
24;
25; Perform early platform initialization
26;
27global ASM_PFX(SecPlatformInit)
28ASM_PFX(SecPlatformInit):
29
30  RET_ESI
31
32;
33; Protected mode portion initializes stack, configures cache, and calls C entry point
34;
35
36;----------------------------------------------------------------------------
37;
38; Procedure:    ProtectedModeEntryPoint
39;
40; Input:        Executing in 32 Bit Protected (flat) mode
41;               cs: 0-4GB
42;               ds: 0-4GB
43;               es: 0-4GB
44;               fs: 0-4GB
45;               gs: 0-4GB
46;               ss: 0-4GB
47;
48; Output:       This function never returns
49;
50; Destroys:
51;               ecx
52;               edi
53;               esi
54;               esp
55;
56; Description:
57;               Perform any essential early platform initialisation
58;               Setup a stack
59;
60;----------------------------------------------------------------------------
61global ASM_PFX(ProtectedModeEntryPoint)
62ASM_PFX(ProtectedModeEntryPoint):
63  ;
64  ; Dummy function. Consume 2 API to make sure they can be linked.
65  ;
66  mov  eax, ASM_PFX(TempRamInitApi)
67
68  ; Should never return
69  jmp  $
70
71;
72; ROM-based Global-Descriptor Table for the PEI Phase
73;
74align 16
75global  ASM_PFX(BootGdtTable)
76
77;
78; GDT[0]: 0x00: Null entry, never used.
79;
80NULL_SEL        equ     $ - GDT_BASE        ; Selector [0]
81GDT_BASE:
82ASM_PFX(BootGdtTable):    DD      0
83                          DD      0
84;
85; Linear code segment descriptor
86;
87LINEAR_CODE_SEL equ     $ - GDT_BASE        ; Selector [0x8]
88        DW      0FFFFh                      ; limit 0xFFFF
89        DW      0                           ; base 0
90        DB      0
91        DB      09Bh                        ; present, ring 0, data, expand-up, not-writable
92        DB      0CFh                        ; page-granular, 32-bit
93        DB      0
94;
95; System data segment descriptor
96;
97SYS_DATA_SEL    equ     $ - GDT_BASE        ; Selector [0x10]
98        DW      0FFFFh                      ; limit 0xFFFF
99        DW      0                           ; base 0
100        DB      0
101        DB      093h                        ; present, ring 0, data, expand-up, not-writable
102        DB      0CFh                        ; page-granular, 32-bit
103        DB      0
104
105GDT_SIZE        EQU     $ - GDT_BASE        ; Size, in bytes
106
107;
108; GDT Descriptor
109;
110GdtDesc:                                    ; GDT descriptor
111        DW      GDT_SIZE - 1                ; GDT limit
112        DD      GDT_BASE                    ; GDT base address
113
114global ASM_PFX(ProtectedModeEntryLinearAddress)
115global ASM_PFX(ProtectedModeEntryLinearOffset)
116
117ASM_PFX(ProtectedModeEntryLinearAddress):
118ASM_PFX(ProtectedModeEntryLinearOffset):
119  DD      ASM_PFX(ProtectedModeEntryPoint)  ; Offset of our 32 bit code
120  DW      LINEAR_CODE_SEL
121
122