📄 boot_loader.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 Boot_loader.cpp
* @brief
* @author Chenfeng Zhou <ini_autumn@163.com>
*
* Created : <2005-04-06 14:59:00 by Cheney Chow>
* Last update: <2005-04-06 15:01:34 by Cheney Chow>
*
* $Id: Boot_loader.cpp,v 1.1 2005/06/16 06:01:43 qilj Exp $
*/
///==================================================
#include <cstdio>
#include "Boot_loader.h"
#include "Utils/Debug.h"
#include "Core/Global.h"
#include "Core/Processor.h"
namespace PPC
{
int Boot_Loader::load_kernel (const std::string &kernel_file)
{
std::vector<Core::u8> buffer;
int kernel_size;
if ( (kernel_size = load_file(kernel_file, buffer)) < 0)
PPC_ERROR_FAIL(("Load kernel file fail!\n"));
Core::MMU<Core::u32>& mmu = ((Core::CPU<Core::u32>*)(Core::Wukong_Get_System().get_cpu()))->get_mmu();
if (mmu.access(Core::Memory<Core::u32>::MEMORY_WRITE, KERNEL_LOAD_ADDR, kernel_size, buffer) < 0)
PPC_ERROR_FAIL(("Load kernel to mem fail!\n"));
return 0;
}
int Boot_Loader::load_file (const std::string &file, std::vector<Core::u8> &buffer)
{
int file_size;
FILE *fp;
if ( (fp = fopen(file.c_str(), "rb")) == NULL )
return -1;
if ( fseek(fp, 0, SEEK_END) < 0 )
return -1;
file_size = ftell(fp);
buffer.resize(file_size);
fseek(fp, 0, SEEK_SET);
if (fread(&buffer[0], file_size, 1, fp) == 0 && !feof(fp)) {
fclose(fp);
return -1;
}
fclose(fp);
return file_size;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -