3

What is a trace bit in Processor Status register, I can't find any resource that describe about how it work, for now all I could find is that it take two bits 0,1 for Trace on/Trace off mode. Can anyone help me understand it in detail?

Tworf
  • 31
  • 3

1 Answers1

4

Yuval's comment is correct. When the flag is set, the processor executes one instruction and then issues a trap (i.e. an interrupt), which is typically caught by the operating system.

The purpose is to help with debugging.

Programmers who are debugging their software want to set breakpoints at specific locations. This can be implemented using a variety of mechanisms, including the processor's debug registers, modifying code (i.e. overwriting an instruction with another instruction which causes a trap; the single-byte INT3 instruction on x86 is for precisely this purpose), or through the virtual memory system (i.e. marking a page in such a way that executing code in that area causes a page fault).

From the earliest days, another desired feature is single-step debugging, where the processor executes one instruction at a time and then returns control to the debugger. Many early CPUs would actually let you stop and "toggle" the processor clock to support single-stepping, but this required additional specialised hardware to make use of it which would add to the cost of a home machine.

Hence, the trace flag.

As a final note, I'm not surprised at all that you didn't know this. Very little attention is paid these days to the kind of support needed by both the CPU and OS to implement a debugger. Code modification, for example, interferes with the instruction pipeline on modern superscalar CPUs, so some extra circuitry is needed to make techniques like INT3 work.

Pseudonym
  • 22,091
  • 2
  • 42
  • 84