// File: CMU-SAFARI[P]MQSim/src/host/SATA_HBA.cpp
// Function: Host_Components::SATA_HBA::SATA_HBA(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, unsigned short, unsigned long, Host_Components::PCIe_Root_Complex*, std::vector<Host_Components::IO_Flow_Base*, std::allocator<Host_Components::IO_Flow_Base*>>*)
SATA_HBA::SATA_HBA(sim_object_id_type id, uint16_t ncq_size, sim_time_type hba_processing_delay, PCIe_Root_Complex* pcie_root_complex, std::vector<Host_Components::IO_Flow_Base*>* IO_flows) :
		MQSimEngine::Sim_Object(id), ncq_size(ncq_size), hba_processing_delay(hba_processing_delay), pcie_root_complex(pcie_root_complex), IO_flows(IO_flows)
	{
		for (uint16_t cmdid = 0; cmdid < (uint16_t)(0xffffffff); cmdid++) {
			available_command_ids.insert(cmdid);
		}
		Host_IO_Request* t = NULL;
		for (uint16_t cmdid = 0; cmdid < ncq_size; cmdid++) {
			request_queue_in_memory.push_back(t);
		}
		sata_ncq.Submission_queue_size = ncq_size;
		sata_ncq.Submission_queue_head = 0;
		sata_ncq.Submission_queue_tail = 0;
		sata_ncq.Completion_queue_size = ncq_size;
		sata_ncq.Completion_queue_head = 0;
		sata_ncq.Completion_queue_tail = 0;
		sata_ncq.Submission_queue_memory_base_address = SUBMISSION_QUEUE_MEMORY_1;
		sata_ncq.Submission_tail_register_address_on_device = NCQ_SUBMISSION_REGISTER;
		sata_ncq.Completion_queue_memory_base_address = COMPLETION_QUEUE_MEMORY_1;
		sata_ncq.Completion_head_register_address_on_device = NCQ_COMPLETION_REGISTER;
	}

// Assembly:
subq $0xa8, %rsp
movw %dx, %ax
movq %rdi, 0xa0(%rsp)
movq %rsi, 0x98(%rsp)
movw %ax, 0x96(%rsp)
movq %rcx, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %r9, 0x78(%rsp)
movq 0xa0(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1fd60
movq 0x38(%rsp), %rdi
leaq 0x993d3(%rip), %rax     # 0xd8d98
movq %rax, (%rdi)
movw 0x96(%rsp), %ax
movw %ax, 0x2a(%rdi)
movq 0x88(%rsp), %rax
movq %rax, 0x30(%rdi)
movq 0x80(%rsp), %rax
movq %rax, 0x38(%rdi)
movq 0x78(%rsp), %rax
movq %rax, 0x40(%rdi)
addq $0x48, %rdi
movq %rdi, 0x18(%rsp)
callq 0x408e0
movq 0x38(%rsp), %rdi
addq $0xb0, %rdi
movq %rdi, 0x20(%rsp)
callq 0x33fe0
movq 0x38(%rsp), %rdi
addq $0xe0, %rdi
movq %rdi, 0x28(%rsp)
callq 0x33ff0
movq 0x38(%rsp), %rdi
addq $0xf8, %rdi
movq %rdi, 0x30(%rsp)
callq 0x34000
movq 0x38(%rsp), %rdi
addq $0x110, %rdi            # imm = 0x110
movq %rdi, 0x40(%rsp)
callq 0x40900
jmp 0x3fa5d
movq 0x38(%rsp), %rdi
addq $0x160, %rdi            # imm = 0x160
movq %rdi, 0x10(%rsp)
callq 0x40930
jmp 0x3fa75
movw $0x0, 0x6a(%rsp)
movzwl 0x6a(%rsp), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jge 0x3fb12
movq 0x38(%rsp), %rdi
addq $0xb0, %rdi
leaq 0x6a(%rsp), %rsi
callq 0x34020
movb %dl, 0x7(%rsp)
movq %rax, 0x8(%rsp)
jmp 0x3faad
movb 0x7(%rsp), %al
movq 0x8(%rsp), %rcx
movq %rcx, 0x58(%rsp)
movb %al, 0x60(%rsp)
movw 0x6a(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x6a(%rsp)
jmp 0x3fa7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x3fbd0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
jmp 0x3fbc6
movq 0x10(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
callq 0x40960
jmp 0x3fbc6
movq $0x0, 0x50(%rsp)
movw $0x0, 0x4e(%rsp)
movzwl 0x4e(%rsp), %eax
movzwl 0x96(%rsp), %ecx
cmpl %ecx, %eax
jge 0x3fb5d
movq 0x38(%rsp), %rdi
addq $0xe0, %rdi
leaq 0x50(%rsp), %rsi
callq 0x34080
jmp 0x3fb4b
jmp 0x3fb4d
movw 0x4e(%rsp), %ax
addw $0x1, %ax
movw %ax, 0x4e(%rsp)
jmp 0x3fb22
movq 0x38(%rsp), %rax
movw 0x96(%rsp), %cx
movw %cx, 0x4c(%rax)
movw $0x0, 0x48(%rax)
movw $0x0, 0x4a(%rax)
movw 0x96(%rsp), %cx
movw %cx, 0x64(%rax)
movw $0x0, 0x60(%rax)
movw $0x0, 0x62(%rax)
movabsq $0x10000000000, %rcx    # imm = 0x10000000000
movq %rcx, 0x58(%rax)
movq $0x1000, 0x50(%rax)     # imm = 0x1000
movabsq $0x1f000000000, %rcx    # imm = 0x1F000000000
movq %rcx, 0x70(%rax)
movq $0x1003, 0x68(%rax)     # imm = 0x1003
addq $0xa8, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x40970
movq 0x30(%rsp), %rdi
callq 0x34100
movq 0x28(%rsp), %rdi
callq 0x34110
movq 0x20(%rsp), %rdi
callq 0x34170
movq 0x18(%rsp), %rdi
callq 0x40980
movq 0x38(%rsp), %rdi
callq 0x1ff90
movq 0x70(%rsp), %rdi
callq 0x8770
nopl (%rax)