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