// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movq %rdi, %r12
leaq 0xc0cb(%rip), %rax      # 0x15c38
movq %rax, (%rdi)
addq $0x10, %rdi
movq %rdi, 0x10(%rsp)
movq %r12, %rsi
callq 0xcea8
leaq 0x1c8(%r12), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x1c8(%r12)
andq $0x0, 0x1d8(%r12)
movl %ebp, 0xc(%rsp)
movl %ebp, 0x1e0(%r12)
andq $0x0, 0x1e8(%r12)
andl $0x0, 0x1f8(%r12)
leaq 0x200(%r12), %rdi
movq %rdi, 0x18(%rsp)
callq 0xa5aa
andq $0x0, 0x260(%r12)
andl $0x0, 0x268(%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x270(%r12)
movq %rbx, 0x250(%r12)
andq $0x0, 0x8(%r12)
pushq $0x20
popq %rdi
callq 0x2190
movq %rax, %r13
leaq 0xc05c(%rip), %rbx      # 0x15c68
movq %rbx, (%rax)
movq %r12, 0x8(%rax)
leaq 0x166(%rip), %rax       # 0x9d80
movq %rax, 0x10(%r13)
andq $0x0, 0x18(%r13)
pushq $0x20
popq %rdi
callq 0x2190
movq %rbx, (%rax)
movq %r12, 0x8(%rax)
leaq 0x419(%rip), %rcx       # 0xa052
movq %rcx, 0x10(%rax)
andq $0x0, 0x18(%rax)
movq 0x10(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0xe242
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbx
xorl %ebp, %ebp
cmpq $0x160, %rbp            # imm = 0x160
je 0x9c9a
movq %rbx, %rdi
movl %r15d, %esi
callq 0xc408
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa89c
movq %rbx, %rdi
callq 0xa560
movq (%r14), %rdi
addq %rbp, %rdi
movq %r13, %rsi
callq 0xccfc
addq $0x58, %rbp
incl %r15d
jmp 0x9c5c
movl $0xb0, %edi
callq 0x2190
movq %rax, %r13
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0xacf8
movq %r13, 0x1e8(%r12)
pushq $0x20
popq %rdi
callq 0x2190
leaq 0xbfde(%rip), %rcx      # 0x15ca8
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
leaq 0x105e(%rip), %rcx      # 0xad36
movq %rcx, 0x10(%rax)
andq $0x0, 0x18(%rax)
movq %rax, 0x258(%r12)
pushq $0x20
popq %rdi
callq 0x2190
leaq 0xc000(%rip), %rcx      # 0x15cf8
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
leaq 0x4de(%rip), %rcx       # 0xa1e4
movq %rcx, 0x10(%rax)
andq $0x0, 0x18(%rax)
movq %r13, %rdi
movq %rax, %rsi
callq 0xad32
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9d59
movq %rax, %r12
movl $0xb0, %esi
movq %r13, %rdi
callq 0x21b0
jmp 0x9d5c
jmp 0x9d59
movq %rax, %r12
jmp 0x9d66
jmp 0x9d59
jmp 0x9d59
jmp 0x9d59
movq %rax, %r12
leaq 0x20(%rsp), %rdi
callq 0xa560
jmp 0x9d5c
movq %rax, %r12
movq 0x18(%rsp), %rdi
callq 0xa7e6
movq %r14, %rdi
callq 0xa4b2
movq 0x10(%rsp), %rdi
callq 0xa4d4
movq %r12, %rdi
callq 0x22f0