def WS(self, XY): ''' Value of XY in shared memory is sent to ax ''' user_memory.write( self.get_ax(), to_hex(configs.SH_MEMEORY_STARTING_BLOCK * configs.BLOCK_SIZE + to_int(str(XY)[0]) * configs.BLOCK_SIZE + to_int(str(XY)[1])))
def JM(self, XY): ''' jump to XY ''' #processor.ic = to_hex(to_int(processor.get_real_address(XY)) + BLOCK_SIZE * DS_LENGTH - 1) #processor.ic = get_real_address_from_cs(XY) if to_int(XY) > self.cs_length: processor.pi = 3 kernel.create_resource(InterruptEvent, self, {'process' : self, 'message' : None }) self.state = configs.BLOCKED_STATE kernel.schedule() else: self.num = to_int(XY) + self.ds_length + 1
def CMP(self): ''' c = 0 if ax == bx c = 1 if ax > bx c = 2 if ax < bx ''' if self.get_ax() == self.get_bx(): self.set_c(0) elif (to_int(self.get_ax()) - to_int(self.get_bx())) > 0: self.set_c(1) else: self.set_c(2)
def JM(self, XY): ''' jump to XY ''' #processor.ic = to_hex(to_int(processor.get_real_address(XY)) + BLOCK_SIZE * DS_LENGTH - 1) #processor.ic = get_real_address_from_cs(XY) if to_int(XY) > self.cs_length: processor.pi = 3 kernel.create_resource(InterruptEvent, self, { 'process': self, 'message': None }) self.state = configs.BLOCKED_STATE kernel.schedule() else: self.num = to_int(XY) + self.ds_length + 1
def update_info(self): ''' update values on screen ''' self.ax_info.set_text(str(processor.r[0])) self.bx_info.set_text(str(processor.r[1])) self.cs_info.set_text(str(processor.cs)) self.ds_info.set_text(str(processor.ds)) self.c_info.set_text(str(processor.c)) self.ic_info.set_text(str(processor.ic)) self.c_info.set_text(str(processor.c)) self.chst0_info.set_text(str(processor.chst[0])) self.chst1_info.set_text(str(processor.chst[1])) self.chst2_info.set_text(str(processor.chst[2])) self.pi_info.set_text(str(processor.pi)) self.si_info.set_text(str(processor.si)) self.ti_info.set_text(str(processor.ti)) self.ioi_info.set_text(str(processor.ioi)) self.time_info.set_text(str(processor.time)) self.mode_info.set_text(str(processor.mode)) self.ptr_info.set_text(str(processor.ptr)) # updating virtual memory self.update_virtual_memory() # updating output self.output_buffer.set_text(output_device.output) # updating commands string = "" for i in range(5): string += str( user_memory.fetch(to_hex(to_int(processor.ic) + i))) + '\n' self.commands_buffer.set_text(string)
def next(self, widget): self.save_state() self.vm.iterate() processor.ic = to_hex(to_int(processor.ic) + 1) self.update_info() if processor.si == 3: self.show_popup()
def update_real(self, widget): addr = self.real_address.get_text() # some regexp validation should be here i = 0 for widget in self.realtable: widget.set_text(str( user_memory.fetch( to_hex(to_int(addr) + i) ))) i += 1
def execute(self, widget): while True: self.vm.iterate() processor.ic = to_hex(to_int(processor.ic) + 1) self.update_info() if processor.si == 3: self.show_popup() break
def get_real_address_of_ds(self, XY): ''' return real address of offset from data segment ''' XY = to_int(XY) if XY > self.ds_length: processor.pi = 1 kernel.create_resource(InterruptEvent, self, {'process' : self, 'message' : 'invalid data pointer' }) self.state = configs.BLOCKED_STATE kernel.schedule() else: return self.addresses[XY + 1]
def get_real_address_from_cs(self, XY): ''' return real address of offset from code segment''' XY = to_int(XY) if XY > self.cs_length: processor.pi = 1 kernel.create_resource(InterruptEvent, self, {'process' : self, 'message' : 'jumping out of program' }) self.state = configs.BLOCKED_STATE kernel.schedule() else: return self.addresses[self.ds_length + 1 + XY]
def get_real_address_from_cs(self, XY): ''' return real address of offset from code segment''' XY = to_int(XY) if XY > self.cs_length: processor.pi = 1 kernel.create_resource(InterruptEvent, self, { 'process': self, 'message': 'jumping out of program' }) self.state = configs.BLOCKED_STATE kernel.schedule() else: return self.addresses[self.ds_length + 1 + XY]
def get_real_address_of_ds(self, XY): ''' return real address of offset from data segment ''' XY = to_int(XY) if XY > self.ds_length: processor.pi = 1 kernel.create_resource(InterruptEvent, self, { 'process': self, 'message': 'invalid data pointer' }) self.state = configs.BLOCKED_STATE kernel.schedule() else: return self.addresses[XY + 1]
def __init__(self, opts = {}): opts['name'] = 'vm_' + str(kernel_data.PID) opts['priority'] = configs.LOADER_PRIORITY Process.__init__(self, opts) self.cs_length = opts['cs_length'] self.ds_length = opts['ds_length'] self.addresses = opts['addresses'] # state self.ic = None self.num = self.ds_length + 1 # skip DATA SEGMENT # prepare DS for i in range(1, self.ds_length): data = user_memory.fetch(self.addresses[i]) if data[0:2] != "DW": processor.pi = 2 kernel.create_resource(InterruptEvent, self, {'process' : self }) else: user_memory.write(to_hex(to_int(data[2:4])), self.addresses[i])
def __init__(self, opts={}): opts['name'] = 'vm_' + str(kernel_data.PID) opts['priority'] = configs.LOADER_PRIORITY Process.__init__(self, opts) self.cs_length = opts['cs_length'] self.ds_length = opts['ds_length'] self.addresses = opts['addresses'] # state self.ic = None self.num = self.ds_length + 1 # skip DATA SEGMENT # prepare DS for i in range(1, self.ds_length): data = user_memory.fetch(self.addresses[i]) if data[0:2] != "DW": processor.pi = 2 kernel.create_resource(InterruptEvent, self, {'process': self}) else: user_memory.write(to_hex(to_int(data[2:4])), self.addresses[i])
def update_page_table(self): i = 0 for widget in self.pgtable: widget.set_text(str( user_memory.fetch(to_hex(to_int(processor.ptr) + i)) )) i += 1
def BXOR(self): '''bx = ax ^ bx ''' self.set_bx( to_hex ( to_int(self.get_ax()) ^ to_int(self.get_bx()) ))
def SUB(self): '''ax = ax - bx''' answer = to_int(self.get_ax()) - to_int(self.get_bx()) if (answer < 0): self.set_c(2) self.set_ax(to_hex(answer))
def ADD(self): '''ax = ax + bx''' self.set_ax( to_hex( to_int(self.get_ax()) + to_int(self.get_bx())))
def LS(self, XY): ''' Value of ax is sent to shared memory ''' value = user_memory.fetch(to_hex(configs.SH_MEMEORY_STARTING_BLOCK * configs.BLOCK_SIZE + to_int(XY[0]) * configs.BLOCK_SIZE + to_int(XY[1]))) self.set_ax(value)
def WS(self, XY): ''' Value of XY in shared memory is sent to ax ''' user_memory.write(self.get_ax(), to_hex(configs.SH_MEMEORY_STARTING_BLOCK * configs.BLOCK_SIZE + to_int(str(XY)[0]) * configs.BLOCK_SIZE + to_int(str(XY)[1])))
def BXOR(self): '''bx = ax ^ bx ''' self.set_bx(to_hex(to_int(self.get_ax()) ^ to_int(self.get_bx())))
def LS(self, XY): ''' Value of ax is sent to shared memory ''' value = user_memory.fetch( to_hex(configs.SH_MEMEORY_STARTING_BLOCK * configs.BLOCK_SIZE + to_int(XY[0]) * configs.BLOCK_SIZE + to_int(XY[1]))) self.set_ax(value)
def ADD(self): '''ax = ax + bx''' self.set_ax(to_hex(to_int(self.get_ax()) + to_int(self.get_bx())))