read.cc

来自「一个mips虚拟机非常好代码,使用C++来编写的,希望大家多学学,」· CC 代码 · 共 51 行

CC
51
字号
#include <string.h>#include <assert.hh>#include <inttypes.hh>#include "rtc.hh"ClockValueMT48Tx2::read(UInt64 addr, UInt64* buf, int size){    assert(size > 0 && size <= 8);    assert(!is_power_of_two(size) || (addr & (size - 1)) == 0);    // Decode the address. Note that, as with real hardware, we simply ignore    // irrelevant address lines (the hardware has no way of knowing where in    // the address space it is currently mapped.)    addr %= 2*KB;    if (addr + size > CONTROL) {	if ((addr + size > CONTROL + 1) && !bit(data[CONTROL], 6)) {	    msg("RTC read without halting.");	    update_read(bus->clock);	}    }    // Fetch the data.    if (size == sizeof(UInt8))	*buf = *(UInt8 *)(data + addr);    else if (size == sizeof(UInt16))	*buf = *(UInt16 *)(data + addr);    else if (size == sizeof(UInt32))	*buf = *(UInt32 *)(data + addr);    else if (size == sizeof(UInt64))	*buf = *(UInt64 *)(data + addr);    else {	// Forget about performance.	memcpy(buf, data + addr, size);	if (big_endian_host())	    *buf >>= (sizeof(*buf) - size) * 8;    }    // Compute the access latency.    if (freq != bus->clock->freq) {	read_latency = bus->clock->cycles(read_latency, freq);	write_latency = bus->clock->cycles(write_latency, freq);	freq = bus->clock->freq;    }    return read_latency * size;}

⌨️ 快捷键说明

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