📄 parser.cpp
字号:
/* -*- C++ -*- */
/**
* Copyright (c) 2005 Zhejiang University, P.R.China
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
///==================================================
/**
* @file Parser.cpp
* @brief
* @author Chenfeng Zhou <ini_autumn@163.com>
*
* Created : <2005-03-02 16:31:44 by Cheney Chow>
* Last update: <2005-03-02 16:54:18 by Cheney Chow>
*
* $Id: Parser.cpp,v 1.1 2005/06/16 06:01:50 qilj Exp $
*/
///==================================================
#include "Parser.h"
namespace PPC
{
void D_Form_Parser::parse_simm (PPC_Instr_T instr,
PPC_s32 &D, PPC_s32 &A, PPC_u32 &SImm)
{
D = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
SImm = instr & 0xffff;
//! Test if it's negative;
if (SImm & 0x8000)
SImm |= 0xffff0000; //! < Sign extend
}
void D_Form_Parser::parse_uimm (PPC_Instr_T instr,
PPC_s32 &D, PPC_s32 &A, PPC_u32 &UImm)
{
D = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
UImm = instr & 0xffff;
}
void D_Form_Parser::parse_shift16 (PPC_Instr_T instr,
PPC_s32 &D, PPC_s32 &A, PPC_u32 &Imm16)
{
D = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
Imm16 = instr << 16;
}
void X_Form_Parser::parse_x (PPC_Instr_T instr,
PPC_s32 &S, PPC_s32 &A, PPC_s32 &B)
{
S = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
B = (instr >> 11) & 0x1f;
}
void X_Form_Parser::parse_xfx (PPC_Instr_T instr,
PPC_s32 &S, PPC_u32 &crm)
{
S = (instr >> 21) & 0x1f;
crm = (instr >> 12) & 0xff;
}
void X_Form_Parser::parse_xo (PPC_Instr_T instr,
PPC_s32 &D, PPC_s32 &A, PPC_s32 &B)
{
D = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
B = (instr >> 11) & 0x1f;
}
void X_Form_Parser::parse_xl (PPC_Instr_T instr,
PPC_u32 &BO, PPC_u32 &BI, PPC_u32 &BD)
{
BO = (instr >> 21) & 0x1f;
BI = (instr >> 16) & 0x1f;
BD = (instr >> 11) & 0x1f;
}
void X_Form_Parser::parse_xfl (PPC_Instr_T instr,
PPC_s32 &B, PPC_u32 &fm)
{
B = (instr >> 11) & 0x1f;
fm = (instr >> 17) & 0xff;
}
void I_Form_Parser::parse (PPC_Instr_T instr, PPC_u32 &LI)
{
LI = instr & 0x3fffffc;
if (LI & 0x02000000)
LI |= 0xfc000000;
}
void B_Form_Parser::parse (PPC_Instr_T instr, PPC_u32 &BO, PPC_u32 &BD, PPC_u32 &BI)
{
BO = (instr >> 21) & 0x1f;
BI = (instr >> 16) & 0x1f;
BD = instr & 0xfffc;
if (BD & 0x8000)
BD |= 0xffff0000;
}
void A_Form_Parser::parse (PPC_Instr_T instr,
PPC_s32 &D, PPC_s32 &A, PPC_s32 &B, PPC_s32 &C)
{
D = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
B = (instr >> 11) & 0x1f;
C = (instr >> 6) & 0x1f;
}
void M_Form_Parser::parse (PPC_Instr_T instr,
PPC_s32 &S, PPC_s32 &A, PPC_s32 &SH,
PPC_s32 &MB, PPC_s32 &ME)
{
S = (instr >> 21) & 0x1f;
A = (instr >> 16) & 0x1f;
SH = (instr >> 11) & 0x1f;
MB = (instr >> 6) & 0x1f;
ME = (instr >> 1) & 0x1f;
}
} // namespace PPC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -