// File: /workspace/github_cpp_makefile_star2_O3/CMU-SAFARI[P]MQSim/src/ssd/Address_Mapping_Unit_Page_Level.cpp
// Function: SSD_Components::Address_Mapping_Unit_Page_Level::generate_flash_read_request_for_mapping_data(unsigned short, unsigned long)
void Address_Mapping_Unit_Page_Level::generate_flash_read_request_for_mapping_data(const stream_id_type stream_id, const LPA_type lpn)
	{
		MVPN_type mvpn = get_MVPN(lpn, stream_id);

		if (mvpn >= domains[stream_id]->Total_translation_pages_no) {
			PRINT_ERROR("Out of range virtual translation page number!")
		}

		domains[stream_id]->ArrivingMappingEntries.insert(std::pair<MVPN_type, LPA_type>(mvpn, lpn));

		if (is_mvpn_locked_for_gc(stream_id, mvpn)) {
			manage_mapping_transaction_facing_barrier(stream_id, mvpn, true);
		} else {
			ftl->TSU->Prepare_for_transaction_submit();

			PPA_type ppn = domains[stream_id]->GlobalTranslationDirectory[mvpn].MPPN;

			if (ppn == NO_MPPN){
				PRINT_ERROR("Reading an invalid physical flash page address in function generate_flash_read_request_for_mapping_data!")
			}

			NVM_Transaction_Flash_RD* readTR = new NVM_Transaction_Flash_RD(Transaction_Source_Type::MAPPING, stream_id,
					SECTOR_SIZE_IN_BYTE, NO_LPA, NO_PPA, NULL, mvpn, ((page_status_type)0x1) << sector_no_per_page, CurrentTimeStamp);
			Convert_ppa_to_address(ppn, readTR->Address);
			block_manager->Read_transaction_issued(readTR->Address);//Inform block_manager as soon as the transaction's target address is determined
			readTR->PPA = ppn;
			ftl->TSU->Submit_transaction(readTR);

			Stats::Total_flash_reads_for_mapping++;
			Stats::Total_flash_reads_for_mapping_per_stream[stream_id]++;

			ftl->TSU->Schedule();
		}
	}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rcx
movl %esi, %ebp
movq %rdi, %rbx
movl 0xc0(%rdi), %esi
movq %rdx, %rax
xorl %edx, %edx
divq %rsi
movq %rax, %r14
movq 0xa8(%rdi), %rax
movl %ebp, %r15d
movq (%rax,%r15,8), %rdi
cmpl %r14d, 0x268(%rdi)
jbe 0x2f09e
addq $0x88, %rdi
leaq 0x8(%rsp), %rsi
movl %r14d, (%rsi)
movq %rcx, 0x8(%rsi)
callq 0x31222
movq (%rbx), %rax
movzwl %bp, %ebp
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq *0xf0(%rax)
testb %al, %al
je 0x2ef83
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl $0x1, %ecx
callq *0xe0(%rax)
jmp 0x2f08f
movq 0x30(%rbx), %rax
movq 0x50(%rax), %rdi
callq 0x2f762
movq 0xa8(%rbx), %rax
movq %r15, (%rsp)
movq (%rax,%r15,8), %rax
movq (%rax), %rax
movl %r14d, %r12d
movq %r12, %rcx
shlq $0x4, %rcx
movl (%rax,%rcx), %r15d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, %r15
je 0x2f0bd
movl $0xa0, %edi
callq 0x73a0
movq %rax, %r14
movb 0x7c(%rbx), %cl
movl $0x1, %r13d
shlq %cl, %r13
callq 0x28018
movq %rax, %rdi
callq 0x2841a
movq %r14, %rdi
movl $0x3, %esi
movl %ebp, %edx
movl $0x200, %ecx            # imm = 0x200
movq $-0x1, %r8
movq $-0x1, %r9
pushq %rax
pushq %r13
pushq %r12
pushq $0x0
callq 0x48114
addq $0x20, %rsp
movq %r14, %r12
addq $0x38, %r12
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x88(%rax)
movq 0x40(%rbx), %rdi
movq %r12, %rsi
callq 0x3d7d8
movq %r15, 0x60(%r14)
movq 0x30(%rbx), %rax
movq 0x50(%rax), %r12
leaq 0x78(%r12), %r15
movl $0x18, %edi
callq 0x73a0
movq %r14, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x7060
incq 0x88(%r12)
leaq 0x406b1(%rip), %rax     # 0x6f720
incq (%rax)
leaq 0x406b7(%rip), %rax     # 0x6f730
movq (%rsp), %rcx
incq (%rax,%rcx,8)
movq 0x30(%rbx), %rax
movq 0x50(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3ff4b(%rip), %rbx     # 0x6eff0
leaq 0x274fc(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x29b32(%rip), %rsi     # 0x58bed
jmp 0x2f0da
movq 0x3ff2c(%rip), %rbx     # 0x6eff0
leaq 0x274dd(%rip), %rsi     # 0x565a8
movq %rbx, %rdi
callq 0x7390
leaq 0x29b41(%rip), %rsi     # 0x58c1b
movq %rbx, %rdi
callq 0x7390
movq %rax, %rdi
callq 0x71c0
movq 0x3fedf(%rip), %rdi     # 0x6efd0
callq 0x7430
movl $0x1, %edi
callq 0x7440
movq %rax, %rbx
movq %r14, %rdi
callq 0x7370
movq %rbx, %rdi
callq 0x7620
nop