1
0
Fork 0
forked from Miroirs/x49gp

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,32 +5,29 @@
#define _X49GP_BITMAP_FONT_H 1
typedef struct {
const char *name;
int width;
int kern;
int ascent;
int descent;
const unsigned char *bits;
const char* name;
int width;
int kern;
int ascent;
int descent;
const unsigned char* bits;
} bitmap_glyph_t;
typedef struct {
int ascent;
int descent;
bitmap_glyph_t glyphs[];
int ascent;
int descent;
bitmap_glyph_t glyphs[];
} bitmap_font_t;
#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 \
}
#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 }
#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

@ -1,8 +1,8 @@
/*
* Block driver for the QCOW format
*
*
* Copyright (c) 2004-2006 Fabrice Bellard
*
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@ -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_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;
if (buf_size >= sizeof(QCowHeader) &&
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
be32_to_cpu(cow_header->version) == QCOW_VERSION)
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 )
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);
if (header.magic != QCOW_MAGIC || header.version != QCOW_VERSION)
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 )
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;
}
@ -177,174 +175,157 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
*
* 2 to allocate a compressed cluster of size
* 'compressed_size'. 'compressed_size' must be > 0 and <
* cluster_size
* cluster_size
*
* 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,76 +397,75 @@ 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;
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 */
header.l2_bits = 12; /* 32 KB L2 tables */
} else {
header.cluster_bits = 12; /* 4 KB clusters */
header.l2_bits = 9; /* 4 KB L2 tables */
header.l2_bits = 9; /* 4 KB L2 tables */
}
header_size = (header_size + 7) & ~7;
header_size = ( header_size + 7 ) & ~7;
shift = header.cluster_bits + header.l2_bits;
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)
return -1;
ret = bdrv_truncate(s->hd, s->l1_table_offset + l1_length);
if (ret < 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 )
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

File diff suppressed because it is too large Load diff

View file

@ -6,65 +6,62 @@
#include <stdint.h>
#define BDRV_O_RDONLY 0x0000
#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
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
bdrv_file_open()) */
#define BDRV_O_RDONLY 0x0000
#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 \
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 \
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,84 +24,77 @@
#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 {
int64_t total_sectors; /* if we are reading a disk image, give its
size in sectors */
int read_only; /* if true, the media is read only */
int removable; /* if true, the media can be removed */
int locked; /* if true, the media cannot temporarily be ejected */
int encrypted; /* if true, the media is encrypted */
int read_only; /* if true, the media is read only */
int removable; /* if true, the media can be removed */
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
this file image */
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;
uint16_t x;
__asm__ __volatile__ ("lduha [%1] %2, %0"
: "=r" (x)
: "r" (p), "i" (ASI_PL));
return x;
__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;
uint32_t x;
__asm__ __volatile__ ("lduwa [%1] %2, %0"
: "=r" (x)
: "r" (p), "i" (ASI_PL));
return x;
__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"
: /* no outputs */
: "r" (x), "r" (p), "i" (ASI_PL));
__asm__ __volatile__( "stha %0, [%1] %2"
: /* no outputs */
: "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"
: /* no outputs */
: "r" (x), "r" (p), "i" (ASI_PL));
__asm__ __volatile__( "stwa %0, [%1] %2"
: /* no outputs */
: "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

@ -6,33 +6,30 @@
#define DEFAULT_GDBSTUB_PORT 1234
/* GDB breakpoint/watchpoint types */
#define GDB_BREAKPOINT_SW 0
#define GDB_BREAKPOINT_HW 1
#define GDB_WATCHPOINT_WRITE 2
#define GDB_WATCHPOINT_READ 3
#define GDB_WATCHPOINT_ACCESS 4
#define GDB_BREAKPOINT_SW 0
#define GDB_BREAKPOINT_HW 1
#define GDB_WATCHPOINT_WRITE 2
#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;
gunichar unichar;
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;
size_t size;
int in, out;
int i;
unsigned char *input, *p;
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], "-"))
in = 0;
else {
in = open(argv[1], O_RDONLY);
if (in < 0) {
perror(argv[1]);
exit(1);
}
}
if ( !strcmp( argv[ 1 ], "-" ) )
in = 0;
else {
in = open( argv[ 1 ], O_RDONLY );
if ( in < 0 ) {
perror( argv[ 1 ] );
exit( 1 );
}
}
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);
}
}
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 );
}
}
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;
else {
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;
else {
fprintf(stderr, "%s: parse error at byte %d\n",
argv[0], i);
exit(1);
}
p++;
}
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;
else {
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;
else {
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;
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;
size_t size;
int in, out;
int i;
unsigned char *input, *p;
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], "-"))
in = 0;
else {
in = open(argv[1], O_RDONLY);
if (in < 0) {
perror(argv[1]);
exit(1);
}
}
if ( !strcmp( argv[ 1 ], "-" ) )
in = 0;
else {
in = open( argv[ 1 ], O_RDONLY );
if ( in < 0 ) {
perror( argv[ 1 ] );
exit( 1 );
}
}
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);
}
}
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 );
}
}
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;
else {
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;
else {
fprintf(stderr, "%s: parse error at byte %d\n",
argv[0], i);
exit(1);
}
p++;
}
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;
else {
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;
else {
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;
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.
@ -28,17 +28,18 @@ static inline void prefetch(const void *x) {;}
*/
struct list_head {
struct list_head *next, *prev;
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD_INIT( name ) { &( name ), &( name ) }
#define LIST_HEAD(name) \
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,14 +47,12 @@ 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;
new->prev = prev;
prev->next = new;
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
/**
@ -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,10 +82,10 @@ 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;
next->prev = prev;
prev->next = next;
}
/**
@ -101,21 +94,21 @@ 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);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
__list_del( entry->prev, entry->next );
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
}
/**
* 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,24 +151,23 @@ 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;
first->prev = head;
head->next = first;
last->next = at;
at->prev = last;
last->next = at;
at->prev = last;
}
/**
@ -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,13 +188,12 @@ 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,42 +363,36 @@ static inline void list_splice_init(struct list_head *list,
*/
struct hlist_head {
struct hlist_node *first;
struct hlist_node* first;
};
struct hlist_node {
struct hlist_node *next, **pprev;
struct hlist_node *next, **pprev;
};
#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)
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 void __hlist_del( struct hlist_node* n )
{
return !h->pprev;
struct hlist_node* next = n->next;
struct hlist_node** pprev = n->pprev;
*pprev = next;
if ( next )
next->pprev = pprev;
}
static inline int hlist_empty(const struct hlist_head *h)
static inline void hlist_del( struct hlist_node* n )
{
return !h->first;
}
static inline void __hlist_del(struct hlist_node *n)
{
struct hlist_node *next = n->next;
struct hlist_node **pprev = n->pprev;
*pprev = next;
if (next)
next->pprev = pprev;
}
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->next = LIST_POISON1;
n->pprev = LIST_POISON2;
__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);
n->pprev = LIST_POISON2;
__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;
n->next = first;
if (first)
first->pprev = &n->next;
h->first = n;
n->pprev = &h->first;
struct hlist_node* first = h->first;
n->next = 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 = next->pprev;
n->next = next;
next->pprev = &n->next;
*( 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;
next->next = n->next;
n->next = next;
next->pprev = &n->next;
if(next->next)
next->next->pprev = &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 */
#endif /* _LINUX_LIST_H */

File diff suppressed because it is too large Load diff

View file

@ -11,493 +11,434 @@
#include "x49gp.h"
int
x49gp_modules_init(x49gp_t *x49gp)
int x49gp_modules_init( x49gp_t* x49gp )
{
x49gp_module_t *module;
int error;
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;
phys_ram_size = 0;
list_for_each_entry(module, &x49gp->modules, list) {
error = module->init(module);
if (error) {
return 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;
return 0;
}
int
x49gp_modules_exit(x49gp_t *x49gp)
int x49gp_modules_exit( x49gp_t* x49gp )
{
x49gp_module_t *module, *next;
int error;
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) {
return error;
}
}
list_for_each_entry_safe_reverse( module, next, &x49gp->modules, list )
{
error = module->exit( module );
if ( error ) {
return error;
}
}
return 0;
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;
int error;
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) {
return error;
}
}
list_for_each_entry( module, &x49gp->modules, list )
{
error = module->reset( module, reset );
if ( error ) {
return error;
}
}
return 0;
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;
int error, result;
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)) {
error = -errno;
fprintf(stderr, "%s:%u: g_mkdir_with_parents: %s\n",
__FUNCTION__, __LINE__, strerror(errno));
return error;
}
if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) {
error = -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__);
return -ENOMEM;
}
x49gp->config = g_key_file_new();
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);
return -EIO;
}
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;
result = 0;
list_for_each_entry(module, &x49gp->modules, list) {
error = module->load(module, x49gp->config);
if (error) {
if (error == -EAGAIN) {
result = -EAGAIN;
} else {
return error;
}
}
}
list_for_each_entry( module, &x49gp->modules, list )
{
error = module->load( module, x49gp->config );
if ( error ) {
if ( error == -EAGAIN ) {
result = -EAGAIN;
} else {
return error;
}
}
}
{
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;
}
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;
gsize length;
int error;
int fd;
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) {
return 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);
return -ENOMEM;
}
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) {
error = -errno;
fprintf(stderr, "%s:%u: open %s: %s\n",
__FUNCTION__, __LINE__, filename, strerror(errno));
g_free(data);
return error;
}
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 );
return error;
}
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 );
return error;
}
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);
return error;
}
close( fd );
g_free( data );
close(fd);
g_free(data);
return 0;
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;
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;
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;
int error;
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);
return error;
}
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);
*valuep = NULL;
}
*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;
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;
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;
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;
char *data, *end;
uint32_t value;
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);
*valuep = reset;
return -EAGAIN;
}
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')) {
*valuep = reset;
g_free(data);
return -EAGAIN;
}
value = strtoul( data, &end, 0 );
if ( ( end == data ) || ( *end != '\0' ) ) {
*valuep = reset;
g_free( data );
return -EAGAIN;
}
*valuep = value;
*valuep = value;
g_free(data);
return 0;
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;
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;
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;
char *data, *end;
uint64_t value;
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);
*valuep = reset;
return -EAGAIN;
}
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')) {
*valuep = reset;
g_free(data);
return -EAGAIN;
}
value = strtoull( data, &end, 0 );
if ( ( end == data ) || ( *end != '\0' ) ) {
*valuep = reset;
g_free( data );
return -EAGAIN;
}
*valuep = value;
*valuep = value;
g_free(data);
return 0;
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);
return -EAGAIN;
}
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;
}
*valuep = data;
return 0;
*valuep = data;
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;
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;
int fd;
int error;
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__);
return -ENOMEM;
}
*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__);
return -ENOMEM;
}
*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) {
error = -errno;
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
module->name, __FUNCTION__, __LINE__,
*path, strerror(errno));
g_free(*path);
*path = NULL;
return error;
}
if ( fd < 0 ) {
error = -errno;
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, *path, strerror( errno ) );
g_free( *path );
*path = NULL;
return error;
}
return fd;
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__);
return -1;
}
memset(module, 0, sizeof(x49gp_module_t));
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 ) );
module->name = name;
module->name = name;
module->init = init;
module->exit = exit;
module->reset = reset;
module->load = load;
module->save = save;
module->init = init;
module->exit = exit;
module->reset = reset;
module->load = load;
module->save = save;
module->user_data = user_data;
module->user_data = user_data;
// module->mutex = g_mutex_new();
module->x49gp = x49gp;
// module->mutex = g_mutex_new();
module->x49gp = x49gp;
*modulep = module;
return 0;
*modulep = module;
return 0;
}

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_usbhost_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_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_sram_init( x49gp );
x49gp_s3c2410_memc_init( x49gp );
/* x49gp_s3c2410_usbhost_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_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 );
return 0;
return 0;
}
int
s3c2410_exit(x49gp_t *x49gp)
{
return 0;
}
int s3c2410_exit( x49gp_t* x49gp ) { return 0; }

View file

@ -12,250 +12,216 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t adccon;
uint32_t adctsc;
uint32_t adcdly;
uint32_t adcdat0;
uint32_t adcdat1;
uint32_t adccon;
uint32_t adctsc;
uint32_t adcdly;
uint32_t adcdat0;
uint32_t adcdat1;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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_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 ),
};
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__);
return -ENOMEM;
}
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;
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) {
case S3C2410_ADC_ADCCON:
*(reg->datap) &= ~(0x0001);
*(reg->datap) |= 0x8000;
break;
default:
break;
}
switch ( offset ) {
case S3C2410_ADC_ADCCON:
*( 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)) {
return;
}
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_adc_data_init(adc)) {
free(adc);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = adc;
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;
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) {
adc = module->user_data;
if (adc->regs)
free(adc->regs);
free(adc);
}
if ( module->user_data ) {
adc = module->user_data;
if ( adc->regs )
free( adc->regs );
free( adc );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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];
int error = 0;
int i;
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]))
error = -EAGAIN;
}
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))
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]))
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]))
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]))
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]))
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]))
error = -EAGAIN;
}
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 ) )
error = -EAGAIN;
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 ] ) )
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 ] ) )
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 ] ) )
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 ] ) )
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 ] ) )
error = -EAGAIN;
}
if (x49gp_module_get_u32(module, key, "CF", 0, &env->CF))
error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "VF", 0, &env->VF))
error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "NF", 0, &env->NF))
error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "ZF", 0, &env->ZF))
error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "QF", 0, &env->QF))
error = -EAGAIN;
if (x49gp_module_get_u32(module, key, "thumb", 0, &env->thumb))
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "CF", 0, &env->CF ) )
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "VF", 0, &env->VF ) )
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "NF", 0, &env->NF ) )
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "ZF", 0, &env->ZF ) )
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "QF", 0, &env->QF ) )
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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 ) )
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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))
error = -EAGAIN;
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 ) )
error = -EAGAIN;
if ( x49gp_module_get_u32( module, key, "halted", 0, &env->halted ) )
error = -EAGAIN;
env->exception_index = -1;
env->exception_index = -1;
if (0 == error) {
if (env->halted)
module->x49gp->arm_idle = 1;
} else {
memset(&env->cp15, 0, sizeof(env->cp15));
}
if ( 0 == error ) {
if ( env->halted )
module->x49gp->arm_idle = 1;
} else {
memset( &env->cp15, 0, sizeof( env->cp15 ) );
}
// s3c2410_arm_dump_state(state);
// s3c2410_arm_dump_state(state);
return error;
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];
int i;
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]);
}
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_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->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->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 ] );
}
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->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 ] );
}
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;
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;
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;
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;
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)) {
return -1;
}
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 );
}

File diff suppressed because it is too large Load diff

View file

@ -4,69 +4,69 @@
#ifndef _X49GP_S3C2410_INTC_H
#define _X49GP_S3C2410_INTC_H 1
#define INT_ADC 31
#define INT_RTC 30
#define INT_SPI1 29
#define INT_UART0 28
#define INT_IIC 27
#define INT_USBH 26
#define INT_USBD 25
#define INT_UART1 23
#define INT_SPI0 22
#define INT_SDI 21
#define INT_DMA3 20
#define INT_DMA2 19
#define INT_DMA1 18
#define INT_DMA0 17
#define INT_LCD 16
#define INT_UART2 15
#define INT_TIMER4 14
#define INT_TIMER3 13
#define INT_TIMER2 12
#define INT_TIMER1 11
#define INT_TIMER0 10
#define INT_WDT 9
#define INT_TICK 8
#define nBATT_FLT 7
#define EINT8_23 5
#define EINT4_7 4
#define EINT3 3
#define EINT2 2
#define EINT1 1
#define EINT0 0
#define INT_ADC 31
#define INT_RTC 30
#define INT_SPI1 29
#define INT_UART0 28
#define INT_IIC 27
#define INT_USBH 26
#define INT_USBD 25
#define INT_UART1 23
#define INT_SPI0 22
#define INT_SDI 21
#define INT_DMA3 20
#define INT_DMA2 19
#define INT_DMA1 18
#define INT_DMA0 17
#define INT_LCD 16
#define INT_UART2 15
#define INT_TIMER4 14
#define INT_TIMER3 13
#define INT_TIMER2 12
#define INT_TIMER1 11
#define INT_TIMER0 10
#define INT_WDT 9
#define INT_TICK 8
#define nBATT_FLT 7
#define EINT8_23 5
#define EINT4_7 4
#define EINT3 3
#define EINT2 2
#define EINT1 1
#define EINT0 0
#define SUB_INT_ADC 10
#define SUB_INT_TC 9
#define SUB_INT_ERR2 8
#define SUB_INT_TXD2 7
#define SUB_INT_RXD2 6
#define SUB_INT_ERR1 5
#define SUB_INT_TXD1 4
#define SUB_INT_RXD1 3
#define SUB_INT_ERR0 2
#define SUB_INT_TXD0 1
#define SUB_INT_RXD0 0
#define SUB_INT_ADC 10
#define SUB_INT_TC 9
#define SUB_INT_ERR2 8
#define SUB_INT_TXD2 7
#define SUB_INT_RXD2 6
#define SUB_INT_ERR1 5
#define SUB_INT_TXD1 4
#define SUB_INT_RXD1 3
#define SUB_INT_ERR0 2
#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_SEL_SHIFT 7
#define ARB1_SEL_SHIFT 9
#define ARB2_SEL_SHIFT 11
#define ARB3_SEL_SHIFT 13
#define ARB4_SEL_SHIFT 15
#define ARB5_SEL_SHIFT 17
#define ARB6_SEL_SHIFT 19
#define ARBx_SEL_MASK 3
#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
#define ARB3_SEL_SHIFT 13
#define ARB4_SEL_SHIFT 15
#define ARB5_SEL_SHIFT 17
#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) */

File diff suppressed because it is too large Load diff

View file

@ -15,402 +15,348 @@
#include "x49gp_ui.h"
#include "s3c2410.h"
typedef struct {
uint32_t lcdcon1;
uint32_t lcdcon2;
uint32_t lcdcon3;
uint32_t lcdcon4;
uint32_t lcdcon5;
uint32_t lcdsaddr1;
uint32_t lcdsaddr2;
uint32_t lcdsaddr3;
uint32_t redlut;
uint32_t greenlut;
uint32_t bluelut;
uint32_t dithmode;
uint32_t tpal;
uint32_t lcdintpnd;
uint32_t lcdsrcpnd;
uint32_t lcdintmsk;
uint32_t lpcsel;
uint32_t __unknown_68;
uint32_t lcdcon1;
uint32_t lcdcon2;
uint32_t lcdcon3;
uint32_t lcdcon4;
uint32_t lcdcon5;
uint32_t lcdsaddr1;
uint32_t lcdsaddr2;
uint32_t lcdsaddr3;
uint32_t redlut;
uint32_t greenlut;
uint32_t bluelut;
uint32_t dithmode;
uint32_t tpal;
uint32_t lcdintpnd;
uint32_t lcdsrcpnd;
uint32_t lcdintmsk;
uint32_t lpcsel;
uint32_t __unknown_68;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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_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 ) };
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__);
return -ENOMEM;
}
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;
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;
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 >>= pixel_offset & 31;
data &= (1 << bits_per_pixel) - 1;
data = ldl_phys( addr + offset );
data >>= pixel_offset & 31;
data &= ( 1 << bits_per_pixel ) - 1;
switch (bits_per_pixel) {
case 1:
return 15 * data;
case 2:
return 15 & (lcd->bluelut >> (4 * data));
default:
return data;
}
switch ( bits_per_pixel ) {
case 1:
return 15 * data;
case 2:
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;
GdkRectangle rect;
GdkGC *gc;
int color, x, y;
x49gp_ui_t* ui = x49gp->ui;
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
GdkRectangle rect;
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);
goto done;
}
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;
rect.y = 0;
rect.width = ui->lcd_width;
rect.height = ui->lcd_height;
rect.x = 0;
rect.y = 0;
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;
uint32_t linecnt;
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) {
case S3C2410_LCD_LCDCON1:
linecnt = (lcd->lcdcon1 >> 18) & 0x3ff;
if (linecnt > 0) {
linecnt--;
} else {
linecnt = (lcd->lcdcon2 >> 14) & 0x3ff;
}
switch ( offset ) {
case S3C2410_LCD_LCDCON1:
linecnt = ( lcd->lcdcon1 >> 18 ) & 0x3ff;
if ( linecnt > 0 ) {
linecnt--;
} else {
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)) {
return;
}
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) {
case S3C2410_LCD_LCDCON1:
if ((lcd->lcdcon1 ^ data) & 1) {
x49gp_schedule_lcd_update(x49gp);
}
switch ( offset ) {
case S3C2410_LCD_LCDCON1:
if ( ( lcd->lcdcon1 ^ data ) & 1 ) {
x49gp_schedule_lcd_update( x49gp );
}
lcd->lcdcon1 = (lcd->lcdcon1 & (0x3ff << 18)) |
(data & ~(0x3ff << 18));
break;
default:
*(reg->datap) = data;
break;
}
lcd->lcdcon1 = ( lcd->lcdcon1 & ( 0x3ff << 18 ) ) | ( data & ~( 0x3ff << 18 ) );
break;
default:
*( 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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_lcd_data_init(lcd)) {
free(lcd);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = lcd;
module->x49gp->s3c2410_lcd = lcd;
lcd->x49gp = module->x49gp;
module->user_data = lcd;
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);
return 0;
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) {
lcd = module->user_data;
if (lcd->regs)
free(lcd->regs);
free(lcd);
}
if ( module->user_data ) {
lcd = module->user_data;
if ( lcd->regs )
free( lcd->regs );
free( lcd );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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,263 +12,231 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t bwscon;
uint32_t bankcon0;
uint32_t bankcon1;
uint32_t bankcon2;
uint32_t bankcon3;
uint32_t bankcon4;
uint32_t bankcon5;
uint32_t bankcon6;
uint32_t bankcon7;
uint32_t refresh;
uint32_t banksize;
uint32_t mrsrb6;
uint32_t mrsrb7;
uint32_t bwscon;
uint32_t bankcon0;
uint32_t bankcon1;
uint32_t bankcon2;
uint32_t bankcon3;
uint32_t bankcon4;
uint32_t bankcon5;
uint32_t bankcon6;
uint32_t bankcon7;
uint32_t refresh;
uint32_t banksize;
uint32_t mrsrb6;
uint32_t mrsrb7;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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_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 ),
};
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__);
return -ENOMEM;
}
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;
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)) {
return;
}
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_memc_data_init(memc)) {
free(memc);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = memc;
memc->x49gp = module->x49gp;
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);
return 0;
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) {
memc = module->user_data;
if (memc->regs)
free(memc->regs);
free(memc);
}
if ( module->user_data ) {
memc = module->user_data;
if ( memc->regs )
free( memc->regs );
free( memc );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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

@ -4,34 +4,34 @@
#ifndef _S3C2410_MMU_H
#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_SIZE 64
#define S3C2410_MMU_TLB_MASK ( S3C2410_MMU_TLB_SIZE - 1 )
typedef struct {
uint32_t mva;
uint32_t mask;
uint32_t pa;
uint32_t dac;
int valid;
uint32_t mva;
uint32_t mask;
uint32_t pa;
uint32_t dac;
int valid;
} TLB_entry_t;
typedef struct {
int victim;
int base;
int index0;
int index1;
unsigned long hit0;
unsigned long hit1;
unsigned long search;
unsigned long nsearch;
unsigned long walk;
TLB_entry_t data[S3C2410_MMU_TLB_SIZE];
int victim;
int base;
int index0;
int index1;
unsigned long hit0;
unsigned long hit1;
unsigned long search;
unsigned long nsearch;
unsigned long walk;
TLB_entry_t data[ S3C2410_MMU_TLB_SIZE ];
} TLB_t;
typedef struct {
uint32_t MMUReg[16];
TLB_t iTLB;
TLB_t dTLB;
uint32_t MMUReg[ 16 ];
TLB_t iTLB;
TLB_t dTLB;
} s3c2410_mmu_t;
#endif /* !(_S3C2410_MMU_H) */

View file

@ -12,244 +12,206 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t nfconf;
uint32_t nfcmd;
uint32_t nfaddr;
uint32_t nfdata;
uint32_t nfstat;
uint32_t nfecc;
uint32_t nfconf;
uint32_t nfcmd;
uint32_t nfaddr;
uint32_t nfdata;
uint32_t nfstat;
uint32_t nfecc;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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_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 ),
};
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__);
return -ENOMEM;
}
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;
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)) {
return;
}
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_nand_data_init(nand)) {
free(nand);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = nand;
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);
return 0;
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) {
nand = module->user_data;
if (nand->regs)
free(nand->regs);
free(nand);
}
if ( module->user_data ) {
nand = module->user_data;
if ( nand->regs )
free( nand->regs );
free( nand );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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

@ -16,351 +16,311 @@
static const uint32_t EXTCLK = 12000000;
typedef struct {
uint32_t locktime;
uint32_t mpllcon;
uint32_t upllcon;
uint32_t clkcon;
uint32_t clkslow;
uint32_t clkdivn;
uint32_t locktime;
uint32_t mpllcon;
uint32_t upllcon;
uint32_t clkcon;
uint32_t clkslow;
uint32_t clkdivn;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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_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 ) };
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__);
return -ENOMEM;
}
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;
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;
uint32_t mMdiv, mPdiv, mSdiv;
uint32_t uMdiv, uPdiv, uSdiv;
uint32_t slow_bit, slow_val;
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)) {
return;
}
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) {
case S3C2410_POWER_CLKCON:
if (data & CLKCON_POWER_OFF) {
*(reg->datap) = 0x7fff0;
switch ( offset ) {
case S3C2410_POWER_CLKCON:
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);
return;
}
// 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);
return;
}
x49gp_set_idle( x49gp, X49GP_ARM_SLEEP );
return;
}
*(reg->datap) = data;
return;
*( reg->datap ) = data;
return;
case S3C2410_POWER_LOCKTIME:
*(reg->datap) = data;
return;
case S3C2410_POWER_LOCKTIME:
*( reg->datap ) = data;
return;
default:
*(reg->datap) = data;
break;
}
default:
*( 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)
x49gp->FCLK = EXTCLK;
else
x49gp->FCLK = EXTCLK / (2 * slow_val);
} else {
x49gp->FCLK = x49gp->MCLK;
}
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 );
} else {
x49gp->FCLK = x49gp->MCLK;
}
if (power->clkdivn & 4) {
x49gp->HCLK = x49gp->FCLK / 4;
x49gp->PCLK = x49gp->FCLK / 4;
x49gp->PCLK_ratio = 4;
} else {
switch (power->clkdivn & 3) {
case 0:
x49gp->HCLK = x49gp->FCLK;
x49gp->PCLK = x49gp->HCLK;
x49gp->PCLK_ratio = 1;
break;
case 1:
x49gp->HCLK = x49gp->FCLK;
x49gp->PCLK = x49gp->HCLK / 2;
x49gp->PCLK_ratio = 2;
break;
case 2:
x49gp->HCLK = x49gp->FCLK / 2;
x49gp->PCLK = x49gp->HCLK;
x49gp->PCLK_ratio = 2;
break;
case 3:
x49gp->HCLK = x49gp->FCLK / 2;
x49gp->PCLK = x49gp->HCLK / 2;
x49gp->PCLK_ratio = 4;
break;
}
}
if ( power->clkdivn & 4 ) {
x49gp->HCLK = x49gp->FCLK / 4;
x49gp->PCLK = x49gp->FCLK / 4;
x49gp->PCLK_ratio = 4;
} else {
switch ( power->clkdivn & 3 ) {
case 0:
x49gp->HCLK = x49gp->FCLK;
x49gp->PCLK = x49gp->HCLK;
x49gp->PCLK_ratio = 1;
break;
case 1:
x49gp->HCLK = x49gp->FCLK;
x49gp->PCLK = x49gp->HCLK / 2;
x49gp->PCLK_ratio = 2;
break;
case 2:
x49gp->HCLK = x49gp->FCLK / 2;
x49gp->PCLK = x49gp->HCLK;
x49gp->PCLK_ratio = 2;
break;
case 3:
x49gp->HCLK = x49gp->FCLK / 2;
x49gp->PCLK = x49gp->HCLK / 2;
x49gp->PCLK_ratio = 4;
break;
}
}
#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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
if (error) {
return error;
}
if ( error ) {
return error;
}
s3c2410_power_write(power, S3C2410_POWER_BASE | S3C2410_POWER_CLKDIVN,
power->clkdivn);
return 0;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_power_data_init(power)) {
free(power);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = power;
power->x49gp = module->x49gp;
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);
return 0;
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) {
power = module->user_data;
if (power->regs)
free(power->regs);
free(power);
}
if ( module->user_data ) {
power = module->user_data;
if ( power->regs )
free( power->regs );
free( power );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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

@ -4,24 +4,24 @@
#ifndef _S3C2410_POWER_H
#define _S3C2410_POWER_H 1
#define CLKCON_SPI 0x00040000
#define CLKCON_IIS 0x00020000
#define CLKCON_IIC 0x00010000
#define CLKCON_ADC 0x00008000
#define CLKCON_RTC 0x00004000
#define CLKCON_GPIO 0x00002000
#define CLKCON_UART2 0x00001000
#define CLKCON_UART1 0x00000800
#define CLKCON_UART0 0x00000400
#define CLKCON_SDI 0x00000200
#define CLKCON_TIMER 0x00000100
#define CLKCON_USBD 0x00000080
#define CLKCON_USBH 0x00000040
#define CLKCON_LCD 0x00000020
#define CLKCON_NAND 0x00000010
#define CLKCON_POWER_OFF 0x00000008
#define CLKCON_IDLE 0x00000004
#define CLKCON_SM_BIT 0x00000001
#define CLKCON_SPI 0x00040000
#define CLKCON_IIS 0x00020000
#define CLKCON_IIC 0x00010000
#define CLKCON_ADC 0x00008000
#define CLKCON_RTC 0x00004000
#define CLKCON_GPIO 0x00002000
#define CLKCON_UART2 0x00001000
#define CLKCON_UART1 0x00000800
#define CLKCON_UART0 0x00000400
#define CLKCON_SDI 0x00000200
#define CLKCON_TIMER 0x00000100
#define CLKCON_USBD 0x00000080
#define CLKCON_USBH 0x00000040
#define CLKCON_LCD 0x00000020
#define CLKCON_NAND 0x00000010
#define CLKCON_POWER_OFF 0x00000008
#define CLKCON_IDLE 0x00000004
#define CLKCON_SM_BIT 0x00000001
extern int s3c2410_idle;

View file

@ -14,490 +14,435 @@
#include "s3c2410.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t rtccon;
uint32_t ticnt;
uint32_t rtcalm;
uint32_t almsec;
uint32_t almmin;
uint32_t almhour;
uint32_t almdate;
uint32_t almmon;
uint32_t almyear;
uint32_t rtcrst;
uint32_t bcdsec;
uint32_t bcdmin;
uint32_t bcdhour;
uint32_t bcddate;
uint32_t bcdday;
uint32_t bcdmon;
uint32_t bcdyear;
uint32_t rtccon;
uint32_t ticnt;
uint32_t rtcalm;
uint32_t almsec;
uint32_t almmin;
uint32_t almhour;
uint32_t almdate;
uint32_t almmon;
uint32_t almyear;
uint32_t rtcrst;
uint32_t bcdsec;
uint32_t bcdmin;
uint32_t bcdhour;
uint32_t bcddate;
uint32_t bcdday;
uint32_t bcdmon;
uint32_t bcdyear;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_regs;
s3c2410_offset_t* regs;
x49gp_t *x49gp;
x49gp_timer_t *tick_timer;
x49gp_timer_t *alarm_timer;
int64_t interval; /* us */
int64_t expires; /* us */
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__);
return -ENOMEM;
}
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;
return 0;
}
static __inline__ uint32_t bin2bcd(uint32_t bin)
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 void s3c2410_rtc_timeout( void* user_data )
{
return ((bin / 10) << 4) | (bin % 10);
s3c2410_rtc_t* rtc = user_data;
x49gp_t* x49gp = rtc->x49gp;
int64_t now, us;
if ( !( rtc->ticnt & 0x80 ) ) {
return;
}
#ifdef DEBUG_S3C2410_RTC
printf( "RTC: assert TICK interrupt\n" );
#endif
s3c2410_intc_assert( x49gp, INT_TICK, 0 );
now = x49gp_get_clock();
while ( rtc->expires <= now ) {
rtc->expires += rtc->interval;
}
us = rtc->expires - now;
if ( us < 1000 )
us = 1000;
#ifdef DEBUG_S3C2410_RTC
printf( "RTC: restart TICK timer (%llu us)\n", ( unsigned long long )us );
#endif
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
}
static __inline__ uint32_t bcd2bin(uint32_t bcd)
static int s3c2410_rtc_set_ticnt( s3c2410_rtc_t* rtc )
{
return ((bcd >> 4) * 10) + (bcd & 0x0f);
int64_t now, us;
if ( x49gp_timer_pending( rtc->tick_timer ) ) {
x49gp_del_timer( rtc->tick_timer );
#ifdef DEBUG_S3C2410_RTC
printf( "RTC: stop TICK timer\n" );
#endif
}
if ( !( rtc->ticnt & 0x80 ) ) {
return 0;
}
us = ( ( ( rtc->ticnt & 0x7f ) + 1 ) * 1000000 ) / 128;
rtc->interval = us;
if ( rtc->interval < 1000 )
rtc->interval = 1000;
now = x49gp_get_clock();
rtc->expires = now + rtc->interval;
us = rtc->expires - now;
if ( us < 1000 )
us = 1000;
#ifdef DEBUG_S3C2410_RTC
printf( "RTC: start TICK timer (%lld us)\n", ( unsigned long long )us );
#endif
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
return 0;
}
static void
s3c2410_rtc_timeout(void * user_data)
static void s3c2410_rtc_alarm( void* user_data )
{
s3c2410_rtc_t *rtc = user_data;
x49gp_t *x49gp = rtc->x49gp;
int64_t now, us;
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->ticnt & 0x80)) {
return;
}
if ( !( rtc->rtcalm & 0x40 ) ) {
return;
}
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 ) )
match = 0;
}
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 ) )
match = 0;
}
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 ) )
match = 0;
}
if ( match && ( rtc->rtcalm & 0x20 ) ) {
if ( ( tm->tm_year % 100 ) != bcd2bin( rtc->almyear ) )
match = 0;
}
if ( match ) {
#ifdef DEBUG_S3C2410_RTC
printf( "RTC: assert ALARM interrupt\n" );
#endif
s3c2410_intc_assert( x49gp, INT_RTC, 0 );
}
#ifdef DEBUG_S3C2410_RTC
printf("RTC: assert TICK interrupt\n");
printf( "RTC: reload ALARM timer (%lld us)\n", ( unsigned long long )us );
#endif
s3c2410_intc_assert(x49gp, INT_TICK, 0);
now = x49gp_get_clock();
while (rtc->expires <= now) {
rtc->expires += rtc->interval;
}
us = rtc->expires - now;
if (us < 1000)
us = 1000;
#ifdef DEBUG_S3C2410_RTC
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->alarm_timer, now + us );
}
static int
s3c2410_rtc_set_ticnt(s3c2410_rtc_t *rtc)
static int s3c2410_rtc_set_rtcalm( s3c2410_rtc_t* rtc )
{
int64_t now, us;
struct timeval tv;
int64_t now, us;
if (x49gp_timer_pending(rtc->tick_timer)) {
x49gp_del_timer(rtc->tick_timer);
#ifdef DEBUG_S3C2410_RTC
printf("RTC: stop TICK timer\n");
#endif
}
if ( !( rtc->rtcalm & 0x40 ) ) {
x49gp_del_timer( rtc->alarm_timer );
return 0;
}
if (!(rtc->ticnt & 0x80)) {
return 0;
}
gettimeofday( &tv, NULL );
us = (((rtc->ticnt & 0x7f) + 1) * 1000000) / 128;
rtc->interval = us;
if (rtc->interval < 1000)
rtc->interval = 1000;
now = x49gp_get_clock();
rtc->expires = now + rtc->interval;
us = rtc->expires - now;
if (us < 1000)
us = 1000;
now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec;
#ifdef DEBUG_S3C2410_RTC
printf("RTC: start TICK 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->tick_timer, rtc->expires);
return 0;
x49gp_mod_timer( rtc->alarm_timer, now + us );
return 0;
}
static void
s3c2410_rtc_alarm(void * user_data)
static uint32_t s3c2410_rtc_read( void* opaque, target_phys_addr_t offset )
{
s3c2410_rtc_t *rtc = user_data;
x49gp_t *x49gp = rtc->x49gp;
struct tm *tm;
struct timeval tv;
int64_t now, us;
int match = 1;
s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t* reg;
if (!(rtc->rtcalm & 0x40)) {
return;
}
if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return ~( 0 );
}
gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec;
if ( S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR ) {
struct tm* tm;
struct timeval tv;
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))
match = 0;
}
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))
match = 0;
}
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))
match = 0;
}
gettimeofday( &tv, NULL );
tm = localtime( &tv.tv_sec );
if (match) {
#ifdef DEBUG_S3C2410_RTC
printf("RTC: assert ALARM interrupt\n");
#endif
s3c2410_intc_assert(x49gp, INT_RTC, 0);
}
switch ( offset ) {
case S3C2410_RTC_BCDSEC:
*( reg->datap ) = bin2bcd( tm->tm_sec );
break;
case S3C2410_RTC_BCDMIN:
*( reg->datap ) = bin2bcd( tm->tm_min );
break;
case S3C2410_RTC_BCDHOUR:
*( reg->datap ) = bin2bcd( tm->tm_hour );
break;
case S3C2410_RTC_BCDDATE:
*( reg->datap ) = bin2bcd( tm->tm_mday );
break;
case S3C2410_RTC_BCDDAY:
*( reg->datap ) = bin2bcd( tm->tm_wday + 1 );
break;
case S3C2410_RTC_BCDMON:
*( reg->datap ) = bin2bcd( tm->tm_mon + 1 );
break;
case S3C2410_RTC_BCDYEAR:
*( reg->datap ) = bin2bcd( tm->tm_year % 100 );
break;
}
}
#ifdef DEBUG_S3C2410_RTC
printf("RTC: reload ALARM timer (%lld us)\n", (unsigned long long) us);
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset,
*( reg->datap ) );
#endif
x49gp_mod_timer(rtc->alarm_timer, now + us);
return *( reg->datap );
}
static int
s3c2410_rtc_set_rtcalm(s3c2410_rtc_t *rtc)
static void s3c2410_rtc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
{
struct timeval tv;
int64_t now, us;
s3c2410_rtc_t* rtc = opaque;
s3c2410_offset_t* reg;
if (!(rtc->rtcalm & 0x40)) {
x49gp_del_timer(rtc->alarm_timer);
return 0;
}
if ( !S3C2410_OFFSET_OK( rtc, offset ) ) {
return;
}
gettimeofday(&tv, NULL);
now = x49gp_get_clock();
us = 1000000LL - tv.tv_usec;
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
#ifdef DEBUG_S3C2410_RTC
printf("RTC: start ALARM timer (%lld us)\n", (unsigned long long) us);
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset, data );
#endif
x49gp_mod_timer(rtc->alarm_timer, now + us);
return 0;
switch ( offset ) {
case S3C2410_RTC_TICNT:
*( reg->datap ) = data;
s3c2410_rtc_set_ticnt( rtc );
break;
case S3C2410_RTC_RTCALM:
*( reg->datap ) = data;
s3c2410_rtc_set_rtcalm( rtc );
break;
default:
*( reg->datap ) = data;
break;
}
}
static uint32_t
s3c2410_rtc_read(void *opaque, target_phys_addr_t offset)
static int s3c2410_rtc_load( x49gp_module_t* module, GKeyFile* key )
{
s3c2410_rtc_t *rtc = opaque;
s3c2410_offset_t *reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) {
return ~(0);
}
reg = S3C2410_OFFSET_ENTRY(rtc, offset);
if (S3C2410_RTC_BCDSEC <= offset && offset <= S3C2410_RTC_BCDYEAR) {
struct tm *tm;
struct timeval tv;
gettimeofday(&tv, NULL);
tm = localtime(&tv.tv_sec);
switch (offset) {
case S3C2410_RTC_BCDSEC:
*(reg->datap) = bin2bcd(tm->tm_sec);
break;
case S3C2410_RTC_BCDMIN:
*(reg->datap) = bin2bcd(tm->tm_min);
break;
case S3C2410_RTC_BCDHOUR:
*(reg->datap) = bin2bcd(tm->tm_hour);
break;
case S3C2410_RTC_BCDDATE:
*(reg->datap) = bin2bcd(tm->tm_mday);
break;
case S3C2410_RTC_BCDDAY:
*(reg->datap) = bin2bcd(tm->tm_wday + 1);
break;
case S3C2410_RTC_BCDMON:
*(reg->datap) = bin2bcd(tm->tm_mon + 1);
break;
case S3C2410_RTC_BCDYEAR:
*(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));
#endif
return *(reg->datap);
}
static void
s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
{
s3c2410_rtc_t *rtc = opaque;
s3c2410_offset_t *reg;
if (! S3C2410_OFFSET_OK(rtc, offset)) {
return;
}
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);
#endif
switch (offset) {
case S3C2410_RTC_TICNT:
*(reg->datap) = data;
s3c2410_rtc_set_ticnt(rtc);
break;
case S3C2410_RTC_RTCALM:
*(reg->datap) = data;
s3c2410_rtc_set_rtcalm(rtc);
break;
default:
*(reg->datap) = data;
break;
}
}
static int
s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
{
s3c2410_rtc_t *rtc = module->user_data;
s3c2410_offset_t *reg;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
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;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
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;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_rtc_data_init(rtc)) {
free(rtc);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = rtc;
rtc->x49gp = module->x49gp;
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;
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) {
rtc = module->user_data;
if (rtc->regs)
free(rtc->regs);
free(rtc);
}
if ( module->user_data ) {
rtc = module->user_data;
if ( rtc->regs )
free( rtc->regs );
free( rtc );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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,281 +13,242 @@
#include "s3c2410.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t spicon0;
uint32_t spista0;
uint32_t sppin0;
uint32_t sppre0;
uint32_t sptdat0;
uint32_t sprdat0;
uint32_t spicon1;
uint32_t spista1;
uint32_t sppin1;
uint32_t sppre1;
uint32_t sptdat1;
uint32_t sprdat1;
uint32_t spicon0;
uint32_t spista0;
uint32_t sppin0;
uint32_t sppre0;
uint32_t sptdat0;
uint32_t sprdat0;
uint32_t spicon1;
uint32_t spista1;
uint32_t sppin1;
uint32_t sppre1;
uint32_t sptdat1;
uint32_t sprdat1;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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__);
return -ENOMEM;
}
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;
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) {
case S3C2410_SPI_SPRDAT0:
spi->spista0 &= ~(1);
break;
switch ( offset ) {
case S3C2410_SPI_SPRDAT0:
spi->spista0 &= ~( 1 );
break;
case S3C2410_SPI_SPRDAT1:
spi->spista1 &= ~(1);
break;
}
case S3C2410_SPI_SPRDAT1:
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)) {
return;
}
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) {
case S3C2410_SPI_SPTDAT0:
spi->spista0 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI0, 0);
break;
switch ( offset ) {
case S3C2410_SPI_SPTDAT0:
spi->spista0 |= 1;
s3c2410_intc_assert( x49gp, INT_SPI0, 0 );
break;
case S3C2410_SPI_SPTDAT1:
spi->spista1 |= 1;
s3c2410_intc_assert(x49gp, INT_SPI1, 0);
break;
}
case S3C2410_SPI_SPTDAT1:
spi->spista1 |= 1;
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_spi_data_init(spi)) {
free(spi);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = spi;
spi->x49gp = module->x49gp;
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);
return 0;
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) {
spi = module->user_data;
if (spi->regs)
free(spi->regs);
free(spi);
}
if ( module->user_data ) {
spi = module->user_data;
if ( spi->regs )
free( spi->regs );
free( spi );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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,182 +14,157 @@
#include "byteorder.h"
typedef struct {
void *data;
char *filename;
int fd;
uint32_t offset;
size_t size;
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;
int error;
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) {
error = -errno;
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
module->name, __FUNCTION__, __LINE__,
filename, strerror(errno));
g_free(filename);
return error;
}
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 );
return error;
}
filemap->size = S3C2410_SRAM_SIZE;
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);
filemap->fd = -1;
return error;
}
filemap->size = S3C2410_SRAM_SIZE;
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 );
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) {
error = -errno;
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;
}
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 );
filemap->fd = -1;
return error;
}
g_free(filename);
g_free( filename );
x49gp_schedule_lcd_update(module->x49gp);
return error;
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;
int error;
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));
return error;
}
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));
return error;
}
error = fsync( filemap->fd );
if ( error ) {
fprintf( stderr, "%s:%u: fsync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
return error;
}
return 0;
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;
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__);
return -ENOMEM;
}
filemap = malloc( sizeof( filemap_t ) );
if ( NULL == filemap ) {
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
return -ENOMEM;
}
filemap->size = 0;
filemap->fd = -1;
filemap->size = 0;
filemap->fd = -1;
module->user_data = filemap;
module->user_data = filemap;
filemap->data = (void *) -1;
filemap->offset = phys_ram_size;
phys_ram_size += S3C2410_SRAM_SIZE;
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;
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) {
filemap = module->user_data;
if ( module->user_data ) {
filemap = module->user_data;
if (filemap->data != (void *) -1) {
munmap(filemap->data, filemap->size);
}
if (filemap->fd >= 0) {
close(filemap->fd);
}
if ( filemap->data != ( void* )-1 ) {
munmap( filemap->data, filemap->size );
}
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;
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)) {
return -1;
}
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,546 +14,490 @@
#include "s3c2410_timer.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t reload_bit;
uint32_t update_bit;
uint32_t start_bit;
unsigned int pre_shift;
unsigned int mux_shift;
int irq;
uint32_t reload_bit;
uint32_t update_bit;
uint32_t start_bit;
unsigned int pre_shift;
unsigned int mux_shift;
int irq;
} s3c2410_timer_config_t;
struct __s3c2410_timer_s__;
typedef struct __s3c2410_timer_s__ s3c2410_timer_t;
struct __s3c2410_timer_s__ {
uint32_t tcfg0;
uint32_t tcfg1;
uint32_t tcon;
uint32_t prev_tcon;
uint32_t tcfg0;
uint32_t tcfg1;
uint32_t tcon;
uint32_t prev_tcon;
x49gp_t *x49gp;
x49gp_t* x49gp;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_regs;
s3c2410_offset_t* regs;
struct s3c2410_timeout {
uint32_t tcntb;
uint32_t tcmpb;
uint32_t tcnt;
uint32_t tcmp;
struct s3c2410_timeout {
uint32_t tcntb;
uint32_t tcmpb;
uint32_t tcnt;
uint32_t tcmp;
const s3c2410_timer_config_t *tconfig;
int index;
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];
unsigned long interval;
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__);
return -ENOMEM;
}
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;
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;
int64_t timeout;
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) {
t->tcnt = t->tcntb;
t->tcmp = t->tcmpb;
} else {
timer->tcon &= ~(t->tconfig->start_bit);
return;
}
if ( timer->tcon & t->tconfig->reload_bit ) {
t->tcnt = t->tcntb;
t->tcmp = t->tcmpb;
} else {
timer->tcon &= ~( t->tconfig->start_bit );
return;
}
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
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;
unsigned long irq, next;
unsigned long ticks;
int i;
s3c2410_timer_t* timer = x49gp->s3c2410_timer;
struct s3c2410_timeout* t;
unsigned long irq, next;
unsigned long ticks;
int i;
ticks = x49gp_get_clock();
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))
continue;
if ( !( timer->tcon & t->tconfig->start_bit ) )
continue;
if (x49gp_timer_pending(t->timer)) {
irq = x49gp_timer_expires(t->timer) - ticks;
} else {
irq = 0;
}
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;
} else {
if (!(timer->tcon & t->tconfig->reload_bit))
continue;
irq += t->tcntb * t->interval;
}
if ( t->tcnt ) {
irq += ( t->tcnt - 1 ) * t->interval;
} else {
if ( !( timer->tcon & t->tconfig->reload_bit ) )
continue;
irq += t->tcntb * t->interval;
}
if (irq < next)
next = irq;
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;
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;
uint32_t pre, mux;
int64_t timeout;
int i;
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);
mux = 3;
}
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)) {
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
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;
int64_t timeout;
uint32_t change;
int i;
struct s3c2410_timeout* t;
x49gp_t* x49gp = timer->x49gp;
int64_t timeout;
uint32_t change;
int i;
change = timer->prev_tcon ^ timer->tcon;
timer->prev_tcon = timer->tcon;
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) {
t->tcnt = t->tcntb;
t->tcmp = t->tcmpb;
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) {
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
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);
} else {
x49gp_del_timer(t->timer);
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
} else {
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;
int64_t now, expires, timeout;
struct s3c2410_timeout* t = &timer->timeout[ index ];
x49gp_t* x49gp = timer->x49gp;
int64_t now, expires, timeout;
if (!(timer->tcon & t->tconfig->start_bit))
return t->tcnt;
if ( !( timer->tcon & t->tconfig->start_bit ) )
return t->tcnt;
if (x49gp_timer_pending(t->timer)) {
now = x49gp_get_clock();
expires = x49gp_timer_expires(t->timer);
if ( x49gp_timer_pending( t->timer ) ) {
now = x49gp_get_clock();
expires = x49gp_timer_expires( t->timer );
timeout = expires - now;
if (timeout <= 0)
return 0;
timeout = expires - now;
if ( timeout <= 0 )
return 0;
t->tcnt = timeout * x49gp->PCLK / (1000000LL * t->interval);
}
t->tcnt = timeout * x49gp->PCLK / ( 1000000LL * t->interval );
}
return t->tcnt;
return t->tcnt;
}
static uint32_t
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;
uint32_t data;
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) {
case S3C2410_TIMER_TCNTO0:
data = s3c2410_read_tcnt(timer, 0);
break;
case S3C2410_TIMER_TCNTO1:
data = s3c2410_read_tcnt(timer, 1);
break;
case S3C2410_TIMER_TCNTO2:
data = s3c2410_read_tcnt(timer, 2);
break;
case S3C2410_TIMER_TCNTO3:
data = s3c2410_read_tcnt(timer, 3);
break;
case S3C2410_TIMER_TCNTO4:
data = s3c2410_read_tcnt(timer, 4);
break;
default:
data = *(reg->datap);
break;
}
switch ( offset ) {
case S3C2410_TIMER_TCNTO0:
data = s3c2410_read_tcnt( timer, 0 );
break;
case S3C2410_TIMER_TCNTO1:
data = s3c2410_read_tcnt( timer, 1 );
break;
case S3C2410_TIMER_TCNTO2:
data = s3c2410_read_tcnt( timer, 2 );
break;
case S3C2410_TIMER_TCNTO3:
data = s3c2410_read_tcnt( timer, 3 );
break;
case S3C2410_TIMER_TCNTO4:
data = s3c2410_read_tcnt( timer, 4 );
break;
default:
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;
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)) {
return;
}
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) {
case S3C2410_TIMER_TCFG0:
*(reg->datap) = data;
s3c2410_update_tcfg(timer);
break;
case S3C2410_TIMER_TCFG1:
*(reg->datap) = data;
s3c2410_update_tcfg(timer);
break;
case S3C2410_TIMER_TCON:
*(reg->datap) = data;
s3c2410_update_tcon(timer);
break;
case S3C2410_TIMER_TCNTO0:
case S3C2410_TIMER_TCNTO1:
case S3C2410_TIMER_TCNTO2:
case S3C2410_TIMER_TCNTO3:
case S3C2410_TIMER_TCNTO4:
/* read only */
break;
default:
*(reg->datap) = data;
break;
}
switch ( offset ) {
case S3C2410_TIMER_TCFG0:
*( reg->datap ) = data;
s3c2410_update_tcfg( timer );
break;
case S3C2410_TIMER_TCFG1:
*( reg->datap ) = data;
s3c2410_update_tcfg( timer );
break;
case S3C2410_TIMER_TCON:
*( reg->datap ) = data;
s3c2410_update_tcon( timer );
break;
case S3C2410_TIMER_TCNTO0:
case S3C2410_TIMER_TCNTO1:
case S3C2410_TIMER_TCNTO2:
case S3C2410_TIMER_TCNTO3:
case S3C2410_TIMER_TCNTO4:
/* read only */
break;
default:
*( 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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
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;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
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;
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;
int iotype;
int i;
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__);
return -ENOMEM;
}
if (s3c2410_timer_data_init(timer)) {
free(timer);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = timer;
module->user_data = timer;
timer->x49gp = module->x49gp;
module->x49gp->s3c2410_timer = timer;
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->index = i;
t->tconfig = &s3c2410_timer_config[ i ];
t->index = i;
t->main = timer;
t->main = timer;
t->timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t);
}
t->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t );
}
iotype = cpu_register_io_memory(s3c2410_timer_readfn,
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);
return 0;
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) {
timer = module->user_data;
if (timer->regs)
free(timer->regs);
free(timer);
}
if ( module->user_data ) {
timer = module->user_data;
if ( timer->regs )
free( timer->regs );
free( timer );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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

@ -6,43 +6,43 @@
#include "x49gp_types.h"
#define TCFG0_DEAD_SHIFT 16
#define TCFG0_DEAD_MASK 0xff
#define TCFG0_PRE1_SHIFT 8
#define TCFG0_PRE0_SHIFT 0
#define TCFG0_PREx_MASK 0xff
#define TCFG0_DEAD_SHIFT 16
#define TCFG0_DEAD_MASK 0xff
#define TCFG0_PRE1_SHIFT 8
#define TCFG0_PRE0_SHIFT 0
#define TCFG0_PREx_MASK 0xff
#define TCFG1_DMA_SHIFT 20
#define TCFG1_DMA_MASK 0x0f
#define TCFG1_MUX4_SHIFT 16
#define TCFG1_MUX3_SHIFT 12
#define TCFG1_MUX2_SHIFT 8
#define TCFG1_MUX1_SHIFT 4
#define TCFG1_MUX0_SHIFT 0
#define TCFG1_MUXx_MASK 0x0f
#define TCFG1_DMA_SHIFT 20
#define TCFG1_DMA_MASK 0x0f
#define TCFG1_MUX4_SHIFT 16
#define TCFG1_MUX3_SHIFT 12
#define TCFG1_MUX2_SHIFT 8
#define TCFG1_MUX1_SHIFT 4
#define TCFG1_MUX0_SHIFT 0
#define TCFG1_MUXx_MASK 0x0f
#define TCON_TIMER4_RELOAD 0x00400000
#define TCON_TIMER4_UPDATE 0x00200000
#define TCON_TIMER4_START 0x00100000
#define TCON_TIMER3_RELOAD 0x00080000
#define TCON_TIMER3_INVERT 0x00040000
#define TCON_TIMER3_UPDATE 0x00020000
#define TCON_TIMER3_START 0x00010000
#define TCON_TIMER2_RELOAD 0x00008000
#define TCON_TIMER2_INVERT 0x00004000
#define TCON_TIMER2_UPDATE 0x00002000
#define TCON_TIMER2_START 0x00001000
#define TCON_TIMER1_RELOAD 0x00000800
#define TCON_TIMER1_INVERT 0x00000400
#define TCON_TIMER1_UPDATE 0x00000200
#define TCON_TIMER1_START 0x00000100
#define TCON_TIMER0_DEADZONE 0x00000010
#define TCON_TIMER0_RELOAD 0x00000008
#define TCON_TIMER0_INVERT 0x00000004
#define TCON_TIMER0_UPDATE 0x00000002
#define TCON_TIMER0_START 0x00000001
#define TCON_TIMER4_RELOAD 0x00400000
#define TCON_TIMER4_UPDATE 0x00200000
#define TCON_TIMER4_START 0x00100000
#define TCON_TIMER3_RELOAD 0x00080000
#define TCON_TIMER3_INVERT 0x00040000
#define TCON_TIMER3_UPDATE 0x00020000
#define TCON_TIMER3_START 0x00010000
#define TCON_TIMER2_RELOAD 0x00008000
#define TCON_TIMER2_INVERT 0x00004000
#define TCON_TIMER2_UPDATE 0x00002000
#define TCON_TIMER2_START 0x00001000
#define TCON_TIMER1_RELOAD 0x00000800
#define TCON_TIMER1_INVERT 0x00000400
#define TCON_TIMER1_UPDATE 0x00000200
#define TCON_TIMER1_START 0x00000100
#define TCON_TIMER0_DEADZONE 0x00000010
#define TCON_TIMER0_RELOAD 0x00000008
#define TCON_TIMER0_INVERT 0x00000004
#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,466 +13,415 @@
#include "s3c2410.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t ulcon;
uint32_t ucon;
uint32_t ufcon;
uint32_t umcon;
uint32_t utrstat;
uint32_t uerstat;
uint32_t ufstat;
uint32_t umstat;
uint32_t utxh;
uint32_t urxh;
uint32_t ubrdiv;
uint32_t ulcon;
uint32_t ucon;
uint32_t ufcon;
uint32_t umcon;
uint32_t utrstat;
uint32_t uerstat;
uint32_t ufstat;
uint32_t umstat;
uint32_t utxh;
uint32_t urxh;
uint32_t ubrdiv;
int int_err;
int int_txd;
int int_rxd;
int int_err;
int int_txd;
int int_rxd;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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__);
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);
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);
return -ENOMEM;
}
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 );
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 );
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;
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;
uint32_t mod_offset;
uint32_t base;
const char* module;
uint32_t mod_offset;
uint32_t base;
base = (offset & 0x0000c000) >> 14;
base = ( offset & 0x0000c000 ) >> 14;
switch (base) {
case 0:
module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE;
break;
case 1:
module = "s3c2410-uart1";
mod_offset = S3C2410_UART1_BASE;
break;
case 2:
module = "s3c2410-uart2";
mod_offset = S3C2410_UART2_BASE;
break;
default:
return ~(0);
}
switch ( base ) {
case 0:
module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE;
break;
case 1:
module = "s3c2410-uart1";
mod_offset = S3C2410_UART1_BASE;
break;
case 2:
module = "s3c2410-uart2";
mod_offset = S3C2410_UART2_BASE;
break;
default:
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) {
case S3C2410_UART0_URXH:
uart_regs->utrstat &= ~(1 << 0);
switch ( offset ) {
case S3C2410_UART0_URXH:
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;
}
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;
uint32_t base;
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;
uint32_t mod_offset, ubrdivn, baud;
const char* module;
uint32_t mod_offset, ubrdivn, baud;
#endif
base = (offset & 0x0000c000) >> 14;
base = ( offset & 0x0000c000 ) >> 14;
#ifdef DEBUG_S3C2410_UART
switch (base) {
case 0:
module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE;
break;
case 1:
module = "s3c2410-uart1";
mod_offset = S3C2410_UART1_BASE;
break;
case 2:
module = "s3c2410-uart2";
mod_offset = S3C2410_UART2_BASE;
break;
default:
return;
}
switch ( base ) {
case 0:
module = "s3c2410-uart0";
mod_offset = S3C2410_UART0_BASE;
break;
case 1:
module = "s3c2410-uart1";
mod_offset = S3C2410_UART1_BASE;
break;
case 2:
module = "s3c2410-uart2";
mod_offset = S3C2410_UART2_BASE;
break;
default:
return;
}
#endif
offset &= ~(0xffffc000);
if (! S3C2410_OFFSET_OK(uart_regs, offset)) {
return;
}
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) {
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);
break;
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 );
break;
case S3C2410_UART0_UBRDIV:
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);
} else {
baud = x49gp->PCLK / 16 / (ubrdivn + 1);
printf("%s: PCLK %u, ubrdivn %u, baud %u\n",
module, x49gp->PCLK, 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 );
}
#endif
break;
break;
case S3C2410_UART0_UTXH:
if (uart_regs->ucon & (1 << 9))
s3c2410_intc_sub_deassert(x49gp, uart_regs->int_txd);
case S3C2410_UART0_UTXH:
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);
else
s3c2410_intc_sub_assert(x49gp, uart_regs->int_txd, 0);
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 );
if (uart_regs->ucon & (1 << 5)) {
uart_regs->urxh = data;
uart_regs->utrstat |= (1 << 0);
if ( uart_regs->ucon & ( 1 << 5 ) ) {
uart_regs->urxh = data;
uart_regs->utrstat |= ( 1 << 0 );
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) {
uart_regs->urxh = data;
uart_regs->utrstat |= (1 << 0);
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 ) {
uart_regs->urxh = data;
uart_regs->utrstat |= ( 1 << 0 );
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);
}
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 );
}
break;
}
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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;
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) {
uart_regs = module->user_data;
if (uart_regs->regs)
free(uart_regs->regs);
}
if ( module->user_data ) {
uart_regs = module->user_data;
if ( uart_regs->regs )
free( uart_regs->regs );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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__);
return -ENOMEM;
}
memset(uart, 0, sizeof(s3c2410_uart_t));
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 ) );
if (s3c2410_uart_data_init(uart)) {
free(uart);
return -ENOMEM;
}
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)) {
return -1;
}
if (x49gp_module_register(module)) {
return -1;
}
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 ) ) {
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)) {
return -1;
}
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 ) ) {
return -1;
}
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)) {
return -1;
}
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 ) ) {
return -1;
}
if ( x49gp_module_register( module ) ) {
return -1;
}
return 0;
return 0;
}

View file

@ -12,322 +12,288 @@
#include "x49gp.h"
#include "s3c2410.h"
typedef struct {
uint32_t func_addr_reg;
uint32_t pwr_reg;
uint32_t ep_int_reg;
uint32_t usb_int_reg;
uint32_t ep_int_en_reg;
uint32_t usb_int_en_reg;
uint32_t frame_num1_reg;
uint32_t frame_num2_reg;
uint32_t index_reg;
uint32_t ep0_fifo_reg;
uint32_t ep1_fifo_reg;
uint32_t ep2_fifo_reg;
uint32_t ep3_fifo_reg;
uint32_t ep4_fifo_reg;
uint32_t ep1_dma_con;
uint32_t ep1_dma_unit;
uint32_t ep1_dma_fifo;
uint32_t ep1_dma_ttc_l;
uint32_t ep1_dma_ttc_m;
uint32_t ep1_dma_ttc_h;
uint32_t ep2_dma_con;
uint32_t ep2_dma_unit;
uint32_t ep2_dma_fifo;
uint32_t ep2_dma_ttc_l;
uint32_t ep2_dma_ttc_m;
uint32_t ep2_dma_ttc_h;
uint32_t ep3_dma_con;
uint32_t ep3_dma_unit;
uint32_t ep3_dma_fifo;
uint32_t ep3_dma_ttc_l;
uint32_t ep3_dma_ttc_m;
uint32_t ep3_dma_ttc_h;
uint32_t ep4_dma_con;
uint32_t ep4_dma_unit;
uint32_t ep4_dma_fifo;
uint32_t ep4_dma_ttc_l;
uint32_t ep4_dma_ttc_m;
uint32_t ep4_dma_ttc_h;
uint32_t __wrong_maxp_reg;
uint32_t in_csr1_reg_ep0_csr;
uint32_t in_csr2_reg;
uint32_t maxp_reg;
uint32_t out_csr1_reg;
uint32_t out_csr2_reg;
uint32_t out_fifo_cnt1_reg;
uint32_t out_fifo_cnt2_reg;
uint32_t func_addr_reg;
uint32_t pwr_reg;
uint32_t ep_int_reg;
uint32_t usb_int_reg;
uint32_t ep_int_en_reg;
uint32_t usb_int_en_reg;
uint32_t frame_num1_reg;
uint32_t frame_num2_reg;
uint32_t index_reg;
uint32_t ep0_fifo_reg;
uint32_t ep1_fifo_reg;
uint32_t ep2_fifo_reg;
uint32_t ep3_fifo_reg;
uint32_t ep4_fifo_reg;
uint32_t ep1_dma_con;
uint32_t ep1_dma_unit;
uint32_t ep1_dma_fifo;
uint32_t ep1_dma_ttc_l;
uint32_t ep1_dma_ttc_m;
uint32_t ep1_dma_ttc_h;
uint32_t ep2_dma_con;
uint32_t ep2_dma_unit;
uint32_t ep2_dma_fifo;
uint32_t ep2_dma_ttc_l;
uint32_t ep2_dma_ttc_m;
uint32_t ep2_dma_ttc_h;
uint32_t ep3_dma_con;
uint32_t ep3_dma_unit;
uint32_t ep3_dma_fifo;
uint32_t ep3_dma_ttc_l;
uint32_t ep3_dma_ttc_m;
uint32_t ep3_dma_ttc_h;
uint32_t ep4_dma_con;
uint32_t ep4_dma_unit;
uint32_t ep4_dma_fifo;
uint32_t ep4_dma_ttc_l;
uint32_t ep4_dma_ttc_m;
uint32_t ep4_dma_ttc_h;
uint32_t __wrong_maxp_reg;
uint32_t in_csr1_reg_ep0_csr;
uint32_t in_csr2_reg;
uint32_t maxp_reg;
uint32_t out_csr1_reg;
uint32_t out_csr2_reg;
uint32_t out_fifo_cnt1_reg;
uint32_t out_fifo_cnt2_reg;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_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__);
return -ENOMEM;
}
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;
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)) {
return;
}
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
error = -EAGAIN;
}
return error;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
return 0;
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_usbdev_data_init(usbdev)) {
free(usbdev);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = usbdev;
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);
return 0;
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) {
usbdev = module->user_data;
if (usbdev->regs)
free(usbdev->regs);
free(usbdev);
}
if ( module->user_data ) {
usbdev = module->user_data;
if ( usbdev->regs )
free( usbdev->regs );
free( usbdev );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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,367 +13,328 @@
#include "s3c2410.h"
#include "s3c2410_intc.h"
typedef struct {
uint32_t wtcon;
uint32_t wtdat;
uint32_t wtcnt;
uint32_t wtcon;
uint32_t wtdat;
uint32_t wtcnt;
unsigned int nr_regs;
s3c2410_offset_t *regs;
unsigned int nr_regs;
s3c2410_offset_t* regs;
x49gp_t *x49gp;
x49gp_t* x49gp;
unsigned long interval;
x49gp_timer_t *timer;
unsigned long interval;
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__);
return -ENOMEM;
}
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;
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) {
watchdog->wtcnt--;
} else {
watchdog->wtcnt = watchdog->wtdat;
}
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);
return;
}
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++;
// }
return;
}
// 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;
unsigned long irq;
unsigned long ticks;
s3c2410_watchdog_t* watchdog = x49gp->s3c2410_watchdog;
unsigned long irq;
unsigned long ticks;
ticks = x49gp_get_clock();
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;
} else {
irq = 0;
}
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;
} else {
irq += watchdog->wtdat * 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;
return irq;
}
static int
s3c2410_watchdog_update(s3c2410_watchdog_t *watchdog)
static int s3c2410_watchdog_update( s3c2410_watchdog_t* watchdog )
{
uint32_t pre, mux;
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;
}
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);
return 0;
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);
}
reg = S3C2410_OFFSET_ENTRY(watchdog, offset);
if ( !S3C2410_OFFSET_OK( watchdog, offset ) ) {
return ~( 0 );
}
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)) {
return;
}
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) {
case S3C2410_WATCHDOG_WTCON:
case S3C2410_WATCHDOG_WTCNT:
s3c2410_watchdog_update(watchdog);
break;
default:
break;
}
switch ( offset ) {
case S3C2410_WATCHDOG_WTCON:
case S3C2410_WATCHDOG_WTCNT:
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;
int error = 0;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
if (x49gp_module_get_u32(module, key, reg->name,
reg->reset, reg->datap))
error = -EAGAIN;
}
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;
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;
int i;
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)
continue;
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;
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;
int i;
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)
continue;
if ( NULL == reg->name )
continue;
*(reg->datap) = reg->reset;
}
*( reg->datap ) = reg->reset;
}
s3c2410_watchdog_update(watchdog);
s3c2410_watchdog_update( watchdog );
return 0;
return 0;
}
static CPUReadMemoryFunc *s3c2410_watchdog_readfn[] =
{
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;
int iotype;
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__);
return -ENOMEM;
}
if (s3c2410_watchdog_data_init(watchdog)) {
free(watchdog);
return -ENOMEM;
}
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 );
return -ENOMEM;
}
module->user_data = watchdog;
module->user_data = watchdog;
watchdog->x49gp = module->x49gp;
module->x49gp->s3c2410_watchdog = watchdog;
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);
return 0;
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) {
watchdog = module->user_data;
if (watchdog->regs)
free(watchdog->regs);
free(watchdog);
}
if ( module->user_data ) {
watchdog = module->user_data;
if ( watchdog->regs )
free( watchdog->regs );
free( watchdog );
}
x49gp_module_unregister(module);
free(module);
x49gp_module_unregister( module );
free( module );
return 0;
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)) {
return -1;
}
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

@ -4,40 +4,40 @@
#ifndef SATURN_H
#define SATURN_H 1
#define NB_RSTK 8
#define NB_RSTK 8
typedef uint64_t saturn_reg_t;
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];
saturn_reg_t A;
saturn_reg_t B;
saturn_reg_t C;
saturn_reg_t D;
saturn_reg_t R0;
saturn_reg_t R1;
saturn_reg_t R2;
saturn_reg_t R3;
saturn_reg_t R4;
uint32_t D0;
uint32_t D1;
uint32_t P, P4, P4_32;
uint32_t ST;
uint32_t HST;
uint32_t carry;
int dec;
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 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;
saturn_reg_t D;
saturn_reg_t R0;
saturn_reg_t R1;
saturn_reg_t R2;
saturn_reg_t R3;
saturn_reg_t R4;
uint32_t D0;
uint32_t D1;
uint32_t P, P4, P4_32;
uint32_t ST;
uint32_t HST;
uint32_t carry;
int dec;
uint32_t RSTK[ NB_RSTK ];
uint32_t RSTK_i;
uint32_t REG_FIELD[ 32 ];
uint32_t FIELD_START[ 32 ];
uint32_t FIELD_LENGTH[ 32 ];
} saturn_cpu_t;
#define SAT_RPLTOP 0x8076b
#define SAT_RSKTOP 0x806f3 /* RETTOP */
#define SAT_DSKTOP 0x806f8
#define SAT_EDITLINE 0x806fd
#define SAT_RPLTOP 0x8076b
#define SAT_RSKTOP 0x806f3 /* RETTOP */
#define SAT_DSKTOP 0x806f8
#define SAT_EDITLINE 0x806fd
#endif /* !(SATURN_H) */

