// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rsi), %rsi
callq 0xe1b2
cmpb $0x1, 0x30(%rbx)
jne 0xde8b
movl (%rbx), %eax
cmpl $0x1, %eax
je 0xdf7c
testl %eax, %eax
jne 0xe0da
incl 0xe4(%r14)
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r15
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x14(%rbx), %r11d
shrl $0x4, %r11d
movl 0x10(%rbx), %r12d
pushq $0x1
popq %rsi
movq %r15, %rdi
pushq $0x1
pushq 0x8(%rbx)
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
leaq 0x28(%r14), %rdi
movq %rsp, %rsi
movq %r15, (%rsi)
callq 0xe548
jmp 0xdff4
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r12
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x10(%rbx), %r11d
pushq $0x4
popq %rsi
movq %r12, %rdi
pushq $0x0
pushq 0x8(%rbx)
pushq %r11
pushq $0x0
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
leaq 0x28(%r14), %r15
movq %rsp, %rsi
movq %r12, (%rsi)
movq %r15, %rdi
callq 0xe616
movl (%rbx), %eax
testl %eax, %eax
je 0xe057
cmpl $0x1, %eax
jne 0xe115
incl 0xe8(%r14)
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r12
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x14(%rbx), %r11d
shrl $0x4, %r11d
movl 0x10(%rbx), %r13d
movzbl 0x30(%rbx), %ebp
pushq $0x3
popq %rsi
movq %r12, %rdi
pushq %rbp
pushq 0x8(%rbx)
pushq %r13
pushq %r11
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
movq %rsp, %rsi
movq %r12, (%rsi)
movq %r15, %rdi
callq 0xe616
movl $0x90, %esi
movq %rbx, %rdi
callq 0x21b0
jmp 0xe0c4
incl 0xe8(%r14)
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r15
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x14(%rbx), %r11d
shrl $0x4, %r11d
movl 0x10(%rbx), %r12d
pushq $0x3
popq %rsi
movq %r15, %rdi
pushq $0x1
pushq 0x8(%rbx)
pushq %r12
pushq %r11
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
leaq 0x28(%r14), %rdi
movq %rsp, %rsi
movq %r15, (%rsi)
callq 0xe548
movl $0x90, %esi
movq %rbx, %rdi
callq 0x21b0
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r15
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x10(%rbx), %r11d
movzbl 0x30(%rbx), %r12d
pushq $0x4
popq %rsi
movq %r15, %rdi
pushq %r12
pushq 0x8(%rbx)
pushq %r11
pushq $0x0
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
leaq 0x28(%r14), %rdi
movq %rsp, %rsi
movq %r15, (%rsi)
callq 0xe548
jmp 0xe0c4
incl 0xe4(%r14)
pushq $0x38
popq %rdi
callq 0x2190
movq %rax, %r12
movl 0x18(%rbx), %edx
movl 0x184(%r14), %ecx
movl 0x180(%r14), %r8d
movl 0x178(%r14), %r9d
movl 0x17c(%r14), %eax
movl 0x1c(%rbx), %r10d
movl 0x14(%rbx), %r11d
shrl $0x4, %r11d
movl 0x10(%rbx), %r13d
movzbl 0x30(%rbx), %ebp
pushq $0x1
popq %rsi
movq %r12, %rdi
pushq %rbp
pushq 0x8(%rbx)
pushq %r13
pushq %r11
pushq %r10
pushq %rax
callq 0x9680
addq $0x30, %rsp
movq %rsp, %rsi
movq %r12, (%rsi)
movq %r15, %rdi
callq 0xe616
incl 0xf4(%r14)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7f0f(%rip), %rdi      # 0x15ff0
leaq 0x1098(%rip), %rsi      # 0xf180
callq 0x2180
leaq 0x28bc(%rip), %rsi      # 0x109b0
movq %rax, %rdi
callq 0x2180
leaq 0x1026(%rip), %rsi      # 0xf129
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movl $0x275, %esi            # imm = 0x275
jmp 0xe14e
movq 0x7ed4(%rip), %rdi      # 0x15ff0
leaq 0x105d(%rip), %rsi      # 0xf180
callq 0x2180
leaq 0x2881(%rip), %rsi      # 0x109b0
movq %rax, %rdi
callq 0x2180
leaq 0xfeb(%rip), %rsi       # 0xf129
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movl $0x28f, %esi            # imm = 0x28F
callq 0x22e0
leaq 0x1037(%rip), %rsi      # 0xf191
movq %rax, %rdi
callq 0x2180
leaq 0x28c6(%rip), %rsi      # 0x10a2f
movq %rax, %rdi
callq 0x2180
movq %rax, %rdi
movq %rbx, %rsi
callq 0xe728
movq %rax, %rdi
callq 0x20b0
callq 0x20e0
jmp 0xe19c
jmp 0xe19c
jmp 0xe191
jmp 0xe191
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r15, %rdi
jmp 0xe1a5
movq %rax, %rbx
pushq $0x38
popq %rsi
movq %r12, %rdi
callq 0x21b0
movq %rbx, %rdi
callq 0x22f0