// File: /workspace/github_cpp_makefile_star2_O2/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), %rax
addq $0x10, %rdi
movq 0x10(%rax), %rbx
callq 0x35c98
movl (%rbx), %eax
cmpl $0x1, %eax
je 0x365c1
testl %eax, %eax
jne 0x3663b
movl $0x80, %edi
callq 0x7370
movq %rax, %r15
movq %rax, %rdi
callq 0x3fc4c
movq %r14, 0x70(%r15)
movzwl 0x8(%rbx), %eax
movw %ax, 0x68(%r15)
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
movq %rax, 0x30(%r15)
movzbl (%r14), %ecx
cmpl $0x1, %ecx
je 0x36601
xorl %eax, %eax
cmpl $0x2, %ecx
je 0x36604
pushq $0x10
popq %rdi
callq 0x71b0
movq %rax, %rbx
leaq 0x11bc1(%rip), %rsi     # 0x48164
movq %rax, %rdi
callq 0x7620
movq 0x2ba16(%rip), %rsi     # 0x61fc8
movq 0x2b9ef(%rip), %rdx     # 0x61fa8
movq %rbx, %rdi
callq 0x7590
callq 0x1f784
movq %rax, %rdi
callq 0x1fb60
testb %al, %al
je 0x365f5
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 0x72e0
jmp 0x365fd
movq 0x8(%rbx), %r15
movq %r14, 0x78(%r15)
pushq $0x18
jmp 0x3662d
pushq $0x1
popq %rax
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)
pushq $0x10
popq %rax
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 0x7340
movq %rax, %r14
movq %rbx, %rdi
callq 0x72a0
jmp 0x36669
movq %rax, %r14
movq %r15, %rdi
callq 0x7340
movq %r14, %rdi
callq 0x75d0
nop