// File: dramninjasUMD[P]BOBSim/BOB.cpp
// Function: BOBSim::BOB::ReportCallback(BOBSim::BusPacket*, unsigned int)
void BOB::ReportCallback(BusPacket *bp, unsigned i)
{
	if(bp->busPacketType==ACTIVATE)
	{
		for(unsigned p=0; p<pendingReads.size(); p++)
		{
			if(pendingReads[p]->transactionID==bp->transactionID)
			{
				pendingReads[p]->dramStartTime = currentClockCycle;
				pendingReads[p]->cyclesInWorkQueue=bp->queueWaitTime;
				break;
			}
		}
	}
	else if(bp->busPacketType==WRITE_P)
	{
		if (writeIssuedCB)
		{
			(*writeIssuedCB)(bp->port, bp->address);
		}
	}
	else if(bp->busPacketType==WRITE_DATA)
	{
		committedWrites++;
	}
	else if(bp->busPacketType==READ_DATA)
	{
		for(unsigned p=0; p<pendingReads.size(); p++)
		{
			if(pendingReads[p]->transactionID==bp->transactionID)
			{
				pendingReads[p]->dramTimeTotal = currentClockCycle - pendingReads[p]->dramStartTime;
				break;
			}
		}
	}
	else
	{
		ERROR("== Error - Wrong type of packet received in bob");
		ERROR(*bp);
		exit(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x4, 0x4(%rax)
jne 0x53a2
movl $0x0, -0x18(%rbp)
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %eax
movq %rax, -0x30(%rbp)
addq $0x70, %rdi
callq 0xbe00
movq %rax, %rcx
movq -0x30(%rbp), %rax
cmpq %rcx, %rax
jae 0x539d
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movq (%rax), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x538d
movq -0x28(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x40(%rbp)
addq $0x70, %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movq -0x40(%rbp), %rcx
movq -0x28(%rbp), %rdi
movq (%rax), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x34(%rbp)
addq $0x70, %rdi
movl -0x18(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movl -0x34(%rbp), %ecx
movq (%rax), %rax
movl %ecx, 0x5c(%rax)
jmp 0x539d
jmp 0x538f
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5300
jmp 0x5597
movq -0x10(%rbp), %rax
cmpl $0x3, 0x4(%rax)
jne 0x53df
movq -0x28(%rbp), %rax
cmpq $0x0, 0x1d8(%rax)
je 0x53da
movq -0x28(%rbp), %rax
movq 0x1d8(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdx
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x5595
movq -0x10(%rbp), %rax
cmpl $0x8, 0x4(%rax)
jne 0x5401
movq -0x28(%rbp), %rax
movl 0x1d0(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1d0(%rax)
jmp 0x5593
movq -0x10(%rbp), %rax
cmpl $0x7, 0x4(%rax)
jne 0x54b7
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %eax
movq %rax, -0x48(%rbp)
addq $0x70, %rdi
callq 0xbe00
movq %rax, %rcx
movq -0x48(%rbp), %rax
cmpq %rcx, %rax
jae 0x54b2
movq -0x28(%rbp), %rdi
addq $0x70, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movq (%rax), %rax
movl 0x18(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jne 0x54a2
movq -0x28(%rbp), %rdi
movq 0x8(%rdi), %rax
movq %rax, -0x58(%rbp)
addq $0x70, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movq -0x28(%rbp), %rdi
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq (%rcx), %rcx
subq 0x70(%rcx), %rax
movq %rax, -0x50(%rbp)
addq $0x70, %rdi
movl -0x1c(%rbp), %eax
movl %eax, %esi
callq 0xbe40
movq -0x50(%rbp), %rcx
movq (%rax), %rax
movq %rcx, 0x78(%rax)
jmp 0x54b2
jmp 0x54a4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x5416
jmp 0x5591
movq 0x32b32(%rip), %rdi     # 0x37ff0
leaq 0x24c4b(%rip), %rsi     # 0x2a110
callq 0x31c0
movq %rax, %rdi
leaq 0x24c45(%rip), %rsi     # 0x2a119
callq 0x31c0
movq %rax, %rdi
leaq 0x24bd6(%rip), %rsi     # 0x2a0b9
callq 0x31c0
movq %rax, %rdi
movl $0x449, %esi            # imm = 0x449
callq 0x3380
movq %rax, %rdi
leaq 0x24c22(%rip), %rsi     # 0x2a121
callq 0x31c0
movq %rax, %rdi
leaq 0x255eb(%rip), %rsi     # 0x2aaf9
callq 0x31c0
movq %rax, %rdi
movq 0x32a8b(%rip), %rsi     # 0x37fa8
callq 0x3200
movq 0x32ac7(%rip), %rdi     # 0x37ff0
leaq 0x24be0(%rip), %rsi     # 0x2a110
callq 0x31c0
movq %rax, %rdi
leaq 0x24bda(%rip), %rsi     # 0x2a119
callq 0x31c0
movq %rax, %rdi
leaq 0x24b6b(%rip), %rsi     # 0x2a0b9
callq 0x31c0
movq %rax, %rdi
movl $0x44a, %esi            # imm = 0x44A
callq 0x3380
movq %rax, %rdi
leaq 0x24bb7(%rip), %rsi     # 0x2a121
callq 0x31c0
movq %rax, %rdi
movq -0x10(%rbp), %rsi
callq 0x18f90
movq %rax, %rdi
movq 0x32a23(%rip), %rsi     # 0x37fa8
callq 0x3200
xorl %edi, %edi
callq 0x3270
jmp 0x5593
jmp 0x5595
jmp 0x5597
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)