// File: /workspace/github_cpp_makefile_star2_O2/CMU-SAFARI[P]MQSim/src/ssd/Data_Cache_Manager_Flash_Simple.cpp
// Function: SSD_Components::Data_Cache_Manager_Flash_Simple::Execute_simulator_event(MQSimEngine::Sim_Event*)
void Data_Cache_Manager_Flash_Simple::Execute_simulator_event(MQSimEngine::Sim_Event* ev)
	{
		Data_Cache_Simulation_Event_Type eventType = (Data_Cache_Simulation_Event_Type)ev->Type;
		Memory_Transfer_Info* transfer_inf = (Memory_Transfer_Info*)ev->Parameters;

		switch (eventType)
			{
			case Data_Cache_Simulation_Event_Type::MEMORY_READ_FOR_USERIO_FINISHED://A user read is service from DRAM cache
			case Data_Cache_Simulation_Event_Type::MEMORY_WRITE_FOR_USERIO_FINISHED:
				((User_Request*)(transfer_inf)->Related_request)->Sectors_serviced_from_cache -= transfer_inf->Size_in_bytes / SECTOR_SIZE_IN_BYTE;
				if (is_user_request_finished((User_Request*)(transfer_inf)->Related_request)) {
					broadcast_user_request_serviced_signal(((User_Request*)(transfer_inf)->Related_request));
				}
				break;
			case Data_Cache_Simulation_Event_Type::MEMORY_READ_FOR_CACHE_EVICTION_FINISHED://Reading data from DRAM and writing it back to the flash storage
				static_cast<FTL*>(nvm_firmware)->Address_Mapping_Unit->Translate_lpa_to_ppa_and_dispatch(*((std::list<NVM_Transaction*>*)(transfer_inf->Related_request)));
				delete (std::list<NVM_Transaction*>*)transfer_inf->Related_request;
				break;
			case Data_Cache_Simulation_Event_Type::MEMORY_WRITE_FOR_CACHE_FINISHED://The recently read data from flash is written back to memory to support future user read requests
				break;
		}

		dram_execution_queue[transfer_inf->Stream_id].pop();
		if (dram_execution_queue[transfer_inf->Stream_id].size() > 0) {
			Memory_Transfer_Info* new_transfer_info = dram_execution_queue[transfer_inf->Stream_id].front();
			Simulator->Register_sim_event(Simulator->Time() + estimate_dram_access_time(new_transfer_info->Size_in_bytes, dram_row_size, dram_busrt_size,
				dram_burst_transfer_time_ddr, dram_tRCD, dram_tCL, dram_tRP),
				this, new_transfer_info, static_cast<int>(new_transfer_info->next_event_type));
		}

		delete transfer_inf;
	}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r14
movl 0x18(%rsi), %eax
movq 0x10(%rsi), %rbx
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x2c0bd
movl (%rbx), %eax
shrl $0x9, %eax
movq 0x8(%rbx), %rsi
movl 0x58(%rsi), %ecx
cmpq $0x0, 0x50(%rsi)
sete %dl
subl %eax, %ecx
movl %ecx, 0x58(%rsi)
sete %al
andb %dl, %al
cmpb $0x1, %al
jne 0x2c0ec
movq %r14, %rdi
callq 0x2956e
jmp 0x2c0ec
testl %eax, %eax
jne 0x2c0ec
movq 0x38(%r14), %rax
movq 0x38(%rax), %rdi
movq 0x8(%rbx), %rsi
movq (%rdi), %rax
callq *0x60(%rax)
movq 0x8(%rbx), %r15
testq %r15, %r15
je 0x2c0e4
movq %r15, %rdi
callq 0x2adc4
movq %r15, %rdi
callq 0x7340
movzwl 0x14(%rbx), %eax
imulq $0x50, %rax, %rdi
addq 0xc8(%r14), %rdi
callq 0x2b006
movzwl 0x14(%rbx), %eax
imulq $0x50, %rax, %rdi
addq 0xc8(%r14), %rdi
callq 0x2afbe
testq %rax, %rax
je 0x2c182
movq 0xc8(%r14), %rax
movzwl 0x14(%rbx), %ecx
imulq $0x50, %rcx, %rcx
movq 0x10(%rax,%rcx), %rax
movq (%rax), %r15
callq 0x1f784
movq %rax, %r12
callq 0x1f784
movq %rax, %rdi
callq 0x1fafc
movq %rax, %r13
movl (%r15), %edi
movl 0x40(%r14), %esi
movl 0x48(%r14), %edx
movsd 0x50(%r14), %xmm0
movq 0x58(%r14), %rcx
movq 0x60(%r14), %r8
movq 0x68(%r14), %r9
callq 0x2abb8
addq %rax, %r13
movl 0x10(%r15), %r8d
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x1fb00
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x7340
nop