// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
movl %ecx, %ebp
movq %rdx, %r14
movq 0x8(%rdi), %r12
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 0x44337
testl %eax, %eax
jne 0x443be
movl $0x80, %edi
callq 0x73a0
movq %rax, %r15
movq %rax, %rdi
callq 0x5224c
movq %r14, 0x70(%r15)
movzwl 0x8(%rbx), %eax
movw %ax, 0x68(%r15)
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
movq %rax, 0x30(%r15)
movzbl (%r14), %ecx
cmpl $0x1, %ecx
je 0x44384
xorl %eax, %eax
cmpl $0x2, %ecx
je 0x44389
movl $0x10, %edi
callq 0x71d0
movq %rax, %rbx
leaq 0x15f7b(%rip), %rsi     # 0x5a294
movq %rax, %rdi
callq 0x7680
movq 0x2aca0(%rip), %rsi     # 0x6efc8
movq 0x2ac81(%rip), %rdx     # 0x6efb0
movq %rbx, %rdi
callq 0x75e0
callq 0x281b4
movq %rax, %rdi
callq 0x28610
testb %al, %al
je 0x4436b
movl %ebp, %r15d
movq %r15, %rdi
callq 0x7030
movq 0x8(%rbx), %rcx
movq %rax, 0x78(%rcx)
movq %rax, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x7310
jmp 0x44373
movq 0x8(%rbx), %rax
movq %r14, 0x78(%rax)
movq 0x50(%r12), %rdi
movq 0x8(%rbx), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
jmp 0x443be
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)
movq 0x50(%r12), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x10(%rax)
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7370
movq %rax, %r14
movq %rbx, %rdi
callq 0x72c0
jmp 0x443e6
movq %rax, %r14
movq %r15, %rdi
callq 0x7370
movq %r14, %rdi
callq 0x7620