@@ -17,7 +17,7 @@ public enum RelocType
17
17
IMAGE_REL_BASED_THUMB_BRANCH24 = 0x13 , // Thumb2: based B, BL
18
18
IMAGE_REL_BASED_THUMB_MOV32_PCREL = 0x14 , // Thumb2: based MOVW/MOVT
19
19
IMAGE_REL_BASED_ARM64_BRANCH26 = 0x15 , // Arm64: B, BL
20
- IMAGE_REL_BASED_LOONGARCH64_PC = 0x16 , // LoongArch64: pcaddu12i +imm12
20
+ IMAGE_REL_BASED_LOONGARCH64_PC = 0x16 , // LoongArch64: pcalau12i +imm12
21
21
IMAGE_REL_BASED_LOONGARCH64_JIR = 0x17 , // LoongArch64: pcaddu18i+jirl
22
22
IMAGE_REL_BASED_RISCV64_PC = 0x18 , // RiscV64: auipc
23
23
IMAGE_REL_BASED_RELPTR32 = 0x7C , // 32-bit relative address from byte starting reloc
@@ -334,43 +334,39 @@ private static unsafe int GetLoongArch64PC12(uint* pCode)
334
334
335
335
// then get the low 12 bits,
336
336
pcInstr = * ( pCode + 1 ) ;
337
- imm + = ( ( int ) ( ( ( pcInstr >> 10 ) & 0xFFF ) << 20 ) ) >> 20 ;
337
+ imm | = ( int ) ( ( pcInstr >> 10 ) & 0xFFF ) ;
338
338
339
339
return imm ;
340
340
}
341
341
342
342
// case:EA_HANDLE_CNS_RELOC
343
- // pcaddu12i reg, off-hi-20bits
343
+ // pcalau12i reg, off-hi-20bits
344
344
// addi_d reg, reg, off-lo-12bits
345
345
// case:EA_PTR_DSP_RELOC
346
- // pcaddu12i reg, off-hi-20bits
346
+ // pcalau12i reg, off-hi-20bits
347
347
// ld_d reg, reg, off-lo-12bits
348
- private static unsafe void PutLoongArch64PC12 ( uint * pCode , long imm32 )
348
+ private static unsafe void PutLoongArch64PC12 ( uint * pCode , long imm )
349
349
{
350
350
// Verify that we got a valid offset
351
- Debug . Assert ( ( int ) imm32 == imm32 ) ;
351
+ Debug . Assert ( ( int ) imm == imm ) ;
352
352
353
353
uint pcInstr = * pCode ;
354
354
355
- Debug . Assert ( ( pcInstr & 0xFE000000 ) == 0x1c000000 ) ; // Must be pcaddu12i
356
-
357
- int relOff = ( int ) imm32 & 0x800 ;
358
- int imm = ( int ) imm32 + relOff ;
359
- relOff = ( ( imm & 0x7ff ) - relOff ) & 0xfff ;
355
+ Debug . Assert ( ( pcInstr & 0xFE000000 ) == 0x1a000000 ) ; // Must be pcalau12i
360
356
361
- // Assemble the pc-relative high 20 bits of 'imm32 ' into the pcaddu12i instruction
362
- pcInstr |= ( uint ) ( ( ( imm >> 12 ) & 0xFFFFF ) << 5 ) ;
357
+ // Assemble the pc-relative high 20 bits of 'imm ' into the pcalau12i instruction
358
+ pcInstr |= ( uint ) ( ( imm >> 7 ) & 0x1FFFFE0 ) ;
363
359
364
360
* pCode = pcInstr ; // write the assembled instruction
365
361
366
362
pcInstr = * ( pCode + 1 ) ;
367
363
368
- // Assemble the pc-relative low 12 bits of 'imm32 ' into the addid or ld instruction
369
- pcInstr |= ( uint ) ( relOff << 10 ) ;
364
+ // Assemble the pc-relative low 12 bits of 'imm ' into the addid or ld instruction
365
+ pcInstr |= ( uint ) ( ( imm & 0xFFF ) << 10 ) ;
370
366
371
367
* ( pCode + 1 ) = pcInstr; // write the assembled instruction
372
368
373
- Debug . Assert ( GetLoongArch64PC12 ( pCode ) == imm32 ) ;
369
+ Debug . Assert ( GetLoongArch64PC12 ( pCode ) == imm ) ;
374
370
}
375
371
376
372
private static unsafe long GetLoongArch64JIR ( uint * pCode )
@@ -402,14 +398,14 @@ private static unsafe void PutLoongArch64JIR(uint* pCode, long imm38)
402
398
long imm = imm38 + relOff ;
403
399
relOff = ( ( ( imm & 0x1ffff ) - relOff ) >> 2 ) & 0xffff ;
404
400
405
- // Assemble the pc-relative high 20 bits of 'imm38' into the pcaddu12i instruction
401
+ // Assemble the pc-relative high 20 bits of 'imm38' into the pcaddu18i instruction
406
402
pcInstr |= ( uint ) ( ( ( imm >> 18 ) & 0xFFFFF ) << 5 ) ;
407
403
408
404
* pCode = pcInstr ; // write the assembled instruction
409
405
410
406
pcInstr = * ( pCode + 1 ) ;
411
407
412
- // Assemble the pc-relative low 18 bits of 'imm38' into the addid or ld instruction
408
+ // Assemble the pc-relative low 18 bits of 'imm38' into the jirl instruction
413
409
pcInstr |= ( uint ) ( relOff << 10 ) ;
414
410
415
411
* ( pCode + 1 ) = pcInstr; // write the assembled instruction
0 commit comments