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 Tue Dec 19 09:51:35 2006 +0000 (17 years ago)
permissions -rw-r--r--
last change First cut of port 576890 (sysreset) and ide enable/disable
view annotate diff log raw
     1 /**
     2  * $Id: mmio_win.c,v 1.5 2006-12-15 10:17:08 nkeynes Exp $
     3  *
     4  * Implements the MMIO register viewing window
     5  *
     6  * Copyright (c) 2005 Nathan Keynes.
     7  *
     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.
    12  *
    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.
    17  */
    19 #include <stdint.h>
    20 #include <gnome.h>
    21 #include "interface.h"
    22 #include "callbacks.h"
    23 #include "gui.h"
    24 #include "mem.h"
    25 #include "mmio.h"
    27 GtkWidget *mmr_win;
    28 GtkNotebook *mmr_book;
    30 static void printbits( char *out, int nbits, uint32_t value )
    31 {
    32     if( nbits < 32 ) {
    33         int i;
    34         for( i=32; i>nbits; i-- ) {
    35             if( !(i % 8) ) *out++ = ' ';
    36             *out++ = ' ';
    37         }
    38     }
    39     while( nbits > 0 ) {
    40         *out++ = (value&(1<<--nbits) ? '1' : '0');
    41         if( !(nbits % 8) ) *out++ = ' ';
    42     }
    43     *out = '\0';
    44 }
    46 static void printhex( char *out, int nbits, uint32_t value )
    47 {
    48     char tmp[10], *p = tmp;
    49     int i;
    51     sprintf( tmp, "%08X", value );
    52     for( i=32; i>0; i-=4, p++ ) {
    53         if( i <= nbits ) *out++ = *p;
    54         else *out++ = ' ';
    55     }
    56     *out = '\0';
    57 }
    60 static GtkCList *create_mmr_page( char *name, struct mmio_region *io_rgn )
    61 {
    62     GtkCList *list;
    63     GtkWidget *scroll;
    64     GtkWidget *tab;
    65     GtkCheckButton *trace_button;
    66     GtkVBox *vbox;
    68     scroll = gtk_scrolled_window_new(NULL, NULL);
    69     gtk_widget_show( scroll );
    70     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
    71                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
    72     list = GTK_CLIST(gtk_clist_new(5));
    73     gtk_clist_set_column_width(list, 0, 70);
    74     gtk_clist_set_column_width(list, 1, 75);
    75     gtk_clist_set_column_width(list, 2, 70);
    76     gtk_clist_set_column_width(list, 3, 280);
    77     gtk_clist_set_column_width(list, 4, 160);
    78     gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
    79     gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
    80     gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
    81     gtk_clist_set_column_title(list, 0, "Address");
    82     gtk_clist_set_column_title(list, 1, "Register");
    83     gtk_clist_set_column_title(list, 2, "Value");
    84     gtk_clist_set_column_title(list, 3, "Bit Pattern");
    85     gtk_clist_set_column_title(list, 4, "Description");
    86     gtk_clist_column_titles_show(list);
    87     gtk_widget_modify_font( GTK_WIDGET(list), fixed_list_font );
    88     gtk_widget_show( GTK_WIDGET(list) );
    89     tab = gtk_label_new(_(name));
    90     gtk_widget_show( tab );
    91     gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
    93     vbox = gtk_vbox_new( FALSE, 0 );
    94     gtk_widget_show( GTK_WIDGET(vbox) );
    95     gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
    97     trace_button = gtk_check_button_new_with_label("Trace access");
    98     gtk_widget_show( GTK_WIDGET(trace_button) );
    99     gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
   100     gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
   101 			       FALSE, FALSE, 0, GTK_PACK_START );
   102     gtk_notebook_append_page( mmr_book, vbox, tab );
   103     gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
   104     g_signal_connect ((gpointer) trace_button, "toggled",
   105                     G_CALLBACK (on_trace_button_toggled),
   106                     io_rgn);
   107     return list;
   108 }
   110 void update_mmr_win( void )
   111 {
   112     int i,j, count = 0;
   113     GtkCList *page, *all_page;
   114     char data[10], bits[40];
   116     all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
   118     for( i=0; i < num_io_rgns; i++ ) {
   119         page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
   120                                               io_rgn[i]->id ));
   121         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   122             if( *io_rgn[i]->ports[j].val !=
   123                 *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
   124                 int sz = io_rgn[i]->ports[j].width;
   125                 /* Changed */
   126                 printhex( data, sz, *io_rgn[i]->ports[j].val );
   127                 printbits( bits, sz, *io_rgn[i]->ports[j].val );
   129                 gtk_clist_set_text( page, j, 2, data );
   130                 gtk_clist_set_text( page, j, 3, bits );
   131                 gtk_clist_set_foreground( page, j, &clrChanged );
   133                 gtk_clist_set_text( all_page, count, 2, data );
   134                 gtk_clist_set_text( all_page, count, 3, bits );
   135                 gtk_clist_set_foreground( all_page, count, &clrChanged );
   137             } else {
   138                 gtk_clist_set_foreground( page, j, &clrNormal );
   139                 gtk_clist_set_foreground( all_page, count, &clrNormal );
   140             }
   141             count++;
   142         }
   143         memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
   144     }
   145 }
   147 void init_mmr_win( void )
   148 {
   149     int i, j;
   150     GtkCList *all_list;
   151     mmr_win = create_mmr_win();
   152     mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
   154     /* kill the dummy page glade insists on adding */
   155     gtk_notebook_remove_page( mmr_book, 0 );
   157     all_list = create_mmr_page( "All", NULL );
   158     for( i=0; i < num_io_rgns; i++ ) {
   159         GtkCList *list = create_mmr_page( io_rgn[i]->id, io_rgn[i] );
   161         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   162             int sz = io_rgn[i]->ports[j].width;
   163             char addr[10], data[10], bits[40];
   164             char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
   165                             io_rgn[i]->ports[j].desc };
   166             sprintf( addr, "%08X",
   167                      io_rgn[i]->base + io_rgn[i]->ports[j].offset );
   168             printhex( data, sz, *io_rgn[i]->ports[j].val );
   169             printbits( bits, io_rgn[i]->ports[j].width,
   170                        *io_rgn[i]->ports[j].val );
   171             gtk_clist_append( list, arr );
   172             gtk_clist_append( all_list, arr );
   173         }
   174     }
   175 }
   177 void mmr_open_win( void )
   178 {
   179     gtk_widget_show( mmr_win );
   180 }
   182 void mmr_close_win( void )
   183 {
   184     gtk_widget_hide( mmr_win );
   185 }
.