make code pretty (and consistent)

This commit is contained in:
Gwenhael Le Moine 2024-10-22 19:36:41 +02:00
parent 8e05de8737
commit 25a78e1ccc
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
49 changed files with 11790 additions and 13236 deletions

View file

@ -5,12 +5,12 @@
#define _X49GP_BITMAP_FONT_H 1 #define _X49GP_BITMAP_FONT_H 1
typedef struct { typedef struct {
const char *name; const char* name;
int width; int width;
int kern; int kern;
int ascent; int ascent;
int descent; int descent;
const unsigned char *bits; const unsigned char* bits;
} bitmap_glyph_t; } bitmap_glyph_t;
typedef struct { typedef struct {
@ -19,18 +19,15 @@ typedef struct {
bitmap_glyph_t glyphs[]; bitmap_glyph_t glyphs[];
} bitmap_font_t; } bitmap_font_t;
#define GLYPH(font, name) \ #define GLYPH( font, name ) \
{ \ { #name, \
#name, \
font##_##name##_width - font##_##name##_x_hot, \ font##_##name##_width - font##_##name##_x_hot, \
-font##_##name##_x_hot, \ -font##_##name##_x_hot, \
font##_##name##_y_hot + 1, \ font##_##name##_y_hot + 1, \
font##_##name##_y_hot + 1 - font##_##name##_height, \ font##_##name##_y_hot + 1 - font##_##name##_height, \
font##_##name##_bits \ font##_##name##_bits }
}
#define SPACE(name, width, kern) \ #define SPACE( name, width, kern ) { name, width, kern, 0, 0, NULL }
{ name, width, kern, 0, 0, NULL }
extern const bitmap_font_t tiny_font; extern const bitmap_font_t tiny_font;

View file

@ -26,19 +26,19 @@
#include "block_int.h" #include "block_int.h"
#include <zlib.h> #include <zlib.h>
#if 0 #if 0
#include "aes.h" # include "aes.h"
#endif #endif
/**************************************************************/ /**************************************************************/
/* QEMU COW block driver with compression and encryption support */ /* QEMU COW block driver with compression and encryption support */
#define QCOW_MAGIC (('Q' << 24) | ('F' << 16) | ('I' << 8) | 0xfb) #define QCOW_MAGIC ( ( 'Q' << 24 ) | ( 'F' << 16 ) | ( 'I' << 8 ) | 0xfb )
#define QCOW_VERSION 1 #define QCOW_VERSION 1
#define QCOW_CRYPT_NONE 0 #define QCOW_CRYPT_NONE 0
#define QCOW_CRYPT_AES 1 #define QCOW_CRYPT_AES 1
#define QCOW_OFLAG_COMPRESSED (1LL << 63) #define QCOW_OFLAG_COMPRESSED ( 1LL << 63 )
typedef struct QCowHeader { typedef struct QCowHeader {
uint32_t magic; uint32_t magic;
@ -56,7 +56,7 @@ typedef struct QCowHeader {
#define L2_CACHE_SIZE 16 #define L2_CACHE_SIZE 16
typedef struct BDRVQcowState { typedef struct BDRVQcowState {
BlockDriverState *hd; BlockDriverState* hd;
int cluster_bits; int cluster_bits;
int cluster_size; int cluster_size;
int cluster_sectors; int cluster_sectors;
@ -65,106 +65,104 @@ typedef struct BDRVQcowState {
int l1_size; int l1_size;
uint64_t cluster_offset_mask; uint64_t cluster_offset_mask;
uint64_t l1_table_offset; uint64_t l1_table_offset;
uint64_t *l1_table; uint64_t* l1_table;
uint64_t *l2_cache; uint64_t* l2_cache;
uint64_t l2_cache_offsets[L2_CACHE_SIZE]; uint64_t l2_cache_offsets[ L2_CACHE_SIZE ];
uint32_t l2_cache_counts[L2_CACHE_SIZE]; uint32_t l2_cache_counts[ L2_CACHE_SIZE ];
uint8_t *cluster_cache; uint8_t* cluster_cache;
uint8_t *cluster_data; uint8_t* cluster_data;
uint64_t cluster_cache_offset; uint64_t cluster_cache_offset;
} BDRVQcowState; } BDRVQcowState;
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset); static int decompress_cluster( BDRVQcowState* s, uint64_t cluster_offset );
static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename) static int qcow_probe( const uint8_t* buf, int buf_size, const char* filename )
{ {
const QCowHeader *cow_header = (const void *)buf; const QCowHeader* cow_header = ( const void* )buf;
if (buf_size >= sizeof(QCowHeader) && if ( buf_size >= sizeof( QCowHeader ) && be32_to_cpu( cow_header->magic ) == QCOW_MAGIC &&
be32_to_cpu(cow_header->magic) == QCOW_MAGIC && be32_to_cpu( cow_header->version ) == QCOW_VERSION )
be32_to_cpu(cow_header->version) == QCOW_VERSION)
return 100; return 100;
else else
return 0; return 0;
} }
static int qcow_open(BlockDriverState *bs, const char *filename, int flags) static int qcow_open( BlockDriverState* bs, const char* filename, int flags )
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
int len, i, shift, ret; int len, i, shift, ret;
QCowHeader header; QCowHeader header;
ret = bdrv_file_open(&s->hd, filename, flags); ret = bdrv_file_open( &s->hd, filename, flags );
if (ret < 0) if ( ret < 0 )
return ret; return ret;
if (bdrv_pread(s->hd, 0, &header, sizeof(header)) != sizeof(header)) if ( bdrv_pread( s->hd, 0, &header, sizeof( header ) ) != sizeof( header ) )
goto fail; goto fail;
be32_to_cpus(&header.magic); be32_to_cpus( &header.magic );
be32_to_cpus(&header.version); be32_to_cpus( &header.version );
be64_to_cpus(&header.backing_file_offset); be64_to_cpus( &header.backing_file_offset );
be32_to_cpus(&header.backing_file_size); be32_to_cpus( &header.backing_file_size );
be32_to_cpus(&header.mtime); be32_to_cpus( &header.mtime );
be64_to_cpus(&header.size); be64_to_cpus( &header.size );
be32_to_cpus(&header.crypt_method); be32_to_cpus( &header.crypt_method );
be64_to_cpus(&header.l1_table_offset); be64_to_cpus( &header.l1_table_offset );
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION) if ( header.magic != QCOW_MAGIC || header.version != QCOW_VERSION )
goto fail; goto fail;
if (header.size <= 1 || header.cluster_bits < 9) if ( header.size <= 1 || header.cluster_bits < 9 )
goto fail; goto fail;
if (header.crypt_method > QCOW_CRYPT_AES) if ( header.crypt_method > QCOW_CRYPT_AES )
goto fail; goto fail;
s->cluster_bits = header.cluster_bits; s->cluster_bits = header.cluster_bits;
s->cluster_size = 1 << s->cluster_bits; s->cluster_size = 1 << s->cluster_bits;
s->cluster_sectors = 1 << (s->cluster_bits - 9); s->cluster_sectors = 1 << ( s->cluster_bits - 9 );
s->l2_bits = header.l2_bits; s->l2_bits = header.l2_bits;
s->l2_size = 1 << s->l2_bits; s->l2_size = 1 << s->l2_bits;
bs->total_sectors = header.size / 512; bs->total_sectors = header.size / 512;
s->cluster_offset_mask = (1LL << (63 - s->cluster_bits)) - 1; s->cluster_offset_mask = ( 1LL << ( 63 - s->cluster_bits ) ) - 1;
/* read the level 1 table */ /* read the level 1 table */
shift = s->cluster_bits + s->l2_bits; shift = s->cluster_bits + s->l2_bits;
s->l1_size = (header.size + (1LL << shift) - 1) >> shift; s->l1_size = ( header.size + ( 1LL << shift ) - 1 ) >> shift;
s->l1_table_offset = header.l1_table_offset; s->l1_table_offset = header.l1_table_offset;
s->l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); s->l1_table = qemu_malloc( s->l1_size * sizeof( uint64_t ) );
if (!s->l1_table) if ( !s->l1_table )
goto fail; goto fail;
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) != if ( bdrv_pread( s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof( uint64_t ) ) != s->l1_size * sizeof( uint64_t ) )
s->l1_size * sizeof(uint64_t))
goto fail; goto fail;
for(i = 0;i < s->l1_size; i++) { for ( i = 0; i < s->l1_size; i++ ) {
be64_to_cpus(&s->l1_table[i]); be64_to_cpus( &s->l1_table[ i ] );
} }
/* alloc L2 cache */ /* alloc L2 cache */
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); s->l2_cache = qemu_malloc( s->l2_size * L2_CACHE_SIZE * sizeof( uint64_t ) );
if (!s->l2_cache) if ( !s->l2_cache )
goto fail; goto fail;
s->cluster_cache = qemu_malloc(s->cluster_size); s->cluster_cache = qemu_malloc( s->cluster_size );
if (!s->cluster_cache) if ( !s->cluster_cache )
goto fail; goto fail;
s->cluster_data = qemu_malloc(s->cluster_size); s->cluster_data = qemu_malloc( s->cluster_size );
if (!s->cluster_data) if ( !s->cluster_data )
goto fail; goto fail;
s->cluster_cache_offset = -1; s->cluster_cache_offset = -1;
/* read the backing file name */ /* read the backing file name */
if (header.backing_file_offset != 0) { if ( header.backing_file_offset != 0 ) {
len = header.backing_file_size; len = header.backing_file_size;
if (len > 1023) if ( len > 1023 )
len = 1023; len = 1023;
if (bdrv_pread(s->hd, header.backing_file_offset, bs->backing_file, len) != len) if ( bdrv_pread( s->hd, header.backing_file_offset, bs->backing_file, len ) != len )
goto fail; goto fail;
bs->backing_file[len] = '\0'; bs->backing_file[ len ] = '\0';
} }
return 0; return 0;
fail: fail:
qemu_free(s->l1_table); qemu_free( s->l1_table );
qemu_free(s->l2_cache); qemu_free( s->l2_cache );
qemu_free(s->cluster_cache); qemu_free( s->cluster_cache );
qemu_free(s->cluster_data); qemu_free( s->cluster_data );
bdrv_delete(s->hd); bdrv_delete( s->hd );
return -1; return -1;
} }
@ -181,170 +179,153 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
* *
* return 0 if not allocated. * return 0 if not allocated.
*/ */
static uint64_t get_cluster_offset(BlockDriverState *bs, static uint64_t get_cluster_offset( BlockDriverState* bs, uint64_t offset, int allocate, int compressed_size, int n_start, int n_end )
uint64_t offset, int allocate,
int compressed_size,
int n_start, int n_end)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
int min_index, i, j, l1_index, l2_index; int min_index, i, j, l1_index, l2_index;
uint64_t l2_offset, *l2_table, cluster_offset, tmp; uint64_t l2_offset, *l2_table, cluster_offset, tmp;
uint32_t min_count; uint32_t min_count;
int new_l2_table; int new_l2_table;
l1_index = offset >> (s->l2_bits + s->cluster_bits); l1_index = offset >> ( s->l2_bits + s->cluster_bits );
l2_offset = s->l1_table[l1_index]; l2_offset = s->l1_table[ l1_index ];
new_l2_table = 0; new_l2_table = 0;
if (!l2_offset) { if ( !l2_offset ) {
if (!allocate) if ( !allocate )
return 0; return 0;
/* allocate a new l2 entry */ /* allocate a new l2 entry */
l2_offset = bdrv_getlength(s->hd); l2_offset = bdrv_getlength( s->hd );
/* round to cluster size */ /* round to cluster size */
l2_offset = (l2_offset + s->cluster_size - 1) & ~(s->cluster_size - 1); l2_offset = ( l2_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
/* update the L1 entry */ /* update the L1 entry */
s->l1_table[l1_index] = l2_offset; s->l1_table[ l1_index ] = l2_offset;
tmp = cpu_to_be64(l2_offset); tmp = cpu_to_be64( l2_offset );
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp), if ( bdrv_pwrite( s->hd, s->l1_table_offset + l1_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
&tmp, sizeof(tmp)) != sizeof(tmp))
return 0; return 0;
new_l2_table = 1; new_l2_table = 1;
} }
for(i = 0; i < L2_CACHE_SIZE; i++) { for ( i = 0; i < L2_CACHE_SIZE; i++ ) {
if (l2_offset == s->l2_cache_offsets[i]) { if ( l2_offset == s->l2_cache_offsets[ i ] ) {
/* increment the hit count */ /* increment the hit count */
if (++s->l2_cache_counts[i] == 0xffffffff) { if ( ++s->l2_cache_counts[ i ] == 0xffffffff ) {
for(j = 0; j < L2_CACHE_SIZE; j++) { for ( j = 0; j < L2_CACHE_SIZE; j++ ) {
s->l2_cache_counts[j] >>= 1; s->l2_cache_counts[ j ] >>= 1;
} }
} }
l2_table = s->l2_cache + (i << s->l2_bits); l2_table = s->l2_cache + ( i << s->l2_bits );
goto found; goto found;
} }
} }
/* not found: load a new entry in the least used one */ /* not found: load a new entry in the least used one */
min_index = 0; min_index = 0;
min_count = 0xffffffff; min_count = 0xffffffff;
for(i = 0; i < L2_CACHE_SIZE; i++) { for ( i = 0; i < L2_CACHE_SIZE; i++ ) {
if (s->l2_cache_counts[i] < min_count) { if ( s->l2_cache_counts[ i ] < min_count ) {
min_count = s->l2_cache_counts[i]; min_count = s->l2_cache_counts[ i ];
min_index = i; min_index = i;
} }
} }
l2_table = s->l2_cache + (min_index << s->l2_bits); l2_table = s->l2_cache + ( min_index << s->l2_bits );
if (new_l2_table) { if ( new_l2_table ) {
memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); memset( l2_table, 0, s->l2_size * sizeof( uint64_t ) );
if (bdrv_pwrite(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) != if ( bdrv_pwrite( s->hd, l2_offset, l2_table, s->l2_size * sizeof( uint64_t ) ) != s->l2_size * sizeof( uint64_t ) )
s->l2_size * sizeof(uint64_t))
return 0; return 0;
} else { } else {
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) != if ( bdrv_pread( s->hd, l2_offset, l2_table, s->l2_size * sizeof( uint64_t ) ) != s->l2_size * sizeof( uint64_t ) )
s->l2_size * sizeof(uint64_t))
return 0; return 0;
} }
s->l2_cache_offsets[min_index] = l2_offset; s->l2_cache_offsets[ min_index ] = l2_offset;
s->l2_cache_counts[min_index] = 1; s->l2_cache_counts[ min_index ] = 1;
found: found:
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1); l2_index = ( offset >> s->cluster_bits ) & ( s->l2_size - 1 );
cluster_offset = be64_to_cpu(l2_table[l2_index]); cluster_offset = be64_to_cpu( l2_table[ l2_index ] );
if (!cluster_offset || if ( !cluster_offset || ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && allocate == 1 ) ) {
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) { if ( !allocate )
if (!allocate)
return 0; return 0;
/* allocate a new cluster */ /* allocate a new cluster */
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) && if ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && ( n_end - n_start ) < s->cluster_sectors ) {
(n_end - n_start) < s->cluster_sectors) {
/* if the cluster is already compressed, we must /* if the cluster is already compressed, we must
decompress it in the case it is not completely decompress it in the case it is not completely
overwritten */ overwritten */
if (decompress_cluster(s, cluster_offset) < 0) if ( decompress_cluster( s, cluster_offset ) < 0 )
return 0; return 0;
cluster_offset = bdrv_getlength(s->hd); cluster_offset = bdrv_getlength( s->hd );
cluster_offset = (cluster_offset + s->cluster_size - 1) & cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
~(s->cluster_size - 1);
/* write the cluster content */ /* write the cluster content */
if (bdrv_pwrite(s->hd, cluster_offset, s->cluster_cache, s->cluster_size) != if ( bdrv_pwrite( s->hd, cluster_offset, s->cluster_cache, s->cluster_size ) != s->cluster_size )
s->cluster_size)
return -1; return -1;
} else { } else {
cluster_offset = bdrv_getlength(s->hd); cluster_offset = bdrv_getlength( s->hd );
if (allocate == 1) { if ( allocate == 1 ) {
/* round to cluster size */ /* round to cluster size */
cluster_offset = (cluster_offset + s->cluster_size - 1) & cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
~(s->cluster_size - 1); bdrv_truncate( s->hd, cluster_offset + s->cluster_size );
bdrv_truncate(s->hd, cluster_offset + s->cluster_size);
} else { } else {
cluster_offset |= QCOW_OFLAG_COMPRESSED | cluster_offset |= QCOW_OFLAG_COMPRESSED | ( uint64_t )compressed_size << ( 63 - s->cluster_bits );
(uint64_t)compressed_size << (63 - s->cluster_bits);
} }
} }
/* update L2 table */ /* update L2 table */
tmp = cpu_to_be64(cluster_offset); tmp = cpu_to_be64( cluster_offset );
l2_table[l2_index] = tmp; l2_table[ l2_index ] = tmp;
if (bdrv_pwrite(s->hd, if ( bdrv_pwrite( s->hd, l2_offset + l2_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
l2_offset + l2_index * sizeof(tmp), &tmp, sizeof(tmp)) != sizeof(tmp))
return 0; return 0;
} }
return cluster_offset; return cluster_offset;
} }
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num, static int qcow_is_allocated( BlockDriverState* bs, int64_t sector_num, int nb_sectors, int* pnum )
int nb_sectors, int *pnum)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
int index_in_cluster, n; int index_in_cluster, n;
uint64_t cluster_offset; uint64_t cluster_offset;
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); cluster_offset = get_cluster_offset( bs, sector_num << 9, 0, 0, 0, 0 );
index_in_cluster = sector_num & (s->cluster_sectors - 1); index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster; n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors) if ( n > nb_sectors )
n = nb_sectors; n = nb_sectors;
*pnum = n; *pnum = n;
return (cluster_offset != 0); return ( cluster_offset != 0 );
} }
static int decompress_buffer(uint8_t *out_buf, int out_buf_size, static int decompress_buffer( uint8_t* out_buf, int out_buf_size, const uint8_t* buf, int buf_size )
const uint8_t *buf, int buf_size)
{ {
z_stream strm1, *strm = &strm1; z_stream strm1, *strm = &strm1;
int ret, out_len; int ret, out_len;
memset(strm, 0, sizeof(*strm)); memset( strm, 0, sizeof( *strm ) );
strm->next_in = (uint8_t *)buf; strm->next_in = ( uint8_t* )buf;
strm->avail_in = buf_size; strm->avail_in = buf_size;
strm->next_out = out_buf; strm->next_out = out_buf;
strm->avail_out = out_buf_size; strm->avail_out = out_buf_size;
ret = inflateInit2(strm, -12); ret = inflateInit2( strm, -12 );
if (ret != Z_OK) if ( ret != Z_OK )
return -1; return -1;
ret = inflate(strm, Z_FINISH); ret = inflate( strm, Z_FINISH );
out_len = strm->next_out - out_buf; out_len = strm->next_out - out_buf;
if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) || if ( ( ret != Z_STREAM_END && ret != Z_BUF_ERROR ) || out_len != out_buf_size ) {
out_len != out_buf_size) { inflateEnd( strm );
inflateEnd(strm);
return -1; return -1;
} }
inflateEnd(strm); inflateEnd( strm );
return 0; return 0;
} }
static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset) static int decompress_cluster( BDRVQcowState* s, uint64_t cluster_offset )
{ {
int ret, csize; int ret, csize;
uint64_t coffset; uint64_t coffset;
coffset = cluster_offset & s->cluster_offset_mask; coffset = cluster_offset & s->cluster_offset_mask;
if (s->cluster_cache_offset != coffset) { if ( s->cluster_cache_offset != coffset ) {
csize = cluster_offset >> (63 - s->cluster_bits); csize = cluster_offset >> ( 63 - s->cluster_bits );
csize &= (s->cluster_size - 1); csize &= ( s->cluster_size - 1 );
ret = bdrv_pread(s->hd, coffset, s->cluster_data, csize); ret = bdrv_pread( s->hd, coffset, s->cluster_data, csize );
if (ret != csize) if ( ret != csize )
return -1; return -1;
if (decompress_buffer(s->cluster_cache, s->cluster_size, if ( decompress_buffer( s->cluster_cache, s->cluster_size, s->cluster_data, csize ) < 0 ) {
s->cluster_data, csize) < 0) {
return -1; return -1;
} }
s->cluster_cache_offset = coffset; s->cluster_cache_offset = coffset;
@ -352,35 +333,34 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
return 0; return 0;
} }
static int qcow_read(BlockDriverState *bs, int64_t sector_num, static int qcow_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors )
uint8_t *buf, int nb_sectors)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
int ret, index_in_cluster, n; int ret, index_in_cluster, n;
uint64_t cluster_offset; uint64_t cluster_offset;
while (nb_sectors > 0) { while ( nb_sectors > 0 ) {
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); cluster_offset = get_cluster_offset( bs, sector_num << 9, 0, 0, 0, 0 );
index_in_cluster = sector_num & (s->cluster_sectors - 1); index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster; n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors) if ( n > nb_sectors )
n = nb_sectors; n = nb_sectors;
if (!cluster_offset) { if ( !cluster_offset ) {
if (bs->backing_hd) { if ( bs->backing_hd ) {
/* read from the base image */ /* read from the base image */
ret = bdrv_read(bs->backing_hd, sector_num, buf, n); ret = bdrv_read( bs->backing_hd, sector_num, buf, n );
if (ret < 0) if ( ret < 0 )
return -1; return -1;
} else { } else {
memset(buf, 0, 512 * n); memset( buf, 0, 512 * n );
} }
} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) { } else if ( cluster_offset & QCOW_OFLAG_COMPRESSED ) {
if (decompress_cluster(s, cluster_offset) < 0) if ( decompress_cluster( s, cluster_offset ) < 0 )
return -1; return -1;
memcpy(buf, s->cluster_cache + index_in_cluster * 512, 512 * n); memcpy( buf, s->cluster_cache + index_in_cluster * 512, 512 * n );
} else { } else {
ret = bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512); ret = bdrv_pread( s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512 );
if (ret != n * 512) if ( ret != n * 512 )
return -1; return -1;
} }
nb_sectors -= n; nb_sectors -= n;
@ -390,27 +370,24 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
return 0; return 0;
} }
static int qcow_write(BlockDriverState *bs, int64_t sector_num, static int qcow_write( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
const uint8_t *buf, int nb_sectors)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
int ret, index_in_cluster, n; int ret, index_in_cluster, n;
uint64_t cluster_offset; uint64_t cluster_offset;
while (nb_sectors > 0) { while ( nb_sectors > 0 ) {
index_in_cluster = sector_num & (s->cluster_sectors - 1); index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster; n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors) if ( n > nb_sectors )
n = nb_sectors; n = nb_sectors;
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0, cluster_offset = get_cluster_offset( bs, sector_num << 9, 1, 0, index_in_cluster, index_in_cluster + n );
index_in_cluster, if ( !cluster_offset )
index_in_cluster + n);
if (!cluster_offset)
return -1; return -1;
{ {
ret = bdrv_pwrite(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512); ret = bdrv_pwrite( s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512 );
} }
if (ret != n * 512) if ( ret != n * 512 )
return -1; return -1;
nb_sectors -= n; nb_sectors -= n;
sector_num += n; sector_num += n;
@ -420,39 +397,38 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num,
return 0; return 0;
} }
static void qcow_close(BlockDriverState *bs) static void qcow_close( BlockDriverState* bs )
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
qemu_free(s->l1_table); qemu_free( s->l1_table );
qemu_free(s->l2_cache); qemu_free( s->l2_cache );
qemu_free(s->cluster_cache); qemu_free( s->cluster_cache );
qemu_free(s->cluster_data); qemu_free( s->cluster_data );
bdrv_delete(s->hd); bdrv_delete( s->hd );
} }
static int qcow_create(const char *filename, int64_t total_size, static int qcow_create( const char* filename, int64_t total_size, const char* backing_file, int flags )
const char *backing_file, int flags)
{ {
int fd, header_size, backing_filename_len, l1_size, i, shift; int fd, header_size, backing_filename_len, l1_size, i, shift;
QCowHeader header; QCowHeader header;
uint64_t tmp; uint64_t tmp;
int ret; int ret;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644 );
if (fd < 0) if ( fd < 0 )
return -1; return -1;
memset(&header, 0, sizeof(header)); memset( &header, 0, sizeof( header ) );
header.magic = cpu_to_be32(QCOW_MAGIC); header.magic = cpu_to_be32( QCOW_MAGIC );
header.version = cpu_to_be32(QCOW_VERSION); header.version = cpu_to_be32( QCOW_VERSION );
header.size = cpu_to_be64(total_size * 512); header.size = cpu_to_be64( total_size * 512 );
header_size = sizeof(header); header_size = sizeof( header );
backing_filename_len = 0; backing_filename_len = 0;
if (backing_file) { if ( backing_file ) {
header.backing_file_offset = cpu_to_be64(header_size); header.backing_file_offset = cpu_to_be64( header_size );
backing_filename_len = strlen(backing_file); backing_filename_len = strlen( backing_file );
header.backing_file_size = cpu_to_be32(backing_filename_len); header.backing_file_size = cpu_to_be32( backing_filename_len );
header_size += backing_filename_len; header_size += backing_filename_len;
header.mtime = cpu_to_be32(0); header.mtime = cpu_to_be32( 0 );
header.cluster_bits = 9; /* 512 byte cluster to avoid copying header.cluster_bits = 9; /* 512 byte cluster to avoid copying
unmodifyed sectors */ unmodifyed sectors */
header.l2_bits = 12; /* 32 KB L2 tables */ header.l2_bits = 12; /* 32 KB L2 tables */
@ -460,36 +436,36 @@ static int qcow_create(const char *filename, int64_t total_size,
header.cluster_bits = 12; /* 4 KB clusters */ header.cluster_bits = 12; /* 4 KB clusters */
header.l2_bits = 9; /* 4 KB L2 tables */ header.l2_bits = 9; /* 4 KB L2 tables */
} }
header_size = (header_size + 7) & ~7; header_size = ( header_size + 7 ) & ~7;
shift = header.cluster_bits + header.l2_bits; shift = header.cluster_bits + header.l2_bits;
l1_size = ((total_size * 512) + (1LL << shift) - 1) >> shift; l1_size = ( ( total_size * 512 ) + ( 1LL << shift ) - 1 ) >> shift;
header.l1_table_offset = cpu_to_be64(header_size); header.l1_table_offset = cpu_to_be64( header_size );
if (flags) { if ( flags ) {
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES); header.crypt_method = cpu_to_be32( QCOW_CRYPT_AES );
} else { } else {
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE); header.crypt_method = cpu_to_be32( QCOW_CRYPT_NONE );
} }
/* write all the data */ /* write all the data */
ret = write(fd, &header, sizeof(header)); ret = write( fd, &header, sizeof( header ) );
if (ret != sizeof(header)) { if ( ret != sizeof( header ) ) {
ret = -1; ret = -1;
goto exit; goto exit;
} }
if (backing_file) { if ( backing_file ) {
ret = write(fd, backing_file, backing_filename_len); ret = write( fd, backing_file, backing_filename_len );
if (ret != backing_filename_len) { if ( ret != backing_filename_len ) {
ret = -1; ret = -1;
goto exit; goto exit;
} }
} }
lseek(fd, header_size, SEEK_SET); lseek( fd, header_size, SEEK_SET );
tmp = 0; tmp = 0;
for(i = 0;i < l1_size; i++) { for ( i = 0; i < l1_size; i++ ) {
ret = write(fd, &tmp, sizeof(tmp)); ret = write( fd, &tmp, sizeof( tmp ) );
if (ret != sizeof(tmp)) { if ( ret != sizeof( tmp ) ) {
ret = -1; ret = -1;
goto exit; goto exit;
} }
@ -497,106 +473,102 @@ static int qcow_create(const char *filename, int64_t total_size,
ret = 0; ret = 0;
exit: exit:
close(fd); close( fd );
return ret; return ret;
} }
static int qcow_make_empty(BlockDriverState *bs) static int qcow_make_empty( BlockDriverState* bs )
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
uint32_t l1_length = s->l1_size * sizeof(uint64_t); uint32_t l1_length = s->l1_size * sizeof( uint64_t );
int ret; int ret;
memset(s->l1_table, 0, l1_length); memset( s->l1_table, 0, l1_length );
if (bdrv_pwrite(s->hd, s->l1_table_offset, s->l1_table, l1_length) < 0) if ( bdrv_pwrite( s->hd, s->l1_table_offset, s->l1_table, l1_length ) < 0 )
return -1; return -1;
ret = bdrv_truncate(s->hd, s->l1_table_offset + l1_length); ret = bdrv_truncate( s->hd, s->l1_table_offset + l1_length );
if (ret < 0) if ( ret < 0 )
return ret; return ret;
memset(s->l2_cache, 0, s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t)); memset( s->l2_cache, 0, s->l2_size * L2_CACHE_SIZE * sizeof( uint64_t ) );
memset(s->l2_cache_offsets, 0, L2_CACHE_SIZE * sizeof(uint64_t)); memset( s->l2_cache_offsets, 0, L2_CACHE_SIZE * sizeof( uint64_t ) );
memset(s->l2_cache_counts, 0, L2_CACHE_SIZE * sizeof(uint32_t)); memset( s->l2_cache_counts, 0, L2_CACHE_SIZE * sizeof( uint32_t ) );
return 0; return 0;
} }
/* XXX: put compressed sectors first, then all the cluster aligned /* XXX: put compressed sectors first, then all the cluster aligned
tables to avoid losing bytes in alignment */ tables to avoid losing bytes in alignment */
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num, static int qcow_write_compressed( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
const uint8_t *buf, int nb_sectors)
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
z_stream strm; z_stream strm;
int ret, out_len; int ret, out_len;
uint8_t *out_buf; uint8_t* out_buf;
uint64_t cluster_offset; uint64_t cluster_offset;
if (nb_sectors != s->cluster_sectors) if ( nb_sectors != s->cluster_sectors )
return -EINVAL; return -EINVAL;
out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128); out_buf = qemu_malloc( s->cluster_size + ( s->cluster_size / 1000 ) + 128 );
if (!out_buf) if ( !out_buf )
return -1; return -1;
/* best compression, small window, no zlib header */ /* best compression, small window, no zlib header */
memset(&strm, 0, sizeof(strm)); memset( &strm, 0, sizeof( strm ) );
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION, ret = deflateInit2( &strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY );
Z_DEFLATED, -12, if ( ret != 0 ) {
9, Z_DEFAULT_STRATEGY); qemu_free( out_buf );
if (ret != 0) {
qemu_free(out_buf);
return -1; return -1;
} }
strm.avail_in = s->cluster_size; strm.avail_in = s->cluster_size;
strm.next_in = (uint8_t *)buf; strm.next_in = ( uint8_t* )buf;
strm.avail_out = s->cluster_size; strm.avail_out = s->cluster_size;
strm.next_out = out_buf; strm.next_out = out_buf;
ret = deflate(&strm, Z_FINISH); ret = deflate( &strm, Z_FINISH );
if (ret != Z_STREAM_END && ret != Z_OK) { if ( ret != Z_STREAM_END && ret != Z_OK ) {
qemu_free(out_buf); qemu_free( out_buf );
deflateEnd(&strm); deflateEnd( &strm );
return -1; return -1;
} }
out_len = strm.next_out - out_buf; out_len = strm.next_out - out_buf;
deflateEnd(&strm); deflateEnd( &strm );
if (ret != Z_STREAM_END || out_len >= s->cluster_size) { if ( ret != Z_STREAM_END || out_len >= s->cluster_size ) {
/* could not compress: write normal cluster */ /* could not compress: write normal cluster */
qcow_write(bs, sector_num, buf, s->cluster_sectors); qcow_write( bs, sector_num, buf, s->cluster_sectors );
} else { } else {
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2, cluster_offset = get_cluster_offset( bs, sector_num << 9, 2, out_len, 0, 0 );
out_len, 0, 0);
cluster_offset &= s->cluster_offset_mask; cluster_offset &= s->cluster_offset_mask;
if (bdrv_pwrite(s->hd, cluster_offset, out_buf, out_len) != out_len) { if ( bdrv_pwrite( s->hd, cluster_offset, out_buf, out_len ) != out_len ) {
qemu_free(out_buf); qemu_free( out_buf );
return -1; return -1;
} }
} }
qemu_free(out_buf); qemu_free( out_buf );
return 0; return 0;
} }
static void qcow_flush(BlockDriverState *bs) static void qcow_flush( BlockDriverState* bs )
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
bdrv_flush(s->hd); bdrv_flush( s->hd );
} }
static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) static int qcow_get_info( BlockDriverState* bs, BlockDriverInfo* bdi )
{ {
BDRVQcowState *s = bs->opaque; BDRVQcowState* s = bs->opaque;
bdi->cluster_size = s->cluster_size; bdi->cluster_size = s->cluster_size;
return 0; return 0;
} }
BlockDriver bdrv_qcow = { BlockDriver bdrv_qcow = {
"qcow", "qcow",
sizeof(BDRVQcowState), sizeof( BDRVQcowState ),
qcow_probe, qcow_probe,
qcow_open, qcow_open,
qcow_read, qcow_read,

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -13,195 +13,180 @@
#include "block_int.h" #include "block_int.h"
#define SECTOR_BITS 9 #define SECTOR_BITS 9
#define SECTOR_SIZE (1 << SECTOR_BITS) #define SECTOR_SIZE ( 1 << SECTOR_BITS )
static BlockDriverState *bdrv_first; static BlockDriverState* bdrv_first;
static BlockDriver *first_drv; static BlockDriver* first_drv;
#ifndef ENOMEDIUM #ifndef ENOMEDIUM
#define ENOMEDIUM ENODEV # define ENOMEDIUM ENODEV
#endif #endif
static void bdrv_close(BlockDriverState *bs); static void bdrv_close( BlockDriverState* bs );
static int static int path_is_absolute( const char* path )
path_is_absolute(const char *path)
{ {
const char *p; const char* p;
#ifdef _WIN32 #ifdef _WIN32
/* specific case for names like: "\\.\d:" */ /* specific case for names like: "\\.\d:" */
if (*path == '/' || *path == '\\') if ( *path == '/' || *path == '\\' )
return 1; return 1;
#endif #endif
p = strchr(path, ':'); p = strchr( path, ':' );
if (p) if ( p )
p++; p++;
else else
p = path; p = path;
#ifdef _WIN32 #ifdef _WIN32
return (*p == '/' || *p == '\\'); return ( *p == '/' || *p == '\\' );
#else #else
return (*p == '/'); return ( *p == '/' );
#endif #endif
} }
/* if filename is absolute, just copy it to dest. Otherwise, build a /* if filename is absolute, just copy it to dest. Otherwise, build a
path to it by considering it is relative to base_path. URL are path to it by considering it is relative to base_path. URL are
supported. */ supported. */
static void static void path_combine( char* dest, int dest_size, const char* base_path, const char* filename )
path_combine(char *dest, int dest_size,
const char *base_path,
const char *filename)
{ {
const char *p, *p1; const char *p, *p1;
int len; int len;
if (dest_size <= 0) if ( dest_size <= 0 )
return; return;
if (path_is_absolute(filename)) { if ( path_is_absolute( filename ) ) {
pstrcpy(dest, dest_size, filename); pstrcpy( dest, dest_size, filename );
} else { } else {
p = strchr(base_path, ':'); p = strchr( base_path, ':' );
if (p) if ( p )
p++; p++;
else else
p = base_path; p = base_path;
p1 = strrchr(base_path, '/'); p1 = strrchr( base_path, '/' );
#ifdef _WIN32 #ifdef _WIN32
{ {
const char *p2; const char* p2;
p2 = strrchr(base_path, '\\'); p2 = strrchr( base_path, '\\' );
if (!p1 || p2 > p1) if ( !p1 || p2 > p1 )
p1 = p2; p1 = p2;
} }
#endif #endif
if (p1) if ( p1 )
p1++; p1++;
else else
p1 = base_path; p1 = base_path;
if (p1 > p) if ( p1 > p )
p = p1; p = p1;
len = p - base_path; len = p - base_path;
if (len > dest_size - 1) if ( len > dest_size - 1 )
len = dest_size - 1; len = dest_size - 1;
memcpy(dest, base_path, len); memcpy( dest, base_path, len );
dest[len] = '\0'; dest[ len ] = '\0';
pstrcat(dest, dest_size, filename); pstrcat( dest, dest_size, filename );
} }
} }
#ifdef _WIN32 #ifdef _WIN32
void get_tmp_filename(char *filename, int size) void get_tmp_filename( char* filename, int size )
{ {
char temp_dir[MAX_PATH]; char temp_dir[ MAX_PATH ];
GetTempPath(MAX_PATH, temp_dir); GetTempPath( MAX_PATH, temp_dir );
GetTempFileName(temp_dir, "x49", 0, filename); GetTempFileName( temp_dir, "x49", 0, filename );
} }
#else #else
void get_tmp_filename(char *filename, int size) void get_tmp_filename( char* filename, int size )
{ {
int fd; int fd;
/* XXX: race condition possible */ /* XXX: race condition possible */
pstrcpy(filename, size, "/tmp/x49gp.XXXXXX"); pstrcpy( filename, size, "/tmp/x49gp.XXXXXX" );
fd = mkstemp(filename); fd = mkstemp( filename );
close(fd); close( fd );
} }
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
static int is_windows_drive_prefix(const char *filename) static int is_windows_drive_prefix( const char* filename )
{ {
return (((filename[0] >= 'a' && filename[0] <= 'z') || return ( ( ( filename[ 0 ] >= 'a' && filename[ 0 ] <= 'z' ) || ( filename[ 0 ] >= 'A' && filename[ 0 ] <= 'Z' ) ) &&
(filename[0] >= 'A' && filename[0] <= 'Z')) && filename[ 1 ] == ':' );
filename[1] == ':');
} }
static int is_windows_drive(const char *filename) static int is_windows_drive( const char* filename )
{ {
if (is_windows_drive_prefix(filename) && if ( is_windows_drive_prefix( filename ) && filename[ 2 ] == '\0' )
filename[2] == '\0')
return 1; return 1;
if (strstart(filename, "\\\\.\\", NULL) || if ( strstart( filename, "\\\\.\\", NULL ) || strstart( filename, "//./", NULL ) )
strstart(filename, "//./", NULL))
return 1; return 1;
return 0; return 0;
} }
#endif #endif
static BlockDriver * static BlockDriver* find_protocol( const char* filename )
find_protocol(const char *filename)
{ {
BlockDriver *drv1; BlockDriver* drv1;
char protocol[128]; char protocol[ 128 ];
int len; int len;
const char *p; const char* p;
#ifdef _WIN32 #ifdef _WIN32
if (is_windows_drive(filename) || if ( is_windows_drive( filename ) || is_windows_drive_prefix( filename ) )
is_windows_drive_prefix(filename))
return &bdrv_raw; return &bdrv_raw;
#endif #endif
p = strchr(filename, ':'); p = strchr( filename, ':' );
if (!p) if ( !p )
return &bdrv_raw; return &bdrv_raw;
len = p - filename; len = p - filename;
if (len > sizeof(protocol) - 1) if ( len > sizeof( protocol ) - 1 )
len = sizeof(protocol) - 1; len = sizeof( protocol ) - 1;
memcpy(protocol, filename, len); memcpy( protocol, filename, len );
protocol[len] = '\0'; protocol[ len ] = '\0';
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) { for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, fprintf( stderr, "%s:%u: protocol '%s', drv->protocol_name '%s'\n", __FUNCTION__, __LINE__, protocol, drv1->protocol_name );
"%s:%u: protocol '%s', drv->protocol_name '%s'\n",
__FUNCTION__, __LINE__, protocol, drv1->protocol_name);
#endif #endif
if (drv1->protocol_name && if ( drv1->protocol_name && !strcmp( drv1->protocol_name, protocol ) ) {
!strcmp(drv1->protocol_name, protocol)) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: protocol '%s', drv %p\n", fprintf( stderr, "%s:%u: protocol '%s', drv %p\n", __FUNCTION__, __LINE__, protocol, drv1 );
__FUNCTION__, __LINE__, protocol, drv1);
#endif #endif
return drv1; return drv1;
} }
} }
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: protocol '%s', NULL\n", fprintf( stderr, "%s:%u: protocol '%s', NULL\n", __FUNCTION__, __LINE__, protocol );
__FUNCTION__, __LINE__, protocol);
#endif #endif
return NULL; return NULL;
} }
/* XXX: force raw format if block or character device ? It would /* XXX: force raw format if block or character device ? It would
simplify the BSD case */ simplify the BSD case */
static BlockDriver * static BlockDriver* find_image_format( const char* filename )
find_image_format(const char *filename)
{ {
int ret, score, score_max; int ret, score, score_max;
BlockDriver *drv1, *drv; BlockDriver *drv1, *drv;
uint8_t buf[2048]; uint8_t buf[ 2048 ];
BlockDriverState *bs; BlockDriverState* bs;
drv = find_protocol(filename); drv = find_protocol( filename );
/* no need to test disk image formats for vvfat */ /* no need to test disk image formats for vvfat */
if (drv == &bdrv_vvfat) if ( drv == &bdrv_vvfat )
return drv; return drv;
ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY); ret = bdrv_file_open( &bs, filename, BDRV_O_RDONLY );
if (ret < 0) if ( ret < 0 )
return NULL; return NULL;
ret = bdrv_pread(bs, 0, buf, sizeof(buf)); ret = bdrv_pread( bs, 0, buf, sizeof( buf ) );
bdrv_delete(bs); bdrv_delete( bs );
if (ret < 0) { if ( ret < 0 ) {
return NULL; return NULL;
} }
score_max = 0; score_max = 0;
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) { for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
if (drv1->bdrv_probe) { if ( drv1->bdrv_probe ) {
score = drv1->bdrv_probe(buf, ret, filename); score = drv1->bdrv_probe( buf, ret, filename );
if (score > score_max) { if ( score > score_max ) {
score_max = score; score_max = score;
drv = drv1; drv = drv1;
} }
@ -210,38 +195,33 @@ find_image_format(const char *filename)
return drv; return drv;
} }
int int bdrv_create( BlockDriver* drv, const char* filename, int64_t size_in_sectors, const char* backing_file, int flags )
bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags)
{ {
if (!drv->bdrv_create) if ( !drv->bdrv_create )
return -ENOTSUP; return -ENOTSUP;
return drv->bdrv_create(filename, size_in_sectors, backing_file, flags); return drv->bdrv_create( filename, size_in_sectors, backing_file, flags );
} }
static void static void bdrv_register( BlockDriver* bdrv )
bdrv_register(BlockDriver *bdrv)
{ {
bdrv->next = first_drv; bdrv->next = first_drv;
first_drv = bdrv; first_drv = bdrv;
} }
/* create a new block device (by default it is empty) */ /* create a new block device (by default it is empty) */
BlockDriverState * BlockDriverState* bdrv_new( const char* device_name )
bdrv_new(const char *device_name)
{ {
BlockDriverState **pbs, *bs; BlockDriverState **pbs, *bs;
bs = qemu_mallocz(sizeof(BlockDriverState)); bs = qemu_mallocz( sizeof( BlockDriverState ) );
if(!bs) if ( !bs )
return NULL; return NULL;
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); pstrcpy( bs->device_name, sizeof( bs->device_name ), device_name );
if (device_name[0] != '\0') { if ( device_name[ 0 ] != '\0' ) {
/* insert at the end */ /* insert at the end */
pbs = &bdrv_first; pbs = &bdrv_first;
while (*pbs != NULL) while ( *pbs != NULL )
pbs = &(*pbs)->next; pbs = &( *pbs )->next;
*pbs = bs; *pbs = bs;
} }
return bs; return bs;
@ -250,95 +230,86 @@ bdrv_new(const char *device_name)
/** /**
* Truncate file to 'offset' bytes (needed only for file protocols) * Truncate file to 'offset' bytes (needed only for file protocols)
*/ */
int int bdrv_truncate( BlockDriverState* bs, int64_t offset )
bdrv_truncate(BlockDriverState *bs, int64_t offset)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!drv) if ( !drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (!drv->bdrv_truncate) if ( !drv->bdrv_truncate )
return -ENOTSUP; return -ENOTSUP;
return drv->bdrv_truncate(bs, offset); return drv->bdrv_truncate( bs, offset );
} }
/** /**
* Length of a file in bytes. Return < 0 if error or unknown. * Length of a file in bytes. Return < 0 if error or unknown.
*/ */
int64_t int64_t bdrv_getlength( BlockDriverState* bs )
bdrv_getlength(BlockDriverState *bs)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!drv) if ( !drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (!drv->bdrv_getlength) { if ( !drv->bdrv_getlength ) {
/* legacy mode */ /* legacy mode */
return bs->total_sectors * SECTOR_SIZE; return bs->total_sectors * SECTOR_SIZE;
} }
return drv->bdrv_getlength(bs); return drv->bdrv_getlength( bs );
} }
int int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags )
bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
{ {
BlockDriverState *bs; BlockDriverState* bs;
int ret; int ret;
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: filename '%s'\n", fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
__FUNCTION__, __LINE__, filename);
#endif #endif
bs = bdrv_new(""); bs = bdrv_new( "" );
if (!bs) if ( !bs )
return -ENOMEM; return -ENOMEM;
ret = bdrv_open(bs, filename, flags | BDRV_O_FILE); ret = bdrv_open( bs, filename, flags | BDRV_O_FILE );
if (ret < 0) { if ( ret < 0 ) {
bdrv_delete(bs); bdrv_delete( bs );
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: '%s': %d\n", fprintf( stderr, "%s:%u: '%s': %d\n", __FUNCTION__, __LINE__, filename, ret );
__FUNCTION__, __LINE__, filename, ret);
#endif #endif
return ret; return ret;
} }
*pbs = bs; *pbs = bs;
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__); fprintf( stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__ );
#endif #endif
return 0; return 0;
} }
int int bdrv_open( BlockDriverState* bs, const char* filename, int flags )
bdrv_open(BlockDriverState *bs, const char *filename, int flags)
{ {
int ret, open_flags; int ret, open_flags;
char backing_filename[1024]; char backing_filename[ 1024 ];
BlockDriver *drv = NULL; BlockDriver* drv = NULL;
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: filename '%s'\n", fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
__FUNCTION__, __LINE__, filename);
#endif #endif
bs->read_only = 0; bs->read_only = 0;
bs->is_temporary = 0; bs->is_temporary = 0;
bs->encrypted = 0; bs->encrypted = 0;
pstrcpy(bs->filename, sizeof(bs->filename), filename); pstrcpy( bs->filename, sizeof( bs->filename ), filename );
if (flags & BDRV_O_FILE) { if ( flags & BDRV_O_FILE ) {
drv = find_protocol(filename); drv = find_protocol( filename );
if (!drv) { if ( !drv ) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
f printf(stderr, "%s:%u: drv: %p\n", f printf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
__FUNCTION__, __LINE__, drv);
#endif #endif
return -ENOENT; return -ENOENT;
} }
} else { } else {
if (!drv) { if ( !drv ) {
drv = find_image_format(filename); drv = find_image_format( filename );
if (!drv) { if ( !drv ) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: drv: %p\n", fprintf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
__FUNCTION__, __LINE__, drv);
#endif #endif
return -1; return -1;
} }
@ -346,75 +317,68 @@ f printf(stderr, "%s:%u: drv: %p\n",
} }
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv); fprintf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
#endif #endif
bs->drv = drv; bs->drv = drv;
bs->opaque = qemu_mallocz(drv->instance_size); bs->opaque = qemu_mallocz( drv->instance_size );
if (bs->opaque == NULL && drv->instance_size > 0) { if ( bs->opaque == NULL && drv->instance_size > 0 ) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: no opaque\n", __FUNCTION__, __LINE__); fprintf( stderr, "%s:%u: no opaque\n", __FUNCTION__, __LINE__ );
#endif #endif
return -1; return -1;
} }
/* Note: for compatibility, we open disk image files as RDWR, and /* Note: for compatibility, we open disk image files as RDWR, and
RDONLY as fallback */ RDONLY as fallback */
if (!(flags & BDRV_O_FILE)) if ( !( flags & BDRV_O_FILE ) )
open_flags = BDRV_O_RDWR; open_flags = BDRV_O_RDWR;
else else
open_flags = flags & ~(BDRV_O_FILE); open_flags = flags & ~( BDRV_O_FILE );
ret = drv->bdrv_open(bs, filename, open_flags); ret = drv->bdrv_open( bs, filename, open_flags );
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: drv->bdrv_open: %d\n", fprintf( stderr, "%s:%u: drv->bdrv_open: %d\n", __FUNCTION__, __LINE__, ret );
__FUNCTION__, __LINE__, ret);
#endif #endif
if (ret == -EACCES && !(flags & BDRV_O_FILE)) { if ( ret == -EACCES && !( flags & BDRV_O_FILE ) ) {
ret = drv->bdrv_open(bs, filename, BDRV_O_RDONLY); ret = drv->bdrv_open( bs, filename, BDRV_O_RDONLY );
bs->read_only = 1; bs->read_only = 1;
} }
if (ret < 0) { if ( ret < 0 ) {
qemu_free(bs->opaque); qemu_free( bs->opaque );
bs->opaque = NULL; bs->opaque = NULL;
bs->drv = NULL; bs->drv = NULL;
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return %d\n", fprintf( stderr, "%s:%u: return %d\n", __FUNCTION__, __LINE__, ret );
__FUNCTION__, __LINE__, ret);
#endif #endif
return ret; return ret;
} }
if (drv->bdrv_getlength) { if ( drv->bdrv_getlength ) {
bs->total_sectors = bdrv_getlength(bs) >> SECTOR_BITS; bs->total_sectors = bdrv_getlength( bs ) >> SECTOR_BITS;
} }
#ifndef _WIN32 #ifndef _WIN32
if (bs->is_temporary) { if ( bs->is_temporary ) {
unlink(filename); unlink( filename );
} }
#endif #endif
if (bs->backing_file[0] != '\0') { if ( bs->backing_file[ 0 ] != '\0' ) {
/* if there is a backing file, use it */ /* if there is a backing file, use it */
bs->backing_hd = bdrv_new(""); bs->backing_hd = bdrv_new( "" );
if (!bs->backing_hd) { if ( !bs->backing_hd ) {
fail: fail:
bdrv_close(bs); bdrv_close( bs );
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return -ENOMEM\n", fprintf( stderr, "%s:%u: return -ENOMEM\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
#endif #endif
return -ENOMEM; return -ENOMEM;
} }
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: combine '%s' '%s'\n", fprintf( stderr, "%s:%u: combine '%s' '%s'\n", __FUNCTION__, __LINE__, filename, bs->backing_file );
__FUNCTION__, __LINE__, filename, bs->backing_file);
#endif #endif
path_combine(backing_filename, sizeof(backing_filename), path_combine( backing_filename, sizeof( backing_filename ), filename, bs->backing_file );
filename, bs->backing_file);
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: combine: '%s'\n", fprintf( stderr, "%s:%u: combine: '%s'\n", __FUNCTION__, __LINE__, backing_filename );
__FUNCTION__, __LINE__, backing_filename);
#endif #endif
if (bdrv_open(bs->backing_hd, backing_filename, 0) < 0) { if ( bdrv_open( bs->backing_hd, backing_filename, 0 ) < 0 ) {
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: backing fail\n", fprintf( stderr, "%s:%u: backing fail\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
#endif #endif
goto fail; goto fail;
} }
@ -422,81 +386,77 @@ f printf(stderr, "%s:%u: drv: %p\n",
/* call the change callback */ /* call the change callback */
bs->media_changed = 1; bs->media_changed = 1;
if (bs->change_cb) if ( bs->change_cb )
bs->change_cb(bs->change_opaque); bs->change_cb( bs->change_opaque );
#ifdef DEBUG_X49GP_BLOCK #ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__); fprintf( stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__ );
#endif #endif
return 0; return 0;
} }
static void static void bdrv_close( BlockDriverState* bs )
bdrv_close(BlockDriverState *bs)
{ {
if (NULL == bs->drv) if ( NULL == bs->drv )
return; return;
/* call the change callback */ /* call the change callback */
bs->media_changed = 1; bs->media_changed = 1;
if (bs->change_cb) if ( bs->change_cb )
bs->change_cb(bs->change_opaque); bs->change_cb( bs->change_opaque );
if (bs->backing_hd) if ( bs->backing_hd )
bdrv_delete(bs->backing_hd); bdrv_delete( bs->backing_hd );
bs->drv->bdrv_close(bs); bs->drv->bdrv_close( bs );
#ifdef _WIN32 #ifdef _WIN32
if (bs->is_temporary) { if ( bs->is_temporary ) {
unlink(bs->filename); unlink( bs->filename );
} }
#endif #endif
qemu_free(bs->opaque); qemu_free( bs->opaque );
bs->opaque = NULL; bs->opaque = NULL;
bs->drv = NULL; bs->drv = NULL;
} }
void void bdrv_delete( BlockDriverState* bs )
bdrv_delete(BlockDriverState *bs)
{ {
/* XXX: remove the driver list */ /* XXX: remove the driver list */
bdrv_close(bs); bdrv_close( bs );
qemu_free(bs); qemu_free( bs );
} }
/* return < 0 if error. See bdrv_write() for the return codes */ /* return < 0 if error. See bdrv_write() for the return codes */
int int bdrv_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors )
bdrv_read(BlockDriverState * bs, int64_t sector_num,
uint8_t * buf, int nb_sectors)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!drv) if ( !drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) { if ( sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0 ) {
memcpy(buf, bs->boot_sector_data, 512); memcpy( buf, bs->boot_sector_data, 512 );
sector_num++; sector_num++;
nb_sectors--; nb_sectors--;
buf += 512; buf += 512;
if (nb_sectors == 0) if ( nb_sectors == 0 )
return 0; return 0;
} }
if (drv->bdrv_pread) { if ( drv->bdrv_pread ) {
int ret, len; int ret, len;
len = nb_sectors * 512; len = nb_sectors * 512;
ret = drv->bdrv_pread(bs, sector_num * 512, buf, len); ret = drv->bdrv_pread( bs, sector_num * 512, buf, len );
if (ret < 0) if ( ret < 0 )
return ret; return ret;
else if (ret != len) else if ( ret != len )
return -EINVAL; return -EINVAL;
else else
return 0; return 0;
} else { } else {
return drv->bdrv_read(bs, sector_num, buf, nb_sectors); return drv->bdrv_read( bs, sector_num, buf, nb_sectors );
} }
} }
@ -506,54 +466,51 @@ bdrv_read(BlockDriverState * bs, int64_t sector_num,
-EINVAL Invalid sector number or nb_sectors -EINVAL Invalid sector number or nb_sectors
-EACCES Trying to write a read-only device -EACCES Trying to write a read-only device
*/ */
static int static int bdrv_write( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
bdrv_write(BlockDriverState * bs, int64_t sector_num,
const uint8_t * buf, int nb_sectors)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!bs->drv) if ( !bs->drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (bs->read_only) if ( bs->read_only )
return -EACCES; return -EACCES;
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) { if ( sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0 ) {
memcpy(bs->boot_sector_data, buf, 512); memcpy( bs->boot_sector_data, buf, 512 );
} }
if (drv->bdrv_pwrite) { if ( drv->bdrv_pwrite ) {
int ret, len; int ret, len;
len = nb_sectors * 512; len = nb_sectors * 512;
ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len); ret = drv->bdrv_pwrite( bs, sector_num * 512, buf, len );
if (ret < 0) if ( ret < 0 )
return ret; return ret;
else if (ret != len) else if ( ret != len )
return -EIO; return -EIO;
else else
return 0; return 0;
} else { } else {
return drv->bdrv_write(bs, sector_num, buf, nb_sectors); return drv->bdrv_write( bs, sector_num, buf, nb_sectors );
} }
} }
static int static int bdrv_pread_em( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count1 )
bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
{ {
uint8_t tmp_buf[SECTOR_SIZE]; uint8_t tmp_buf[ SECTOR_SIZE ];
int len, nb_sectors, count; int len, nb_sectors, count;
int64_t sector_num; int64_t sector_num;
count = count1; count = count1;
/* first read to align to sector start */ /* first read to align to sector start */
len = (SECTOR_SIZE - offset) & (SECTOR_SIZE - 1); len = ( SECTOR_SIZE - offset ) & ( SECTOR_SIZE - 1 );
if (len > count) if ( len > count )
len = count; len = count;
sector_num = offset >> SECTOR_BITS; sector_num = offset >> SECTOR_BITS;
if (len > 0) { if ( len > 0 ) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
memcpy(buf, tmp_buf + (offset & (SECTOR_SIZE - 1)), len); memcpy( buf, tmp_buf + ( offset & ( SECTOR_SIZE - 1 ) ), len );
count -= len; count -= len;
if (count == 0) if ( count == 0 )
return count1; return count1;
sector_num++; sector_num++;
buf += len; buf += len;
@ -561,8 +518,8 @@ bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
/* read the sectors "in place" */ /* read the sectors "in place" */
nb_sectors = count >> SECTOR_BITS; nb_sectors = count >> SECTOR_BITS;
if (nb_sectors > 0) { if ( nb_sectors > 0 ) {
if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0) if ( bdrv_read( bs, sector_num, buf, nb_sectors ) < 0 )
return -EIO; return -EIO;
sector_num += nb_sectors; sector_num += nb_sectors;
len = nb_sectors << SECTOR_BITS; len = nb_sectors << SECTOR_BITS;
@ -571,36 +528,34 @@ bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
} }
/* add data from the last sector */ /* add data from the last sector */
if (count > 0) { if ( count > 0 ) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
memcpy(buf, tmp_buf, count); memcpy( buf, tmp_buf, count );
} }
return count1; return count1;
} }
static int static int bdrv_pwrite_em( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count1 )
bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
const uint8_t * buf, int count1)
{ {
uint8_t tmp_buf[SECTOR_SIZE]; uint8_t tmp_buf[ SECTOR_SIZE ];
int len, nb_sectors, count; int len, nb_sectors, count;
int64_t sector_num; int64_t sector_num;
count = count1; count = count1;
/* first write to align to sector start */ /* first write to align to sector start */
len = (SECTOR_SIZE - offset) & (SECTOR_SIZE - 1); len = ( SECTOR_SIZE - offset ) & ( SECTOR_SIZE - 1 );
if (len > count) if ( len > count )
len = count; len = count;
sector_num = offset >> SECTOR_BITS; sector_num = offset >> SECTOR_BITS;
if (len > 0) { if ( len > 0 ) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
memcpy(tmp_buf + (offset & (SECTOR_SIZE - 1)), buf, len); memcpy( tmp_buf + ( offset & ( SECTOR_SIZE - 1 ) ), buf, len );
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_write( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
count -= len; count -= len;
if (count == 0) if ( count == 0 )
return count1; return count1;
sector_num++; sector_num++;
buf += len; buf += len;
@ -608,8 +563,8 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
/* write the sectors "in place" */ /* write the sectors "in place" */
nb_sectors = count >> SECTOR_BITS; nb_sectors = count >> SECTOR_BITS;
if (nb_sectors > 0) { if ( nb_sectors > 0 ) {
if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0) if ( bdrv_write( bs, sector_num, buf, nb_sectors ) < 0 )
return -EIO; return -EIO;
sector_num += nb_sectors; sector_num += nb_sectors;
len = nb_sectors << SECTOR_BITS; len = nb_sectors << SECTOR_BITS;
@ -618,11 +573,11 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
} }
/* add data from the last sector */ /* add data from the last sector */
if (count > 0) { if ( count > 0 ) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
memcpy(tmp_buf, buf, count); memcpy( tmp_buf, buf, count );
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0) if ( bdrv_write( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO; return -EIO;
} }
return count1; return count1;
@ -631,47 +586,43 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
/** /**
* Read with byte offsets (needed only for file protocols) * Read with byte offsets (needed only for file protocols)
*/ */
int int bdrv_pread( BlockDriverState* bs, int64_t offset, void* buf1, int count1 )
bdrv_pread(BlockDriverState * bs, int64_t offset, void *buf1, int count1)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!drv) if ( !drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (!drv->bdrv_pread) if ( !drv->bdrv_pread )
return bdrv_pread_em(bs, offset, buf1, count1); return bdrv_pread_em( bs, offset, buf1, count1 );
return drv->bdrv_pread(bs, offset, buf1, count1); return drv->bdrv_pread( bs, offset, buf1, count1 );
} }
/** /**
* Write with byte offsets (needed only for file protocols) * Write with byte offsets (needed only for file protocols)
*/ */
int int bdrv_pwrite( BlockDriverState* bs, int64_t offset, const void* buf1, int count1 )
bdrv_pwrite(BlockDriverState * bs, int64_t offset, const void *buf1, int count1)
{ {
BlockDriver *drv = bs->drv; BlockDriver* drv = bs->drv;
if (!drv) if ( !drv )
return -ENOMEDIUM; return -ENOMEDIUM;
if (!drv->bdrv_pwrite) if ( !drv->bdrv_pwrite )
return bdrv_pwrite_em(bs, offset, buf1, count1); return bdrv_pwrite_em( bs, offset, buf1, count1 );
return drv->bdrv_pwrite(bs, offset, buf1, count1); return drv->bdrv_pwrite( bs, offset, buf1, count1 );
} }
void void bdrv_flush( BlockDriverState* bs )
bdrv_flush(BlockDriverState *bs)
{ {
if (bs->drv->bdrv_flush) if ( bs->drv->bdrv_flush )
bs->drv->bdrv_flush(bs); bs->drv->bdrv_flush( bs );
if (bs->backing_hd) if ( bs->backing_hd )
bdrv_flush(bs->backing_hd); bdrv_flush( bs->backing_hd );
} }
void void bdrv_init( void )
bdrv_init(void)
{ {
/* bdrv_register(&bdrv_raw); */ /* bdrv_register(&bdrv_raw); */
/* bdrv_register(&bdrv_host_device); */ /* bdrv_register(&bdrv_host_device); */
bdrv_register(&bdrv_qcow); bdrv_register( &bdrv_qcow );
bdrv_register(&bdrv_vvfat); bdrv_register( &bdrv_vvfat );
} }

View file

@ -10,61 +10,58 @@
#define BDRV_O_RDWR 0x0002 #define BDRV_O_RDWR 0x0002
#define BDRV_O_ACCESS 0x0003 #define BDRV_O_ACCESS 0x0003
#define BDRV_O_CREAT 0x0004 /* create an empty file */ #define BDRV_O_CREAT 0x0004 /* create an empty file */
#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save #define BDRV_O_SNAPSHOT \
0x0008 /* open the file read only and save \
writes in a snapshot */ writes in a snapshot */
#define BDRV_O_FILE 0x0010 /* open as a raw file (do not try to #define BDRV_O_FILE \
use a disk image format on top of 0x0010 /* open as a raw file (do not try to \
it (default for use a disk image format on top of \
it (default for \
bdrv_file_open()) */ bdrv_file_open()) */
typedef struct BlockDriver BlockDriver; typedef struct BlockDriver BlockDriver;
typedef struct SnapshotInfo QEMUSnapshotInfo; typedef struct SnapshotInfo QEMUSnapshotInfo;
typedef struct BlockDriverInfo BlockDriverInfo; typedef struct BlockDriverInfo BlockDriverInfo;
typedef struct BlockDriverAIOCB BlockDriverAIOCB; typedef struct BlockDriverAIOCB BlockDriverAIOCB;
typedef void BlockDriverCompletionFunc(void *opaque, int ret); typedef void BlockDriverCompletionFunc( void* opaque, int ret );
extern BlockDriver bdrv_raw; extern BlockDriver bdrv_raw;
extern BlockDriver bdrv_host_device; extern BlockDriver bdrv_host_device;
extern BlockDriver bdrv_qcow; extern BlockDriver bdrv_qcow;
extern BlockDriver bdrv_vvfat; extern BlockDriver bdrv_vvfat;
void bdrv_init(void); void bdrv_init( void );
int bdrv_create(BlockDriver *drv, int bdrv_create( BlockDriver* drv, const char* filename, int64_t size_in_sectors, const char* backing_file, int flags );
const char *filename, int64_t size_in_sectors, BlockDriverState* bdrv_new( const char* device_name );
const char *backing_file, int flags); void bdrv_delete( BlockDriverState* bs );
BlockDriverState *bdrv_new(const char *device_name); int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags );
void bdrv_delete(BlockDriverState *bs); int bdrv_open( BlockDriverState* bs, const char* filename, int flags );
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
int bdrv_read(BlockDriverState *bs, int64_t sector_num, int bdrv_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors );
uint8_t *buf, int nb_sectors); int bdrv_pread( BlockDriverState* bs, int64_t offset, void* buf, int count );
int bdrv_pread(BlockDriverState *bs, int64_t offset, int bdrv_pwrite( BlockDriverState* bs, int64_t offset, const void* buf, int count );
void *buf, int count);
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
const void *buf, int count);
int bdrv_truncate(BlockDriverState *bs, int64_t offset); int bdrv_truncate( BlockDriverState* bs, int64_t offset );
int64_t bdrv_getlength(BlockDriverState *bs); int64_t bdrv_getlength( BlockDriverState* bs );
void bdrv_flush(BlockDriverState *bs); void bdrv_flush( BlockDriverState* bs );
/* timers */ /* timers */
typedef struct QEMUClock QEMUClock; typedef struct QEMUClock QEMUClock;
typedef void QEMUTimerCB(void *opaque); typedef void QEMUTimerCB( void* opaque );
/* The real time clock should be used only for stuff which does not /* The real time clock should be used only for stuff which does not
change the virtual machine state, as it is run even if the virtual change the virtual machine state, as it is run even if the virtual
machine is stopped. The real time clock has a frequency of 1000 machine is stopped. The real time clock has a frequency of 1000
Hz. */ Hz. */
extern QEMUClock *rt_clock; extern QEMUClock* rt_clock;
int64_t qemu_get_clock(QEMUClock *clock); int64_t qemu_get_clock( QEMUClock* clock );
QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque); QEMUTimer* qemu_new_timer( QEMUClock* clock, QEMUTimerCB* cb, void* opaque );
void qemu_del_timer(QEMUTimer *ts); void qemu_del_timer( QEMUTimer* ts );
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); void qemu_mod_timer( QEMUTimer* ts, int64_t expire_time );
int qemu_timer_pending(QEMUTimer *ts); int qemu_timer_pending( QEMUTimer* ts );
extern int64_t ticks_per_sec; extern int64_t ticks_per_sec;

View file

@ -24,46 +24,39 @@
#ifndef BLOCK_INT_H #ifndef BLOCK_INT_H
#define BLOCK_INT_H #define BLOCK_INT_H
# include "qemu-git/qemu-common.h" #include "qemu-git/qemu-common.h"
# include "block.h" #include "block.h"
struct BlockDriver { struct BlockDriver {
const char *format_name; const char* format_name;
int instance_size; int instance_size;
int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *filename); int ( *bdrv_probe )( const uint8_t* buf, int buf_size, const char* filename );
int (*bdrv_open)(BlockDriverState *bs, const char *filename, int flags); int ( *bdrv_open )( BlockDriverState* bs, const char* filename, int flags );
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num, int ( *bdrv_read )( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors );
uint8_t *buf, int nb_sectors); int ( *bdrv_write )( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors );
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, void ( *bdrv_close )( BlockDriverState* bs );
const uint8_t *buf, int nb_sectors); int ( *bdrv_create )( const char* filename, int64_t total_sectors, const char* backing_file, int flags );
void (*bdrv_close)(BlockDriverState *bs); void ( *bdrv_flush )( BlockDriverState* bs );
int (*bdrv_create)(const char *filename, int64_t total_sectors, int ( *bdrv_is_allocated )( BlockDriverState* bs, int64_t sector_num, int nb_sectors, int* pnum );
const char *backing_file, int flags); int ( *bdrv_set_key )( BlockDriverState* bs, const char* key );
void (*bdrv_flush)(BlockDriverState *bs); int ( *bdrv_make_empty )( BlockDriverState* bs );
int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum);
int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
int (*bdrv_make_empty)(BlockDriverState *bs);
const char *protocol_name; const char* protocol_name;
int (*bdrv_pread)(BlockDriverState *bs, int64_t offset, int ( *bdrv_pread )( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count );
uint8_t *buf, int count); int ( *bdrv_pwrite )( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count );
int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset, int ( *bdrv_truncate )( BlockDriverState* bs, int64_t offset );
const uint8_t *buf, int count); int64_t ( *bdrv_getlength )( BlockDriverState* bs );
int (*bdrv_truncate)(BlockDriverState *bs, int64_t offset); int ( *bdrv_write_compressed )( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors );
int64_t (*bdrv_getlength)(BlockDriverState *bs);
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors);
int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); int ( *bdrv_get_info )( BlockDriverState* bs, BlockDriverInfo* bdi );
/* removable device specific */ /* removable device specific */
int (*bdrv_is_inserted)(BlockDriverState *bs); int ( *bdrv_is_inserted )( BlockDriverState* bs );
int (*bdrv_media_changed)(BlockDriverState *bs); int ( *bdrv_media_changed )( BlockDriverState* bs );
int (*bdrv_eject)(BlockDriverState *bs, int eject_flag); int ( *bdrv_eject )( BlockDriverState* bs, int eject_flag );
int (*bdrv_set_locked)(BlockDriverState *bs, int locked); int ( *bdrv_set_locked )( BlockDriverState* bs, int locked );
struct BlockDriver *next; struct BlockDriver* next;
}; };
struct BlockDriverState { struct BlockDriverState {
@ -74,34 +67,34 @@ struct BlockDriverState {
int locked; /* if true, the media cannot temporarily be ejected */ int locked; /* if true, the media cannot temporarily be ejected */
int encrypted; /* if true, the media is encrypted */ int encrypted; /* if true, the media is encrypted */
/* event callback when inserting/removing */ /* event callback when inserting/removing */
void (*change_cb)(void *opaque); void ( *change_cb )( void* opaque );
void *change_opaque; void* change_opaque;
BlockDriver *drv; /* NULL means no media */ BlockDriver* drv; /* NULL means no media */
void *opaque; void* opaque;
int boot_sector_enabled; int boot_sector_enabled;
uint8_t boot_sector_data[512]; uint8_t boot_sector_data[ 512 ];
char filename[1024]; char filename[ 1024 ];
char backing_file[1024]; /* if non zero, the image is a diff of char backing_file[ 1024 ]; /* if non zero, the image is a diff of
this file image */ this file image */
int is_temporary; int is_temporary;
int media_changed; int media_changed;
BlockDriverState *backing_hd; BlockDriverState* backing_hd;
/* async read/write emulation */ /* async read/write emulation */
void *sync_aiocb; void* sync_aiocb;
/* NOTE: the following infos are only hints for real hardware /* NOTE: the following infos are only hints for real hardware
drivers. They are not used by the block driver */ drivers. They are not used by the block driver */
int cyls, heads, secs, translation; int cyls, heads, secs, translation;
int type; int type;
char device_name[32]; char device_name[ 32 ];
BlockDriverState *next; BlockDriverState* next;
}; };
void get_tmp_filename(char *filename, int size); void get_tmp_filename( char* filename, int size );
#endif /* BLOCK_INT_H */ #endif /* BLOCK_INT_H */

View file

@ -6,86 +6,75 @@
#include <sys/types.h> #include <sys/types.h>
static __inline__ uint16_t swab16(uint16_t x) static __inline__ uint16_t swab16( uint16_t x ) { return ( ( x & 0xff00 ) >> 8 ) | ( ( x & 0x00ff ) << 8 ); }
{
return ((x & 0xff00) >> 8) |
((x & 0x00ff) << 8);
}
static __inline__ uint32_t swab32(uint32_t x) static __inline__ uint32_t swab32( uint32_t x )
{ {
return ((x & 0xff000000) >> 24) | return ( ( x & 0xff000000 ) >> 24 ) | ( ( x & 0x00ff0000 ) >> 8 ) | ( ( x & 0x0000ff00 ) << 8 ) | ( ( x & 0x000000ff ) << 24 );
((x & 0x00ff0000) >> 8) |
((x & 0x0000ff00) << 8) |
((x & 0x000000ff) << 24);
} }
#ifdef __sparc__ #ifdef __sparc__
#define ASI_PL 0x88 /* Primary, implicit, little endian. */ # define ASI_PL 0x88 /* Primary, implicit, little endian. */
static __inline__ uint16_t __load_le16(const uint16_t *p) static __inline__ uint16_t __load_le16( const uint16_t* p )
{ {
uint16_t x; uint16_t x;
__asm__ __volatile__ ("lduha [%1] %2, %0" __asm__ __volatile__( "lduha [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
: "=r" (x)
: "r" (p), "i" (ASI_PL));
return x; return x;
} }
static __inline__ uint32_t __load_le32(const uint32_t *p) static __inline__ uint32_t __load_le32( const uint32_t* p )
{ {
uint32_t x; uint32_t x;
__asm__ __volatile__ ("lduwa [%1] %2, %0" __asm__ __volatile__( "lduwa [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
: "=r" (x)
: "r" (p), "i" (ASI_PL));
return x; return x;
} }
static __inline__ void __store_le16(uint16_t *p, uint16_t x) static __inline__ void __store_le16( uint16_t* p, uint16_t x )
{ {
__asm__ __volatile__ ("stha %0, [%1] %2" __asm__ __volatile__( "stha %0, [%1] %2"
: /* no outputs */ : /* no outputs */
: "r" (x), "r" (p), "i" (ASI_PL)); : "r"( x ), "r"( p ), "i"( ASI_PL ) );
} }
static __inline__ void __store_le32(uint32_t *p, uint32_t x) static __inline__ void __store_le32( uint32_t* p, uint32_t x )
{ {
__asm__ __volatile__ ("stwa %0, [%1] %2" __asm__ __volatile__( "stwa %0, [%1] %2"
: /* no outputs */ : /* no outputs */
: "r" (x), "r" (p), "i" (ASI_PL)); : "r"( x ), "r"( p ), "i"( ASI_PL ) );
} }
#endif /* __sparc__ */ #endif /* __sparc__ */
#if __BYTE_ORDER == __LITTLE_ENDIAN #if __BYTE_ORDER == __LITTLE_ENDIAN
#define le16_to_cpu(x) (x) # define le16_to_cpu( x ) ( x )
#define cpu_to_le16(x) (x) # define cpu_to_le16( x ) ( x )
#define le32_to_cpu(x) (x) # define le32_to_cpu( x ) ( x )
#define cpu_to_le32(x) (x) # define cpu_to_le32( x ) ( x )
#define load_le16(p) (*(p)) # define load_le16( p ) ( *( p ) )
#define store_le16(p, x) (*(p) = (x)) # define store_le16( p, x ) ( *( p ) = ( x ) )
#define load_le32(p) (*(p)) # define load_le32( p ) ( *( p ) )
#define store_le32(p, x) (*(p) = (x)) # define store_le32( p, x ) ( *( p ) = ( x ) )
#elif __BYTE_ORDER == __BIG_ENDIAN #elif __BYTE_ORDER == __BIG_ENDIAN
#define le16_to_cpu(x) swab16(x) # define le16_to_cpu( x ) swab16( x )
#define cpu_to_le16(x) swab16(x) # define cpu_to_le16( x ) swab16( x )
#define le32_to_cpu(x) swab32(x) # define le32_to_cpu( x ) swab32( x )
#define cpu_to_le32(x) swab32(x) # define cpu_to_le32( x ) swab32( x )
#define load_le16(p) __load_le16(p) # define load_le16( p ) __load_le16( p )
#define store_le16(p, x) __store_le16(p, x) # define store_le16( p, x ) __store_le16( p, x )
#define load_le32(p) __load_le32(p) # define load_le32( p ) __load_le32( p )
#define store_le32(p, x) __store_le32(p, x) # define store_le32( p, x ) __store_le32( p, x )
#else #else
#error "Cannot determine host byteorder" # error "Cannot determine host byteorder"
#endif #endif
#endif /* !(_X49GP_BYTEORDER_H) */ #endif /* !(_X49GP_BYTEORDER_H) */

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -12,27 +12,24 @@
#define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_READ 3
#define GDB_WATCHPOINT_ACCESS 4 #define GDB_WATCHPOINT_ACCESS 4
typedef void (*gdb_syscall_complete_cb)(CPUState *env, typedef void ( *gdb_syscall_complete_cb )( CPUState* env, target_ulong ret, target_ulong err );
target_ulong ret, target_ulong err);
void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...); void gdb_do_syscall( gdb_syscall_complete_cb cb, const char* fmt, ... );
int use_gdb_syscalls(void); int use_gdb_syscalls( void );
void gdb_set_stop_cpu(CPUState *env); void gdb_set_stop_cpu( CPUState* env );
int gdb_poll(CPUState *); int gdb_poll( CPUState* );
int gdb_queuesig (void); int gdb_queuesig( void );
int gdb_handlesig (CPUState *, int); int gdb_handlesig( CPUState*, int );
void gdb_exit(CPUState *, int); void gdb_exit( CPUState*, int );
void gdb_signalled(CPUState *, int); void gdb_signalled( CPUState*, int );
int gdbserver_start(int); int gdbserver_start( int );
void gdbserver_fork(CPUState *); void gdbserver_fork( CPUState* );
/* Get or set a register. Returns the size of the register. */ /* Get or set a register. Returns the size of the register. */
typedef int (*gdb_reg_cb)(CPUState *env, uint8_t *buf, int reg); typedef int ( *gdb_reg_cb )( CPUState* env, uint8_t* buf, int reg );
void gdb_register_coprocessor(CPUState *env, void gdb_register_coprocessor( CPUState* env, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char* xml, int g_pos );
gdb_reg_cb get_reg, gdb_reg_cb set_reg,
int num_regs, const char *xml, int g_pos);
int gdbserver_isactive(); int gdbserver_isactive();

View file

@ -5,234 +5,233 @@
#define _X49GP_GLYPHNAME_H 1 #define _X49GP_GLYPHNAME_H 1
typedef struct { typedef struct {
const char *name; const char* name;
gunichar unichar; gunichar unichar;
} x49gp_glyph_t; } x49gp_glyph_t;
static const x49gp_glyph_t x49gp_glyphs[] = static const x49gp_glyph_t x49gp_glyphs[] = {
{ {"exclamdown", 0x00a1},
{ "exclamdown", 0x00a1 }, {"cent", 0x00a2},
{ "cent", 0x00a2 }, {"sterling", 0x00a3},
{ "sterling", 0x00a3 }, {"fraction", 0x2044},
{ "fraction", 0x2044 }, {"yen", 0x00a5},
{ "yen", 0x00a5 }, {"florin", 0x0192},
{ "florin", 0x0192 }, {"section", 0x00a7},
{ "section", 0x00a7 }, {"currency", 0x00a4},
{ "currency", 0x00a4 }, {"quotesingle", 0x0027},
{ "quotesingle", 0x0027 }, {"quotedblleft", 0x201c},
{ "quotedblleft", 0x201c }, {"guillemotleft", 0x00ab},
{ "guillemotleft", 0x00ab }, {"guilsinglleft", 0x2039},
{ "guilsinglleft", 0x2039 }, {"guilsinglright", 0x203a},
{ "guilsinglright", 0x203a }, {"fi", 0xfb01},
{ "fi", 0xfb01 }, {"fl", 0xfb02},
{ "fl", 0xfb02 }, {"endash", 0x2013},
{ "endash", 0x2013 }, {"dagger", 0x2020},
{ "dagger", 0x2020 }, {"daggerdbl", 0x2021},
{ "daggerdbl", 0x2021 }, {"periodcentered", 0x00b7},
{ "periodcentered", 0x00b7 }, {"paragraph", 0x00b6},
{ "paragraph", 0x00b6 }, {"bullet", 0x2022},
{ "bullet", 0x2022 }, {"quotesinglbase", 0x201a},
{ "quotesinglbase", 0x201a }, {"quotedblbase", 0x201e},
{ "quotedblbase", 0x201e }, {"quotedblright", 0x201d},
{ "quotedblright", 0x201d }, {"guillemotright", 0x00bb},
{ "guillemotright", 0x00bb }, {"ellipsis", 0x2026},
{ "ellipsis", 0x2026 }, {"perthousand", 0x2030},
{ "perthousand", 0x2030 }, {"questiondown", 0x00bf},
{ "questiondown", 0x00bf }, {"grave", 0x0060},
{ "grave", 0x0060 }, {"acute", 0x00b4},
{ "acute", 0x00b4 }, {"circumflex", 0x02c6},
{ "circumflex", 0x02c6 }, {"tilde", 0x02dc},
{ "tilde", 0x02dc }, {"macron", 0x00af},
{ "macron", 0x00af }, {"breve", 0x02d8},
{ "breve", 0x02d8 }, {"dotaccent", 0x02d9},
{ "dotaccent", 0x02d9 }, {"dieresis", 0x00a8},
{ "dieresis", 0x00a8 }, {"ring", 0x02da},
{ "ring", 0x02da }, {"cedilla", 0x00b8},
{ "cedilla", 0x00b8 }, {"hungarumlaut", 0x02dd},
{ "hungarumlaut", 0x02dd }, {"ogonek", 0x02db},
{ "ogonek", 0x02db }, {"caron", 0x02c7},
{ "caron", 0x02c7 }, {"emdash", 0x2014},
{ "emdash", 0x2014 }, {"AE", 0x00c6},
{ "AE", 0x00c6 }, {"ordfeminine", 0x00aa},
{ "ordfeminine", 0x00aa }, {"Lslash", 0x0141},
{ "Lslash", 0x0141 }, {"Oslash", 0x00d8},
{ "Oslash", 0x00d8 }, {"OE", 0x0152},
{ "OE", 0x0152 }, {"ordmasculine", 0x00ba},
{ "ordmasculine", 0x00ba }, {"ae", 0x00e6},
{ "ae", 0x00e6 }, {"dotlessi", 0x0131},
{ "dotlessi", 0x0131 }, {"lslash", 0x0142},
{ "lslash", 0x0142 }, {"oslash", 0x00f8},
{ "oslash", 0x00f8 }, {"oe", 0x0153},
{ "oe", 0x0153 }, {"germandbls", 0x00df},
{ "germandbls", 0x00df }, {"Udieresis", 0x00dc},
{ "Udieresis", 0x00dc }, {"Uacute", 0x00da},
{ "Uacute", 0x00da }, {"Scedilla", 0x015e},
{ "Scedilla", 0x015e }, {"Tcaron", 0x0164},
{ "Tcaron", 0x0164 }, {"Scaron", 0x0160},
{ "Scaron", 0x0160 }, {"Rcaron", 0x0158},
{ "Rcaron", 0x0158 }, {"Racute", 0x0154},
{ "Racute", 0x0154 }, {"Sacute", 0x015a},
{ "Sacute", 0x015a }, {"Otilde", 0x00d5},
{ "Otilde", 0x00d5 }, {"ucircumflex", 0x00fb},
{ "ucircumflex", 0x00fb }, {"Ohungarumlaut", 0x0150},
{ "Ohungarumlaut", 0x0150 }, {"Uhungarumlaut", 0x0170},
{ "Uhungarumlaut", 0x0170 }, {"Yacute", 0x00dd},
{ "Yacute", 0x00dd }, {"Eth", 0x00d0},
{ "Eth", 0x00d0 }, {"Dcroat", 0x0110},
{ "Dcroat", 0x0110 }, {"Zacute", 0x0179},
{ "Zacute", 0x0179 }, {"Uring", 0x016e},
{ "Uring", 0x016e }, {"gbreve", 0x011f},
{ "gbreve", 0x011f }, {"eogonek", 0x0119},
{ "eogonek", 0x0119 }, {"edotaccent", 0x0117},
{ "edotaccent", 0x0117 }, {"ecaron", 0x011b},
{ "ecaron", 0x011b }, {"Ugrave", 0x00d9},
{ "Ugrave", 0x00d9 }, {"Thorn", 0x00de},
{ "Thorn", 0x00de }, {"eacute", 0x00e9},
{ "eacute", 0x00e9 }, {"edieresis", 0x00eb},
{ "edieresis", 0x00eb }, {"dcaron", 0x010f},
{ "dcaron", 0x010f }, {"ccedilla", 0x00e7},
{ "ccedilla", 0x00e7 }, {"ccaron", 0x010d},
{ "ccaron", 0x010d }, {"cacute", 0x0107},
{ "cacute", 0x0107 }, {"aogonek", 0x0105},
{ "aogonek", 0x0105 }, {"aring", 0x00e5},
{ "aring", 0x00e5 }, {"atilde", 0x00e3},
{ "atilde", 0x00e3 }, {"abreve", 0x0103},
{ "abreve", 0x0103 }, {"egrave", 0x00e8},
{ "egrave", 0x00e8 }, {"agrave", 0x00e0},
{ "agrave", 0x00e0 }, {"aacute", 0x00e1},
{ "aacute", 0x00e1 }, {"adieresis", 0x00e4},
{ "adieresis", 0x00e4 }, {"Uogonek", 0x0172},
{ "Uogonek", 0x0172 }, {"ugrave", 0x00f9},
{ "ugrave", 0x00f9 }, {"uacute", 0x00fa},
{ "uacute", 0x00fa }, {"udieresis", 0x00fc},
{ "udieresis", 0x00fc }, {"tcaron", 0x0165},
{ "tcaron", 0x0165 }, {"scommaaccent", 0x0219},
{ "scommaaccent", 0x0219 }, {"Zcaron", 0x017d},
{ "Zcaron", 0x017d }, {"ecircumflex", 0x00ea},
{ "ecircumflex", 0x00ea }, {"Ucircumflex", 0x00db},
{ "Ucircumflex", 0x00db }, {"acircumflex", 0x00e2},
{ "acircumflex", 0x00e2 }, {"Zdotaccent", 0x017b},
{ "Zdotaccent", 0x017b }, {"scaron", 0x0161},
{ "scaron", 0x0161 }, {"Amacron", 0x0100},
{ "Amacron", 0x0100 }, {"sacute", 0x015b},
{ "sacute", 0x015b }, {"Tcommaaccent", 0x0162},
{ "Tcommaaccent", 0x0162 }, {"Ydieresis", 0x0178},
{ "Ydieresis", 0x0178 }, {"thorn", 0x00fe},
{ "thorn", 0x00fe }, {"Emacron", 0x0112},
{ "Emacron", 0x0112 }, {"Ograve", 0x00d2},
{ "Ograve", 0x00d2 }, {"Oacute", 0x00d3},
{ "Oacute", 0x00d3 }, {"Odieresis", 0x00d6},
{ "Odieresis", 0x00d6 }, {"Ntilde", 0x00d1},
{ "Ntilde", 0x00d1 }, {"Ncaron", 0x0147},
{ "Ncaron", 0x0147 }, {"Nacute", 0x0143},
{ "Nacute", 0x0143 }, {"Lcaron", 0x013d},
{ "Lcaron", 0x013d }, {"Lacute", 0x0139},
{ "Lacute", 0x0139 }, {"Idotaccent", 0x0130},
{ "Idotaccent", 0x0130 }, {"racute", 0x0155},
{ "racute", 0x0155 }, {"Icircumflex", 0x00ce},
{ "Icircumflex", 0x00ce }, {"ohungarumlaut", 0x0151},
{ "ohungarumlaut", 0x0151 }, {"otilde", 0x00f5},
{ "otilde", 0x00f5 }, {"Euro", 0x20ac},
{ "Euro", 0x20ac }, {"ocircumflex", 0x00f4},
{ "ocircumflex", 0x00f4 }, {"onesuperior", 0x00b9},
{ "onesuperior", 0x00b9 }, {"twosuperior", 0x00b2},
{ "twosuperior", 0x00b2 }, {"threesuperior", 0x00b3},
{ "threesuperior", 0x00b3 }, {"Igrave", 0x00cc},
{ "Igrave", 0x00cc }, {"Iacute", 0x00cd},
{ "Iacute", 0x00cd }, {"Imacron", 0x012a},
{ "Imacron", 0x012a }, {"Iogonek", 0x012e},
{ "Iogonek", 0x012e }, {"Idieresis", 0x00cf},
{ "Idieresis", 0x00cf }, {"Gbreve", 0x011e},
{ "Gbreve", 0x011e }, {"Umacron", 0x016a},
{ "Umacron", 0x016a }, {"Kcommaaccent", 0x0136},
{ "Kcommaaccent", 0x0136 }, {"ograve", 0x00f2},
{ "ograve", 0x00f2 }, {"Scommaaccent", 0x0218},
{ "Scommaaccent", 0x0218 }, {"Eogonek", 0x0118},
{ "Eogonek", 0x0118 }, {"oacute", 0x00f3},
{ "oacute", 0x00f3 }, {"Edotaccent", 0x0116},
{ "Edotaccent", 0x0116 }, {"iogonek", 0x012f},
{ "iogonek", 0x012f }, {"gcommaaccent", 0x0123},
{ "gcommaaccent", 0x0123 }, {"odieresis", 0x00f6},
{ "odieresis", 0x00f6 }, {"ntilde", 0x00f1},
{ "ntilde", 0x00f1 }, {"ncaron", 0x0148},
{ "ncaron", 0x0148 }, {"Ecaron", 0x011a},
{ "Ecaron", 0x011a }, {"Ecircumflex", 0x00ca},
{ "Ecircumflex", 0x00ca }, {"scedilla", 0x015f},
{ "scedilla", 0x015f }, {"rcaron", 0x0159},
{ "rcaron", 0x0159 }, {"Egrave", 0x00c8},
{ "Egrave", 0x00c8 }, {"Eacute", 0x00c9},
{ "Eacute", 0x00c9 }, {"Gcommaaccent", 0x0122},
{ "Gcommaaccent", 0x0122 }, {"Rcommaaccent", 0x0156},
{ "Rcommaaccent", 0x0156 }, {"Edieresis", 0x00cb},
{ "Edieresis", 0x00cb }, {"nacute", 0x0144},
{ "nacute", 0x0144 }, {"uogonek", 0x0173},
{ "uogonek", 0x0173 }, {"umacron", 0x016b},
{ "umacron", 0x016b }, {"Dcaron", 0x010e},
{ "Dcaron", 0x010e }, {"lcaron", 0x013e},
{ "lcaron", 0x013e }, {"Ccaron", 0x010c},
{ "Ccaron", 0x010c }, {"Cacute", 0x0106},
{ "Cacute", 0x0106 }, {"Ccedilla", 0x00c7},
{ "Ccedilla", 0x00c7 }, {"degree", 0x00b0},
{ "degree", 0x00b0 }, {"Aogonek", 0x0104},
{ "Aogonek", 0x0104 }, {"minus", 0x2212},
{ "minus", 0x2212 }, {"multiply", 0x00d7},
{ "multiply", 0x00d7 }, {"divide", 0x00f7},
{ "divide", 0x00f7 }, {"Aring", 0x00c5},
{ "Aring", 0x00c5 }, {"trademark", 0x2122},
{ "trademark", 0x2122 }, {"rcommaaccent", 0x0157},
{ "rcommaaccent", 0x0157 }, {"lacute", 0x013a},
{ "lacute", 0x013a }, {"omacron", 0x014d},
{ "omacron", 0x014d }, {"Atilde", 0x00c3},
{ "Atilde", 0x00c3 }, {"icircumflex", 0x00ee},
{ "icircumflex", 0x00ee }, {"igrave", 0x00ec},
{ "igrave", 0x00ec }, {"ncommaaccent", 0x0146},
{ "ncommaaccent", 0x0146 }, {"lcommaaccent", 0x013c},
{ "lcommaaccent", 0x013c }, {"plusminus", 0x00b1},
{ "plusminus", 0x00b1 }, {"onehalf", 0x00bd},
{ "onehalf", 0x00bd }, {"onequarter", 0x00bc},
{ "onequarter", 0x00bc }, {"threequarters", 0x00be},
{ "threequarters", 0x00be }, {"iacute", 0x00ed},
{ "iacute", 0x00ed }, {"Abreve", 0x0102},
{ "Abreve", 0x0102 }, {"kcommaaccent", 0x0137},
{ "kcommaaccent", 0x0137 }, {"Omacron", 0x014c},
{ "Omacron", 0x014c }, {"imacron", 0x012b},
{ "imacron", 0x012b }, {"emacron", 0x0113},
{ "emacron", 0x0113 }, {"amacron", 0x0101},
{ "amacron", 0x0101 }, {"tcommaaccent", 0x0163},
{ "tcommaaccent", 0x0163 }, {"ydieresis", 0x00ff},
{ "ydieresis", 0x00ff }, {"zdotaccent", 0x017c},
{ "zdotaccent", 0x017c }, {"zcaron", 0x017e},
{ "zcaron", 0x017e }, {"zacute", 0x017a},
{ "zacute", 0x017a }, {"yacute", 0x00fd},
{ "yacute", 0x00fd }, {"uhungarumlaut", 0x0171},
{ "uhungarumlaut", 0x0171 }, {"eth", 0x00f0},
{ "eth", 0x00f0 }, {"uring", 0x016f},
{ "uring", 0x016f }, {"Ocircumflex", 0x00d4},
{ "Ocircumflex", 0x00d4 }, {"commaaccent", 0xf6c3},
{ "commaaccent", 0xf6c3 }, {"copyright", 0x00a9},
{ "copyright", 0x00a9 }, {"registered", 0x00ae},
{ "registered", 0x00ae }, {"Acircumflex", 0x00c2},
{ "Acircumflex", 0x00c2 }, {"idieresis", 0x00ef},
{ "idieresis", 0x00ef }, {"lozenge", 0x25ca},
{ "lozenge", 0x25ca }, {"Delta", 0x2206},
{ "Delta", 0x2206 }, {"notequal", 0x2260},
{ "notequal", 0x2260 }, {"radical", 0x221a},
{ "radical", 0x221a }, {"Agrave", 0x00c0},
{ "Agrave", 0x00c0 }, {"Aacute", 0x00c1},
{ "Aacute", 0x00c1 }, {"lessequal", 0x2264},
{ "lessequal", 0x2264 }, {"greaterequal", 0x2265},
{ "greaterequal", 0x2265 }, {"logicalnot", 0x00ac},
{ "logicalnot", 0x00ac }, {"summation", 0x2211},
{ "summation", 0x2211 }, {"partialdiff", 0x2202},
{ "partialdiff", 0x2202 }, {"Ncommaaccent", 0x0145},
{ "Ncommaaccent", 0x0145 }, {"dcroat", 0x0111},
{ "dcroat", 0x0111 }, {"brokenbar", 0x00a6},
{ "brokenbar", 0x00a6 }, {"Lcommaaccent", 0x013b},
{ "Lcommaaccent", 0x013b }, {"Adieresis", 0x00c4},
{ "Adieresis", 0x00c4 }, {"mu", 0x00b5}
{ "mu", 0x00b5 }
}; };
#define NR_GLYPHNAMES (sizeof(x49gp_glyphs) / sizeof(x49gp_glyphs[0])) #define NR_GLYPHNAMES ( sizeof( x49gp_glyphs ) / sizeof( x49gp_glyphs[ 0 ] ) )
#endif /* !(_X49GP_GLYPHNAME_H) */ #endif /* !(_X49GP_GLYPHNAME_H) */

View file

@ -26,92 +26,89 @@
#include <ctype.h> #include <ctype.h>
#include <netinet/in.h> #include <netinet/in.h>
int int main( int argc, char** argv )
main(int argc, char **argv)
{ {
unsigned char *input, *p; unsigned char *input, *p;
unsigned char *memory = NULL; unsigned char* memory = NULL;
size_t size; size_t size;
int in, out; int in, out;
int i; int i;
if (argc < 3) { if ( argc < 3 ) {
fprintf(stderr, "usage: %s <infile> <outfile>\n", argv[0]); fprintf( stderr, "usage: %s <infile> <outfile>\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
if (!strcmp(argv[1], "-")) if ( !strcmp( argv[ 1 ], "-" ) )
in = 0; in = 0;
else { else {
in = open(argv[1], O_RDONLY); in = open( argv[ 1 ], O_RDONLY );
if (in < 0) { if ( in < 0 ) {
perror(argv[1]); perror( argv[ 1 ] );
exit(1); exit( 1 );
} }
} }
if (!strcmp(argv[2], "-")) if ( !strcmp( argv[ 2 ], "-" ) )
out = 1; out = 1;
else { else {
out = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666); out = open( argv[ 2 ], O_WRONLY | O_CREAT | O_TRUNC, 0666 );
if (out < 0) { if ( out < 0 ) {
perror(argv[2]); perror( argv[ 2 ] );
exit(1); exit( 1 );
} }
} }
size = lseek(in, 0, SEEK_END); size = lseek( in, 0, SEEK_END );
lseek(in, 0, SEEK_SET); lseek( in, 0, SEEK_SET );
input = (unsigned char *)malloc(size); input = ( unsigned char* )malloc( size );
if (!input) { if ( !input ) {
fprintf(stderr, "%s: out of memory\n", argv[0]); fprintf( stderr, "%s: out of memory\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
if (read(in, input, size) != size) { if ( read( in, input, size ) != size ) {
perror("read"); perror( "read" );
exit(1); exit( 1 );
} }
close(in); close( in );
memory = malloc(size >> 1); memory = malloc( size >> 1 );
if (!memory) { if ( !memory ) {
fprintf(stderr, "%s: out of memory\n", argv[0]); fprintf( stderr, "%s: out of memory\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
p = input; p = input;
for (i = 0; i < (size >> 1); i++) { for ( i = 0; i < ( size >> 1 ); i++ ) {
if ('0' <= *p && *p <= '9') if ( '0' <= *p && *p <= '9' )
memory[i] = (*p - '0') << 0; memory[ i ] = ( *p - '0' ) << 0;
else if ('a' <= *p && *p <= 'f') else if ( 'a' <= *p && *p <= 'f' )
memory[i] = (*p - 'a' + 10) << 0; memory[ i ] = ( *p - 'a' + 10 ) << 0;
else if ('A' <= *p && *p <= 'F') else if ( 'A' <= *p && *p <= 'F' )
memory[i] = (*p - 'A' + 10) << 0; memory[ i ] = ( *p - 'A' + 10 ) << 0;
else { else {
fprintf(stderr, "%s: parse error at byte %d\n", fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
argv[0], i); exit( 1 );
exit(1);
} }
p++; p++;
if ('0' <= *p && *p <= '9') if ( '0' <= *p && *p <= '9' )
memory[i] |= (*p - '0') << 4; memory[ i ] |= ( *p - '0' ) << 4;
else if ('a' <= *p && *p <= 'f') else if ( 'a' <= *p && *p <= 'f' )
memory[i] |= (*p - 'a' + 10) << 4; memory[ i ] |= ( *p - 'a' + 10 ) << 4;
else if ('A' <= *p && *p <= 'F') else if ( 'A' <= *p && *p <= 'F' )
memory[i] |= (*p - 'A' + 10) << 4; memory[ i ] |= ( *p - 'A' + 10 ) << 4;
else { else {
fprintf(stderr, "%s: parse error at byte %d\n", fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
argv[0], i); exit( 1 );
exit(1);
} }
p++; p++;
} }
write(out, memory, size >> 1); write( out, memory, size >> 1 );
close(out); close( out );
return 0; return 0;
} }

View file

@ -26,92 +26,89 @@
#include <ctype.h> #include <ctype.h>
#include <netinet/in.h> #include <netinet/in.h>
int int main( int argc, char** argv )
main(int argc, char **argv)
{ {
unsigned char *input, *p; unsigned char *input, *p;
unsigned char *memory = NULL; unsigned char* memory = NULL;
size_t size; size_t size;
int in, out; int in, out;
int i; int i;
if (argc < 3) { if ( argc < 3 ) {
fprintf(stderr, "usage: %s <infile> <outfile>\n", argv[0]); fprintf( stderr, "usage: %s <infile> <outfile>\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
if (!strcmp(argv[1], "-")) if ( !strcmp( argv[ 1 ], "-" ) )
in = 0; in = 0;
else { else {
in = open(argv[1], O_RDONLY); in = open( argv[ 1 ], O_RDONLY );
if (in < 0) { if ( in < 0 ) {
perror(argv[1]); perror( argv[ 1 ] );
exit(1); exit( 1 );
} }
} }
if (!strcmp(argv[2], "-")) if ( !strcmp( argv[ 2 ], "-" ) )
out = 1; out = 1;
else { else {
out = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0666); out = open( argv[ 2 ], O_WRONLY | O_CREAT | O_TRUNC, 0666 );
if (out < 0) { if ( out < 0 ) {
perror(argv[2]); perror( argv[ 2 ] );
exit(1); exit( 1 );
} }
} }
size = lseek(in, 0, SEEK_END); size = lseek( in, 0, SEEK_END );
lseek(in, 0, SEEK_SET); lseek( in, 0, SEEK_SET );
input = (unsigned char *)malloc(size); input = ( unsigned char* )malloc( size );
if (!input) { if ( !input ) {
fprintf(stderr, "%s: out of memory\n", argv[0]); fprintf( stderr, "%s: out of memory\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
if (read(in, input, size) != size) { if ( read( in, input, size ) != size ) {
perror("read"); perror( "read" );
exit(1); exit( 1 );
} }
close(in); close( in );
memory = malloc(size >> 1); memory = malloc( size >> 1 );
if (!memory) { if ( !memory ) {
fprintf(stderr, "%s: out of memory\n", argv[0]); fprintf( stderr, "%s: out of memory\n", argv[ 0 ] );
exit(1); exit( 1 );
} }
p = input; p = input;
for (i = 0; i < (size >> 1); i++) { for ( i = 0; i < ( size >> 1 ); i++ ) {
if ('0' <= *p && *p <= '9') if ( '0' <= *p && *p <= '9' )
memory[(i & ~3) + 3 - (i & 3)] = (*p - '0') << 0; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] = ( *p - '0' ) << 0;
else if ('a' <= *p && *p <= 'f') else if ( 'a' <= *p && *p <= 'f' )
memory[(i & ~3) + 3 - (i & 3)] = (*p - 'a' + 10) << 0; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] = ( *p - 'a' + 10 ) << 0;
else if ('A' <= *p && *p <= 'F') else if ( 'A' <= *p && *p <= 'F' )
memory[(i & ~3) + 3 - (i & 3)] = (*p - 'A' + 10) << 0; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] = ( *p - 'A' + 10 ) << 0;
else { else {
fprintf(stderr, "%s: parse error at byte %d\n", fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
argv[0], i); exit( 1 );
exit(1);
} }
p++; p++;
if ('0' <= *p && *p <= '9') if ( '0' <= *p && *p <= '9' )
memory[(i & ~3) + 3 - (i & 3)] |= (*p - '0') << 4; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] |= ( *p - '0' ) << 4;
else if ('a' <= *p && *p <= 'f') else if ( 'a' <= *p && *p <= 'f' )
memory[(i & ~3) + 3 - (i & 3)] |= (*p - 'a' + 10) << 4; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] |= ( *p - 'a' + 10 ) << 4;
else if ('A' <= *p && *p <= 'F') else if ( 'A' <= *p && *p <= 'F' )
memory[(i & ~3) + 3 - (i & 3)] |= (*p - 'A' + 10) << 4; memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] |= ( *p - 'A' + 10 ) << 4;
else { else {
fprintf(stderr, "%s: parse error at byte %d\n", fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
argv[0], i); exit( 1 );
exit(1);
} }
p++; p++;
} }
write(out, memory, size >> 1); write( out, memory, size >> 1 );
close(out); close( out );
return 0; return 0;
} }

View file

@ -3,10 +3,10 @@
#include <stddef.h> #include <stddef.h>
static inline void prefetch(const void *x) {;} static inline void prefetch( const void* x ) { ; }
#ifndef offsetof #ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) # define offsetof( TYPE, MEMBER ) ( ( size_t )&( ( TYPE* )0 )->MEMBER )
#endif #endif
/* /*
@ -14,8 +14,8 @@ static inline void prefetch(const void *x) {;}
* under normal circumstances, used to verify that nobody uses * under normal circumstances, used to verify that nobody uses
* non-initialized list entries. * non-initialized list entries.
*/ */
#define LIST_POISON1 ((void *) 0x00100100) #define LIST_POISON1 ( ( void* )0x00100100 )
#define LIST_POISON2 ((void *) 0x00200200) #define LIST_POISON2 ( ( void* )0x00200200 )
/* /*
* Simple doubly linked list implementation. * Simple doubly linked list implementation.
@ -31,14 +31,15 @@ struct list_head {
struct list_head *next, *prev; struct list_head *next, *prev;
}; };
#define LIST_HEAD_INIT(name) { &(name), &(name) } #define LIST_HEAD_INIT( name ) { &( name ), &( name ) }
#define LIST_HEAD(name) \ #define LIST_HEAD( name ) struct list_head name = LIST_HEAD_INIT( name )
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \ #define INIT_LIST_HEAD( ptr ) \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \ do { \
} while (0) ( ptr )->next = ( ptr ); \
( ptr )->prev = ( ptr ); \
} while ( 0 )
/* /*
* Insert a new entry between two known consecutive entries. * Insert a new entry between two known consecutive entries.
@ -46,9 +47,7 @@ struct list_head {
* This is only for internal list manipulation where we know * This is only for internal list manipulation where we know
* the prev/next entries already! * the prev/next entries already!
*/ */
static inline void __list_add(struct list_head *new, static inline void __list_add( struct list_head* new, struct list_head* prev, struct list_head* next )
struct list_head *prev,
struct list_head *next)
{ {
next->prev = new; next->prev = new;
new->next = next; new->next = next;
@ -64,10 +63,7 @@ static inline void __list_add(struct list_head *new,
* Insert a new entry after the specified head. * Insert a new entry after the specified head.
* This is good for implementing stacks. * This is good for implementing stacks.
*/ */
static inline void list_add(struct list_head *new, struct list_head *head) static inline void list_add( struct list_head* new, struct list_head* head ) { __list_add( new, head, head->next ); }
{
__list_add(new, head, head->next);
}
/** /**
* list_add_tail - add a new entry * list_add_tail - add a new entry
@ -77,10 +73,7 @@ static inline void list_add(struct list_head *new, struct list_head *head)
* Insert a new entry before the specified head. * Insert a new entry before the specified head.
* This is useful for implementing queues. * This is useful for implementing queues.
*/ */
static inline void list_add_tail(struct list_head *new, struct list_head *head) static inline void list_add_tail( struct list_head* new, struct list_head* head ) { __list_add( new, head->prev, head ); }
{
__list_add(new, head->prev, head);
}
/* /*
* Delete a list entry by making the prev/next entries * Delete a list entry by making the prev/next entries
@ -89,7 +82,7 @@ static inline void list_add_tail(struct list_head *new, struct list_head *head)
* This is only for internal list manipulation where we know * This is only for internal list manipulation where we know
* the prev/next entries already! * the prev/next entries already!
*/ */
static inline void __list_del(struct list_head * prev, struct list_head * next) static inline void __list_del( struct list_head* prev, struct list_head* next )
{ {
next->prev = prev; next->prev = prev;
prev->next = next; prev->next = next;
@ -101,9 +94,9 @@ static inline void __list_del(struct list_head * prev, struct list_head * next)
* Note: list_empty on entry does not return true after this, the entry is * Note: list_empty on entry does not return true after this, the entry is
* in an undefined state. * in an undefined state.
*/ */
static inline void list_del(struct list_head *entry) static inline void list_del( struct list_head* entry )
{ {
__list_del(entry->prev, entry->next); __list_del( entry->prev, entry->next );
entry->next = LIST_POISON1; entry->next = LIST_POISON1;
entry->prev = LIST_POISON2; entry->prev = LIST_POISON2;
} }
@ -112,10 +105,10 @@ static inline void list_del(struct list_head *entry)
* list_del_init - deletes entry from list and reinitialize it. * list_del_init - deletes entry from list and reinitialize it.
* @entry: the element to delete from the list. * @entry: the element to delete from the list.
*/ */
static inline void list_del_init(struct list_head *entry) static inline void list_del_init( struct list_head* entry )
{ {
__list_del(entry->prev, entry->next); __list_del( entry->prev, entry->next );
INIT_LIST_HEAD(entry); INIT_LIST_HEAD( entry );
} }
/** /**
@ -123,10 +116,10 @@ static inline void list_del_init(struct list_head *entry)
* @list: the entry to move * @list: the entry to move
* @head: the head that will precede our entry * @head: the head that will precede our entry
*/ */
static inline void list_move(struct list_head *list, struct list_head *head) static inline void list_move( struct list_head* list, struct list_head* head )
{ {
__list_del(list->prev, list->next); __list_del( list->prev, list->next );
list_add(list, head); list_add( list, head );
} }
/** /**
@ -134,21 +127,17 @@ static inline void list_move(struct list_head *list, struct list_head *head)
* @list: the entry to move * @list: the entry to move
* @head: the head that will follow our entry * @head: the head that will follow our entry
*/ */
static inline void list_move_tail(struct list_head *list, static inline void list_move_tail( struct list_head* list, struct list_head* head )
struct list_head *head)
{ {
__list_del(list->prev, list->next); __list_del( list->prev, list->next );
list_add_tail(list, head); list_add_tail( list, head );
} }
/** /**
* list_empty - tests whether a list is empty * list_empty - tests whether a list is empty
* @head: the list to test. * @head: the list to test.
*/ */
static inline int list_empty(const struct list_head *head) static inline int list_empty( const struct list_head* head ) { return head->next == head; }
{
return head->next == head;
}
/** /**
* list_empty_careful - tests whether a list is * list_empty_careful - tests whether a list is
@ -162,18 +151,17 @@ static inline int list_empty(const struct list_head *head)
* *
* @head: the list to test. * @head: the list to test.
*/ */
static inline int list_empty_careful(const struct list_head *head) static inline int list_empty_careful( const struct list_head* head )
{ {
struct list_head *next = head->next; struct list_head* next = head->next;
return (next == head) && (next == head->prev); return ( next == head ) && ( next == head->prev );
} }
static inline void __list_splice(struct list_head *list, static inline void __list_splice( struct list_head* list, struct list_head* head )
struct list_head *head)
{ {
struct list_head *first = list->next; struct list_head* first = list->next;
struct list_head *last = list->prev; struct list_head* last = list->prev;
struct list_head *at = head->next; struct list_head* at = head->next;
first->prev = head; first->prev = head;
head->next = first; head->next = first;
@ -187,10 +175,10 @@ static inline void __list_splice(struct list_head *list,
* @list: the new list to add. * @list: the new list to add.
* @head: the place to add it in the first list. * @head: the place to add it in the first list.
*/ */
static inline void list_splice(struct list_head *list, struct list_head *head) static inline void list_splice( struct list_head* list, struct list_head* head )
{ {
if (!list_empty(list)) if ( !list_empty( list ) )
__list_splice(list, head); __list_splice( list, head );
} }
/** /**
@ -200,12 +188,11 @@ static inline void list_splice(struct list_head *list, struct list_head *head)
* *
* The list at @list is reinitialised * The list at @list is reinitialised
*/ */
static inline void list_splice_init(struct list_head *list, static inline void list_splice_init( struct list_head* list, struct list_head* head )
struct list_head *head)
{ {
if (!list_empty(list)) { if ( !list_empty( list ) ) {
__list_splice(list, head); __list_splice( list, head );
INIT_LIST_HEAD(list); INIT_LIST_HEAD( list );
} }
} }
@ -215,17 +202,14 @@ static inline void list_splice_init(struct list_head *list,
* @type: the type of the struct this is embedded in. * @type: the type of the struct this is embedded in.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_entry(ptr, type, member) \ #define list_entry( ptr, type, member ) container_of( ptr, type, member )
container_of(ptr, type, member)
/** /**
* list_for_each - iterate over a list * list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop counter. * @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each(pos, head) \ #define list_for_each( pos, head ) for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = pos->next )
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
pos = pos->next)
/** /**
* __list_for_each - iterate over a list * __list_for_each - iterate over a list
@ -237,17 +221,14 @@ static inline void list_splice_init(struct list_head *list,
* Use this for code that knows the list to be very short (empty * Use this for code that knows the list to be very short (empty
* or 1 entry) most of the time. * or 1 entry) most of the time.
*/ */
#define __list_for_each(pos, head) \ #define __list_for_each( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = pos->next )
for (pos = (head)->next; pos != (head); pos = pos->next)
/** /**
* list_for_each_prev - iterate over a list backwards * list_for_each_prev - iterate over a list backwards
* @pos: the &struct list_head to use as a loop counter. * @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each_prev(pos, head) \ #define list_for_each_prev( pos, head ) for ( pos = ( head )->prev; prefetch( pos->prev ), pos != ( head ); pos = pos->prev )
for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
pos = pos->prev)
/** /**
* list_for_each_safe - iterate over a list safe against removal of list entry * list_for_each_safe - iterate over a list safe against removal of list entry
@ -255,9 +236,7 @@ static inline void list_splice_init(struct list_head *list,
* @n: another &struct list_head to use as temporary storage * @n: another &struct list_head to use as temporary storage
* @head: the head for your list. * @head: the head for your list.
*/ */
#define list_for_each_safe(pos, n, head) \ #define list_for_each_safe( pos, n, head ) for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = n, n = pos->next )
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
/** /**
* list_for_each_entry - iterate over list of given type * list_for_each_entry - iterate over list of given type
@ -265,10 +244,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry(pos, head, member) \ #define list_for_each_entry( pos, head, member ) \
for (pos = list_entry((head)->next, typeof(*pos), member); \ for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
prefetch(pos->member.next), &pos->member != (head); \ pos = list_entry( pos->member.next, typeof( *pos ), member ) )
pos = list_entry(pos->member.next, typeof(*pos), member))
/** /**
* list_for_each_entry_reverse - iterate backwards over list of given type. * list_for_each_entry_reverse - iterate backwards over list of given type.
@ -276,10 +254,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_reverse(pos, head, member) \ #define list_for_each_entry_reverse( pos, head, member ) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \ for ( pos = list_entry( ( head )->prev, typeof( *pos ), member ); prefetch( pos->member.prev ), &pos->member != ( head ); \
prefetch(pos->member.prev), &pos->member != (head); \ pos = list_entry( pos->member.prev, typeof( *pos ), member ) )
pos = list_entry(pos->member.prev, typeof(*pos), member))
/** /**
* list_prepare_entry - prepare a pos entry for use as a start point in * list_prepare_entry - prepare a pos entry for use as a start point in
@ -288,8 +265,7 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head of the list * @head: the head of the list
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_prepare_entry(pos, head, member) \ #define list_prepare_entry( pos, head, member ) ( ( pos ) ?: list_entry( head, typeof( *pos ), member ) )
((pos) ? : list_entry(head, typeof(*pos), member))
/** /**
* list_for_each_entry_continue - iterate over list of given type * list_for_each_entry_continue - iterate over list of given type
@ -298,10 +274,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_continue(pos, head, member) \ #define list_for_each_entry_continue( pos, head, member ) \
for (pos = list_entry(pos->member.next, typeof(*pos), member); \ for ( pos = list_entry( pos->member.next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
prefetch(pos->member.next), &pos->member != (head); \ pos = list_entry( pos->member.next, typeof( *pos ), member ) )
pos = list_entry(pos->member.next, typeof(*pos), member))
/** /**
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@ -310,11 +285,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_safe(pos, n, head, member) \ #define list_for_each_entry_safe( pos, n, head, member ) \
for (pos = list_entry((head)->next, typeof(*pos), member), \ for ( pos = list_entry( ( head )->next, typeof( *pos ), member ), n = list_entry( pos->member.next, typeof( *pos ), member ); \
n = list_entry(pos->member.next, typeof(*pos), member); \ &pos->member != ( head ); pos = n, n = list_entry( n->member.next, typeof( *n ), member ) )
&pos->member != (head); \
pos = n, n = list_entry(n->member.next, typeof(*n), member))
/** /**
* list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry. * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry.
@ -323,11 +296,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the list_struct within the struct. * @member: the name of the list_struct within the struct.
*/ */
#define list_for_each_entry_safe_reverse(pos, n, head, member) \ #define list_for_each_entry_safe_reverse( pos, n, head, member ) \
for (pos = list_entry((head)->prev, typeof(*pos), member), \ for ( pos = list_entry( ( head )->prev, typeof( *pos ), member ), n = list_entry( pos->member.prev, typeof( *pos ), member ); \
n = list_entry(pos->member.prev, typeof(*pos), member); \ prefetch( pos->member.prev ), &pos->member != ( head ); pos = n, n = list_entry( n->member.prev, typeof( *n ), member ) )
prefetch(pos->member.prev), &pos->member != (head); \
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
/** /**
* list_for_each_rcu - iterate over an rcu-protected list * list_for_each_rcu - iterate over an rcu-protected list
@ -338,13 +309,10 @@ static inline void list_splice_init(struct list_head *list,
* the _rcu list-mutation primitives such as list_add_rcu() * the _rcu list-mutation primitives such as list_add_rcu()
* as long as the traversal is guarded by rcu_read_lock(). * as long as the traversal is guarded by rcu_read_lock().
*/ */
#define list_for_each_rcu(pos, head) \ #define list_for_each_rcu( pos, head ) \
for (pos = (head)->next; prefetch(pos->next), pos != (head); \ for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = rcu_dereference( pos->next ) )
pos = rcu_dereference(pos->next))
#define __list_for_each_rcu(pos, head) \ #define __list_for_each_rcu( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = rcu_dereference( pos->next ) )
for (pos = (head)->next; pos != (head); \
pos = rcu_dereference(pos->next))
/** /**
* list_for_each_safe_rcu - iterate over an rcu-protected list safe * list_for_each_safe_rcu - iterate over an rcu-protected list safe
@ -357,9 +325,8 @@ static inline void list_splice_init(struct list_head *list,
* the _rcu list-mutation primitives such as list_add_rcu() * the _rcu list-mutation primitives such as list_add_rcu()
* as long as the traversal is guarded by rcu_read_lock(). * as long as the traversal is guarded by rcu_read_lock().
*/ */
#define list_for_each_safe_rcu(pos, n, head) \ #define list_for_each_safe_rcu( pos, n, head ) \
for (pos = (head)->next, n = pos->next; pos != (head); \ for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = rcu_dereference( n ), n = pos->next )
pos = rcu_dereference(n), n = pos->next)
/** /**
* list_for_each_entry_rcu - iterate over rcu list of given type * list_for_each_entry_rcu - iterate over rcu list of given type
@ -371,12 +338,9 @@ static inline void list_splice_init(struct list_head *list,
* the _rcu list-mutation primitives such as list_add_rcu() * the _rcu list-mutation primitives such as list_add_rcu()
* as long as the traversal is guarded by rcu_read_lock(). * as long as the traversal is guarded by rcu_read_lock().
*/ */
#define list_for_each_entry_rcu(pos, head, member) \ #define list_for_each_entry_rcu( pos, head, member ) \
for (pos = list_entry((head)->next, typeof(*pos), member); \ for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
prefetch(pos->member.next), &pos->member != (head); \ pos = rcu_dereference( list_entry( pos->member.next, typeof( *pos ), member ) ) )
pos = rcu_dereference(list_entry(pos->member.next, \
typeof(*pos), member)))
/** /**
* list_for_each_continue_rcu - iterate over an rcu-protected list * list_for_each_continue_rcu - iterate over an rcu-protected list
@ -388,9 +352,8 @@ static inline void list_splice_init(struct list_head *list,
* the _rcu list-mutation primitives such as list_add_rcu() * the _rcu list-mutation primitives such as list_add_rcu()
* as long as the traversal is guarded by rcu_read_lock(). * as long as the traversal is guarded by rcu_read_lock().
*/ */
#define list_for_each_continue_rcu(pos, head) \ #define list_for_each_continue_rcu( pos, head ) \
for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \ for ( ( pos ) = ( pos )->next; prefetch( ( pos )->next ), ( pos ) != ( head ); ( pos ) = rcu_dereference( ( pos )->next ) )
(pos) = rcu_dereference((pos)->next))
/* /*
* Double linked lists with a single pointer list head. * Double linked lists with a single pointer list head.
@ -400,7 +363,7 @@ static inline void list_splice_init(struct list_head *list,
*/ */
struct hlist_head { struct hlist_head {
struct hlist_node *first; struct hlist_node* first;
}; };
struct hlist_node { struct hlist_node {
@ -408,32 +371,26 @@ struct hlist_node {
}; };
#define HLIST_HEAD_INIT { .first = NULL } #define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL } #define HLIST_HEAD( name ) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL) #define INIT_HLIST_HEAD( ptr ) ( ( ptr )->first = NULL )
#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL) #define INIT_HLIST_NODE( ptr ) ( ( ptr )->next = NULL, ( ptr )->pprev = NULL )
static inline int hlist_unhashed(const struct hlist_node *h) static inline int hlist_unhashed( const struct hlist_node* h ) { return !h->pprev; }
{
return !h->pprev;
}
static inline int hlist_empty(const struct hlist_head *h) static inline int hlist_empty( const struct hlist_head* h ) { return !h->first; }
{
return !h->first;
}
static inline void __hlist_del(struct hlist_node *n) static inline void __hlist_del( struct hlist_node* n )
{ {
struct hlist_node *next = n->next; struct hlist_node* next = n->next;
struct hlist_node **pprev = n->pprev; struct hlist_node** pprev = n->pprev;
*pprev = next; *pprev = next;
if (next) if ( next )
next->pprev = pprev; next->pprev = pprev;
} }
static inline void hlist_del(struct hlist_node *n) static inline void hlist_del( struct hlist_node* n )
{ {
__hlist_del(n); __hlist_del( n );
n->next = LIST_POISON1; n->next = LIST_POISON1;
n->pprev = LIST_POISON2; n->pprev = LIST_POISON2;
} }
@ -457,64 +414,71 @@ static inline void hlist_del(struct hlist_node *n)
* the _rcu list-traversal primitives, such as * the _rcu list-traversal primitives, such as
* hlist_for_each_entry(). * hlist_for_each_entry().
*/ */
static inline void hlist_del_rcu(struct hlist_node *n) static inline void hlist_del_rcu( struct hlist_node* n )
{ {
__hlist_del(n); __hlist_del( n );
n->pprev = LIST_POISON2; n->pprev = LIST_POISON2;
} }
static inline void hlist_del_init(struct hlist_node *n) static inline void hlist_del_init( struct hlist_node* n )
{ {
if (n->pprev) { if ( n->pprev ) {
__hlist_del(n); __hlist_del( n );
INIT_HLIST_NODE(n); INIT_HLIST_NODE( n );
} }
} }
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h) static inline void hlist_add_head( struct hlist_node* n, struct hlist_head* h )
{ {
struct hlist_node *first = h->first; struct hlist_node* first = h->first;
n->next = first; n->next = first;
if (first) if ( first )
first->pprev = &n->next; first->pprev = &n->next;
h->first = n; h->first = n;
n->pprev = &h->first; n->pprev = &h->first;
} }
/* next must be != NULL */ /* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n, static inline void hlist_add_before( struct hlist_node* n, struct hlist_node* next )
struct hlist_node *next)
{ {
n->pprev = next->pprev; n->pprev = next->pprev;
n->next = next; n->next = next;
next->pprev = &n->next; next->pprev = &n->next;
*(n->pprev) = n; *( n->pprev ) = n;
} }
static inline void hlist_add_after(struct hlist_node *n, static inline void hlist_add_after( struct hlist_node* n, struct hlist_node* next )
struct hlist_node *next)
{ {
next->next = n->next; next->next = n->next;
n->next = next; n->next = next;
next->pprev = &n->next; next->pprev = &n->next;
if(next->next) if ( next->next )
next->next->pprev = &next->next; next->next->pprev = &next->next;
} }
#define hlist_entry(ptr, type, member) container_of(ptr,type,member) #define hlist_entry( ptr, type, member ) container_of( ptr, type, member )
#define hlist_for_each(pos, head) \ #define hlist_for_each( pos, head ) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \ for ( pos = ( head )->first; pos && ( { \
pos = pos->next) prefetch( pos->next ); \
1; \
} ); \
pos = pos->next )
#define hlist_for_each_safe(pos, n, head) \ #define hlist_for_each_safe( pos, n, head ) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \ for ( pos = ( head )->first; pos && ( { \
pos = n) n = pos->next; \
1; \
} ); \
pos = n )
#define hlist_for_each_rcu(pos, head) \ #define hlist_for_each_rcu( pos, head ) \
for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \ for ( ( pos ) = ( head )->first; pos && ( { \
(pos) = rcu_dereference((pos)->next)) prefetch( ( pos )->next ); \
1; \
} ); \
( pos ) = rcu_dereference( ( pos )->next ) )
/** /**
* hlist_for_each_entry - iterate over list of given type * hlist_for_each_entry - iterate over list of given type
@ -523,11 +487,16 @@ static inline void hlist_add_after(struct hlist_node *n,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the hlist_node within the struct. * @member: the name of the hlist_node within the struct.
*/ */
#define hlist_for_each_entry(tpos, pos, head, member) \ #define hlist_for_each_entry( tpos, pos, head, member ) \
for (pos = (head)->first; \ for ( pos = ( head )->first; pos && ( { \
pos && ({ prefetch(pos->next); 1;}) && \ prefetch( pos->next ); \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 1; \
pos = pos->next) } ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = pos->next )
/** /**
* hlist_for_each_entry_continue - iterate over a hlist continuing after existing point * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
@ -535,11 +504,16 @@ static inline void hlist_add_after(struct hlist_node *n,
* @pos: the &struct hlist_node to use as a loop counter. * @pos: the &struct hlist_node to use as a loop counter.
* @member: the name of the hlist_node within the struct. * @member: the name of the hlist_node within the struct.
*/ */
#define hlist_for_each_entry_continue(tpos, pos, member) \ #define hlist_for_each_entry_continue( tpos, pos, member ) \
for (pos = (pos)->next; \ for ( pos = ( pos )->next; pos && ( { \
pos && ({ prefetch(pos->next); 1;}) && \ prefetch( pos->next ); \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 1; \
pos = pos->next) } ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = pos->next )
/** /**
* hlist_for_each_entry_from - iterate over a hlist continuing from existing point * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
@ -547,10 +521,16 @@ static inline void hlist_add_after(struct hlist_node *n,
* @pos: the &struct hlist_node to use as a loop counter. * @pos: the &struct hlist_node to use as a loop counter.
* @member: the name of the hlist_node within the struct. * @member: the name of the hlist_node within the struct.
*/ */
#define hlist_for_each_entry_from(tpos, pos, member) \ #define hlist_for_each_entry_from( tpos, pos, member ) \
for (; pos && ({ prefetch(pos->next); 1;}) && \ for ( ; pos && ( { \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ prefetch( pos->next ); \
pos = pos->next) 1; \
} ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = pos->next )
/** /**
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
@ -560,11 +540,16 @@ static inline void hlist_add_after(struct hlist_node *n,
* @head: the head for your list. * @head: the head for your list.
* @member: the name of the hlist_node within the struct. * @member: the name of the hlist_node within the struct.
*/ */
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ #define hlist_for_each_entry_safe( tpos, pos, n, head, member ) \
for (pos = (head)->first; \ for ( pos = ( head )->first; pos && ( { \
pos && ({ n = pos->next; 1; }) && \ n = pos->next; \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 1; \
pos = n) } ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = n )
/** /**
* hlist_for_each_entry_rcu - iterate over rcu list of given type * hlist_for_each_entry_rcu - iterate over rcu list of given type
@ -577,10 +562,15 @@ static inline void hlist_add_after(struct hlist_node *n,
* the _rcu list-mutation primitives such as hlist_add_head_rcu() * the _rcu list-mutation primitives such as hlist_add_head_rcu()
* as long as the traversal is guarded by rcu_read_lock(). * as long as the traversal is guarded by rcu_read_lock().
*/ */
#define hlist_for_each_entry_rcu(tpos, pos, head, member) \ #define hlist_for_each_entry_rcu( tpos, pos, head, member ) \
for (pos = (head)->first; \ for ( pos = ( head )->first; pos && ( { \
pos && ({ prefetch(pos->next); 1;}) && \ prefetch( pos->next ); \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \ 1; \
pos = rcu_dereference(pos->next)) } ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = rcu_dereference( pos->next ) )
#endif /* _LINUX_LIST_H */ #endif /* _LINUX_LIST_H */

View file

@ -26,154 +26,125 @@
#include "gdbstub.h" #include "gdbstub.h"
static x49gp_t *x49gp; static x49gp_t* x49gp;
/* LD TEMPO HACK */ /* LD TEMPO HACK */
CPUState *__GLOBAL_env; CPUState* __GLOBAL_env;
int semihosting_enabled = 1; int semihosting_enabled = 1;
uint8_t *phys_ram_base; uint8_t* phys_ram_base;
int phys_ram_size; int phys_ram_size;
ram_addr_t ram_size = 0x80000; // LD ??? ram_addr_t ram_size = 0x80000; // LD ???
/* vl.c */ /* vl.c */
int singlestep; int singlestep;
#if !(defined(__APPLE__) || defined(_POSIX_C_SOURCE) && !defined(__sun__)) #if !( defined( __APPLE__ ) || defined( _POSIX_C_SOURCE ) && !defined( __sun__ ) )
static void *oom_check(void *ptr) static void* oom_check( void* ptr )
{ {
if (ptr == NULL) { if ( ptr == NULL ) {
abort(); abort();
} }
return ptr; return ptr;
} }
#endif #endif
void *qemu_memalign(size_t alignment, size_t size) void* qemu_memalign( size_t alignment, size_t size )
{ {
#if defined(__APPLE__) || defined(_POSIX_C_SOURCE) && !defined(__sun__) #if defined( __APPLE__ ) || defined( _POSIX_C_SOURCE ) && !defined( __sun__ )
int ret; int ret;
void *ptr; void* ptr;
ret = posix_memalign(&ptr, alignment, size); ret = posix_memalign( &ptr, alignment, size );
if (ret != 0) if ( ret != 0 )
abort(); abort();
return ptr; return ptr;
#elif defined(CONFIG_BSD) #elif defined( CONFIG_BSD )
return oom_check(valloc(size)); return oom_check( valloc( size ) );
#else #else
return oom_check(memalign(alignment, size)); return oom_check( memalign( alignment, size ) );
#endif #endif
} }
void qemu_init_vcpu( void* _env )
void qemu_init_vcpu(void *_env)
{ {
CPUState *env = _env; CPUState* env = _env;
env->nr_cores = 1; env->nr_cores = 1;
env->nr_threads = 1; env->nr_threads = 1;
} }
int qemu_cpu_self(void *env) int qemu_cpu_self( void* env ) { return 1; }
{
return 1;
}
void qemu_cpu_kick(void *env) void qemu_cpu_kick( void* env ) {}
{
}
void armv7m_nvic_set_pending(void *opaque, int irq) void armv7m_nvic_set_pending( void* opaque, int irq ) { abort(); }
{ int armv7m_nvic_acknowledge_irq( void* opaque ) { abort(); }
abort(); void armv7m_nvic_complete_irq( void* opaque, int irq ) { abort(); }
}
int armv7m_nvic_acknowledge_irq(void *opaque)
{
abort();
}
void armv7m_nvic_complete_irq(void *opaque, int irq)
{
abort();
}
void * void* qemu_malloc( size_t size ) { return malloc( size ); }
qemu_malloc(size_t size)
{
return malloc(size);
}
void * void* qemu_mallocz( size_t size )
qemu_mallocz(size_t size)
{ {
void *ptr; void* ptr;
ptr = qemu_malloc(size); ptr = qemu_malloc( size );
if (NULL == ptr) if ( NULL == ptr )
return NULL; return NULL;
memset(ptr, 0, size); memset( ptr, 0, size );
return ptr; return ptr;
} }
void void qemu_free( void* ptr ) { free( ptr ); }
qemu_free(void *ptr)
{
free(ptr);
}
void * void* qemu_vmalloc( size_t size )
qemu_vmalloc(size_t size)
{ {
#if defined(__linux__) #if defined( __linux__ )
void *mem; void* mem;
if (0 == posix_memalign(&mem, sysconf(_SC_PAGE_SIZE), size)) if ( 0 == posix_memalign( &mem, sysconf( _SC_PAGE_SIZE ), size ) )
return mem; return mem;
return NULL; return NULL;
#else #else
return valloc(size); return valloc( size );
#endif #endif
} }
#define SWI_Breakpoint 0x180000 #define SWI_Breakpoint 0x180000
uint32_t uint32_t do_arm_semihosting( CPUState* env )
do_arm_semihosting(CPUState *env)
{ {
uint32_t number; uint32_t number;
if (env->thumb) { if ( env->thumb ) {
number = lduw_code(env->regs[15] - 2) & 0xff; number = lduw_code( env->regs[ 15 ] - 2 ) & 0xff;
} else { } else {
number = ldl_code(env->regs[15] - 4) & 0xffffff; number = ldl_code( env->regs[ 15 ] - 4 ) & 0xffffff;
} }
switch (number) { switch ( number ) {
case SWI_Breakpoint: case SWI_Breakpoint:
break; break;
case 0: case 0:
#ifdef DEBUG_X49GP_SYSCALL #ifdef DEBUG_X49GP_SYSCALL
printf("%s: SWI LR %08x: syscall %u: args %08x %08x %08x %08x %08x %08x %08x\n", printf( "%s: SWI LR %08x: syscall %u: args %08x %08x %08x %08x %08x %08x %08x\n", __FUNCTION__, env->regs[ 14 ], env->regs[ 0 ],
__FUNCTION__, env->regs[14], env->regs[0], env->regs[ 1 ], env->regs[ 2 ], env->regs[ 3 ], env->regs[ 4 ], env->regs[ 5 ], env->regs[ 6 ], env->regs[ 7 ] );
env->regs[1], env->regs[2], env->regs[3],
env->regs[4], env->regs[5], env->regs[6],
env->regs[7]);
#endif #endif
#if 1 #if 1
switch (env->regs[0]) { switch ( env->regs[ 0 ] ) {
case 305: /* Beep */ case 305: /* Beep */
printf("%s: BEEP: frequency %u, time %u, override %u\n", printf( "%s: BEEP: frequency %u, time %u, override %u\n", __FUNCTION__, env->regs[ 1 ], env->regs[ 2 ],
__FUNCTION__, env->regs[1], env->regs[2], env->regs[3]); env->regs[ 3 ] );
gdk_beep(); gdk_beep();
env->regs[0] = 0; env->regs[ 0 ] = 0;
return 1; return 1;
case 28: /* CheckBeepEnd */ case 28: /* CheckBeepEnd */
env->regs[0] = 0; env->regs[ 0 ] = 0;
return 1; return 1;
case 29: /* StopBeep */ case 29: /* StopBeep */
env->regs[0] = 0; env->regs[ 0 ] = 0;
return 1; return 1;
default: default:
@ -189,73 +160,68 @@ do_arm_semihosting(CPUState *env)
return 0; return 0;
} }
void void x49gp_set_idle( x49gp_t* x49gp, x49gp_arm_idle_t idle )
x49gp_set_idle(x49gp_t *x49gp, x49gp_arm_idle_t idle)
{ {
#ifdef DEBUG_X49GP_ARM_IDLE #ifdef DEBUG_X49GP_ARM_IDLE
if (idle != x49gp->arm_idle) { if ( idle != x49gp->arm_idle ) {
printf("%s: arm_idle %u, idle %u\n", __FUNCTION__, x49gp->arm_idle, idle); printf( "%s: arm_idle %u, idle %u\n", __FUNCTION__, x49gp->arm_idle, idle );
} }
#endif #endif
x49gp->arm_idle = idle; x49gp->arm_idle = idle;
if (x49gp->arm_idle == X49GP_ARM_RUN) { if ( x49gp->arm_idle == X49GP_ARM_RUN ) {
x49gp->env->halted = 0; x49gp->env->halted = 0;
} else { } else {
x49gp->env->halted = 1; x49gp->env->halted = 1;
cpu_exit(x49gp->env); cpu_exit( x49gp->env );
} }
} }
static void static void arm_sighnd( int sig )
arm_sighnd(int sig)
{ {
switch (sig) { switch ( sig ) {
case SIGUSR1: case SIGUSR1:
// stop_simulator = 1; // stop_simulator = 1;
// x49gp->arm->CallDebug ^= 1; // x49gp->arm->CallDebug ^= 1;
break; break;
default: default:
fprintf(stderr, "%s: sig %u\n", __FUNCTION__, sig); fprintf( stderr, "%s: sig %u\n", __FUNCTION__, sig );
break; break;
} }
} }
void void x49gp_gtk_timer( void* data )
x49gp_gtk_timer(void *data)
{ {
while (gtk_events_pending()) { while ( gtk_events_pending() ) {
// printf("%s: gtk_main_iteration_do()\n", __FUNCTION__); // printf("%s: gtk_main_iteration_do()\n", __FUNCTION__);
gtk_main_iteration_do(FALSE); gtk_main_iteration_do( FALSE );
} }
x49gp_mod_timer(x49gp->gtk_timer, x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL );
x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL);
} }
void void x49gp_lcd_timer( void* data )
x49gp_lcd_timer(void *data)
{ {
x49gp_t *x49gp = data; x49gp_t* x49gp = data;
int64_t now, expires; int64_t now, expires;
// printf("%s: lcd_update\n", __FUNCTION__); // printf("%s: lcd_update\n", __FUNCTION__);
x49gp_lcd_update(x49gp); x49gp_lcd_update( x49gp );
gdk_flush(); gdk_flush();
now = x49gp_get_clock(); now = x49gp_get_clock();
expires = now + X49GP_LCD_REFRESH_INTERVAL; expires = now + X49GP_LCD_REFRESH_INTERVAL;
// printf("%s: now: %lld, next update: %lld\n", __FUNCTION__, now, expires); // printf("%s: now: %lld, next update: %lld\n", __FUNCTION__, now, expires);
x49gp_mod_timer(x49gp->lcd_timer, expires); x49gp_mod_timer( x49gp->lcd_timer, expires );
} }
struct options { struct options {
char *config; char* config;
int debug_port; int debug_port;
int start_debugger; int start_debugger;
char *firmware; char* firmware;
x49gp_reinit_t reinit; x49gp_reinit_t reinit;
int more_options; int more_options;
@ -263,69 +229,56 @@ struct options {
struct option_def; struct option_def;
typedef int (*option_action)(struct options *opt, struct option_def *match, typedef int ( *option_action )( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
char *this_opt, char *param, char *progname);
struct option_def { struct option_def {
option_action action; option_action action;
char *longname; char* longname;
char shortname; char shortname;
}; };
static int action_help(struct options *opt, struct option_def *match, static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
char *this_opt, char *param, char *progname); static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_debuglater(struct options *opt, struct option_def *match, static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
char *this_opt, char *param, char *progname); static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_debug(struct options *opt, struct option_def *match, static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
char *this_opt, char *param, char *progname); static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_reinit_flash(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname);
static int action_reinit_flash_full(struct options *opt,
struct option_def *match, char *this_opt,
char *param, char *progname);
static int action_reboot(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname);
static int action_unknown_with_param(struct options *opt, static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
struct option_def *match, char *this_opt, static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
char *param, char *progname); static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
static int action_longopt(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname);
static int action_endopt(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname);
struct option_def option_defs[] = { struct option_def option_defs[] = {
{ action_help, "help", 'h' }, {action_help, "help", 'h' },
{ action_debuglater, "enable-debug", 'D' }, {action_debuglater, "enable-debug", 'D' },
{ action_debug, "debug", 'd' }, {action_debug, "debug", 'd' },
{ action_reinit_flash, "reflash", 'f' }, {action_reinit_flash, "reflash", 'f' },
{ action_reinit_flash_full, "reflash-full", 'F' }, {action_reinit_flash_full, "reflash-full", 'F' },
{ action_reboot, "reboot", 'r' }, {action_reboot, "reboot", 'r' },
{ action_longopt, NULL, '-' }, {action_longopt, NULL, '-' },
{ action_unknown_with_param, NULL, '=' }, {action_unknown_with_param, NULL, '=' },
{ action_endopt, "", '\0' } {action_endopt, "", '\0'}
}; };
static void static void warn_unneeded_param( struct option_def* match, char* this_opt )
warn_unneeded_param(struct option_def *match, char *this_opt)
{ {
if (this_opt[1] == '-') { if ( this_opt[ 1 ] == '-' ) {
fprintf(stderr, "The option \"--%s\" does not support" fprintf( stderr,
" parameters\n", match->longname); "The option \"--%s\" does not support"
" parameters\n",
match->longname );
} else } else
fprintf(stderr, "The option '-%c' does not support parameters\n", fprintf( stderr, "The option '-%c' does not support parameters\n", match->shortname );
match->shortname);
} }
static int static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_help(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
if (param != NULL) if ( param != NULL )
warn_unneeded_param(match, this_opt); warn_unneeded_param( match, this_opt );
fprintf(stderr, "Emulator for HP 49G+ / 50G calculators\n" fprintf( stderr,
"Emulator for HP 49G+ / 50G calculators\n"
"Usage: %s [<options>] [<config-file>]\n" "Usage: %s [<options>] [<config-file>]\n"
"Valid options:\n" "Valid options:\n"
" -D, --enable-debug[=<port] enable the debugger interface\n" " -D, --enable-debug[=<port] enable the debugger interface\n"
@ -353,355 +306,317 @@ action_help(struct options *opt, struct option_def *match, char *this_opt,
" registers, etc.\n" " registers, etc.\n"
"If the config file is omitted, ~/.%s/config is used.\n" "If the config file is omitted, ~/.%s/config is used.\n"
"Please consult the manual for more details on config file" "Please consult the manual for more details on config file"
" settings.\n", progname, DEFAULT_GDBSTUB_PORT, progname); " settings.\n",
exit(0); progname, DEFAULT_GDBSTUB_PORT, progname );
exit( 0 );
} }
static int static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_debuglater(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
char *end; char* end;
int port; int port;
if (param == NULL) { if ( param == NULL ) {
if (opt->debug_port == 0) if ( opt->debug_port == 0 )
opt->debug_port = DEFAULT_GDBSTUB_PORT; opt->debug_port = DEFAULT_GDBSTUB_PORT;
return FALSE; return FALSE;
} }
port = strtoul(param, &end, 0); port = strtoul( param, &end, 0 );
if ((end == param) || (*end != '\0')) { if ( ( end == param ) || ( *end != '\0' ) ) {
fprintf(stderr, "Invalid port \"%s\", using default\n", param); fprintf( stderr, "Invalid port \"%s\", using default\n", param );
if (opt->debug_port == 0) if ( opt->debug_port == 0 )
opt->debug_port = DEFAULT_GDBSTUB_PORT; opt->debug_port = DEFAULT_GDBSTUB_PORT;
return TRUE; return TRUE;
} }
if (opt->debug_port != 0 && opt->debug_port != DEFAULT_GDBSTUB_PORT) if ( opt->debug_port != 0 && opt->debug_port != DEFAULT_GDBSTUB_PORT )
fprintf(stderr, "Additional debug port \"%s\" specified," fprintf( stderr,
" overriding\n", param); "Additional debug port \"%s\" specified,"
" overriding\n",
param );
opt->debug_port = port; opt->debug_port = port;
return TRUE; return TRUE;
} }
static int static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_debug(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
opt->start_debugger = TRUE; opt->start_debugger = TRUE;
return action_debuglater(opt, match, this_opt, param, progname); return action_debuglater( opt, match, this_opt, param, progname );
} }
static int static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_reinit_flash(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname)
{ {
if (opt->reinit < X49GP_REINIT_FLASH) if ( opt->reinit < X49GP_REINIT_FLASH )
opt->reinit = X49GP_REINIT_FLASH; opt->reinit = X49GP_REINIT_FLASH;
if (param == NULL) if ( param == NULL )
return FALSE; return FALSE;
if (opt->firmware != NULL) if ( opt->firmware != NULL )
fprintf(stderr, "Additional firmware file \"%s\" specified," fprintf( stderr,
" overriding\n", param); "Additional firmware file \"%s\" specified,"
" overriding\n",
param );
opt->firmware = param; opt->firmware = param;
return TRUE; return TRUE;
} }
static int static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_reinit_flash_full(struct options *opt,
struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
int result = action_reinit_flash(opt, match, this_opt, param, progname); int result = action_reinit_flash( opt, match, this_opt, param, progname );
opt->reinit = X49GP_REINIT_FLASH_FULL; opt->reinit = X49GP_REINIT_FLASH_FULL;
return result; return result;
} }
static int static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_reboot(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
if (param != NULL) if ( param != NULL )
warn_unneeded_param(match, this_opt); warn_unneeded_param( match, this_opt );
if (opt->reinit < X49GP_REINIT_REBOOT_ONLY) if ( opt->reinit < X49GP_REINIT_REBOOT_ONLY )
opt->reinit = X49GP_REINIT_REBOOT_ONLY; opt->reinit = X49GP_REINIT_REBOOT_ONLY;
return param != NULL; return param != NULL;
} }
static int static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_longopt(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
int i; int i;
char *test_str, *option_str; char *test_str, *option_str;
if (this_opt[1] != '-' || param != NULL) { if ( this_opt[ 1 ] != '-' || param != NULL ) {
fprintf(stderr, "Unrecognized option '-', ignoring\n"); fprintf( stderr, "Unrecognized option '-', ignoring\n" );
return FALSE; return FALSE;
} }
for (i = 0; i < sizeof(option_defs) / sizeof(option_defs[0]); i++) { for ( i = 0; i < sizeof( option_defs ) / sizeof( option_defs[ 0 ] ); i++ ) {
if (option_defs[i].longname == NULL) if ( option_defs[ i ].longname == NULL )
continue; continue;
test_str = option_defs[i].longname; test_str = option_defs[ i ].longname;
option_str = this_opt + 2; option_str = this_opt + 2;
while (*test_str != '\0' && *test_str == *option_str) { while ( *test_str != '\0' && *test_str == *option_str ) {
test_str++; test_str++;
option_str++; option_str++;
} }
if (*test_str != '\0') continue; if ( *test_str != '\0' )
continue;
switch (*option_str) { switch ( *option_str ) {
case '\0': case '\0':
(option_defs[i].action)(opt, option_defs + i, this_opt, ( option_defs[ i ].action )( opt, option_defs + i, this_opt, NULL, progname );
NULL, progname);
return TRUE; return TRUE;
case '=': case '=':
(option_defs[i].action)(opt, option_defs + i, this_opt, ( option_defs[ i ].action )( opt, option_defs + i, this_opt, option_str + 1, progname );
option_str+1, progname);
return TRUE; return TRUE;
} }
} }
fprintf(stderr, "Unrecognized option \"%s\", ignoring\n", this_opt + 2); fprintf( stderr, "Unrecognized option \"%s\", ignoring\n", this_opt + 2 );
return TRUE; return TRUE;
} }
static int static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_unknown_with_param(struct options *opt, struct option_def *match,
char *this_opt, char *param, char *progname)
{ {
return TRUE; return TRUE;
} }
static int static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
action_endopt(struct options *opt, struct option_def *match, char *this_opt,
char *param, char *progname)
{ {
opt->more_options = FALSE; opt->more_options = FALSE;
return TRUE; return TRUE;
} }
static void static void parse_shortopt( struct options* opt, char* this_opt, char* progname )
parse_shortopt(struct options *opt, char *this_opt, char *progname)
{ {
char *option = this_opt + 1; char* option = this_opt + 1;
char *param; char* param;
int i; int i;
if (*option == '\0') { if ( *option == '\0' ) {
fprintf(stderr, fprintf( stderr, "Empty option present, ignoring\n" );
"Empty option present, ignoring\n");
return; return;
} }
do { do {
for (i = 0; i < sizeof(option_defs) / sizeof(option_defs[0]); for ( i = 0; i < sizeof( option_defs ) / sizeof( option_defs[ 0 ] ); i++ ) {
i++) {
if (*option == option_defs[i].shortname) { if ( *option == option_defs[ i ].shortname ) {
if (*(option + 1) == '=') { if ( *( option + 1 ) == '=' ) {
param = option + 2; param = option + 2;
} else { } else {
param = NULL; param = NULL;
} }
if ((option_defs[i].action)(opt, option_defs + i, if ( ( option_defs[ i ].action )( opt, option_defs + i, this_opt, param, progname ) )
this_opt, param,
progname))
return; return;
break; break;
} }
} }
if ( i == sizeof( option_defs ) / sizeof( option_defs[ 0 ] ) )
if (i == sizeof(option_defs) / sizeof(option_defs[0])) fprintf( stderr, "Unrecognized option '%c', ignoring\n", *option );
fprintf(stderr,
"Unrecognized option '%c', ignoring\n",
*option);
option++; option++;
} while (*option != '\0'); } while ( *option != '\0' );
} }
static void static void parse_options( struct options* opt, int argc, char** argv, char* progname )
parse_options(struct options *opt, int argc, char **argv, char *progname)
{ {
opt->more_options = TRUE; opt->more_options = TRUE;
while (argc > 1) { while ( argc > 1 ) {
switch (argv[1][0]) { switch ( argv[ 1 ][ 0 ] ) {
case '\0': case '\0':
break; break;
break; break;
case '-': case '-':
if (opt->more_options) { if ( opt->more_options ) {
parse_shortopt(opt, argv[1], progname); parse_shortopt( opt, argv[ 1 ], progname );
break; break;
} }
/* FALL THROUGH */ /* FALL THROUGH */
default: default:
if (opt->config != NULL) { if ( opt->config != NULL ) {
fprintf(stderr, fprintf( stderr,
"Additional config file \"%s\"" "Additional config file \"%s\""
" specified, overriding\n", " specified, overriding\n",
argv[1]); argv[ 1 ] );
} }
opt->config = argv[1]; opt->config = argv[ 1 ];
} }
argc--; argc--;
argv++; argv++;
} }
} }
void void ui_sighnd( int sig )
ui_sighnd(int sig)
{ {
switch (sig) { switch ( sig ) {
case SIGINT: case SIGINT:
case SIGQUIT: case SIGQUIT:
case SIGTERM: case SIGTERM:
x49gp->arm_exit = 1; x49gp->arm_exit = 1;
cpu_exit(x49gp->env); cpu_exit( x49gp->env );
break; break;
} }
} }
int int main( int argc, char** argv )
main(int argc, char **argv)
{ {
char *progname, *progpath; char *progname, *progpath;
int error; int error;
struct options opt; struct options opt;
const char *home; const char* home;
progname = g_path_get_basename( argv[ 0 ] );
progpath = g_path_get_dirname( argv[ 0 ] );
progname = g_path_get_basename(argv[0]); gtk_init( &argc, &argv );
progpath = g_path_get_dirname(argv[0]);
gtk_init(&argc, &argv);
opt.config = NULL; opt.config = NULL;
opt.debug_port = 0; opt.debug_port = 0;
opt.start_debugger = FALSE; opt.start_debugger = FALSE;
opt.reinit = X49GP_REINIT_NONE; opt.reinit = X49GP_REINIT_NONE;
opt.firmware = NULL; opt.firmware = NULL;
parse_options(&opt, argc, argv, progname); parse_options( &opt, argc, argv, progname );
x49gp = malloc(sizeof(x49gp_t)); x49gp = malloc( sizeof( x49gp_t ) );
if (NULL == x49gp) { if ( NULL == x49gp ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", progname, __FUNCTION__, __LINE__ );
progname, __FUNCTION__, __LINE__); exit( 1 );
exit(1);
} }
memset(x49gp, 0, sizeof(x49gp_t)); memset( x49gp, 0, sizeof( x49gp_t ) );
#ifdef DEBUG_X49GP_MAIN #ifdef DEBUG_X49GP_MAIN
fprintf(stderr, "_SC_PAGE_SIZE: %08lx\n", sysconf(_SC_PAGE_SIZE)); fprintf( stderr, "_SC_PAGE_SIZE: %08lx\n", sysconf( _SC_PAGE_SIZE ) );
printf("%s:%u: x49gp: %p\n", __FUNCTION__, __LINE__, x49gp); printf( "%s:%u: x49gp: %p\n", __FUNCTION__, __LINE__, x49gp );
#endif #endif
INIT_LIST_HEAD(&x49gp->modules); INIT_LIST_HEAD( &x49gp->modules );
x49gp->progname = progname; x49gp->progname = progname;
x49gp->progpath = progpath; x49gp->progpath = progpath;
x49gp->clk_tck = sysconf(_SC_CLK_TCK); x49gp->clk_tck = sysconf( _SC_CLK_TCK );
x49gp->emulator_fclk = 75000000; x49gp->emulator_fclk = 75000000;
x49gp->PCLK_ratio = 4; x49gp->PCLK_ratio = 4;
x49gp->PCLK = 75000000 / 4; x49gp->PCLK = 75000000 / 4;
//cpu_set_log(0xffffffff); // cpu_set_log(0xffffffff);
cpu_exec_init_all(0); cpu_exec_init_all( 0 );
x49gp->env = cpu_init("arm926"); x49gp->env = cpu_init( "arm926" );
__GLOBAL_env = x49gp->env; __GLOBAL_env = x49gp->env;
// cpu_set_log(cpu_str_to_log_mask("all")); // cpu_set_log(cpu_str_to_log_mask("all"));
x49gp_timer_init(x49gp); x49gp_timer_init( x49gp );
x49gp->gtk_timer = x49gp_new_timer(X49GP_TIMER_REALTIME, x49gp->gtk_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, x49gp_gtk_timer, x49gp );
x49gp_gtk_timer, x49gp); x49gp->lcd_timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, x49gp_lcd_timer, x49gp );
x49gp->lcd_timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL,
x49gp_lcd_timer, x49gp);
x49gp_ui_init(x49gp); x49gp_ui_init( x49gp );
x49gp_s3c2410_arm_init(x49gp); x49gp_s3c2410_arm_init( x49gp );
x49gp_flash_init(x49gp); x49gp_flash_init( x49gp );
x49gp_sram_init(x49gp); x49gp_sram_init( x49gp );
x49gp_s3c2410_init(x49gp); x49gp_s3c2410_init( x49gp );
if (x49gp_modules_init(x49gp)) { if ( x49gp_modules_init( x49gp ) ) {
exit(1); exit( 1 );
} }
if (opt.config == NULL) { if ( opt.config == NULL ) {
char config_dir[strlen(progname) + 9]; char config_dir[ strlen( progname ) + 9 ];
home = g_get_home_dir(); home = g_get_home_dir();
sprintf(config_dir, ".config/%s", progname); sprintf( config_dir, ".config/%s", progname );
opt.config = g_build_filename(home, config_dir, opt.config = g_build_filename( home, config_dir, "config", NULL );
"config", NULL);
} }
x49gp->basename = g_path_get_dirname(opt.config); x49gp->basename = g_path_get_dirname( opt.config );
x49gp->debug_port = opt.debug_port; x49gp->debug_port = opt.debug_port;
x49gp->startup_reinit = opt.reinit; x49gp->startup_reinit = opt.reinit;
x49gp->firmware = opt.firmware; x49gp->firmware = opt.firmware;
error = x49gp_modules_load(x49gp, opt.config); error = x49gp_modules_load( x49gp, opt.config );
if (error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY) { if ( error || opt.reinit >= X49GP_REINIT_REBOOT_ONLY ) {
if (error && error != -EAGAIN) { if ( error && error != -EAGAIN ) {
exit(1); exit( 1 );
} }
x49gp_modules_reset(x49gp, X49GP_RESET_POWER_ON); x49gp_modules_reset( x49gp, X49GP_RESET_POWER_ON );
} }
// x49gp_modules_reset(x49gp, X49GP_RESET_POWER_ON); // x49gp_modules_reset(x49gp, X49GP_RESET_POWER_ON);
signal(SIGINT, ui_sighnd); signal( SIGINT, ui_sighnd );
signal(SIGTERM, ui_sighnd); signal( SIGTERM, ui_sighnd );
signal(SIGQUIT, ui_sighnd); signal( SIGQUIT, ui_sighnd );
signal(SIGUSR1, arm_sighnd); signal( SIGUSR1, arm_sighnd );
x49gp_set_idle( x49gp, 0 );
x49gp_set_idle(x49gp, 0); // stl_phys(0x08000a1c, 0x55555555);
// stl_phys(0x08000a1c, 0x55555555); x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() );
x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() );
if ( opt.debug_port != 0 && opt.start_debugger ) {
x49gp_mod_timer(x49gp->gtk_timer, x49gp_get_clock()); gdbserver_start( opt.debug_port );
x49gp_mod_timer(x49gp->lcd_timer, x49gp_get_clock()); gdb_handlesig( x49gp->env, 0 );
if(opt.debug_port != 0 && opt.start_debugger) {
gdbserver_start(opt.debug_port);
gdb_handlesig(x49gp->env, 0);
} }
x49gp_main_loop(x49gp); x49gp_main_loop( x49gp );
x49gp_modules_save(x49gp, opt.config);
x49gp_modules_exit(x49gp);
x49gp_modules_save( x49gp, opt.config );
x49gp_modules_exit( x49gp );
#if 0 #if 0
printf("ClkTicks: %lu\n", ARMul_Time(x49gp->arm)); printf("ClkTicks: %lu\n", ARMul_Time(x49gp->arm));

View file

@ -11,58 +11,57 @@
#include "x49gp.h" #include "x49gp.h"
int int x49gp_modules_init( x49gp_t* x49gp )
x49gp_modules_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
int error; int error;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u:\n", __FUNCTION__, __LINE__); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
phys_ram_size = 0; phys_ram_size = 0;
list_for_each_entry(module, &x49gp->modules, list) { list_for_each_entry( module, &x49gp->modules, list )
error = module->init(module); {
if (error) { error = module->init( module );
if ( error ) {
return error; return error;
} }
} }
phys_ram_base = mmap(0, phys_ram_size, PROT_NONE, MAP_SHARED | MAP_ANON, -1, 0); phys_ram_base = mmap( 0, phys_ram_size, PROT_NONE, MAP_SHARED | MAP_ANON, -1, 0 );
if (phys_ram_base == (uint8_t *) -1) { if ( phys_ram_base == ( uint8_t* )-1 ) {
fprintf(stderr, "%s: can't mmap %08x anonymous bytes\n", fprintf( stderr, "%s: can't mmap %08x anonymous bytes\n", __FUNCTION__, phys_ram_size );
__FUNCTION__, phys_ram_size); exit( 1 );
exit(1);
} }
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base); printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base );
#endif #endif
phys_ram_dirty = qemu_vmalloc(phys_ram_size >> TARGET_PAGE_BITS); phys_ram_dirty = qemu_vmalloc( phys_ram_size >> TARGET_PAGE_BITS );
memset(phys_ram_dirty, 0xff, phys_ram_size >> TARGET_PAGE_BITS); memset( phys_ram_dirty, 0xff, phys_ram_size >> TARGET_PAGE_BITS );
ram_addr_t x49gp_ram_alloc(ram_addr_t size, uint8_t *base); ram_addr_t x49gp_ram_alloc( ram_addr_t size, uint8_t* base );
x49gp_ram_alloc(phys_ram_size, phys_ram_base); x49gp_ram_alloc( phys_ram_size, phys_ram_base );
return 0; return 0;
} }
int int x49gp_modules_exit( x49gp_t* x49gp )
x49gp_modules_exit(x49gp_t *x49gp)
{ {
x49gp_module_t *module, *next; x49gp_module_t *module, *next;
int error; int error;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u:\n", __FUNCTION__, __LINE__); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
list_for_each_entry_safe_reverse(module, next, &x49gp->modules, list) { list_for_each_entry_safe_reverse( module, next, &x49gp->modules, list )
error = module->exit(module); {
if (error) { error = module->exit( module );
if ( error ) {
return error; return error;
} }
} }
@ -70,19 +69,19 @@ x49gp_modules_exit(x49gp_t *x49gp)
return 0; return 0;
} }
int int x49gp_modules_reset( x49gp_t* x49gp, x49gp_reset_t reset )
x49gp_modules_reset(x49gp_t *x49gp, x49gp_reset_t reset)
{ {
x49gp_module_t *module; x49gp_module_t* module;
int error; int error;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u:\n", __FUNCTION__, __LINE__); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
list_for_each_entry(module, &x49gp->modules, list) { list_for_each_entry( module, &x49gp->modules, list )
error = module->reset(module, reset); {
if (error) { error = module->reset( module, reset );
if ( error ) {
return error; return error;
} }
} }
@ -90,46 +89,42 @@ x49gp_modules_reset(x49gp_t *x49gp, x49gp_reset_t reset)
return 0; return 0;
} }
int int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
x49gp_modules_load(x49gp_t *x49gp, const char *filename)
{ {
x49gp_module_t *module; x49gp_module_t* module;
GError *gerror = NULL; GError* gerror = NULL;
int error, result; int error, result;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u:\n", __FUNCTION__, __LINE__); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
if (g_mkdir_with_parents(x49gp->basename, 0755)) { if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) {
error = -errno; error = -errno;
fprintf(stderr, "%s:%u: g_mkdir_with_parents: %s\n", fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
__FUNCTION__, __LINE__, strerror(errno));
return error; return error;
} }
x49gp->config = g_key_file_new(); x49gp->config = g_key_file_new();
if (NULL == x49gp->config) { if ( NULL == x49gp->config ) {
fprintf(stderr, "%s:%u: g_key_file_new: Out of memory\n", fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (! g_key_file_load_from_file(x49gp->config, filename, if ( !g_key_file_load_from_file( x49gp->config, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) &&
G_KEY_FILE_KEEP_COMMENTS, &gerror) !g_error_matches( gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT ) ) {
&& ! g_error_matches(gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { fprintf( stderr, "%s:%u: g_key_file_load_from_file: %s\n", __FUNCTION__, __LINE__, gerror->message );
fprintf(stderr, "%s:%u: g_key_file_load_from_file: %s\n", g_key_file_free( x49gp->config );
__FUNCTION__, __LINE__, gerror->message);
g_key_file_free(x49gp->config);
return -EIO; return -EIO;
} }
result = 0; result = 0;
list_for_each_entry(module, &x49gp->modules, list) { list_for_each_entry( module, &x49gp->modules, list )
error = module->load(module, x49gp->config); {
if (error) { error = module->load( module, x49gp->config );
if (error == -EAGAIN) { if ( error ) {
if ( error == -EAGAIN ) {
result = -EAGAIN; result = -EAGAIN;
} else { } else {
return error; return error;
@ -137,275 +132,234 @@ x49gp_modules_load(x49gp_t *x49gp, const char *filename)
} }
} }
{ {
extern unsigned char *phys_ram_base; extern unsigned char* phys_ram_base;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base); printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base );
printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n", printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x\n", phys_ram_base[ 0 ], phys_ram_base[ 1 ], phys_ram_base[ 2 ],
phys_ram_base[0], phys_ram_base[ 3 ], phys_ram_base[ 4 ], phys_ram_base[ 5 ], phys_ram_base[ 6 ], phys_ram_base[ 7 ] );
phys_ram_base[1],
phys_ram_base[2],
phys_ram_base[3],
phys_ram_base[4],
phys_ram_base[5],
phys_ram_base[6],
phys_ram_base[7]);
#endif #endif
} }
return result; return result;
} }
int int x49gp_modules_save( x49gp_t* x49gp, const char* filename )
x49gp_modules_save(x49gp_t *x49gp, const char *filename)
{ {
x49gp_module_t *module; x49gp_module_t* module;
GError *gerror = NULL; GError* gerror = NULL;
gchar *data; gchar* data;
gsize length; gsize length;
int error; int error;
int fd; int fd;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u:\n", __FUNCTION__, __LINE__); printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
#endif #endif
list_for_each_entry(module, &x49gp->modules, list) { list_for_each_entry( module, &x49gp->modules, list )
error = module->save(module, x49gp->config); {
if (error) { error = module->save( module, x49gp->config );
if ( error ) {
return error; return error;
} }
} }
data = g_key_file_to_data(x49gp->config, &length, &gerror); data = g_key_file_to_data( x49gp->config, &length, &gerror );
if (NULL == data) { if ( NULL == data ) {
fprintf(stderr, "%s:%u: g_key_file_to_data: %s\n", fprintf( stderr, "%s:%u: g_key_file_to_data: %s\n", __FUNCTION__, __LINE__, gerror->message );
__FUNCTION__, __LINE__, gerror->message);
return -ENOMEM; return -ENOMEM;
} }
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC, 0644 );
if (fd < 0) { if ( fd < 0 ) {
error = -errno; error = -errno;
fprintf(stderr, "%s:%u: open %s: %s\n", fprintf( stderr, "%s:%u: open %s: %s\n", __FUNCTION__, __LINE__, filename, strerror( errno ) );
__FUNCTION__, __LINE__, filename, strerror(errno)); g_free( data );
g_free(data);
return error; return error;
} }
if ( write( fd, data, length ) != length ) {
if (write(fd, data, length) != length) {
error = -errno; error = -errno;
fprintf(stderr, "%s:%u: write %s: %s\n", fprintf( stderr, "%s:%u: write %s: %s\n", __FUNCTION__, __LINE__, filename, strerror( errno ) );
__FUNCTION__, __LINE__, filename, strerror(errno)); close( fd );
close(fd); g_free( data );
g_free(data);
return error; return error;
} }
close(fd); close( fd );
g_free(data); g_free( data );
return 0; return 0;
} }
int int x49gp_module_register( x49gp_module_t* module )
x49gp_module_register(x49gp_module_t *module)
{ {
x49gp_t *x49gp = module->x49gp; x49gp_t* x49gp = module->x49gp;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u: %s\n", __FUNCTION__, __LINE__, module->name); printf( "%s:%u: %s\n", __FUNCTION__, __LINE__, module->name );
#endif #endif
list_add_tail(&module->list, &x49gp->modules); list_add_tail( &module->list, &x49gp->modules );
return 0; return 0;
} }
int int x49gp_module_unregister( x49gp_module_t* module )
x49gp_module_unregister(x49gp_module_t *module)
{ {
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s:%u: %s\n", __FUNCTION__, __LINE__, module->name); printf( "%s:%u: %s\n", __FUNCTION__, __LINE__, module->name );
#endif #endif
list_del(&module->list); list_del( &module->list );
return 0; return 0;
} }
int int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path )
x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *key,
const char *name, char *reset, char **valuep,
char **path)
{ {
x49gp_t *x49gp = module->x49gp; x49gp_t* x49gp = module->x49gp;
int error; int error;
error = x49gp_module_get_string(module, key, name, reset, valuep); error = x49gp_module_get_string( module, key, name, reset, valuep );
if (g_path_is_absolute(*valuep)) { if ( g_path_is_absolute( *valuep ) ) {
*path = g_strdup(*valuep); *path = g_strdup( *valuep );
return error; return error;
} }
*path = g_build_filename(x49gp->basename, *valuep, NULL); *path = g_build_filename( x49gp->basename, *valuep, NULL );
if (NULL == path) { if ( NULL == path ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
module->name, __FUNCTION__, __LINE__); g_free( *valuep );
g_free(*valuep);
*valuep = NULL; *valuep = NULL;
} }
return error; return error;
} }
int int x49gp_module_set_filename( x49gp_module_t* module, GKeyFile* key, const char* name, const char* value )
x49gp_module_set_filename(x49gp_module_t *module, GKeyFile *key,
const char *name, const char *value)
{ {
return x49gp_module_set_string(module, key, name, value); return x49gp_module_set_string( module, key, name, value );
} }
int int x49gp_module_get_int( x49gp_module_t* module, GKeyFile* key, const char* name, int reset, int* valuep )
x49gp_module_get_int(x49gp_module_t *module, GKeyFile *key, const char *name,
int reset, int *valuep)
{ {
return x49gp_module_get_u32(module, key, name, reset, return x49gp_module_get_u32( module, key, name, reset, ( uint32_t* )valuep );
(uint32_t *) valuep);
} }
int int x49gp_module_set_int( x49gp_module_t* module, GKeyFile* key, const char* name, int value )
x49gp_module_set_int(x49gp_module_t *module, GKeyFile *key,
const char *name, int value)
{ {
char data[16]; char data[ 16 ];
snprintf(data, sizeof(data), "%d", value); snprintf( data, sizeof( data ), "%d", value );
g_key_file_set_value(key, module->name, name, data); g_key_file_set_value( key, module->name, name, data );
return 0; return 0;
} }
int int x49gp_module_get_uint( x49gp_module_t* module, GKeyFile* key, const char* name, unsigned int reset, unsigned int* valuep )
x49gp_module_get_uint(x49gp_module_t *module, GKeyFile *key, const char *name,
unsigned int reset, unsigned int *valuep)
{ {
return x49gp_module_get_u32(module, key, name, reset, valuep); return x49gp_module_get_u32( module, key, name, reset, valuep );
} }
int int x49gp_module_set_uint( x49gp_module_t* module, GKeyFile* key, const char* name, unsigned int value )
x49gp_module_set_uint(x49gp_module_t *module, GKeyFile *key,
const char *name, unsigned int value)
{ {
char data[16]; char data[ 16 ];
snprintf(data, sizeof(data), "%u", value); snprintf( data, sizeof( data ), "%u", value );
g_key_file_set_value(key, module->name, name, data); g_key_file_set_value( key, module->name, name, data );
return 0; return 0;
} }
int int x49gp_module_get_u32( x49gp_module_t* module, GKeyFile* key, const char* name, uint32_t reset, uint32_t* valuep )
x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *key,
const char *name, uint32_t reset, uint32_t *valuep)
{ {
GError *gerror = NULL; GError* gerror = NULL;
char *data, *end; char *data, *end;
uint32_t value; uint32_t value;
data = g_key_file_get_value(key, module->name, name, &gerror); data = g_key_file_get_value( key, module->name, name, &gerror );
if (NULL == data) { if ( NULL == data ) {
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n", fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
module->name, __FUNCTION__, __LINE__, name);
*valuep = reset; *valuep = reset;
return -EAGAIN; return -EAGAIN;
} }
value = strtoul(data, &end, 0); value = strtoul( data, &end, 0 );
if ((end == data) || (*end != '\0')) { if ( ( end == data ) || ( *end != '\0' ) ) {
*valuep = reset; *valuep = reset;
g_free(data); g_free( data );
return -EAGAIN; return -EAGAIN;
} }
*valuep = value; *valuep = value;
g_free(data); g_free( data );
return 0; return 0;
} }
int int x49gp_module_set_u32( x49gp_module_t* module, GKeyFile* key, const char* name, uint32_t value )
x49gp_module_set_u32(x49gp_module_t *module, GKeyFile *key,
const char *name, uint32_t value)
{ {
char data[16]; char data[ 16 ];
snprintf(data, sizeof(data), "0x%08x", value); snprintf( data, sizeof( data ), "0x%08x", value );
g_key_file_set_value(key, module->name, name, data); g_key_file_set_value( key, module->name, name, data );
return 0; return 0;
} }
int int x49gp_module_set_u64( x49gp_module_t* module, GKeyFile* key, const char* name, uint64_t value )
x49gp_module_set_u64(x49gp_module_t *module, GKeyFile *key,
const char *name, uint64_t value)
{ {
char data[32]; char data[ 32 ];
snprintf(data, sizeof(data), "0x%016" PRIx64 "", value); snprintf( data, sizeof( data ), "0x%016" PRIx64 "", value );
g_key_file_set_value(key, module->name, name, data); g_key_file_set_value( key, module->name, name, data );
return 0; return 0;
} }
int int x49gp_module_get_u64( x49gp_module_t* module, GKeyFile* key, const char* name, uint64_t reset, uint64_t* valuep )
x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *key,
const char *name, uint64_t reset, uint64_t *valuep)
{ {
GError *gerror = NULL; GError* gerror = NULL;
char *data, *end; char *data, *end;
uint64_t value; uint64_t value;
data = g_key_file_get_value(key, module->name, name, &gerror); data = g_key_file_get_value( key, module->name, name, &gerror );
if (NULL == data) { if ( NULL == data ) {
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n", fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
module->name, __FUNCTION__, __LINE__, name);
*valuep = reset; *valuep = reset;
return -EAGAIN; return -EAGAIN;
} }
value = strtoull(data, &end, 0); value = strtoull( data, &end, 0 );
if ((end == data) || (*end != '\0')) { if ( ( end == data ) || ( *end != '\0' ) ) {
*valuep = reset; *valuep = reset;
g_free(data); g_free( data );
return -EAGAIN; return -EAGAIN;
} }
*valuep = value; *valuep = value;
g_free(data); g_free( data );
return 0; return 0;
} }
int int x49gp_module_get_string( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep )
x49gp_module_get_string(x49gp_module_t *module, GKeyFile *key,
const char *name, char *reset, char **valuep)
{ {
GError *gerror = NULL; GError* gerror = NULL;
char *data; char* data;
data = g_key_file_get_value(key, module->name, name, &gerror); data = g_key_file_get_value( key, module->name, name, &gerror );
if (NULL == data) { if ( NULL == data ) {
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n", fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
module->name, __FUNCTION__, __LINE__, name); *valuep = g_strdup( reset );
*valuep = g_strdup(reset);
return -EAGAIN; return -EAGAIN;
} }
@ -413,52 +367,45 @@ x49gp_module_get_string(x49gp_module_t *module, GKeyFile *key,
return 0; return 0;
} }
int x49gp_module_set_string(x49gp_module_t *module, GKeyFile *key, int x49gp_module_set_string( x49gp_module_t* module, GKeyFile* key, const char* name, const char* value )
const char *name, const char *value)
{ {
g_key_file_set_value(key, module->name, name, value); g_key_file_set_value( key, module->name, name, value );
return 0; return 0;
} }
int int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** path )
x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
char **path)
{ {
x49gp_t *x49gp = module->x49gp; x49gp_t* x49gp = module->x49gp;
int fd; int fd;
int error; int error;
*path = g_build_filename(x49gp->progpath, name, NULL); *path = g_build_filename( x49gp->progpath, name, NULL );
if (NULL == *path) { if ( NULL == *path ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
module->name, __FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
fd = open(*path, O_RDONLY); fd = open( *path, O_RDONLY );
#ifdef X49GP_DATADIR #ifdef X49GP_DATADIR
if (fd < 0 && (errno == EACCES || errno == ENOENT)) { if ( fd < 0 && ( errno == EACCES || errno == ENOENT ) ) {
g_free(*path); g_free( *path );
*path = g_build_filename(X49GP_DATADIR, name, NULL); *path = g_build_filename( X49GP_DATADIR, name, NULL );
if (NULL == *path) { if ( NULL == *path ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
module->name, __FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
fd = open(*path, O_RDONLY); fd = open( *path, O_RDONLY );
} }
#endif #endif
if (fd < 0) { if ( fd < 0 ) {
error = -errno; error = -errno;
fprintf(stderr, "%s: %s:%u: open %s: %s\n", fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, *path, strerror( errno ) );
module->name, __FUNCTION__, __LINE__, g_free( *path );
*path, strerror(errno));
g_free(*path);
*path = NULL; *path = NULL;
return error; return error;
} }
@ -466,24 +413,18 @@ x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
return fd; return fd;
} }
int int x49gp_module_init( x49gp_t* x49gp, const char* name, int ( *init )( x49gp_module_t* ), int ( *exit )( x49gp_module_t* ),
x49gp_module_init(x49gp_t *x49gp, const char *name, int ( *reset )( x49gp_module_t*, x49gp_reset_t ), int ( *load )( x49gp_module_t*, GKeyFile* ),
int (*init)(x49gp_module_t *), int ( *save )( x49gp_module_t*, GKeyFile* ), void* user_data, x49gp_module_t** modulep )
int (*exit)(x49gp_module_t *),
int (*reset)(x49gp_module_t *, x49gp_reset_t),
int (*load)(x49gp_module_t *, GKeyFile *),
int (*save)(x49gp_module_t *, GKeyFile *),
void *user_data, x49gp_module_t **modulep)
{ {
x49gp_module_t *module; x49gp_module_t* module;
module = malloc(sizeof(x49gp_module_t)); module = malloc( sizeof( x49gp_module_t ) );
if (NULL == module) { if ( NULL == module ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", name, __FUNCTION__, __LINE__ );
name, __FUNCTION__, __LINE__);
return -1; return -1;
} }
memset(module, 0, sizeof(x49gp_module_t)); memset( module, 0, sizeof( x49gp_module_t ) );
module->name = name; module->name = name;
@ -495,7 +436,7 @@ x49gp_module_init(x49gp_t *x49gp, const char *name,
module->user_data = user_data; module->user_data = user_data;
// module->mutex = g_mutex_new(); // module->mutex = g_mutex_new();
module->x49gp = x49gp; module->x49gp = x49gp;
*modulep = module; *modulep = module;

View file

@ -34,34 +34,29 @@
* SPI Interface: 0x59000000 * SPI Interface: 0x59000000
* SDI Interface: 0x5a000000 * SDI Interface: 0x5a000000
*/ */
int int x49gp_s3c2410_init( x49gp_t* x49gp )
x49gp_s3c2410_init(x49gp_t *x49gp)
{ {
x49gp_s3c2410_sram_init(x49gp); x49gp_s3c2410_sram_init( x49gp );
x49gp_s3c2410_memc_init(x49gp); x49gp_s3c2410_memc_init( x49gp );
/* x49gp_s3c2410_usbhost_init(x49gp); */ /* x49gp_s3c2410_usbhost_init(x49gp); */
x49gp_s3c2410_intc_init(x49gp); x49gp_s3c2410_intc_init( x49gp );
/* x49gp_s3c2410_dma_init(x49gp); */ /* x49gp_s3c2410_dma_init(x49gp); */
x49gp_s3c2410_power_init(x49gp); x49gp_s3c2410_power_init( x49gp );
x49gp_s3c2410_lcd_init(x49gp); x49gp_s3c2410_lcd_init( x49gp );
x49gp_s3c2410_nand_init(x49gp); x49gp_s3c2410_nand_init( x49gp );
x49gp_s3c2410_uart_init(x49gp); x49gp_s3c2410_uart_init( x49gp );
x49gp_s3c2410_timer_init(x49gp); x49gp_s3c2410_timer_init( x49gp );
x49gp_s3c2410_usbdev_init(x49gp); x49gp_s3c2410_usbdev_init( x49gp );
x49gp_s3c2410_watchdog_init(x49gp); x49gp_s3c2410_watchdog_init( x49gp );
/* x49gp_s3c2410_i2c_init(x49gp); */ /* x49gp_s3c2410_i2c_init(x49gp); */
/* x49gp_s3c2410_iis_init(x49gp); */ /* x49gp_s3c2410_iis_init(x49gp); */
x49gp_s3c2410_io_port_init(x49gp); x49gp_s3c2410_io_port_init( x49gp );
x49gp_s3c2410_rtc_init(x49gp); x49gp_s3c2410_rtc_init( x49gp );
x49gp_s3c2410_adc_init(x49gp); x49gp_s3c2410_adc_init( x49gp );
x49gp_s3c2410_spi_init(x49gp); x49gp_s3c2410_spi_init( x49gp );
x49gp_s3c2410_sdi_init(x49gp); x49gp_s3c2410_sdi_init( x49gp );
return 0; return 0;
} }
int int s3c2410_exit( x49gp_t* x49gp ) { return 0; }
s3c2410_exit(x49gp_t *x49gp)
{
return 0;
}

View file

@ -12,7 +12,6 @@
#include "x49gp.h" #include "x49gp.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct { typedef struct {
uint32_t adccon; uint32_t adccon;
uint32_t adctsc; uint32_t adctsc;
@ -21,241 +20,208 @@ typedef struct {
uint32_t adcdat1; uint32_t adcdat1;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
} s3c2410_adc_t; } s3c2410_adc_t;
static int static int s3c2410_adc_data_init( s3c2410_adc_t* adc )
s3c2410_adc_data_init(s3c2410_adc_t *adc)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(ADC, ADCCON, 0x00003fc4, adc->adccon), S3C2410_OFFSET( ADC, ADCCON, 0x00003fc4, adc->adccon ), S3C2410_OFFSET( ADC, ADCTSC, 0x00000058, adc->adctsc ),
S3C2410_OFFSET(ADC, ADCTSC, 0x00000058, adc->adctsc), S3C2410_OFFSET( ADC, ADCDLY, 0x000000ff, adc->adcdly ), S3C2410_OFFSET( ADC, ADCDAT0, 0x3ff, adc->adcdat0 ),
S3C2410_OFFSET(ADC, ADCDLY, 0x000000ff, adc->adcdly), S3C2410_OFFSET( ADC, ADCDAT1, 0x3ff, adc->adcdat1 ),
S3C2410_OFFSET(ADC, ADCDAT0, 0x3ff, adc->adcdat0),
S3C2410_OFFSET(ADC, ADCDAT1, 0x3ff, adc->adcdat1),
}; };
memset(adc, 0, sizeof(s3c2410_adc_t)); memset( adc, 0, sizeof( s3c2410_adc_t ) );
adc->regs = malloc(sizeof(regs)); adc->regs = malloc( sizeof( regs ) );
if (NULL == adc->regs) { if ( NULL == adc->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(adc->regs, regs, sizeof(regs)); memcpy( adc->regs, regs, sizeof( regs ) );
adc->nr_regs = sizeof(regs) / sizeof(regs[0]); adc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_adc_read( void* opaque, target_phys_addr_t offset )
s3c2410_adc_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_adc_t *adc = opaque; s3c2410_adc_t* adc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(adc, offset)) { if ( !S3C2410_OFFSET_OK( adc, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(adc, offset); reg = S3C2410_OFFSET_ENTRY( adc, offset );
#ifdef DEBUG_S3C2410_ADC #ifdef DEBUG_S3C2410_ADC
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset,
"s3c2410-adc", S3C2410_ADC_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_ADC_ADCCON: case S3C2410_ADC_ADCCON:
*(reg->datap) &= ~(0x0001); *( reg->datap ) &= ~( 0x0001 );
*(reg->datap) |= 0x8000; *( reg->datap ) |= 0x8000;
break; break;
default: default:
break; break;
} }
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_adc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_adc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_adc_t *adc = opaque; s3c2410_adc_t* adc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(adc, offset)) { if ( !S3C2410_OFFSET_OK( adc, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(adc, offset); reg = S3C2410_OFFSET_ENTRY( adc, offset );
#ifdef DEBUG_S3C2410_ADC #ifdef DEBUG_S3C2410_ADC
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-adc", S3C2410_ADC_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
} }
static int static int s3c2410_adc_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_adc_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_adc_t *adc = module->user_data; s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < adc->nr_regs; i++) { for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[i]; reg = &adc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_adc_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_adc_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_adc_t *adc = module->user_data; s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < adc->nr_regs; i++) { for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[i]; reg = &adc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_adc_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_adc_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_adc_t *adc = module->user_data; s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < adc->nr_regs; i++) { for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[i]; reg = &adc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_adc_readfn[] = static CPUReadMemoryFunc* s3c2410_adc_readfn[] = { s3c2410_adc_read, s3c2410_adc_read, s3c2410_adc_read };
{
s3c2410_adc_read,
s3c2410_adc_read,
s3c2410_adc_read
};
static CPUWriteMemoryFunc *s3c2410_adc_writefn[] = static CPUWriteMemoryFunc* s3c2410_adc_writefn[] = { s3c2410_adc_write, s3c2410_adc_write, s3c2410_adc_write };
{
s3c2410_adc_write,
s3c2410_adc_write,
s3c2410_adc_write
};
static int static int s3c2410_adc_init( x49gp_module_t* module )
s3c2410_adc_init(x49gp_module_t *module)
{ {
s3c2410_adc_t *adc; s3c2410_adc_t* adc;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
adc = malloc(sizeof(s3c2410_adc_t)); adc = malloc( sizeof( s3c2410_adc_t ) );
if (NULL == adc) { if ( NULL == adc ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_adc_data_init(adc)) { if ( s3c2410_adc_data_init( adc ) ) {
free(adc); free( adc );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = adc; module->user_data = adc;
iotype = cpu_register_io_memory(s3c2410_adc_readfn, iotype = cpu_register_io_memory( s3c2410_adc_readfn, s3c2410_adc_writefn, adc );
s3c2410_adc_writefn, adc);
#ifdef DEBUG_S3C2410_ADC #ifdef DEBUG_S3C2410_ADC
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_ADC_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_ADC_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_adc_exit( x49gp_module_t* module )
s3c2410_adc_exit(x49gp_module_t *module)
{ {
s3c2410_adc_t *adc; s3c2410_adc_t* adc;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
adc = module->user_data; adc = module->user_data;
if (adc->regs) if ( adc->regs )
free(adc->regs); free( adc->regs );
free(adc); free( adc );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_adc_init( x49gp_t* x49gp )
x49gp_s3c2410_adc_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-adc", if ( x49gp_module_init( x49gp, "s3c2410-adc", s3c2410_adc_init, s3c2410_adc_exit, s3c2410_adc_reset, s3c2410_adc_load, s3c2410_adc_save,
s3c2410_adc_init, NULL, &module ) ) {
s3c2410_adc_exit,
s3c2410_adc_reset,
s3c2410_adc_load,
s3c2410_adc_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -1,7 +1,6 @@
/* $Id: s3c2410_arm.c,v 1.7 2008/12/11 12:18:17 ecd Exp $ /* $Id: s3c2410_arm.c,v 1.7 2008/12/11 12:18:17 ecd Exp $
*/ */
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -15,260 +14,247 @@
#include "qemu-git/cpu-all.h" #include "qemu-git/cpu-all.h"
static int static int s3c2410_arm_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_arm_load(x49gp_module_t *module, GKeyFile *key)
{ {
struct CPUARMState *env = module->user_data; struct CPUARMState* env = module->user_data;
char name[32]; char name[ 32 ];
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
cpu_reset(env); cpu_reset( env );
tlb_flush(env, 1); tlb_flush( env, 1 );
for (i = 0; i < (sizeof(env->regs) / sizeof(env->regs[0])); i++) { for ( i = 0; i < ( sizeof( env->regs ) / sizeof( env->regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-%02u", i); sprintf( name, "reg-%02u", i );
if (x49gp_module_get_u32(module, key, name, 0, &env->regs[i])) if ( x49gp_module_get_u32( module, key, name, 0, &env->regs[ i ] ) )
error = -EAGAIN; error = -EAGAIN;
} }
if (x49gp_module_get_u32(module, key, "cpsr", 0, &env->uncached_cpsr)) if ( x49gp_module_get_u32( module, key, "cpsr", 0, &env->uncached_cpsr ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "spsr", 0, &env->spsr)) if ( x49gp_module_get_u32( module, key, "spsr", 0, &env->spsr ) )
error = -EAGAIN; error = -EAGAIN;
for (i = 0; i < (sizeof(env->banked_spsr) / sizeof(env->banked_spsr[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_spsr ) / sizeof( env->banked_spsr[ 0 ] ) ); i++ ) {
sprintf(name, "banked-spsr-%02u", i); sprintf( name, "banked-spsr-%02u", i );
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_spsr[i])) if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_spsr[ i ] ) )
error = -EAGAIN; error = -EAGAIN;
} }
for (i = 0; i < (sizeof(env->banked_r13) / sizeof(env->banked_r13[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_r13 ) / sizeof( env->banked_r13[ 0 ] ) ); i++ ) {
sprintf(name, "banked-r13-%02u", i); sprintf( name, "banked-r13-%02u", i );
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_r13[i])) if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_r13[ i ] ) )
error = -EAGAIN; error = -EAGAIN;
} }
for (i = 0; i < (sizeof(env->banked_r14) / sizeof(env->banked_r14[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_r14 ) / sizeof( env->banked_r14[ 0 ] ) ); i++ ) {
sprintf(name, "banked-r14-%02u", i); sprintf( name, "banked-r14-%02u", i );
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_r14[i])) if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_r14[ i ] ) )
error = -EAGAIN; error = -EAGAIN;
} }
for (i = 0; i < (sizeof(env->usr_regs) / sizeof(env->usr_regs[0])); i++) { for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-usr-%02u", i); sprintf( name, "reg-usr-%02u", i );
if (x49gp_module_get_u32(module, key, name, if ( x49gp_module_get_u32( module, key, name, 0, &env->usr_regs[ i ] ) )
0, &env->usr_regs[i]))
error = -EAGAIN; error = -EAGAIN;
} }
for (i = 0; i < (sizeof(env->fiq_regs) / sizeof(env->fiq_regs[0])); i++) { for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-fiq-%02u", i); sprintf( name, "reg-fiq-%02u", i );
if (x49gp_module_get_u32(module, key, name, if ( x49gp_module_get_u32( module, key, name, 0, &env->fiq_regs[ i ] ) )
0, &env->fiq_regs[i]))
error = -EAGAIN; error = -EAGAIN;
} }
if (x49gp_module_get_u32(module, key, "CF", 0, &env->CF)) if ( x49gp_module_get_u32( module, key, "CF", 0, &env->CF ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "VF", 0, &env->VF)) if ( x49gp_module_get_u32( module, key, "VF", 0, &env->VF ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "NF", 0, &env->NF)) if ( x49gp_module_get_u32( module, key, "NF", 0, &env->NF ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "ZF", 0, &env->ZF)) if ( x49gp_module_get_u32( module, key, "ZF", 0, &env->ZF ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "QF", 0, &env->QF)) if ( x49gp_module_get_u32( module, key, "QF", 0, &env->QF ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "thumb", 0, &env->thumb)) if ( x49gp_module_get_u32( module, key, "thumb", 0, &env->thumb ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c0-cpuid", 0, &env->cp15.c0_cpuid)) if ( x49gp_module_get_u32( module, key, "cp15-c0-cpuid", 0, &env->cp15.c0_cpuid ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c1-sys", 0, &env->cp15.c1_sys)) if ( x49gp_module_get_u32( module, key, "cp15-c1-sys", 0, &env->cp15.c1_sys ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c1-coproc", 0, &env->cp15.c1_coproc)) if ( x49gp_module_get_u32( module, key, "cp15-c1-coproc", 0, &env->cp15.c1_coproc ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-base0", 0, &env->cp15.c2_base0)) if ( x49gp_module_get_u32( module, key, "cp15-c2-base0", 0, &env->cp15.c2_base0 ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-base1", 0, &env->cp15.c2_base1)) if ( x49gp_module_get_u32( module, key, "cp15-c2-base1", 0, &env->cp15.c2_base1 ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-control", 0, &env->cp15.c2_control)) if ( x49gp_module_get_u32( module, key, "cp15-c2-control", 0, &env->cp15.c2_control ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-mask", 0, &env->cp15.c2_mask)) if ( x49gp_module_get_u32( module, key, "cp15-c2-mask", 0, &env->cp15.c2_mask ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-base-mask", 0, &env->cp15.c2_base_mask)) if ( x49gp_module_get_u32( module, key, "cp15-c2-base-mask", 0, &env->cp15.c2_base_mask ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-data", 0, &env->cp15.c2_data)) if ( x49gp_module_get_u32( module, key, "cp15-c2-data", 0, &env->cp15.c2_data ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c2-insn", 0, &env->cp15.c2_insn)) if ( x49gp_module_get_u32( module, key, "cp15-c2-insn", 0, &env->cp15.c2_insn ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c3", 0, &env->cp15.c3)) if ( x49gp_module_get_u32( module, key, "cp15-c3", 0, &env->cp15.c3 ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c5-insn", 0, &env->cp15.c5_insn)) if ( x49gp_module_get_u32( module, key, "cp15-c5-insn", 0, &env->cp15.c5_insn ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c5-data", 0, &env->cp15.c5_data)) if ( x49gp_module_get_u32( module, key, "cp15-c5-data", 0, &env->cp15.c5_data ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c6-insn", 0, &env->cp15.c6_insn)) if ( x49gp_module_get_u32( module, key, "cp15-c6-insn", 0, &env->cp15.c6_insn ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c6-data", 0, &env->cp15.c6_data)) if ( x49gp_module_get_u32( module, key, "cp15-c6-data", 0, &env->cp15.c6_data ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c9-insn", 0, &env->cp15.c9_insn)) if ( x49gp_module_get_u32( module, key, "cp15-c9-insn", 0, &env->cp15.c9_insn ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c9-data", 0, &env->cp15.c9_data)) if ( x49gp_module_get_u32( module, key, "cp15-c9-data", 0, &env->cp15.c9_data ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c13-fcse", 0, &env->cp15.c13_fcse)) if ( x49gp_module_get_u32( module, key, "cp15-c13-fcse", 0, &env->cp15.c13_fcse ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "cp15-c13-context", 0, &env->cp15.c13_context)) if ( x49gp_module_get_u32( module, key, "cp15-c13-context", 0, &env->cp15.c13_context ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "features", 0, &env->features)) if ( x49gp_module_get_u32( module, key, "features", 0, &env->features ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_int(module, key, "exception-index", 0, &env->exception_index)) if ( x49gp_module_get_int( module, key, "exception-index", 0, &env->exception_index ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "interrupt-request", 0, &env->interrupt_request)) if ( x49gp_module_get_u32( module, key, "interrupt-request", 0, &env->interrupt_request ) )
error = -EAGAIN; error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "halted", 0, &env->halted)) if ( x49gp_module_get_u32( module, key, "halted", 0, &env->halted ) )
error = -EAGAIN; error = -EAGAIN;
env->exception_index = -1; env->exception_index = -1;
if (0 == error) { if ( 0 == error ) {
if (env->halted) if ( env->halted )
module->x49gp->arm_idle = 1; module->x49gp->arm_idle = 1;
} else { } else {
memset(&env->cp15, 0, sizeof(env->cp15)); memset( &env->cp15, 0, sizeof( env->cp15 ) );
} }
// s3c2410_arm_dump_state(state); // s3c2410_arm_dump_state(state);
return error; return error;
} }
static int static int s3c2410_arm_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_arm_save(x49gp_module_t *module, GKeyFile *key)
{ {
struct CPUARMState *env = module->user_data; struct CPUARMState* env = module->user_data;
char name[32]; char name[ 32 ];
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < (sizeof(env->regs) / sizeof(env->regs[0])); i++) { for ( i = 0; i < ( sizeof( env->regs ) / sizeof( env->regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-%02u", i); sprintf( name, "reg-%02u", i );
x49gp_module_set_u32(module, key, name, env->regs[i]); x49gp_module_set_u32( module, key, name, env->regs[ i ] );
} }
x49gp_module_set_u32(module, key, "cpsr", env->uncached_cpsr); x49gp_module_set_u32( module, key, "cpsr", env->uncached_cpsr );
x49gp_module_set_u32(module, key, "spsr", env->spsr); x49gp_module_set_u32( module, key, "spsr", env->spsr );
for (i = 0; i < (sizeof(env->banked_spsr) / sizeof(env->banked_spsr[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_spsr ) / sizeof( env->banked_spsr[ 0 ] ) ); i++ ) {
sprintf(name, "banked-spsr-%02u", i); sprintf( name, "banked-spsr-%02u", i );
x49gp_module_set_u32(module, key, name, env->banked_spsr[i]); x49gp_module_set_u32( module, key, name, env->banked_spsr[ i ] );
} }
for (i = 0; i < (sizeof(env->banked_r13) / sizeof(env->banked_r13[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_r13 ) / sizeof( env->banked_r13[ 0 ] ) ); i++ ) {
sprintf(name, "banked-r13-%02u", i); sprintf( name, "banked-r13-%02u", i );
x49gp_module_set_u32(module, key, name, env->banked_r13[i]); x49gp_module_set_u32( module, key, name, env->banked_r13[ i ] );
} }
for (i = 0; i < (sizeof(env->banked_r14) / sizeof(env->banked_r14[0])); i++) { for ( i = 0; i < ( sizeof( env->banked_r14 ) / sizeof( env->banked_r14[ 0 ] ) ); i++ ) {
sprintf(name, "banked-r14-%02u", i); sprintf( name, "banked-r14-%02u", i );
x49gp_module_set_u32(module, key, name, env->banked_r14[i]); x49gp_module_set_u32( module, key, name, env->banked_r14[ i ] );
} }
for (i = 0; i < (sizeof(env->usr_regs) / sizeof(env->usr_regs[0])); i++) { for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-usr-%02u", i); sprintf( name, "reg-usr-%02u", i );
x49gp_module_set_u32(module, key, name, env->usr_regs[i]); x49gp_module_set_u32( module, key, name, env->usr_regs[ i ] );
} }
for (i = 0; i < (sizeof(env->fiq_regs) / sizeof(env->fiq_regs[0])); i++) { for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
sprintf(name, "reg-fiq-%02u", i); sprintf( name, "reg-fiq-%02u", i );
x49gp_module_set_u32(module, key, name, env->fiq_regs[i]); x49gp_module_set_u32( module, key, name, env->fiq_regs[ i ] );
} }
x49gp_module_set_u32(module, key, "CF", env->CF); x49gp_module_set_u32( module, key, "CF", env->CF );
x49gp_module_set_u32(module, key, "VF", env->VF); x49gp_module_set_u32( module, key, "VF", env->VF );
x49gp_module_set_u32(module, key, "NF", env->NF); x49gp_module_set_u32( module, key, "NF", env->NF );
x49gp_module_set_u32(module, key, "ZF", env->ZF); x49gp_module_set_u32( module, key, "ZF", env->ZF );
x49gp_module_set_u32(module, key, "QF", env->QF); x49gp_module_set_u32( module, key, "QF", env->QF );
x49gp_module_set_int(module, key, "thumb", env->thumb); x49gp_module_set_int( module, key, "thumb", env->thumb );
x49gp_module_set_u32(module, key, "cp15-c0-cpuid", env->cp15.c0_cpuid); x49gp_module_set_u32( module, key, "cp15-c0-cpuid", env->cp15.c0_cpuid );
x49gp_module_set_u32(module, key, "cp15-c1-sys", env->cp15.c1_sys); x49gp_module_set_u32( module, key, "cp15-c1-sys", env->cp15.c1_sys );
x49gp_module_set_u32(module, key, "cp15-c1-coproc", env->cp15.c1_coproc); x49gp_module_set_u32( module, key, "cp15-c1-coproc", env->cp15.c1_coproc );
x49gp_module_set_u32(module, key, "cp15-c2-base0", env->cp15.c2_base0); x49gp_module_set_u32( module, key, "cp15-c2-base0", env->cp15.c2_base0 );
x49gp_module_set_u32(module, key, "cp15-c2-base1", env->cp15.c2_base1); x49gp_module_set_u32( module, key, "cp15-c2-base1", env->cp15.c2_base1 );
x49gp_module_set_u32(module, key, "cp15-c2-control", env->cp15.c2_control); x49gp_module_set_u32( module, key, "cp15-c2-control", env->cp15.c2_control );
x49gp_module_set_u32(module, key, "cp15-c2-mask", env->cp15.c2_mask); x49gp_module_set_u32( module, key, "cp15-c2-mask", env->cp15.c2_mask );
x49gp_module_set_u32(module, key, "cp15-c2-base-mask", env->cp15.c2_base_mask); x49gp_module_set_u32( module, key, "cp15-c2-base-mask", env->cp15.c2_base_mask );
x49gp_module_set_u32(module, key, "cp15-c2-data", env->cp15.c2_data); x49gp_module_set_u32( module, key, "cp15-c2-data", env->cp15.c2_data );
x49gp_module_set_u32(module, key, "cp15-c2-insn", env->cp15.c2_insn); x49gp_module_set_u32( module, key, "cp15-c2-insn", env->cp15.c2_insn );
x49gp_module_set_u32(module, key, "cp15-c3", env->cp15.c3); x49gp_module_set_u32( module, key, "cp15-c3", env->cp15.c3 );
x49gp_module_set_u32(module, key, "cp15-c5-insn", env->cp15.c5_insn); x49gp_module_set_u32( module, key, "cp15-c5-insn", env->cp15.c5_insn );
x49gp_module_set_u32(module, key, "cp15-c5-data", env->cp15.c5_data); x49gp_module_set_u32( module, key, "cp15-c5-data", env->cp15.c5_data );
x49gp_module_set_u32(module, key, "cp15-c6-insn", env->cp15.c6_insn); x49gp_module_set_u32( module, key, "cp15-c6-insn", env->cp15.c6_insn );
x49gp_module_set_u32(module, key, "cp15-c6-data", env->cp15.c6_data); x49gp_module_set_u32( module, key, "cp15-c6-data", env->cp15.c6_data );
x49gp_module_set_u32(module, key, "cp15-c9-insn", env->cp15.c9_insn); x49gp_module_set_u32( module, key, "cp15-c9-insn", env->cp15.c9_insn );
x49gp_module_set_u32(module, key, "cp15-c9-data", env->cp15.c9_data); x49gp_module_set_u32( module, key, "cp15-c9-data", env->cp15.c9_data );
x49gp_module_set_u32(module, key, "cp15-c13-fcse", env->cp15.c13_fcse); x49gp_module_set_u32( module, key, "cp15-c13-fcse", env->cp15.c13_fcse );
x49gp_module_set_u32(module, key, "cp15-c13-context", env->cp15.c13_context); x49gp_module_set_u32( module, key, "cp15-c13-context", env->cp15.c13_context );
x49gp_module_set_u32(module, key, "features", env->features); x49gp_module_set_u32( module, key, "features", env->features );
x49gp_module_set_int(module, key, "exception-index", env->exception_index); x49gp_module_set_int( module, key, "exception-index", env->exception_index );
x49gp_module_set_int(module, key, "interrupt-request", env->interrupt_request); x49gp_module_set_int( module, key, "interrupt-request", env->interrupt_request );
x49gp_module_set_int(module, key, "halted", env->halted); x49gp_module_set_int( module, key, "halted", env->halted );
return 0; return 0;
} }
static int static int s3c2410_arm_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_arm_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
struct CPUARMState *env = module->user_data; struct CPUARMState* env = module->user_data;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
cpu_reset(env); cpu_reset( env );
tlb_flush(env, 1); tlb_flush( env, 1 );
return 0; return 0;
} }
static int static int s3c2410_arm_init( x49gp_module_t* module )
s3c2410_arm_init(x49gp_module_t *module)
{ {
x49gp_t *x49gp = module->x49gp; x49gp_t* x49gp = module->x49gp;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
module->user_data = x49gp->env; module->user_data = x49gp->env;
return 0; return 0;
} }
static int static int s3c2410_arm_exit( x49gp_module_t* module )
s3c2410_arm_exit(x49gp_module_t *module)
{ {
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
return 0; return 0;
} }
int int x49gp_s3c2410_arm_init( x49gp_t* x49gp )
x49gp_s3c2410_arm_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-arm", if ( x49gp_module_init( x49gp, "s3c2410-arm", s3c2410_arm_init, s3c2410_arm_exit, s3c2410_arm_reset, s3c2410_arm_load, s3c2410_arm_save,
s3c2410_arm_init, NULL, &module ) ) {
s3c2410_arm_exit,
s3c2410_arm_reset,
s3c2410_arm_load,
s3c2410_arm_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -19,7 +19,7 @@ typedef struct {
int sel_shift; int sel_shift;
uint32_t mode_bit; uint32_t mode_bit;
int index; int index;
int req[6]; int req[ 6 ];
} s3c2410_arb_t; } s3c2410_arb_t;
typedef struct { typedef struct {
@ -27,33 +27,32 @@ typedef struct {
uint32_t mode; uint32_t mode;
} s3c2410_arb_data_t; } s3c2410_arb_data_t;
static const int s3c2410_arb_order[4][6] = static const int s3c2410_arb_order[ 4 ][ 6 ] = {
{ {0, 1, 2, 3, 4, 5},
{ 0, 1, 2, 3, 4, 5 }, {0, 2, 3, 4, 1, 5},
{ 0, 2, 3, 4, 1, 5 }, {0, 3, 4, 1, 2, 5},
{ 0, 3, 4, 1, 2, 5 }, {0, 4, 1, 2, 3, 5}
{ 0, 4, 1, 2, 3, 5 }
}; };
static const s3c2410_arb_t s3c2410_arb_table[] = static const s3c2410_arb_t s3c2410_arb_table[] = {
{ [0] = {ARB0_SEL_SHIFT, ARB0_MODE, 0, { -1, EINT0, EINT1, EINT2, EINT3, -1 } },
[0] = { ARB0_SEL_SHIFT, ARB0_MODE, 0, [1] = {ARB1_SEL_SHIFT, ARB1_MODE, 1, { EINT4_7, EINT8_23, -1, nBATT_FLT, INT_TICK, INT_WDT } },
{ -1, EINT0, EINT1, EINT2, EINT3, -1 } }, [2] = {ARB2_SEL_SHIFT, ARB2_MODE, 2, { INT_TIMER0, INT_TIMER1, INT_TIMER2, INT_TIMER3, INT_TIMER4, INT_UART2 }},
[1] = { ARB1_SEL_SHIFT, ARB1_MODE, 1, [3] = {ARB3_SEL_SHIFT, ARB3_MODE, 3, { INT_LCD, INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3, INT_SDI } },
{ EINT4_7, EINT8_23, -1, nBATT_FLT, INT_TICK, INT_WDT } }, [4] = {ARB4_SEL_SHIFT, ARB4_MODE, 4, { INT_SPI0, INT_UART1, -1, INT_USBD, INT_USBH, INT_IIC } },
[2] = { ARB2_SEL_SHIFT, ARB2_MODE, 2, [5] = {ARB5_SEL_SHIFT,
{ INT_TIMER0, INT_TIMER1, INT_TIMER2, INT_TIMER3, INT_TIMER4, INT_UART2} }, ARB5_MODE, 5,
[3] = { ARB3_SEL_SHIFT, ARB3_MODE, 3, {
{ INT_LCD, INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3, INT_SDI } }, -1,
[4] = { ARB4_SEL_SHIFT, ARB4_MODE, 4, INT_UART0,
{ INT_SPI0, INT_UART1, -1, INT_USBD, INT_USBH, INT_IIC } }, INT_SPI1,
[5] = { ARB5_SEL_SHIFT, ARB5_MODE, 5, INT_RTC,
{ -1, INT_UART0, INT_SPI1, INT_RTC, INT_ADC, -1, } }, INT_ADC,
[6] = { ARB6_SEL_SHIFT, ARB6_MODE, 6, -1,
{ 0, 1, 2, 3, 4, 5 } }, } },
[6] = {ARB6_SEL_SHIFT, ARB6_MODE, 6, { 0, 1, 2, 3, 4, 5 } },
}; };
#define INTC_NR_ARB (sizeof(s3c2410_arb_table) / sizeof(s3c2410_arb_table[0])) #define INTC_NR_ARB ( sizeof( s3c2410_arb_table ) / sizeof( s3c2410_arb_table[ 0 ] ) )
typedef struct { typedef struct {
uint32_t srcpnd; uint32_t srcpnd;
@ -65,78 +64,67 @@ typedef struct {
uint32_t subsrcpnd; uint32_t subsrcpnd;
uint32_t intsubmsk; uint32_t intsubmsk;
s3c2410_arb_data_t arb_data[INTC_NR_ARB]; s3c2410_arb_data_t arb_data[ INTC_NR_ARB ];
x49gp_t *x49gp; x49gp_t* x49gp;
uint32_t src_pending; uint32_t src_pending;
uint32_t subsrc_pending; uint32_t subsrc_pending;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
} s3c2410_intc_t; } s3c2410_intc_t;
static void s3c2410_intc_gen_int( s3c2410_intc_t* intc );
static void s3c2410_intc_gen_int_from_sub_int( s3c2410_intc_t* intc );
static void s3c2410_intc_gen_int(s3c2410_intc_t *intc); static int s3c2410_intc_data_init( s3c2410_intc_t* intc )
static void s3c2410_intc_gen_int_from_sub_int(s3c2410_intc_t *intc);
static int
s3c2410_intc_data_init(s3c2410_intc_t *intc)
{ {
int i; int i;
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(INTC, SRCPND, 0x00000000, intc->srcpnd), S3C2410_OFFSET( INTC, SRCPND, 0x00000000, intc->srcpnd ), S3C2410_OFFSET( INTC, INTMOD, 0x00000000, intc->intmod ),
S3C2410_OFFSET(INTC, INTMOD, 0x00000000, intc->intmod), S3C2410_OFFSET( INTC, INTMSK, 0xffffffff, intc->intmsk ), S3C2410_OFFSET( INTC, PRIORITY, 0x0000007f, intc->priority ),
S3C2410_OFFSET(INTC, INTMSK, 0xffffffff, intc->intmsk), S3C2410_OFFSET( INTC, INTPND, 0x00000000, intc->intpnd ), S3C2410_OFFSET( INTC, INTOFFSET, 0x00000000, intc->intoffset ),
S3C2410_OFFSET(INTC, PRIORITY, 0x0000007f, intc->priority), S3C2410_OFFSET( INTC, SUBSRCPND, 0x00000000, intc->subsrcpnd ), S3C2410_OFFSET( INTC, INTSUBMSK, 0x000007ff, intc->intsubmsk ) };
S3C2410_OFFSET(INTC, INTPND, 0x00000000, intc->intpnd),
S3C2410_OFFSET(INTC, INTOFFSET, 0x00000000, intc->intoffset),
S3C2410_OFFSET(INTC, SUBSRCPND, 0x00000000, intc->subsrcpnd),
S3C2410_OFFSET(INTC, INTSUBMSK, 0x000007ff, intc->intsubmsk)
};
memset(intc, 0, sizeof(s3c2410_intc_t)); memset( intc, 0, sizeof( s3c2410_intc_t ) );
intc->regs = malloc(sizeof(regs)); intc->regs = malloc( sizeof( regs ) );
if (NULL == intc->regs) { if ( NULL == intc->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(intc->regs, regs, sizeof(regs)); memcpy( intc->regs, regs, sizeof( regs ) );
intc->nr_regs = sizeof(regs) / sizeof(regs[0]); intc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
for (i = 0; i < INTC_NR_ARB; i++) { for ( i = 0; i < INTC_NR_ARB; i++ ) {
intc->arb_data[i].sel = 0; intc->arb_data[ i ].sel = 0;
intc->arb_data[i].mode = s3c2410_arb_table[i].mode_bit; intc->arb_data[ i ].mode = s3c2410_arb_table[ i ].mode_bit;
} }
return 0; return 0;
} }
static void static void srcpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
srcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
intc->srcpnd &= ~(data); intc->srcpnd &= ~( data );
intc->srcpnd |= intc->src_pending; intc->srcpnd |= intc->src_pending;
if (intc->src_pending & data) { if ( intc->src_pending & data ) {
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
} }
static void static void intmod_put_word( s3c2410_intc_t* intc, uint32_t data )
intmod_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
intc->intmod = data & 0xfeffffbf; intc->intmod = data & 0xfeffffbf;
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
static void static void intmsk_put_word( s3c2410_intc_t* intc, uint32_t data )
intmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
#ifdef DEBUG_X49GP_ENABLE_IRQ #ifdef DEBUG_X49GP_ENABLE_IRQ
uint32_t change; uint32_t change;
@ -148,104 +136,96 @@ intmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
intc->intmsk = data | 0x01000040; intc->intmsk = data | 0x01000040;
#ifdef DEBUG_X49GP_ENABLE_IRQ #ifdef DEBUG_X49GP_ENABLE_IRQ
for (i = 0; i < 32; i++) { for ( i = 0; i < 32; i++ ) {
if ((change & (1 << i)) && !(intc->intmsk & (1 << i))) { if ( ( change & ( 1 << i ) ) && !( intc->intmsk & ( 1 << i ) ) ) {
printf("INTC: Enable IRQ %u\n", i); printf( "INTC: Enable IRQ %u\n", i );
} }
} }
#endif #endif
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
static uint32_t static uint32_t priority_get_word( s3c2410_intc_t* intc )
priority_get_word(s3c2410_intc_t *intc)
{ {
const s3c2410_arb_t *arb; const s3c2410_arb_t* arb;
s3c2410_arb_data_t *arb_data; s3c2410_arb_data_t* arb_data;
int i; int i;
intc->priority = 0; intc->priority = 0;
for (i = 0; i < INTC_NR_ARB; i++) { for ( i = 0; i < INTC_NR_ARB; i++ ) {
arb = &s3c2410_arb_table[i]; arb = &s3c2410_arb_table[ i ];
arb_data = &intc->arb_data[i]; arb_data = &intc->arb_data[ i ];
intc->priority |= (arb_data->sel << arb->sel_shift) | intc->priority |= ( arb_data->sel << arb->sel_shift ) | arb_data->mode;
arb_data->mode;
} }
return intc->priority; return intc->priority;
} }
static void static void priority_put_word( s3c2410_intc_t* intc, uint32_t data )
priority_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
const s3c2410_arb_t *arb; const s3c2410_arb_t* arb;
s3c2410_arb_data_t *arb_data; s3c2410_arb_data_t* arb_data;
int i; int i;
intc->priority = data & 0x001fffff; intc->priority = data & 0x001fffff;
for (i = 0; i < INTC_NR_ARB; i++) { for ( i = 0; i < INTC_NR_ARB; i++ ) {
arb = &s3c2410_arb_table[i]; arb = &s3c2410_arb_table[ i ];
arb_data = &intc->arb_data[i]; arb_data = &intc->arb_data[ i ];
arb_data->sel = (intc->priority >> arb->sel_shift) & ARBx_SEL_MASK; arb_data->sel = ( intc->priority >> arb->sel_shift ) & ARBx_SEL_MASK;
arb_data->mode = intc->priority & arb->mode_bit; arb_data->mode = intc->priority & arb->mode_bit;
} }
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
static void static void intpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
intpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
intc->intpnd &= ~(data); intc->intpnd &= ~( data );
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
static void static void subsrcpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
subsrcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
intc->subsrcpnd &= ~(data); intc->subsrcpnd &= ~( data );
intc->subsrcpnd |= intc->subsrc_pending; intc->subsrcpnd |= intc->subsrc_pending;
if (intc->subsrc_pending & data) { if ( intc->subsrc_pending & data ) {
s3c2410_intc_gen_int_from_sub_int(intc); s3c2410_intc_gen_int_from_sub_int( intc );
} }
} }
static void static void intsubmsk_put_word( s3c2410_intc_t* intc, uint32_t data )
intsubmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
{ {
intc->intsubmsk = data & 0x000007ff; intc->intsubmsk = data & 0x000007ff;
s3c2410_intc_gen_int_from_sub_int(intc); s3c2410_intc_gen_int_from_sub_int( intc );
} }
static uint32_t static uint32_t s3c2410_intc_select_int( s3c2410_intc_t* intc, const s3c2410_arb_t* arb, uint32_t service, int* offset )
s3c2410_intc_select_int(s3c2410_intc_t *intc, const s3c2410_arb_t *arb,
uint32_t service, int *offset)
{ {
s3c2410_arb_data_t *arb_data = &intc->arb_data[arb->index]; s3c2410_arb_data_t* arb_data = &intc->arb_data[ arb->index ];
const int *order; const int* order;
int i, req; int i, req;
order = s3c2410_arb_order[arb_data->sel]; order = s3c2410_arb_order[ arb_data->sel ];
for (i = 0; i < 6; i++) { for ( i = 0; i < 6; i++ ) {
req = order[i]; req = order[ i ];
if (-1 == arb->req[req]) if ( -1 == arb->req[ req ] )
continue; continue;
if (service & (1 << arb->req[req])) { if ( service & ( 1 << arb->req[ req ] ) ) {
if (arb_data->mode) if ( arb_data->mode )
arb_data->sel = (arb_data->sel + 1) & ARBx_SEL_MASK; arb_data->sel = ( arb_data->sel + 1 ) & ARBx_SEL_MASK;
*offset = arb->req[req]; *offset = arb->req[ req ];
return (1 << arb->index); return ( 1 << arb->index );
} }
} }
@ -253,339 +233,316 @@ s3c2410_intc_select_int(s3c2410_intc_t *intc, const s3c2410_arb_t *arb,
return 0; return 0;
} }
void void s3c2410_FIQ( CPUState* env ) { cpu_interrupt( env, CPU_INTERRUPT_FIQ ); }
s3c2410_FIQ (CPUState *env)
{
cpu_interrupt(env, CPU_INTERRUPT_FIQ);
}
void void s3c2410_IRQ( CPUState* env ) { cpu_interrupt( env, CPU_INTERRUPT_HARD ); }
s3c2410_IRQ (CPUState *env)
{
cpu_interrupt(env, CPU_INTERRUPT_HARD);
}
static void s3c2410_intc_gen_int( s3c2410_intc_t* intc )
static void
s3c2410_intc_gen_int(s3c2410_intc_t *intc)
{ {
x49gp_t *x49gp = intc->x49gp; x49gp_t* x49gp = intc->x49gp;
uint32_t fiq, service; uint32_t fiq, service;
int offset[6], index; int offset[ 6 ], index;
const s3c2410_arb_t *arb; const s3c2410_arb_t* arb;
uint32_t request; uint32_t request;
int i; int i;
fiq = intc->srcpnd & intc->intmod; fiq = intc->srcpnd & intc->intmod;
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: FIQ service request: %08x\n", fiq); printf( "INTC: FIQ service request: %08x\n", fiq );
#endif #endif
if (fiq) { if ( fiq ) {
/* /*
* Generate FIQ. * Generate FIQ.
*/ */
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: vector to %08x\n", 0x1c); printf( "INTC: vector to %08x\n", 0x1c );
#endif #endif
cpu_interrupt(x49gp->env, CPU_INTERRUPT_FIQ); cpu_interrupt( x49gp->env, CPU_INTERRUPT_FIQ );
x49gp_set_idle(x49gp, 0); x49gp_set_idle( x49gp, 0 );
return; return;
} else { } else {
cpu_reset_interrupt(x49gp->env, CPU_INTERRUPT_FIQ); cpu_reset_interrupt( x49gp->env, CPU_INTERRUPT_FIQ );
} }
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: IRQ pending request: %08x\n", intc->intpnd); printf( "INTC: IRQ pending request: %08x\n", intc->intpnd );
#endif #endif
if (intc->intpnd) { if ( intc->intpnd ) {
/* /*
* Generate IRQ. * Generate IRQ.
*/ */
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: vector to %08x\n", 0x18); printf( "INTC: vector to %08x\n", 0x18 );
#endif #endif
cpu_interrupt(x49gp->env, CPU_INTERRUPT_HARD); cpu_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
x49gp_set_idle(x49gp, 0); x49gp_set_idle( x49gp, 0 );
return; return;
} }
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: srcpnd %08x, intmsk: %08x\n", intc->srcpnd, intc->intmsk); printf( "INTC: srcpnd %08x, intmsk: %08x\n", intc->srcpnd, intc->intmsk );
#endif #endif
service = intc->srcpnd & ~(intc->intmsk); service = intc->srcpnd & ~( intc->intmsk );
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: IRQ service request: %08x\n", service); printf( "INTC: IRQ service request: %08x\n", service );
#endif #endif
if (0 == service) { if ( 0 == service ) {
cpu_reset_interrupt(x49gp->env, CPU_INTERRUPT_HARD); cpu_reset_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
return; return;
} }
request = 0; request = 0;
for (i = 0; i < 6; i++) { for ( i = 0; i < 6; i++ ) {
arb = &s3c2410_arb_table[i]; arb = &s3c2410_arb_table[ i ];
request |= s3c2410_intc_select_int(intc, arb, service, &offset[i]); request |= s3c2410_intc_select_int( intc, arb, service, &offset[ i ] );
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: ARB%u highest %d\n", i, offset[i]); printf( "INTC: ARB%u highest %d\n", i, offset[ i ] );
#endif #endif
} }
arb = &s3c2410_arb_table[6]; arb = &s3c2410_arb_table[ 6 ];
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: ARB%u request: %08x\n", 6, request); printf( "INTC: ARB%u request: %08x\n", 6, request );
#endif #endif
if (s3c2410_intc_select_int(intc, arb, request, &index)) { if ( s3c2410_intc_select_int( intc, arb, request, &index ) ) {
intc->intoffset = offset[index]; intc->intoffset = offset[ index ];
intc->intpnd |= (1 << intc->intoffset); intc->intpnd |= ( 1 << intc->intoffset );
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: irq pending: %u (%08x)\n", intc->intoffset, intc->intpnd); printf( "INTC: irq pending: %u (%08x)\n", intc->intoffset, intc->intpnd );
#endif #endif
/* /*
* Generate IRQ. * Generate IRQ.
*/ */
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: vector to %08x\n", 0x18); printf( "INTC: vector to %08x\n", 0x18 );
#endif #endif
cpu_interrupt(x49gp->env, CPU_INTERRUPT_HARD); cpu_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
x49gp_set_idle(x49gp, 0); x49gp_set_idle( x49gp, 0 );
return; return;
} }
#ifdef DEBUG_S3C2410_INTC0 #ifdef DEBUG_S3C2410_INTC0
printf("INTC: No irq pending\n"); printf( "INTC: No irq pending\n" );
#endif #endif
cpu_reset_interrupt(x49gp->env, CPU_INTERRUPT_HARD); cpu_reset_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
} }
void void s3c2410_intc_assert( x49gp_t* x49gp, int irq, int level )
s3c2410_intc_assert(x49gp_t *x49gp, int irq, int level)
{ {
s3c2410_intc_t *intc = x49gp->s3c2410_intc; s3c2410_intc_t* intc = x49gp->s3c2410_intc;
if (irq > 31) if ( irq > 31 )
return; return;
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: assert irq %u (%08x)\n", irq, 1 << irq); printf( "INTC: assert irq %u (%08x)\n", irq, 1 << irq );
#endif #endif
if (! (intc->src_pending & (1 << irq))) { if ( !( intc->src_pending & ( 1 << irq ) ) ) {
if (level) if ( level )
intc->src_pending |= (1 << irq); intc->src_pending |= ( 1 << irq );
intc->srcpnd |= (1 << irq); intc->srcpnd |= ( 1 << irq );
s3c2410_intc_gen_int(intc); s3c2410_intc_gen_int( intc );
} }
if (x49gp->arm_idle == 2) { if ( x49gp->arm_idle == 2 ) {
if (irq == EINT0 || irq == INT_RTC) if ( irq == EINT0 || irq == INT_RTC )
x49gp_set_idle(x49gp, 0); x49gp_set_idle( x49gp, 0 );
} }
} }
void void s3c2410_intc_deassert( x49gp_t* x49gp, int irq )
s3c2410_intc_deassert(x49gp_t *x49gp, int irq)
{ {
s3c2410_intc_t *intc = x49gp->s3c2410_intc; s3c2410_intc_t* intc = x49gp->s3c2410_intc;
if (irq > 31) if ( irq > 31 )
return; return;
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: deassert irq %u (%08x)\n", irq, 1 << irq); printf( "INTC: deassert irq %u (%08x)\n", irq, 1 << irq );
#endif #endif
intc->src_pending &= ~(1 << irq); intc->src_pending &= ~( 1 << irq );
} }
static void static void s3c2410_intc_gen_int_from_sub_int( s3c2410_intc_t* intc )
s3c2410_intc_gen_int_from_sub_int(s3c2410_intc_t *intc)
{ {
x49gp_t *x49gp = intc->x49gp; x49gp_t* x49gp = intc->x49gp;
uint32_t service; uint32_t service;
service = intc->subsrcpnd & ~(intc->intsubmsk); service = intc->subsrcpnd & ~( intc->intsubmsk );
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: subirq service request: %08x\n", service); printf( "INTC: subirq service request: %08x\n", service );
#endif #endif
if (service & ((1 << SUB_INT_ERR0) | (1 << SUB_INT_TXD0) | (1 << SUB_INT_RXD0))) { if ( service & ( ( 1 << SUB_INT_ERR0 ) | ( 1 << SUB_INT_TXD0 ) | ( 1 << SUB_INT_RXD0 ) ) ) {
s3c2410_intc_assert(x49gp, INT_UART0, 1); s3c2410_intc_assert( x49gp, INT_UART0, 1 );
} else { } else {
s3c2410_intc_deassert(x49gp, INT_UART0); s3c2410_intc_deassert( x49gp, INT_UART0 );
} }
if (service & ((1 << SUB_INT_ERR1) | (1 << SUB_INT_TXD1) | (1 << SUB_INT_RXD1))) { if ( service & ( ( 1 << SUB_INT_ERR1 ) | ( 1 << SUB_INT_TXD1 ) | ( 1 << SUB_INT_RXD1 ) ) ) {
s3c2410_intc_assert(x49gp, INT_UART1, 1); s3c2410_intc_assert( x49gp, INT_UART1, 1 );
} else { } else {
s3c2410_intc_deassert(x49gp, INT_UART1); s3c2410_intc_deassert( x49gp, INT_UART1 );
} }
if (service & ((1 << SUB_INT_ERR2) | (1 << SUB_INT_TXD2) | (1 << SUB_INT_RXD2))) { if ( service & ( ( 1 << SUB_INT_ERR2 ) | ( 1 << SUB_INT_TXD2 ) | ( 1 << SUB_INT_RXD2 ) ) ) {
s3c2410_intc_assert(x49gp, INT_UART2, 1); s3c2410_intc_assert( x49gp, INT_UART2, 1 );
} else { } else {
s3c2410_intc_deassert(x49gp, INT_UART2); s3c2410_intc_deassert( x49gp, INT_UART2 );
} }
if (service & ((1 << SUB_INT_ADC) | (1 << SUB_INT_TC))) { if ( service & ( ( 1 << SUB_INT_ADC ) | ( 1 << SUB_INT_TC ) ) ) {
s3c2410_intc_assert(x49gp, INT_ADC, 1); s3c2410_intc_assert( x49gp, INT_ADC, 1 );
} else { } else {
s3c2410_intc_deassert(x49gp, INT_ADC); s3c2410_intc_deassert( x49gp, INT_ADC );
} }
intc->subsrcpnd = intc->subsrc_pending; intc->subsrcpnd = intc->subsrc_pending;
} }
void void s3c2410_intc_sub_assert( x49gp_t* x49gp, int sub_irq, int level )
s3c2410_intc_sub_assert(x49gp_t *x49gp, int sub_irq, int level)
{ {
s3c2410_intc_t *intc = x49gp->s3c2410_intc; s3c2410_intc_t* intc = x49gp->s3c2410_intc;
if (sub_irq > 31) if ( sub_irq > 31 )
return; return;
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: assert subirq %u (%08x)\n", sub_irq, 1 << sub_irq); printf( "INTC: assert subirq %u (%08x)\n", sub_irq, 1 << sub_irq );
#endif #endif
if (! (intc->subsrc_pending & (1 << sub_irq))) { if ( !( intc->subsrc_pending & ( 1 << sub_irq ) ) ) {
if (level) if ( level )
intc->subsrc_pending |= (1 << sub_irq); intc->subsrc_pending |= ( 1 << sub_irq );
intc->subsrcpnd |= (1 << sub_irq); intc->subsrcpnd |= ( 1 << sub_irq );
s3c2410_intc_gen_int_from_sub_int(intc); s3c2410_intc_gen_int_from_sub_int( intc );
} }
} }
void void s3c2410_intc_sub_deassert( x49gp_t* x49gp, int sub_irq )
s3c2410_intc_sub_deassert(x49gp_t *x49gp, int sub_irq)
{ {
s3c2410_intc_t *intc = x49gp->s3c2410_intc; s3c2410_intc_t* intc = x49gp->s3c2410_intc;
if (sub_irq > 31) if ( sub_irq > 31 )
return; return;
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("INTC: deassert subirq %u (%08x)\n", sub_irq, 1 << sub_irq); printf( "INTC: deassert subirq %u (%08x)\n", sub_irq, 1 << sub_irq );
#endif #endif
intc->subsrc_pending &= ~(1 << sub_irq); intc->subsrc_pending &= ~( 1 << sub_irq );
} }
static uint32_t static uint32_t s3c2410_intc_read( void* opaque, target_phys_addr_t offset )
s3c2410_intc_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_intc_t *intc = opaque; s3c2410_intc_t* intc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t data; uint32_t data;
if (! S3C2410_OFFSET_OK(intc, offset)) { if ( !S3C2410_OFFSET_OK( intc, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(intc, offset); reg = S3C2410_OFFSET_ENTRY( intc, offset );
switch (offset) { switch ( offset ) {
case S3C2410_INTC_PRIORITY: case S3C2410_INTC_PRIORITY:
data = priority_get_word(intc); data = priority_get_word( intc );
break; break;
default: default:
data = *(reg->datap); data = *( reg->datap );
break; break;
} }
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-intc", S3C2410_INTC_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-intc", S3C2410_INTC_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
return data; return data;
} }
static void static void s3c2410_intc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_intc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
#endif #endif
s3c2410_intc_t *intc = opaque; s3c2410_intc_t* intc = opaque;
if (! S3C2410_OFFSET_OK(intc, offset)) { if ( !S3C2410_OFFSET_OK( intc, offset ) ) {
return; return;
} }
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
reg = S3C2410_OFFSET_ENTRY(intc, offset); reg = S3C2410_OFFSET_ENTRY( intc, offset );
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-intc", S3C2410_INTC_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-intc", S3C2410_INTC_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_INTC_SRCPND: case S3C2410_INTC_SRCPND:
srcpnd_put_word(intc, data); srcpnd_put_word( intc, data );
break; break;
case S3C2410_INTC_INTMOD: case S3C2410_INTC_INTMOD:
intmod_put_word(intc, data); intmod_put_word( intc, data );
break; break;
case S3C2410_INTC_INTMSK: case S3C2410_INTC_INTMSK:
intmsk_put_word(intc, data); intmsk_put_word( intc, data );
break; break;
case S3C2410_INTC_PRIORITY: case S3C2410_INTC_PRIORITY:
priority_put_word(intc, data); priority_put_word( intc, data );
break; break;
case S3C2410_INTC_INTPND: case S3C2410_INTC_INTPND:
intpnd_put_word(intc, data); intpnd_put_word( intc, data );
break; break;
case S3C2410_INTC_SUBSRCPND: case S3C2410_INTC_SUBSRCPND:
subsrcpnd_put_word(intc, data); subsrcpnd_put_word( intc, data );
break; break;
case S3C2410_INTC_INTSUBMSK: case S3C2410_INTC_INTSUBMSK:
intsubmsk_put_word(intc, data); intsubmsk_put_word( intc, data );
break; break;
default: default:
break; break;
} }
} }
static int static int s3c2410_intc_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_intc_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_intc_t *intc = module->user_data; s3c2410_intc_t* intc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < intc->nr_regs; i++) { for ( i = 0; i < intc->nr_regs; i++ ) {
reg = &intc->regs[i]; reg = &intc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
@ -594,98 +551,84 @@ s3c2410_intc_load(x49gp_module_t *module, GKeyFile *key)
intc->srcpnd = 0; intc->srcpnd = 0;
intc->subsrcpnd = 0; intc->subsrcpnd = 0;
priority_put_word(intc, intc->priority); priority_put_word( intc, intc->priority );
intsubmsk_put_word(intc, intc->intsubmsk); intsubmsk_put_word( intc, intc->intsubmsk );
intmsk_put_word(intc, intc->intmsk); intmsk_put_word( intc, intc->intmsk );
return error; return error;
} }
static int static int s3c2410_intc_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_intc_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_intc_t *intc = module->user_data; s3c2410_intc_t* intc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
intc->srcpnd = intc->src_pending; intc->srcpnd = intc->src_pending;
intc->subsrcpnd = intc->subsrc_pending; intc->subsrcpnd = intc->subsrc_pending;
for (i = 0; i < intc->nr_regs; i++) { for ( i = 0; i < intc->nr_regs; i++ ) {
reg = &intc->regs[i]; reg = &intc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_intc_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_intc_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_intc_t *intc = module->user_data; s3c2410_intc_t* intc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (reset == X49GP_RESET_POWER_OFF) { if ( reset == X49GP_RESET_POWER_OFF ) {
return 0; return 0;
} }
for (i = 0; i < intc->nr_regs; i++) { for ( i = 0; i < intc->nr_regs; i++ ) {
reg = &intc->regs[i]; reg = &intc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_intc_readfn[] = static CPUReadMemoryFunc* s3c2410_intc_readfn[] = { s3c2410_intc_read, s3c2410_intc_read, s3c2410_intc_read };
{
s3c2410_intc_read,
s3c2410_intc_read,
s3c2410_intc_read
};
static CPUWriteMemoryFunc *s3c2410_intc_writefn[] = static CPUWriteMemoryFunc* s3c2410_intc_writefn[] = { s3c2410_intc_write, s3c2410_intc_write, s3c2410_intc_write };
{
s3c2410_intc_write,
s3c2410_intc_write,
s3c2410_intc_write
};
static int static int s3c2410_intc_init( x49gp_module_t* module )
s3c2410_intc_init(x49gp_module_t *module)
{ {
s3c2410_intc_t *intc; s3c2410_intc_t* intc;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
intc = malloc(sizeof(s3c2410_intc_t)); intc = malloc( sizeof( s3c2410_intc_t ) );
if (NULL == intc) { if ( NULL == intc ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_intc_data_init(intc)) { if ( s3c2410_intc_data_init( intc ) ) {
free(intc); free( intc );
return -ENOMEM; return -ENOMEM;
} }
@ -694,51 +637,43 @@ s3c2410_intc_init(x49gp_module_t *module)
intc->x49gp = module->x49gp; intc->x49gp = module->x49gp;
intc->x49gp->s3c2410_intc = intc; intc->x49gp->s3c2410_intc = intc;
iotype = cpu_register_io_memory(s3c2410_intc_readfn, iotype = cpu_register_io_memory( s3c2410_intc_readfn, s3c2410_intc_writefn, intc );
s3c2410_intc_writefn, intc);
#ifdef DEBUG_S3C2410_INTC #ifdef DEBUG_S3C2410_INTC
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_INTC_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_INTC_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_intc_exit( x49gp_module_t* module )
s3c2410_intc_exit(x49gp_module_t *module)
{ {
s3c2410_intc_t *intc; s3c2410_intc_t* intc;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
intc = module->user_data; intc = module->user_data;
if (intc->regs) if ( intc->regs )
free(intc->regs); free( intc->regs );
free(intc); free( intc );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_intc_init( x49gp_t* x49gp )
x49gp_s3c2410_intc_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-intc", if ( x49gp_module_init( x49gp, "s3c2410-intc", s3c2410_intc_init, s3c2410_intc_exit, s3c2410_intc_reset, s3c2410_intc_load,
s3c2410_intc_init, s3c2410_intc_save, NULL, &module ) ) {
s3c2410_intc_exit,
s3c2410_intc_reset,
s3c2410_intc_load,
s3c2410_intc_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -47,13 +47,13 @@
#define SUB_INT_TXD0 1 #define SUB_INT_TXD0 1
#define SUB_INT_RXD0 0 #define SUB_INT_RXD0 0
#define ARB0_MODE (1 << 0) #define ARB0_MODE ( 1 << 0 )
#define ARB1_MODE (1 << 1) #define ARB1_MODE ( 1 << 1 )
#define ARB2_MODE (1 << 2) #define ARB2_MODE ( 1 << 2 )
#define ARB3_MODE (1 << 3) #define ARB3_MODE ( 1 << 3 )
#define ARB4_MODE (1 << 4) #define ARB4_MODE ( 1 << 4 )
#define ARB5_MODE (1 << 5) #define ARB5_MODE ( 1 << 5 )
#define ARB6_MODE (1 << 6) #define ARB6_MODE ( 1 << 6 )
#define ARB0_SEL_SHIFT 7 #define ARB0_SEL_SHIFT 7
#define ARB1_SEL_SHIFT 9 #define ARB1_SEL_SHIFT 9
#define ARB2_SEL_SHIFT 11 #define ARB2_SEL_SHIFT 11
@ -63,10 +63,10 @@
#define ARB6_SEL_SHIFT 19 #define ARB6_SEL_SHIFT 19
#define ARBx_SEL_MASK 3 #define ARBx_SEL_MASK 3
void s3c2410_intc_sub_assert(x49gp_t *x49gp, int sub_irq, int level); void s3c2410_intc_sub_assert( x49gp_t* x49gp, int sub_irq, int level );
void s3c2410_intc_sub_deassert(x49gp_t *x49gp, int sub_irq); void s3c2410_intc_sub_deassert( x49gp_t* x49gp, int sub_irq );
void s3c2410_intc_assert(x49gp_t *x49gp, int irq, int level); void s3c2410_intc_assert( x49gp_t* x49gp, int irq, int level );
void s3c2410_intc_deassert(x49gp_t *x49gp, int irq); void s3c2410_intc_deassert( x49gp_t* x49gp, int irq );
#endif /* !(_X49GP_S3C2410_INTC_H) */ #endif /* !(_X49GP_S3C2410_INTC_H) */

View file

@ -12,7 +12,6 @@
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
#include "byteorder.h" #include "byteorder.h"
typedef struct { typedef struct {
uint32_t gpacon; uint32_t gpacon;
uint32_t gpadat; uint32_t gpadat;
@ -65,118 +64,99 @@ typedef struct {
uint32_t gstatus4; uint32_t gstatus4;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_io_port_t; } s3c2410_io_port_t;
static int static int s3c2410_io_port_data_init( s3c2410_io_port_t* io )
s3c2410_io_port_data_init(s3c2410_io_port_t *io)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(IO_PORT, GPACON, 0x007fffff, io->gpacon), S3C2410_OFFSET( IO_PORT, GPACON, 0x007fffff, io->gpacon ), S3C2410_OFFSET( IO_PORT, GPADAT, 0x00000000, io->gpadat ),
S3C2410_OFFSET(IO_PORT, GPADAT, 0x00000000, io->gpadat),
S3C2410_OFFSET(IO_PORT, GPBCON, 0x00000000, io->gpbcon), S3C2410_OFFSET( IO_PORT, GPBCON, 0x00000000, io->gpbcon ), S3C2410_OFFSET( IO_PORT, GPBDAT, 0x00000000, io->gpbdat ),
S3C2410_OFFSET(IO_PORT, GPBDAT, 0x00000000, io->gpbdat), S3C2410_OFFSET( IO_PORT, GPBUP, 0x00000000, io->gpbup ),
S3C2410_OFFSET(IO_PORT, GPBUP, 0x00000000, io->gpbup),
S3C2410_OFFSET(IO_PORT, GPCCON, 0x00000000, io->gpccon), S3C2410_OFFSET( IO_PORT, GPCCON, 0x00000000, io->gpccon ), S3C2410_OFFSET( IO_PORT, GPCDAT, 0x00000000, io->gpcdat ),
S3C2410_OFFSET(IO_PORT, GPCDAT, 0x00000000, io->gpcdat), S3C2410_OFFSET( IO_PORT, GPCUP, 0x00000000, io->gpcup ),
S3C2410_OFFSET(IO_PORT, GPCUP, 0x00000000, io->gpcup),
S3C2410_OFFSET(IO_PORT, GPDCON, 0x00000000, io->gpdcon), S3C2410_OFFSET( IO_PORT, GPDCON, 0x00000000, io->gpdcon ), S3C2410_OFFSET( IO_PORT, GPDDAT, 0x0000038c, io->gpddat ),
S3C2410_OFFSET(IO_PORT, GPDDAT, 0x0000038c, io->gpddat), S3C2410_OFFSET( IO_PORT, GPDUP, 0x0000f000, io->gpdup ),
S3C2410_OFFSET(IO_PORT, GPDUP, 0x0000f000, io->gpdup),
S3C2410_OFFSET(IO_PORT, GPECON, 0x00000000, io->gpecon), S3C2410_OFFSET( IO_PORT, GPECON, 0x00000000, io->gpecon ), S3C2410_OFFSET( IO_PORT, GPEDAT, 0x0000c7c0, io->gpedat ),
S3C2410_OFFSET(IO_PORT, GPEDAT, 0x0000c7c0, io->gpedat), S3C2410_OFFSET( IO_PORT, GPEUP, 0x00000000, io->gpeup ),
S3C2410_OFFSET(IO_PORT, GPEUP, 0x00000000, io->gpeup),
S3C2410_OFFSET(IO_PORT, GPFCON, 0x00000000, io->gpfcon), S3C2410_OFFSET( IO_PORT, GPFCON, 0x00000000, io->gpfcon ), S3C2410_OFFSET( IO_PORT, GPFDAT, 0x00000008, io->gpfdat ),
S3C2410_OFFSET(IO_PORT, GPFDAT, 0x00000008, io->gpfdat), S3C2410_OFFSET( IO_PORT, GPFUP, 0x00000000, io->gpfup ),
S3C2410_OFFSET(IO_PORT, GPFUP, 0x00000000, io->gpfup),
S3C2410_OFFSET(IO_PORT, GPGCON, 0x00000000, io->gpgcon), S3C2410_OFFSET( IO_PORT, GPGCON, 0x00000000, io->gpgcon ), S3C2410_OFFSET( IO_PORT, GPGDAT, 0x0000fffe, io->gpgdat ),
S3C2410_OFFSET(IO_PORT, GPGDAT, 0x0000fffe, io->gpgdat), S3C2410_OFFSET( IO_PORT, GPGUP, 0x0000f800, io->gpgup ),
S3C2410_OFFSET(IO_PORT, GPGUP, 0x0000f800, io->gpgup),
S3C2410_OFFSET(IO_PORT, GPHCON, 0x00000000, io->gphcon), S3C2410_OFFSET( IO_PORT, GPHCON, 0x00000000, io->gphcon ), S3C2410_OFFSET( IO_PORT, GPHDAT, 0x00000000, io->gphdat ),
S3C2410_OFFSET(IO_PORT, GPHDAT, 0x00000000, io->gphdat), S3C2410_OFFSET( IO_PORT, GPHUP, 0x00000000, io->gphup ),
S3C2410_OFFSET(IO_PORT, GPHUP, 0x00000000, io->gphup),
S3C2410_OFFSET(IO_PORT, MISCCR, 0x00010330, io->misccr), S3C2410_OFFSET( IO_PORT, MISCCR, 0x00010330, io->misccr ), S3C2410_OFFSET( IO_PORT, DCLKCON, 0x00000000, io->dclkcon ),
S3C2410_OFFSET(IO_PORT, DCLKCON, 0x00000000, io->dclkcon),
S3C2410_OFFSET(IO_PORT, EXTINT0, 0x00000000, io->extint0), S3C2410_OFFSET( IO_PORT, EXTINT0, 0x00000000, io->extint0 ), S3C2410_OFFSET( IO_PORT, EXTINT1, 0x00000000, io->extint1 ),
S3C2410_OFFSET(IO_PORT, EXTINT1, 0x00000000, io->extint1), S3C2410_OFFSET( IO_PORT, EXTINT2, 0x00000000, io->extint2 ), S3C2410_OFFSET( IO_PORT, EINTFLT0, 0x00000000, io->eintflt0 ),
S3C2410_OFFSET(IO_PORT, EXTINT2, 0x00000000, io->extint2), S3C2410_OFFSET( IO_PORT, EINTFLT1, 0x00000000, io->eintflt1 ), S3C2410_OFFSET( IO_PORT, EINTFLT2, 0x00000000, io->eintflt2 ),
S3C2410_OFFSET(IO_PORT, EINTFLT0, 0x00000000, io->eintflt0), S3C2410_OFFSET( IO_PORT, EINTFLT3, 0x00000000, io->eintflt3 ), S3C2410_OFFSET( IO_PORT, EINTMASK, 0x00fffff0, io->eintmask ),
S3C2410_OFFSET(IO_PORT, EINTFLT1, 0x00000000, io->eintflt1), S3C2410_OFFSET( IO_PORT, EINTPEND, 0x00000000, io->eintpend ),
S3C2410_OFFSET(IO_PORT, EINTFLT2, 0x00000000, io->eintflt2),
S3C2410_OFFSET(IO_PORT, EINTFLT3, 0x00000000, io->eintflt3),
S3C2410_OFFSET(IO_PORT, EINTMASK, 0x00fffff0, io->eintmask),
S3C2410_OFFSET(IO_PORT, EINTPEND, 0x00000000, io->eintpend),
S3C2410_OFFSET(IO_PORT, GSTATUS0, 0x00000001, io->gstatus0), S3C2410_OFFSET( IO_PORT, GSTATUS0, 0x00000001, io->gstatus0 ), S3C2410_OFFSET( IO_PORT, GSTATUS1, 0x32410002, io->gstatus1 ),
S3C2410_OFFSET(IO_PORT, GSTATUS1, 0x32410002, io->gstatus1), S3C2410_OFFSET( IO_PORT, GSTATUS2, 0x00000001, io->gstatus2 ), S3C2410_OFFSET( IO_PORT, GSTATUS3, 0x00000000, io->gstatus3 ),
S3C2410_OFFSET(IO_PORT, GSTATUS2, 0x00000001, io->gstatus2), S3C2410_OFFSET( IO_PORT, GSTATUS4, 0x00000000, io->gstatus4 ) };
S3C2410_OFFSET(IO_PORT, GSTATUS3, 0x00000000, io->gstatus3),
S3C2410_OFFSET(IO_PORT, GSTATUS4, 0x00000000, io->gstatus4)
};
memset(io, 0, sizeof(s3c2410_io_port_t)); memset( io, 0, sizeof( s3c2410_io_port_t ) );
io->regs = malloc(sizeof(regs)); io->regs = malloc( sizeof( regs ) );
if (NULL == io->regs) { if ( NULL == io->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(io->regs, regs, sizeof(regs)); memcpy( io->regs, regs, sizeof( regs ) );
io->nr_regs = sizeof(regs) / sizeof(regs[0]); io->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_scan_keys( x49gp_t* x49gp, uint32_t gpgcon, uint32_t gpgdat )
s3c2410_scan_keys(x49gp_t *x49gp, uint32_t gpgcon, uint32_t gpgdat)
{ {
uint32_t result; uint32_t result;
int col, row; int col, row;
result = 0xfffe | (gpgdat & 1); result = 0xfffe | ( gpgdat & 1 );
for (col = 0; col < 8; col++) { for ( col = 0; col < 8; col++ ) {
switch ((gpgcon >> (2 * (col + 8))) & 3) { switch ( ( gpgcon >> ( 2 * ( col + 8 ) ) ) & 3 ) {
case 0: /* Input */ case 0: /* Input */
case 2: /* Interrupt */ case 2: /* Interrupt */
case 3: /* Reserved */ case 3: /* Reserved */
break; break;
case 1: /* Output */ case 1: /* Output */
result &= ~(1 << (col + 8)); result &= ~( 1 << ( col + 8 ) );
result |= gpgdat & (1 << (col + 8)); result |= gpgdat & ( 1 << ( col + 8 ) );
if (0 == (gpgdat & (1 << (col + 8)))) { if ( 0 == ( gpgdat & ( 1 << ( col + 8 ) ) ) ) {
result &= ~(x49gp->keybycol[col]); result &= ~( x49gp->keybycol[ col ] );
} }
break; break;
} }
} }
for (row = 1; row < 8; row++) { for ( row = 1; row < 8; row++ ) {
switch ((gpgcon >> (2 * row)) & 3) { switch ( ( gpgcon >> ( 2 * row ) ) & 3 ) {
case 0: /* Input */ case 0: /* Input */
case 2: /* Interrupt */ case 2: /* Interrupt */
case 3: /* Reserved */ case 3: /* Reserved */
break; break;
case 1: /* Output */ case 1: /* Output */
result &= ~(1 << row); result &= ~( 1 << row );
result |= gpgdat & (1 << row); result |= gpgdat & ( 1 << row );
if (0 == (gpgdat & (1 << row))) { if ( 0 == ( gpgdat & ( 1 << row ) ) ) {
result &= ~(x49gp->keybyrow[row] << 8); result &= ~( x49gp->keybyrow[ row ] << 8 );
} }
break; break;
} }
@ -185,142 +165,135 @@ s3c2410_scan_keys(x49gp_t *x49gp, uint32_t gpgcon, uint32_t gpgdat)
return result; return result;
} }
static uint32_t static uint32_t s3c2410_io_port_read( void* opaque, target_phys_addr_t offset )
s3c2410_io_port_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_io_port_t *io = opaque; s3c2410_io_port_t* io = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(io, offset)) { if ( !S3C2410_OFFSET_OK( io, offset ) ) {
fprintf(stderr, "%s:%u: offset %08lx not OK\n", __FUNCTION__, __LINE__, (unsigned long) offset); fprintf( stderr, "%s:%u: offset %08lx not OK\n", __FUNCTION__, __LINE__, ( unsigned long )offset );
abort(); abort();
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(io, offset); reg = S3C2410_OFFSET_ENTRY( io, offset );
switch (offset) { switch ( offset ) {
case S3C2410_IO_PORT_MISCCR: case S3C2410_IO_PORT_MISCCR:
// if (io->x49gp->arm->NresetSig != LOW) { // if (io->x49gp->arm->NresetSig != LOW) {
*(reg->datap) |= 0x00010000; *( reg->datap ) |= 0x00010000;
// } // }
break; break;
case S3C2410_IO_PORT_GPCDAT: case S3C2410_IO_PORT_GPCDAT:
if (0 == ((io->gpccon >> 30) & 3)) { if ( 0 == ( ( io->gpccon >> 30 ) & 3 ) ) {
*(reg->datap) |= 0x8000; *( reg->datap ) |= 0x8000;
} }
if (0 == ((io->gpccon >> 28) & 3)) { if ( 0 == ( ( io->gpccon >> 28 ) & 3 ) ) {
*(reg->datap) |= 0x4000; *( reg->datap ) |= 0x4000;
} }
if (0 == ((io->gpccon >> 26) & 3)) { if ( 0 == ( ( io->gpccon >> 26 ) & 3 ) ) {
*(reg->datap) |= 0x2000; *( reg->datap ) |= 0x2000;
} }
if (0 == ((io->gpccon >> 24) & 3)) { if ( 0 == ( ( io->gpccon >> 24 ) & 3 ) ) {
*(reg->datap) |= 0x1000; *( reg->datap ) |= 0x1000;
} }
break; break;
case S3C2410_IO_PORT_GPDDAT: case S3C2410_IO_PORT_GPDDAT:
if (0 == ((io->gpdcon >> 6) & 3)) { if ( 0 == ( ( io->gpdcon >> 6 ) & 3 ) ) {
*(reg->datap) |= 0x0008; *( reg->datap ) |= 0x0008;
} }
break; break;
case S3C2410_IO_PORT_GPEDAT: case S3C2410_IO_PORT_GPEDAT:
if (0 == ((io->gpecon >> 30) & 3)) { if ( 0 == ( ( io->gpecon >> 30 ) & 3 ) ) {
*(reg->datap) |= 0x8000; *( reg->datap ) |= 0x8000;
} }
if (0 == ((io->gpecon >> 28) & 3)) { if ( 0 == ( ( io->gpecon >> 28 ) & 3 ) ) {
*(reg->datap) |= 0x4000; *( reg->datap ) |= 0x4000;
} }
break; break;
case S3C2410_IO_PORT_GPFDAT: case S3C2410_IO_PORT_GPFDAT:
#if 1 #if 1
if (1 != ((io->gpfcon >> 6) & 3)) { if ( 1 != ( ( io->gpfcon >> 6 ) & 3 ) ) {
*(reg->datap) |= 0x0008; *( reg->datap ) |= 0x0008;
} }
#endif #endif
break; break;
case S3C2410_IO_PORT_GPGDAT: case S3C2410_IO_PORT_GPGDAT:
return s3c2410_scan_keys(io->x49gp, io->gpgcon, io->gpgdat); return s3c2410_scan_keys( io->x49gp, io->gpgcon, io->gpgdat );
case S3C2410_IO_PORT_GPHDAT: case S3C2410_IO_PORT_GPHDAT:
if (0 == ((io->gphcon >> 14) & 3)) { if ( 0 == ( ( io->gphcon >> 14 ) & 3 ) ) {
*(reg->datap) |= 0x80; *( reg->datap ) |= 0x80;
} }
if (0 == ((io->gphcon >> 12) & 3)) { if ( 0 == ( ( io->gphcon >> 12 ) & 3 ) ) {
*(reg->datap) &= ~(0x40); *( reg->datap ) &= ~( 0x40 );
} }
break; break;
} }
#ifdef DEBUG_S3C2410_IO_PORT #ifdef DEBUG_S3C2410_IO_PORT
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-io-port", S3C2410_IO_PORT_BASE, reg->name, ( unsigned long )offset,
"s3c2410-io-port", S3C2410_IO_PORT_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_io_port_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_io_port_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_io_port_t *io = opaque; s3c2410_io_port_t* io = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t change; uint32_t change;
static uint32_t lcd_data = 0; static uint32_t lcd_data = 0;
if (! S3C2410_OFFSET_OK(io, offset)) { if ( !S3C2410_OFFSET_OK( io, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(io, offset); reg = S3C2410_OFFSET_ENTRY( io, offset );
#ifdef DEBUG_S3C2410_IO_PORT #ifdef DEBUG_S3C2410_IO_PORT
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-io-port", S3C2410_IO_PORT_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-io-port", S3C2410_IO_PORT_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_IO_PORT_GPDDAT: case S3C2410_IO_PORT_GPDDAT:
change = *(reg->datap) ^ data; change = *( reg->datap ) ^ data;
*(reg->datap) = data; *( reg->datap ) = data;
if (!(data & 0x200) && (change & 0x200)) { if ( !( data & 0x200 ) && ( change & 0x200 ) ) {
lcd_data = 0; lcd_data = 0;
} }
if (!(data & 0x200) && (data & 0x2000) && (change & 0x2000)) { if ( !( data & 0x200 ) && ( data & 0x2000 ) && ( change & 0x2000 ) ) {
#ifdef DEBUG_S3C2410_IO_PORT #ifdef DEBUG_S3C2410_IO_PORT
printf("IO_PORT GPDDAT: clk0 rise: data %u\n", printf( "IO_PORT GPDDAT: clk0 rise: data %u\n", ( data >> 12 ) & 1 );
(data >> 12) & 1);
#endif #endif
lcd_data <<= 1; lcd_data <<= 1;
lcd_data |= (data >> 12) & 1; lcd_data |= ( data >> 12 ) & 1;
} }
if ((data & 0x200) && (change & 0x200)) { if ( ( data & 0x200 ) && ( change & 0x200 ) ) {
#ifdef DEBUG_S3C2410_IO_PORT #ifdef DEBUG_S3C2410_IO_PORT
printf("IO_PORT GPDDAT: cs0 rise: data %04x\n", printf( "IO_PORT GPDDAT: cs0 rise: data %04x\n", lcd_data );
lcd_data);
#endif #endif
} }
break; break;
case S3C2410_IO_PORT_MISCCR: case S3C2410_IO_PORT_MISCCR:
*(reg->datap) = data; *( reg->datap ) = data;
if (!(*(reg->datap) & 0x00010000)) { if ( !( *( reg->datap ) & 0x00010000 ) ) {
*(reg->datap) = 0x10330; *( reg->datap ) = 0x10330;
// if (io->x49gp->arm->NresetSig != LOW) { // if (io->x49gp->arm->NresetSig != LOW) {
// io->x49gp->arm->NresetSig = LOW; // io->x49gp->arm->NresetSig = LOW;
// io->x49gp->arm->Exception++; // io->x49gp->arm->Exception++;
// } // }
} }
break; break;
@ -330,96 +303,91 @@ static uint32_t lcd_data = 0;
break; break;
case S3C2410_IO_PORT_GSTATUS2: case S3C2410_IO_PORT_GSTATUS2:
*(reg->datap) &= ~(data & 7); *( reg->datap ) &= ~( data & 7 );
break; break;
case S3C2410_IO_PORT_EINTPEND: case S3C2410_IO_PORT_EINTPEND:
*(reg->datap) &= ~(data); *( reg->datap ) &= ~( data );
if (0 == (*(reg->datap) & 0x000000f0)) if ( 0 == ( *( reg->datap ) & 0x000000f0 ) )
s3c2410_intc_deassert(io->x49gp, EINT4_7); s3c2410_intc_deassert( io->x49gp, EINT4_7 );
if (0 == (*(reg->datap) & 0x00ffff00)) if ( 0 == ( *( reg->datap ) & 0x00ffff00 ) )
s3c2410_intc_deassert(io->x49gp, EINT8_23); s3c2410_intc_deassert( io->x49gp, EINT8_23 );
break; break;
default: default:
*(reg->datap) = data; *( reg->datap ) = data;
break; break;
} }
} }
void void s3c2410_io_port_g_update( x49gp_t* x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state )
s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state)
{ {
s3c2410_io_port_t *io = x49gp->s3c2410_io_port; s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
uint32_t oldvalue, newvalue, change; uint32_t oldvalue, newvalue, change;
int n; int n;
oldvalue = s3c2410_scan_keys(x49gp, io->gpgcon, io->gpgdat); oldvalue = s3c2410_scan_keys( x49gp, io->gpgcon, io->gpgdat );
if (new_state) { if ( new_state ) {
x49gp->keybycol[column] |= rowbit; x49gp->keybycol[ column ] |= rowbit;
x49gp->keybyrow[row] |= columnbit; x49gp->keybyrow[ row ] |= columnbit;
} else { } else {
x49gp->keybycol[column] &= ~rowbit; x49gp->keybycol[ column ] &= ~rowbit;
x49gp->keybyrow[row] &= ~columnbit; x49gp->keybyrow[ row ] &= ~columnbit;
} }
newvalue = s3c2410_scan_keys(x49gp, io->gpgcon, io->gpgdat); newvalue = s3c2410_scan_keys( x49gp, io->gpgcon, io->gpgdat );
change=newvalue^oldvalue; change = newvalue ^ oldvalue;
for ( n = 0; n < 15; ++n ) {
for(n=0;n<15;++n) { switch ( ( io->gpgcon >> ( 2 * n ) ) & 3 ) {
switch ((io->gpgcon >> (2 * n)) & 3) {
case 2: /* Interrupt */ case 2: /* Interrupt */
{ {
switch (n+8<=15 ? switch ( n + 8 <= 15 ? ( io->extint1 >> ( 4 * n ) ) & 7 : // EINT 8-15
(io->extint1 >> (4 * n)) & 7 : // EINT 8-15 ( io->extint2 >> ( 4 * ( n - 8 ) ) ) & 7 // EINT 16-23
(io->extint2 >> (4 * (n-8))) & 7 // EINT 16-23
) { ) {
case 0: /* Low Level */ case 0: /* Low Level */
if (!(newvalue & (1 << n))) if ( !( newvalue & ( 1 << n ) ) ) {
{ io->eintpend |= 1 << ( n + 8 );
io->eintpend |= 1 << (n + 8); if ( io->eintpend & ~( io->eintmask ) )
if (io->eintpend & ~(io->eintmask)) s3c2410_intc_assert( x49gp, EINT8_23, 1 );
s3c2410_intc_assert(x49gp, EINT8_23, 1);
} }
break; break;
case 1: /* High Level */ case 1: /* High Level */
if (newvalue & (1 << n)) { if ( newvalue & ( 1 << n ) ) {
io->eintpend |= 1 << (n + 8); io->eintpend |= 1 << ( n + 8 );
if (io->eintpend & ~(io->eintmask)) if ( io->eintpend & ~( io->eintmask ) )
s3c2410_intc_assert(x49gp, EINT8_23, 1); s3c2410_intc_assert( x49gp, EINT8_23, 1 );
} }
break; break;
case 2: /* Falling Edge */ case 2: /* Falling Edge */
case 3: case 3:
if ((change & (1 << n)) && !(newvalue & (1 << n))) { if ( ( change & ( 1 << n ) ) && !( newvalue & ( 1 << n ) ) ) {
io->eintpend |= 1 << (n + 8); io->eintpend |= 1 << ( n + 8 );
if (io->eintpend & ~(io->eintmask)) if ( io->eintpend & ~( io->eintmask ) )
s3c2410_intc_assert(x49gp, EINT8_23, 1); s3c2410_intc_assert( x49gp, EINT8_23, 1 );
} }
break; break;
case 4: /* Rising Edge */ case 4: /* Rising Edge */
case 5: case 5:
if ((change & (1 << n)) && (newvalue & (1 << n))) { if ( ( change & ( 1 << n ) ) && ( newvalue & ( 1 << n ) ) ) {
io->eintpend |= 1 << (n + 8); io->eintpend |= 1 << ( n + 8 );
if (io->eintpend & ~(io->eintmask)) if ( io->eintpend & ~( io->eintmask ) )
s3c2410_intc_assert(x49gp, EINT8_23, 1); s3c2410_intc_assert( x49gp, EINT8_23, 1 );
} }
break; break;
case 6: /* Any Edge */ case 6: /* Any Edge */
case 7: case 7:
if (change & (1 << n)) { if ( change & ( 1 << n ) ) {
io->eintpend |= 1 << (n + 8); io->eintpend |= 1 << ( n + 8 );
if (io->eintpend & ~(io->eintmask)) if ( io->eintpend & ~( io->eintmask ) )
s3c2410_intc_assert(x49gp, EINT8_23, 1); s3c2410_intc_assert( x49gp, EINT8_23, 1 );
} }
break; break;
} }
} }
break; break;
@ -428,35 +396,33 @@ s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char colu
case 3: /* Reserved */ case 3: /* Reserved */
break; break;
} }
} }
return; return;
} }
void void s3c2410_io_port_f_set_bit( x49gp_t* x49gp, int n, uint32_t value )
s3c2410_io_port_f_set_bit(x49gp_t *x49gp, int n, uint32_t value)
{ {
s3c2410_io_port_t *io = x49gp->s3c2410_io_port; s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
uint32_t change; uint32_t change;
int pending, level; int pending, level;
if (n > 7) if ( n > 7 )
return; return;
// g_mutex_lock(x49gp->memlock); // g_mutex_lock(x49gp->memlock);
change = 0; change = 0;
switch ((io->gpfcon >> (2 * n)) & 3) { switch ( ( io->gpfcon >> ( 2 * n ) ) & 3 ) {
case 0: /* Input */ case 0: /* Input */
io->gpfdat &= ~(1 << n); io->gpfdat &= ~( 1 << n );
io->gpfdat |= (value << n); io->gpfdat |= ( value << n );
goto out; goto out;
case 2: /* Interrupt */ case 2: /* Interrupt */
change = io->gpfdat ^ (value << n); change = io->gpfdat ^ ( value << n );
io->gpfdat &= ~(1 << n); io->gpfdat &= ~( 1 << n );
io->gpfdat |= (value << n); io->gpfdat |= ( value << n );
break; break;
case 1: /* Output */ case 1: /* Output */
@ -466,183 +432,167 @@ s3c2410_io_port_f_set_bit(x49gp_t *x49gp, int n, uint32_t value)
pending = -1; pending = -1;
level = 0; level = 0;
switch ((io->extint0 >> (4 * n)) & 7) { switch ( ( io->extint0 >> ( 4 * n ) ) & 7 ) {
case 0: /* Low Level */ case 0: /* Low Level */
if (!(io->gpfdat & (1 << n))) if ( !( io->gpfdat & ( 1 << n ) ) )
pending = n; pending = n;
level = 1; level = 1;
break; break;
case 1: /* High Level */ case 1: /* High Level */
if (io->gpfdat & (1 << n)) if ( io->gpfdat & ( 1 << n ) )
pending = n; pending = n;
level = 1; level = 1;
break; break;
case 2: /* Falling Edge */ case 2: /* Falling Edge */
case 3: case 3:
if ((change & (1 << n)) && !(io->gpfdat & (1 << n))) if ( ( change & ( 1 << n ) ) && !( io->gpfdat & ( 1 << n ) ) )
pending = n; pending = n;
break; break;
case 4: /* Rising Edge */ case 4: /* Rising Edge */
case 5: case 5:
if ((change & (1 << n)) && (io->gpfdat & (1 << n))) if ( ( change & ( 1 << n ) ) && ( io->gpfdat & ( 1 << n ) ) )
pending = n; pending = n;
break; break;
case 6: /* Any Edge */ case 6: /* Any Edge */
case 7: case 7:
if (change & (1 << n)) if ( change & ( 1 << n ) )
pending = n; pending = n;
break; break;
} }
if (-1 == pending) if ( -1 == pending )
goto out; goto out;
switch (n) { switch ( n ) {
case 0: case 0:
s3c2410_intc_assert(x49gp, EINT0, level); s3c2410_intc_assert( x49gp, EINT0, level );
break; break;
case 1: case 1:
s3c2410_intc_assert(x49gp, EINT1, level); s3c2410_intc_assert( x49gp, EINT1, level );
break; break;
case 2: case 2:
s3c2410_intc_assert(x49gp, EINT2, level); s3c2410_intc_assert( x49gp, EINT2, level );
break; break;
case 3: case 3:
s3c2410_intc_assert(x49gp, EINT3, level); s3c2410_intc_assert( x49gp, EINT3, level );
break; break;
case 4: case 4:
case 5: case 5:
case 6: case 6:
case 7: case 7:
io->eintpend |= (1 << n); io->eintpend |= ( 1 << n );
if (io->eintpend & ~(io->eintmask)) if ( io->eintpend & ~( io->eintmask ) )
s3c2410_intc_assert(x49gp, EINT4_7, 1); s3c2410_intc_assert( x49gp, EINT4_7, 1 );
break; break;
} }
out: out:
// g_mutex_unlock(x49gp->memlock); // g_mutex_unlock(x49gp->memlock);
return; return;
} }
static int static int s3c2410_io_port_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_io_port_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_io_port_t *io = module->user_data; s3c2410_io_port_t* io = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < io->nr_regs; i++) { for ( i = 0; i < io->nr_regs; i++ ) {
reg = &io->regs[i]; reg = &io->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_io_port_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_io_port_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_io_port_t *io = module->user_data; s3c2410_io_port_t* io = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < io->nr_regs; i++) { for ( i = 0; i < io->nr_regs; i++ ) {
reg = &io->regs[i]; reg = &io->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_io_port_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_io_port_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_io_port_t *io = module->user_data; s3c2410_io_port_t* io = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (reset == X49GP_RESET_POWER_OFF) { if ( reset == X49GP_RESET_POWER_OFF ) {
io->gstatus2 = 2; io->gstatus2 = 2;
return 0; return 0;
} }
for (i = 0; i < io->nr_regs; i++) { for ( i = 0; i < io->nr_regs; i++ ) {
reg = &io->regs[i]; reg = &io->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
if (reset == X49GP_RESET_WATCHDOG) { if ( reset == X49GP_RESET_WATCHDOG ) {
io->gstatus2 = 4; io->gstatus2 = 4;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_io_port_readfn[] = static CPUReadMemoryFunc* s3c2410_io_port_readfn[] = { s3c2410_io_port_read, s3c2410_io_port_read, s3c2410_io_port_read };
{
s3c2410_io_port_read,
s3c2410_io_port_read,
s3c2410_io_port_read
};
static CPUWriteMemoryFunc *s3c2410_io_port_writefn[] = static CPUWriteMemoryFunc* s3c2410_io_port_writefn[] = { s3c2410_io_port_write, s3c2410_io_port_write, s3c2410_io_port_write };
{
s3c2410_io_port_write,
s3c2410_io_port_write,
s3c2410_io_port_write
};
static int static int s3c2410_io_port_init( x49gp_module_t* module )
s3c2410_io_port_init(x49gp_module_t *module)
{ {
s3c2410_io_port_t *io; s3c2410_io_port_t* io;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
io = malloc(sizeof(s3c2410_io_port_t)); io = malloc( sizeof( s3c2410_io_port_t ) );
if (NULL == io) { if ( NULL == io ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_io_port_data_init(io)) { if ( s3c2410_io_port_data_init( io ) ) {
free(io); free( io );
return -ENOMEM; return -ENOMEM;
} }
@ -650,51 +600,43 @@ s3c2410_io_port_init(x49gp_module_t *module)
module->x49gp->s3c2410_io_port = io; module->x49gp->s3c2410_io_port = io;
io->x49gp = module->x49gp; io->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_io_port_readfn, iotype = cpu_register_io_memory( s3c2410_io_port_readfn, s3c2410_io_port_writefn, io );
s3c2410_io_port_writefn, io);
#ifdef DEBUG_S3C2410_IO_PORT #ifdef DEBUG_S3C2410_IO_PORT
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_IO_PORT_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_IO_PORT_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_io_port_exit( x49gp_module_t* module )
s3c2410_io_port_exit(x49gp_module_t *module)
{ {
s3c2410_io_port_t *io; s3c2410_io_port_t* io;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
io = module->user_data; io = module->user_data;
if (io->regs) if ( io->regs )
free(io->regs); free( io->regs );
free(io); free( io );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_io_port_init( x49gp_t* x49gp )
x49gp_s3c2410_io_port_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-io-port", if ( x49gp_module_init( x49gp, "s3c2410-io-port", s3c2410_io_port_init, s3c2410_io_port_exit, s3c2410_io_port_reset,
s3c2410_io_port_init, s3c2410_io_port_load, s3c2410_io_port_save, NULL, &module ) ) {
s3c2410_io_port_exit,
s3c2410_io_port_reset,
s3c2410_io_port_load,
s3c2410_io_port_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -15,7 +15,6 @@
#include "x49gp_ui.h" #include "x49gp_ui.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct { typedef struct {
uint32_t lcdcon1; uint32_t lcdcon1;
uint32_t lcdcon2; uint32_t lcdcon2;
@ -37,143 +36,122 @@ typedef struct {
uint32_t __unknown_68; uint32_t __unknown_68;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_lcd_t; } s3c2410_lcd_t;
static int static int s3c2410_lcd_data_init( s3c2410_lcd_t* lcd )
s3c2410_lcd_data_init(s3c2410_lcd_t *lcd)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(LCD, LCDCON1, 0x00000000, lcd->lcdcon1), S3C2410_OFFSET( LCD, LCDCON1, 0x00000000, lcd->lcdcon1 ), S3C2410_OFFSET( LCD, LCDCON2, 0x00000000, lcd->lcdcon2 ),
S3C2410_OFFSET(LCD, LCDCON2, 0x00000000, lcd->lcdcon2), S3C2410_OFFSET( LCD, LCDCON3, 0x00000000, lcd->lcdcon3 ), S3C2410_OFFSET( LCD, LCDCON4, 0x00000000, lcd->lcdcon4 ),
S3C2410_OFFSET(LCD, LCDCON3, 0x00000000, lcd->lcdcon3), S3C2410_OFFSET( LCD, LCDCON5, 0x00000000, lcd->lcdcon5 ), S3C2410_OFFSET( LCD, LCDSADDR1, 0x00000000, lcd->lcdsaddr1 ),
S3C2410_OFFSET(LCD, LCDCON4, 0x00000000, lcd->lcdcon4), S3C2410_OFFSET( LCD, LCDSADDR2, 0x00000000, lcd->lcdsaddr2 ), S3C2410_OFFSET( LCD, LCDSADDR3, 0x00000000, lcd->lcdsaddr3 ),
S3C2410_OFFSET(LCD, LCDCON5, 0x00000000, lcd->lcdcon5), S3C2410_OFFSET( LCD, REDLUT, 0x00000000, lcd->redlut ), S3C2410_OFFSET( LCD, GREENLUT, 0x00000000, lcd->greenlut ),
S3C2410_OFFSET(LCD, LCDSADDR1, 0x00000000, lcd->lcdsaddr1), S3C2410_OFFSET( LCD, BLUELUT, 0x00000000, lcd->bluelut ), S3C2410_OFFSET( LCD, DITHMODE, 0x00000000, lcd->dithmode ),
S3C2410_OFFSET(LCD, LCDSADDR2, 0x00000000, lcd->lcdsaddr2), S3C2410_OFFSET( LCD, TPAL, 0x00000000, lcd->tpal ), S3C2410_OFFSET( LCD, LCDINTPND, 0x00000000, lcd->lcdintpnd ),
S3C2410_OFFSET(LCD, LCDSADDR3, 0x00000000, lcd->lcdsaddr3), S3C2410_OFFSET( LCD, LCDSRCPND, 0x00000000, lcd->lcdsrcpnd ), S3C2410_OFFSET( LCD, LCDINTMSK, 0x00000003, lcd->lcdintmsk ),
S3C2410_OFFSET(LCD, REDLUT, 0x00000000, lcd->redlut), S3C2410_OFFSET( LCD, LPCSEL, 0x00000004, lcd->lpcsel ), S3C2410_OFFSET( LCD, UNKNOWN_68, 0x00000000, lcd->__unknown_68 ) };
S3C2410_OFFSET(LCD, GREENLUT, 0x00000000, lcd->greenlut),
S3C2410_OFFSET(LCD, BLUELUT, 0x00000000, lcd->bluelut),
S3C2410_OFFSET(LCD, DITHMODE, 0x00000000, lcd->dithmode),
S3C2410_OFFSET(LCD, TPAL, 0x00000000, lcd->tpal),
S3C2410_OFFSET(LCD, LCDINTPND, 0x00000000, lcd->lcdintpnd),
S3C2410_OFFSET(LCD, LCDSRCPND, 0x00000000, lcd->lcdsrcpnd),
S3C2410_OFFSET(LCD, LCDINTMSK, 0x00000003, lcd->lcdintmsk),
S3C2410_OFFSET(LCD, LPCSEL, 0x00000004, lcd->lpcsel),
S3C2410_OFFSET(LCD, UNKNOWN_68, 0x00000000, lcd->__unknown_68)
};
memset(lcd, 0, sizeof(s3c2410_lcd_t)); memset( lcd, 0, sizeof( s3c2410_lcd_t ) );
lcd->regs = malloc(sizeof(regs)); lcd->regs = malloc( sizeof( regs ) );
if (NULL == lcd->regs) { if ( NULL == lcd->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(lcd->regs, regs, sizeof(regs)); memcpy( lcd->regs, regs, sizeof( regs ) );
lcd->nr_regs = sizeof(regs) / sizeof(regs[0]); lcd->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
void void x49gp_schedule_lcd_update( x49gp_t* x49gp )
x49gp_schedule_lcd_update(x49gp_t *x49gp)
{ {
if (! x49gp_timer_pending(x49gp->lcd_timer)) { if ( !x49gp_timer_pending( x49gp->lcd_timer ) ) {
x49gp_mod_timer(x49gp->lcd_timer, x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL );
x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL);
} }
} }
static int static int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y )
x49gp_get_pixel_color(s3c2410_lcd_t *lcd, int x, int y)
{ {
uint32_t bank, addr, data, offset, pixel_offset; uint32_t bank, addr, data, offset, pixel_offset;
int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5; int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5;
bank = (lcd->lcdsaddr1 << 1) & 0x7fc00000; bank = ( lcd->lcdsaddr1 << 1 ) & 0x7fc00000;
addr = bank | ((lcd->lcdsaddr1 << 1) & 0x003ffffe); addr = bank | ( ( lcd->lcdsaddr1 << 1 ) & 0x003ffffe );
pixel_offset = (160 * y + x) * bits_per_pixel; pixel_offset = ( 160 * y + x ) * bits_per_pixel;
offset = (pixel_offset >> 3) & 0xfffffffc; offset = ( pixel_offset >> 3 ) & 0xfffffffc;
data = ldl_phys(addr + offset); data = ldl_phys( addr + offset );
data >>= pixel_offset & 31; data >>= pixel_offset & 31;
data &= (1 << bits_per_pixel) - 1; data &= ( 1 << bits_per_pixel ) - 1;
switch (bits_per_pixel) { switch ( bits_per_pixel ) {
case 1: case 1:
return 15 * data; return 15 * data;
case 2: case 2:
return 15 & (lcd->bluelut >> (4 * data)); return 15 & ( lcd->bluelut >> ( 4 * data ) );
default: default:
return data; return data;
} }
} }
void void x49gp_lcd_update( x49gp_t* x49gp )
x49gp_lcd_update(x49gp_t *x49gp)
{ {
x49gp_ui_t *ui = x49gp->ui; x49gp_ui_t* ui = x49gp->ui;
s3c2410_lcd_t *lcd = x49gp->s3c2410_lcd; s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
GdkRectangle rect; GdkRectangle rect;
GdkGC *gc; GdkGC* gc;
int color, x, y; int color, x, y;
if (!(lcd->lcdcon1 & 1)) { if ( !( lcd->lcdcon1 & 1 ) ) {
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0], gdk_draw_drawable( ui->lcd_pixmap, ui->window->style->bg_gc[ 0 ], ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0,
ui->bg_pixmap, ui->lcd_width, ui->lcd_height );
ui->lcd_x_offset, ui->lcd_y_offset,
0, 0, ui->lcd_width, ui->lcd_height);
goto done; goto done;
} }
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0], gdk_draw_drawable( ui->lcd_pixmap, ui->window->style->bg_gc[ 0 ], ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0,
ui->bg_pixmap, ui->lcd_width, ui->lcd_height );
ui->lcd_x_offset, ui->lcd_y_offset,
0, 0, ui->lcd_width, ui->lcd_height);
color = x49gp_get_pixel_color(lcd, 131, 0); color = x49gp_get_pixel_color( lcd, 131, 0 );
gdk_gc_set_rgb_fg_color(ui->ann_io_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_io_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_io_gc, TRUE, 236, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_io_gc, TRUE, 236, 0, 15, 12 );
color = x49gp_get_pixel_color(lcd, 131, 1); color = x49gp_get_pixel_color( lcd, 131, 1 );
gdk_gc_set_rgb_fg_color(ui->ann_left_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_left_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_left_gc, TRUE, 11, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_left_gc, TRUE, 11, 0, 15, 12 );
color = x49gp_get_pixel_color(lcd, 131, 2); color = x49gp_get_pixel_color( lcd, 131, 2 );
gdk_gc_set_rgb_fg_color(ui->ann_right_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_right_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_right_gc, TRUE, 56, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_right_gc, TRUE, 56, 0, 15, 12 );
color = x49gp_get_pixel_color(lcd, 131, 3); color = x49gp_get_pixel_color( lcd, 131, 3 );
gdk_gc_set_rgb_fg_color(ui->ann_alpha_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_alpha_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_alpha_gc, TRUE, 101, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_alpha_gc, TRUE, 101, 0, 15, 12 );
color = x49gp_get_pixel_color(lcd, 131, 4); color = x49gp_get_pixel_color( lcd, 131, 4 );
gdk_gc_set_rgb_fg_color(ui->ann_battery_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_battery_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_battery_gc, TRUE, 146, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_battery_gc, TRUE, 146, 0, 15, 12 );
color = x49gp_get_pixel_color(lcd, 131, 5); color = x49gp_get_pixel_color( lcd, 131, 5 );
gdk_gc_set_rgb_fg_color(ui->ann_busy_gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( ui->ann_busy_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, ui->ann_busy_gc, TRUE, 191, 0, 15, 12); gdk_draw_rectangle( ui->lcd_pixmap, ui->ann_busy_gc, TRUE, 191, 0, 15, 12 );
gc = gdk_gc_new(ui->lcd_canvas->window); gc = gdk_gc_new( ui->lcd_canvas->window );
for (y = 0; y < (ui->lcd_height - ui->lcd_top_margin) / 2; y++) { for ( y = 0; y < ( ui->lcd_height - ui->lcd_top_margin ) / 2; y++ ) {
for (x = 0; x < ui->lcd_width / 2; x++) { for ( x = 0; x < ui->lcd_width / 2; x++ ) {
color = x49gp_get_pixel_color(lcd, x, y); color = x49gp_get_pixel_color( lcd, x, y );
gdk_gc_set_rgb_fg_color(gc, &(ui->colors[UI_COLOR_GRAYSCALE_0 + color])); gdk_gc_set_rgb_fg_color( gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
gdk_draw_rectangle(ui->lcd_pixmap, gc, TRUE, gdk_draw_rectangle( ui->lcd_pixmap, gc, TRUE, 2 * x, 2 * y + ui->lcd_top_margin, 2, 2 );
2 * x, 2 * y + ui->lcd_top_margin, 2, 2);
} }
} }
g_object_unref(gc); g_object_unref( gc );
done: done:
rect.x = 0; rect.x = 0;
@ -181,184 +159,160 @@ done:
rect.width = ui->lcd_width; rect.width = ui->lcd_width;
rect.height = ui->lcd_height; rect.height = ui->lcd_height;
gdk_window_invalidate_rect(ui->lcd_canvas->window, &rect, FALSE); gdk_window_invalidate_rect( ui->lcd_canvas->window, &rect, FALSE );
} }
static uint32_t s3c2410_lcd_read( void* opaque, target_phys_addr_t offset )
static uint32_t
s3c2410_lcd_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_lcd_t *lcd = opaque; s3c2410_lcd_t* lcd = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t linecnt; uint32_t linecnt;
if (! S3C2410_OFFSET_OK(lcd, offset)) { if ( !S3C2410_OFFSET_OK( lcd, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(lcd, offset); reg = S3C2410_OFFSET_ENTRY( lcd, offset );
switch (offset) { switch ( offset ) {
case S3C2410_LCD_LCDCON1: case S3C2410_LCD_LCDCON1:
linecnt = (lcd->lcdcon1 >> 18) & 0x3ff; linecnt = ( lcd->lcdcon1 >> 18 ) & 0x3ff;
if (linecnt > 0) { if ( linecnt > 0 ) {
linecnt--; linecnt--;
} else { } else {
linecnt = (lcd->lcdcon2 >> 14) & 0x3ff; linecnt = ( lcd->lcdcon2 >> 14 ) & 0x3ff;
} }
lcd->lcdcon1 &= ~(0x3ff << 18); lcd->lcdcon1 &= ~( 0x3ff << 18 );
lcd->lcdcon1 |= (linecnt << 18); lcd->lcdcon1 |= ( linecnt << 18 );
} }
#ifdef DEBUG_S3C2410_LCD #ifdef DEBUG_S3C2410_LCD
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-lcd", S3C2410_LCD_BASE, reg->name, ( unsigned long )offset,
"s3c2410-lcd", S3C2410_LCD_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_lcd_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_lcd_t *lcd = opaque; s3c2410_lcd_t* lcd = opaque;
x49gp_t *x49gp = lcd->x49gp; x49gp_t* x49gp = lcd->x49gp;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(lcd, offset)) { if ( !S3C2410_OFFSET_OK( lcd, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(lcd, offset); reg = S3C2410_OFFSET_ENTRY( lcd, offset );
#ifdef DEBUG_S3C2410_LCD #ifdef DEBUG_S3C2410_LCD
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-lcd", S3C2410_LCD_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-lcd", S3C2410_LCD_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_LCD_LCDCON1: case S3C2410_LCD_LCDCON1:
if ((lcd->lcdcon1 ^ data) & 1) { if ( ( lcd->lcdcon1 ^ data ) & 1 ) {
x49gp_schedule_lcd_update(x49gp); x49gp_schedule_lcd_update( x49gp );
} }
lcd->lcdcon1 = (lcd->lcdcon1 & (0x3ff << 18)) | lcd->lcdcon1 = ( lcd->lcdcon1 & ( 0x3ff << 18 ) ) | ( data & ~( 0x3ff << 18 ) );
(data & ~(0x3ff << 18));
break; break;
default: default:
*(reg->datap) = data; *( reg->datap ) = data;
break; break;
} }
} }
static int s3c2410_lcd_load( x49gp_module_t* module, GKeyFile* key )
static int
s3c2410_lcd_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_lcd_t *lcd = module->user_data; s3c2410_lcd_t* lcd = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < lcd->nr_regs; i++) { for ( i = 0; i < lcd->nr_regs; i++ ) {
reg = &lcd->regs[i]; reg = &lcd->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_lcd_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_lcd_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_lcd_t *lcd = module->user_data; s3c2410_lcd_t* lcd = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < lcd->nr_regs; i++) { for ( i = 0; i < lcd->nr_regs; i++ ) {
reg = &lcd->regs[i]; reg = &lcd->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_lcd_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_lcd_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_lcd_t *lcd = module->user_data; s3c2410_lcd_t* lcd = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < lcd->nr_regs; i++) { for ( i = 0; i < lcd->nr_regs; i++ ) {
reg = &lcd->regs[i]; reg = &lcd->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_lcd_readfn[] = static CPUReadMemoryFunc* s3c2410_lcd_readfn[] = { s3c2410_lcd_read, s3c2410_lcd_read, s3c2410_lcd_read };
{
s3c2410_lcd_read,
s3c2410_lcd_read,
s3c2410_lcd_read
};
static CPUWriteMemoryFunc *s3c2410_lcd_writefn[] = static CPUWriteMemoryFunc* s3c2410_lcd_writefn[] = { s3c2410_lcd_write, s3c2410_lcd_write, s3c2410_lcd_write };
{
s3c2410_lcd_write,
s3c2410_lcd_write,
s3c2410_lcd_write
};
static int static int s3c2410_lcd_init( x49gp_module_t* module )
s3c2410_lcd_init(x49gp_module_t *module)
{ {
s3c2410_lcd_t *lcd; s3c2410_lcd_t* lcd;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
lcd = malloc(sizeof(s3c2410_lcd_t)); lcd = malloc( sizeof( s3c2410_lcd_t ) );
if (NULL == lcd) { if ( NULL == lcd ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_lcd_data_init(lcd)) { if ( s3c2410_lcd_data_init( lcd ) ) {
free(lcd); free( lcd );
return -ENOMEM; return -ENOMEM;
} }
@ -366,51 +320,43 @@ s3c2410_lcd_init(x49gp_module_t *module)
module->x49gp->s3c2410_lcd = lcd; module->x49gp->s3c2410_lcd = lcd;
lcd->x49gp = module->x49gp; lcd->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_lcd_readfn, iotype = cpu_register_io_memory( s3c2410_lcd_readfn, s3c2410_lcd_writefn, lcd );
s3c2410_lcd_writefn, lcd);
#ifdef DEBUG_S3C2410_LCD #ifdef DEBUG_S3C2410_LCD
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_LCD_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_LCD_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_lcd_exit( x49gp_module_t* module )
s3c2410_lcd_exit(x49gp_module_t *module)
{ {
s3c2410_lcd_t *lcd; s3c2410_lcd_t* lcd;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
lcd = module->user_data; lcd = module->user_data;
if (lcd->regs) if ( lcd->regs )
free(lcd->regs); free( lcd->regs );
free(lcd); free( lcd );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_lcd_init( x49gp_t* x49gp )
x49gp_s3c2410_lcd_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-lcd", if ( x49gp_module_init( x49gp, "s3c2410-lcd", s3c2410_lcd_init, s3c2410_lcd_exit, s3c2410_lcd_reset, s3c2410_lcd_load, s3c2410_lcd_save,
s3c2410_lcd_init, NULL, &module ) ) {
s3c2410_lcd_exit,
s3c2410_lcd_reset,
s3c2410_lcd_load,
s3c2410_lcd_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -12,7 +12,6 @@
#include "x49gp.h" #include "x49gp.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct { typedef struct {
uint32_t bwscon; uint32_t bwscon;
uint32_t bankcon0; uint32_t bankcon0;
@ -29,246 +28,215 @@ typedef struct {
uint32_t mrsrb7; uint32_t mrsrb7;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_memc_t; } s3c2410_memc_t;
static int static int s3c2410_memc_data_init( s3c2410_memc_t* memc )
s3c2410_memc_data_init(s3c2410_memc_t *memc)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(MEMC, BWSCON, 0x00000000, memc->bwscon), S3C2410_OFFSET( MEMC, BWSCON, 0x00000000, memc->bwscon ),
S3C2410_OFFSET(MEMC, BANKCON0, 0x00000700, memc->bankcon0), S3C2410_OFFSET( MEMC, BANKCON0, 0x00000700, memc->bankcon0 ),
S3C2410_OFFSET(MEMC, BANKCON1, 0x00000700, memc->bankcon1), S3C2410_OFFSET( MEMC, BANKCON1, 0x00000700, memc->bankcon1 ),
S3C2410_OFFSET(MEMC, BANKCON2, 0x00000700, memc->bankcon2), S3C2410_OFFSET( MEMC, BANKCON2, 0x00000700, memc->bankcon2 ),
S3C2410_OFFSET(MEMC, BANKCON3, 0x00000700, memc->bankcon3), S3C2410_OFFSET( MEMC, BANKCON3, 0x00000700, memc->bankcon3 ),
S3C2410_OFFSET(MEMC, BANKCON4, 0x00000700, memc->bankcon4), S3C2410_OFFSET( MEMC, BANKCON4, 0x00000700, memc->bankcon4 ),
S3C2410_OFFSET(MEMC, BANKCON5, 0x00000700, memc->bankcon5), S3C2410_OFFSET( MEMC, BANKCON5, 0x00000700, memc->bankcon5 ),
S3C2410_OFFSET(MEMC, BANKCON6, 0x00018008, memc->bankcon6), S3C2410_OFFSET( MEMC, BANKCON6, 0x00018008, memc->bankcon6 ),
S3C2410_OFFSET(MEMC, BANKCON7, 0x00018008, memc->bankcon7), S3C2410_OFFSET( MEMC, BANKCON7, 0x00018008, memc->bankcon7 ),
S3C2410_OFFSET(MEMC, REFRESH, 0x00ac0000, memc->refresh), S3C2410_OFFSET( MEMC, REFRESH, 0x00ac0000, memc->refresh ),
S3C2410_OFFSET(MEMC, BANKSIZE, 0x00000000, memc->banksize), S3C2410_OFFSET( MEMC, BANKSIZE, 0x00000000, memc->banksize ),
S3C2410_OFFSET(MEMC, MRSRB6, 0, memc->mrsrb6), S3C2410_OFFSET( MEMC, MRSRB6, 0, memc->mrsrb6 ),
S3C2410_OFFSET(MEMC, MRSRB7, 0, memc->mrsrb7), S3C2410_OFFSET( MEMC, MRSRB7, 0, memc->mrsrb7 ),
}; };
memset(memc, 0, sizeof(s3c2410_memc_t)); memset( memc, 0, sizeof( s3c2410_memc_t ) );
memc->regs = malloc(sizeof(regs)); memc->regs = malloc( sizeof( regs ) );
if (NULL == memc->regs) { if ( NULL == memc->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(memc->regs, regs, sizeof(regs)); memcpy( memc->regs, regs, sizeof( regs ) );
memc->nr_regs = sizeof(regs) / sizeof(regs[0]); memc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_memc_read( void* opaque, target_phys_addr_t offset )
s3c2410_memc_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_memc_t *memc = opaque; s3c2410_memc_t* memc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(memc, offset)) { if ( !S3C2410_OFFSET_OK( memc, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(memc, offset); reg = S3C2410_OFFSET_ENTRY( memc, offset );
#ifdef DEBUG_S3C2410_MEMC #ifdef DEBUG_S3C2410_MEMC
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-memc", S3C2410_MEMC_BASE, reg->name, ( unsigned long )offset,
"s3c2410-memc", S3C2410_MEMC_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_memc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_memc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_memc_t *memc = opaque; s3c2410_memc_t* memc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(memc, offset)) { if ( !S3C2410_OFFSET_OK( memc, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(memc, offset); reg = S3C2410_OFFSET_ENTRY( memc, offset );
#ifdef DEBUG_S3C2410_MEMC #ifdef DEBUG_S3C2410_MEMC
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-memc", S3C2410_MEMC_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-memc", S3C2410_MEMC_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
#ifdef DEBUG_S3C2410_MEMC #ifdef DEBUG_S3C2410_MEMC
printf("%s:%u: env %p\n", __FUNCTION__, __LINE__, memc->x49gp->env); printf( "%s:%u: env %p\n", __FUNCTION__, __LINE__, memc->x49gp->env );
#endif #endif
} }
static int static int s3c2410_memc_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_memc_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_memc_t *memc = module->user_data; s3c2410_memc_t* memc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < memc->nr_regs; i++) { for ( i = 0; i < memc->nr_regs; i++ ) {
reg = &memc->regs[i]; reg = &memc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_memc_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_memc_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_memc_t *memc = module->user_data; s3c2410_memc_t* memc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < memc->nr_regs; i++) { for ( i = 0; i < memc->nr_regs; i++ ) {
reg = &memc->regs[i]; reg = &memc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_memc_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_memc_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_memc_t *memc = module->user_data; s3c2410_memc_t* memc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < memc->nr_regs; i++) { for ( i = 0; i < memc->nr_regs; i++ ) {
reg = &memc->regs[i]; reg = &memc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_memc_readfn[] = static CPUReadMemoryFunc* s3c2410_memc_readfn[] = { s3c2410_memc_read, s3c2410_memc_read, s3c2410_memc_read };
{
s3c2410_memc_read,
s3c2410_memc_read,
s3c2410_memc_read
};
static CPUWriteMemoryFunc *s3c2410_memc_writefn[] = static CPUWriteMemoryFunc* s3c2410_memc_writefn[] = { s3c2410_memc_write, s3c2410_memc_write, s3c2410_memc_write };
{
s3c2410_memc_write,
s3c2410_memc_write,
s3c2410_memc_write
};
static int static int s3c2410_memc_init( x49gp_module_t* module )
s3c2410_memc_init(x49gp_module_t *module)
{ {
s3c2410_memc_t *memc; s3c2410_memc_t* memc;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
memc = malloc(sizeof(s3c2410_memc_t)); memc = malloc( sizeof( s3c2410_memc_t ) );
if (NULL == memc) { if ( NULL == memc ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_memc_data_init(memc)) { if ( s3c2410_memc_data_init( memc ) ) {
free(memc); free( memc );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = memc; module->user_data = memc;
memc->x49gp = module->x49gp; memc->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_memc_readfn, iotype = cpu_register_io_memory( s3c2410_memc_readfn, s3c2410_memc_writefn, memc );
s3c2410_memc_writefn, memc);
#ifdef DEBUG_S3C2410_MEMC #ifdef DEBUG_S3C2410_MEMC
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_MEMC_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_MEMC_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_memc_exit( x49gp_module_t* module )
s3c2410_memc_exit(x49gp_module_t *module)
{ {
s3c2410_memc_t *memc; s3c2410_memc_t* memc;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
memc = module->user_data; memc = module->user_data;
if (memc->regs) if ( memc->regs )
free(memc->regs); free( memc->regs );
free(memc); free( memc );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_memc_init( x49gp_t* x49gp )
x49gp_s3c2410_memc_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-memc", if ( x49gp_module_init( x49gp, "s3c2410-memc", s3c2410_memc_init, s3c2410_memc_exit, s3c2410_memc_reset, s3c2410_memc_load,
s3c2410_memc_init, s3c2410_memc_save, NULL, &module ) ) {
s3c2410_memc_exit,
s3c2410_memc_reset,
s3c2410_memc_load,
s3c2410_memc_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -5,7 +5,7 @@
#define _S3C2410_MMU_H 1 #define _S3C2410_MMU_H 1
#define S3C2410_MMU_TLB_SIZE 64 #define S3C2410_MMU_TLB_SIZE 64
#define S3C2410_MMU_TLB_MASK (S3C2410_MMU_TLB_SIZE - 1) #define S3C2410_MMU_TLB_MASK ( S3C2410_MMU_TLB_SIZE - 1 )
typedef struct { typedef struct {
uint32_t mva; uint32_t mva;
@ -25,11 +25,11 @@ typedef struct {
unsigned long search; unsigned long search;
unsigned long nsearch; unsigned long nsearch;
unsigned long walk; unsigned long walk;
TLB_entry_t data[S3C2410_MMU_TLB_SIZE]; TLB_entry_t data[ S3C2410_MMU_TLB_SIZE ];
} TLB_t; } TLB_t;
typedef struct { typedef struct {
uint32_t MMUReg[16]; uint32_t MMUReg[ 16 ];
TLB_t iTLB; TLB_t iTLB;
TLB_t dTLB; TLB_t dTLB;
} s3c2410_mmu_t; } s3c2410_mmu_t;

View file

@ -12,7 +12,6 @@
#include "x49gp.h" #include "x49gp.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct { typedef struct {
uint32_t nfconf; uint32_t nfconf;
uint32_t nfcmd; uint32_t nfcmd;
@ -22,234 +21,197 @@ typedef struct {
uint32_t nfecc; uint32_t nfecc;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
} s3c2410_nand_t; } s3c2410_nand_t;
static int s3c2410_nand_data_init( s3c2410_nand_t* nand )
static int
s3c2410_nand_data_init(s3c2410_nand_t *nand)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(NAND, NFCONF, 0x00000000, nand->nfconf), S3C2410_OFFSET( NAND, NFCONF, 0x00000000, nand->nfconf ), S3C2410_OFFSET( NAND, NFCMD, 0x00000000, nand->nfcmd ),
S3C2410_OFFSET(NAND, NFCMD, 0x00000000, nand->nfcmd), S3C2410_OFFSET( NAND, NFADDR, 0x00000000, nand->nfaddr ), S3C2410_OFFSET( NAND, NFDATA, 0x00000000, nand->nfdata ),
S3C2410_OFFSET(NAND, NFADDR, 0x00000000, nand->nfaddr), S3C2410_OFFSET( NAND, NFSTAT, 0x00000000, nand->nfstat ), S3C2410_OFFSET( NAND, NFECC, 0x00000000, nand->nfecc ),
S3C2410_OFFSET(NAND, NFDATA, 0x00000000, nand->nfdata),
S3C2410_OFFSET(NAND, NFSTAT, 0x00000000, nand->nfstat),
S3C2410_OFFSET(NAND, NFECC, 0x00000000, nand->nfecc),
}; };
memset(nand, 0, sizeof(s3c2410_nand_t)); memset( nand, 0, sizeof( s3c2410_nand_t ) );
nand->regs = malloc(sizeof(regs)); nand->regs = malloc( sizeof( regs ) );
if (NULL == nand->regs) { if ( NULL == nand->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(nand->regs, regs, sizeof(regs)); memcpy( nand->regs, regs, sizeof( regs ) );
nand->nr_regs = sizeof(regs) / sizeof(regs[0]); nand->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
uint32_t uint32_t s3c2410_nand_read( void* opaque, target_phys_addr_t offset )
s3c2410_nand_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_nand_t *nand = opaque; s3c2410_nand_t* nand = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(nand, offset)) { if ( !S3C2410_OFFSET_OK( nand, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(nand, offset); reg = S3C2410_OFFSET_ENTRY( nand, offset );
#ifdef DEBUG_S3C2410_NAND #ifdef DEBUG_S3C2410_NAND
printf("read %s [%08x] %s [%08x] data %08x\n", printf( "read %s [%08x] %s [%08x] data %08x\n", "s3c2410-nand", S3C2410_NAND_BASE, reg->name, offset, *( reg->datap ) );
"s3c2410-nand", S3C2410_NAND_BASE,
reg->name, offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
void void s3c2410_nand_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_nand_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_nand_t *nand = opaque; s3c2410_nand_t* nand = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(nand, offset)) { if ( !S3C2410_OFFSET_OK( nand, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(nand, offset); reg = S3C2410_OFFSET_ENTRY( nand, offset );
#ifdef DEBUG_S3C2410_NAND #ifdef DEBUG_S3C2410_NAND
printf("write %s [%08x] %s [%08x] data %08x\n", printf( "write %s [%08x] %s [%08x] data %08x\n", "s3c2410-nand", S3C2410_NAND_BASE, reg->name, offset, data );
"s3c2410-nand", S3C2410_NAND_BASE,
reg->name, offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
} }
static int s3c2410_nand_load( x49gp_module_t* module, GKeyFile* key )
static int
s3c2410_nand_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_nand_t *nand = module->user_data; s3c2410_nand_t* nand = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < nand->nr_regs; i++) { for ( i = 0; i < nand->nr_regs; i++ ) {
reg = &nand->regs[i]; reg = &nand->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_nand_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_nand_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_nand_t *nand = module->user_data; s3c2410_nand_t* nand = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < nand->nr_regs; i++) { for ( i = 0; i < nand->nr_regs; i++ ) {
reg = &nand->regs[i]; reg = &nand->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_nand_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_nand_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_nand_t *nand = module->user_data; s3c2410_nand_t* nand = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < nand->nr_regs; i++) { for ( i = 0; i < nand->nr_regs; i++ ) {
reg = &nand->regs[i]; reg = &nand->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_nand_readfn[] = static CPUReadMemoryFunc* s3c2410_nand_readfn[] = { s3c2410_nand_read, s3c2410_nand_read, s3c2410_nand_read };
{
s3c2410_nand_read,
s3c2410_nand_read,
s3c2410_nand_read
};
static CPUWriteMemoryFunc *s3c2410_nand_writefn[] = static CPUWriteMemoryFunc* s3c2410_nand_writefn[] = { s3c2410_nand_write, s3c2410_nand_write, s3c2410_nand_write };
{
s3c2410_nand_write,
s3c2410_nand_write,
s3c2410_nand_write
};
static int static int s3c2410_nand_init( x49gp_module_t* module )
s3c2410_nand_init(x49gp_module_t *module)
{ {
s3c2410_nand_t *nand; s3c2410_nand_t* nand;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
nand = malloc(sizeof(s3c2410_nand_t)); nand = malloc( sizeof( s3c2410_nand_t ) );
if (NULL == nand) { if ( NULL == nand ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_nand_data_init(nand)) { if ( s3c2410_nand_data_init( nand ) ) {
free(nand); free( nand );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = nand; module->user_data = nand;
iotype = cpu_register_io_memory(s3c2410_nand_readfn, iotype = cpu_register_io_memory( s3c2410_nand_readfn, s3c2410_nand_writefn, nand );
s3c2410_nand_writefn, nand);
#ifdef DEBUG_S3C2410_NAND #ifdef DEBUG_S3C2410_NAND
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_NAND_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_NAND_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_nand_exit( x49gp_module_t* module )
s3c2410_nand_exit(x49gp_module_t *module)
{ {
s3c2410_nand_t *nand; s3c2410_nand_t* nand;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
nand = module->user_data; nand = module->user_data;
if (nand->regs) if ( nand->regs )
free(nand->regs); free( nand->regs );
free(nand); free( nand );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_nand_init( x49gp_t* x49gp )
x49gp_s3c2410_nand_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-nand", if ( x49gp_module_init( x49gp, "s3c2410-nand", s3c2410_nand_init, s3c2410_nand_exit, s3c2410_nand_reset, s3c2410_nand_load,
s3c2410_nand_init, s3c2410_nand_save, NULL, &module ) ) {
s3c2410_nand_exit,
s3c2410_nand_reset,
s3c2410_nand_load,
s3c2410_nand_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -24,147 +24,136 @@ typedef struct {
uint32_t clkdivn; uint32_t clkdivn;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_power_t; } s3c2410_power_t;
static int static int s3c2410_power_data_init( s3c2410_power_t* power )
s3c2410_power_data_init(s3c2410_power_t *power)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = {
S3C2410_OFFSET(POWER, LOCKTIME, 0x00ffffff, power->locktime), S3C2410_OFFSET( POWER, LOCKTIME, 0x00ffffff, power->locktime ), S3C2410_OFFSET( POWER, MPLLCON, 0x0005c080, power->mpllcon ),
S3C2410_OFFSET(POWER, MPLLCON, 0x0005c080, power->mpllcon), S3C2410_OFFSET( POWER, UPLLCON, 0x00028080, power->upllcon ), S3C2410_OFFSET( POWER, CLKCON, 0x0007fff0, power->clkcon ),
S3C2410_OFFSET(POWER, UPLLCON, 0x00028080, power->upllcon), S3C2410_OFFSET( POWER, CLKSLOW, 0x00000004, power->clkslow ), S3C2410_OFFSET( POWER, CLKDIVN, 0x00000000, power->clkdivn ) };
S3C2410_OFFSET(POWER, CLKCON, 0x0007fff0, power->clkcon),
S3C2410_OFFSET(POWER, CLKSLOW, 0x00000004, power->clkslow),
S3C2410_OFFSET(POWER, CLKDIVN, 0x00000000, power->clkdivn)
};
memset(power, 0, sizeof(s3c2410_power_t)); memset( power, 0, sizeof( s3c2410_power_t ) );
power->regs = malloc(sizeof(regs)); power->regs = malloc( sizeof( regs ) );
if (NULL == power->regs) { if ( NULL == power->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(power->regs, regs, sizeof(regs)); memcpy( power->regs, regs, sizeof( regs ) );
power->nr_regs = sizeof(regs) / sizeof(regs[0]); power->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_power_read( void* opaque, target_phys_addr_t offset )
s3c2410_power_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_power_t *power = opaque; s3c2410_power_t* power = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(power, offset)) { if ( !S3C2410_OFFSET_OK( power, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(power, offset); reg = S3C2410_OFFSET_ENTRY( power, offset );
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-power", S3C2410_POWER_BASE, reg->name, ( unsigned long )offset,
"s3c2410-power", S3C2410_POWER_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_power_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_power_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_power_t *power = opaque; s3c2410_power_t* power = opaque;
x49gp_t *x49gp = power->x49gp; x49gp_t* x49gp = power->x49gp;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t mMdiv, mPdiv, mSdiv; uint32_t mMdiv, mPdiv, mSdiv;
uint32_t uMdiv, uPdiv, uSdiv; uint32_t uMdiv, uPdiv, uSdiv;
uint32_t slow_bit, slow_val; uint32_t slow_bit, slow_val;
if (! S3C2410_OFFSET_OK(power, offset)) { if ( !S3C2410_OFFSET_OK( power, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(power, offset); reg = S3C2410_OFFSET_ENTRY( power, offset );
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-power", S3C2410_POWER_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-power", S3C2410_POWER_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_POWER_CLKCON: case S3C2410_POWER_CLKCON:
if (data & CLKCON_POWER_OFF) { if ( data & CLKCON_POWER_OFF ) {
*(reg->datap) = 0x7fff0; *( reg->datap ) = 0x7fff0;
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("POWER: enter POWER_OFF\n"); printf( "POWER: enter POWER_OFF\n" );
#endif #endif
x49gp_modules_reset(x49gp, X49GP_RESET_POWER_OFF); x49gp_modules_reset( x49gp, X49GP_RESET_POWER_OFF );
// if (x49gp->arm->NresetSig != LOW) { // if (x49gp->arm->NresetSig != LOW) {
// x49gp->arm->NresetSig = LOW; // x49gp->arm->NresetSig = LOW;
// x49gp->arm->Exception++; // x49gp->arm->Exception++;
// } // }
x49gp_set_idle(x49gp, X49GP_ARM_OFF); x49gp_set_idle( x49gp, X49GP_ARM_OFF );
return; return;
} }
if (!(power->clkcon & CLKCON_IDLE) && (data & CLKCON_IDLE)) { if ( !( power->clkcon & CLKCON_IDLE ) && ( data & CLKCON_IDLE ) ) {
*(reg->datap) = data; *( reg->datap ) = data;
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("POWER: enter IDLE\n"); printf( "POWER: enter IDLE\n" );
#endif #endif
x49gp_set_idle(x49gp, X49GP_ARM_SLEEP); x49gp_set_idle( x49gp, X49GP_ARM_SLEEP );
return; return;
} }
*(reg->datap) = data; *( reg->datap ) = data;
return; return;
case S3C2410_POWER_LOCKTIME: case S3C2410_POWER_LOCKTIME:
*(reg->datap) = data; *( reg->datap ) = data;
return; return;
default: default:
*(reg->datap) = data; *( reg->datap ) = data;
break; break;
} }
mMdiv = (power->mpllcon >> 12) & 0xff; mMdiv = ( power->mpllcon >> 12 ) & 0xff;
mPdiv = (power->mpllcon >> 4) & 0x3f; mPdiv = ( power->mpllcon >> 4 ) & 0x3f;
mSdiv = (power->mpllcon >> 0) & 0x03; mSdiv = ( power->mpllcon >> 0 ) & 0x03;
x49gp->MCLK = (((u64) EXTCLK) * ((u64) (mMdiv + 8))) / ((u64) ((mPdiv + 2) * (1 << mSdiv))); x49gp->MCLK = ( ( ( u64 )EXTCLK ) * ( ( u64 )( mMdiv + 8 ) ) ) / ( ( u64 )( ( mPdiv + 2 ) * ( 1 << mSdiv ) ) );
uMdiv = (power->upllcon >> 12) & 0xff; uMdiv = ( power->upllcon >> 12 ) & 0xff;
uPdiv = (power->upllcon >> 4) & 0x3f; uPdiv = ( power->upllcon >> 4 ) & 0x3f;
uSdiv = (power->upllcon >> 0) & 0x03; uSdiv = ( power->upllcon >> 0 ) & 0x03;
x49gp->UCLK = (((u64) EXTCLK) * ((u64) (uMdiv + 8))) / ((u64) ((uPdiv + 2) * (1 << uSdiv))); x49gp->UCLK = ( ( ( u64 )EXTCLK ) * ( ( u64 )( uMdiv + 8 ) ) ) / ( ( u64 )( ( uPdiv + 2 ) * ( 1 << uSdiv ) ) );
slow_bit = (power->clkslow & 0x10); slow_bit = ( power->clkslow & 0x10 );
if (slow_bit) { if ( slow_bit ) {
slow_val = (power->clkslow >> 0) & 0x07; slow_val = ( power->clkslow >> 0 ) & 0x07;
if (0 == slow_val) if ( 0 == slow_val )
x49gp->FCLK = EXTCLK; x49gp->FCLK = EXTCLK;
else else
x49gp->FCLK = EXTCLK / (2 * slow_val); x49gp->FCLK = EXTCLK / ( 2 * slow_val );
} else { } else {
x49gp->FCLK = x49gp->MCLK; x49gp->FCLK = x49gp->MCLK;
} }
if (power->clkdivn & 4) { if ( power->clkdivn & 4 ) {
x49gp->HCLK = x49gp->FCLK / 4; x49gp->HCLK = x49gp->FCLK / 4;
x49gp->PCLK = x49gp->FCLK / 4; x49gp->PCLK = x49gp->FCLK / 4;
x49gp->PCLK_ratio = 4; x49gp->PCLK_ratio = 4;
} else { } else {
switch (power->clkdivn & 3) { switch ( power->clkdivn & 3 ) {
case 0: case 0:
x49gp->HCLK = x49gp->FCLK; x49gp->HCLK = x49gp->FCLK;
x49gp->PCLK = x49gp->HCLK; x49gp->PCLK = x49gp->HCLK;
@ -189,178 +178,149 @@ s3c2410_power_write(void *opaque, target_phys_addr_t offset, uint32_t data)
} }
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: MCLK %u\n", printf( "%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: MCLK %u\n", __FUNCTION__, EXTCLK, mMdiv, mPdiv, mSdiv, x49gp->MCLK );
__FUNCTION__, EXTCLK, mMdiv, mPdiv, mSdiv, x49gp->MCLK); printf( "%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: UCLK %u\n", __FUNCTION__, EXTCLK, uMdiv, uPdiv, uSdiv, x49gp->UCLK );
printf("%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: UCLK %u\n", printf( "%s: FCLK %s: %u\n", __FUNCTION__, slow_bit ? "(slow)" : "", x49gp->FCLK );
__FUNCTION__, EXTCLK, uMdiv, uPdiv, uSdiv, x49gp->UCLK); printf( "%s: HCLK %u, PCLK %u\n", __FUNCTION__, x49gp->HCLK, x49gp->PCLK );
printf("%s: FCLK %s: %u\n",
__FUNCTION__, slow_bit ? "(slow)" : "", x49gp->FCLK);
printf("%s: HCLK %u, PCLK %u\n",
__FUNCTION__, x49gp->HCLK, x49gp->PCLK);
#endif #endif
} }
static int static int s3c2410_power_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_power_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_power_t *power = module->user_data; s3c2410_power_t* power = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < power->nr_regs; i++) { for ( i = 0; i < power->nr_regs; i++ ) {
reg = &power->regs[i]; reg = &power->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
if (error) { if ( error ) {
return error; return error;
} }
s3c2410_power_write(power, S3C2410_POWER_BASE | S3C2410_POWER_CLKDIVN, s3c2410_power_write( power, S3C2410_POWER_BASE | S3C2410_POWER_CLKDIVN, power->clkdivn );
power->clkdivn);
return 0; return 0;
} }
static int static int s3c2410_power_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_power_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_power_t *power = module->user_data; s3c2410_power_t* power = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < power->nr_regs; i++) { for ( i = 0; i < power->nr_regs; i++ ) {
reg = &power->regs[i]; reg = &power->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_power_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_power_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_power_t *power = module->user_data; s3c2410_power_t* power = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < power->nr_regs; i++) { for ( i = 0; i < power->nr_regs; i++ ) {
reg = &power->regs[i]; reg = &power->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_power_readfn[] = static CPUReadMemoryFunc* s3c2410_power_readfn[] = { s3c2410_power_read, s3c2410_power_read, s3c2410_power_read };
{
s3c2410_power_read,
s3c2410_power_read,
s3c2410_power_read
};
static CPUWriteMemoryFunc *s3c2410_power_writefn[] = static CPUWriteMemoryFunc* s3c2410_power_writefn[] = { s3c2410_power_write, s3c2410_power_write, s3c2410_power_write };
{
s3c2410_power_write,
s3c2410_power_write,
s3c2410_power_write
};
static int static int s3c2410_power_init( x49gp_module_t* module )
s3c2410_power_init(x49gp_module_t *module)
{ {
s3c2410_power_t *power; s3c2410_power_t* power;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
power = malloc(sizeof(s3c2410_power_t)); power = malloc( sizeof( s3c2410_power_t ) );
if (NULL == power) { if ( NULL == power ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_power_data_init(power)) { if ( s3c2410_power_data_init( power ) ) {
free(power); free( power );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = power; module->user_data = power;
power->x49gp = module->x49gp; power->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_power_readfn, iotype = cpu_register_io_memory( s3c2410_power_readfn, s3c2410_power_writefn, power );
s3c2410_power_writefn, power);
#ifdef DEBUG_S3C2410_POWER #ifdef DEBUG_S3C2410_POWER
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_POWER_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_POWER_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_power_exit( x49gp_module_t* module )
s3c2410_power_exit(x49gp_module_t *module)
{ {
s3c2410_power_t *power; s3c2410_power_t* power;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
power = module->user_data; power = module->user_data;
if (power->regs) if ( power->regs )
free(power->regs); free( power->regs );
free(power); free( power );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_power_init( x49gp_t* x49gp )
x49gp_s3c2410_power_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-power", if ( x49gp_module_init( x49gp, "s3c2410-power", s3c2410_power_init, s3c2410_power_exit, s3c2410_power_reset, s3c2410_power_load,
s3c2410_power_init, s3c2410_power_save, NULL, &module ) ) {
s3c2410_power_exit,
s3c2410_power_reset,
s3c2410_power_load,
s3c2410_power_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -14,7 +14,6 @@
#include "s3c2410.h" #include "s3c2410.h"
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
typedef struct { typedef struct {
uint32_t rtccon; uint32_t rtccon;
uint32_t ticnt; uint32_t ticnt;
@ -35,469 +34,415 @@ typedef struct {
uint32_t bcdyear; uint32_t bcdyear;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
x49gp_timer_t *tick_timer; x49gp_timer_t* tick_timer;
x49gp_timer_t *alarm_timer; x49gp_timer_t* alarm_timer;
int64_t interval; /* us */ int64_t interval; /* us */
int64_t expires; /* us */ int64_t expires; /* us */
} s3c2410_rtc_t; } s3c2410_rtc_t;
static int s3c2410_rtc_data_init( s3c2410_rtc_t* rtc )
static int
s3c2410_rtc_data_init(s3c2410_rtc_t *rtc)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = { S3C2410_OFFSET( RTC, RTCCON, 0x00, rtc->rtccon ), S3C2410_OFFSET( RTC, TICNT, 0x00, rtc->ticnt ),
S3C2410_OFFSET(RTC, RTCCON, 0x00, rtc->rtccon), S3C2410_OFFSET( RTC, RTCALM, 0x00, rtc->rtcalm ), S3C2410_OFFSET( RTC, ALMSEC, 0x00, rtc->almsec ),
S3C2410_OFFSET(RTC, TICNT, 0x00, rtc->ticnt), S3C2410_OFFSET( RTC, ALMMIN, 0x00, rtc->almmin ), S3C2410_OFFSET( RTC, ALMHOUR, 0x00, rtc->almhour ),
S3C2410_OFFSET(RTC, RTCALM, 0x00, rtc->rtcalm), S3C2410_OFFSET( RTC, ALMDATE, 0x01, rtc->almdate ), S3C2410_OFFSET( RTC, ALMMON, 0x01, rtc->almmon ),
S3C2410_OFFSET(RTC, ALMSEC, 0x00, rtc->almsec), S3C2410_OFFSET( RTC, ALMYEAR, 0x00, rtc->almyear ), S3C2410_OFFSET( RTC, RTCRST, 0x00, rtc->rtcrst ),
S3C2410_OFFSET(RTC, ALMMIN, 0x00, rtc->almmin), S3C2410_OFFSET( RTC, BCDSEC, 0, rtc->bcdsec ), S3C2410_OFFSET( RTC, BCDMIN, 0, rtc->bcdmin ),
S3C2410_OFFSET(RTC, ALMHOUR, 0x00, rtc->almhour), S3C2410_OFFSET( RTC, BCDHOUR, 0, rtc->bcdhour ), S3C2410_OFFSET( RTC, BCDDATE, 0, rtc->bcddate ),
S3C2410_OFFSET(RTC, ALMDATE, 0x01, rtc->almdate), S3C2410_OFFSET( RTC, BCDDAY, 0, rtc->bcdday ), S3C2410_OFFSET( RTC, BCDMON, 0, rtc->bcdmon ),
S3C2410_OFFSET(RTC, ALMMON, 0x01, rtc->almmon), S3C2410_OFFSET( RTC, BCDYEAR, 0, rtc->bcdyear ) };
S3C2410_OFFSET(RTC, ALMYEAR, 0x00, rtc->almyear),
S3C2410_OFFSET(RTC, RTCRST, 0x00, rtc->rtcrst),
S3C2410_OFFSET(RTC, BCDSEC, 0, rtc->bcdsec),
S3C2410_OFFSET(RTC, BCDMIN, 0, rtc->bcdmin),
S3C2410_OFFSET(RTC, BCDHOUR, 0, rtc->bcdhour),
S3C2410_OFFSET(RTC, BCDDATE, 0, rtc->bcddate),
S3C2410_OFFSET(RTC, BCDDAY, 0, rtc->bcdday),
S3C2410_OFFSET(RTC, BCDMON, 0, rtc->bcdmon),
S3C2410_OFFSET(RTC, BCDYEAR, 0, rtc->bcdyear)
};
memset(rtc, 0, sizeof(s3c2410_rtc_t)); memset( rtc, 0, sizeof( s3c2410_rtc_t ) );
rtc->regs = malloc(sizeof(regs)); rtc->regs = malloc( sizeof( regs ) );
if (NULL == rtc->regs) { if ( NULL == rtc->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(rtc->regs, regs, sizeof(regs)); memcpy( rtc->regs, regs, sizeof( regs ) );
rtc->nr_regs = sizeof(regs) / sizeof(regs[0]); rtc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static __inline__ uint32_t bin2bcd(uint32_t bin) static __inline__ uint32_t bin2bcd( uint32_t bin ) { return ( ( bin / 10 ) << 4 ) | ( bin % 10 ); }
{
return ((bin / 10) << 4) | (bin % 10);
}
static __inline__ uint32_t bcd2bin(uint32_t bcd) static __inline__ uint32_t bcd2bin( uint32_t bcd ) { return ( ( bcd >> 4 ) * 10 ) + ( bcd & 0x0f ); }
{
return ((bcd >> 4) * 10) + (bcd & 0x0f);
}
static void static void s3c2410_rtc_timeout( void* user_data )
s3c2410_rtc_timeout(void * user_data)
{ {
s3c2410_rtc_t *rtc = user_data; s3c2410_rtc_t* rtc = user_data;
x49gp_t *x49gp = rtc->x49gp; x49gp_t* x49gp = rtc->x49gp;
int64_t now, us; int64_t now, us;
if (!(rtc->ticnt & 0x80)) { if ( !( rtc->ticnt & 0x80 ) ) {
return; return;
} }
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: assert TICK interrupt\n"); printf( "RTC: assert TICK interrupt\n" );
#endif #endif
s3c2410_intc_assert(x49gp, INT_TICK, 0); s3c2410_intc_assert( x49gp, INT_TICK, 0 );
now = x49gp_get_clock(); now = x49gp_get_clock();
while (rtc->expires <= now) { while ( rtc->expires <= now ) {
rtc->expires += rtc->interval; rtc->expires += rtc->interval;
} }
us = rtc->expires - now; us = rtc->expires - now;
if (us < 1000) if ( us < 1000 )
us = 1000; us = 1000;
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: restart TICK timer (%llu us)\n", (unsigned long long) us); printf( "RTC: restart TICK timer (%llu us)\n", ( unsigned long long )us );
#endif #endif
x49gp_mod_timer(rtc->tick_timer, rtc->expires); x49gp_mod_timer( rtc->tick_timer, rtc->expires );
} }
static int static int s3c2410_rtc_set_ticnt( s3c2410_rtc_t* rtc )
s3c2410_rtc_set_ticnt(s3c2410_rtc_t *rtc)
{ {
int64_t now, us; int64_t now, us;
if (x49gp_timer_pending(rtc->tick_timer)) { if ( x49gp_timer_pending( rtc->tick_timer ) ) {
x49gp_del_timer(rtc->tick_timer); x49gp_del_timer( rtc->tick_timer );
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: stop TICK timer\n"); printf( "RTC: stop TICK timer\n" );
#endif #endif
} }
if (!(rtc->ticnt & 0x80)) { if ( !( rtc->ticnt & 0x80 ) ) {
return 0; return 0;
} }
us = (((rtc->ticnt & 0x7f) + 1) * 1000000) / 128; us = ( ( ( rtc->ticnt & 0x7f ) + 1 ) * 1000000 ) / 128;
rtc->interval = us; rtc->interval = us;
if (rtc->interval < 1000) if ( rtc->interval < 1000 )
rtc->interval = 1000; rtc->interval = 1000;
now = x49gp_get_clock(); now = x49gp_get_clock();
rtc->expires = now + rtc->interval; rtc->expires = now + rtc->interval;
us = rtc->expires - now; us = rtc->expires - now;
if (us < 1000) if ( us < 1000 )
us = 1000; us = 1000;
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: start TICK timer (%lld us)\n", (unsigned long long) us); printf( "RTC: start TICK timer (%lld us)\n", ( unsigned long long )us );
#endif #endif
x49gp_mod_timer(rtc->tick_timer, rtc->expires); x49gp_mod_timer( rtc->tick_timer, rtc->expires );
return 0; return 0;
} }
static void static void s3c2410_rtc_alarm( void* user_data )
s3c2410_rtc_alarm(void * user_data)
{ {
s3c2410_rtc_t *rtc = user_data; s3c2410_rtc_t* rtc = user_data;
x49gp_t *x49gp = rtc->x49gp; x49gp_t* x49gp = rtc->x49gp;
struct tm *tm; struct tm* tm;
struct timeval tv; struct timeval tv;
int64_t now, us; int64_t now, us;
int match = 1; int match = 1;
if (!(rtc->rtcalm & 0x40)) { if ( !( rtc->rtcalm & 0x40 ) ) {
return; return;
} }
gettimeofday(&tv, NULL); gettimeofday( &tv, NULL );
tm = localtime(&tv.tv_sec); tm = localtime( &tv.tv_sec );
now = x49gp_get_clock(); now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec; us = 1000000LL - tv.tv_usec;
if (match && (rtc->rtcalm & 0x01)) { if ( match && ( rtc->rtcalm & 0x01 ) ) {
if (tm->tm_sec != bcd2bin(rtc->almsec)) if ( tm->tm_sec != bcd2bin( rtc->almsec ) )
match = 0; match = 0;
} }
if (match && (rtc->rtcalm & 0x02)) { if ( match && ( rtc->rtcalm & 0x02 ) ) {
if (tm->tm_min != bcd2bin(rtc->almmin)) if ( tm->tm_min != bcd2bin( rtc->almmin ) )
match = 0; match = 0;
} }
if (match && (rtc->rtcalm & 0x04)) { if ( match && ( rtc->rtcalm & 0x04 ) ) {
if (tm->tm_hour != bcd2bin(rtc->almhour)) if ( tm->tm_hour != bcd2bin( rtc->almhour ) )
match = 0; match = 0;
} }
if (match && (rtc->rtcalm & 0x08)) { if ( match && ( rtc->rtcalm & 0x08 ) ) {
if (tm->tm_mday != bcd2bin(rtc->almdate)) if ( tm->tm_mday != bcd2bin( rtc->almdate ) )
match = 0; match = 0;
} }
if (match && (rtc->rtcalm & 0x10)) { if ( match && ( rtc->rtcalm & 0x10 ) ) {
if ((tm->tm_mon + 1) != bcd2bin(rtc->almmon)) if ( ( tm->tm_mon + 1 ) != bcd2bin( rtc->almmon ) )
match = 0; match = 0;
} }
if (match && (rtc->rtcalm & 0x20)) { if ( match && ( rtc->rtcalm & 0x20 ) ) {
if ((tm->tm_year % 100) != bcd2bin(rtc->almyear)) if ( ( tm->tm_year % 100 ) != bcd2bin( rtc->almyear ) )
match = 0; match = 0;
} }
if (match) { if ( match ) {
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: assert ALARM interrupt\n"); printf( "RTC: assert ALARM interrupt\n" );
#endif #endif
s3c2410_intc_assert(x49gp, INT_RTC, 0); s3c2410_intc_assert( x49gp, INT_RTC, 0 );
} }
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: reload ALARM timer (%lld us)\n", (unsigned long long) us); printf( "RTC: reload ALARM timer (%lld us)\n", ( unsigned long long )us );
#endif #endif
x49gp_mod_timer(rtc->alarm_timer, now + us); x49gp_mod_timer( rtc->alarm_timer, now + us );
} }
static int static int s3c2410_rtc_set_rtcalm( s3c2410_rtc_t* rtc )
s3c2410_rtc_set_rtcalm(s3c2410_rtc_t *rtc)
{ {
struct timeval tv; struct timeval tv;
int64_t now, us; int64_t now, us;
if (!(rtc->rtcalm & 0x40)) { if ( !( rtc->rtcalm & 0x40 ) ) {
x49gp_del_timer(rtc->alarm_timer); x49gp_del_timer( rtc->alarm_timer );
return 0; return 0;
} }
gettimeofday(&tv, NULL); gettimeofday( &tv, NULL );
now = x49gp_get_clock(); now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec; us = 1000000LL - tv.tv_usec;
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("RTC: start ALARM timer (%lld us)\n", (unsigned long long) us); printf( "RTC: start ALARM timer (%lld us)\n", ( unsigned long long )us );
#endif #endif
x49gp_mod_timer(rtc->alarm_timer, now + us); x49gp_mod_timer( rtc->alarm_timer, now + us );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_rtc_read( void* opaque, target_phys_addr_t offset )
s3c2410_rtc_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_rtc_t *rtc = opaque; s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) { if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(rtc, offset); reg = S3C2410_OFFSET_ENTRY( rtc, offset );
if (S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR) { if ( S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR ) {
struct tm *tm; struct tm* tm;
struct timeval tv; struct timeval tv;
gettimeofday(&tv, NULL); gettimeofday( &tv, NULL );
tm = localtime(&tv.tv_sec); tm = localtime( &tv.tv_sec );
switch (offset) { switch ( offset ) {
case S3C2410_RTC_BCDSEC: case S3C2410_RTC_BCDSEC:
*(reg->datap) = bin2bcd(tm->tm_sec); *( reg->datap ) = bin2bcd( tm->tm_sec );
break; break;
case S3C2410_RTC_BCDMIN: case S3C2410_RTC_BCDMIN:
*(reg->datap) = bin2bcd(tm->tm_min); *( reg->datap ) = bin2bcd( tm->tm_min );
break; break;
case S3C2410_RTC_BCDHOUR: case S3C2410_RTC_BCDHOUR:
*(reg->datap) = bin2bcd(tm->tm_hour); *( reg->datap ) = bin2bcd( tm->tm_hour );
break; break;
case S3C2410_RTC_BCDDATE: case S3C2410_RTC_BCDDATE:
*(reg->datap) = bin2bcd(tm->tm_mday); *( reg->datap ) = bin2bcd( tm->tm_mday );
break; break;
case S3C2410_RTC_BCDDAY: case S3C2410_RTC_BCDDAY:
*(reg->datap) = bin2bcd(tm->tm_wday + 1); *( reg->datap ) = bin2bcd( tm->tm_wday + 1 );
break; break;
case S3C2410_RTC_BCDMON: case S3C2410_RTC_BCDMON:
*(reg->datap) = bin2bcd(tm->tm_mon + 1); *( reg->datap ) = bin2bcd( tm->tm_mon + 1 );
break; break;
case S3C2410_RTC_BCDYEAR: case S3C2410_RTC_BCDYEAR:
*(reg->datap) = bin2bcd(tm->tm_year % 100); *( reg->datap ) = bin2bcd( tm->tm_year % 100 );
break; break;
} }
} }
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset,
"s3c2410-rtc", S3C2410_RTC_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_rtc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_rtc_t *rtc = opaque; s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) { if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(rtc, offset); reg = S3C2410_OFFSET_ENTRY( rtc, offset );
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-rtc", S3C2410_RTC_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_RTC_TICNT: case S3C2410_RTC_TICNT:
*(reg->datap) = data; *( reg->datap ) = data;
s3c2410_rtc_set_ticnt(rtc); s3c2410_rtc_set_ticnt( rtc );
break; break;
case S3C2410_RTC_RTCALM: case S3C2410_RTC_RTCALM:
*(reg->datap) = data; *( reg->datap ) = data;
s3c2410_rtc_set_rtcalm(rtc); s3c2410_rtc_set_rtcalm( rtc );
break; break;
default: default:
*(reg->datap) = data; *( reg->datap ) = data;
break; break;
} }
} }
static int static int s3c2410_rtc_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_rtc_t *rtc = module->user_data; s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < rtc->nr_regs; i++) { for ( i = 0; i < rtc->nr_regs; i++ ) {
reg = &rtc->regs[i]; reg = &rtc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
s3c2410_rtc_set_ticnt(rtc); s3c2410_rtc_set_ticnt( rtc );
s3c2410_rtc_set_rtcalm(rtc); s3c2410_rtc_set_rtcalm( rtc );
return error; return error;
} }
static int static int s3c2410_rtc_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_rtc_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_rtc_t *rtc = module->user_data; s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < rtc->nr_regs; i++) { for ( i = 0; i < rtc->nr_regs; i++ ) {
reg = &rtc->regs[i]; reg = &rtc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_rtc_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_rtc_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_rtc_t *rtc = module->user_data; s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < (S3C2410_RTC_RTCALM >> 2); i++) { for ( i = 0; i < ( S3C2410_RTC_RTCALM >> 2 ); i++ ) {
reg = &rtc->regs[i]; reg = &rtc->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
s3c2410_rtc_set_ticnt(rtc); s3c2410_rtc_set_ticnt( rtc );
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_rtc_readfn[] = static CPUReadMemoryFunc* s3c2410_rtc_readfn[] = { s3c2410_rtc_read, s3c2410_rtc_read, s3c2410_rtc_read };
{
s3c2410_rtc_read,
s3c2410_rtc_read,
s3c2410_rtc_read
};
static CPUWriteMemoryFunc *s3c2410_rtc_writefn[] = static CPUWriteMemoryFunc* s3c2410_rtc_writefn[] = { s3c2410_rtc_write, s3c2410_rtc_write, s3c2410_rtc_write };
{
s3c2410_rtc_write,
s3c2410_rtc_write,
s3c2410_rtc_write
};
static int static int s3c2410_rtc_init( x49gp_module_t* module )
s3c2410_rtc_init(x49gp_module_t *module)
{ {
s3c2410_rtc_t *rtc; s3c2410_rtc_t* rtc;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
rtc = malloc(sizeof(s3c2410_rtc_t)); rtc = malloc( sizeof( s3c2410_rtc_t ) );
if (NULL == rtc) { if ( NULL == rtc ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
module->x49gp->progname, __FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_rtc_data_init(rtc)) { if ( s3c2410_rtc_data_init( rtc ) ) {
free(rtc); free( rtc );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = rtc; module->user_data = rtc;
rtc->x49gp = module->x49gp; rtc->x49gp = module->x49gp;
rtc->tick_timer = x49gp_new_timer(X49GP_TIMER_REALTIME, rtc->tick_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_timeout, rtc );
s3c2410_rtc_timeout, rtc); rtc->alarm_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_alarm, rtc );
rtc->alarm_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
s3c2410_rtc_alarm, rtc);
iotype = cpu_register_io_memory(s3c2410_rtc_readfn, iotype = cpu_register_io_memory( s3c2410_rtc_readfn, s3c2410_rtc_writefn, rtc );
s3c2410_rtc_writefn, rtc);
#ifdef DEBUG_S3C2410_RTC #ifdef DEBUG_S3C2410_RTC
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_RTC_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_RTC_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_rtc_exit( x49gp_module_t* module )
s3c2410_rtc_exit(x49gp_module_t *module)
{ {
s3c2410_rtc_t *rtc; s3c2410_rtc_t* rtc;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
rtc = module->user_data; rtc = module->user_data;
if (rtc->regs) if ( rtc->regs )
free(rtc->regs); free( rtc->regs );
free(rtc); free( rtc );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_rtc_init( x49gp_t* x49gp )
x49gp_s3c2410_rtc_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-rtc", if ( x49gp_module_init( x49gp, "s3c2410-rtc", s3c2410_rtc_init, s3c2410_rtc_exit, s3c2410_rtc_reset, s3c2410_rtc_load, s3c2410_rtc_save,
s3c2410_rtc_init, NULL, &module ) ) {
s3c2410_rtc_exit,
s3c2410_rtc_reset,
s3c2410_rtc_load,
s3c2410_rtc_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

File diff suppressed because it is too large Load diff

View file

@ -13,7 +13,6 @@
#include "s3c2410.h" #include "s3c2410.h"
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
typedef struct { typedef struct {
uint32_t spicon0; uint32_t spicon0;
uint32_t spista0; uint32_t spista0;
@ -29,265 +28,227 @@ typedef struct {
uint32_t sprdat1; uint32_t sprdat1;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_spi_t; } s3c2410_spi_t;
static int static int s3c2410_spi_data_init( s3c2410_spi_t* spi )
s3c2410_spi_data_init(s3c2410_spi_t *spi)
{ {
s3c2410_offset_t regs[] = s3c2410_offset_t regs[] = {
{ S3C2410_OFFSET( SPI, SPICON0, 0x00000000, spi->spicon0 ), S3C2410_OFFSET( SPI, SPISTA0, 0x00000000, spi->spista0 ),
S3C2410_OFFSET(SPI, SPICON0, 0x00000000, spi->spicon0), S3C2410_OFFSET( SPI, SPPIN0, 0x00000000, spi->sppin0 ), S3C2410_OFFSET( SPI, SPPRE0, 0x00000000, spi->sppre0 ),
S3C2410_OFFSET(SPI, SPISTA0, 0x00000000, spi->spista0), S3C2410_OFFSET( SPI, SPTDAT0, 0x00000000, spi->sptdat0 ), S3C2410_OFFSET( SPI, SPRDAT0, 0x00000000, spi->sprdat0 ),
S3C2410_OFFSET(SPI, SPPIN0, 0x00000000, spi->sppin0), S3C2410_OFFSET( SPI, SPICON1, 0x00000000, spi->spicon1 ), S3C2410_OFFSET( SPI, SPISTA1, 0x00000000, spi->spista1 ),
S3C2410_OFFSET(SPI, SPPRE0, 0x00000000, spi->sppre0), S3C2410_OFFSET( SPI, SPPIN1, 0x00000000, spi->sppin1 ), S3C2410_OFFSET( SPI, SPPRE1, 0x00000000, spi->sppre1 ),
S3C2410_OFFSET(SPI, SPTDAT0, 0x00000000, spi->sptdat0), S3C2410_OFFSET( SPI, SPTDAT1, 0x00000000, spi->sptdat1 ), S3C2410_OFFSET( SPI, SPRDAT1, 0x00000000, spi->sprdat1 ),
S3C2410_OFFSET(SPI, SPRDAT0, 0x00000000, spi->sprdat0),
S3C2410_OFFSET(SPI, SPICON1, 0x00000000, spi->spicon1),
S3C2410_OFFSET(SPI, SPISTA1, 0x00000000, spi->spista1),
S3C2410_OFFSET(SPI, SPPIN1, 0x00000000, spi->sppin1),
S3C2410_OFFSET(SPI, SPPRE1, 0x00000000, spi->sppre1),
S3C2410_OFFSET(SPI, SPTDAT1, 0x00000000, spi->sptdat1),
S3C2410_OFFSET(SPI, SPRDAT1, 0x00000000, spi->sprdat1),
}; };
memset(spi, 0, sizeof(s3c2410_spi_t)); memset( spi, 0, sizeof( s3c2410_spi_t ) );
spi->regs = malloc(sizeof(regs)); spi->regs = malloc( sizeof( regs ) );
if (NULL == spi->regs) { if ( NULL == spi->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(spi->regs, regs, sizeof(regs)); memcpy( spi->regs, regs, sizeof( regs ) );
spi->nr_regs = sizeof(regs) / sizeof(regs[0]); spi->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
uint32_t uint32_t s3c2410_spi_read( void* opaque, target_phys_addr_t offset )
s3c2410_spi_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_spi_t *spi = opaque; s3c2410_spi_t* spi = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(spi, offset)) { if ( !S3C2410_OFFSET_OK( spi, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(spi, offset); reg = S3C2410_OFFSET_ENTRY( spi, offset );
#ifdef DEBUG_S3C2410_SPI #ifdef DEBUG_S3C2410_SPI
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset,
"s3c2410-spi", S3C2410_SPI_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_SPI_SPRDAT0: case S3C2410_SPI_SPRDAT0:
spi->spista0 &= ~(1); spi->spista0 &= ~( 1 );
break; break;
case S3C2410_SPI_SPRDAT1: case S3C2410_SPI_SPRDAT1:
spi->spista1 &= ~(1); spi->spista1 &= ~( 1 );
break; break;
} }
return *(reg->datap); return *( reg->datap );
} }
void void s3c2410_spi_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_spi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_spi_t *spi = opaque; s3c2410_spi_t* spi = opaque;
x49gp_t *x49gp = spi->x49gp; x49gp_t* x49gp = spi->x49gp;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(spi, offset)) { if ( !S3C2410_OFFSET_OK( spi, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(spi, offset); reg = S3C2410_OFFSET_ENTRY( spi, offset );
#ifdef DEBUG_S3C2410_SPI #ifdef DEBUG_S3C2410_SPI
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-spi", S3C2410_SPI_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
switch (offset) { switch ( offset ) {
case S3C2410_SPI_SPTDAT0: case S3C2410_SPI_SPTDAT0:
spi->spista0 |= 1; spi->spista0 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI0, 0); s3c2410_intc_assert( x49gp, INT_SPI0, 0 );
break; break;
case S3C2410_SPI_SPTDAT1: case S3C2410_SPI_SPTDAT1:
spi->spista1 |= 1; spi->spista1 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI1, 0); s3c2410_intc_assert( x49gp, INT_SPI1, 0 );
break; break;
} }
} }
static int static int s3c2410_spi_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_spi_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_spi_t *spi = module->user_data; s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < spi->nr_regs; i++) { for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[i]; reg = &spi->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_spi_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_spi_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_spi_t *spi = module->user_data; s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < spi->nr_regs; i++) { for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[i]; reg = &spi->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_spi_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_spi_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_spi_t *spi = module->user_data; s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < spi->nr_regs; i++) { for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[i]; reg = &spi->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_spi_readfn[] = static CPUReadMemoryFunc* s3c2410_spi_readfn[] = { s3c2410_spi_read, s3c2410_spi_read, s3c2410_spi_read };
{
s3c2410_spi_read,
s3c2410_spi_read,
s3c2410_spi_read
};
static CPUWriteMemoryFunc *s3c2410_spi_writefn[] = static CPUWriteMemoryFunc* s3c2410_spi_writefn[] = { s3c2410_spi_write, s3c2410_spi_write, s3c2410_spi_write };
{
s3c2410_spi_write,
s3c2410_spi_write,
s3c2410_spi_write
};
static int static int s3c2410_spi_init( x49gp_module_t* module )
s3c2410_spi_init(x49gp_module_t *module)
{ {
s3c2410_spi_t *spi; s3c2410_spi_t* spi;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
spi = malloc(sizeof(s3c2410_spi_t)); spi = malloc( sizeof( s3c2410_spi_t ) );
if (NULL == spi) { if ( NULL == spi ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_spi_data_init(spi)) { if ( s3c2410_spi_data_init( spi ) ) {
free(spi); free( spi );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = spi; module->user_data = spi;
spi->x49gp = module->x49gp; spi->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_spi_readfn, iotype = cpu_register_io_memory( s3c2410_spi_readfn, s3c2410_spi_writefn, spi );
s3c2410_spi_writefn, spi);
#ifdef DEBUG_S3C2410_SPI #ifdef DEBUG_S3C2410_SPI
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_SPI_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_SPI_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_spi_exit( x49gp_module_t* module )
s3c2410_spi_exit(x49gp_module_t *module)
{ {
s3c2410_spi_t *spi; s3c2410_spi_t* spi;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
spi = module->user_data; spi = module->user_data;
if (spi->regs) if ( spi->regs )
free(spi->regs); free( spi->regs );
free(spi); free( spi );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_spi_init( x49gp_t* x49gp )
x49gp_s3c2410_spi_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-spi", if ( x49gp_module_init( x49gp, "s3c2410-spi", s3c2410_spi_init, s3c2410_spi_exit, s3c2410_spi_reset, s3c2410_spi_load, s3c2410_spi_save,
s3c2410_spi_init, NULL, &module ) ) {
s3c2410_spi_exit,
s3c2410_spi_reset,
s3c2410_spi_load,
s3c2410_spi_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -14,122 +14,105 @@
#include "byteorder.h" #include "byteorder.h"
typedef struct { typedef struct {
void *data; void* data;
char *filename; char* filename;
int fd; int fd;
uint32_t offset; uint32_t offset;
size_t size; size_t size;
} filemap_t; } filemap_t;
static int static int s3c2410_sram_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_sram_load(x49gp_module_t *module, GKeyFile *key)
{ {
filemap_t *filemap = module->user_data; filemap_t* filemap = module->user_data;
char *filename; char* filename;
int error; int error;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
error = x49gp_module_get_filename(module, key, "filename", error = x49gp_module_get_filename( module, key, "filename", "s3c2410-sram", &( filemap->filename ), &filename );
"s3c2410-sram", &(filemap->filename),
&filename);
filemap->fd = open(filename, O_RDWR | O_CREAT, 0644); filemap->fd = open( filename, O_RDWR | O_CREAT, 0644 );
if (filemap->fd < 0) { if ( filemap->fd < 0 ) {
error = -errno; error = -errno;
fprintf(stderr, "%s: %s:%u: open %s: %s\n", fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
module->name, __FUNCTION__, __LINE__, g_free( filename );
filename, strerror(errno));
g_free(filename);
return error; return error;
} }
filemap->size = S3C2410_SRAM_SIZE; filemap->size = S3C2410_SRAM_SIZE;
if (ftruncate(filemap->fd, filemap->size) < 0) { if ( ftruncate( filemap->fd, filemap->size ) < 0 ) {
error = -errno; error = -errno;
fprintf(stderr, "%s: %s:%u: ftruncate %s: %s\n", fprintf( stderr, "%s: %s:%u: ftruncate %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
module->name, __FUNCTION__, __LINE__, g_free( filename );
filename, strerror(errno)); close( filemap->fd );
g_free(filename);
close(filemap->fd);
filemap->fd = -1; filemap->fd = -1;
return error; return error;
} }
filemap->data = mmap(phys_ram_base + filemap->offset, filemap->size, filemap->data = mmap( phys_ram_base + filemap->offset, filemap->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, filemap->fd, 0 );
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, if ( filemap->data == ( void* )-1 ) {
filemap->fd, 0);
if (filemap->data == (void *) -1) {
error = -errno; error = -errno;
fprintf(stderr, "%s: %s:%u: mmap %s: %s\n", fprintf( stderr, "%s: %s:%u: mmap %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
module->name, __FUNCTION__, __LINE__, g_free( filename );
filename, strerror(errno)); close( filemap->fd );
g_free(filename);
close(filemap->fd);
filemap->fd = -1; filemap->fd = -1;
return error; return error;
} }
g_free(filename); g_free( filename );
x49gp_schedule_lcd_update(module->x49gp); x49gp_schedule_lcd_update( module->x49gp );
return error; return error;
} }
static int static int s3c2410_sram_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_sram_save(x49gp_module_t *module, GKeyFile *key)
{ {
filemap_t *filemap = module->user_data; filemap_t* filemap = module->user_data;
int error; int error;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
x49gp_module_set_filename(module, key, "filename", filemap->filename); x49gp_module_set_filename( module, key, "filename", filemap->filename );
error = msync(filemap->data, filemap->size, MS_ASYNC); error = msync( filemap->data, filemap->size, MS_ASYNC );
if (error) { if ( error ) {
fprintf(stderr, "%s:%u: msync: %s\n", fprintf( stderr, "%s:%u: msync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
__FUNCTION__, __LINE__, strerror(errno));
return error; return error;
} }
error = fsync(filemap->fd); error = fsync( filemap->fd );
if (error) { if ( error ) {
fprintf(stderr, "%s:%u: fsync: %s\n", fprintf( stderr, "%s:%u: fsync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
__FUNCTION__, __LINE__, strerror(errno));
return error; return error;
} }
return 0; return 0;
} }
static int static int s3c2410_sram_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
return 0; return 0;
} }
static int static int s3c2410_sram_init( x49gp_module_t* module )
s3c2410_sram_init(x49gp_module_t *module)
{ {
filemap_t *filemap; filemap_t* filemap;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
filemap = malloc(sizeof(filemap_t)); filemap = malloc( sizeof( filemap_t ) );
if (NULL == filemap) { if ( NULL == filemap ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
@ -138,58 +121,50 @@ s3c2410_sram_init(x49gp_module_t *module)
module->user_data = filemap; module->user_data = filemap;
filemap->data = (void *) -1; filemap->data = ( void* )-1;
filemap->offset = phys_ram_size; filemap->offset = phys_ram_size;
phys_ram_size += S3C2410_SRAM_SIZE; phys_ram_size += S3C2410_SRAM_SIZE;
cpu_register_physical_memory(S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE, cpu_register_physical_memory( S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE, filemap->offset | IO_MEM_RAM );
filemap->offset | IO_MEM_RAM);
return 0; return 0;
} }
static int static int s3c2410_sram_exit( x49gp_module_t* module )
s3c2410_sram_exit(x49gp_module_t *module)
{ {
filemap_t *filemap; filemap_t* filemap;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
filemap = module->user_data; filemap = module->user_data;
if (filemap->data != (void *) -1) { if ( filemap->data != ( void* )-1 ) {
munmap(filemap->data, filemap->size); munmap( filemap->data, filemap->size );
} }
if (filemap->fd >= 0) { if ( filemap->fd >= 0 ) {
close(filemap->fd); close( filemap->fd );
} }
free(filemap); free( filemap );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_sram_init( x49gp_t* x49gp )
x49gp_s3c2410_sram_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-sram", if ( x49gp_module_init( x49gp, "s3c2410-sram", s3c2410_sram_init, s3c2410_sram_exit, s3c2410_sram_reset, s3c2410_sram_load,
s3c2410_sram_init, s3c2410_sram_save, NULL, &module ) ) {
s3c2410_sram_exit,
s3c2410_sram_reset,
s3c2410_sram_load,
s3c2410_sram_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -14,7 +14,6 @@
#include "s3c2410_timer.h" #include "s3c2410_timer.h"
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
typedef struct { typedef struct {
uint32_t reload_bit; uint32_t reload_bit;
uint32_t update_bit; uint32_t update_bit;
@ -33,10 +32,10 @@ struct __s3c2410_timer_s__ {
uint32_t tcon; uint32_t tcon;
uint32_t prev_tcon; uint32_t prev_tcon;
x49gp_t *x49gp; x49gp_t* x49gp;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
struct s3c2410_timeout { struct s3c2410_timeout {
uint32_t tcntb; uint32_t tcntb;
@ -44,193 +43,168 @@ struct __s3c2410_timer_s__ {
uint32_t tcnt; uint32_t tcnt;
uint32_t tcmp; uint32_t tcmp;
const s3c2410_timer_config_t *tconfig; const s3c2410_timer_config_t* tconfig;
int index; int index;
s3c2410_timer_t *main; s3c2410_timer_t* main;
unsigned long interval; unsigned long interval;
x49gp_timer_t *timer; x49gp_timer_t* timer;
} timeout[5]; } timeout[ 5 ];
}; };
static const s3c2410_timer_config_t s3c2410_timer_config[] = static const s3c2410_timer_config_t s3c2410_timer_config[] = {
{ {TCON_TIMER0_RELOAD, TCON_TIMER0_UPDATE, TCON_TIMER0_START, TCFG0_PRE0_SHIFT, TCFG1_MUX0_SHIFT, INT_TIMER0},
{ {TCON_TIMER1_RELOAD, TCON_TIMER1_UPDATE, TCON_TIMER1_START, TCFG0_PRE0_SHIFT, TCFG1_MUX1_SHIFT, INT_TIMER1},
TCON_TIMER0_RELOAD, TCON_TIMER0_UPDATE, TCON_TIMER0_START, {TCON_TIMER2_RELOAD, TCON_TIMER2_UPDATE, TCON_TIMER2_START, TCFG0_PRE1_SHIFT, TCFG1_MUX2_SHIFT, INT_TIMER2},
TCFG0_PRE0_SHIFT, TCFG1_MUX0_SHIFT, INT_TIMER0 {TCON_TIMER3_RELOAD, TCON_TIMER3_UPDATE, TCON_TIMER3_START, TCFG0_PRE1_SHIFT, TCFG1_MUX3_SHIFT, INT_TIMER3},
}, {TCON_TIMER4_RELOAD, TCON_TIMER4_UPDATE, TCON_TIMER4_START, TCFG0_PRE1_SHIFT, TCFG1_MUX4_SHIFT, INT_TIMER4},
{
TCON_TIMER1_RELOAD, TCON_TIMER1_UPDATE, TCON_TIMER1_START,
TCFG0_PRE0_SHIFT, TCFG1_MUX1_SHIFT, INT_TIMER1
},
{
TCON_TIMER2_RELOAD, TCON_TIMER2_UPDATE, TCON_TIMER2_START,
TCFG0_PRE1_SHIFT, TCFG1_MUX2_SHIFT, INT_TIMER2
},
{
TCON_TIMER3_RELOAD, TCON_TIMER3_UPDATE, TCON_TIMER3_START,
TCFG0_PRE1_SHIFT, TCFG1_MUX3_SHIFT, INT_TIMER3
},
{
TCON_TIMER4_RELOAD, TCON_TIMER4_UPDATE, TCON_TIMER4_START,
TCFG0_PRE1_SHIFT, TCFG1_MUX4_SHIFT, INT_TIMER4
},
}; };
static int static int s3c2410_timer_data_init( s3c2410_timer_t* timer )
s3c2410_timer_data_init(s3c2410_timer_t *timer)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = { S3C2410_OFFSET( TIMER, TCFG0, 0, timer->tcfg0 ),
S3C2410_OFFSET(TIMER, TCFG0, 0, timer->tcfg0), S3C2410_OFFSET( TIMER, TCFG1, 0, timer->tcfg1 ),
S3C2410_OFFSET(TIMER, TCFG1, 0, timer->tcfg1), S3C2410_OFFSET( TIMER, TCON, 0, timer->tcon ),
S3C2410_OFFSET(TIMER, TCON, 0, timer->tcon), S3C2410_OFFSET( TIMER, TCNTB0, 0, timer->timeout[ 0 ].tcntb ),
S3C2410_OFFSET(TIMER, TCNTB0, 0, timer->timeout[0].tcntb), S3C2410_OFFSET( TIMER, TCMPB0, 0, timer->timeout[ 0 ].tcmpb ),
S3C2410_OFFSET(TIMER, TCMPB0, 0, timer->timeout[0].tcmpb), S3C2410_OFFSET( TIMER, TCNTO0, 0, timer->timeout[ 0 ].tcnt ),
S3C2410_OFFSET(TIMER, TCNTO0, 0, timer->timeout[0].tcnt), S3C2410_OFFSET( TIMER, TCNTB1, 0, timer->timeout[ 1 ].tcntb ),
S3C2410_OFFSET(TIMER, TCNTB1, 0, timer->timeout[1].tcntb), S3C2410_OFFSET( TIMER, TCMPB1, 0, timer->timeout[ 1 ].tcmpb ),
S3C2410_OFFSET(TIMER, TCMPB1, 0, timer->timeout[1].tcmpb), S3C2410_OFFSET( TIMER, TCNTO1, 0, timer->timeout[ 1 ].tcnt ),
S3C2410_OFFSET(TIMER, TCNTO1, 0, timer->timeout[1].tcnt), S3C2410_OFFSET( TIMER, TCNTB2, 0, timer->timeout[ 2 ].tcntb ),
S3C2410_OFFSET(TIMER, TCNTB2, 0, timer->timeout[2].tcntb), S3C2410_OFFSET( TIMER, TCMPB2, 0, timer->timeout[ 2 ].tcmpb ),
S3C2410_OFFSET(TIMER, TCMPB2, 0, timer->timeout[2].tcmpb), S3C2410_OFFSET( TIMER, TCNTO2, 0, timer->timeout[ 2 ].tcnt ),
S3C2410_OFFSET(TIMER, TCNTO2, 0, timer->timeout[2].tcnt), S3C2410_OFFSET( TIMER, TCNTB3, 0, timer->timeout[ 3 ].tcntb ),
S3C2410_OFFSET(TIMER, TCNTB3, 0, timer->timeout[3].tcntb), S3C2410_OFFSET( TIMER, TCMPB3, 0, timer->timeout[ 3 ].tcmpb ),
S3C2410_OFFSET(TIMER, TCMPB3, 0, timer->timeout[3].tcmpb), S3C2410_OFFSET( TIMER, TCNTO3, 0, timer->timeout[ 3 ].tcnt ),
S3C2410_OFFSET(TIMER, TCNTO3, 0, timer->timeout[3].tcnt), S3C2410_OFFSET( TIMER, TCNTB4, 0, timer->timeout[ 4 ].tcntb ),
S3C2410_OFFSET(TIMER, TCNTB4, 0, timer->timeout[4].tcntb), S3C2410_OFFSET( TIMER, TCNTO4, 0, timer->timeout[ 4 ].tcnt ) };
S3C2410_OFFSET(TIMER, TCNTO4, 0, timer->timeout[4].tcnt)
};
memset(timer, 0, sizeof(s3c2410_timer_t)); memset( timer, 0, sizeof( s3c2410_timer_t ) );
timer->regs = malloc(sizeof(regs)); timer->regs = malloc( sizeof( regs ) );
if (NULL == timer->regs) { if ( NULL == timer->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(timer->regs, regs, sizeof(regs)); memcpy( timer->regs, regs, sizeof( regs ) );
timer->nr_regs = sizeof(regs) / sizeof(regs[0]); timer->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static void static void s3c2410_timer_timeout( void* data )
s3c2410_timer_timeout(void *data)
{ {
struct s3c2410_timeout *t = data; struct s3c2410_timeout* t = data;
s3c2410_timer_t *timer = t->main; s3c2410_timer_t* timer = t->main;
x49gp_t *x49gp = timer->x49gp; x49gp_t* x49gp = timer->x49gp;
int64_t timeout; int64_t timeout;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: assert TIMER%u interrupt\n", t->index); printf( "s3c2410-timer: assert TIMER%u interrupt\n", t->index );
#endif #endif
s3c2410_intc_assert(timer->x49gp, t->tconfig->irq, 0); s3c2410_intc_assert( timer->x49gp, t->tconfig->irq, 0 );
if (timer->tcon & t->tconfig->reload_bit) { if ( timer->tcon & t->tconfig->reload_bit ) {
t->tcnt = t->tcntb; t->tcnt = t->tcntb;
t->tcmp = t->tcmpb; t->tcmp = t->tcmpb;
} else { } else {
timer->tcon &= ~(t->tconfig->start_bit); timer->tcon &= ~( t->tconfig->start_bit );
return; return;
} }
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK; timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: reload TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, (unsigned long long) timeout); printf( "s3c2410-timer: reload TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, ( unsigned long long )timeout );
#endif #endif
x49gp_mod_timer(t->timer, x49gp_get_clock() + timeout); x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
} }
unsigned long unsigned long s3c2410_timer_next_interrupt( x49gp_t* x49gp )
s3c2410_timer_next_interrupt(x49gp_t *x49gp)
{ {
s3c2410_timer_t *timer = x49gp->s3c2410_timer; s3c2410_timer_t* timer = x49gp->s3c2410_timer;
struct s3c2410_timeout *t; struct s3c2410_timeout* t;
unsigned long irq, next; unsigned long irq, next;
unsigned long ticks; unsigned long ticks;
int i; int i;
ticks = x49gp_get_clock(); ticks = x49gp_get_clock();
next = ~(0); next = ~( 0 );
for (i = 0; i < 5; i++) { for ( i = 0; i < 5; i++ ) {
t = &timer->timeout[i]; t = &timer->timeout[ i ];
if (!(timer->tcon & t->tconfig->start_bit)) if ( !( timer->tcon & t->tconfig->start_bit ) )
continue; continue;
if (x49gp_timer_pending(t->timer)) { if ( x49gp_timer_pending( t->timer ) ) {
irq = x49gp_timer_expires(t->timer) - ticks; irq = x49gp_timer_expires( t->timer ) - ticks;
} else { } else {
irq = 0; irq = 0;
} }
if (t->tcnt) { if ( t->tcnt ) {
irq += (t->tcnt - 1) * t->interval; irq += ( t->tcnt - 1 ) * t->interval;
} else { } else {
if (!(timer->tcon & t->tconfig->reload_bit)) if ( !( timer->tcon & t->tconfig->reload_bit ) )
continue; continue;
irq += t->tcntb * t->interval; irq += t->tcntb * t->interval;
} }
if (irq < next) if ( irq < next )
next = irq; next = irq;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: TIMER%u: tcnt %u, interval %lu, pending %u, next irq %lu\n", printf( "s3c2410-timer: TIMER%u: tcnt %u, interval %lu, pending %u, next irq %lu\n", t->index, t->tcnt, t->interval,
t->index, t->tcnt, t->interval, x49gp_timer_pending(t->timer), irq); x49gp_timer_pending( t->timer ), irq );
#endif #endif
} }
return next; return next;
} }
static void static void s3c2410_update_tcfg( s3c2410_timer_t* timer )
s3c2410_update_tcfg(s3c2410_timer_t *timer)
{ {
struct s3c2410_timeout *t; struct s3c2410_timeout* t;
x49gp_t *x49gp = timer->x49gp; x49gp_t* x49gp = timer->x49gp;
uint32_t pre, mux; uint32_t pre, mux;
int64_t timeout; int64_t timeout;
int i; int i;
for (i = 0; i < 5; i++) { for ( i = 0; i < 5; i++ ) {
t = &timer->timeout[i]; t = &timer->timeout[ i ];
pre = (timer->tcfg0 >> t->tconfig->pre_shift) & TCFG0_PREx_MASK; pre = ( timer->tcfg0 >> t->tconfig->pre_shift ) & TCFG0_PREx_MASK;
mux = (timer->tcfg1 >> t->tconfig->mux_shift) & TCFG1_MUXx_MASK; mux = ( timer->tcfg1 >> t->tconfig->mux_shift ) & TCFG1_MUXx_MASK;
if (mux > 3) { if ( mux > 3 ) {
printf("s3c2410-timer: can't handle MUX %02x for TIMER%u\n", printf( "s3c2410-timer: can't handle MUX %02x for TIMER%u\n", mux, t->index );
mux, t->index);
mux = 3; mux = 3;
} }
t->interval = (pre + 1) * (2 << mux); t->interval = ( pre + 1 ) * ( 2 << mux );
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: TIMER%u: pre %u, mux %u, tick %lu PCLKs\n", printf( "s3c2410-timer: TIMER%u: pre %u, mux %u, tick %lu PCLKs\n", t->index, pre, mux, t->interval );
t->index, pre, mux, t->interval);
#endif #endif
if (x49gp_timer_pending(t->timer)) { if ( x49gp_timer_pending( t->timer ) ) {
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK; timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: mod TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, (unsigned long long) timeout); printf( "s3c2410-timer: mod TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval,
( unsigned long long )timeout );
#endif #endif
x49gp_mod_timer(t->timer, x49gp_get_clock() + timeout); x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
} }
} }
} }
static void static void s3c2410_update_tcon( s3c2410_timer_t* timer )
s3c2410_update_tcon(s3c2410_timer_t *timer)
{ {
struct s3c2410_timeout *t; struct s3c2410_timeout* t;
x49gp_t *x49gp = timer->x49gp; x49gp_t* x49gp = timer->x49gp;
int64_t timeout; int64_t timeout;
uint32_t change; uint32_t change;
int i; int i;
@ -238,132 +212,126 @@ s3c2410_update_tcon(s3c2410_timer_t *timer)
change = timer->prev_tcon ^ timer->tcon; change = timer->prev_tcon ^ timer->tcon;
timer->prev_tcon = timer->tcon; timer->prev_tcon = timer->tcon;
for (i = 0; i < 5; i++) { for ( i = 0; i < 5; i++ ) {
t = &timer->timeout[i]; t = &timer->timeout[ i ];
if (timer->tcon & t->tconfig->update_bit) { if ( timer->tcon & t->tconfig->update_bit ) {
t->tcnt = t->tcntb; t->tcnt = t->tcntb;
t->tcmp = t->tcmpb; t->tcmp = t->tcmpb;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: update TIMER%u tcnt %u, tcmp %u\n", t->index, t->tcnt, t->tcmp); printf( "s3c2410-timer: update TIMER%u tcnt %u, tcmp %u\n", t->index, t->tcnt, t->tcmp );
#endif #endif
} }
if (change & t->tconfig->start_bit) { if ( change & t->tconfig->start_bit ) {
if (timer->tcon & t->tconfig->start_bit) { if ( timer->tcon & t->tconfig->start_bit ) {
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK; timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: start TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, (unsigned long long) timeout); printf( "s3c2410-timer: start TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval,
( unsigned long long )timeout );
#endif #endif
x49gp_mod_timer(t->timer, x49gp_get_clock() + timeout); x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
} else { } else {
x49gp_del_timer(t->timer); x49gp_del_timer( t->timer );
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("s3c2410-timer: stop TIMER%u\n", t->index); printf( "s3c2410-timer: stop TIMER%u\n", t->index );
#endif #endif
} }
} }
} }
} }
static uint32_t static uint32_t s3c2410_read_tcnt( s3c2410_timer_t* timer, int index )
s3c2410_read_tcnt(s3c2410_timer_t *timer, int index)
{ {
struct s3c2410_timeout *t = &timer->timeout[index]; struct s3c2410_timeout* t = &timer->timeout[ index ];
x49gp_t *x49gp = timer->x49gp; x49gp_t* x49gp = timer->x49gp;
int64_t now, expires, timeout; int64_t now, expires, timeout;
if (!(timer->tcon & t->tconfig->start_bit)) if ( !( timer->tcon & t->tconfig->start_bit ) )
return t->tcnt; return t->tcnt;
if (x49gp_timer_pending(t->timer)) { if ( x49gp_timer_pending( t->timer ) ) {
now = x49gp_get_clock(); now = x49gp_get_clock();
expires = x49gp_timer_expires(t->timer); expires = x49gp_timer_expires( t->timer );
timeout = expires - now; timeout = expires - now;
if (timeout <= 0) if ( timeout <= 0 )
return 0; return 0;
t->tcnt = timeout * x49gp->PCLK / (1000000LL * t->interval); t->tcnt = timeout * x49gp->PCLK / ( 1000000LL * t->interval );
} }
return t->tcnt; return t->tcnt;
} }
static uint32_t static uint32_t s3c2410_timer_read( void* opaque, target_phys_addr_t offset )
s3c2410_timer_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_timer_t *timer = opaque; s3c2410_timer_t* timer = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t data; uint32_t data;
if (! S3C2410_OFFSET_OK(timer, offset)) { if ( !S3C2410_OFFSET_OK( timer, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(timer, offset); reg = S3C2410_OFFSET_ENTRY( timer, offset );
switch (offset) { switch ( offset ) {
case S3C2410_TIMER_TCNTO0: case S3C2410_TIMER_TCNTO0:
data = s3c2410_read_tcnt(timer, 0); data = s3c2410_read_tcnt( timer, 0 );
break; break;
case S3C2410_TIMER_TCNTO1: case S3C2410_TIMER_TCNTO1:
data = s3c2410_read_tcnt(timer, 1); data = s3c2410_read_tcnt( timer, 1 );
break; break;
case S3C2410_TIMER_TCNTO2: case S3C2410_TIMER_TCNTO2:
data = s3c2410_read_tcnt(timer, 2); data = s3c2410_read_tcnt( timer, 2 );
break; break;
case S3C2410_TIMER_TCNTO3: case S3C2410_TIMER_TCNTO3:
data = s3c2410_read_tcnt(timer, 3); data = s3c2410_read_tcnt( timer, 3 );
break; break;
case S3C2410_TIMER_TCNTO4: case S3C2410_TIMER_TCNTO4:
data = s3c2410_read_tcnt(timer, 4); data = s3c2410_read_tcnt( timer, 4 );
break; break;
default: default:
data = *(reg->datap); data = *( reg->datap );
break; break;
} }
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-timer", S3C2410_TIMER_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-timer", S3C2410_TIMER_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
return data; return data;
} }
static void static void s3c2410_timer_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_timer_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_timer_t *timer = opaque; s3c2410_timer_t* timer = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(timer, offset)) { if ( !S3C2410_OFFSET_OK( timer, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(timer, offset); reg = S3C2410_OFFSET_ENTRY( timer, offset );
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-timer", S3C2410_TIMER_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-timer", S3C2410_TIMER_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_TIMER_TCFG0: case S3C2410_TIMER_TCFG0:
*(reg->datap) = data; *( reg->datap ) = data;
s3c2410_update_tcfg(timer); s3c2410_update_tcfg( timer );
break; break;
case S3C2410_TIMER_TCFG1: case S3C2410_TIMER_TCFG1:
*(reg->datap) = data; *( reg->datap ) = data;
s3c2410_update_tcfg(timer); s3c2410_update_tcfg( timer );
break; break;
case S3C2410_TIMER_TCON: case S3C2410_TIMER_TCON:
*(reg->datap) = data; *( reg->datap ) = data;
s3c2410_update_tcon(timer); s3c2410_update_tcon( timer );
break; break;
case S3C2410_TIMER_TCNTO0: case S3C2410_TIMER_TCNTO0:
case S3C2410_TIMER_TCNTO1: case S3C2410_TIMER_TCNTO1:
@ -373,123 +341,107 @@ s3c2410_timer_write(void *opaque, target_phys_addr_t offset, uint32_t data)
/* read only */ /* read only */
break; break;
default: default:
*(reg->datap) = data; *( reg->datap ) = data;
break; break;
} }
} }
static int static int s3c2410_timer_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_timer_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_timer_t *timer = module->user_data; s3c2410_timer_t* timer = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < timer->nr_regs; i++) { for ( i = 0; i < timer->nr_regs; i++ ) {
reg = &timer->regs[i]; reg = &timer->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
s3c2410_update_tcon(timer); s3c2410_update_tcon( timer );
s3c2410_update_tcfg(timer); s3c2410_update_tcfg( timer );
return error; return error;
} }
static int static int s3c2410_timer_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_timer_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_timer_t *timer = module->user_data; s3c2410_timer_t* timer = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < timer->nr_regs; i++) { for ( i = 0; i < timer->nr_regs; i++ ) {
reg = &timer->regs[i]; reg = &timer->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_timer_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_timer_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_timer_t *timer = module->user_data; s3c2410_timer_t* timer = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < timer->nr_regs; i++) { for ( i = 0; i < timer->nr_regs; i++ ) {
reg = &timer->regs[i]; reg = &timer->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
s3c2410_update_tcon(timer); s3c2410_update_tcon( timer );
s3c2410_update_tcfg(timer); s3c2410_update_tcfg( timer );
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_timer_readfn[] = static CPUReadMemoryFunc* s3c2410_timer_readfn[] = { s3c2410_timer_read, s3c2410_timer_read, s3c2410_timer_read };
{
s3c2410_timer_read,
s3c2410_timer_read,
s3c2410_timer_read
};
static CPUWriteMemoryFunc *s3c2410_timer_writefn[] = static CPUWriteMemoryFunc* s3c2410_timer_writefn[] = { s3c2410_timer_write, s3c2410_timer_write, s3c2410_timer_write };
{
s3c2410_timer_write,
s3c2410_timer_write,
s3c2410_timer_write
};
static int static int s3c2410_timer_init( x49gp_module_t* module )
s3c2410_timer_init(x49gp_module_t *module)
{ {
s3c2410_timer_t *timer; s3c2410_timer_t* timer;
struct s3c2410_timeout *t; struct s3c2410_timeout* t;
int iotype; int iotype;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
timer = malloc(sizeof(s3c2410_timer_t)); timer = malloc( sizeof( s3c2410_timer_t ) );
if (NULL == timer) { if ( NULL == timer ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
module->x49gp->progname, __FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_timer_data_init(timer)) { if ( s3c2410_timer_data_init( timer ) ) {
free(timer); free( timer );
return -ENOMEM; return -ENOMEM;
} }
@ -498,62 +450,54 @@ s3c2410_timer_init(x49gp_module_t *module)
timer->x49gp = module->x49gp; timer->x49gp = module->x49gp;
module->x49gp->s3c2410_timer = timer; module->x49gp->s3c2410_timer = timer;
for (i = 0; i < 5; i++) { for ( i = 0; i < 5; i++ ) {
t = &timer->timeout[i]; t = &timer->timeout[ i ];
t->tconfig = &s3c2410_timer_config[i]; t->tconfig = &s3c2410_timer_config[ i ];
t->index = i; t->index = i;
t->main = timer; t->main = timer;
t->timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t); t->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t );
} }
iotype = cpu_register_io_memory(s3c2410_timer_readfn, iotype = cpu_register_io_memory( s3c2410_timer_readfn, s3c2410_timer_writefn, timer );
s3c2410_timer_writefn, timer);
#ifdef DEBUG_S3C2410_TIMER #ifdef DEBUG_S3C2410_TIMER
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_TIMER_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_TIMER_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_timer_exit( x49gp_module_t* module )
s3c2410_timer_exit(x49gp_module_t *module)
{ {
s3c2410_timer_t *timer; s3c2410_timer_t* timer;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
timer = module->user_data; timer = module->user_data;
if (timer->regs) if ( timer->regs )
free(timer->regs); free( timer->regs );
free(timer); free( timer );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_timer_init( x49gp_t* x49gp )
x49gp_s3c2410_timer_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-timer", if ( x49gp_module_init( x49gp, "s3c2410-timer", s3c2410_timer_init, s3c2410_timer_exit, s3c2410_timer_reset, s3c2410_timer_load,
s3c2410_timer_init, s3c2410_timer_save, NULL, &module ) ) {
s3c2410_timer_exit,
s3c2410_timer_reset,
s3c2410_timer_load,
s3c2410_timer_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -42,7 +42,7 @@
#define TCON_TIMER0_UPDATE 0x00000002 #define TCON_TIMER0_UPDATE 0x00000002
#define TCON_TIMER0_START 0x00000001 #define TCON_TIMER0_START 0x00000001
void s3c2410_run_timers(x49gp_t *x49gp); void s3c2410_run_timers( x49gp_t* x49gp );
clock_t s3c2410_next_timer(x49gp_t *x49gp); clock_t s3c2410_next_timer( x49gp_t* x49gp );
#endif /* !(_S3C2410_TIMER_H) */ #endif /* !(_S3C2410_TIMER_H) */

View file

@ -13,7 +13,6 @@
#include "s3c2410.h" #include "s3c2410.h"
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
typedef struct { typedef struct {
uint32_t ulcon; uint32_t ulcon;
uint32_t ucon; uint32_t ucon;
@ -32,113 +31,102 @@ typedef struct {
int int_rxd; int int_rxd;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
} s3c2410_uart_reg_t; } s3c2410_uart_reg_t;
typedef struct { typedef struct {
s3c2410_uart_reg_t uart[3]; s3c2410_uart_reg_t uart[ 3 ];
} s3c2410_uart_t; } s3c2410_uart_t;
static int static int s3c2410_uart_data_init( s3c2410_uart_t* uart )
s3c2410_uart_data_init(s3c2410_uart_t *uart)
{ {
s3c2410_offset_t regs0[] = { s3c2410_offset_t regs0[] = { S3C2410_OFFSET( UART0, ULCON, 0x00000000, uart->uart[ 0 ].ulcon ),
S3C2410_OFFSET(UART0, ULCON, 0x00000000, uart->uart[0].ulcon), S3C2410_OFFSET( UART0, UCON, 0x00000000, uart->uart[ 0 ].ucon ),
S3C2410_OFFSET(UART0, UCON, 0x00000000, uart->uart[0].ucon), S3C2410_OFFSET( UART0, UFCON, 0x00000000, uart->uart[ 0 ].ufcon ),
S3C2410_OFFSET(UART0, UFCON, 0x00000000, uart->uart[0].ufcon), S3C2410_OFFSET( UART0, UMCON, 0x00000000, uart->uart[ 0 ].umcon ),
S3C2410_OFFSET(UART0, UMCON, 0x00000000, uart->uart[0].umcon), S3C2410_OFFSET( UART0, UTRSTAT, 0x00000006, uart->uart[ 0 ].utrstat ),
S3C2410_OFFSET(UART0, UTRSTAT, 0x00000006, uart->uart[0].utrstat), S3C2410_OFFSET( UART0, UERSTAT, 0x00000000, uart->uart[ 0 ].uerstat ),
S3C2410_OFFSET(UART0, UERSTAT, 0x00000000, uart->uart[0].uerstat), S3C2410_OFFSET( UART0, UFSTAT, 0x00000000, uart->uart[ 0 ].ufstat ),
S3C2410_OFFSET(UART0, UFSTAT, 0x00000000, uart->uart[0].ufstat), S3C2410_OFFSET( UART0, UMSTAT, 0x00000000, uart->uart[ 0 ].umstat ),
S3C2410_OFFSET(UART0, UMSTAT, 0x00000000, uart->uart[0].umstat), S3C2410_OFFSET( UART0, UTXH, 0, uart->uart[ 0 ].utxh ),
S3C2410_OFFSET(UART0, UTXH, 0, uart->uart[0].utxh), S3C2410_OFFSET( UART0, URXH, 0, uart->uart[ 0 ].urxh ),
S3C2410_OFFSET(UART0, URXH, 0, uart->uart[0].urxh), S3C2410_OFFSET( UART0, UBRDIV, 0, uart->uart[ 0 ].ubrdiv ) };
S3C2410_OFFSET(UART0, UBRDIV, 0, uart->uart[0].ubrdiv) s3c2410_offset_t regs1[] = { S3C2410_OFFSET( UART1, ULCON, 0x00000000, uart->uart[ 1 ].ulcon ),
}; S3C2410_OFFSET( UART1, UCON, 0x00000000, uart->uart[ 1 ].ucon ),
s3c2410_offset_t regs1[] = { S3C2410_OFFSET( UART1, UFCON, 0x00000000, uart->uart[ 1 ].ufcon ),
S3C2410_OFFSET(UART1, ULCON, 0x00000000, uart->uart[1].ulcon), S3C2410_OFFSET( UART1, UMCON, 0x00000000, uart->uart[ 1 ].umcon ),
S3C2410_OFFSET(UART1, UCON, 0x00000000, uart->uart[1].ucon), S3C2410_OFFSET( UART1, UTRSTAT, 0x00000006, uart->uart[ 1 ].utrstat ),
S3C2410_OFFSET(UART1, UFCON, 0x00000000, uart->uart[1].ufcon), S3C2410_OFFSET( UART1, UERSTAT, 0x00000000, uart->uart[ 1 ].uerstat ),
S3C2410_OFFSET(UART1, UMCON, 0x00000000, uart->uart[1].umcon), S3C2410_OFFSET( UART1, UFSTAT, 0x00000000, uart->uart[ 1 ].ufstat ),
S3C2410_OFFSET(UART1, UTRSTAT, 0x00000006, uart->uart[1].utrstat), S3C2410_OFFSET( UART1, UMSTAT, 0x00000000, uart->uart[ 1 ].umstat ),
S3C2410_OFFSET(UART1, UERSTAT, 0x00000000, uart->uart[1].uerstat), S3C2410_OFFSET( UART1, UTXH, 0, uart->uart[ 1 ].utxh ),
S3C2410_OFFSET(UART1, UFSTAT, 0x00000000, uart->uart[1].ufstat), S3C2410_OFFSET( UART1, URXH, 0, uart->uart[ 1 ].urxh ),
S3C2410_OFFSET(UART1, UMSTAT, 0x00000000, uart->uart[1].umstat), S3C2410_OFFSET( UART1, UBRDIV, 0, uart->uart[ 1 ].ubrdiv ) };
S3C2410_OFFSET(UART1, UTXH, 0, uart->uart[1].utxh), s3c2410_offset_t regs2[] = { S3C2410_OFFSET( UART2, ULCON, 0x00000000, uart->uart[ 2 ].ulcon ),
S3C2410_OFFSET(UART1, URXH, 0, uart->uart[1].urxh), S3C2410_OFFSET( UART2, UCON, 0x00000000, uart->uart[ 2 ].ucon ),
S3C2410_OFFSET(UART1, UBRDIV, 0, uart->uart[1].ubrdiv) S3C2410_OFFSET( UART2, UFCON, 0x00000000, uart->uart[ 2 ].ufcon ),
}; S3C2410_OFFSET( UART2, UTRSTAT, 0x00000006, uart->uart[ 2 ].utrstat ),
s3c2410_offset_t regs2[] = { S3C2410_OFFSET( UART2, UERSTAT, 0x00000000, uart->uart[ 2 ].uerstat ),
S3C2410_OFFSET(UART2, ULCON, 0x00000000, uart->uart[2].ulcon), S3C2410_OFFSET( UART2, UFSTAT, 0x00000000, uart->uart[ 2 ].ufstat ),
S3C2410_OFFSET(UART2, UCON, 0x00000000, uart->uart[2].ucon), S3C2410_OFFSET( UART2, UTXH, 0, uart->uart[ 2 ].utxh ),
S3C2410_OFFSET(UART2, UFCON, 0x00000000, uart->uart[2].ufcon), S3C2410_OFFSET( UART2, URXH, 0, uart->uart[ 2 ].urxh ),
S3C2410_OFFSET(UART2, UTRSTAT, 0x00000006, uart->uart[2].utrstat), S3C2410_OFFSET( UART2, UBRDIV, 0, uart->uart[ 2 ].ubrdiv ) };
S3C2410_OFFSET(UART2, UERSTAT, 0x00000000, uart->uart[2].uerstat),
S3C2410_OFFSET(UART2, UFSTAT, 0x00000000, uart->uart[2].ufstat),
S3C2410_OFFSET(UART2, UTXH, 0, uart->uart[2].utxh),
S3C2410_OFFSET(UART2, URXH, 0, uart->uart[2].urxh),
S3C2410_OFFSET(UART2, UBRDIV, 0, uart->uart[2].ubrdiv)
};
uart->uart[0].regs = malloc(sizeof(regs0)); uart->uart[ 0 ].regs = malloc( sizeof( regs0 ) );
if (NULL == uart->uart[0].regs) { if ( NULL == uart->uart[ 0 ].regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
uart->uart[1].regs = malloc(sizeof(regs1)); uart->uart[ 1 ].regs = malloc( sizeof( regs1 ) );
if (NULL == uart->uart[1].regs) { if ( NULL == uart->uart[ 1 ].regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__); free( uart->uart[ 0 ].regs );
free(uart->uart[0].regs);
return -ENOMEM; return -ENOMEM;
} }
uart->uart[2].regs = malloc(sizeof(regs2)); uart->uart[ 2 ].regs = malloc( sizeof( regs2 ) );
if (NULL == uart->uart[2].regs) { if ( NULL == uart->uart[ 2 ].regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__); free( uart->uart[ 0 ].regs );
free(uart->uart[0].regs); free( uart->uart[ 1 ].regs );
free(uart->uart[1].regs);
return -ENOMEM; return -ENOMEM;
} }
memcpy(uart->uart[0].regs, regs0, sizeof(regs0)); memcpy( uart->uart[ 0 ].regs, regs0, sizeof( regs0 ) );
uart->uart[0].nr_regs = sizeof(regs0) / sizeof(regs0[0]); uart->uart[ 0 ].nr_regs = sizeof( regs0 ) / sizeof( regs0[ 0 ] );
uart->uart[0].int_err = SUB_INT_ERR0; uart->uart[ 0 ].int_err = SUB_INT_ERR0;
uart->uart[0].int_txd = SUB_INT_TXD0; uart->uart[ 0 ].int_txd = SUB_INT_TXD0;
uart->uart[0].int_rxd = SUB_INT_RXD0; uart->uart[ 0 ].int_rxd = SUB_INT_RXD0;
memcpy(uart->uart[1].regs, regs1, sizeof(regs1)); memcpy( uart->uart[ 1 ].regs, regs1, sizeof( regs1 ) );
uart->uart[1].nr_regs = sizeof(regs1) / sizeof(regs1[0]); uart->uart[ 1 ].nr_regs = sizeof( regs1 ) / sizeof( regs1[ 0 ] );
uart->uart[1].int_err = SUB_INT_ERR1; uart->uart[ 1 ].int_err = SUB_INT_ERR1;
uart->uart[1].int_txd = SUB_INT_TXD1; uart->uart[ 1 ].int_txd = SUB_INT_TXD1;
uart->uart[1].int_rxd = SUB_INT_RXD1; uart->uart[ 1 ].int_rxd = SUB_INT_RXD1;
memcpy(uart->uart[2].regs, regs2, sizeof(regs2)); memcpy( uart->uart[ 2 ].regs, regs2, sizeof( regs2 ) );
uart->uart[2].nr_regs = sizeof(regs2) / sizeof(regs2[0]); uart->uart[ 2 ].nr_regs = sizeof( regs2 ) / sizeof( regs2[ 0 ] );
uart->uart[2].int_err = SUB_INT_ERR2; uart->uart[ 2 ].int_err = SUB_INT_ERR2;
uart->uart[2].int_txd = SUB_INT_TXD2; uart->uart[ 2 ].int_txd = SUB_INT_TXD2;
uart->uart[2].int_rxd = SUB_INT_RXD2; uart->uart[ 2 ].int_rxd = SUB_INT_RXD2;
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_uart_read( void* opaque, target_phys_addr_t offset )
s3c2410_uart_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_uart_reg_t *uart_regs = opaque; s3c2410_uart_reg_t* uart_regs = opaque;
x49gp_t *x49gp = uart_regs->x49gp; x49gp_t* x49gp = uart_regs->x49gp;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
const char *module; const char* module;
uint32_t mod_offset; uint32_t mod_offset;
uint32_t base; uint32_t base;
base = (offset & 0x0000c000) >> 14; base = ( offset & 0x0000c000 ) >> 14;
switch (base) { switch ( base ) {
case 0: case 0:
module = "s3c2410-uart0"; module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE; mod_offset = S3C2410_UART0_BASE;
@ -152,52 +140,50 @@ s3c2410_uart_read(void *opaque, target_phys_addr_t offset)
mod_offset = S3C2410_UART2_BASE; mod_offset = S3C2410_UART2_BASE;
break; break;
default: default:
return ~(0); return ~( 0 );
} }
#endif #endif
offset &= ~(0xffffc000); offset &= ~( 0xffffc000 );
if (! S3C2410_OFFSET_OK(uart_regs, offset)) { if ( !S3C2410_OFFSET_OK( uart_regs, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(uart_regs, offset); reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", module, mod_offset, reg->name, ( unsigned long )offset, *( reg->datap ) );
module, mod_offset, reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
switch (offset) { switch ( offset ) {
case S3C2410_UART0_URXH: case S3C2410_UART0_URXH:
uart_regs->utrstat &= ~(1 << 0); uart_regs->utrstat &= ~( 1 << 0 );
if (uart_regs->ucon & (1 << 8)) { if ( uart_regs->ucon & ( 1 << 8 ) ) {
s3c2410_intc_sub_deassert(x49gp, uart_regs->int_rxd); s3c2410_intc_sub_deassert( x49gp, uart_regs->int_rxd );
} }
break; break;
} }
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_uart_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_uart_reg_t *uart_regs = opaque; s3c2410_uart_reg_t* uart_regs = opaque;
x49gp_t *x49gp = uart_regs->x49gp; x49gp_t* x49gp = uart_regs->x49gp;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
uint32_t base; uint32_t base;
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
const char *module; const char* module;
uint32_t mod_offset, ubrdivn, baud; uint32_t mod_offset, ubrdivn, baud;
#endif #endif
base = (offset & 0x0000c000) >> 14; base = ( offset & 0x0000c000 ) >> 14;
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
switch (base) { switch ( base ) {
case 0: case 0:
module = "s3c2410-uart0"; module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE; mod_offset = S3C2410_UART0_BASE;
@ -215,262 +201,225 @@ s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
} }
#endif #endif
offset &= ~(0xffffc000); offset &= ~( 0xffffc000 );
if (! S3C2410_OFFSET_OK(uart_regs, offset)) { if ( !S3C2410_OFFSET_OK( uart_regs, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(uart_regs, offset); reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", module, mod_offset, reg->name, ( unsigned long )offset, data );
module, mod_offset, reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
switch (offset) { switch ( offset ) {
case S3C2410_UART0_UCON: case S3C2410_UART0_UCON:
if (*(reg->datap) & (1 << 9)) if ( *( reg->datap ) & ( 1 << 9 ) )
s3c2410_intc_sub_assert(x49gp, uart_regs->int_txd, 1); s3c2410_intc_sub_assert( x49gp, uart_regs->int_txd, 1 );
if (*(reg->datap) & (1 << 8)) if ( *( reg->datap ) & ( 1 << 8 ) )
s3c2410_intc_sub_deassert(x49gp, uart_regs->int_rxd); s3c2410_intc_sub_deassert( x49gp, uart_regs->int_rxd );
break; break;
case S3C2410_UART0_UBRDIV: case S3C2410_UART0_UBRDIV:
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
ubrdivn = (data >> 0) & 0xffff; ubrdivn = ( data >> 0 ) & 0xffff;
if (uart_regs->ucon & (1 << 10)) { if ( uart_regs->ucon & ( 1 << 10 ) ) {
baud = x49gp->UCLK / 16 / (ubrdivn + 1); baud = x49gp->UCLK / 16 / ( ubrdivn + 1 );
printf("%s: UEXTCLK %u, ubrdivn %u, baud %u\n", printf( "%s: UEXTCLK %u, ubrdivn %u, baud %u\n", module, x49gp->UCLK, ubrdivn, baud );
module, x49gp->UCLK, ubrdivn, baud);
} else { } else {
baud = x49gp->PCLK / 16 / (ubrdivn + 1); baud = x49gp->PCLK / 16 / ( ubrdivn + 1 );
printf("%s: PCLK %u, ubrdivn %u, baud %u\n", printf( "%s: PCLK %u, ubrdivn %u, baud %u\n", module, x49gp->PCLK, ubrdivn, baud );
module, x49gp->PCLK, ubrdivn, baud);
} }
#endif #endif
break; break;
case S3C2410_UART0_UTXH: case S3C2410_UART0_UTXH:
if (uart_regs->ucon & (1 << 9)) if ( uart_regs->ucon & ( 1 << 9 ) )
s3c2410_intc_sub_deassert(x49gp, uart_regs->int_txd); s3c2410_intc_sub_deassert( x49gp, uart_regs->int_txd );
uart_regs->utrstat |= (1 << 2) | (1 << 1); uart_regs->utrstat |= ( 1 << 2 ) | ( 1 << 1 );
if (uart_regs->ucon & (1 << 9)) if ( uart_regs->ucon & ( 1 << 9 ) )
s3c2410_intc_sub_assert(x49gp, uart_regs->int_txd, 1); s3c2410_intc_sub_assert( x49gp, uart_regs->int_txd, 1 );
else else
s3c2410_intc_sub_assert(x49gp, uart_regs->int_txd, 0); s3c2410_intc_sub_assert( x49gp, uart_regs->int_txd, 0 );
if (uart_regs->ucon & (1 << 5)) { if ( uart_regs->ucon & ( 1 << 5 ) ) {
uart_regs->urxh = data; uart_regs->urxh = data;
uart_regs->utrstat |= (1 << 0); uart_regs->utrstat |= ( 1 << 0 );
if (uart_regs->ucon & (1 << 8)) if ( uart_regs->ucon & ( 1 << 8 ) )
s3c2410_intc_sub_assert(x49gp, uart_regs->int_rxd, 1); s3c2410_intc_sub_assert( x49gp, uart_regs->int_rxd, 1 );
else else
s3c2410_intc_sub_assert(x49gp, uart_regs->int_rxd, 0); s3c2410_intc_sub_assert( x49gp, uart_regs->int_rxd, 0 );
} else if (base == 2) { } else if ( base == 2 ) {
uart_regs->urxh = data; uart_regs->urxh = data;
uart_regs->utrstat |= (1 << 0); uart_regs->utrstat |= ( 1 << 0 );
if (uart_regs->ucon & (1 << 8)) if ( uart_regs->ucon & ( 1 << 8 ) )
s3c2410_intc_sub_assert(x49gp, uart_regs->int_rxd, 1); s3c2410_intc_sub_assert( x49gp, uart_regs->int_rxd, 1 );
else else
s3c2410_intc_sub_assert(x49gp, uart_regs->int_rxd, 0); s3c2410_intc_sub_assert( x49gp, uart_regs->int_rxd, 0 );
} }
break; break;
} }
} }
static int static int s3c2410_uart_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_uart_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_uart_reg_t *uart_regs = module->user_data; s3c2410_uart_reg_t* uart_regs = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < uart_regs->nr_regs; i++) { for ( i = 0; i < uart_regs->nr_regs; i++ ) {
reg = &uart_regs->regs[i]; reg = &uart_regs->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_uart_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_uart_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_uart_reg_t *uart_regs = module->user_data; s3c2410_uart_reg_t* uart_regs = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < uart_regs->nr_regs; i++) { for ( i = 0; i < uart_regs->nr_regs; i++ ) {
reg = &uart_regs->regs[i]; reg = &uart_regs->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_uart_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_uart_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_uart_reg_t *uart_regs = module->user_data; s3c2410_uart_reg_t* uart_regs = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < uart_regs->nr_regs; i++) { for ( i = 0; i < uart_regs->nr_regs; i++ ) {
reg = &uart_regs->regs[i]; reg = &uart_regs->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_uart_readfn[] = static CPUReadMemoryFunc* s3c2410_uart_readfn[] = { s3c2410_uart_read, s3c2410_uart_read, s3c2410_uart_read };
{
s3c2410_uart_read,
s3c2410_uart_read,
s3c2410_uart_read
};
static CPUWriteMemoryFunc *s3c2410_uart_writefn[] = static CPUWriteMemoryFunc* s3c2410_uart_writefn[] = { s3c2410_uart_write, s3c2410_uart_write, s3c2410_uart_write };
{
s3c2410_uart_write,
s3c2410_uart_write,
s3c2410_uart_write
};
static int static int s3c2410_uart_init( x49gp_module_t* module )
s3c2410_uart_init(x49gp_module_t *module)
{ {
s3c2410_uart_reg_t *uart_regs = module->user_data; s3c2410_uart_reg_t* uart_regs = module->user_data;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
iotype = cpu_register_io_memory(s3c2410_uart_readfn, iotype = cpu_register_io_memory( s3c2410_uart_readfn, s3c2410_uart_writefn, uart_regs );
s3c2410_uart_writefn, uart_regs);
#ifdef DEBUG_S3C2410_UART #ifdef DEBUG_S3C2410_UART
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_UART0_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_UART0_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_uart_exit( x49gp_module_t* module )
s3c2410_uart_exit(x49gp_module_t *module)
{ {
s3c2410_uart_reg_t *uart_regs; s3c2410_uart_reg_t* uart_regs;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
uart_regs = module->user_data; uart_regs = module->user_data;
if (uart_regs->regs) if ( uart_regs->regs )
free(uart_regs->regs); free( uart_regs->regs );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_uart_init( x49gp_t* x49gp )
x49gp_s3c2410_uart_init(x49gp_t *x49gp)
{ {
s3c2410_uart_t *uart; s3c2410_uart_t* uart;
x49gp_module_t *module; x49gp_module_t* module;
uart = malloc(sizeof(s3c2410_uart_t)); uart = malloc( sizeof( s3c2410_uart_t ) );
if (NULL == uart) { if ( NULL == uart ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memset(uart, 0, sizeof(s3c2410_uart_t)); memset( uart, 0, sizeof( s3c2410_uart_t ) );
if (s3c2410_uart_data_init(uart)) { if ( s3c2410_uart_data_init( uart ) ) {
free(uart); free( uart );
return -ENOMEM; return -ENOMEM;
} }
uart->uart[0].x49gp = x49gp; uart->uart[ 0 ].x49gp = x49gp;
uart->uart[1].x49gp = x49gp; uart->uart[ 1 ].x49gp = x49gp;
uart->uart[2].x49gp = x49gp; uart->uart[ 2 ].x49gp = x49gp;
if (x49gp_module_init(x49gp, "s3c2410-uart0", if ( x49gp_module_init( x49gp, "s3c2410-uart0", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
s3c2410_uart_init, s3c2410_uart_save, &uart->uart[ 0 ], &module ) ) {
s3c2410_uart_exit,
s3c2410_uart_reset,
s3c2410_uart_load,
s3c2410_uart_save,
&uart->uart[0], &module)) {
return -1; return -1;
} }
if (x49gp_module_register(module)) { if ( x49gp_module_register( module ) ) {
return -1; return -1;
} }
if (x49gp_module_init(x49gp, "s3c2410-uart1", if ( x49gp_module_init( x49gp, "s3c2410-uart1", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
s3c2410_uart_init, s3c2410_uart_save, &uart->uart[ 1 ], &module ) ) {
s3c2410_uart_exit,
s3c2410_uart_reset,
s3c2410_uart_load,
s3c2410_uart_save,
&uart->uart[1], &module)) {
return -1; return -1;
} }
if (x49gp_module_register(module)) { if ( x49gp_module_register( module ) ) {
return -1; return -1;
} }
if (x49gp_module_init(x49gp, "s3c2410-uart2", if ( x49gp_module_init( x49gp, "s3c2410-uart2", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
s3c2410_uart_init, s3c2410_uart_save, &uart->uart[ 2 ], &module ) ) {
s3c2410_uart_exit,
s3c2410_uart_reset,
s3c2410_uart_load,
s3c2410_uart_save,
&uart->uart[2], &module)) {
return -1; return -1;
} }
if (x49gp_module_register(module)) { if ( x49gp_module_register( module ) ) {
return -1; return -1;
} }

View file

@ -12,7 +12,6 @@
#include "x49gp.h" #include "x49gp.h"
#include "s3c2410.h" #include "s3c2410.h"
typedef struct { typedef struct {
uint32_t func_addr_reg; uint32_t func_addr_reg;
uint32_t pwr_reg; uint32_t pwr_reg;
@ -62,272 +61,239 @@ typedef struct {
uint32_t out_fifo_cnt2_reg; uint32_t out_fifo_cnt2_reg;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
} s3c2410_usbdev_t; } s3c2410_usbdev_t;
static int static int s3c2410_usbdev_data_init( s3c2410_usbdev_t* usbdev )
s3c2410_usbdev_data_init(s3c2410_usbdev_t *usbdev)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = { S3C2410_OFFSET( USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg ),
S3C2410_OFFSET(USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg), S3C2410_OFFSET( USBDEV, PWR_REG, 0x00, usbdev->pwr_reg ),
S3C2410_OFFSET(USBDEV, PWR_REG, 0x00, usbdev->pwr_reg), S3C2410_OFFSET( USBDEV, EP_INT_REG, 0x00, usbdev->ep_int_reg ),
S3C2410_OFFSET(USBDEV, EP_INT_REG, 0x00, usbdev->ep_int_reg), S3C2410_OFFSET( USBDEV, USB_INT_REG, 0x00, usbdev->usb_int_reg ),
S3C2410_OFFSET(USBDEV, USB_INT_REG, 0x00, usbdev->usb_int_reg), S3C2410_OFFSET( USBDEV, EP_INT_EN_REG, 0xff, usbdev->ep_int_en_reg ),
S3C2410_OFFSET(USBDEV, EP_INT_EN_REG, 0xff, usbdev->ep_int_en_reg), S3C2410_OFFSET( USBDEV, USB_INT_EN_REG, 0x04, usbdev->usb_int_en_reg ),
S3C2410_OFFSET(USBDEV, USB_INT_EN_REG, 0x04, usbdev->usb_int_en_reg), S3C2410_OFFSET( USBDEV, FRAME_NUM1_REG, 0x00, usbdev->frame_num1_reg ),
S3C2410_OFFSET(USBDEV, FRAME_NUM1_REG, 0x00, usbdev->frame_num1_reg), S3C2410_OFFSET( USBDEV, FRAME_NUM2_REG, 0x00, usbdev->frame_num2_reg ),
S3C2410_OFFSET(USBDEV, FRAME_NUM2_REG, 0x00, usbdev->frame_num2_reg), S3C2410_OFFSET( USBDEV, INDEX_REG, 0x00, usbdev->index_reg ),
S3C2410_OFFSET(USBDEV, INDEX_REG, 0x00, usbdev->index_reg), S3C2410_OFFSET( USBDEV, EP0_FIFO_REG, 0, usbdev->ep0_fifo_reg ),
S3C2410_OFFSET(USBDEV, EP0_FIFO_REG, 0, usbdev->ep0_fifo_reg), S3C2410_OFFSET( USBDEV, EP1_FIFO_REG, 0, usbdev->ep1_fifo_reg ),
S3C2410_OFFSET(USBDEV, EP1_FIFO_REG, 0, usbdev->ep1_fifo_reg), S3C2410_OFFSET( USBDEV, EP2_FIFO_REG, 0, usbdev->ep2_fifo_reg ),
S3C2410_OFFSET(USBDEV, EP2_FIFO_REG, 0, usbdev->ep2_fifo_reg), S3C2410_OFFSET( USBDEV, EP3_FIFO_REG, 0, usbdev->ep3_fifo_reg ),
S3C2410_OFFSET(USBDEV, EP3_FIFO_REG, 0, usbdev->ep3_fifo_reg), S3C2410_OFFSET( USBDEV, EP4_FIFO_REG, 0, usbdev->ep4_fifo_reg ),
S3C2410_OFFSET(USBDEV, EP4_FIFO_REG, 0, usbdev->ep4_fifo_reg), S3C2410_OFFSET( USBDEV, EP1_DMA_CON, 0x00, usbdev->ep1_dma_con ),
S3C2410_OFFSET(USBDEV, EP1_DMA_CON, 0x00, usbdev->ep1_dma_con), S3C2410_OFFSET( USBDEV, EP1_DMA_UNIT, 0x00, usbdev->ep1_dma_unit ),
S3C2410_OFFSET(USBDEV, EP1_DMA_UNIT, 0x00, usbdev->ep1_dma_unit), S3C2410_OFFSET( USBDEV, EP1_DMA_FIFO, 0x00, usbdev->ep1_dma_fifo ),
S3C2410_OFFSET(USBDEV, EP1_DMA_FIFO, 0x00, usbdev->ep1_dma_fifo), S3C2410_OFFSET( USBDEV, EP1_DMA_TTC_L, 0x00, usbdev->ep1_dma_ttc_l ),
S3C2410_OFFSET(USBDEV, EP1_DMA_TTC_L, 0x00, usbdev->ep1_dma_ttc_l), S3C2410_OFFSET( USBDEV, EP1_DMA_TTC_M, 0x00, usbdev->ep1_dma_ttc_m ),
S3C2410_OFFSET(USBDEV, EP1_DMA_TTC_M, 0x00, usbdev->ep1_dma_ttc_m), S3C2410_OFFSET( USBDEV, EP1_DMA_TTC_H, 0x00, usbdev->ep1_dma_ttc_h ),
S3C2410_OFFSET(USBDEV, EP1_DMA_TTC_H, 0x00, usbdev->ep1_dma_ttc_h), S3C2410_OFFSET( USBDEV, EP2_DMA_CON, 0x00, usbdev->ep2_dma_con ),
S3C2410_OFFSET(USBDEV, EP2_DMA_CON, 0x00, usbdev->ep2_dma_con), S3C2410_OFFSET( USBDEV, EP2_DMA_UNIT, 0x00, usbdev->ep2_dma_unit ),
S3C2410_OFFSET(USBDEV, EP2_DMA_UNIT, 0x00, usbdev->ep2_dma_unit), S3C2410_OFFSET( USBDEV, EP2_DMA_FIFO, 0x00, usbdev->ep2_dma_fifo ),
S3C2410_OFFSET(USBDEV, EP2_DMA_FIFO, 0x00, usbdev->ep2_dma_fifo), S3C2410_OFFSET( USBDEV, EP2_DMA_TTC_L, 0x00, usbdev->ep2_dma_ttc_l ),
S3C2410_OFFSET(USBDEV, EP2_DMA_TTC_L, 0x00, usbdev->ep2_dma_ttc_l), S3C2410_OFFSET( USBDEV, EP2_DMA_TTC_M, 0x00, usbdev->ep2_dma_ttc_m ),
S3C2410_OFFSET(USBDEV, EP2_DMA_TTC_M, 0x00, usbdev->ep2_dma_ttc_m), S3C2410_OFFSET( USBDEV, EP2_DMA_TTC_H, 0x00, usbdev->ep2_dma_ttc_h ),
S3C2410_OFFSET(USBDEV, EP2_DMA_TTC_H, 0x00, usbdev->ep2_dma_ttc_h), S3C2410_OFFSET( USBDEV, EP3_DMA_CON, 0x00, usbdev->ep3_dma_con ),
S3C2410_OFFSET(USBDEV, EP3_DMA_CON, 0x00, usbdev->ep3_dma_con), S3C2410_OFFSET( USBDEV, EP3_DMA_UNIT, 0x00, usbdev->ep3_dma_unit ),
S3C2410_OFFSET(USBDEV, EP3_DMA_UNIT, 0x00, usbdev->ep3_dma_unit), S3C2410_OFFSET( USBDEV, EP3_DMA_FIFO, 0x00, usbdev->ep3_dma_fifo ),
S3C2410_OFFSET(USBDEV, EP3_DMA_FIFO, 0x00, usbdev->ep3_dma_fifo), S3C2410_OFFSET( USBDEV, EP3_DMA_TTC_L, 0x00, usbdev->ep3_dma_ttc_l ),
S3C2410_OFFSET(USBDEV, EP3_DMA_TTC_L, 0x00, usbdev->ep3_dma_ttc_l), S3C2410_OFFSET( USBDEV, EP3_DMA_TTC_M, 0x00, usbdev->ep3_dma_ttc_m ),
S3C2410_OFFSET(USBDEV, EP3_DMA_TTC_M, 0x00, usbdev->ep3_dma_ttc_m), S3C2410_OFFSET( USBDEV, EP3_DMA_TTC_H, 0x00, usbdev->ep3_dma_ttc_h ),
S3C2410_OFFSET(USBDEV, EP3_DMA_TTC_H, 0x00, usbdev->ep3_dma_ttc_h), S3C2410_OFFSET( USBDEV, EP4_DMA_CON, 0x00, usbdev->ep4_dma_con ),
S3C2410_OFFSET(USBDEV, EP4_DMA_CON, 0x00, usbdev->ep4_dma_con), S3C2410_OFFSET( USBDEV, EP4_DMA_UNIT, 0x00, usbdev->ep4_dma_unit ),
S3C2410_OFFSET(USBDEV, EP4_DMA_UNIT, 0x00, usbdev->ep4_dma_unit), S3C2410_OFFSET( USBDEV, EP4_DMA_FIFO, 0x00, usbdev->ep4_dma_fifo ),
S3C2410_OFFSET(USBDEV, EP4_DMA_FIFO, 0x00, usbdev->ep4_dma_fifo), S3C2410_OFFSET( USBDEV, EP4_DMA_TTC_L, 0x00, usbdev->ep4_dma_ttc_l ),
S3C2410_OFFSET(USBDEV, EP4_DMA_TTC_L, 0x00, usbdev->ep4_dma_ttc_l), S3C2410_OFFSET( USBDEV, EP4_DMA_TTC_M, 0x00, usbdev->ep4_dma_ttc_m ),
S3C2410_OFFSET(USBDEV, EP4_DMA_TTC_M, 0x00, usbdev->ep4_dma_ttc_m), S3C2410_OFFSET( USBDEV, EP4_DMA_TTC_H, 0x00, usbdev->ep4_dma_ttc_h ),
S3C2410_OFFSET(USBDEV, EP4_DMA_TTC_H, 0x00, usbdev->ep4_dma_ttc_h), S3C2410_OFFSET( USBDEV, MAXP_REG_WRONG, 0x01, usbdev->__wrong_maxp_reg ),
S3C2410_OFFSET(USBDEV, MAXP_REG_WRONG, 0x01, usbdev->__wrong_maxp_reg), S3C2410_OFFSET( USBDEV, IN_CSR1_REG_EP0_CSR, 0x00, usbdev->in_csr1_reg_ep0_csr ),
S3C2410_OFFSET(USBDEV, IN_CSR1_REG_EP0_CSR, 0x00, usbdev->in_csr1_reg_ep0_csr), S3C2410_OFFSET( USBDEV, IN_CSR2_REG, 0x20, usbdev->in_csr2_reg ),
S3C2410_OFFSET(USBDEV, IN_CSR2_REG, 0x20, usbdev->in_csr2_reg), S3C2410_OFFSET( USBDEV, MAXP_REG, 0x01, usbdev->maxp_reg ),
S3C2410_OFFSET(USBDEV, MAXP_REG, 0x01, usbdev->maxp_reg), S3C2410_OFFSET( USBDEV, OUT_CSR1_REG, 0x00, usbdev->out_csr1_reg ),
S3C2410_OFFSET(USBDEV, OUT_CSR1_REG, 0x00, usbdev->out_csr1_reg), S3C2410_OFFSET( USBDEV, OUT_CSR2_REG, 0x00, usbdev->out_csr2_reg ),
S3C2410_OFFSET(USBDEV, OUT_CSR2_REG, 0x00, usbdev->out_csr2_reg), S3C2410_OFFSET( USBDEV, OUT_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_reg ),
S3C2410_OFFSET(USBDEV, OUT_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_reg), S3C2410_OFFSET( USBDEV, OUT_FIFO_CNT2_REG, 0x00, usbdev->out_fifo_cnt2_reg ) };
S3C2410_OFFSET(USBDEV, OUT_FIFO_CNT2_REG, 0x00, usbdev->out_fifo_cnt2_reg)
};
memset(usbdev, 0, sizeof(s3c2410_usbdev_t)); memset( usbdev, 0, sizeof( s3c2410_usbdev_t ) );
usbdev->regs = malloc(sizeof(regs)); usbdev->regs = malloc( sizeof( regs ) );
if (NULL == usbdev->regs) { if ( NULL == usbdev->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(usbdev->regs, regs, sizeof(regs)); memcpy( usbdev->regs, regs, sizeof( regs ) );
usbdev->nr_regs = sizeof(regs) / sizeof(regs[0]); usbdev->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_usbdev_read( void* opaque, target_phys_addr_t offset )
s3c2410_usbdev_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_usbdev_t *usbdev = opaque; s3c2410_usbdev_t* usbdev = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(usbdev, offset)) { if ( !S3C2410_OFFSET_OK( usbdev, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(usbdev, offset); reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
#ifdef DEBUG_S3C2410_USBDEV #ifdef DEBUG_S3C2410_USBDEV
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset,
"s3c2410-usbdev", S3C2410_USBDEV_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_usbdev_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_usbdev_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_usbdev_t *usbdev = opaque; s3c2410_usbdev_t* usbdev = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(usbdev, offset)) { if ( !S3C2410_OFFSET_OK( usbdev, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(usbdev, offset); reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
#ifdef DEBUG_S3C2410_USBDEV #ifdef DEBUG_S3C2410_USBDEV
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-usbdev", S3C2410_USBDEV_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
} }
static int static int s3c2410_usbdev_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_usbdev_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_usbdev_t *usbdev = module->user_data; s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < usbdev->nr_regs; i++) { for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[i]; reg = &usbdev->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
return error; return error;
} }
static int static int s3c2410_usbdev_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_usbdev_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_usbdev_t *usbdev = module->user_data; s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < usbdev->nr_regs; i++) { for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[i]; reg = &usbdev->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_usbdev_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_usbdev_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_usbdev_t *usbdev = module->user_data; s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < usbdev->nr_regs; i++) { for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[i]; reg = &usbdev->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_usbdev_readfn[] = static CPUReadMemoryFunc* s3c2410_usbdev_readfn[] = { s3c2410_usbdev_read, s3c2410_usbdev_read, s3c2410_usbdev_read };
{
s3c2410_usbdev_read,
s3c2410_usbdev_read,
s3c2410_usbdev_read
};
static CPUWriteMemoryFunc *s3c2410_usbdev_writefn[] = static CPUWriteMemoryFunc* s3c2410_usbdev_writefn[] = { s3c2410_usbdev_write, s3c2410_usbdev_write, s3c2410_usbdev_write };
{
s3c2410_usbdev_write,
s3c2410_usbdev_write,
s3c2410_usbdev_write
};
static int static int s3c2410_usbdev_init( x49gp_module_t* module )
s3c2410_usbdev_init(x49gp_module_t *module)
{ {
s3c2410_usbdev_t *usbdev; s3c2410_usbdev_t* usbdev;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
usbdev = malloc(sizeof(s3c2410_usbdev_t)); usbdev = malloc( sizeof( s3c2410_usbdev_t ) );
if (NULL == usbdev) { if ( NULL == usbdev ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_usbdev_data_init(usbdev)) { if ( s3c2410_usbdev_data_init( usbdev ) ) {
free(usbdev); free( usbdev );
return -ENOMEM; return -ENOMEM;
} }
module->user_data = usbdev; module->user_data = usbdev;
iotype = cpu_register_io_memory(s3c2410_usbdev_readfn, iotype = cpu_register_io_memory( s3c2410_usbdev_readfn, s3c2410_usbdev_writefn, usbdev );
s3c2410_usbdev_writefn, usbdev);
#ifdef DEBUG_S3C2410_USBDEV #ifdef DEBUG_S3C2410_USBDEV
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_USBDEV_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_USBDEV_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_usbdev_exit( x49gp_module_t* module )
s3c2410_usbdev_exit(x49gp_module_t *module)
{ {
s3c2410_usbdev_t *usbdev; s3c2410_usbdev_t* usbdev;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
usbdev = module->user_data; usbdev = module->user_data;
if (usbdev->regs) if ( usbdev->regs )
free(usbdev->regs); free( usbdev->regs );
free(usbdev); free( usbdev );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_usbdev_init( x49gp_t* x49gp )
x49gp_s3c2410_usbdev_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-usbdev", if ( x49gp_module_init( x49gp, "s3c2410-usbdev", s3c2410_usbdev_init, s3c2410_usbdev_exit, s3c2410_usbdev_reset, s3c2410_usbdev_load,
s3c2410_usbdev_init, s3c2410_usbdev_save, NULL, &module ) ) {
s3c2410_usbdev_exit,
s3c2410_usbdev_reset,
s3c2410_usbdev_load,
s3c2410_usbdev_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -13,311 +13,281 @@
#include "s3c2410.h" #include "s3c2410.h"
#include "s3c2410_intc.h" #include "s3c2410_intc.h"
typedef struct { typedef struct {
uint32_t wtcon; uint32_t wtcon;
uint32_t wtdat; uint32_t wtdat;
uint32_t wtcnt; uint32_t wtcnt;
unsigned int nr_regs; unsigned int nr_regs;
s3c2410_offset_t *regs; s3c2410_offset_t* regs;
x49gp_t *x49gp; x49gp_t* x49gp;
unsigned long interval; unsigned long interval;
x49gp_timer_t *timer; x49gp_timer_t* timer;
} s3c2410_watchdog_t; } s3c2410_watchdog_t;
static int static int s3c2410_watchdog_data_init( s3c2410_watchdog_t* watchdog )
s3c2410_watchdog_data_init(s3c2410_watchdog_t *watchdog)
{ {
s3c2410_offset_t regs[] = { s3c2410_offset_t regs[] = { S3C2410_OFFSET( WATCHDOG, WTCON, 0x8021, watchdog->wtcon ),
S3C2410_OFFSET(WATCHDOG, WTCON, 0x8021, watchdog->wtcon), S3C2410_OFFSET( WATCHDOG, WTDAT, 0x8000, watchdog->wtdat ),
S3C2410_OFFSET(WATCHDOG, WTDAT, 0x8000, watchdog->wtdat), S3C2410_OFFSET( WATCHDOG, WTCNT, 0x8000, watchdog->wtcnt ) };
S3C2410_OFFSET(WATCHDOG, WTCNT, 0x8000, watchdog->wtcnt)
};
memset(watchdog, 0, sizeof(s3c2410_watchdog_t)); memset( watchdog, 0, sizeof( s3c2410_watchdog_t ) );
watchdog->regs = malloc(sizeof(regs)); watchdog->regs = malloc( sizeof( regs ) );
if (NULL == watchdog->regs) { if ( NULL == watchdog->regs ) {
fprintf(stderr, "%s:%u: Out of memory\n", fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
__FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
memcpy(watchdog->regs, regs, sizeof(regs)); memcpy( watchdog->regs, regs, sizeof( regs ) );
watchdog->nr_regs = sizeof(regs) / sizeof(regs[0]); watchdog->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0; return 0;
} }
static void static void s3c2410_watchdog_tick( void* data )
s3c2410_watchdog_tick(void *data)
{ {
s3c2410_watchdog_t *watchdog = data; s3c2410_watchdog_t* watchdog = data;
x49gp_t *x49gp = watchdog->x49gp; x49gp_t* x49gp = watchdog->x49gp;
if (watchdog->wtcnt > 0) { if ( watchdog->wtcnt > 0 ) {
watchdog->wtcnt--; watchdog->wtcnt--;
} else { } else {
watchdog->wtcnt = watchdog->wtdat; watchdog->wtcnt = watchdog->wtdat;
} }
if (watchdog->wtcnt > 0) { if ( watchdog->wtcnt > 0 ) {
// watchdog->timer.expires += watchdog->interval; // watchdog->timer.expires += watchdog->interval;
x49gp_mod_timer(watchdog->timer, x49gp_get_clock() + watchdog->interval); x49gp_mod_timer( watchdog->timer, x49gp_get_clock() + watchdog->interval );
return; return;
} }
if (watchdog->wtcon & 0x0004) { if ( watchdog->wtcon & 0x0004 ) {
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("WATCHDOG: assert WDT interrupt\n"); printf( "WATCHDOG: assert WDT interrupt\n" );
#endif #endif
// g_mutex_lock(x49gp->memlock); // g_mutex_lock(x49gp->memlock);
s3c2410_intc_assert(x49gp, INT_WDT, 0); s3c2410_intc_assert( x49gp, INT_WDT, 0 );
// g_mutex_unlock(x49gp->memlock); // g_mutex_unlock(x49gp->memlock);
} }
if (watchdog->wtcon & 0x0001) { if ( watchdog->wtcon & 0x0001 ) {
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("WATCHDOG: assert internal RESET\n"); printf( "WATCHDOG: assert internal RESET\n" );
#endif #endif
x49gp_modules_reset(x49gp, X49GP_RESET_WATCHDOG); x49gp_modules_reset( x49gp, X49GP_RESET_WATCHDOG );
cpu_reset(x49gp->env); cpu_reset( x49gp->env );
// if (x49gp->arm->NresetSig != LOW) { // if (x49gp->arm->NresetSig != LOW) {
// x49gp->arm->NresetSig = LOW; // x49gp->arm->NresetSig = LOW;
// x49gp->arm->Exception++; // x49gp->arm->Exception++;
// } // }
return; return;
} }
// watchdog->timer.expires += watchdog->interval; // watchdog->timer.expires += watchdog->interval;
x49gp_mod_timer(watchdog->timer, x49gp_get_clock() + watchdog->interval); x49gp_mod_timer( watchdog->timer, x49gp_get_clock() + watchdog->interval );
} }
unsigned long unsigned long s3c2410_watchdog_next_interrupt( x49gp_t* x49gp )
s3c2410_watchdog_next_interrupt(x49gp_t *x49gp)
{ {
s3c2410_watchdog_t *watchdog = x49gp->s3c2410_watchdog; s3c2410_watchdog_t* watchdog = x49gp->s3c2410_watchdog;
unsigned long irq; unsigned long irq;
unsigned long ticks; unsigned long ticks;
ticks = x49gp_get_clock(); ticks = x49gp_get_clock();
if (!(watchdog->wtcon & 0x0020)) { if ( !( watchdog->wtcon & 0x0020 ) ) {
return ~(0); return ~( 0 );
} }
if (x49gp_timer_pending(watchdog->timer)) { if ( x49gp_timer_pending( watchdog->timer ) ) {
irq = x49gp_timer_expires(watchdog->timer) - ticks; irq = x49gp_timer_expires( watchdog->timer ) - ticks;
} else { } else {
irq = 0; irq = 0;
} }
if (watchdog->wtcnt) { if ( watchdog->wtcnt ) {
irq += (watchdog->wtcnt - 1) * watchdog->interval; irq += ( watchdog->wtcnt - 1 ) * watchdog->interval;
} else { } else {
irq += watchdog->wtdat * watchdog->interval; irq += watchdog->wtdat * watchdog->interval;
} }
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("WATCHDOG: wtcnt %u, interval %lu, expires %llu, next irq %lu\n", printf( "WATCHDOG: wtcnt %u, interval %lu, expires %llu, next irq %lu\n", watchdog->wtcnt, watchdog->interval,
watchdog->wtcnt, watchdog->interval, (unsigned long long) (x49gp_timer_pending(watchdog->timer) ? x49gp_timer_expires(watchdog->timer) : 0), irq); ( unsigned long long )( x49gp_timer_pending( watchdog->timer ) ? x49gp_timer_expires( watchdog->timer ) : 0 ), irq );
#endif #endif
return irq; return irq;
} }
static int static int s3c2410_watchdog_update( s3c2410_watchdog_t* watchdog )
s3c2410_watchdog_update(s3c2410_watchdog_t *watchdog)
{ {
uint32_t pre, mux; uint32_t pre, mux;
if (!(watchdog->wtcon & 0x0020)) { if ( !( watchdog->wtcon & 0x0020 ) ) {
x49gp_del_timer(watchdog->timer); x49gp_del_timer( watchdog->timer );
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("WATCHDOG: stop timer\n"); printf( "WATCHDOG: stop timer\n" );
#endif #endif
return 0; return 0;
} }
pre = (watchdog->wtcon >> 8) & 0xff; pre = ( watchdog->wtcon >> 8 ) & 0xff;
mux = (watchdog->wtcon >> 3) & 3; mux = ( watchdog->wtcon >> 3 ) & 3;
watchdog->interval = (pre + 1) * (16 << mux); watchdog->interval = ( pre + 1 ) * ( 16 << mux );
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("WATCHDOG: start tick (%lu PCLKs)\n", watchdog->interval); printf( "WATCHDOG: start tick (%lu PCLKs)\n", watchdog->interval );
#endif #endif
x49gp_mod_timer(watchdog->timer, x49gp_get_clock() + watchdog->interval); x49gp_mod_timer( watchdog->timer, x49gp_get_clock() + watchdog->interval );
return 0; return 0;
} }
static uint32_t static uint32_t s3c2410_watchdog_read( void* opaque, target_phys_addr_t offset )
s3c2410_watchdog_read(void *opaque, target_phys_addr_t offset)
{ {
s3c2410_watchdog_t *watchdog = opaque; s3c2410_watchdog_t* watchdog = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(watchdog, offset)) { if ( !S3C2410_OFFSET_OK( watchdog, offset ) ) {
return ~(0); return ~( 0 );
} }
reg = S3C2410_OFFSET_ENTRY(watchdog, offset); reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("read %s [%08x] %s [%08lx] data %08x\n", printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-watchdog", S3C2410_WATCHDOG_BASE, reg->name, ( unsigned long )offset,
"s3c2410-watchdog", S3C2410_WATCHDOG_BASE, *( reg->datap ) );
reg->name, (unsigned long) offset, *(reg->datap));
#endif #endif
return *(reg->datap); return *( reg->datap );
} }
static void static void s3c2410_watchdog_write( void* opaque, target_phys_addr_t offset, uint32_t data )
s3c2410_watchdog_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{ {
s3c2410_watchdog_t *watchdog = opaque; s3c2410_watchdog_t* watchdog = opaque;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(watchdog, offset)) { if ( !S3C2410_OFFSET_OK( watchdog, offset ) ) {
return; return;
} }
reg = S3C2410_OFFSET_ENTRY(watchdog, offset); reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("write %s [%08x] %s [%08lx] data %08x\n", printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-watchdog", S3C2410_WATCHDOG_BASE, reg->name, ( unsigned long )offset, data );
"s3c2410-watchdog", S3C2410_WATCHDOG_BASE,
reg->name, (unsigned long) offset, data);
#endif #endif
*(reg->datap) = data; *( reg->datap ) = data;
switch (offset) { switch ( offset ) {
case S3C2410_WATCHDOG_WTCON: case S3C2410_WATCHDOG_WTCON:
case S3C2410_WATCHDOG_WTCNT: case S3C2410_WATCHDOG_WTCNT:
s3c2410_watchdog_update(watchdog); s3c2410_watchdog_update( watchdog );
break; break;
default: default:
break; break;
} }
} }
static int static int s3c2410_watchdog_load( x49gp_module_t* module, GKeyFile* key )
s3c2410_watchdog_load(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_watchdog_t *watchdog = module->user_data; s3c2410_watchdog_t* watchdog = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int error = 0; int error = 0;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < watchdog->nr_regs; i++) { for ( i = 0; i < watchdog->nr_regs; i++ ) {
reg = &watchdog->regs[i]; reg = &watchdog->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
if (x49gp_module_get_u32(module, key, reg->name, if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
reg->reset, reg->datap))
error = -EAGAIN; error = -EAGAIN;
} }
s3c2410_watchdog_update(watchdog); s3c2410_watchdog_update( watchdog );
return error; return error;
} }
static int static int s3c2410_watchdog_save( x49gp_module_t* module, GKeyFile* key )
s3c2410_watchdog_save(x49gp_module_t *module, GKeyFile *key)
{ {
s3c2410_watchdog_t *watchdog = module->user_data; s3c2410_watchdog_t* watchdog = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < watchdog->nr_regs; i++) { for ( i = 0; i < watchdog->nr_regs; i++ ) {
reg = &watchdog->regs[i]; reg = &watchdog->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap)); x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
} }
return 0; return 0;
} }
static int static int s3c2410_watchdog_reset( x49gp_module_t* module, x49gp_reset_t reset )
s3c2410_watchdog_reset(x49gp_module_t *module, x49gp_reset_t reset)
{ {
s3c2410_watchdog_t *watchdog = module->user_data; s3c2410_watchdog_t* watchdog = module->user_data;
s3c2410_offset_t *reg; s3c2410_offset_t* reg;
int i; int i;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
for (i = 0; i < watchdog->nr_regs; i++) { for ( i = 0; i < watchdog->nr_regs; i++ ) {
reg = &watchdog->regs[i]; reg = &watchdog->regs[ i ];
if (NULL == reg->name) if ( NULL == reg->name )
continue; continue;
*(reg->datap) = reg->reset; *( reg->datap ) = reg->reset;
} }
s3c2410_watchdog_update(watchdog); s3c2410_watchdog_update( watchdog );
return 0; return 0;
} }
static CPUReadMemoryFunc *s3c2410_watchdog_readfn[] = static CPUReadMemoryFunc* s3c2410_watchdog_readfn[] = { s3c2410_watchdog_read, s3c2410_watchdog_read, s3c2410_watchdog_read };
{
s3c2410_watchdog_read,
s3c2410_watchdog_read,
s3c2410_watchdog_read
};
static CPUWriteMemoryFunc *s3c2410_watchdog_writefn[] = static CPUWriteMemoryFunc* s3c2410_watchdog_writefn[] = { s3c2410_watchdog_write, s3c2410_watchdog_write, s3c2410_watchdog_write };
{
s3c2410_watchdog_write,
s3c2410_watchdog_write,
s3c2410_watchdog_write
};
static int static int s3c2410_watchdog_init( x49gp_module_t* module )
s3c2410_watchdog_init(x49gp_module_t *module)
{ {
s3c2410_watchdog_t *watchdog; s3c2410_watchdog_t* watchdog;
int iotype; int iotype;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
watchdog = malloc(sizeof(s3c2410_watchdog_t)); watchdog = malloc( sizeof( s3c2410_watchdog_t ) );
if (NULL == watchdog) { if ( NULL == watchdog ) {
fprintf(stderr, "%s: %s:%u: Out of memory\n", fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
module->x49gp->progname, __FUNCTION__, __LINE__);
return -ENOMEM; return -ENOMEM;
} }
if (s3c2410_watchdog_data_init(watchdog)) { if ( s3c2410_watchdog_data_init( watchdog ) ) {
free(watchdog); free( watchdog );
return -ENOMEM; return -ENOMEM;
} }
@ -326,54 +296,45 @@ s3c2410_watchdog_init(x49gp_module_t *module)
watchdog->x49gp = module->x49gp; watchdog->x49gp = module->x49gp;
module->x49gp->s3c2410_watchdog = watchdog; module->x49gp->s3c2410_watchdog = watchdog;
watchdog->timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL, watchdog->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_watchdog_tick, watchdog );
s3c2410_watchdog_tick, watchdog);
iotype = cpu_register_io_memory(s3c2410_watchdog_readfn, iotype = cpu_register_io_memory( s3c2410_watchdog_readfn, s3c2410_watchdog_writefn, watchdog );
s3c2410_watchdog_writefn, watchdog);
#ifdef DEBUG_S3C2410_WATCHDOG #ifdef DEBUG_S3C2410_WATCHDOG
printf("%s: iotype %08x\n", __FUNCTION__, iotype); printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#endif #endif
cpu_register_physical_memory(S3C2410_WATCHDOG_BASE, S3C2410_MAP_SIZE, iotype); cpu_register_physical_memory( S3C2410_WATCHDOG_BASE, S3C2410_MAP_SIZE, iotype );
return 0; return 0;
} }
static int static int s3c2410_watchdog_exit( x49gp_module_t* module )
s3c2410_watchdog_exit(x49gp_module_t *module)
{ {
s3c2410_watchdog_t *watchdog; s3c2410_watchdog_t* watchdog;
#ifdef DEBUG_X49GP_MODULES #ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__); printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif #endif
if (module->user_data) { if ( module->user_data ) {
watchdog = module->user_data; watchdog = module->user_data;
if (watchdog->regs) if ( watchdog->regs )
free(watchdog->regs); free( watchdog->regs );
free(watchdog); free( watchdog );
} }
x49gp_module_unregister(module); x49gp_module_unregister( module );
free(module); free( module );
return 0; return 0;
} }
int int x49gp_s3c2410_watchdog_init( x49gp_t* x49gp )
x49gp_s3c2410_watchdog_init(x49gp_t *x49gp)
{ {
x49gp_module_t *module; x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-watchdog", if ( x49gp_module_init( x49gp, "s3c2410-watchdog", s3c2410_watchdog_init, s3c2410_watchdog_exit, s3c2410_watchdog_reset,
s3c2410_watchdog_init, s3c2410_watchdog_load, s3c2410_watchdog_save, NULL, &module ) ) {
s3c2410_watchdog_exit,
s3c2410_watchdog_reset,
s3c2410_watchdog_load,
s3c2410_watchdog_save,
NULL, &module)) {
return -1; return -1;
} }
return x49gp_module_register(module); return x49gp_module_register( module );
} }

View file

@ -9,9 +9,9 @@
typedef uint64_t saturn_reg_t; typedef uint64_t saturn_reg_t;
typedef struct { typedef struct {
uint32_t read_map[256 + 1]; uint32_t read_map[ 256 + 1 ];
uint32_t write_map[256 + 1]; uint32_t write_map[ 256 + 1 ];
uint8_t top_map[256 + 1 + 3]; uint8_t top_map[ 256 + 1 + 3 ];
saturn_reg_t A; saturn_reg_t A;
saturn_reg_t B; saturn_reg_t B;
saturn_reg_t C; saturn_reg_t C;
@ -28,11 +28,11 @@ typedef struct {
uint32_t HST; uint32_t HST;
uint32_t carry; uint32_t carry;
int dec; int dec;
uint32_t RSTK[NB_RSTK]; uint32_t RSTK[ NB_RSTK ];
uint32_t RSTK_i; uint32_t RSTK_i;
uint32_t REG_FIELD[32]; uint32_t REG_FIELD[ 32 ];
uint32_t FIELD_START[32]; uint32_t FIELD_START[ 32 ];
uint32_t FIELD_LENGTH[32]; uint32_t FIELD_LENGTH[ 32 ];
} saturn_cpu_t; } saturn_cpu_t;
#define SAT_RPLTOP 0x8076b #define SAT_RPLTOP 0x8076b

File diff suppressed because it is too large Load diff

View file

@ -9,144 +9,71 @@
#include "symbol.h" #include "symbol.h"
static const cairo_path_data_t symbol_square_path_data[] = static const cairo_path_data_t symbol_square_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.100 ), SYMBOL_LINE_TO( 0.500, 0.000 ),
{ SYMBOL_LINE_TO( 0.000, 0.500 ), SYMBOL_LINE_TO( -0.500, 0.000 ),
SYMBOL_MOVE_TO( 0.100, 0.100 ), SYMBOL_CLOSE_PATH() };
SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.500 ),
SYMBOL_LINE_TO( -0.500, 0.000 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(square, 0.7, 0.0, 0.1, 0.1, 0.6, 0.6); SYMBOL( square, 0.7, 0.0, 0.1, 0.1, 0.6, 0.6 );
static const cairo_path_data_t symbol_triangleup_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.000 ), SYMBOL_LINE_TO( 0.800, 0.000 ),
SYMBOL_LINE_TO( -0.400, 0.693 ), SYMBOL_CLOSE_PATH() };
static const cairo_path_data_t symbol_triangleup_path_data[] = SYMBOL( triangleup, 1.0, 0.0, 0.1, 0.0, 0.9, 0.693 );
{
SYMBOL_MOVE_TO( 0.100, 0.000 ),
SYMBOL_LINE_TO( 0.800, 0.000 ),
SYMBOL_LINE_TO( -0.400, 0.693 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(triangleup, 1.0, 0.0, 0.1, 0.0, 0.9, 0.693); static const cairo_path_data_t symbol_triangleright_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.000 ), SYMBOL_LINE_TO( 0.000, 0.800 ),
SYMBOL_LINE_TO( 0.693, -0.400 ), SYMBOL_CLOSE_PATH() };
SYMBOL( triangleright, 0.893, 0.0, 0.1, 0.0, 0.793, 0.8 );
static const cairo_path_data_t symbol_triangleright_path_data[] = static const cairo_path_data_t symbol_arrowleftdblfull_path_data[] = {
{ SYMBOL_MOVE_TO( 0.100, 0.370 ), SYMBOL_LINE_TO( 0.652, 0.500 ), SYMBOL_LINE_TO( 0.000, -0.250 ), SYMBOL_LINE_TO( 1.000, 0.000 ),
SYMBOL_MOVE_TO( 0.100, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.500 ), SYMBOL_LINE_TO( -1.000, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.250 ), SYMBOL_CLOSE_PATH() };
SYMBOL_LINE_TO( 0.000, 0.800 ),
SYMBOL_LINE_TO( 0.693, -0.400 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(triangleright, 0.893, 0.0, 0.1, 0.0, 0.793, 0.8); SYMBOL( arrowleftdblfull, 1.852, 0.0, 0.1, -0.13, 1.752, 0.87 );
static const cairo_path_data_t symbol_uparrowleft_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.500 ), SYMBOL_LINE_TO( 0.600, 0.200 ),
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.550 ), SYMBOL_LINE_TO( -0.100, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.450 ), SYMBOL_LINE_TO( -0.400, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_CLOSE_PATH() };
static const cairo_path_data_t symbol_arrowleftdblfull_path_data[] = SYMBOL( uparrowleft, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7 );
{
SYMBOL_MOVE_TO( 0.100, 0.370 ),
SYMBOL_LINE_TO( 0.652, 0.500 ),
SYMBOL_LINE_TO( 0.000, -0.250 ),
SYMBOL_LINE_TO( 1.000, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.500 ),
SYMBOL_LINE_TO( -1.000, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.250 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(arrowleftdblfull, 1.852, 0.0, 0.1, -0.13, 1.752, 0.87); static const cairo_path_data_t symbol_uparrowright_path_data[] = { SYMBOL_MOVE_TO( 1.200, 0.500 ), SYMBOL_LINE_TO( -0.600, 0.200 ),
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_LINE_TO( -0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.550 ), SYMBOL_LINE_TO( 0.100, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.450 ), SYMBOL_LINE_TO( 0.400, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_CLOSE_PATH() };
static const cairo_path_data_t symbol_uparrowleft_path_data[] = SYMBOL( uparrowright, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7 );
{
SYMBOL_MOVE_TO( 0.100, 0.500 ),
SYMBOL_LINE_TO( 0.600, 0.200 ),
SYMBOL_LINE_TO( 0.000, -0.150 ),
SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.550 ),
SYMBOL_LINE_TO( -0.100, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.450 ),
SYMBOL_LINE_TO( -0.400, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.150 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(uparrowleft, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7); static const cairo_path_data_t symbol_tick_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.400 ), SYMBOL_LINE_TO( 0.000, 0.450 ),
SYMBOL_LINE_TO( 0.150, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.450 ),
SYMBOL_CLOSE_PATH() };
SYMBOL( tick, 0.35, 0.0, 0.1, 0.4, 0.25, 0.85 );
static const cairo_path_data_t symbol_uparrowright_path_data[] = static const cairo_path_data_t symbol_radical_path_data[] = { SYMBOL_MOVE_TO( 0.000, 0.500 ), SYMBOL_LINE_TO( 0.214, 0.100 ),
{ SYMBOL_LINE_TO( 0.213, -0.456 ), SYMBOL_LINE_TO( 0.229, 0.856 ),
SYMBOL_MOVE_TO( 1.200, 0.500 ), SYMBOL_LINE_TO( 0.077, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.100 ),
SYMBOL_LINE_TO( -0.600, 0.200 ), SYMBOL_LINE_TO( -0.281, -1.050 ), SYMBOL_LINE_TO( -0.287, 0.616 ),
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_LINE_TO( -0.123, -0.057 ), SYMBOL_CLOSE_PATH() };
SYMBOL_LINE_TO( -0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.550 ),
SYMBOL_LINE_TO( 0.100, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.450 ),
SYMBOL_LINE_TO( 0.400, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.150 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(uparrowright, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7); SYMBOL( radical, 0.733, 0.0, 0.0, -0.15, 0.733, 1.0 );
static const cairo_path_data_t symbol_overscore_path_data[] = { SYMBOL_MOVE_TO( 0.000, 1.000 ), SYMBOL_LINE_TO( 0.900, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.100 ), SYMBOL_LINE_TO( -0.900, 0.000 ),
SYMBOL_CLOSE_PATH() };
static const cairo_path_data_t symbol_tick_path_data[] = SYMBOL( overscore, 0.8, 0.0, 0.0, 0.9, 0.9, 1.0 );
{
SYMBOL_MOVE_TO( 0.100, 0.400 ),
SYMBOL_LINE_TO( 0.000, 0.450 ),
SYMBOL_LINE_TO( 0.150, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.450 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(tick, 0.35, 0.0, 0.1, 0.4, 0.25, 0.85); static const cairo_path_data_t symbol_minus_path_data[] = { SYMBOL_MOVE_TO( 0.050, 0.312 ), SYMBOL_LINE_TO( 0.000, 0.118 ),
SYMBOL_LINE_TO( 0.500, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.118 ),
SYMBOL_CLOSE_PATH() };
SYMBOL( minus, 0.6, 0.0, 0.05, 0.312, 0.55, 0.430 );
static const cairo_path_data_t symbol_radical_path_data[] = static const cairo_path_data_t symbol_divide_path_data[] = { SYMBOL_MOVE_TO( 0.050, 0.312 ),
{
SYMBOL_MOVE_TO( 0.000, 0.500 ),
SYMBOL_LINE_TO( 0.214, 0.100 ),
SYMBOL_LINE_TO( 0.213, -0.456 ),
SYMBOL_LINE_TO( 0.229, 0.856 ),
SYMBOL_LINE_TO( 0.077, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.100 ),
SYMBOL_LINE_TO( -0.281, -1.050 ),
SYMBOL_LINE_TO( -0.287, 0.616 ),
SYMBOL_LINE_TO( -0.123, -0.057 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(radical, 0.733, 0.0, 0.0, -0.15, 0.733, 1.0);
static const cairo_path_data_t symbol_overscore_path_data[] =
{
SYMBOL_MOVE_TO( 0.000, 1.000 ),
SYMBOL_LINE_TO( 0.900, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.100 ),
SYMBOL_LINE_TO( -0.900, 0.000 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(overscore, 0.8, 0.0, 0.0, 0.9, 0.9, 1.0);
static const cairo_path_data_t symbol_minus_path_data[] =
{
SYMBOL_MOVE_TO( 0.050, 0.312 ),
SYMBOL_LINE_TO( 0.000, 0.118 ),
SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.118 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(minus, 0.6, 0.0, 0.05, 0.312, 0.55, 0.430);
static const cairo_path_data_t symbol_divide_path_data[] =
{
SYMBOL_MOVE_TO( 0.050, 0.312 ),
SYMBOL_LINE_TO( 0.000, 0.118 ), SYMBOL_LINE_TO( 0.000, 0.118 ),
SYMBOL_LINE_TO( 0.500, 0.000 ), SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.118 ), SYMBOL_LINE_TO( 0.000, -0.118 ),
@ -160,77 +87,66 @@ static const cairo_path_data_t symbol_divide_path_data[] =
SYMBOL_LINE_TO( 0.000, 0.135 ), SYMBOL_LINE_TO( 0.000, 0.135 ),
SYMBOL_LINE_TO( 0.135, 0.000 ), SYMBOL_LINE_TO( 0.135, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.135 ), SYMBOL_LINE_TO( 0.000, -0.135 ),
SYMBOL_CLOSE_PATH() SYMBOL_CLOSE_PATH() };
};
SYMBOL(divide, 0.6, 0.0, 0.05, 0.069, 0.55, 0.673); SYMBOL( divide, 0.6, 0.0, 0.05, 0.069, 0.55, 0.673 );
static const cairo_path_data_t symbol_divisionslash_path_data[] = { SYMBOL_MOVE_TO( 0.050, 0.000 ), SYMBOL_LINE_TO( 0.345, 0.739 ),
SYMBOL_LINE_TO( 0.130, 0.000 ), SYMBOL_LINE_TO( -0.345, -0.739 ),
SYMBOL_CLOSE_PATH() };
static const cairo_path_data_t symbol_divisionslash_path_data[] = SYMBOL( divisionslash, 0.575, 0.000, 0.050, 0.000, 0.525, 0.739 );
{
SYMBOL_MOVE_TO( 0.050, 0.000 ),
SYMBOL_LINE_TO( 0.345, 0.739 ),
SYMBOL_LINE_TO( 0.130, 0.000 ),
SYMBOL_LINE_TO( -0.345, -0.739 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(divisionslash, 0.575, 0.000, 0.050, 0.000, 0.525, 0.739); CONTROL( beginsuperscript, 0.0, 0.5, 1.0, 0.8 );
CONTROL( endsuperscript, 0.0, 0.5, 1.25, 1.0 );
CONTROL(beginsuperscript, 0.0, 0.5, 1.0, 0.8);
CONTROL(endsuperscript, 0.0, 0.5, 1.25, 1.0);
CONTROL(kern_m1, -0.1, 0.0, 1.0, 1.0);
CONTROL(kern_m2, -0.2, 0.0, 1.0, 1.0);
CONTROL(kern_m3, -0.3, 0.0, 1.0, 1.0);
CONTROL(kern_m4, -0.4, 0.0, 1.0, 1.0);
CONTROL(kern_m5, -0.5, 0.0, 1.0, 1.0);
CONTROL(kern_m6, -0.6, 0.0, 1.0, 1.0);
CONTROL(kern_m7, -0.7, 0.0, 1.0, 1.0);
CONTROL(kern_m8, -0.8, 0.0, 1.0, 1.0);
CONTROL(kern_m9, -0.9, 0.0, 1.0, 1.0);
CONTROL( kern_m1, -0.1, 0.0, 1.0, 1.0 );
CONTROL( kern_m2, -0.2, 0.0, 1.0, 1.0 );
CONTROL( kern_m3, -0.3, 0.0, 1.0, 1.0 );
CONTROL( kern_m4, -0.4, 0.0, 1.0, 1.0 );
CONTROL( kern_m5, -0.5, 0.0, 1.0, 1.0 );
CONTROL( kern_m6, -0.6, 0.0, 1.0, 1.0 );
CONTROL( kern_m7, -0.7, 0.0, 1.0, 1.0 );
CONTROL( kern_m8, -0.8, 0.0, 1.0, 1.0 );
CONTROL( kern_m9, -0.9, 0.0, 1.0, 1.0 );
typedef struct { typedef struct {
const char *name; const char* name;
const x49gp_symbol_t *symbol; const x49gp_symbol_t* symbol;
} symbol_name_t; } symbol_name_t;
static const symbol_name_t symbol_names[] = static const symbol_name_t symbol_names[] = {
{ {".notdef", &symbol_square },
{ ".notdef", &symbol_square }, {"arrowleftdblfull", &symbol_arrowleftdblfull},
{ "arrowleftdblfull", &symbol_arrowleftdblfull }, {"divide", &symbol_divide },
{ "divide", &symbol_divide }, {"divisionslash", &symbol_divisionslash },
{ "divisionslash", &symbol_divisionslash }, {"minus", &symbol_minus },
{ "minus", &symbol_minus }, {"overscore", &symbol_overscore },
{ "overscore", &symbol_overscore }, {"radical", &symbol_radical },
{ "radical", &symbol_radical }, {"square", &symbol_square },
{ "square", &symbol_square }, {"tick", &symbol_tick },
{ "tick", &symbol_tick }, {"triangleright", &symbol_triangleright },
{ "triangleright", &symbol_triangleright }, {"triangleup", &symbol_triangleup },
{ "triangleup", &symbol_triangleup }, {"uparrowleft", &symbol_uparrowleft },
{ "uparrowleft", &symbol_uparrowleft }, {"uparrowright", &symbol_uparrowright },
{ "uparrowright", &symbol_uparrowright }, {"super", &symbol_beginsuperscript},
{ "super", &symbol_beginsuperscript }, {"/super", &symbol_endsuperscript },
{ "/super", &symbol_endsuperscript }, {"kern-1", &symbol_kern_m1 },
{ "kern-1", &symbol_kern_m1 }, {"kern-2", &symbol_kern_m2 },
{ "kern-2", &symbol_kern_m2 }, {"kern-3", &symbol_kern_m3 },
{ "kern-3", &symbol_kern_m3 }, {"kern-4", &symbol_kern_m4 },
{ "kern-4", &symbol_kern_m4 }, {"kern-5", &symbol_kern_m5 },
{ "kern-5", &symbol_kern_m5 }, {"kern-6", &symbol_kern_m6 },
{ "kern-6", &symbol_kern_m6 }, {"kern-7", &symbol_kern_m7 },
{ "kern-7", &symbol_kern_m7 }, {"kern-8", &symbol_kern_m8 },
{ "kern-8", &symbol_kern_m8 }, {"kern-9", &symbol_kern_m9 },
{ "kern-9", &symbol_kern_m9 }, {NULL, NULL }
{ NULL, NULL }
}; };
#define NR_SYMBOLS (sizeof(symbol_names) / sizeof(symbol_names[0]) - 1) #define NR_SYMBOLS ( sizeof( symbol_names ) / sizeof( symbol_names[ 0 ] ) - 1 )
int int symbol_lookup_glyph_by_name( const char* name, int namelen, gunichar* glyph )
symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
{ {
const symbol_name_t *symname; const symbol_name_t* symname;
int i = 0; int i = 0;
/* /*
@ -238,10 +154,9 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
*/ */
symname = symbol_names; symname = symbol_names;
while (symname->name) { while ( symname->name ) {
if ((strlen(symname->name) == namelen) && if ( ( strlen( symname->name ) == namelen ) && !strncmp( symname->name, name, namelen ) ) {
!strncmp(symname->name, name, namelen)) { if ( glyph ) {
if (glyph) {
*glyph = 0xe000 + i; *glyph = 0xe000 + i;
} }
return 1; return 1;
@ -254,25 +169,23 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
return 0; return 0;
} }
const x49gp_symbol_t * const x49gp_symbol_t* symbol_get_by_glyph( gunichar glyph )
symbol_get_by_glyph(gunichar glyph)
{ {
int index = glyph - 0xe000; int index = glyph - 0xe000;
if ((index >= 0) && (index < NR_SYMBOLS)) { if ( ( index >= 0 ) && ( index < NR_SYMBOLS ) ) {
return symbol_names[index].symbol; return symbol_names[ index ].symbol;
} }
return NULL; return NULL;
} }
const x49gp_symbol_t * const x49gp_symbol_t* symbol_get_by_name( const char* name )
symbol_get_by_name(const char *name)
{ {
gunichar glyph; gunichar glyph;
if (symbol_lookup_glyph_by_name(name, strlen(name), &glyph)) { if ( symbol_lookup_glyph_by_name( name, strlen( name ), &glyph ) ) {
return symbol_get_by_glyph(glyph); return symbol_get_by_glyph( glyph );
} }
return NULL; return NULL;

View file

@ -7,7 +7,7 @@
#include <math.h> #include <math.h>
typedef struct { typedef struct {
const cairo_path_data_t *data; const cairo_path_data_t* data;
int num_data; int num_data;
} symbol_path_t; } symbol_path_t;
@ -20,49 +20,60 @@ typedef struct {
double ury; double ury;
double prescale; double prescale;
double postscale; double postscale;
const symbol_path_t *path; const symbol_path_t* path;
} x49gp_symbol_t; } x49gp_symbol_t;
#define SYMBOL_MOVE_TO(x, y) \ #define SYMBOL_MOVE_TO( x, y ) \
{ header: { CAIRO_PATH_MOVE_TO, 2 } }, \ { \
{ point: { x, y } } header : { CAIRO_PATH_MOVE_TO, 2 } \
}, \
{ \
point: \
{ \
x, y \
} \
}
#define SYMBOL_LINE_TO(x, y) \ #define SYMBOL_LINE_TO( x, y ) \
{ header: { CAIRO_PATH_LINE_TO, 2 } }, \ { \
{ point: { x, y } } header : { CAIRO_PATH_LINE_TO, 2 } \
}, \
{ \
point: \
{ \
x, y \
} \
}
#define SYMBOL_CURVE_TO(x1, y1, x2, y2, x3, y3) \ #define SYMBOL_CURVE_TO( x1, y1, x2, y2, x3, y3 ) \
{ header: { CAIRO_PATH_CURVE_TO, 4 } }, \ { \
{ point: { x1, y1 } }, \ header : { CAIRO_PATH_CURVE_TO, 4 } \
{ point: { x2, y2 } }, \ }, \
{ point: { x3, y3 } } { point : { x1, y1 } }, { point : { x2, y2 } }, \
{ \
point: \
{ \
x3, y3 \
} \
}
#define SYMBOL_CLOSE_PATH() \ #define SYMBOL_CLOSE_PATH() \
{ header: { CAIRO_PATH_CLOSE_PATH, 1 } } { \
header : { CAIRO_PATH_CLOSE_PATH, 1 } \
}
#define SYMBOL(name, x_advance, y_advance, llx, lly, urx, ury) \ #define SYMBOL( name, x_advance, y_advance, llx, lly, urx, ury ) \
static const symbol_path_t symbol_##name##_path = \ static const symbol_path_t symbol_##name##_path = { symbol_##name##_path_data, \
{ \ sizeof( symbol_##name##_path_data ) / sizeof( cairo_path_data_t ) }; \
symbol_##name##_path_data, \
sizeof(symbol_##name##_path_data) / sizeof(cairo_path_data_t) \
}; \
\ \
static const x49gp_symbol_t symbol_##name = \ static const x49gp_symbol_t symbol_##name = { x_advance, y_advance, llx, lly, urx, ury, 1.0, 1.0, &symbol_##name##_path }
{ \
x_advance, y_advance, llx, lly, urx, ury, 1.0, 1.0, \
&symbol_##name##_path \
}
#define CONTROL(name, x_advance, y_advance, prescale, postscale) \ #define CONTROL( name, x_advance, y_advance, prescale, postscale ) \
static const x49gp_symbol_t symbol_##name = \ static const x49gp_symbol_t symbol_##name = { x_advance, y_advance, 0.0, 0.0, 0.0, 0.0, prescale, postscale, NULL }
{ \
x_advance, y_advance, 0.0, 0.0, 0.0, 0.0, \
prescale, postscale, NULL \
}
int symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *); int symbol_lookup_glyph_by_name( const char* name, int namelen, gunichar* );
const x49gp_symbol_t *symbol_get_by_name(const char *name); const x49gp_symbol_t* symbol_get_by_name( const char* name );
const x49gp_symbol_t *symbol_get_by_glyph(gunichar glyph); const x49gp_symbol_t* symbol_get_by_glyph( gunichar glyph );
#endif /* !(_X49GP_SYMBOL_H) */ #endif /* !(_X49GP_SYMBOL_H) */

View file

@ -30,41 +30,39 @@ struct x49gp_timer_s {
long type; long type;
int64_t expires; int64_t expires;
x49gp_timer_cb_t cb; x49gp_timer_cb_t cb;
void *user_data; void* user_data;
x49gp_timer_t *next; x49gp_timer_t* next;
}; };
typedef x49gp_timer_cb_t QEMUTimerCB; typedef x49gp_timer_cb_t QEMUTimerCB;
typedef void * QEMUClock; typedef void* QEMUClock;
QEMUClock *rt_clock = (void *) X49GP_TIMER_REALTIME; QEMUClock* rt_clock = ( void* )X49GP_TIMER_REALTIME;
QEMUClock *vm_clock = (void *) X49GP_TIMER_VIRTUAL; QEMUClock* vm_clock = ( void* )X49GP_TIMER_VIRTUAL;
int64_t ticks_per_sec = 1000000; int64_t ticks_per_sec = 1000000;
static x49gp_timer_t *x49gp_timer_lists[2]; static x49gp_timer_t* x49gp_timer_lists[ 2 ];
int64_t int64_t x49gp_get_clock( void )
x49gp_get_clock(void)
{ {
struct timeval tv; struct timeval tv;
int64_t us; int64_t us;
gettimeofday(&tv, NULL); gettimeofday( &tv, NULL );
us = tv.tv_sec * 1000000LL + tv.tv_usec; us = tv.tv_sec * 1000000LL + tv.tv_usec;
return us; return us;
} }
x49gp_timer_t * x49gp_timer_t* x49gp_new_timer( long type, x49gp_timer_cb_t cb, void* user_data )
x49gp_new_timer(long type, x49gp_timer_cb_t cb, void *user_data)
{ {
x49gp_timer_t *ts; x49gp_timer_t* ts;
ts = malloc(sizeof(x49gp_timer_t)); ts = malloc( sizeof( x49gp_timer_t ) );
if (NULL == ts) { if ( NULL == ts ) {
return NULL; return NULL;
} }
memset(ts, 0, sizeof(x49gp_timer_t)); memset( ts, 0, sizeof( x49gp_timer_t ) );
ts->type = type; ts->type = type;
ts->cb = cb; ts->cb = cb;
@ -73,24 +71,19 @@ x49gp_new_timer(long type, x49gp_timer_cb_t cb, void *user_data)
return ts; return ts;
} }
void void x49gp_free_timer( x49gp_timer_t* ts ) { free( ts ); }
x49gp_free_timer(x49gp_timer_t *ts)
{
free(ts);
}
void void x49gp_del_timer( x49gp_timer_t* ts )
x49gp_del_timer(x49gp_timer_t *ts)
{ {
x49gp_timer_t **pt, *t; x49gp_timer_t **pt, *t;
// printf("%s: ts %p\n", __FUNCTION__, ts); // printf("%s: ts %p\n", __FUNCTION__, ts);
pt = &x49gp_timer_lists[ts->type]; pt = &x49gp_timer_lists[ ts->type ];
while (1) { while ( 1 ) {
t = *pt; t = *pt;
if (NULL == t) if ( NULL == t )
break; break;
if (t == ts) { if ( t == ts ) {
*pt = t->next; *pt = t->next;
ts->next = NULL; ts->next = NULL;
break; break;
@ -99,20 +92,19 @@ x49gp_del_timer(x49gp_timer_t *ts)
} }
} }
void void x49gp_mod_timer( x49gp_timer_t* ts, int64_t expires )
x49gp_mod_timer(x49gp_timer_t *ts, int64_t expires)
{ {
x49gp_timer_t **pt, *t; x49gp_timer_t **pt, *t;
x49gp_del_timer(ts); x49gp_del_timer( ts );
// printf("%s: ts %p, expires %lld\n", __FUNCTION__, ts, expires); // printf("%s: ts %p, expires %lld\n", __FUNCTION__, ts, expires);
pt = &x49gp_timer_lists[ts->type]; pt = &x49gp_timer_lists[ ts->type ];
while (1) { while ( 1 ) {
t = *pt; t = *pt;
if (NULL == t) if ( NULL == t )
break; break;
if (t->expires > expires) if ( t->expires > expires )
break; break;
pt = &t->next; pt = &t->next;
} }
@ -122,167 +114,131 @@ x49gp_mod_timer(x49gp_timer_t *ts, int64_t expires)
*pt = ts; *pt = ts;
} }
int int x49gp_timer_pending( x49gp_timer_t* ts )
x49gp_timer_pending(x49gp_timer_t *ts)
{ {
x49gp_timer_t *t; x49gp_timer_t* t;
for (t = x49gp_timer_lists[ts->type]; t; t = t->next) { for ( t = x49gp_timer_lists[ ts->type ]; t; t = t->next ) {
if (t == ts) if ( t == ts )
return 1; return 1;
} }
return 0; return 0;
} }
int64_t int64_t x49gp_timer_expires( x49gp_timer_t* ts ) { return ts->expires; }
x49gp_timer_expires(x49gp_timer_t *ts)
{
return ts->expires;
}
static int static int x49gp_timer_expired( x49gp_timer_t* timer_head, int64_t current_time )
x49gp_timer_expired(x49gp_timer_t *timer_head, int64_t current_time)
{ {
if (NULL == timer_head) if ( NULL == timer_head )
return 0; return 0;
return (timer_head->expires <= current_time); return ( timer_head->expires <= current_time );
} }
/* LD TEMPO HACK */ /* LD TEMPO HACK */
QEMUTimer * QEMUTimer* qemu_new_timer( QEMUClock* clock, QEMUTimerCB cb, void* opaque )
qemu_new_timer(QEMUClock *clock, QEMUTimerCB cb, void *opaque)
{ {
return (void *) x49gp_new_timer((long) clock, cb, opaque); return ( void* )x49gp_new_timer( ( long )clock, cb, opaque );
} }
void void qemu_free_timer( QEMUTimer* ts ) { return x49gp_free_timer( ( void* )ts ); }
qemu_free_timer(QEMUTimer *ts)
{
return x49gp_free_timer((void *) ts);
}
void void qemu_mod_timer( QEMUTimer* ts, int64_t expire_time ) { return x49gp_mod_timer( ( void* )ts, expire_time ); }
qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
{
return x49gp_mod_timer((void *) ts, expire_time);
}
void void qemu_del_timer( QEMUTimer* ts ) { return x49gp_del_timer( ( void* )ts ); }
qemu_del_timer(QEMUTimer *ts)
{
return x49gp_del_timer((void *) ts);
}
int int qemu_timer_pending( QEMUTimer* ts ) { return x49gp_timer_pending( ( void* )ts ); }
qemu_timer_pending(QEMUTimer *ts)
{
return x49gp_timer_pending((void *) ts);
}
int64_t int64_t qemu_get_clock( QEMUClock* clock ) { return x49gp_get_clock(); }
qemu_get_clock(QEMUClock *clock)
{
return x49gp_get_clock();
}
static void static void x49gp_run_timers( x49gp_timer_t** ptimer_head, int64_t current_time )
x49gp_run_timers(x49gp_timer_t **ptimer_head, int64_t current_time)
{ {
x49gp_timer_t *ts; x49gp_timer_t* ts;
// printf("%s: now %lld\n", __FUNCTION__, current_time); // printf("%s: now %lld\n", __FUNCTION__, current_time);
while (1) { while ( 1 ) {
ts = *ptimer_head; ts = *ptimer_head;
if (NULL == ts || ts->expires > current_time) if ( NULL == ts || ts->expires > current_time )
break; break;
*ptimer_head = ts->next; *ptimer_head = ts->next;
ts->next = NULL; ts->next = NULL;
// printf("%s: call ts %p\n", __FUNCTION__, ts); // printf("%s: call ts %p\n", __FUNCTION__, ts);
ts->cb(ts->user_data); ts->cb( ts->user_data );
// printf("%s: ts %p done\n", __FUNCTION__, ts); // printf("%s: ts %p done\n", __FUNCTION__, ts);
} }
// printf("%s: timers done\n", __FUNCTION__); // printf("%s: timers done\n", __FUNCTION__);
} }
static void static void x49gp_alarm_handler( int sig )
x49gp_alarm_handler(int sig)
{ {
if (x49gp_timer_expired(x49gp_timer_lists[X49GP_TIMER_VIRTUAL], if ( x49gp_timer_expired( x49gp_timer_lists[ X49GP_TIMER_VIRTUAL ], x49gp_get_clock() ) ||
x49gp_get_clock()) || x49gp_timer_expired( x49gp_timer_lists[ X49GP_TIMER_REALTIME ], x49gp_get_clock() ) ) {
x49gp_timer_expired(x49gp_timer_lists[X49GP_TIMER_REALTIME], if ( cpu_single_env && !cpu_single_env->exit_request ) {
x49gp_get_clock())) { cpu_exit( cpu_single_env );
if (cpu_single_env && ! cpu_single_env->exit_request) {
cpu_exit(cpu_single_env);
} }
} }
} }
static void static void x49gp_main_loop_wait( x49gp_t* x49gp, int timeout )
x49gp_main_loop_wait(x49gp_t *x49gp, int timeout)
{ {
// printf("%s: timeout: %d\n", __FUNCTION__, timeout); // printf("%s: timeout: %d\n", __FUNCTION__, timeout);
if (gdb_poll(x49gp->env)) { if ( gdb_poll( x49gp->env ) ) {
gdb_handlesig(x49gp->env, 0); gdb_handlesig( x49gp->env, 0 );
} else } else
poll(NULL, 0, timeout); poll( NULL, 0, timeout );
if (x49gp->arm_idle != X49GP_ARM_OFF) { if ( x49gp->arm_idle != X49GP_ARM_OFF ) {
x49gp_run_timers(&x49gp_timer_lists[X49GP_TIMER_VIRTUAL], x49gp_run_timers( &x49gp_timer_lists[ X49GP_TIMER_VIRTUAL ], x49gp_get_clock() );
x49gp_get_clock());
} }
x49gp_run_timers(&x49gp_timer_lists[X49GP_TIMER_REALTIME], x49gp_run_timers( &x49gp_timer_lists[ X49GP_TIMER_REALTIME ], x49gp_get_clock() );
x49gp_get_clock());
// printf("%s: done\n", __FUNCTION__); // printf("%s: done\n", __FUNCTION__);
} }
int int x49gp_main_loop( x49gp_t* x49gp )
x49gp_main_loop(x49gp_t *x49gp)
{ {
int prev_idle; int prev_idle;
int ret, timeout; int ret, timeout;
while (! x49gp->arm_exit) { while ( !x49gp->arm_exit ) {
prev_idle = x49gp->arm_idle; prev_idle = x49gp->arm_idle;
if (x49gp->arm_idle == X49GP_ARM_RUN) { if ( x49gp->arm_idle == X49GP_ARM_RUN ) {
#ifdef DEBUG_X49GP_TIMER_IDLE #ifdef DEBUG_X49GP_TIMER_IDLE
printf("%lld: %s: call cpu_exec(%p)\n", (unsigned long long) x49gp_get_clock(), __FUNCTION__, x49gp->env); printf( "%lld: %s: call cpu_exec(%p)\n", ( unsigned long long )x49gp_get_clock(), __FUNCTION__, x49gp->env );
#endif #endif
ret = cpu_exec(x49gp->env); ret = cpu_exec( x49gp->env );
#ifdef DEBUG_X49GP_TIMER_IDLE #ifdef DEBUG_X49GP_TIMER_IDLE
printf("%lld: %s: cpu_exec(): %d, PC %08x\n", (unsigned long long) x49gp_get_clock(), __FUNCTION__, ret, x49gp->env->regs[15]); printf( "%lld: %s: cpu_exec(): %d, PC %08x\n", ( unsigned long long )x49gp_get_clock(), __FUNCTION__, ret,
x49gp->env->regs[ 15 ] );
#endif #endif
if (x49gp->env->regs[15] == 0x8620) { if ( x49gp->env->regs[ 15 ] == 0x8620 ) {
printf("PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[15], 0x08000a0c, printf( "PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[ 15 ], 0x08000a0c,
* ((uint32_t *) &x49gp->sram[0x0a00]), *( ( uint32_t* )&x49gp->sram[ 0x0a00 ] ), *( ( uint32_t* )&x49gp->sram[ 0x0a04 ] ),
* ((uint32_t *) &x49gp->sram[0x0a04]), *( ( uint32_t* )&x49gp->sram[ 0x0a08 ] ), *( ( uint32_t* )&x49gp->sram[ 0x0a0c ] ) );
* ((uint32_t *) &x49gp->sram[0x0a08]), *( ( uint32_t* )&x49gp->sram[ 0x0a0c ] ) = 0x00000000;
* ((uint32_t *) &x49gp->sram[0x0a0c])); }
* ((uint32_t *) &x49gp->sram[0x0a0c]) = 0x00000000;
}
if (ret == EXCP_DEBUG) { if ( ret == EXCP_DEBUG ) {
gdb_handlesig(x49gp->env, SIGTRAP); gdb_handlesig( x49gp->env, SIGTRAP );
continue; continue;
} }
if (x49gp->arm_idle != prev_idle) { if ( x49gp->arm_idle != prev_idle ) {
if (x49gp->arm_idle == X49GP_ARM_OFF) { if ( x49gp->arm_idle == X49GP_ARM_OFF ) {
x49gp_lcd_update(x49gp); x49gp_lcd_update( x49gp );
cpu_reset(x49gp->env); cpu_reset( x49gp->env );
} }
} }
if (ret == EXCP_HALTED) { if ( ret == EXCP_HALTED ) {
timeout = 10; timeout = 10;
} else { } else {
timeout = 0; timeout = 0;
@ -291,31 +247,30 @@ printf("PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[15], 0x08
timeout = 1; timeout = 1;
} }
x49gp_main_loop_wait(x49gp, timeout); x49gp_main_loop_wait( x49gp, timeout );
} }
return 0; return 0;
} }
int int x49gp_timer_init( x49gp_t* x49gp )
x49gp_timer_init(x49gp_t *x49gp)
{ {
struct sigaction sa; struct sigaction sa;
struct itimerval it; struct itimerval it;
x49gp_timer_lists[X49GP_TIMER_VIRTUAL] = NULL; x49gp_timer_lists[ X49GP_TIMER_VIRTUAL ] = NULL;
x49gp_timer_lists[X49GP_TIMER_REALTIME] = NULL; x49gp_timer_lists[ X49GP_TIMER_REALTIME ] = NULL;
sigfillset(&sa.sa_mask); sigfillset( &sa.sa_mask );
sa.sa_flags = SA_RESTART; sa.sa_flags = SA_RESTART;
sa.sa_handler = x49gp_alarm_handler; sa.sa_handler = x49gp_alarm_handler;
sigaction(SIGALRM, &sa, NULL); sigaction( SIGALRM, &sa, NULL );
it.it_interval.tv_sec = 0; it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = 1000; it.it_interval.tv_usec = 1000;
it.it_value.tv_sec = 0; it.it_value.tv_sec = 0;
it.it_value.tv_usec = 1000; it.it_value.tv_usec = 1000;
setitimer(ITIMER_REAL, &it, NULL); setitimer( ITIMER_REAL, &it, NULL );
return 0; return 0;
} }

View file

@ -94,113 +94,110 @@
#include "bitmaps/tiny__i.xbm" #include "bitmaps/tiny__i.xbm"
const bitmap_font_t tiny_font = const bitmap_font_t tiny_font = {
{
7, 7,
-3, -3,
{ { GLYPH( tiny, notdef ),
GLYPH(tiny, notdef),
SPACE("space", 4, 0), SPACE( "space", 4, 0 ),
GLYPH(tiny, quotedbl), GLYPH( tiny, quotedbl ),
GLYPH(tiny, numbersign), GLYPH( tiny, numbersign ),
GLYPH(tiny, ampersand), GLYPH( tiny, ampersand ),
GLYPH(tiny, parenleft), GLYPH( tiny, parenleft ),
GLYPH(tiny, parenright), GLYPH( tiny, parenright ),
GLYPH(tiny, comma), GLYPH( tiny, comma ),
GLYPH(tiny, hyphen), GLYPH( tiny, hyphen ),
GLYPH(tiny, period), GLYPH( tiny, period ),
GLYPH(tiny, slash), GLYPH( tiny, slash ),
GLYPH(tiny, zero), GLYPH( tiny, zero ),
GLYPH(tiny, one), GLYPH( tiny, one ),
GLYPH(tiny, two), GLYPH( tiny, two ),
GLYPH(tiny, three), GLYPH( tiny, three ),
GLYPH(tiny, colon), GLYPH( tiny, colon ),
GLYPH(tiny, less), GLYPH( tiny, less ),
GLYPH(tiny, equal), GLYPH( tiny, equal ),
GLYPH(tiny, greater), GLYPH( tiny, greater ),
GLYPH(tiny, A), GLYPH( tiny, A ),
GLYPH(tiny, B), GLYPH( tiny, B ),
GLYPH(tiny, C), GLYPH( tiny, C ),
GLYPH(tiny, D), GLYPH( tiny, D ),
GLYPH(tiny, E), GLYPH( tiny, E ),
GLYPH(tiny, F), GLYPH( tiny, F ),
GLYPH(tiny, G), GLYPH( tiny, G ),
GLYPH(tiny, H), GLYPH( tiny, H ),
GLYPH(tiny, I), GLYPH( tiny, I ),
GLYPH(tiny, J), GLYPH( tiny, J ),
GLYPH(tiny, K), GLYPH( tiny, K ),
GLYPH(tiny, L), GLYPH( tiny, L ),
GLYPH(tiny, M), GLYPH( tiny, M ),
GLYPH(tiny, N), GLYPH( tiny, N ),
GLYPH(tiny, O), GLYPH( tiny, O ),
GLYPH(tiny, P), GLYPH( tiny, P ),
GLYPH(tiny, Q), GLYPH( tiny, Q ),
GLYPH(tiny, R), GLYPH( tiny, R ),
GLYPH(tiny, S), GLYPH( tiny, S ),
GLYPH(tiny, T), GLYPH( tiny, T ),
GLYPH(tiny, U), GLYPH( tiny, U ),
GLYPH(tiny, V), GLYPH( tiny, V ),
GLYPH(tiny, W), GLYPH( tiny, W ),
GLYPH(tiny, X), GLYPH( tiny, X ),
GLYPH(tiny, Y), GLYPH( tiny, Y ),
GLYPH(tiny, Z), GLYPH( tiny, Z ),
GLYPH(tiny, bracketleft), GLYPH( tiny, bracketleft ),
GLYPH(tiny, bracketright), GLYPH( tiny, bracketright ),
GLYPH(tiny, underscore), GLYPH( tiny, underscore ),
GLYPH(tiny, i), GLYPH( tiny, i ),
GLYPH(tiny, overscore), GLYPH( tiny, overscore ),
GLYPH(tiny, arrowleft), GLYPH( tiny, arrowleft ),
GLYPH(tiny, arrowright), GLYPH( tiny, arrowright ),
GLYPH(tiny, guillemotleft), GLYPH( tiny, guillemotleft ),
GLYPH(tiny, guillemotright), GLYPH( tiny, guillemotright ),
GLYPH(tiny, braceleft), GLYPH( tiny, braceleft ),
GLYPH(tiny, braceright), GLYPH( tiny, braceright ),
GLYPH(tiny, large_comma), GLYPH( tiny, large_comma ),
GLYPH(tiny, xsuperior), GLYPH( tiny, xsuperior ),
GLYPH(tiny, twosuperior), GLYPH( tiny, twosuperior ),
GLYPH(tiny, math_e), GLYPH( tiny, math_e ),
GLYPH(tiny, math_x), GLYPH( tiny, math_x ),
GLYPH(tiny, math_y), GLYPH( tiny, math_y ),
GLYPH(tiny, math_pi), GLYPH( tiny, math_pi ),
GLYPH(tiny, math_summation), GLYPH( tiny, math_summation ),
GLYPH(tiny, math_radical), GLYPH( tiny, math_radical ),
GLYPH(tiny, math_partialdiff), GLYPH( tiny, math_partialdiff ),
GLYPH(tiny, math_integral), GLYPH( tiny, math_integral ),
GLYPH(tiny, math_infinity), GLYPH( tiny, math_infinity ),
GLYPH(tiny, math_numbersign), GLYPH( tiny, math_numbersign ),
GLYPH(tiny, math_less), GLYPH( tiny, math_less ),
GLYPH(tiny, math_greater), GLYPH( tiny, math_greater ),
GLYPH(tiny, math_lessequal), GLYPH( tiny, math_lessequal ),
GLYPH(tiny, math_greaterequal), GLYPH( tiny, math_greaterequal ),
GLYPH(tiny, math_equal), GLYPH( tiny, math_equal ),
GLYPH(tiny, math_notequal), GLYPH( tiny, math_notequal ),
GLYPH(tiny, math_arrowleft), GLYPH( tiny, math_arrowleft ),
GLYPH(tiny, math_arrowright), GLYPH( tiny, math_arrowright ),
GLYPH(tiny, math_downarrowleft), GLYPH( tiny, math_downarrowleft ),
GLYPH(tiny, math_downarrowright), GLYPH( tiny, math_downarrowright ),
SPACE("kern-1", -1, -1), SPACE( "kern-1", -1, -1 ),
SPACE("kern-2", -2, -2), SPACE( "kern-2", -2, -2 ),
SPACE("kern-3", -3, -3), SPACE( "kern-3", -3, -3 ),
SPACE("kern-4", -4, -4), SPACE( "kern-4", -4, -4 ),
SPACE("kern-5", -5, -5), SPACE( "kern-5", -5, -5 ),
SPACE("kern-6", -6, -6), SPACE( "kern-6", -6, -6 ),
SPACE("kern-7", -7, -7), SPACE( "kern-7", -7, -7 ),
{ NULL } { NULL } }
}
}; };

View file

@ -20,62 +20,49 @@
#include "list.h" #include "list.h"
/* LD TEMPO HACK */ /* LD TEMPO HACK */
extern uint8_t *phys_ram_base; extern uint8_t* phys_ram_base;
extern int phys_ram_size; extern int phys_ram_size;
typedef enum { typedef enum { X49GP_ARM_RUN = 0, X49GP_ARM_SLEEP, X49GP_ARM_OFF } x49gp_arm_idle_t;
X49GP_ARM_RUN = 0,
X49GP_ARM_SLEEP,
X49GP_ARM_OFF
} x49gp_arm_idle_t;
typedef enum { typedef enum { X49GP_RESET_POWER_ON = 0, X49GP_RESET_POWER_OFF, X49GP_RESET_WATCHDOG } x49gp_reset_t;
X49GP_RESET_POWER_ON = 0,
X49GP_RESET_POWER_OFF,
X49GP_RESET_WATCHDOG
} x49gp_reset_t;
struct __x49gp_module_s__; struct __x49gp_module_s__;
typedef struct __x49gp_module_s__ x49gp_module_t; typedef struct __x49gp_module_s__ x49gp_module_t;
struct __x49gp_module_s__ { struct __x49gp_module_s__ {
const char *name; const char* name;
int (*init) (x49gp_module_t *); int ( *init )( x49gp_module_t* );
int (*exit) (x49gp_module_t *); int ( *exit )( x49gp_module_t* );
int (*reset) (x49gp_module_t *, x49gp_reset_t); int ( *reset )( x49gp_module_t*, x49gp_reset_t );
int (*load) (x49gp_module_t *, GKeyFile *); int ( *load )( x49gp_module_t*, GKeyFile* );
int (*save) (x49gp_module_t *, GKeyFile *); int ( *save )( x49gp_module_t*, GKeyFile* );
void *user_data; void* user_data;
x49gp_t *x49gp; x49gp_t* x49gp;
struct list_head list; struct list_head list;
}; };
typedef enum { typedef enum { X49GP_REINIT_NONE = 0, X49GP_REINIT_REBOOT_ONLY, X49GP_REINIT_FLASH, X49GP_REINIT_FLASH_FULL } x49gp_reinit_t;
X49GP_REINIT_NONE = 0,
X49GP_REINIT_REBOOT_ONLY,
X49GP_REINIT_FLASH,
X49GP_REINIT_FLASH_FULL
} x49gp_reinit_t;
struct __x49gp_s__ { struct __x49gp_s__ {
CPUARMState *env; CPUARMState* env;
struct list_head modules; struct list_head modules;
void *s3c2410_lcd; void* s3c2410_lcd;
void *s3c2410_timer; void* s3c2410_timer;
void *s3c2410_watchdog; void* s3c2410_watchdog;
void *s3c2410_intc; void* s3c2410_intc;
void *s3c2410_io_port; void* s3c2410_io_port;
void *s3c2410_sdi; void* s3c2410_sdi;
void *timer; void* timer;
uint8_t *sram; uint8_t* sram;
uint32_t MCLK; uint32_t MCLK;
uint32_t UCLK; uint32_t UCLK;
@ -88,80 +75,60 @@ struct __x49gp_s__ {
clock_t clk_tck; clock_t clk_tck;
unsigned long emulator_fclk; unsigned long emulator_fclk;
unsigned char keybycol[8]; unsigned char keybycol[ 8 ];
unsigned char keybyrow[8]; unsigned char keybyrow[ 8 ];
x49gp_timer_t *gtk_timer; x49gp_timer_t* gtk_timer;
x49gp_timer_t *lcd_timer; x49gp_timer_t* lcd_timer;
x49gp_arm_idle_t arm_idle; x49gp_arm_idle_t arm_idle;
int arm_exit; int arm_exit;
x49gp_ui_t *ui; x49gp_ui_t* ui;
GKeyFile *config; GKeyFile* config;
const char *progname; const char* progname;
const char *progpath; const char* progpath;
const char *basename; const char* basename;
int debug_port; int debug_port;
x49gp_reinit_t startup_reinit; x49gp_reinit_t startup_reinit;
char *firmware; char* firmware;
}; };
extern void x49gp_set_idle(x49gp_t *, x49gp_arm_idle_t idle); extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );
extern int x49gp_module_init(x49gp_t *x49gp, const char *name, extern int x49gp_module_init( x49gp_t* x49gp, const char* name, int ( *init )( x49gp_module_t* ), int ( *exit )( x49gp_module_t* ),
int (*init)(x49gp_module_t *), int ( *reset )( x49gp_module_t*, x49gp_reset_t ), int ( *load )( x49gp_module_t*, GKeyFile* ),
int (*exit)(x49gp_module_t *), int ( *save )( x49gp_module_t*, GKeyFile* ), void* user_data, x49gp_module_t** module );
int (*reset)(x49gp_module_t *, x49gp_reset_t),
int (*load)(x49gp_module_t *, GKeyFile *),
int (*save)(x49gp_module_t *, GKeyFile *),
void *user_data, x49gp_module_t **module);
extern int x49gp_module_register(x49gp_module_t *module); extern int x49gp_module_register( x49gp_module_t* module );
extern int x49gp_module_unregister(x49gp_module_t *module); extern int x49gp_module_unregister( x49gp_module_t* module );
extern int x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile*, const char*, char*, char**, char** );
const char *, char *, char **, extern int x49gp_module_set_filename( x49gp_module_t* module, GKeyFile*, const char*, const char* );
char **); extern int x49gp_module_get_int( x49gp_module_t* module, GKeyFile*, const char*, int, int* );
extern int x49gp_module_set_filename(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_set_int( x49gp_module_t* module, GKeyFile*, const char*, int );
const char *, const char *); extern int x49gp_module_get_uint( x49gp_module_t* module, GKeyFile*, const char*, unsigned int, unsigned int* );
extern int x49gp_module_get_int(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_set_uint( x49gp_module_t* module, GKeyFile*, const char*, unsigned int );
const char *, int, int *); extern int x49gp_module_get_u32( x49gp_module_t* module, GKeyFile*, const char*, uint32_t, uint32_t* );
extern int x49gp_module_set_int(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_set_u32( x49gp_module_t* module, GKeyFile*, const char*, uint32_t );
const char *, int); extern int x49gp_module_get_u64( x49gp_module_t* module, GKeyFile*, const char*, uint64_t, uint64_t* );
extern int x49gp_module_get_uint(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_set_u64( x49gp_module_t* module, GKeyFile*, const char*, uint64_t );
const char *, extern int x49gp_module_get_string( x49gp_module_t* module, GKeyFile*, const char*, char*, char** );
unsigned int, unsigned int *); extern int x49gp_module_set_string( x49gp_module_t* module, GKeyFile*, const char*, const char* );
extern int x49gp_module_set_uint(x49gp_module_t *module, GKeyFile *, extern int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** path );
const char *, unsigned int);
extern int x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *,
const char *, uint32_t, uint32_t *);
extern int x49gp_module_set_u32(x49gp_module_t *module, GKeyFile *,
const char *, uint32_t);
extern int x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *,
const char *, uint64_t, uint64_t *);
extern int x49gp_module_set_u64(x49gp_module_t *module, GKeyFile *,
const char *, uint64_t);
extern int x49gp_module_get_string(x49gp_module_t *module, GKeyFile *,
const char *, char *, char **);
extern int x49gp_module_set_string(x49gp_module_t *module, GKeyFile *,
const char *, const char *);
extern int x49gp_module_open_rodata(x49gp_module_t *module,
const char *name,
char **path);
extern void s3c2410_sdi_unmount(x49gp_t *x49gp); extern void s3c2410_sdi_unmount( x49gp_t* x49gp );
extern int s3c2410_sdi_mount(x49gp_t *x49gp, char *filename); extern int s3c2410_sdi_mount( x49gp_t* x49gp, char* filename );
extern int s3c2410_sdi_is_mounted(x49gp_t *x49gp); extern int s3c2410_sdi_is_mounted( x49gp_t* x49gp );
extern int x49gp_modules_init(x49gp_t *); extern int x49gp_modules_init( x49gp_t* );
extern int x49gp_modules_exit(x49gp_t *); extern int x49gp_modules_exit( x49gp_t* );
extern int x49gp_modules_reset(x49gp_t *, x49gp_reset_t); extern int x49gp_modules_reset( x49gp_t*, x49gp_reset_t );
extern int x49gp_modules_load(x49gp_t *, const char *); extern int x49gp_modules_load( x49gp_t*, const char* );
extern int x49gp_modules_save(x49gp_t *, const char *); extern int x49gp_modules_save( x49gp_t*, const char* );
extern int x49gp_flash_init(x49gp_t *); extern int x49gp_flash_init( x49gp_t* );
extern int x49gp_sram_init(x49gp_t *); extern int x49gp_sram_init( x49gp_t* );
#endif /* !(_X49GP_H) */ #endif /* !(_X49GP_H) */

View file

@ -11,23 +11,23 @@
#define X49GP_TIMER_VIRTUAL 0 #define X49GP_TIMER_VIRTUAL 0
#define X49GP_TIMER_REALTIME 1 #define X49GP_TIMER_REALTIME 1
int64_t x49gp_get_clock(void); int64_t x49gp_get_clock( void );
typedef void (*x49gp_timer_cb_t) (void *); typedef void ( *x49gp_timer_cb_t )( void* );
typedef struct x49gp_timer_s x49gp_timer_t; typedef struct x49gp_timer_s x49gp_timer_t;
x49gp_timer_t *x49gp_new_timer(long type, x49gp_timer_cb_t, void *user_data); x49gp_timer_t* x49gp_new_timer( long type, x49gp_timer_cb_t, void* user_data );
void x49gp_free_timer(x49gp_timer_t *); void x49gp_free_timer( x49gp_timer_t* );
void x49gp_mod_timer(x49gp_timer_t *, int64_t expires); void x49gp_mod_timer( x49gp_timer_t*, int64_t expires );
void x49gp_del_timer(x49gp_timer_t *); void x49gp_del_timer( x49gp_timer_t* );
int x49gp_timer_pending(x49gp_timer_t *); int x49gp_timer_pending( x49gp_timer_t* );
int64_t x49gp_timer_expires(x49gp_timer_t *); int64_t x49gp_timer_expires( x49gp_timer_t* );
#define X49GP_GTK_REFRESH_INTERVAL 30000LL #define X49GP_GTK_REFRESH_INTERVAL 30000LL
#define X49GP_LCD_REFRESH_INTERVAL 50000LL #define X49GP_LCD_REFRESH_INTERVAL 50000LL
int x49gp_main_loop(x49gp_t *); int x49gp_main_loop( x49gp_t* );
int x49gp_timer_init(x49gp_t *); int x49gp_timer_init( x49gp_t* );
#endif /* !(_X49GP_TIMER_H) */ #endif /* !(_X49GP_TIMER_H) */

View file

@ -43,12 +43,7 @@ typedef enum {
UI_SHAPE_MAX UI_SHAPE_MAX
} x49gp_ui_shape_t; } x49gp_ui_shape_t;
typedef enum { typedef enum { UI_LAYOUT_LEFT = 0, UI_LAYOUT_LEFT_NO_SPACE, UI_LAYOUT_BELOW, UI_LAYOUT_MAX } x49gp_ui_layout_t;
UI_LAYOUT_LEFT = 0,
UI_LAYOUT_LEFT_NO_SPACE,
UI_LAYOUT_BELOW,
UI_LAYOUT_MAX
} x49gp_ui_layout_t;
typedef enum { typedef enum {
UI_CALCULATOR_HP49GP = 0, UI_CALCULATOR_HP49GP = 0,
@ -57,13 +52,12 @@ typedef enum {
UI_CALCULATOR_HP50G_NEWRPL UI_CALCULATOR_HP50G_NEWRPL
} x49gp_ui_calculator_t; } x49gp_ui_calculator_t;
typedef struct { typedef struct {
const char *label; const char* label;
const char *letter; const char* letter;
const char *left; const char* left;
const char *right; const char* right;
const char *below; const char* below;
x49gp_ui_color_t color; x49gp_ui_color_t color;
double font_size; double font_size;
cairo_font_weight_t font_weight; cairo_font_weight_t font_weight;
@ -82,54 +76,54 @@ typedef struct {
} x49gp_ui_key_t; } x49gp_ui_key_t;
typedef struct { typedef struct {
x49gp_t *x49gp; x49gp_t* x49gp;
const x49gp_ui_key_t *key; const x49gp_ui_key_t* key;
GtkWidget *button; GtkWidget* button;
GtkWidget *label; GtkWidget* label;
GtkWidget *box; GtkWidget* box;
GdkPixmap *pixmap; GdkPixmap* pixmap;
gboolean down; gboolean down;
gboolean hold; gboolean hold;
} x49gp_ui_button_t; } x49gp_ui_button_t;
struct __x49gp_ui_s__ { struct __x49gp_ui_s__ {
GtkWidget *window; GtkWidget* window;
GtkWidget *fixed; GtkWidget* fixed;
GtkWidget *menu; GtkWidget* menu;
GtkWidget *menu_unmount; GtkWidget* menu_unmount;
GtkWidget *menu_debug; GtkWidget* menu_debug;
GdkPixbuf *bg_pixbuf; GdkPixbuf* bg_pixbuf;
GdkPixmap *bg_pixmap; GdkPixmap* bg_pixmap;
GtkWidget *background; GtkWidget* background;
GdkColor colors[UI_COLOR_MAX]; GdkColor colors[ UI_COLOR_MAX ];
GdkBitmap *shapes[UI_SHAPE_MAX]; GdkBitmap* shapes[ UI_SHAPE_MAX ];
x49gp_ui_calculator_t calculator; x49gp_ui_calculator_t calculator;
x49gp_ui_button_t *buttons; x49gp_ui_button_t* buttons;
unsigned int nr_buttons; unsigned int nr_buttons;
unsigned int buttons_down; unsigned int buttons_down;
char *name; char* name;
GtkWidget *lcd_canvas; GtkWidget* lcd_canvas;
GdkPixmap *lcd_pixmap; GdkPixmap* lcd_pixmap;
GdkGC *ann_left_gc; GdkGC* ann_left_gc;
GdkGC *ann_right_gc; GdkGC* ann_right_gc;
GdkGC *ann_alpha_gc; GdkGC* ann_alpha_gc;
GdkGC *ann_battery_gc; GdkGC* ann_battery_gc;
GdkGC *ann_busy_gc; GdkGC* ann_busy_gc;
GdkGC *ann_io_gc; GdkGC* ann_io_gc;
GdkBitmap *ann_left; GdkBitmap* ann_left;
GdkBitmap *ann_right; GdkBitmap* ann_right;
GdkBitmap *ann_alpha; GdkBitmap* ann_alpha;
GdkBitmap *ann_battery; GdkBitmap* ann_battery;
GdkBitmap *ann_busy; GdkBitmap* ann_busy;
GdkBitmap *ann_io; GdkBitmap* ann_io;
gint width; gint width;
gint height; gint height;
@ -144,8 +138,8 @@ struct __x49gp_ui_s__ {
gint lcd_top_margin; gint lcd_top_margin;
}; };
int x49gp_ui_init(x49gp_t *x49gp); int x49gp_ui_init( x49gp_t* x49gp );
void x49gp_ui_show_error(x49gp_t *x49gp, const char *text); void x49gp_ui_show_error( x49gp_t* x49gp, const char* text );
void x49gp_ui_open_firmware(x49gp_t *x49gp, char **filename); void x49gp_ui_open_firmware( x49gp_t* x49gp, char** filename );
#endif /* !(_X49GP_UI_H) */ #endif /* !(_X49GP_UI_H) */