Search
lxdream.org :: lxdream/src/gtkui/mmio_win.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/mmio_win.c
changeset 561:533f6b478071
prev537:d924be49e192
next562:e598411b640b
author nkeynes
date Tue Jan 01 05:08:38 2008 +0000 (12 years ago)
branchlxdream-mmu
permissions -rw-r--r--
last change Enable Id keyword on all source files
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@31
     3
 *
nkeynes@31
     4
 * Implements the MMIO register viewing window
nkeynes@31
     5
 *
nkeynes@31
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@31
     7
 *
nkeynes@31
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@31
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@31
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@31
    11
 * (at your option) any later version.
nkeynes@31
    12
 *
nkeynes@31
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@31
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@31
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@31
    16
 * GNU General Public License for more details.
nkeynes@31
    17
 */
nkeynes@31
    18
nkeynes@2
    19
#include <stdint.h>
nkeynes@484
    20
#include <string.h>
nkeynes@484
    21
#include <glib/gi18n.h>
nkeynes@537
    22
#include "gtkui/gtkui.h"
nkeynes@2
    23
#include "mem.h"
nkeynes@2
    24
#include "mmio.h"
nkeynes@2
    25
nkeynes@457
    26
nkeynes@457
    27
struct mmio_window_info {
nkeynes@457
    28
    GtkWidget *window;
nkeynes@457
    29
    GtkWidget *notebook;
nkeynes@457
    30
};
nkeynes@2
    31
nkeynes@2
    32
static void printbits( char *out, int nbits, uint32_t value )
nkeynes@2
    33
{
nkeynes@2
    34
    if( nbits < 32 ) {
nkeynes@2
    35
        int i;
nkeynes@2
    36
        for( i=32; i>nbits; i-- ) {
nkeynes@2
    37
            if( !(i % 8) ) *out++ = ' ';
nkeynes@2
    38
            *out++ = ' ';
nkeynes@2
    39
        }
nkeynes@2
    40
    }
nkeynes@2
    41
    while( nbits > 0 ) {
nkeynes@2
    42
        *out++ = (value&(1<<--nbits) ? '1' : '0');
nkeynes@2
    43
        if( !(nbits % 8) ) *out++ = ' ';
nkeynes@2
    44
    }
nkeynes@2
    45
    *out = '\0';
nkeynes@2
    46
}
nkeynes@2
    47
nkeynes@2
    48
static void printhex( char *out, int nbits, uint32_t value )
nkeynes@2
    49
{
nkeynes@2
    50
    char tmp[10], *p = tmp;
nkeynes@2
    51
    int i;
nkeynes@2
    52
nkeynes@2
    53
    sprintf( tmp, "%08X", value );
nkeynes@2
    54
    for( i=32; i>0; i-=4, p++ ) {
nkeynes@2
    55
        if( i <= nbits ) *out++ = *p;
nkeynes@2
    56
        else *out++ = ' ';
nkeynes@2
    57
    }
nkeynes@2
    58
    *out = '\0';
nkeynes@2
    59
}
nkeynes@2
    60
    
nkeynes@457
    61
nkeynes@457
    62
nkeynes@457
    63
nkeynes@457
    64
gboolean
nkeynes@457
    65
on_mmio_delete_event                (GtkWidget       *widget,
nkeynes@457
    66
                                        GdkEvent        *event,
nkeynes@457
    67
                                        gpointer         user_data)
nkeynes@457
    68
{
nkeynes@457
    69
    gtk_widget_hide(widget);
nkeynes@457
    70
    return TRUE;
nkeynes@457
    71
}
nkeynes@457
    72
nkeynes@457
    73
nkeynes@457
    74
void on_mmio_close_clicked( GtkButton *button, gpointer user_data)
nkeynes@457
    75
{
nkeynes@457
    76
    gtk_widget_hide( ((mmio_window_t)user_data)->window );
nkeynes@457
    77
}
nkeynes@457
    78
nkeynes@457
    79
nkeynes@457
    80
void on_trace_button_toggled           (GtkToggleButton *button,
nkeynes@457
    81
					gpointer user_data)
