// File: dramninjasUMD[P]BOBSim/SimpleController.cpp
// Function: BOBSim::SimpleController::AddTransaction(BOBSim::Transaction*)
void SimpleController::AddTransaction(Transaction *trans)
{
	//map physical address to rank/bank/row/col
	AddressMapping(trans->address,mappedRank,mappedBank,mappedRow,mappedCol);

	if(GIVE_LOGIC_PRIORITY && trans->originatedFromLogicOp)
	{
		//if requests from logic ops have priority, put them at the front so they go first
		if(DEBUG_LOGIC) DEBUG("  == Simple Controller received transaction from logic op : "<<*trans);
		switch(trans->transactionType)
		{
		case DATA_READ:
			readCounter++;
			//create column read bus packet and add it to command queue
			commandQueue.push_front(new BusPacket(READ_P,trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,trans->transactionSize/DRAM_BUS_WIDTH,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));
			break;
		case DATA_WRITE:
			writeCounter++;
			//create column write bus packet and add it to command queue
			commandQueue.push_front(new BusPacket(WRITE_P,trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,trans->transactionSize/DRAM_BUS_WIDTH,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));
			delete trans;
			break;
		default:
			ERROR("== ERROR - Adding wrong transaction to simple controller : "<<*trans);
			abort();
			break;
		}
		//since we're pushing front, add the ACT after so it ends up being first
		commandQueue.push_front(new BusPacket(ACTIVATE, trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,0,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));
	}
	else
	{
		//create the row activate bus packet and add it to command queue
		commandQueue.push_back(new BusPacket(ACTIVATE, trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,0,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));

		switch(trans->transactionType)
		{
		case DATA_READ:
			readCounter++;
			//create column read bus packet and add it to command queue
			commandQueue.push_back(new BusPacket(READ_P,trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,trans->transactionSize/DRAM_BUS_WIDTH,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));
			break;
		case DATA_WRITE:
			writeCounter++;
			//create column write bus packet and add it to command queue
			commandQueue.push_back(new BusPacket(WRITE_P,trans->transactionID,mappedCol,mappedRow,mappedRank,mappedBank,trans->portID,trans->transactionSize/DRAM_BUS_WIDTH,trans->mappedChannel,trans->address,trans->originatedFromLogicOp));
			delete trans;
			break;
		default:
			ERROR("== ERROR - Adding wrong transaction to simple controller : "<<*trans);
			abort();
			break;
		}
	}

	waitingACTS++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rsi
movq %rdi, %rdx
addq $0x178, %rdx            # imm = 0x178
movq %rdi, %rcx
addq $0x17c, %rcx            # imm = 0x17C
movq %rdi, %r8
addq $0x180, %r8             # imm = 0x180
movq %rdi, %r9
addq $0x184, %r9             # imm = 0x184
callq 0x279d0
testb $0x1, 0x112cc(%rip)     # 0x38508
je 0x27615
movq -0x28(%rbp), %rax
testb $0x1, 0x30(%rax)
je 0x27615
testb $0x1, 0x115f0(%rip)     # 0x38847
je 0x27295
leaq 0x11114(%rip), %rax     # 0x38374
cmpl $0x0, (%rax)
je 0x27293
movq 0x10d5c(%rip), %rdi     # 0x37fc8
leaq 0x4fec(%rip), %rsi      # 0x2c25f
callq 0x31c0
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x294b0
movq %rax, %rdi
movq 0x10d1a(%rip), %rsi     # 0x37fa8
callq 0x3200
jmp 0x27295
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
testl %eax, %eax
je 0x272b5
jmp 0x272a4
movl -0x74(%rbp), %eax
subl $0x1, %eax
je 0x273ae
jmp 0x274cf
movq -0x70(%rbp), %rax
movl 0xe4(%rax), %ecx
incl %ecx
movl %ecx, 0xe4(%rax)
addq $0x28, %rax
movq %rax, -0x98(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x90(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x80(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x84(%rbp)
movl 0x184(%rdx), %ecx
movl 0x180(%rdx), %r8d
movl 0x178(%rdx), %r9d
movl 0x17c(%rdx), %esi
movl 0x1c(%rax), %r10d
movl 0x14(%rax), %eax
movl 0x1117e(%rip), %r11d    # 0x384a4
xorl %edx, %edx
divl %r11d
movl -0x84(%rbp), %edx
movl %eax, %r11d
movq -0x80(%rbp), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r14
movzbl 0x30(%rax), %r15d
andl $0x1, %r15d
movq %rsp, %rax
movl %r15d, 0x28(%rax)
movq %r14, 0x20(%rax)
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x1, %esi
callq 0x18c50
jmp 0x2736c
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x287b0
jmp 0x2754b
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq -0x70(%rbp), %rax
movl 0xe8(%rax), %ecx
incl %ecx
movl %ecx, 0xe8(%rax)
addq $0x28, %rax
movq %rax, -0xb8(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0xa4(%rbp)
movl 0x184(%rdx), %ecx
movl 0x180(%rdx), %r8d
movl 0x178(%rdx), %r9d
movl 0x17c(%rdx), %esi
movl 0x1c(%rax), %r10d
movl 0x14(%rax), %eax
movl 0x11082(%rip), %r11d    # 0x384a4
xorl %edx, %edx
divl %r11d
movl -0xa4(%rbp), %edx
movl %eax, %r11d
movq -0xa0(%rbp), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r14
movzbl 0x30(%rax), %r15d
andl $0x1, %r15d
movq %rsp, %rax
movl %r15d, 0x28(%rax)
movq %r14, 0x20(%rax)
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x3, %esi
callq 0x18c50
jmp 0x2746b
movq -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x287b0
movq -0x28(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpq $0x0, %rax
je 0x274a8
movq -0xc0(%rbp), %rdi
movl $0x90, %esi
callq 0x31f0
jmp 0x2754b
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq 0x10b1a(%rip), %rdi     # 0x37ff0
leaq 0x2c33(%rip), %rsi      # 0x2a110
callq 0x31c0
movq %rax, %rdi
leaq 0x4c5e(%rip), %rsi      # 0x2c14a
callq 0x31c0
movq %rax, %rdi
leaq 0x2bbe(%rip), %rsi      # 0x2a0b9
callq 0x31c0
movq %rax, %rdi
movl $0x275, %esi            # imm = 0x275
callq 0x3380
movq %rax, %rdi
leaq 0x2c0a(%rip), %rsi      # 0x2a121
callq 0x31c0
movq %rax, %rdi
leaq 0x4d76(%rip), %rsi      # 0x2c29c
callq 0x31c0
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x294b0
movq %rax, %rdi
movq 0x10a67(%rip), %rsi     # 0x37fa8
callq 0x3200
callq 0x30f0
movq -0x70(%rbp), %rax
addq $0x28, %rax
movq %rax, -0xd0(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %edx
movl 0x184(%rsi), %ecx
movl 0x180(%rsi), %r8d
movl 0x178(%rsi), %r9d
movl 0x17c(%rsi), %esi
movl 0x1c(%rax), %r10d
movl 0x10(%rax), %r11d
movq 0x8(%rax), %rbx
movzbl 0x30(%rax), %r14d
andl $0x1, %r14d
movq %rsp, %rax
movl %r14d, 0x28(%rax)
movq %rbx, 0x20(%rax)
movl %r11d, 0x18(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x0, 0x10(%rax)
movl $0x4, %esi
callq 0x18c50
jmp 0x275d3
movq -0xd0(%rbp), %rdi
movq -0xc8(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq -0x50(%rbp), %rsi
callq 0x287b0
jmp 0x2799e
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq -0x70(%rbp), %rax
addq $0x28, %rax
movq %rax, -0xe0(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rsi
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd8(%rbp)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %edx
movl 0x184(%rsi), %ecx
movl 0x180(%rsi), %r8d
movl 0x178(%rsi), %r9d
movl 0x17c(%rsi), %esi
movl 0x1c(%rax), %r10d
movl 0x10(%rax), %r11d
movq 0x8(%rax), %rbx
movzbl 0x30(%rax), %r14d
andl $0x1, %r14d
movq %rsp, %rax
movl %r14d, 0x28(%rax)
movq %rbx, 0x20(%rax)
movl %r11d, 0x18(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x0, 0x10(%rax)
movl $0x4, %esi
callq 0x18c50
jmp 0x2769d
movq -0xe0(%rbp), %rdi
movq -0xd8(%rbp), %rax
movq %rax, -0x58(%rbp)
leaq -0x58(%rbp), %rsi
callq 0x287e0
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
testl %eax, %eax
je 0x27700
jmp 0x276ca
movl -0xe4(%rbp), %eax
subl $0x1, %eax
je 0x277ff
jmp 0x27920
movq -0xd8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq -0x70(%rbp), %rax
movl 0xe4(%rax), %ecx
incl %ecx
movl %ecx, 0xe4(%rax)
addq $0x28, %rax
movq %rax, -0x108(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x100(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xf0(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0xf4(%rbp)
movl 0x184(%rdx), %ecx
movl 0x180(%rdx), %r8d
movl 0x178(%rdx), %r9d
movl 0x17c(%rdx), %esi
movl 0x1c(%rax), %r10d
movl 0x14(%rax), %eax
movl 0x10d30(%rip), %r11d    # 0x384a4
xorl %edx, %edx
divl %r11d
movl -0xf4(%rbp), %edx
movl %eax, %r11d
movq -0xf0(%rbp), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r14
movzbl 0x30(%rax), %r15d
andl $0x1, %r15d
movq %rsp, %rax
movl %r15d, 0x28(%rax)
movq %r14, 0x20(%rax)
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x1, %esi
callq 0x18c50
jmp 0x277bd
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rax
movq %rax, -0x60(%rbp)
leaq -0x60(%rbp), %rsi
callq 0x287e0
jmp 0x2799c
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq -0x70(%rbp), %rax
movl 0xe8(%rax), %ecx
incl %ecx
movl %ecx, 0xe8(%rax)
addq $0x28, %rax
movq %rax, -0x128(%rbp)
movl $0x38, %edi
callq 0x31d0
movq -0x70(%rbp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x110(%rbp)
movl 0x18(%rax), %ecx
movl %ecx, -0x114(%rbp)
movl 0x184(%rdx), %ecx
movl 0x180(%rdx), %r8d
movl 0x178(%rdx), %r9d
movl 0x17c(%rdx), %esi
movl 0x1c(%rax), %r10d
movl 0x14(%rax), %eax
movl 0x10c31(%rip), %r11d    # 0x384a4
xorl %edx, %edx
divl %r11d
movl -0x114(%rbp), %edx
movl %eax, %r11d
movq -0x110(%rbp), %rax
movl 0x10(%rax), %ebx
movq 0x8(%rax), %r14
movzbl 0x30(%rax), %r15d
andl $0x1, %r15d
movq %rsp, %rax
movl %r15d, 0x28(%rax)
movq %r14, 0x20(%rax)
movl %ebx, 0x18(%rax)
movl %r11d, 0x10(%rax)
movl %r10d, 0x8(%rax)
movl %esi, (%rax)
movl $0x3, %esi
callq 0x18c50
jmp 0x278bc
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x68(%rbp), %rsi
callq 0x287e0
movq -0x28(%rbp), %rax
movq %rax, -0x130(%rbp)
cmpq $0x0, %rax
je 0x278f9
movq -0x130(%rbp), %rdi
movl $0x90, %esi
callq 0x31f0
jmp 0x2799c
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x38, %esi
callq 0x31f0
jmp 0x279bf
movq 0x106c9(%rip), %rdi     # 0x37ff0
leaq 0x27e2(%rip), %rsi      # 0x2a110
callq 0x31c0
movq %rax, %rdi
leaq 0x480d(%rip), %rsi      # 0x2c14a
callq 0x31c0
movq %rax, %rdi
leaq 0x276d(%rip), %rsi      # 0x2a0b9
callq 0x31c0
movq %rax, %rdi
movl $0x28f, %esi            # imm = 0x28F
callq 0x3380
movq %rax, %rdi
leaq 0x27b9(%rip), %rsi      # 0x2a121
callq 0x31c0
movq %rax, %rdi
leaq 0x4925(%rip), %rsi      # 0x2c29c
callq 0x31c0
movq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x294b0
movq %rax, %rdi
movq 0x10616(%rip), %rsi     # 0x37fa8
callq 0x3200
callq 0x30f0
jmp 0x2799e
movq -0x70(%rbp), %rax
movl 0xf4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xf4(%rax)
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x33a0
nopl (%rax,%rax)