Search
lxdream.org :: lxdream/src/gtkui/gtk_mmio.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gtkui/gtk_mmio.c
changeset 796:a2dc83592467
prev763:b3ce4448f200
next1065:bc1cc0c54917
author nkeynes
date Wed Jul 30 22:50:44 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Bug #61: OpenBSD support
(Modified) patch from bsdmaniak, thanks!
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@537
    21
#include "gtkui/gtkui.h"
nkeynes@2
    22
#include "mem.h"
nkeynes@2
    23
#include "mmio.h"
nkeynes@2
    24
nkeynes@457
    25
nkeynes@457
    26
struct mmio_window_info {
nkeynes@457
    27
    GtkWidget *window;
nkeynes@457
    28
    GtkWidget *notebook;
nkeynes@457
    29
};
nkeynes@2
    30
nkeynes@2
    31
static void printbits( char *out, int nbits, uint32_t value )
nkeynes@2
    32
{
nkeynes@2
    33
    if( nbits < 32 ) {
nkeynes@2
    34
        int i;
nkeynes@2
    35
        for( i=32; i>nbits; i-- ) {
nkeynes@2
    36
            if( !(i % 8) ) *out++ = ' ';
nkeynes@2
    37
            *out++ = ' ';
nkeynes@2
    38
        }
nkeynes@2
    39
    }
nkeynes@2
    40
    while( nbits > 0 ) {
nkeynes@2
    41
        *out++ = (value&(1<<--nbits) ? '1' : '0');
nkeynes@2
    42
        if( !(nbits % 8) ) *out++ = ' ';
nkeynes@2
    43
    }
nkeynes@2
    44
    *out = '\0';
nkeynes@2
    45
}
nkeynes@2
    46
nkeynes@2
    47
static void printhex( char *out, int nbits, uint32_t value )
nkeynes@2
    48
{
nkeynes@2
    49
    char tmp[10], *p = tmp;
nkeynes@2
    50
    int i;
nkeynes@2
    51
nkeynes@2
    52
    sprintf( tmp, "%08X", value );
nkeynes@2
    53
    for( i=32; i>0; i-=4, p++ ) {
nkeynes@2
    54
        if( i <= nbits ) *out++ = *p;
nkeynes@2
    55
        else *out++ = ' ';
nkeynes@2
    56
    }
nkeynes@2
    57
    *out = '\0';
nkeynes@2
    58
}
nkeynes@736
    59
nkeynes@457
    60
nkeynes@457
    61
nkeynes@457
    62
nkeynes@457
    63
gboolean
nkeynes@457
    64
on_mmio_delete_event                (GtkWidget       *widget,
nkeynes@736
    65
                                     GdkEvent        *event,
nkeynes@736
    66
                                     gpointer         user_data)
nkeynes@457
    67
{
nkeynes@457
    68
    gtk_widget_hide(widget);
nkeynes@457
    69
    return TRUE;
nkeynes@457
    70
}
nkeynes@457
    71
nkeynes@457
    72
nkeynes@457
    73
void on_mmio_close_clicked( GtkButton *button, gpointer user_data)
nkeynes@457
    74
{
nkeynes@457
    75
    gtk_widget_hide( ((mmio_window_t)user_data)->window );
nkeynes@457
    76
}
nkeynes@457
    77
nkeynes@457
    78
nkeynes@457
    79
void on_trace_button_toggled           (GtkToggleButton *button,
nkeynes@736
    80
                                        gpointer user_data)
nkeynes@457
    81
{
nkeynes@457
    82
    struct mmio_region *io_rgn = (struct mmio_region *)user_data;
nkeynes@457
    83
    gboolean isActive = gtk_toggle_button_get_active(button);
nkeynes@457
    84
    if( io_rgn != NULL ) {
nkeynes@736
    85
        io_rgn->trace_flag = isActive ? 1 : 0;
nkeynes@457
    86
    }
nkeynes@457
    87
}
nkeynes@457
    88
nkeynes@457
    89
static GtkCList *mmio_window_add_page( mmio_window_t mmio, char *name, struct mmio_region *io_rgn )
nkeynes@2
    90
{
nkeynes@2
    91
    GtkCList *list;
nkeynes@2
    92
    GtkWidget *scroll;
nkeynes@2
    93
    GtkWidget *tab;
nkeynes@238
    94
    GtkCheckButton *trace_button;
nkeynes@238
    95
    GtkVBox *vbox;
nkeynes@2
    96
nkeynes@2
    97
    scroll = gtk_scrolled_window_new(NULL, NULL);
nkeynes@2
    98
    gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW(scroll),
nkeynes@2
    99
                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS );
nkeynes@2
   100
    list = GTK_CLIST(gtk_clist_new(5));
nkeynes@45
   101
    gtk_clist_set_column_width(list, 0, 70);
nkeynes@45
   102
    gtk_clist_set_column_width(list, 1, 75);
nkeynes@45
   103
    gtk_clist_set_column_width(list, 2, 70);
