Exemple #1
0
 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])))
Exemple #2
0
 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
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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
Exemple #6
0
    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)
Exemple #7
0
    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()
Exemple #8
0
 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
Exemple #9
0
 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
Exemple #10
0
 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]
Exemple #11
0
 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]
Exemple #12
0
 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]
Exemple #13
0
 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]
Exemple #14
0
    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])
Exemple #15
0
    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])
Exemple #16
0
 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
Exemple #17
0
 def BXOR(self):
     '''bx = ax ^ bx '''
     self.set_bx( to_hex ( to_int(self.get_ax()) ^ to_int(self.get_bx()) ))
Exemple #18
0
 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))
Exemple #19
0
 def ADD(self):
     '''ax = ax + bx'''
     self.set_ax( to_hex( to_int(self.get_ax()) + to_int(self.get_bx())))
Exemple #20
0
 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)
Exemple #21
0
 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]))) 
Exemple #22
0
 def BXOR(self):
     '''bx = ax ^ bx '''
     self.set_bx(to_hex(to_int(self.get_ax()) ^ to_int(self.get_bx())))
Exemple #23
0
 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)
Exemple #24
0
 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))
Exemple #25
0
 def ADD(self):
     '''ax = ax + bx'''
     self.set_ax(to_hex(to_int(self.get_ax()) + to_int(self.get_bx())))