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 736:a02d1475ccfd
prev586:2a3ba82cf243
next755:ab873907b00e
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@31
     1
/**
nkeynes@586
     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@736
    60
nkeynes@457
    61
nkeynes@457
    62
nkeynes@457
    63
nkeynes@457
    64
gboolean
nkeynes@457
    65
on_mmio_delete_event                (GtkWidget       *widget,
nkeynes@736
    66
                                     GdkEvent        *event,
nkeynes@736
    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@736
    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@736
    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@736
   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@586
   124
    if( io_rgn != NULL ) {
nkeynes@736
   125
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trace_button), 
nkeynes@736
   126
                io_rgn->trace_flag ? TRUE : FALSE);
nkeynes@586
   127
    }
nkeynes@238
   128
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
nkeynes@238
   129
    gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
nkeynes@736
   130
                               FALSE, FALSE, 0, GTK_PACK_START );
nkeynes@457
   131
    gtk_notebook_append_page( GTK_NOTEBOOK(mmio->notebook), GTK_WIDGET(vbox), tab );
nkeynes@457
   132
    gtk_object_set_data( GTK_OBJECT(mmio->window), name, list );
nkeynes@238
   133
    g_signal_connect ((gpointer) trace_button, "toggled",
nkeynes@736
   134
                      G_CALLBACK (on_trace_button_toggled),
nkeynes@736
   135
                      io_rgn);
nkeynes@2
   136
    return list;
nkeynes@2
   137
}
nkeynes@2
   138
nkeynes@457
   139
nkeynes@457
   140
nkeynes@457
   141
mmio_window_t mmio_window_new( const gchar *title )
nkeynes@457
   142
{
nkeynes@457
   143
    mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );
nkeynes@736
   144
nkeynes@457
   145
    int i, j;
nkeynes@457
   146
    GtkCList *all_list;
nkeynes@457
   147
    GtkWidget *vbox1;
nkeynes@457
   148
    GtkWidget *hbuttonbox1;
nkeynes@457
   149
    GtkWidget *mmr_close;
nkeynes@457
   150
nkeynes@457
   151
    mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
nkeynes@457
   152
    gtk_window_set_title (GTK_WINDOW (mmio->window), title);
nkeynes@457
   153
    gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);
nkeynes@457
   154
nkeynes@457
   155
    vbox1 = gtk_vbox_new (FALSE, 0);
nkeynes@457
   156
    gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);
nkeynes@457
   157
nkeynes@457
   158
    mmio->notebook = gtk_notebook_new ();
nkeynes@457
   159
    gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
nkeynes@457
   160
    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);
nkeynes@457
   161
nkeynes@457
   162
    hbuttonbox1 = gtk_hbutton_box_new ();
nkeynes@457
   163
    gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
nkeynes@457
   164
    gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);
nkeynes@736
   165
nkeynes@457
   166
    mmr_close = gtk_button_new_with_mnemonic (_("Close"));
nkeynes@457
   167
    gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
nkeynes@457
   168
    GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);
nkeynes@457
   169
nkeynes@457
   170
    /* Add the mmio register data */
nkeynes@457
   171
    all_list = mmio_window_add_page( mmio, "All", NULL );
nkeynes@457
   172
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   173
        GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
nkeynes@457
   174
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@457
   175
            int sz = io_rgn[i]->ports[j].width;
nkeynes@457
   176
            char addr[10], data[10], bits[40];
nkeynes@457
   177
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@736
   178
                    io_rgn[i]->ports[j].desc };
nkeynes@457
   179
            sprintf( addr, "%08X",
nkeynes@457
   180
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@457
   181
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@457
   182
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@457
   183
                       *io_rgn[i]->ports[j].val );
nkeynes@457
   184
            gtk_clist_append( list, arr );
nkeynes@457
   185
            gtk_clist_append( all_list, arr );
nkeynes@457
   186
        }
nkeynes@457
   187
    }
nkeynes@736
   188
nkeynes@457
   189
    g_signal_connect ((gpointer) mmio->window, "delete_event",
nkeynes@736
   190
                      G_CALLBACK (on_mmio_delete_event),
nkeynes@736
   191
                      NULL);
nkeynes@457
   192
    g_signal_connect ((gpointer) mmr_close, "clicked",
nkeynes@736
   193
                      G_CALLBACK (on_mmio_close_clicked),
nkeynes@736
   194
                      mmio);
nkeynes@457
   195
nkeynes@457
   196
    gtk_widget_show_all( mmio->window );
nkeynes@457
   197
    return mmio;
nkeynes@457
   198
}
nkeynes@736
   199
nkeynes@457
   200
void mmio_window_update( mmio_window_t mmio )
nkeynes@2
   201
{
nkeynes@2
   202
    int i,j, count = 0;
nkeynes@2
   203
    GtkCList *page, *all_page;
nkeynes@2
   204
    char data[10], bits[40];
nkeynes@2
   205
nkeynes@457
   206
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));
nkeynes@736
   207
nkeynes@57
   208
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   209
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
nkeynes@736
   210
                io_rgn[i]->id ));
nkeynes@2
   211
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   212
            if( *io_rgn[i]->ports[j].val !=
nkeynes@2
   213
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@2
   214
                int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   215
                /* Changed */
nkeynes@2
   216
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   217
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@736
   218
nkeynes@2
   219
                gtk_clist_set_text( page, j, 2, data );
nkeynes@2
   220
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@435
   221
                gtk_clist_set_foreground( page, j, &gui_colour_changed );
nkeynes@736
   222
nkeynes@2
   223
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@2
   224
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@435
   225
                gtk_clist_set_foreground( all_page, count, &gui_colour_changed );
nkeynes@736
   226
nkeynes@2
   227
            } else {
nkeynes@435
   228
                gtk_clist_set_foreground( page, j, &gui_colour_normal );
nkeynes@435
   229
                gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
nkeynes@2
   230
            }
nkeynes@2
   231
            count++;
nkeynes@2
   232
        }
nkeynes@2
   233
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, PAGE_SIZE );
nkeynes@2
   234
    }
nkeynes@2
   235
}
nkeynes@2
   236
nkeynes@457
   237
void mmio_window_show( mmio_window_t mmio, gboolean show )
nkeynes@2
   238
{
nkeynes@457
   239
    if( show ) {
nkeynes@736
   240
        gtk_widget_show( mmio->window );
nkeynes@457
   241
    } else {
nkeynes@736
   242
        gtk_widget_hide( mmio->window );
nkeynes@2
   243
    }
nkeynes@2
   244
}
nkeynes@2
   245
.