RDFU  1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
IdtGdt.c File Reference

Functions for IDT and GDT parsing. More...

#include "EfiScannerHeaders.h"
#include "EfiScannerLib.h"
Include dependency graph for IdtGdt.c:

Go to the source code of this file.

Classes

struct  _gdt_type_text
 

Macros

#define IDT_GET_BASE(IdtE)   (UINT_ARCH)(IdtE->OffsetLow | (IdtE->OffsetHigh << 16))
 

Typedefs

typedef struct _gdt_type_text gdt_type_text
 

Functions

EFI_STATUS DumpGDT (VOID)
 
idt_entry * GetIdtEntry (ULONG IdtVectorNum)
 
EFI_STATUS IdtHookInterrupt (C_PTR NewIntHandlerAddr, ULONG IdtVectorNum, C_PTR *OutOldIntAddr)
 
EFI_STATUS IdtHookTest (VOID)
 
EFI_STATUS DumpIDT (VOID)
 

Variables

const gdt_type_text GdtTypeText []
 

Detailed Description

Functions for IDT and GDT parsing.

Author
Piotr Bania
Date
Feb 2013 Functions for IDT and GDT parsing

Definition in file IdtGdt.c.

Macro Definition Documentation

#define IDT_GET_BASE (   IdtE)    (UINT_ARCH)(IdtE->OffsetLow | (IdtE->OffsetHigh << 16))

Definition at line 118 of file IdtGdt.c.

Referenced by DumpIDT(), and IdtHookInterrupt().

Typedef Documentation

typedef struct _gdt_type_text gdt_type_text

Function Documentation

EFI_STATUS DumpGDT ( VOID  )

Functions dump the GDT. (even on x64 efi platform the GDT entries are not extended - meaning the GDT format stays the same)

Return values
EFI_SUCCESS

Definition at line 56 of file IdtGdt.c.

References ASMGetGdtBase(), ASMGetGdtLimit(), _gdt_entry::Base0, _gdt_entry::Base1, _gdt_entry::Base2, _gdt_entry::DPL, _gdt_entry::LimitHigh, _gdt_entry::LimitLow, LogFullAscii(), _gdt_entry::Present, _gdt_entry::s, _gdt_entry::System, and _gdt_entry::Type.

Referenced by DrawBoxAndMenu(), ProcessCommand(), and TestDumpHandles().

