| ... | ... | @@ -7,6 +7,7 @@ else switch (native_arch) { |
| 7 | 7 | .aarch64, .aarch64_be => Aarch64, |
| 8 | 8 | .arm, .armeb, .thumb, .thumbeb => Arm, |
| 9 | 9 | .loongarch32, .loongarch64 => LoongArch, |
| 10 | .riscv32, .riscv32be, .riscv64, .riscv64be => Riscv, |
| 10 | 11 | .x86 => X86, |
| 11 | 12 | .x86_64 => X86_64, |
| 12 | 13 | else => noreturn, |
| ... | ... | @@ -181,6 +182,13 @@ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native { |
| 181 | 182 | }, |
| 182 | 183 | else => null, |
| 183 | 184 | }, |
| 185 | .riscv32, .riscv64 => switch (builtin.os.tag) { |
| 186 | .linux => .{ |
| 187 | .r = [1]usize{0} ++ uc.mcontext.gregs[1..].*, // r0 position is used for pc; replace with zero |
| 188 | .pc = uc.mcontext.gregs[0], |
| 189 | }, |
| 190 | else => null, |
| 191 | }, |
| 184 | 192 | else => null, |
| 185 | 193 | }; |
| 186 | 194 | } |
| ... | ... | @@ -571,6 +579,104 @@ pub const LoongArch = extern struct { |
| 571 | 579 | } |
| 572 | 580 | }; |
| 573 | 581 | |
| 582 | /// This is an `extern struct` so that inline assembly in `current` can use field offsets. |
| 583 | pub const Riscv = extern struct { |
| 584 | /// The numbered general-purpose registers r0 - r31. r0 must be zero. |
| 585 | r: [32]usize, |
| 586 | pc: usize, |
| 587 | |
| 588 | pub inline fn current() Riscv { |
| 589 | var ctx: Riscv = undefined; |
| 590 | asm volatile (if (@sizeOf(usize) == 8) |
| 591 | \\ sd zero, 0(t0) |
| 592 | \\ sd ra, 8(t0) |
| 593 | \\ sd sp, 16(t0) |
| 594 | \\ sd gp, 24(t0) |
| 595 | \\ sd tp, 32(t0) |
| 596 | \\ sd t0, 40(t0) |
| 597 | \\ sd t1, 48(t0) |
| 598 | \\ sd t2, 56(t0) |
| 599 | \\ sd s0, 64(t0) |
| 600 | \\ sd s1, 72(t0) |
| 601 | \\ sd a0, 80(t0) |
| 602 | \\ sd a1, 88(t0) |
| 603 | \\ sd a2, 96(t0) |
| 604 | \\ sd a3, 104(t0) |
| 605 | \\ sd a4, 112(t0) |
| 606 | \\ sd a5, 120(t0) |
| 607 | \\ sd a6, 128(t0) |
| 608 | \\ sd a7, 136(t0) |
| 609 | \\ sd s2, 144(t0) |
| 610 | \\ sd s3, 152(t0) |
| 611 | \\ sd s4, 160(t0) |
| 612 | \\ sd s5, 168(t0) |
| 613 | \\ sd s6, 176(t0) |
| 614 | \\ sd s7, 184(t0) |
| 615 | \\ sd s8, 192(t0) |
| 616 | \\ sd s9, 200(t0) |
| 617 | \\ sd s10, 208(t0) |
| 618 | \\ sd s11, 216(t0) |
| 619 | \\ sd t3, 224(t0) |
| 620 | \\ sd t4, 232(t0) |
| 621 | \\ sd t5, 240(t0) |
| 622 | \\ sd t6, 248(t0) |
| 623 | \\ jal ra, 1f |
| 624 | \\1: |
| 625 | \\ sd ra, 256(t0) |
| 626 | \\ ld ra, 8(t0) |
| 627 | else |
| 628 | \\ sw zero, 0(t0) |
| 629 | \\ sw ra, 4(t0) |
| 630 | \\ sw sp, 8(t0) |
| 631 | \\ sw gp, 12(t0) |
| 632 | \\ sw tp, 16(t0) |
| 633 | \\ sw t0, 20(t0) |
| 634 | \\ sw t1, 24(t0) |
| 635 | \\ sw t2, 28(t0) |
| 636 | \\ sw s0, 32(t0) |
| 637 | \\ sw s1, 36(t0) |
| 638 | \\ sw a0, 40(t0) |
| 639 | \\ sw a1, 44(t0) |
| 640 | \\ sw a2, 48(t0) |
| 641 | \\ sw a3, 52(t0) |
| 642 | \\ sw a4, 56(t0) |
| 643 | \\ sw a5, 60(t0) |
| 644 | \\ sw a6, 64(t0) |
| 645 | \\ sw a7, 68(t0) |
| 646 | \\ sw s2, 72(t0) |
| 647 | \\ sw s3, 76(t0) |
| 648 | \\ sw s4, 80(t0) |
| 649 | \\ sw s5, 84(t0) |
| 650 | \\ sw s6, 88(t0) |
| 651 | \\ sw s7, 92(t0) |
| 652 | \\ sw s8, 96(t0) |
| 653 | \\ sw s9, 100(t0) |
| 654 | \\ sw s10, 104(t0) |
| 655 | \\ sw s11, 108(t0) |
| 656 | \\ sw t3, 112(t0) |
| 657 | \\ sw t4, 116(t0) |
| 658 | \\ sw t5, 120(t0) |
| 659 | \\ sw t6, 124(t0) |
| 660 | \\ jal ra, 1f |
| 661 | \\1: |
| 662 | \\ sw ra, 128(t0) |
| 663 | \\ lw ra, 4(t0) |
| 664 | : |
| 665 | : [gprs] "{t0}" (&ctx), |
| 666 | : .{ .memory = true }); |
| 667 | return ctx; |
| 668 | } |
| 669 | |
| 670 | pub fn dwarfRegisterBytes(ctx: *Riscv, register_num: u16) DwarfRegisterError![]u8 { |
| 671 | switch (register_num) { |
| 672 | 0...31 => return @ptrCast(&ctx.r[register_num]), |
| 673 | 32 => return @ptrCast(&ctx.pc), |
| 674 | |
| 675 | else => return error.InvalidRegister, |
| 676 | } |
| 677 | } |
| 678 | }; |
| 679 | |
| 574 | 680 | const signal_ucontext_t = switch (native_os) { |
| 575 | 681 | .linux => std.os.linux.ucontext_t, |
| 576 | 682 | .emscripten => std.os.emscripten.ucontext_t, |