2 * Ptrace test for TAR, PPR, DSCR registers
4 * Copyright (C) 2015 Anshuman Khandual, IBM Corporation.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include "ptrace-tar.h"
14 /* Tracer and Tracee Shared Data */
24 cptr = (int *)shmat(shm_id, NULL, 0);
25 printf("%-30s TAR: %u PPR: %lx DSCR: %u\n",
26 user_write, TAR_1, PPR_1, DSCR_1);
28 mtspr(SPRN_TAR, TAR_1);
29 mtspr(SPRN_PPR, PPR_1);
30 mtspr(SPRN_DSCR, DSCR_1);
36 asm volatile("" : : : "memory");
38 reg[0] = mfspr(SPRN_TAR);
39 reg[1] = mfspr(SPRN_PPR);
40 reg[2] = mfspr(SPRN_DSCR);
42 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
43 user_read, reg[0], reg[1], reg[2]);
45 /* Unblock the parent now */
49 ret = validate_tar_registers(reg, TAR_2, PPR_2, DSCR_2);
55 int trace_tar(pid_t child)
59 FAIL_IF(start_trace(child));
60 FAIL_IF(show_tar_registers(child, reg));
61 printf("%-30s TAR: %lu PPR: %lx DSCR: %lu\n",
62 ptrace_read_running, reg[0], reg[1], reg[2]);
64 FAIL_IF(validate_tar_registers(reg, TAR_1, PPR_1, DSCR_1));
65 FAIL_IF(stop_trace(child));
69 int trace_tar_write(pid_t child)
71 FAIL_IF(start_trace(child));
72 FAIL_IF(write_tar_registers(child, TAR_2, PPR_2, DSCR_2));
73 printf("%-30s TAR: %u PPR: %lx DSCR: %u\n",
74 ptrace_write_running, TAR_2, PPR_2, DSCR_2);
76 FAIL_IF(stop_trace(child));
85 shm_id = shmget(IPC_PRIVATE, sizeof(int) * 3, 0777|IPC_CREAT);
88 perror("fork() failed");
96 pptr = (int *)shmat(shm_id, NULL, 0);
101 asm volatile("" : : : "memory");
102 ret = trace_tar(pid);
106 ret = trace_tar_write(pid);
110 /* Unblock the child now */
115 asm volatile("" : : : "memory");
120 shmctl(shm_id, IPC_RMID, NULL);
122 printf("Child's exit status not captured\n");
126 return (WIFEXITED(status) && WEXITSTATUS(status)) ? TEST_FAIL :
132 int main(int argc, char *argv[])
134 return test_harness(ptrace_tar, "ptrace_tar");