Пример #1
0
    def run(self):
        ''' create virtual machine '''

        # get load task
        if self.used_resources.get_by_class(TaskLoaded) is None:
            kernel.ask_for_resource(
                kernel_data.RESOURCES.get_by_class(TaskLoaded), self,
                TaskLoaded)
            return

        in_data = True
        ds_length = 0
        cs_length = 0

        # manual ugly counting
        for address in self.used_resources.get_by_class(TaskLoaded).addresses:
            if user_memory.fetch(address) == "CODE":
                in_data = False
                cs_length -= 1

            if in_data:
                ds_length += 1
            else:
                cs_length += 1

        kernel.create_process(
            VirtualMachine, self, {
                'ds_length': ds_length,
                'cs_length': cs_length,
                'addresses':
                self.used_resources.get_by_class(TaskLoaded).addresses
            })
        kernel.delete_resource(self.used_resources.get_by_class(TaskLoaded))
Пример #2
0
    def run(self):
        ''' create virtual machine '''

        # get load task
        if self.used_resources.get_by_class(TaskLoaded) is None:
            kernel.ask_for_resource(kernel_data.RESOURCES.get_by_class(TaskLoaded), self, TaskLoaded)
            return
        
        in_data = True 
        ds_length = 0
        cs_length = 0

        # manual ugly counting
        for address in self.used_resources.get_by_class(TaskLoaded).addresses:
            if user_memory.fetch(address) == "CODE":
                in_data = False
                cs_length -= 1

            if in_data:
                ds_length += 1
            else:
                cs_length += 1

        kernel.create_process(VirtualMachine, self, { 'ds_length' : ds_length, 'cs_length' : cs_length, 'addresses' : self.used_resources.get_by_class(TaskLoaded).addresses })
        kernel.delete_resource(self.used_resources.get_by_class(TaskLoaded))
Пример #3
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)
Пример #4
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
Пример #5
0
    def run(self):
        ''' execute user task until interrupt is encountered '''

        self.update()
        command = user_memory.fetch(self.ic)
        if command[0:2] == 'LA':
            self.LA(command[2:4])
        elif command[0:2] == 'LB':
            self.LB(command[2:4])
        elif command[0:2] == 'MA':
            self.MA(command[2:4])
        elif command[0:2] == 'MB':
            self.MB(command[2:4])
        elif command[0:2] == 'WS':
            self.WS(command[2:4])
        elif command[0:2] == 'LS':
            self.LS(command[2:4])
        elif command[0:2] == 'JM':
            self.JM(command[2:4])
        elif command[0:2] == 'JL':
            self.JL(command[2:4])
        elif command[0:2] == 'JE':
            self.JE(command[2:4])
        elif command[0:2] == 'PD':
            pass
        elif command[0:3] == 'ADD':
            self.ADD()
        elif command[0:3] == 'SUB':
            self.SUB()
        elif command[0:3] == 'CMP':
            self.CMP()
        elif command[0:3] == 'END':
            self.END()
            return
        elif command == 'SWAP':
            self.SWAP()
        elif command == 'AXOR':
            self.AXOR()
        elif command == 'BXOR':
            self.BXOR()
        else: 
            processor.pi = 2
            kernel.create_resource(InterruptEvent, self, {'process' : self, 'message' : str(command) })
            self.state = configs.BLOCKED_STATE
            kernel.schedule()
            return

        logger.log("COMMAND EVALUATED: " + command)
        logger.log("TIME IS : " + str(processor.time))
        self.update_time(2)
        if self.time_is_over():
            processor.ti = 1
            kernel.create_resource(InterruptEvent, self, {'process' : self, 'message' : None })
            self.state = configs.BLOCKED_STATE
            kernel.schedule()
Пример #6
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])
Пример #7
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])
Пример #8
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)
Пример #9
0
 def read_from_ds(self, XY):
     ''' read word from given virtual address '''
     return user_memory.fetch(self.get_real_address_of_ds(XY))
Пример #10
0
    def run(self):
        ''' execute user task until interrupt is encountered '''

        self.update()
        command = user_memory.fetch(self.ic)
        if command[0:2] == 'LA':
            self.LA(command[2:4])
        elif command[0:2] == 'LB':
            self.LB(command[2:4])
        elif command[0:2] == 'MA':
            self.MA(command[2:4])
        elif command[0:2] == 'MB':
            self.MB(command[2:4])
        elif command[0:2] == 'WS':
            self.WS(command[2:4])
        elif command[0:2] == 'LS':
            self.LS(command[2:4])
        elif command[0:2] == 'JM':
            self.JM(command[2:4])
        elif command[0:2] == 'JL':
            self.JL(command[2:4])
        elif command[0:2] == 'JE':
            self.JE(command[2:4])
        elif command[0:2] == 'PD':
            pass
        elif command[0:3] == 'ADD':
            self.ADD()
        elif command[0:3] == 'SUB':
            self.SUB()
        elif command[0:3] == 'CMP':
            self.CMP()
        elif command[0:3] == 'END':
            self.END()
            return
        elif command == 'SWAP':
            self.SWAP()
        elif command == 'AXOR':
            self.AXOR()
        elif command == 'BXOR':
            self.BXOR()
        else:
            processor.pi = 2
            kernel.create_resource(InterruptEvent, self, {
                'process': self,
                'message': str(command)
            })
            self.state = configs.BLOCKED_STATE
            kernel.schedule()
            return

        logger.log("COMMAND EVALUATED: " + command)
        logger.log("TIME IS : " + str(processor.time))
        self.update_time(2)
        if self.time_is_over():
            processor.ti = 1
            kernel.create_resource(InterruptEvent, self, {
                'process': self,
                'message': None
            })
            self.state = configs.BLOCKED_STATE
            kernel.schedule()
Пример #11
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)
Пример #12
0
 def read_from_ds(self, XY):
     ''' read word from given virtual address '''
     return user_memory.fetch(self.get_real_address_of_ds(XY))
Пример #13
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