Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't display/i $pc in Scratchpad #8

Closed
mwachs5 opened this issue Dec 14, 2016 · 3 comments
Closed

Can't display/i $pc in Scratchpad #8

mwachs5 opened this issue Dec 14, 2016 · 3 comments
Assignees

Comments

@mwachs5
Copy link
Collaborator

mwachs5 commented Dec 14, 2016

I can't currently display instructions which are in Scratchpad memory:

(gdb) load
Loading section .text, size 0x848 lma 0x80000000
...
Start address 0x80000000, load size 2194
(gdb)display/i $pc
  0x80000000: <error: Cannot access memory at address 0x80000000>
(gdb) x 0x80000000
0x80000000 <_prog_start>: 0xf14024f3

Any thoughts? Is this related to the working area declared at 0x80000000?

If I have a program which is executed from Flash (0x20000000) then it works as expected.

@timsifive
Copy link
Collaborator

This error comes from gdb, somehow. It doesn't ask OpenOCD for anything. Specifying the address works:

(gdb) display/i 0x80000000
6: x/i 0x80000000
=> 0x80000000 <_start>:	j	0x8000000c <handle_reset>

I fear gdb is trying to access the ELF file, and then failing somehow. I'll dig more once the latest riscv gdb builds again.

@mwachs5
Copy link
Collaborator Author

mwachs5 commented Dec 19, 2016 via email

@timsifive
Copy link
Collaborator

What's happening is that gdb gets the PC value (0x8000_0000). Then because the PC register has a type of int32, it gets sign extended into an internal address type (which is 64 bits), to 0xffff_ffff_8000_0000. Then gdb tries to find the memory region corresponding to that address, comes up empty, and prints out the error you see.

The simple fix is to change the type of all GPRs to be unsigned. I don't know if that's good/bad. You'd usually think of the pc as unsigned, because it contains an address. But what about other GPRs? Some contain addresses, and some just values. If a register contains 0xffffffff it would be nice if gdb prints out its value as -1, which it won't if we tell it the value is unsigned.

For comparison, MIPS declares its registers to be signed. I don't know if it has the same problem we have.

My inclination is to make GPRs unsigned, and put a comment in there explaining why it is that way. Then when somebody discovers it's an issue, they can read the rationale and make an informed decisions.

timsifive added a commit to timsifive/riscv-binutils-gdb that referenced this issue Jan 3, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Feb 8, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Feb 13, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Feb 19, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Feb 24, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Mar 6, 2017
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"
palmer-dabbelt pushed a commit to riscvarchive/riscv-binutils-gdb that referenced this issue Mar 6, 2017
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"
timsifive pushed a commit that referenced this issue Apr 9, 2018
…oo far

Without this, we have some types promoted to `int` when they need to be
`unsigned int`.

Here's some ubsan output hitting this:

Unfortunately, what happens is that things get promoted to `int`, but
need to be `unsigned int`. Here's the ubsan output:

src/helper/types.h:126:65: runtime error: left shift of 255 by 24 places cannot be represented in type 'int'
    #0 0x55978a612060 in le_to_h_u32 src/helper/types.h:126
    #1 0x55978a61ff9e in stlink_usb_read_reg src/jtag/drivers/stlink_usb.c:1539
    #2 0x55978a8cfd45 in adapter_load_core_reg_u32 src/target/hla_target.c:67
    #3 0x55978a9f48e3 in armv7m_read_core_reg src/target/armv7m.c:236
    #4 0x55978a8d24fc in adapter_load_context src/target/hla_target.c:372
    #5 0x55978a8d261b in adapter_debug_entry src/target/hla_target.c:396
    #6 0x55978a8d3123 in adapter_poll src/target/hla_target.c:457
    #7 0x55978a528357 in target_poll src/target/target.c:535
    #8 0x55978a539fd4 in target_wait_state src/target/target.c:2914
    #9 0x55978a556e20 in jim_target_wait_state src/target/target.c:5256
    #10 0x55978a5cca62 in command_unknown src/helper/command.c:1030
    #11 0x55978aaed894 in JimInvokeCommand /home/cody/d/openocd-code/jimtcl/jim.c:10364

Change-Id: I24f6abfd26b6980100657397d69c84f2b80a005a
Signed-off-by: Cody P Schafer <[email protected]>
Reviewed-on: http://openocd.zylin.com/4455
Reviewed-by: Tomas Vanek <[email protected]>
Tested-by: jenkins
Reviewed-by: Christopher Head <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants