Msg/FetchBadPC: Difference between revisions

From CPUlator Wiki

< Msg
No edit summary
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:
nop
nop
</syntaxhighlight>
</syntaxhighlight>
(This example uses two nops in the .text section for ARM because the assembler pads the length of the .text section to a multiple of 8 bytes.)
==== Nios II ====
==== Nios II ====
<syntaxhighlight line lang="Asm" highlight="5">
<syntaxhighlight line lang="Asm" highlight="5">

Latest revision as of 04:00, 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

(This example uses two nops in the .text section for ARM because the assembler pads the length of the .text section to a multiple of 8 bytes.)

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.