Search
lxdream.org :: lxdream/src/gtkui/gtk_mmio.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_mmio.c
changeset 1065:bc1cc0c54917
prev563:72ccfd1f432b
prev796:a2dc83592467
author nkeynes
date Sun Jul 05 13:52:50 2009 +1000 (11 years ago)
permissions -rw-r--r--
last change No-op merge lxdream-mmu to remove head (actually merged long ago)
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gtkui/gtk_mmio.c Sun Jul 05 13:52:50 2009 +1000
1.3 @@ -0,0 +1,244 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Implements the MMIO register viewing window
1.8 + *
1.9 + * Copyright (c) 2005 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include <stdint.h>
1.23 +#include <string.h>
1.24 +#include "gtkui/gtkui.h"
1.25 +#include "mem.h"
1.26 +#include "mmio.h"
1.27 +
1.28 +
1.29 +struct mmio_window_info {
1.30 + GtkWidget *window;
1.31 + GtkWidget *notebook;
1.32 +};
1.33 +
1.34 +static void printbits( char *out, int nbits, uint32_t value )
1.35 +{
1.36 + if( nbits < 32 ) {
1.37 + int i;
1.38 + for( i=32; i>nbits; i-- ) {
1.39 + if( !(i % 8) ) *out++ = ' ';
1.40 + *out++ = ' ';
1.41 + }
1.42 + }
1.43 + while( nbits > 0 ) {
1.44 + *out++ = (value&(1<<--nbits) ? '1' : '0');
1.45 + if( !(nbits % 8) ) *out++ = ' ';
1.46 + }
1.47 + *out = '\0';
1.48 +}
1.49 +
1.50 +static void printhex( char *out, int nbits, uint32_t value )
1.51 +{
1.52 + char tmp[10], *p = tmp;
1.53 + int i;
1.54 +
1.55 + sprintf( tmp, "%08X", value );
1.56 + for( i=32; i>0; i-=4, p++ ) {
1.57 + if( i <= nbits ) *out++ = *p;
1.58 + else *out++ = ' ';
1.59 + }
1.60 + *out = '\0';
1.61 +}
1.62 +
1.63 +
1.64 +
1.65 +
1.66 +gboolean
1.67 +on_mmio_delete_event (GtkWidget *widget,
1.68 + GdkEvent *event,
1.69 + gpointer user_data)
1.70 +{
1.71 + gtk_widget_hide(widget);
1.72 + return TRUE;
1.73 +}
1.74 +
1.75 +
1.76 +void on_mmio_close_clicked( GtkButton *button, gpointer user_data)
1.77 +{
1.78 + gtk_widget_hide( ((mmio_window_t)user_data)->window );
1.79 +}
1.80 +
1.81 +
1.82 +void on_trace_button_toggled (GtkToggleButton *button,
1.83 + gpointer user_data)
1.84 +{
1.85 + struct mmio_region *io_rgn = (struct mmio_region *)user_data;
1.86 + gboolean isActive = gtk_toggle_button_get_active(button);
1.87 + if( io_rgn != NULL ) {
1.88 + io_rgn->trace_flag = isActive ? 1 : 0;
1.89 + }
1.90 +}
1.91 +
1.92 +static GtkCList *mmio_window_add_page( mmio_window_t mmio, char *name, struct mmio_region *io_rgn )
1.93 +{
1.94 + GtkCList *list;
1.95 + GtkWidget *scroll;
1.96 + GtkWidget *tab;
1.97 + GtkCheckButton *trace_button;
1.98 + GtkVBox *vbox;
1.99 +
1.100 + scroll = gtk_scrolled_window_new(NULL, NULL);
1.101 + gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
1.102 + GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
1.103 + list = GTK_CLIST(gtk_clist_new(5));
1.104 + gtk_clist_set_column_width(list, 0, 70);
1.105 + gtk_clist_set_column_width(list, 1, 75);
1.106 + gtk_clist_set_column_width(list, 2, 70);
1.107 + gtk_clist_set_column_width(list, 3, 280);
1.108 + gtk_clist_set_column_width(list, 4, 160);
1.109 + gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
1.110 + gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
1.111 + gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
1.112 + gtk_clist_set_column_title(list, 0, _("Address"));
1.113 + gtk_clist_set_column_title(list, 1, _("Register"));
1.114 + gtk_clist_set_column_title(list, 2, _("Value"));
1.115 + gtk_clist_set_column_title(list, 3, _("Bit Pattern"));
1.116 + gtk_clist_set_column_title(list, 4, _("Description"));
1.117 + gtk_clist_column_titles_show(list);
1.118 + gtk_widget_modify_font( GTK_WIDGET(list), gui_fixed_font );
1.119 + tab = gtk_label_new(_(name));
1.120 + gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
1.121 +
1.122 + vbox = GTK_VBOX(gtk_vbox_new( FALSE, 0 ));
1.123 + gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
1.124 +
1.125 + trace_button = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("Trace access")));
1.126 + if( io_rgn != NULL ) {
1.127 + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trace_button),
1.128 + io_rgn->trace_flag ? TRUE : FALSE);
1.129 + }
1.130 + gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
1.131 + gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button),
1.132 + FALSE, FALSE, 0, GTK_PACK_START );
1.133 + gtk_notebook_append_page( GTK_NOTEBOOK(mmio->notebook), GTK_WIDGET(vbox), tab );
1.134 + gtk_object_set_data( GTK_OBJECT(mmio->window), name, list );
1.135 + g_signal_connect ((gpointer) trace_button, "toggled",
1.136 + G_CALLBACK (on_trace_button_toggled),
1.137 + io_rgn);
1.138 + return list;
1.139 +}
1.140 +
1.141 +
1.142 +
1.143 +mmio_window_t mmio_window_new( const gchar *title )
1.144 +{
1.145 + mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );
1.146 +
1.147 + int i, j;
1.148 + GtkCList *all_list;
1.149 + GtkWidget *vbox1;
1.150 + GtkWidget *hbuttonbox1;
1.151 + GtkWidget *mmr_close;
1.152 +
1.153 + mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
1.154 + gtk_window_set_title (GTK_WINDOW (mmio->window), title);
1.155 + gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);
1.156 +
1.157 + vbox1 = gtk_vbox_new (FALSE, 0);
1.158 + gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);
1.159 +
1.160 + mmio->notebook = gtk_notebook_new ();
1.161 + gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
1.162 + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);
1.163 +
1.164 + hbuttonbox1 = gtk_hbutton_box_new ();
1.165 + gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
1.166 + gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);
1.167 +
1.168 + mmr_close = gtk_button_new_with_mnemonic (_("Close"));
1.169 + gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
1.170 + GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);
1.171 +
1.172 + /* Add the mmio register data */
1.173 + all_list = mmio_window_add_page( mmio, "All", NULL );
1.174 + for( i=0; i < num_io_rgns; i++ ) {
1.175 + GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
1.176 + for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
1.177 + int sz = io_rgn[i]->ports[j].width;
1.178 + char addr[10], data[10], bits[40];
1.179 + char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
1.180 + io_rgn[i]->ports[j].desc };
1.181 + sprintf( addr, "%08X",
1.182 + io_rgn[i]->base + io_rgn[i]->ports[j].offset );
1.183 + printhex( data, sz, *io_rgn[i]->ports[j].val );
1.184 + printbits( bits, io_rgn[i]->ports[j].width,
1.185 + *io_rgn[i]->ports[j].val );
1.186 + gtk_clist_append( list, arr );
1.187 + gtk_clist_append( all_list, arr );
1.188 + }
1.189 + }
1.190 +
1.191 + g_signal_connect ((gpointer) mmio->window, "delete_event",
1.192 + G_CALLBACK (on_mmio_delete_event),
1.193 + NULL);
1.194 + g_signal_connect ((gpointer) mmr_close, "clicked",
1.195 + G_CALLBACK (on_mmio_close_clicked),
1.196 + mmio);
1.197 +
1.198 + gtk_widget_show_all( mmio->window );
1.199 + return mmio;
1.200 +}
1.201 +
1.202 +void mmio_window_update( mmio_window_t mmio )
1.203 +{
1.204 + int i,j, count = 0;
1.205 + GtkCList *page, *all_page;
1.206 + char data[10], bits[40];
1.207 +
1.208 + all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));
1.209 +
1.210 + for( i=0; i < num_io_rgns; i++ ) {
1.211 + page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
1.212 + io_rgn[i]->id ));
1.213 + for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
1.214 + if( *io_rgn[i]->ports[j].val !=
1.215 + *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
1.216 + int sz = io_rgn[i]->ports[j].width;
1.217 + /* Changed */
1.218 + printhex( data, sz, *io_rgn[i]->ports[j].val );
1.219 + printbits( bits, sz, *io_rgn[i]->ports[j].val );
1.220 +
1.221 + gtk_clist_set_text( page, j, 2, data );
1.222 + gtk_clist_set_text( page, j, 3, bits );
1.223 + gtk_clist_set_foreground( page, j, &gui_colour_changed );
1.224 +
1.225 + gtk_clist_set_text( all_page, count, 2, data );
1.226 + gtk_clist_set_text( all_page, count, 3, bits );
1.227 + gtk_clist_set_foreground( all_page, count, &gui_colour_changed );
1.228 +
1.229 + } else {
1.230 + gtk_clist_set_foreground( page, j, &gui_colour_normal );
1.231 + gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
1.232 + }
1.233 + count++;
1.234 + }
1.235 + memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, LXDREAM_PAGE_SIZE );
1.236 + }
1.237 +}
1.238 +
1.239 +void mmio_window_show( mmio_window_t mmio, gboolean show )
1.240 +{
1.241 + if( show ) {
1.242 + gtk_widget_show( mmio->window );
1.243 + } else {
1.244 + gtk_widget_hide( mmio->window );
1.245 + }
1.246 +}
1.247 +
.