def run(self):
    if (self.ql.archtype not in (QL_ARCH.X86, QL_ARCH.X8664)):
        raise QlErrorArch('Unsupported architecture')
    if (self.ql.archtype != QL_ARCH.X8664):
        raise QlErrorArch('Only 64 bit arch is supported at the moment')
    self.loaded_image_protocol_guid = self.ql.os.profile['LOADED_IMAGE_PROTOCOL']['Guid']
    self.loaded_image_protocol_modules = []
    self.tpl = 4
    arch_key = {QL_ARCH.X86: 'OS32', QL_ARCH.X8664: 'OS64'}[self.ql.archtype]
    os_profile = self.ql.os.profile[arch_key]
    self.dxe_context = context.DxeContext(self.ql)
    heap_base = int(os_profile['heap_address'], 0)
    heap_size = int(os_profile['heap_size'], 0)
    self.dxe_context.init_heap(heap_base, heap_size)
    self.heap_base_address = heap_base
    self.ql.log.info(f'Located heap at {heap_base:#010x}')
    stack_base = int(os_profile['stack_address'], 0)
    stack_size = int(os_profile['stack_size'], 0)
    self.dxe_context.init_stack(stack_base, stack_size)
    sp = ((stack_base + stack_size) - CPU_STACK_ALIGNMENT)
    self.ql.log.info(f'Located stack at {sp:#010x}')
    gST = self.dxe_context.heap.alloc((256 * 1024))
    st.initialize(self.ql, gST)
    protocols = (EfiSmmAccess2Protocol, EfiSmmBase2Protocol)
    for proto in protocols:
        self.dxe_context.install_protocol(proto.descriptor, 1)
    self.ql.os.heap = self.dxe_context.heap
    smm_profile = self.ql.os.profile['SMRAM']
    self.smm_context = context.SmmContext(self.ql)
    heap_base = int(smm_profile['heap_address'], 0)
    heap_size = int(smm_profile['heap_size'], 0)
    self.smm_context.init_heap(heap_base, heap_size)
    self.ql.log.info(f'Located SMM heap at {heap_base:#010x}')
    gSmst = self.smm_context.heap.alloc((256 * 1024))
    smst.initialize(self.ql, gSmst)
    self.in_smm = False
    protocols = (EfiSmmCpuProtocol, EfiSmmSwDispatch2Protocol)
    for proto in protocols:
        self.smm_context.install_protocol(proto.descriptor, 1)
    mmio_map = self.ql.os.profile['MMIO']
    self.ql.mem.map(int(mmio_map['sbreg_base'], 0), int(mmio_map['sbreg_size'], 0))
    self.ql.reg.rsp = sp
    self.ql.reg.rbp = sp
    self.entry_point = 0
    self.load_address = 0
    self.next_image_base = int(os_profile['image_address'], 0)
    try:
        for dependency in self.ql.argv:
            self.map_and_load(dependency)
    except QlMemoryMappedError:
        self.ql.log.critical("Couldn't map dependency")
    self.ql.log.info(f'Done with loading {self.ql.path}')
    self.end_of_execution_ptr = gST
    self.ql.hook_address(hook_EndOfExecution, self.end_of_execution_ptr)
    self.execute_next_module()
def run(self):
    if (self.ql.archtype not in (QL_ARCH.X86, QL_ARCH.X8664)):
        raise QlErrorArch('Unsupported architecture')
    if (self.ql.archtype != QL_ARCH.X8664):
        raise QlErrorArch('Only 64 bit arch is supported at the moment')
    self.loaded_image_protocol_guid = self.ql.os.profile['LOADED_IMAGE_PROTOCOL']['Guid']
    self.loaded_image_protocol_modules = []
    self.tpl = 4
    arch_key = {QL_ARCH.X86: 'OS32', QL_ARCH.X8664: 'OS64'}[self.ql.archtype]
    os_profile = self.ql.os.profile[arch_key]
    self.dxe_context = context.DxeContext(self.ql)
    heap_base = int(os_profile['heap_address'], 0)
    heap_size = int(os_profile['heap_size'], 0)
    self.dxe_context.init_heap(heap_base, heap_size)
    self.heap_base_address = heap_base
    self.ql.log.info(f'Located heap at {heap_base:#010x}')
    stack_base = int(os_profile['stack_address'], 0)
    stack_size = int(os_profile['stack_size'], 0)
    self.dxe_context.init_stack(stack_base, stack_size)
    sp = ((stack_base + stack_size) - CPU_STACK_ALIGNMENT)
    self.ql.log.info(f'Located stack at {sp:#010x}')
    gST = self.dxe_context.heap.alloc((256 * 1024))
    st.initialize(self.ql, gST)
    protocols = (EfiSmmAccess2Protocol, EfiSmmBase2Protocol)
    for proto in protocols:
        self.dxe_context.install_protocol(proto.descriptor, 1)
    self.ql.os.heap = self.dxe_context.heap
    smm_profile = self.ql.os.profile['SMRAM']
    self.smm_context = context.SmmContext(self.ql)
    heap_base = int(smm_profile['heap_address'], 0)
    heap_size = int(smm_profile['heap_size'], 0)
    self.smm_context.init_heap(heap_base, heap_size)
    self.ql.log.info(f'Located SMM heap at {heap_base:#010x}')
    gSmst = self.smm_context.heap.alloc((256 * 1024))
    smst.initialize(self.ql, gSmst)
    self.in_smm = False
    protocols = (EfiSmmCpuProtocol, EfiSmmSwDispatch2Protocol)
    for proto in protocols:
        self.smm_context.install_protocol(proto.descriptor, 1)
    mmio_map = self.ql.os.profile['MMIO']
    self.ql.mem.map(int(mmio_map['sbreg_base'], 0), int(mmio_map['sbreg_size'], 0))
    self.ql.reg.rsp = sp
    self.ql.reg.rbp = sp
    self.entry_point = 0
    self.load_address = 0
    self.next_image_base = int(os_profile['image_address'], 0)
    try:
        for dependency in self.ql.argv:
            self.map_and_load(dependency)
    except QlMemoryMappedError:
        self.ql.log.critical("Couldn't map dependency")
    self.ql.log.info(f'Done with loading {self.ql.path}')
    self.end_of_execution_ptr = gST
    self.ql.hook_address(hook_EndOfExecution, self.end_of_execution_ptr)
    self.execute_next_module()