nkeynes@457
    82
{
nkeynes@457
    83
    struct mmio_region *io_rgn = (struct mmio_region *)user_data;
nkeynes@457
    84
    gboolean isActive = gtk_toggle_button_get_active(button);
nkeynes@457
    85
    if( io_rgn != NULL ) {
nkeynes@457
    86
	io_rgn->trace_flag = isActive ? 1 : 0;
nkeynes@457
    87
    }
nkeynes@457
    88
}
nkeynes@457
    89
nkeynes@457
    90
static GtkCList *mmio_window_add_page( mmio_window_t mmio, char *name, struct mmio_region *io_rgn )
nkeynes@2
    91
{
nkeynes@2
    92
    GtkCList *list;
nkeynes@2
    93
    GtkWidget *scroll;
nkeynes@2
    94
    GtkWidget *tab;
nkeynes@238
    95
    GtkCheckButton *trace_button;
nkeynes@238
    96
    GtkVBox *vbox;
nkeynes@2
    97
nkeynes@2
    98
    scroll = gtk_scrolled_window_new(NULL, NULL);
nkeynes@2
    99
    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
nkeynes@2
   100
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
nkeynes@2
   101
    list = GTK_CLIST(gtk_clist_new(5));
nkeynes@45
   102
    gtk_clist_set_column_width(list, 0, 70);
nkeynes@45
   103
    gtk_clist_set_column_width(list, 1, 75);
nkeynes@45
   104
    gtk_clist_set_column_width(list, 2, 70);
nkeynes@45
   105
    gtk_clist_set_column_width(list, 3, 280);
nkeynes@2
   106
    gtk_clist_set_column_width(list, 4, 160);
nkeynes@2
   107
    gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
nkeynes@2
   108
    gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
nkeynes@2
   109
    gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
nkeynes@508
   110
    gtk_clist_set_column_title(list, 0, _("Address"));
nkeynes@508
   111
    gtk_clist_set_column_title(list, 1, _("Register"));
nkeynes@508
   112
    gtk_clist_set_column_title(list, 2, _("Value"));
nkeynes@508
   113
    gtk_clist_set_column_title(list, 3, _("Bit Pattern"));
nkeynes@508
   114
    gtk_clist_set_column_title(list, 4, _("Description"));
nkeynes@2
   115
    gtk_clist_column_titles_show(list);
nkeynes@435
   116
    gtk_widget_modify_font( GTK_WIDGET(list), gui_fixed_font );
nkeynes@2
   117
    tab = gtk_label_new(_(name));
nkeynes@2
   118
    gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
nkeynes@238
   119
    
nkeynes@429
   120
    vbox = GTK_VBOX(gtk_vbox_new( FALSE, 0 ));
nkeynes@238
   121
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
nkeynes@238
   122
nkeynes@508
   123
    trace_button = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("Trace access")));
nkeynes@238
   124
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
nkeynes@238
   125
    gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
nkeynes@238
   126
			       FALSE, FALSE, 0, GTK_PACK_START );
nkeynes@457
   127
    gtk_notebook_append_page( GTK_NOTEBOOK(mmio->notebook), GTK_WIDGET(vbox), tab );
nkeynes@457
   128
    gtk_object_set_data( GTK_OBJECT(mmio->window), name, list );
nkeynes@238
   129
    g_signal_connect ((gpointer) trace_button, "toggled",
nkeynes@238
   130
                    G_CALLBACK (on_trace_button_toggled),
nkeynes@238
   131
                    io_rgn);
nkeynes@2
   132
    return list;
nkeynes@2
   133
}
nkeynes@2
   134
nkeynes@457
   135
nkeynes@457
   136
nkeynes@457
   137
mmio_window_t mmio_window_new( const gchar *title )
nkeynes@457
   138
{
nkeynes@457
   139
    mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );
nkeynes@457
   140
    
nkeynes@457
   141
    int i, j;
nkeynes@457
   142
    GtkCList *all_list;
nkeynes@457
   143
    GtkWidget *vbox1;
nkeynes@457
   144
    GtkWidget *hbuttonbox1;
nkeynes@457
   145
    GtkWidget *mmr_close;
nkeynes@457
   146
nkeynes@457
   147
    mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
nkeynes@457
   148
    gtk_window_set_title (GTK_WINDOW (mmio->window), title);
nkeynes@457
   149
    gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);
nkeynes@457
   150
nkeynes@457
   151
    vbox1 = gtk_vbox_new (FALSE, 0);