1121
src/sram.c

File diff suppressed because it is too large Load diff

View file

@ -9,271 +9,184 @@
#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()
};
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 ),
SYMBOL_CLOSE_PATH(),
SYMBOL_MOVE_TO( 0.180, -0.108 ),
SYMBOL_LINE_TO( 0.135, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.135 ),
SYMBOL_LINE_TO( -0.135, 0.000 ),
SYMBOL_CLOSE_PATH(),
SYMBOL_MOVE_TO( 0.000, 0.334 ),
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(radical, 0.733, 0.0, 0.0, -0.15, 0.733, 1.0);
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_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( divisionslash, 0.575, 0.000, 0.050, 0.000, 0.525, 0.739 );
SYMBOL(overscore, 0.8, 0.0, 0.0, 0.9, 0.9, 1.0);
static const cairo_path_data_t symbol_minus_path_data[] =
{
SYMBOL_MOVE_TO( 0.050, 0.312 ),
SYMBOL_LINE_TO( 0.000, 0.118 ),
SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.118 ),
SYMBOL_CLOSE_PATH()
};
SYMBOL(minus, 0.6, 0.0, 0.05, 0.312, 0.55, 0.430);
static const cairo_path_data_t symbol_divide_path_data[] =
{
SYMBOL_MOVE_TO( 0.050, 0.312 ),
SYMBOL_LINE_TO( 0.000, 0.118 ),
SYMBOL_LINE_TO( 0.500, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.118 ),
SYMBOL_CLOSE_PATH(),
SYMBOL_MOVE_TO( 0.180, -0.108 ),
SYMBOL_LINE_TO( 0.135, 0.000 ),
SYMBOL_LINE_TO( 0.000, -0.135 ),
SYMBOL_LINE_TO( -0.135, 0.000 ),
SYMBOL_CLOSE_PATH(),
SYMBOL_MOVE_TO( 0.000, 0.334 ),
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(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()
};
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;
int i = 0;
const symbol_name_t* symname;
int i = 0;
/*
* Code symbols as Unicode Private Use from U+E000 on...
*/
/*
* Code symbols as Unicode Private Use from U+E000 on...
*/
symname = symbol_names;
while (symname->name) {
if ((strlen(symname->name) == namelen) &&
!strncmp(symname->name, name, namelen)) {
if (glyph) {
*glyph = 0xe000 + i;
}
return 1;
}
symname = symbol_names;
while ( symname->name ) {
if ( ( strlen( symname->name ) == namelen ) && !strncmp( symname->name, name, namelen ) ) {
if ( glyph ) {
*glyph = 0xe000 + i;
}
return 1;
}
symname++;
i++;
}
symname++;
i++;
}
return 0;
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;
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;
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;
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;
return NULL;
}

