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 457:af605fd32c0b
prev455:3080881d00d4
next484:e2c1476f4c67
author nkeynes
date Wed Oct 31 11:53:35 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Fix miscellaneous warnings
view annotate diff log raw
     1 /**
     2  * $Id: mmio_win.c,v 1.9 2007-10-21 11:38:02 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 "gui/gtkui.h"
    22 #include "mem.h"
    23 #include "mmio.h"
    26 struct mmio_window_info {
    27     GtkWidget *window;
    28     GtkWidget *notebook;
    29 };
    31 static void printbits( char *out, int nbits, uint32_t value )
    32 {
    33     if( nbits < 32 ) {
    34         int i;
    35         for( i=32; i>nbits; i-- ) {
    36             if( !(i % 8) ) *out++ = ' ';
    37             *out++ = ' ';
    38         }
    39     }
    40     while( nbits > 0 ) {
    41         *out++ = (value&(1<<--nbits) ? '1' : '0');
    42         if( !(nbits % 8) ) *out++ = ' ';
    43     }
    44     *out = '\0';
    45 }
    47 static void printhex( char *out, int nbits, uint32_t value )
    48 {
    49     char tmp[10], *p = tmp;
    50     int i;
    52     sprintf( tmp, "%08X", value );
    53     for( i=32; i>0; i-=4, p++ ) {
    54         if( i <= nbits ) *out++ = *p;
    55         else *out++ = ' ';
    56     }
    57     *out = '\0';
    58 }
    63 gboolean
    64 on_mmio_delete_event                (GtkWidget       *widget,
    65                                         GdkEvent        *event,
    66                                         gpointer         user_data)
    67 {
    68     gtk_widget_hide(widget);
    69     return TRUE;
    70 }
    73 void on_mmio_close_clicked( GtkButton *button, gpointer user_data)
    74 {
    75     gtk_widget_hide( ((mmio_window_t)user_data)->window );
    76 }
    79 void on_trace_button_toggled           (GtkToggleButton *button,
    80 					gpointer user_data)
    81 {
    82     struct mmio_region *io_rgn = (struct mmio_region *)user_data;
    83     gboolean isActive = gtk_toggle_button_get_active(button);
    84     if( io_rgn != NULL ) {
    85 	io_rgn->trace_flag = isActive ? 1 : 0;
    86     }
    87 }
    89 static GtkCList *mmio_window_add_page( mmio_window_t mmio, char *name, struct mmio_region *io_rgn )
    90 {
    91     GtkCList *list;
    92     GtkWidget *scroll;
    93     GtkWidget *tab;
    94     GtkCheckButton *trace_button;
    95     GtkVBox *vbox;
    97     scroll = gtk_scrolled_window_new(NULL, NULL);
    98     gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
    99                                     GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
   100     list = GTK_CLIST(gtk_clist_new(5));
   101     gtk_clist_set_column_width(list, 0, 70);
   102     gtk_clist_set_column_width(list, 1, 75);
   103     gtk_clist_set_column_width(list, 2, 70);
   104     gtk_clist_set_column_width(list, 3, 280);
   105     gtk_clist_set_column_width(list, 4, 160);
   106     gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
   107     gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
   108     gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
   109     gtk_clist_set_column_title(list, 0, "Address");
   110     gtk_clist_set_column_title(list, 1, "Register");
   111     gtk_clist_set_column_title(list, 2, "Value");
   112     gtk_clist_set_column_title(list, 3, "Bit Pattern");
   113     gtk_clist_set_column_title(list, 4, "Description");
   114     gtk_clist_column_titles_show(list);
   115     gtk_widget_modify_font( GTK_WIDGET(list), gui_fixed_font );
   116     tab = gtk_label_new(_(name));
   117     gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
   119     vbox = GTK_VBOX(gtk_vbox_new( FALSE, 0 ));
   120     gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
   122     trace_button = GTK_CHECK_BUTTON(gtk_check_button_new_with_label("Trace access"));
   123     gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
   124     gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
   125 			       FALSE, FALSE, 0, GTK_PACK_START );
   126     gtk_notebook_append_page( GTK_NOTEBOOK(mmio->notebook), GTK_WIDGET(vbox), tab );
   127     gtk_object_set_data( GTK_OBJECT(mmio->window), name, list );
   128     g_signal_connect ((gpointer) trace_button, "toggled",
   129                     G_CALLBACK (on_trace_button_toggled),
   130                     io_rgn);
   131     return list;
   132 }
   136 mmio_window_t mmio_window_new( const gchar *title )
   137 {
   138     mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );
   140     int i, j;
   141     GtkCList *all_list;
   142     GtkWidget *vbox1;
   143     GtkWidget *hbuttonbox1;
   144     GtkWidget *mmr_close;
   146     mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   147     gtk_window_set_title (GTK_WINDOW (mmio->window), title);
   148     gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);
   150     vbox1 = gtk_vbox_new (FALSE, 0);
   151     gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);
   153     mmio->notebook = gtk_notebook_new ();
   154     gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
   155     gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);
   157     hbuttonbox1 = gtk_hbutton_box_new ();
   158     gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
   159     gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);
   161     mmr_close = gtk_button_new_with_mnemonic (_("Close"));
   162     gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
   163     GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);
   165     /* Add the mmio register data */
   166     all_list = mmio_window_add_page( mmio, "All", NULL );
   167     for( i=0; i < num_io_rgns; i++ ) {
   168         GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
   169         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   170             int sz = io_rgn[i]->ports[j].width;
   171             char addr[10], data[10], bits[40];
   172             char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
   173                             io_rgn[i]->ports[j].desc };
   174             sprintf( addr, "%08X",
   175                      io_rgn[i]->base + io_rgn[i]->ports[j].offset );
   176             printhex( data, sz, *io_rgn[i]->ports[j].val );
   177             printbits( bits, io_rgn[i]->ports[j].width,
   178                        *io_rgn[i]->ports[j].val );
   179             gtk_clist_append( list, arr );
   180             gtk_clist_append( all_list, arr );
   181         }
   182     }
   184     g_signal_connect ((gpointer) mmio->window, "delete_event",
   185 		      G_CALLBACK (on_mmio_delete_event),
   186 		      NULL);
   187     g_signal_connect ((gpointer) mmr_close, "clicked",
   188 		      G_CALLBACK (on_mmio_close_clicked),
   189 		      mmio);
   191     gtk_widget_show_all( mmio->window );
   192     return mmio;
   193 }
   195 void mmio_window_update( mmio_window_t mmio )
   196 {
   197     int i,j, count = 0;
   198     GtkCList *page, *all_page;
   199     char data[10], bits[40];
   201     all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));
   203     for( i=0; i < num_io_rgns; i++ ) {
   204         page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
   205                                               io_rgn[i]->id ));
   206         for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
   207             if( *io_rgn[i]->ports[j].val !=
   208                 *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
   209                 int sz = io_rgn[i]->ports[j].width;
   210                 /* Changed */
   211                 printhex( data, sz, *io_rgn[i]->ports[j].val );
   212                 printbits( bits, sz, *io_rgn[i]->ports[j].val );
   214                 gtk_clist_set_text( page, j, 2, data );
   215                 gtk_clist_set_text( page, j, 3, bits );
   216                 gtk_clist_set_foreground( page, j, &gui_colour_changed );
   218                 gtk_clist_set_text( all_page, count, 2, data );
   219                 gtk_clist_set_text( all_page, count, 3, bits );
   220                 gtk_clist_set_foreground( all_page, count, &gui_colour_changed );
   222             } else {
   223                 gtk_clist_set_foreground( page, j, &gui_colour_normal );
   224                 gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
   225             }
   226             count++;
   227         }
   228         memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
   229     }
   230 }
   232 void mmio_window_show( mmio_window_t mmio, gboolean show )
   233 {
   234     if( show ) {
   235 	gtk_widget_show( mmio->window );
   236     } else {
   237 	gtk_widget_hide( mmio->window );
   238     }
   239 }
.