101289ec36fc530aebefa38085655d1d656b3339fHarry Liebel/** @file
201289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  Default exception handler
301289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
401289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  Copyright (c) 2014, ARM Limited. All rights reserved.
501289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
601289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  This program and the accompanying materials
701289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  are licensed and made available under the terms and conditions of the BSD
801289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  License which accompanies this distribution.  The full text of the license may
901289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  be found at http://opensource.org/licenses/bsd-license.php
1001289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
1101289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
1201289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
1301289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
1401289ec36fc530aebefa38085655d1d656b3339fHarry Liebel**/
1501289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
1601289ec36fc530aebefa38085655d1d656b3339fHarry Liebel#include <Base.h>
1701289ec36fc530aebefa38085655d1d656b3339fHarry Liebel#include <Library/BaseLib.h>
1801289ec36fc530aebefa38085655d1d656b3339fHarry Liebel#include <Library/PrintLib.h>
1901289ec36fc530aebefa38085655d1d656b3339fHarry Liebel#include <Library/ArmDisassemblerLib.h>
2001289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
2101289ec36fc530aebefa38085655d1d656b3339fHarry Liebel/**
2201289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  Place a disassembly of of **OpCodePtr into buffer, and update OpCodePtr to
2301289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  point to next instruction.
2401289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
2501289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  OpCodePtrPtr  Pointer to pointer of instruction to disassemble.
2601289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  Thumb         TRUE for Thumb(2), FALSE for ARM instruction stream
2701289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  Extended      TRUE dump hex for instruction too.
2801289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  ItBlock       Size of IT Block
2901289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  Buf           Buffer to sprintf disassembly into.
3001289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  @param  Size          Size of Buf in bytes.
3101289ec36fc530aebefa38085655d1d656b3339fHarry Liebel
3201289ec36fc530aebefa38085655d1d656b3339fHarry Liebel**/
3301289ec36fc530aebefa38085655d1d656b3339fHarry LiebelVOID
3401289ec36fc530aebefa38085655d1d656b3339fHarry LiebelDisassembleInstruction (
3501289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  IN  UINT8     **OpCodePtr,
3601289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  IN  BOOLEAN   Thumb,
3701289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  IN  BOOLEAN   Extended,
3801289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  IN OUT UINT32 *ItBlock,
3901289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  OUT CHAR8     *Buf,
4001289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  OUT UINTN     Size
4101289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  )
4201289ec36fc530aebefa38085655d1d656b3339fHarry Liebel{
4301289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  // Not yet supported for AArch64.
4401289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  // Put error in the buffer as we have no return code and the buffer may be
4501289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  // printed directly so needs a '\0'.
4601289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  AsciiSPrint (Buf, Size, "AArch64 not supported");
4701289ec36fc530aebefa38085655d1d656b3339fHarry Liebel  return;
4801289ec36fc530aebefa38085655d1d656b3339fHarry Liebel}
49