nkeynes@457
   152
    gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);
nkeynes@457
   153
nkeynes@457
   154
    mmio->notebook = gtk_notebook_new ();
nkeynes@457
   155
    gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
nkeynes@457
   156
    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);
nkeynes@457
   157
nkeynes@457
   158
    hbuttonbox1 = gtk_hbutton_box_new ();
nkeynes@457
   159
    gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
nkeynes@457
   160
    gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);
nkeynes@457
   161
    
nkeynes@457
   162
    mmr_close = gtk_button_new_with_mnemonic (_("Close"));
nkeynes@457
   163
    gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
nkeynes@457
   164
    GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);
nkeynes@457
   165
nkeynes@457
   166
    /* Add the mmio register data */
nkeynes@457
   167
    all_list = mmio_window_add_page( mmio, "All", NULL );
nkeynes@457
   168
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   169
        GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
nkeynes@457
   170
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@457
   171
            int sz = io_rgn[i]->ports[j].width;
nkeynes@457
   172
            char addr[10], data[10], bits[40];
nkeynes@457
   173
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@457
   174
                            io_rgn[i]->ports[j].desc };
nkeynes@457
   175
            sprintf( addr, "%08X",
nkeynes@457
   176
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@457
   177
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@457
   178
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@457
   179
                       *io_rgn[i]->ports[j].val );
nkeynes@457
   180
            gtk_clist_append( list, arr );
nkeynes@457
   181
            gtk_clist_append( all_list, arr );
nkeynes@457
   182
        }
nkeynes@457
   183
    }
nkeynes@457
   184
    
nkeynes@457
   185
    g_signal_connect ((gpointer) mmio->window, "delete_event",
nkeynes@457
   186
		      G_CALLBACK (on_mmio_delete_event),
nkeynes@457
   187
		      NULL);
nkeynes@457
   188
    g_signal_connect ((gpointer) mmr_close, "clicked",
nkeynes@457
   189
		      G_CALLBACK (on_mmio_close_clicked),
nkeynes@457
   190
		      mmio);
nkeynes@457
   191
nkeynes@457
   192
    gtk_widget_show_all( mmio->window );
nkeynes@457
   193
    return mmio;
nkeynes@457
   194
}
nkeynes@457
   195
        
nkeynes@457
   196
void mmio_window_update( mmio_window_t mmio )
nkeynes@2
   197
{
nkeynes@2
   198
    int i,j, count = 0;
nkeynes@2
   199
    GtkCList *page, *all_page;
nkeynes@2
   200
    char data[10], bits[40];
nkeynes@2
   201
nkeynes@457
   202
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));
nkeynes@2
   203
    
nkeynes@57
   204
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   205
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
nkeynes@2
   206
                                              io_rgn[i]->id ));
nkeynes@2
   207
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   208
            if( *io_rgn[i]->ports[j].val !=
nkeynes@2
   209
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@2
   210
                int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   211
                /* Changed */
nkeynes@2
   212
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   213
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   214
                
nkeynes@2
   215
                gtk_clist_set_text( page, j, 2, data );
nkeynes@2
   216
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@435
   217
                gtk_clist_set_foreground( page, j, &gui_colour_changed );
nkeynes@2
   218
                
nkeynes@2
   219
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@2
   220
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@435
   221
                gtk_clist_set_foreground( all_page, count, &gui_colour_changed );
nkeynes@2
   222
                
nkeynes@2
   223
            } else {
nkeynes@435
   224
                gtk_clist_set_foreground( page, j, &gui_colour_normal );
nkeynes@435
   225
                gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
nkeynes@2
   226
            }
nkeynes@2
   227
            count++;
nkeynes@2
   228
        }
nkeynes@2
   229
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
nkeynes@2
   230
    }
nkeynes@2
   231
}
nkeynes@2
   232
nkeynes@457
   233
void mmio_window_show( mmio_window_t mmio, gboolean show )
nkeynes@2
   234
{
nkeynes@457
   235
    if( show ) {
nkeynes@457
   236
	gtk_widget_show( mmio->window );
nkeynes@457
   237
    } else {
nkeynes@457
   238
	gtk_widget_hide( mmio->window );
nkeynes@2
   239
    }
nkeynes@2
   240
}
nkeynes@2
   241
.