Search
lxdream.org :: lxdream/src/watch.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/watch.c
changeset 6:6e3663e58565
prev2:42349f6ea216
next480:d28c2992f5ee
author nkeynes
date Sat Oct 02 05:49:39 2004 +0000 (17 years ago)
permissions -rw-r--r--
last change compile fix
file annotate diff log raw
nkeynes@2
     1
#include <stdlib.h>
nkeynes@2
     2
#include "mem.h"
nkeynes@2
     3
nkeynes@2
     4
struct watch_point {
nkeynes@2
     5
    uint32_t start;
nkeynes@2
     6
    uint32_t end;
nkeynes@2
     7
    int flags;
nkeynes@2
     8
};
nkeynes@2
     9
nkeynes@2
    10
struct watch_point *watch_arr = NULL;
nkeynes@2
    11
int watch_count = 0, watch_capacity = 0;
nkeynes@2
    12
nkeynes@2
    13
nkeynes@2
    14
watch_point_t mem_new_watch( uint32_t start, uint32_t end, int flags )
nkeynes@2
    15
{
nkeynes@2
    16
    int num;
nkeynes@2
    17
    if( watch_arr == NULL ) {
nkeynes@2
    18
        watch_capacity = 10;
nkeynes@2
    19
        watch_arr = calloc( sizeof(struct watch_point), watch_capacity );
nkeynes@2
    20
        num = 0;
nkeynes@2
    21
    } else if( watch_count == watch_capacity ) {
nkeynes@2
    22
        struct watch_point *tmp = realloc( watch_arr, sizeof(struct watch_point) * watch_capacity * 2 );
nkeynes@2
    23
        if( tmp == NULL )
nkeynes@2
    24
            return NULL;
nkeynes@2
    25
        watch_arr = tmp;
nkeynes@2
    26
        memset( &watch_arr[watch_capacity], 0, sizeof( struct watch_point ) * watch_capacity );
nkeynes@2
    27
        num = watch_capacity;
nkeynes@2
    28
        watch_capacity *= 2;
nkeynes@2
    29
    } else {
nkeynes@2
    30
        for( num=0; num<watch_capacity; num++ ) {
nkeynes@2
    31
            if( watch_arr[num].flags == 0 )
nkeynes@2
    32
                break;
nkeynes@2
    33
        }
nkeynes@2
    34
    }
nkeynes@2
    35
    watch_arr[num].start = start & 0x1FFFFFFF;
nkeynes@2
    36
    watch_arr[num].end = end & 0x1FFFFFFF;
nkeynes@2
    37
    watch_arr[num].flags = flags;
nkeynes@2
    38
    watch_count++;
nkeynes@2
    39
    return &watch_arr[num];
nkeynes@2
    40
}
nkeynes@2
    41
nkeynes@2
    42
void mem_delete_watch( watch_point_t watch )
nkeynes@2
    43
{
nkeynes@2
    44
    if( watch_arr == NULL )
nkeynes@2
    45
        return;
nkeynes@2
    46
    int num = watch - watch_arr;
nkeynes@2
    47
    if( num < 0 || num >= watch_capacity )
nkeynes@6
    48
        return;
nkeynes@2
    49
    watch->start = watch->end = 0;
nkeynes@2
    50
    watch->flags = 0;
nkeynes@2
    51
    watch_count--;
nkeynes@2
    52
}
nkeynes@2
    53
nkeynes@2
    54
nkeynes@2
    55
watch_point_t mem_is_watched( uint32_t addr, int size, int op )
nkeynes@2
    56
{
nkeynes@2
    57
    int i, count;
nkeynes@2
    58
    addr &= 0x1FFFFFFF;
nkeynes@2
    59
    for( i=0, count=0; count< watch_count; i++ ) {
nkeynes@2
    60
        if( watch_arr[i].flags == 0 )
nkeynes@2
    61
            continue;
nkeynes@2
    62
        count++;
nkeynes@2
    63
        if( watch_arr[i].flags & op &&
nkeynes@2
    64
            watch_arr[i].start < addr+size &&
nkeynes@2
    65
            watch_arr[i].end >= addr ) {
nkeynes@2
    66
            return &watch_arr[i];
nkeynes@2
    67
        }
nkeynes@2
    68
    }
nkeynes@2
    69
    return NULL;
nkeynes@2
    70
}
nkeynes@2
    71
.