The DAWR (Data Address Watch Register) is a PowerPC hardware CPU register used for debugging and tracing memory access. It's not a standard general-purpose register, but a specialized one for monitoring specific memory addresses. It's part of the memory management unit (MMU) and allows the programmer to set breakpoints or triggers based on memory reads or writes to a particular address.
Purpose:
The DAWR is primarily used for debugging purposes. It allows programmers to set up watchpoints on specific memory locations. When the CPU accesses (reads or writes) the watched address, it can trigger an event, such as a breakpoint or a debug interrupt. It detects unexpected memory writes, helping diagnose issues like buffer overflows or data corruption.
Hardware Implementation:
The DAWR is part of the PowerPC's MMU. It works by comparing the memory address being accessed with the address stored in the DAWR. If they match, the hardware triggers a specified action.
DAWR operates by:
- Storing a target memory address.
- Comparing every memory access against this address.
- Triggering an event if there's a match.
This is done entirely in hardware, making it efficient and low-overhead compared to software-based tracing.
Usage:
The DAWR is not directly used for arithmetic or other general-purpose computations. It's a dedicated resource for tracing memory access patterns during development and debugging.
DAWR is integrated with Linux kernel features like:
- perf
- ptrace
- hw_breakpoint API
Example:
A programmer might use the DAWR to detect when a specific variable in memory is being written to by the program, which can be helpful in tracking down data corruption issues.
Step 1: Create a simple C program
#include <stdio.h>
#include <unistd.h>
int main() {
volatile int target = 0;
for (int i = 0; i < 10; i++) {
target += i;
printf("target = %d\\n", target);
sleep(1);
}
return 0;
}
------------------------
Compile it:
gcc -O0 -g -o watchme watchme.c
-----------------------
Step 2: Find the address of `target` using GDB
gdb ./watchme
(gdb) break main
(gdb) run
(gdb) print &target
Suppose it returns 0x555555756014
Step 3: Use perf to trace writes
perf record -e mem:0x555555756014:w -p $(pidof watchme)
Step 4: View the report
perf report
-----------------------------------------------------
Other PowerPC Registers:
Besides the DAWR, PowerPC has a set of general-purpose registers (32 of them), floating-point registers (32), and vector registers (32 with AltiVec).
1. General-Purpose Registers (GPRs)
- Count: 32 registers (`r0` to `r31`)
- Width: 32-bit or 64-bit depending on the architecture
- Purpose: Used for integer arithmetic, logical operations, address calculations, and data movement.
- Special Notes:
- `r1` is typically used as the stack pointer.
- `r0` has special behavior in some instructions (e.g., it may be treated as zero).
Example:
addi r3, r3, 1 ; Increment value in r3 by 1
------------------------------------------------
2. Floating-Point Registers (FPRs) :
- Count: 32 registers (`f0` to `f31`)
- Width: 64-bit
- Purpose: Used for floating-point arithmetic (e.g., addition, multiplication, division).
- IEEE 754 compliant for single and double precision.
Example:
fadd f1, f2, f3 ; f1 = f2 + f3
3. Vector Registers (VRs) with AltiVec/VMX
- Count: 32 registers (`v0` to `v31`)
- Width: 128-bit
- Purpose: Used for SIMD (Single Instruction, Multiple Data) operations.
- AltiVec (also known as VMX) enables parallel processing of data—ideal for multimedia, signal processing, and scientific computing.
Example:
vector float a, b, c;
c = vec_add(a, b); // Adds two vectors element-wise
NOTE: VMX stands for Vector Multimedia Extension, and it's the original name for what is more commonly known as AltiVec — a SIMD (Single Instruction, Multiple Data) instruction set used in PowerPC processors. That allows a single instruction to operate on multiple data elements in parallel. Each vector register(`v0` to `v31`) can hold:
- - 16 x 8-bit integers
- - 8 x 16-bit integers
- - 4 x 32-bit integers or floats
vector float a = {1.0, 2.0, 3.0, 4.0};
vector float b = {5.0, 6.0, 7.0, 8.0};
vector float c = vec_add(a, b); // c = {6.0, 8.0, 10.0, 12.0}
----------------------------------
4. Special-Purpose Registers (SPRs):
Includes registers like:
- LR (Link Register): Stores return address for function calls
- CTR (Count Register): Used in loops and branching
- XER (Fixed-Point Exception Register): Tracks overflow, carry, etc.
- MSR (Machine State Register): Controls processor state
- DAWR: For memory watchpoint
These are accessed using `mfspr` (move from SPR) and `mtspr` (move to SPR) instructions.
---------------------------------
Conclusion :
DAWR is a powerful tool for low-level debugging on PowerPC systems. Whether you're working on kernel modules, embedded systems, or performance profiling, DAWR can help you pinpoint memory access issues with precision.
Reference :
- https://www.ibm.com/docs/en/aix/7.2.0?topic=faa-special-purpose-register-changes-special-purpose-register-field-handling
- https://docs.rtems.org/docs/4.11.0/cpu-supplement/powerpc.html
No comments:
Post a Comment