57 {
58  UINTN i;
59  UINT_ARCH GdtBase, EntryBase;
60  USHORT GdtLimit;
61  ULONG EntryLimit;
62  gdt_entry *GdtEntry;
63 
64  GdtBase = ASMGetGdtBase();
65  GdtLimit = ASMGetGdtLimit();
66 
67  LogFullAscii("DumpGDT: base = %016lx Limit=%04x GdEntrySize=%x\r\n",
68  (MAX_PTR)GdtBase,
69  GdtLimit,
70  sizeof(gdt_entry));
71 
72  GdtEntry = (gdt_entry*)GdtBase;
73  for (i = 0; i < (GdtLimit/sizeof(gdt_entry)); i++, GdtEntry++)
74  {
75 
76  EntryBase = GdtEntry->s.Base0 | (GdtEntry->s.Base1 << 16) | (GdtEntry->s.Base2 << 24);
77  EntryLimit = GdtEntry->s.LimitLow | (GdtEntry->s.LimitHigh << 16);
78 
79 
80  LogFullAscii("%04d : base=%08x limit=%08x System=%02d DPL=%02d Present=%02d type=(%03d)%a\r\n",
81  i,
82  EntryBase,
83  EntryLimit,
84  GdtEntry->s.System,
85  GdtEntry->s.DPL,
86  GdtEntry->s.Present,
87  GdtEntry->s.Type,
88  &GdtTypeText[GdtEntry->s.Type]);
89 
90 
91  }
92 
93  return EFI_SUCCESS;
94 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS DumpIDT ( VOID  )

Functions dump the IDT. This function works with both x86 and x64. (on x64 the idt base calulation algo changes)

Return values
EFI_SUCCESS

Definition at line 191 of file IdtGdt.c.

References ASMGetIdtBase(), ASMGetIdtLimit(), idt_entry::Dpl, IDT_GET_BASE, LogFullAscii(), idt_entry::Present, idt_entry::SegmentSelector, and idt_entry::Type.

Referenced by DrawBoxAndMenu(), ProcessCommand(), and TestDumpHandles().

192 {
193 
194  UINTN i;
195  UINT_ARCH IdtBase, EntryBase;
196  USHORT IdtLimit;
197  idt_entry *IdtEntry;
198 
199  IdtBase = ASMGetIdtBase();
200  IdtLimit = ASMGetIdtLimit();
201 
202  IdtEntry = (idt_entry*)IdtBase;
203 
204 
205  LogFullAscii("%a: base = %016lx Limit=%04x GdEntrySize=%x\r\n",
206  __FUNCTION__,
207  (MAX_PTR)IdtBase,
208  IdtLimit,
209  sizeof(idt_entry));
210 
211 
212  for (i = 0; i < (IdtLimit/sizeof(idt_entry)); i++, IdtEntry++)
213  {
214 
215  EntryBase = IDT_GET_BASE(IdtEntry);
216 
217  LogFullAscii("%04d : base=%016lx Selector=%04x DPL=%02d Present=%02d Type=%04x\r\n",
218  i,
219  (MAX_PTR)EntryBase,
220  IdtEntry->SegmentSelector,
221  IdtEntry->Dpl,
222  IdtEntry->Present,
223  IdtEntry->Type);
224 
225  }
226 
227 
228 
229  return EFI_SUCCESS;
230 }

Here is the call graph for this function:

Here is the caller graph for this function:

idt_entry* GetIdtEntry ( ULONG  IdtVectorNum)

Returns IDT entry for selected entry.

Parameters
IdtVectorNumindex of wanted entry
Return values
ptrto idt_entry

Definition at line 106 of file IdtGdt.c.

References ASMGetIdtBase().

Referenced by IdtHookInterrupt().

107 {
108  idt_entry *IdtEntry;
109  IdtEntry = (idt_entry*)ASMGetIdtBase();
110  return &IdtEntry[IdtVectorNum];
111 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS IdtHookInterrupt ( C_PTR  NewIntHandlerAddr,
ULONG  IdtVectorNum,
C_PTR *  OutOldIntAddr 
)

Function hooks selected IDT entry (vector) and points it to the NewIntHandlerAddr (supplied by the requestor).

Parameters
NewIntHandlerAddrNew interrupt vector handler
IdtVectorNumSpecified vector number
OutOldIntAddrPointer to variable which will hold the old interrupt vector handler
Return values
EFI_SUCCESSOn success
EFI_ERROR*On error

Definition at line 137 of file IdtGdt.c.

References GetIdtEntry(), IDT_GET_BASE, LogFullAscii(), idt_entry::OffsetHigh, and idt_entry::OffsetLow.

Referenced by IdtHookTest().

138 {
139  UINT_ARCH OldBase;
140  idt_entry *IdtEntry;
141 
142  IdtEntry = GetIdtEntry(IdtVectorNum);
143  OldBase = IDT_GET_BASE(IdtEntry);
144 
145  *OutOldIntAddr = OldBase;
146 
147 #if DEBUG_ON == 1
148  LogFullAscii("%a: Interrupt: %d OldBase=%016lx NewBase=%016lx\r\n",
149  __FUNCTION__,
150  IdtVectorNum,
151  (MAX_PTR)OldBase,
152  (MAX_PTR)NewIntHandlerAddr);
153 #endif
154 
155  IdtEntry->OffsetHigh = (USHORT)(NewIntHandlerAddr >> 16);
156  IdtEntry->OffsetLow = (USHORT)(NewIntHandlerAddr & 0xFFFF);
157 
158 #if defined(_WIN64)
159  IdtEntry->HighOffset64 = (ULONG)((ULONG64)NewIntHandlerAddr >> 32);
160 #endif
161 
162 
163 #if DEBUG_ON == 1
164  LogFullAscii("IdtHookInterrupt: hooked!\r\n");
165 #endif
166 
167  return EFI_SUCCESS;
168 }

Here is the call graph for this function:

Here is the caller graph for this function:

EFI_STATUS IdtHookTest ( VOID  )

Definition at line 171 of file IdtGdt.c.

References ASMDbgBreak(), IdtHookInterrupt(), and Int03Handler().

172 {
173  ULONG64 OldAddr;
174 
175  IdtHookInterrupt((C_PTR)&Int03Handler, 3, (C_PTR*)&OldAddr);
176  ASMDbgBreak();
177 
178  return EFI_SUCCESS;
179 }

Here is the call graph for this function:

Variable Documentation

const gdt_type_text GdtTypeText[]
Initial value:
= {
{ "Data Read-Only" },
{ "Data Read-Only, accessed" },
{ "Data Read/Write" },
{ "Data Read/Write, accessed" },
{ "Data Read-Only, expand-down" },
{ "Data Read-Only, expand-down, accessed" },
{ "Data Read/Write, expand-down" },
{ "Data Read/Write, expand-down, accessed" },
{ "Code Execute-Only" },
{ "Code Execute-Only, accessed" },
{ "Code Execute/Read" },
{ "Code Execute/Read, accessed" },
{ "Code Execute-Only, conforming" },
{ "Code Execute-Only, conforming, accessed" },
{ "Code Execute/Read, conforming" },
{ "Code Execute/Read, conforming, accessed" },
{ 0 }
}

Ascii GDT entry type values.

Definition at line 26 of file IdtGdt.c.