Search
lxdream.org :: lxdream/src/cpu.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/cpu.c
changeset 1093:34faf227070e
prev1091:186558374345
author nkeynes
date Sun Dec 20 21:19:09 2009 +1000 (11 years ago)
permissions -rw-r--r--
last change Make sure there's a trailing new-line after the cpu registers are printed
file annotate diff log raw
nkeynes@1091
     1
/**
nkeynes@1091
     2
 * $Id$
nkeynes@1091
     3
 *
nkeynes@1091
     4
 * Generic CPU utility functions
nkeynes@1091
     5
 *
nkeynes@1091
     6
 * Copyright (c) 2009 Nathan Keynes.
nkeynes@1091
     7
 *
nkeynes@1091
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1091
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1091
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1091
    11
 * (at your option) any later version.
nkeynes@1091
    12
 *
nkeynes@1091
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1091
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1091
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1091
    16
 * GNU General Public License for more details.
nkeynes@1091
    17
 */
nkeynes@1091
    18
nkeynes@1091
    19
#include "cpu.h"
nkeynes@1091
    20
nkeynes@1091
    21
void cpu_print_registers( FILE *f, cpu_desc_t cpu )
nkeynes@1091
    22
{
nkeynes@1091
    23
    int i;
nkeynes@1091
    24
    int column = 0;
nkeynes@1091
    25
nkeynes@1091
    26
    fprintf( f, "%s registers:\n", cpu->name );
nkeynes@1091
    27
    for( i=0; cpu->regs_info[i].name != NULL; i++ ) {
nkeynes@1091
    28
        void *value = cpu->get_register(i);
nkeynes@1091
    29
        if( value != NULL ) {
nkeynes@1091
    30
            column++;
nkeynes@1091
    31
            switch( cpu->regs_info[i].type ) {
nkeynes@1091
    32
            case REG_TYPE_INT:
nkeynes@1091
    33
                fprintf( f,  "%5s: %08x   ", cpu->regs_info[i].name, *(uint32_t *)value );
nkeynes@1091
    34
                break;
nkeynes@1091
    35
            case REG_TYPE_FLOAT:
nkeynes@1091
    36
                fprintf( f, "%5s: %.8f ", cpu->regs_info[i].name, (double)*(float *)value );
nkeynes@1091
    37
                break;
nkeynes@1091
    38
            case REG_TYPE_DOUBLE:
nkeynes@1091
    39
                fprintf( f, "%5s: %.8f ", cpu->regs_info[i].name, *(double *)value );
nkeynes@1091
    40
                break;
nkeynes@1091
    41
            case REG_TYPE_NONE:
nkeynes@1091
    42
                column = 4;
nkeynes@1091
    43
            }
nkeynes@1091
    44
        }
nkeynes@1091
    45
        if( column == 4 ) {
nkeynes@1091
    46
            fprintf( f, "\n" );
nkeynes@1091
    47
            column = 0;
nkeynes@1091
    48
        }
nkeynes@1091
    49
    }
nkeynes@1093
    50
    if( column != 0 ) {
nkeynes@1093
    51
        fprintf( f, "\n" );
nkeynes@1093
    52
    }
nkeynes@1091
    53
}
.