Search
lxdream.org :: lxdream/src/watch.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/watch.c
changeset 2:42349f6ea216
next6:6e3663e58565
author nkeynes
date Sat Aug 21 06:15:49 2004 +0000 (17 years ago)
permissions -rw-r--r--
last change Commit changes into cvs
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/watch.c Sat Aug 21 06:15:49 2004 +0000
1.3 @@ -0,0 +1,71 @@
1.4 +#include <stdlib.h>
1.5 +#include "mem.h"
1.6 +
1.7 +struct watch_point {
1.8 + uint32_t start;
1.9 + uint32_t end;
1.10 + int flags;
1.11 +};
1.12 +
1.13 +struct watch_point *watch_arr = NULL;
1.14 +int watch_count = 0, watch_capacity = 0;
1.15 +
1.16 +
1.17 +watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags )
1.18 +{
1.19 + int num;
1.20 + if( watch_arr == NULL ) {
1.21 + watch_capacity = 10;
1.22 + watch_arr = calloc( sizeof(struct watch_point), watch_capacity );
1.23 + num = 0;
1.24 + } else if( watch_count == watch_capacity ) {
1.25 + struct watch_point *tmp = realloc( watch_arr, sizeof(struct watch_point) * watch_capacity * 2 );
1.26 + if( tmp == NULL )
1.27 + return NULL;
1.28 + watch_arr = tmp;
1.29 + memset( &watch_arr[watch_capacity], 0, sizeof( struct watch_point ) * watch_capacity );
1.30 + num = watch_capacity;
1.31 + watch_capacity *= 2;
1.32 + } else {
1.33 + for( num=0; num<watch_capacity; num++ ) {
1.34 + if( watch_arr[num].flags == 0 )
1.35 + break;
1.36 + }
1.37 + }
1.38 + watch_arr[num].start = start & 0x1FFFFFFF;
1.39 + watch_arr[num].end = end & 0x1FFFFFFF;
1.40 + watch_arr[num].flags = flags;
1.41 + watch_count++;
1.42 + return &watch_arr[num];
1.43 +}
1.44 +
1.45 +void mem_delete_watch( watch_point_t watch )
1.46 +{
1.47 + if( watch_arr == NULL )
1.48 + return;
1.49 + int num = watch - watch_arr;
1.50 + if( num < 0 || num >= watch_capacity )
1.51 + return NULL;
1.52 + watch->start = watch->end = 0;
1.53 + watch->flags = 0;
1.54 + watch_count--;
1.55 +}
1.56 +
1.57 +
1.58 +watch_point_t mem_is_watched( uint32_t addr, int size, int op )
1.59 +{
1.60 + int i, count;
1.61 + addr &= 0x1FFFFFFF;
1.62 + for( i=0, count=0; count< watch_count; i++ ) {
1.63 + if( watch_arr[i].flags == 0 )
1.64 + continue;
1.65 + count++;
1.66 + if( watch_arr[i].flags & op &&
1.67 + watch_arr[i].start < addr+size &&
1.68 + watch_arr[i].end >= addr ) {
1.69 + return &watch_arr[i];
1.70 + }
1.71 + }
1.72 + return NULL;
1.73 +}
1.74 +
.