// File: /workspace/github_cpp_makefile_star2_O1/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
cmpq $0x0, 0x270(%rdi)
jne 0xd4da
incl 0x27c(%rbx)
leaq 0x270(%rbx), %r14
movq 0x260(%rbx), %rsi
testq %rsi, %rsi
je 0xd513
decl 0x268(%rbx)
jne 0xd513
movl 0x14(%rsi), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
callq 0xfbee
movq $0x0, 0x260(%rbx)
movq (%r14), %r15
testq %r15, %r15
je 0xd598
decl 0x278(%rbx)
jne 0xd598
movl 0x4(%r15), %eax
cmpl $0x8, %eax
je 0xd57a
cmpl $0x7, %eax
jne 0xd694
cmpb $0x1, (%r15)
jne 0xd5e0
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 0x123f0
movq (%r13), %rax
movq %r13, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq *0x10(%rax)
jmp 0xd591
movl 0x14(%r15), %eax
imulq $0x58, %rax, %rdi
addq 0x1c8(%rbx), %rdi
movq %r15, %rsi
callq 0xfbee
movq $0x0, (%r14)
movq 0x1e8(%rbx), %rdi
testq %rdi, %rdi
je 0xd5a9
callq 0xe1b0
leaq 0x10(%rbx), %rdi
callq 0x10ada
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 0xd5b5
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 0xd604
movq %r15, (%rax)
addq $0x8, 0x230(%rbx)
jmp 0xd613
leaq 0x200(%rbx), %rdi
movq %r14, %rsi
callq 0xdee0
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 0xd591
movl %eax, 0x1f8(%rbx)
jmp 0xd591
movq 0xb955(%rip), %rdi      # 0x18ff0
leaq 0x5ad6(%rip), %rsi      # 0x13178
callq 0x31c0
leaq 0x6b8d(%rip), %rsi      # 0x1423b
movq %rax, %rdi
callq 0x31c0
leaq 0x5a64(%rip), %rsi      # 0x13121
movq %rax, %rdi
callq 0x31c0
movq %rax, %rdi
movl $0x98, %esi
callq 0x3330
leaq 0x5ab0(%rip), %rsi      # 0x13189
movq %rax, %rdi
callq 0x31c0
leaq 0x6b63(%rip), %rsi      # 0x1424b
movq %rax, %rdi
callq 0x31c0
movq (%r14), %rsi
movq %rax, %rdi
callq 0xc9a7
movq %rax, %rdi
callq 0x30d0
callq 0x3100
movq %rax, %rbx
movl $0x90, %esi
movq %r12, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x3340