// File: /workspace/github_cpp_makefile_star2_O1/CMU-SAFARI[P]MQSim/src/ssd/NVM_PHY_ONFI_NVDDR2.cpp
// Function: SSD_Components::NVM_PHY_ONFI_NVDDR2::perform_interleaved_cmd_data_transfer(NVM::FlashMemory::Flash_Chip*, SSD_Components::DieBookKeepingEntry*)
void NVM_PHY_ONFI_NVDDR2::perform_interleaved_cmd_data_transfer(NVM::FlashMemory::Flash_Chip* chip, DieBookKeepingEntry* bookKeepingEntry)
	{
		ONFI_Channel_NVDDR2* target_channel = channels[bookKeepingEntry->ActiveTransactions.front()->Address.ChannelID];
		/*if (target_channel->Status == BusChannelStatus::BUSY)
			PRINT_ERROR("Requesting communication on a busy bus!")*/

		switch (bookKeepingEntry->ActiveTransactions.front()->Type)
		{
			case Transaction_Type::READ:
				chip->StartCMDXfer();
				bookKeepingTable[chip->ChannelID][chip->ChipID].Status = ChipStatus::CMD_IN;
				Simulator->Register_sim_event(Simulator->Time() + bookKeepingEntry->DieInterleavedTime,
					this, bookKeepingEntry, (int)NVDDR2_SimEventType::READ_CMD_ADDR_TRANSFERRED);
				break;
			case Transaction_Type::WRITE:
				if (((NVM_Transaction_Flash_WR*)bookKeepingEntry->ActiveTransactions.front())->RelatedRead == NULL) {
					chip->StartCMDDataInXfer();
					bookKeepingTable[chip->ChannelID][chip->ChipID].Status = ChipStatus::CMD_DATA_IN;
					Simulator->Register_sim_event(Simulator->Time() + bookKeepingEntry->DieInterleavedTime,
						this, bookKeepingEntry, (int)NVDDR2_SimEventType::PROGRAM_CMD_ADDR_DATA_TRANSFERRED);
				} else {
					chip->StartCMDXfer();
					bookKeepingTable[chip->ChannelID][chip->ChipID].Status = ChipStatus::CMD_IN;
					Simulator->Register_sim_event(Simulator->Time() + bookKeepingEntry->DieInterleavedTime, this,
						bookKeepingEntry, (int)NVDDR2_SimEventType::READ_CMD_ADDR_TRANSFERRED);
				}
				break;
			case Transaction_Type::ERASE:
				chip->StartCMDXfer();
				bookKeepingTable[chip->ChannelID][chip->ChipID].Status = ChipStatus::CMD_IN;
				Simulator->Register_sim_event(Simulator->Time() + bookKeepingEntry->DieInterleavedTime,
					this, bookKeepingEntry, (int)NVDDR2_SimEventType::ERASE_SETUP_COMPLETED);
				break;
			default:
				PRINT_ERROR("NVMController_NVDDR2: Uknown flash transaction type!")
		}
		target_channel->SetStatus(BusChannelStatus::BUSY, chip);
	}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq 0x88(%rdi), %rdx
movq 0x8(%r15), %rax
movq 0x10(%rax), %rax
movl 0x8(%rax), %ecx
movl 0x38(%rax), %esi
movq (%rdx,%rsi,8), %r14
cmpl $0x2, %ecx
je 0x4750e
cmpl $0x1, %ecx
je 0x4749e
testl %ecx, %ecx
jne 0x475b8
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
movq %rax, 0x98(%rbx)
movq 0x90(%r12), %rax
movl 0x2c(%rbx), %ecx
movl 0x30(%rbx), %edx
movq (%rax,%rcx,8), %rax
shlq $0x7, %rdx
movl $0x1, (%rax,%rdx)
jmp 0x474de
movq 0x88(%rax), %r13
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
movq %rax, 0x98(%rbx)
movq 0x90(%r12), %rcx
movl 0x2c(%rbx), %edx
movl 0x30(%rbx), %eax
shlq $0x7, %rax
addq (%rcx,%rdx,8), %rax
testq %r13, %r13
je 0x4756c
movl $0x1, (%rax)
callq 0x281b4
movq %rax, %r13
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
addq 0x60(%r15), %rax
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x1, %r8d
jmp 0x4759d
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
movq %rax, 0x98(%rbx)
movq 0x90(%r12), %rax
movl 0x2c(%rbx), %ecx
movl 0x30(%rbx), %edx
movq (%rax,%rcx,8), %rax
shlq $0x7, %rdx
movl $0x1, (%rax,%rdx)
callq 0x281b4
movq %rax, %r13
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
addq 0x60(%r15), %rax
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x4, %r8d
jmp 0x4759d
movl $0x2, (%rax)
callq 0x281b4
movq %rax, %r13
callq 0x281b4
movq %rax, %rdi
callq 0x285a6
addq 0x60(%r15), %rax
movq %r13, %rdi
movq %rax, %rsi
movq %r12, %rdx
movq %r15, %rcx
movl $0x2, %r8d
callq 0x285aa
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x47e24
movq 0x27a31(%rip), %rbx     # 0x6eff0
leaq 0xefe2(%rip), %rsi      # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x12edc(%rip), %rsi     # 0x5a4b1
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x279e4(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
nop