boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

arm64-link-prel64-condbr.after (1277B)


      1         case R_AARCH64_ABS32:
      2             write32le(ptr, val);
      3             return;
      4 	case R_AARCH64_PREL32:
      5 	    write32le(ptr, val - addr);
      6 	    return;
      7 	case R_AARCH64_PREL64:
      8 	    write64le(ptr, val - addr);
      9 	    return;
     10         case R_AARCH64_CONDBR19: {
     11             /* B.cond imm19 (bits 23:5), encoding 4-byte aligned target. */
     12             int64_t off = (int64_t)(val - addr);
     13             if (off & 3)
     14                 tcc_error("R_AARCH64_CONDBR19: target not 4-byte aligned");
     15             if (off < -(1 << 20) || off >= (1 << 20))
     16                 tcc_error("R_AARCH64_CONDBR19: target out of range");
     17             write32le(ptr, (read32le(ptr) & 0xff00001fu) |
     18                            (((uint32_t)(off >> 2) & 0x7ffffu) << 5));
     19             return;
     20         }
     21         case R_AARCH64_TSTBR14: {
     22             /* TBZ/TBNZ imm14 (bits 18:5). */
     23             int64_t off = (int64_t)(val - addr);
     24             if (off & 3)
     25                 tcc_error("R_AARCH64_TSTBR14: target not 4-byte aligned");
     26             if (off < -(1 << 15) || off >= (1 << 15))
     27                 tcc_error("R_AARCH64_TSTBR14: target out of range");
     28             write32le(ptr, (read32le(ptr) & 0xfff8001fu) |
     29                            (((uint32_t)(off >> 2) & 0x3fffu) << 5));
     30             return;
     31         }