<commit_before>/** @file
  CPU Exception library provides the default CPU interrupt/exception handler.
  It also provides capability to register user interrupt/exception handler.

  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef __CPU_EXCEPTION_HANDLER_LIB_H__
#define __CPU_EXCEPTION_HANDLER_LIB_H__

#include <Ppi/VectorHandoffInfo.h>
#include <Protocol/Cpu.h>

/**
  Initializes all CPU exceptions entries and provides the default exception handlers.
  
  Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
  If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. 
  If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.

  @param[in]  VectorInfo    Pointer to reserved vector list.
  
  @retval EFI_SUCCESS           CPU Exception Entries have been successfully initialized 
                                with default exception handlers.
  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
  @retval EFI_UNSUPPORTED       This function is not supported.

**/
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL
  );

/**
  Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.<commit_msg>MdeModulePkg/CpuExceptionHandlerLib.h: Add a new API InitializeCpuExceptionHandlersEx<commit_after>/** @file
  CPU Exception library provides the default CPU interrupt/exception handler.
  It also provides capability to register user interrupt/exception handler.

  Copyright (c) 2012 - 2017, Intel Corporation. All rights reserved.<BR>
  This program and the accompanying materials
  are licensed and made available under the terms and conditions of the BSD License
  which accompanies this distribution.  The full text of the license may be found at
  http://opensource.org/licenses/bsd-license.php

  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef __CPU_EXCEPTION_HANDLER_LIB_H__
#define __CPU_EXCEPTION_HANDLER_LIB_H__

#include <Ppi/VectorHandoffInfo.h>
#include <Protocol/Cpu.h>

#define CPU_EXCEPTION_INIT_DATA_REV     1

typedef union {
  struct {
    //
    // Revision number of this structure.
    //
    UINT32                    Revision;
    //
    // The address of top of known good stack reserved for *ALL* exceptions
    // listed in field StackSwitchExceptions.
    //
    UINTN                     KnownGoodStackTop;
    //
    // The size of known good stack for *ONE* exception only.
    //
    UINTN                     KnownGoodStackSize;
    //
    // Buffer of exception vector list for stack switch.
    //
    UINT8                     *StackSwitchExceptions;
    //
    // Number of exception vectors in StackSwitchExceptions.
    //
    UINTN                     StackSwitchExceptionNumber;
    //
    // Buffer of IDT table. It must be type of IA32_IDT_GATE_DESCRIPTOR.
    // Normally there's no need to change IDT table size.
    //
    VOID                      *IdtTable;
    //
    // Size of buffer for IdtTable.
    //
    UINTN                     IdtTableSize;
    //
    // Buffer of GDT table. It must be type of IA32_SEGMENT_DESCRIPTOR.
    //
    VOID                      *GdtTable;
    //
    // Size of buffer for GdtTable.
    //
    UINTN                     GdtTableSize;
    //
    // Pointer to start address of descriptor of exception task gate in the
    // GDT table. It must be type of IA32_TSS_DESCRIPTOR.
    //
    VOID                      *ExceptionTssDesc;
    //
    // Size of buffer for ExceptionTssDesc.
    //
    UINTN                     ExceptionTssDescSize;
    //
    // Buffer of task-state segment for exceptions. It must be type of
    // IA32_TASK_STATE_SEGMENT.
    //
    VOID                      *ExceptionTss;
    //
    // Size of buffer for ExceptionTss.
    //
    UINTN                     ExceptionTssSize;
    //
    // Flag to indicate if default handlers should be initialized or not.
    //
    BOOLEAN                   InitDefaultHandlers;
  } Ia32, X64;
} CPU_EXCEPTION_INIT_DATA;

/**
  Initializes all CPU exceptions entries and provides the default exception handlers.
  
  Caller should try to get an array of interrupt and/or exception vectors that are in use and need to
  persist by EFI_VECTOR_HANDOFF_INFO defined in PI 1.3 specification.
  If caller cannot get reserved vector list or it does not exists, set VectorInfo to NULL. 
  If VectorInfo is not NULL, the exception vectors will be initialized per vector attribute accordingly.

  @param[in]  VectorInfo    Pointer to reserved vector list.
  
  @retval EFI_SUCCESS           CPU Exception Entries have been successfully initialized 
                                with default exception handlers.
  @retval EFI_INVALID_PARAMETER VectorInfo includes the invalid content if VectorInfo is not NULL.
  @retval EFI_UNSUPPORTED       This function is not supported.

**/
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlers (
  IN EFI_VECTOR_HANDOFF_INFO       *VectorInfo OPTIONAL
  );

/**
  Initializes all CPU exceptions entries with optional extra initializations.

  By default, this method should include all functionalities implemented by
  InitializeCpuExceptionHandlers(), plus extra initialization works, if any.
  This could be done by calling InitializeCpuExceptionHandlers() directly
  in this method besides the extra works.

  InitData is optional and its use and content are processor arch dependent.
  The typical usage of it is to convey resources which have to be reserved
  elsewhere and are necessary for the extra initializations of exception.

  @param[in]  VectorInfo    Pointer to reserved vector list.
  @param[in]  InitData      Pointer to data optional for extra initializations
                            of exception.

  @retval EFI_SUCCESS             The exceptions have been successfully
                                  initialized.
  @retval EFI_INVALID_PARAMETER   VectorInfo or InitData contains invalid
                                  content.
  @retval EFI_UNSUPPORTED         This function is not supported.

**/
EFI_STATUS
EFIAPI
InitializeCpuExceptionHandlersEx (
  IN EFI_VECTOR_HANDOFF_INFO            *VectorInfo OPTIONAL,
  IN CPU_EXCEPTION_INIT_DATA            *InitData OPTIONAL
  );

/**
  Initializes all CPU interrupt/exceptions entries and provides the default interrupt/exception handlers.
{'fraction_non_alphanumeric': 0.04903751580722215, 'fraction_numerical': 0.005058311086131797, 'mean_word_length': 2.6022267206477734, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3396843', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1840, 'n_words': 753}