// File: /workspace/github_c_makefile_star2_O2/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 0x1d56(%rip), %rax      # 0x53ee
movq %rax, (%rsp)
leaq 0x1a5d(%rip), %rdx      # 0x5100
leaq 0x1ce9(%rip), %rcx      # 0x5393
leaq 0x1c7d(%rip), %r8       # 0x532e
leaq 0x1de6(%rip), %r9       # 0x549e
movl $0x20400000, %edi       # imm = 0x20400000
movl $0x1cecc, %esi          # imm = 0x1CECC
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0x925(%rip), %rbx       # 0x3ffb
movq %rbx, (%rsp)
leaq 0x5d7(%rip), %rdx       # 0x3cb8
leaq 0x8b8(%rip), %rcx       # 0x3fa0
leaq 0x7e8(%rip), %r8        # 0x3ed7
leaq 0x9b5(%rip), %r9        # 0x40ab
movl $0x80000000, %edi       # imm = 0x80000000
movl $0x4000, %esi           # imm = 0x4000
callq 0x38d1
testl %eax, %eax
je 0x38aa
movq %rbx, (%rsp)
leaq 0x5a0(%rip), %rdx       # 0x3cb8
leaq 0x881(%rip), %rcx       # 0x3fa0
leaq 0x7b1(%rip), %r8        # 0x3ed7
leaq 0x97e(%rip), %r9        # 0x40ab
movl $0x10000000, %edi       # imm = 0x10000000
movl $0x170, %esi            # imm = 0x170
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0x18c8(%rip), %rax      # 0x5013
movq %rax, (%rsp)
leaq 0x16f6(%rip), %rdx      # 0x4e4c
leaq 0x1826(%rip), %rcx      # 0x4f83
leaq 0x1729(%rip), %r8       # 0x4e8d
leaq 0x1958(%rip), %r9       # 0x50c3
movl $0x10008000, %edi       # imm = 0x10008000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0x24cf(%rip), %rax      # 0x5c58
movq %rax, (%rsp)
leaq 0x230c(%rip), %rdx      # 0x5aa0
leaq 0x243c(%rip), %rcx      # 0x5bd7
leaq 0x233f(%rip), %r8       # 0x5ae1
leaq 0x255f(%rip), %r9       # 0x5d08
movl $0x10012000, %edi       # imm = 0x10012000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0xe5d(%rip), %rax       # 0x4624
movq %rax, (%rsp)
leaq 0x916(%rip), %rdx       # 0x40e8
leaq 0xc06(%rip), %rcx       # 0x43df
leaq 0x94d(%rip), %r8        # 0x412d
leaq 0xe51(%rip), %r9        # 0x4638
movl $0x10013000, %edi       # imm = 0x10013000
movl $0xfff, %esi            # imm = 0xFFF
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0x1e98(%rip), %rax      # 0x569d
movq %rax, (%rsp)
leaq 0x1cc8(%rip), %rdx      # 0x54d8
leaq 0x1df8(%rip), %rcx      # 0x560f
leaq 0x1cfb(%rip), %r8       # 0x5519
leaq 0x1f28(%rip), %r9       # 0x574d
movl $0x10014000, %edi       # imm = 0x10014000
movl $0x80, %esi
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0x2174(%rip), %rax      # 0x59b3
movq %rax, (%rsp)
leaq 0x1f3e(%rip), %rdx      # 0x5788
leaq 0x206e(%rip), %rcx      # 0x58bf
leaq 0x1f71(%rip), %r8       # 0x57c9
leaq 0x2204(%rip), %r9       # 0x5a63
movl $0x2000000, %edi        # imm = 0x2000000
movl $0x10000, %esi          # imm = 0x10000
callq 0x38d1
testl %eax, %eax
je 0x38aa
leaq 0xd26f(%rip), %rbx      # 0x10ae8
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x38c0
movq %rbx, %rdi
callq *0x10(%rbx)
testl %eax, %eax
jne 0x3879
movq 0x8766(%rip), %rax      # 0xbff8
movq (%rax), %rdi
movl 0x8(%rbx), %edx
leaq 0x463d(%rip), %rsi      # 0x7edc
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x2140
jmp 0x38b8
leaq 0x4615(%rip), %rdi      # 0x7ec6
callq 0x4b7e
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
retq
leaq 0x4639(%rip), %rdi      # 0x7f00
callq 0x4b7e
pushq $0x1
popq %rbx
jmp 0x38b8