nkeynes@45
   104
    gtk_clist_set_column_width(list, 3, 280);
nkeynes@2
   105
    gtk_clist_set_column_width(list, 4, 160);
nkeynes@2
   106
    gtk_clist_set_column_justification(list, 0, GTK_JUSTIFY_CENTER );
nkeynes@2
   107
    gtk_clist_set_column_justification(list, 2, GTK_JUSTIFY_CENTER );
nkeynes@2
   108
    gtk_clist_set_column_justification(list, 3, GTK_JUSTIFY_CENTER );
nkeynes@508
   109
    gtk_clist_set_column_title(list, 0, _("Address"));
nkeynes@508
   110
    gtk_clist_set_column_title(list, 1, _("Register"));
nkeynes@508
   111
    gtk_clist_set_column_title(list, 2, _("Value"));
nkeynes@508
   112
    gtk_clist_set_column_title(list, 3, _("Bit Pattern"));
nkeynes@508
   113
    gtk_clist_set_column_title(list, 4, _("Description"));
nkeynes@2
   114
    gtk_clist_column_titles_show(list);
nkeynes@435
   115
    gtk_widget_modify_font( GTK_WIDGET(list), gui_fixed_font );
nkeynes@2
   116
    tab = gtk_label_new(_(name));
nkeynes@2
   117
    gtk_container_add( GTK_CONTAINER(scroll), GTK_WIDGET(list) );
nkeynes@736
   118
nkeynes@429
   119
    vbox = GTK_VBOX(gtk_vbox_new( FALSE, 0 ));
nkeynes@238
   120
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(scroll) );
nkeynes@238
   121
nkeynes@508
   122
    trace_button = GTK_CHECK_BUTTON(gtk_check_button_new_with_label(_("Trace access")));
nkeynes@586
   123
    if( io_rgn != NULL ) {
nkeynes@736
   124
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(trace_button), 
nkeynes@736
   125
                io_rgn->trace_flag ? TRUE : FALSE);
nkeynes@586
   126
    }
nkeynes@238
   127
    gtk_container_add( GTK_CONTAINER(vbox), GTK_WIDGET(trace_button) );
nkeynes@238
   128
    gtk_box_set_child_packing( GTK_BOX(vbox), GTK_WIDGET(trace_button), 
nkeynes@736
   129
                               FALSE, FALSE, 0, GTK_PACK_START );
nkeynes@457
   130
    gtk_notebook_append_page( GTK_NOTEBOOK(mmio->notebook), GTK_WIDGET(vbox), tab );
nkeynes@457
   131
    gtk_object_set_data( GTK_OBJECT(mmio->window), name, list );
nkeynes@238
   132
    g_signal_connect ((gpointer) trace_button, "toggled",
nkeynes@736
   133
                      G_CALLBACK (on_trace_button_toggled),
nkeynes@736
   134
                      io_rgn);
nkeynes@2
   135
    return list;
nkeynes@2
   136
}
nkeynes@2
   137
nkeynes@457
   138
nkeynes@457
   139
nkeynes@457
   140
mmio_window_t mmio_window_new( const gchar *title )
nkeynes@457
   141
{
nkeynes@457
   142
    mmio_window_t mmio = g_malloc0( sizeof(struct mmio_window_info) );
nkeynes@736
   143
nkeynes@457
   144
    int i, j;
nkeynes@457
   145
    GtkCList *all_list;
nkeynes@457
   146
    GtkWidget *vbox1;
nkeynes@457
   147
    GtkWidget *hbuttonbox1;
nkeynes@457
   148
    GtkWidget *mmr_close;
nkeynes@457
   149
nkeynes@457
   150
    mmio->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
nkeynes@457
   151
    gtk_window_set_title (GTK_WINDOW (mmio->window), title);
nkeynes@457
   152
    gtk_window_set_default_size (GTK_WINDOW (mmio->window), 600, 600);
nkeynes@457
   153
nkeynes@457
   154
    vbox1 = gtk_vbox_new (FALSE, 0);
nkeynes@457
   155
    gtk_container_add (GTK_CONTAINER (mmio->window), vbox1);
nkeynes@457
   156
nkeynes@457
   157
    mmio->notebook = gtk_notebook_new ();
nkeynes@457
   158
    gtk_box_pack_start (GTK_BOX (vbox1), mmio->notebook, TRUE, TRUE, 0);
nkeynes@457
   159
    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (mmio->notebook), GTK_POS_LEFT);
nkeynes@457
   160
nkeynes@457
   161
    hbuttonbox1 = gtk_hbutton_box_new ();
nkeynes@457
   162
    gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, TRUE, 0);
nkeynes@457
   163
    gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 30);
nkeynes@736
   164
nkeynes@457
   165
    mmr_close = gtk_button_new_with_mnemonic (_("Close"));
nkeynes@457
   166
    gtk_container_add (GTK_CONTAINER (hbuttonbox1), mmr_close);
nkeynes@457
   167
    GTK_WIDGET_SET_FLAGS (mmr_close, GTK_CAN_DEFAULT);
