Skip to content
This repository has been archived by the owner on Aug 17, 2022. It is now read-only.

Commit

Permalink
Make the PC and other GPRs unsigned.
Browse files Browse the repository at this point in the history
Fixes riscv-collab/riscv-openocd#8

Pros of unsigned: addresses with the high bit set work as expected, eg.
in "x/i $pc".
Pros of signed: values that actually are signed are printed as expected,
eg. in "p $t0"
  • Loading branch information
timsifive authored and palmer-dabbelt committed Feb 24, 2017
1 parent 04474cf commit e12e99c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions gdb/riscv-tdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,22 @@ riscv_register_type (struct gdbarch *gdbarch,

if (regnum < RISCV_FIRST_FP_REGNUM)
{
/*
* GPRs and especially the PC are listed as unsigned so that gdb can
* interpret them as addresses without any problems. Specifically, if a
* user runs "x/i $pc" then they should see the instruction at the PC.
* But on a 32-bit system, with a signed PC of eg. 0x8000_0000, gdb will
* internally sign extend the value and then attempt to read from
* 0xffff_ffff_8000_0000, which it then concludes it can't read.
*/
switch (regsize)
{
case 4:
return builtin_type (gdbarch)->builtin_int32;
return builtin_type (gdbarch)->builtin_uint32;
case 8:
return builtin_type (gdbarch)->builtin_int64;
return builtin_type (gdbarch)->builtin_uint64;
case 16:
return builtin_type (gdbarch)->builtin_int128;
return builtin_type (gdbarch)->builtin_uint128;
default:
internal_error (__FILE__, __LINE__,
_("unknown isa regsize %i"), regsize);
Expand Down

0 comments on commit e12e99c

Please sign in to comment.