filename | src/watch.c |
changeset | 480:d28c2992f5ee |
prev | 6:6e3663e58565 |
next | 561:533f6b478071 |
author | nkeynes |
date | Sat Nov 17 01:18:09 2007 +0000 (16 years ago) |
permissions | -rw-r--r-- |
last change | Move the failing TA tests into a separate file for now - there's a bug about these already (basically error handling behaviour) |
view | annotate | diff | log | raw |
1 #include <stdlib.h>
2 #include <string.h>
3 #include "mem.h"
5 struct watch_point {
6 uint32_t start;
7 uint32_t end;
8 int flags;
9 };
11 struct watch_point *watch_arr = NULL;
12 int watch_count = 0, watch_capacity = 0;
15 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags )
16 {
17 int num;
18 if( watch_arr == NULL ) {
19 watch_capacity = 10;
20 watch_arr = calloc( sizeof(struct watch_point), watch_capacity );
21 num = 0;
22 } else if( watch_count == watch_capacity ) {
23 struct watch_point *tmp = realloc( watch_arr, sizeof(struct watch_point) * watch_capacity * 2 );
24 if( tmp == NULL )
25 return NULL;
26 watch_arr = tmp;
27 memset( &watch_arr[watch_capacity], 0, sizeof( struct watch_point ) * watch_capacity );
28 num = watch_capacity;
29 watch_capacity *= 2;
30 } else {
31 for( num=0; num<watch_capacity; num++ ) {
32 if( watch_arr[num].flags == 0 )
33 break;
34 }
35 }
36 watch_arr[num].start = start & 0x1FFFFFFF;
37 watch_arr[num].end = end & 0x1FFFFFFF;
38 watch_arr[num].flags = flags;
39 watch_count++;
40 return &watch_arr[num];
41 }
43 void mem_delete_watch( watch_point_t watch )
44 {
45 if( watch_arr == NULL )
46 return;
47 int num = watch - watch_arr;
48 if( num < 0 || num >= watch_capacity )
49 return;
50 watch->start = watch->end = 0;
51 watch->flags = 0;
52 watch_count--;
53 }
56 watch_point_t mem_is_watched( uint32_t addr, int size, int op )
57 {
58 int i, count;
59 addr &= 0x1FFFFFFF;
60 for( i=0, count=0; count< watch_count; i++ ) {
61 if( watch_arr[i].flags == 0 )
62 continue;
63 count++;
64 if( watch_arr[i].flags & op &&
65 watch_arr[i].start < addr+size &&
66 watch_arr[i].end >= addr ) {
67 return &watch_arr[i];
68 }
69 }
70 return NULL;
71 }
.