2 * $Id: mmio_win.c,v 1.4 2006-01-02 14:47:55 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"
27 GtkNotebook *mmr_book;
29 static void printbits( char *out, int nbits, uint32_t value )
33 for( i=32; i>nbits; i-- ) {
34 if( !(i % 8) ) *out++ = ' ';
39 *out++ = (value&(1<<--nbits) ? '1' : '0');
40 if( !(nbits % 8) ) *out++ = ' ';
45 static void printhex( char *out, int nbits, uint32_t value )
47 char tmp[10], *p = tmp;
50 sprintf( tmp, "%08X", value );
51 for( i=32; i>0; i-=4, p++ ) {
52 if( i <= nbits ) *out++ = *p;
59 static GtkCList *create_mmr_page( char *name )
65 scroll = gtk_scrolled_window_new(NULL, NULL);
66 gtk_widget_show( scroll );
67 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
68 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
69 list = GTK_CLIST(gtk_clist_new(5));
70 gtk_clist_set_column_width(list, 0, 70);
71 gtk_clist_set_column_width(list, 1, 75);
72 gtk_clist_set_column_width(list, 2, 70);
73 gtk_clist_set_column_width(list, 3, 280);
74 gtk_clist_set_column_width(list, 4, 160);
75 gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
76 gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
77 gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
78 gtk_clist_set_column_title(list, 0, "Address");
79 gtk_clist_set_column_title(list, 1, "Register");
80 gtk_clist_set_column_title(list, 2, "Value");
81 gtk_clist_set_column_title(list, 3, "Bit Pattern");
82 gtk_clist_set_column_title(list, 4, "Description");
83 gtk_clist_column_titles_show(list);
84 gtk_widget_modify_font( GTK_WIDGET(list), fixed_list_font );
85 gtk_widget_show( GTK_WIDGET(list) );
86 tab = gtk_label_new(_(name));
87 gtk_widget_show( tab );
88 gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
89 gtk_notebook_append_page( mmr_book, scroll, tab );
90 gtk_object_set_data( GTK_OBJECT(mmr_win), name, list );
94 void update_mmr_win( void )
97 GtkCList *page, *all_page;
98 char data[10], bits[40];
100 all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win), "All" ));
102 for( i=0; i < num_io_rgns; i++ ) {
103 page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmr_win),
105 for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
106 if( *io_rgn[i]->ports[j].val !=
107 *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
108 int sz = io_rgn[i]->ports[j].width;
110 printhex( data, sz, *io_rgn[i]->ports[j].val );
111 printbits( bits, sz, *io_rgn[i]->ports[j].val );
113 gtk_clist_set_text( page, j, 2, data );
114 gtk_clist_set_text( page, j, 3, bits );
115 gtk_clist_set_foreground( page, j, &clrChanged );
117 gtk_clist_set_text( all_page, count, 2, data );
118 gtk_clist_set_text( all_page, count, 3, bits );
119 gtk_clist_set_foreground( all_page, count, &clrChanged );
122 gtk_clist_set_foreground( page, j, &clrNormal );
123 gtk_clist_set_foreground( all_page, count, &clrNormal );
127 memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
131 void init_mmr_win( void )
135 mmr_win = create_mmr_win();
136 mmr_book = GTK_NOTEBOOK( gtk_object_get_data( GTK_OBJECT(mmr_win), "mmr_notebook" ));
138 /* kill the dummy page glade insists on adding */
139 gtk_notebook_remove_page( mmr_book, 0 );
141 all_list = create_mmr_page( "All" );
142 for( i=0; i < num_io_rgns; i++ ) {
143 GtkCList *list = create_mmr_page( io_rgn[i]->id );
145 for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
146 int sz = io_rgn[i]->ports[j].width;
147 char addr[10], data[10], bits[40];
148 char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
149 io_rgn[i]->ports[j].desc };
150 sprintf( addr, "%08X",
151 io_rgn[i]->base + io_rgn[i]->ports[j].offset );
152 printhex( data, sz, *io_rgn[i]->ports[j].val );
153 printbits( bits, io_rgn[i]->ports[j].width,
154 *io_rgn[i]->ports[j].val );
155 gtk_clist_append( list, arr );
156 gtk_clist_append( all_list, arr );
161 void mmr_open_win( void )
163 gtk_widget_show( mmr_win );
166 void mmr_close_win( void )
168 gtk_widget_hide( mmr_win );
.