// File: 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:
subq $0xb8, %rsp
movw %si, %ax
movq %rdi, 0xb0(%rsp)
movw %ax, 0xae(%rsp)
movq %rdx, 0xa0(%rsp)
movq 0xb0(%rsp), %rdi
movq %rdi, 0x58(%rsp)
movq 0xa0(%rsp), %rsi
movzwl 0xae(%rsp), %edx
callq 0x5a1d0
movq 0x58(%rsp), %rcx
movl %eax, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
movq 0xa8(%rcx), %rcx
movzwl 0xae(%rsp), %edx
movq (%rcx,%rdx,8), %rcx
cmpl 0x268(%rcx), %eax
jb 0x5856d
movq 0x81ac7(%rip), %rdi     # 0xd9ff0
leaq 0x523b8(%rip), %rsi     # 0xaa8e8
callq 0x8440
movq 0x81ab4(%rip), %rdi     # 0xd9ff0
leaq 0x5471a(%rip), %rsi     # 0xacc5d
callq 0x8440
movq %rax, %rdi
movq 0x81a06(%rip), %rsi     # 0xd9f58
callq 0x8480
movq 0x81a72(%rip), %rdi     # 0xd9fd0
callq 0x84f0
movl $0x1, %edi
callq 0x8500
movq 0x58(%rsp), %rax
movq 0xa8(%rax), %rax
movzwl 0xae(%rsp), %ecx
movq (%rax,%rcx,8), %rax
addq $0x88, %rax
movq %rax, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x9c(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x5a2b0
movq 0x50(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x5a280
movq 0x58(%rsp), %rdi
movq %rax, 0x80(%rsp)
movw 0xae(%rsp), %cx
movl 0x9c(%rsp), %edx
movq (%rdi), %rax
movzwl %cx, %esi
callq *0xf0(%rax)
testb $0x1, %al
jne 0x585ed
jmp 0x58617
movq 0x58(%rsp), %rdi
movw 0xae(%rsp), %si
movl 0x9c(%rsp), %edx
movq (%rdi), %rax
movl $0x1, %ecx
movzwl %si, %esi
callq *0xe0(%rax)
jmp 0x58827
movq 0x58(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x50(%rax), %rdi
callq 0x59940
movq 0x58(%rsp), %rax
movq 0xa8(%rax), %rax
movzwl 0xae(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl 0x9c(%rsp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movq %rax, 0x78(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rax, 0x78(%rsp)
jne 0x586b0
movq 0x81984(%rip), %rdi     # 0xd9ff0
leaq 0x52275(%rip), %rsi     # 0xaa8e8
callq 0x8440
movq 0x81971(%rip), %rdi     # 0xd9ff0
leaq 0x54605(%rip), %rsi     # 0xacc8b
callq 0x8440
movq %rax, %rdi
movq 0x818c3(%rip), %rsi     # 0xd9f58
callq 0x8480
movq 0x8192f(%rip), %rdi     # 0xd9fd0
callq 0x84f0
movl $0x1, %edi
callq 0x8500
movl $0xa0, %edi
callq 0x8450
movq %rax, %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x28(%rsp)
movw 0xae(%rsp), %cx
movw %cx, 0x36(%rsp)
movl 0x9c(%rsp), %ecx
movq %rcx, 0x38(%rsp)
movb 0x7c(%rax), %cl
movl $0x1, %eax
shlq %cl, %rax
movq %rax, 0x40(%rsp)
callq 0x46500
movq %rax, 0x48(%rsp)
jmp 0x586fc
movq 0x48(%rsp), %rdi
callq 0x46c50
movq %rax, 0x20(%rsp)
jmp 0x5870d
movq 0x28(%rsp), %rdi
movw 0x36(%rsp), %ax
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rsi
movq 0x20(%rsp), %r8
movq %rsp, %rcx
movq %r8, 0x18(%rcx)
movq %rsi, 0x10(%rcx)
movq %rdx, 0x8(%rcx)
movq $0x0, (%rcx)
movzwl %ax, %edx
movl $0x3, %esi
movl $0x200, %ecx            # imm = 0x200
movq $-0x1, %r9
movq %r9, %r8
callq 0x96180
jmp 0x5875a
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x78(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq $0x38, %rdx
movq (%rdi), %rax
callq *0x88(%rax)
movq 0x58(%rsp), %rax
movq 0x40(%rax), %rdi
movq 0x70(%rsp), %rsi
addq $0x38, %rsi
callq 0x7cd70
movq 0x58(%rsp), %rax
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
movq %rdx, 0x60(%rcx)
movq 0x30(%rax), %rax
movq 0x50(%rax), %rdi
movq 0x70(%rsp), %rsi
callq 0x59980
movq 0x58(%rsp), %rax
leaq 0x82018(%rip), %rcx     # 0xda7e0
movq (%rcx), %rdx
addq $0x1, %rdx
leaq 0x8200a(%rip), %rcx     # 0xda7e0
movq %rdx, (%rcx)
movzwl 0xae(%rsp), %ecx
movl %ecx, %edx
leaq 0x82006(%rip), %rcx     # 0xda7f0
movq (%rcx,%rdx,8), %rsi
addq $0x1, %rsi
leaq 0x81ff7(%rip), %rcx     # 0xda7f0
movq %rsi, (%rcx,%rdx,8)
movq 0x30(%rax), %rax
movq 0x50(%rax), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
jmp 0x58827
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
callq 0x8410
jmp 0x5882f
addq $0xb8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x8770
nopl (%rax)