UEFIStarter
a simple UEFI framework
Data Structures | Macros | Functions
cpuid.c File Reference

This application will show some information about the CPU. More...

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <UEFIStarter/core.h>

Data Structures

struct  idt_reg_t
 data type for interrupt descriptor table metadata More...
 

Macros

#define CI(NAME, REGISTER, BIT)   Print(L ## #NAME ": %d\n",(REGISTER&1<<BIT)>0)
 helper macro to quickly output a CPUID flag More...
 

Functions

void cpuid ()
 Prints the CPU's vendor ID and a few of the capability flags.
 
UINT64 rdmsr (UINT64 rcx)
 Reads a CPU's model-specific register. More...
 
void read_msrs ()
 Prints a selection of model-specific CPU registers. More...
 
void handler ()
 Interrupt handler, this will be registered by test_idt() and should get called when signalling the interrupt there. More...
 
void write_idt_entry_address (void *entry_base, void *func)
 Writes an interrupt handler address into the IDT. More...
 
void test_idt ()
 Tests whether interrupt handlers can be registered. More...
 
INTN EFIAPI ShellAppMain (UINTN argc, CHAR16 **argv)
 Main function, gets invoked by UEFI shell. More...
 

Detailed Description

This application will show some information about the CPU.

Author
Richard Nusser
License
GPLv3 (see http://www.gnu.org/licenses/)
See also
https://github.com/rinusser/UEFIStarter

Macro Definition Documentation

◆ CI

#define CI (   NAME,
  REGISTER,
  BIT 
)    Print(L ## #NAME ": %d\n",(REGISTER&1<<BIT)>0)

helper macro to quickly output a CPUID flag

Parameters
NAMEthe flag's name
REGISTERthe variable to read from
BITthe flag's bit offset

Function Documentation

◆ rdmsr()

UINT64 rdmsr ( UINT64  rcx)

Reads a CPU's model-specific register.

Parameters
rcxthe register selector for the RDMSR instruction
Returns
the register's value

◆ read_msrs()

void read_msrs ( )

Prints a selection of model-specific CPU registers.

Currently the selection is very narrow: the function just prints the APIC base address.

◆ handler()

void handler ( )

Interrupt handler, this will be registered by test_idt() and should get called when signalling the interrupt there.

This will set rax (the return register) to the current instruction pointer.

◆ write_idt_entry_address()

void write_idt_entry_address ( void *  entry_base,
void *  func 
)

Writes an interrupt handler address into the IDT.

Parameters
entry_basethe start of the IDT entry to write to
functhe handler's address

◆ test_idt()

void test_idt ( )

Tests whether interrupt handlers can be registered.

This will register handler() as the handling function for INT 3, then signal INT 3. The handler should get called and should return its instruction pointer (which should be very close to handler()'s address). This function checks the returned instruction pointer.

◆ ShellAppMain()

INTN EFIAPI ShellAppMain ( UINTN  argc,
CHAR16 **  argv 
)

Main function, gets invoked by UEFI shell.

Parameters
argcthe number of command-line arguments passed
argvthe command-line arguments passed
Returns
an EFI status code for the shell