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

View file

@ -26,19 +26,19 @@
#include "block_int.h"
#include <zlib.h>
#if 0
#include "aes.h"
# include "aes.h"
#endif
/**************************************************************/
/* 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_CRYPT_NONE 0
#define QCOW_CRYPT_AES 1
#define QCOW_OFLAG_COMPRESSED (1LL << 63)
#define QCOW_OFLAG_COMPRESSED ( 1LL << 63 )
typedef struct QCowHeader {
uint32_t magic;
@ -56,7 +56,7 @@ typedef struct QCowHeader {
#define L2_CACHE_SIZE 16
typedef struct BDRVQcowState {
BlockDriverState *hd;
BlockDriverState* hd;
int cluster_bits;
int cluster_size;
int cluster_sectors;
@ -65,106 +65,104 @@ typedef struct BDRVQcowState {
int l1_size;
uint64_t cluster_offset_mask;
uint64_t l1_table_offset;
uint64_t *l1_table;
uint64_t *l2_cache;
uint64_t l2_cache_offsets[L2_CACHE_SIZE];
uint32_t l2_cache_counts[L2_CACHE_SIZE];
uint8_t *cluster_cache;
uint8_t *cluster_data;
uint64_t* l1_table;
uint64_t* l2_cache;
uint64_t l2_cache_offsets[ L2_CACHE_SIZE ];
uint32_t l2_cache_counts[ L2_CACHE_SIZE ];
uint8_t* cluster_cache;
uint8_t* cluster_data;
uint64_t cluster_cache_offset;
} 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) &&
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
be32_to_cpu(cow_header->version) == QCOW_VERSION)
if ( buf_size >= sizeof( QCowHeader ) && be32_to_cpu( cow_header->magic ) == QCOW_MAGIC &&
be32_to_cpu( cow_header->version ) == QCOW_VERSION )
return 100;
else
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;
QCowHeader header;
ret = bdrv_file_open(&s->hd, filename, flags);
if (ret < 0)
ret = bdrv_file_open( &s->hd, filename, flags );
if ( ret < 0 )
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;
be32_to_cpus(&header.magic);
be32_to_cpus(&header.version);
be64_to_cpus(&header.backing_file_offset);
be32_to_cpus(&header.backing_file_size);
be32_to_cpus(&header.mtime);
be64_to_cpus(&header.size);
be32_to_cpus(&header.crypt_method);
be64_to_cpus(&header.l1_table_offset);
be32_to_cpus( &header.magic );
be32_to_cpus( &header.version );
be64_to_cpus( &header.backing_file_offset );
be32_to_cpus( &header.backing_file_size );
be32_to_cpus( &header.mtime );
be64_to_cpus( &header.size );
be32_to_cpus( &header.crypt_method );
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;
if (header.size <= 1 || header.cluster_bits < 9)
if ( header.size <= 1 || header.cluster_bits < 9 )
goto fail;
if (header.crypt_method > QCOW_CRYPT_AES)
if ( header.crypt_method > QCOW_CRYPT_AES )
goto fail;
s->cluster_bits = header.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_size = 1 << s->l2_bits;
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 */
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 = qemu_malloc(s->l1_size * sizeof(uint64_t));
if (!s->l1_table)
s->l1_table = qemu_malloc( s->l1_size * sizeof( uint64_t ) );
if ( !s->l1_table )
goto fail;
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
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 ) )
goto fail;
for(i = 0;i < s->l1_size; i++) {
be64_to_cpus(&s->l1_table[i]);
for ( i = 0; i < s->l1_size; i++ ) {
be64_to_cpus( &s->l1_table[ i ] );
}
/* alloc L2 cache */
s->l2_cache = qemu_malloc(s->l2_size * L2_CACHE_SIZE * sizeof(uint64_t));
if (!s->l2_cache)
s->l2_cache = qemu_malloc( s->l2_size * L2_CACHE_SIZE * sizeof( uint64_t ) );
if ( !s->l2_cache )
goto fail;
s->cluster_cache = qemu_malloc(s->cluster_size);
if (!s->cluster_cache)
s->cluster_cache = qemu_malloc( s->cluster_size );
if ( !s->cluster_cache )
goto fail;
s->cluster_data = qemu_malloc(s->cluster_size);
if (!s->cluster_data)
s->cluster_data = qemu_malloc( s->cluster_size );
if ( !s->cluster_data )
goto fail;
s->cluster_cache_offset = -1;
/* read the backing file name */
if (header.backing_file_offset != 0) {
if ( header.backing_file_offset != 0 ) {
len = header.backing_file_size;
if (len > 1023)
if ( 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;
bs->backing_file[len] = '\0';
bs->backing_file[ len ] = '\0';
}
return 0;
fail:
qemu_free(s->l1_table);
qemu_free(s->l2_cache);
qemu_free(s->cluster_cache);
qemu_free(s->cluster_data);
bdrv_delete(s->hd);
fail:
qemu_free( s->l1_table );
qemu_free( s->l2_cache );
qemu_free( s->cluster_cache );
qemu_free( s->cluster_data );
bdrv_delete( s->hd );
return -1;
}
@ -181,170 +179,153 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
*
* return 0 if not allocated.
*/
static uint64_t get_cluster_offset(BlockDriverState *bs,
uint64_t offset, int allocate,
int compressed_size,
int n_start, int n_end)
static uint64_t get_cluster_offset( BlockDriverState* bs, 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;
uint64_t l2_offset, *l2_table, cluster_offset, tmp;
uint32_t min_count;
int new_l2_table;
l1_index = offset >> (s->l2_bits + s->cluster_bits);
l2_offset = s->l1_table[l1_index];
l1_index = offset >> ( s->l2_bits + s->cluster_bits );
l2_offset = s->l1_table[ l1_index ];
new_l2_table = 0;
if (!l2_offset) {
if (!allocate)
if ( !l2_offset ) {
if ( !allocate )
return 0;
/* allocate a new l2 entry */
l2_offset = bdrv_getlength(s->hd);
l2_offset = bdrv_getlength( s->hd );
/* 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 */
s->l1_table[l1_index] = l2_offset;
tmp = cpu_to_be64(l2_offset);
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
&tmp, sizeof(tmp)) != sizeof(tmp))
s->l1_table[ l1_index ] = l2_offset;
tmp = cpu_to_be64( l2_offset );
if ( bdrv_pwrite( s->hd, s->l1_table_offset + l1_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
return 0;
new_l2_table = 1;
}
for(i = 0; i < L2_CACHE_SIZE; i++) {
if (l2_offset == s->l2_cache_offsets[i]) {
for ( i = 0; i < L2_CACHE_SIZE; i++ ) {
if ( l2_offset == s->l2_cache_offsets[ i ] ) {
/* increment the hit count */
if (++s->l2_cache_counts[i] == 0xffffffff) {
for(j = 0; j < L2_CACHE_SIZE; j++) {
s->l2_cache_counts[j] >>= 1;
if ( ++s->l2_cache_counts[ i ] == 0xffffffff ) {
for ( j = 0; j < L2_CACHE_SIZE; j++ ) {
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;
}
}
/* not found: load a new entry in the least used one */
min_index = 0;
min_count = 0xffffffff;
for(i = 0; i < L2_CACHE_SIZE; i++) {
if (s->l2_cache_counts[i] < min_count) {
min_count = s->l2_cache_counts[i];
for ( i = 0; i < L2_CACHE_SIZE; i++ ) {
if ( s->l2_cache_counts[ i ] < min_count ) {
min_count = s->l2_cache_counts[ i ];
min_index = i;
}
}
l2_table = s->l2_cache + (min_index << s->l2_bits);
if (new_l2_table) {
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)) !=
s->l2_size * sizeof(uint64_t))
l2_table = s->l2_cache + ( min_index << s->l2_bits );
if ( new_l2_table ) {
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 ) ) != s->l2_size * sizeof( uint64_t ) )
return 0;
} else {
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
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 ) )
return 0;
}
s->l2_cache_offsets[min_index] = l2_offset;
s->l2_cache_counts[min_index] = 1;
found:
l2_index = (offset >> s->cluster_bits) & (s->l2_size - 1);
cluster_offset = be64_to_cpu(l2_table[l2_index]);
if (!cluster_offset ||
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) {
if (!allocate)
s->l2_cache_offsets[ min_index ] = l2_offset;
s->l2_cache_counts[ min_index ] = 1;
found:
l2_index = ( offset >> s->cluster_bits ) & ( s->l2_size - 1 );
cluster_offset = be64_to_cpu( l2_table[ l2_index ] );
if ( !cluster_offset || ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && allocate == 1 ) ) {
if ( !allocate )
return 0;
/* allocate a new cluster */
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) &&
(n_end - n_start) < s->cluster_sectors) {
if ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && ( n_end - n_start ) < s->cluster_sectors ) {
/* if the cluster is already compressed, we must
decompress it in the case it is not completely
overwritten */
if (decompress_cluster(s, cluster_offset) < 0)
if ( decompress_cluster( s, cluster_offset ) < 0 )
return 0;
cluster_offset = bdrv_getlength(s->hd);
cluster_offset = (cluster_offset + s->cluster_size - 1) &
~(s->cluster_size - 1);
cluster_offset = bdrv_getlength( s->hd );
cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
/* write the cluster content */
if (bdrv_pwrite(s->hd, cluster_offset, s->cluster_cache, s->cluster_size) !=
s->cluster_size)
if ( bdrv_pwrite( s->hd, cluster_offset, s->cluster_cache, s->cluster_size ) != s->cluster_size )
return -1;
} else {
cluster_offset = bdrv_getlength(s->hd);
if (allocate == 1) {
cluster_offset = bdrv_getlength( s->hd );
if ( allocate == 1 ) {
/* round to cluster size */
cluster_offset = (cluster_offset + s->cluster_size - 1) &
~(s->cluster_size - 1);
bdrv_truncate(s->hd, cluster_offset + s->cluster_size);
cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
bdrv_truncate( s->hd, cluster_offset + s->cluster_size );
} else {
cluster_offset |= QCOW_OFLAG_COMPRESSED |
(uint64_t)compressed_size << (63 - s->cluster_bits);
cluster_offset |= QCOW_OFLAG_COMPRESSED | ( uint64_t )compressed_size << ( 63 - s->cluster_bits );
}
}
/* update L2 table */
tmp = cpu_to_be64(cluster_offset);
l2_table[l2_index] = tmp;
if (bdrv_pwrite(s->hd,
l2_offset + l2_index * sizeof(tmp), &tmp, sizeof(tmp)) != sizeof(tmp))
tmp = cpu_to_be64( cluster_offset );
l2_table[ l2_index ] = tmp;
if ( bdrv_pwrite( s->hd, l2_offset + l2_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
return 0;
}
return cluster_offset;
}
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
int nb_sectors, int *pnum)
static int qcow_is_allocated( BlockDriverState* bs, int64_t sector_num, int nb_sectors, int* pnum )
{
BDRVQcowState *s = bs->opaque;
BDRVQcowState* s = bs->opaque;
int index_in_cluster, n;
uint64_t cluster_offset;
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
index_in_cluster = sector_num & (s->cluster_sectors - 1);
cluster_offset = get_cluster_offset( bs, sector_num << 9, 0, 0, 0, 0 );
index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors)
if ( n > nb_sectors )
n = nb_sectors;
*pnum = n;
return (cluster_offset != 0);
return ( cluster_offset != 0 );
}
static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
const uint8_t *buf, int buf_size)
static int decompress_buffer( uint8_t* out_buf, int out_buf_size, const uint8_t* buf, int buf_size )
{
z_stream strm1, *strm = &strm1;
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->next_out = out_buf;
strm->avail_out = out_buf_size;
ret = inflateInit2(strm, -12);
if (ret != Z_OK)
ret = inflateInit2( strm, -12 );
if ( ret != Z_OK )
return -1;
ret = inflate(strm, Z_FINISH);
ret = inflate( strm, Z_FINISH );
out_len = strm->next_out - out_buf;
if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) ||
out_len != out_buf_size) {
inflateEnd(strm);
if ( ( ret != Z_STREAM_END && ret != Z_BUF_ERROR ) || out_len != out_buf_size ) {
inflateEnd( strm );
return -1;
}
inflateEnd(strm);
inflateEnd( strm );
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;
uint64_t coffset;
coffset = cluster_offset & s->cluster_offset_mask;
if (s->cluster_cache_offset != coffset) {
csize = cluster_offset >> (63 - s->cluster_bits);
csize &= (s->cluster_size - 1);
ret = bdrv_pread(s->hd, coffset, s->cluster_data, csize);
if (ret != csize)
if ( s->cluster_cache_offset != coffset ) {
csize = cluster_offset >> ( 63 - s->cluster_bits );
csize &= ( s->cluster_size - 1 );
ret = bdrv_pread( s->hd, coffset, s->cluster_data, csize );
if ( ret != csize )
return -1;
if (decompress_buffer(s->cluster_cache, s->cluster_size,
s->cluster_data, csize) < 0) {
if ( decompress_buffer( s->cluster_cache, s->cluster_size, s->cluster_data, csize ) < 0 ) {
return -1;
}
s->cluster_cache_offset = coffset;
@ -352,35 +333,34 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
return 0;
}
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
uint8_t *buf, int nb_sectors)
static int qcow_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors )
{
BDRVQcowState *s = bs->opaque;
BDRVQcowState* s = bs->opaque;
int ret, index_in_cluster, n;
uint64_t cluster_offset;
while (nb_sectors > 0) {
cluster_offset = get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0);
index_in_cluster = sector_num & (s->cluster_sectors - 1);
while ( nb_sectors > 0 ) {
cluster_offset = get_cluster_offset( bs, sector_num << 9, 0, 0, 0, 0 );
index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors)
if ( n > nb_sectors )
n = nb_sectors;
if (!cluster_offset) {
if (bs->backing_hd) {
if ( !cluster_offset ) {
if ( bs->backing_hd ) {
/* read from the base image */
ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
if (ret < 0)
ret = bdrv_read( bs->backing_hd, sector_num, buf, n );
if ( ret < 0 )
return -1;
} else {
memset(buf, 0, 512 * n);
memset( buf, 0, 512 * n );
}
} else if (cluster_offset & QCOW_OFLAG_COMPRESSED) {
if (decompress_cluster(s, cluster_offset) < 0)
} else if ( cluster_offset & QCOW_OFLAG_COMPRESSED ) {
if ( decompress_cluster( s, cluster_offset ) < 0 )
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 {
ret = bdrv_pread(s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512);
if (ret != n * 512)
ret = bdrv_pread( s->hd, cluster_offset + index_in_cluster * 512, buf, n * 512 );
if ( ret != n * 512 )
return -1;
}
nb_sectors -= n;
@ -390,27 +370,24 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
return 0;
}
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
static int qcow_write( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
{
BDRVQcowState *s = bs->opaque;
BDRVQcowState* s = bs->opaque;
int ret, index_in_cluster, n;
uint64_t cluster_offset;
while (nb_sectors > 0) {
index_in_cluster = sector_num & (s->cluster_sectors - 1);
while ( nb_sectors > 0 ) {
index_in_cluster = sector_num & ( s->cluster_sectors - 1 );
n = s->cluster_sectors - index_in_cluster;
if (n > nb_sectors)
if ( n > nb_sectors )
n = nb_sectors;
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
index_in_cluster,
index_in_cluster + n);
if (!cluster_offset)
cluster_offset = get_cluster_offset( bs, sector_num << 9, 1, 0, index_in_cluster, index_in_cluster + n );
if ( !cluster_offset )
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;
nb_sectors -= n;
sector_num += n;
@ -420,39 +397,38 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num,
return 0;
}
static void qcow_close(BlockDriverState *bs)
static void qcow_close( BlockDriverState* bs )
{
BDRVQcowState *s = bs->opaque;
qemu_free(s->l1_table);
qemu_free(s->l2_cache);
qemu_free(s->cluster_cache);
qemu_free(s->cluster_data);
bdrv_delete(s->hd);
BDRVQcowState* s = bs->opaque;
qemu_free( s->l1_table );
qemu_free( s->l2_cache );
qemu_free( s->cluster_cache );
qemu_free( s->cluster_data );
bdrv_delete( s->hd );
}
static int qcow_create(const char *filename, int64_t total_size,
const char *backing_file, int flags)
static int qcow_create( const char* filename, int64_t total_size, const char* backing_file, int flags )
{
int fd, header_size, backing_filename_len, l1_size, i, shift;
QCowHeader header;
uint64_t tmp;
int ret;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (fd < 0)
fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644 );
if ( fd < 0 )
return -1;
memset(&header, 0, sizeof(header));
header.magic = cpu_to_be32(QCOW_MAGIC);
header.version = cpu_to_be32(QCOW_VERSION);
header.size = cpu_to_be64(total_size * 512);
header_size = sizeof(header);
memset( &header, 0, sizeof( header ) );
header.magic = cpu_to_be32( QCOW_MAGIC );
header.version = cpu_to_be32( QCOW_VERSION );
header.size = cpu_to_be64( total_size * 512 );
header_size = sizeof( header );
backing_filename_len = 0;
if (backing_file) {
header.backing_file_offset = cpu_to_be64(header_size);
backing_filename_len = strlen(backing_file);
header.backing_file_size = cpu_to_be32(backing_filename_len);
if ( backing_file ) {
header.backing_file_offset = cpu_to_be64( header_size );
backing_filename_len = strlen( backing_file );
header.backing_file_size = cpu_to_be32( 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
unmodifyed sectors */
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.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;
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);
if (flags) {
header.crypt_method = cpu_to_be32(QCOW_CRYPT_AES);
header.l1_table_offset = cpu_to_be64( header_size );
if ( flags ) {
header.crypt_method = cpu_to_be32( QCOW_CRYPT_AES );
} else {
header.crypt_method = cpu_to_be32(QCOW_CRYPT_NONE);
header.crypt_method = cpu_to_be32( QCOW_CRYPT_NONE );
}
/* write all the data */
ret = write(fd, &header, sizeof(header));
if (ret != sizeof(header)) {
ret = write( fd, &header, sizeof( header ) );
if ( ret != sizeof( header ) ) {
ret = -1;
goto exit;
}
if (backing_file) {
ret = write(fd, backing_file, backing_filename_len);
if (ret != backing_filename_len) {
if ( backing_file ) {
ret = write( fd, backing_file, backing_filename_len );
if ( ret != backing_filename_len ) {
ret = -1;
goto exit;
}
}
lseek(fd, header_size, SEEK_SET);
lseek( fd, header_size, SEEK_SET );
tmp = 0;
for(i = 0;i < l1_size; i++) {
ret = write(fd, &tmp, sizeof(tmp));
if (ret != sizeof(tmp)) {
for ( i = 0; i < l1_size; i++ ) {
ret = write( fd, &tmp, sizeof( tmp ) );
if ( ret != sizeof( tmp ) ) {
ret = -1;
goto exit;
}
@ -497,106 +473,102 @@ static int qcow_create(const char *filename, int64_t total_size,
ret = 0;
exit:
close(fd);
close( fd );
return ret;
}
static int qcow_make_empty(BlockDriverState *bs)
static int qcow_make_empty( BlockDriverState* bs )
{
BDRVQcowState *s = bs->opaque;
uint32_t l1_length = s->l1_size * sizeof(uint64_t);
BDRVQcowState* s = bs->opaque;
uint32_t l1_length = s->l1_size * sizeof( uint64_t );
int ret;
memset(s->l1_table, 0, l1_length);
if (bdrv_pwrite(s->hd, s->l1_table_offset, s->l1_table, l1_length) < 0)
memset( s->l1_table, 0, l1_length );
if ( bdrv_pwrite( s->hd, s->l1_table_offset, s->l1_table, l1_length ) < 0 )
return -1;
ret = bdrv_truncate(s->hd, s->l1_table_offset + l1_length);
if (ret < 0)
ret = bdrv_truncate( s->hd, s->l1_table_offset + l1_length );
if ( ret < 0 )
return ret;
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_counts, 0, L2_CACHE_SIZE * sizeof(uint32_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_counts, 0, L2_CACHE_SIZE * sizeof( uint32_t ) );
return 0;
}
/* XXX: put compressed sectors first, then all the cluster aligned
tables to avoid losing bytes in alignment */
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
const uint8_t *buf, int nb_sectors)
static int qcow_write_compressed( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
{
BDRVQcowState *s = bs->opaque;
BDRVQcowState* s = bs->opaque;
z_stream strm;
int ret, out_len;
uint8_t *out_buf;
uint8_t* out_buf;
uint64_t cluster_offset;
if (nb_sectors != s->cluster_sectors)
if ( nb_sectors != s->cluster_sectors )
return -EINVAL;
out_buf = qemu_malloc(s->cluster_size + (s->cluster_size / 1000) + 128);
if (!out_buf)
out_buf = qemu_malloc( s->cluster_size + ( s->cluster_size / 1000 ) + 128 );
if ( !out_buf )
return -1;
/* best compression, small window, no zlib header */
memset(&strm, 0, sizeof(strm));
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
Z_DEFLATED, -12,
9, Z_DEFAULT_STRATEGY);
if (ret != 0) {
qemu_free(out_buf);
memset( &strm, 0, sizeof( strm ) );
ret = deflateInit2( &strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY );
if ( ret != 0 ) {
qemu_free( out_buf );
return -1;
}
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.next_out = out_buf;
ret = deflate(&strm, Z_FINISH);
if (ret != Z_STREAM_END && ret != Z_OK) {
qemu_free(out_buf);
deflateEnd(&strm);
ret = deflate( &strm, Z_FINISH );
if ( ret != Z_STREAM_END && ret != Z_OK ) {
qemu_free( out_buf );
deflateEnd( &strm );
return -1;
}
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 */
qcow_write(bs, sector_num, buf, s->cluster_sectors);
qcow_write( bs, sector_num, buf, s->cluster_sectors );
} else {
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
out_len, 0, 0);
cluster_offset = get_cluster_offset( bs, sector_num << 9, 2, out_len, 0, 0 );
cluster_offset &= s->cluster_offset_mask;
if (bdrv_pwrite(s->hd, cluster_offset, out_buf, out_len) != out_len) {
qemu_free(out_buf);
if ( bdrv_pwrite( s->hd, cluster_offset, out_buf, out_len ) != out_len ) {
qemu_free( out_buf );
return -1;
}
}
qemu_free(out_buf);
qemu_free( out_buf );
return 0;
}
static void qcow_flush(BlockDriverState *bs)
static void qcow_flush( BlockDriverState* bs )
{
BDRVQcowState *s = bs->opaque;
bdrv_flush(s->hd);
BDRVQcowState* s = bs->opaque;
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;
return 0;
}
BlockDriver bdrv_qcow = {
"qcow",
sizeof(BDRVQcowState),
sizeof( BDRVQcowState ),
qcow_probe,
qcow_open,
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"
#define SECTOR_BITS 9
#define SECTOR_SIZE (1 << SECTOR_BITS)
#define SECTOR_SIZE ( 1 << SECTOR_BITS )
static BlockDriverState *bdrv_first;
static BlockDriver *first_drv;
static BlockDriverState* bdrv_first;
static BlockDriver* first_drv;
#ifndef ENOMEDIUM
#define ENOMEDIUM ENODEV
# define ENOMEDIUM ENODEV
#endif
static void bdrv_close(BlockDriverState *bs);
static void bdrv_close( BlockDriverState* bs );
static int
path_is_absolute(const char *path)
static int path_is_absolute( const char* path )
{
const char *p;
const char* p;
#ifdef _WIN32
/* specific case for names like: "\\.\d:" */
if (*path == '/' || *path == '\\')
if ( *path == '/' || *path == '\\' )
return 1;
#endif
p = strchr(path, ':');
if (p)
p = strchr( path, ':' );
if ( p )
p++;
else
p = path;
#ifdef _WIN32
return (*p == '/' || *p == '\\');
return ( *p == '/' || *p == '\\' );
#else
return (*p == '/');
return ( *p == '/' );
#endif
}
/* 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
supported. */
static void
path_combine(char *dest, int dest_size,
const char *base_path,
const char *filename)
static void path_combine( char* dest, int dest_size, const char* base_path, const char* filename )
{
const char *p, *p1;
int len;
if (dest_size <= 0)
if ( dest_size <= 0 )
return;
if (path_is_absolute(filename)) {
pstrcpy(dest, dest_size, filename);
if ( path_is_absolute( filename ) ) {
pstrcpy( dest, dest_size, filename );
} else {
p = strchr(base_path, ':');
if (p)
p = strchr( base_path, ':' );
if ( p )
p++;
else
p = base_path;
p1 = strrchr(base_path, '/');
p1 = strrchr( base_path, '/' );
#ifdef _WIN32
{
const char *p2;
p2 = strrchr(base_path, '\\');
if (!p1 || p2 > p1)
const char* p2;
p2 = strrchr( base_path, '\\' );
if ( !p1 || p2 > p1 )
p1 = p2;
}
#endif
if (p1)
if ( p1 )
p1++;
else
p1 = base_path;
if (p1 > p)
if ( p1 > p )
p = p1;
len = p - base_path;
if (len > dest_size - 1)
if ( len > dest_size - 1 )
len = dest_size - 1;
memcpy(dest, base_path, len);
dest[len] = '\0';
pstrcat(dest, dest_size, filename);
memcpy( dest, base_path, len );
dest[ len ] = '\0';
pstrcat( dest, dest_size, filename );
}
}
#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);
GetTempFileName(temp_dir, "x49", 0, filename);
GetTempPath( MAX_PATH, temp_dir );
GetTempFileName( temp_dir, "x49", 0, filename );
}
#else
void get_tmp_filename(char *filename, int size)
void get_tmp_filename( char* filename, int size )
{
int fd;
/* XXX: race condition possible */
pstrcpy(filename, size, "/tmp/x49gp.XXXXXX");
fd = mkstemp(filename);
close(fd);
pstrcpy( filename, size, "/tmp/x49gp.XXXXXX" );
fd = mkstemp( filename );
close( fd );
}
#endif
#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') ||
(filename[0] >= 'A' && filename[0] <= 'Z')) &&
filename[1] == ':');
return ( ( ( filename[ 0 ] >= 'a' && filename[ 0 ] <= 'z' ) || ( filename[ 0 ] >= 'A' && filename[ 0 ] <= 'Z' ) ) &&
filename[ 1 ] == ':' );
}
static int is_windows_drive(const char *filename)
static int is_windows_drive( const char* filename )
{
if (is_windows_drive_prefix(filename) &&
filename[2] == '\0')
if ( is_windows_drive_prefix( filename ) && filename[ 2 ] == '\0' )
return 1;
if (strstart(filename, "\\\\.\\", NULL) ||
strstart(filename, "//./", NULL))
if ( strstart( filename, "\\\\.\\", NULL ) || strstart( filename, "//./", NULL ) )
return 1;
return 0;
}
#endif
static BlockDriver *
find_protocol(const char *filename)
static BlockDriver* find_protocol( const char* filename )
{
BlockDriver *drv1;
char protocol[128];
BlockDriver* drv1;
char protocol[ 128 ];
int len;
const char *p;
const char* p;
#ifdef _WIN32
if (is_windows_drive(filename) ||
is_windows_drive_prefix(filename))
if ( is_windows_drive( filename ) || is_windows_drive_prefix( filename ) )
return &bdrv_raw;
#endif
p = strchr(filename, ':');
if (!p)
p = strchr( filename, ':' );
if ( !p )
return &bdrv_raw;
len = p - filename;
if (len > sizeof(protocol) - 1)
len = sizeof(protocol) - 1;
memcpy(protocol, filename, len);
protocol[len] = '\0';
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) {
if ( len > sizeof( protocol ) - 1 )
len = sizeof( protocol ) - 1;
memcpy( protocol, filename, len );
protocol[ len ] = '\0';
for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr,
"%s:%u: protocol '%s', drv->protocol_name '%s'\n",
__FUNCTION__, __LINE__, protocol, drv1->protocol_name);
fprintf( stderr, "%s:%u: protocol '%s', drv->protocol_name '%s'\n", __FUNCTION__, __LINE__, protocol, drv1->protocol_name );
#endif
if (drv1->protocol_name &&
!strcmp(drv1->protocol_name, protocol)) {
if ( drv1->protocol_name && !strcmp( drv1->protocol_name, protocol ) ) {
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: protocol '%s', drv %p\n",
__FUNCTION__, __LINE__, protocol, drv1);
fprintf( stderr, "%s:%u: protocol '%s', drv %p\n", __FUNCTION__, __LINE__, protocol, drv1 );
#endif
return drv1;
}
}
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: protocol '%s', NULL\n",
__FUNCTION__, __LINE__, protocol);
fprintf( stderr, "%s:%u: protocol '%s', NULL\n", __FUNCTION__, __LINE__, protocol );
#endif
return NULL;
}
/* XXX: force raw format if block or character device ? It would
simplify the BSD case */
static BlockDriver *
find_image_format(const char *filename)
static BlockDriver* find_image_format( const char* filename )
{
int ret, score, score_max;
BlockDriver *drv1, *drv;
uint8_t buf[2048];
BlockDriverState *bs;
uint8_t buf[ 2048 ];
BlockDriverState* bs;
drv = find_protocol(filename);
drv = find_protocol( filename );
/* no need to test disk image formats for vvfat */
if (drv == &bdrv_vvfat)
if ( drv == &bdrv_vvfat )
return drv;
ret = bdrv_file_open(&bs, filename, BDRV_O_RDONLY);
if (ret < 0)
ret = bdrv_file_open( &bs, filename, BDRV_O_RDONLY );
if ( ret < 0 )
return NULL;
ret = bdrv_pread(bs, 0, buf, sizeof(buf));
bdrv_delete(bs);
if (ret < 0) {
ret = bdrv_pread( bs, 0, buf, sizeof( buf ) );
bdrv_delete( bs );
if ( ret < 0 ) {
return NULL;
}
score_max = 0;
for(drv1 = first_drv; drv1 != NULL; drv1 = drv1->next) {
if (drv1->bdrv_probe) {
score = drv1->bdrv_probe(buf, ret, filename);
if (score > score_max) {
for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
if ( drv1->bdrv_probe ) {
score = drv1->bdrv_probe( buf, ret, filename );
if ( score > score_max ) {
score_max = score;
drv = drv1;
}
@ -210,38 +195,33 @@ find_image_format(const char *filename)
return drv;
}
int
bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags)
int 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 drv->bdrv_create(filename, size_in_sectors, backing_file, flags);
return drv->bdrv_create( filename, size_in_sectors, backing_file, flags );
}
static void
bdrv_register(BlockDriver *bdrv)
static void bdrv_register( BlockDriver* bdrv )
{
bdrv->next = first_drv;
first_drv = bdrv;
}
/* create a new block device (by default it is empty) */
BlockDriverState *
bdrv_new(const char *device_name)
BlockDriverState* bdrv_new( const char* device_name )
{
BlockDriverState **pbs, *bs;
bs = qemu_mallocz(sizeof(BlockDriverState));
if(!bs)
bs = qemu_mallocz( sizeof( BlockDriverState ) );
if ( !bs )
return NULL;
pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
if (device_name[0] != '\0') {
pstrcpy( bs->device_name, sizeof( bs->device_name ), device_name );
if ( device_name[ 0 ] != '\0' ) {
/* insert at the end */
pbs = &bdrv_first;
while (*pbs != NULL)
pbs = &(*pbs)->next;
while ( *pbs != NULL )
pbs = &( *pbs )->next;
*pbs = bs;
}
return bs;
@ -250,95 +230,86 @@ bdrv_new(const char *device_name)
/**
* Truncate file to 'offset' bytes (needed only for file protocols)
*/
int
bdrv_truncate(BlockDriverState *bs, int64_t offset)
int bdrv_truncate( BlockDriverState* bs, int64_t offset )
{
BlockDriver *drv = bs->drv;
if (!drv)
BlockDriver* drv = bs->drv;
if ( !drv )
return -ENOMEDIUM;
if (!drv->bdrv_truncate)
if ( !drv->bdrv_truncate )
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.
*/
int64_t
bdrv_getlength(BlockDriverState *bs)
int64_t bdrv_getlength( BlockDriverState* bs )
{
BlockDriver *drv = bs->drv;
if (!drv)
BlockDriver* drv = bs->drv;
if ( !drv )
return -ENOMEDIUM;
if (!drv->bdrv_getlength) {
if ( !drv->bdrv_getlength ) {
/* legacy mode */
return bs->total_sectors * SECTOR_SIZE;
}
return drv->bdrv_getlength(bs);
return drv->bdrv_getlength( bs );
}
int
bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags )
{
BlockDriverState *bs;
BlockDriverState* bs;
int ret;
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: filename '%s'\n",
__FUNCTION__, __LINE__, filename);
fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
#endif
bs = bdrv_new("");
if (!bs)
bs = bdrv_new( "" );
if ( !bs )
return -ENOMEM;
ret = bdrv_open(bs, filename, flags | BDRV_O_FILE);
if (ret < 0) {
bdrv_delete(bs);
ret = bdrv_open( bs, filename, flags | BDRV_O_FILE );
if ( ret < 0 ) {
bdrv_delete( bs );
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: '%s': %d\n",
__FUNCTION__, __LINE__, filename, ret);
fprintf( stderr, "%s:%u: '%s': %d\n", __FUNCTION__, __LINE__, filename, ret );
#endif
return ret;
}
*pbs = bs;
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__);
fprintf( stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__ );
#endif
return 0;
}
int
bdrv_open(BlockDriverState *bs, const char *filename, int flags)
int bdrv_open( BlockDriverState* bs, const char* filename, int flags )
{
int ret, open_flags;
char backing_filename[1024];
BlockDriver *drv = NULL;
char backing_filename[ 1024 ];
BlockDriver* drv = NULL;
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: filename '%s'\n",
__FUNCTION__, __LINE__, filename);
fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
#endif
bs->read_only = 0;
bs->is_temporary = 0;
bs->encrypted = 0;
pstrcpy(bs->filename, sizeof(bs->filename), filename);
if (flags & BDRV_O_FILE) {
drv = find_protocol(filename);
if (!drv) {
pstrcpy( bs->filename, sizeof( bs->filename ), filename );
if ( flags & BDRV_O_FILE ) {
drv = find_protocol( filename );
if ( !drv ) {
#ifdef DEBUG_X49GP_BLOCK
f printf(stderr, "%s:%u: drv: %p\n",
__FUNCTION__, __LINE__, drv);
f printf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
#endif
return -ENOENT;
}
} else {
if (!drv) {
drv = find_image_format(filename);
if (!drv) {
if ( !drv ) {
drv = find_image_format( filename );
if ( !drv ) {
#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
return -1;
}
@ -346,75 +317,68 @@ f printf(stderr, "%s:%u: drv: %p\n",
}
#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
bs->drv = drv;
bs->opaque = qemu_mallocz(drv->instance_size);
if (bs->opaque == NULL && drv->instance_size > 0) {
bs->opaque = qemu_mallocz( drv->instance_size );
if ( bs->opaque == NULL && drv->instance_size > 0 ) {
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: no opaque\n", __FUNCTION__, __LINE__);
fprintf( stderr, "%s:%u: no opaque\n", __FUNCTION__, __LINE__ );
#endif
return -1;
}
/* Note: for compatibility, we open disk image files as RDWR, and
RDONLY as fallback */
if (!(flags & BDRV_O_FILE))
if ( !( flags & BDRV_O_FILE ) )
open_flags = BDRV_O_RDWR;
else
open_flags = flags & ~(BDRV_O_FILE);
ret = drv->bdrv_open(bs, filename, open_flags);
open_flags = flags & ~( BDRV_O_FILE );
ret = drv->bdrv_open( bs, filename, open_flags );
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: drv->bdrv_open: %d\n",
__FUNCTION__, __LINE__, ret);
fprintf( stderr, "%s:%u: drv->bdrv_open: %d\n", __FUNCTION__, __LINE__, ret );
#endif
if (ret == -EACCES && !(flags & BDRV_O_FILE)) {
ret = drv->bdrv_open(bs, filename, BDRV_O_RDONLY);
if ( ret == -EACCES && !( flags & BDRV_O_FILE ) ) {
ret = drv->bdrv_open( bs, filename, BDRV_O_RDONLY );
bs->read_only = 1;
}
if (ret < 0) {
qemu_free(bs->opaque);
if ( ret < 0 ) {
qemu_free( bs->opaque );
bs->opaque = NULL;
bs->drv = NULL;
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return %d\n",
__FUNCTION__, __LINE__, ret);
fprintf( stderr, "%s:%u: return %d\n", __FUNCTION__, __LINE__, ret );
#endif
return ret;
}
if (drv->bdrv_getlength) {
bs->total_sectors = bdrv_getlength(bs) >> SECTOR_BITS;
if ( drv->bdrv_getlength ) {
bs->total_sectors = bdrv_getlength( bs ) >> SECTOR_BITS;
}
#ifndef _WIN32
if (bs->is_temporary) {
unlink(filename);
if ( bs->is_temporary ) {
unlink( filename );
}
#endif
if (bs->backing_file[0] != '\0') {
if ( bs->backing_file[ 0 ] != '\0' ) {
/* if there is a backing file, use it */
bs->backing_hd = bdrv_new("");
if (!bs->backing_hd) {
fail:
bdrv_close(bs);
bs->backing_hd = bdrv_new( "" );
if ( !bs->backing_hd ) {
fail:
bdrv_close( bs );
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return -ENOMEM\n",
__FUNCTION__, __LINE__);
fprintf( stderr, "%s:%u: return -ENOMEM\n", __FUNCTION__, __LINE__ );
#endif
return -ENOMEM;
}
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: combine '%s' '%s'\n",
__FUNCTION__, __LINE__, filename, bs->backing_file);
fprintf( stderr, "%s:%u: combine '%s' '%s'\n", __FUNCTION__, __LINE__, filename, bs->backing_file );
#endif
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
path_combine( backing_filename, sizeof( backing_filename ), filename, bs->backing_file );
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: combine: '%s'\n",
__FUNCTION__, __LINE__, backing_filename);
fprintf( stderr, "%s:%u: combine: '%s'\n", __FUNCTION__, __LINE__, backing_filename );
#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
fprintf(stderr, "%s:%u: backing fail\n",
__FUNCTION__, __LINE__);
fprintf( stderr, "%s:%u: backing fail\n", __FUNCTION__, __LINE__ );
#endif
goto fail;
}
@ -422,81 +386,77 @@ f printf(stderr, "%s:%u: drv: %p\n",
/* call the change callback */
bs->media_changed = 1;
if (bs->change_cb)
bs->change_cb(bs->change_opaque);
if ( bs->change_cb )
bs->change_cb( bs->change_opaque );
#ifdef DEBUG_X49GP_BLOCK
fprintf(stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__);
fprintf( stderr, "%s:%u: return 0\n", __FUNCTION__, __LINE__ );
#endif
return 0;
}
static void
bdrv_close(BlockDriverState *bs)
static void bdrv_close( BlockDriverState* bs )
{
if (NULL == bs->drv)
if ( NULL == bs->drv )
return;
/* call the change callback */
bs->media_changed = 1;
if (bs->change_cb)
bs->change_cb(bs->change_opaque);
if ( bs->change_cb )
bs->change_cb( bs->change_opaque );
if (bs->backing_hd)
bdrv_delete(bs->backing_hd);
if ( bs->backing_hd )
bdrv_delete( bs->backing_hd );
bs->drv->bdrv_close(bs);
bs->drv->bdrv_close( bs );
#ifdef _WIN32
if (bs->is_temporary) {
unlink(bs->filename);
if ( bs->is_temporary ) {
unlink( bs->filename );
}
#endif
qemu_free(bs->opaque);
qemu_free( bs->opaque );
bs->opaque = NULL;
bs->drv = NULL;
}
void
bdrv_delete(BlockDriverState *bs)
void bdrv_delete( BlockDriverState* bs )
{
/* XXX: remove the driver list */
bdrv_close(bs);
qemu_free(bs);
bdrv_close( bs );
qemu_free( bs );
}
/* return < 0 if error. See bdrv_write() for the return codes */
int
bdrv_read(BlockDriverState * bs, int64_t sector_num,
uint8_t * buf, int nb_sectors)
int 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;
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
memcpy(buf, bs->boot_sector_data, 512);
if ( sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0 ) {
memcpy( buf, bs->boot_sector_data, 512 );
sector_num++;
nb_sectors--;
buf += 512;
if (nb_sectors == 0)
if ( nb_sectors == 0 )
return 0;
}
if (drv->bdrv_pread) {
if ( drv->bdrv_pread ) {
int ret, len;
len = nb_sectors * 512;
ret = drv->bdrv_pread(bs, sector_num * 512, buf, len);
if (ret < 0)
ret = drv->bdrv_pread( bs, sector_num * 512, buf, len );
if ( ret < 0 )
return ret;
else if (ret != len)
else if ( ret != len )
return -EINVAL;
else
return 0;
} 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
-EACCES Trying to write a read-only device
*/
static int
bdrv_write(BlockDriverState * bs, int64_t sector_num,
const uint8_t * buf, int nb_sectors)
static int 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;
if (bs->read_only)
if ( bs->read_only )
return -EACCES;
if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
memcpy(bs->boot_sector_data, buf, 512);
if ( sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0 ) {
memcpy( bs->boot_sector_data, buf, 512 );
}
if (drv->bdrv_pwrite) {
if ( drv->bdrv_pwrite ) {
int ret, len;
len = nb_sectors * 512;
ret = drv->bdrv_pwrite(bs, sector_num * 512, buf, len);
if (ret < 0)
ret = drv->bdrv_pwrite( bs, sector_num * 512, buf, len );
if ( ret < 0 )
return ret;
else if (ret != len)
else if ( ret != len )
return -EIO;
else
return 0;
} else {
return drv->bdrv_write(bs, sector_num, buf, nb_sectors);
return drv->bdrv_write( bs, sector_num, buf, nb_sectors );
}
}
static int
bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
static int 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;
int64_t sector_num;
count = count1;
/* first read to align to sector start */
len = (SECTOR_SIZE - offset) & (SECTOR_SIZE - 1);
if (len > count)
len = ( SECTOR_SIZE - offset ) & ( SECTOR_SIZE - 1 );
if ( len > count )
len = count;
sector_num = offset >> SECTOR_BITS;
if (len > 0) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
if ( len > 0 ) {
if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
memcpy(buf, tmp_buf + (offset & (SECTOR_SIZE - 1)), len);
memcpy( buf, tmp_buf + ( offset & ( SECTOR_SIZE - 1 ) ), len );
count -= len;
if (count == 0)
if ( count == 0 )
return count1;
sector_num++;
buf += len;
@ -561,8 +518,8 @@ bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
/* read the sectors "in place" */
nb_sectors = count >> SECTOR_BITS;
if (nb_sectors > 0) {
if (bdrv_read(bs, sector_num, buf, nb_sectors) < 0)
if ( nb_sectors > 0 ) {
if ( bdrv_read( bs, sector_num, buf, nb_sectors ) < 0 )
return -EIO;
sector_num += nb_sectors;
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 */
if (count > 0) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
if ( count > 0 ) {
if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
memcpy(buf, tmp_buf, count);
memcpy( buf, tmp_buf, count );
}
return count1;
}
static int
bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
const uint8_t * buf, int count1)
static int 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;
int64_t sector_num;
count = count1;
/* first write to align to sector start */
len = (SECTOR_SIZE - offset) & (SECTOR_SIZE - 1);
if (len > count)
len = ( SECTOR_SIZE - offset ) & ( SECTOR_SIZE - 1 );
if ( len > count )
len = count;
sector_num = offset >> SECTOR_BITS;
if (len > 0) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
if ( len > 0 ) {
if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
memcpy(tmp_buf + (offset & (SECTOR_SIZE - 1)), buf, len);
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
memcpy( tmp_buf + ( offset & ( SECTOR_SIZE - 1 ) ), buf, len );
if ( bdrv_write( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
count -= len;
if (count == 0)
if ( count == 0 )
return count1;
sector_num++;
buf += len;
@ -608,8 +563,8 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
/* write the sectors "in place" */
nb_sectors = count >> SECTOR_BITS;
if (nb_sectors > 0) {
if (bdrv_write(bs, sector_num, buf, nb_sectors) < 0)
if ( nb_sectors > 0 ) {
if ( bdrv_write( bs, sector_num, buf, nb_sectors ) < 0 )
return -EIO;
sector_num += nb_sectors;
len = nb_sectors << SECTOR_BITS;
@ -618,11 +573,11 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
}
/* add data from the last sector */
if (count > 0) {
if (bdrv_read(bs, sector_num, tmp_buf, 1) < 0)
if ( count > 0 ) {
if ( bdrv_read( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
memcpy(tmp_buf, buf, count);
if (bdrv_write(bs, sector_num, tmp_buf, 1) < 0)
memcpy( tmp_buf, buf, count );
if ( bdrv_write( bs, sector_num, tmp_buf, 1 ) < 0 )
return -EIO;
}
return count1;
@ -631,47 +586,43 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
/**
* Read with byte offsets (needed only for file protocols)
*/
int
bdrv_pread(BlockDriverState * bs, int64_t offset, void *buf1, int count1)
int 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;
if (!drv->bdrv_pread)
return bdrv_pread_em(bs, offset, buf1, count1);
return drv->bdrv_pread(bs, offset, buf1, count1);
if ( !drv->bdrv_pread )
return bdrv_pread_em( bs, offset, buf1, count1 );
return drv->bdrv_pread( bs, offset, buf1, count1 );
}
/**
* Write with byte offsets (needed only for file protocols)
*/
int
bdrv_pwrite(BlockDriverState * bs, int64_t offset, const void *buf1, int count1)
int 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;
if (!drv->bdrv_pwrite)
return bdrv_pwrite_em(bs, offset, buf1, count1);
return drv->bdrv_pwrite(bs, offset, buf1, count1);
if ( !drv->bdrv_pwrite )
return bdrv_pwrite_em( bs, offset, buf1, count1 );
return drv->bdrv_pwrite( bs, offset, buf1, count1 );
}
void
bdrv_flush(BlockDriverState *bs)
void bdrv_flush( BlockDriverState* bs )
{
if (bs->drv->bdrv_flush)
bs->drv->bdrv_flush(bs);
if (bs->backing_hd)
bdrv_flush(bs->backing_hd);
if ( bs->drv->bdrv_flush )
bs->drv->bdrv_flush( bs );
if ( bs->backing_hd )
bdrv_flush( bs->backing_hd );
}
void
bdrv_init(void)
void bdrv_init( void )
{
/* bdrv_register(&bdrv_raw); */
/* bdrv_register(&bdrv_host_device); */
bdrv_register(&bdrv_qcow);
bdrv_register(&bdrv_vvfat);
bdrv_register( &bdrv_qcow );
bdrv_register( &bdrv_vvfat );
}

View file

@ -10,61 +10,58 @@
#define BDRV_O_RDWR 0x0002
#define BDRV_O_ACCESS 0x0003
#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 */
#define BDRV_O_FILE 0x0010 /* open as a raw file (do not try to
use a disk image format on top of
it (default for
#define BDRV_O_FILE \
0x0010 /* open as a raw file (do not try to \
use a disk image format on top of \
it (default for \
bdrv_file_open()) */
typedef struct BlockDriver BlockDriver;
typedef struct SnapshotInfo QEMUSnapshotInfo;
typedef struct BlockDriverInfo BlockDriverInfo;
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_host_device;
extern BlockDriver bdrv_qcow;
extern BlockDriver bdrv_vvfat;
void bdrv_init(void);
int bdrv_create(BlockDriver *drv,
const char *filename, int64_t size_in_sectors,
const char *backing_file, int flags);
BlockDriverState *bdrv_new(const char *device_name);
void bdrv_delete(BlockDriverState *bs);
int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags);
int bdrv_open(BlockDriverState *bs, const char *filename, int flags);
void bdrv_init( void );
int bdrv_create( BlockDriver* drv, const char* filename, int64_t size_in_sectors, const char* backing_file, int flags );
BlockDriverState* bdrv_new( const char* device_name );
void bdrv_delete( BlockDriverState* bs );
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,
uint8_t *buf, int nb_sectors);
int bdrv_pread(BlockDriverState *bs, int64_t offset,
void *buf, int count);
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
const void *buf, int count);
int bdrv_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors );
int bdrv_pread( BlockDriverState* bs, int64_t offset, 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);
int64_t bdrv_getlength(BlockDriverState *bs);
void bdrv_flush(BlockDriverState *bs);
int bdrv_truncate( BlockDriverState* bs, int64_t offset );
int64_t bdrv_getlength( BlockDriverState* bs );
void bdrv_flush( BlockDriverState* bs );
/* timers */
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
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
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);
void qemu_del_timer(QEMUTimer *ts);
void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time);
int qemu_timer_pending(QEMUTimer *ts);
QEMUTimer* qemu_new_timer( QEMUClock* clock, QEMUTimerCB* cb, void* opaque );
void qemu_del_timer( QEMUTimer* ts );
void qemu_mod_timer( QEMUTimer* ts, int64_t expire_time );
int qemu_timer_pending( QEMUTimer* ts );
extern int64_t ticks_per_sec;

View file

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

View file

@ -6,86 +6,75 @@
#include <sys/types.h>
static __inline__ uint16_t swab16(uint16_t x)
{
return ((x & 0xff00) >> 8) |
((x & 0x00ff) << 8);
}
static __inline__ uint16_t swab16( uint16_t x ) { 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) |
((x & 0x00ff0000) >> 8) |
((x & 0x0000ff00) << 8) |
((x & 0x000000ff) << 24);
return ( ( x & 0xff000000 ) >> 24 ) | ( ( x & 0x00ff0000 ) >> 8 ) | ( ( x & 0x0000ff00 ) << 8 ) | ( ( x & 0x000000ff ) << 24 );
}
#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;
__asm__ __volatile__ ("lduha [%1] %2, %0"
: "=r" (x)
: "r" (p), "i" (ASI_PL));
__asm__ __volatile__( "lduha [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
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;
__asm__ __volatile__ ("lduwa [%1] %2, %0"
: "=r" (x)
: "r" (p), "i" (ASI_PL));
__asm__ __volatile__( "lduwa [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
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 */
: "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 */
: "r" (x), "r" (p), "i" (ASI_PL));
: "r"( x ), "r"( p ), "i"( ASI_PL ) );
}
#endif /* __sparc__ */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define le16_to_cpu(x) (x)
#define cpu_to_le16(x) (x)
#define le32_to_cpu(x) (x)
#define cpu_to_le32(x) (x)
# define le16_to_cpu( x ) ( x )
# define cpu_to_le16( x ) ( x )
# define le32_to_cpu( x ) ( x )
# define cpu_to_le32( x ) ( x )
#define load_le16(p) (*(p))
#define store_le16(p, x) (*(p) = (x))
#define load_le32(p) (*(p))
#define store_le32(p, x) (*(p) = (x))
# define load_le16( p ) ( *( p ) )
# define store_le16( p, x ) ( *( p ) = ( x ) )
# define load_le32( p ) ( *( p ) )
# define store_le32( p, x ) ( *( p ) = ( x ) )
#elif __BYTE_ORDER == __BIG_ENDIAN
#define le16_to_cpu(x) swab16(x)
#define cpu_to_le16(x) swab16(x)
#define le32_to_cpu(x) swab32(x)
#define cpu_to_le32(x) swab32(x)
# define le16_to_cpu( x ) swab16( x )
# define cpu_to_le16( x ) swab16( x )
# define le32_to_cpu( x ) swab32( x )
# define cpu_to_le32( x ) swab32( x )
#define load_le16(p) __load_le16(p)
#define store_le16(p, x) __store_le16(p, x)
#define load_le32(p) __load_le32(p)
#define store_le32(p, x) __store_le32(p, x)
# define load_le16( p ) __load_le16( p )
# define store_le16( p, x ) __store_le16( p, x )
# define load_le32( p ) __load_le32( p )
# define store_le32( p, x ) __store_le32( p, x )
#else
#error "Cannot determine host byteorder"
# error "Cannot determine host byteorder"
#endif
#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_ACCESS 4
typedef void (*gdb_syscall_complete_cb)(CPUState *env,
target_ulong ret, target_ulong err);
typedef void ( *gdb_syscall_complete_cb )( CPUState* env, target_ulong ret, target_ulong err );
void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...);
int use_gdb_syscalls(void);
void gdb_set_stop_cpu(CPUState *env);
void gdb_do_syscall( gdb_syscall_complete_cb cb, const char* fmt, ... );
int use_gdb_syscalls( void );
void gdb_set_stop_cpu( CPUState* env );
int gdb_poll(CPUState *);
int gdb_poll( CPUState* );
int gdb_queuesig (void);
int gdb_handlesig (CPUState *, int);
void gdb_exit(CPUState *, int);
void gdb_signalled(CPUState *, int);
int gdbserver_start(int);
void gdbserver_fork(CPUState *);
int gdb_queuesig( void );
int gdb_handlesig( CPUState*, int );
void gdb_exit( CPUState*, int );
void gdb_signalled( CPUState*, int );
int gdbserver_start( int );
void gdbserver_fork( CPUState* );
/* Get or set a register. Returns the size of the register. */
typedef int (*gdb_reg_cb)(CPUState *env, uint8_t *buf, int reg);
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);
typedef int ( *gdb_reg_cb )( CPUState* env, uint8_t* buf, int reg );
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 );
int gdbserver_isactive();

View file

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

View file

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

View file

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

View file

@ -3,10 +3,10 @@
#include <stddef.h>
static inline void prefetch(const void *x) {;}
static inline void prefetch( const void* x ) { ; }
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
# define offsetof( TYPE, MEMBER ) ( ( size_t )&( ( TYPE* )0 )->MEMBER )
#endif
/*
@ -14,8 +14,8 @@ static inline void prefetch(const void *x) {;}
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries.
*/
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)
#define LIST_POISON1 ( ( void* )0x00100100 )
#define LIST_POISON2 ( ( void* )0x00200200 )
/*
* Simple doubly linked list implementation.
@ -31,14 +31,15 @@ struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD_INIT( name ) { &( name ), &( name ) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define LIST_HEAD( name ) struct list_head name = LIST_HEAD_INIT( name )
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
#define INIT_LIST_HEAD( ptr ) \
do { \
( ptr )->next = ( ptr ); \
( ptr )->prev = ( ptr ); \
} while ( 0 )
/*
* 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
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
static inline void __list_add( struct list_head* new, struct list_head* prev, struct list_head* next )
{
next->prev = new;
new->next = next;
@ -64,10 +63,7 @@ static inline void __list_add(struct list_head *new,
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
static inline void list_add( struct list_head* new, struct list_head* head ) { __list_add( new, head, head->next ); }
/**
* 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.
* This is useful for implementing queues.
*/
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
__list_add(new, head->prev, head);
}
static inline void list_add_tail( struct list_head* new, struct list_head* head ) { __list_add( new, head->prev, head ); }
/*
* 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
* 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;
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
* 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->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.
* @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);
INIT_LIST_HEAD(entry);
__list_del( entry->prev, entry->next );
INIT_LIST_HEAD( entry );
}
/**
@ -123,10 +116,10 @@ static inline void list_del_init(struct list_head *entry)
* @list: the entry to move
* @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_add(list, head);
__list_del( list->prev, list->next );
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
* @head: the head that will follow our entry
*/
static inline void list_move_tail(struct list_head *list,
struct list_head *head)
static inline void list_move_tail( struct list_head* list, struct list_head* head )
{
__list_del(list->prev, list->next);
list_add_tail(list, head);
__list_del( list->prev, list->next );
list_add_tail( list, head );
}
/**
* list_empty - tests whether a list is empty
* @head: the list to test.
*/
static inline int list_empty(const struct list_head *head)
{
return head->next == head;
}
static inline int list_empty( const struct list_head* head ) { return head->next == head; }
/**
* 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.
*/
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;
return (next == head) && (next == head->prev);
struct list_head* next = head->next;
return ( next == head ) && ( next == head->prev );
}
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 )
{
struct list_head *first = list->next;
struct list_head *last = list->prev;
struct list_head *at = head->next;
struct list_head* first = list->next;
struct list_head* last = list->prev;
struct list_head* at = head->next;
first->prev = head;
head->next = first;
@ -187,10 +175,10 @@ static inline void __list_splice(struct list_head *list,
* @list: the new list to add.
* @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))
__list_splice(list, head);
if ( !list_empty( list ) )
__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
*/
static inline void list_splice_init(struct list_head *list,
struct list_head *head)
static inline void list_splice_init( struct list_head* list, struct list_head* head )
{
if (!list_empty(list)) {
__list_splice(list, head);
INIT_LIST_HEAD(list);
if ( !list_empty( list ) ) {
__list_splice( list, head );
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.
* @member: the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
container_of(ptr, type, member)
#define list_entry( ptr, type, member ) container_of( ptr, type, member )
/**
* list_for_each - iterate over a list
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
pos = pos->next)
#define list_for_each( pos, head ) for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = pos->next )
/**
* __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
* or 1 entry) most of the time.
*/
#define __list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)
#define __list_for_each( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = pos->next )
/**
* list_for_each_prev - iterate over a list backwards
* @pos: the &struct list_head to use as a loop counter.
* @head: the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
pos = pos->prev)
#define list_for_each_prev( pos, head ) 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
@ -255,9 +236,7 @@ static inline void list_splice_init(struct list_head *list,
* @n: another &struct list_head to use as temporary storage
* @head: the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)
#define list_for_each_safe( pos, n, head ) for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = n, n = pos->next )
/**
* 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.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
#define list_for_each_entry( pos, head, member ) \
for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
pos = list_entry( pos->member.next, typeof( *pos ), member ) )
/**
* 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.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_reverse(pos, head, member) \
for (pos = list_entry((head)->prev, typeof(*pos), member); \
prefetch(pos->member.prev), &pos->member != (head); \
pos = list_entry(pos->member.prev, typeof(*pos), member))
#define list_for_each_entry_reverse( pos, head, member ) \
for ( pos = list_entry( ( head )->prev, typeof( *pos ), member ); prefetch( pos->member.prev ), &pos->member != ( head ); \
pos = list_entry( pos->member.prev, typeof( *pos ), member ) )
/**
* 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
* @member: the name of the list_struct within the struct.
*/
#define list_prepare_entry(pos, head, member) \
((pos) ? : list_entry(head, typeof(*pos), member))
#define list_prepare_entry( pos, head, member ) ( ( pos ) ?: list_entry( head, typeof( *pos ), member ) )
/**
* 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.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_continue(pos, head, member) \
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = list_entry(pos->member.next, typeof(*pos), member))
#define list_for_each_entry_continue( pos, head, member ) \
for ( pos = list_entry( pos->member.next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
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
@ -310,11 +285,9 @@ static inline void list_splice_init(struct list_head *list,
* @head: the head for your list.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member) \
for (pos = list_entry((head)->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))
#define list_for_each_entry_safe( pos, n, head, member ) \
for ( pos = list_entry( ( head )->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 ) )
/**
* 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.
* @member: the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
for (pos = list_entry((head)->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))
#define list_for_each_entry_safe_reverse( pos, n, head, member ) \
for ( pos = list_entry( ( head )->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 ) )
/**
* 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()
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_rcu(pos, head) \
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
pos = rcu_dereference(pos->next))
#define list_for_each_rcu( pos, head ) \
for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = rcu_dereference( pos->next ) )
#define __list_for_each_rcu(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = rcu_dereference(pos->next))
#define __list_for_each_rcu( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = rcu_dereference( pos->next ) )
/**
* 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()
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_safe_rcu(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = rcu_dereference(n), n = pos->next)
#define list_for_each_safe_rcu( pos, n, head ) \
for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = rcu_dereference( n ), n = pos->next )
/**
* 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()
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_entry_rcu(pos, head, member) \
for (pos = list_entry((head)->next, typeof(*pos), member); \
prefetch(pos->member.next), &pos->member != (head); \
pos = rcu_dereference(list_entry(pos->member.next, \
typeof(*pos), member)))
#define list_for_each_entry_rcu( pos, head, member ) \
for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
pos = rcu_dereference( list_entry( pos->member.next, typeof( *pos ), member ) ) )
/**
* 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()
* as long as the traversal is guarded by rcu_read_lock().
*/
#define list_for_each_continue_rcu(pos, head) \
for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \
(pos) = rcu_dereference((pos)->next))
#define list_for_each_continue_rcu( pos, head ) \
for ( ( pos ) = ( pos )->next; prefetch( ( pos )->next ), ( pos ) != ( head ); ( pos ) = rcu_dereference( ( pos )->next ) )
/*
* 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_node *first;
struct hlist_node* first;
};
struct hlist_node {
@ -408,32 +371,26 @@ struct hlist_node {
};
#define HLIST_HEAD_INIT { .first = NULL }
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
#define HLIST_HEAD( name ) struct hlist_head name = { .first = NULL }
#define INIT_HLIST_HEAD( ptr ) ( ( ptr )->first = NULL )
#define INIT_HLIST_NODE( ptr ) ( ( ptr )->next = NULL, ( ptr )->pprev = NULL )
static inline int hlist_unhashed(const struct hlist_node *h)
{
return !h->pprev;
}
static inline int hlist_unhashed( const struct hlist_node* h ) { return !h->pprev; }
static inline int hlist_empty(const struct hlist_head *h)
{
return !h->first;
}
static inline int hlist_empty( const struct hlist_head* h ) { 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 **pprev = n->pprev;
struct hlist_node* next = n->next;
struct hlist_node** pprev = n->pprev;
*pprev = next;
if (next)
if ( next )
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->pprev = LIST_POISON2;
}
@ -457,64 +414,71 @@ static inline void hlist_del(struct hlist_node *n)
* the _rcu list-traversal primitives, such as
* 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;
}
static inline void hlist_del_init(struct hlist_node *n)
static inline void hlist_del_init( struct hlist_node* n )
{
if (n->pprev) {
__hlist_del(n);
INIT_HLIST_NODE(n);
if ( n->pprev ) {
__hlist_del( 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;
if (first)
if ( first )
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
}
/* next must be != NULL */
static inline void hlist_add_before(struct hlist_node *n,
struct hlist_node *next)
static inline void hlist_add_before( struct hlist_node* n, struct hlist_node* next )
{
n->pprev = next->pprev;
n->next = next;
next->pprev = &n->next;
*(n->pprev) = n;
*( n->pprev ) = n;
}
static inline void hlist_add_after(struct hlist_node *n,
struct hlist_node *next)
static inline void hlist_add_after( struct hlist_node* n, struct hlist_node* next )
{
next->next = n->next;
n->next = next;
next->pprev = &n->next;
if(next->next)
if ( 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) \
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
pos = pos->next)
#define hlist_for_each( pos, head ) \
for ( pos = ( head )->first; pos && ( { \
prefetch( pos->next ); \
1; \
} ); \
pos = pos->next )
#define hlist_for_each_safe(pos, n, head) \
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
pos = n)
#define hlist_for_each_safe( pos, n, head ) \
for ( pos = ( head )->first; pos && ( { \
n = pos->next; \
1; \
} ); \
pos = n )
#define hlist_for_each_rcu(pos, head) \
for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \
(pos) = rcu_dereference((pos)->next))
#define hlist_for_each_rcu( pos, head ) \
for ( ( pos ) = ( head )->first; pos && ( { \
prefetch( ( pos )->next ); \
1; \
} ); \
( pos ) = rcu_dereference( ( pos )->next ) )
/**
* 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.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry(tpos, pos, head, member) \
for (pos = (head)->first; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
#define hlist_for_each_entry( tpos, pos, head, member ) \
for ( pos = ( head )->first; pos && ( { \
prefetch( pos->next ); \
1; \
} ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = pos->next )
/**
* 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.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_continue(tpos, pos, member) \
for (pos = (pos)->next; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
#define hlist_for_each_entry_continue( tpos, pos, member ) \
for ( pos = ( pos )->next; pos && ( { \
prefetch( pos->next ); \
1; \
} ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = pos->next )
/**
* 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.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_from(tpos, pos, member) \
for (; pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = pos->next)
#define hlist_for_each_entry_from( tpos, pos, member ) \
for ( ; pos && ( { \
prefetch( 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
@ -560,11 +540,16 @@ static inline void hlist_add_after(struct hlist_node *n,
* @head: the head for your list.
* @member: the name of the hlist_node within the struct.
*/
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
for (pos = (head)->first; \
pos && ({ n = pos->next; 1; }) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = n)
#define hlist_for_each_entry_safe( tpos, pos, n, head, member ) \
for ( pos = ( head )->first; pos && ( { \
n = pos->next; \
1; \
} ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = n )
/**
* 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()
* as long as the traversal is guarded by rcu_read_lock().
*/
#define hlist_for_each_entry_rcu(tpos, pos, head, member) \
for (pos = (head)->first; \
pos && ({ prefetch(pos->next); 1;}) && \
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
pos = rcu_dereference(pos->next))
#define hlist_for_each_entry_rcu( tpos, pos, head, member ) \
for ( pos = ( head )->first; pos && ( { \
prefetch( pos->next ); \
1; \
} ) && \
( { \
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
1; \
} ); \
pos = rcu_dereference( pos->next ) )
#endif /* _LINUX_LIST_H */

View file

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

View file

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

View file

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

View file

@ -12,7 +12,6 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t adccon;
uint32_t adctsc;
@ -21,241 +20,208 @@ typedef struct {
uint32_t adcdat1;
unsigned int nr_regs;
s3c2410_offset_t *regs;
s3c2410_offset_t* regs;
} s3c2410_adc_t;
static int
s3c2410_adc_data_init(s3c2410_adc_t *adc)
static int s3c2410_adc_data_init( s3c2410_adc_t* adc )
{
s3c2410_offset_t regs[] = {
S3C2410_OFFSET(ADC, ADCCON, 0x00003fc4, adc->adccon),
S3C2410_OFFSET(ADC, ADCTSC, 0x00000058, adc->adctsc),
S3C2410_OFFSET(ADC, ADCDLY, 0x000000ff, adc->adcdly),
S3C2410_OFFSET(ADC, ADCDAT0, 0x3ff, adc->adcdat0),
S3C2410_OFFSET(ADC, ADCDAT1, 0x3ff, adc->adcdat1),
S3C2410_OFFSET( ADC, ADCCON, 0x00003fc4, adc->adccon ), S3C2410_OFFSET( ADC, ADCTSC, 0x00000058, adc->adctsc ),
S3C2410_OFFSET( ADC, ADCDLY, 0x000000ff, adc->adcdly ), 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));
if (NULL == adc->regs) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
adc->regs = malloc( sizeof( regs ) );
if ( NULL == adc->regs ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
memcpy(adc->regs, regs, sizeof(regs));
adc->nr_regs = sizeof(regs) / sizeof(regs[0]);
memcpy( adc->regs, regs, sizeof( regs ) );
adc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0;
}
static uint32_t
s3c2410_adc_read(void *opaque, target_phys_addr_t offset)
static uint32_t s3c2410_adc_read( void* opaque, target_phys_addr_t offset )
{
s3c2410_adc_t *adc = opaque;
s3c2410_offset_t *reg;
s3c2410_adc_t* adc = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(adc, offset)) {
return ~(0);
if ( !S3C2410_OFFSET_OK( adc, offset ) ) {
return ~( 0 );
}
reg = S3C2410_OFFSET_ENTRY(adc, offset);
reg = S3C2410_OFFSET_ENTRY( adc, offset );
#ifdef DEBUG_S3C2410_ADC
printf("read %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-adc", S3C2410_ADC_BASE,
reg->name, (unsigned long) offset, *(reg->datap));
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset,
*( reg->datap ) );
#endif
switch (offset) {
switch ( offset ) {
case S3C2410_ADC_ADCCON:
*(reg->datap) &= ~(0x0001);
*(reg->datap) |= 0x8000;
*( reg->datap ) &= ~( 0x0001 );
*( reg->datap ) |= 0x8000;
break;
default:
break;
}
return *(reg->datap);
return *( reg->datap );
}
static void
s3c2410_adc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
static void s3c2410_adc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
{
s3c2410_adc_t *adc = opaque;
s3c2410_offset_t *reg;
s3c2410_adc_t* adc = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(adc, offset)) {
if ( !S3C2410_OFFSET_OK( adc, offset ) ) {
return;
}
reg = S3C2410_OFFSET_ENTRY(adc, offset);
reg = S3C2410_OFFSET_ENTRY( adc, offset );
#ifdef DEBUG_S3C2410_ADC
printf("write %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-adc", S3C2410_ADC_BASE,
reg->name, (unsigned long) offset, data);
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset, data );
#endif
*(reg->datap) = data;
*( reg->datap ) = data;
}
static int
s3c2410_adc_load(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_adc_load( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_adc_t *adc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t* reg;
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < adc->nr_regs; i++) {
reg = &adc->regs[i];
for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
}
static int
s3c2410_adc_save(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_adc_save( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_adc_t *adc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < adc->nr_regs; i++) {
reg = &adc->regs[i];
for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap));
x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
}
return 0;
}
static int
s3c2410_adc_reset(x49gp_module_t *module, x49gp_reset_t reset)
static int s3c2410_adc_reset( x49gp_module_t* module, x49gp_reset_t reset )
{
s3c2410_adc_t *adc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_adc_t* adc = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < adc->nr_regs; i++) {
reg = &adc->regs[i];
for ( i = 0; i < adc->nr_regs; i++ ) {
reg = &adc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
*( reg->datap ) = reg->reset;
}
return 0;
}
static CPUReadMemoryFunc *s3c2410_adc_readfn[] =
{
s3c2410_adc_read,
s3c2410_adc_read,
s3c2410_adc_read
};
static CPUReadMemoryFunc* s3c2410_adc_readfn[] = { s3c2410_adc_read, s3c2410_adc_read, s3c2410_adc_read };
static CPUWriteMemoryFunc *s3c2410_adc_writefn[] =
{
s3c2410_adc_write,
s3c2410_adc_write,
s3c2410_adc_write
};
static CPUWriteMemoryFunc* s3c2410_adc_writefn[] = { s3c2410_adc_write, s3c2410_adc_write, s3c2410_adc_write };
static int
s3c2410_adc_init(x49gp_module_t *module)
static int s3c2410_adc_init( x49gp_module_t* module )
{
s3c2410_adc_t *adc;
s3c2410_adc_t* adc;
int iotype;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
adc = malloc(sizeof(s3c2410_adc_t));
if (NULL == adc) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
adc = malloc( sizeof( s3c2410_adc_t ) );
if ( NULL == adc ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
if (s3c2410_adc_data_init(adc)) {
free(adc);
if ( s3c2410_adc_data_init( adc ) ) {
free( adc );
return -ENOMEM;
}
module->user_data = adc;
iotype = cpu_register_io_memory(s3c2410_adc_readfn,
s3c2410_adc_writefn, adc);
iotype = cpu_register_io_memory( s3c2410_adc_readfn, s3c2410_adc_writefn, adc );
#ifdef DEBUG_S3C2410_ADC
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#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;
}
static int
s3c2410_adc_exit(x49gp_module_t *module)
static int s3c2410_adc_exit( x49gp_module_t* module )
{
s3c2410_adc_t *adc;
s3c2410_adc_t* adc;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
if (module->user_data) {
if ( module->user_data ) {
adc = module->user_data;
if (adc->regs)
free(adc->regs);
free(adc);
if ( adc->regs )
free( adc->regs );
free( adc );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
}
int
x49gp_s3c2410_adc_init(x49gp_t *x49gp)
int x49gp_s3c2410_adc_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-adc",
s3c2410_adc_init,
s3c2410_adc_exit,
s3c2410_adc_reset,
s3c2410_adc_load,
s3c2410_adc_save,
NULL, &module)) {
if ( x49gp_module_init( x49gp, "s3c2410-adc", s3c2410_adc_init, s3c2410_adc_exit, s3c2410_adc_reset, s3c2410_adc_load, s3c2410_adc_save,
NULL, &module ) ) {
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 $
*/
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
@ -15,260 +14,247 @@
#include "qemu-git/cpu-all.h"
static int
s3c2410_arm_load(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_arm_load( x49gp_module_t* module, GKeyFile* key )
{
struct CPUARMState *env = module->user_data;
char name[32];
struct CPUARMState* env = module->user_data;
char name[ 32 ];
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
cpu_reset(env);
tlb_flush(env, 1);
cpu_reset( env );
tlb_flush( env, 1 );
for (i = 0; i < (sizeof(env->regs) / sizeof(env->regs[0])); i++) {
sprintf(name, "reg-%02u", i);
if (x49gp_module_get_u32(module, key, name, 0, &env->regs[i]))
for ( i = 0; i < ( sizeof( env->regs ) / sizeof( env->regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->regs[ i ] ) )
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;
if (x49gp_module_get_u32(module, key, "spsr", 0, &env->spsr))
if ( x49gp_module_get_u32( module, key, "spsr", 0, &env->spsr ) )
error = -EAGAIN;
for (i = 0; i < (sizeof(env->banked_spsr) / sizeof(env->banked_spsr[0])); i++) {
sprintf(name, "banked-spsr-%02u", i);
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_spsr[i]))
for ( i = 0; i < ( sizeof( env->banked_spsr ) / sizeof( env->banked_spsr[ 0 ] ) ); i++ ) {
sprintf( name, "banked-spsr-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_spsr[ i ] ) )
error = -EAGAIN;
}
for (i = 0; i < (sizeof(env->banked_r13) / sizeof(env->banked_r13[0])); i++) {
sprintf(name, "banked-r13-%02u", i);
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_r13[i]))
for ( i = 0; i < ( sizeof( env->banked_r13 ) / sizeof( env->banked_r13[ 0 ] ) ); i++ ) {
sprintf( name, "banked-r13-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_r13[ i ] ) )
error = -EAGAIN;
}
for (i = 0; i < (sizeof(env->banked_r14) / sizeof(env->banked_r14[0])); i++) {
sprintf(name, "banked-r14-%02u", i);
if (x49gp_module_get_u32(module, key, name, 0, &env->banked_r14[i]))
for ( i = 0; i < ( sizeof( env->banked_r14 ) / sizeof( env->banked_r14[ 0 ] ) ); i++ ) {
sprintf( name, "banked-r14-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->banked_r14[ i ] ) )
error = -EAGAIN;
}
for (i = 0; i < (sizeof(env->usr_regs) / sizeof(env->usr_regs[0])); i++) {
sprintf(name, "reg-usr-%02u", i);
if (x49gp_module_get_u32(module, key, name,
0, &env->usr_regs[i]))
for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-usr-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->usr_regs[ i ] ) )
error = -EAGAIN;
}
for (i = 0; i < (sizeof(env->fiq_regs) / sizeof(env->fiq_regs[0])); i++) {
sprintf(name, "reg-fiq-%02u", i);
if (x49gp_module_get_u32(module, key, name,
0, &env->fiq_regs[i]))
for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-fiq-%02u", i );
if ( x49gp_module_get_u32( module, key, name, 0, &env->fiq_regs[ i ] ) )
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;
if (x49gp_module_get_u32(module, key, "VF", 0, &env->VF))
if ( x49gp_module_get_u32( module, key, "VF", 0, &env->VF ) )
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;
if (x49gp_module_get_u32(module, key, "ZF", 0, &env->ZF))
if ( x49gp_module_get_u32( module, key, "ZF", 0, &env->ZF ) )
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;
if (x49gp_module_get_u32(module, key, "thumb", 0, &env->thumb))
if ( x49gp_module_get_u32( module, key, "thumb", 0, &env->thumb ) )
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
if (x49gp_module_get_u32(module, key, "features", 0, &env->features))
if ( x49gp_module_get_u32( module, key, "features", 0, &env->features ) )
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;
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;
if (x49gp_module_get_u32(module, key, "halted", 0, &env->halted))
if ( x49gp_module_get_u32( module, key, "halted", 0, &env->halted ) )
error = -EAGAIN;
env->exception_index = -1;
if (0 == error) {
if (env->halted)
if ( 0 == error ) {
if ( env->halted )
module->x49gp->arm_idle = 1;
} 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;
}
static int
s3c2410_arm_save(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_arm_save( x49gp_module_t* module, GKeyFile* key )
{
struct CPUARMState *env = module->user_data;
char name[32];
struct CPUARMState* env = module->user_data;
char name[ 32 ];
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < (sizeof(env->regs) / sizeof(env->regs[0])); i++) {
sprintf(name, "reg-%02u", i);
x49gp_module_set_u32(module, key, name, env->regs[i]);
for ( i = 0; i < ( sizeof( env->regs ) / sizeof( env->regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-%02u", 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, "spsr", env->spsr);
for (i = 0; i < (sizeof(env->banked_spsr) / sizeof(env->banked_spsr[0])); i++) {
sprintf(name, "banked-spsr-%02u", i);
x49gp_module_set_u32(module, key, name, env->banked_spsr[i]);
x49gp_module_set_u32( module, key, "cpsr", env->uncached_cpsr );
x49gp_module_set_u32( module, key, "spsr", env->spsr );
for ( i = 0; i < ( sizeof( env->banked_spsr ) / sizeof( env->banked_spsr[ 0 ] ) ); i++ ) {
sprintf( name, "banked-spsr-%02u", 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++) {
sprintf(name, "banked-r13-%02u", i);
x49gp_module_set_u32(module, key, name, env->banked_r13[i]);
for ( i = 0; i < ( sizeof( env->banked_r13 ) / sizeof( env->banked_r13[ 0 ] ) ); i++ ) {
sprintf( name, "banked-r13-%02u", 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++) {
sprintf(name, "banked-r14-%02u", i);
x49gp_module_set_u32(module, key, name, env->banked_r14[i]);
for ( i = 0; i < ( sizeof( env->banked_r14 ) / sizeof( env->banked_r14[ 0 ] ) ); i++ ) {
sprintf( name, "banked-r14-%02u", 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++) {
sprintf(name, "reg-usr-%02u", i);
x49gp_module_set_u32(module, key, name, env->usr_regs[i]);
for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-usr-%02u", 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++) {
sprintf(name, "reg-fiq-%02u", i);
x49gp_module_set_u32(module, key, name, env->fiq_regs[i]);
for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
sprintf( name, "reg-fiq-%02u", 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, "VF", env->VF);
x49gp_module_set_u32(module, key, "NF", env->NF);
x49gp_module_set_u32(module, key, "ZF", env->ZF);
x49gp_module_set_u32(module, key, "QF", env->QF);
x49gp_module_set_int(module, key, "thumb", env->thumb);
x49gp_module_set_u32( module, key, "CF", env->CF );
x49gp_module_set_u32( module, key, "VF", env->VF );
x49gp_module_set_u32( module, key, "NF", env->NF );
x49gp_module_set_u32( module, key, "ZF", env->ZF );
x49gp_module_set_u32( module, key, "QF", env->QF );
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-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-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-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-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-insn", env->cp15.c2_insn);
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-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-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-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-context", env->cp15.c13_context);
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-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-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-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-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-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-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-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-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-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, "interrupt-request", env->interrupt_request);
x49gp_module_set_int(module, key, "halted", env->halted);
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, "halted", env->halted );
return 0;
}
static int
s3c2410_arm_reset(x49gp_module_t *module, x49gp_reset_t reset)
static int 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
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
cpu_reset(env);
tlb_flush(env, 1);
cpu_reset( env );
tlb_flush( env, 1 );
return 0;
}
static int
s3c2410_arm_init(x49gp_module_t *module)
static int s3c2410_arm_init( x49gp_module_t* module )
{
x49gp_t *x49gp = module->x49gp;
x49gp_t* x49gp = module->x49gp;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
module->user_data = x49gp->env;
return 0;
}
static int
s3c2410_arm_exit(x49gp_module_t *module)
static int s3c2410_arm_exit( x49gp_module_t* module )
{
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
return 0;
}
int
x49gp_s3c2410_arm_init(x49gp_t *x49gp)
int x49gp_s3c2410_arm_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-arm",
s3c2410_arm_init,
s3c2410_arm_exit,
s3c2410_arm_reset,
s3c2410_arm_load,
s3c2410_arm_save,
NULL, &module)) {
if ( x49gp_module_init( x49gp, "s3c2410-arm", s3c2410_arm_init, s3c2410_arm_exit, s3c2410_arm_reset, s3c2410_arm_load, s3c2410_arm_save,
NULL, &module ) ) {
return -1;
}
return x49gp_module_register(module);
return x49gp_module_register( module );
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -14,7 +14,6 @@
#include "s3c2410.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t rtccon;
uint32_t ticnt;
@ -35,469 +34,415 @@ typedef struct {
uint32_t bcdyear;
unsigned int nr_regs;
s3c2410_offset_t *regs;
s3c2410_offset_t* regs;
x49gp_t *x49gp;
x49gp_timer_t *tick_timer;
x49gp_timer_t *alarm_timer;
x49gp_t* x49gp;
x49gp_timer_t* tick_timer;
x49gp_timer_t* alarm_timer;
int64_t interval; /* us */
int64_t expires; /* us */
} 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(RTC, RTCCON, 0x00, rtc->rtccon),
S3C2410_OFFSET(RTC, TICNT, 0x00, rtc->ticnt),
S3C2410_OFFSET(RTC, RTCALM, 0x00, rtc->rtcalm),
S3C2410_OFFSET(RTC, ALMSEC, 0x00, rtc->almsec),
S3C2410_OFFSET(RTC, ALMMIN, 0x00, rtc->almmin),
S3C2410_OFFSET(RTC, ALMHOUR, 0x00, rtc->almhour),
S3C2410_OFFSET(RTC, ALMDATE, 0x01, rtc->almdate),
S3C2410_OFFSET(RTC, ALMMON, 0x01, rtc->almmon),
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)
};
s3c2410_offset_t regs[] = { S3C2410_OFFSET( RTC, RTCCON, 0x00, rtc->rtccon ), S3C2410_OFFSET( RTC, TICNT, 0x00, rtc->ticnt ),
S3C2410_OFFSET( RTC, RTCALM, 0x00, rtc->rtcalm ), S3C2410_OFFSET( RTC, ALMSEC, 0x00, rtc->almsec ),
S3C2410_OFFSET( RTC, ALMMIN, 0x00, rtc->almmin ), S3C2410_OFFSET( RTC, ALMHOUR, 0x00, rtc->almhour ),
S3C2410_OFFSET( RTC, ALMDATE, 0x01, rtc->almdate ), S3C2410_OFFSET( RTC, ALMMON, 0x01, rtc->almmon ),
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));
if (NULL == rtc->regs) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
rtc->regs = malloc( sizeof( regs ) );
if ( NULL == rtc->regs ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
memcpy(rtc->regs, regs, sizeof(regs));
rtc->nr_regs = sizeof(regs) / sizeof(regs[0]);
memcpy( rtc->regs, regs, sizeof( regs ) );
rtc->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0;
}
static __inline__ uint32_t bin2bcd(uint32_t bin)
{
return ((bin / 10) << 4) | (bin % 10);
}
static __inline__ uint32_t bin2bcd( uint32_t bin ) { return ( ( bin / 10 ) << 4 ) | ( bin % 10 ); }
static __inline__ uint32_t bcd2bin(uint32_t bcd)
{
return ((bcd >> 4) * 10) + (bcd & 0x0f);
}
static __inline__ uint32_t bcd2bin( uint32_t bcd ) { return ( ( bcd >> 4 ) * 10 ) + ( bcd & 0x0f ); }
static void
s3c2410_rtc_timeout(void * user_data)
static void s3c2410_rtc_timeout( void* user_data )
{
s3c2410_rtc_t *rtc = user_data;
x49gp_t *x49gp = rtc->x49gp;
s3c2410_rtc_t* rtc = user_data;
x49gp_t* x49gp = rtc->x49gp;
int64_t now, us;
if (!(rtc->ticnt & 0x80)) {
if ( !( rtc->ticnt & 0x80 ) ) {
return;
}
#ifdef DEBUG_S3C2410_RTC
printf("RTC: assert TICK interrupt\n");
printf( "RTC: assert TICK interrupt\n" );
#endif
s3c2410_intc_assert(x49gp, INT_TICK, 0);
s3c2410_intc_assert( x49gp, INT_TICK, 0 );
now = x49gp_get_clock();
while (rtc->expires <= now) {
while ( rtc->expires <= now ) {
rtc->expires += rtc->interval;
}
us = rtc->expires - now;
if (us < 1000)
if ( us < 1000 )
us = 1000;
#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
x49gp_mod_timer(rtc->tick_timer, rtc->expires);
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
}
static int
s3c2410_rtc_set_ticnt(s3c2410_rtc_t *rtc)
static int s3c2410_rtc_set_ticnt( s3c2410_rtc_t* rtc )
{
int64_t now, us;
if (x49gp_timer_pending(rtc->tick_timer)) {
x49gp_del_timer(rtc->tick_timer);
if ( x49gp_timer_pending( rtc->tick_timer ) ) {
x49gp_del_timer( rtc->tick_timer );
#ifdef DEBUG_S3C2410_RTC
printf("RTC: stop TICK timer\n");
printf( "RTC: stop TICK timer\n" );
#endif
}
if (!(rtc->ticnt & 0x80)) {
if ( !( rtc->ticnt & 0x80 ) ) {
return 0;
}
us = (((rtc->ticnt & 0x7f) + 1) * 1000000) / 128;
us = ( ( ( rtc->ticnt & 0x7f ) + 1 ) * 1000000 ) / 128;
rtc->interval = us;
if (rtc->interval < 1000)
if ( rtc->interval < 1000 )
rtc->interval = 1000;
now = x49gp_get_clock();
rtc->expires = now + rtc->interval;
us = rtc->expires - now;
if (us < 1000)
if ( us < 1000 )
us = 1000;
#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
x49gp_mod_timer(rtc->tick_timer, rtc->expires);
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
return 0;
}
static void
s3c2410_rtc_alarm(void * user_data)
static void s3c2410_rtc_alarm( void* user_data )
{
s3c2410_rtc_t *rtc = user_data;
x49gp_t *x49gp = rtc->x49gp;
struct tm *tm;
s3c2410_rtc_t* rtc = user_data;
x49gp_t* x49gp = rtc->x49gp;
struct tm* tm;
struct timeval tv;
int64_t now, us;
int match = 1;
if (!(rtc->rtcalm & 0x40)) {
if ( !( rtc->rtcalm & 0x40 ) ) {
return;
}
gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
gettimeofday( &tv, NULL );
tm = localtime( &tv.tv_sec );
now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec;
if (match && (rtc->rtcalm & 0x01)) {
if (tm->tm_sec != bcd2bin(rtc->almsec))
if ( match && ( rtc->rtcalm & 0x01 ) ) {
if ( tm->tm_sec != bcd2bin( rtc->almsec ) )
match = 0;
}
if (match && (rtc->rtcalm & 0x02)) {
if (tm->tm_min != bcd2bin(rtc->almmin))
if ( match && ( rtc->rtcalm & 0x02 ) ) {
if ( tm->tm_min != bcd2bin( rtc->almmin ) )
match = 0;
}
if (match && (rtc->rtcalm & 0x04)) {
if (tm->tm_hour != bcd2bin(rtc->almhour))
if ( match && ( rtc->rtcalm & 0x04 ) ) {
if ( tm->tm_hour != bcd2bin( rtc->almhour ) )
match = 0;
}
if (match && (rtc->rtcalm & 0x08)) {
if (tm->tm_mday != bcd2bin(rtc->almdate))
if ( match && ( rtc->rtcalm & 0x08 ) ) {
if ( tm->tm_mday != bcd2bin( rtc->almdate ) )
match = 0;
}
if (match && (rtc->rtcalm & 0x10)) {
if ((tm->tm_mon + 1) != bcd2bin(rtc->almmon))
if ( match && ( rtc->rtcalm & 0x10 ) ) {
if ( ( tm->tm_mon + 1 ) != bcd2bin( rtc->almmon ) )
match = 0;
}
if (match && (rtc->rtcalm & 0x20)) {
if ((tm->tm_year % 100) != bcd2bin(rtc->almyear))
if ( match && ( rtc->rtcalm & 0x20 ) ) {
if ( ( tm->tm_year % 100 ) != bcd2bin( rtc->almyear ) )
match = 0;
}
if (match) {
if ( match ) {
#ifdef DEBUG_S3C2410_RTC
printf("RTC: assert ALARM interrupt\n");
printf( "RTC: assert ALARM interrupt\n" );
#endif
s3c2410_intc_assert(x49gp, INT_RTC, 0);
s3c2410_intc_assert( x49gp, INT_RTC, 0 );
}
#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
x49gp_mod_timer(rtc->alarm_timer, now + us);
x49gp_mod_timer( rtc->alarm_timer, now + us );
}
static int
s3c2410_rtc_set_rtcalm(s3c2410_rtc_t *rtc)
static int s3c2410_rtc_set_rtcalm( s3c2410_rtc_t* rtc )
{
struct timeval tv;
int64_t now, us;
if (!(rtc->rtcalm & 0x40)) {
x49gp_del_timer(rtc->alarm_timer);
if ( !( rtc->rtcalm & 0x40 ) ) {
x49gp_del_timer( rtc->alarm_timer );
return 0;
}
gettimeofday(&tv, NULL);
gettimeofday( &tv, NULL );
now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec;
#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
x49gp_mod_timer(rtc->alarm_timer, now + us);
x49gp_mod_timer( rtc->alarm_timer, now + us );
return 0;
}
static uint32_t
s3c2410_rtc_read(void *opaque, target_phys_addr_t offset)
static uint32_t s3c2410_rtc_read( void* opaque, target_phys_addr_t offset )
{
s3c2410_rtc_t *rtc = opaque;
s3c2410_offset_t *reg;
s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) {
return ~(0);
if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return ~( 0 );
}
reg = S3C2410_OFFSET_ENTRY(rtc, offset);
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
if (S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR) {
struct tm *tm;
if ( S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR ) {
struct tm* tm;
struct timeval tv;
gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
gettimeofday( &tv, NULL );
tm = localtime( &tv.tv_sec );
switch (offset) {
switch ( offset ) {
case S3C2410_RTC_BCDSEC:
*(reg->datap) = bin2bcd(tm->tm_sec);
*( reg->datap ) = bin2bcd( tm->tm_sec );
break;
case S3C2410_RTC_BCDMIN:
*(reg->datap) = bin2bcd(tm->tm_min);
*( reg->datap ) = bin2bcd( tm->tm_min );
break;
case S3C2410_RTC_BCDHOUR:
*(reg->datap) = bin2bcd(tm->tm_hour);
*( reg->datap ) = bin2bcd( tm->tm_hour );
break;
case S3C2410_RTC_BCDDATE:
*(reg->datap) = bin2bcd(tm->tm_mday);
*( reg->datap ) = bin2bcd( tm->tm_mday );
break;
case S3C2410_RTC_BCDDAY:
*(reg->datap) = bin2bcd(tm->tm_wday + 1);
*( reg->datap ) = bin2bcd( tm->tm_wday + 1 );
break;
case S3C2410_RTC_BCDMON:
*(reg->datap) = bin2bcd(tm->tm_mon + 1);
*( reg->datap ) = bin2bcd( tm->tm_mon + 1 );
break;
case S3C2410_RTC_BCDYEAR:
*(reg->datap) = bin2bcd(tm->tm_year % 100);
*( reg->datap ) = bin2bcd( tm->tm_year % 100 );
break;
}
}
#ifdef DEBUG_S3C2410_RTC
printf("read %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-rtc", S3C2410_RTC_BASE,
reg->name, (unsigned long) offset, *(reg->datap));
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset,
*( reg->datap ) );
#endif
return *(reg->datap);
return *( reg->datap );
}
static void
s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
static void s3c2410_rtc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
{
s3c2410_rtc_t *rtc = opaque;
s3c2410_offset_t *reg;
s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) {
if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return;
}
reg = S3C2410_OFFSET_ENTRY(rtc, offset);
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
#ifdef DEBUG_S3C2410_RTC
printf("write %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-rtc", S3C2410_RTC_BASE,
reg->name, (unsigned long) offset, data);
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset, data );
#endif
switch (offset) {
switch ( offset ) {
case S3C2410_RTC_TICNT:
*(reg->datap) = data;
s3c2410_rtc_set_ticnt(rtc);
*( reg->datap ) = data;
s3c2410_rtc_set_ticnt( rtc );
break;
case S3C2410_RTC_RTCALM:
*(reg->datap) = data;
s3c2410_rtc_set_rtcalm(rtc);
*( reg->datap ) = data;
s3c2410_rtc_set_rtcalm( rtc );
break;
default:
*(reg->datap) = data;
*( reg->datap ) = data;
break;
}
}
static int
s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_rtc_load( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_rtc_t *rtc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t* reg;
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < rtc->nr_regs; i++) {
reg = &rtc->regs[i];
for ( i = 0; i < rtc->nr_regs; i++ ) {
reg = &rtc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
s3c2410_rtc_set_ticnt(rtc);
s3c2410_rtc_set_rtcalm(rtc);
s3c2410_rtc_set_ticnt( rtc );
s3c2410_rtc_set_rtcalm( rtc );
return error;
}
static int
s3c2410_rtc_save(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_rtc_save( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_rtc_t *rtc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < rtc->nr_regs; i++) {
reg = &rtc->regs[i];
for ( i = 0; i < rtc->nr_regs; i++ ) {
reg = &rtc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap));
x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
}
return 0;
}
static int
s3c2410_rtc_reset(x49gp_module_t *module, x49gp_reset_t reset)
static int s3c2410_rtc_reset( x49gp_module_t* module, x49gp_reset_t reset )
{
s3c2410_rtc_t *rtc = module->user_data;
s3c2410_offset_t *reg;
s3c2410_rtc_t* rtc = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < (S3C2410_RTC_RTCALM >> 2); i++) {
reg = &rtc->regs[i];
for ( i = 0; i < ( S3C2410_RTC_RTCALM >> 2 ); i++ ) {
reg = &rtc->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
*( reg->datap ) = reg->reset;
}
s3c2410_rtc_set_ticnt(rtc);
s3c2410_rtc_set_ticnt( rtc );
return 0;
}
static CPUReadMemoryFunc *s3c2410_rtc_readfn[] =
{
s3c2410_rtc_read,
s3c2410_rtc_read,
s3c2410_rtc_read
};
static CPUReadMemoryFunc* s3c2410_rtc_readfn[] = { s3c2410_rtc_read, s3c2410_rtc_read, s3c2410_rtc_read };
static CPUWriteMemoryFunc *s3c2410_rtc_writefn[] =
{
s3c2410_rtc_write,
s3c2410_rtc_write,
s3c2410_rtc_write
};
static CPUWriteMemoryFunc* s3c2410_rtc_writefn[] = { s3c2410_rtc_write, s3c2410_rtc_write, s3c2410_rtc_write };
static int
s3c2410_rtc_init(x49gp_module_t *module)
static int s3c2410_rtc_init( x49gp_module_t* module )
{
s3c2410_rtc_t *rtc;
s3c2410_rtc_t* rtc;
int iotype;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
rtc = malloc(sizeof(s3c2410_rtc_t));
if (NULL == rtc) {
fprintf(stderr, "%s: %s:%u: Out of memory\n",
module->x49gp->progname, __FUNCTION__, __LINE__);
rtc = malloc( sizeof( s3c2410_rtc_t ) );
if ( NULL == rtc ) {
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
return -ENOMEM;
}
if (s3c2410_rtc_data_init(rtc)) {
free(rtc);
if ( s3c2410_rtc_data_init( rtc ) ) {
free( rtc );
return -ENOMEM;
}
module->user_data = rtc;
rtc->x49gp = module->x49gp;
rtc->tick_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
s3c2410_rtc_timeout, rtc);
rtc->alarm_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
s3c2410_rtc_alarm, rtc);
rtc->tick_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_timeout, rtc );
rtc->alarm_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_alarm, rtc );
iotype = cpu_register_io_memory(s3c2410_rtc_readfn,
s3c2410_rtc_writefn, rtc);
iotype = cpu_register_io_memory( s3c2410_rtc_readfn, s3c2410_rtc_writefn, rtc );
#ifdef DEBUG_S3C2410_RTC
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#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;
}
static int
s3c2410_rtc_exit(x49gp_module_t *module)
static int s3c2410_rtc_exit( x49gp_module_t* module )
{
s3c2410_rtc_t *rtc;
s3c2410_rtc_t* rtc;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
if (module->user_data) {
if ( module->user_data ) {
rtc = module->user_data;
if (rtc->regs)
free(rtc->regs);
free(rtc);
if ( rtc->regs )
free( rtc->regs );
free( rtc );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
}
int
x49gp_s3c2410_rtc_init(x49gp_t *x49gp)
int x49gp_s3c2410_rtc_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-rtc",
s3c2410_rtc_init,
s3c2410_rtc_exit,
s3c2410_rtc_reset,
s3c2410_rtc_load,
s3c2410_rtc_save,
NULL, &module)) {
if ( x49gp_module_init( x49gp, "s3c2410-rtc", s3c2410_rtc_init, s3c2410_rtc_exit, s3c2410_rtc_reset, s3c2410_rtc_load, s3c2410_rtc_save,
NULL, &module ) ) {
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_intc.h"
typedef struct {
uint32_t spicon0;
uint32_t spista0;
@ -29,265 +28,227 @@ typedef struct {
uint32_t sprdat1;
unsigned int nr_regs;
s3c2410_offset_t *regs;
s3c2410_offset_t* regs;
x49gp_t *x49gp;
x49gp_t* x49gp;
} s3c2410_spi_t;
static int
s3c2410_spi_data_init(s3c2410_spi_t *spi)
static int s3c2410_spi_data_init( s3c2410_spi_t* spi )
{
s3c2410_offset_t regs[] =
{
S3C2410_OFFSET(SPI, SPICON0, 0x00000000, spi->spicon0),
S3C2410_OFFSET(SPI, SPISTA0, 0x00000000, spi->spista0),
S3C2410_OFFSET(SPI, SPPIN0, 0x00000000, spi->sppin0),
S3C2410_OFFSET(SPI, SPPRE0, 0x00000000, spi->sppre0),
S3C2410_OFFSET(SPI, SPTDAT0, 0x00000000, spi->sptdat0),
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),
s3c2410_offset_t regs[] = {
S3C2410_OFFSET( SPI, SPICON0, 0x00000000, spi->spicon0 ), S3C2410_OFFSET( SPI, SPISTA0, 0x00000000, spi->spista0 ),
S3C2410_OFFSET( SPI, SPPIN0, 0x00000000, spi->sppin0 ), S3C2410_OFFSET( SPI, SPPRE0, 0x00000000, spi->sppre0 ),
S3C2410_OFFSET( SPI, SPTDAT0, 0x00000000, spi->sptdat0 ), 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));
if (NULL == spi->regs) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
spi->regs = malloc( sizeof( regs ) );
if ( NULL == spi->regs ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
memcpy(spi->regs, regs, sizeof(regs));
spi->nr_regs = sizeof(regs) / sizeof(regs[0]);
memcpy( spi->regs, regs, sizeof( regs ) );
spi->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0;
}
uint32_t
s3c2410_spi_read(void *opaque, target_phys_addr_t offset)
uint32_t s3c2410_spi_read( void* opaque, target_phys_addr_t offset )
{
s3c2410_spi_t *spi = opaque;
s3c2410_offset_t *reg;
s3c2410_spi_t* spi = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(spi, offset)) {
return ~(0);
if ( !S3C2410_OFFSET_OK( spi, offset ) ) {
return ~( 0 );
}
reg = S3C2410_OFFSET_ENTRY(spi, offset);
reg = S3C2410_OFFSET_ENTRY( spi, offset );
#ifdef DEBUG_S3C2410_SPI
printf("read %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-spi", S3C2410_SPI_BASE,
reg->name, (unsigned long) offset, *(reg->datap));
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset,
*( reg->datap ) );
#endif
switch (offset) {
switch ( offset ) {
case S3C2410_SPI_SPRDAT0:
spi->spista0 &= ~(1);
spi->spista0 &= ~( 1 );
break;
case S3C2410_SPI_SPRDAT1:
spi->spista1 &= ~(1);
spi->spista1 &= ~( 1 );
break;
}
return *(reg->datap);
return *( reg->datap );
}
void
s3c2410_spi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
void s3c2410_spi_write( void* opaque, target_phys_addr_t offset, uint32_t data )
{
s3c2410_spi_t *spi = opaque;
x49gp_t *x49gp = spi->x49gp;
s3c2410_offset_t *reg;
s3c2410_spi_t* spi = opaque;
x49gp_t* x49gp = spi->x49gp;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(spi, offset)) {
if ( !S3C2410_OFFSET_OK( spi, offset ) ) {
return;
}
reg = S3C2410_OFFSET_ENTRY(spi, offset);
reg = S3C2410_OFFSET_ENTRY( spi, offset );
#ifdef DEBUG_S3C2410_SPI
printf("write %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-spi", S3C2410_SPI_BASE,
reg->name, (unsigned long) offset, data);
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset, data );
#endif
*(reg->datap) = data;
*( reg->datap ) = data;
switch (offset) {
switch ( offset ) {
case S3C2410_SPI_SPTDAT0:
spi->spista0 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI0, 0);
s3c2410_intc_assert( x49gp, INT_SPI0, 0 );
break;
case S3C2410_SPI_SPTDAT1:
spi->spista1 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI1, 0);
s3c2410_intc_assert( x49gp, INT_SPI1, 0 );
break;
}
}
static int
s3c2410_spi_load(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_spi_load( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_spi_t *spi = module->user_data;
s3c2410_offset_t *reg;
s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t* reg;
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < spi->nr_regs; i++) {
reg = &spi->regs[i];
for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
}
static int
s3c2410_spi_save(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_spi_save( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_spi_t *spi = module->user_data;
s3c2410_offset_t *reg;
s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < spi->nr_regs; i++) {
reg = &spi->regs[i];
for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap));
x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
}
return 0;
}
static int
s3c2410_spi_reset(x49gp_module_t *module, x49gp_reset_t reset)
static int s3c2410_spi_reset( x49gp_module_t* module, x49gp_reset_t reset )
{
s3c2410_spi_t *spi = module->user_data;
s3c2410_offset_t *reg;
s3c2410_spi_t* spi = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < spi->nr_regs; i++) {
reg = &spi->regs[i];
for ( i = 0; i < spi->nr_regs; i++ ) {
reg = &spi->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
*( reg->datap ) = reg->reset;
}
return 0;
}
static CPUReadMemoryFunc *s3c2410_spi_readfn[] =
{
s3c2410_spi_read,
s3c2410_spi_read,
s3c2410_spi_read
};
static CPUReadMemoryFunc* s3c2410_spi_readfn[] = { s3c2410_spi_read, s3c2410_spi_read, s3c2410_spi_read };
static CPUWriteMemoryFunc *s3c2410_spi_writefn[] =
{
s3c2410_spi_write,
s3c2410_spi_write,
s3c2410_spi_write
};
static CPUWriteMemoryFunc* s3c2410_spi_writefn[] = { s3c2410_spi_write, s3c2410_spi_write, s3c2410_spi_write };
static int
s3c2410_spi_init(x49gp_module_t *module)
static int s3c2410_spi_init( x49gp_module_t* module )
{
s3c2410_spi_t *spi;
s3c2410_spi_t* spi;
int iotype;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
spi = malloc(sizeof(s3c2410_spi_t));
if (NULL == spi) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
spi = malloc( sizeof( s3c2410_spi_t ) );
if ( NULL == spi ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
if (s3c2410_spi_data_init(spi)) {
free(spi);
if ( s3c2410_spi_data_init( spi ) ) {
free( spi );
return -ENOMEM;
}
module->user_data = spi;
spi->x49gp = module->x49gp;
iotype = cpu_register_io_memory(s3c2410_spi_readfn,
s3c2410_spi_writefn, spi);
iotype = cpu_register_io_memory( s3c2410_spi_readfn, s3c2410_spi_writefn, spi );
#ifdef DEBUG_S3C2410_SPI
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#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;
}
static int
s3c2410_spi_exit(x49gp_module_t *module)
static int s3c2410_spi_exit( x49gp_module_t* module )
{
s3c2410_spi_t *spi;
s3c2410_spi_t* spi;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
if (module->user_data) {
if ( module->user_data ) {
spi = module->user_data;
if (spi->regs)
free(spi->regs);
free(spi);
if ( spi->regs )
free( spi->regs );
free( spi );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
}
int
x49gp_s3c2410_spi_init(x49gp_t *x49gp)
int x49gp_s3c2410_spi_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-spi",
s3c2410_spi_init,
s3c2410_spi_exit,
s3c2410_spi_reset,
s3c2410_spi_load,
s3c2410_spi_save,
NULL, &module)) {
if ( x49gp_module_init( x49gp, "s3c2410-spi", s3c2410_spi_init, s3c2410_spi_exit, s3c2410_spi_reset, s3c2410_spi_load, s3c2410_spi_save,
NULL, &module ) ) {
return -1;
}
return x49gp_module_register(module);
return x49gp_module_register( module );
}

View file

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

View file

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

View file

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

View file

@ -12,7 +12,6 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t func_addr_reg;
uint32_t pwr_reg;
@ -62,272 +61,239 @@ typedef struct {
uint32_t out_fifo_cnt2_reg;
unsigned int nr_regs;
s3c2410_offset_t *regs;
s3c2410_offset_t* regs;
} s3c2410_usbdev_t;
static int
s3c2410_usbdev_data_init(s3c2410_usbdev_t *usbdev)
static int s3c2410_usbdev_data_init( s3c2410_usbdev_t* usbdev )
{
s3c2410_offset_t regs[] = {
S3C2410_OFFSET(USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg),
S3C2410_OFFSET(USBDEV, PWR_REG, 0x00, usbdev->pwr_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, 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, FRAME_NUM1_REG, 0x00, usbdev->frame_num1_reg),
S3C2410_OFFSET(USBDEV, FRAME_NUM2_REG, 0x00, usbdev->frame_num2_reg),
S3C2410_OFFSET(USBDEV, INDEX_REG, 0x00, usbdev->index_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, EP2_FIFO_REG, 0, usbdev->ep2_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, EP1_DMA_CON, 0x00, usbdev->ep1_dma_con),
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_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_H, 0x00, usbdev->ep1_dma_ttc_h),
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_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_M, 0x00, usbdev->ep2_dma_ttc_m),
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_UNIT, 0x00, usbdev->ep3_dma_unit),
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_M, 0x00, usbdev->ep3_dma_ttc_m),
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_UNIT, 0x00, usbdev->ep4_dma_unit),
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_M, 0x00, usbdev->ep4_dma_ttc_m),
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, 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, MAXP_REG, 0x01, usbdev->maxp_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_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_reg),
S3C2410_OFFSET(USBDEV, OUT_FIFO_CNT2_REG, 0x00, usbdev->out_fifo_cnt2_reg)
};
s3c2410_offset_t regs[] = { S3C2410_OFFSET( USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg ),
S3C2410_OFFSET( USBDEV, PWR_REG, 0x00, usbdev->pwr_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, 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, FRAME_NUM1_REG, 0x00, usbdev->frame_num1_reg ),
S3C2410_OFFSET( USBDEV, FRAME_NUM2_REG, 0x00, usbdev->frame_num2_reg ),
S3C2410_OFFSET( USBDEV, INDEX_REG, 0x00, usbdev->index_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, EP2_FIFO_REG, 0, usbdev->ep2_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, EP1_DMA_CON, 0x00, usbdev->ep1_dma_con ),
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_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_H, 0x00, usbdev->ep1_dma_ttc_h ),
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_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_M, 0x00, usbdev->ep2_dma_ttc_m ),
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_UNIT, 0x00, usbdev->ep3_dma_unit ),
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_M, 0x00, usbdev->ep3_dma_ttc_m ),
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_UNIT, 0x00, usbdev->ep4_dma_unit ),
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_M, 0x00, usbdev->ep4_dma_ttc_m ),
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, 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, MAXP_REG, 0x01, usbdev->maxp_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_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_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));
if (NULL == usbdev->regs) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
usbdev->regs = malloc( sizeof( regs ) );
if ( NULL == usbdev->regs ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
memcpy(usbdev->regs, regs, sizeof(regs));
usbdev->nr_regs = sizeof(regs) / sizeof(regs[0]);
memcpy( usbdev->regs, regs, sizeof( regs ) );
usbdev->nr_regs = sizeof( regs ) / sizeof( regs[ 0 ] );
return 0;
}
static uint32_t
s3c2410_usbdev_read(void *opaque, target_phys_addr_t offset)
static uint32_t s3c2410_usbdev_read( void* opaque, target_phys_addr_t offset )
{
s3c2410_usbdev_t *usbdev = opaque;
s3c2410_offset_t *reg;
s3c2410_usbdev_t* usbdev = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(usbdev, offset)) {
return ~(0);
if ( !S3C2410_OFFSET_OK( usbdev, offset ) ) {
return ~( 0 );
}
reg = S3C2410_OFFSET_ENTRY(usbdev, offset);
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
#ifdef DEBUG_S3C2410_USBDEV
printf("read %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-usbdev", S3C2410_USBDEV_BASE,
reg->name, (unsigned long) offset, *(reg->datap));
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset,
*( reg->datap ) );
#endif
return *(reg->datap);
return *( reg->datap );
}
static void
s3c2410_usbdev_write(void *opaque, target_phys_addr_t offset, uint32_t data)
static void s3c2410_usbdev_write( void* opaque, target_phys_addr_t offset, uint32_t data )
{
s3c2410_usbdev_t *usbdev = opaque;
s3c2410_offset_t *reg;
s3c2410_usbdev_t* usbdev = opaque;
s3c2410_offset_t* reg;
if (! S3C2410_OFFSET_OK(usbdev, offset)) {
if ( !S3C2410_OFFSET_OK( usbdev, offset ) ) {
return;
}
reg = S3C2410_OFFSET_ENTRY(usbdev, offset);
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
#ifdef DEBUG_S3C2410_USBDEV
printf("write %s [%08x] %s [%08lx] data %08x\n",
"s3c2410-usbdev", S3C2410_USBDEV_BASE,
reg->name, (unsigned long) offset, data);
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset, data );
#endif
*(reg->datap) = data;
*( reg->datap ) = data;
}
static int
s3c2410_usbdev_load(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_usbdev_load( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_usbdev_t *usbdev = module->user_data;
s3c2410_offset_t *reg;
s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t* reg;
int error = 0;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < usbdev->nr_regs; i++) {
reg = &usbdev->regs[i];
for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
}
static int
s3c2410_usbdev_save(x49gp_module_t *module, GKeyFile *key)
static int s3c2410_usbdev_save( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_usbdev_t *usbdev = module->user_data;
s3c2410_offset_t *reg;
s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < usbdev->nr_regs; i++) {
reg = &usbdev->regs[i];
for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
x49gp_module_set_u32(module, key, reg->name, *(reg->datap));
x49gp_module_set_u32( module, key, reg->name, *( reg->datap ) );
}
return 0;
}
static int
s3c2410_usbdev_reset(x49gp_module_t *module, x49gp_reset_t reset)
static int s3c2410_usbdev_reset( x49gp_module_t* module, x49gp_reset_t reset )
{
s3c2410_usbdev_t *usbdev = module->user_data;
s3c2410_offset_t *reg;
s3c2410_usbdev_t* usbdev = module->user_data;
s3c2410_offset_t* reg;
int i;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
for (i = 0; i < usbdev->nr_regs; i++) {
reg = &usbdev->regs[i];
for ( i = 0; i < usbdev->nr_regs; i++ ) {
reg = &usbdev->regs[ i ];
if (NULL == reg->name)
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
*( reg->datap ) = reg->reset;
}
return 0;
}
static CPUReadMemoryFunc *s3c2410_usbdev_readfn[] =
{
s3c2410_usbdev_read,
s3c2410_usbdev_read,
s3c2410_usbdev_read
};
static CPUReadMemoryFunc* s3c2410_usbdev_readfn[] = { s3c2410_usbdev_read, s3c2410_usbdev_read, s3c2410_usbdev_read };
static CPUWriteMemoryFunc *s3c2410_usbdev_writefn[] =
{
s3c2410_usbdev_write,
s3c2410_usbdev_write,
s3c2410_usbdev_write
};
static CPUWriteMemoryFunc* s3c2410_usbdev_writefn[] = { s3c2410_usbdev_write, s3c2410_usbdev_write, s3c2410_usbdev_write };
static int
s3c2410_usbdev_init(x49gp_module_t *module)
static int s3c2410_usbdev_init( x49gp_module_t* module )
{
s3c2410_usbdev_t *usbdev;
s3c2410_usbdev_t* usbdev;
int iotype;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
usbdev = malloc(sizeof(s3c2410_usbdev_t));
if (NULL == usbdev) {
fprintf(stderr, "%s:%u: Out of memory\n",
__FUNCTION__, __LINE__);
usbdev = malloc( sizeof( s3c2410_usbdev_t ) );
if ( NULL == usbdev ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
if (s3c2410_usbdev_data_init(usbdev)) {
free(usbdev);
if ( s3c2410_usbdev_data_init( usbdev ) ) {
free( usbdev );
return -ENOMEM;
}
module->user_data = usbdev;
iotype = cpu_register_io_memory(s3c2410_usbdev_readfn,
s3c2410_usbdev_writefn, usbdev);
iotype = cpu_register_io_memory( s3c2410_usbdev_readfn, s3c2410_usbdev_writefn, usbdev );
#ifdef DEBUG_S3C2410_USBDEV
printf("%s: iotype %08x\n", __FUNCTION__, iotype);
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
#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;
}
static int
s3c2410_usbdev_exit(x49gp_module_t *module)
static int s3c2410_usbdev_exit( x49gp_module_t* module )
{
s3c2410_usbdev_t *usbdev;
s3c2410_usbdev_t* usbdev;
#ifdef DEBUG_X49GP_MODULES
printf("%s: %s:%u\n", module->name, __FUNCTION__, __LINE__);
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
#endif
if (module->user_data) {
if ( module->user_data ) {
usbdev = module->user_data;
if (usbdev->regs)
free(usbdev->regs);
free(usbdev);
if ( usbdev->regs )
free( usbdev->regs );
free( usbdev );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
}
int
x49gp_s3c2410_usbdev_init(x49gp_t *x49gp)
int x49gp_s3c2410_usbdev_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
x49gp_module_t* module;
if (x49gp_module_init(x49gp, "s3c2410-usbdev",
s3c2410_usbdev_init,
s3c2410_usbdev_exit,
s3c2410_usbdev_reset,
s3c2410_usbdev_load,
s3c2410_usbdev_save,
NULL, &module)) {
if ( x49gp_module_init( x49gp, "s3c2410-usbdev", s3c2410_usbdev_init, s3c2410_usbdev_exit, s3c2410_usbdev_reset, s3c2410_usbdev_load,
s3c2410_usbdev_save, NULL, &module ) ) {
return -1;
}
return x49gp_module_register(module);
return x49gp_module_register( module );
}

View file

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

File diff suppressed because it is too large Load diff

View file

@ -9,144 +9,71 @@
#include "symbol.h"
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_CLOSE_PATH()
};
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_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_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 );
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[] =
{
SYMBOL_MOVE_TO( 0.100, 0.000 ),
SYMBOL_LINE_TO( 0.000, 0.800 ),
SYMBOL_LINE_TO( 0.693, -0.400 ),
SYMBOL_CLOSE_PATH()
};
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_LINE_TO( 0.000, -0.500 ), SYMBOL_LINE_TO( -1.000, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.250 ), 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_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( uparrowleft, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7 );
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_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( uparrowright, 1.3, 0.0, 0.1, 0.0, 1.2, 0.7 );
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[] =
{
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_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_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(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_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( overscore, 0.8, 0.0, 0.0, 0.9, 0.9, 1.0 );
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[] =
{
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 ),
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.500, 0.000 ),
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.135, 0.000 ),
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_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 );
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(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( 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 );
typedef struct {
const char *name;
const x49gp_symbol_t *symbol;
const char* name;
const x49gp_symbol_t* symbol;
} symbol_name_t;
static const symbol_name_t symbol_names[] =
{
{ ".notdef", &symbol_square },
{ "arrowleftdblfull", &symbol_arrowleftdblfull },
{ "divide", &symbol_divide },
{ "divisionslash", &symbol_divisionslash },
{ "minus", &symbol_minus },
{ "overscore", &symbol_overscore },
{ "radical", &symbol_radical },
{ "square", &symbol_square },
{ "tick", &symbol_tick },
{ "triangleright", &symbol_triangleright },
{ "triangleup", &symbol_triangleup },
{ "uparrowleft", &symbol_uparrowleft },
{ "uparrowright", &symbol_uparrowright },
{ "super", &symbol_beginsuperscript },
{ "/super", &symbol_endsuperscript },
{ "kern-1", &symbol_kern_m1 },
{ "kern-2", &symbol_kern_m2 },
{ "kern-3", &symbol_kern_m3 },
{ "kern-4", &symbol_kern_m4 },
{ "kern-5", &symbol_kern_m5 },
{ "kern-6", &symbol_kern_m6 },
{ "kern-7", &symbol_kern_m7 },
{ "kern-8", &symbol_kern_m8 },
{ "kern-9", &symbol_kern_m9 },
{ NULL, NULL }
static const symbol_name_t symbol_names[] = {
{".notdef", &symbol_square },
{"arrowleftdblfull", &symbol_arrowleftdblfull},
{"divide", &symbol_divide },
{"divisionslash", &symbol_divisionslash },
{"minus", &symbol_minus },
{"overscore", &symbol_overscore },
{"radical", &symbol_radical },
{"square", &symbol_square },
{"tick", &symbol_tick },
{"triangleright", &symbol_triangleright },
{"triangleup", &symbol_triangleup },
{"uparrowleft", &symbol_uparrowleft },
{"uparrowright", &symbol_uparrowright },
{"super", &symbol_beginsuperscript},
{"/super", &symbol_endsuperscript },
{"kern-1", &symbol_kern_m1 },
{"kern-2", &symbol_kern_m2 },
{"kern-3", &symbol_kern_m3 },
{"kern-4", &symbol_kern_m4 },
{"kern-5", &symbol_kern_m5 },
{"kern-6", &symbol_kern_m6 },
{"kern-7", &symbol_kern_m7 },
{"kern-8", &symbol_kern_m8 },
{"kern-9", &symbol_kern_m9 },
{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
symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
int 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;
/*
@ -238,10 +154,9 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
*/
symname = symbol_names;
while (symname->name) {
if ((strlen(symname->name) == namelen) &&
!strncmp(symname->name, name, namelen)) {
if (glyph) {
while ( symname->name ) {
if ( ( strlen( symname->name ) == namelen ) && !strncmp( symname->name, name, namelen ) ) {
if ( glyph ) {
*glyph = 0xe000 + i;
}
return 1;
@ -254,25 +169,23 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
return 0;
}
const x49gp_symbol_t *
symbol_get_by_glyph(gunichar glyph)
const x49gp_symbol_t* symbol_get_by_glyph( gunichar glyph )
{
int index = glyph - 0xe000;
if ((index >= 0) && (index < NR_SYMBOLS)) {
return symbol_names[index].symbol;
if ( ( index >= 0 ) && ( index < NR_SYMBOLS ) ) {
return symbol_names[ index ].symbol;
}
return NULL;
}
const x49gp_symbol_t *
symbol_get_by_name(const char *name)
const x49gp_symbol_t* symbol_get_by_name( const char* name )
{
gunichar glyph;
if (symbol_lookup_glyph_by_name(name, strlen(name), &glyph)) {
return symbol_get_by_glyph(glyph);
if ( symbol_lookup_glyph_by_name( name, strlen( name ), &glyph ) ) {
return symbol_get_by_glyph( glyph );
}
return NULL;

View file

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

View file

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

View file

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

View file

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

View file

@ -11,23 +11,23 @@
#define X49GP_TIMER_VIRTUAL 0
#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;
x49gp_timer_t *x49gp_new_timer(long type, x49gp_timer_cb_t, void *user_data);
void x49gp_free_timer(x49gp_timer_t *);
x49gp_timer_t* x49gp_new_timer( long type, x49gp_timer_cb_t, void* user_data );
void x49gp_free_timer( x49gp_timer_t* );
void x49gp_mod_timer(x49gp_timer_t *, int64_t expires);
void x49gp_del_timer(x49gp_timer_t *);
int x49gp_timer_pending(x49gp_timer_t *);
int64_t x49gp_timer_expires(x49gp_timer_t *);
void x49gp_mod_timer( x49gp_timer_t*, int64_t expires );
void x49gp_del_timer( x49gp_timer_t* );
int x49gp_timer_pending( x49gp_timer_t* );
int64_t x49gp_timer_expires( x49gp_timer_t* );
#define X49GP_GTK_REFRESH_INTERVAL 30000LL
#define X49GP_LCD_REFRESH_INTERVAL 50000LL
int x49gp_main_loop(x49gp_t *);
int x49gp_timer_init(x49gp_t *);
int x49gp_main_loop( x49gp_t* );
int x49gp_timer_init( x49gp_t* );
#endif /* !(_X49GP_TIMER_H) */

View file

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