// File: /workspace/github_cpp_makefile_star2_O3/dramninjasUMD[P]BOBSim/DRAMChannel.cpp
// Function: BOBSim::DRAMChannel::DRAMChannel(unsigned int, BOBSim::Callback<BOBSim::BOB, void, BOBSim::BusPacket*, unsigned int>*)
DRAMChannel::DRAMChannel(unsigned id, Callback<BOB, void, BusPacket*, unsigned> *reportCB):
	inFlightCommandCountdown(0),
	inFlightDataCountdown(0),
	channelID(id),
	inFlightCommandPacket(NULL),
	inFlightDataPacket(NULL),
	readReturnQueueMax(0),
	simpleController(this),
	logicLayer(NULL),
	DRAMBusIdleCount(0)
{
	ReportCallback = reportCB;

	currentClockCycle = 0;

	Callback<DRAMChannel,void,BusPacket*,unsigned> *dataCallback = new Callback<DRAMChannel,void, BusPacket*,unsigned>(this, &DRAMChannel::ReceiveOnDataBus);
	Callback<DRAMChannel,void,BusPacket*,unsigned> *cmdCallback = new Callback<DRAMChannel,void, BusPacket*,unsigned>(this, &DRAMChannel::ReceiveOnCmdBus);
	simpleController.RegisterCallback(cmdCallback, dataCallback);

	for(int i=0; i<NUM_RANKS; i++)
	{
		ranks.push_back(Rank(i));
		ranks[i].RegisterCallback(dataCallback);
	}

	logicLayer = new LogicLayerInterface(id);

	Callback<LogicLayerInterface, void, Transaction*, unsigned> *logicCallback = new Callback<LogicLayerInterface, void, Transaction*, unsigned>(logicLayer, &LogicLayerInterface::ReceiveLogicOperation);
	SendToLogicLayer = logicCallback;

	Callback<DRAMChannel, bool, Transaction*, unsigned> *returnCallback = new Callback<DRAMChannel, bool, Transaction*, unsigned>(this, &DRAMChannel::AddTransaction);
	logicLayer->RegisterReturnCallback(returnCallback);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rbx
movl %esi, %r12d
movq %rdi, %rbp
leaq 0xc0fc(%rip), %rax      # 0x18c30
movq %rax, (%rdi)
leaq 0x10(%rdi), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x1045c
leaq 0x1c8(%rbp), %r14
xorl %eax, %eax
movq %rax, 0x1d8(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x1c8(%rbp)
movl %r12d, 0x4(%rsp)
movl %r12d, 0x1e0(%rbp)
movq %rax, 0x1e8(%rbp)
movl $0x0, 0x1f8(%rbp)
leaq 0x200(%rbp), %r12
movups %xmm0, 0x200(%rbp)
movups %xmm0, 0x210(%rbp)
movups %xmm0, 0x220(%rbp)
movups %xmm0, 0x230(%rbp)
movups %xmm0, 0x240(%rbp)
movq %r12, %rdi
xorl %esi, %esi
movq %r15, 0x10(%rsp)
callq 0xd6d8
xorl %eax, %eax
movq %rax, 0x260(%rbp)
movl $0x0, 0x268(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x270(%rbp)
movq %rbx, 0x250(%rbp)
movq %rax, 0x8(%rbp)
movl $0x20, %edi
movq %r12, 0x8(%rsp)
callq 0x31d0
movq %rax, %r13
leaq 0xc069(%rip), %rbx      # 0x18c60
movq %rbx, (%rax)
movq %rbp, 0x8(%rax)
leaq 0x1ad(%rip), %rax       # 0xcdb2
movq %rax, 0x10(%r13)
movq $0x0, 0x18(%r13)
movl $0x20, %edi
callq 0x31d0
movq %rbx, (%rax)
movq %rbp, 0x8(%rax)
leaq 0x45b(%rip), %rcx       # 0xd084
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x11dd2
movq %rbp, 0x18(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
leaq 0xc0da(%rip), %r12      # 0x18d30
addq $0x10, %r12
xorl %ebx, %ebx
movq %r15, %rdi
movl %ebx, %esi
callq 0xf986
movq %r14, %rdi
movq %r15, %rsi
callq 0xd93c
movq %r12, 0x20(%rsp)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xcc8d
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xcca4
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movq (%r14), %rdi
addq %rbp, %rdi
movq %r13, %rsi
callq 0x10318
incq %rbx
addq $0x58, %rbp
cmpq $0x4, %rbx
jne 0xcc5c
movl $0xb0, %edi
callq 0x31d0
movq 0x18(%rsp), %rbx
movq %rax, %r15
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0xdecc
movq %r15, 0x1e8(%rbx)
movl $0x20, %edi
callq 0x31d0
leaq 0xbfab(%rip), %rcx      # 0x18ca0
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
leaq 0x1223(%rip), %rcx      # 0xdf26
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x258(%rbx)
movl $0x20, %edi
callq 0x31d0
leaq 0xbfc9(%rip), %rcx      # 0x18cf0
movq %rcx, (%rax)
movq %rbx, 0x8(%rax)
leaq 0x4e1(%rip), %rcx       # 0xd216
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0xdf22
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcd8b
movq %rax, %rbx
movl $0xb0, %esi
movq %r15, %rdi
callq 0x31f0
jmp 0xcd8e
jmp 0xcd8b
movq %rax, %rbx
jmp 0xcd98
jmp 0xcd8b
jmp 0xcd8b
jmp 0xcd8b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xd698
jmp 0xcd8e
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0xd84e
movq %r14, %rdi
callq 0xd564
movq 0x10(%rsp), %rdi
callq 0xd594
movq %rbx, %rdi
callq 0x3340