LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_st_stm32wb55.c
// Function: target_erase
static void target_erase(void)
{
  int num_pages = target_flash_size / FLASH_PAGE_SIZE;

  // Mass Erase is not supported from the CPU1, so do a manual erase.
  for (int page = 0; page < num_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(page));
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(page) | FLASH_CR_STRT);
    flash_wait_done();
  }

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl 0x72ad7(%rip), %ebx     # 0x7ed18
cmpl $0x1000, %ebx           # imm = 0x1000
jb 0xc281
shrl $0xc, %ebx
shll $0x3, %ebx
xorl %r14d, %r14d
leal 0x2(%r14), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x723e
movl %r14d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x723e
callq 0xc593
addl $0x8, %r14d
cmpl %r14d, %ebx
jne 0xc252
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_st_stm32wb55.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint32_t start_page, number_of_pages;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

  start_page = target_options.offset / FLASH_PAGE_SIZE;
  number_of_pages = (size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE;

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(start_page + page));
    dap_write_word(FLASH_CR, FLASH_CR_PER | FLASH_CR_PNB(start_page + page) | FLASH_CR_STRT);
    flash_wait_done();

    if (0 == (page % STATUS_INTERVAL))
      verbose(".");
  }

  verbose(",");

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    dap_write_word(FLASH_CR, FLASH_CR_PG);

    for (int i = 0; i < (FLASH_PAGE_SIZE / FLASH_ROW_SIZE); i++)
    {
      dap_write_block(addr, &buf[offs], FLASH_ROW_SIZE);
      addr += FLASH_ROW_SIZE;
      offs += FLASH_ROW_SIZE;
    }

    if (0 == (page % STATUS_INTERVAL))
      verbose(".");

    flash_wait_done();
  }

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x72a36(%rip), %r14d    # 0x7ecf8
movl $0xfff, %r12d           # imm = 0xFFF
leal (%r14,%r12), %r13d
testl %r14d, %r14d
cmovnsl %r14d, %r13d
addl 0x72a2e(%rip), %r12d    # 0x7ed08
movq 0x72a2f(%rip), %r15     # 0x7ed10
movl %r12d, %ebp
shrl $0xc, %ebp
cmpl $0x1000, %r12d          # imm = 0x1000
jb 0xc33d
sarl $0xc, %r13d
shll $0x3, %r13d
xorl %ebx, %ebx
leal 0x2(%r13), %esi
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x723e
movl %r13d, %esi
orl $0x10002, %esi          # imm = 0x10002
movl $0x58004014, %edi       # imm = 0x58004014
callq 0x723e
callq 0xc593
testb $0x3, %bl
jne 0xc333
leaq 0x44f3(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
incl %ebx
addl $0x8, %r13d
cmpl %ebx, %ebp
jne 0xc2fa
leaq 0x6a88(%rip), %rdi      # 0x12dcc
xorl %eax, %eax
callq 0x7a78
cmpl $0x1000, %r12d          # imm = 0x1000
jb 0xc3bc
addl $0x8000000, %r14d       # imm = 0x8000000
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x58004014, %edi       # imm = 0x58004014
movl $0x1, %esi
callq 0x723e
xorl %ebx, %ebx
leal (%r14,%rbx), %edi
leal (%rbx,%r13), %esi
addq %r15, %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x73b6
addl $0x200, %ebx            # imm = 0x200
cmpl $0x1000, %ebx           # imm = 0x1000
jne 0xc372
testb $0x3, %r12b
jne 0xc3a9
leaq 0x447d(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
addl %ebx, %r14d
addl %ebx, %r13d
callq 0xc593
incl %r12d
cmpl %ebp, %r12d
jne 0xc361
movl $0x58004014, %edi       # imm = 0x58004014
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_st_stm32wb55.c
// Function: flash_wait_done
static void flash_wait_done(void)
{
  uint32_t sr;

  while (dap_read_word(FLASH_SR) & (FLASH_SR_BSY | FLASH_SR_CFGBSY));

  sr = dap_read_word(FLASH_SR);

  if (sr & FLASH_SR_ALL_ERRORS)
    error_exit("flash operation failed. FLASH_SR = 0x%08x", sr);
}

// Assembly:
pushq %rax
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x71ef
testl $0x50000, %eax          # imm = 0x50000
jne 0xc594
movl $0x58004010, %edi       # imm = 0x58004010
callq 0x71ef
testl $0xc3fa, %eax           # imm = 0xC3FA
je 0xc5c7
leaq 0x6e97(%rip), %rdi      # 0x13454
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7c8d
popq %rax
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word(FMC_CTL, FMC_CTL_MER0 | FMC_CTL_MER1);
  dap_write_word(FMC_CTL, FMC_CTL_MER0 | FMC_CTL_MER1 | FMC_CTL_START);
  flash_wait_done();
  dap_write_word(FMC_CTL, 0);
}

// Assembly:
pushq %rax
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x8004, %esi           # imm = 0x8004
callq 0x723e
movl $0x40023c10, %edi       # imm = 0x40023C10
movl $0x18004, %esi          # imm = 0x18004
callq 0x723e
callq 0xcc44
movl $0x40023c10, %edi       # imm = 0x40023C10
xorl %esi, %esi
popq %rax
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_lock
static void target_lock(void)
{
  uint32_t ob0 = dap_read_word(FMC_OBCTL0);
  uint32_t ob1 = dap_read_word(FMC_OBCTL1);

  ob0 |= FMC_OBCTL0_SPC(0xff); // Set low level security

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x71ef
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x71ef
movl %ebx, %ebp
orl $0xff00, %ebp           # imm = 0xFF00
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x723e
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x723e
orl $0xff02, %ebx           # imm = 0xFF02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x723e
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc44
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_unlock
static void target_unlock(void)
{
  uint32_t ob0 = dap_read_word(FMC_OBCTL0);
  uint32_t ob1 = dap_read_word(FMC_OBCTL1);

  ob0 = (ob0 & ~FMC_OBCTL0_SPC(0xff)) | FMC_OBCTL0_SPC(0xaa);

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x71ef
movl %eax, %ebx
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x71ef
andl $0xffff00ff, %ebx       # imm = 0xFFFF00FF
leal 0xaa00(%rbx), %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %eax, %esi
callq 0x723e
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x723e
orl $0xaa02, %ebx           # imm = 0xAA02
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebx, %esi
callq 0x723e
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc44
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t block_size;
  uint32_t offs = 0;
  uint8_t *bufb;
  uint8_t *bufa = target_options.file_data;
  uint32_t size = target_options.file_size;

  bufb = buf_alloc(FLASH_ALIGN_SIZE);

  while (size)
  {
    dap_read_block(addr, bufb, FLASH_ALIGN_SIZE);

    block_size = (size > FLASH_ALIGN_SIZE) ? FLASH_ALIGN_SIZE : size;

    for (int i = 0; i < (int)block_size; i++)
    {
      if (bufa[offs + i] != bufb[i])
      {
        verbose("\nat address 0x%x expected 0x%02x, read 0x%02x\n",
            addr + i, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

    addr += FLASH_ALIGN_SIZE;
    offs += FLASH_ALIGN_SIZE;
    size -= block_size;

    if (0 == (offs % (FLASH_ALIGN_SIZE * 64)))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x72322(%rip), %ebx     # 0x7ed38
movq 0x72333(%rip), %rax     # 0x7ed50
movq %rax, 0x10(%rsp)
movl 0x72320(%rip), %ebp     # 0x7ed48
movl $0x100, %edi            # imm = 0x100
callq 0x7dba
movq %rax, %r14
testl %ebp, %ebp
je 0xcaf8
addl $0x8000000, %ebx        # imm = 0x8000000
leaq 0x702e(%rip), %r13      # 0x13a78
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
movq %r14, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
movl $0x100, %eax            # imm = 0x100
cmpl %eax, %ebp
movl %ebp, 0xc(%rsp)
cmovbl %ebp, %eax
cmpl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %eax, %ebp
adcl $0x0, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xcab8
leal (%rbx,%r12), %esi
leaq 0x5d6e(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
movq %r13, %rdi
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %rbp
jne 0xca86
movl 0x8(%rsp), %r15d
addl $0x100, %r15d           # imm = 0x100
testl $0x3f00, %r15d          # imm = 0x3F00
jne 0xcae3
leaq 0x3d43(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
addq $0x100, %rbx            # imm = 0x100
movl 0xc(%rsp), %ebp
subl 0x4(%rsp), %ebp
jne 0xca4d
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  size = round_up(size, FLASH_ALIGN_SIZE);

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_ALIGN_SIZE);

    addr += FLASH_ALIGN_SIZE;
    offs += FLASH_ALIGN_SIZE;
    size -= FLASH_ALIGN_SIZE;

    if (0 == (offs % (FLASH_ALIGN_SIZE * 64)))
      verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl 0x7221b(%rip), %r15d    # 0x7ed38
movq 0x7222c(%rip), %rbx     # 0x7ed50
movl 0x72212(%rip), %edi     # 0x7ed3c
movl $0x100, %esi            # imm = 0x100
callq 0x7d65
testl %eax, %eax
je 0xcb7e
movl %eax, %ebp
addl $0x8000000, %r15d       # imm = 0x8000000
leaq 0x3cd7(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x7258
addl $0x100, %r12d           # imm = 0x100
testl $0x3f00, %r12d          # imm = 0x3F00
jne 0xcb79
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xcb4b
movq 0x721ab(%rip), %rdi     # 0x7ed30
movl 0x721b1(%rip), %edx     # 0x7ed3c
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t value = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];
  uint32_t ob0, ob1;

  check(section < OPTIONS_COUNT, "internal: incorrect section index in target_fuse_write()");

  if (0 == section)
  {
    ob0 = value;
    ob1 = dap_read_word(FMC_OBCTL1);
  }
  else
  {
    ob0 = dap_read_word(FMC_OBCTL0);
    ob1 = value;
  }

  ob0 &= ~(FMC_OBCTL0_OB_LK | FMC_OBCTL0_OB_START);

  dap_write_word(FMC_OBCTL1, ob1);
  dap_write_word(FMC_OBCTL0, ob0);
  dap_write_word(FMC_OBCTL0, ob0 | FMC_OBCTL0_OB_START);
  flash_wait_done();
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %edi, %ebp
movl (%rsi), %ebx
xorl %edi, %edi
cmpl $0x2, %ebp
setl %dil
leaq 0x5c61(%rip), %rsi      # 0x1283c
xorl %eax, %eax
callq 0x7bb4
testl %ebp, %ebp
je 0xcbf4
movl $0x40023c14, %edi       # imm = 0x40023C14
callq 0x71ef
movl %eax, %ebp
jmp 0xcc02
movl $0x40023c18, %edi       # imm = 0x40023C18
callq 0x71ef
movl %ebx, %ebp
movl %eax, %ebx
andl $-0x4, %ebp
movl $0x40023c18, %edi       # imm = 0x40023C18
movl %ebx, %esi
callq 0x723e
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x723e
orl $0x2, %ebp
movl $0x40023c14, %edi       # imm = 0x40023C14
movl %ebp, %esi
callq 0x723e
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xcc44
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_gd_gd32f4xx.c
// Function: flash_wait_done
static void flash_wait_done(void)
{
  uint32_t stat;

  while (dap_read_word(FMC_STAT) & FMC_STAT_BUSY);

  stat = dap_read_word(FMC_STAT);

  if (stat & FMC_STAT_ALL_ERRORS)
    error_exit("flash operation failed. FMC_STAT = 0x%08x", stat);
}

// Assembly:
pushq %rax
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x71ef
btl $0x10, %eax
jb 0xcc45
movl $0x40023c0c, %edi       # imm = 0x40023C0C
callq 0x71ef
testl $0x1d2, %eax            # imm = 0x1D2
je 0xcc77
leaq 0x6974(%rip), %rdi      # 0x135e1
movl %eax, %esi
xorl %eax, %eax
popq %rcx
jmp 0x7c8d
popq %rax
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_select
static void target_select(target_options_t *options)
{
  uint32_t idcode;
  bool locked;

  dap_disconnect();
  dap_connect(DAP_INTERFACE_SWD);
  dap_reset_pin(0);
  dap_reset_link();

  // Stop the core
  dap_write_word(DHCSR, DHCSR_DBGKEY | DHCSR_DEBUGEN | DHCSR_HALT);
  dap_write_word(DEMCR, DEMCR_VC_CORERESET);
  dap_write_word(AIRCR, AIRCR_VECTKEY | AIRCR_SYSRESETREQ);

  dap_reset_pin(1);
  sleep_ms(10);

  idcode = dap_read_word(SYS_PDID);

  for (int i = 0; i < ARRAY_SIZE(devices); i++)
  {
    if (devices[i].idcode != idcode)
      continue;

    verbose("Target: %s\n", devices[i].name);

    target_device = devices[i];
    target_options = *options;

    target_check_options(&target_options, devices[i].flash_size, FLASH_PAGE_SIZE);

    dap_write_word(SYS_REGLCTL, 0x59);
    dap_write_word(SYS_REGLCTL, 0x16);
    dap_write_word(SYS_REGLCTL, 0x88);

    dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN);

    locked = (0 == (fmc_read(CONFIG0) & CONFIG0_LOCK));

    if (locked && !options->unlock)
      error_exit("target is locked, unlock is necessary");

    return;
  }

  error_exit("unknown target device (SYS_PDID = 0x%08x)", idcode);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
callq 0x65ab
movl $0x1, %edi
callq 0x654e
xorl %edi, %edi
callq 0x7074
callq 0x6789
movl $0xe000edf0, %edi       # imm = 0xE000EDF0
movl $0xa05f0003, %esi       # imm = 0xA05F0003
callq 0x723e
movl $0xe000edfc, %edi       # imm = 0xE000EDFC
movl $0x1, %esi
callq 0x723e
movl $0xe000ed0c, %edi       # imm = 0xE000ED0C
movl $0x5fa0004, %esi        # imm = 0x5FA0004
callq 0x723e
movl $0x1, %edi
callq 0x7074
movl $0xa, %edi
callq 0x7d74
movl $0x40000000, %edi       # imm = 0x40000000
callq 0x71ef
cmpl $0xd48410, %eax         # imm = 0xD48410
jne 0xcdb5
leaq 0x5b7d(%rip), %rdi      # 0x12875
leaq 0x6a20(%rip), %rsi      # 0x1371f
xorl %eax, %eax
callq 0x7a78
movaps 0xe013(%rip), %xmm0     # 0x1ad20
movups %xmm0, 0x72054(%rip)    # 0x7ed68
movaps 0xdff5(%rip), %xmm0     # 0x1ad10
movups %xmm0, 0x72036(%rip)    # 0x7ed58
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x72044(%rip)    # 0x7ed78
movups %xmm1, 0x7204d(%rip)    # 0x7ed88
movups %xmm2, 0x72056(%rip)    # 0x7ed98
movq 0x30(%rbx), %rax
movq %rax, 0x7205b(%rip)     # 0x7eda8
leaq 0x72024(%rip), %rdi     # 0x7ed78
movl $0x80000, %esi          # imm = 0x80000
movl $0x1000, %edx           # imm = 0x1000
callq 0x8edf
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x59, %esi
callq 0x723e
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x16, %esi
callq 0x723e
movl $0x40000100, %edi       # imm = 0x40000100
movl $0x88, %esi
callq 0x723e
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x1, %esi
callq 0x723e
movl $0x300000, %edi         # imm = 0x300000
callq 0xd27f
testb $0x2, %al
jne 0xcdb3
cmpb $0x0, 0x8(%rbx)
je 0xcdc6
popq %rbx
retq
leaq 0x6934(%rip), %rdi      # 0x136f0
movl %eax, %esi
xorl %eax, %eax
popq %rbx
jmp 0x7c8d
leaq 0x526e(%rip), %rdi      # 0x1203b
xorl %eax, %eax
popq %rbx
jmp 0x7c8d
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_APUEN);

  // Bank 0
  dap_write_word(FMC_ISPADDR, 0);
  fmc_cmd(FMC_ISPCMD_BANK_ERASE, BANK_ERASE_TIME);

  // Bank 1
  dap_write_word(FMC_ISPADDR, target_device.flash_size / 2);
  fmc_cmd(FMC_ISPCMD_BANK_ERASE, BANK_ERASE_TIME);
}

// Assembly:
pushq %rax
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x723e
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x723e
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
callq 0xd2ce
movl 0x71f41(%rip), %eax     # 0x7ed70
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movl $0x4000c004, %edi       # imm = 0x4000C004
callq 0x723e
movl $0x23, %edi
movl $0x140, %esi            # imm = 0x140
popq %rax
jmp 0xd2ce
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_unlock
static void target_unlock(void)
{
  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_APUEN);
  dap_write_word(FMC_UNDOCUMENTED, 1);

  dap_write_word(FMC_ISPADDR, 0);
  fmc_cmd(FMC_ISPCMD_MASS_ERASE, BANK_ERASE_TIME);

  dap_write_word(FMC_UNDOCUMENTED, 0);
}

// Assembly:
pushq %rax
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x9, %esi
callq 0x723e
movl $0x4000c01c, %edi       # imm = 0x4000C01C
movl $0x1, %esi
callq 0x723e
movl $0x4000c004, %edi       # imm = 0x4000C004
xorl %esi, %esi
callq 0x723e
movl $0x26, %edi
movl $0x140, %esi            # imm = 0x140
callq 0xd2ce
movl $0x4000c01c, %edi       # imm = 0x4000C01C
xorl %esi, %esi
popq %rax
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t addr = target_options.offset;
  uint32_t block_size;
  uint32_t offs = 0;
  uint8_t *bufb;
  uint8_t *bufa = target_options.file_data;
  uint32_t size = target_options.file_size;

  bufb = buf_alloc(FLASH_PAGE_SIZE);

  while (size)
  {
    dap_read_block(addr, bufb, FLASH_PAGE_SIZE);

    block_size = (size > FLASH_PAGE_SIZE) ? FLASH_PAGE_SIZE : size;

    for (int i = 0; i < (int)block_size; i++)
    {
      if (bufa[offs + i] != bufb[i])
      {
        verbose("\nat address 0x%x expected 0x%02x, read 0x%02x\n",
            addr + i, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;
    size -= block_size;

    if (0 == (offs % (FLASH_PAGE_SIZE * STATUS_INTERVAL)))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x71d5c(%rip), %ebx     # 0x7ed90
movq 0x71d6d(%rip), %rax     # 0x7eda8
movq %rax, 0x10(%rsp)
movl 0x71d5a(%rip), %ebp     # 0x7eda0
movl $0x1000, %edi           # imm = 0x1000
callq 0x7dba
movq %rax, %r14
testl %ebp, %ebp
je 0xd110
leaq 0x6a16(%rip), %r13      # 0x13a78
xorl %r15d, %r15d
movl %r15d, 0x8(%rsp)
movl %r15d, %r15d
addq 0x10(%rsp), %r15
movl %ebx, %edi
movq %r14, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7258
movl $0x1000, %eax           # imm = 0x1000
cmpl %eax, %ebp
movl %ebp, 0xc(%rsp)
cmovbl %ebp, %eax
cmpl $0x1, %eax
movl %eax, 0x4(%rsp)
movl %eax, %ebp
adcl $0x0, %ebp
xorl %r12d, %r12d
movzbl (%r15,%r12), %edx
movzbl (%r14,%r12), %ecx
cmpb %cl, %dl
je 0xd0d0
leal (%rbx,%r12), %esi
leaq 0x5756(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %r14, %rdi
callq 0x7de7
movq %r13, %rdi
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %rbp
jne 0xd09e
movl 0x8(%rsp), %r15d
addl $0x1000, %r15d          # imm = 0x1000
testl $0x3000, %r15d          # imm = 0x3000
jne 0xd0fb
leaq 0x372b(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
addq $0x1000, %rbx           # imm = 0x1000
movl 0xc(%rsp), %ebp
subl 0x4(%rsp), %ebp
jne 0xd065
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_PAGE_SIZE);

    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;
    size -= FLASH_PAGE_SIZE;

    if (0 == (offs % (FLASH_PAGE_SIZE * STATUS_INTERVAL)))
      verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq 0x71c73(%rip), %rbx     # 0x7eda8
movl 0x71c59(%rip), %ebp     # 0x7ed94
testl %ebp, %ebp
je 0xd183
movl 0x71c4a(%rip), %r15d    # 0x7ed90
leaq 0x36d2(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
leal (%r15,%r12), %edi
movl %r12d, %esi
addq %rbx, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7258
addl $0x1000, %r12d          # imm = 0x1000
testl $0x3000, %r12d          # imm = 0x3000
jne 0xd17e
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
cmpl %r12d, %ebp
jne 0xd150
movq 0x71bfe(%rip), %rdi     # 0x7ed88
movl 0x71c04(%rip), %edx     # 0x7ed94
movq %rbx, %rsi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: target_fuse_write
static void target_fuse_write(int section, uint8_t *data)
{
  uint32_t config[CONFIG_COUNT];

  if (section >= CONFIG_COUNT)
    return;

  dap_write_word(FMC_ISPCTL, FMC_ISPCTL_ISPEN | FMC_ISPCTL_CFGUEN);

  for (int i = 0; i < CONFIG_COUNT; i++)
    config[i] = fmc_read(CONFIG0 + i*4);

  config[section] = *(uint32_t *)data;
  config[0] |= CONFIG0_ICELOCK; // Make sure ICE is never locked for now

  dap_write_word(FMC_ISPADDR, CONFIG0);
  fmc_cmd(FMC_ISPCMD_PAGE_ERASE, PAGE_ERASE_TIME);

  for (int i = 0; i < CONFIG_COUNT; i++)
    fmc_write(CONFIG0 + i*4, config[i]);
}

// Assembly:
cmpl $0x3, %edi
jg 0xd26e
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movl %edi, %ebx
movl $0x4000c000, %edi       # imm = 0x4000C000
movl $0x11, %esi
callq 0x723e
xorl %r15d, %r15d
leal 0x300000(%r15), %edi
callq 0xd27f
movl %eax, (%rsp,%r15)
addq $0x4, %r15
cmpq $0x10, %r15
jne 0xd205
movl (%r14), %eax
movslq %ebx, %rcx
movl %eax, (%rsp,%rcx,4)
orb $0x8, 0x1(%rsp)
movl $0x4000c004, %edi       # imm = 0x4000C004
movl $0x300000, %esi         # imm = 0x300000
callq 0x723e
movl $0x22, %edi
movl $0x50, %esi
callq 0xd2ce
xorl %ebx, %ebx
movl (%rsp,%rbx), %esi
leal 0x300000(%rbx), %edi
callq 0xd330
addq $0x4, %rbx
cmpq $0x10, %rbx
jne 0xd24d
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_read
static uint32_t fmc_read(uint32_t addr)
{
  dap_write_word(FMC_ISPCMD, FMC_ISPCMD_READ);
  dap_write_word(FMC_ISPADDR, addr);
  dap_write_word(FMC_ISPDAT, 0);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);
  while (dap_read_word(FMC_ISPTRG));
  return dap_read_word(FMC_ISPDAT);
}

// Assembly:
pushq %rbx
movl %edi, %ebx
movl $0x4000c00c, %edi       # imm = 0x4000C00C
xorl %esi, %esi
callq 0x723e
movl $0x4000c004, %edi       # imm = 0x4000C004
movl %ebx, %esi
callq 0x723e
movl $0x4000c008, %edi       # imm = 0x4000C008
xorl %esi, %esi
callq 0x723e
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x723e
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x71ef
testl %eax, %eax
jne 0xd2b5
movl $0x4000c008, %edi       # imm = 0x4000C008
popq %rbx
jmp 0x71ef
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_cmd
static void fmc_cmd(int cmd, int delay)
{
  uint32_t sts;

  dap_write_word(FMC_ISPCMD, cmd);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);

  if (delay)
    sleep_ms(delay);

  while (dap_read_word(FMC_ISPTRG));

  sts = dap_read_word(FMC_ISPSTS);
  if (sts & FMC_ISPSTS_ISPFF)
    error_exit("flash error while executing command 0x%02x", cmd);
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movl %edi, %ebx
movl $0x4000c00c, %edi       # imm = 0x4000C00C
movl %ebx, %esi
callq 0x723e
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x723e
movl %ebp, %edi
callq 0x7d74
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x71ef
testl %eax, %eax
jne 0xd2f7
movl $0x4000c040, %edi       # imm = 0x4000C040
callq 0x71ef
testb $0x40, %al
jne 0xd31a
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x6408(%rip), %rdi      # 0x13729
movl %ebx, %esi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x7c8d
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_nu_m480.c
// Function: fmc_write
static void fmc_write(uint32_t addr, uint32_t data)
{
  dap_write_word(FMC_ISPCMD, FMC_ISPCMD_32B_PROG);
  dap_write_word(FMC_ISPADDR, addr);
  dap_write_word(FMC_ISPDAT, data);
  dap_write_word(FMC_ISPTRG, FMC_ISPTRG_ISPGO);
  while (dap_read_word(FMC_ISPTRG));
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebx
movl %edi, %ebp
movl $0x4000c00c, %edi       # imm = 0x4000C00C
movl $0x21, %esi
callq 0x723e
movl $0x4000c004, %edi       # imm = 0x4000C004
movl %ebp, %esi
callq 0x723e
movl $0x4000c008, %edi       # imm = 0x4000C008
movl %ebx, %esi
callq 0x723e
movl $0x4000c010, %edi       # imm = 0x4000C010
movl $0x1, %esi
callq 0x723e
movl $0x4000c010, %edi       # imm = 0x4000C010
callq 0x71ef
testl %eax, %eax
jne 0xd36d
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: target_select
static void target_select(target_options_t *options)
{
  uint32_t chain[MAX_CHAIN_COUNT];
  int chain_count;

  dap_connect(DAP_INTERFACE_JTAG);

  chain_count = dap_jtag_scan_chain(chain, MAX_CHAIN_COUNT);

  verbose("Detected JTAG chain:\n");
  for (int i = 0; i < chain_count; i++)
    verbose("  %d: 0x%08x\n", i, chain[i]);

  if (chain_count == 0)
    error_exit("no devices detected in the JTAG chain");

  if (chain_count > 1)
    error_exit("more than one device detected in the JTAG chain");

  for (int i = 0; i < ARRAY_SIZE(devices); i++)
  {
    if (devices[i].idcode != chain[0])
      continue;

    verbose("Target: %s\n", devices[i].name);

    target_device = devices[i];
    target_options = *options;

    return;
  }

  error_exit("unknown target device (IDCODE = 0x%08x)", chain[0]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %rbx
movl $0x2, %edi
callq 0x654e
movq %rsp, %rdi
movl $0x5, %esi
callq 0x79b4
movl %eax, %ebp
leaq 0x63ad(%rip), %rdi      # 0x13760
xorl %eax, %eax
callq 0x7a78
testl %ebp, %ebp
jle 0xd3e4
movl %ebp, %r12d
leaq 0x63ae(%rip), %r14      # 0x13776
xorl %r15d, %r15d
movl (%rsp,%r15,4), %edx
movq %r14, %rdi
movl %r15d, %esi
xorl %eax, %eax
callq 0x7a78
incq %r15
cmpq %r15, %r12
jne 0xd3cb
testl %ebp, %ebp
jne 0xd3f6
leaq 0x6395(%rip), %rdi      # 0x13784
xorl %eax, %eax
callq 0x7c8d
cmpl $0x2, %ebp
jl 0xd409
leaq 0x63a8(%rip), %rdi      # 0x137aa
xorl %eax, %eax
callq 0x7c8d
movl (%rsp), %eax
xorl %r14d, %r14d
leaq 0xd91a(%rip), %r15      # 0x1ad30
cmpl %eax, (%r14,%r15)
je 0xd439
addq $0x18, %r14
cmpq $0x48, %r14
jne 0xd416
movl (%rsp), %esi
leaq 0x63aa(%rip), %rdi      # 0x137da
xorl %eax, %eax
callq 0x7c8d
jmp 0xd48f
movq 0x10(%r14,%r15), %rsi
leaq 0x5430(%rip), %rdi      # 0x12875
xorl %eax, %eax
callq 0x7a78
movq 0x10(%r14,%r15), %rax
movq %rax, 0x71968(%rip)     # 0x7edc0
movups (%r14,%r15), %xmm0
movups %xmm0, 0x7194c(%rip)    # 0x7edb0
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm0, 0x71952(%rip)    # 0x7edc8
movups %xmm1, 0x7195b(%rip)    # 0x7edd8
movups %xmm2, 0x71964(%rip)    # 0x7ede8
movq 0x30(%rbx), %rax
movq %rax, 0x71969(%rip)     # 0x7edf8
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: target_deselect
static void target_deselect(void)
{
  dap_jtag_write_ir(CMD_ISC_PROGRAM_DONE, IR_LENGTH);
  dap_jtag_idle(1000);
  poll_busy_flag();

  dap_jtag_write_ir(CMD_ISC_DISABLE, IR_LENGTH);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_NOOP, IR_LENGTH);
  dap_jtag_idle(100);

  dap_jtag_write_ir(CMD_LSC_REFRESH, IR_LENGTH);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_NOOP, IR_LENGTH);
  dap_jtag_idle(100);

  dap_jtag_flush();
}

// Assembly:
pushq %rax
movl $0x5e, %edi
movl $0x8, %esi
callq 0x782a
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x77ee
callq 0xd9ad
movl $0x26, %edi
movl $0x8, %esi
callq 0x782a
movl $0x8, %edi
callq 0x77ee
movl $0xff, %edi
movl $0x8, %esi
callq 0x782a
movl $0x64, %edi
callq 0x77ee
movl $0x79, %edi
movl $0x8, %esi
callq 0x782a
movl $0x8, %edi
callq 0x77ee
movl $0xff, %edi
movl $0x8, %esi
callq 0x782a
movl $0x64, %edi
callq 0x77ee
popq %rax
jmp 0x74cf
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: target_erase
static void target_erase(void)
{
  erase_sram();

  // Enable Flash
  dap_jtag_write_ir(CMD_ISC_ENABLE, IR_LENGTH);
  dap_jtag_write_dr((uint8_t[]){ ISC_ENABLE_FLASH }, 8);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_ERASE, IR_LENGTH);
  dap_jtag_write_dr((uint8_t[]){ ISC_ERASE_ALL_NV }, 8);
  dap_jtag_idle(8);

  poll_busy_flag();
}

// Assembly:
pushq %rax
callq 0xda3f
movl $0xc6, %edi
movl $0x8, %esi
callq 0x782a
leaq 0x7(%rsp), %rdi
movb $0x8, (%rdi)
movl $0x8, %esi
callq 0x78b2
movl $0x8, %edi
callq 0x77ee
movl $0xe, %edi
movl $0x8, %esi
callq 0x782a
leaq 0x6(%rsp), %rdi
movb $0xe, (%rdi)
movl $0x8, %esi
callq 0x78b2
movl $0x8, %edi
callq 0x77ee
callq 0xd9ad
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: poll_busy_flag
static void poll_busy_flag(void)
{
  uint32_t status = 0;
  uint8_t busy = 1;

  while (busy)
  {
    dap_jtag_write_ir(CMD_LSC_CHECK_BUSY, IR_LENGTH);
    dap_jtag_read_dr(&busy, 1);
  }

  dap_jtag_write_ir(CMD_LSC_READ_STATUS, IR_LENGTH);
  dap_jtag_read_dr((uint8_t *)&status, 32);
  dap_jtag_idle(8);

  if (status & STATUS_BUSY)
    error_exit("poll_busy_flag(): busy");

  if (status & STATUS_FAIL)
    error_exit("poll_busy_flag(): fail");
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl $0x0, 0xc(%rsp)
leaq 0xb(%rsp), %rbx
movb $0x1, (%rbx)
movl $0xf0, %edi
movl $0x8, %esi
callq 0x782a
movq %rbx, %rdi
movl $0x1, %esi
callq 0x793f
cmpb $0x0, 0xb(%rsp)
jne 0xd9c2
movl $0x3c, %edi
movl $0x8, %esi
callq 0x782a
leaq 0xc(%rsp), %rbx
movq %rbx, %rdi
movl $0x20, %esi
callq 0x793f
movl $0x8, %edi
callq 0x77ee
testb $0x10, 0x1(%rbx)
je 0xda24
leaq 0x5e15(%rip), %rdi      # 0x13832
xorl %eax, %eax
callq 0x7c8d
testb $0x20, 0xd(%rsp)
je 0xda39
leaq 0x5e17(%rip), %rdi      # 0x13849
xorl %eax, %eax
callq 0x7c8d
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_lattice_lcmxo2.c
// Function: erase_sram
static void erase_sram(void)
{
  dap_jtag_write_ir(CMD_ISC_ENABLE, IR_LENGTH);
  dap_jtag_write_dr((uint8_t[]){ ISC_ENABLE_SRAM }, 8);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_ERASE, IR_LENGTH);
  dap_jtag_write_dr((uint8_t[]){ ISC_ERASE_SRAM }, 8);
  dap_jtag_idle(8);

  dap_jtag_write_ir(CMD_ISC_NOOP, IR_LENGTH);
}

// Assembly:
pushq %rax
movl $0xc6, %edi
movl $0x8, %esi
callq 0x782a
leaq 0x7(%rsp), %rdi
movb $0x0, (%rdi)
movl $0x8, %esi
callq 0x78b2
movl $0x8, %edi
callq 0x77ee
movl $0xe, %edi
movl $0x8, %esi
callq 0x782a
leaq 0x6(%rsp), %rdi
movb $0x1, (%rdi)
movl $0x8, %esi
callq 0x78b2
movl $0x8, %edi
callq 0x77ee
movl $0xff, %edi
movl $0x8, %esi
callq 0x782a
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: target_erase
static void target_erase(void)
{
  uint8_t buf[4];
  int cnt = 0;

  buf[0] = FLASH_CMD_CHIP_ERASE;

  flash_write_enable();

  spi_select(0);
  spi_transfer(buf, 1, 1);
  spi_select(1);

  while (flash_is_busy())
  {
    sleep_ms(100);

    if ((cnt++ % 10) == 0)
      verbose(".");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
leaq 0xc(%rsp), %rbx
movb $-0x39, (%rbx)
callq 0xe7d8
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x200, %esi            # imm = 0x200
callq 0x70f4
callq 0x6a6f
movq %rbx, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xe727
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x300, %esi            # imm = 0x300
callq 0x70f4
callq 0x6a6f
callq 0xe816
testb %al, %al
je 0xe3a1
movl $0xcccccccd, %r14d      # imm = 0xCCCCCCCD
leaq 0x24bc(%rip), %rbx      # 0x1081f
xorl %ebp, %ebp
xorl %r15d, %r15d
movl %r15d, %eax
imulq %r14, %rax
shrq $0x23, %rax
leal (%rax,%rax,4), %r12d
addl %r12d, %r12d
movl $0x64, %edi
callq 0x7d74
addl %ebp, %r12d
jne 0xe393
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7a78
callq 0xe816
decl %ebp
incl %r15d
testb %al, %al
jne 0xe368
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: target_program
static void target_program(void)
{
  uint32_t addr = target_options.offset;
  uint32_t offs = 0;
  uint32_t number_of_pages;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.file_size;

  number_of_pages = (size + FLASH_PAGE_SIZE - 1) / FLASH_PAGE_SIZE;

  for (uint32_t page = 0; page < number_of_pages; page++)
  {
    if (0 == (addr % FLASH_SECTOR_SIZE))
      flash_erase_sector(addr);

    flash_program_page(addr, &buf[offs]);

    addr += FLASH_PAGE_SIZE;
    offs += FLASH_PAGE_SIZE;

    if (0 == (addr % (FLASH_SECTOR_SIZE * STATUS_INTERVAL)))
      verbose(".");
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl $0xff, %ebp
addl 0x70a42(%rip), %ebp     # 0x7ee28
cmpl $0x100, %ebp            # imm = 0x100
jb 0xe523
movq 0x70a37(%rip), %r12     # 0x7ee30
shrl $0x8, %ebp
movl 0x70a15(%rip), %r13d    # 0x7ee18
xorl %r15d, %r15d
xorl %ebx, %ebx
movl %r13d, %ecx
testl $0xfff, %ecx            # imm = 0xFFF
movl %ecx, %r14d
jne 0xe47c
movb 0xdbbc(%rip), %al       # 0x1bfd8
movb %al, (%rsp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rsp)
movb %ch, 0x2(%rsp)
movb $0x0, 0x3(%rsp)
callq 0xe7d8
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x200, %esi            # imm = 0x200
callq 0x70f4
callq 0x6a6f
movq %rsp, %rdi
movl $0x4, %esi
movl $0x4, %edx
callq 0xe727
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x300, %esi            # imm = 0x300
callq 0x70f4
callq 0x6a6f
callq 0xe816
testb %al, %al
jne 0xe470
movl %r14d, %ecx
leaq (%r12,%r15), %rsi
movb $0x2, (%rsp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x1(%rsp)
movb %ch, 0x2(%rsp)
movb %r13b, 0x3(%rsp)
movl $0x100, %edx            # imm = 0x100
leaq 0x4(%rsp), %rdi
callq 0x6180
callq 0xe7d8
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x200, %esi            # imm = 0x200
callq 0x70f4
callq 0x6a6f
movq %rsp, %rdi
movl $0x104, %esi            # imm = 0x104
movl $0x104, %edx            # imm = 0x104
callq 0xe727
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x300, %esi            # imm = 0x300
callq 0x70f4
callq 0x6a6f
callq 0xe816
testb %al, %al
jne 0xe4e4
movl %r14d, %ecx
addl $0x100, %ecx            # imm = 0x100
testl $0x3fff, %ecx           # imm = 0x3FFF
jne 0xe512
leaq 0x231a(%rip), %rdi      # 0x1081f
xorl %eax, %eax
movl %ecx, %r14d
callq 0x7a78
movl %r14d, %ecx
addq $0x100, %r15            # imm = 0x100
incl %ebx
cmpl %ebp, %ebx
jne 0xe40b
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: target_verify
static void target_verify(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t block_size;
  uint32_t offs = 0;
  uint8_t *bufb;
  uint8_t *bufa = target_options.file_data;
  uint32_t size = target_options.file_size;
  int sector = 0;

  bufb = buf_alloc(FLASH_SECTOR_SIZE);

  spi_xip_mode();

  while (size)
  {
    dap_read_block(addr, bufb, FLASH_SECTOR_SIZE);

    block_size = (size > FLASH_SECTOR_SIZE) ? FLASH_SECTOR_SIZE : size;

    for (int i = 0; i < (int)block_size; i++)
    {
      if (bufa[offs + i] != bufb[i])
      {
        verbose("\nat address 0x%x expected 0x%02x, read 0x%02x\n",
            addr + i - FLASH_ADDR, bufa[offs + i], bufb[i]);
        buf_free(bufb);
        error_exit("verification failed");
      }
    }

    addr += FLASH_SECTOR_SIZE;
    offs += FLASH_SECTOR_SIZE;
    size -= block_size;

    if (0 == (sector++ % STATUS_INTERVAL))
      verbose(".");
  }

  buf_free(bufb);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x708ce(%rip), %r13d    # 0x7ee18
movq 0x708df(%rip), %rax     # 0x7ee30
movq %rax, 0x10(%rsp)
movl 0x708cb(%rip), %r15d    # 0x7ee28
movl $0x1000, %r12d          # imm = 0x1000
movl $0x1000, %edi           # imm = 0x1000
callq 0x7dba
movq %rax, %rbx
callq 0xe877
testl %r15d, %r15d
je 0xe64e
leal 0x13000000(%r13), %edi
xorl %r14d, %r14d
xorl %eax, %eax
movl %r14d, 0x4(%rsp)
movl %eax, (%rsp)
movl %eax, %r14d
addq 0x10(%rsp), %r14
movl %edi, 0x8(%rsp)
movq %rbx, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7258
cmpl %r12d, %r15d
movl $0x1000, %ebp           # imm = 0x1000
movl %r15d, 0xc(%rsp)
cmovbl %r15d, %ebp
cmpl $0x1, %ebp
movl %ebp, %r15d
adcl $0x0, %r15d
xorl %r12d, %r12d
movzbl (%r14,%r12), %edx
movzbl (%rbx,%r12), %ecx
cmpb %cl, %dl
je 0xe5ff
leal (%r12,%r13), %esi
leaq 0x422b(%rip), %rdi      # 0x1280d
xorl %eax, %eax
callq 0x7a78
movq %rbx, %rdi
callq 0x7de7
leaq 0x5480(%rip), %rdi      # 0x13a78
xorl %eax, %eax
callq 0x7c8d
incq %r12
cmpq %r12, %r15
jne 0xe5c9
movl 0x4(%rsp), %r14d
testb $0x3, %r14b
jne 0xe620
leaq 0x2206(%rip), %rdi      # 0x1081f
xorl %eax, %eax
callq 0x7a78
movl $0x1000, %r12d          # imm = 0x1000
movl 0x8(%rsp), %edi
addl %r12d, %edi
movl (%rsp), %eax
addl %r12d, %eax
movl 0xc(%rsp), %r15d
subl %ebp, %r15d
incl %r14d
addq $0x1000, %r13           # imm = 0x1000
testl %r15d, %r15d
jne 0xe58a
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7de7
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: target_read
static void target_read(void)
{
  uint32_t addr = FLASH_ADDR + target_options.offset;
  uint32_t offs = 0;
  uint8_t *buf = target_options.file_data;
  uint32_t size = target_options.size;
  int sector = 0;

  spi_xip_mode();

  while (size)
  {
    dap_read_block(addr, &buf[offs], FLASH_SECTOR_SIZE);

    addr += FLASH_SECTOR_SIZE;
    offs += FLASH_SECTOR_SIZE;
    size -= FLASH_SECTOR_SIZE;

    if (0 == (sector++ % STATUS_INTERVAL))
      verbose(".");
  }

  save_file(target_options.name, buf, target_options.size);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl 0x707a2(%rip), %r15d    # 0x7ee18
movq 0x707b3(%rip), %rbx     # 0x7ee30
movl 0x70799(%rip), %ebp     # 0x7ee1c
callq 0xe877
testl %ebp, %ebp
je 0xe6d3
addl $0x13000000, %r15d      # imm = 0x13000000
leaq 0x2185(%rip), %r14      # 0x1081f
xorl %r12d, %r12d
xorl %r13d, %r13d
leal (%r15,%r13), %edi
movl %r13d, %esi
addq %rbx, %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x7258
testb $0x3, %r12b
jne 0xe6c4
movq %r14, %rdi
xorl %eax, %eax
callq 0x7a78
addl $0x1000, %r13d          # imm = 0x1000
incl %r12d
cmpl %r13d, %ebp
jne 0xe6a0
movq 0x70736(%rip), %rdi     # 0x7ee10
movl 0x7073c(%rip), %edx     # 0x7ee1c
movq %rbx, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x7e95
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: spi_transfer
static void spi_transfer(uint8_t *data, int size, int rx_skip)
{
  assert(rx_skip <= size);

  dap_write_block(RAM_ADDR, data, size);

  dap_write_word_req(DMA_CH0_WRITE_ADDR, RAM_HALF_ADDR);
  dap_write_word_req(DMA_CH0_TRANS_COUNT, size);

  dap_write_word_req(DMA_CH1_READ_ADDR, RAM_ADDR);
  dap_write_word_req(DMA_CH1_TRANS_COUNT, size);

  dap_transfer();

  while (dap_read_word(DMA_CH0_CTRL) & DMA_CHx_CTRL_BUSY);

  dap_read_block(RAM_HALF_ADDR + rx_skip, data, size - rx_skip);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
subl %edx, %ebp
jl 0xe7b9
movl %edx, %ebx
movl %esi, %r15d
movq %rdi, %r14
movl $0x20000000, %edi       # imm = 0x20000000
movq %r14, %rsi
movl %r15d, %edx
callq 0x73b6
movl $0x50000018, %edi       # imm = 0x50000018
movl $0x20020000, %esi       # imm = 0x20020000
callq 0x70f4
movl $0x5000001c, %edi       # imm = 0x5000001C
movl %r15d, %esi
callq 0x70f4
movl $0x50000054, %edi       # imm = 0x50000054
movl $0x20000000, %esi       # imm = 0x20000000
callq 0x70f4
movl $0x5000005c, %edi       # imm = 0x5000005C
movl %r15d, %esi
callq 0x70f4
callq 0x6a6f
movl $0x50000010, %edi       # imm = 0x50000010
callq 0x71ef
btl $0x18, %eax
jb 0xe78d
addl $0x20020000, %ebx       # imm = 0x20020000
movl %ebx, %edi
movq %r14, %rsi
movl %ebp, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7258
leaq 0x53f4(%rip), %rdi      # 0x13bb4
leaq 0x53fd(%rip), %rsi      # 0x13bc4
leaq 0x540a(%rip), %rcx      # 0x13bd8
movl $0xdc, %edx
callq 0x60d0
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: flash_write_enable
static void flash_write_enable(void)
{
  spi_select_req(0);
  dap_write_word_req(QSPI_DR0, FLASH_CMD_WRITE_ENABLE);
  dap_read_word_req(QSPI_DR0);
  spi_select_req(1);
  dap_transfer();
}

// Assembly:
pushq %rax
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x200, %esi            # imm = 0x200
callq 0x70f4
movl $0x18000060, %edi       # imm = 0x18000060
movl $0x6, %esi
callq 0x70f4
movl $0x18000060, %edi       # imm = 0x18000060
callq 0x70c1
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x300, %esi            # imm = 0x300
callq 0x70f4
popq %rax
jmp 0x6a6f
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: flash_is_busy
static bool flash_is_busy(void)
{
  spi_select_req(0);
  dap_write_word_req(QSPI_DR0, FLASH_CMD_READ_STATUS);
  dap_write_word_req(QSPI_DR0, 0);
  dap_read_word_req(QSPI_DR0);
  dap_read_word_req(QSPI_DR0);
  spi_select_req(1);
  dap_transfer();

  return (dap_get_response(4) & 1);
}

// Assembly:
pushq %rax
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x200, %esi            # imm = 0x200
callq 0x70f4
movl $0x18000060, %edi       # imm = 0x18000060
movl $0x5, %esi
callq 0x70f4
movl $0x18000060, %edi       # imm = 0x18000060
xorl %esi, %esi
callq 0x70f4
movl $0x18000060, %edi       # imm = 0x18000060
callq 0x70c1
movl $0x18000060, %edi       # imm = 0x18000060
callq 0x70c1
movl $0x4001800c, %edi       # imm = 0x4001800C
movl $0x300, %esi            # imm = 0x300
callq 0x70f4
callq 0x6a6f
movl $0x4, %edi
callq 0x717f
andb $0x1, %al
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_rpi_rp2040.c
// Function: spi_xip_mode
static void spi_xip_mode(void)
{
  dap_write_word_req(GPIO_QSPI_SS_CTRL, GPIO_QSPI_xx_CTRL_OUTOVER_NORMAL);
  dap_write_word_req(QSPI_SSIENR, 0);
  dap_write_word_req(QSPI_CTRLR0, (flash_quad_mode ? QSPI_CTRLR0_SPI_FRF_QUAD : QSPI_CTRLR0_SPI_FRF_STD) |
      QSPI_CTRLR0_TMOD_EEPROM_READ | QSPI_CTRLR0_DFS_32(32-1));
  dap_write_word_req(QSPI_SPI_CTRLR0, QSPI_SPI_CTRLR0_XIP_CMD(flash_cmd_read_data) |
    QSPI_SPI_CTRLR0_ADDR_L(24 / 4) | QSPI_SPI_CTRLR0_INST_L_8B | QSPI_SPI_CTRLR0_TRANS_TYPE_1C1A |
    QSPI_SPI_CTRLR0_WAIT_CYCLES(flash_wait_cycles));
  dap_write_word_req(QSPI_SSIENR, QSPI_SSIENR_SSI_EN);

  dap_write_word_req(QSPI_DMACR, 0);

  dap_transfer();
}

// Assembly:
pushq %rax
movl $0x4001800c, %edi       # imm = 0x4001800C
xorl %esi, %esi
callq 0x70f4
movl $0x18000008, %edi       # imm = 0x18000008
xorl %esi, %esi
callq 0x70f4
movzbl 0x705a1(%rip), %esi     # 0x7ee38
shll $0x16, %esi
orl $0x1f0300, %esi         # imm = 0x1F0300
movl $0x18000000, %edi       # imm = 0x18000000
callq 0x70f4
movl 0xd72c(%rip), %eax      # 0x1bfdc
shll $0x18, %eax
movl 0x70583(%rip), %esi     # 0x7ee3c
shll $0xb, %esi
orl %eax, %esi
orl $0x218, %esi            # imm = 0x218
movl $0x180000f4, %edi       # imm = 0x180000F4
callq 0x70f4
movl $0x18000008, %edi       # imm = 0x18000008
movl $0x1, %esi
callq 0x70f4
movl $0x1800004c, %edi       # imm = 0x1800004C
xorl %esi, %esi
callq 0x70f4
popq %rax
jmp 0x6a6f
nop
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_puya_py32f0.c
// Function: target_erase
static void target_erase(void)
{
  dap_write_word_req(FLASH_CR, FLASH_CR_MER);
  dap_write_word_req(FLASH_ADDR, 0);
  dap_transfer();

  flash_wait_done();

  dap_write_word(FLASH_CR, 0);
}

// Assembly:
pushq %rax
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x4, %esi
callq 0x70f4
movl $0x8000000, %edi        # imm = 0x8000000
xorl %esi, %esi
callq 0x70f4
callq 0x6a6f
callq 0xeea0
movl $0x40022014, %edi       # imm = 0x40022014
xorl %esi, %esi
popq %rax
jmp 0x723e
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_puya_py32f0.c
// Function: target_lock
static void target_lock(void)
{
  uint32_t value = (dap_read_word(OPTIONS_OPTR) & 0xff00) | 0xee;

  dap_write_word_req(FLASH_OPTR, value);
  dap_write_word_req(FLASH_CR, FLASH_CR_OPTSTRT);
  dap_write_word_req(0x40022080, 0);
  dap_transfer();

  flash_wait_done();
}

// Assembly:
pushq %rax
movl $0x1fff0e80, %edi       # imm = 0x1FFF0E80
callq 0x71ef
andl $0xff00, %eax           # imm = 0xFF00
leal 0xee(%rax), %esi
movl $0x40022020, %edi       # imm = 0x40022020
callq 0x70f4
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x20000, %esi          # imm = 0x20000
callq 0x70f4
movl $0x40022080, %edi       # imm = 0x40022080
xorl %esi, %esi
callq 0x70f4
callq 0x6a6f
popq %rax
jmp 0xeea0
// File: /workspace/github_c_makefile_star2_O1/ataradov[P]edbg/target_puya_py32f0.c
// Function: target_unlock
static void target_unlock(void)
{
  uint32_t value = (dap_read_word(OPTIONS_OPTR) & 0xff00) | 0xaa;

  dap_write_word_req(FLASH_OPTR, value);
  dap_write_word_req(FLASH_CR, FLASH_CR_OPTSTRT);
  dap_write_word_req(0x40022080, 0);
  dap_transfer();

  flash_wait_done();
}

// Assembly:
pushq %rax
movl $0x1fff0e80, %edi       # imm = 0x1FFF0E80
callq 0x71ef
andl $0xff00, %eax           # imm = 0xFF00
leal 0xaa(%rax), %esi
movl $0x40022020, %edi       # imm = 0x40022020
callq 0x70f4
movl $0x40022014, %edi       # imm = 0x40022014
movl $0x20000, %esi          # imm = 0x20000
callq 0x70f4
movl $0x40022080, %edi       # imm = 0x40022080
xorl %esi, %esi
callq 0x70f4
callq 0x6a6f
popq %rax
jmp 0xeea0