4 * Watchpoint support (for debugging)
6 * Copyright (c) 2005 Nathan Keynes.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
29 struct watch_point *watch_arr = NULL;
30 int watch_count = 0, watch_capacity = 0;
33 watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags )
36 if( watch_arr == NULL ) {
38 watch_arr = calloc( sizeof(struct watch_point), watch_capacity );
40 } else if( watch_count == watch_capacity ) {
41 struct watch_point *tmp = realloc( watch_arr, sizeof(struct watch_point) * watch_capacity * 2 );
45 memset( &watch_arr[watch_capacity], 0, sizeof( struct watch_point ) * watch_capacity );
49 for( num=0; num<watch_capacity; num++ ) {
50 if( watch_arr[num].flags == 0 )
54 watch_arr[num].start = start & 0x1FFFFFFF;
55 watch_arr[num].end = end & 0x1FFFFFFF;
56 watch_arr[num].flags = flags;
58 return &watch_arr[num];
61 void mem_delete_watch( watch_point_t watch )
63 if( watch_arr == NULL )
65 int num = watch - watch_arr;
66 if( num < 0 || num >= watch_capacity )
68 watch->start = watch->end = 0;
74 watch_point_t mem_is_watched( uint32_t addr, int size, int op )
78 for( i=0, count=0; count< watch_count; i++ ) {
79 if( watch_arr[i].flags == 0 )
82 if( watch_arr[i].flags & op &&
83 watch_arr[i].start < addr+size &&
84 watch_arr[i].end >= addr ) {
.