// File: /workspace/github_c_makefile_star2_O3/hamsternz[P]emulate-risc-v/memorymap.c
// Function: memorymap_initialise
int memorymap_initialise(char *image) {
  struct region *r;
  if(!add_region(0x20400000, 118476, ROM_init, ROM_get, ROM_set, ROM_free, ROM_dump)) {
    display_log("Unable to add regions");
    return 0;
  }

  if(!add_region(0x80000000, 0x4000, RAM_init, RAM_get, RAM_set, RAM_free, RAM_dump)) {
    display_log("Unable to add regions");
    return 0;
  }
 
  // AON
  if(!add_region(0x10000000, 0x0170, RAM_init, RAM_get, RAM_set, RAM_free, RAM_dump)) {
    display_log("Unable to add regions");
    return 0;
  }

  // PRCI
  if(!add_region(0x10008000, 0x0FFF, PRCI_init, PRCI_get, PRCI_set, PRCI_free, PRCI_dump)) {
    display_log("Unable to add regions");
    return 0;
  }

  // GPIO 
  if(!add_region(0x10012000, 0x0FFF, GPIO_init, GPIO_get, GPIO_set, GPIO_free, GPIO_dump)) {
    display_log("Unable to add regions");
    return 0;
  }
  
  // UART 
  if(!add_region(0x10013000, 0x0FFF, UART_init, UART_get, UART_set, UART_free, UART_dump)) {
    display_log("Unable to add regions");
    return 0;
  }
  
  // SPI  
  if(!add_region(0x10014000, 0x0080, SPI_init, SPI_get, SPI_set, SPI_free, SPI_dump)) {
    display_log("Unable to add regions");
    return 0;
  }
  

  if(!add_region(0x02000000, 0x10000, CLINT_init, CLINT_get, CLINT_set, CLINT_free, CLINT_dump)) {
    display_log("Unable to add regions");
    return 0;
  }

  r = first_region;
  while(r != NULL) {
    if(!r->init(r)) {
       fprintf(stderr,"Unable to initialize region 0x%08x\n", r->base);
       return 0;
    }
    r = r->next;
  } 
  display_log("Memory map initialized");
  return 1;
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
leaq 0x1dab(%rip), %rax      # 0x55ee
movq %rax, (%rsp)
leaq 0x1ad2(%rip), %rdx      # 0x5320
leaq 0x1d3c(%rip), %rcx      # 0x5591
leaq 0x1cce(%rip), %r8       # 0x552a
leaq 0x1e33(%rip), %r9       # 0x5696
movl $0x20400000, %edi       # imm = 0x20400000
movl $0x1cecc, %esi          # imm = 0x1CECC
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0x959(%rip), %rbx       # 0x41da
movq %rbx, (%rsp)
leaq 0x64c(%rip), %rdx       # 0x3ed8
leaq 0x8ea(%rip), %rcx       # 0x417d
leaq 0x818(%rip), %r8        # 0x40b2
leaq 0x9e1(%rip), %r9        # 0x4282
movl $0x80000000, %edi       # imm = 0x80000000
movl $0x4000, %esi           # imm = 0x4000
callq 0x3a67
testl %eax, %eax
je 0x3a40
movq %rbx, (%rsp)
leaq 0x615(%rip), %rdx       # 0x3ed8
leaq 0x8b3(%rip), %rcx       # 0x417d
leaq 0x7e1(%rip), %r8        # 0x40b2
leaq 0x9aa(%rip), %r9        # 0x4282
movl $0x10000000, %edi       # imm = 0x10000000
movl $0x170, %esi            # imm = 0x170
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0x1941(%rip), %rax      # 0x5237
movq %rax, (%rsp)
leaq 0x1767(%rip), %rdx      # 0x5068
leaq 0x189d(%rip), %rcx      # 0x51a5
leaq 0x179e(%rip), %r8       # 0x50ad
leaq 0x19c9(%rip), %r9       # 0x52df
movl $0x10008000, %edi       # imm = 0x10008000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0x253c(%rip), %rax      # 0x5e70
movq %rax, (%rsp)
leaq 0x2371(%rip), %rdx      # 0x5cb0
leaq 0x24a7(%rip), %rcx      # 0x5ded
leaq 0x23a8(%rip), %r8       # 0x5cf5
leaq 0x25c4(%rip), %r9       # 0x5f18
movl $0x10012000, %edi       # imm = 0x10012000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0xe95(%rip), %rax       # 0x4807
movq %rax, (%rsp)
leaq 0x947(%rip), %rdx       # 0x42c4
leaq 0xc3c(%rip), %rcx       # 0x45c0
leaq 0x985(%rip), %r8        # 0x4310
leaq 0xe89(%rip), %r9        # 0x481b
movl $0x10013000, %edi       # imm = 0x10013000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0x1ef5(%rip), %rax      # 0x58a5
movq %rax, (%rsp)
leaq 0x1d1d(%rip), %rdx      # 0x56d8
leaq 0x1e53(%rip), %rcx      # 0x5815
leaq 0x1d54(%rip), %r8       # 0x571d
leaq 0x1f7d(%rip), %r9       # 0x594d
movl $0x10014000, %edi       # imm = 0x10014000
movl $0x80, %esi
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0x21de(%rip), %rax      # 0x5bc8
movq %rax, (%rsp)
leaq 0x1f97(%rip), %rdx      # 0x598c
leaq 0x20cd(%rip), %rcx      # 0x5ac9
leaq 0x1fce(%rip), %r8       # 0x59d1
leaq 0x2266(%rip), %r9       # 0x5c70
movl $0x2000000, %edi        # imm = 0x2000000
movl $0x10000, %esi          # imm = 0x10000
callq 0x3a67
testl %eax, %eax
je 0x3a40
leaq 0xd0d4(%rip), %rbx      # 0x10af8
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x3a54
movq %rbx, %rdi
callq *0x10(%rbx)
testl %eax, %eax
jne 0x3a24
movq %rbx, %rdi
callq 0x226c
jmp 0x3a4c
leaq 0x447f(%rip), %rdi      # 0x7ec6
callq 0x4d36
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
retq
leaq 0x44a5(%rip), %rdi      # 0x7f00
callq 0x4d36
movl $0x1, %eax
jmp 0x3a4e