📄 board.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 Board.cpp
* @brief
* @author Chenfeng Zhou <ini_autumn@163.com>
*
* Created : <2005-02-24 18:55:51 by Cheney Chow>
* Last update: <2005-02-24 19:13:35 by Cheney Chow>
* $Id: Board.cpp,v 1.1 2005/06/16 06:01:43 qilj Exp $
*/
///==================================================
#include "Core/System.h"
#include "Core/Memory.h"
#include "Core/Helper.h"
#include "Core/ConfigFile.h"
#include "Board.h"
#include "Utils/Debug.h"
#include "Reg_Utils.h"
#include "Utils/Logger.h"
namespace PPC
{
void PPC_Board::on_create ()
{
name_ = "PPC_Board";
Core::Board_32Bit::on_create ();
}
void PPC_Board::on_destroy()
{}
void PPC_Board::io_do_cycle ()
{}
Core::Interrupt_Type PPC_Board::get_highest_interrupt ()
{
return 0;
}
bool PPC_Board::load_fs(std::string name, Core::u32 addr)
{
std::string filepath = Core::Host_Machine::gen_fullpath(Core::Host_Machine::get_image_path("PPC"), name);
std::ifstream fs((const char *)filepath.c_str(), std::ios::binary);
if (fs.fail())
{
return false;
}
Core::Bytecode_Type buffer;
char ch;
while(fs.get(ch))
{
buffer.push_back(ch);
}
PPC_CPU *cpu = (PPC_CPU *)Core::Wukong_Get_System().get_cpu();
cpu->get_mmu().access(Core::Memory_32Bit::MEMORY_WRITE, addr, buffer.size(), buffer);
return true;
}
bool PPC_Board::prepare_rom ()
{
std::string arch_name = Core::Wukong_Get_System().get_arch_name();
std::string conf_file = Core::Wukong_Get_System().get_conf_name();
std::string fs_name = "";
Core::u32 fs_addr = 0;
Core::Wukong_Get_System().load_config(arch_name, conf_file);
Core::Config_File * cf = Core::Wukong_Get_System().get_config();
cf->read("/filesystem/name", fs_name);
cf->read("/filesystem/address", fs_addr);
load_fs(fs_name, fs_addr);
return true;
}
Core::Memory_Result PPC_Board::io_dispatch(Core::Memory_Access_Type type, Core::u32 start,
size_t size, Core::Bytecode_Type & buffer)
{
switch(type)
{
case Core::Memory_32Bit::MEMORY_READ:
return io_read(start, size, buffer);
case Core::Memory_32Bit::MEMORY_WRITE:
return io_write(start, size, buffer);
default:
return Core::Dummy_MMU<Core::u32>::MEMORY_ACCESS_VIOLATION;
}
}
Core::Memory_Result PPC_Board::io_read(Core::u32 start, size_t size, Core::Bytecode_Type & buffer)
{
if (start >= UART_START && start < UART_END) {
PPC_SHOW("UART0 read\n");
}
else if (start >= RTC_START && start < RTC_END) {
PPC_SHOW("RTC read\n");
}
else {
PPC_SHOW("unhandled device read\n");
}
buffer.resize(size);
return Core::Dummy_MMU<Core::u32>::MEMORY_SUCCESSFUL;
}
Core::Memory_Result PPC_Board::io_write(Core::u32 start, size_t size, Core::Bytecode_Type & buffer)
{
if (start >= UART_START && start < UART_END) {
PPC_SHOW("UART0 write\n");
Core::u8 byte = 0;
switch( start & 0x7 ) {
case 0:
Core::Wukong_Get_System().convert_from_bytecode(buffer, byte);
//printf("%c", byte);
WUKONG_STDOUT<<(char)byte;
WUKONG_STDOUT.flush();
break;
default:
break;
}
}
else if (start >= RTC_START && start < RTC_END) {
PPC_SHOW("RTC write\n");
}
else if (start >= UCOS_IO_START && start < UCOS_IO_END) {
Core::u32 word = 0;
Core::Wukong_Get_System().convert_from_bytecode(buffer, word);
//printf("%c", (char)word);
WUKONG_STDOUT<<(char)word;
WUKONG_STDOUT.flush();
}
else {
PPC_SHOW("unhandled device write\n");
}
return 0;
}
} // namespace PPC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -