// File: /workspace/github_cpp_makefile_star2_O3/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 0xd2f0
incl 0x27c(%rbx)
movq 0x260(%rbx), %rsi
testq %rsi, %rsi
je 0xd329
decl 0x268(%rbx)
jne 0xd329
movl 0x14(%rsi), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
callq 0xfa80
movq $0x0, 0x260(%rbx)
movq 0x270(%rbx), %r15
testq %r15, %r15
je 0xd3b6
decl 0x278(%rbx)
jne 0xd3b6
leaq 0x270(%rbx), %r14
movl 0x4(%r15), %eax
cmpl $0x8, %eax
je 0xd398
cmpl $0x7, %eax
jne 0xd4b2
cmpb $0x1, (%r15)
jne 0xd3fe
movq 0x258(%rbx), %r13
movl $0x90, %edi
callq 0x31d0
movq %rax, %r12
movq 0x30(%r15), %rcx
movq %rax, %rdi
movl $0x2, %esi
movl $0x40, %edx
callq 0x122bc
movq (%r13), %rax
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x10(%rax)
jmp 0xd3af
movl 0x14(%r15), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
movq %r15, %rsi
callq 0xfa80
movq $0x0, (%r14)
movq 0x1e8(%rbx), %rdi
testq %rdi, %rdi
je 0xd3c7
callq 0xdf88
leaq 0x10(%rbx), %rdi
callq 0x1087c
xorl %r14d, %r14d
movq 0x1c8(%rbx), %rdi
movq (%rdi,%r14), %rax
addq %r14, %rdi
callq *(%rax)
addq $0x58, %r14
cmpq $0x160, %r14            # imm = 0x160
jne 0xd3d3
incq 0x8(%rbx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x230(%rbx), %rax
movq 0x240(%rbx), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0xd422
movq %r15, (%rax)
addq $0x8, 0x230(%rbx)
jmp 0xd431
leaq 0x200(%rbx), %rdi
movq %r14, %rsi
callq 0xdcb6
decl 0x100(%rbx)
movq 0x250(%rbx), %rdi
movq 0x270(%rbx), %rsi
movq (%rdi), %rax
xorl %edx, %edx
callq *0x10(%rax)
movq 0x248(%rbx), %rax
movq %rax, %rcx
subq 0x228(%rbx), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x230(%rbx), %rdx
subq 0x238(%rbx), %rdx
sarq $0x3, %rdx
movq 0x220(%rbx), %rax
subq 0x210(%rbx), %rax
sarq $0x3, %rax
addq %rdx, %rax
addq %rcx, %rax
movl 0x1f8(%rbx), %ecx
cmpq %rcx, %rax
jbe 0xd3af
movl %eax, 0x1f8(%rbx)
jmp 0xd3af
movq 0xbb37(%rip), %rdi      # 0x18ff0
leaq 0x5d08(%rip), %rsi      # 0x131c8
callq 0x31c0
leaq 0x6e0f(%rip), %rsi      # 0x142db
movq %rax, %rdi
callq 0x31c0
leaq 0x5c96(%rip), %rsi      # 0x13171
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x98, %esi
callq 0x3330
leaq 0x5ce2(%rip), %rsi      # 0x131d9
movq %rax, %rdi
callq 0x31c0
leaq 0x6de5(%rip), %rsi      # 0x142eb
movq %rax, %rdi
callq 0x31c0
movq (%r14), %rsi
movq %rax, %rdi
callq 0xc7bb
movq %rax, %rdi
callq 0x30d0
callq 0x3100
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3340