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

  // 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));
    vector<int> sa_counters(ctrl->channel->spec->org_entry.count[(int)DSARP::Level::SubArray], 0);
    subarray_ref_counters.push_back(sa_counters);
  }

  level_chan = (int)DSARP::Level::Channel;
  level_rank = (int)DSARP::Level::Rank;
  level_bank = (int)DSARP::Level::Bank;
  level_sa   = (int)DSARP::Level::SubArray;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
leaq 0x14e5ee(%rip), %rax    # 0x34d5f0
addq $0x10, %rax
movq %rax, (%rdi)
movq -0x10(%rbp), %rax
movq %rax, 0x8(%rdi)
addq $0x20, %rdi
movq %rdi, -0x78(%rbp)
callq 0x31c30
movq -0x60(%rbp), %rdi
addq $0x50, %rdi
movq %rdi, -0x70(%rbp)
callq 0x32cd0
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
movq %rdi, -0x68(%rbp)
callq 0x32cf0
movq -0x60(%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 0x137e00
movq %rax, %rcx
movq -0x60(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x10(%rbp), %rcx
movq 0x1098(%rcx), %rcx
movq 0x390(%rcx), %rcx
movl 0x30d0(%rcx), %ecx
movl %ecx, 0x3c(%rax)
movq -0x10(%rbp), %rcx
movq 0x1098(%rcx), %rcx
movq 0x390(%rcx), %rcx
movl 0x30d4(%rcx), %ecx
movl %ecx, 0x80(%rax)
movl $0x0, -0x14(%rbp)
movq -0x60(%rbp), %rcx
movl -0x14(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x1ff28e
movq -0x60(%rbp), %rdi
addq $0x20, %rdi
movl $0x0, -0x18(%rbp)
leaq -0x18(%rbp), %rsi
callq 0x32d10
jmp 0x1ff10e
movq -0x60(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x88(%rbp)
movl $0x18, %edi
callq 0xc360
movq %rax, -0x80(%rbp)
jmp 0x1ff12d
movq -0x60(%rbp), %rax
movb $0x1, -0x36(%rbp)
movslq 0x3c(%rax), %rax
movq %rax, -0x98(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x35(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x2fb30
movq -0x80(%rbp), %rdi
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rcx
leaq -0x34(%rbp), %rdx
callq 0x32d70
jmp 0x1ff174
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rax
movb $0x0, -0x36(%rbp)
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rsi
callq 0x32d40
jmp 0x1ff192
leaq -0x35(%rbp), %rdi
callq 0x2fbd0
movq -0x10(%rbp), %rax
movq 0x1098(%rax), %rax
movq 0x390(%rax), %rax
movslq 0x30d4(%rax), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x54(%rbp)
leaq -0x55(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x2fb30
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rcx
leaq -0x50(%rbp), %rdi
leaq -0x54(%rbp), %rdx
callq 0x32d70
jmp 0x1ff1ef
leaq -0x55(%rbp), %rdi
callq 0x2fbd0
movq -0x60(%rbp), %rdi
addq $0x68, %rdi
leaq -0x50(%rbp), %rsi
callq 0x43410
jmp 0x1ff20b
leaq -0x50(%rbp), %rdi
callq 0x2fcd0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1ff0e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x1ff2b7
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 0x1ff250
jmp 0x1ff25e
movq -0x80(%rbp), %rdi
movl $0x18, %esi
callq 0xc370
jmp 0x1ff2b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x55(%rbp), %rdi
callq 0x2fbd0
jmp 0x1ff2b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x2fcd0
jmp 0x1ff2b7
movq -0x60(%rbp), %rax
movl $0x0, 0x40(%rax)
movl $0x1, 0x44(%rax)
movl $0x2, 0x48(%rax)
movl $0x3, 0x4c(%rax)
addq $0xb0, %rsp
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x32df0
movq -0x70(%rbp), %rdi
callq 0x32e50
movq -0x78(%rbp), %rdi
callq 0x2fcd0
movq -0x20(%rbp), %rdi
callq 0xc5d0
nopl (%rax,%rax)