Search
lxdream.org :: lxdream/src/gui/mmio_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/mmio_win.c
changeset 238:6af4cc93b137
prev57:5648c0e0638b
next429:e581b90c3fb3
author nkeynes
date Fri Dec 15 10:17:08 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Add UI for the trace flag
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@238
     2
 * $Id: mmio_win.c,v 1.5 2006-12-15 10:17:08 nkeynes Exp $
nkeynes@31
     3
 *
nkeynes@31
     4
 * Implements the MMIO register viewing window
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@31
    17
 */
nkeynes@31
    18
nkeynes@2
    19
#include <stdint.h>
nkeynes@2
    20
#include <gnome.h>
nkeynes@2
    21
#include "interface.h"
nkeynes@238
    22
#include "callbacks.h"
nkeynes@2
    23
#include "gui.h"
nkeynes@2
    24
#include "mem.h"
nkeynes@2
    25
#include "mmio.h"
nkeynes@2
    26
nkeynes@2
    27
GtkWidget *mmr_win;
nkeynes@2
    28
GtkNotebook *mmr_book;
nkeynes@2
    29
nkeynes@2
    30
static void printbits( char *out, int nbits, uint32_t value )
nkeynes@2
    31
{
nkeynes@2
    32
    if( nbits < 32 ) {
nkeynes@2
    33
        int i;
nkeynes@2
    34
        for( i=32; i>nbits; i-- ) {
nkeynes@2
    35
            if( !(i % 8) ) *out++ = ' ';
nkeynes@2
    36
            *out++ = ' ';
nkeynes@2
    37
        }
nkeynes@2
    38
    }
nkeynes@2
    39
    while( nbits > 0 ) {
nkeynes@2
    40
        *out++ = (value&(1<<--nbits) ? '1' : '0');
nkeynes@2
    41
        if( !(nbits % 8) ) *out++ = ' ';
nkeynes@2
    42
    }
nkeynes@2
    43
    *out = '\0';
nkeynes@2
    44
}
nkeynes@2
    45
nkeynes@2
    46
static void printhex( char *out, int nbits, uint32_t value )
nkeynes@2
    47
{
nkeynes@2
    48
    char tmp[10], *p = tmp;
nkeynes@2
    49
    int i;
nkeynes@2
    50
nkeynes@2
    51
    sprintf( tmp, "%08X", value );
nkeynes@2
    52
    for( i=32; i>0; i-=4, p++ ) {
nkeynes@2
    53
        if( i <= nbits ) *out++ = *p;
nkeynes@2
    54
        else *out++ = ' ';
nkeynes@2
    55
    }
nkeynes@2
    56
    *out = '\0';
nkeynes@2
    57
}
nkeynes@2
    58
    
nkeynes@2
    59
        
nkeynes@238
    60
static GtkCList *create_mmr_page( char *name, struct mmio_region *io_rgn )
nkeynes@2
    61
{
nkeynes@2
    62
    GtkCList *list;
nkeynes@2
    63
    GtkWidget *scroll;
nkeynes@2
    64
    GtkWidget *tab;
nkeynes@238
    65
    GtkCheckButton *trace_button;
nkeynes@238
    66
    GtkVBox *vbox;
nkeynes@2
    67
nkeynes@2
    68
    scroll = gtk_scrolled_window_new(NULL, NULL);
nkeynes@2
    69
    gtk_widget_show( scroll );
nkeynes@2
    70
    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
nkeynes@2
    71
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
nkeynes@2
    72
    list = GTK_CLIST(gtk_clist_new(5));
nkeynes@45
    73
    gtk_clist_set_column_width(list, 0, 70);
nkeynes@45
    74
    gtk_clist_set_column_width(list, 1, 75);
nkeynes@45
    75
    gtk_clist_set_column_width(list, 2, 70);
nkeynes@45
    76
    gtk_clist_set_column_width(list, 3, 280);
nkeynes@2
    77
    gtk_clist_set_column_width(list, 4, 160);
nkeynes@2
    78
    gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
nkeynes@2
    79
    gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
nkeynes@2
    80
    gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
nkeynes@2
    81
    gtk_clist_set_column_title(list, 0, "Address");
nkeynes@2
    82
    gtk_clist_set_column_title(list, 1, "Register");
nkeynes@2
    83
    gtk_clist_set_column_title(list, 2, "Value");
nkeynes@2
    84
    gtk_clist_set_column_title(list, 3, "Bit Pattern");
nkeynes@2
    85
    gtk_clist_set_column_title(list, 4, "Description");
nkeynes@2
    86
    gtk_clist_column_titles_show(list);
nkeynes@2
    87
    gtk_widget_modify_font( GTK_WIDGET(list), fixed_list_font );
nkeynes@2
    88
    gtk_widget_show( GTK_WIDGET(list) );
nkeynes@2
    89
    tab = gtk_label_new(_(name));
nkeynes@2
    90
    gtk_widget_show( tab );
nkeynes@2
    91
    gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
nkeynes@238
    92
    
nkeynes@238
    93
    vbox = gtk_vbox_new( FALSE, 0 );
nkeynes@238
    94
    gtk_widget_show( GTK_WIDGET(vbox) );
nkeynes@238
    95
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
nkeynes@238
    96
nkeynes@238
    97
    trace_button = gtk_check_button_new_with_label("Trace access");
nkeynes@238
    98
    gtk_widget_show( GTK_WIDGET(trace_button) );
nkeynes@238
    99
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
nkeynes@238
   100
    gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
nkeynes@238
   101
			       FALSE, FALSE, 0, GTK_PACK_START );
