⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logger.cpp

📁 浙江大学的悟空嵌入式系统模拟器
💻 CPP
字号:
/**
 *  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        Logger.cpp
 * @brief      
 * @author      Chenfeng Zhou <ini_autumn@163.com> 
 *
 * Created    : <2005-04-04 20:28:36 by Cheney Chow>
 * Last update: <2005-04-04 20:34:40 by Cheney Chow>
 *
 * $Id: Logger.cpp,v 1.1 2005/06/16 06:06:36 qilj Exp $
 */
///==================================================

#include <cstdio>
#include "Core/System.h"

#include "CPU.h"
#include "Register.h"
#include "Logger.h"

namespace PPC
{
	S_Logger::S_Logger() : enable_trace_(false) {}

	S_Logger::~S_Logger()
	{
		fclose(log_);
	}

    int S_Logger::init_logfile (std::string file)
    {
        log_ = fopen(file.c_str(), "w+");
		
        return (log_ == NULL)? -1 : 0;
    }

    void S_Logger::dump_cpu_state ()
    {

		if (!is_tracing()) 
			return;

		PPC_CPU *cpu = (PPC_CPU*)Core::Wukong_Get_System().get_cpu();

        fprintf(log_, "************************************************\n");
		fprintf(log_, "ops: %d\n", cpu->get_cpu_state().ops);
		fprintf(log_, "PC: 0x%x	INSTR: 0x%8x\n", cpu->get_pc(), cpu->get_current_instr());
		fprintf(log_, "r0~r7:   0x%x 0x%x 0x%x 0x%x	0x%x 0x%x 0x%x 0x%x\n"
					  "r8~r15:  0x%x 0x%x 0x%x 0x%x	0x%x 0x%x 0x%x 0x%x\n"
					  "r16~r23: 0x%x 0x%x 0x%x 0x%x	0x%x 0x%x 0x%x 0x%x\n"
					  "r24~r31: 0x%x 0x%x 0x%x 0x%x	0x%x 0x%x 0x%x 0x%x\n"
					  "CR: 0x%x  LR: 0x%x  XER: 0x%x  CTR: 0x%x\n"
					  "MSR: 0x%x SRR0: 0x%x SRR1: 0x%x\n"
					  "enable_ee: %u  pdec: %ld\n",
				cpu->get_register(GPR0).convert_to_int(), cpu->get_register(GPR1).convert_to_int(),
				cpu->get_register(GPR2).convert_to_int(), cpu->get_register(GPR3).convert_to_int(),
				cpu->get_register(GPR4).convert_to_int(), cpu->get_register(GPR5).convert_to_int(),
				cpu->get_register(GPR6).convert_to_int(), cpu->get_register(GPR7).convert_to_int(),
				cpu->get_register(GPR8).convert_to_int(), cpu->get_register(GPR9).convert_to_int(),
				cpu->get_register(GPR10).convert_to_int(), cpu->get_register(GPR11).convert_to_int(),
				cpu->get_register(GPR12).convert_to_int(), cpu->get_register(GPR13).convert_to_int(),
				cpu->get_register(GPR14).convert_to_int(), cpu->get_register(GPR15).convert_to_int(),
				cpu->get_register(GPR16).convert_to_int(), cpu->get_register(GPR17).convert_to_int(),
				cpu->get_register(GPR18).convert_to_int(), cpu->get_register(GPR19).convert_to_int(),
				cpu->get_register(GPR20).convert_to_int(), cpu->get_register(GPR21).convert_to_int(),
				cpu->get_register(GPR22).convert_to_int(), cpu->get_register(GPR23).convert_to_int(),
				cpu->get_register(GPR24).convert_to_int(), cpu->get_register(GPR25).convert_to_int(),
				cpu->get_register(GPR26).convert_to_int(), cpu->get_register(GPR27).convert_to_int(),
				cpu->get_register(GPR28).convert_to_int(), cpu->get_register(GPR29).convert_to_int(),
				cpu->get_register(GPR30).convert_to_int(), cpu->get_register(GPR31).convert_to_int(),
				cpu->get_register(CR).convert_to_int(), cpu->get_register(LR).convert_to_int(),
				cpu->get_register(XER).convert_to_int(), cpu->get_register(CTR).convert_to_int(),
				cpu->get_register(MSR).convert_to_int(), cpu->get_register(SRR0).convert_to_int(),
				cpu->get_register(SRR1).convert_to_int(), cpu->get_cpu_state().enable_ee,
				cpu->get_cpu_state().pdec);

		fflush(log_);
    }

	void S_Logger::dump_mem(Core::u32 start, Core::u32 size)
	{

		if (!is_tracing()) 
			return;

		Core::Bytecode_Type buffer;

		Core::MMU<Core::u32>& mmu = ((Core::CPU<Core::u32>*)(Core::Wukong_Get_System().get_cpu()))->get_mmu();
		
		fprintf(log_, "********************************************************\n");
		if (mmu.access(Core::Memory<Core::u32>::MEMORY_READ, start, size, buffer) < 0) {
			fprintf(log_, "mem access violation!\n");
			return;
		}

		for (size_t i = 0; i < size;) {
			if ( i % 8 == 0)
				fprintf(log_, "0x%32x:", start + i);

			fprintf(log_, "%2x%2x ", buffer[i], buffer[i + 1]);
			i += 2;

			if ( i % 8 == 0)
				fprintf(log_, "\n");
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -