Fix segment offset extraction

This commit is contained in:
caheckman 2019-08-21 15:19:58 -04:00
parent 0595537962
commit 1556928554
2 changed files with 21 additions and 9 deletions

View File

@ -31,7 +31,7 @@ public class SegmentedAddress extends GenericAddress {
*/
SegmentedAddress(long flat, SegmentedAddressSpace addrSpace) {
super(adjustOffset(flat, addrSpace), addrSpace);
segment = addrSpace.getSegmentFromFlat(flat);
segment = addrSpace.getDefaultSegmentFromFlat(flat);
}
/**
@ -56,12 +56,12 @@ public class SegmentedAddress extends GenericAddress {
SegmentedAddress(SegmentedAddressSpace addrSpace, long flat)
throws AddressOutOfBoundsException {
super(addrSpace, adjustOffset(flat, addrSpace));
segment = addrSpace.getSegmentFromFlat(flat);
segment = addrSpace.getDefaultSegmentFromFlat(flat);
}
private static long adjustOffset(long flat, SegmentedAddressSpace addrSpace) {
int seg = addrSpace.getSegmentFromFlat(flat);
long offset = addrSpace.getOffsetFromFlat(flat);
int seg = addrSpace.getDefaultSegmentFromFlat(flat);
long offset = addrSpace.getDefaultOffsetFromFlat(flat);
return addrSpace.getFlatOffset(seg, offset);
}
@ -78,7 +78,7 @@ public class SegmentedAddress extends GenericAddress {
* @return the offset value
*/
public int getSegmentOffset() {
return (int) ((SegmentedAddressSpace) addrSpace).getOffsetFromFlat(offset);
return (int) ((SegmentedAddressSpace) addrSpace).getOffsetFromFlat(offset, segment);
}
/**

View File

@ -52,11 +52,11 @@ public class SegmentedAddressSpace extends GenericAddressSpace {
}
/**
* Given a flat address offset, extract the 16-bit segment portion
* Given a flat address offset, extract the default 16-bit segment portion
* @param flat is the flat offset
* @return the segment value
*/
protected int getSegmentFromFlat(long flat) {
protected int getDefaultSegmentFromFlat(long flat) {
if (flat > 0xFFFFFL) {
return 0xFFFF;
}
@ -64,17 +64,29 @@ public class SegmentedAddressSpace extends GenericAddressSpace {
}
/**
* Given a flat address offset, extract the offset portion
* Given a flat address offset, extract the offset portion assuming the
* default segment.
* @param flat is the flat offset
* @return the offset value
*/
protected long getOffsetFromFlat(long flat) {
protected long getDefaultOffsetFromFlat(long flat) {
if (flat > 0xFFFFFL) {
return flat - 0xFFFF0;
}
return flat & 0xFFFFL;
}
/**
* Given a flat address offset, extract a segment offset assuming a
* specific segment value.
* @param flat is the flat offset
* @param segment is the specific segment value
* @return the segment offset
*/
protected long getOffsetFromFlat(long flat, int segment) {
return flat - (segment << 4);
}
/**
* Given a flat address offset and a preferred segment, try
* to create an address that maps to the offset and is in the segment. For