nkeynes@457
   168
nkeynes@457
   169
    /* Add the mmio register data */
nkeynes@457
   170
    all_list = mmio_window_add_page( mmio, "All", NULL );
nkeynes@457
   171
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   172
        GtkCList *list = mmio_window_add_page( mmio, io_rgn[i]->id, io_rgn[i] );
nkeynes@457
   173
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@457
   174
            int sz = io_rgn[i]->ports[j].width;
nkeynes@457
   175
            char addr[10], data[10], bits[40];
nkeynes@457
   176
            char *arr[] = { addr, io_rgn[i]->ports[j].id, data, bits,
nkeynes@736
   177
                    io_rgn[i]->ports[j].desc };
nkeynes@457
   178
            sprintf( addr, "%08X",
nkeynes@457
   179
                     io_rgn[i]->base + io_rgn[i]->ports[j].offset );
nkeynes@457
   180
            printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@457
   181
            printbits( bits, io_rgn[i]->ports[j].width,
nkeynes@457
   182
                       *io_rgn[i]->ports[j].val );
nkeynes@457
   183
            gtk_clist_append( list, arr );
nkeynes@457
   184
            gtk_clist_append( all_list, arr );
nkeynes@457
   185
        }
nkeynes@457
   186
    }
nkeynes@736
   187
nkeynes@457
   188
    g_signal_connect ((gpointer) mmio->window, "delete_event",
nkeynes@736
   189
                      G_CALLBACK (on_mmio_delete_event),
nkeynes@736
   190
                      NULL);
nkeynes@457
   191
    g_signal_connect ((gpointer) mmr_close, "clicked",
nkeynes@736
   192
                      G_CALLBACK (on_mmio_close_clicked),
nkeynes@736
   193
                      mmio);
nkeynes@457
   194
nkeynes@457
   195
    gtk_widget_show_all( mmio->window );
nkeynes@457
   196
    return mmio;
nkeynes@457
   197
}
nkeynes@736
   198
nkeynes@457
   199
void mmio_window_update( mmio_window_t mmio )
nkeynes@2
   200
{
nkeynes@2
   201
    int i,j, count = 0;
nkeynes@2
   202
    GtkCList *page, *all_page;
nkeynes@2
   203
    char data[10], bits[40];
nkeynes@2
   204
nkeynes@457
   205
    all_page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window), "All" ));
nkeynes@736
   206
nkeynes@57
   207
    for( i=0; i < num_io_rgns; i++ ) {
nkeynes@457
   208
        page = GTK_CLIST(gtk_object_get_data( GTK_OBJECT(mmio->window),
nkeynes@736
   209
                io_rgn[i]->id ));
nkeynes@2
   210
        for( j=0; io_rgn[i]->ports[j].id != NULL; j++ ) {
nkeynes@2
   211
            if( *io_rgn[i]->ports[j].val !=
nkeynes@2
   212
                *(uint32_t *)(io_rgn[i]->save_mem+io_rgn[i]->ports[j].offset)){
nkeynes@2
   213
                int sz = io_rgn[i]->ports[j].width;
nkeynes@2
   214
                /* Changed */
nkeynes@2
   215
                printhex( data, sz, *io_rgn[i]->ports[j].val );
nkeynes@2
   216
                printbits( bits, sz, *io_rgn[i]->ports[j].val );
nkeynes@736
   217
nkeynes@2
   218
                gtk_clist_set_text( page, j, 2, data );
nkeynes@2
   219
                gtk_clist_set_text( page, j, 3, bits );
nkeynes@435
   220
                gtk_clist_set_foreground( page, j, &gui_colour_changed );
nkeynes@736
   221
nkeynes@2
   222
                gtk_clist_set_text( all_page, count, 2, data );
nkeynes@2
   223
                gtk_clist_set_text( all_page, count, 3, bits );
nkeynes@435
   224
                gtk_clist_set_foreground( all_page, count, &gui_colour_changed );
nkeynes@736
   225
nkeynes@2
   226
            } else {
nkeynes@435
   227
                gtk_clist_set_foreground( page, j, &gui_colour_normal );
nkeynes@435
   228
                gtk_clist_set_foreground( all_page, count, &gui_colour_normal );
nkeynes@2
   229
            }
nkeynes@2
   230
            count++;
nkeynes@2
   231
        }
nkeynes@796
   232
        memcpy( io_rgn[i]->save_mem, io_rgn[i]->mem, LXDREAM_PAGE_SIZE );
nkeynes@2
   233
    }
nkeynes@2
   234
}
nkeynes@2
   235
nkeynes@457
   236
void mmio_window_show( mmio_window_t mmio, gboolean show )
nkeynes@2
   237
{
nkeynes@457
   238
    if( show ) {
nkeynes@736
   239
        gtk_widget_show( mmio->window );
nkeynes@457
   240
    } else {
nkeynes@736
   241
        gtk_widget_hide( mmio->window );
nkeynes@2
   242
    }
nkeynes@2
   243
}
nkeynes@2
   244
.