nkeynes@238
   102
    gtk_notebook_append_page( mmr_book, vbox, tab );
nkeynes@2
   103
    gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
nkeynes@238
   104
    g_signal_connect ((gpointer) trace_button, "toggled",
nkeynes@238
   105
                    G_CALLBACK (on_trace_button_toggled),
nkeynes@238
   106
                    io_rgn);
nkeynes@2
   107
    return list;
nkeynes@2
   108
}
nkeynes@2
   109
nkeynes@2
   110
void update_mmr_win( void )
nkeynes@2
   111
{
nkeynes@2
   112
    int i,j, count = 0;
nkeynes@2
   113
    GtkCList *page, *all_page;
nkeynes@2
   114
    char data[10], bits[40];
nkeynes@2
   115
nkeynes@2
   116
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
nkeynes@2
   117
    
nkeynes@57
   118
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@2
   119
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
nkeynes@2
   120
                                              io_rgn[i]->id ));
nkeynes@2
   121
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   122
            if( *io_rgn[i]->ports[j].val !=
nkeynes@2
   123
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@2
   124
                int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   125
                /* Changed */
nkeynes@2
   126
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   127
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   128
                
nkeynes@2
   129
                gtk_clist_set_text( page, j, 2, data );
nkeynes@2
   130
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@2
   131
                gtk_clist_set_foreground( page, j, &clrChanged );
nkeynes@2
   132
                
nkeynes@2
   133
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@2
   134
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@2
   135
                gtk_clist_set_foreground( all_page, count, &clrChanged );
nkeynes@2
   136
                
nkeynes@2
   137
            } else {
nkeynes@2
   138
                gtk_clist_set_foreground( page, j, &clrNormal );
nkeynes@2
   139
                gtk_clist_set_foreground( all_page, count, &clrNormal );
nkeynes@2
   140
            }
nkeynes@2
   141
            count++;
nkeynes@2
   142
        }
nkeynes@2
   143
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
nkeynes@2
   144
    }
nkeynes@2
   145
}
nkeynes@2
   146
nkeynes@2
   147
void init_mmr_win( void )
nkeynes@2
   148
{
nkeynes@2
   149
    int i, j;
nkeynes@2
   150
    GtkCList *all_list;
nkeynes@2
   151
    mmr_win = create_mmr_win();
nkeynes@2
   152
    mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
nkeynes@2
   153
    
nkeynes@2
   154
    /* kill the dummy page glade insists on adding */
nkeynes@2
   155
    gtk_notebook_remove_page( mmr_book, 0 );
nkeynes@2
   156
    
nkeynes@238
   157
    all_list = create_mmr_page( "All", NULL );
nkeynes@57
   158
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@238
   159
        GtkCList *list = create_mmr_page( io_rgn[i]->id, io_rgn[i] );
nkeynes@2
   160
        
nkeynes@2
   161
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   162
            int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   163
            char addr[10], data[10], bits[40];
nkeynes@2
   164
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@2
   165
                            io_rgn[i]->ports[j].desc };
nkeynes@2
   166
            sprintf( addr, "%08X",
nkeynes@2
   167
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@2
   168
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   169
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@2
   170
                       *io_rgn[i]->ports[j].val );
nkeynes@2
   171
            gtk_clist_append( list, arr );
nkeynes@2
   172
            gtk_clist_append( all_list, arr );
nkeynes@2
   173
        }
nkeynes@2
   174
    }
nkeynes@2
   175
}
nkeynes@2
   176
nkeynes@2
   177
void mmr_open_win( void )
nkeynes@2
   178
{
nkeynes@2
   179
    gtk_widget_show( mmr_win );
nkeynes@2
   180
}
nkeynes@2
   181
nkeynes@2
   182
void mmr_close_win( void )
nkeynes@2
   183
{
nkeynes@2
   184
    gtk_widget_hide( mmr_win );
nkeynes@2
   185
}
.