View file

@ -7,62 +7,73 @@
#include <math.h>
typedef struct {
const cairo_path_data_t *data;
int num_data;
const cairo_path_data_t* data;
int num_data;
} symbol_path_t;
typedef struct {
double x_advance;
double y_advance;
double llx;
double lly;
double urx;
double ury;
double prescale;
double postscale;
const symbol_path_t *path;
double x_advance;
double y_advance;
double llx;
double lly;
double urx;
double ury;
double prescale;
double postscale;
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 } }
#define SYMBOL_CLOSE_PATH() \
{ \
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) \
}; \
\
static const x49gp_symbol_t symbol_##name = \
{ \
x_advance, y_advance, llx, lly, urx, ury, 1.0, 1.0, \
&symbol_##name##_path \
}
#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 }
#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

@ -23,299 +23,254 @@
#include "gdbstub.h"
typedef struct {
long type;
long type;
} x49gp_clock_t;
struct x49gp_timer_s {
long type;
int64_t expires;
x49gp_timer_cb_t cb;
void *user_data;
x49gp_timer_t *next;
long type;
int64_t expires;
x49gp_timer_cb_t cb;
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;
int64_t ticks_per_sec = 1000000;
typedef x49gp_timer_cb_t QEMUTimerCB;
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;
struct timeval tv;
int64_t us;
gettimeofday(&tv, NULL);
gettimeofday( &tv, NULL );
us = tv.tv_sec * 1000000LL + tv.tv_usec;
us = tv.tv_sec * 1000000LL + tv.tv_usec;
return us;
return us;
}
x49gp_timer_t *
x49gp_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) {
return NULL;
}
memset(ts, 0, sizeof(x49gp_timer_t));
ts = malloc( sizeof( x49gp_timer_t ) );
if ( NULL == ts ) {
return NULL;
}
memset( ts, 0, sizeof( x49gp_timer_t ) );
ts->type = type;
ts->cb = cb;
ts->user_data = user_data;
ts->type = type;
ts->cb = cb;
ts->user_data = user_data;
return ts;
return ts;
}
void
x49gp_free_timer(x49gp_timer_t *ts)
void x49gp_free_timer( x49gp_timer_t* ts ) { free( ts ); }
void x49gp_del_timer( x49gp_timer_t* ts )
{
free(ts);
x49gp_timer_t **pt, *t;
// printf("%s: ts %p\n", __FUNCTION__, ts);
pt = &x49gp_timer_lists[ ts->type ];
while ( 1 ) {
t = *pt;
if ( NULL == t )
break;
if ( t == ts ) {
*pt = t->next;
ts->next = NULL;
break;
}
pt = &t->next;
}
}
void
x49gp_del_timer(x49gp_timer_t *ts)
void x49gp_mod_timer( x49gp_timer_t* ts, int64_t expires )
{
x49gp_timer_t **pt, *t;
x49gp_timer_t **pt, *t;
// printf("%s: ts %p\n", __FUNCTION__, ts);
pt = &x49gp_timer_lists[ts->type];
while (1) {
t = *pt;
if (NULL == t)
break;
if (t == ts) {
*pt = t->next;
ts->next = NULL;
break;
}
pt = &t->next;
}
x49gp_del_timer( ts );
// printf("%s: ts %p, expires %lld\n", __FUNCTION__, ts, expires);
pt = &x49gp_timer_lists[ ts->type ];
while ( 1 ) {
t = *pt;
if ( NULL == t )
break;
if ( t->expires > expires )
break;
pt = &t->next;
}
ts->expires = expires;
ts->next = *pt;
*pt = ts;
}
void
x49gp_mod_timer(x49gp_timer_t *ts, int64_t expires)
int x49gp_timer_pending( x49gp_timer_t* ts )
{
x49gp_timer_t **pt, *t;
x49gp_timer_t* t;
x49gp_del_timer(ts);
for ( t = x49gp_timer_lists[ ts->type ]; t; t = t->next ) {
if ( t == ts )
return 1;
}
// printf("%s: ts %p, expires %lld\n", __FUNCTION__, ts, expires);
pt = &x49gp_timer_lists[ts->type];
while (1) {
t = *pt;
if (NULL == t)
break;
if (t->expires > expires)
break;
pt = &t->next;
}
ts->expires = expires;
ts->next = *pt;
*pt = ts;
return 0;
}
int
x49gp_timer_pending(x49gp_timer_t *ts)
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 )
{
x49gp_timer_t *t;
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;
}
static int
x49gp_timer_expired(x49gp_timer_t *timer_head, int64_t current_time)
{
if (NULL == timer_head)
return 0;
return (timer_head->expires <= current_time);
if ( NULL == timer_head )
return 0;
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)
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_del_timer( QEMUTimer* ts ) { return x49gp_del_timer( ( 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(); }
static void x49gp_run_timers( x49gp_timer_t** ptimer_head, int64_t current_time )
{
return x49gp_free_timer((void *) ts);
x49gp_timer_t* ts;
// printf("%s: now %lld\n", __FUNCTION__, current_time);
while ( 1 ) {
ts = *ptimer_head;
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: timers done\n", __FUNCTION__);
}
void
qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
static void x49gp_alarm_handler( int sig )
{
return x49gp_mod_timer((void *) ts, expire_time);
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 );
}
}
}
void
qemu_del_timer(QEMUTimer *ts)
static void x49gp_main_loop_wait( x49gp_t* x49gp, int timeout )
{
return x49gp_del_timer((void *) ts);
// printf("%s: timeout: %d\n", __FUNCTION__, timeout);
if ( gdb_poll( x49gp->env ) ) {
gdb_handlesig( x49gp->env, 0 );
} else
poll( NULL, 0, timeout );
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() );
// printf("%s: done\n", __FUNCTION__);
}
int
qemu_timer_pending(QEMUTimer *ts)
int x49gp_main_loop( x49gp_t* x49gp )
{
return x49gp_timer_pending((void *) ts);
}
int prev_idle;
int ret, timeout;
int64_t
qemu_get_clock(QEMUClock *clock)
{
return x49gp_get_clock();
}
while ( !x49gp->arm_exit ) {
prev_idle = x49gp->arm_idle;
static void
x49gp_run_timers(x49gp_timer_t **ptimer_head, int64_t current_time)
{
x49gp_timer_t *ts;
// printf("%s: now %lld\n", __FUNCTION__, current_time);
while (1) {
ts = *ptimer_head;
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: timers done\n", __FUNCTION__);
}
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);
}
}
}
static void
x49gp_main_loop_wait(x49gp_t *x49gp, int timeout)
{
// printf("%s: timeout: %d\n", __FUNCTION__, timeout);
if (gdb_poll(x49gp->env)) {
gdb_handlesig(x49gp->env, 0);
} else
poll(NULL, 0, timeout);
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());
// printf("%s: done\n", __FUNCTION__);
}
int
x49gp_main_loop(x49gp_t *x49gp)
{
int prev_idle;
int ret, timeout;
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 );
continue;
}
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 ) {
timeout = 10;
} else {
timeout = 0;
}
} else {
timeout = 1;
}
x49gp_main_loop_wait( x49gp, timeout );
}
return 0;
}
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 (ret == EXCP_HALTED) {
timeout = 10;
} else {
timeout = 0;
}
} else {
timeout = 1;
}
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;
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);
sa.sa_flags = SA_RESTART;
sa.sa_handler = x49gp_alarm_handler;
sigaction(SIGALRM, &sa, NULL);
sigfillset( &sa.sa_mask );
sa.sa_flags = SA_RESTART;
sa.sa_handler = x49gp_alarm_handler;
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;
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);
return 0;
setitimer( ITIMER_REAL, &it, NULL );
return 0;
}

