// File: /workspace/github_cpp_makefile_star2_O1/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 0xbef8(%rip), %rax      # 0x18c18
movq %rax, (%rdi)
leaq 0x10(%rdi), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x105d0
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 0xd8ba
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 0xbe7d(%rip), %rbx      # 0x18c60
movq %rbx, (%rax)
movq %rbp, 0x8(%rax)
leaq 0x1ad(%rip), %rax       # 0xcf9e
movq %rax, 0x10(%r13)
movq $0x0, 0x18(%r13)
movl $0x20, %edi
callq 0x31d0
movq %rbx, (%rax)
movq %rbp, 0x8(%rax)
leaq 0x45b(%rip), %rcx       # 0xd270
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x11ee0
movq %rbp, 0x18(%rsp)
xorl %ebp, %ebp
leaq 0x20(%rsp), %r15
leaq 0xbeee(%rip), %r12      # 0x18d30
addq $0x10, %r12
xorl %ebx, %ebx
movq %r15, %rdi
movl %ebx, %esi
callq 0xfb02
movq %r14, %rdi
movq %r15, %rsi
callq 0xdb16
movq %r12, 0x20(%rsp)
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xce79
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0xce90
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x31f0
movq (%r14), %rdi
addq %rbp, %rdi
movq %r13, %rsi
callq 0x1048e
incq %rbx
addq $0x58, %rbp
cmpq $0x4, %rbx
jne 0xce48
movl $0xb0, %edi
callq 0x31d0
movq 0x18(%rsp), %rbx
movq %rax, %r15
movq %rax, %rdi
movl 0x4(%rsp), %esi
callq 0xe0f4
movq %r15, 0x1e8(%rbx)
movl $0x20, %edi
callq 0x31d0
leaq 0xbdbf(%rip), %rcx      # 0x18ca0
movq %rcx, (%rax)
movq %r15, 0x8(%rax)
leaq 0x125f(%rip), %rcx      # 0xe14e
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %rax, 0x258(%rbx)
movl $0x20, %edi
callq 0x31d0
leaq 0xbddd(%rip), %rcx      # 0x18cf0
movq %rcx, (%rax)
movq %rbx, 0x8(%rax)
leaq 0x4e1(%rip), %rcx       # 0xd402
movq %rcx, 0x10(%rax)
movq $0x0, 0x18(%rax)
movq %r15, %rdi
movq %rax, %rsi
callq 0xe14a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xcf77
movq %rax, %rbx
movl $0xb0, %esi
movq %r15, %rdi
callq 0x31f0
jmp 0xcf7a
jmp 0xcf77
movq %rax, %rbx
jmp 0xcf84
jmp 0xcf77
jmp 0xcf77
jmp 0xcf77
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0xd87a
jmp 0xcf7a
movq %rax, %rbx
movq 0x8(%rsp), %rdi
callq 0xda30
movq %r14, %rdi
callq 0xd746
movq 0x10(%rsp), %rdi
callq 0xd776
movq %rbx, %rdi
callq 0x3340