2 * $Id: mmio_win.c,v 1.5 2006-12-15 10:17:08 nkeynes Exp $
4 * Implements the MMIO register viewing window
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
21 #include "interface.h"
22 #include "callbacks.h"
28 GtkNotebook *mmr_book;
30 static void printbits( char *out, int nbits, uint32_t value )
34 for( i=32; i>nbits; i-- ) {
35 if( !(i % 8) ) *out++ = ' ';
40 *out++ = (value&(1<<--nbits) ? '1' : '0');
41 if( !(nbits % 8) ) *out++ = ' ';
46 static void printhex( char *out, int nbits, uint32_t value )
48 char tmp[10], *p = tmp;
51 sprintf( tmp, "%08X", value );
52 for( i=32; i>0; i-=4, p++ ) {
53 if( i <= nbits ) *out++ = *p;
60 static GtkCList *create_mmr_page( char *name, struct mmio_region *io_rgn )
65 GtkCheckButton *trace_button;
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),
110 void update_mmr_win( void )
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),
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;
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 );
138 gtk_clist_set_foreground( page, j, &clrNormal );
139 gtk_clist_set_foreground( all_page, count, &clrNormal );
143 memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
147 void init_mmr_win( void )
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 );
177 void mmr_open_win( void )
179 gtk_widget_show( mmr_win );
182 void mmr_close_win( void )
184 gtk_widget_hide( mmr_win );
.