Exemple #1
0
def occupy_empty_area(number_of_words):
    ''' find given number of words in user memory and marks them read. 
          Returns None if occupation was not possible 
          Returns array of real addresses.
    '''
    addresses = []
    recov = []
    enough = True
    block = USER_STARTING_BLOCK
    word = 0
    i = 0

    while len(addresses) != number_of_words:
        if memory[block][word] == []:
            addresses.append(processor.to_hex(block * BLOCK_SIZE + word))
            memory[block][word] = 'X'
            recov.append([block, word])
        word += 1 
        if word == BLOCK_SIZE:
            block += 1
            word = 0
        if block == USER_ENDING_BLOCK:
            # recover occupied areas
            for addr in recov:
                memory[addr[0]][addr[1]] = []
            return None
        i += 1

    logger.log("Addreses occupied: " + str(addresses))
    return addresses
Exemple #2
0
def occupy_empty_area(number_of_words):
    ''' find given number of words in user memory and marks them read. 
          Returns None if occupation was not possible 
          Returns array of real addresses.
    '''
    addresses = []
    recov = []
    enough = True
    block = USER_STARTING_BLOCK
    word = 0
    i = 0

    while len(addresses) != number_of_words:
        if memory[block][word] == []:
            addresses.append(processor.to_hex(block * BLOCK_SIZE + word))
            memory[block][word] = 'X'
            recov.append([block, word])
        word += 1
        if word == BLOCK_SIZE:
            block += 1
            word = 0
        if block == USER_ENDING_BLOCK:
            # recover occupied areas
            for addr in recov:
                memory[addr[0]][addr[1]] = []
            return None
        i += 1

    logger.log("Addreses occupied: " + str(addresses))
    return addresses
Exemple #3
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()
Exemple #4
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()