Msg/FetchBadPC: Difference between revisions
From CPUlator Wiki
< Msg
Created page with "Normally, the CPU should execute code that came from a code section (such as <code>.text</code>) from an executable file generated by an assembler or compiler. This message te..." |
No edit summary |
||
Line 20: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
As the examples above show, one of the common reasons for encountering this warning is that the program runs past the end of the <code>.text</code> section and starts executing in the <code>.data</code> section. Although the first 32-bit word of the <code>.data</code> section is a valid opcode, executing instructions from the <code>.data</code> section is usually unintended. | ==== MIPS ==== | ||
<syntaxhighlight line lang="Asm" highlight="5"> | |||
.global _start | |||
_start: | |||
nop | |||
.data | |||
nop | |||
</syntaxhighlight> | |||
As the examples above show, one of the common reasons for encountering this warning is that the program runs past the end of the <code>.text</code> section and starts executing in the <code>.data</code> section. Although the first 32-bit word of the <code>.data</code> section is a valid opcode in this example, executing instructions from the <code>.data</code> section is usually unintended. | |||
=== Debugging === | === Debugging === |
Revision as of 03:57, 17 March 2019
Normally, the CPU should execute code that came from a code section (such as .text
) from an executable file generated by an assembler or compiler. This message tells you that the simulator thinks you're currently executing outside a code section.
Examples
ARMv7
.global _start
_start:
nop
nop
.data
nop
Nios II
.global _start
_start:
nop
.data
nop
MIPS
.global _start
_start:
nop
.data
nop
As the examples above show, one of the common reasons for encountering this warning is that the program runs past the end of the .text
section and starts executing in the .data
section. Although the first 32-bit word of the .data
section is a valid opcode in this example, executing instructions from the .data
section is usually unintended.
Debugging
- As in the examples above, make sure your program isn't executing past the end of the
.text
section. - Executing from a bad location could also be due to a branch with an incorrect target address. To find the offending branch, try using the Trace window (located in the same panel as the registers window by default) to look backwards in the program execution.
Implementation
ELF executables contain "sections" of bytes that define where in memory each blob of bytes in the executable should be loaded. The ELF executable also includes information on whether each section is intended for executable code (e.g., the .text
section contains code) or for data (the .data
section is marked as containing data). The simulator tracks the sections defined in the most recently loaded ELF executable, and checks each instruction fetch against the sections. This message is generated at the instruction fetch.
There may be uncommon cases where the simulator's idea of what is a code section doesn't match reality, and you may want to disable this warning. Some examples:
- Your program writes code into a data section and then executes it. In this case, executing from a data section really is the right thing to do.
- Your program has multiple ELF executables. The simulator uses the section boundaries defined in the most recently loaded ELF executable.
Disabling this message
This debugging check can be disabled in the Debugging Checks section of the Settings box: Instruction fetch: Outside a code section.