Skip to content

Commit 94b533a

Browse files
Yadong WangRealFYang
authored andcommitted
8285699: riscv: Provide information when hitting a HaltNode
Reviewed-by: fyang
1 parent e2e943a commit 94b533a

File tree

9 files changed

+59
-53
lines changed

9 files changed

+59
-53
lines changed

src/hotspot/cpu/riscv/assembler_riscv.hpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,51 @@ class Assembler : public AbstractAssembler {
388388
emit_int32((jint)insn);
389389
}
390390

391-
void _halt() {
392-
emit_int32(0);
391+
enum csr {
392+
cycle = 0xc00,
393+
time,
394+
instret,
395+
hpmcounter3,
396+
hpmcounter4,
397+
hpmcounter5,
398+
hpmcounter6,
399+
hpmcounter7,
400+
hpmcounter8,
401+
hpmcounter9,
402+
hpmcounter10,
403+
hpmcounter11,
404+
hpmcounter12,
405+
hpmcounter13,
406+
hpmcounter14,
407+
hpmcounter15,
408+
hpmcounter16,
409+
hpmcounter17,
410+
hpmcounter18,
411+
hpmcounter19,
412+
hpmcounter20,
413+
hpmcounter21,
414+
hpmcounter22,
415+
hpmcounter23,
416+
hpmcounter24,
417+
hpmcounter25,
418+
hpmcounter26,
419+
hpmcounter27,
420+
hpmcounter28,
421+
hpmcounter29,
422+
hpmcounter30,
423+
hpmcounter31 = 0xc1f
424+
};
425+
426+
// Emit an illegal instruction that's known to trap, with 32 read-only CSR
427+
// to choose as the input operand.
428+
// According to the RISC-V Assembly Programmer's Manual, a de facto implementation
429+
// of this instruction is the UNIMP pseduo-instruction, 'CSRRW x0, cycle, x0',
430+
// attempting to write zero to a read-only CSR 'cycle' (0xC00).
431+
// RISC-V ISAs provide a set of up to 32 read-only CSR registers 0xC00-0xC1F,
432+
// and an attempt to write into any read-only CSR (whether it exists or not)
433+
// will generate an illegal instruction exception.
434+
void illegal_instruction(csr csr_reg) {
435+
csrrw(x0, (unsigned)csr_reg, x0);
393436
}
394437

395438
// Register Instruction
@@ -2854,20 +2897,6 @@ enum Nf {
28542897

28552898
#undef INSN
28562899

2857-
#define INSN(NAME) \
2858-
void NAME() { \
2859-
/* The illegal instruction in RVC is presented by a 16-bit 0. */ \
2860-
if (do_compress()) { \
2861-
emit_int16(0); \
2862-
return; \
2863-
} \
2864-
_halt(); \
2865-
}
2866-
2867-
INSN(halt);
2868-
2869-
#undef INSN
2870-
28712900
// --------------------------
28722901
// Immediate Instructions
28732902
// --------------------------

src/hotspot/cpu/riscv/frame_riscv.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,12 @@
106106
public:
107107
enum {
108108
pc_return_offset = 0,
109+
109110
// All frames
110111
link_offset = -2,
111112
return_addr_offset = -1,
112113
sender_sp_offset = 0,
114+
113115
// Interpreter frames
114116
interpreter_frame_oop_temp_offset = 1, // for native calls only
115117

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ void MacroAssembler::_verify_oop(Register reg, const char* s, const char* file,
379379

380380
mv(c_rarg0, reg); // c_rarg0 : x10
381381
// The length of the instruction sequence emitted should be independent
382-
// of the values of the local char buffer address so that the size of mach
382+
// of the value of the local char buffer address so that the size of mach
383383
// nodes for scratch emit and normal emit matches.
384384
mv(t0, (address)b);
385385

@@ -418,7 +418,7 @@ void MacroAssembler::_verify_oop_addr(Address addr, const char* s, const char* f
418418
}
419419

420420
// The length of the instruction sequence emitted should be independent
421-
// of the values of the local char buffer address so that the size of mach
421+
// of the value of the local char buffer address so that the size of mach
422422
// nodes for scratch emit and normal emit matches.
423423
mv(t0, (address)b);
424424

@@ -535,17 +535,9 @@ void MacroAssembler::resolve_jobject(Register value, Register thread, Register t
535535
}
536536

537537
void MacroAssembler::stop(const char* msg) {
538-
address ip = pc();
539-
pusha();
540-
// The length of the instruction sequence emitted should be independent
541-
// of the values of msg and ip so that the size of mach nodes for scratch
542-
// emit and normal emit matches.
543-
mv(c_rarg0, (address)msg);
544-
mv(c_rarg1, (address)ip);
545-
mv(c_rarg2, sp);
546-
mv(c_rarg3, CAST_FROM_FN_PTR(address, MacroAssembler::debug64));
547-
jalr(c_rarg3);
548-
ebreak();
538+
BLOCK_COMMENT(msg);
539+
illegal_instruction(Assembler::csr::time);
540+
emit_int64((uintptr_t)msg);
549541
}
550542

551543
void MacroAssembler::unimplemented(const char* what) {
@@ -1119,18 +1111,6 @@ void MacroAssembler::pop_call_clobbered_registers_except(RegSet exclude) {
11191111
pop_reg(RegSet::of(x7) + RegSet::range(x10, x17) + RegSet::range(x28, x31) - exclude, sp);
11201112
}
11211113

1122-
// Push all the integer registers, except zr(x0) & sp(x2) & gp(x3) & tp(x4).
1123-
void MacroAssembler::pusha() {
1124-
CompressibleRegion cr(this);
1125-
push_reg(0xffffffe2, sp);
1126-
}
1127-
1128-
// Pop all the integer registers, except zr(x0) & sp(x2) & gp(x3) & tp(x4).
1129-
void MacroAssembler::popa() {
1130-
CompressibleRegion cr(this);
1131-
pop_reg(0xffffffe2, sp);
1132-
}
1133-
11341114
void MacroAssembler::push_CPU_state(bool save_vectors, int vector_size_in_bytes) {
11351115
CompressibleRegion cr(this);
11361116
// integer registers, except zr(x0) & ra(x1) & sp(x2) & gp(x3) & tp(x4)
@@ -2936,9 +2916,7 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
29362916
// with the call instruction at insts_call_instruction_offset in the
29372917
// instructions code-section.
29382918

2939-
// make sure 4 byte aligned here, so that the destination address would be
2940-
// 8 byte aligned after 3 instructions
2941-
// when we reach here we may get a 2-byte alignment so need to align it
2919+
// Make sure the address of destination 8-byte aligned after 3 instructions.
29422920
align(wordSize, NativeCallTrampolineStub::data_offset);
29432921

29442922
relocate(trampoline_stub_Relocation::spec(code()->insts()->start() +

src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ class MacroAssembler: public Assembler {
512512
pop_call_clobbered_registers_except(RegSet());
513513
}
514514

515-
void pusha();
516-
void popa();
517515
void push_CPU_state(bool save_vectors = false, int vector_size_in_bytes = 0);
518516
void pop_CPU_state(bool restore_vectors = false, int vector_size_in_bytes = 0);
519517

src/hotspot/cpu/riscv/nativeInst_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ void NativeIllegalInstruction::insert(address code_pos) {
339339
}
340340

341341
bool NativeInstruction::is_stop() {
342-
return uint_at(0) == 0xffffffff; // an illegal instruction
342+
return uint_at(0) == 0xc0101073; // an illegal instruction, 'csrrw x0, time, x0'
343343
}
344344

345345
//-------------------------------------------------------------------

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10565,9 +10565,8 @@ instruct ShouldNotReachHere() %{
1056510565
format %{ "#@ShouldNotReachHere" %}
1056610566

1056710567
ins_encode %{
10568-
Assembler::CompressibleRegion cr(&_masm);
1056910568
if (is_reachable()) {
10570-
__ halt();
10569+
__ stop(_halt_reason);
1057110570
}
1057210571
%}
1057310572

src/hotspot/cpu/riscv/stubGenerator_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class StubGenerator: public StubCodeGenerator {
578578
__ bind(error);
579579
__ pop_reg(0x3000, sp); // pop c_rarg2 and c_rarg3
580580

581-
__ pusha();
581+
__ push_reg(RegSet::range(x0, x31), sp);
582582
// debug(char* msg, int64_t pc, int64_t regs[])
583583
__ mv(c_rarg0, t0); // pass address of error message
584584
__ mv(c_rarg1, ra); // pass return address

src/hotspot/cpu/riscv/templateInterpreterGenerator_riscv.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,11 +1228,11 @@ address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) {
12281228
__ addi(t1, zr, (u1)StackOverflow::stack_guard_yellow_reserved_disabled);
12291229
__ bne(t0, t1, no_reguard);
12301230

1231-
__ pusha(); // only save smashed registers
1231+
__ push_call_clobbered_registers();
12321232
__ mv(c_rarg0, xthread);
12331233
__ mv(t1, CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages));
12341234
__ jalr(t1);
1235-
__ popa(); // only restore smashed registers
1235+
__ pop_call_clobbered_registers();
12361236
__ bind(no_reguard);
12371237
}
12381238

src/hotspot/os_cpu/linux_riscv/os_linux_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ void os::print_context(outputStream *st, const void *context) {
354354
// point to garbage if entry point in an nmethod is corrupted. Leave
355355
// this at the end, and hope for the best.
356356
address pc = os::Posix::ucontext_get_pc(uc);
357-
print_instructions(st, pc, sizeof(char));
357+
print_instructions(st, pc, UseRVC ? sizeof(char) : 4/*non-compressed native instruction size*/);
358358
st->cr();
359359
}
360360

0 commit comments

Comments
 (0)