summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Widawsky <ben@bwidawsk.net>2011-06-21 22:25:29 -0700
committerBen Widawsky <ben@bwidawsk.net>2011-06-21 22:25:29 -0700
commite32187ab4841d966c7e38856af6ef4fab80b1b92 (patch)
tree3acc91a195a385e43222a8d07b9a6746f46a65ce
parent9d2eac4c827aaa6466024121e1bed8ae7ee6f6eb (diff)
-rw-r--r--debugger/eudb.c89
-rw-r--r--debugger/system_routine/sr.g4a70
2 files changed, 94 insertions, 65 deletions
diff --git a/debugger/eudb.c b/debugger/eudb.c
index 8faeef6f..cf6e884b 100644
--- a/debugger/eudb.c
+++ b/debugger/eudb.c
@@ -46,16 +46,9 @@
#include "intel_bufmgr.h"
#include "intel_gpu_tools.h"
#include "intel_batchbuffer.h"
+#include "intel_debug.h"
#include "debug.h"
-/*
- * This should come from a shared interface with the DRI client that is
- * submitting the program to be debugged.
- */
-#ifndef PER_THREAD_SCRATCH
- #define PER_THREAD_SCRATCH (1 << 20)
-#endif
-
#define EU_ATT 0x7810
#define EU_ATT_CLR 0x7830
@@ -96,6 +89,8 @@ const char *debug_file = "dump_debug.bin";
int debug;
int clear_waits;
int shutting_down = 0;
+struct debug_handshake dh;
+int force_clear = 0;
/*
* The docs are wrong about the attention clear bits. The clear bits are
@@ -212,7 +207,7 @@ wait_for_attn(int timeout, int *out_bits) {
static struct eu_state *
find_eu_shmem(int bit, volatile uint8_t *buf) {
struct per_thread_data {
- uint8_t ____[PER_THREAD_SCRATCH];
+ uint8_t ____[dh.per_thread_scratch];
}__attribute__((packed)) *data;
struct eu_state *eu;
int mem_tid, mem_euid, i;
@@ -233,7 +228,7 @@ find_eu_shmem(int bit, volatile uint8_t *buf) {
#define GRF_CMP(a, b) memcmp(a, b, sizeof(grf))
#define GRF_CPY(a, b) memcpy(a, b, sizeof(grf))
static int
-handshake(struct eu_state *eu) {
+verify(struct eu_state *eu) {
if (GRF_CMP(eu->version, protocol_version)) {
if (debug) {
printf("Bad EU protocol version %x %x\n",
@@ -284,7 +279,7 @@ collect_data(int bit, volatile uint8_t *buf) {
return -EBAD_SHMEM;
}
- ret = handshake(eu);
+ ret = verify(eu);
if (ret)
return ret;
@@ -312,10 +307,17 @@ clear_attn_old(int bit) {
intel_register_write(0x7830 + (bit/32) * 4, 1 << bit_to_clear);
}
#else
- int bit_to_clear;
- bit_to_clear = eu_info->debuggees[bit].clr;
- intel_register_write(EU_ATT_CLR + (bit/32) * 4, 0);
- intel_register_write(EU_ATT_CLR + (bit/32) * 4, 1 << bit_to_clear);
+ if (!force_clear) {
+ int bit_to_clear;
+ bit_to_clear = eu_info->debuggees[bit].clr;
+ intel_register_write(EU_ATT_CLR + (bit/32) * 4, 0);
+ intel_register_write(EU_ATT_CLR + (bit/32) * 4, 1 << bit_to_clear);
+ } else {
+ intel_register_write(EU_ATT_CLR + 0, 0);
+ intel_register_write(EU_ATT_CLR + 4, 0);
+ intel_register_write(EU_ATT_CLR + 0, 0xffffffff);
+ intel_register_write(EU_ATT_CLR + 4, 0xffffffff);
+ }
#endif
}
@@ -409,10 +411,10 @@ out:
close(fd);
}
-#define SHADER_DEBUG_SOCKET "/tmp/gen_debug"
static int
wait_for_scratch_bo(void) {
struct sockaddr_un addr;
+ uint8_t version;
int fd, ret, handle = -1;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -441,7 +443,7 @@ wait_for_scratch_bo(void) {
while(1) {
int client_fd;
size_t count;
- char okay[] = "okay";
+ char ack[] = DEBUG_HANDSHAKE_ACK;
client_fd = accept(fd, NULL, NULL);
if (client_fd == -1) {
@@ -449,18 +451,38 @@ wait_for_scratch_bo(void) {
goto done;
}
- count = read(client_fd, &handle, sizeof(handle));
- if (count != sizeof(handle)) {
- perror("read");
- close(client_fd);
- goto done;
+ count = read(client_fd, &version, sizeof(version));
+ if (count != sizeof(version)) {
+ perror("read version");
+ goto loop_out;
}
- count = write(client_fd, okay, 5);
- if (count != sizeof(okay)) {
- perror("write");
- close(client_fd);
- goto done;
+
+ if (version != DEBUG_HANDSHAKE_VERSION) {
+ fprintf(stderr, "Bad debug handshake\n");
+ goto loop_out;
}
+
+ count = read(client_fd, ((char *)&dh) + 1, sizeof(dh) - 1);
+ if (count != sizeof(dh) - 1) {
+ perror("read handshake");
+ goto loop_out;
+ }
+
+ count = write(client_fd, ack, sizeof(ack));
+ if (count != sizeof(ack)) {
+ perror("write ack");
+ goto loop_out;
+ }
+ handle = dh.flink_handle;
+ if (debug > 0) {
+ printf("Handshake completed successfully\n"
+ "\tprotocol version = %d\n"
+ "\tflink handle = %d\n"
+ "\tper thread scratch = %x\n", version,
+ dh.flink_handle, dh.per_thread_scratch);
+ }
+
+ loop_out:
close(client_fd);
break;
}
@@ -476,7 +498,7 @@ int main(int argc, char* argv[]) {
int bits[64];
int devid = -1, opt;
- while ((opt = getopt(argc, argv, "cdr:p?h")) != -1) {
+ while ((opt = getopt(argc, argv, "cdr:pf?h")) != -1) {
switch (opt) {
case 'c':
clear_waits = 1;
@@ -491,6 +513,9 @@ int main(int argc, char* argv[]) {
case 'p':
devid = atoi(optarg);
break;
+ case 'f':
+ force_clear = 1;
+ break;
case '?':
case 'h':
default:
@@ -527,12 +552,16 @@ int main(int argc, char* argv[]) {
if (fscanf(stdin, "%1d", &handle) == 0)
exit(1);
}
- printf("Given handle %d from mesa\n", handle);
scratch_bo = intel_bo_gem_create_from_name(bufmgr, "scratch", handle);
+ if (scratch_bo == NULL) {
+ fprintf(stderr, "Couldn't flink buffer\n");
+ abort();
+ }
signal(SIGINT, db_shutdown);
printf("Press Ctrl-C to stop\n");
} else {
- while (wait_for_attn(20000, bits)) {
+ int time = force_clear ? 0 : 20000;
+ while (wait_for_attn(time, bits)) {
clear_attn(bits[0]);
memset(bits, -1, sizeof(bits));
}
diff --git a/debugger/system_routine/sr.g4a b/debugger/system_routine/sr.g4a
index 61c65d75..a70e7712 100644
--- a/debugger/system_routine/sr.g4a
+++ b/debugger/system_routine/sr.g4a
@@ -151,51 +151,51 @@
/*
* clobbers: mrf.2 mrf.5
*/
-#define SAVE_MRF(mrf, offset) \
+#define STORE_MRF(mrf, offset) \
SET_OFFSET(mrf, offset); \
WRITE_SCRATCH1(mrf)
/*
- * non-quirky semantics, unlike SAVE_MRF
+ * non-quirky semantics, unlike STORE_MRF
* clobbers: g1
*/
-#define RESTORE_MRF(mrf, offset) \
+#define LOAD_MRF(mrf, offset) \
LOAD_GRF(g1, offset); \
mov (8) mrf:ud g1:ud FLAGS
#define SAVE_ALL_MRF \
/* m1 is saved already */ \
- SAVE_MRF(m1, 0x2); \
- SAVE_MRF(m2, 0x4); \
- SAVE_MRF(m3, 0x6); \
- SAVE_MRF(m4, 0x8); \
- SAVE_MRF(m5, 0xa); \
- SAVE_MRF(m6, 0xc); \
- SAVE_MRF(m7, 0xe); \
- SAVE_MRF(m8, 0x10); \
- SAVE_MRF(m9, 0x12); \
- SAVE_MRF(m10, 0x14); \
- SAVE_MRF(m11, 0x16); \
- SAVE_MRF(m12, 0x18); \
- SAVE_MRF(m13, 0x1a); \
- SAVE_MRF(m14, 0x1c)
+ STORE_MRF(m1, 0x2); \
+ STORE_MRF(m2, 0x4); \
+ STORE_MRF(m3, 0x6); \
+ STORE_MRF(m4, 0x8); \
+ STORE_MRF(m5, 0xa); \
+ STORE_MRF(m6, 0xc); \
+ STORE_MRF(m7, 0xe); \
+ STORE_MRF(m8, 0x10); \
+ STORE_MRF(m9, 0x12); \
+ STORE_MRF(m10, 0x14); \
+ STORE_MRF(m11, 0x16); \
+ STORE_MRF(m12, 0x18); \
+ STORE_MRF(m13, 0x1a); \
+ STORE_MRF(m14, 0x1c)
#define RESTORE_ALL_MRF \
- RESTORE_MRF(m15, 0x1c); \
- RESTORE_MRF(m14, 0x1a); \
- RESTORE_MRF(m13, 0x18); \
- RESTORE_MRF(m12, 0x16); \
- RESTORE_MRF(m11, 0x14); \
- RESTORE_MRF(m10, 0x12); \
- RESTORE_MRF(m9, 0x10); \
- RESTORE_MRF(m8, 0xe); \
- RESTORE_MRF(m7, 0xc); \
- RESTORE_MRF(m6, 0xa); \
- RESTORE_MRF(m5, 0x8); \
- RESTORE_MRF(m4, 0x6); \
- RESTORE_MRF(m3, 0x4); \
- RESTORE_MRF(m2, 0x2); \
- RESTORE_MRF(m1, 0x0)
+ LOAD_MRF(m15, 0x1c); \
+ LOAD_MRF(m14, 0x1a); \
+ LOAD_MRF(m13, 0x18); \
+ LOAD_MRF(m12, 0x16); \
+ LOAD_MRF(m11, 0x14); \
+ LOAD_MRF(m10, 0x12); \
+ LOAD_MRF(m9, 0x10); \
+ LOAD_MRF(m8, 0xe); \
+ LOAD_MRF(m7, 0xc); \
+ LOAD_MRF(m6, 0xa); \
+ LOAD_MRF(m5, 0x8); \
+ LOAD_MRF(m4, 0x6); \
+ LOAD_MRF(m3, 0x4); \
+ LOAD_MRF(m2, 0x2); \
+ LOAD_MRF(m1, 0x0)
#ifndef SANDYBRIDGE
#error Only SandyBridge is supported
@@ -222,9 +222,8 @@ Enter:
* EUID is in sr0.0[11:8]
*/
- mov (1) g0.4:ud 0:ud FLAGS;
-
#ifdef GPGPU
+ mov (1) g0.4:ud 0:ud FLAGS;
#if 0
/* This should work according to the docs, the add blows up */
shr (1) g0.8:uw sr0.0:uw 5 FLAGS;
@@ -239,9 +238,10 @@ Enter:
#endif
#endif
+ mov (8) m0:ud 0:ud FLAGS;
/* Saves must occur in order so as not to clobber the next register */
- SAVE_MRF(m0, 0);
+ STORE_MRF(m0, 0);
STORE_GRF(g0, 0x20);
STORE_GRF(g1, 0x22);
SAVE_ALL_MRF;