// File: CMU-SAFARI[P]ramulator/src/Refresh.h
// Function: ramulator::Refresh<ramulator::DDR3>::Refresh(ramulator::Controller<ramulator::DDR3>*)
Refresh(Controller<T>* ctrl) : ctrl(ctrl) {
    clk = refreshed = 0;
    max_rank_count = ctrl->channel->children.size();
    max_bank_count = ctrl->channel->spec->org_entry.count[(int)T::Level::Bank];

    // Init refresh counters
    for (int r = 0; r < max_rank_count; r++) {
      bank_ref_counters.push_back(0);
      bank_refresh_backlog.push_back(new vector<int>(max_bank_count, 0));
    }

    level_chan = (int)T::Level::Channel;
    level_rank = (int)T::Level::Rank;
    level_bank = (int)T::Level::Bank;
    level_sa   = -1; // Most DRAM doesn't have subarray level
  }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x40(%rbp)
leaq 0x31e0e6(%rip), %rax    # 0x34b468
addq $0x10, %rax
movq %rax, (%rdi)
movq -0x10(%rbp), %rax
movq %rax, 0x8(%rdi)
addq $0x20, %rdi
movq %rdi, -0x58(%rbp)
callq 0x31c30
movq -0x40(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x50(%rbp)
callq 0x32cd0
movq -0x40(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x48(%rbp)
callq 0x32cf0
movq -0x40(%rbp), %rax
movl $0x0, 0x80(%rax)
movl $0x8, 0x84(%rax)
movl $0xfffffff8, 0x88(%rax) # imm = 0xFFFFFFF8
movl $0xfffffffa, 0x8c(%rax) # imm = 0xFFFFFFFA
movb $0x0, 0x90(%rax)
movq $0x0, 0x18(%rax)
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x1098(%rax), %rdi
addq $0x3b0, %rdi            # imm = 0x3B0
callq 0x2bfd0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rcx
movq 0x1098(%rcx), %rcx
movq 0x390(%rcx), %rcx
movl 0x2734(%rcx), %ecx
movl %ecx, 0x3c(%rax)
movl $0x0, -0x14(%rbp)
movq -0x40(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x2d534
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
movl $0x0, -0x18(%rbp)
leaq -0x18(%rbp), %rsi
callq 0x32d10
jmp 0x2d470
movq -0x40(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x68(%rbp)
movl $0x18, %edi
callq 0xc360
movq %rax, -0x60(%rbp)
jmp 0x2d48c
movq -0x40(%rbp), %rax
movb $0x1, -0x36(%rbp)
movslq 0x3c(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x35(%rbp), %rdi
movq %rdi, -0x70(%rbp)
callq 0x2fb30
movq -0x60(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rcx
leaq -0x34(%rbp), %rdx
callq 0x32d70
jmp 0x2d4c7
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rax
movb $0x0, -0x36(%rbp)
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x32d40
jmp 0x2d4e2
leaq -0x35(%rbp), %rdi
callq 0x2fbd0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x2d446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x2d55d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x35(%rbp), %rdi
callq 0x2fbd0
testb $0x1, -0x36(%rbp)
jne 0x2d524
jmp 0x2d532
movq -0x60(%rbp), %rdi
movl $0x18, %esi
callq 0xc370
jmp 0x2d55d
movq -0x40(%rbp), %rax
movl $0x0, 0x40(%rax)
movl $0x1, 0x44(%rax)
movl $0x2, 0x48(%rax)
movl $0xffffffff, 0x4c(%rax) # imm = 0xFFFFFFFF
addq $0x80, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x32df0
movq -0x50(%rbp), %rdi
callq 0x32e50
movq -0x58(%rbp), %rdi
callq 0x2fcd0
movq -0x20(%rbp), %rdi
callq 0xc5d0
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)