pcibaseaddress.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 181 行
JAVA
181 行
/*
* $Id: PCIBaseAddress.java,v 1.1 2003/11/25 11:41:21 epr Exp $
*/
package org.jnode.driver.pci;
import org.jnode.util.NumberUtils;
/**
* @author epr
*/
public class PCIBaseAddress {
/** Is this base address in IO Space? */
private final boolean isIO;
/** The base address in the IO space */
private final int ioAddress;
/** Memory type */
private final byte memType;
/** The base address in the memory space */
private final long memAddress;
/** Must a memory address be relocated below 1Mb? */
private final boolean below1Mb;
/** Is this a 64-bit memory address? */
private final boolean b64;
/** Size of the address space */
private final int size;
public static PCIBaseAddress read(PCIDevice dev, int offset) {
final int rawData = dev.readConfigDword(4+offset, 0);
// Determine the size
dev.writeConfigDword(4+offset, 0, 0xFFFFFFFF);
final int sizeData = dev.readConfigDword(4+offset, 0);
// Restore previous data
dev.writeConfigDword(4+offset, 0, rawData);
if ((sizeData == 0) || (sizeData == 0xFFFFFFFF)) {
return null;
} else {
return new PCIBaseAddress(dev, offset, rawData, sizeData);
}
}
private static int pci_size(int base, int mask) {
int size = mask & base;
size = size & ~(size-1);
return size;
}
/**
* Create a new instance
* @param rawData
*/
private PCIBaseAddress(PCIDevice dev, int offset, int rawData, int sizeData) {
this.isIO = ((rawData & 0x01) != 0);
if (isIO) {
this.ioAddress = rawData & 0xFFFFFFFC;
this.size = pci_size(sizeData, 0xFFFFFFFC);
// Set dummy values to memory specific fields
this.memType = 0;
this.memAddress = 0;
this.below1Mb = false;
this.b64 = false;
} else {
this.memType = (byte)((rawData >> 1) & 0x03);
this.size = pci_size(sizeData, 0xFFFFFFF0);
switch (memType) {
case 0x00: {
// 32-bit address relocatable anywhere in the memory space
this.memAddress = rawData & 0xFFFFFFF0;
this.below1Mb = false;
this.b64 = false;
} break;
case 0x01: {
// 32-bit address relocatable below 1Mb boundary
this.memAddress = rawData & 0xFFFFFFF0;
this.below1Mb = true;
this.b64 = false;
} break;
case 0x02: {
// 64-bit address relocatable anywhere in the memory space
final int nextRawData = dev.readConfigDword(4+offset+1, 0);
this.memAddress = ((rawData & 0xFFFFFFF0) | (nextRawData << 32));
this.below1Mb = false;
this.b64 = true;
} break;
default: {
// Unknown type
this.memAddress = -1;
this.below1Mb = false;
this.b64 = false;
}
}
// Set dummy values to io specific fields
this.ioAddress = -1;
}
}
/**
* Is this base address in IO space?
*/
public boolean isIOSpace() {
return isIO;
}
/**
* Is this base address in memory space.
*/
public boolean isMemorySpace() {
return !isIO;
}
/**
* Is this a valid base address?
*/
public boolean isValid() {
return (isIO || ((memType >= 0) && (memType <= 2)));
}
/**
* Is this a 64-bit address?
*/
public boolean is64Bit() {
return b64;
}
/**
* Is this a 32-bit address?
*/
public boolean is32Bit() {
return !b64;
}
/**
* Must this address be relocated below the 1Mb boundary?
*/
public boolean isBelow1Mb() {
return below1Mb;
}
/**
* Gets the staring IO address
*/
public int getIOBase() {
return ioAddress;
}
/**
* Gets the starting memory address
*/
public long getMemoryBase() {
return memAddress;
}
/**
* Gets the size of the IO or memory space
*/
public int getSize() {
return size;
}
/**
* Convert this to a String representation
* @see java.lang.Object#toString()
*/
public String toString() {
if (!isValid()) {
return "Invalid";
} else if (isIO) {
return "IO:" + NumberUtils.hex(ioAddress) + "-" + NumberUtils.hex(ioAddress+size - 1);
} else if (b64) {
return "MEM64:" + NumberUtils.hex(memAddress) + "-" + NumberUtils.hex(memAddress + size - 1);
} else if (below1Mb) {
return "MEM32-BELOW1Mb:" + NumberUtils.hex((int)memAddress) + "-" + NumberUtils.hex((int)(memAddress + size - 1));
} else {
return "MEM32:" + NumberUtils.hex((int)memAddress) + "-" + NumberUtils.hex((int)(memAddress + size - 1));
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?