// File: CMU-SAFARI[P]MQSim/src/nvm_chip/flash_memory/Flash_Chip.cpp
// Function: NVM::FlashMemory::Flash_Chip::Flash_Chip(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, unsigned int, unsigned int, Flash_Technology_Type, unsigned int, unsigned int, unsigned int, unsigned int, unsigned long*, unsigned long*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)
Flash_Chip::Flash_Chip(const sim_object_id_type& id, flash_channel_ID_type channelID, flash_chip_ID_type localChipID,
			Flash_Technology_Type flash_technology, 
			unsigned int dieNo, unsigned int PlaneNoPerDie, unsigned int Block_no_per_plane, unsigned int Page_no_per_block,
			sim_time_type* readLatency, sim_time_type* programLatency, sim_time_type eraseLatency,
			sim_time_type suspendProgramLatency, sim_time_type suspendEraseLatency,
			sim_time_type commProtocolDelayRead, sim_time_type commProtocolDelayWrite, sim_time_type commProtocolDelayErase)
			: NVM_Chip(id), ChannelID(channelID), ChipID(localChipID), flash_technology(flash_technology),
			status(Internal_Status::IDLE), die_no(dieNo), plane_no_in_die(PlaneNoPerDie), block_no_in_plane(Block_no_per_plane), page_no_per_block(Page_no_per_block),
			_RBSignalDelayRead(commProtocolDelayRead), _RBSignalDelayWrite(commProtocolDelayWrite), _RBSignalDelayErase(commProtocolDelayErase),
			lastTransferStart(INVALID_TIME), executionStartTime(INVALID_TIME), expectedFinishTime(INVALID_TIME),
			STAT_readCount(0), STAT_progamCount(0), STAT_eraseCount(0),
			STAT_totalSuspensionCount(0), STAT_totalResumeCount(0),
			STAT_totalExecTime(0), STAT_totalXferTime(0), STAT_totalOverlappedXferExecTime(0)
		{
			int bits_per_cell = static_cast<int>(flash_technology);
			_readLatency = new sim_time_type[bits_per_cell];
			_programLatency = new sim_time_type[bits_per_cell];
			for (int i = 0; i < bits_per_cell; i++) {
				_readLatency[i] = readLatency[i];
				_programLatency[i] = programLatency[i];
			}
			_eraseLatency = eraseLatency;
			_suspendProgramLatency = suspendProgramLatency;
			_suspendEraseLatency = suspendEraseLatency;
			idleDieNo = dieNo;
			Dies = new Die*[dieNo];
			for (unsigned int dieID = 0; dieID < dieNo; dieID++) {
				Dies[dieID] = new Die(PlaneNoPerDie, Block_no_per_plane, Page_no_per_block);
			}
		}

// Assembly:
subq $0x78, %rsp
movq 0xd0(%rsp), %rax
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rax
movq 0xb8(%rsp), %rax
movq 0xb0(%rsp), %rax
movq 0xa8(%rsp), %rax
movq 0xa0(%rsp), %rax
movq 0x98(%rsp), %rax
movl 0x90(%rsp), %eax
movl 0x88(%rsp), %eax
movl 0x80(%rsp), %eax
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movl %edx, 0x64(%rsp)
movl %ecx, 0x60(%rsp)
movl %r8d, 0x5c(%rsp)
movl %r9d, 0x58(%rsp)
movq 0x70(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq 0x68(%rsp), %rsi
callq 0x455e0
movq 0x20(%rsp), %rdi
leaq 0x95a1b(%rip), %rax     # 0xd8df0
movq %rax, (%rdi)
movl 0x64(%rsp), %eax
movl %eax, 0x2c(%rdi)
movl 0x60(%rsp), %eax
movl %eax, 0x30(%rdi)
movl 0x5c(%rsp), %eax
movl %eax, 0x34(%rdi)
movl $0x0, 0x38(%rdi)
movl 0x58(%rsp), %eax
movl %eax, 0x48(%rdi)
movl 0x80(%rsp), %eax
movl %eax, 0x4c(%rdi)
movl 0x88(%rsp), %eax
movl %eax, 0x50(%rdi)
movl 0x90(%rsp), %eax
movl %eax, 0x54(%rdi)
movq 0xc0(%rsp), %rax
movq %rax, 0x80(%rdi)
movq 0xc8(%rsp), %rax
movq %rax, 0x88(%rdi)
movq 0xd0(%rsp), %rax
movq %rax, 0x90(%rdi)
movq $-0x1, 0x98(%rdi)
movq $-0x1, 0xa0(%rdi)
movq $-0x1, 0xa8(%rdi)
movq $0x0, 0xb0(%rdi)
movq $0x0, 0xb8(%rdi)
movq $0x0, 0xc0(%rdi)
movq $0x0, 0xc8(%rdi)
movq $0x0, 0xd0(%rdi)
movq $0x0, 0xd8(%rdi)
movq $0x0, 0xe0(%rdi)
movq $0x0, 0xe8(%rdi)
addq $0xf0, %rdi
movq %rdi, 0x28(%rsp)
callq 0x45620
movl 0x5c(%rsp), %eax
movl %eax, 0x54(%rsp)
movslq 0x54(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x8030
movq %rax, 0x30(%rsp)
jmp 0x434ff
movq 0x20(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x58(%rax)
movslq 0x54(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x8030
movq %rax, 0x18(%rsp)
jmp 0x43534
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x60(%rax)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x435b5
movq 0x20(%rsp), %rax
movq 0x98(%rsp), %rcx
movslq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %rsi
movq 0x58(%rax), %rcx
movslq 0x40(%rsp), %rdx
movq %rsi, (%rcx,%rdx,8)
movq 0xa0(%rsp), %rcx
movslq 0x40(%rsp), %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x60(%rax), %rax
movslq 0x40(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x4354a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
jmp 0x4368f
movq 0x20(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq %rcx, 0x68(%rax)
movq 0xb0(%rsp), %rcx
movq %rcx, 0x70(%rax)
movq 0xb8(%rsp), %rcx
movq %rcx, 0x78(%rax)
movl 0x58(%rsp), %ecx
movl %ecx, 0x3c(%rax)
movl 0x58(%rsp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x8030
movq %rax, 0x10(%rsp)
jmp 0x435fb
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x40(%rax)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x58(%rsp), %eax
jae 0x4368a
movl $0x60, %edi
callq 0x8450
movq %rax, 0x8(%rsp)
jmp 0x4362c
movq 0x8(%rsp), %rdi
movl 0x80(%rsp), %esi
movl 0x88(%rsp), %edx
movl 0x90(%rsp), %ecx
callq 0x43180
jmp 0x4364d
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rax
movq 0x40(%rax), %rax
movl 0x3c(%rsp), %ecx
movq %rdx, (%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x43611
movq 0x8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x48(%rsp)
movl %eax, 0x44(%rsp)
callq 0x8410
jmp 0x4368f
addq $0x78, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x45630
movq 0x20(%rsp), %rdi
callq 0x45690
movq 0x48(%rsp), %rdi
callq 0x8770
nopl (%rax)