fixed bug (found by Benjamin Wilhelm) that doesn't check if phys addr is big enough given various base addresses
This commit is contained in:
parent
681c8dad20
commit
ab8cba148a
|
@ -30,40 +30,27 @@ def convert(size):
|
|||
nsize = int(size)
|
||||
return nsize
|
||||
|
||||
def abort_if(condition, message):
|
||||
if condition:
|
||||
print('Error:', message)
|
||||
exit(1)
|
||||
return
|
||||
|
||||
|
||||
#
|
||||
# main program
|
||||
#
|
||||
parser = OptionParser()
|
||||
parser.add_option("-s", "--seed", default=0, help="the random seed",
|
||||
action="store", type="int", dest="seed")
|
||||
parser.add_option("-A", "--addresses", default="-1",
|
||||
help="a set of comma-separated pages to access; -1 means randomly generate",
|
||||
action="store", type="string", dest="addresses")
|
||||
parser.add_option("-a", "--asize", default="1k",
|
||||
help="address space size (e.g., 16, 64k, 32m, 1g)",
|
||||
action="store", type="string", dest="asize")
|
||||
parser.add_option("-p", "--physmem", default="16k",
|
||||
help="physical memory size (e.g., 16, 64k, 32m, 1g)",
|
||||
action="store", type="string", dest="psize")
|
||||
parser.add_option("-n", "--numaddrs", default=5,
|
||||
help="number of virtual addresses to generate",
|
||||
action="store", type="int", dest="num")
|
||||
parser.add_option("-b", "--b0", default="-1",
|
||||
help="value of segment 0 base register",
|
||||
action="store", type="string", dest="base0")
|
||||
parser.add_option("-l", "--l0", default="-1",
|
||||
help="value of segment 0 limit register",
|
||||
action="store", type="string", dest="len0")
|
||||
parser.add_option("-B", "--b1", default="-1",
|
||||
help="value of segment 1 base register",
|
||||
action="store", type="string", dest="base1")
|
||||
parser.add_option("-L", "--l1", default="-1",
|
||||
help="value of segment 1 limit register",
|
||||
action="store", type="string", dest="len1")
|
||||
parser.add_option("-c", help="compute answers for me",
|
||||
action="store_true", default=False, dest="solve")
|
||||
|
||||
parser.add_option("-s", "--seed", default=0, help="the random seed", action="store", type="int", dest="seed")
|
||||
parser.add_option("-A", "--addresses", default="-1", help="a set of comma-separated pages to access; -1 means randomly generate", action="store", type="string", dest="addresses")
|
||||
parser.add_option("-a", "--asize", default="1k", help="address space size (e.g., 16, 64k, 32m, 1g)", action="store", type="string", dest="asize")
|
||||
parser.add_option("-p", "--physmem", default="16k", help="physical memory size (e.g., 16, 64k, 32m, 1g)", action="store", type="string", dest="psize")
|
||||
parser.add_option("-n", "--numaddrs", default=5, help="number of virtual addresses to generate", action="store", type="int", dest="num")
|
||||
parser.add_option("-b", "--b0", default="-1", help="value of segment 0 base register", action="store", type="string", dest="base0")
|
||||
parser.add_option("-l", "--l0", default="-1", help="value of segment 0 limit register", action="store", type="string", dest="len0")
|
||||
parser.add_option("-B", "--b1", default="-1", help="value of segment 1 base register", action="store", type="string", dest="base1")
|
||||
parser.add_option("-L", "--l1", default="-1", help="value of segment 1 limit register", action="store", type="string", dest="len1")
|
||||
parser.add_option("-c", help="compute answers for me", action="store_true", default=False, dest="solve")
|
||||
|
||||
(options, args) = parser.parse_args()
|
||||
|
||||
|
@ -77,17 +64,9 @@ asize = convert(options.asize)
|
|||
psize = convert(options.psize)
|
||||
addresses = str(options.addresses)
|
||||
|
||||
if psize <= 1:
|
||||
print('Error: must specify a non-zero physical memory size.')
|
||||
exit(1)
|
||||
|
||||
if asize == 0:
|
||||
print('Error: must specify a non-zero address-space size.')
|
||||
exit(1)
|
||||
|
||||
if psize <= asize:
|
||||
print('Error: physical memory size must be GREATER than address space size (for this simulation)')
|
||||
exit(1)
|
||||
abort_if(psize <= 4, 'must specify a bigger physical memory size')
|
||||
abort_if(asize == 0, 'must specify a non-zero address-space size')
|
||||
abort_if(psize <= asize, 'physical memory size > address space size (for this simulation)')
|
||||
|
||||
#
|
||||
# need to generate base, bounds for segment registers
|
||||
|
@ -97,13 +76,17 @@ len1 = convert(options.len1)
|
|||
base0 = convert(options.base0)
|
||||
base1 = convert(options.base1)
|
||||
|
||||
# if randomly generating length, make it 1/4-1/2 the address space size (roughly)
|
||||
if len0 == -1:
|
||||
len0 = int(asize/4.0 + (asize/4.0 * random.random()))
|
||||
|
||||
if len1 == -1:
|
||||
len1 = int(asize/4.0 + (asize/4.0 * random.random()))
|
||||
|
||||
# now have to find room for them
|
||||
if base0 == -1 or base1 == -1:
|
||||
# this restriction just makes it easier to place randomly-placed segments
|
||||
abort_if(psize <= 2 * asize, 'physical memory must be 2x GREATER than address space size (if randomly generating base registers)')
|
||||
|
||||
# if randomly generate base, have to find room for them
|
||||
if base0 == -1:
|
||||
done = 0
|
||||
while done == 0:
|
||||
|
@ -112,7 +95,7 @@ if base0 == -1:
|
|||
done = 1
|
||||
|
||||
# internally, base1 points to the lower address, and base1+len1 the higher address
|
||||
# (this differs from what the user would pass in, for example)
|
||||
# (this differs from what the user would pass in)
|
||||
if base1 == -1:
|
||||
done = 0
|
||||
while done == 0:
|
||||
|
@ -123,11 +106,11 @@ if base1 == -1:
|
|||
else:
|
||||
base1 = base1 - len1
|
||||
|
||||
|
||||
if len0 > asize/2.0 or len1 > asize/2.0:
|
||||
print('Error: length register is too large for this address space')
|
||||
exit(1)
|
||||
|
||||
abort_if(psize < base0 + len0 - 1, 'seg0 is not in physical memory')
|
||||
abort_if(psize < base1, 'seg1 is not in physical memory')
|
||||
|
||||
abort_if(len0 > asize/2.0, 'length0 register is too large for this address space')
|
||||
abort_if(len1 > asize/2.0, 'length1 register is too large for this address space')
|
||||
|
||||
print('Segment register information:')
|
||||
print('')
|
||||
|
@ -137,12 +120,10 @@ print('')
|
|||
print(' Segment 1 base (grows negative) : 0x%08x (decimal %d)' % (base1+len1, base1+len1))
|
||||
print(' Segment 1 limit : %d' % (len1))
|
||||
print('')
|
||||
nbase1 = base1 + len1
|
||||
|
||||
if (len0 + base0) > (base1) and (base1 > base0):
|
||||
print('Error: segments overlap in physical memory')
|
||||
exit(1)
|
||||
nbase1 = base1 + len1
|
||||
|
||||
abort_if((len0 + base0) > base1 and (base1 > base0), 'segments overlap in physical memory')
|
||||
|
||||
addrList = []
|
||||
if addresses == '-1':
|
||||
|
@ -158,9 +139,8 @@ else:
|
|||
#
|
||||
print('Virtual Address Trace')
|
||||
i = 0
|
||||
for vStr in addrList:
|
||||
# vaddr = int(asize * random.random())
|
||||
vaddr = int(vStr)
|
||||
for vstr in addrList:
|
||||
vaddr = int(vstr)
|
||||
if vaddr < 0 or vaddr >= asize:
|
||||
print('Error: virtual address %d cannot be generated in an address space of size %d' % (vaddr, asize))
|
||||
exit(1)
|
||||
|
|
Loading…
Reference in New Issue