// File: /workspace/github_cpp_makefile_star2_O2/dramninjasUMD[P]BOBSim/DRAMChannel.cpp
// Function: BOBSim::DRAMChannel::Update()
void DRAMChannel::Update()
{
	if(DEBUG_CHANNEL)
	{
		DEBUG("   == DRAM Channel "<<channelID<<" [DRAM cycle "<<currentClockCycle<<"]");

		DEBUG("     == Read Return Queue");
		for(unsigned i=0; i<readReturnQueue.size(); i++)
		{
			DEBUG("     "<<i<<"] "<<*readReturnQueue[i]);
		}
	}

	if(inFlightDataPacket==NULL)
	{
		DRAMBusIdleCount++;
	}

	//update buses
	if(inFlightCommandPacket!=NULL)
	{
		inFlightCommandCountdown--;
		if(inFlightCommandCountdown==0)
		{
			ranks[inFlightCommandPacket->rank].ReceiveFromBus(inFlightCommandPacket);
			inFlightCommandPacket = NULL;
		}
	}

	if(inFlightDataPacket!=NULL)
	{
		inFlightDataCountdown--;
		if(inFlightDataCountdown==0)
		{
			switch(inFlightDataPacket->busPacketType)
			{
			case READ_DATA:
				if(DEBUG_CHANNEL) DEBUG("     == Data burst complete : " << *inFlightDataPacket);

				//if the bus packet was from a request originating from a logic operation, send it back to logic layer
				if(inFlightDataPacket->fromLogicOp)
				{
					(*SendToLogicLayer)(new Transaction(RETURN_DATA, 64, inFlightDataPacket->address),0);
				}
				//if it was a regular request, add to return queue
				else
				{
					readReturnQueue.push_back(inFlightDataPacket);

					simpleController.outstandingReads--;

					(*ReportCallback)(inFlightDataPacket, 0);

					//keep track of total number of entries in return queue
					if(readReturnQueue.size()>readReturnQueueMax)
					{
						readReturnQueueMax = readReturnQueue.size();
					}
				}
				break;
			case WRITE_DATA:
				//(*ReportCallback)(inFlightDataPacket, 0);
				ranks[inFlightDataPacket->rank].ReceiveFromBus(inFlightDataPacket);
				break;
			default:
				ERROR("Encountered unexpected bus packet type" << *inFlightDataPacket);
				abort();
			}

			inFlightDataPacket = NULL;
		}
	}

	//updates
	if(logicLayer!=NULL)
	{
		logicLayer->Update();
	}

	simpleController.Update();
	for(unsigned i=0; i<NUM_RANKS; i++)
	{
		ranks[i].Update();
	}

	currentClockCycle++;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x270(%rdi), %r15
testq %r15, %r15
jne 0xa2be
incl 0x27c(%rbx)
movq 0x260(%rbx), %rsi
testq %rsi, %rsi
je 0xa2f4
decl 0x268(%rbx)
jne 0xa2f4
movl 0x14(%rsi), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
callq 0xc4d4
andq $0x0, 0x260(%rbx)
movq 0x270(%rbx), %r15
testq %r15, %r15
je 0xa376
decl 0x278(%rbx)
jne 0xa376
leaq 0x270(%rbx), %r14
movl 0x4(%r15), %eax
cmpl $0x8, %eax
je 0xa35b
cmpl $0x7, %eax
jne 0xa418
cmpb $0x1, (%r15)
jne 0xa3c0
movq 0x258(%rbx), %r13
movl $0x90, %edi
callq 0x2190
movq %rax, %r12
movq 0x30(%r15), %rcx
pushq $0x2
popq %rsi
pushq $0x40
popq %rdx
movq %rax, %rdi
callq 0xe6e0
movq (%r13), %rax
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x10(%rax)
jmp 0xa372
movl 0x14(%r15), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
movq %r15, %rsi
callq 0xc4d4
andq $0x0, (%r14)
movq 0x1e8(%rbx), %rdi
testq %rdi, %rdi
je 0xa387
callq 0xad5c
leaq 0x10(%rbx), %rdi
callq 0xd28e
xorl %r14d, %r14d
cmpq $0x160, %r14            # imm = 0x160
je 0xa3b2
movq 0x1c8(%rbx), %rdi
movq (%rdi,%r14), %rax
addq %r14, %rdi
callq *(%rax)
addq $0x58, %r14
jmp 0xa393
incq 0x8(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x200(%rbx), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0xa588
decl 0x100(%rbx)
movq 0x250(%rbx), %rdi
movq 0x270(%rbx), %rsi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x10(%rax)
movq %r15, %rdi
callq 0x5364
movl 0x1f8(%rbx), %ecx
cmpq %rcx, %rax
jbe 0xa372
movq %r15, %rdi
callq 0x5364
movl %eax, 0x1f8(%rbx)
jmp 0xa372
movq 0xbbd1(%rip), %rdi      # 0x15ff0
leaq 0x4d5a(%rip), %rsi      # 0xf180
callq 0x2180
leaq 0x5e19(%rip), %rsi      # 0x1024b
movq %rax, %rdi
callq 0x2180
leaq 0x4ce8(%rip), %rsi      # 0xf129
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movl $0x98, %esi
callq 0x22e0
leaq 0x4d34(%rip), %rsi      # 0xf191
movq %rax, %rdi
callq 0x2180
leaq 0x5def(%rip), %rsi      # 0x1025b
movq %rax, %rdi
callq 0x2180
movq (%r14), %rsi
movq %rax, %rdi
callq 0x98b8
movq %rax, %rdi
callq 0x20b0
callq 0x20e0
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x21b0
movq %rbx, %rdi
callq 0x22f0