// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movl $0x20400000, %edi       # imm = 0x20400000
movl $0x1cecc, %esi          # imm = 0x1CECC
leaq 0x31c6(%rip), %rdx      # 0x7570
leaq 0x368f(%rip), %rcx      # 0x7a40
leaq 0x35d8(%rip), %r8       # 0x7990
leaq 0x38d1(%rip), %r9       # 0x7c90
leaq 0x37ca(%rip), %rax      # 0x7b90
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x43ed
leaq 0x6a7d(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x80000000, %edi       # imm = 0x80000000
movl $0x4000, %esi           # imm = 0x4000
leaq 0xbb2(%rip), %rdx       # 0x4fb0
leaq 0x10ab(%rip), %rcx      # 0x54b0
leaq 0xf54(%rip), %r8        # 0x5360
leaq 0x12ed(%rip), %r9       # 0x5700
leaq 0x11e6(%rip), %rax      # 0x5600
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x4441
leaq 0x6a29(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x10000000, %edi       # imm = 0x10000000
movl $0x170, %esi            # imm = 0x170
leaq 0xb5e(%rip), %rdx       # 0x4fb0
leaq 0x1057(%rip), %rcx      # 0x54b0
leaq 0xf00(%rip), %r8        # 0x5360
leaq 0x1299(%rip), %r9       # 0x5700
leaq 0x1192(%rip), %rax      # 0x5600
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x4495
leaq 0x69d5(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x10008000, %edi       # imm = 0x10008000
movl $0xfff, %esi            # imm = 0xFFF
leaq 0x2b7a(%rip), %rdx      # 0x7020
leaq 0x2d93(%rip), %rcx      # 0x7240
leaq 0x2c0c(%rip), %r8       # 0x70c0
leaq 0x3065(%rip), %r9       # 0x7520
leaq 0x2f5e(%rip), %rax      # 0x7420
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x44e9
leaq 0x6981(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x10012000, %edi       # imm = 0x10012000
movl $0xfff, %esi            # imm = 0xFFF
leaq 0x42a6(%rip), %rdx      # 0x87a0
leaq 0x44bf(%rip), %rcx      # 0x89c0
leaq 0x4338(%rip), %r8       # 0x8840
leaq 0x47a1(%rip), %r9       # 0x8cb0
leaq 0x469a(%rip), %rax      # 0x8bb0
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x453d
leaq 0x692d(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x10013000, %edi       # imm = 0x10013000
movl $0xfff, %esi            # imm = 0xFFF
leaq 0x1202(%rip), %rdx      # 0x5750
leaq 0x186b(%rip), %rcx      # 0x5dc0
leaq 0x1294(%rip), %r8       # 0x57f0
leaq 0x1dcd(%rip), %r9       # 0x6330
leaq 0x1d96(%rip), %rax      # 0x6300
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x4591
leaq 0x68d9(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x10014000, %edi       # imm = 0x10014000
movl $0x80, %esi
leaq 0x373e(%rip), %rdx      # 0x7ce0
leaq 0x3957(%rip), %rcx      # 0x7f00
leaq 0x37d0(%rip), %r8       # 0x7d80
leaq 0x3bc9(%rip), %r9       # 0x8180
leaq 0x3ac2(%rip), %rax      # 0x8080
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x45e5
leaq 0x6885(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movl $0x2000000, %edi        # imm = 0x2000000
movl $0x10000, %esi          # imm = 0x10000
leaq 0x3bda(%rip), %rdx      # 0x81d0
leaq 0x3df3(%rip), %rcx      # 0x83f0
leaq 0x3c6c(%rip), %r8       # 0x8270
leaq 0x4145(%rip), %r9       # 0x8750
leaq 0x403e(%rip), %rax      # 0x8650
movq %rax, (%rsp)
callq 0x46c0
cmpl $0x0, %eax
jne 0x4636
leaq 0x6831(%rip), %rdi      # 0xae58
callq 0x6b20
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movq 0xe4b3(%rip), %rax      # 0x12af0
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x4698
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rsp), %rdi
callq *%rax
cmpl $0x0, %eax
jne 0x4689
movq 0x9992(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movq 0x10(%rsp), %rax
movl 0x8(%rax), %edx
leaq 0x67f6(%rip), %rsi      # 0xae6e
movb $0x0, %al
callq 0x2130
movl $0x0, 0x24(%rsp)
jmp 0x46ac
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x4642
leaq 0x67f3(%rip), %rdi      # 0xae92
callq 0x6b20
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)