View file

@ -94,113 +94,110 @@
#include "bitmaps/tiny__i.xbm"
const bitmap_font_t tiny_font =
{
7,
-3,
{
GLYPH(tiny, notdef),
const bitmap_font_t tiny_font = {
7,
-3,
{ 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 } }
};

1720
src/ui.c

File diff suppressed because it is too large Load diff

View file

@ -20,148 +20,115 @@
#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;
struct list_head list;
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;
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;
uint32_t MCLK;
uint32_t UCLK;
uint32_t FCLK;
uint32_t HCLK;
uint32_t PCLK;
int PCLK_ratio;
uint32_t FCLK;
uint32_t HCLK;
uint32_t PCLK;
int PCLK_ratio;
clock_t clk_tck;
unsigned long emulator_fclk;
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_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;
int debug_port;
x49gp_reinit_t startup_reinit;
char *firmware;
GKeyFile* config;
const char* progname;
const char* progpath;
const char* basename;
int debug_port;
x49gp_reinit_t startup_reinit;
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

@ -8,26 +8,26 @@
#include "list.h"
#define X49GP_TIMER_VIRTUAL 0
#define X49GP_TIMER_REALTIME 1
#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
#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

@ -15,9 +15,9 @@ typedef unsigned int u32;
typedef unsigned long long u64;
struct __x49gp_s__;
typedef struct __x49gp_s__ x49gp_t;
typedef struct __x49gp_s__ x49gp_t;
struct __x49gp_ui_s__;
typedef struct __x49gp_ui_s__ x49gp_ui_t;
typedef struct __x49gp_ui_s__ x49gp_ui_t;
#endif /* !(_X49GP_TYPES_H) */

View file

@ -7,145 +7,139 @@
#include "x49gp_types.h"
typedef enum {
UI_COLOR_BLACK = 0,
UI_COLOR_WHITE,
UI_COLOR_YELLOW,
UI_COLOR_RED,
UI_COLOR_GREEN,
UI_COLOR_SILVER,
UI_COLOR_ORANGE,
UI_COLOR_BLUE,
UI_COLOR_GRAYSCALE_0,
UI_COLOR_GRAYSCALE_1,
UI_COLOR_GRAYSCALE_2,
UI_COLOR_GRAYSCALE_3,
UI_COLOR_GRAYSCALE_4,
UI_COLOR_GRAYSCALE_5,
UI_COLOR_GRAYSCALE_6,
UI_COLOR_GRAYSCALE_7,
UI_COLOR_GRAYSCALE_8,
UI_COLOR_GRAYSCALE_9,
UI_COLOR_GRAYSCALE_10,
UI_COLOR_GRAYSCALE_11,
UI_COLOR_GRAYSCALE_12,
UI_COLOR_GRAYSCALE_13,
UI_COLOR_GRAYSCALE_14,
UI_COLOR_GRAYSCALE_15,
UI_COLOR_MAX
UI_COLOR_BLACK = 0,
UI_COLOR_WHITE,
UI_COLOR_YELLOW,
UI_COLOR_RED,
UI_COLOR_GREEN,
UI_COLOR_SILVER,
UI_COLOR_ORANGE,
UI_COLOR_BLUE,
UI_COLOR_GRAYSCALE_0,
UI_COLOR_GRAYSCALE_1,
UI_COLOR_GRAYSCALE_2,
UI_COLOR_GRAYSCALE_3,
UI_COLOR_GRAYSCALE_4,
UI_COLOR_GRAYSCALE_5,
UI_COLOR_GRAYSCALE_6,
UI_COLOR_GRAYSCALE_7,
UI_COLOR_GRAYSCALE_8,
UI_COLOR_GRAYSCALE_9,
UI_COLOR_GRAYSCALE_10,
UI_COLOR_GRAYSCALE_11,
UI_COLOR_GRAYSCALE_12,
UI_COLOR_GRAYSCALE_13,
UI_COLOR_GRAYSCALE_14,
UI_COLOR_GRAYSCALE_15,
UI_COLOR_MAX
} x49gp_ui_color_t;
typedef enum {
UI_SHAPE_BUTTON_TINY = 0,
UI_SHAPE_BUTTON_SMALL,
UI_SHAPE_BUTTON_NORMAL,
UI_SHAPE_BUTTON_LARGE,
UI_SHAPE_BUTTON_ROUND,
UI_SHAPE_MAX
UI_SHAPE_BUTTON_TINY = 0,
UI_SHAPE_BUTTON_SMALL,
UI_SHAPE_BUTTON_NORMAL,
UI_SHAPE_BUTTON_LARGE,
UI_SHAPE_BUTTON_ROUND,
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,
UI_CALCULATOR_HP49GP_NEWRPL,
UI_CALCULATOR_HP50G,
UI_CALCULATOR_HP50G_NEWRPL
UI_CALCULATOR_HP49GP = 0,
UI_CALCULATOR_HP49GP_NEWRPL,
UI_CALCULATOR_HP50G,
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;
x49gp_ui_color_t color;
double font_size;
cairo_font_weight_t font_weight;
x49gp_ui_shape_t shape;
double letter_size;
x49gp_ui_layout_t layout;
int x;
int y;
int width;
int height;
int column;
int row;
unsigned char columnbit;
unsigned char rowbit;
int eint;
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;
x49gp_ui_shape_t shape;
double letter_size;
x49gp_ui_layout_t layout;
int x;
int y;
int width;
int height;
int column;
int row;
unsigned char columnbit;
unsigned char rowbit;
int eint;
} x49gp_ui_key_t;
typedef struct {
x49gp_t *x49gp;
const x49gp_ui_key_t *key;
GtkWidget *button;
GtkWidget *label;
GtkWidget *box;
GdkPixmap *pixmap;
gboolean down;
gboolean hold;
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_calculator_t calculator;
x49gp_ui_button_t *buttons;
unsigned int nr_buttons;
unsigned int buttons_down;
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;
gint width;
gint height;
gint kb_x_offset;
gint kb_y_offset;
gint kb_x_offset;
gint kb_y_offset;
gint lcd_x_offset;
gint lcd_y_offset;
gint lcd_width;
gint lcd_height;
gint lcd_top_margin;
gint lcd_x_offset;
gint lcd_y_offset;
gint lcd_width;
gint lcd_height;
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) */