// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Host_Interface_SATA.cpp
// Function: SSD_Components::Request_Fetch_Unit_SATA::Process_pcie_read_message(unsigned long, void*, unsigned int)
void Request_Fetch_Unit_SATA::Process_pcie_read_message(uint64_t address, void * payload, unsigned int payload_size)
	{
		Host_Interface_SATA* hi = (Host_Interface_SATA*)host_interface;
		DMA_Req_Item* dma_req_item = dma_list.front();
		dma_list.pop_front();

		switch (dma_req_item->Type)
		{
			case DMA_Req_Type::REQUEST_INFO:
			{
				User_Request* new_request = new User_Request;
				new_request->IO_command_info = payload;
				new_request->Stream_id = (stream_id_type)((uint64_t)(dma_req_item->object));
				new_request->STAT_InitiationTime = Simulator->Time();
				Submission_Queue_Entry* sqe = (Submission_Queue_Entry*)payload;
				switch (sqe->Opcode)
				{
					case SATA_READ_OPCODE:
						new_request->Type = UserRequestType::READ;
						new_request->Start_LBA = ((LHA_type)sqe->Command_specific[1]) << 31 | (LHA_type)sqe->Command_specific[0];//Command Dword 10 and Command Dword 11
						new_request->SizeInSectors = sqe->Command_specific[2] & (LHA_type)(0x0000ffff);
						new_request->Size_in_byte = new_request->SizeInSectors * SECTOR_SIZE_IN_BYTE;
						break;
					case SATA_WRITE_OPCODE:
						new_request->Type = UserRequestType::WRITE;
						new_request->Start_LBA = ((LHA_type)sqe->Command_specific[1]) << 31 | (LHA_type)sqe->Command_specific[0];//Command Dword 10 and Command Dword 11
						new_request->SizeInSectors = sqe->Command_specific[2] & (LHA_type)(0x0000ffff);
						new_request->Size_in_byte = new_request->SizeInSectors * SECTOR_SIZE_IN_BYTE;
						break;
					default:
						throw std::invalid_argument("SATA command is not supported!");
				}
				((Input_Stream_Manager_SATA*)(hi->input_stream_manager))->Handle_new_arrived_request(new_request);
				break;
			}
			case DMA_Req_Type::WRITE_DATA:
				COPYDATA(((User_Request*)dma_req_item->object)->Data, payload, payload_size);
				((Input_Stream_Manager_SATA*)(hi->input_stream_manager))->Handle_arrived_write_data((User_Request*)dma_req_item->object);
				break;
			default:
				break;
		}

		delete dma_req_item;
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r14
movq 0x8(%rdi), %r13
movq 0x10(%rdi), %r15
movq 0x10(%r15), %rbx
decq 0x20(%rdi)
movq %r15, %rdi
callq 0x7580
movq %r15, %rdi
callq 0x7370
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x438ca
testl %eax, %eax
jne 0x4394b
movl $0x80, %edi
callq 0x73a0
movq %rax, %r15
movq %rax, %rdi
callq 0x5181c
movq %r14, 0x70(%r15)
movzwl 0x8(%rbx), %eax
movw %ax, 0x68(%r15)
callq 0x28018
movq %rax, %rdi
callq 0x2841a
movq %rax, 0x30(%r15)
movzbl (%r14), %ecx
cmpl $0x1, %ecx
je 0x4390d
xorl %eax, %eax
cmpl $0x2, %ecx
je 0x43912
movl $0x10, %edi
callq 0x71d0
movq %rax, %rbx
leaq 0x169e8(%rip), %rsi     # 0x5a294
movq %rax, %rdi
callq 0x7680
movq 0x2b70d(%rip), %rsi     # 0x6efc8
movq 0x2b6e6(%rip), %rdx     # 0x6efa8
movq %rbx, %rdi
callq 0x75e0
callq 0x28018
movq %rax, %rdi
callq 0x28484
testb %al, %al
je 0x438fe
movl %ebp, %r12d
movq %r12, %rdi
callq 0x7030
movq 0x8(%rbx), %r15
movq %rax, 0x78(%r15)
movq %rax, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x7310
jmp 0x43906
movq 0x8(%rbx), %r15
movq %r14, 0x78(%r15)
movl $0x18, %eax
jmp 0x4393e
movl $0x1, %eax
movl %eax, 0x64(%r15)
movl 0x30(%r14), %eax
movl 0x34(%r14), %ecx
shlq $0x1f, %rcx
orq %rcx, %rax
movq %rax, 0x28(%r15)
movzwl 0x38(%r14), %eax
movl %eax, 0x60(%r15)
shll $0x9, %eax
movl %eax, 0x5c(%r15)
movl $0x10, %eax
movq 0x50(%r13), %rdi
movq (%rdi), %rcx
movq %r15, %rsi
callq *(%rcx,%rax)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7370
movq %rax, %r14
movq %rbx, %rdi
callq 0x72c0
jmp 0x43979
movq %rax, %r14
movq %r15, %rdi
callq 0x7370
movq %r14, %rdi
callq 0x7620
nop