mirror of
https://github.com/gwenhael-le-moine/x49gp.git
synced 2024-12-26 21:58:41 +01:00
make code pretty (and consistent)
This commit is contained in:
parent
8e05de8737
commit
25a78e1ccc
49 changed files with 11790 additions and 13236 deletions
|
@ -20,17 +20,14 @@ typedef struct {
|
||||||
} bitmap_font_t;
|
} bitmap_font_t;
|
||||||
|
|
||||||
#define GLYPH( font, name ) \
|
#define GLYPH( font, name ) \
|
||||||
{ \
|
{ #name, \
|
||||||
#name, \
|
|
||||||
font##_##name##_width - font##_##name##_x_hot, \
|
font##_##name##_width - font##_##name##_x_hot, \
|
||||||
-font##_##name##_x_hot, \
|
-font##_##name##_x_hot, \
|
||||||
font##_##name##_y_hot + 1, \
|
font##_##name##_y_hot + 1, \
|
||||||
font##_##name##_y_hot + 1 - font##_##name##_height, \
|
font##_##name##_y_hot + 1 - font##_##name##_height, \
|
||||||
font##_##name##_bits \
|
font##_##name##_bits }
|
||||||
}
|
|
||||||
|
|
||||||
#define SPACE(name, width, kern) \
|
#define SPACE( name, width, kern ) { name, width, kern, 0, 0, NULL }
|
||||||
{ name, width, kern, 0, 0, NULL }
|
|
||||||
|
|
||||||
extern const bitmap_font_t tiny_font;
|
extern const bitmap_font_t tiny_font;
|
||||||
|
|
||||||
|
|
|
@ -80,8 +80,7 @@ static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
||||||
{
|
{
|
||||||
const QCowHeader* cow_header = ( const void* )buf;
|
const QCowHeader* cow_header = ( const void* )buf;
|
||||||
|
|
||||||
if (buf_size >= sizeof(QCowHeader) &&
|
if ( buf_size >= sizeof( QCowHeader ) && be32_to_cpu( cow_header->magic ) == QCOW_MAGIC &&
|
||||||
be32_to_cpu(cow_header->magic) == QCOW_MAGIC &&
|
|
||||||
be32_to_cpu( cow_header->version ) == QCOW_VERSION )
|
be32_to_cpu( cow_header->version ) == QCOW_VERSION )
|
||||||
return 100;
|
return 100;
|
||||||
else
|
else
|
||||||
|
@ -130,8 +129,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
s->l1_table = qemu_malloc( s->l1_size * sizeof( uint64_t ) );
|
s->l1_table = qemu_malloc( s->l1_size * sizeof( uint64_t ) );
|
||||||
if ( !s->l1_table )
|
if ( !s->l1_table )
|
||||||
goto fail;
|
goto fail;
|
||||||
if (bdrv_pread(s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof(uint64_t)) !=
|
if ( bdrv_pread( s->hd, s->l1_table_offset, s->l1_table, s->l1_size * sizeof( uint64_t ) ) != s->l1_size * sizeof( uint64_t ) )
|
||||||
s->l1_size * sizeof(uint64_t))
|
|
||||||
goto fail;
|
goto fail;
|
||||||
for ( i = 0; i < s->l1_size; i++ ) {
|
for ( i = 0; i < s->l1_size; i++ ) {
|
||||||
be64_to_cpus( &s->l1_table[ i ] );
|
be64_to_cpus( &s->l1_table[ i ] );
|
||||||
|
@ -181,10 +179,7 @@ static int qcow_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
*
|
*
|
||||||
* return 0 if not allocated.
|
* return 0 if not allocated.
|
||||||
*/
|
*/
|
||||||
static uint64_t get_cluster_offset(BlockDriverState *bs,
|
static uint64_t get_cluster_offset( BlockDriverState* bs, uint64_t offset, int allocate, int compressed_size, int n_start, int n_end )
|
||||||
uint64_t offset, int allocate,
|
|
||||||
int compressed_size,
|
|
||||||
int n_start, int n_end)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState* s = bs->opaque;
|
BDRVQcowState* s = bs->opaque;
|
||||||
int min_index, i, j, l1_index, l2_index;
|
int min_index, i, j, l1_index, l2_index;
|
||||||
|
@ -205,8 +200,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||||
/* update the L1 entry */
|
/* update the L1 entry */
|
||||||
s->l1_table[ l1_index ] = l2_offset;
|
s->l1_table[ l1_index ] = l2_offset;
|
||||||
tmp = cpu_to_be64( l2_offset );
|
tmp = cpu_to_be64( l2_offset );
|
||||||
if (bdrv_pwrite(s->hd, s->l1_table_offset + l1_index * sizeof(tmp),
|
if ( bdrv_pwrite( s->hd, s->l1_table_offset + l1_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
|
||||||
&tmp, sizeof(tmp)) != sizeof(tmp))
|
|
||||||
return 0;
|
return 0;
|
||||||
new_l2_table = 1;
|
new_l2_table = 1;
|
||||||
}
|
}
|
||||||
|
@ -234,12 +228,10 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||||
l2_table = s->l2_cache + ( min_index << s->l2_bits );
|
l2_table = s->l2_cache + ( min_index << s->l2_bits );
|
||||||
if ( new_l2_table ) {
|
if ( new_l2_table ) {
|
||||||
memset( l2_table, 0, s->l2_size * sizeof( uint64_t ) );
|
memset( l2_table, 0, s->l2_size * sizeof( uint64_t ) );
|
||||||
if (bdrv_pwrite(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
if ( bdrv_pwrite( s->hd, l2_offset, l2_table, s->l2_size * sizeof( uint64_t ) ) != s->l2_size * sizeof( uint64_t ) )
|
||||||
s->l2_size * sizeof(uint64_t))
|
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (bdrv_pread(s->hd, l2_offset, l2_table, s->l2_size * sizeof(uint64_t)) !=
|
if ( bdrv_pread( s->hd, l2_offset, l2_table, s->l2_size * sizeof( uint64_t ) ) != s->l2_size * sizeof( uint64_t ) )
|
||||||
s->l2_size * sizeof(uint64_t))
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s->l2_cache_offsets[ min_index ] = l2_offset;
|
s->l2_cache_offsets[ min_index ] = l2_offset;
|
||||||
|
@ -247,49 +239,41 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
|
||||||
found:
|
found:
|
||||||
l2_index = ( offset >> s->cluster_bits ) & ( s->l2_size - 1 );
|
l2_index = ( offset >> s->cluster_bits ) & ( s->l2_size - 1 );
|
||||||
cluster_offset = be64_to_cpu( l2_table[ l2_index ] );
|
cluster_offset = be64_to_cpu( l2_table[ l2_index ] );
|
||||||
if (!cluster_offset ||
|
if ( !cluster_offset || ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && allocate == 1 ) ) {
|
||||||
((cluster_offset & QCOW_OFLAG_COMPRESSED) && allocate == 1)) {
|
|
||||||
if ( !allocate )
|
if ( !allocate )
|
||||||
return 0;
|
return 0;
|
||||||
/* allocate a new cluster */
|
/* allocate a new cluster */
|
||||||
if ((cluster_offset & QCOW_OFLAG_COMPRESSED) &&
|
if ( ( cluster_offset & QCOW_OFLAG_COMPRESSED ) && ( n_end - n_start ) < s->cluster_sectors ) {
|
||||||
(n_end - n_start) < s->cluster_sectors) {
|
|
||||||
/* if the cluster is already compressed, we must
|
/* if the cluster is already compressed, we must
|
||||||
decompress it in the case it is not completely
|
decompress it in the case it is not completely
|
||||||
overwritten */
|
overwritten */
|
||||||
if ( decompress_cluster( s, cluster_offset ) < 0 )
|
if ( decompress_cluster( s, cluster_offset ) < 0 )
|
||||||
return 0;
|
return 0;
|
||||||
cluster_offset = bdrv_getlength( s->hd );
|
cluster_offset = bdrv_getlength( s->hd );
|
||||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
|
||||||
~(s->cluster_size - 1);
|
|
||||||
/* write the cluster content */
|
/* write the cluster content */
|
||||||
if (bdrv_pwrite(s->hd, cluster_offset, s->cluster_cache, s->cluster_size) !=
|
if ( bdrv_pwrite( s->hd, cluster_offset, s->cluster_cache, s->cluster_size ) != s->cluster_size )
|
||||||
s->cluster_size)
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
cluster_offset = bdrv_getlength( s->hd );
|
cluster_offset = bdrv_getlength( s->hd );
|
||||||
if ( allocate == 1 ) {
|
if ( allocate == 1 ) {
|
||||||
/* round to cluster size */
|
/* round to cluster size */
|
||||||
cluster_offset = (cluster_offset + s->cluster_size - 1) &
|
cluster_offset = ( cluster_offset + s->cluster_size - 1 ) & ~( s->cluster_size - 1 );
|
||||||
~(s->cluster_size - 1);
|
|
||||||
bdrv_truncate( s->hd, cluster_offset + s->cluster_size );
|
bdrv_truncate( s->hd, cluster_offset + s->cluster_size );
|
||||||
} else {
|
} else {
|
||||||
cluster_offset |= QCOW_OFLAG_COMPRESSED |
|
cluster_offset |= QCOW_OFLAG_COMPRESSED | ( uint64_t )compressed_size << ( 63 - s->cluster_bits );
|
||||||
(uint64_t)compressed_size << (63 - s->cluster_bits);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* update L2 table */
|
/* update L2 table */
|
||||||
tmp = cpu_to_be64( cluster_offset );
|
tmp = cpu_to_be64( cluster_offset );
|
||||||
l2_table[ l2_index ] = tmp;
|
l2_table[ l2_index ] = tmp;
|
||||||
if (bdrv_pwrite(s->hd,
|
if ( bdrv_pwrite( s->hd, l2_offset + l2_index * sizeof( tmp ), &tmp, sizeof( tmp ) ) != sizeof( tmp ) )
|
||||||
l2_offset + l2_index * sizeof(tmp), &tmp, sizeof(tmp)) != sizeof(tmp))
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return cluster_offset;
|
return cluster_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_is_allocated( BlockDriverState* bs, int64_t sector_num, int nb_sectors, int* pnum )
|
||||||
int nb_sectors, int *pnum)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState* s = bs->opaque;
|
BDRVQcowState* s = bs->opaque;
|
||||||
int index_in_cluster, n;
|
int index_in_cluster, n;
|
||||||
|
@ -304,8 +288,7 @@ static int qcow_is_allocated(BlockDriverState *bs, int64_t sector_num,
|
||||||
return ( cluster_offset != 0 );
|
return ( cluster_offset != 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
static int decompress_buffer( uint8_t* out_buf, int out_buf_size, const uint8_t* buf, int buf_size )
|
||||||
const uint8_t *buf, int buf_size)
|
|
||||||
{
|
{
|
||||||
z_stream strm1, *strm = &strm1;
|
z_stream strm1, *strm = &strm1;
|
||||||
int ret, out_len;
|
int ret, out_len;
|
||||||
|
@ -322,8 +305,7 @@ static int decompress_buffer(uint8_t *out_buf, int out_buf_size,
|
||||||
return -1;
|
return -1;
|
||||||
ret = inflate( strm, Z_FINISH );
|
ret = inflate( strm, Z_FINISH );
|
||||||
out_len = strm->next_out - out_buf;
|
out_len = strm->next_out - out_buf;
|
||||||
if ((ret != Z_STREAM_END && ret != Z_BUF_ERROR) ||
|
if ( ( ret != Z_STREAM_END && ret != Z_BUF_ERROR ) || out_len != out_buf_size ) {
|
||||||
out_len != out_buf_size) {
|
|
||||||
inflateEnd( strm );
|
inflateEnd( strm );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -343,8 +325,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||||
ret = bdrv_pread( s->hd, coffset, s->cluster_data, csize );
|
ret = bdrv_pread( s->hd, coffset, s->cluster_data, csize );
|
||||||
if ( ret != csize )
|
if ( ret != csize )
|
||||||
return -1;
|
return -1;
|
||||||
if (decompress_buffer(s->cluster_cache, s->cluster_size,
|
if ( decompress_buffer( s->cluster_cache, s->cluster_size, s->cluster_data, csize ) < 0 ) {
|
||||||
s->cluster_data, csize) < 0) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
s->cluster_cache_offset = coffset;
|
s->cluster_cache_offset = coffset;
|
||||||
|
@ -352,8 +333,7 @@ static int decompress_cluster(BDRVQcowState *s, uint64_t cluster_offset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors )
|
||||||
uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState* s = bs->opaque;
|
BDRVQcowState* s = bs->opaque;
|
||||||
int ret, index_in_cluster, n;
|
int ret, index_in_cluster, n;
|
||||||
|
@ -390,8 +370,7 @@ static int qcow_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_write( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState* s = bs->opaque;
|
BDRVQcowState* s = bs->opaque;
|
||||||
int ret, index_in_cluster, n;
|
int ret, index_in_cluster, n;
|
||||||
|
@ -402,9 +381,7 @@ static int qcow_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
n = s->cluster_sectors - index_in_cluster;
|
n = s->cluster_sectors - index_in_cluster;
|
||||||
if ( n > nb_sectors )
|
if ( n > nb_sectors )
|
||||||
n = nb_sectors;
|
n = nb_sectors;
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 1, 0,
|
cluster_offset = get_cluster_offset( bs, sector_num << 9, 1, 0, index_in_cluster, index_in_cluster + n );
|
||||||
index_in_cluster,
|
|
||||||
index_in_cluster + n);
|
|
||||||
if ( !cluster_offset )
|
if ( !cluster_offset )
|
||||||
return -1;
|
return -1;
|
||||||
{
|
{
|
||||||
|
@ -430,8 +407,7 @@ static void qcow_close(BlockDriverState *bs)
|
||||||
bdrv_delete( s->hd );
|
bdrv_delete( s->hd );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int qcow_create(const char *filename, int64_t total_size,
|
static int qcow_create( const char* filename, int64_t total_size, const char* backing_file, int flags )
|
||||||
const char *backing_file, int flags)
|
|
||||||
{
|
{
|
||||||
int fd, header_size, backing_filename_len, l1_size, i, shift;
|
int fd, header_size, backing_filename_len, l1_size, i, shift;
|
||||||
QCowHeader header;
|
QCowHeader header;
|
||||||
|
@ -523,8 +499,7 @@ static int qcow_make_empty(BlockDriverState *bs)
|
||||||
|
|
||||||
/* XXX: put compressed sectors first, then all the cluster aligned
|
/* XXX: put compressed sectors first, then all the cluster aligned
|
||||||
tables to avoid losing bytes in alignment */
|
tables to avoid losing bytes in alignment */
|
||||||
static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
static int qcow_write_compressed( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
|
||||||
const uint8_t *buf, int nb_sectors)
|
|
||||||
{
|
{
|
||||||
BDRVQcowState* s = bs->opaque;
|
BDRVQcowState* s = bs->opaque;
|
||||||
z_stream strm;
|
z_stream strm;
|
||||||
|
@ -541,9 +516,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
|
||||||
/* best compression, small window, no zlib header */
|
/* best compression, small window, no zlib header */
|
||||||
memset( &strm, 0, sizeof( strm ) );
|
memset( &strm, 0, sizeof( strm ) );
|
||||||
ret = deflateInit2(&strm, Z_DEFAULT_COMPRESSION,
|
ret = deflateInit2( &strm, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -12, 9, Z_DEFAULT_STRATEGY );
|
||||||
Z_DEFLATED, -12,
|
|
||||||
9, Z_DEFAULT_STRATEGY);
|
|
||||||
if ( ret != 0 ) {
|
if ( ret != 0 ) {
|
||||||
qemu_free( out_buf );
|
qemu_free( out_buf );
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -568,8 +541,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
|
||||||
/* could not compress: write normal cluster */
|
/* could not compress: write normal cluster */
|
||||||
qcow_write( bs, sector_num, buf, s->cluster_sectors );
|
qcow_write( bs, sector_num, buf, s->cluster_sectors );
|
||||||
} else {
|
} else {
|
||||||
cluster_offset = get_cluster_offset(bs, sector_num << 9, 2,
|
cluster_offset = get_cluster_offset( bs, sector_num << 9, 2, out_len, 0, 0 );
|
||||||
out_len, 0, 0);
|
|
||||||
cluster_offset &= s->cluster_offset_mask;
|
cluster_offset &= s->cluster_offset_mask;
|
||||||
if ( bdrv_pwrite( s->hd, cluster_offset, out_buf, out_len ) != out_len ) {
|
if ( bdrv_pwrite( s->hd, cluster_offset, out_buf, out_len ) != out_len ) {
|
||||||
qemu_free( out_buf );
|
qemu_free( out_buf );
|
||||||
|
|
|
@ -127,8 +127,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
#endif
|
#endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
static int raw_pread( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count )
|
||||||
uint8_t *buf, int count)
|
|
||||||
{
|
{
|
||||||
BDRVRawState* s = bs->opaque;
|
BDRVRawState* s = bs->opaque;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -142,8 +141,7 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
static int raw_pwrite( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count )
|
||||||
const uint8_t *buf, int count)
|
|
||||||
{
|
{
|
||||||
BDRVRawState* s = bs->opaque;
|
BDRVRawState* s = bs->opaque;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -223,8 +221,7 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_create(const char *filename, int64_t total_size,
|
static int raw_create( const char* filename, int64_t total_size, const char* backing_file, int flags )
|
||||||
const char *backing_file, int flags)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
@ -232,8 +229,7 @@ static int raw_create(const char *filename, int64_t total_size,
|
||||||
if ( flags || backing_file )
|
if ( flags || backing_file )
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644 );
|
||||||
0644);
|
|
||||||
if ( fd < 0 ) {
|
if ( fd < 0 ) {
|
||||||
result = -errno;
|
result = -errno;
|
||||||
} else {
|
} else {
|
||||||
|
@ -295,8 +291,7 @@ kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
|
||||||
CFDictionarySetValue( classesToMatch, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue );
|
CFDictionarySetValue( classesToMatch, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue );
|
||||||
}
|
}
|
||||||
kernResult = IOServiceGetMatchingServices( masterPort, classesToMatch, mediaIterator );
|
kernResult = IOServiceGetMatchingServices( masterPort, classesToMatch, mediaIterator );
|
||||||
if ( KERN_SUCCESS != kernResult )
|
if ( KERN_SUCCESS != kernResult ) {
|
||||||
{
|
|
||||||
printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
|
printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,8 +304,7 @@ kern_return_t GetBSDPath( io_iterator_t mediaIterator, char *bsdPath, CFIndex ma
|
||||||
kern_return_t kernResult = KERN_FAILURE;
|
kern_return_t kernResult = KERN_FAILURE;
|
||||||
*bsdPath = '\0';
|
*bsdPath = '\0';
|
||||||
nextMedia = IOIteratorNext( mediaIterator );
|
nextMedia = IOIteratorNext( mediaIterator );
|
||||||
if ( nextMedia )
|
if ( nextMedia ) {
|
||||||
{
|
|
||||||
CFTypeRef bsdPathAsCFString;
|
CFTypeRef bsdPathAsCFString;
|
||||||
bsdPathAsCFString = IORegistryEntryCreateCFProperty( nextMedia, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 );
|
bsdPathAsCFString = IORegistryEntryCreateCFProperty( nextMedia, CFSTR( kIOBSDNameKey ), kCFAllocatorDefault, 0 );
|
||||||
if ( bsdPathAsCFString ) {
|
if ( bsdPathAsCFString ) {
|
||||||
|
@ -402,10 +396,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fd_open(BlockDriverState *bs)
|
static int fd_open( BlockDriverState* bs ) { return 0; }
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
# if defined( __linux__ )
|
# if defined( __linux__ )
|
||||||
|
|
||||||
|
@ -510,25 +501,13 @@ static int raw_set_locked(BlockDriverState *bs, int locked)
|
||||||
|
|
||||||
# else
|
# else
|
||||||
|
|
||||||
static int raw_is_inserted(BlockDriverState *bs)
|
static int raw_is_inserted( BlockDriverState* bs ) { return 1; }
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int raw_media_changed(BlockDriverState *bs)
|
static int raw_media_changed( BlockDriverState* bs ) { return -ENOTSUP; }
|
||||||
{
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int raw_eject(BlockDriverState *bs, int eject_flag)
|
static int raw_eject( BlockDriverState* bs, int eject_flag ) { return -ENOTSUP; }
|
||||||
{
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int raw_set_locked(BlockDriverState *bs, int locked)
|
static int raw_set_locked( BlockDriverState* bs, int locked ) { return -ENOTSUP; }
|
||||||
{
|
|
||||||
return -ENOTSUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
# endif /* !linux */
|
# endif /* !linux */
|
||||||
|
|
||||||
|
@ -599,8 +578,7 @@ int qemu_ftruncate64(int fd, int64_t length)
|
||||||
static int set_sparse( int fd )
|
static int set_sparse( int fd )
|
||||||
{
|
{
|
||||||
DWORD returned;
|
DWORD returned;
|
||||||
return (int) DeviceIoControl((HANDLE)_get_osfhandle(fd), FSCTL_SET_SPARSE,
|
return ( int )DeviceIoControl( ( HANDLE )_get_osfhandle( fd ), FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &returned, NULL );
|
||||||
NULL, 0, NULL, 0, &returned, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_open( BlockDriverState* bs, const char* filename, int flags )
|
static int raw_open( BlockDriverState* bs, const char* filename, int flags )
|
||||||
|
@ -626,9 +604,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
# else
|
# else
|
||||||
overlapped = FILE_FLAG_OVERLAPPED;
|
overlapped = FILE_FLAG_OVERLAPPED;
|
||||||
# endif
|
# endif
|
||||||
s->hfile = CreateFile(filename, access_flags,
|
s->hfile = CreateFile( filename, access_flags, FILE_SHARE_READ, NULL, create_flags, overlapped, NULL );
|
||||||
FILE_SHARE_READ, NULL,
|
|
||||||
create_flags, overlapped, NULL);
|
|
||||||
if ( s->hfile == INVALID_HANDLE_VALUE ) {
|
if ( s->hfile == INVALID_HANDLE_VALUE ) {
|
||||||
int err = GetLastError();
|
int err = GetLastError();
|
||||||
|
|
||||||
|
@ -639,8 +615,7 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_pread(BlockDriverState *bs, int64_t offset,
|
static int raw_pread( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count )
|
||||||
uint8_t *buf, int count)
|
|
||||||
{
|
{
|
||||||
BDRVRawState* s = bs->opaque;
|
BDRVRawState* s = bs->opaque;
|
||||||
OVERLAPPED ov;
|
OVERLAPPED ov;
|
||||||
|
@ -661,8 +636,7 @@ static int raw_pread(BlockDriverState *bs, int64_t offset,
|
||||||
return ret_count;
|
return ret_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_pwrite(BlockDriverState *bs, int64_t offset,
|
static int raw_pwrite( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count )
|
||||||
const uint8_t *buf, int count)
|
|
||||||
{
|
{
|
||||||
BDRVRawState* s = bs->opaque;
|
BDRVRawState* s = bs->opaque;
|
||||||
OVERLAPPED ov;
|
OVERLAPPED ov;
|
||||||
|
@ -730,11 +704,9 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||||
l.QuadPart = total.QuadPart;
|
l.QuadPart = total.QuadPart;
|
||||||
break;
|
break;
|
||||||
case FTYPE_HARDDISK:
|
case FTYPE_HARDDISK:
|
||||||
status = DeviceIoControl(s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY,
|
status = DeviceIoControl( s->hfile, IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, &dg, sizeof( dg ), &count, NULL );
|
||||||
NULL, 0, &dg, sizeof(dg), &count, NULL);
|
|
||||||
if ( status != FALSE ) {
|
if ( status != FALSE ) {
|
||||||
l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder
|
l.QuadPart = dg.Cylinders.QuadPart * dg.TracksPerCylinder * dg.SectorsPerTrack * dg.BytesPerSector;
|
||||||
* dg.SectorsPerTrack * dg.BytesPerSector;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -743,16 +715,14 @@ static int64_t raw_getlength(BlockDriverState *bs)
|
||||||
return l.QuadPart;
|
return l.QuadPart;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int raw_create(const char *filename, int64_t total_size,
|
static int raw_create( const char* filename, int64_t total_size, const char* backing_file, int flags )
|
||||||
const char *backing_file, int flags)
|
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if ( flags || backing_file )
|
if ( flags || backing_file )
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
|
|
||||||
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644 );
|
||||||
0644);
|
|
||||||
if ( fd < 0 )
|
if ( fd < 0 )
|
||||||
return -EIO;
|
return -EIO;
|
||||||
set_sparse( fd );
|
set_sparse( fd );
|
||||||
|
@ -808,8 +778,7 @@ static int find_device_type(BlockDriverState *bs, const char *filename)
|
||||||
UINT type;
|
UINT type;
|
||||||
const char* p;
|
const char* p;
|
||||||
|
|
||||||
if (strstart(filename, "\\\\.\\", &p) ||
|
if ( strstart( filename, "\\\\.\\", &p ) || strstart( filename, "//./", &p ) ) {
|
||||||
strstart(filename, "//./", &p)) {
|
|
||||||
if ( stristart( p, "PhysicalDrive", NULL ) )
|
if ( stristart( p, "PhysicalDrive", NULL ) )
|
||||||
return FTYPE_HARDDISK;
|
return FTYPE_HARDDISK;
|
||||||
snprintf( s->drive_path, sizeof( s->drive_path ), "%c:\\", p[ 0 ] );
|
snprintf( s->drive_path, sizeof( s->drive_path ), "%c:\\", p[ 0 ] );
|
||||||
|
@ -836,8 +805,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
filename = device_name;
|
filename = device_name;
|
||||||
} else {
|
} else {
|
||||||
/* transform drive letters into device name */
|
/* transform drive letters into device name */
|
||||||
if (((filename[0] >= 'a' && filename[0] <= 'z') ||
|
if ( ( ( filename[ 0 ] >= 'a' && filename[ 0 ] <= 'z' ) || ( filename[ 0 ] >= 'A' && filename[ 0 ] <= 'Z' ) ) &&
|
||||||
(filename[0] >= 'A' && filename[0] <= 'Z')) &&
|
|
||||||
filename[ 1 ] == ':' && filename[ 2 ] == '\0' ) {
|
filename[ 1 ] == ':' && filename[ 2 ] == '\0' ) {
|
||||||
snprintf( device_name, sizeof( device_name ), "\\\\.\\%c:", filename[ 0 ] );
|
snprintf( device_name, sizeof( device_name ), "\\\\.\\%c:", filename[ 0 ] );
|
||||||
filename = device_name;
|
filename = device_name;
|
||||||
|
@ -857,9 +825,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
# else
|
# else
|
||||||
overlapped = FILE_FLAG_OVERLAPPED;
|
overlapped = FILE_FLAG_OVERLAPPED;
|
||||||
# endif
|
# endif
|
||||||
s->hfile = CreateFile(filename, access_flags,
|
s->hfile = CreateFile( filename, access_flags, FILE_SHARE_READ, NULL, create_flags, overlapped, NULL );
|
||||||
FILE_SHARE_READ, NULL,
|
|
||||||
create_flags, overlapped, NULL);
|
|
||||||
if ( s->hfile == INVALID_HANDLE_VALUE ) {
|
if ( s->hfile == INVALID_HANDLE_VALUE ) {
|
||||||
int err = GetLastError();
|
int err = GetLastError();
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load diff
131
src/block.c
131
src/block.c
|
@ -24,8 +24,7 @@ static BlockDriver *first_drv;
|
||||||
|
|
||||||
static void bdrv_close( BlockDriverState* bs );
|
static void bdrv_close( BlockDriverState* bs );
|
||||||
|
|
||||||
static int
|
static int path_is_absolute( const char* path )
|
||||||
path_is_absolute(const char *path)
|
|
||||||
{
|
{
|
||||||
const char* p;
|
const char* p;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -48,10 +47,7 @@ path_is_absolute(const char *path)
|
||||||
/* if filename is absolute, just copy it to dest. Otherwise, build a
|
/* if filename is absolute, just copy it to dest. Otherwise, build a
|
||||||
path to it by considering it is relative to base_path. URL are
|
path to it by considering it is relative to base_path. URL are
|
||||||
supported. */
|
supported. */
|
||||||
static void
|
static void path_combine( char* dest, int dest_size, const char* base_path, const char* filename )
|
||||||
path_combine(char *dest, int dest_size,
|
|
||||||
const char *base_path,
|
|
||||||
const char *filename)
|
|
||||||
{
|
{
|
||||||
const char *p, *p1;
|
const char *p, *p1;
|
||||||
int len;
|
int len;
|
||||||
|
@ -113,25 +109,21 @@ void get_tmp_filename(char *filename, int size)
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static int is_windows_drive_prefix( const char* filename )
|
static int is_windows_drive_prefix( const char* filename )
|
||||||
{
|
{
|
||||||
return (((filename[0] >= 'a' && filename[0] <= 'z') ||
|
return ( ( ( filename[ 0 ] >= 'a' && filename[ 0 ] <= 'z' ) || ( filename[ 0 ] >= 'A' && filename[ 0 ] <= 'Z' ) ) &&
|
||||||
(filename[0] >= 'A' && filename[0] <= 'Z')) &&
|
|
||||||
filename[ 1 ] == ':' );
|
filename[ 1 ] == ':' );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int is_windows_drive( const char* filename )
|
static int is_windows_drive( const char* filename )
|
||||||
{
|
{
|
||||||
if (is_windows_drive_prefix(filename) &&
|
if ( is_windows_drive_prefix( filename ) && filename[ 2 ] == '\0' )
|
||||||
filename[2] == '\0')
|
|
||||||
return 1;
|
return 1;
|
||||||
if (strstart(filename, "\\\\.\\", NULL) ||
|
if ( strstart( filename, "\\\\.\\", NULL ) || strstart( filename, "//./", NULL ) )
|
||||||
strstart(filename, "//./", NULL))
|
|
||||||
return 1;
|
return 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static BlockDriver *
|
static BlockDriver* find_protocol( const char* filename )
|
||||||
find_protocol(const char *filename)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv1;
|
BlockDriver* drv1;
|
||||||
char protocol[ 128 ];
|
char protocol[ 128 ];
|
||||||
|
@ -139,8 +131,7 @@ find_protocol(const char *filename)
|
||||||
const char* p;
|
const char* p;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
if (is_windows_drive(filename) ||
|
if ( is_windows_drive( filename ) || is_windows_drive_prefix( filename ) )
|
||||||
is_windows_drive_prefix(filename))
|
|
||||||
return &bdrv_raw;
|
return &bdrv_raw;
|
||||||
#endif
|
#endif
|
||||||
p = strchr( filename, ':' );
|
p = strchr( filename, ':' );
|
||||||
|
@ -153,30 +144,24 @@ find_protocol(const char *filename)
|
||||||
protocol[ len ] = '\0';
|
protocol[ len ] = '\0';
|
||||||
for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
|
for ( drv1 = first_drv; drv1 != NULL; drv1 = drv1->next ) {
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr,
|
fprintf( stderr, "%s:%u: protocol '%s', drv->protocol_name '%s'\n", __FUNCTION__, __LINE__, protocol, drv1->protocol_name );
|
||||||
"%s:%u: protocol '%s', drv->protocol_name '%s'\n",
|
|
||||||
__FUNCTION__, __LINE__, protocol, drv1->protocol_name);
|
|
||||||
#endif
|
#endif
|
||||||
if (drv1->protocol_name &&
|
if ( drv1->protocol_name && !strcmp( drv1->protocol_name, protocol ) ) {
|
||||||
!strcmp(drv1->protocol_name, protocol)) {
|
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: protocol '%s', drv %p\n",
|
fprintf( stderr, "%s:%u: protocol '%s', drv %p\n", __FUNCTION__, __LINE__, protocol, drv1 );
|
||||||
__FUNCTION__, __LINE__, protocol, drv1);
|
|
||||||
#endif
|
#endif
|
||||||
return drv1;
|
return drv1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: protocol '%s', NULL\n",
|
fprintf( stderr, "%s:%u: protocol '%s', NULL\n", __FUNCTION__, __LINE__, protocol );
|
||||||
__FUNCTION__, __LINE__, protocol);
|
|
||||||
#endif
|
#endif
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: force raw format if block or character device ? It would
|
/* XXX: force raw format if block or character device ? It would
|
||||||
simplify the BSD case */
|
simplify the BSD case */
|
||||||
static BlockDriver *
|
static BlockDriver* find_image_format( const char* filename )
|
||||||
find_image_format(const char *filename)
|
|
||||||
{
|
{
|
||||||
int ret, score, score_max;
|
int ret, score, score_max;
|
||||||
BlockDriver *drv1, *drv;
|
BlockDriver *drv1, *drv;
|
||||||
|
@ -210,26 +195,21 @@ find_image_format(const char *filename)
|
||||||
return drv;
|
return drv;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int bdrv_create( BlockDriver* drv, const char* filename, int64_t size_in_sectors, const char* backing_file, int flags )
|
||||||
bdrv_create(BlockDriver *drv,
|
|
||||||
const char *filename, int64_t size_in_sectors,
|
|
||||||
const char *backing_file, int flags)
|
|
||||||
{
|
{
|
||||||
if ( !drv->bdrv_create )
|
if ( !drv->bdrv_create )
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
return drv->bdrv_create( filename, size_in_sectors, backing_file, flags );
|
return drv->bdrv_create( filename, size_in_sectors, backing_file, flags );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void bdrv_register( BlockDriver* bdrv )
|
||||||
bdrv_register(BlockDriver *bdrv)
|
|
||||||
{
|
{
|
||||||
bdrv->next = first_drv;
|
bdrv->next = first_drv;
|
||||||
first_drv = bdrv;
|
first_drv = bdrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a new block device (by default it is empty) */
|
/* create a new block device (by default it is empty) */
|
||||||
BlockDriverState *
|
BlockDriverState* bdrv_new( const char* device_name )
|
||||||
bdrv_new(const char *device_name)
|
|
||||||
{
|
{
|
||||||
BlockDriverState **pbs, *bs;
|
BlockDriverState **pbs, *bs;
|
||||||
|
|
||||||
|
@ -250,8 +230,7 @@ bdrv_new(const char *device_name)
|
||||||
/**
|
/**
|
||||||
* Truncate file to 'offset' bytes (needed only for file protocols)
|
* Truncate file to 'offset' bytes (needed only for file protocols)
|
||||||
*/
|
*/
|
||||||
int
|
int bdrv_truncate( BlockDriverState* bs, int64_t offset )
|
||||||
bdrv_truncate(BlockDriverState *bs, int64_t offset)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
if ( !drv )
|
if ( !drv )
|
||||||
|
@ -264,8 +243,7 @@ bdrv_truncate(BlockDriverState *bs, int64_t offset)
|
||||||
/**
|
/**
|
||||||
* Length of a file in bytes. Return < 0 if error or unknown.
|
* Length of a file in bytes. Return < 0 if error or unknown.
|
||||||
*/
|
*/
|
||||||
int64_t
|
int64_t bdrv_getlength( BlockDriverState* bs )
|
||||||
bdrv_getlength(BlockDriverState *bs)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
if ( !drv )
|
if ( !drv )
|
||||||
|
@ -277,14 +255,12 @@ bdrv_getlength(BlockDriverState *bs)
|
||||||
return drv->bdrv_getlength( bs );
|
return drv->bdrv_getlength( bs );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags )
|
||||||
bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
|
|
||||||
{
|
{
|
||||||
BlockDriverState* bs;
|
BlockDriverState* bs;
|
||||||
int ret;
|
int ret;
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: filename '%s'\n",
|
fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
|
||||||
__FUNCTION__, __LINE__, filename);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bs = bdrv_new( "" );
|
bs = bdrv_new( "" );
|
||||||
|
@ -294,8 +270,7 @@ bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
|
||||||
if ( ret < 0 ) {
|
if ( ret < 0 ) {
|
||||||
bdrv_delete( bs );
|
bdrv_delete( bs );
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: '%s': %d\n",
|
fprintf( stderr, "%s:%u: '%s': %d\n", __FUNCTION__, __LINE__, filename, ret );
|
||||||
__FUNCTION__, __LINE__, filename, ret);
|
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -306,16 +281,14 @@ bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int bdrv_open( BlockDriverState* bs, const char* filename, int flags )
|
||||||
bdrv_open(BlockDriverState *bs, const char *filename, int flags)
|
|
||||||
{
|
{
|
||||||
int ret, open_flags;
|
int ret, open_flags;
|
||||||
char backing_filename[ 1024 ];
|
char backing_filename[ 1024 ];
|
||||||
BlockDriver* drv = NULL;
|
BlockDriver* drv = NULL;
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: filename '%s'\n",
|
fprintf( stderr, "%s:%u: filename '%s'\n", __FUNCTION__, __LINE__, filename );
|
||||||
__FUNCTION__, __LINE__, filename);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bs->read_only = 0;
|
bs->read_only = 0;
|
||||||
|
@ -327,8 +300,7 @@ bdrv_open(BlockDriverState *bs, const char *filename, int flags)
|
||||||
drv = find_protocol( filename );
|
drv = find_protocol( filename );
|
||||||
if ( !drv ) {
|
if ( !drv ) {
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
f printf(stderr, "%s:%u: drv: %p\n",
|
f printf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
|
||||||
__FUNCTION__, __LINE__, drv);
|
|
||||||
#endif
|
#endif
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
@ -337,8 +309,7 @@ f printf(stderr, "%s:%u: drv: %p\n",
|
||||||
drv = find_image_format( filename );
|
drv = find_image_format( filename );
|
||||||
if ( !drv ) {
|
if ( !drv ) {
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: drv: %p\n",
|
fprintf( stderr, "%s:%u: drv: %p\n", __FUNCTION__, __LINE__, drv );
|
||||||
__FUNCTION__, __LINE__, drv);
|
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -364,8 +335,7 @@ f printf(stderr, "%s:%u: drv: %p\n",
|
||||||
open_flags = flags & ~( BDRV_O_FILE );
|
open_flags = flags & ~( BDRV_O_FILE );
|
||||||
ret = drv->bdrv_open( bs, filename, open_flags );
|
ret = drv->bdrv_open( bs, filename, open_flags );
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: drv->bdrv_open: %d\n",
|
fprintf( stderr, "%s:%u: drv->bdrv_open: %d\n", __FUNCTION__, __LINE__, ret );
|
||||||
__FUNCTION__, __LINE__, ret);
|
|
||||||
#endif
|
#endif
|
||||||
if ( ret == -EACCES && !( flags & BDRV_O_FILE ) ) {
|
if ( ret == -EACCES && !( flags & BDRV_O_FILE ) ) {
|
||||||
ret = drv->bdrv_open( bs, filename, BDRV_O_RDONLY );
|
ret = drv->bdrv_open( bs, filename, BDRV_O_RDONLY );
|
||||||
|
@ -376,8 +346,7 @@ f printf(stderr, "%s:%u: drv: %p\n",
|
||||||
bs->opaque = NULL;
|
bs->opaque = NULL;
|
||||||
bs->drv = NULL;
|
bs->drv = NULL;
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: return %d\n",
|
fprintf( stderr, "%s:%u: return %d\n", __FUNCTION__, __LINE__, ret );
|
||||||
__FUNCTION__, __LINE__, ret);
|
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -396,25 +365,20 @@ f printf(stderr, "%s:%u: drv: %p\n",
|
||||||
fail:
|
fail:
|
||||||
bdrv_close( bs );
|
bdrv_close( bs );
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: return -ENOMEM\n",
|
fprintf( stderr, "%s:%u: return -ENOMEM\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
#endif
|
#endif
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: combine '%s' '%s'\n",
|
fprintf( stderr, "%s:%u: combine '%s' '%s'\n", __FUNCTION__, __LINE__, filename, bs->backing_file );
|
||||||
__FUNCTION__, __LINE__, filename, bs->backing_file);
|
|
||||||
#endif
|
#endif
|
||||||
path_combine(backing_filename, sizeof(backing_filename),
|
path_combine( backing_filename, sizeof( backing_filename ), filename, bs->backing_file );
|
||||||
filename, bs->backing_file);
|
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: combine: '%s'\n",
|
fprintf( stderr, "%s:%u: combine: '%s'\n", __FUNCTION__, __LINE__, backing_filename );
|
||||||
__FUNCTION__, __LINE__, backing_filename);
|
|
||||||
#endif
|
#endif
|
||||||
if ( bdrv_open( bs->backing_hd, backing_filename, 0 ) < 0 ) {
|
if ( bdrv_open( bs->backing_hd, backing_filename, 0 ) < 0 ) {
|
||||||
#ifdef DEBUG_X49GP_BLOCK
|
#ifdef DEBUG_X49GP_BLOCK
|
||||||
fprintf(stderr, "%s:%u: backing fail\n",
|
fprintf( stderr, "%s:%u: backing fail\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
#endif
|
#endif
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
@ -431,8 +395,7 @@ f printf(stderr, "%s:%u: drv: %p\n",
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void bdrv_close( BlockDriverState* bs )
|
||||||
bdrv_close(BlockDriverState *bs)
|
|
||||||
{
|
{
|
||||||
if ( NULL == bs->drv )
|
if ( NULL == bs->drv )
|
||||||
return;
|
return;
|
||||||
|
@ -458,8 +421,7 @@ bdrv_close(BlockDriverState *bs)
|
||||||
bs->drv = NULL;
|
bs->drv = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void bdrv_delete( BlockDriverState* bs )
|
||||||
bdrv_delete(BlockDriverState *bs)
|
|
||||||
{
|
{
|
||||||
/* XXX: remove the driver list */
|
/* XXX: remove the driver list */
|
||||||
bdrv_close( bs );
|
bdrv_close( bs );
|
||||||
|
@ -467,9 +429,7 @@ bdrv_delete(BlockDriverState *bs)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return < 0 if error. See bdrv_write() for the return codes */
|
/* return < 0 if error. See bdrv_write() for the return codes */
|
||||||
int
|
int bdrv_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors )
|
||||||
bdrv_read(BlockDriverState * bs, int64_t sector_num,
|
|
||||||
uint8_t * buf, int nb_sectors)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
|
|
||||||
|
@ -506,9 +466,7 @@ bdrv_read(BlockDriverState * bs, int64_t sector_num,
|
||||||
-EINVAL Invalid sector number or nb_sectors
|
-EINVAL Invalid sector number or nb_sectors
|
||||||
-EACCES Trying to write a read-only device
|
-EACCES Trying to write a read-only device
|
||||||
*/
|
*/
|
||||||
static int
|
static int bdrv_write( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors )
|
||||||
bdrv_write(BlockDriverState * bs, int64_t sector_num,
|
|
||||||
const uint8_t * buf, int nb_sectors)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
|
|
||||||
|
@ -535,8 +493,7 @@ bdrv_write(BlockDriverState * bs, int64_t sector_num,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int bdrv_pread_em( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count1 )
|
||||||
bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
|
|
||||||
{
|
{
|
||||||
uint8_t tmp_buf[ SECTOR_SIZE ];
|
uint8_t tmp_buf[ SECTOR_SIZE ];
|
||||||
int len, nb_sectors, count;
|
int len, nb_sectors, count;
|
||||||
|
@ -579,9 +536,7 @@ bdrv_pread_em(BlockDriverState * bs, int64_t offset, uint8_t * buf, int count1)
|
||||||
return count1;
|
return count1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int bdrv_pwrite_em( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count1 )
|
||||||
bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
|
|
||||||
const uint8_t * buf, int count1)
|
|
||||||
{
|
{
|
||||||
uint8_t tmp_buf[ SECTOR_SIZE ];
|
uint8_t tmp_buf[ SECTOR_SIZE ];
|
||||||
int len, nb_sectors, count;
|
int len, nb_sectors, count;
|
||||||
|
@ -631,8 +586,7 @@ bdrv_pwrite_em(BlockDriverState * bs, int64_t offset,
|
||||||
/**
|
/**
|
||||||
* Read with byte offsets (needed only for file protocols)
|
* Read with byte offsets (needed only for file protocols)
|
||||||
*/
|
*/
|
||||||
int
|
int bdrv_pread( BlockDriverState* bs, int64_t offset, void* buf1, int count1 )
|
||||||
bdrv_pread(BlockDriverState * bs, int64_t offset, void *buf1, int count1)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
|
|
||||||
|
@ -646,8 +600,7 @@ bdrv_pread(BlockDriverState * bs, int64_t offset, void *buf1, int count1)
|
||||||
/**
|
/**
|
||||||
* Write with byte offsets (needed only for file protocols)
|
* Write with byte offsets (needed only for file protocols)
|
||||||
*/
|
*/
|
||||||
int
|
int bdrv_pwrite( BlockDriverState* bs, int64_t offset, const void* buf1, int count1 )
|
||||||
bdrv_pwrite(BlockDriverState * bs, int64_t offset, const void *buf1, int count1)
|
|
||||||
{
|
{
|
||||||
BlockDriver* drv = bs->drv;
|
BlockDriver* drv = bs->drv;
|
||||||
|
|
||||||
|
@ -658,8 +611,7 @@ bdrv_pwrite(BlockDriverState * bs, int64_t offset, const void *buf1, int count1)
|
||||||
return drv->bdrv_pwrite( bs, offset, buf1, count1 );
|
return drv->bdrv_pwrite( bs, offset, buf1, count1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void bdrv_flush( BlockDriverState* bs )
|
||||||
bdrv_flush(BlockDriverState *bs)
|
|
||||||
{
|
{
|
||||||
if ( bs->drv->bdrv_flush )
|
if ( bs->drv->bdrv_flush )
|
||||||
bs->drv->bdrv_flush( bs );
|
bs->drv->bdrv_flush( bs );
|
||||||
|
@ -667,8 +619,7 @@ bdrv_flush(BlockDriverState *bs)
|
||||||
bdrv_flush( bs->backing_hd );
|
bdrv_flush( bs->backing_hd );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void bdrv_init( void )
|
||||||
bdrv_init(void)
|
|
||||||
{
|
{
|
||||||
/* bdrv_register(&bdrv_raw); */
|
/* bdrv_register(&bdrv_raw); */
|
||||||
/* bdrv_register(&bdrv_host_device); */
|
/* bdrv_register(&bdrv_host_device); */
|
||||||
|
|
23
src/block.h
23
src/block.h
|
@ -10,11 +10,13 @@
|
||||||
#define BDRV_O_RDWR 0x0002
|
#define BDRV_O_RDWR 0x0002
|
||||||
#define BDRV_O_ACCESS 0x0003
|
#define BDRV_O_ACCESS 0x0003
|
||||||
#define BDRV_O_CREAT 0x0004 /* create an empty file */
|
#define BDRV_O_CREAT 0x0004 /* create an empty file */
|
||||||
#define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save
|
#define BDRV_O_SNAPSHOT \
|
||||||
|
0x0008 /* open the file read only and save \
|
||||||
writes in a snapshot */
|
writes in a snapshot */
|
||||||
#define BDRV_O_FILE 0x0010 /* open as a raw file (do not try to
|
#define BDRV_O_FILE \
|
||||||
use a disk image format on top of
|
0x0010 /* open as a raw file (do not try to \
|
||||||
it (default for
|
use a disk image format on top of \
|
||||||
|
it (default for \
|
||||||
bdrv_file_open()) */
|
bdrv_file_open()) */
|
||||||
|
|
||||||
typedef struct BlockDriver BlockDriver;
|
typedef struct BlockDriver BlockDriver;
|
||||||
|
@ -29,20 +31,15 @@ extern BlockDriver bdrv_qcow;
|
||||||
extern BlockDriver bdrv_vvfat;
|
extern BlockDriver bdrv_vvfat;
|
||||||
|
|
||||||
void bdrv_init( void );
|
void bdrv_init( void );
|
||||||
int bdrv_create(BlockDriver *drv,
|
int bdrv_create( BlockDriver* drv, const char* filename, int64_t size_in_sectors, const char* backing_file, int flags );
|
||||||
const char *filename, int64_t size_in_sectors,
|
|
||||||
const char *backing_file, int flags);
|
|
||||||
BlockDriverState* bdrv_new( const char* device_name );
|
BlockDriverState* bdrv_new( const char* device_name );
|
||||||
void bdrv_delete( BlockDriverState* bs );
|
void bdrv_delete( BlockDriverState* bs );
|
||||||
int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags );
|
int bdrv_file_open( BlockDriverState** pbs, const char* filename, int flags );
|
||||||
int bdrv_open( BlockDriverState* bs, const char* filename, int flags );
|
int bdrv_open( BlockDriverState* bs, const char* filename, int flags );
|
||||||
|
|
||||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
int bdrv_read( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors );
|
||||||
uint8_t *buf, int nb_sectors);
|
int bdrv_pread( BlockDriverState* bs, int64_t offset, void* buf, int count );
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
int bdrv_pwrite( BlockDriverState* bs, int64_t offset, const void* buf, int count );
|
||||||
void *buf, int count);
|
|
||||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
|
||||||
const void *buf, int count);
|
|
||||||
|
|
||||||
int bdrv_truncate( BlockDriverState* bs, int64_t offset );
|
int bdrv_truncate( BlockDriverState* bs, int64_t offset );
|
||||||
int64_t bdrv_getlength( BlockDriverState* bs );
|
int64_t bdrv_getlength( BlockDriverState* bs );
|
||||||
|
|
|
@ -32,28 +32,21 @@ struct BlockDriver {
|
||||||
int instance_size;
|
int instance_size;
|
||||||
int ( *bdrv_probe )( const uint8_t* buf, int buf_size, const char* filename );
|
int ( *bdrv_probe )( const uint8_t* buf, int buf_size, const char* filename );
|
||||||
int ( *bdrv_open )( BlockDriverState* bs, const char* filename, int flags );
|
int ( *bdrv_open )( BlockDriverState* bs, const char* filename, int flags );
|
||||||
int (*bdrv_read)(BlockDriverState *bs, int64_t sector_num,
|
int ( *bdrv_read )( BlockDriverState* bs, int64_t sector_num, uint8_t* buf, int nb_sectors );
|
||||||
uint8_t *buf, int nb_sectors);
|
int ( *bdrv_write )( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors );
|
||||||
int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num,
|
|
||||||
const uint8_t *buf, int nb_sectors);
|
|
||||||
void ( *bdrv_close )( BlockDriverState* bs );
|
void ( *bdrv_close )( BlockDriverState* bs );
|
||||||
int (*bdrv_create)(const char *filename, int64_t total_sectors,
|
int ( *bdrv_create )( const char* filename, int64_t total_sectors, const char* backing_file, int flags );
|
||||||
const char *backing_file, int flags);
|
|
||||||
void ( *bdrv_flush )( BlockDriverState* bs );
|
void ( *bdrv_flush )( BlockDriverState* bs );
|
||||||
int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
|
int ( *bdrv_is_allocated )( BlockDriverState* bs, int64_t sector_num, int nb_sectors, int* pnum );
|
||||||
int nb_sectors, int *pnum);
|
|
||||||
int ( *bdrv_set_key )( BlockDriverState* bs, const char* key );
|
int ( *bdrv_set_key )( BlockDriverState* bs, const char* key );
|
||||||
int ( *bdrv_make_empty )( BlockDriverState* bs );
|
int ( *bdrv_make_empty )( BlockDriverState* bs );
|
||||||
|
|
||||||
const char* protocol_name;
|
const char* protocol_name;
|
||||||
int (*bdrv_pread)(BlockDriverState *bs, int64_t offset,
|
int ( *bdrv_pread )( BlockDriverState* bs, int64_t offset, uint8_t* buf, int count );
|
||||||
uint8_t *buf, int count);
|
int ( *bdrv_pwrite )( BlockDriverState* bs, int64_t offset, const uint8_t* buf, int count );
|
||||||
int (*bdrv_pwrite)(BlockDriverState *bs, int64_t offset,
|
|
||||||
const uint8_t *buf, int count);
|
|
||||||
int ( *bdrv_truncate )( BlockDriverState* bs, int64_t offset );
|
int ( *bdrv_truncate )( BlockDriverState* bs, int64_t offset );
|
||||||
int64_t ( *bdrv_getlength )( BlockDriverState* bs );
|
int64_t ( *bdrv_getlength )( BlockDriverState* bs );
|
||||||
int (*bdrv_write_compressed)(BlockDriverState *bs, int64_t sector_num,
|
int ( *bdrv_write_compressed )( BlockDriverState* bs, int64_t sector_num, const uint8_t* buf, int nb_sectors );
|
||||||
const uint8_t *buf, int nb_sectors);
|
|
||||||
|
|
||||||
int ( *bdrv_get_info )( BlockDriverState* bs, BlockDriverInfo* bdi );
|
int ( *bdrv_get_info )( BlockDriverState* bs, BlockDriverInfo* bdi );
|
||||||
|
|
||||||
|
|
|
@ -6,18 +6,11 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
static __inline__ uint16_t swab16(uint16_t x)
|
static __inline__ uint16_t swab16( uint16_t x ) { return ( ( x & 0xff00 ) >> 8 ) | ( ( x & 0x00ff ) << 8 ); }
|
||||||
{
|
|
||||||
return ((x & 0xff00) >> 8) |
|
|
||||||
((x & 0x00ff) << 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ uint32_t swab32( uint32_t x )
|
static __inline__ uint32_t swab32( uint32_t x )
|
||||||
{
|
{
|
||||||
return ((x & 0xff000000) >> 24) |
|
return ( ( x & 0xff000000 ) >> 24 ) | ( ( x & 0x00ff0000 ) >> 8 ) | ( ( x & 0x0000ff00 ) << 8 ) | ( ( x & 0x000000ff ) << 24 );
|
||||||
((x & 0x00ff0000) >> 8) |
|
|
||||||
((x & 0x0000ff00) << 8) |
|
|
||||||
((x & 0x000000ff) << 24);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __sparc__
|
#ifdef __sparc__
|
||||||
|
@ -28,9 +21,7 @@ static __inline__ uint16_t __load_le16(const uint16_t *p)
|
||||||
{
|
{
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
|
|
||||||
__asm__ __volatile__ ("lduha [%1] %2, %0"
|
__asm__ __volatile__( "lduha [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
|
||||||
: "=r" (x)
|
|
||||||
: "r" (p), "i" (ASI_PL));
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,9 +29,7 @@ static __inline__ uint32_t __load_le32(const uint32_t *p)
|
||||||
{
|
{
|
||||||
uint32_t x;
|
uint32_t x;
|
||||||
|
|
||||||
__asm__ __volatile__ ("lduwa [%1] %2, %0"
|
__asm__ __volatile__( "lduwa [%1] %2, %0" : "=r"( x ) : "r"( p ), "i"( ASI_PL ) );
|
||||||
: "=r" (x)
|
|
||||||
: "r" (p), "i" (ASI_PL));
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
267
src/flash.c
267
src/flash.c
|
@ -63,62 +63,26 @@ typedef struct {
|
||||||
|
|
||||||
#define BOOT_SIZE 0x00004000
|
#define BOOT_SIZE 0x00004000
|
||||||
|
|
||||||
static const unsigned short sst29vf160_cfi_data[] =
|
static const unsigned short sst29vf160_cfi_data[] = {
|
||||||
{
|
[0x10] = 0x0051, [0x11] = 0x0052, [0x12] = 0x0059, [0x13] = 0x0001, [0x14] = 0x0007, [0x15] = 0x0000, [0x16] = 0x0000,
|
||||||
[0x10] = 0x0051,
|
[0x17] = 0x0000, [0x18] = 0x0000, [0x19] = 0x0000, [0x1a] = 0x0000,
|
||||||
[0x11] = 0x0052,
|
|
||||||
[0x12] = 0x0059,
|
|
||||||
[0x13] = 0x0001,
|
|
||||||
[0x14] = 0x0007,
|
|
||||||
[0x15] = 0x0000,
|
|
||||||
[0x16] = 0x0000,
|
|
||||||
[0x17] = 0x0000,
|
|
||||||
[0x18] = 0x0000,
|
|
||||||
[0x19] = 0x0000,
|
|
||||||
[0x1a] = 0x0000,
|
|
||||||
|
|
||||||
[0x1b] = 0x0027,
|
[0x1b] = 0x0027, [0x1c] = 0x0036, [0x1d] = 0x0000, [0x1e] = 0x0000, [0x1f] = 0x0004, [0x20] = 0x0000, [0x21] = 0x0004,
|
||||||
[0x1c] = 0x0036,
|
[0x22] = 0x0006, [0x23] = 0x0001, [0x24] = 0x0000, [0x25] = 0x0001, [0x26] = 0x0001,
|
||||||
[0x1d] = 0x0000,
|
|
||||||
[0x1e] = 0x0000,
|
|
||||||
[0x1f] = 0x0004,
|
|
||||||
[0x20] = 0x0000,
|
|
||||||
[0x21] = 0x0004,
|
|
||||||
[0x22] = 0x0006,
|
|
||||||
[0x23] = 0x0001,
|
|
||||||
[0x24] = 0x0000,
|
|
||||||
[0x25] = 0x0001,
|
|
||||||
[0x26] = 0x0001,
|
|
||||||
|
|
||||||
[0x27] = 0x0015,
|
[0x27] = 0x0015, [0x28] = 0x0001, [0x29] = 0x0000, [0x2a] = 0x0000, [0x2b] = 0x0000, [0x2c] = 0x0002, [0x2d] = 0x00ff,
|
||||||
[0x28] = 0x0001,
|
[0x2e] = 0x0001, [0x2f] = 0x0010, [0x30] = 0x0000, [0x31] = 0x003f, [0x32] = 0x0000, [0x33] = 0x0000, [0x34] = 0x0001 };
|
||||||
[0x29] = 0x0000,
|
|
||||||
[0x2a] = 0x0000,
|
|
||||||
[0x2b] = 0x0000,
|
|
||||||
[0x2c] = 0x0002,
|
|
||||||
[0x2d] = 0x00ff,
|
|
||||||
[0x2e] = 0x0001,
|
|
||||||
[0x2f] = 0x0010,
|
|
||||||
[0x30] = 0x0000,
|
|
||||||
[0x31] = 0x003f,
|
|
||||||
[0x32] = 0x0000,
|
|
||||||
[0x33] = 0x0000,
|
|
||||||
[0x34] = 0x0001
|
|
||||||
};
|
|
||||||
#define SST29VF160_CFI_SIZE ( sizeof( sst29vf160_cfi_data ) / sizeof( sst29vf160_cfi_data[ 0 ] ) )
|
#define SST29VF160_CFI_SIZE ( sizeof( sst29vf160_cfi_data ) / sizeof( sst29vf160_cfi_data[ 0 ] ) )
|
||||||
|
|
||||||
static void
|
static void flash_state_reset( x49gp_flash_t* flash )
|
||||||
flash_state_reset(x49gp_flash_t *flash)
|
|
||||||
{
|
{
|
||||||
if ( flash->state != FLASH_STATE_NORMAL ) {
|
if ( flash->state != FLASH_STATE_NORMAL ) {
|
||||||
cpu_register_physical_memory(0x00000000, SST29VF160_SIZE,
|
cpu_register_physical_memory( 0x00000000, SST29VF160_SIZE, flash->offset | flash->iotype | IO_MEM_ROMD );
|
||||||
flash->offset | flash->iotype | IO_MEM_ROMD);
|
|
||||||
flash->state = FLASH_STATE_NORMAL;
|
flash->state = FLASH_STATE_NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t flash_get_halfword( x49gp_flash_t* flash, uint32_t offset )
|
||||||
flash_get_halfword(x49gp_flash_t *flash, uint32_t offset)
|
|
||||||
{
|
{
|
||||||
uint8_t* datap = flash->data;
|
uint8_t* datap = flash->data;
|
||||||
uint16_t data;
|
uint16_t data;
|
||||||
|
@ -152,8 +116,7 @@ flash_get_halfword(x49gp_flash_t *flash, uint32_t offset)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void flash_put_halfword( x49gp_flash_t* flash, uint32_t offset, uint32_t data )
|
||||||
flash_put_halfword(x49gp_flash_t *flash, uint32_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
uint8_t* datap = flash->data;
|
uint8_t* datap = flash->data;
|
||||||
uint16_t temp;
|
uint16_t temp;
|
||||||
|
@ -273,8 +236,7 @@ flash_put_halfword(x49gp_flash_t *flash, uint32_t offset, uint32_t data)
|
||||||
stw_p( datap + offset, data & temp );
|
stw_p( datap + offset, data & temp );
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("write FLASH 2 (state %u) at offset %08x: %04x, result: %04x\n",
|
printf( "write FLASH 2 (state %u) at offset %08x: %04x, result: %04x\n", flash->state, offset, data, lduw_p( datap + offset ) );
|
||||||
flash->state, offset, data, lduw_p(datap + offset));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
flash_state_reset( flash );
|
flash_state_reset( flash );
|
||||||
|
@ -291,25 +253,19 @@ flash_put_halfword(x49gp_flash_t *flash, uint32_t offset, uint32_t data)
|
||||||
|
|
||||||
case 0x30: /* Sector Erase */
|
case 0x30: /* Sector Erase */
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("erase FLASH %08x %08x\n",
|
printf( "erase FLASH %08x %08x\n", ( offset & ~( flash->sector_size - 1 ) ), flash->sector_size );
|
||||||
(offset & ~(flash->sector_size - 1)),
|
|
||||||
flash->sector_size);
|
|
||||||
#endif
|
#endif
|
||||||
memset( datap + ( offset & ~( flash->sector_size - 1 ) ), 0xff, flash->sector_size );
|
memset( datap + ( offset & ~( flash->sector_size - 1 ) ), 0xff, flash->sector_size );
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("erase FLASH %08x: %04x, %08x: %04x, %08x: %04x\n",
|
printf( "erase FLASH %08x: %04x, %08x: %04x, %08x: %04x\n", offset, lduw_p( datap + offset ), offset + 0x800,
|
||||||
offset, lduw_p(datap + offset),
|
lduw_p( datap + offset + 0x800 ), offset + 0xffc, lduw_p( datap + offset + 0xffc ) );
|
||||||
offset + 0x800, lduw_p(datap + offset + 0x800),
|
|
||||||
offset + 0xffc, lduw_p(datap + offset + 0xffc));
|
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x50: /* Block Erase */
|
case 0x50: /* Block Erase */
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("erase FLASH %08x %08x\n",
|
printf( "erase FLASH %08x %08x\n", ( offset & ~( flash->block_size - 1 ) ), flash->block_size );
|
||||||
(offset & ~(flash->block_size - 1)),
|
|
||||||
flash->block_size);
|
|
||||||
#endif
|
#endif
|
||||||
memset( datap + ( offset & ~( flash->block_size - 1 ) ), 0xff, flash->block_size );
|
memset( datap + ( offset & ~( flash->block_size - 1 ) ), 0xff, flash->block_size );
|
||||||
break;
|
break;
|
||||||
|
@ -322,8 +278,7 @@ flash_put_halfword(x49gp_flash_t *flash, uint32_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t flash_readb( void* opaque, target_phys_addr_t offset )
|
||||||
flash_readb(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
uint8_t* datap = flash->data;
|
uint8_t* datap = flash->data;
|
||||||
|
@ -340,15 +295,13 @@ flash_readb(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_READ
|
#ifdef DEBUG_X49GP_FLASH_READ
|
||||||
printf("read FLASH 1 (state %u) at offset %08lx: %02x\n",
|
printf( "read FLASH 1 (state %u) at offset %08lx: %02x\n", flash->state, ( unsigned long )offset, data );
|
||||||
flash->state, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t flash_readw( void* opaque, target_phys_addr_t offset )
|
||||||
flash_readw(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
uint8_t* datap = flash->data;
|
uint8_t* datap = flash->data;
|
||||||
|
@ -361,15 +314,13 @@ flash_readw(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_READ
|
#ifdef DEBUG_X49GP_FLASH_READ
|
||||||
printf("read FLASH 2 (state %u) at offset %08lx: %04x\n",
|
printf( "read FLASH 2 (state %u) at offset %08lx: %04x\n", flash->state, ( unsigned long )offset, data );
|
||||||
flash->state, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t flash_readl( void* opaque, target_phys_addr_t offset )
|
||||||
flash_readl(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
uint8_t* datap = flash->data;
|
uint8_t* datap = flash->data;
|
||||||
|
@ -378,20 +329,17 @@ flash_readl(void *opaque, target_phys_addr_t offset)
|
||||||
if ( flash->state == FLASH_STATE_NORMAL ) {
|
if ( flash->state == FLASH_STATE_NORMAL ) {
|
||||||
data = ldl_p( datap + offset );
|
data = ldl_p( datap + offset );
|
||||||
} else {
|
} else {
|
||||||
data = (flash_get_halfword(flash, offset + 2) << 16) |
|
data = ( flash_get_halfword( flash, offset + 2 ) << 16 ) | ( flash_get_halfword( flash, offset + 0 ) << 0 );
|
||||||
(flash_get_halfword(flash, offset + 0) << 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_READ
|
#ifdef DEBUG_X49GP_FLASH_READ
|
||||||
printf("read FLASH 4 (state %u) at offset %08lx: %08x\n",
|
printf( "read FLASH 4 (state %u) at offset %08lx: %08x\n", flash->state, ( unsigned long )offset, data );
|
||||||
flash->state, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void flash_writeb( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
flash_writeb(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
uint32_t shift;
|
uint32_t shift;
|
||||||
|
@ -399,8 +347,7 @@ flash_writeb(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
data &= 0xff;
|
data &= 0xff;
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("write FLASH 1 (state %u) at offset %08lx: %02x\n",
|
printf( "write FLASH 1 (state %u) at offset %08lx: %02x\n", flash->state, offset, data );
|
||||||
flash->state, offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -412,37 +359,32 @@ flash_writeb(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
flash_put_halfword( flash, offset & ~( 1 ), data << shift );
|
flash_put_halfword( flash, offset & ~( 1 ), data << shift );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void flash_writew( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
flash_writew(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
|
|
||||||
data &= 0xffff;
|
data &= 0xffff;
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("write FLASH 2 (state %u) at offset %08lx: %04x\n",
|
printf( "write FLASH 2 (state %u) at offset %08lx: %04x\n", flash->state, offset, data );
|
||||||
flash->state, offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
flash_put_halfword( flash, offset, data );
|
flash_put_halfword( flash, offset, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void flash_writel( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
flash_writel(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = opaque;
|
x49gp_flash_t* flash = opaque;
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_FLASH_WRITE
|
#ifdef DEBUG_X49GP_FLASH_WRITE
|
||||||
printf("write FLASH 4 (state %u) at offset %08lx: %08x\n",
|
printf( "write FLASH 4 (state %u) at offset %08lx: %08x\n", flash->state, offset, data );
|
||||||
flash->state, offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
flash_put_halfword( flash, offset + 2, ( data >> 16 ) & 0xffff );
|
flash_put_halfword( flash, offset + 2, ( data >> 16 ) & 0xffff );
|
||||||
flash_put_halfword( flash, offset + 0, ( data >> 0 ) & 0xffff );
|
flash_put_halfword( flash, offset + 0, ( data >> 0 ) & 0xffff );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int flash_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
flash_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = module->user_data;
|
x49gp_flash_t* flash = module->user_data;
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
|
@ -461,15 +403,12 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error = x49gp_module_get_filename(module, key, "filename", "flash",
|
error = x49gp_module_get_filename( module, key, "filename", "flash", &( flash->filename ), &filename );
|
||||||
&(flash->filename), &filename);
|
|
||||||
|
|
||||||
flash->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
flash->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
||||||
if ( flash->fd < 0 ) {
|
if ( flash->fd < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -477,9 +416,7 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
flash->size = SST29VF160_SIZE;
|
flash->size = SST29VF160_SIZE;
|
||||||
if ( fstat( flash->fd, &st ) < 0 ) {
|
if ( fstat( flash->fd, &st ) < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: fstat %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: fstat %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( flash->fd );
|
close( flash->fd );
|
||||||
flash->fd = -1;
|
flash->fd = -1;
|
||||||
|
@ -488,30 +425,23 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
|
|
||||||
if ( ftruncate( flash->fd, flash->size ) < 0 ) {
|
if ( ftruncate( flash->fd, flash->size ) < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: ftruncate %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: ftruncate %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( flash->fd );
|
close( flash->fd );
|
||||||
flash->fd = -1;
|
flash->fd = -1;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
flash->data = mmap(phys_ram_base + flash->offset, flash->size,
|
flash->data = mmap( phys_ram_base + flash->offset, flash->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, flash->fd, 0 );
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
|
|
||||||
flash->fd, 0);
|
|
||||||
if ( flash->data == ( void* )-1 ) {
|
if ( flash->data == ( void* )-1 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: mmap %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: mmap %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( flash->fd );
|
close( flash->fd );
|
||||||
flash->fd = -1;
|
flash->fd = -1;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( flash->size > st.st_size ) {
|
if ( flash->size > st.st_size ) {
|
||||||
fprintf( stderr, "Flash too small, rebuilding\n" );
|
fprintf( stderr, "Flash too small, rebuilding\n" );
|
||||||
x49gp->startup_reinit = X49GP_REINIT_FLASH_FULL;
|
x49gp->startup_reinit = X49GP_REINIT_FLASH_FULL;
|
||||||
|
@ -519,14 +449,11 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( x49gp->startup_reinit >= X49GP_REINIT_FLASH ) {
|
if ( x49gp->startup_reinit >= X49GP_REINIT_FLASH ) {
|
||||||
|
|
||||||
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL )
|
if ( x49gp->startup_reinit == X49GP_REINIT_FLASH_FULL )
|
||||||
memset(phys_ram_base + flash->offset, 0xff,
|
memset( phys_ram_base + flash->offset, 0xff, flash->size - st.st_size );
|
||||||
flash->size - st.st_size);
|
|
||||||
|
|
||||||
bootfd = x49gp_module_open_rodata( module,
|
bootfd = x49gp_module_open_rodata( module,
|
||||||
calc == UI_CALCULATOR_HP49GP ||
|
calc == UI_CALCULATOR_HP49GP || calc == UI_CALCULATOR_HP49GP_NEWRPL ? "firmware/boot-49g+.bin"
|
||||||
calc == UI_CALCULATOR_HP49GP_NEWRPL ?
|
: "firmware/boot-50g.bin",
|
||||||
"firmware/boot-49g+.bin" :
|
|
||||||
"firmware/boot-50g.bin",
|
|
||||||
&bootfile );
|
&bootfile );
|
||||||
|
|
||||||
if ( bootfd < 0 ) {
|
if ( bootfd < 0 ) {
|
||||||
|
@ -536,12 +463,9 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return bootfd;
|
return bootfd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read(bootfd, phys_ram_base + flash->offset,
|
if ( read( bootfd, phys_ram_base + flash->offset, BOOT_SIZE ) < 0 ) {
|
||||||
BOOT_SIZE) < 0) {
|
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: read %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: read %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
g_free( bootfile );
|
g_free( bootfile );
|
||||||
close( bootfd );
|
close( bootfd );
|
||||||
|
@ -566,8 +490,7 @@ flash_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
properly. */
|
properly. */
|
||||||
for ( i = 2; i < 14; i++ ) {
|
for ( i = 2; i < 14; i++ ) {
|
||||||
bank_marker[ 1 ] = i;
|
bank_marker[ 1 ] = i;
|
||||||
memcpy(phys_ram_base + flash->offset + 0x40100 +
|
memcpy( phys_ram_base + flash->offset + 0x40100 + 0x20000 * i, bank_marker, 5 );
|
||||||
0x20000 * i, bank_marker, 5);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -581,37 +504,27 @@ retry:
|
||||||
if ( filename != NULL ) {
|
if ( filename != NULL ) {
|
||||||
fwfd = open( filename, O_RDONLY );
|
fwfd = open( filename, O_RDONLY );
|
||||||
if ( fwfd < 0 ) {
|
if ( fwfd < 0 ) {
|
||||||
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
/* Mark firmware as invalid if there is one */
|
/* Mark firmware as invalid if there is one */
|
||||||
memset(phys_ram_base + flash->offset +
|
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||||
BOOT_SIZE, 0, 16);
|
|
||||||
if ( x49gp->firmware != NULL ) {
|
if ( x49gp->firmware != NULL ) {
|
||||||
fprintf( stderr, "Warning: Could not "
|
fprintf( stderr, "Warning: Could not "
|
||||||
"open selected firmware, "
|
"open selected firmware, "
|
||||||
"falling back to bootloader "
|
"falling back to bootloader "
|
||||||
"recovery tools\n" );
|
"recovery tools\n" );
|
||||||
} else {
|
} else {
|
||||||
x49gp_ui_show_error(x49gp,
|
x49gp_ui_show_error( x49gp, "Could not open "
|
||||||
"Could not open "
|
|
||||||
"selected "
|
"selected "
|
||||||
"firmware!" );
|
"firmware!" );
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bytes_read = read(fwfd, phys_ram_base +
|
bytes_read = read( fwfd, phys_ram_base + flash->offset + BOOT_SIZE, 16 );
|
||||||
flash->offset + BOOT_SIZE,
|
|
||||||
16);
|
|
||||||
if ( bytes_read < 0 ) {
|
if ( bytes_read < 0 ) {
|
||||||
fprintf(stderr, "%s: %s:%u: read %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: read %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__,
|
|
||||||
__LINE__, filename,
|
|
||||||
strerror(errno));
|
|
||||||
/* Mark firmware as invalid
|
/* Mark firmware as invalid
|
||||||
if there is one */
|
if there is one */
|
||||||
memset(phys_ram_base + flash->offset +
|
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||||
BOOT_SIZE, 0, 16);
|
|
||||||
if ( x49gp->firmware != NULL ) {
|
if ( x49gp->firmware != NULL ) {
|
||||||
fprintf( stderr, "Warning: "
|
fprintf( stderr, "Warning: "
|
||||||
"Could not read "
|
"Could not read "
|
||||||
|
@ -620,21 +533,15 @@ retry:
|
||||||
"bootloader recovery "
|
"bootloader recovery "
|
||||||
"tools\n" );
|
"tools\n" );
|
||||||
} else {
|
} else {
|
||||||
x49gp_ui_show_error(x49gp,
|
x49gp_ui_show_error( x49gp, "Could not "
|
||||||
"Could not "
|
|
||||||
"read "
|
"read "
|
||||||
"selected "
|
"selected "
|
||||||
"firmware!" );
|
"firmware!" );
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
} else if (bytes_read < 16 ||
|
} else if ( bytes_read < 16 || memcmp( phys_ram_base + flash->offset + BOOT_SIZE, "KINPOUPDATEIMAGE", 16 ) != 0 ) {
|
||||||
memcmp(phys_ram_base +
|
|
||||||
flash->offset + BOOT_SIZE,
|
|
||||||
"KINPOUPDATEIMAGE", 16)
|
|
||||||
!= 0) {
|
|
||||||
/* Mark firmware as invalid */
|
/* Mark firmware as invalid */
|
||||||
memset(phys_ram_base + flash->offset +
|
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||||
BOOT_SIZE, 0, 16);
|
|
||||||
if ( x49gp->firmware != NULL ) {
|
if ( x49gp->firmware != NULL ) {
|
||||||
fprintf( stderr, "Warning: "
|
fprintf( stderr, "Warning: "
|
||||||
"Firmware is invalid, "
|
"Firmware is invalid, "
|
||||||
|
@ -642,8 +549,7 @@ retry:
|
||||||
"bootloader recovery "
|
"bootloader recovery "
|
||||||
"tools\n" );
|
"tools\n" );
|
||||||
} else {
|
} else {
|
||||||
x49gp_ui_show_error(x49gp,
|
x49gp_ui_show_error( x49gp, "Selected "
|
||||||
"Selected "
|
|
||||||
"firmware "
|
"firmware "
|
||||||
"is "
|
"is "
|
||||||
"invalid!" );
|
"invalid!" );
|
||||||
|
@ -653,19 +559,11 @@ retry:
|
||||||
SST29VF160_SIZE - BOOT_SIZE, but if so,
|
SST29VF160_SIZE - BOOT_SIZE, but if so,
|
||||||
read will just give us what it sees.
|
read will just give us what it sees.
|
||||||
The space after that will remain empty. */
|
The space after that will remain empty. */
|
||||||
} else if (read(fwfd, phys_ram_base +
|
} else if ( read( fwfd, phys_ram_base + flash->offset + BOOT_SIZE + 16, SST29VF160_SIZE - ( BOOT_SIZE + 16 ) ) < 0 ) {
|
||||||
flash->offset + BOOT_SIZE + 16,
|
fprintf( stderr, "%s: %s:%u: read %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
SST29VF160_SIZE -
|
|
||||||
(BOOT_SIZE + 16))
|
|
||||||
< 0) {
|
|
||||||
fprintf(stderr, "%s: %s:%u: read %s: %s\n",
|
|
||||||
module->name, __FUNCTION__,
|
|
||||||
__LINE__, filename,
|
|
||||||
strerror(errno));
|
|
||||||
/* Mark firmware as invalid
|
/* Mark firmware as invalid
|
||||||
if there is one */
|
if there is one */
|
||||||
memset(phys_ram_base + flash->offset +
|
memset( phys_ram_base + flash->offset + BOOT_SIZE, 0, 16 );
|
||||||
BOOT_SIZE, 0, 16);
|
|
||||||
if ( x49gp->firmware != NULL ) {
|
if ( x49gp->firmware != NULL ) {
|
||||||
fprintf( stderr, "Warning: "
|
fprintf( stderr, "Warning: "
|
||||||
"Could not read "
|
"Could not read "
|
||||||
|
@ -674,8 +572,7 @@ retry:
|
||||||
"bootloader recovery "
|
"bootloader recovery "
|
||||||
"tools\n" );
|
"tools\n" );
|
||||||
} else {
|
} else {
|
||||||
x49gp_ui_show_error(x49gp,
|
x49gp_ui_show_error( x49gp, "Could not "
|
||||||
"Could not "
|
|
||||||
"read "
|
"read "
|
||||||
"selected "
|
"selected "
|
||||||
"firmware!" );
|
"firmware!" );
|
||||||
|
@ -684,9 +581,7 @@ retry:
|
||||||
} else {
|
} else {
|
||||||
/* Mark firmware as valid in the same
|
/* Mark firmware as valid in the same
|
||||||
way the bootloader does */
|
way the bootloader does */
|
||||||
memcpy(phys_ram_base + flash->offset +
|
memcpy( phys_ram_base + flash->offset + BOOT_SIZE, "Kinposhcopyright", 16 );
|
||||||
BOOT_SIZE, "Kinposhcopyright",
|
|
||||||
16);
|
|
||||||
}
|
}
|
||||||
close( fwfd );
|
close( fwfd );
|
||||||
}
|
}
|
||||||
|
@ -699,8 +594,7 @@ retry:
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int flash_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
flash_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = module->user_data;
|
x49gp_flash_t* flash = module->user_data;
|
||||||
int error;
|
int error;
|
||||||
|
@ -713,23 +607,20 @@ flash_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
|
|
||||||
error = msync( flash->data, flash->size, MS_ASYNC );
|
error = msync( flash->data, flash->size, MS_ASYNC );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: msync: %s\n",
|
fprintf( stderr, "%s:%u: msync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = fsync( flash->fd );
|
error = fsync( flash->fd );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: fsync: %s\n",
|
fprintf( stderr, "%s:%u: fsync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int flash_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
flash_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash = module->user_data;
|
x49gp_flash_t* flash = module->user_data;
|
||||||
|
|
||||||
|
@ -741,22 +632,11 @@ flash_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *flash_readfn[] =
|
static CPUReadMemoryFunc* flash_readfn[] = { flash_readb, flash_readw, flash_readl };
|
||||||
{
|
|
||||||
flash_readb,
|
|
||||||
flash_readw,
|
|
||||||
flash_readl
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *flash_writefn[] =
|
static CPUWriteMemoryFunc* flash_writefn[] = { flash_writeb, flash_writew, flash_writel };
|
||||||
{
|
|
||||||
flash_writeb,
|
|
||||||
flash_writew,
|
|
||||||
flash_writel
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int flash_init( x49gp_module_t* module )
|
||||||
flash_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash;
|
x49gp_flash_t* flash;
|
||||||
|
|
||||||
|
@ -766,8 +646,7 @@ flash_init(x49gp_module_t *module)
|
||||||
|
|
||||||
flash = malloc( sizeof( x49gp_flash_t ) );
|
flash = malloc( sizeof( x49gp_flash_t ) );
|
||||||
if ( NULL == flash ) {
|
if ( NULL == flash ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
module->name, __FUNCTION__, __LINE__);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset( flash, 0, sizeof( x49gp_flash_t ) );
|
memset( flash, 0, sizeof( x49gp_flash_t ) );
|
||||||
|
@ -782,21 +661,18 @@ flash_init(x49gp_module_t *module)
|
||||||
|
|
||||||
module->user_data = flash;
|
module->user_data = flash;
|
||||||
|
|
||||||
flash->iotype = cpu_register_io_memory(flash_readfn,
|
flash->iotype = cpu_register_io_memory( flash_readfn, flash_writefn, flash );
|
||||||
flash_writefn, flash);
|
|
||||||
|
|
||||||
flash->data = ( void* )-1;
|
flash->data = ( void* )-1;
|
||||||
flash->offset = phys_ram_size;
|
flash->offset = phys_ram_size;
|
||||||
phys_ram_size += SST29VF160_SIZE;
|
phys_ram_size += SST29VF160_SIZE;
|
||||||
|
|
||||||
cpu_register_physical_memory(0x00000000, SST29VF160_SIZE,
|
cpu_register_physical_memory( 0x00000000, SST29VF160_SIZE, flash->offset | flash->iotype | IO_MEM_ROMD );
|
||||||
flash->offset | flash->iotype | IO_MEM_ROMD);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int flash_exit( x49gp_module_t* module )
|
||||||
flash_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_flash_t* flash;
|
x49gp_flash_t* flash;
|
||||||
|
|
||||||
|
@ -823,14 +699,11 @@ flash_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_flash_init( x49gp_t* x49gp )
|
||||||
x49gp_flash_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "flash", flash_init, flash_exit,
|
if ( x49gp_module_init( x49gp, "flash", flash_init, flash_exit, flash_reset, flash_load, flash_save, NULL, &module ) ) {
|
||||||
flash_reset, flash_load, flash_save, NULL,
|
|
||||||
&module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
108
src/gdbstub.c
108
src/gdbstub.c
|
@ -34,30 +34,14 @@
|
||||||
|
|
||||||
#define MAX_PACKET_LENGTH 4096
|
#define MAX_PACKET_LENGTH 4096
|
||||||
|
|
||||||
|
enum { GDB_SIGNAL_0 = 0, GDB_SIGNAL_INT = 2, GDB_SIGNAL_TRAP = 5, GDB_SIGNAL_UNKNOWN = 143 };
|
||||||
enum {
|
|
||||||
GDB_SIGNAL_0 = 0,
|
|
||||||
GDB_SIGNAL_INT = 2,
|
|
||||||
GDB_SIGNAL_TRAP = 5,
|
|
||||||
GDB_SIGNAL_UNKNOWN = 143
|
|
||||||
};
|
|
||||||
|
|
||||||
/* In system mode we only need SIGINT and SIGTRAP; other signals
|
/* In system mode we only need SIGINT and SIGTRAP; other signals
|
||||||
are not yet supported. */
|
are not yet supported. */
|
||||||
|
|
||||||
enum {
|
enum { TARGET_SIGINT = 2, TARGET_SIGTRAP = 5 };
|
||||||
TARGET_SIGINT = 2,
|
|
||||||
TARGET_SIGTRAP = 5
|
|
||||||
};
|
|
||||||
|
|
||||||
static int gdb_signal_table[] = {
|
static int gdb_signal_table[] = { -1, -1, TARGET_SIGINT, -1, -1, TARGET_SIGTRAP };
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
TARGET_SIGINT,
|
|
||||||
-1,
|
|
||||||
-1,
|
|
||||||
TARGET_SIGTRAP
|
|
||||||
};
|
|
||||||
|
|
||||||
static int target_signal_to_gdb( int sig )
|
static int target_signal_to_gdb( int sig )
|
||||||
{
|
{
|
||||||
|
@ -161,17 +145,13 @@ static enum {
|
||||||
int use_gdb_syscalls( void )
|
int use_gdb_syscalls( void )
|
||||||
{
|
{
|
||||||
if ( gdb_syscall_mode == GDB_SYS_UNKNOWN ) {
|
if ( gdb_syscall_mode == GDB_SYS_UNKNOWN ) {
|
||||||
gdb_syscall_mode = (gdbserver_state ? GDB_SYS_ENABLED
|
gdb_syscall_mode = ( gdbserver_state ? GDB_SYS_ENABLED : GDB_SYS_DISABLED );
|
||||||
: GDB_SYS_DISABLED);
|
|
||||||
}
|
}
|
||||||
return gdb_syscall_mode == GDB_SYS_ENABLED;
|
return gdb_syscall_mode == GDB_SYS_ENABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Resume execution. */
|
/* Resume execution. */
|
||||||
static inline void gdb_continue(GDBState *s)
|
static inline void gdb_continue( GDBState* s ) { s->running_state = 1; }
|
||||||
{
|
|
||||||
s->running_state = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void put_buffer( GDBState* s, const uint8_t* buf, int len )
|
static void put_buffer( GDBState* s, const uint8_t* buf, int len )
|
||||||
{
|
{
|
||||||
|
@ -277,19 +257,23 @@ static int put_packet(GDBState *s, const char *buf)
|
||||||
we can use the raw memory access routines to access the value buffer.
|
we can use the raw memory access routines to access the value buffer.
|
||||||
Conveniently, these also handle the case where the buffer is mis-aligned.
|
Conveniently, these also handle the case where the buffer is mis-aligned.
|
||||||
*/
|
*/
|
||||||
#define GET_REG8(val) do { \
|
#define GET_REG8( val ) \
|
||||||
|
do { \
|
||||||
stb_p( mem_buf, val ); \
|
stb_p( mem_buf, val ); \
|
||||||
return 1; \
|
return 1; \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
#define GET_REG16(val) do { \
|
#define GET_REG16( val ) \
|
||||||
|
do { \
|
||||||
stw_p( mem_buf, val ); \
|
stw_p( mem_buf, val ); \
|
||||||
return 2; \
|
return 2; \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
#define GET_REG32(val) do { \
|
#define GET_REG32( val ) \
|
||||||
|
do { \
|
||||||
stl_p( mem_buf, val ); \
|
stl_p( mem_buf, val ); \
|
||||||
return 4; \
|
return 4; \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
#define GET_REG64(val) do { \
|
#define GET_REG64( val ) \
|
||||||
|
do { \
|
||||||
stq_p( mem_buf, val ); \
|
stq_p( mem_buf, val ); \
|
||||||
return 8; \
|
return 8; \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
|
@ -386,7 +370,10 @@ static int memtox(char *buf, const char *mem, int len)
|
||||||
while ( len-- ) {
|
while ( len-- ) {
|
||||||
c = *( mem++ );
|
c = *( mem++ );
|
||||||
switch ( c ) {
|
switch ( c ) {
|
||||||
case '#': case '$': case '*': case '}':
|
case '#':
|
||||||
|
case '$':
|
||||||
|
case '*':
|
||||||
|
case '}':
|
||||||
*( p++ ) = '}';
|
*( p++ ) = '}';
|
||||||
*( p++ ) = c ^ 0x20;
|
*( p++ ) = c ^ 0x20;
|
||||||
break;
|
break;
|
||||||
|
@ -478,9 +465,7 @@ static int gdb_write_register(CPUState *env, uint8_t *mem_buf, int reg)
|
||||||
gdb reading a CPU register, and set_reg is gdb modifying a CPU register.
|
gdb reading a CPU register, and set_reg is gdb modifying a CPU register.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void gdb_register_coprocessor(CPUState * env,
|
void gdb_register_coprocessor( CPUState* env, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char* xml, int g_pos )
|
||||||
gdb_reg_cb get_reg, gdb_reg_cb set_reg,
|
|
||||||
int num_regs, const char *xml, int g_pos)
|
|
||||||
{
|
{
|
||||||
GDBRegisterState* s;
|
GDBRegisterState* s;
|
||||||
GDBRegisterState** p;
|
GDBRegisterState** p;
|
||||||
|
@ -504,8 +489,10 @@ void gdb_register_coprocessor(CPUState * env,
|
||||||
*p = s;
|
*p = s;
|
||||||
if ( g_pos ) {
|
if ( g_pos ) {
|
||||||
if ( g_pos != s->base_reg ) {
|
if ( g_pos != s->base_reg ) {
|
||||||
fprintf(stderr, "Error: Bad gdb register numbering for '%s'\n"
|
fprintf( stderr,
|
||||||
"Expected %d got %d\n", xml, g_pos, s->base_reg);
|
"Error: Bad gdb register numbering for '%s'\n"
|
||||||
|
"Expected %d got %d\n",
|
||||||
|
xml, g_pos, s->base_reg );
|
||||||
} else {
|
} else {
|
||||||
num_g_regs = last_reg;
|
num_g_regs = last_reg;
|
||||||
}
|
}
|
||||||
|
@ -539,8 +526,7 @@ static int gdb_breakpoint_insert(target_ulong addr, target_ulong len, int type)
|
||||||
case GDB_WATCHPOINT_READ:
|
case GDB_WATCHPOINT_READ:
|
||||||
case GDB_WATCHPOINT_ACCESS:
|
case GDB_WATCHPOINT_ACCESS:
|
||||||
for ( env = first_cpu; env != NULL; env = env->next_cpu ) {
|
for ( env = first_cpu; env != NULL; env = env->next_cpu ) {
|
||||||
err = cpu_watchpoint_insert(env, addr, len, xlat_gdb_type[type],
|
err = cpu_watchpoint_insert( env, addr, len, xlat_gdb_type[ type ], NULL );
|
||||||
NULL);
|
|
||||||
if ( err )
|
if ( err )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -593,10 +579,7 @@ static void gdb_breakpoint_remove_all(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gdb_set_cpu_pc(GDBState *s, target_ulong pc)
|
static void gdb_set_cpu_pc( GDBState* s, target_ulong pc ) { s->c_cpu->regs[ 15 ] = pc; }
|
||||||
{
|
|
||||||
s->c_cpu->regs[15] = pc;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int gdb_id( CPUState* env )
|
static inline int gdb_id( CPUState* env )
|
||||||
{
|
{
|
||||||
|
@ -639,8 +622,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
|
||||||
switch ( ch ) {
|
switch ( ch ) {
|
||||||
case '?':
|
case '?':
|
||||||
/* TODO: Make this return the correct value for user-mode. */
|
/* TODO: Make this return the correct value for user-mode. */
|
||||||
snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP,
|
snprintf( buf, sizeof( buf ), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, gdb_id( s->c_cpu ) );
|
||||||
gdb_id(s->c_cpu));
|
|
||||||
put_packet( s, buf );
|
put_packet( s, buf );
|
||||||
/* Remove all the breakpoints when this query is issued,
|
/* Remove all the breakpoints when this query is issued,
|
||||||
* because gdb is doing and initial connect and the state
|
* because gdb is doing and initial connect and the state
|
||||||
|
@ -894,10 +876,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
|
||||||
/* parse any 'q' packets here */
|
/* parse any 'q' packets here */
|
||||||
if ( !strcmp( p, "qemu.sstepbits" ) ) {
|
if ( !strcmp( p, "qemu.sstepbits" ) ) {
|
||||||
/* Query Breakpoint bit definitions */
|
/* Query Breakpoint bit definitions */
|
||||||
snprintf(buf, sizeof(buf), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x",
|
snprintf( buf, sizeof( buf ), "ENABLE=%x,NOIRQ=%x,NOTIMER=%x", SSTEP_ENABLE, SSTEP_NOIRQ, SSTEP_NOTIMER );
|
||||||
SSTEP_ENABLE,
|
|
||||||
SSTEP_NOIRQ,
|
|
||||||
SSTEP_NOTIMER);
|
|
||||||
put_packet( s, buf );
|
put_packet( s, buf );
|
||||||
break;
|
break;
|
||||||
} else if ( strncmp( p, "qemu.sstep", 10 ) == 0 ) {
|
} else if ( strncmp( p, "qemu.sstep", 10 ) == 0 ) {
|
||||||
|
@ -935,9 +914,8 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)
|
||||||
thread = strtoull( p + 16, ( char** )&p, 16 );
|
thread = strtoull( p + 16, ( char** )&p, 16 );
|
||||||
env = find_cpu( thread );
|
env = find_cpu( thread );
|
||||||
if ( env != NULL ) {
|
if ( env != NULL ) {
|
||||||
len = snprintf((char *)mem_buf, sizeof(mem_buf),
|
len =
|
||||||
"CPU#%d [%s]", env->cpu_index,
|
snprintf( ( char* )mem_buf, sizeof( mem_buf ), "CPU#%d [%s]", env->cpu_index, env->halted ? "halted " : "running" );
|
||||||
env->halted ? "halted " : "running");
|
|
||||||
memtohex( buf, mem_buf, len );
|
memtohex( buf, mem_buf, len );
|
||||||
put_packet( s, buf );
|
put_packet( s, buf );
|
||||||
}
|
}
|
||||||
|
@ -1048,13 +1026,11 @@ void gdb_do_syscall(gdb_syscall_complete_cb cb, const char *fmt, ...)
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
addr = va_arg( va, target_ulong );
|
addr = va_arg( va, target_ulong );
|
||||||
p += snprintf(p, &buf[sizeof(buf)] - p, TARGET_FMT_lx "/%x",
|
p += snprintf( p, &buf[ sizeof( buf ) ] - p, TARGET_FMT_lx "/%x", addr, va_arg( va, int ) );
|
||||||
addr, va_arg(va, int));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bad_format:
|
bad_format:
|
||||||
fprintf(stderr, "gdbstub: Bad syscall format string '%s'\n",
|
fprintf( stderr, "gdbstub: Bad syscall format string '%s'\n", fmt - 1 );
|
||||||
fmt - 1);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1125,8 +1101,7 @@ static void gdb_read_byte(GDBState *s, int ch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int gdb_queuesig( void )
|
||||||
gdb_queuesig (void)
|
|
||||||
{
|
{
|
||||||
GDBState* s;
|
GDBState* s;
|
||||||
|
|
||||||
|
@ -1138,8 +1113,7 @@ gdb_queuesig (void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int gdb_handlesig( CPUState* env, int sig )
|
||||||
gdb_handlesig (CPUState *env, int sig)
|
|
||||||
{
|
{
|
||||||
GDBState* s;
|
GDBState* s;
|
||||||
char buf[ 256 ];
|
char buf[ 256 ];
|
||||||
|
@ -1158,8 +1132,7 @@ gdb_handlesig (CPUState *env, int sig)
|
||||||
cpu_single_step( env, 0 );
|
cpu_single_step( env, 0 );
|
||||||
tb_flush( env );
|
tb_flush( env );
|
||||||
|
|
||||||
if (sig != 0)
|
if ( sig != 0 ) {
|
||||||
{
|
|
||||||
snprintf( buf, sizeof( buf ), "S%02x", target_signal_to_gdb( sig ) );
|
snprintf( buf, sizeof( buf ), "S%02x", target_signal_to_gdb( sig ) );
|
||||||
put_packet( s, buf );
|
put_packet( s, buf );
|
||||||
}
|
}
|
||||||
|
@ -1173,8 +1146,7 @@ gdb_handlesig (CPUState *env, int sig)
|
||||||
s->running_state = 0;
|
s->running_state = 0;
|
||||||
while ( s->running_state == 0 ) {
|
while ( s->running_state == 0 ) {
|
||||||
n = read( s->fd, buf, 256 );
|
n = read( s->fd, buf, 256 );
|
||||||
if (n > 0)
|
if ( n > 0 ) {
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
#ifdef DEBUG_GDB
|
#ifdef DEBUG_GDB
|
||||||
|
@ -1184,9 +1156,7 @@ gdb_handlesig (CPUState *env, int sig)
|
||||||
|
|
||||||
for ( i = 0; i < n; i++ )
|
for ( i = 0; i < n; i++ )
|
||||||
gdb_read_byte( s, buf[ i ] );
|
gdb_read_byte( s, buf[ i ] );
|
||||||
}
|
} else if ( n == 0 || errno != EAGAIN ) {
|
||||||
else if (n == 0 || errno != EAGAIN)
|
|
||||||
{
|
|
||||||
/* XXX: Connection closed. Should probably wait for annother
|
/* XXX: Connection closed. Should probably wait for annother
|
||||||
connection before continuing. */
|
connection before continuing. */
|
||||||
gdbserver_fd = -1;
|
gdbserver_fd = -1;
|
||||||
|
@ -1198,8 +1168,7 @@ gdb_handlesig (CPUState *env, int sig)
|
||||||
return sig;
|
return sig;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int gdb_poll( CPUState* env )
|
||||||
gdb_poll (CPUState *env)
|
|
||||||
{
|
{
|
||||||
GDBState* s;
|
GDBState* s;
|
||||||
struct pollfd pfd;
|
struct pollfd pfd;
|
||||||
|
@ -1356,7 +1325,4 @@ void gdbserver_fork(CPUState *env)
|
||||||
cpu_watchpoint_remove_all( env, BP_GDB );
|
cpu_watchpoint_remove_all( env, BP_GDB );
|
||||||
}
|
}
|
||||||
|
|
||||||
int gdbserver_isactive()
|
int gdbserver_isactive() { return ( gdbserver_fd >= 0 ); }
|
||||||
{
|
|
||||||
return (gdbserver_fd >= 0);
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,8 +12,7 @@
|
||||||
#define GDB_WATCHPOINT_READ 3
|
#define GDB_WATCHPOINT_READ 3
|
||||||
#define GDB_WATCHPOINT_ACCESS 4
|
#define GDB_WATCHPOINT_ACCESS 4
|
||||||
|
|
||||||
typedef void (*gdb_syscall_complete_cb)(CPUState *env,
|
typedef void ( *gdb_syscall_complete_cb )( CPUState* env, target_ulong ret, target_ulong err );
|
||||||
target_ulong ret, target_ulong err);
|
|
||||||
|
|
||||||
void gdb_do_syscall( gdb_syscall_complete_cb cb, const char* fmt, ... );
|
void gdb_do_syscall( gdb_syscall_complete_cb cb, const char* fmt, ... );
|
||||||
int use_gdb_syscalls( void );
|
int use_gdb_syscalls( void );
|
||||||
|
@ -30,9 +29,7 @@ void gdbserver_fork(CPUState *);
|
||||||
|
|
||||||
/* Get or set a register. Returns the size of the register. */
|
/* Get or set a register. Returns the size of the register. */
|
||||||
typedef int ( *gdb_reg_cb )( CPUState* env, uint8_t* buf, int reg );
|
typedef int ( *gdb_reg_cb )( CPUState* env, uint8_t* buf, int reg );
|
||||||
void gdb_register_coprocessor(CPUState *env,
|
void gdb_register_coprocessor( CPUState* env, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char* xml, int g_pos );
|
||||||
gdb_reg_cb get_reg, gdb_reg_cb set_reg,
|
|
||||||
int num_regs, const char *xml, int g_pos);
|
|
||||||
|
|
||||||
int gdbserver_isactive();
|
int gdbserver_isactive();
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,7 @@ typedef struct {
|
||||||
gunichar unichar;
|
gunichar unichar;
|
||||||
} x49gp_glyph_t;
|
} x49gp_glyph_t;
|
||||||
|
|
||||||
static const x49gp_glyph_t x49gp_glyphs[] =
|
static const x49gp_glyph_t x49gp_glyphs[] = {
|
||||||
{
|
|
||||||
{"exclamdown", 0x00a1},
|
{"exclamdown", 0x00a1},
|
||||||
{"cent", 0x00a2},
|
{"cent", 0x00a2},
|
||||||
{"sterling", 0x00a3},
|
{"sterling", 0x00a3},
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
int
|
int main( int argc, char** argv )
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
unsigned char *input, *p;
|
unsigned char *input, *p;
|
||||||
unsigned char* memory = NULL;
|
unsigned char* memory = NULL;
|
||||||
|
@ -91,8 +90,7 @@ main(int argc, char **argv)
|
||||||
else if ( 'A' <= *p && *p <= 'F' )
|
else if ( 'A' <= *p && *p <= 'F' )
|
||||||
memory[ i ] = ( *p - 'A' + 10 ) << 0;
|
memory[ i ] = ( *p - 'A' + 10 ) << 0;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: parse error at byte %d\n",
|
fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
|
||||||
argv[0], i);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
|
@ -103,8 +101,7 @@ main(int argc, char **argv)
|
||||||
else if ( 'A' <= *p && *p <= 'F' )
|
else if ( 'A' <= *p && *p <= 'F' )
|
||||||
memory[ i ] |= ( *p - 'A' + 10 ) << 4;
|
memory[ i ] |= ( *p - 'A' + 10 ) << 4;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: parse error at byte %d\n",
|
fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
|
||||||
argv[0], i);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
|
|
|
@ -26,8 +26,7 @@
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
int
|
int main( int argc, char** argv )
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
unsigned char *input, *p;
|
unsigned char *input, *p;
|
||||||
unsigned char* memory = NULL;
|
unsigned char* memory = NULL;
|
||||||
|
@ -91,8 +90,7 @@ main(int argc, char **argv)
|
||||||
else if ( 'A' <= *p && *p <= 'F' )
|
else if ( 'A' <= *p && *p <= 'F' )
|
||||||
memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] = ( *p - 'A' + 10 ) << 0;
|
memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] = ( *p - 'A' + 10 ) << 0;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: parse error at byte %d\n",
|
fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
|
||||||
argv[0], i);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
|
@ -103,8 +101,7 @@ main(int argc, char **argv)
|
||||||
else if ( 'A' <= *p && *p <= 'F' )
|
else if ( 'A' <= *p && *p <= 'F' )
|
||||||
memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] |= ( *p - 'A' + 10 ) << 4;
|
memory[ ( i & ~3 ) + 3 - ( i & 3 ) ] |= ( *p - 'A' + 10 ) << 4;
|
||||||
else {
|
else {
|
||||||
fprintf(stderr, "%s: parse error at byte %d\n",
|
fprintf( stderr, "%s: parse error at byte %d\n", argv[ 0 ], i );
|
||||||
argv[0], i);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
p++;
|
p++;
|
||||||
|
|
184
src/list.h
184
src/list.h
|
@ -33,11 +33,12 @@ struct list_head {
|
||||||
|
|
||||||
#define LIST_HEAD_INIT( name ) { &( name ), &( name ) }
|
#define LIST_HEAD_INIT( name ) { &( name ), &( name ) }
|
||||||
|
|
||||||
#define LIST_HEAD(name) \
|
#define LIST_HEAD( name ) struct list_head name = LIST_HEAD_INIT( name )
|
||||||
struct list_head name = LIST_HEAD_INIT(name)
|
|
||||||
|
|
||||||
#define INIT_LIST_HEAD(ptr) do { \
|
#define INIT_LIST_HEAD( ptr ) \
|
||||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
do { \
|
||||||
|
( ptr )->next = ( ptr ); \
|
||||||
|
( ptr )->prev = ( ptr ); \
|
||||||
} while ( 0 )
|
} while ( 0 )
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -46,9 +47,7 @@ struct list_head {
|
||||||
* This is only for internal list manipulation where we know
|
* This is only for internal list manipulation where we know
|
||||||
* the prev/next entries already!
|
* the prev/next entries already!
|
||||||
*/
|
*/
|
||||||
static inline void __list_add(struct list_head *new,
|
static inline void __list_add( struct list_head* new, struct list_head* prev, struct list_head* next )
|
||||||
struct list_head *prev,
|
|
||||||
struct list_head *next)
|
|
||||||
{
|
{
|
||||||
next->prev = new;
|
next->prev = new;
|
||||||
new->next = next;
|
new->next = next;
|
||||||
|
@ -64,10 +63,7 @@ static inline void __list_add(struct list_head *new,
|
||||||
* Insert a new entry after the specified head.
|
* Insert a new entry after the specified head.
|
||||||
* This is good for implementing stacks.
|
* This is good for implementing stacks.
|
||||||
*/
|
*/
|
||||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
static inline void list_add( struct list_head* new, struct list_head* head ) { __list_add( new, head, head->next ); }
|
||||||
{
|
|
||||||
__list_add(new, head, head->next);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_add_tail - add a new entry
|
* list_add_tail - add a new entry
|
||||||
|
@ -77,10 +73,7 @@ static inline void list_add(struct list_head *new, struct list_head *head)
|
||||||
* Insert a new entry before the specified head.
|
* Insert a new entry before the specified head.
|
||||||
* This is useful for implementing queues.
|
* This is useful for implementing queues.
|
||||||
*/
|
*/
|
||||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
static inline void list_add_tail( struct list_head* new, struct list_head* head ) { __list_add( new, head->prev, head ); }
|
||||||
{
|
|
||||||
__list_add(new, head->prev, head);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Delete a list entry by making the prev/next entries
|
* Delete a list entry by making the prev/next entries
|
||||||
|
@ -134,8 +127,7 @@ static inline void list_move(struct list_head *list, struct list_head *head)
|
||||||
* @list: the entry to move
|
* @list: the entry to move
|
||||||
* @head: the head that will follow our entry
|
* @head: the head that will follow our entry
|
||||||
*/
|
*/
|
||||||
static inline void list_move_tail(struct list_head *list,
|
static inline void list_move_tail( struct list_head* list, struct list_head* head )
|
||||||
struct list_head *head)
|
|
||||||
{
|
{
|
||||||
__list_del( list->prev, list->next );
|
__list_del( list->prev, list->next );
|
||||||
list_add_tail( list, head );
|
list_add_tail( list, head );
|
||||||
|
@ -145,10 +137,7 @@ static inline void list_move_tail(struct list_head *list,
|
||||||
* list_empty - tests whether a list is empty
|
* list_empty - tests whether a list is empty
|
||||||
* @head: the list to test.
|
* @head: the list to test.
|
||||||
*/
|
*/
|
||||||
static inline int list_empty(const struct list_head *head)
|
static inline int list_empty( const struct list_head* head ) { return head->next == head; }
|
||||||
{
|
|
||||||
return head->next == head;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_empty_careful - tests whether a list is
|
* list_empty_careful - tests whether a list is
|
||||||
|
@ -168,8 +157,7 @@ static inline int list_empty_careful(const struct list_head *head)
|
||||||
return ( next == head ) && ( next == head->prev );
|
return ( next == head ) && ( next == head->prev );
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void __list_splice(struct list_head *list,
|
static inline void __list_splice( struct list_head* list, struct list_head* head )
|
||||||
struct list_head *head)
|
|
||||||
{
|
{
|
||||||
struct list_head* first = list->next;
|
struct list_head* first = list->next;
|
||||||
struct list_head* last = list->prev;
|
struct list_head* last = list->prev;
|
||||||
|
@ -200,8 +188,7 @@ static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||||
*
|
*
|
||||||
* The list at @list is reinitialised
|
* The list at @list is reinitialised
|
||||||
*/
|
*/
|
||||||
static inline void list_splice_init(struct list_head *list,
|
static inline void list_splice_init( struct list_head* list, struct list_head* head )
|
||||||
struct list_head *head)
|
|
||||||
{
|
{
|
||||||
if ( !list_empty( list ) ) {
|
if ( !list_empty( list ) ) {
|
||||||
__list_splice( list, head );
|
__list_splice( list, head );
|
||||||
|
@ -215,17 +202,14 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @type: the type of the struct this is embedded in.
|
* @type: the type of the struct this is embedded in.
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_entry(ptr, type, member) \
|
#define list_entry( ptr, type, member ) container_of( ptr, type, member )
|
||||||
container_of(ptr, type, member)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each - iterate over a list
|
* list_for_each - iterate over a list
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
* @pos: the &struct list_head to use as a loop counter.
|
||||||
* @head: the head for your list.
|
* @head: the head for your list.
|
||||||
*/
|
*/
|
||||||
#define list_for_each(pos, head) \
|
#define list_for_each( pos, head ) for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = pos->next )
|
||||||
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
|
|
||||||
pos = pos->next)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __list_for_each - iterate over a list
|
* __list_for_each - iterate over a list
|
||||||
|
@ -237,17 +221,14 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* Use this for code that knows the list to be very short (empty
|
* Use this for code that knows the list to be very short (empty
|
||||||
* or 1 entry) most of the time.
|
* or 1 entry) most of the time.
|
||||||
*/
|
*/
|
||||||
#define __list_for_each(pos, head) \
|
#define __list_for_each( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = pos->next )
|
||||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_prev - iterate over a list backwards
|
* list_for_each_prev - iterate over a list backwards
|
||||||
* @pos: the &struct list_head to use as a loop counter.
|
* @pos: the &struct list_head to use as a loop counter.
|
||||||
* @head: the head for your list.
|
* @head: the head for your list.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_prev(pos, head) \
|
#define list_for_each_prev( pos, head ) for ( pos = ( head )->prev; prefetch( pos->prev ), pos != ( head ); pos = pos->prev )
|
||||||
for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
|
|
||||||
pos = pos->prev)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||||
|
@ -255,9 +236,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @n: another &struct list_head to use as temporary storage
|
* @n: another &struct list_head to use as temporary storage
|
||||||
* @head: the head for your list.
|
* @head: the head for your list.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_safe(pos, n, head) \
|
#define list_for_each_safe( pos, n, head ) for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = n, n = pos->next )
|
||||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
|
||||||
pos = n, n = pos->next)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_entry - iterate over list of given type
|
* list_for_each_entry - iterate over list of given type
|
||||||
|
@ -266,8 +245,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry( pos, head, member ) \
|
#define list_for_each_entry( pos, head, member ) \
|
||||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
|
||||||
prefetch(pos->member.next), &pos->member != (head); \
|
|
||||||
pos = list_entry( pos->member.next, typeof( *pos ), member ) )
|
pos = list_entry( pos->member.next, typeof( *pos ), member ) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -277,8 +255,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_reverse( pos, head, member ) \
|
#define list_for_each_entry_reverse( pos, head, member ) \
|
||||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
for ( pos = list_entry( ( head )->prev, typeof( *pos ), member ); prefetch( pos->member.prev ), &pos->member != ( head ); \
|
||||||
prefetch(pos->member.prev), &pos->member != (head); \
|
|
||||||
pos = list_entry( pos->member.prev, typeof( *pos ), member ) )
|
pos = list_entry( pos->member.prev, typeof( *pos ), member ) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -288,8 +265,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @head: the head of the list
|
* @head: the head of the list
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_prepare_entry(pos, head, member) \
|
#define list_prepare_entry( pos, head, member ) ( ( pos ) ?: list_entry( head, typeof( *pos ), member ) )
|
||||||
((pos) ? : list_entry(head, typeof(*pos), member))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_entry_continue - iterate over list of given type
|
* list_for_each_entry_continue - iterate over list of given type
|
||||||
|
@ -299,8 +275,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_continue( pos, head, member ) \
|
#define list_for_each_entry_continue( pos, head, member ) \
|
||||||
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
|
for ( pos = list_entry( pos->member.next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
|
||||||
prefetch(pos->member.next), &pos->member != (head); \
|
|
||||||
pos = list_entry( pos->member.next, typeof( *pos ), member ) )
|
pos = list_entry( pos->member.next, typeof( *pos ), member ) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,10 +286,8 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_safe( pos, n, head, member ) \
|
#define list_for_each_entry_safe( pos, n, head, member ) \
|
||||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
for ( pos = list_entry( ( head )->next, typeof( *pos ), member ), n = list_entry( pos->member.next, typeof( *pos ), member ); \
|
||||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
&pos->member != ( head ); pos = n, n = list_entry( n->member.next, typeof( *n ), member ) )
|
||||||
&pos->member != (head); \
|
|
||||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry.
|
* list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against removal of list entry.
|
||||||
|
@ -324,10 +297,8 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* @member: the name of the list_struct within the struct.
|
* @member: the name of the list_struct within the struct.
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_safe_reverse( pos, n, head, member ) \
|
#define list_for_each_entry_safe_reverse( pos, n, head, member ) \
|
||||||
for (pos = list_entry((head)->prev, typeof(*pos), member), \
|
for ( pos = list_entry( ( head )->prev, typeof( *pos ), member ), n = list_entry( pos->member.prev, typeof( *pos ), member ); \
|
||||||
n = list_entry(pos->member.prev, typeof(*pos), member); \
|
prefetch( pos->member.prev ), &pos->member != ( head ); pos = n, n = list_entry( n->member.prev, typeof( *n ), member ) )
|
||||||
prefetch(pos->member.prev), &pos->member != (head); \
|
|
||||||
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_rcu - iterate over an rcu-protected list
|
* list_for_each_rcu - iterate over an rcu-protected list
|
||||||
|
@ -339,12 +310,9 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* as long as the traversal is guarded by rcu_read_lock().
|
* as long as the traversal is guarded by rcu_read_lock().
|
||||||
*/
|
*/
|
||||||
#define list_for_each_rcu( pos, head ) \
|
#define list_for_each_rcu( pos, head ) \
|
||||||
for (pos = (head)->next; prefetch(pos->next), pos != (head); \
|
for ( pos = ( head )->next; prefetch( pos->next ), pos != ( head ); pos = rcu_dereference( pos->next ) )
|
||||||
pos = rcu_dereference(pos->next))
|
|
||||||
|
|
||||||
#define __list_for_each_rcu(pos, head) \
|
#define __list_for_each_rcu( pos, head ) for ( pos = ( head )->next; pos != ( head ); pos = rcu_dereference( pos->next ) )
|
||||||
for (pos = (head)->next; pos != (head); \
|
|
||||||
pos = rcu_dereference(pos->next))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_safe_rcu - iterate over an rcu-protected list safe
|
* list_for_each_safe_rcu - iterate over an rcu-protected list safe
|
||||||
|
@ -358,8 +326,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* as long as the traversal is guarded by rcu_read_lock().
|
* as long as the traversal is guarded by rcu_read_lock().
|
||||||
*/
|
*/
|
||||||
#define list_for_each_safe_rcu( pos, n, head ) \
|
#define list_for_each_safe_rcu( pos, n, head ) \
|
||||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
for ( pos = ( head )->next, n = pos->next; pos != ( head ); pos = rcu_dereference( n ), n = pos->next )
|
||||||
pos = rcu_dereference(n), n = pos->next)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_entry_rcu - iterate over rcu list of given type
|
* list_for_each_entry_rcu - iterate over rcu list of given type
|
||||||
|
@ -372,11 +339,8 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* as long as the traversal is guarded by rcu_read_lock().
|
* as long as the traversal is guarded by rcu_read_lock().
|
||||||
*/
|
*/
|
||||||
#define list_for_each_entry_rcu( pos, head, member ) \
|
#define list_for_each_entry_rcu( pos, head, member ) \
|
||||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
for ( pos = list_entry( ( head )->next, typeof( *pos ), member ); prefetch( pos->member.next ), &pos->member != ( head ); \
|
||||||
prefetch(pos->member.next), &pos->member != (head); \
|
pos = rcu_dereference( list_entry( pos->member.next, typeof( *pos ), member ) ) )
|
||||||
pos = rcu_dereference(list_entry(pos->member.next, \
|
|
||||||
typeof(*pos), member)))
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list_for_each_continue_rcu - iterate over an rcu-protected list
|
* list_for_each_continue_rcu - iterate over an rcu-protected list
|
||||||
|
@ -389,8 +353,7 @@ static inline void list_splice_init(struct list_head *list,
|
||||||
* as long as the traversal is guarded by rcu_read_lock().
|
* as long as the traversal is guarded by rcu_read_lock().
|
||||||
*/
|
*/
|
||||||
#define list_for_each_continue_rcu( pos, head ) \
|
#define list_for_each_continue_rcu( pos, head ) \
|
||||||
for ((pos) = (pos)->next; prefetch((pos)->next), (pos) != (head); \
|
for ( ( pos ) = ( pos )->next; prefetch( ( pos )->next ), ( pos ) != ( head ); ( pos ) = rcu_dereference( ( pos )->next ) )
|
||||||
(pos) = rcu_dereference((pos)->next))
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Double linked lists with a single pointer list head.
|
* Double linked lists with a single pointer list head.
|
||||||
|
@ -412,15 +375,9 @@ struct hlist_node {
|
||||||
#define INIT_HLIST_HEAD( ptr ) ( ( ptr )->first = NULL )
|
#define INIT_HLIST_HEAD( ptr ) ( ( ptr )->first = NULL )
|
||||||
#define INIT_HLIST_NODE( ptr ) ( ( ptr )->next = NULL, ( ptr )->pprev = NULL )
|
#define INIT_HLIST_NODE( ptr ) ( ( ptr )->next = NULL, ( ptr )->pprev = NULL )
|
||||||
|
|
||||||
static inline int hlist_unhashed(const struct hlist_node *h)
|
static inline int hlist_unhashed( const struct hlist_node* h ) { return !h->pprev; }
|
||||||
{
|
|
||||||
return !h->pprev;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int hlist_empty(const struct hlist_head *h)
|
static inline int hlist_empty( const struct hlist_head* h ) { return !h->first; }
|
||||||
{
|
|
||||||
return !h->first;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void __hlist_del( struct hlist_node* n )
|
static inline void __hlist_del( struct hlist_node* n )
|
||||||
{
|
{
|
||||||
|
@ -482,8 +439,7 @@ static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* next must be != NULL */
|
/* next must be != NULL */
|
||||||
static inline void hlist_add_before(struct hlist_node *n,
|
static inline void hlist_add_before( struct hlist_node* n, struct hlist_node* next )
|
||||||
struct hlist_node *next)
|
|
||||||
{
|
{
|
||||||
n->pprev = next->pprev;
|
n->pprev = next->pprev;
|
||||||
n->next = next;
|
n->next = next;
|
||||||
|
@ -491,8 +447,7 @@ static inline void hlist_add_before(struct hlist_node *n,
|
||||||
*( n->pprev ) = n;
|
*( n->pprev ) = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void hlist_add_after(struct hlist_node *n,
|
static inline void hlist_add_after( struct hlist_node* n, struct hlist_node* next )
|
||||||
struct hlist_node *next)
|
|
||||||
{
|
{
|
||||||
next->next = n->next;
|
next->next = n->next;
|
||||||
n->next = next;
|
n->next = next;
|
||||||
|
@ -505,15 +460,24 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
#define hlist_entry( ptr, type, member ) container_of( ptr, type, member )
|
#define hlist_entry( ptr, type, member ) container_of( ptr, type, member )
|
||||||
|
|
||||||
#define hlist_for_each( pos, head ) \
|
#define hlist_for_each( pos, head ) \
|
||||||
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
|
for ( pos = ( head )->first; pos && ( { \
|
||||||
|
prefetch( pos->next ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = pos->next )
|
pos = pos->next )
|
||||||
|
|
||||||
#define hlist_for_each_safe( pos, n, head ) \
|
#define hlist_for_each_safe( pos, n, head ) \
|
||||||
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
for ( pos = ( head )->first; pos && ( { \
|
||||||
|
n = pos->next; \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = n )
|
pos = n )
|
||||||
|
|
||||||
#define hlist_for_each_rcu( pos, head ) \
|
#define hlist_for_each_rcu( pos, head ) \
|
||||||
for ((pos) = (head)->first; pos && ({ prefetch((pos)->next); 1; }); \
|
for ( ( pos ) = ( head )->first; pos && ( { \
|
||||||
|
prefetch( ( pos )->next ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
( pos ) = rcu_dereference( ( pos )->next ) )
|
( pos ) = rcu_dereference( ( pos )->next ) )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -524,9 +488,14 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
* @member: the name of the hlist_node within the struct.
|
* @member: the name of the hlist_node within the struct.
|
||||||
*/
|
*/
|
||||||
#define hlist_for_each_entry( tpos, pos, head, member ) \
|
#define hlist_for_each_entry( tpos, pos, head, member ) \
|
||||||
for (pos = (head)->first; \
|
for ( pos = ( head )->first; pos && ( { \
|
||||||
pos && ({ prefetch(pos->next); 1;}) && \
|
prefetch( pos->next ); \
|
||||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
1; \
|
||||||
|
} ) && \
|
||||||
|
( { \
|
||||||
|
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = pos->next )
|
pos = pos->next )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -536,9 +505,14 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
* @member: the name of the hlist_node within the struct.
|
* @member: the name of the hlist_node within the struct.
|
||||||
*/
|
*/
|
||||||
#define hlist_for_each_entry_continue( tpos, pos, member ) \
|
#define hlist_for_each_entry_continue( tpos, pos, member ) \
|
||||||
for (pos = (pos)->next; \
|
for ( pos = ( pos )->next; pos && ( { \
|
||||||
pos && ({ prefetch(pos->next); 1;}) && \
|
prefetch( pos->next ); \
|
||||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
1; \
|
||||||
|
} ) && \
|
||||||
|
( { \
|
||||||
|
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = pos->next )
|
pos = pos->next )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -548,8 +522,14 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
* @member: the name of the hlist_node within the struct.
|
* @member: the name of the hlist_node within the struct.
|
||||||
*/
|
*/
|
||||||
#define hlist_for_each_entry_from( tpos, pos, member ) \
|
#define hlist_for_each_entry_from( tpos, pos, member ) \
|
||||||
for (; pos && ({ prefetch(pos->next); 1;}) && \
|
for ( ; pos && ( { \
|
||||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
prefetch( pos->next ); \
|
||||||
|
1; \
|
||||||
|
} ) && \
|
||||||
|
( { \
|
||||||
|
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = pos->next )
|
pos = pos->next )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -561,9 +541,14 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
* @member: the name of the hlist_node within the struct.
|
* @member: the name of the hlist_node within the struct.
|
||||||
*/
|
*/
|
||||||
#define hlist_for_each_entry_safe( tpos, pos, n, head, member ) \
|
#define hlist_for_each_entry_safe( tpos, pos, n, head, member ) \
|
||||||
for (pos = (head)->first; \
|
for ( pos = ( head )->first; pos && ( { \
|
||||||
pos && ({ n = pos->next; 1; }) && \
|
n = pos->next; \
|
||||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
1; \
|
||||||
|
} ) && \
|
||||||
|
( { \
|
||||||
|
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = n )
|
pos = n )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -578,9 +563,14 @@ static inline void hlist_add_after(struct hlist_node *n,
|
||||||
* as long as the traversal is guarded by rcu_read_lock().
|
* as long as the traversal is guarded by rcu_read_lock().
|
||||||
*/
|
*/
|
||||||
#define hlist_for_each_entry_rcu( tpos, pos, head, member ) \
|
#define hlist_for_each_entry_rcu( tpos, pos, head, member ) \
|
||||||
for (pos = (head)->first; \
|
for ( pos = ( head )->first; pos && ( { \
|
||||||
pos && ({ prefetch(pos->next); 1;}) && \
|
prefetch( pos->next ); \
|
||||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
1; \
|
||||||
|
} ) && \
|
||||||
|
( { \
|
||||||
|
tpos = hlist_entry( pos, typeof( *tpos ), member ); \
|
||||||
|
1; \
|
||||||
|
} ); \
|
||||||
pos = rcu_dereference( pos->next ) )
|
pos = rcu_dereference( pos->next ) )
|
||||||
|
|
||||||
#endif /* _LINUX_LIST_H */
|
#endif /* _LINUX_LIST_H */
|
||||||
|
|
229
src/main.c
229
src/main.c
|
@ -66,7 +66,6 @@ void *qemu_memalign(size_t alignment, size_t size)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void qemu_init_vcpu( void* _env )
|
void qemu_init_vcpu( void* _env )
|
||||||
{
|
{
|
||||||
CPUState* env = _env;
|
CPUState* env = _env;
|
||||||
|
@ -75,36 +74,17 @@ void qemu_init_vcpu(void *_env)
|
||||||
env->nr_threads = 1;
|
env->nr_threads = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemu_cpu_self(void *env)
|
int qemu_cpu_self( void* env ) { return 1; }
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void qemu_cpu_kick(void *env)
|
void qemu_cpu_kick( void* env ) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void armv7m_nvic_set_pending(void *opaque, int irq)
|
void armv7m_nvic_set_pending( void* opaque, int irq ) { abort(); }
|
||||||
{
|
int armv7m_nvic_acknowledge_irq( void* opaque ) { abort(); }
|
||||||
abort();
|
void armv7m_nvic_complete_irq( void* opaque, int irq ) { abort(); }
|
||||||
}
|
|
||||||
int armv7m_nvic_acknowledge_irq(void *opaque)
|
|
||||||
{
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
void armv7m_nvic_complete_irq(void *opaque, int irq)
|
|
||||||
{
|
|
||||||
abort();
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void* qemu_malloc( size_t size ) { return malloc( size ); }
|
||||||
qemu_malloc(size_t size)
|
|
||||||
{
|
|
||||||
return malloc(size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void* qemu_mallocz( size_t size )
|
||||||
qemu_mallocz(size_t size)
|
|
||||||
{
|
{
|
||||||
void* ptr;
|
void* ptr;
|
||||||
|
|
||||||
|
@ -115,14 +95,9 @@ qemu_mallocz(size_t size)
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void qemu_free( void* ptr ) { free( ptr ); }
|
||||||
qemu_free(void *ptr)
|
|
||||||
{
|
|
||||||
free(ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *
|
void* qemu_vmalloc( size_t size )
|
||||||
qemu_vmalloc(size_t size)
|
|
||||||
{
|
{
|
||||||
#if defined( __linux__ )
|
#if defined( __linux__ )
|
||||||
void* mem;
|
void* mem;
|
||||||
|
@ -136,8 +111,7 @@ qemu_vmalloc(size_t size)
|
||||||
|
|
||||||
#define SWI_Breakpoint 0x180000
|
#define SWI_Breakpoint 0x180000
|
||||||
|
|
||||||
uint32_t
|
uint32_t do_arm_semihosting( CPUState* env )
|
||||||
do_arm_semihosting(CPUState *env)
|
|
||||||
{
|
{
|
||||||
uint32_t number;
|
uint32_t number;
|
||||||
if ( env->thumb ) {
|
if ( env->thumb ) {
|
||||||
|
@ -151,18 +125,15 @@ do_arm_semihosting(CPUState *env)
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
#ifdef DEBUG_X49GP_SYSCALL
|
#ifdef DEBUG_X49GP_SYSCALL
|
||||||
printf("%s: SWI LR %08x: syscall %u: args %08x %08x %08x %08x %08x %08x %08x\n",
|
printf( "%s: SWI LR %08x: syscall %u: args %08x %08x %08x %08x %08x %08x %08x\n", __FUNCTION__, env->regs[ 14 ], env->regs[ 0 ],
|
||||||
__FUNCTION__, env->regs[14], env->regs[0],
|
env->regs[ 1 ], env->regs[ 2 ], env->regs[ 3 ], env->regs[ 4 ], env->regs[ 5 ], env->regs[ 6 ], env->regs[ 7 ] );
|
||||||
env->regs[1], env->regs[2], env->regs[3],
|
|
||||||
env->regs[4], env->regs[5], env->regs[6],
|
|
||||||
env->regs[7]);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
switch ( env->regs[ 0 ] ) {
|
switch ( env->regs[ 0 ] ) {
|
||||||
case 305: /* Beep */
|
case 305: /* Beep */
|
||||||
printf("%s: BEEP: frequency %u, time %u, override %u\n",
|
printf( "%s: BEEP: frequency %u, time %u, override %u\n", __FUNCTION__, env->regs[ 1 ], env->regs[ 2 ],
|
||||||
__FUNCTION__, env->regs[1], env->regs[2], env->regs[3]);
|
env->regs[ 3 ] );
|
||||||
|
|
||||||
gdk_beep();
|
gdk_beep();
|
||||||
env->regs[ 0 ] = 0;
|
env->regs[ 0 ] = 0;
|
||||||
|
@ -189,8 +160,7 @@ do_arm_semihosting(CPUState *env)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_set_idle( x49gp_t* x49gp, x49gp_arm_idle_t idle )
|
||||||
x49gp_set_idle(x49gp_t *x49gp, x49gp_arm_idle_t idle)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_ARM_IDLE
|
#ifdef DEBUG_X49GP_ARM_IDLE
|
||||||
if ( idle != x49gp->arm_idle ) {
|
if ( idle != x49gp->arm_idle ) {
|
||||||
|
@ -208,8 +178,7 @@ x49gp_set_idle(x49gp_t *x49gp, x49gp_arm_idle_t idle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void arm_sighnd( int sig )
|
||||||
arm_sighnd(int sig)
|
|
||||||
{
|
{
|
||||||
switch ( sig ) {
|
switch ( sig ) {
|
||||||
case SIGUSR1:
|
case SIGUSR1:
|
||||||
|
@ -222,20 +191,17 @@ arm_sighnd(int sig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_gtk_timer( void* data )
|
||||||
x49gp_gtk_timer(void *data)
|
|
||||||
{
|
{
|
||||||
while ( gtk_events_pending() ) {
|
while ( gtk_events_pending() ) {
|
||||||
// printf("%s: gtk_main_iteration_do()\n", __FUNCTION__);
|
// printf("%s: gtk_main_iteration_do()\n", __FUNCTION__);
|
||||||
gtk_main_iteration_do( FALSE );
|
gtk_main_iteration_do( FALSE );
|
||||||
}
|
}
|
||||||
|
|
||||||
x49gp_mod_timer(x49gp->gtk_timer,
|
x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL );
|
||||||
x49gp_get_clock() + X49GP_GTK_REFRESH_INTERVAL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_lcd_timer( void* data )
|
||||||
x49gp_lcd_timer(void *data)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = data;
|
x49gp_t* x49gp = data;
|
||||||
int64_t now, expires;
|
int64_t now, expires;
|
||||||
|
@ -263,8 +229,7 @@ struct options {
|
||||||
|
|
||||||
struct option_def;
|
struct option_def;
|
||||||
|
|
||||||
typedef int (*option_action)(struct options *opt, struct option_def *match,
|
typedef int ( *option_action )( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
char *this_opt, char *param, char *progname);
|
|
||||||
|
|
||||||
struct option_def {
|
struct option_def {
|
||||||
option_action action;
|
option_action action;
|
||||||
|
@ -272,27 +237,16 @@ struct option_def {
|
||||||
char shortname;
|
char shortname;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int action_help(struct options *opt, struct option_def *match,
|
static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
char *this_opt, char *param, char *progname);
|
static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
static int action_debuglater(struct options *opt, struct option_def *match,
|
static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
char *this_opt, char *param, char *progname);
|
static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
static int action_debug(struct options *opt, struct option_def *match,
|
static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
char *this_opt, char *param, char *progname);
|
static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
static int action_reinit_flash(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname);
|
|
||||||
static int action_reinit_flash_full(struct options *opt,
|
|
||||||
struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname);
|
|
||||||
static int action_reboot(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname);
|
|
||||||
|
|
||||||
static int action_unknown_with_param(struct options *opt,
|
static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
struct option_def *match, char *this_opt,
|
static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
char *param, char *progname);
|
static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname );
|
||||||
static int action_longopt(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname);
|
|
||||||
static int action_endopt(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname);
|
|
||||||
|
|
||||||
struct option_def option_defs[] = {
|
struct option_def option_defs[] = {
|
||||||
{action_help, "help", 'h' },
|
{action_help, "help", 'h' },
|
||||||
|
@ -307,25 +261,24 @@ struct option_def option_defs[] = {
|
||||||
{action_endopt, "", '\0'}
|
{action_endopt, "", '\0'}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void warn_unneeded_param( struct option_def* match, char* this_opt )
|
||||||
warn_unneeded_param(struct option_def *match, char *this_opt)
|
|
||||||
{
|
{
|
||||||
if ( this_opt[ 1 ] == '-' ) {
|
if ( this_opt[ 1 ] == '-' ) {
|
||||||
fprintf(stderr, "The option \"--%s\" does not support"
|
fprintf( stderr,
|
||||||
" parameters\n", match->longname);
|
"The option \"--%s\" does not support"
|
||||||
|
" parameters\n",
|
||||||
|
match->longname );
|
||||||
} else
|
} else
|
||||||
fprintf(stderr, "The option '-%c' does not support parameters\n",
|
fprintf( stderr, "The option '-%c' does not support parameters\n", match->shortname );
|
||||||
match->shortname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_help( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_help(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
if ( param != NULL )
|
if ( param != NULL )
|
||||||
warn_unneeded_param( match, this_opt );
|
warn_unneeded_param( match, this_opt );
|
||||||
|
|
||||||
fprintf(stderr, "Emulator for HP 49G+ / 50G calculators\n"
|
fprintf( stderr,
|
||||||
|
"Emulator for HP 49G+ / 50G calculators\n"
|
||||||
"Usage: %s [<options>] [<config-file>]\n"
|
"Usage: %s [<options>] [<config-file>]\n"
|
||||||
"Valid options:\n"
|
"Valid options:\n"
|
||||||
" -D, --enable-debug[=<port] enable the debugger interface\n"
|
" -D, --enable-debug[=<port] enable the debugger interface\n"
|
||||||
|
@ -353,13 +306,12 @@ action_help(struct options *opt, struct option_def *match, char *this_opt,
|
||||||
" registers, etc.\n"
|
" registers, etc.\n"
|
||||||
"If the config file is omitted, ~/.%s/config is used.\n"
|
"If the config file is omitted, ~/.%s/config is used.\n"
|
||||||
"Please consult the manual for more details on config file"
|
"Please consult the manual for more details on config file"
|
||||||
" settings.\n", progname, DEFAULT_GDBSTUB_PORT, progname);
|
" settings.\n",
|
||||||
|
progname, DEFAULT_GDBSTUB_PORT, progname );
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_debuglater( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_debuglater(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
char* end;
|
char* end;
|
||||||
int port;
|
int port;
|
||||||
|
@ -379,23 +331,21 @@ action_debuglater(struct options *opt, struct option_def *match, char *this_opt,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( opt->debug_port != 0 && opt->debug_port != DEFAULT_GDBSTUB_PORT )
|
if ( opt->debug_port != 0 && opt->debug_port != DEFAULT_GDBSTUB_PORT )
|
||||||
fprintf(stderr, "Additional debug port \"%s\" specified,"
|
fprintf( stderr,
|
||||||
" overriding\n", param);
|
"Additional debug port \"%s\" specified,"
|
||||||
|
" overriding\n",
|
||||||
|
param );
|
||||||
opt->debug_port = port;
|
opt->debug_port = port;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_debug( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_debug(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
opt->start_debugger = TRUE;
|
opt->start_debugger = TRUE;
|
||||||
return action_debuglater( opt, match, this_opt, param, progname );
|
return action_debuglater( opt, match, this_opt, param, progname );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_reinit_flash( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_reinit_flash(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
if ( opt->reinit < X49GP_REINIT_FLASH )
|
if ( opt->reinit < X49GP_REINIT_FLASH )
|
||||||
opt->reinit = X49GP_REINIT_FLASH;
|
opt->reinit = X49GP_REINIT_FLASH;
|
||||||
|
@ -404,25 +354,22 @@ action_reinit_flash(struct options *opt, struct option_def *match,
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if ( opt->firmware != NULL )
|
if ( opt->firmware != NULL )
|
||||||
fprintf(stderr, "Additional firmware file \"%s\" specified,"
|
fprintf( stderr,
|
||||||
" overriding\n", param);
|
"Additional firmware file \"%s\" specified,"
|
||||||
|
" overriding\n",
|
||||||
|
param );
|
||||||
opt->firmware = param;
|
opt->firmware = param;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_reinit_flash_full( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_reinit_flash_full(struct options *opt,
|
|
||||||
struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
int result = action_reinit_flash( opt, match, this_opt, param, progname );
|
int result = action_reinit_flash( opt, match, this_opt, param, progname );
|
||||||
opt->reinit = X49GP_REINIT_FLASH_FULL;
|
opt->reinit = X49GP_REINIT_FLASH_FULL;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_reboot( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_reboot(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
if ( param != NULL )
|
if ( param != NULL )
|
||||||
warn_unneeded_param( match, this_opt );
|
warn_unneeded_param( match, this_opt );
|
||||||
|
@ -432,9 +379,7 @@ action_reboot(struct options *opt, struct option_def *match, char *this_opt,
|
||||||
return param != NULL;
|
return param != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_longopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_longopt(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *test_str, *option_str;
|
char *test_str, *option_str;
|
||||||
|
@ -456,16 +401,15 @@ action_longopt(struct options *opt, struct option_def *match, char *this_opt,
|
||||||
option_str++;
|
option_str++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*test_str != '\0') continue;
|
if ( *test_str != '\0' )
|
||||||
|
continue;
|
||||||
|
|
||||||
switch ( *option_str ) {
|
switch ( *option_str ) {
|
||||||
case '\0':
|
case '\0':
|
||||||
(option_defs[i].action)(opt, option_defs + i, this_opt,
|
( option_defs[ i ].action )( opt, option_defs + i, this_opt, NULL, progname );
|
||||||
NULL, progname);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
case '=':
|
case '=':
|
||||||
(option_defs[i].action)(opt, option_defs + i, this_opt,
|
( option_defs[ i ].action )( opt, option_defs + i, this_opt, option_str + 1, progname );
|
||||||
option_str+1, progname);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,37 +418,30 @@ action_longopt(struct options *opt, struct option_def *match, char *this_opt,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_unknown_with_param( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_unknown_with_param(struct options *opt, struct option_def *match,
|
|
||||||
char *this_opt, char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int action_endopt( struct options* opt, struct option_def* match, char* this_opt, char* param, char* progname )
|
||||||
action_endopt(struct options *opt, struct option_def *match, char *this_opt,
|
|
||||||
char *param, char *progname)
|
|
||||||
{
|
{
|
||||||
opt->more_options = FALSE;
|
opt->more_options = FALSE;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void parse_shortopt( struct options* opt, char* this_opt, char* progname )
|
||||||
parse_shortopt(struct options *opt, char *this_opt, char *progname)
|
|
||||||
{
|
{
|
||||||
char* option = this_opt + 1;
|
char* option = this_opt + 1;
|
||||||
char* param;
|
char* param;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if ( *option == '\0' ) {
|
if ( *option == '\0' ) {
|
||||||
fprintf(stderr,
|
fprintf( stderr, "Empty option present, ignoring\n" );
|
||||||
"Empty option present, ignoring\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
for (i = 0; i < sizeof(option_defs) / sizeof(option_defs[0]);
|
for ( i = 0; i < sizeof( option_defs ) / sizeof( option_defs[ 0 ] ); i++ ) {
|
||||||
i++) {
|
|
||||||
|
|
||||||
if ( *option == option_defs[ i ].shortname ) {
|
if ( *option == option_defs[ i ].shortname ) {
|
||||||
if ( *( option + 1 ) == '=' ) {
|
if ( *( option + 1 ) == '=' ) {
|
||||||
|
@ -513,25 +450,19 @@ parse_shortopt(struct options *opt, char *this_opt, char *progname)
|
||||||
param = NULL;
|
param = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((option_defs[i].action)(opt, option_defs + i,
|
if ( ( option_defs[ i ].action )( opt, option_defs + i, this_opt, param, progname ) )
|
||||||
this_opt, param,
|
|
||||||
progname))
|
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( i == sizeof( option_defs ) / sizeof( option_defs[ 0 ] ) )
|
if ( i == sizeof( option_defs ) / sizeof( option_defs[ 0 ] ) )
|
||||||
fprintf(stderr,
|
fprintf( stderr, "Unrecognized option '%c', ignoring\n", *option );
|
||||||
"Unrecognized option '%c', ignoring\n",
|
|
||||||
*option);
|
|
||||||
option++;
|
option++;
|
||||||
} while ( *option != '\0' );
|
} while ( *option != '\0' );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void parse_options( struct options* opt, int argc, char** argv, char* progname )
|
||||||
parse_options(struct options *opt, int argc, char **argv, char *progname)
|
|
||||||
{
|
{
|
||||||
opt->more_options = TRUE;
|
opt->more_options = TRUE;
|
||||||
|
|
||||||
|
@ -561,11 +492,9 @@ parse_options(struct options *opt, int argc, char **argv, char *progname)
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void ui_sighnd( int sig )
|
||||||
ui_sighnd(int sig)
|
|
||||||
{
|
{
|
||||||
switch ( sig ) {
|
switch ( sig ) {
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
|
@ -577,22 +506,18 @@ ui_sighnd(int sig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int main( int argc, char** argv )
|
||||||
main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
char *progname, *progpath;
|
char *progname, *progpath;
|
||||||
int error;
|
int error;
|
||||||
struct options opt;
|
struct options opt;
|
||||||
const char* home;
|
const char* home;
|
||||||
|
|
||||||
|
|
||||||
progname = g_path_get_basename( argv[ 0 ] );
|
progname = g_path_get_basename( argv[ 0 ] );
|
||||||
progpath = g_path_get_dirname( argv[ 0 ] );
|
progpath = g_path_get_dirname( argv[ 0 ] );
|
||||||
|
|
||||||
|
|
||||||
gtk_init( &argc, &argv );
|
gtk_init( &argc, &argv );
|
||||||
|
|
||||||
|
|
||||||
opt.config = NULL;
|
opt.config = NULL;
|
||||||
opt.debug_port = 0;
|
opt.debug_port = 0;
|
||||||
opt.start_debugger = FALSE;
|
opt.start_debugger = FALSE;
|
||||||
|
@ -602,8 +527,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
x49gp = malloc( sizeof( x49gp_t ) );
|
x49gp = malloc( sizeof( x49gp_t ) );
|
||||||
if ( NULL == x49gp ) {
|
if ( NULL == x49gp ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", progname, __FUNCTION__, __LINE__ );
|
||||||
progname, __FUNCTION__, __LINE__);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
memset( x49gp, 0, sizeof( x49gp_t ) );
|
memset( x49gp, 0, sizeof( x49gp_t ) );
|
||||||
|
@ -616,7 +540,6 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
INIT_LIST_HEAD( &x49gp->modules );
|
INIT_LIST_HEAD( &x49gp->modules );
|
||||||
|
|
||||||
|
|
||||||
x49gp->progname = progname;
|
x49gp->progname = progname;
|
||||||
x49gp->progpath = progpath;
|
x49gp->progpath = progpath;
|
||||||
x49gp->clk_tck = sysconf( _SC_CLK_TCK );
|
x49gp->clk_tck = sysconf( _SC_CLK_TCK );
|
||||||
|
@ -634,10 +557,8 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
x49gp_timer_init( x49gp );
|
x49gp_timer_init( x49gp );
|
||||||
|
|
||||||
x49gp->gtk_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
|
x49gp->gtk_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, x49gp_gtk_timer, x49gp );
|
||||||
x49gp_gtk_timer, x49gp);
|
x49gp->lcd_timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, x49gp_lcd_timer, x49gp );
|
||||||
x49gp->lcd_timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL,
|
|
||||||
x49gp_lcd_timer, x49gp);
|
|
||||||
|
|
||||||
x49gp_ui_init( x49gp );
|
x49gp_ui_init( x49gp );
|
||||||
|
|
||||||
|
@ -657,8 +578,7 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
home = g_get_home_dir();
|
home = g_get_home_dir();
|
||||||
sprintf( config_dir, ".config/%s", progname );
|
sprintf( config_dir, ".config/%s", progname );
|
||||||
opt.config = g_build_filename(home, config_dir,
|
opt.config = g_build_filename( home, config_dir, "config", NULL );
|
||||||
"config", NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x49gp->basename = g_path_get_dirname( opt.config );
|
x49gp->basename = g_path_get_dirname( opt.config );
|
||||||
|
@ -681,16 +601,13 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
signal( SIGUSR1, arm_sighnd );
|
signal( SIGUSR1, arm_sighnd );
|
||||||
|
|
||||||
|
|
||||||
x49gp_set_idle( x49gp, 0 );
|
x49gp_set_idle( x49gp, 0 );
|
||||||
|
|
||||||
// stl_phys(0x08000a1c, 0x55555555);
|
// stl_phys(0x08000a1c, 0x55555555);
|
||||||
|
|
||||||
|
|
||||||
x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() );
|
x49gp_mod_timer( x49gp->gtk_timer, x49gp_get_clock() );
|
||||||
x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() );
|
x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() );
|
||||||
|
|
||||||
|
|
||||||
if ( opt.debug_port != 0 && opt.start_debugger ) {
|
if ( opt.debug_port != 0 && opt.start_debugger ) {
|
||||||
gdbserver_start( opt.debug_port );
|
gdbserver_start( opt.debug_port );
|
||||||
gdb_handlesig( x49gp->env, 0 );
|
gdb_handlesig( x49gp->env, 0 );
|
||||||
|
@ -698,11 +615,9 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
x49gp_main_loop( x49gp );
|
x49gp_main_loop( x49gp );
|
||||||
|
|
||||||
|
|
||||||
x49gp_modules_save( x49gp, opt.config );
|
x49gp_modules_save( x49gp, opt.config );
|
||||||
x49gp_modules_exit( x49gp );
|
x49gp_modules_exit( x49gp );
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
printf("ClkTicks: %lu\n", ARMul_Time(x49gp->arm));
|
printf("ClkTicks: %lu\n", ARMul_Time(x49gp->arm));
|
||||||
printf("D TLB: hit0 %lu, hit1 %lu, search %lu (%lu), walk %lu\n",
|
printf("D TLB: hit0 %lu, hit1 %lu, search %lu (%lu), walk %lu\n",
|
||||||
|
|
165
src/module.c
165
src/module.c
|
@ -11,8 +11,7 @@
|
||||||
|
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
|
|
||||||
int
|
int x49gp_modules_init( x49gp_t* x49gp )
|
||||||
x49gp_modules_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
int error;
|
int error;
|
||||||
|
@ -23,7 +22,8 @@ x49gp_modules_init(x49gp_t *x49gp)
|
||||||
|
|
||||||
phys_ram_size = 0;
|
phys_ram_size = 0;
|
||||||
|
|
||||||
list_for_each_entry(module, &x49gp->modules, list) {
|
list_for_each_entry( module, &x49gp->modules, list )
|
||||||
|
{
|
||||||
error = module->init( module );
|
error = module->init( module );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
return error;
|
return error;
|
||||||
|
@ -32,8 +32,7 @@ x49gp_modules_init(x49gp_t *x49gp)
|
||||||
|
|
||||||
phys_ram_base = mmap( 0, phys_ram_size, PROT_NONE, MAP_SHARED | MAP_ANON, -1, 0 );
|
phys_ram_base = mmap( 0, phys_ram_size, PROT_NONE, MAP_SHARED | MAP_ANON, -1, 0 );
|
||||||
if ( phys_ram_base == ( uint8_t* )-1 ) {
|
if ( phys_ram_base == ( uint8_t* )-1 ) {
|
||||||
fprintf(stderr, "%s: can't mmap %08x anonymous bytes\n",
|
fprintf( stderr, "%s: can't mmap %08x anonymous bytes\n", __FUNCTION__, phys_ram_size );
|
||||||
__FUNCTION__, phys_ram_size);
|
|
||||||
exit( 1 );
|
exit( 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +49,7 @@ x49gp_modules_init(x49gp_t *x49gp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_modules_exit( x49gp_t* x49gp )
|
||||||
x49gp_modules_exit(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t *module, *next;
|
x49gp_module_t *module, *next;
|
||||||
int error;
|
int error;
|
||||||
|
@ -60,7 +58,8 @@ x49gp_modules_exit(x49gp_t *x49gp)
|
||||||
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_for_each_entry_safe_reverse(module, next, &x49gp->modules, list) {
|
list_for_each_entry_safe_reverse( module, next, &x49gp->modules, list )
|
||||||
|
{
|
||||||
error = module->exit( module );
|
error = module->exit( module );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
return error;
|
return error;
|
||||||
|
@ -70,8 +69,7 @@ x49gp_modules_exit(x49gp_t *x49gp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_modules_reset( x49gp_t* x49gp, x49gp_reset_t reset )
|
||||||
x49gp_modules_reset(x49gp_t *x49gp, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
int error;
|
int error;
|
||||||
|
@ -80,7 +78,8 @@ x49gp_modules_reset(x49gp_t *x49gp, x49gp_reset_t reset)
|
||||||
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_for_each_entry(module, &x49gp->modules, list) {
|
list_for_each_entry( module, &x49gp->modules, list )
|
||||||
|
{
|
||||||
error = module->reset( module, reset );
|
error = module->reset( module, reset );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
return error;
|
return error;
|
||||||
|
@ -90,8 +89,7 @@ x49gp_modules_reset(x49gp_t *x49gp, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_modules_load( x49gp_t* x49gp, const char* filename )
|
||||||
x49gp_modules_load(x49gp_t *x49gp, const char *filename)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
GError* gerror = NULL;
|
GError* gerror = NULL;
|
||||||
|
@ -103,30 +101,27 @@ x49gp_modules_load(x49gp_t *x49gp, const char *filename)
|
||||||
|
|
||||||
if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) {
|
if ( g_mkdir_with_parents( x49gp->basename, 0755 ) ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s:%u: g_mkdir_with_parents: %s\n",
|
fprintf( stderr, "%s:%u: g_mkdir_with_parents: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
x49gp->config = g_key_file_new();
|
x49gp->config = g_key_file_new();
|
||||||
if ( NULL == x49gp->config ) {
|
if ( NULL == x49gp->config ) {
|
||||||
fprintf(stderr, "%s:%u: g_key_file_new: Out of memory\n",
|
fprintf( stderr, "%s:%u: g_key_file_new: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! g_key_file_load_from_file(x49gp->config, filename,
|
if ( !g_key_file_load_from_file( x49gp->config, filename, G_KEY_FILE_KEEP_COMMENTS, &gerror ) &&
|
||||||
G_KEY_FILE_KEEP_COMMENTS, &gerror)
|
!g_error_matches( gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT ) ) {
|
||||||
&& ! g_error_matches(gerror, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
|
fprintf( stderr, "%s:%u: g_key_file_load_from_file: %s\n", __FUNCTION__, __LINE__, gerror->message );
|
||||||
fprintf(stderr, "%s:%u: g_key_file_load_from_file: %s\n",
|
|
||||||
__FUNCTION__, __LINE__, gerror->message);
|
|
||||||
g_key_file_free( x49gp->config );
|
g_key_file_free( x49gp->config );
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
list_for_each_entry(module, &x49gp->modules, list) {
|
list_for_each_entry( module, &x49gp->modules, list )
|
||||||
|
{
|
||||||
error = module->load( module, x49gp->config );
|
error = module->load( module, x49gp->config );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
if ( error == -EAGAIN ) {
|
if ( error == -EAGAIN ) {
|
||||||
|
@ -142,23 +137,15 @@ x49gp_modules_load(x49gp_t *x49gp, const char *filename)
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_MODULES
|
#ifdef DEBUG_X49GP_MODULES
|
||||||
printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base );
|
printf( "%s: phys_ram_base: %p\n", __FUNCTION__, phys_ram_base );
|
||||||
printf("\t%02x %02x %02x %02x %02x %02x %02x %02x\n",
|
printf( "\t%02x %02x %02x %02x %02x %02x %02x %02x\n", phys_ram_base[ 0 ], phys_ram_base[ 1 ], phys_ram_base[ 2 ],
|
||||||
phys_ram_base[0],
|
phys_ram_base[ 3 ], phys_ram_base[ 4 ], phys_ram_base[ 5 ], phys_ram_base[ 6 ], phys_ram_base[ 7 ] );
|
||||||
phys_ram_base[1],
|
|
||||||
phys_ram_base[2],
|
|
||||||
phys_ram_base[3],
|
|
||||||
phys_ram_base[4],
|
|
||||||
phys_ram_base[5],
|
|
||||||
phys_ram_base[6],
|
|
||||||
phys_ram_base[7]);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_modules_save( x49gp_t* x49gp, const char* filename )
|
||||||
x49gp_modules_save(x49gp_t *x49gp, const char *filename)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
GError* gerror = NULL;
|
GError* gerror = NULL;
|
||||||
|
@ -171,7 +158,8 @@ x49gp_modules_save(x49gp_t *x49gp, const char *filename)
|
||||||
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
printf( "%s:%u:\n", __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
list_for_each_entry(module, &x49gp->modules, list) {
|
list_for_each_entry( module, &x49gp->modules, list )
|
||||||
|
{
|
||||||
error = module->save( module, x49gp->config );
|
error = module->save( module, x49gp->config );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
return error;
|
return error;
|
||||||
|
@ -180,25 +168,21 @@ x49gp_modules_save(x49gp_t *x49gp, const char *filename)
|
||||||
|
|
||||||
data = g_key_file_to_data( x49gp->config, &length, &gerror );
|
data = g_key_file_to_data( x49gp->config, &length, &gerror );
|
||||||
if ( NULL == data ) {
|
if ( NULL == data ) {
|
||||||
fprintf(stderr, "%s:%u: g_key_file_to_data: %s\n",
|
fprintf( stderr, "%s:%u: g_key_file_to_data: %s\n", __FUNCTION__, __LINE__, gerror->message );
|
||||||
__FUNCTION__, __LINE__, gerror->message);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC, 0644 );
|
fd = open( filename, O_WRONLY | O_CREAT | O_TRUNC, 0644 );
|
||||||
if ( fd < 0 ) {
|
if ( fd < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s:%u: open %s: %s\n",
|
fprintf( stderr, "%s:%u: open %s: %s\n", __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, filename, strerror(errno));
|
|
||||||
g_free( data );
|
g_free( data );
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( write( fd, data, length ) != length ) {
|
if ( write( fd, data, length ) != length ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s:%u: write %s: %s\n",
|
fprintf( stderr, "%s:%u: write %s: %s\n", __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, filename, strerror(errno));
|
|
||||||
close( fd );
|
close( fd );
|
||||||
g_free( data );
|
g_free( data );
|
||||||
return error;
|
return error;
|
||||||
|
@ -210,8 +194,7 @@ x49gp_modules_save(x49gp_t *x49gp, const char *filename)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_register( x49gp_module_t* module )
|
||||||
x49gp_module_register(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
|
|
||||||
|
@ -224,8 +207,7 @@ x49gp_module_register(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_unregister( x49gp_module_t* module )
|
||||||
x49gp_module_unregister(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_MODULES
|
#ifdef DEBUG_X49GP_MODULES
|
||||||
printf( "%s:%u: %s\n", __FUNCTION__, __LINE__, module->name );
|
printf( "%s:%u: %s\n", __FUNCTION__, __LINE__, module->name );
|
||||||
|
@ -236,10 +218,7 @@ x49gp_module_unregister(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep, char** path )
|
||||||
x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, char *reset, char **valuep,
|
|
||||||
char **path)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
int error;
|
int error;
|
||||||
|
@ -253,8 +232,7 @@ x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *key,
|
||||||
|
|
||||||
*path = g_build_filename( x49gp->basename, *valuep, NULL );
|
*path = g_build_filename( x49gp->basename, *valuep, NULL );
|
||||||
if ( NULL == path ) {
|
if ( NULL == path ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
module->name, __FUNCTION__, __LINE__);
|
|
||||||
g_free( *valuep );
|
g_free( *valuep );
|
||||||
*valuep = NULL;
|
*valuep = NULL;
|
||||||
}
|
}
|
||||||
|
@ -262,24 +240,17 @@ x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *key,
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_set_filename( x49gp_module_t* module, GKeyFile* key, const char* name, const char* value )
|
||||||
x49gp_module_set_filename(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, const char *value)
|
|
||||||
{
|
{
|
||||||
return x49gp_module_set_string( module, key, name, value );
|
return x49gp_module_set_string( module, key, name, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_int( x49gp_module_t* module, GKeyFile* key, const char* name, int reset, int* valuep )
|
||||||
x49gp_module_get_int(x49gp_module_t *module, GKeyFile *key, const char *name,
|
|
||||||
int reset, int *valuep)
|
|
||||||
{
|
{
|
||||||
return x49gp_module_get_u32(module, key, name, reset,
|
return x49gp_module_get_u32( module, key, name, reset, ( uint32_t* )valuep );
|
||||||
(uint32_t *) valuep);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_set_int( x49gp_module_t* module, GKeyFile* key, const char* name, int value )
|
||||||
x49gp_module_set_int(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, int value)
|
|
||||||
{
|
{
|
||||||
char data[ 16 ];
|
char data[ 16 ];
|
||||||
|
|
||||||
|
@ -290,16 +261,12 @@ x49gp_module_set_int(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_uint( x49gp_module_t* module, GKeyFile* key, const char* name, unsigned int reset, unsigned int* valuep )
|
||||||
x49gp_module_get_uint(x49gp_module_t *module, GKeyFile *key, const char *name,
|
|
||||||
unsigned int reset, unsigned int *valuep)
|
|
||||||
{
|
{
|
||||||
return x49gp_module_get_u32( module, key, name, reset, valuep );
|
return x49gp_module_get_u32( module, key, name, reset, valuep );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_set_uint( x49gp_module_t* module, GKeyFile* key, const char* name, unsigned int value )
|
||||||
x49gp_module_set_uint(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, unsigned int value)
|
|
||||||
{
|
{
|
||||||
char data[ 16 ];
|
char data[ 16 ];
|
||||||
|
|
||||||
|
@ -310,9 +277,7 @@ x49gp_module_set_uint(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_u32( x49gp_module_t* module, GKeyFile* key, const char* name, uint32_t reset, uint32_t* valuep )
|
||||||
x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, uint32_t reset, uint32_t *valuep)
|
|
||||||
{
|
{
|
||||||
GError* gerror = NULL;
|
GError* gerror = NULL;
|
||||||
char *data, *end;
|
char *data, *end;
|
||||||
|
@ -320,8 +285,7 @@ x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *key,
|
||||||
|
|
||||||
data = g_key_file_get_value( key, module->name, name, &gerror );
|
data = g_key_file_get_value( key, module->name, name, &gerror );
|
||||||
if ( NULL == data ) {
|
if ( NULL == data ) {
|
||||||
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n",
|
fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
|
||||||
module->name, __FUNCTION__, __LINE__, name);
|
|
||||||
*valuep = reset;
|
*valuep = reset;
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
@ -339,9 +303,7 @@ x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_set_u32( x49gp_module_t* module, GKeyFile* key, const char* name, uint32_t value )
|
||||||
x49gp_module_set_u32(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, uint32_t value)
|
|
||||||
{
|
{
|
||||||
char data[ 16 ];
|
char data[ 16 ];
|
||||||
|
|
||||||
|
@ -352,9 +314,7 @@ x49gp_module_set_u32(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_set_u64( x49gp_module_t* module, GKeyFile* key, const char* name, uint64_t value )
|
||||||
x49gp_module_set_u64(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, uint64_t value)
|
|
||||||
{
|
{
|
||||||
char data[ 32 ];
|
char data[ 32 ];
|
||||||
|
|
||||||
|
@ -365,9 +325,7 @@ x49gp_module_set_u64(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_u64( x49gp_module_t* module, GKeyFile* key, const char* name, uint64_t reset, uint64_t* valuep )
|
||||||
x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, uint64_t reset, uint64_t *valuep)
|
|
||||||
{
|
{
|
||||||
GError* gerror = NULL;
|
GError* gerror = NULL;
|
||||||
char *data, *end;
|
char *data, *end;
|
||||||
|
@ -375,8 +333,7 @@ x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *key,
|
||||||
|
|
||||||
data = g_key_file_get_value( key, module->name, name, &gerror );
|
data = g_key_file_get_value( key, module->name, name, &gerror );
|
||||||
if ( NULL == data ) {
|
if ( NULL == data ) {
|
||||||
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n",
|
fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
|
||||||
module->name, __FUNCTION__, __LINE__, name);
|
|
||||||
*valuep = reset;
|
*valuep = reset;
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
@ -394,17 +351,14 @@ x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_get_string( x49gp_module_t* module, GKeyFile* key, const char* name, char* reset, char** valuep )
|
||||||
x49gp_module_get_string(x49gp_module_t *module, GKeyFile *key,
|
|
||||||
const char *name, char *reset, char **valuep)
|
|
||||||
{
|
{
|
||||||
GError* gerror = NULL;
|
GError* gerror = NULL;
|
||||||
char* data;
|
char* data;
|
||||||
|
|
||||||
data = g_key_file_get_value( key, module->name, name, &gerror );
|
data = g_key_file_get_value( key, module->name, name, &gerror );
|
||||||
if ( NULL == data ) {
|
if ( NULL == data ) {
|
||||||
fprintf(stderr, "%s: %s:%u: key \"%s\" not found\n",
|
fprintf( stderr, "%s: %s:%u: key \"%s\" not found\n", module->name, __FUNCTION__, __LINE__, name );
|
||||||
module->name, __FUNCTION__, __LINE__, name);
|
|
||||||
*valuep = g_strdup( reset );
|
*valuep = g_strdup( reset );
|
||||||
return -EAGAIN;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
@ -413,17 +367,14 @@ x49gp_module_get_string(x49gp_module_t *module, GKeyFile *key,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int x49gp_module_set_string(x49gp_module_t *module, GKeyFile *key,
|
int x49gp_module_set_string( x49gp_module_t* module, GKeyFile* key, const char* name, const char* value )
|
||||||
const char *name, const char *value)
|
|
||||||
{
|
{
|
||||||
g_key_file_set_value( key, module->name, name, value );
|
g_key_file_set_value( key, module->name, name, value );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** path )
|
||||||
x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
|
|
||||||
char **path)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -431,8 +382,7 @@ x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
|
||||||
|
|
||||||
*path = g_build_filename( x49gp->progpath, name, NULL );
|
*path = g_build_filename( x49gp->progpath, name, NULL );
|
||||||
if ( NULL == *path ) {
|
if ( NULL == *path ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
module->name, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,8 +394,7 @@ x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
|
||||||
|
|
||||||
*path = g_build_filename( X49GP_DATADIR, name, NULL );
|
*path = g_build_filename( X49GP_DATADIR, name, NULL );
|
||||||
if ( NULL == *path ) {
|
if ( NULL == *path ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
module->name, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -455,9 +404,7 @@ x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
|
||||||
|
|
||||||
if ( fd < 0 ) {
|
if ( fd < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, *path, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
*path, strerror(errno));
|
|
||||||
g_free( *path );
|
g_free( *path );
|
||||||
*path = NULL;
|
*path = NULL;
|
||||||
return error;
|
return error;
|
||||||
|
@ -466,21 +413,15 @@ x49gp_module_open_rodata(x49gp_module_t *module, const char *name,
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_module_init( x49gp_t* x49gp, const char* name, int ( *init )( x49gp_module_t* ), int ( *exit )( x49gp_module_t* ),
|
||||||
x49gp_module_init(x49gp_t *x49gp, const char *name,
|
int ( *reset )( x49gp_module_t*, x49gp_reset_t ), int ( *load )( x49gp_module_t*, GKeyFile* ),
|
||||||
int (*init)(x49gp_module_t *),
|
int ( *save )( x49gp_module_t*, GKeyFile* ), void* user_data, x49gp_module_t** modulep )
|
||||||
int (*exit)(x49gp_module_t *),
|
|
||||||
int (*reset)(x49gp_module_t *, x49gp_reset_t),
|
|
||||||
int (*load)(x49gp_module_t *, GKeyFile *),
|
|
||||||
int (*save)(x49gp_module_t *, GKeyFile *),
|
|
||||||
void *user_data, x49gp_module_t **modulep)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
module = malloc( sizeof( x49gp_module_t ) );
|
module = malloc( sizeof( x49gp_module_t ) );
|
||||||
if ( NULL == module ) {
|
if ( NULL == module ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", name, __FUNCTION__, __LINE__ );
|
||||||
name, __FUNCTION__, __LINE__);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset( module, 0, sizeof( x49gp_module_t ) );
|
memset( module, 0, sizeof( x49gp_module_t ) );
|
||||||
|
|
|
@ -34,8 +34,7 @@
|
||||||
* SPI Interface: 0x59000000
|
* SPI Interface: 0x59000000
|
||||||
* SDI Interface: 0x5a000000
|
* SDI Interface: 0x5a000000
|
||||||
*/
|
*/
|
||||||
int
|
int x49gp_s3c2410_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_s3c2410_sram_init( x49gp );
|
x49gp_s3c2410_sram_init( x49gp );
|
||||||
x49gp_s3c2410_memc_init( x49gp );
|
x49gp_s3c2410_memc_init( x49gp );
|
||||||
|
@ -60,8 +59,4 @@ x49gp_s3c2410_init(x49gp_t *x49gp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int s3c2410_exit( x49gp_t* x49gp ) { return 0; }
|
||||||
s3c2410_exit(x49gp_t *x49gp)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t adccon;
|
uint32_t adccon;
|
||||||
uint32_t adctsc;
|
uint32_t adctsc;
|
||||||
|
@ -24,14 +23,11 @@ typedef struct {
|
||||||
s3c2410_offset_t* regs;
|
s3c2410_offset_t* regs;
|
||||||
} s3c2410_adc_t;
|
} s3c2410_adc_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_data_init( s3c2410_adc_t* adc )
|
||||||
s3c2410_adc_data_init(s3c2410_adc_t *adc)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(ADC, ADCCON, 0x00003fc4, adc->adccon),
|
S3C2410_OFFSET( ADC, ADCCON, 0x00003fc4, adc->adccon ), S3C2410_OFFSET( ADC, ADCTSC, 0x00000058, adc->adctsc ),
|
||||||
S3C2410_OFFSET(ADC, ADCTSC, 0x00000058, adc->adctsc),
|
S3C2410_OFFSET( ADC, ADCDLY, 0x000000ff, adc->adcdly ), S3C2410_OFFSET( ADC, ADCDAT0, 0x3ff, adc->adcdat0 ),
|
||||||
S3C2410_OFFSET(ADC, ADCDLY, 0x000000ff, adc->adcdly),
|
|
||||||
S3C2410_OFFSET(ADC, ADCDAT0, 0x3ff, adc->adcdat0),
|
|
||||||
S3C2410_OFFSET( ADC, ADCDAT1, 0x3ff, adc->adcdat1 ),
|
S3C2410_OFFSET( ADC, ADCDAT1, 0x3ff, adc->adcdat1 ),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,8 +35,7 @@ s3c2410_adc_data_init(s3c2410_adc_t *adc)
|
||||||
|
|
||||||
adc->regs = malloc( sizeof( regs ) );
|
adc->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == adc->regs ) {
|
if ( NULL == adc->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,8 +45,7 @@ s3c2410_adc_data_init(s3c2410_adc_t *adc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_adc_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_adc_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc = opaque;
|
s3c2410_adc_t* adc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -63,9 +57,8 @@ s3c2410_adc_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( adc, offset );
|
reg = S3C2410_OFFSET_ENTRY( adc, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_ADC
|
#ifdef DEBUG_S3C2410_ADC
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-adc", S3C2410_ADC_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -80,8 +73,7 @@ s3c2410_adc_read(void *opaque, target_phys_addr_t offset)
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_adc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_adc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc = opaque;
|
s3c2410_adc_t* adc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -93,16 +85,13 @@ s3c2410_adc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( adc, offset );
|
reg = S3C2410_OFFSET_ENTRY( adc, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_ADC
|
#ifdef DEBUG_S3C2410_ADC
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-adc", S3C2410_ADC_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-adc", S3C2410_ADC_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_adc_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc = module->user_data;
|
s3c2410_adc_t* adc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -119,16 +108,14 @@ s3c2410_adc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_adc_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc = module->user_data;
|
s3c2410_adc_t* adc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -150,8 +137,7 @@ s3c2410_adc_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_adc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc = module->user_data;
|
s3c2410_adc_t* adc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -173,22 +159,11 @@ s3c2410_adc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_adc_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_adc_readfn[] = { s3c2410_adc_read, s3c2410_adc_read, s3c2410_adc_read };
|
||||||
{
|
|
||||||
s3c2410_adc_read,
|
|
||||||
s3c2410_adc_read,
|
|
||||||
s3c2410_adc_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_adc_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_adc_writefn[] = { s3c2410_adc_write, s3c2410_adc_write, s3c2410_adc_write };
|
||||||
{
|
|
||||||
s3c2410_adc_write,
|
|
||||||
s3c2410_adc_write,
|
|
||||||
s3c2410_adc_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_init( x49gp_module_t* module )
|
||||||
s3c2410_adc_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc;
|
s3c2410_adc_t* adc;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -199,8 +174,7 @@ s3c2410_adc_init(x49gp_module_t *module)
|
||||||
|
|
||||||
adc = malloc( sizeof( s3c2410_adc_t ) );
|
adc = malloc( sizeof( s3c2410_adc_t ) );
|
||||||
if ( NULL == adc ) {
|
if ( NULL == adc ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_adc_data_init( adc ) ) {
|
if ( s3c2410_adc_data_init( adc ) ) {
|
||||||
|
@ -210,8 +184,7 @@ s3c2410_adc_init(x49gp_module_t *module)
|
||||||
|
|
||||||
module->user_data = adc;
|
module->user_data = adc;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_adc_readfn,
|
iotype = cpu_register_io_memory( s3c2410_adc_readfn, s3c2410_adc_writefn, adc );
|
||||||
s3c2410_adc_writefn, adc);
|
|
||||||
#ifdef DEBUG_S3C2410_ADC
|
#ifdef DEBUG_S3C2410_ADC
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -220,8 +193,7 @@ s3c2410_adc_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_adc_exit( x49gp_module_t* module )
|
||||||
s3c2410_adc_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_adc_t* adc;
|
s3c2410_adc_t* adc;
|
||||||
|
|
||||||
|
@ -242,17 +214,11 @@ s3c2410_adc_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_adc_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_adc_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-adc",
|
if ( x49gp_module_init( x49gp, "s3c2410-adc", s3c2410_adc_init, s3c2410_adc_exit, s3c2410_adc_reset, s3c2410_adc_load, s3c2410_adc_save,
|
||||||
s3c2410_adc_init,
|
|
||||||
s3c2410_adc_exit,
|
|
||||||
s3c2410_adc_reset,
|
|
||||||
s3c2410_adc_load,
|
|
||||||
s3c2410_adc_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* $Id: s3c2410_arm.c,v 1.7 2008/12/11 12:18:17 ecd Exp $
|
/* $Id: s3c2410_arm.c,v 1.7 2008/12/11 12:18:17 ecd Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -15,8 +14,7 @@
|
||||||
|
|
||||||
#include "qemu-git/cpu-all.h"
|
#include "qemu-git/cpu-all.h"
|
||||||
|
|
||||||
static int
|
static int s3c2410_arm_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_arm_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
struct CPUARMState* env = module->user_data;
|
struct CPUARMState* env = module->user_data;
|
||||||
char name[ 32 ];
|
char name[ 32 ];
|
||||||
|
@ -56,14 +54,12 @@ s3c2410_arm_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
}
|
}
|
||||||
for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
|
for ( i = 0; i < ( sizeof( env->usr_regs ) / sizeof( env->usr_regs[ 0 ] ) ); i++ ) {
|
||||||
sprintf( name, "reg-usr-%02u", i );
|
sprintf( name, "reg-usr-%02u", i );
|
||||||
if (x49gp_module_get_u32(module, key, name,
|
if ( x49gp_module_get_u32( module, key, name, 0, &env->usr_regs[ i ] ) )
|
||||||
0, &env->usr_regs[i]))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
|
for ( i = 0; i < ( sizeof( env->fiq_regs ) / sizeof( env->fiq_regs[ 0 ] ) ); i++ ) {
|
||||||
sprintf( name, "reg-fiq-%02u", i );
|
sprintf( name, "reg-fiq-%02u", i );
|
||||||
if (x49gp_module_get_u32(module, key, name,
|
if ( x49gp_module_get_u32( module, key, name, 0, &env->fiq_regs[ i ] ) )
|
||||||
0, &env->fiq_regs[i]))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,8 +139,7 @@ s3c2410_arm_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_arm_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_arm_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
struct CPUARMState* env = module->user_data;
|
struct CPUARMState* env = module->user_data;
|
||||||
char name[ 32 ];
|
char name[ 32 ];
|
||||||
|
@ -217,8 +212,7 @@ s3c2410_arm_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_arm_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_arm_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
struct CPUARMState* env = module->user_data;
|
struct CPUARMState* env = module->user_data;
|
||||||
|
|
||||||
|
@ -232,8 +226,7 @@ s3c2410_arm_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_arm_init( x49gp_module_t* module )
|
||||||
s3c2410_arm_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
|
|
||||||
|
@ -245,8 +238,7 @@ s3c2410_arm_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_arm_exit( x49gp_module_t* module )
|
||||||
s3c2410_arm_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_MODULES
|
#ifdef DEBUG_X49GP_MODULES
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
|
@ -255,17 +247,11 @@ s3c2410_arm_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_arm_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_arm_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-arm",
|
if ( x49gp_module_init( x49gp, "s3c2410-arm", s3c2410_arm_init, s3c2410_arm_exit, s3c2410_arm_reset, s3c2410_arm_load, s3c2410_arm_save,
|
||||||
s3c2410_arm_init,
|
|
||||||
s3c2410_arm_exit,
|
|
||||||
s3c2410_arm_reset,
|
|
||||||
s3c2410_arm_load,
|
|
||||||
s3c2410_arm_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,34 +27,33 @@ typedef struct {
|
||||||
uint32_t mode;
|
uint32_t mode;
|
||||||
} s3c2410_arb_data_t;
|
} s3c2410_arb_data_t;
|
||||||
|
|
||||||
static const int s3c2410_arb_order[4][6] =
|
static const int s3c2410_arb_order[ 4 ][ 6 ] = {
|
||||||
{
|
|
||||||
{0, 1, 2, 3, 4, 5},
|
{0, 1, 2, 3, 4, 5},
|
||||||
{0, 2, 3, 4, 1, 5},
|
{0, 2, 3, 4, 1, 5},
|
||||||
{0, 3, 4, 1, 2, 5},
|
{0, 3, 4, 1, 2, 5},
|
||||||
{0, 4, 1, 2, 3, 5}
|
{0, 4, 1, 2, 3, 5}
|
||||||
};
|
};
|
||||||
|
|
||||||
static const s3c2410_arb_t s3c2410_arb_table[] =
|
static const s3c2410_arb_t s3c2410_arb_table[] = {
|
||||||
|
[0] = {ARB0_SEL_SHIFT, ARB0_MODE, 0, { -1, EINT0, EINT1, EINT2, EINT3, -1 } },
|
||||||
|
[1] = {ARB1_SEL_SHIFT, ARB1_MODE, 1, { EINT4_7, EINT8_23, -1, nBATT_FLT, INT_TICK, INT_WDT } },
|
||||||
|
[2] = {ARB2_SEL_SHIFT, ARB2_MODE, 2, { INT_TIMER0, INT_TIMER1, INT_TIMER2, INT_TIMER3, INT_TIMER4, INT_UART2 }},
|
||||||
|
[3] = {ARB3_SEL_SHIFT, ARB3_MODE, 3, { INT_LCD, INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3, INT_SDI } },
|
||||||
|
[4] = {ARB4_SEL_SHIFT, ARB4_MODE, 4, { INT_SPI0, INT_UART1, -1, INT_USBD, INT_USBH, INT_IIC } },
|
||||||
|
[5] = {ARB5_SEL_SHIFT,
|
||||||
|
ARB5_MODE, 5,
|
||||||
{
|
{
|
||||||
[0] = { ARB0_SEL_SHIFT, ARB0_MODE, 0,
|
-1,
|
||||||
{ -1, EINT0, EINT1, EINT2, EINT3, -1 } },
|
INT_UART0,
|
||||||
[1] = { ARB1_SEL_SHIFT, ARB1_MODE, 1,
|
INT_SPI1,
|
||||||
{ EINT4_7, EINT8_23, -1, nBATT_FLT, INT_TICK, INT_WDT } },
|
INT_RTC,
|
||||||
[2] = { ARB2_SEL_SHIFT, ARB2_MODE, 2,
|
INT_ADC,
|
||||||
{ INT_TIMER0, INT_TIMER1, INT_TIMER2, INT_TIMER3, INT_TIMER4, INT_UART2} },
|
-1,
|
||||||
[3] = { ARB3_SEL_SHIFT, ARB3_MODE, 3,
|
} },
|
||||||
{ INT_LCD, INT_DMA0, INT_DMA1, INT_DMA2, INT_DMA3, INT_SDI } },
|
[6] = {ARB6_SEL_SHIFT, ARB6_MODE, 6, { 0, 1, 2, 3, 4, 5 } },
|
||||||
[4] = { ARB4_SEL_SHIFT, ARB4_MODE, 4,
|
|
||||||
{ INT_SPI0, INT_UART1, -1, INT_USBD, INT_USBH, INT_IIC } },
|
|
||||||
[5] = { ARB5_SEL_SHIFT, ARB5_MODE, 5,
|
|
||||||
{ -1, INT_UART0, INT_SPI1, INT_RTC, INT_ADC, -1, } },
|
|
||||||
[6] = { ARB6_SEL_SHIFT, ARB6_MODE, 6,
|
|
||||||
{ 0, 1, 2, 3, 4, 5 } },
|
|
||||||
};
|
};
|
||||||
#define INTC_NR_ARB ( sizeof( s3c2410_arb_table ) / sizeof( s3c2410_arb_table[ 0 ] ) )
|
#define INTC_NR_ARB ( sizeof( s3c2410_arb_table ) / sizeof( s3c2410_arb_table[ 0 ] ) )
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t srcpnd;
|
uint32_t srcpnd;
|
||||||
uint32_t intmod;
|
uint32_t intmod;
|
||||||
|
@ -76,32 +75,24 @@ typedef struct {
|
||||||
s3c2410_offset_t* regs;
|
s3c2410_offset_t* regs;
|
||||||
} s3c2410_intc_t;
|
} s3c2410_intc_t;
|
||||||
|
|
||||||
|
|
||||||
static void s3c2410_intc_gen_int( s3c2410_intc_t* intc );
|
static void s3c2410_intc_gen_int( s3c2410_intc_t* intc );
|
||||||
static void s3c2410_intc_gen_int_from_sub_int( s3c2410_intc_t* intc );
|
static void s3c2410_intc_gen_int_from_sub_int( s3c2410_intc_t* intc );
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_data_init( s3c2410_intc_t* intc )
|
||||||
s3c2410_intc_data_init(s3c2410_intc_t *intc)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(INTC, SRCPND, 0x00000000, intc->srcpnd),
|
S3C2410_OFFSET( INTC, SRCPND, 0x00000000, intc->srcpnd ), S3C2410_OFFSET( INTC, INTMOD, 0x00000000, intc->intmod ),
|
||||||
S3C2410_OFFSET(INTC, INTMOD, 0x00000000, intc->intmod),
|
S3C2410_OFFSET( INTC, INTMSK, 0xffffffff, intc->intmsk ), S3C2410_OFFSET( INTC, PRIORITY, 0x0000007f, intc->priority ),
|
||||||
S3C2410_OFFSET(INTC, INTMSK, 0xffffffff, intc->intmsk),
|
S3C2410_OFFSET( INTC, INTPND, 0x00000000, intc->intpnd ), S3C2410_OFFSET( INTC, INTOFFSET, 0x00000000, intc->intoffset ),
|
||||||
S3C2410_OFFSET(INTC, PRIORITY, 0x0000007f, intc->priority),
|
S3C2410_OFFSET( INTC, SUBSRCPND, 0x00000000, intc->subsrcpnd ), S3C2410_OFFSET( INTC, INTSUBMSK, 0x000007ff, intc->intsubmsk ) };
|
||||||
S3C2410_OFFSET(INTC, INTPND, 0x00000000, intc->intpnd),
|
|
||||||
S3C2410_OFFSET(INTC, INTOFFSET, 0x00000000, intc->intoffset),
|
|
||||||
S3C2410_OFFSET(INTC, SUBSRCPND, 0x00000000, intc->subsrcpnd),
|
|
||||||
S3C2410_OFFSET(INTC, INTSUBMSK, 0x000007ff, intc->intsubmsk)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( intc, 0, sizeof( s3c2410_intc_t ) );
|
memset( intc, 0, sizeof( s3c2410_intc_t ) );
|
||||||
|
|
||||||
intc->regs = malloc( sizeof( regs ) );
|
intc->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == intc->regs ) {
|
if ( NULL == intc->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +107,7 @@ s3c2410_intc_data_init(s3c2410_intc_t *intc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void srcpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
srcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
intc->srcpnd &= ~( data );
|
intc->srcpnd &= ~( data );
|
||||||
intc->srcpnd |= intc->src_pending;
|
intc->srcpnd |= intc->src_pending;
|
||||||
|
@ -127,16 +117,14 @@ srcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void intmod_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
intmod_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
intc->intmod = data & 0xfeffffbf;
|
intc->intmod = data & 0xfeffffbf;
|
||||||
|
|
||||||
s3c2410_intc_gen_int( intc );
|
s3c2410_intc_gen_int( intc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void intmsk_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
intmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_ENABLE_IRQ
|
#ifdef DEBUG_X49GP_ENABLE_IRQ
|
||||||
uint32_t change;
|
uint32_t change;
|
||||||
|
@ -158,8 +146,7 @@ intmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
|
||||||
s3c2410_intc_gen_int( intc );
|
s3c2410_intc_gen_int( intc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t priority_get_word( s3c2410_intc_t* intc )
|
||||||
priority_get_word(s3c2410_intc_t *intc)
|
|
||||||
{
|
{
|
||||||
const s3c2410_arb_t* arb;
|
const s3c2410_arb_t* arb;
|
||||||
s3c2410_arb_data_t* arb_data;
|
s3c2410_arb_data_t* arb_data;
|
||||||
|
@ -171,15 +158,13 @@ priority_get_word(s3c2410_intc_t *intc)
|
||||||
arb = &s3c2410_arb_table[ i ];
|
arb = &s3c2410_arb_table[ i ];
|
||||||
arb_data = &intc->arb_data[ i ];
|
arb_data = &intc->arb_data[ i ];
|
||||||
|
|
||||||
intc->priority |= (arb_data->sel << arb->sel_shift) |
|
intc->priority |= ( arb_data->sel << arb->sel_shift ) | arb_data->mode;
|
||||||
arb_data->mode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intc->priority;
|
return intc->priority;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void priority_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
priority_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
const s3c2410_arb_t* arb;
|
const s3c2410_arb_t* arb;
|
||||||
s3c2410_arb_data_t* arb_data;
|
s3c2410_arb_data_t* arb_data;
|
||||||
|
@ -198,16 +183,14 @@ priority_put_word(s3c2410_intc_t *intc, uint32_t data)
|
||||||
s3c2410_intc_gen_int( intc );
|
s3c2410_intc_gen_int( intc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void intpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
intpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
intc->intpnd &= ~( data );
|
intc->intpnd &= ~( data );
|
||||||
|
|
||||||
s3c2410_intc_gen_int( intc );
|
s3c2410_intc_gen_int( intc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void subsrcpnd_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
subsrcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
intc->subsrcpnd &= ~( data );
|
intc->subsrcpnd &= ~( data );
|
||||||
intc->subsrcpnd |= intc->subsrc_pending;
|
intc->subsrcpnd |= intc->subsrc_pending;
|
||||||
|
@ -217,17 +200,14 @@ subsrcpnd_put_word(s3c2410_intc_t *intc, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void intsubmsk_put_word( s3c2410_intc_t* intc, uint32_t data )
|
||||||
intsubmsk_put_word(s3c2410_intc_t *intc, uint32_t data)
|
|
||||||
{
|
{
|
||||||
intc->intsubmsk = data & 0x000007ff;
|
intc->intsubmsk = data & 0x000007ff;
|
||||||
|
|
||||||
s3c2410_intc_gen_int_from_sub_int( intc );
|
s3c2410_intc_gen_int_from_sub_int( intc );
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_intc_select_int( s3c2410_intc_t* intc, const s3c2410_arb_t* arb, uint32_t service, int* offset )
|
||||||
s3c2410_intc_select_int(s3c2410_intc_t *intc, const s3c2410_arb_t *arb,
|
|
||||||
uint32_t service, int *offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_arb_data_t* arb_data = &intc->arb_data[ arb->index ];
|
s3c2410_arb_data_t* arb_data = &intc->arb_data[ arb->index ];
|
||||||
const int* order;
|
const int* order;
|
||||||
|
@ -253,21 +233,11 @@ s3c2410_intc_select_int(s3c2410_intc_t *intc, const s3c2410_arb_t *arb,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_FIQ( CPUState* env ) { cpu_interrupt( env, CPU_INTERRUPT_FIQ ); }
|
||||||
s3c2410_FIQ (CPUState *env)
|
|
||||||
{
|
|
||||||
cpu_interrupt(env, CPU_INTERRUPT_FIQ);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void s3c2410_IRQ( CPUState* env ) { cpu_interrupt( env, CPU_INTERRUPT_HARD ); }
|
||||||
s3c2410_IRQ (CPUState *env)
|
|
||||||
{
|
|
||||||
cpu_interrupt(env, CPU_INTERRUPT_HARD);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
static void s3c2410_intc_gen_int( s3c2410_intc_t* intc )
|
||||||
static void
|
|
||||||
s3c2410_intc_gen_int(s3c2410_intc_t *intc)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = intc->x49gp;
|
x49gp_t* x49gp = intc->x49gp;
|
||||||
uint32_t fiq, service;
|
uint32_t fiq, service;
|
||||||
|
@ -372,8 +342,7 @@ s3c2410_intc_gen_int(s3c2410_intc_t *intc)
|
||||||
cpu_reset_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
|
cpu_reset_interrupt( x49gp->env, CPU_INTERRUPT_HARD );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_intc_assert( x49gp_t* x49gp, int irq, int level )
|
||||||
s3c2410_intc_assert(x49gp_t *x49gp, int irq, int level)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
||||||
|
|
||||||
|
@ -398,8 +367,7 @@ s3c2410_intc_assert(x49gp_t *x49gp, int irq, int level)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_intc_deassert( x49gp_t* x49gp, int irq )
|
||||||
s3c2410_intc_deassert(x49gp_t *x49gp, int irq)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
||||||
|
|
||||||
|
@ -413,8 +381,7 @@ s3c2410_intc_deassert(x49gp_t *x49gp, int irq)
|
||||||
intc->src_pending &= ~( 1 << irq );
|
intc->src_pending &= ~( 1 << irq );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_intc_gen_int_from_sub_int( s3c2410_intc_t* intc )
|
||||||
s3c2410_intc_gen_int_from_sub_int(s3c2410_intc_t *intc)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = intc->x49gp;
|
x49gp_t* x49gp = intc->x49gp;
|
||||||
uint32_t service;
|
uint32_t service;
|
||||||
|
@ -452,8 +419,7 @@ s3c2410_intc_gen_int_from_sub_int(s3c2410_intc_t *intc)
|
||||||
intc->subsrcpnd = intc->subsrc_pending;
|
intc->subsrcpnd = intc->subsrc_pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_intc_sub_assert( x49gp_t* x49gp, int sub_irq, int level )
|
||||||
s3c2410_intc_sub_assert(x49gp_t *x49gp, int sub_irq, int level)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
||||||
|
|
||||||
|
@ -473,8 +439,7 @@ s3c2410_intc_sub_assert(x49gp_t *x49gp, int sub_irq, int level)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_intc_sub_deassert( x49gp_t* x49gp, int sub_irq )
|
||||||
s3c2410_intc_sub_deassert(x49gp_t *x49gp, int sub_irq)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
s3c2410_intc_t* intc = x49gp->s3c2410_intc;
|
||||||
|
|
||||||
|
@ -488,8 +453,7 @@ s3c2410_intc_sub_deassert(x49gp_t *x49gp, int sub_irq)
|
||||||
intc->subsrc_pending &= ~( 1 << sub_irq );
|
intc->subsrc_pending &= ~( 1 << sub_irq );
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_intc_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_intc_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = opaque;
|
s3c2410_intc_t* intc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -511,16 +475,13 @@ s3c2410_intc_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_INTC
|
#ifdef DEBUG_S3C2410_INTC
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-intc", S3C2410_INTC_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-intc", S3C2410_INTC_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_intc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_intc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_S3C2410_INTC
|
#ifdef DEBUG_S3C2410_INTC
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -534,9 +495,7 @@ s3c2410_intc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
#ifdef DEBUG_S3C2410_INTC
|
#ifdef DEBUG_S3C2410_INTC
|
||||||
reg = S3C2410_OFFSET_ENTRY( intc, offset );
|
reg = S3C2410_OFFSET_ENTRY( intc, offset );
|
||||||
|
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-intc", S3C2410_INTC_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-intc", S3C2410_INTC_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -566,8 +525,7 @@ s3c2410_intc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_intc_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = module->user_data;
|
s3c2410_intc_t* intc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -584,8 +542,7 @@ s3c2410_intc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -601,8 +558,7 @@ s3c2410_intc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_intc_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = module->user_data;
|
s3c2410_intc_t* intc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -627,8 +583,7 @@ s3c2410_intc_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_intc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc = module->user_data;
|
s3c2410_intc_t* intc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -654,22 +609,11 @@ s3c2410_intc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_intc_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_intc_readfn[] = { s3c2410_intc_read, s3c2410_intc_read, s3c2410_intc_read };
|
||||||
{
|
|
||||||
s3c2410_intc_read,
|
|
||||||
s3c2410_intc_read,
|
|
||||||
s3c2410_intc_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_intc_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_intc_writefn[] = { s3c2410_intc_write, s3c2410_intc_write, s3c2410_intc_write };
|
||||||
{
|
|
||||||
s3c2410_intc_write,
|
|
||||||
s3c2410_intc_write,
|
|
||||||
s3c2410_intc_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_init( x49gp_module_t* module )
|
||||||
s3c2410_intc_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc;
|
s3c2410_intc_t* intc;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -680,8 +624,7 @@ s3c2410_intc_init(x49gp_module_t *module)
|
||||||
|
|
||||||
intc = malloc( sizeof( s3c2410_intc_t ) );
|
intc = malloc( sizeof( s3c2410_intc_t ) );
|
||||||
if ( NULL == intc ) {
|
if ( NULL == intc ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_intc_data_init( intc ) ) {
|
if ( s3c2410_intc_data_init( intc ) ) {
|
||||||
|
@ -694,8 +637,7 @@ s3c2410_intc_init(x49gp_module_t *module)
|
||||||
intc->x49gp = module->x49gp;
|
intc->x49gp = module->x49gp;
|
||||||
intc->x49gp->s3c2410_intc = intc;
|
intc->x49gp->s3c2410_intc = intc;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_intc_readfn,
|
iotype = cpu_register_io_memory( s3c2410_intc_readfn, s3c2410_intc_writefn, intc );
|
||||||
s3c2410_intc_writefn, intc);
|
|
||||||
#ifdef DEBUG_S3C2410_INTC
|
#ifdef DEBUG_S3C2410_INTC
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -703,8 +645,7 @@ s3c2410_intc_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_intc_exit( x49gp_module_t* module )
|
||||||
s3c2410_intc_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_intc_t* intc;
|
s3c2410_intc_t* intc;
|
||||||
|
|
||||||
|
@ -725,18 +666,12 @@ s3c2410_intc_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_intc_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_intc_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-intc",
|
if ( x49gp_module_init( x49gp, "s3c2410-intc", s3c2410_intc_init, s3c2410_intc_exit, s3c2410_intc_reset, s3c2410_intc_load,
|
||||||
s3c2410_intc_init,
|
s3c2410_intc_save, NULL, &module ) ) {
|
||||||
s3c2410_intc_exit,
|
|
||||||
s3c2410_intc_reset,
|
|
||||||
s3c2410_intc_load,
|
|
||||||
s3c2410_intc_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
#include "byteorder.h"
|
#include "byteorder.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t gpacon;
|
uint32_t gpacon;
|
||||||
uint32_t gpadat;
|
uint32_t gpadat;
|
||||||
|
@ -70,67 +69,49 @@ typedef struct {
|
||||||
x49gp_t* x49gp;
|
x49gp_t* x49gp;
|
||||||
} s3c2410_io_port_t;
|
} s3c2410_io_port_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_data_init( s3c2410_io_port_t* io )
|
||||||
s3c2410_io_port_data_init(s3c2410_io_port_t *io)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(IO_PORT, GPACON, 0x007fffff, io->gpacon),
|
S3C2410_OFFSET( IO_PORT, GPACON, 0x007fffff, io->gpacon ), S3C2410_OFFSET( IO_PORT, GPADAT, 0x00000000, io->gpadat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPADAT, 0x00000000, io->gpadat),
|
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPBCON, 0x00000000, io->gpbcon),
|
S3C2410_OFFSET( IO_PORT, GPBCON, 0x00000000, io->gpbcon ), S3C2410_OFFSET( IO_PORT, GPBDAT, 0x00000000, io->gpbdat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPBDAT, 0x00000000, io->gpbdat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPBUP, 0x00000000, io->gpbup ),
|
S3C2410_OFFSET( IO_PORT, GPBUP, 0x00000000, io->gpbup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPCCON, 0x00000000, io->gpccon),
|
S3C2410_OFFSET( IO_PORT, GPCCON, 0x00000000, io->gpccon ), S3C2410_OFFSET( IO_PORT, GPCDAT, 0x00000000, io->gpcdat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPCDAT, 0x00000000, io->gpcdat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPCUP, 0x00000000, io->gpcup ),
|
S3C2410_OFFSET( IO_PORT, GPCUP, 0x00000000, io->gpcup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPDCON, 0x00000000, io->gpdcon),
|
S3C2410_OFFSET( IO_PORT, GPDCON, 0x00000000, io->gpdcon ), S3C2410_OFFSET( IO_PORT, GPDDAT, 0x0000038c, io->gpddat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPDDAT, 0x0000038c, io->gpddat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPDUP, 0x0000f000, io->gpdup ),
|
S3C2410_OFFSET( IO_PORT, GPDUP, 0x0000f000, io->gpdup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPECON, 0x00000000, io->gpecon),
|
S3C2410_OFFSET( IO_PORT, GPECON, 0x00000000, io->gpecon ), S3C2410_OFFSET( IO_PORT, GPEDAT, 0x0000c7c0, io->gpedat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPEDAT, 0x0000c7c0, io->gpedat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPEUP, 0x00000000, io->gpeup ),
|
S3C2410_OFFSET( IO_PORT, GPEUP, 0x00000000, io->gpeup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPFCON, 0x00000000, io->gpfcon),
|
S3C2410_OFFSET( IO_PORT, GPFCON, 0x00000000, io->gpfcon ), S3C2410_OFFSET( IO_PORT, GPFDAT, 0x00000008, io->gpfdat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPFDAT, 0x00000008, io->gpfdat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPFUP, 0x00000000, io->gpfup ),
|
S3C2410_OFFSET( IO_PORT, GPFUP, 0x00000000, io->gpfup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPGCON, 0x00000000, io->gpgcon),
|
S3C2410_OFFSET( IO_PORT, GPGCON, 0x00000000, io->gpgcon ), S3C2410_OFFSET( IO_PORT, GPGDAT, 0x0000fffe, io->gpgdat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPGDAT, 0x0000fffe, io->gpgdat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPGUP, 0x0000f800, io->gpgup ),
|
S3C2410_OFFSET( IO_PORT, GPGUP, 0x0000f800, io->gpgup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GPHCON, 0x00000000, io->gphcon),
|
S3C2410_OFFSET( IO_PORT, GPHCON, 0x00000000, io->gphcon ), S3C2410_OFFSET( IO_PORT, GPHDAT, 0x00000000, io->gphdat ),
|
||||||
S3C2410_OFFSET(IO_PORT, GPHDAT, 0x00000000, io->gphdat),
|
|
||||||
S3C2410_OFFSET( IO_PORT, GPHUP, 0x00000000, io->gphup ),
|
S3C2410_OFFSET( IO_PORT, GPHUP, 0x00000000, io->gphup ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, MISCCR, 0x00010330, io->misccr),
|
S3C2410_OFFSET( IO_PORT, MISCCR, 0x00010330, io->misccr ), S3C2410_OFFSET( IO_PORT, DCLKCON, 0x00000000, io->dclkcon ),
|
||||||
S3C2410_OFFSET(IO_PORT, DCLKCON, 0x00000000, io->dclkcon),
|
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, EXTINT0, 0x00000000, io->extint0),
|
S3C2410_OFFSET( IO_PORT, EXTINT0, 0x00000000, io->extint0 ), S3C2410_OFFSET( IO_PORT, EXTINT1, 0x00000000, io->extint1 ),
|
||||||
S3C2410_OFFSET(IO_PORT, EXTINT1, 0x00000000, io->extint1),
|
S3C2410_OFFSET( IO_PORT, EXTINT2, 0x00000000, io->extint2 ), S3C2410_OFFSET( IO_PORT, EINTFLT0, 0x00000000, io->eintflt0 ),
|
||||||
S3C2410_OFFSET(IO_PORT, EXTINT2, 0x00000000, io->extint2),
|
S3C2410_OFFSET( IO_PORT, EINTFLT1, 0x00000000, io->eintflt1 ), S3C2410_OFFSET( IO_PORT, EINTFLT2, 0x00000000, io->eintflt2 ),
|
||||||
S3C2410_OFFSET(IO_PORT, EINTFLT0, 0x00000000, io->eintflt0),
|
S3C2410_OFFSET( IO_PORT, EINTFLT3, 0x00000000, io->eintflt3 ), S3C2410_OFFSET( IO_PORT, EINTMASK, 0x00fffff0, io->eintmask ),
|
||||||
S3C2410_OFFSET(IO_PORT, EINTFLT1, 0x00000000, io->eintflt1),
|
|
||||||
S3C2410_OFFSET(IO_PORT, EINTFLT2, 0x00000000, io->eintflt2),
|
|
||||||
S3C2410_OFFSET(IO_PORT, EINTFLT3, 0x00000000, io->eintflt3),
|
|
||||||
S3C2410_OFFSET(IO_PORT, EINTMASK, 0x00fffff0, io->eintmask),
|
|
||||||
S3C2410_OFFSET( IO_PORT, EINTPEND, 0x00000000, io->eintpend ),
|
S3C2410_OFFSET( IO_PORT, EINTPEND, 0x00000000, io->eintpend ),
|
||||||
|
|
||||||
S3C2410_OFFSET(IO_PORT, GSTATUS0, 0x00000001, io->gstatus0),
|
S3C2410_OFFSET( IO_PORT, GSTATUS0, 0x00000001, io->gstatus0 ), S3C2410_OFFSET( IO_PORT, GSTATUS1, 0x32410002, io->gstatus1 ),
|
||||||
S3C2410_OFFSET(IO_PORT, GSTATUS1, 0x32410002, io->gstatus1),
|
S3C2410_OFFSET( IO_PORT, GSTATUS2, 0x00000001, io->gstatus2 ), S3C2410_OFFSET( IO_PORT, GSTATUS3, 0x00000000, io->gstatus3 ),
|
||||||
S3C2410_OFFSET(IO_PORT, GSTATUS2, 0x00000001, io->gstatus2),
|
S3C2410_OFFSET( IO_PORT, GSTATUS4, 0x00000000, io->gstatus4 ) };
|
||||||
S3C2410_OFFSET(IO_PORT, GSTATUS3, 0x00000000, io->gstatus3),
|
|
||||||
S3C2410_OFFSET(IO_PORT, GSTATUS4, 0x00000000, io->gstatus4)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( io, 0, sizeof( s3c2410_io_port_t ) );
|
memset( io, 0, sizeof( s3c2410_io_port_t ) );
|
||||||
|
|
||||||
io->regs = malloc( sizeof( regs ) );
|
io->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == io->regs ) {
|
if ( NULL == io->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,8 +121,7 @@ s3c2410_io_port_data_init(s3c2410_io_port_t *io)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_scan_keys( x49gp_t* x49gp, uint32_t gpgcon, uint32_t gpgdat )
|
||||||
s3c2410_scan_keys(x49gp_t *x49gp, uint32_t gpgcon, uint32_t gpgdat)
|
|
||||||
{
|
{
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
int col, row;
|
int col, row;
|
||||||
|
@ -185,8 +165,7 @@ s3c2410_scan_keys(x49gp_t *x49gp, uint32_t gpgcon, uint32_t gpgdat)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_io_port_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_io_port_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = opaque;
|
s3c2410_io_port_t* io = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -258,16 +237,14 @@ s3c2410_io_port_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_IO_PORT
|
#ifdef DEBUG_S3C2410_IO_PORT
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-io-port", S3C2410_IO_PORT_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-io-port", S3C2410_IO_PORT_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_io_port_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_io_port_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = opaque;
|
s3c2410_io_port_t* io = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -281,9 +258,7 @@ static uint32_t lcd_data = 0;
|
||||||
reg = S3C2410_OFFSET_ENTRY( io, offset );
|
reg = S3C2410_OFFSET_ENTRY( io, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_IO_PORT
|
#ifdef DEBUG_S3C2410_IO_PORT
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-io-port", S3C2410_IO_PORT_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-io-port", S3C2410_IO_PORT_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -297,8 +272,7 @@ static uint32_t lcd_data = 0;
|
||||||
|
|
||||||
if ( !( data & 0x200 ) && ( data & 0x2000 ) && ( change & 0x2000 ) ) {
|
if ( !( data & 0x200 ) && ( data & 0x2000 ) && ( change & 0x2000 ) ) {
|
||||||
#ifdef DEBUG_S3C2410_IO_PORT
|
#ifdef DEBUG_S3C2410_IO_PORT
|
||||||
printf("IO_PORT GPDDAT: clk0 rise: data %u\n",
|
printf( "IO_PORT GPDDAT: clk0 rise: data %u\n", ( data >> 12 ) & 1 );
|
||||||
(data >> 12) & 1);
|
|
||||||
#endif
|
#endif
|
||||||
lcd_data <<= 1;
|
lcd_data <<= 1;
|
||||||
lcd_data |= ( data >> 12 ) & 1;
|
lcd_data |= ( data >> 12 ) & 1;
|
||||||
|
@ -306,8 +280,7 @@ static uint32_t lcd_data = 0;
|
||||||
|
|
||||||
if ( ( data & 0x200 ) && ( change & 0x200 ) ) {
|
if ( ( data & 0x200 ) && ( change & 0x200 ) ) {
|
||||||
#ifdef DEBUG_S3C2410_IO_PORT
|
#ifdef DEBUG_S3C2410_IO_PORT
|
||||||
printf("IO_PORT GPDDAT: cs0 rise: data %04x\n",
|
printf( "IO_PORT GPDDAT: cs0 rise: data %04x\n", lcd_data );
|
||||||
lcd_data);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,8 +321,7 @@ static uint32_t lcd_data = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_io_port_g_update( x49gp_t* x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state )
|
||||||
s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char columnbit, unsigned char rowbit, uint32_t new_state)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
|
s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
|
||||||
uint32_t oldvalue, newvalue, change;
|
uint32_t oldvalue, newvalue, change;
|
||||||
|
@ -369,20 +341,17 @@ s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char colu
|
||||||
newvalue = s3c2410_scan_keys( x49gp, io->gpgcon, io->gpgdat );
|
newvalue = s3c2410_scan_keys( x49gp, io->gpgcon, io->gpgdat );
|
||||||
change = newvalue ^ oldvalue;
|
change = newvalue ^ oldvalue;
|
||||||
|
|
||||||
|
|
||||||
for ( n = 0; n < 15; ++n ) {
|
for ( n = 0; n < 15; ++n ) {
|
||||||
|
|
||||||
switch ( ( io->gpgcon >> ( 2 * n ) ) & 3 ) {
|
switch ( ( io->gpgcon >> ( 2 * n ) ) & 3 ) {
|
||||||
|
|
||||||
case 2: /* Interrupt */
|
case 2: /* Interrupt */
|
||||||
{
|
{
|
||||||
switch (n+8<=15 ?
|
switch ( n + 8 <= 15 ? ( io->extint1 >> ( 4 * n ) ) & 7 : // EINT 8-15
|
||||||
(io->extint1 >> (4 * n)) & 7 : // EINT 8-15
|
|
||||||
( io->extint2 >> ( 4 * ( n - 8 ) ) ) & 7 // EINT 16-23
|
( io->extint2 >> ( 4 * ( n - 8 ) ) ) & 7 // EINT 16-23
|
||||||
) {
|
) {
|
||||||
case 0: /* Low Level */
|
case 0: /* Low Level */
|
||||||
if (!(newvalue & (1 << n)))
|
if ( !( newvalue & ( 1 << n ) ) ) {
|
||||||
{
|
|
||||||
io->eintpend |= 1 << ( n + 8 );
|
io->eintpend |= 1 << ( n + 8 );
|
||||||
if ( io->eintpend & ~( io->eintmask ) )
|
if ( io->eintpend & ~( io->eintmask ) )
|
||||||
s3c2410_intc_assert( x49gp, EINT8_23, 1 );
|
s3c2410_intc_assert( x49gp, EINT8_23, 1 );
|
||||||
|
@ -419,7 +388,6 @@ s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char colu
|
||||||
s3c2410_intc_assert( x49gp, EINT8_23, 1 );
|
s3c2410_intc_assert( x49gp, EINT8_23, 1 );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -428,14 +396,12 @@ s3c2410_io_port_g_update(x49gp_t *x49gp, int column, int row, unsigned char colu
|
||||||
case 3: /* Reserved */
|
case 3: /* Reserved */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_io_port_f_set_bit( x49gp_t* x49gp, int n, uint32_t value )
|
||||||
s3c2410_io_port_f_set_bit(x49gp_t *x49gp, int n, uint32_t value)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
|
s3c2410_io_port_t* io = x49gp->s3c2410_io_port;
|
||||||
uint32_t change;
|
uint32_t change;
|
||||||
|
@ -530,8 +496,7 @@ out:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_io_port_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = module->user_data;
|
s3c2410_io_port_t* io = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -548,16 +513,14 @@ s3c2410_io_port_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_io_port_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = module->user_data;
|
s3c2410_io_port_t* io = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -579,8 +542,7 @@ s3c2410_io_port_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_io_port_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io = module->user_data;
|
s3c2410_io_port_t* io = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -611,22 +573,11 @@ s3c2410_io_port_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_io_port_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_io_port_readfn[] = { s3c2410_io_port_read, s3c2410_io_port_read, s3c2410_io_port_read };
|
||||||
{
|
|
||||||
s3c2410_io_port_read,
|
|
||||||
s3c2410_io_port_read,
|
|
||||||
s3c2410_io_port_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_io_port_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_io_port_writefn[] = { s3c2410_io_port_write, s3c2410_io_port_write, s3c2410_io_port_write };
|
||||||
{
|
|
||||||
s3c2410_io_port_write,
|
|
||||||
s3c2410_io_port_write,
|
|
||||||
s3c2410_io_port_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_init( x49gp_module_t* module )
|
||||||
s3c2410_io_port_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io;
|
s3c2410_io_port_t* io;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -637,8 +588,7 @@ s3c2410_io_port_init(x49gp_module_t *module)
|
||||||
|
|
||||||
io = malloc( sizeof( s3c2410_io_port_t ) );
|
io = malloc( sizeof( s3c2410_io_port_t ) );
|
||||||
if ( NULL == io ) {
|
if ( NULL == io ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_io_port_data_init( io ) ) {
|
if ( s3c2410_io_port_data_init( io ) ) {
|
||||||
|
@ -650,8 +600,7 @@ s3c2410_io_port_init(x49gp_module_t *module)
|
||||||
module->x49gp->s3c2410_io_port = io;
|
module->x49gp->s3c2410_io_port = io;
|
||||||
io->x49gp = module->x49gp;
|
io->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_io_port_readfn,
|
iotype = cpu_register_io_memory( s3c2410_io_port_readfn, s3c2410_io_port_writefn, io );
|
||||||
s3c2410_io_port_writefn, io);
|
|
||||||
#ifdef DEBUG_S3C2410_IO_PORT
|
#ifdef DEBUG_S3C2410_IO_PORT
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -659,8 +608,7 @@ s3c2410_io_port_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_io_port_exit( x49gp_module_t* module )
|
||||||
s3c2410_io_port_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_io_port_t* io;
|
s3c2410_io_port_t* io;
|
||||||
|
|
||||||
|
@ -681,18 +629,12 @@ s3c2410_io_port_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_io_port_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_io_port_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-io-port",
|
if ( x49gp_module_init( x49gp, "s3c2410-io-port", s3c2410_io_port_init, s3c2410_io_port_exit, s3c2410_io_port_reset,
|
||||||
s3c2410_io_port_init,
|
s3c2410_io_port_load, s3c2410_io_port_save, NULL, &module ) ) {
|
||||||
s3c2410_io_port_exit,
|
|
||||||
s3c2410_io_port_reset,
|
|
||||||
s3c2410_io_port_load,
|
|
||||||
s3c2410_io_port_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
#include "x49gp_ui.h"
|
#include "x49gp_ui.h"
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t lcdcon1;
|
uint32_t lcdcon1;
|
||||||
uint32_t lcdcon2;
|
uint32_t lcdcon2;
|
||||||
|
@ -42,36 +41,24 @@ typedef struct {
|
||||||
x49gp_t* x49gp;
|
x49gp_t* x49gp;
|
||||||
} s3c2410_lcd_t;
|
} s3c2410_lcd_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_lcd_data_init( s3c2410_lcd_t* lcd )
|
||||||
s3c2410_lcd_data_init(s3c2410_lcd_t *lcd)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(LCD, LCDCON1, 0x00000000, lcd->lcdcon1),
|
S3C2410_OFFSET( LCD, LCDCON1, 0x00000000, lcd->lcdcon1 ), S3C2410_OFFSET( LCD, LCDCON2, 0x00000000, lcd->lcdcon2 ),
|
||||||
S3C2410_OFFSET(LCD, LCDCON2, 0x00000000, lcd->lcdcon2),
|
S3C2410_OFFSET( LCD, LCDCON3, 0x00000000, lcd->lcdcon3 ), S3C2410_OFFSET( LCD, LCDCON4, 0x00000000, lcd->lcdcon4 ),
|
||||||
S3C2410_OFFSET(LCD, LCDCON3, 0x00000000, lcd->lcdcon3),
|
S3C2410_OFFSET( LCD, LCDCON5, 0x00000000, lcd->lcdcon5 ), S3C2410_OFFSET( LCD, LCDSADDR1, 0x00000000, lcd->lcdsaddr1 ),
|
||||||
S3C2410_OFFSET(LCD, LCDCON4, 0x00000000, lcd->lcdcon4),
|
S3C2410_OFFSET( LCD, LCDSADDR2, 0x00000000, lcd->lcdsaddr2 ), S3C2410_OFFSET( LCD, LCDSADDR3, 0x00000000, lcd->lcdsaddr3 ),
|
||||||
S3C2410_OFFSET(LCD, LCDCON5, 0x00000000, lcd->lcdcon5),
|
S3C2410_OFFSET( LCD, REDLUT, 0x00000000, lcd->redlut ), S3C2410_OFFSET( LCD, GREENLUT, 0x00000000, lcd->greenlut ),
|
||||||
S3C2410_OFFSET(LCD, LCDSADDR1, 0x00000000, lcd->lcdsaddr1),
|
S3C2410_OFFSET( LCD, BLUELUT, 0x00000000, lcd->bluelut ), S3C2410_OFFSET( LCD, DITHMODE, 0x00000000, lcd->dithmode ),
|
||||||
S3C2410_OFFSET(LCD, LCDSADDR2, 0x00000000, lcd->lcdsaddr2),
|
S3C2410_OFFSET( LCD, TPAL, 0x00000000, lcd->tpal ), S3C2410_OFFSET( LCD, LCDINTPND, 0x00000000, lcd->lcdintpnd ),
|
||||||
S3C2410_OFFSET(LCD, LCDSADDR3, 0x00000000, lcd->lcdsaddr3),
|
S3C2410_OFFSET( LCD, LCDSRCPND, 0x00000000, lcd->lcdsrcpnd ), S3C2410_OFFSET( LCD, LCDINTMSK, 0x00000003, lcd->lcdintmsk ),
|
||||||
S3C2410_OFFSET(LCD, REDLUT, 0x00000000, lcd->redlut),
|
S3C2410_OFFSET( LCD, LPCSEL, 0x00000004, lcd->lpcsel ), S3C2410_OFFSET( LCD, UNKNOWN_68, 0x00000000, lcd->__unknown_68 ) };
|
||||||
S3C2410_OFFSET(LCD, GREENLUT, 0x00000000, lcd->greenlut),
|
|
||||||
S3C2410_OFFSET(LCD, BLUELUT, 0x00000000, lcd->bluelut),
|
|
||||||
S3C2410_OFFSET(LCD, DITHMODE, 0x00000000, lcd->dithmode),
|
|
||||||
S3C2410_OFFSET(LCD, TPAL, 0x00000000, lcd->tpal),
|
|
||||||
S3C2410_OFFSET(LCD, LCDINTPND, 0x00000000, lcd->lcdintpnd),
|
|
||||||
S3C2410_OFFSET(LCD, LCDSRCPND, 0x00000000, lcd->lcdsrcpnd),
|
|
||||||
S3C2410_OFFSET(LCD, LCDINTMSK, 0x00000003, lcd->lcdintmsk),
|
|
||||||
S3C2410_OFFSET(LCD, LPCSEL, 0x00000004, lcd->lpcsel),
|
|
||||||
S3C2410_OFFSET(LCD, UNKNOWN_68, 0x00000000, lcd->__unknown_68)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( lcd, 0, sizeof( s3c2410_lcd_t ) );
|
memset( lcd, 0, sizeof( s3c2410_lcd_t ) );
|
||||||
|
|
||||||
lcd->regs = malloc( sizeof( regs ) );
|
lcd->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == lcd->regs ) {
|
if ( NULL == lcd->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,17 +68,14 @@ s3c2410_lcd_data_init(s3c2410_lcd_t *lcd)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_schedule_lcd_update( x49gp_t* x49gp )
|
||||||
x49gp_schedule_lcd_update(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
if ( !x49gp_timer_pending( x49gp->lcd_timer ) ) {
|
if ( !x49gp_timer_pending( x49gp->lcd_timer ) ) {
|
||||||
x49gp_mod_timer(x49gp->lcd_timer,
|
x49gp_mod_timer( x49gp->lcd_timer, x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL );
|
||||||
x49gp_get_clock() + X49GP_LCD_REFRESH_INTERVAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int x49gp_get_pixel_color( s3c2410_lcd_t* lcd, int x, int y )
|
||||||
x49gp_get_pixel_color(s3c2410_lcd_t *lcd, int x, int y)
|
|
||||||
{
|
{
|
||||||
uint32_t bank, addr, data, offset, pixel_offset;
|
uint32_t bank, addr, data, offset, pixel_offset;
|
||||||
int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5;
|
int bits_per_pixel = lcd->lcdcon5 > 2 ? 1 : 4 >> lcd->lcdcon5;
|
||||||
|
@ -116,8 +100,7 @@ x49gp_get_pixel_color(s3c2410_lcd_t *lcd, int x, int y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_lcd_update( x49gp_t* x49gp )
|
||||||
x49gp_lcd_update(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_ui_t* ui = x49gp->ui;
|
x49gp_ui_t* ui = x49gp->ui;
|
||||||
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
|
s3c2410_lcd_t* lcd = x49gp->s3c2410_lcd;
|
||||||
|
@ -126,17 +109,13 @@ x49gp_lcd_update(x49gp_t *x49gp)
|
||||||
int color, x, y;
|
int color, x, y;
|
||||||
|
|
||||||
if ( !( lcd->lcdcon1 & 1 ) ) {
|
if ( !( lcd->lcdcon1 & 1 ) ) {
|
||||||
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0],
|
gdk_draw_drawable( ui->lcd_pixmap, ui->window->style->bg_gc[ 0 ], ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0,
|
||||||
ui->bg_pixmap,
|
ui->lcd_width, ui->lcd_height );
|
||||||
ui->lcd_x_offset, ui->lcd_y_offset,
|
|
||||||
0, 0, ui->lcd_width, ui->lcd_height);
|
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
gdk_draw_drawable(ui->lcd_pixmap, ui->window->style->bg_gc[0],
|
gdk_draw_drawable( ui->lcd_pixmap, ui->window->style->bg_gc[ 0 ], ui->bg_pixmap, ui->lcd_x_offset, ui->lcd_y_offset, 0, 0,
|
||||||
ui->bg_pixmap,
|
ui->lcd_width, ui->lcd_height );
|
||||||
ui->lcd_x_offset, ui->lcd_y_offset,
|
|
||||||
0, 0, ui->lcd_width, ui->lcd_height);
|
|
||||||
|
|
||||||
color = x49gp_get_pixel_color( lcd, 131, 0 );
|
color = x49gp_get_pixel_color( lcd, 131, 0 );
|
||||||
gdk_gc_set_rgb_fg_color( ui->ann_io_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
|
gdk_gc_set_rgb_fg_color( ui->ann_io_gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
|
||||||
|
@ -168,8 +147,7 @@ x49gp_lcd_update(x49gp_t *x49gp)
|
||||||
for ( x = 0; x < ui->lcd_width / 2; x++ ) {
|
for ( x = 0; x < ui->lcd_width / 2; x++ ) {
|
||||||
color = x49gp_get_pixel_color( lcd, x, y );
|
color = x49gp_get_pixel_color( lcd, x, y );
|
||||||
gdk_gc_set_rgb_fg_color( gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
|
gdk_gc_set_rgb_fg_color( gc, &( ui->colors[ UI_COLOR_GRAYSCALE_0 + color ] ) );
|
||||||
gdk_draw_rectangle(ui->lcd_pixmap, gc, TRUE,
|
gdk_draw_rectangle( ui->lcd_pixmap, gc, TRUE, 2 * x, 2 * y + ui->lcd_top_margin, 2, 2 );
|
||||||
2 * x, 2 * y + ui->lcd_top_margin, 2, 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,9 +162,7 @@ done:
|
||||||
gdk_window_invalidate_rect( ui->lcd_canvas->window, &rect, FALSE );
|
gdk_window_invalidate_rect( ui->lcd_canvas->window, &rect, FALSE );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static uint32_t s3c2410_lcd_read( void* opaque, target_phys_addr_t offset )
|
||||||
static uint32_t
|
|
||||||
s3c2410_lcd_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd = opaque;
|
s3c2410_lcd_t* lcd = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -212,16 +188,14 @@ s3c2410_lcd_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_LCD
|
#ifdef DEBUG_S3C2410_LCD
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-lcd", S3C2410_LCD_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-lcd", S3C2410_LCD_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_lcd_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd = opaque;
|
s3c2410_lcd_t* lcd = opaque;
|
||||||
x49gp_t* x49gp = lcd->x49gp;
|
x49gp_t* x49gp = lcd->x49gp;
|
||||||
|
@ -234,9 +208,7 @@ s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( lcd, offset );
|
reg = S3C2410_OFFSET_ENTRY( lcd, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_LCD
|
#ifdef DEBUG_S3C2410_LCD
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-lcd", S3C2410_LCD_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-lcd", S3C2410_LCD_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -245,8 +217,7 @@ s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
x49gp_schedule_lcd_update( x49gp );
|
x49gp_schedule_lcd_update( x49gp );
|
||||||
}
|
}
|
||||||
|
|
||||||
lcd->lcdcon1 = (lcd->lcdcon1 & (0x3ff << 18)) |
|
lcd->lcdcon1 = ( lcd->lcdcon1 & ( 0x3ff << 18 ) ) | ( data & ~( 0x3ff << 18 ) );
|
||||||
(data & ~(0x3ff << 18));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
@ -254,9 +225,7 @@ s3c2410_lcd_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int s3c2410_lcd_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
static int
|
|
||||||
s3c2410_lcd_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd = module->user_data;
|
s3c2410_lcd_t* lcd = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -273,16 +242,14 @@ s3c2410_lcd_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_lcd_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_lcd_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd = module->user_data;
|
s3c2410_lcd_t* lcd = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -304,8 +271,7 @@ s3c2410_lcd_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_lcd_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_lcd_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd = module->user_data;
|
s3c2410_lcd_t* lcd = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -327,22 +293,11 @@ s3c2410_lcd_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_lcd_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_lcd_readfn[] = { s3c2410_lcd_read, s3c2410_lcd_read, s3c2410_lcd_read };
|
||||||
{
|
|
||||||
s3c2410_lcd_read,
|
|
||||||
s3c2410_lcd_read,
|
|
||||||
s3c2410_lcd_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_lcd_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_lcd_writefn[] = { s3c2410_lcd_write, s3c2410_lcd_write, s3c2410_lcd_write };
|
||||||
{
|
|
||||||
s3c2410_lcd_write,
|
|
||||||
s3c2410_lcd_write,
|
|
||||||
s3c2410_lcd_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_lcd_init( x49gp_module_t* module )
|
||||||
s3c2410_lcd_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd;
|
s3c2410_lcd_t* lcd;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -353,8 +308,7 @@ s3c2410_lcd_init(x49gp_module_t *module)
|
||||||
|
|
||||||
lcd = malloc( sizeof( s3c2410_lcd_t ) );
|
lcd = malloc( sizeof( s3c2410_lcd_t ) );
|
||||||
if ( NULL == lcd ) {
|
if ( NULL == lcd ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_lcd_data_init( lcd ) ) {
|
if ( s3c2410_lcd_data_init( lcd ) ) {
|
||||||
|
@ -366,8 +320,7 @@ s3c2410_lcd_init(x49gp_module_t *module)
|
||||||
module->x49gp->s3c2410_lcd = lcd;
|
module->x49gp->s3c2410_lcd = lcd;
|
||||||
lcd->x49gp = module->x49gp;
|
lcd->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_lcd_readfn,
|
iotype = cpu_register_io_memory( s3c2410_lcd_readfn, s3c2410_lcd_writefn, lcd );
|
||||||
s3c2410_lcd_writefn, lcd);
|
|
||||||
#ifdef DEBUG_S3C2410_LCD
|
#ifdef DEBUG_S3C2410_LCD
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -375,8 +328,7 @@ s3c2410_lcd_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_lcd_exit( x49gp_module_t* module )
|
||||||
s3c2410_lcd_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_lcd_t* lcd;
|
s3c2410_lcd_t* lcd;
|
||||||
|
|
||||||
|
@ -397,17 +349,11 @@ s3c2410_lcd_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_lcd_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_lcd_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-lcd",
|
if ( x49gp_module_init( x49gp, "s3c2410-lcd", s3c2410_lcd_init, s3c2410_lcd_exit, s3c2410_lcd_reset, s3c2410_lcd_load, s3c2410_lcd_save,
|
||||||
s3c2410_lcd_init,
|
|
||||||
s3c2410_lcd_exit,
|
|
||||||
s3c2410_lcd_reset,
|
|
||||||
s3c2410_lcd_load,
|
|
||||||
s3c2410_lcd_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t bwscon;
|
uint32_t bwscon;
|
||||||
uint32_t bankcon0;
|
uint32_t bankcon0;
|
||||||
|
@ -34,8 +33,7 @@ typedef struct {
|
||||||
x49gp_t* x49gp;
|
x49gp_t* x49gp;
|
||||||
} s3c2410_memc_t;
|
} s3c2410_memc_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_data_init( s3c2410_memc_t* memc )
|
||||||
s3c2410_memc_data_init(s3c2410_memc_t *memc)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET( MEMC, BWSCON, 0x00000000, memc->bwscon ),
|
S3C2410_OFFSET( MEMC, BWSCON, 0x00000000, memc->bwscon ),
|
||||||
|
@ -57,8 +55,7 @@ s3c2410_memc_data_init(s3c2410_memc_t *memc)
|
||||||
|
|
||||||
memc->regs = malloc( sizeof( regs ) );
|
memc->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == memc->regs ) {
|
if ( NULL == memc->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +65,7 @@ s3c2410_memc_data_init(s3c2410_memc_t *memc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_memc_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_memc_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc = opaque;
|
s3c2410_memc_t* memc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -81,16 +77,14 @@ s3c2410_memc_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( memc, offset );
|
reg = S3C2410_OFFSET_ENTRY( memc, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_MEMC
|
#ifdef DEBUG_S3C2410_MEMC
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-memc", S3C2410_MEMC_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-memc", S3C2410_MEMC_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_memc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_memc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc = opaque;
|
s3c2410_memc_t* memc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -102,9 +96,7 @@ s3c2410_memc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( memc, offset );
|
reg = S3C2410_OFFSET_ENTRY( memc, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_MEMC
|
#ifdef DEBUG_S3C2410_MEMC
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-memc", S3C2410_MEMC_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-memc", S3C2410_MEMC_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
@ -114,8 +106,7 @@ s3c2410_memc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_memc_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc = module->user_data;
|
s3c2410_memc_t* memc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -132,16 +123,14 @@ s3c2410_memc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_memc_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc = module->user_data;
|
s3c2410_memc_t* memc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -163,8 +152,7 @@ s3c2410_memc_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_memc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc = module->user_data;
|
s3c2410_memc_t* memc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -186,22 +174,11 @@ s3c2410_memc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_memc_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_memc_readfn[] = { s3c2410_memc_read, s3c2410_memc_read, s3c2410_memc_read };
|
||||||
{
|
|
||||||
s3c2410_memc_read,
|
|
||||||
s3c2410_memc_read,
|
|
||||||
s3c2410_memc_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_memc_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_memc_writefn[] = { s3c2410_memc_write, s3c2410_memc_write, s3c2410_memc_write };
|
||||||
{
|
|
||||||
s3c2410_memc_write,
|
|
||||||
s3c2410_memc_write,
|
|
||||||
s3c2410_memc_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_init( x49gp_module_t* module )
|
||||||
s3c2410_memc_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc;
|
s3c2410_memc_t* memc;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -212,8 +189,7 @@ s3c2410_memc_init(x49gp_module_t *module)
|
||||||
|
|
||||||
memc = malloc( sizeof( s3c2410_memc_t ) );
|
memc = malloc( sizeof( s3c2410_memc_t ) );
|
||||||
if ( NULL == memc ) {
|
if ( NULL == memc ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_memc_data_init( memc ) ) {
|
if ( s3c2410_memc_data_init( memc ) ) {
|
||||||
|
@ -224,8 +200,7 @@ s3c2410_memc_init(x49gp_module_t *module)
|
||||||
module->user_data = memc;
|
module->user_data = memc;
|
||||||
memc->x49gp = module->x49gp;
|
memc->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_memc_readfn,
|
iotype = cpu_register_io_memory( s3c2410_memc_readfn, s3c2410_memc_writefn, memc );
|
||||||
s3c2410_memc_writefn, memc);
|
|
||||||
#ifdef DEBUG_S3C2410_MEMC
|
#ifdef DEBUG_S3C2410_MEMC
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -233,8 +208,7 @@ s3c2410_memc_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_memc_exit( x49gp_module_t* module )
|
||||||
s3c2410_memc_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_memc_t* memc;
|
s3c2410_memc_t* memc;
|
||||||
|
|
||||||
|
@ -255,18 +229,12 @@ s3c2410_memc_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_memc_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_memc_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-memc",
|
if ( x49gp_module_init( x49gp, "s3c2410-memc", s3c2410_memc_init, s3c2410_memc_exit, s3c2410_memc_reset, s3c2410_memc_load,
|
||||||
s3c2410_memc_init,
|
s3c2410_memc_save, NULL, &module ) ) {
|
||||||
s3c2410_memc_exit,
|
|
||||||
s3c2410_memc_reset,
|
|
||||||
s3c2410_memc_load,
|
|
||||||
s3c2410_memc_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t nfconf;
|
uint32_t nfconf;
|
||||||
uint32_t nfcmd;
|
uint32_t nfcmd;
|
||||||
|
@ -25,25 +24,19 @@ typedef struct {
|
||||||
s3c2410_offset_t* regs;
|
s3c2410_offset_t* regs;
|
||||||
} s3c2410_nand_t;
|
} s3c2410_nand_t;
|
||||||
|
|
||||||
|
static int s3c2410_nand_data_init( s3c2410_nand_t* nand )
|
||||||
static int
|
|
||||||
s3c2410_nand_data_init(s3c2410_nand_t *nand)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(NAND, NFCONF, 0x00000000, nand->nfconf),
|
S3C2410_OFFSET( NAND, NFCONF, 0x00000000, nand->nfconf ), S3C2410_OFFSET( NAND, NFCMD, 0x00000000, nand->nfcmd ),
|
||||||
S3C2410_OFFSET(NAND, NFCMD, 0x00000000, nand->nfcmd),
|
S3C2410_OFFSET( NAND, NFADDR, 0x00000000, nand->nfaddr ), S3C2410_OFFSET( NAND, NFDATA, 0x00000000, nand->nfdata ),
|
||||||
S3C2410_OFFSET(NAND, NFADDR, 0x00000000, nand->nfaddr),
|
S3C2410_OFFSET( NAND, NFSTAT, 0x00000000, nand->nfstat ), S3C2410_OFFSET( NAND, NFECC, 0x00000000, nand->nfecc ),
|
||||||
S3C2410_OFFSET(NAND, NFDATA, 0x00000000, nand->nfdata),
|
|
||||||
S3C2410_OFFSET(NAND, NFSTAT, 0x00000000, nand->nfstat),
|
|
||||||
S3C2410_OFFSET(NAND, NFECC, 0x00000000, nand->nfecc),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
memset( nand, 0, sizeof( s3c2410_nand_t ) );
|
memset( nand, 0, sizeof( s3c2410_nand_t ) );
|
||||||
|
|
||||||
nand->regs = malloc( sizeof( regs ) );
|
nand->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == nand->regs ) {
|
if ( NULL == nand->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +46,7 @@ s3c2410_nand_data_init(s3c2410_nand_t *nand)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t s3c2410_nand_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_nand_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand = opaque;
|
s3c2410_nand_t* nand = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -66,16 +58,13 @@ s3c2410_nand_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( nand, offset );
|
reg = S3C2410_OFFSET_ENTRY( nand, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_NAND
|
#ifdef DEBUG_S3C2410_NAND
|
||||||
printf("read %s [%08x] %s [%08x] data %08x\n",
|
printf( "read %s [%08x] %s [%08x] data %08x\n", "s3c2410-nand", S3C2410_NAND_BASE, reg->name, offset, *( reg->datap ) );
|
||||||
"s3c2410-nand", S3C2410_NAND_BASE,
|
|
||||||
reg->name, offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_nand_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_nand_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand = opaque;
|
s3c2410_nand_t* nand = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -87,17 +76,13 @@ s3c2410_nand_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( nand, offset );
|
reg = S3C2410_OFFSET_ENTRY( nand, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_NAND
|
#ifdef DEBUG_S3C2410_NAND
|
||||||
printf("write %s [%08x] %s [%08x] data %08x\n",
|
printf( "write %s [%08x] %s [%08x] data %08x\n", "s3c2410-nand", S3C2410_NAND_BASE, reg->name, offset, data );
|
||||||
"s3c2410-nand", S3C2410_NAND_BASE,
|
|
||||||
reg->name, offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int s3c2410_nand_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
static int
|
|
||||||
s3c2410_nand_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand = module->user_data;
|
s3c2410_nand_t* nand = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -114,16 +99,14 @@ s3c2410_nand_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_nand_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_nand_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand = module->user_data;
|
s3c2410_nand_t* nand = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -145,8 +128,7 @@ s3c2410_nand_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_nand_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_nand_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand = module->user_data;
|
s3c2410_nand_t* nand = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -168,22 +150,11 @@ s3c2410_nand_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_nand_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_nand_readfn[] = { s3c2410_nand_read, s3c2410_nand_read, s3c2410_nand_read };
|
||||||
{
|
|
||||||
s3c2410_nand_read,
|
|
||||||
s3c2410_nand_read,
|
|
||||||
s3c2410_nand_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_nand_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_nand_writefn[] = { s3c2410_nand_write, s3c2410_nand_write, s3c2410_nand_write };
|
||||||
{
|
|
||||||
s3c2410_nand_write,
|
|
||||||
s3c2410_nand_write,
|
|
||||||
s3c2410_nand_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_nand_init( x49gp_module_t* module )
|
||||||
s3c2410_nand_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand;
|
s3c2410_nand_t* nand;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -194,8 +165,7 @@ s3c2410_nand_init(x49gp_module_t *module)
|
||||||
|
|
||||||
nand = malloc( sizeof( s3c2410_nand_t ) );
|
nand = malloc( sizeof( s3c2410_nand_t ) );
|
||||||
if ( NULL == nand ) {
|
if ( NULL == nand ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_nand_data_init( nand ) ) {
|
if ( s3c2410_nand_data_init( nand ) ) {
|
||||||
|
@ -205,8 +175,7 @@ s3c2410_nand_init(x49gp_module_t *module)
|
||||||
|
|
||||||
module->user_data = nand;
|
module->user_data = nand;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_nand_readfn,
|
iotype = cpu_register_io_memory( s3c2410_nand_readfn, s3c2410_nand_writefn, nand );
|
||||||
s3c2410_nand_writefn, nand);
|
|
||||||
#ifdef DEBUG_S3C2410_NAND
|
#ifdef DEBUG_S3C2410_NAND
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -214,8 +183,7 @@ s3c2410_nand_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_nand_exit( x49gp_module_t* module )
|
||||||
s3c2410_nand_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_nand_t* nand;
|
s3c2410_nand_t* nand;
|
||||||
|
|
||||||
|
@ -236,18 +204,12 @@ s3c2410_nand_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_nand_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_nand_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-nand",
|
if ( x49gp_module_init( x49gp, "s3c2410-nand", s3c2410_nand_init, s3c2410_nand_exit, s3c2410_nand_reset, s3c2410_nand_load,
|
||||||
s3c2410_nand_init,
|
s3c2410_nand_save, NULL, &module ) ) {
|
||||||
s3c2410_nand_exit,
|
|
||||||
s3c2410_nand_reset,
|
|
||||||
s3c2410_nand_load,
|
|
||||||
s3c2410_nand_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,24 +29,18 @@ typedef struct {
|
||||||
x49gp_t* x49gp;
|
x49gp_t* x49gp;
|
||||||
} s3c2410_power_t;
|
} s3c2410_power_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_data_init( s3c2410_power_t* power )
|
||||||
s3c2410_power_data_init(s3c2410_power_t *power)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(POWER, LOCKTIME, 0x00ffffff, power->locktime),
|
S3C2410_OFFSET( POWER, LOCKTIME, 0x00ffffff, power->locktime ), S3C2410_OFFSET( POWER, MPLLCON, 0x0005c080, power->mpllcon ),
|
||||||
S3C2410_OFFSET(POWER, MPLLCON, 0x0005c080, power->mpllcon),
|
S3C2410_OFFSET( POWER, UPLLCON, 0x00028080, power->upllcon ), S3C2410_OFFSET( POWER, CLKCON, 0x0007fff0, power->clkcon ),
|
||||||
S3C2410_OFFSET(POWER, UPLLCON, 0x00028080, power->upllcon),
|
S3C2410_OFFSET( POWER, CLKSLOW, 0x00000004, power->clkslow ), S3C2410_OFFSET( POWER, CLKDIVN, 0x00000000, power->clkdivn ) };
|
||||||
S3C2410_OFFSET(POWER, CLKCON, 0x0007fff0, power->clkcon),
|
|
||||||
S3C2410_OFFSET(POWER, CLKSLOW, 0x00000004, power->clkslow),
|
|
||||||
S3C2410_OFFSET(POWER, CLKDIVN, 0x00000000, power->clkdivn)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( power, 0, sizeof( s3c2410_power_t ) );
|
memset( power, 0, sizeof( s3c2410_power_t ) );
|
||||||
|
|
||||||
power->regs = malloc( sizeof( regs ) );
|
power->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == power->regs ) {
|
if ( NULL == power->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,8 +50,7 @@ s3c2410_power_data_init(s3c2410_power_t *power)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_power_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_power_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power = opaque;
|
s3c2410_power_t* power = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -69,16 +62,14 @@ s3c2410_power_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( power, offset );
|
reg = S3C2410_OFFSET_ENTRY( power, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_POWER
|
#ifdef DEBUG_S3C2410_POWER
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-power", S3C2410_POWER_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-power", S3C2410_POWER_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_power_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_power_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power = opaque;
|
s3c2410_power_t* power = opaque;
|
||||||
x49gp_t* x49gp = power->x49gp;
|
x49gp_t* x49gp = power->x49gp;
|
||||||
|
@ -94,9 +85,7 @@ s3c2410_power_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( power, offset );
|
reg = S3C2410_OFFSET_ENTRY( power, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_POWER
|
#ifdef DEBUG_S3C2410_POWER
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-power", S3C2410_POWER_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-power", S3C2410_POWER_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -189,19 +178,14 @@ s3c2410_power_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_POWER
|
#ifdef DEBUG_S3C2410_POWER
|
||||||
printf("%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: MCLK %u\n",
|
printf( "%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: MCLK %u\n", __FUNCTION__, EXTCLK, mMdiv, mPdiv, mSdiv, x49gp->MCLK );
|
||||||
__FUNCTION__, EXTCLK, mMdiv, mPdiv, mSdiv, x49gp->MCLK);
|
printf( "%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: UCLK %u\n", __FUNCTION__, EXTCLK, uMdiv, uPdiv, uSdiv, x49gp->UCLK );
|
||||||
printf("%s: EXTCLK %u, mdiv %u, pdiv %u, sdiv %u: UCLK %u\n",
|
printf( "%s: FCLK %s: %u\n", __FUNCTION__, slow_bit ? "(slow)" : "", x49gp->FCLK );
|
||||||
__FUNCTION__, EXTCLK, uMdiv, uPdiv, uSdiv, x49gp->UCLK);
|
printf( "%s: HCLK %u, PCLK %u\n", __FUNCTION__, x49gp->HCLK, x49gp->PCLK );
|
||||||
printf("%s: FCLK %s: %u\n",
|
|
||||||
__FUNCTION__, slow_bit ? "(slow)" : "", x49gp->FCLK);
|
|
||||||
printf("%s: HCLK %u, PCLK %u\n",
|
|
||||||
__FUNCTION__, x49gp->HCLK, x49gp->PCLK);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_power_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power = module->user_data;
|
s3c2410_power_t* power = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -218,8 +202,7 @@ s3c2410_power_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,13 +210,11 @@ s3c2410_power_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
s3c2410_power_write(power, S3C2410_POWER_BASE | S3C2410_POWER_CLKDIVN,
|
s3c2410_power_write( power, S3C2410_POWER_BASE | S3C2410_POWER_CLKDIVN, power->clkdivn );
|
||||||
power->clkdivn);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_power_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power = module->user_data;
|
s3c2410_power_t* power = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -255,8 +236,7 @@ s3c2410_power_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_power_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power = module->user_data;
|
s3c2410_power_t* power = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -278,22 +258,11 @@ s3c2410_power_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_power_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_power_readfn[] = { s3c2410_power_read, s3c2410_power_read, s3c2410_power_read };
|
||||||
{
|
|
||||||
s3c2410_power_read,
|
|
||||||
s3c2410_power_read,
|
|
||||||
s3c2410_power_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_power_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_power_writefn[] = { s3c2410_power_write, s3c2410_power_write, s3c2410_power_write };
|
||||||
{
|
|
||||||
s3c2410_power_write,
|
|
||||||
s3c2410_power_write,
|
|
||||||
s3c2410_power_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_init( x49gp_module_t* module )
|
||||||
s3c2410_power_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power;
|
s3c2410_power_t* power;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -304,8 +273,7 @@ s3c2410_power_init(x49gp_module_t *module)
|
||||||
|
|
||||||
power = malloc( sizeof( s3c2410_power_t ) );
|
power = malloc( sizeof( s3c2410_power_t ) );
|
||||||
if ( NULL == power ) {
|
if ( NULL == power ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_power_data_init( power ) ) {
|
if ( s3c2410_power_data_init( power ) ) {
|
||||||
|
@ -316,8 +284,7 @@ s3c2410_power_init(x49gp_module_t *module)
|
||||||
module->user_data = power;
|
module->user_data = power;
|
||||||
power->x49gp = module->x49gp;
|
power->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_power_readfn,
|
iotype = cpu_register_io_memory( s3c2410_power_readfn, s3c2410_power_writefn, power );
|
||||||
s3c2410_power_writefn, power);
|
|
||||||
#ifdef DEBUG_S3C2410_POWER
|
#ifdef DEBUG_S3C2410_POWER
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -325,8 +292,7 @@ s3c2410_power_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_power_exit( x49gp_module_t* module )
|
||||||
s3c2410_power_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_power_t* power;
|
s3c2410_power_t* power;
|
||||||
|
|
||||||
|
@ -347,18 +313,12 @@ s3c2410_power_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_power_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_power_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-power",
|
if ( x49gp_module_init( x49gp, "s3c2410-power", s3c2410_power_init, s3c2410_power_exit, s3c2410_power_reset, s3c2410_power_load,
|
||||||
s3c2410_power_init,
|
s3c2410_power_save, NULL, &module ) ) {
|
||||||
s3c2410_power_exit,
|
|
||||||
s3c2410_power_reset,
|
|
||||||
s3c2410_power_load,
|
|
||||||
s3c2410_power_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t rtccon;
|
uint32_t rtccon;
|
||||||
uint32_t ticnt;
|
uint32_t ticnt;
|
||||||
|
@ -44,36 +43,23 @@ typedef struct {
|
||||||
int64_t expires; /* us */
|
int64_t expires; /* us */
|
||||||
} s3c2410_rtc_t;
|
} s3c2410_rtc_t;
|
||||||
|
|
||||||
|
static int s3c2410_rtc_data_init( s3c2410_rtc_t* rtc )
|
||||||
static int
|
|
||||||
s3c2410_rtc_data_init(s3c2410_rtc_t *rtc)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = { S3C2410_OFFSET( RTC, RTCCON, 0x00, rtc->rtccon ), S3C2410_OFFSET( RTC, TICNT, 0x00, rtc->ticnt ),
|
||||||
S3C2410_OFFSET(RTC, RTCCON, 0x00, rtc->rtccon),
|
S3C2410_OFFSET( RTC, RTCALM, 0x00, rtc->rtcalm ), S3C2410_OFFSET( RTC, ALMSEC, 0x00, rtc->almsec ),
|
||||||
S3C2410_OFFSET(RTC, TICNT, 0x00, rtc->ticnt),
|
S3C2410_OFFSET( RTC, ALMMIN, 0x00, rtc->almmin ), S3C2410_OFFSET( RTC, ALMHOUR, 0x00, rtc->almhour ),
|
||||||
S3C2410_OFFSET(RTC, RTCALM, 0x00, rtc->rtcalm),
|
S3C2410_OFFSET( RTC, ALMDATE, 0x01, rtc->almdate ), S3C2410_OFFSET( RTC, ALMMON, 0x01, rtc->almmon ),
|
||||||
S3C2410_OFFSET(RTC, ALMSEC, 0x00, rtc->almsec),
|
S3C2410_OFFSET( RTC, ALMYEAR, 0x00, rtc->almyear ), S3C2410_OFFSET( RTC, RTCRST, 0x00, rtc->rtcrst ),
|
||||||
S3C2410_OFFSET(RTC, ALMMIN, 0x00, rtc->almmin),
|
S3C2410_OFFSET( RTC, BCDSEC, 0, rtc->bcdsec ), S3C2410_OFFSET( RTC, BCDMIN, 0, rtc->bcdmin ),
|
||||||
S3C2410_OFFSET(RTC, ALMHOUR, 0x00, rtc->almhour),
|
S3C2410_OFFSET( RTC, BCDHOUR, 0, rtc->bcdhour ), S3C2410_OFFSET( RTC, BCDDATE, 0, rtc->bcddate ),
|
||||||
S3C2410_OFFSET(RTC, ALMDATE, 0x01, rtc->almdate),
|
S3C2410_OFFSET( RTC, BCDDAY, 0, rtc->bcdday ), S3C2410_OFFSET( RTC, BCDMON, 0, rtc->bcdmon ),
|
||||||
S3C2410_OFFSET(RTC, ALMMON, 0x01, rtc->almmon),
|
S3C2410_OFFSET( RTC, BCDYEAR, 0, rtc->bcdyear ) };
|
||||||
S3C2410_OFFSET(RTC, ALMYEAR, 0x00, rtc->almyear),
|
|
||||||
S3C2410_OFFSET(RTC, RTCRST, 0x00, rtc->rtcrst),
|
|
||||||
S3C2410_OFFSET(RTC, BCDSEC, 0, rtc->bcdsec),
|
|
||||||
S3C2410_OFFSET(RTC, BCDMIN, 0, rtc->bcdmin),
|
|
||||||
S3C2410_OFFSET(RTC, BCDHOUR, 0, rtc->bcdhour),
|
|
||||||
S3C2410_OFFSET(RTC, BCDDATE, 0, rtc->bcddate),
|
|
||||||
S3C2410_OFFSET(RTC, BCDDAY, 0, rtc->bcdday),
|
|
||||||
S3C2410_OFFSET(RTC, BCDMON, 0, rtc->bcdmon),
|
|
||||||
S3C2410_OFFSET(RTC, BCDYEAR, 0, rtc->bcdyear)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( rtc, 0, sizeof( s3c2410_rtc_t ) );
|
memset( rtc, 0, sizeof( s3c2410_rtc_t ) );
|
||||||
|
|
||||||
rtc->regs = malloc( sizeof( regs ) );
|
rtc->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == rtc->regs ) {
|
if ( NULL == rtc->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,18 +69,11 @@ s3c2410_rtc_data_init(s3c2410_rtc_t *rtc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static __inline__ uint32_t bin2bcd(uint32_t bin)
|
static __inline__ uint32_t bin2bcd( uint32_t bin ) { return ( ( bin / 10 ) << 4 ) | ( bin % 10 ); }
|
||||||
{
|
|
||||||
return ((bin / 10) << 4) | (bin % 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
static __inline__ uint32_t bcd2bin(uint32_t bcd)
|
static __inline__ uint32_t bcd2bin( uint32_t bcd ) { return ( ( bcd >> 4 ) * 10 ) + ( bcd & 0x0f ); }
|
||||||
{
|
|
||||||
return ((bcd >> 4) * 10) + (bcd & 0x0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void s3c2410_rtc_timeout( void* user_data )
|
||||||
s3c2410_rtc_timeout(void * user_data)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = user_data;
|
s3c2410_rtc_t* rtc = user_data;
|
||||||
x49gp_t* x49gp = rtc->x49gp;
|
x49gp_t* x49gp = rtc->x49gp;
|
||||||
|
@ -126,8 +105,7 @@ s3c2410_rtc_timeout(void * user_data)
|
||||||
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
|
x49gp_mod_timer( rtc->tick_timer, rtc->expires );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_set_ticnt( s3c2410_rtc_t* rtc )
|
||||||
s3c2410_rtc_set_ticnt(s3c2410_rtc_t *rtc)
|
|
||||||
{
|
{
|
||||||
int64_t now, us;
|
int64_t now, us;
|
||||||
|
|
||||||
|
@ -163,8 +141,7 @@ s3c2410_rtc_set_ticnt(s3c2410_rtc_t *rtc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_rtc_alarm( void* user_data )
|
||||||
s3c2410_rtc_alarm(void * user_data)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = user_data;
|
s3c2410_rtc_t* rtc = user_data;
|
||||||
x49gp_t* x49gp = rtc->x49gp;
|
x49gp_t* x49gp = rtc->x49gp;
|
||||||
|
@ -222,8 +199,7 @@ s3c2410_rtc_alarm(void * user_data)
|
||||||
x49gp_mod_timer( rtc->alarm_timer, now + us );
|
x49gp_mod_timer( rtc->alarm_timer, now + us );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_set_rtcalm( s3c2410_rtc_t* rtc )
|
||||||
s3c2410_rtc_set_rtcalm(s3c2410_rtc_t *rtc)
|
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int64_t now, us;
|
int64_t now, us;
|
||||||
|
@ -246,8 +222,7 @@ s3c2410_rtc_set_rtcalm(s3c2410_rtc_t *rtc)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_rtc_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_rtc_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = opaque;
|
s3c2410_rtc_t* rtc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -291,16 +266,14 @@ s3c2410_rtc_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_RTC
|
#ifdef DEBUG_S3C2410_RTC
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-rtc", S3C2410_RTC_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_rtc_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = opaque;
|
s3c2410_rtc_t* rtc = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -312,9 +285,7 @@ s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
|
reg = S3C2410_OFFSET_ENTRY( rtc, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_RTC
|
#ifdef DEBUG_S3C2410_RTC
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-rtc", S3C2410_RTC_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-rtc", S3C2410_RTC_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -332,8 +303,7 @@ s3c2410_rtc_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = module->user_data;
|
s3c2410_rtc_t* rtc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -350,8 +320,7 @@ s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,8 +330,7 @@ s3c2410_rtc_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_rtc_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = module->user_data;
|
s3c2410_rtc_t* rtc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -384,8 +352,7 @@ s3c2410_rtc_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_rtc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc = module->user_data;
|
s3c2410_rtc_t* rtc = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -409,22 +376,11 @@ s3c2410_rtc_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_rtc_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_rtc_readfn[] = { s3c2410_rtc_read, s3c2410_rtc_read, s3c2410_rtc_read };
|
||||||
{
|
|
||||||
s3c2410_rtc_read,
|
|
||||||
s3c2410_rtc_read,
|
|
||||||
s3c2410_rtc_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_rtc_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_rtc_writefn[] = { s3c2410_rtc_write, s3c2410_rtc_write, s3c2410_rtc_write };
|
||||||
{
|
|
||||||
s3c2410_rtc_write,
|
|
||||||
s3c2410_rtc_write,
|
|
||||||
s3c2410_rtc_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_init( x49gp_module_t* module )
|
||||||
s3c2410_rtc_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc;
|
s3c2410_rtc_t* rtc;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -435,8 +391,7 @@ s3c2410_rtc_init(x49gp_module_t *module)
|
||||||
|
|
||||||
rtc = malloc( sizeof( s3c2410_rtc_t ) );
|
rtc = malloc( sizeof( s3c2410_rtc_t ) );
|
||||||
if ( NULL == rtc ) {
|
if ( NULL == rtc ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
|
||||||
module->x49gp->progname, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_rtc_data_init( rtc ) ) {
|
if ( s3c2410_rtc_data_init( rtc ) ) {
|
||||||
|
@ -447,13 +402,10 @@ s3c2410_rtc_init(x49gp_module_t *module)
|
||||||
module->user_data = rtc;
|
module->user_data = rtc;
|
||||||
rtc->x49gp = module->x49gp;
|
rtc->x49gp = module->x49gp;
|
||||||
|
|
||||||
rtc->tick_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
|
rtc->tick_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_timeout, rtc );
|
||||||
s3c2410_rtc_timeout, rtc);
|
rtc->alarm_timer = x49gp_new_timer( X49GP_TIMER_REALTIME, s3c2410_rtc_alarm, rtc );
|
||||||
rtc->alarm_timer = x49gp_new_timer(X49GP_TIMER_REALTIME,
|
|
||||||
s3c2410_rtc_alarm, rtc);
|
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_rtc_readfn,
|
iotype = cpu_register_io_memory( s3c2410_rtc_readfn, s3c2410_rtc_writefn, rtc );
|
||||||
s3c2410_rtc_writefn, rtc);
|
|
||||||
#ifdef DEBUG_S3C2410_RTC
|
#ifdef DEBUG_S3C2410_RTC
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -462,8 +414,7 @@ s3c2410_rtc_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_rtc_exit( x49gp_module_t* module )
|
||||||
s3c2410_rtc_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_rtc_t* rtc;
|
s3c2410_rtc_t* rtc;
|
||||||
|
|
||||||
|
@ -484,17 +435,11 @@ s3c2410_rtc_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_rtc_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_rtc_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-rtc",
|
if ( x49gp_module_init( x49gp, "s3c2410-rtc", s3c2410_rtc_init, s3c2410_rtc_exit, s3c2410_rtc_reset, s3c2410_rtc_load, s3c2410_rtc_save,
|
||||||
s3c2410_rtc_init,
|
|
||||||
s3c2410_rtc_exit,
|
|
||||||
s3c2410_rtc_reset,
|
|
||||||
s3c2410_rtc_load,
|
|
||||||
s3c2410_rtc_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
// #define DEBUG_S3C2410_SDI 1
|
// #define DEBUG_S3C2410_SDI 1
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t sdicon;
|
uint32_t sdicon;
|
||||||
uint32_t sdipre;
|
uint32_t sdipre;
|
||||||
|
@ -61,36 +60,24 @@ typedef struct {
|
||||||
int card_state;
|
int card_state;
|
||||||
} s3c2410_sdi_t;
|
} s3c2410_sdi_t;
|
||||||
|
|
||||||
|
static int s3c2410_sdi_data_init( s3c2410_sdi_t* sdi )
|
||||||
static int
|
|
||||||
s3c2410_sdi_data_init(s3c2410_sdi_t *sdi)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = {
|
||||||
S3C2410_OFFSET(SDI, SDICON, 0x00000000, sdi->sdicon),
|
S3C2410_OFFSET( SDI, SDICON, 0x00000000, sdi->sdicon ), S3C2410_OFFSET( SDI, SDIPRE, 0x00000000, sdi->sdipre ),
|
||||||
S3C2410_OFFSET(SDI, SDIPRE, 0x00000000, sdi->sdipre),
|
S3C2410_OFFSET( SDI, SDICARG, 0x00000000, sdi->sdicarg ), S3C2410_OFFSET( SDI, SDICCON, 0x00000000, sdi->sdiccon ),
|
||||||
S3C2410_OFFSET(SDI, SDICARG, 0x00000000, sdi->sdicarg),
|
S3C2410_OFFSET( SDI, SDICSTA, 0x00000000, sdi->sdicsta ), S3C2410_OFFSET( SDI, SDIRSP0, 0x00000000, sdi->sdirsp0 ),
|
||||||
S3C2410_OFFSET(SDI, SDICCON, 0x00000000, sdi->sdiccon),
|
S3C2410_OFFSET( SDI, SDIRSP1, 0x00000000, sdi->sdirsp1 ), S3C2410_OFFSET( SDI, SDIRSP2, 0x00000000, sdi->sdirsp2 ),
|
||||||
S3C2410_OFFSET(SDI, SDICSTA, 0x00000000, sdi->sdicsta),
|
S3C2410_OFFSET( SDI, SDIRSP3, 0x00000000, sdi->sdirsp3 ), S3C2410_OFFSET( SDI, SDIDTIMER, 0x00002000, sdi->sdidtimer ),
|
||||||
S3C2410_OFFSET(SDI, SDIRSP0, 0x00000000, sdi->sdirsp0),
|
S3C2410_OFFSET( SDI, SDIBSIZE, 0x00000000, sdi->sdibsize ), S3C2410_OFFSET( SDI, SDIDCON, 0x00000000, sdi->sdidcon ),
|
||||||
S3C2410_OFFSET(SDI, SDIRSP1, 0x00000000, sdi->sdirsp1),
|
S3C2410_OFFSET( SDI, SDIDCNT, 0x00000000, sdi->sdidcnt ), S3C2410_OFFSET( SDI, SDIDSTA, 0x00000000, sdi->sdidsta ),
|
||||||
S3C2410_OFFSET(SDI, SDIRSP2, 0x00000000, sdi->sdirsp2),
|
S3C2410_OFFSET( SDI, SDIFSTA, 0x00000000, sdi->sdifsta ), S3C2410_OFFSET( SDI, SDIDAT, 0x00000000, sdi->sdidat ),
|
||||||
S3C2410_OFFSET(SDI, SDIRSP3, 0x00000000, sdi->sdirsp3),
|
S3C2410_OFFSET( SDI, SDIIMSK, 0x00000000, sdi->sdiimsk ) };
|
||||||
S3C2410_OFFSET(SDI, SDIDTIMER, 0x00002000, sdi->sdidtimer),
|
|
||||||
S3C2410_OFFSET(SDI, SDIBSIZE, 0x00000000, sdi->sdibsize),
|
|
||||||
S3C2410_OFFSET(SDI, SDIDCON, 0x00000000, sdi->sdidcon),
|
|
||||||
S3C2410_OFFSET(SDI, SDIDCNT, 0x00000000, sdi->sdidcnt),
|
|
||||||
S3C2410_OFFSET(SDI, SDIDSTA, 0x00000000, sdi->sdidsta),
|
|
||||||
S3C2410_OFFSET(SDI, SDIFSTA, 0x00000000, sdi->sdifsta),
|
|
||||||
S3C2410_OFFSET(SDI, SDIDAT, 0x00000000, sdi->sdidat),
|
|
||||||
S3C2410_OFFSET(SDI, SDIIMSK, 0x00000000, sdi->sdiimsk)
|
|
||||||
};
|
|
||||||
|
|
||||||
memset( sdi, 0, sizeof( s3c2410_sdi_t ) );
|
memset( sdi, 0, sizeof( s3c2410_sdi_t ) );
|
||||||
|
|
||||||
sdi->regs = malloc( sizeof( regs ) );
|
sdi->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == sdi->regs ) {
|
if ( NULL == sdi->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,8 +87,7 @@ s3c2410_sdi_data_init(s3c2410_sdi_t *sdi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sdcard_read( s3c2410_sdi_t* sdi )
|
||||||
sdcard_read(s3c2410_sdi_t *sdi)
|
|
||||||
{
|
{
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
@ -151,8 +137,7 @@ sdcard_read(s3c2410_sdi_t *sdi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sdcard_write_prepare( s3c2410_sdi_t* sdi )
|
||||||
sdcard_write_prepare(s3c2410_sdi_t *sdi)
|
|
||||||
{
|
{
|
||||||
sdi->write_index = 0;
|
sdi->write_index = 0;
|
||||||
|
|
||||||
|
@ -170,8 +155,7 @@ sdcard_write_prepare(s3c2410_sdi_t *sdi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sdcard_write( s3c2410_sdi_t* sdi )
|
||||||
sdcard_write(s3c2410_sdi_t *sdi)
|
|
||||||
{
|
{
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
@ -217,8 +201,7 @@ sdcard_write(s3c2410_sdi_t *sdi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_sdi_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_sdi_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = opaque;
|
s3c2410_sdi_t* sdi = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -250,7 +233,8 @@ s3c2410_sdi_read(void *opaque, target_phys_addr_t offset)
|
||||||
sdi->read_index = 0;
|
sdi->read_index = 0;
|
||||||
free( sdi->read_data );
|
free( sdi->read_data );
|
||||||
sdi->read_data = NULL;
|
sdi->read_data = NULL;
|
||||||
if(sdi->multiple_block) --sdi->multiple_block;
|
if ( sdi->multiple_block )
|
||||||
|
--sdi->multiple_block;
|
||||||
if ( sdi->multiple_block ) {
|
if ( sdi->multiple_block ) {
|
||||||
sdi->read_offset += sdi->nr_read_data;
|
sdi->read_offset += sdi->nr_read_data;
|
||||||
|
|
||||||
|
@ -266,8 +250,8 @@ s3c2410_sdi_read(void *opaque, target_phys_addr_t offset)
|
||||||
read_avail = sdi->nr_read_data - sdi->read_index;
|
read_avail = sdi->nr_read_data - sdi->read_index;
|
||||||
|
|
||||||
sdi->sdidcnt = read_avail;
|
sdi->sdidcnt = read_avail;
|
||||||
}
|
} else
|
||||||
else *(reg->datap)=0;
|
*( reg->datap ) = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -301,16 +285,14 @@ s3c2410_sdi_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_SDI
|
#ifdef DEBUG_S3C2410_SDI
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-sdi", S3C2410_SDI_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-sdi", S3C2410_SDI_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_sdi_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = opaque;
|
s3c2410_sdi_t* sdi = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -323,9 +305,7 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( sdi, offset );
|
reg = S3C2410_OFFSET_ENTRY( sdi, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_SDI
|
#ifdef DEBUG_S3C2410_SDI
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-sdi", S3C2410_SDI_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-sdi", S3C2410_SDI_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -337,11 +317,8 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_SDI
|
#ifdef DEBUG_S3C2410_SDI
|
||||||
printf("SDI: cmd %02u, start %u, %s response %u, data %u, abort %u\n",
|
printf( "SDI: cmd %02u, start %u, %s response %u, data %u, abort %u\n", data & 0x3f, ( data >> 8 ) & 1,
|
||||||
data & 0x3f, (data >> 8) & 1,
|
( data >> 10 ) & 1 ? "long" : "short", ( data >> 9 ) & 1, ( data >> 11 ) & 1, ( data >> 12 ) & 1 );
|
||||||
(data >> 10) & 1 ? "long" : "short",
|
|
||||||
(data >> 9) & 1,
|
|
||||||
(data >> 11) & 1, (data >> 12) & 1);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( data & ( 1 << 8 ) ) {
|
if ( data & ( 1 << 8 ) ) {
|
||||||
|
@ -387,8 +364,10 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
sdi->card_state = 3;
|
sdi->card_state = 3;
|
||||||
sdi->sdicsta |= 3;
|
sdi->sdicsta |= 3;
|
||||||
sdi->sdirsp0 = sdi->card_state << 9;
|
sdi->sdirsp0 = sdi->card_state << 9;
|
||||||
if(sdi->card_state==5) sdi->sdirsp0 |=0x100;
|
if ( sdi->card_state == 5 )
|
||||||
if(sdi->acmd) sdi->sdirsp0|=0x20;
|
sdi->sdirsp0 |= 0x100;
|
||||||
|
if ( sdi->acmd )
|
||||||
|
sdi->sdirsp0 |= 0x20;
|
||||||
sdi->sdirsp0 |= 0x12340000; // PUBLISHED RCA NUMBER
|
sdi->sdirsp0 |= 0x12340000; // PUBLISHED RCA NUMBER
|
||||||
sdi->sdirsp1 = 0xff000000;
|
sdi->sdirsp1 = 0xff000000;
|
||||||
break;
|
break;
|
||||||
|
@ -451,8 +430,10 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
sdi->sdicsta |= 16;
|
sdi->sdicsta |= 16;
|
||||||
sdi->sdicsta |= data & 0x3f;
|
sdi->sdicsta |= data & 0x3f;
|
||||||
sdi->sdirsp0 = sdi->card_state << 9;
|
sdi->sdirsp0 = sdi->card_state << 9;
|
||||||
if(sdi->card_state==5) sdi->sdirsp0 |=0x100;
|
if ( sdi->card_state == 5 )
|
||||||
if(sdi->acmd) sdi->sdirsp0|=0x20;
|
sdi->sdirsp0 |= 0x100;
|
||||||
|
if ( sdi->acmd )
|
||||||
|
sdi->sdirsp0 |= 0x20;
|
||||||
sdi->sdirsp1 = 0xff000000;
|
sdi->sdirsp1 = 0xff000000;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -476,7 +457,6 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
|
|
||||||
case 23:
|
case 23:
|
||||||
|
|
||||||
|
|
||||||
case 25:
|
case 25:
|
||||||
sdi->multiple_block = sdi->sdicarg;
|
sdi->multiple_block = sdi->sdicarg;
|
||||||
/* fall through */
|
/* fall through */
|
||||||
|
@ -498,8 +478,10 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
sdi->acmd = 1;
|
sdi->acmd = 1;
|
||||||
sdi->sdicsta |= data & 0x3f;
|
sdi->sdicsta |= data & 0x3f;
|
||||||
sdi->sdirsp0 = sdi->card_state << 9;
|
sdi->sdirsp0 = sdi->card_state << 9;
|
||||||
if(sdi->card_state==5) sdi->sdirsp0 |=0x100;
|
if ( sdi->card_state == 5 )
|
||||||
if(sdi->acmd) sdi->sdirsp0|=0x20;
|
sdi->sdirsp0 |= 0x100;
|
||||||
|
if ( sdi->acmd )
|
||||||
|
sdi->sdirsp0 |= 0x20;
|
||||||
sdi->sdirsp1 = 0xff000000;
|
sdi->sdirsp1 = 0xff000000;
|
||||||
break;
|
break;
|
||||||
case 256 + 41:
|
case 256 + 41:
|
||||||
|
@ -515,8 +497,10 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
// ACMD42
|
// ACMD42
|
||||||
sdi->sdicsta |= data & 0x3f;
|
sdi->sdicsta |= data & 0x3f;
|
||||||
sdi->sdirsp0 = sdi->card_state << 9;
|
sdi->sdirsp0 = sdi->card_state << 9;
|
||||||
if(sdi->card_state==5) sdi->sdirsp0 |=0x100;
|
if ( sdi->card_state == 5 )
|
||||||
if(sdi->acmd) sdi->sdirsp0|=0x20;
|
sdi->sdirsp0 |= 0x100;
|
||||||
|
if ( sdi->acmd )
|
||||||
|
sdi->sdirsp0 |= 0x20;
|
||||||
sdi->sdirsp1 = 0xff000000;
|
sdi->sdirsp1 = 0xff000000;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -562,7 +546,8 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
|
|
||||||
if ( sdi->write_index >= sdi->nr_write_data ) {
|
if ( sdi->write_index >= sdi->nr_write_data ) {
|
||||||
sdcard_write( sdi );
|
sdcard_write( sdi );
|
||||||
if(sdi->multiple_block) sdi->multiple_block--;
|
if ( sdi->multiple_block )
|
||||||
|
sdi->multiple_block--;
|
||||||
if ( sdi->multiple_block ) {
|
if ( sdi->multiple_block ) {
|
||||||
sdi->write_offset += sdi->nr_write_data;
|
sdi->write_offset += sdi->nr_write_data;
|
||||||
sdcard_write_prepare( sdi );
|
sdcard_write_prepare( sdi );
|
||||||
|
@ -578,7 +563,6 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
|
|
||||||
sdi->sdidcnt = write_avail;
|
sdi->sdidcnt = write_avail;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -601,8 +585,7 @@ s3c2410_sdi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_sdi_unmount( x49gp_t* x49gp )
|
||||||
s3c2410_sdi_unmount(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
||||||
|
|
||||||
|
@ -622,8 +605,7 @@ s3c2410_sdi_unmount(x49gp_t *x49gp)
|
||||||
s3c2410_io_port_f_set_bit( x49gp, 3, 0 );
|
s3c2410_io_port_f_set_bit( x49gp, 3, 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int s3c2410_sdi_mount( x49gp_t* x49gp, char* filename )
|
||||||
s3c2410_sdi_mount(x49gp_t *x49gp, char *filename)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
@ -641,10 +623,7 @@ s3c2410_sdi_mount(x49gp_t *x49gp, char *filename)
|
||||||
if ( sdi->bs ) {
|
if ( sdi->bs ) {
|
||||||
error = bdrv_open( sdi->bs, vvfat_name, 0 );
|
error = bdrv_open( sdi->bs, vvfat_name, 0 );
|
||||||
if ( error != 0 ) {
|
if ( error != 0 ) {
|
||||||
fprintf(stderr,
|
fprintf( stderr, "%s:%u: bdrv_open %s: %d\n", __FUNCTION__, __LINE__, vvfat_name, error );
|
||||||
"%s:%u: bdrv_open %s: %d\n",
|
|
||||||
__FUNCTION__, __LINE__,
|
|
||||||
vvfat_name, error);
|
|
||||||
bdrv_delete( sdi->bs );
|
bdrv_delete( sdi->bs );
|
||||||
sdi->bs = NULL;
|
sdi->bs = NULL;
|
||||||
}
|
}
|
||||||
|
@ -652,9 +631,7 @@ s3c2410_sdi_mount(x49gp_t *x49gp, char *filename)
|
||||||
} else {
|
} else {
|
||||||
sdi->fd = open( filename, O_RDWR );
|
sdi->fd = open( filename, O_RDWR );
|
||||||
if ( sdi->fd < 0 ) {
|
if ( sdi->fd < 0 ) {
|
||||||
fprintf(stderr, "%s:%u: open %s: %s\n",
|
fprintf( stderr, "%s:%u: open %s: %s\n", __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, filename,
|
|
||||||
strerror(errno));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -668,16 +645,14 @@ s3c2410_sdi_mount(x49gp_t *x49gp, char *filename)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int s3c2410_sdi_is_mounted( x49gp_t* x49gp )
|
||||||
s3c2410_sdi_is_mounted(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
s3c2410_sdi_t* sdi = x49gp->s3c2410_sdi;
|
||||||
|
|
||||||
return ( sdi->bs != NULL ) || ( sdi->fd >= 0 );
|
return ( sdi->bs != NULL ) || ( sdi->fd >= 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sdi_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_sdi_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
x49gp_t* x49gp = module->x49gp;
|
x49gp_t* x49gp = module->x49gp;
|
||||||
s3c2410_sdi_t* sdi = module->user_data;
|
s3c2410_sdi_t* sdi = module->user_data;
|
||||||
|
@ -694,11 +669,11 @@ s3c2410_sdi_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
sdi->bs = NULL;
|
sdi->bs = NULL;
|
||||||
sdi->filename = NULL;
|
sdi->filename = NULL;
|
||||||
|
|
||||||
error = x49gp_module_get_filename(module, key, "filename", "",
|
error = x49gp_module_get_filename( module, key, "filename", "", &filename, &filepath );
|
||||||
&filename, &filepath);
|
|
||||||
if ( strcmp( filename, "" ) ) {
|
if ( strcmp( filename, "" ) ) {
|
||||||
error2 = s3c2410_sdi_mount( x49gp, filepath );
|
error2 = s3c2410_sdi_mount( x49gp, filepath );
|
||||||
if (0 == error) error = error2;
|
if ( 0 == error )
|
||||||
|
error = error2;
|
||||||
} else {
|
} else {
|
||||||
s3c2410_sdi_unmount( x49gp );
|
s3c2410_sdi_unmount( x49gp );
|
||||||
}
|
}
|
||||||
|
@ -711,16 +686,14 @@ s3c2410_sdi_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sdi_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_sdi_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = module->user_data;
|
s3c2410_sdi_t* sdi = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -744,8 +717,7 @@ s3c2410_sdi_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sdi_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_sdi_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi = module->user_data;
|
s3c2410_sdi_t* sdi = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -767,22 +739,11 @@ s3c2410_sdi_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_sdi_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_sdi_readfn[] = { s3c2410_sdi_read, s3c2410_sdi_read, s3c2410_sdi_read };
|
||||||
{
|
|
||||||
s3c2410_sdi_read,
|
|
||||||
s3c2410_sdi_read,
|
|
||||||
s3c2410_sdi_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_sdi_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_sdi_writefn[] = { s3c2410_sdi_write, s3c2410_sdi_write, s3c2410_sdi_write };
|
||||||
{
|
|
||||||
s3c2410_sdi_write,
|
|
||||||
s3c2410_sdi_write,
|
|
||||||
s3c2410_sdi_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_sdi_init( x49gp_module_t* module )
|
||||||
s3c2410_sdi_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi;
|
s3c2410_sdi_t* sdi;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -793,8 +754,7 @@ s3c2410_sdi_init(x49gp_module_t *module)
|
||||||
|
|
||||||
sdi = malloc( sizeof( s3c2410_sdi_t ) );
|
sdi = malloc( sizeof( s3c2410_sdi_t ) );
|
||||||
if ( NULL == sdi ) {
|
if ( NULL == sdi ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
|
||||||
module->x49gp->progname, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_sdi_data_init( sdi ) ) {
|
if ( s3c2410_sdi_data_init( sdi ) ) {
|
||||||
|
@ -806,8 +766,7 @@ s3c2410_sdi_init(x49gp_module_t *module)
|
||||||
module->x49gp->s3c2410_sdi = sdi;
|
module->x49gp->s3c2410_sdi = sdi;
|
||||||
sdi->x49gp = module->x49gp;
|
sdi->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_sdi_readfn,
|
iotype = cpu_register_io_memory( s3c2410_sdi_readfn, s3c2410_sdi_writefn, sdi );
|
||||||
s3c2410_sdi_writefn, sdi);
|
|
||||||
#ifdef DEBUG_S3C2410_SDI
|
#ifdef DEBUG_S3C2410_SDI
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -817,8 +776,7 @@ s3c2410_sdi_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sdi_exit( x49gp_module_t* module )
|
||||||
s3c2410_sdi_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_sdi_t* sdi;
|
s3c2410_sdi_t* sdi;
|
||||||
|
|
||||||
|
@ -839,17 +797,11 @@ s3c2410_sdi_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_sdi_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_sdi_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-sdi",
|
if ( x49gp_module_init( x49gp, "s3c2410-sdi", s3c2410_sdi_init, s3c2410_sdi_exit, s3c2410_sdi_reset, s3c2410_sdi_load, s3c2410_sdi_save,
|
||||||
s3c2410_sdi_init,
|
|
||||||
s3c2410_sdi_exit,
|
|
||||||
s3c2410_sdi_reset,
|
|
||||||
s3c2410_sdi_load,
|
|
||||||
s3c2410_sdi_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t spicon0;
|
uint32_t spicon0;
|
||||||
uint32_t spista0;
|
uint32_t spista0;
|
||||||
|
@ -34,31 +33,22 @@ typedef struct {
|
||||||
x49gp_t* x49gp;
|
x49gp_t* x49gp;
|
||||||
} s3c2410_spi_t;
|
} s3c2410_spi_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_data_init( s3c2410_spi_t* spi )
|
||||||
s3c2410_spi_data_init(s3c2410_spi_t *spi)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] =
|
s3c2410_offset_t regs[] = {
|
||||||
{
|
S3C2410_OFFSET( SPI, SPICON0, 0x00000000, spi->spicon0 ), S3C2410_OFFSET( SPI, SPISTA0, 0x00000000, spi->spista0 ),
|
||||||
S3C2410_OFFSET(SPI, SPICON0, 0x00000000, spi->spicon0),
|
S3C2410_OFFSET( SPI, SPPIN0, 0x00000000, spi->sppin0 ), S3C2410_OFFSET( SPI, SPPRE0, 0x00000000, spi->sppre0 ),
|
||||||
S3C2410_OFFSET(SPI, SPISTA0, 0x00000000, spi->spista0),
|
S3C2410_OFFSET( SPI, SPTDAT0, 0x00000000, spi->sptdat0 ), S3C2410_OFFSET( SPI, SPRDAT0, 0x00000000, spi->sprdat0 ),
|
||||||
S3C2410_OFFSET(SPI, SPPIN0, 0x00000000, spi->sppin0),
|
S3C2410_OFFSET( SPI, SPICON1, 0x00000000, spi->spicon1 ), S3C2410_OFFSET( SPI, SPISTA1, 0x00000000, spi->spista1 ),
|
||||||
S3C2410_OFFSET(SPI, SPPRE0, 0x00000000, spi->sppre0),
|
S3C2410_OFFSET( SPI, SPPIN1, 0x00000000, spi->sppin1 ), S3C2410_OFFSET( SPI, SPPRE1, 0x00000000, spi->sppre1 ),
|
||||||
S3C2410_OFFSET(SPI, SPTDAT0, 0x00000000, spi->sptdat0),
|
S3C2410_OFFSET( SPI, SPTDAT1, 0x00000000, spi->sptdat1 ), S3C2410_OFFSET( SPI, SPRDAT1, 0x00000000, spi->sprdat1 ),
|
||||||
S3C2410_OFFSET(SPI, SPRDAT0, 0x00000000, spi->sprdat0),
|
|
||||||
S3C2410_OFFSET(SPI, SPICON1, 0x00000000, spi->spicon1),
|
|
||||||
S3C2410_OFFSET(SPI, SPISTA1, 0x00000000, spi->spista1),
|
|
||||||
S3C2410_OFFSET(SPI, SPPIN1, 0x00000000, spi->sppin1),
|
|
||||||
S3C2410_OFFSET(SPI, SPPRE1, 0x00000000, spi->sppre1),
|
|
||||||
S3C2410_OFFSET(SPI, SPTDAT1, 0x00000000, spi->sptdat1),
|
|
||||||
S3C2410_OFFSET(SPI, SPRDAT1, 0x00000000, spi->sprdat1),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
memset( spi, 0, sizeof( s3c2410_spi_t ) );
|
memset( spi, 0, sizeof( s3c2410_spi_t ) );
|
||||||
|
|
||||||
spi->regs = malloc( sizeof( regs ) );
|
spi->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == spi->regs ) {
|
if ( NULL == spi->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,8 +58,7 @@ s3c2410_spi_data_init(s3c2410_spi_t *spi)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t
|
uint32_t s3c2410_spi_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_spi_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi = opaque;
|
s3c2410_spi_t* spi = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -81,9 +70,8 @@ s3c2410_spi_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( spi, offset );
|
reg = S3C2410_OFFSET_ENTRY( spi, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_SPI
|
#ifdef DEBUG_S3C2410_SPI
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-spi", S3C2410_SPI_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -99,8 +87,7 @@ s3c2410_spi_read(void *opaque, target_phys_addr_t offset)
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void s3c2410_spi_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_spi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi = opaque;
|
s3c2410_spi_t* spi = opaque;
|
||||||
x49gp_t* x49gp = spi->x49gp;
|
x49gp_t* x49gp = spi->x49gp;
|
||||||
|
@ -113,9 +100,7 @@ s3c2410_spi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( spi, offset );
|
reg = S3C2410_OFFSET_ENTRY( spi, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_SPI
|
#ifdef DEBUG_S3C2410_SPI
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-spi", S3C2410_SPI_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-spi", S3C2410_SPI_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
@ -133,8 +118,7 @@ s3c2410_spi_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_spi_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi = module->user_data;
|
s3c2410_spi_t* spi = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -151,16 +135,14 @@ s3c2410_spi_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_spi_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi = module->user_data;
|
s3c2410_spi_t* spi = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -182,8 +164,7 @@ s3c2410_spi_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_spi_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi = module->user_data;
|
s3c2410_spi_t* spi = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -205,22 +186,11 @@ s3c2410_spi_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_spi_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_spi_readfn[] = { s3c2410_spi_read, s3c2410_spi_read, s3c2410_spi_read };
|
||||||
{
|
|
||||||
s3c2410_spi_read,
|
|
||||||
s3c2410_spi_read,
|
|
||||||
s3c2410_spi_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_spi_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_spi_writefn[] = { s3c2410_spi_write, s3c2410_spi_write, s3c2410_spi_write };
|
||||||
{
|
|
||||||
s3c2410_spi_write,
|
|
||||||
s3c2410_spi_write,
|
|
||||||
s3c2410_spi_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_init( x49gp_module_t* module )
|
||||||
s3c2410_spi_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi;
|
s3c2410_spi_t* spi;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -231,8 +201,7 @@ s3c2410_spi_init(x49gp_module_t *module)
|
||||||
|
|
||||||
spi = malloc( sizeof( s3c2410_spi_t ) );
|
spi = malloc( sizeof( s3c2410_spi_t ) );
|
||||||
if ( NULL == spi ) {
|
if ( NULL == spi ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_spi_data_init( spi ) ) {
|
if ( s3c2410_spi_data_init( spi ) ) {
|
||||||
|
@ -243,8 +212,7 @@ s3c2410_spi_init(x49gp_module_t *module)
|
||||||
module->user_data = spi;
|
module->user_data = spi;
|
||||||
spi->x49gp = module->x49gp;
|
spi->x49gp = module->x49gp;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_spi_readfn,
|
iotype = cpu_register_io_memory( s3c2410_spi_readfn, s3c2410_spi_writefn, spi );
|
||||||
s3c2410_spi_writefn, spi);
|
|
||||||
#ifdef DEBUG_S3C2410_SPI
|
#ifdef DEBUG_S3C2410_SPI
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -252,8 +220,7 @@ s3c2410_spi_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_spi_exit( x49gp_module_t* module )
|
||||||
s3c2410_spi_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_spi_t* spi;
|
s3c2410_spi_t* spi;
|
||||||
|
|
||||||
|
@ -274,17 +241,11 @@ s3c2410_spi_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_spi_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_spi_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-spi",
|
if ( x49gp_module_init( x49gp, "s3c2410-spi", s3c2410_spi_init, s3c2410_spi_exit, s3c2410_spi_reset, s3c2410_spi_load, s3c2410_spi_save,
|
||||||
s3c2410_spi_init,
|
|
||||||
s3c2410_spi_exit,
|
|
||||||
s3c2410_spi_reset,
|
|
||||||
s3c2410_spi_load,
|
|
||||||
s3c2410_spi_save,
|
|
||||||
NULL, &module ) ) {
|
NULL, &module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,8 +21,7 @@ typedef struct {
|
||||||
size_t size;
|
size_t size;
|
||||||
} filemap_t;
|
} filemap_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_sram_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_sram_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
filemap_t* filemap = module->user_data;
|
filemap_t* filemap = module->user_data;
|
||||||
char* filename;
|
char* filename;
|
||||||
|
@ -32,16 +31,12 @@ s3c2410_sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error = x49gp_module_get_filename(module, key, "filename",
|
error = x49gp_module_get_filename( module, key, "filename", "s3c2410-sram", &( filemap->filename ), &filename );
|
||||||
"s3c2410-sram", &(filemap->filename),
|
|
||||||
&filename);
|
|
||||||
|
|
||||||
filemap->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
filemap->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
||||||
if ( filemap->fd < 0 ) {
|
if ( filemap->fd < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -49,23 +44,17 @@ s3c2410_sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
filemap->size = S3C2410_SRAM_SIZE;
|
filemap->size = S3C2410_SRAM_SIZE;
|
||||||
if ( ftruncate( filemap->fd, filemap->size ) < 0 ) {
|
if ( ftruncate( filemap->fd, filemap->size ) < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: ftruncate %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: ftruncate %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( filemap->fd );
|
close( filemap->fd );
|
||||||
filemap->fd = -1;
|
filemap->fd = -1;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
filemap->data = mmap(phys_ram_base + filemap->offset, filemap->size,
|
filemap->data = mmap( phys_ram_base + filemap->offset, filemap->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, filemap->fd, 0 );
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
|
|
||||||
filemap->fd, 0);
|
|
||||||
if ( filemap->data == ( void* )-1 ) {
|
if ( filemap->data == ( void* )-1 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: mmap %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: mmap %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( filemap->fd );
|
close( filemap->fd );
|
||||||
filemap->fd = -1;
|
filemap->fd = -1;
|
||||||
|
@ -78,8 +67,7 @@ s3c2410_sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sram_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_sram_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
filemap_t* filemap = module->user_data;
|
filemap_t* filemap = module->user_data;
|
||||||
int error;
|
int error;
|
||||||
|
@ -92,23 +80,20 @@ s3c2410_sram_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
|
|
||||||
error = msync( filemap->data, filemap->size, MS_ASYNC );
|
error = msync( filemap->data, filemap->size, MS_ASYNC );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: msync: %s\n",
|
fprintf( stderr, "%s:%u: msync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = fsync( filemap->fd );
|
error = fsync( filemap->fd );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: fsync: %s\n",
|
fprintf( stderr, "%s:%u: fsync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sram_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_MODULES
|
#ifdef DEBUG_X49GP_MODULES
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
|
@ -117,8 +102,7 @@ s3c2410_sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sram_init( x49gp_module_t* module )
|
||||||
s3c2410_sram_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
filemap_t* filemap;
|
filemap_t* filemap;
|
||||||
|
|
||||||
|
@ -128,8 +112,7 @@ s3c2410_sram_init(x49gp_module_t *module)
|
||||||
|
|
||||||
filemap = malloc( sizeof( filemap_t ) );
|
filemap = malloc( sizeof( filemap_t ) );
|
||||||
if ( NULL == filemap ) {
|
if ( NULL == filemap ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,14 +125,12 @@ s3c2410_sram_init(x49gp_module_t *module)
|
||||||
filemap->offset = phys_ram_size;
|
filemap->offset = phys_ram_size;
|
||||||
phys_ram_size += S3C2410_SRAM_SIZE;
|
phys_ram_size += S3C2410_SRAM_SIZE;
|
||||||
|
|
||||||
cpu_register_physical_memory(S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE,
|
cpu_register_physical_memory( S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE, filemap->offset | IO_MEM_RAM );
|
||||||
filemap->offset | IO_MEM_RAM);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_sram_exit( x49gp_module_t* module )
|
||||||
s3c2410_sram_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
filemap_t* filemap;
|
filemap_t* filemap;
|
||||||
|
|
||||||
|
@ -176,18 +157,12 @@ s3c2410_sram_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_sram_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_sram_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-sram",
|
if ( x49gp_module_init( x49gp, "s3c2410-sram", s3c2410_sram_init, s3c2410_sram_exit, s3c2410_sram_reset, s3c2410_sram_load,
|
||||||
s3c2410_sram_init,
|
s3c2410_sram_save, NULL, &module ) ) {
|
||||||
s3c2410_sram_exit,
|
|
||||||
s3c2410_sram_reset,
|
|
||||||
s3c2410_sram_load,
|
|
||||||
s3c2410_sram_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
#include "s3c2410_timer.h"
|
#include "s3c2410_timer.h"
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t reload_bit;
|
uint32_t reload_bit;
|
||||||
uint32_t update_bit;
|
uint32_t update_bit;
|
||||||
|
@ -54,35 +53,17 @@ struct __s3c2410_timer_s__ {
|
||||||
} timeout[ 5 ];
|
} timeout[ 5 ];
|
||||||
};
|
};
|
||||||
|
|
||||||
static const s3c2410_timer_config_t s3c2410_timer_config[] =
|
static const s3c2410_timer_config_t s3c2410_timer_config[] = {
|
||||||
{
|
{TCON_TIMER0_RELOAD, TCON_TIMER0_UPDATE, TCON_TIMER0_START, TCFG0_PRE0_SHIFT, TCFG1_MUX0_SHIFT, INT_TIMER0},
|
||||||
{
|
{TCON_TIMER1_RELOAD, TCON_TIMER1_UPDATE, TCON_TIMER1_START, TCFG0_PRE0_SHIFT, TCFG1_MUX1_SHIFT, INT_TIMER1},
|
||||||
TCON_TIMER0_RELOAD, TCON_TIMER0_UPDATE, TCON_TIMER0_START,
|
{TCON_TIMER2_RELOAD, TCON_TIMER2_UPDATE, TCON_TIMER2_START, TCFG0_PRE1_SHIFT, TCFG1_MUX2_SHIFT, INT_TIMER2},
|
||||||
TCFG0_PRE0_SHIFT, TCFG1_MUX0_SHIFT, INT_TIMER0
|
{TCON_TIMER3_RELOAD, TCON_TIMER3_UPDATE, TCON_TIMER3_START, TCFG0_PRE1_SHIFT, TCFG1_MUX3_SHIFT, INT_TIMER3},
|
||||||
},
|
{TCON_TIMER4_RELOAD, TCON_TIMER4_UPDATE, TCON_TIMER4_START, TCFG0_PRE1_SHIFT, TCFG1_MUX4_SHIFT, INT_TIMER4},
|
||||||
{
|
|
||||||
TCON_TIMER1_RELOAD, TCON_TIMER1_UPDATE, TCON_TIMER1_START,
|
|
||||||
TCFG0_PRE0_SHIFT, TCFG1_MUX1_SHIFT, INT_TIMER1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TCON_TIMER2_RELOAD, TCON_TIMER2_UPDATE, TCON_TIMER2_START,
|
|
||||||
TCFG0_PRE1_SHIFT, TCFG1_MUX2_SHIFT, INT_TIMER2
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TCON_TIMER3_RELOAD, TCON_TIMER3_UPDATE, TCON_TIMER3_START,
|
|
||||||
TCFG0_PRE1_SHIFT, TCFG1_MUX3_SHIFT, INT_TIMER3
|
|
||||||
},
|
|
||||||
{
|
|
||||||
TCON_TIMER4_RELOAD, TCON_TIMER4_UPDATE, TCON_TIMER4_START,
|
|
||||||
TCFG0_PRE1_SHIFT, TCFG1_MUX4_SHIFT, INT_TIMER4
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_data_init( s3c2410_timer_t* timer )
|
||||||
s3c2410_timer_data_init(s3c2410_timer_t *timer)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = { S3C2410_OFFSET( TIMER, TCFG0, 0, timer->tcfg0 ),
|
||||||
S3C2410_OFFSET(TIMER, TCFG0, 0, timer->tcfg0),
|
|
||||||
S3C2410_OFFSET( TIMER, TCFG1, 0, timer->tcfg1 ),
|
S3C2410_OFFSET( TIMER, TCFG1, 0, timer->tcfg1 ),
|
||||||
S3C2410_OFFSET( TIMER, TCON, 0, timer->tcon ),
|
S3C2410_OFFSET( TIMER, TCON, 0, timer->tcon ),
|
||||||
S3C2410_OFFSET( TIMER, TCNTB0, 0, timer->timeout[ 0 ].tcntb ),
|
S3C2410_OFFSET( TIMER, TCNTB0, 0, timer->timeout[ 0 ].tcntb ),
|
||||||
|
@ -98,15 +79,13 @@ s3c2410_timer_data_init(s3c2410_timer_t *timer)
|
||||||
S3C2410_OFFSET( TIMER, TCMPB3, 0, timer->timeout[ 3 ].tcmpb ),
|
S3C2410_OFFSET( TIMER, TCMPB3, 0, timer->timeout[ 3 ].tcmpb ),
|
||||||
S3C2410_OFFSET( TIMER, TCNTO3, 0, timer->timeout[ 3 ].tcnt ),
|
S3C2410_OFFSET( TIMER, TCNTO3, 0, timer->timeout[ 3 ].tcnt ),
|
||||||
S3C2410_OFFSET( TIMER, TCNTB4, 0, timer->timeout[ 4 ].tcntb ),
|
S3C2410_OFFSET( TIMER, TCNTB4, 0, timer->timeout[ 4 ].tcntb ),
|
||||||
S3C2410_OFFSET(TIMER, TCNTO4, 0, timer->timeout[4].tcnt)
|
S3C2410_OFFSET( TIMER, TCNTO4, 0, timer->timeout[ 4 ].tcnt ) };
|
||||||
};
|
|
||||||
|
|
||||||
memset( timer, 0, sizeof( s3c2410_timer_t ) );
|
memset( timer, 0, sizeof( s3c2410_timer_t ) );
|
||||||
|
|
||||||
timer->regs = malloc( sizeof( regs ) );
|
timer->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == timer->regs ) {
|
if ( NULL == timer->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +95,7 @@ s3c2410_timer_data_init(s3c2410_timer_t *timer)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_timer_timeout( void* data )
|
||||||
s3c2410_timer_timeout(void *data)
|
|
||||||
{
|
{
|
||||||
struct s3c2410_timeout* t = data;
|
struct s3c2410_timeout* t = data;
|
||||||
s3c2410_timer_t* timer = t->main;
|
s3c2410_timer_t* timer = t->main;
|
||||||
|
@ -145,8 +123,7 @@ s3c2410_timer_timeout(void *data)
|
||||||
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long s3c2410_timer_next_interrupt( x49gp_t* x49gp )
|
||||||
s3c2410_timer_next_interrupt(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = x49gp->s3c2410_timer;
|
s3c2410_timer_t* timer = x49gp->s3c2410_timer;
|
||||||
struct s3c2410_timeout* t;
|
struct s3c2410_timeout* t;
|
||||||
|
@ -181,16 +158,15 @@ s3c2410_timer_next_interrupt(x49gp_t *x49gp)
|
||||||
next = irq;
|
next = irq;
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("s3c2410-timer: TIMER%u: tcnt %u, interval %lu, pending %u, next irq %lu\n",
|
printf( "s3c2410-timer: TIMER%u: tcnt %u, interval %lu, pending %u, next irq %lu\n", t->index, t->tcnt, t->interval,
|
||||||
t->index, t->tcnt, t->interval, x49gp_timer_pending(t->timer), irq);
|
x49gp_timer_pending( t->timer ), irq );
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_update_tcfg( s3c2410_timer_t* timer )
|
||||||
s3c2410_update_tcfg(s3c2410_timer_t *timer)
|
|
||||||
{
|
{
|
||||||
struct s3c2410_timeout* t;
|
struct s3c2410_timeout* t;
|
||||||
x49gp_t* x49gp = timer->x49gp;
|
x49gp_t* x49gp = timer->x49gp;
|
||||||
|
@ -205,29 +181,27 @@ s3c2410_update_tcfg(s3c2410_timer_t *timer)
|
||||||
mux = ( timer->tcfg1 >> t->tconfig->mux_shift ) & TCFG1_MUXx_MASK;
|
mux = ( timer->tcfg1 >> t->tconfig->mux_shift ) & TCFG1_MUXx_MASK;
|
||||||
|
|
||||||
if ( mux > 3 ) {
|
if ( mux > 3 ) {
|
||||||
printf("s3c2410-timer: can't handle MUX %02x for TIMER%u\n",
|
printf( "s3c2410-timer: can't handle MUX %02x for TIMER%u\n", mux, t->index );
|
||||||
mux, t->index);
|
|
||||||
mux = 3;
|
mux = 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
t->interval = ( pre + 1 ) * ( 2 << mux );
|
t->interval = ( pre + 1 ) * ( 2 << mux );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("s3c2410-timer: TIMER%u: pre %u, mux %u, tick %lu PCLKs\n",
|
printf( "s3c2410-timer: TIMER%u: pre %u, mux %u, tick %lu PCLKs\n", t->index, pre, mux, t->interval );
|
||||||
t->index, pre, mux, t->interval);
|
|
||||||
#endif
|
#endif
|
||||||
if ( x49gp_timer_pending( t->timer ) ) {
|
if ( x49gp_timer_pending( t->timer ) ) {
|
||||||
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
|
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("s3c2410-timer: mod TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, (unsigned long long) timeout);
|
printf( "s3c2410-timer: mod TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval,
|
||||||
|
( unsigned long long )timeout );
|
||||||
#endif
|
#endif
|
||||||
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_update_tcon( s3c2410_timer_t* timer )
|
||||||
s3c2410_update_tcon(s3c2410_timer_t *timer)
|
|
||||||
{
|
{
|
||||||
struct s3c2410_timeout* t;
|
struct s3c2410_timeout* t;
|
||||||
x49gp_t* x49gp = timer->x49gp;
|
x49gp_t* x49gp = timer->x49gp;
|
||||||
|
@ -254,7 +228,8 @@ s3c2410_update_tcon(s3c2410_timer_t *timer)
|
||||||
if ( timer->tcon & t->tconfig->start_bit ) {
|
if ( timer->tcon & t->tconfig->start_bit ) {
|
||||||
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
|
timeout = 1000000LL * t->tcnt * t->interval / x49gp->PCLK;
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("s3c2410-timer: start TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval, (unsigned long long) timeout);
|
printf( "s3c2410-timer: start TIMER%u: CNT %u (%lu PCLKs): %llu us\n", t->index, t->tcnt, t->interval,
|
||||||
|
( unsigned long long )timeout );
|
||||||
#endif
|
#endif
|
||||||
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
x49gp_mod_timer( t->timer, x49gp_get_clock() + timeout );
|
||||||
} else {
|
} else {
|
||||||
|
@ -267,8 +242,7 @@ s3c2410_update_tcon(s3c2410_timer_t *timer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_read_tcnt( s3c2410_timer_t* timer, int index )
|
||||||
s3c2410_read_tcnt(s3c2410_timer_t *timer, int index)
|
|
||||||
{
|
{
|
||||||
struct s3c2410_timeout* t = &timer->timeout[ index ];
|
struct s3c2410_timeout* t = &timer->timeout[ index ];
|
||||||
x49gp_t* x49gp = timer->x49gp;
|
x49gp_t* x49gp = timer->x49gp;
|
||||||
|
@ -291,8 +265,7 @@ s3c2410_read_tcnt(s3c2410_timer_t *timer, int index)
|
||||||
return t->tcnt;
|
return t->tcnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_timer_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_timer_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = opaque;
|
s3c2410_timer_t* timer = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -326,16 +299,13 @@ s3c2410_timer_read(void *opaque, target_phys_addr_t offset)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-timer", S3C2410_TIMER_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-timer", S3C2410_TIMER_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_timer_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_timer_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = opaque;
|
s3c2410_timer_t* timer = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -347,9 +317,7 @@ s3c2410_timer_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( timer, offset );
|
reg = S3C2410_OFFSET_ENTRY( timer, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-timer", S3C2410_TIMER_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-timer", S3C2410_TIMER_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -378,8 +346,7 @@ s3c2410_timer_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_timer_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = module->user_data;
|
s3c2410_timer_t* timer = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -396,8 +363,7 @@ s3c2410_timer_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,8 +373,7 @@ s3c2410_timer_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_timer_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = module->user_data;
|
s3c2410_timer_t* timer = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -430,8 +395,7 @@ s3c2410_timer_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_timer_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer = module->user_data;
|
s3c2410_timer_t* timer = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -456,22 +420,11 @@ s3c2410_timer_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_timer_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_timer_readfn[] = { s3c2410_timer_read, s3c2410_timer_read, s3c2410_timer_read };
|
||||||
{
|
|
||||||
s3c2410_timer_read,
|
|
||||||
s3c2410_timer_read,
|
|
||||||
s3c2410_timer_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_timer_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_timer_writefn[] = { s3c2410_timer_write, s3c2410_timer_write, s3c2410_timer_write };
|
||||||
{
|
|
||||||
s3c2410_timer_write,
|
|
||||||
s3c2410_timer_write,
|
|
||||||
s3c2410_timer_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_init( x49gp_module_t* module )
|
||||||
s3c2410_timer_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer;
|
s3c2410_timer_t* timer;
|
||||||
struct s3c2410_timeout* t;
|
struct s3c2410_timeout* t;
|
||||||
|
@ -484,8 +437,7 @@ s3c2410_timer_init(x49gp_module_t *module)
|
||||||
|
|
||||||
timer = malloc( sizeof( s3c2410_timer_t ) );
|
timer = malloc( sizeof( s3c2410_timer_t ) );
|
||||||
if ( NULL == timer ) {
|
if ( NULL == timer ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
|
||||||
module->x49gp->progname, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_timer_data_init( timer ) ) {
|
if ( s3c2410_timer_data_init( timer ) ) {
|
||||||
|
@ -509,8 +461,7 @@ s3c2410_timer_init(x49gp_module_t *module)
|
||||||
t->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t );
|
t->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_timer_timeout, t );
|
||||||
}
|
}
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_timer_readfn,
|
iotype = cpu_register_io_memory( s3c2410_timer_readfn, s3c2410_timer_writefn, timer );
|
||||||
s3c2410_timer_writefn, timer);
|
|
||||||
#ifdef DEBUG_S3C2410_TIMER
|
#ifdef DEBUG_S3C2410_TIMER
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -518,8 +469,7 @@ s3c2410_timer_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_timer_exit( x49gp_module_t* module )
|
||||||
s3c2410_timer_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_timer_t* timer;
|
s3c2410_timer_t* timer;
|
||||||
|
|
||||||
|
@ -540,18 +490,12 @@ s3c2410_timer_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_timer_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_timer_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-timer",
|
if ( x49gp_module_init( x49gp, "s3c2410-timer", s3c2410_timer_init, s3c2410_timer_exit, s3c2410_timer_reset, s3c2410_timer_load,
|
||||||
s3c2410_timer_init,
|
s3c2410_timer_save, NULL, &module ) ) {
|
||||||
s3c2410_timer_exit,
|
|
||||||
s3c2410_timer_reset,
|
|
||||||
s3c2410_timer_load,
|
|
||||||
s3c2410_timer_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t ulcon;
|
uint32_t ulcon;
|
||||||
uint32_t ucon;
|
uint32_t ucon;
|
||||||
|
@ -41,11 +40,9 @@ typedef struct {
|
||||||
s3c2410_uart_reg_t uart[ 3 ];
|
s3c2410_uart_reg_t uart[ 3 ];
|
||||||
} s3c2410_uart_t;
|
} s3c2410_uart_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_data_init( s3c2410_uart_t* uart )
|
||||||
s3c2410_uart_data_init(s3c2410_uart_t *uart)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs0[] = {
|
s3c2410_offset_t regs0[] = { S3C2410_OFFSET( UART0, ULCON, 0x00000000, uart->uart[ 0 ].ulcon ),
|
||||||
S3C2410_OFFSET(UART0, ULCON, 0x00000000, uart->uart[0].ulcon),
|
|
||||||
S3C2410_OFFSET( UART0, UCON, 0x00000000, uart->uart[ 0 ].ucon ),
|
S3C2410_OFFSET( UART0, UCON, 0x00000000, uart->uart[ 0 ].ucon ),
|
||||||
S3C2410_OFFSET( UART0, UFCON, 0x00000000, uart->uart[ 0 ].ufcon ),
|
S3C2410_OFFSET( UART0, UFCON, 0x00000000, uart->uart[ 0 ].ufcon ),
|
||||||
S3C2410_OFFSET( UART0, UMCON, 0x00000000, uart->uart[ 0 ].umcon ),
|
S3C2410_OFFSET( UART0, UMCON, 0x00000000, uart->uart[ 0 ].umcon ),
|
||||||
|
@ -55,10 +52,8 @@ s3c2410_uart_data_init(s3c2410_uart_t *uart)
|
||||||
S3C2410_OFFSET( UART0, UMSTAT, 0x00000000, uart->uart[ 0 ].umstat ),
|
S3C2410_OFFSET( UART0, UMSTAT, 0x00000000, uart->uart[ 0 ].umstat ),
|
||||||
S3C2410_OFFSET( UART0, UTXH, 0, uart->uart[ 0 ].utxh ),
|
S3C2410_OFFSET( UART0, UTXH, 0, uart->uart[ 0 ].utxh ),
|
||||||
S3C2410_OFFSET( UART0, URXH, 0, uart->uart[ 0 ].urxh ),
|
S3C2410_OFFSET( UART0, URXH, 0, uart->uart[ 0 ].urxh ),
|
||||||
S3C2410_OFFSET(UART0, UBRDIV, 0, uart->uart[0].ubrdiv)
|
S3C2410_OFFSET( UART0, UBRDIV, 0, uart->uart[ 0 ].ubrdiv ) };
|
||||||
};
|
s3c2410_offset_t regs1[] = { S3C2410_OFFSET( UART1, ULCON, 0x00000000, uart->uart[ 1 ].ulcon ),
|
||||||
s3c2410_offset_t regs1[] = {
|
|
||||||
S3C2410_OFFSET(UART1, ULCON, 0x00000000, uart->uart[1].ulcon),
|
|
||||||
S3C2410_OFFSET( UART1, UCON, 0x00000000, uart->uart[ 1 ].ucon ),
|
S3C2410_OFFSET( UART1, UCON, 0x00000000, uart->uart[ 1 ].ucon ),
|
||||||
S3C2410_OFFSET( UART1, UFCON, 0x00000000, uart->uart[ 1 ].ufcon ),
|
S3C2410_OFFSET( UART1, UFCON, 0x00000000, uart->uart[ 1 ].ufcon ),
|
||||||
S3C2410_OFFSET( UART1, UMCON, 0x00000000, uart->uart[ 1 ].umcon ),
|
S3C2410_OFFSET( UART1, UMCON, 0x00000000, uart->uart[ 1 ].umcon ),
|
||||||
|
@ -68,10 +63,8 @@ s3c2410_uart_data_init(s3c2410_uart_t *uart)
|
||||||
S3C2410_OFFSET( UART1, UMSTAT, 0x00000000, uart->uart[ 1 ].umstat ),
|
S3C2410_OFFSET( UART1, UMSTAT, 0x00000000, uart->uart[ 1 ].umstat ),
|
||||||
S3C2410_OFFSET( UART1, UTXH, 0, uart->uart[ 1 ].utxh ),
|
S3C2410_OFFSET( UART1, UTXH, 0, uart->uart[ 1 ].utxh ),
|
||||||
S3C2410_OFFSET( UART1, URXH, 0, uart->uart[ 1 ].urxh ),
|
S3C2410_OFFSET( UART1, URXH, 0, uart->uart[ 1 ].urxh ),
|
||||||
S3C2410_OFFSET(UART1, UBRDIV, 0, uart->uart[1].ubrdiv)
|
S3C2410_OFFSET( UART1, UBRDIV, 0, uart->uart[ 1 ].ubrdiv ) };
|
||||||
};
|
s3c2410_offset_t regs2[] = { S3C2410_OFFSET( UART2, ULCON, 0x00000000, uart->uart[ 2 ].ulcon ),
|
||||||
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, UCON, 0x00000000, uart->uart[ 2 ].ucon ),
|
||||||
S3C2410_OFFSET( UART2, UFCON, 0x00000000, uart->uart[ 2 ].ufcon ),
|
S3C2410_OFFSET( UART2, UFCON, 0x00000000, uart->uart[ 2 ].ufcon ),
|
||||||
S3C2410_OFFSET( UART2, UTRSTAT, 0x00000006, uart->uart[ 2 ].utrstat ),
|
S3C2410_OFFSET( UART2, UTRSTAT, 0x00000006, uart->uart[ 2 ].utrstat ),
|
||||||
|
@ -79,26 +72,22 @@ s3c2410_uart_data_init(s3c2410_uart_t *uart)
|
||||||
S3C2410_OFFSET( UART2, UFSTAT, 0x00000000, uart->uart[ 2 ].ufstat ),
|
S3C2410_OFFSET( UART2, UFSTAT, 0x00000000, uart->uart[ 2 ].ufstat ),
|
||||||
S3C2410_OFFSET( UART2, UTXH, 0, uart->uart[ 2 ].utxh ),
|
S3C2410_OFFSET( UART2, UTXH, 0, uart->uart[ 2 ].utxh ),
|
||||||
S3C2410_OFFSET( UART2, URXH, 0, uart->uart[ 2 ].urxh ),
|
S3C2410_OFFSET( UART2, URXH, 0, uart->uart[ 2 ].urxh ),
|
||||||
S3C2410_OFFSET(UART2, UBRDIV, 0, uart->uart[2].ubrdiv)
|
S3C2410_OFFSET( UART2, UBRDIV, 0, uart->uart[ 2 ].ubrdiv ) };
|
||||||
};
|
|
||||||
|
|
||||||
uart->uart[ 0 ].regs = malloc( sizeof( regs0 ) );
|
uart->uart[ 0 ].regs = malloc( sizeof( regs0 ) );
|
||||||
if ( NULL == uart->uart[ 0 ].regs ) {
|
if ( NULL == uart->uart[ 0 ].regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
uart->uart[ 1 ].regs = malloc( sizeof( regs1 ) );
|
uart->uart[ 1 ].regs = malloc( sizeof( regs1 ) );
|
||||||
if ( NULL == uart->uart[ 1 ].regs ) {
|
if ( NULL == uart->uart[ 1 ].regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
free( uart->uart[ 0 ].regs );
|
free( uart->uart[ 0 ].regs );
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
uart->uart[ 2 ].regs = malloc( sizeof( regs2 ) );
|
uart->uart[ 2 ].regs = malloc( sizeof( regs2 ) );
|
||||||
if ( NULL == uart->uart[ 2 ].regs ) {
|
if ( NULL == uart->uart[ 2 ].regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
free( uart->uart[ 0 ].regs );
|
free( uart->uart[ 0 ].regs );
|
||||||
free( uart->uart[ 1 ].regs );
|
free( uart->uart[ 1 ].regs );
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -125,8 +114,7 @@ s3c2410_uart_data_init(s3c2410_uart_t *uart)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_uart_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_uart_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = opaque;
|
s3c2410_uart_reg_t* uart_regs = opaque;
|
||||||
x49gp_t* x49gp = uart_regs->x49gp;
|
x49gp_t* x49gp = uart_regs->x49gp;
|
||||||
|
@ -164,8 +152,7 @@ s3c2410_uart_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
|
reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_UART
|
#ifdef DEBUG_S3C2410_UART
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", module, mod_offset, reg->name, ( unsigned long )offset, *( reg->datap ) );
|
||||||
module, mod_offset, reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch ( offset ) {
|
switch ( offset ) {
|
||||||
|
@ -182,8 +169,7 @@ s3c2410_uart_read(void *opaque, target_phys_addr_t offset)
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_uart_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = opaque;
|
s3c2410_uart_reg_t* uart_regs = opaque;
|
||||||
x49gp_t* x49gp = uart_regs->x49gp;
|
x49gp_t* x49gp = uart_regs->x49gp;
|
||||||
|
@ -223,8 +209,7 @@ s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
|
reg = S3C2410_OFFSET_ENTRY( uart_regs, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_UART
|
#ifdef DEBUG_S3C2410_UART
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", module, mod_offset, reg->name, ( unsigned long )offset, data );
|
||||||
module, mod_offset, reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
@ -242,12 +227,10 @@ s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
ubrdivn = ( data >> 0 ) & 0xffff;
|
ubrdivn = ( data >> 0 ) & 0xffff;
|
||||||
if ( uart_regs->ucon & ( 1 << 10 ) ) {
|
if ( uart_regs->ucon & ( 1 << 10 ) ) {
|
||||||
baud = x49gp->UCLK / 16 / ( ubrdivn + 1 );
|
baud = x49gp->UCLK / 16 / ( ubrdivn + 1 );
|
||||||
printf("%s: UEXTCLK %u, ubrdivn %u, baud %u\n",
|
printf( "%s: UEXTCLK %u, ubrdivn %u, baud %u\n", module, x49gp->UCLK, ubrdivn, baud );
|
||||||
module, x49gp->UCLK, ubrdivn, baud);
|
|
||||||
} else {
|
} else {
|
||||||
baud = x49gp->PCLK / 16 / ( ubrdivn + 1 );
|
baud = x49gp->PCLK / 16 / ( ubrdivn + 1 );
|
||||||
printf("%s: PCLK %u, ubrdivn %u, baud %u\n",
|
printf( "%s: PCLK %u, ubrdivn %u, baud %u\n", module, x49gp->PCLK, ubrdivn, baud );
|
||||||
module, x49gp->PCLK, ubrdivn, baud);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
|
@ -285,8 +268,7 @@ s3c2410_uart_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_uart_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -303,16 +285,14 @@ s3c2410_uart_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_uart_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -334,8 +314,7 @@ s3c2410_uart_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_uart_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -357,22 +336,11 @@ s3c2410_uart_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_uart_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_uart_readfn[] = { s3c2410_uart_read, s3c2410_uart_read, s3c2410_uart_read };
|
||||||
{
|
|
||||||
s3c2410_uart_read,
|
|
||||||
s3c2410_uart_read,
|
|
||||||
s3c2410_uart_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_uart_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_uart_writefn[] = { s3c2410_uart_write, s3c2410_uart_write, s3c2410_uart_write };
|
||||||
{
|
|
||||||
s3c2410_uart_write,
|
|
||||||
s3c2410_uart_write,
|
|
||||||
s3c2410_uart_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_init( x49gp_module_t* module )
|
||||||
s3c2410_uart_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
s3c2410_uart_reg_t* uart_regs = module->user_data;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -381,8 +349,7 @@ s3c2410_uart_init(x49gp_module_t *module)
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_uart_readfn,
|
iotype = cpu_register_io_memory( s3c2410_uart_readfn, s3c2410_uart_writefn, uart_regs );
|
||||||
s3c2410_uart_writefn, uart_regs);
|
|
||||||
#ifdef DEBUG_S3C2410_UART
|
#ifdef DEBUG_S3C2410_UART
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -391,8 +358,7 @@ s3c2410_uart_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_uart_exit( x49gp_module_t* module )
|
||||||
s3c2410_uart_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_reg_t* uart_regs;
|
s3c2410_uart_reg_t* uart_regs;
|
||||||
|
|
||||||
|
@ -412,16 +378,14 @@ s3c2410_uart_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_uart_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_uart_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
s3c2410_uart_t* uart;
|
s3c2410_uart_t* uart;
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
uart = malloc( sizeof( s3c2410_uart_t ) );
|
uart = malloc( sizeof( s3c2410_uart_t ) );
|
||||||
if ( NULL == uart ) {
|
if ( NULL == uart ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset( uart, 0, sizeof( s3c2410_uart_t ) );
|
memset( uart, 0, sizeof( s3c2410_uart_t ) );
|
||||||
|
@ -435,39 +399,24 @@ x49gp_s3c2410_uart_init(x49gp_t *x49gp)
|
||||||
uart->uart[ 1 ].x49gp = x49gp;
|
uart->uart[ 1 ].x49gp = x49gp;
|
||||||
uart->uart[ 2 ].x49gp = x49gp;
|
uart->uart[ 2 ].x49gp = x49gp;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-uart0",
|
if ( x49gp_module_init( x49gp, "s3c2410-uart0", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
|
||||||
s3c2410_uart_init,
|
s3c2410_uart_save, &uart->uart[ 0 ], &module ) ) {
|
||||||
s3c2410_uart_exit,
|
|
||||||
s3c2410_uart_reset,
|
|
||||||
s3c2410_uart_load,
|
|
||||||
s3c2410_uart_save,
|
|
||||||
&uart->uart[0], &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( x49gp_module_register( module ) ) {
|
if ( x49gp_module_register( module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-uart1",
|
if ( x49gp_module_init( x49gp, "s3c2410-uart1", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
|
||||||
s3c2410_uart_init,
|
s3c2410_uart_save, &uart->uart[ 1 ], &module ) ) {
|
||||||
s3c2410_uart_exit,
|
|
||||||
s3c2410_uart_reset,
|
|
||||||
s3c2410_uart_load,
|
|
||||||
s3c2410_uart_save,
|
|
||||||
&uart->uart[1], &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( x49gp_module_register( module ) ) {
|
if ( x49gp_module_register( module ) ) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-uart2",
|
if ( x49gp_module_init( x49gp, "s3c2410-uart2", s3c2410_uart_init, s3c2410_uart_exit, s3c2410_uart_reset, s3c2410_uart_load,
|
||||||
s3c2410_uart_init,
|
s3c2410_uart_save, &uart->uart[ 2 ], &module ) ) {
|
||||||
s3c2410_uart_exit,
|
|
||||||
s3c2410_uart_reset,
|
|
||||||
s3c2410_uart_load,
|
|
||||||
s3c2410_uart_save,
|
|
||||||
&uart->uart[2], &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if ( x49gp_module_register( module ) ) {
|
if ( x49gp_module_register( module ) ) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "x49gp.h"
|
#include "x49gp.h"
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t func_addr_reg;
|
uint32_t func_addr_reg;
|
||||||
uint32_t pwr_reg;
|
uint32_t pwr_reg;
|
||||||
|
@ -65,11 +64,9 @@ typedef struct {
|
||||||
s3c2410_offset_t* regs;
|
s3c2410_offset_t* regs;
|
||||||
} s3c2410_usbdev_t;
|
} s3c2410_usbdev_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_data_init( s3c2410_usbdev_t* usbdev )
|
||||||
s3c2410_usbdev_data_init(s3c2410_usbdev_t *usbdev)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = { S3C2410_OFFSET( USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg ),
|
||||||
S3C2410_OFFSET(USBDEV, FUNC_ADDR_REG, 0x00, usbdev->func_addr_reg),
|
|
||||||
S3C2410_OFFSET( USBDEV, PWR_REG, 0x00, usbdev->pwr_reg ),
|
S3C2410_OFFSET( USBDEV, PWR_REG, 0x00, usbdev->pwr_reg ),
|
||||||
S3C2410_OFFSET( USBDEV, EP_INT_REG, 0x00, usbdev->ep_int_reg ),
|
S3C2410_OFFSET( USBDEV, EP_INT_REG, 0x00, usbdev->ep_int_reg ),
|
||||||
S3C2410_OFFSET( USBDEV, USB_INT_REG, 0x00, usbdev->usb_int_reg ),
|
S3C2410_OFFSET( USBDEV, USB_INT_REG, 0x00, usbdev->usb_int_reg ),
|
||||||
|
@ -114,15 +111,13 @@ s3c2410_usbdev_data_init(s3c2410_usbdev_t *usbdev)
|
||||||
S3C2410_OFFSET( USBDEV, OUT_CSR1_REG, 0x00, usbdev->out_csr1_reg ),
|
S3C2410_OFFSET( USBDEV, OUT_CSR1_REG, 0x00, usbdev->out_csr1_reg ),
|
||||||
S3C2410_OFFSET( USBDEV, OUT_CSR2_REG, 0x00, usbdev->out_csr2_reg ),
|
S3C2410_OFFSET( USBDEV, OUT_CSR2_REG, 0x00, usbdev->out_csr2_reg ),
|
||||||
S3C2410_OFFSET( USBDEV, OUT_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_reg ),
|
S3C2410_OFFSET( USBDEV, OUT_FIFO_CNT1_REG, 0x00, usbdev->out_fifo_cnt1_reg ),
|
||||||
S3C2410_OFFSET(USBDEV, OUT_FIFO_CNT2_REG, 0x00, usbdev->out_fifo_cnt2_reg)
|
S3C2410_OFFSET( USBDEV, OUT_FIFO_CNT2_REG, 0x00, usbdev->out_fifo_cnt2_reg ) };
|
||||||
};
|
|
||||||
|
|
||||||
memset( usbdev, 0, sizeof( s3c2410_usbdev_t ) );
|
memset( usbdev, 0, sizeof( s3c2410_usbdev_t ) );
|
||||||
|
|
||||||
usbdev->regs = malloc( sizeof( regs ) );
|
usbdev->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == usbdev->regs ) {
|
if ( NULL == usbdev->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +127,7 @@ s3c2410_usbdev_data_init(s3c2410_usbdev_t *usbdev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_usbdev_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_usbdev_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev = opaque;
|
s3c2410_usbdev_t* usbdev = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -145,16 +139,14 @@ s3c2410_usbdev_read(void *opaque, target_phys_addr_t offset)
|
||||||
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
|
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_USBDEV
|
#ifdef DEBUG_S3C2410_USBDEV
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-usbdev", S3C2410_USBDEV_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_usbdev_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_usbdev_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev = opaque;
|
s3c2410_usbdev_t* usbdev = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -166,16 +158,13 @@ s3c2410_usbdev_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
|
reg = S3C2410_OFFSET_ENTRY( usbdev, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_USBDEV
|
#ifdef DEBUG_S3C2410_USBDEV
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-usbdev", S3C2410_USBDEV_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-usbdev", S3C2410_USBDEV_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_usbdev_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev = module->user_data;
|
s3c2410_usbdev_t* usbdev = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -192,16 +181,14 @@ s3c2410_usbdev_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_usbdev_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev = module->user_data;
|
s3c2410_usbdev_t* usbdev = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -223,8 +210,7 @@ s3c2410_usbdev_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_usbdev_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev = module->user_data;
|
s3c2410_usbdev_t* usbdev = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -246,22 +232,11 @@ s3c2410_usbdev_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_usbdev_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_usbdev_readfn[] = { s3c2410_usbdev_read, s3c2410_usbdev_read, s3c2410_usbdev_read };
|
||||||
{
|
|
||||||
s3c2410_usbdev_read,
|
|
||||||
s3c2410_usbdev_read,
|
|
||||||
s3c2410_usbdev_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_usbdev_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_usbdev_writefn[] = { s3c2410_usbdev_write, s3c2410_usbdev_write, s3c2410_usbdev_write };
|
||||||
{
|
|
||||||
s3c2410_usbdev_write,
|
|
||||||
s3c2410_usbdev_write,
|
|
||||||
s3c2410_usbdev_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_init( x49gp_module_t* module )
|
||||||
s3c2410_usbdev_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev;
|
s3c2410_usbdev_t* usbdev;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -272,8 +247,7 @@ s3c2410_usbdev_init(x49gp_module_t *module)
|
||||||
|
|
||||||
usbdev = malloc( sizeof( s3c2410_usbdev_t ) );
|
usbdev = malloc( sizeof( s3c2410_usbdev_t ) );
|
||||||
if ( NULL == usbdev ) {
|
if ( NULL == usbdev ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_usbdev_data_init( usbdev ) ) {
|
if ( s3c2410_usbdev_data_init( usbdev ) ) {
|
||||||
|
@ -283,8 +257,7 @@ s3c2410_usbdev_init(x49gp_module_t *module)
|
||||||
|
|
||||||
module->user_data = usbdev;
|
module->user_data = usbdev;
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_usbdev_readfn,
|
iotype = cpu_register_io_memory( s3c2410_usbdev_readfn, s3c2410_usbdev_writefn, usbdev );
|
||||||
s3c2410_usbdev_writefn, usbdev);
|
|
||||||
#ifdef DEBUG_S3C2410_USBDEV
|
#ifdef DEBUG_S3C2410_USBDEV
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -292,8 +265,7 @@ s3c2410_usbdev_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_usbdev_exit( x49gp_module_t* module )
|
||||||
s3c2410_usbdev_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_usbdev_t* usbdev;
|
s3c2410_usbdev_t* usbdev;
|
||||||
|
|
||||||
|
@ -314,18 +286,12 @@ s3c2410_usbdev_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_usbdev_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_usbdev_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-usbdev",
|
if ( x49gp_module_init( x49gp, "s3c2410-usbdev", s3c2410_usbdev_init, s3c2410_usbdev_exit, s3c2410_usbdev_reset, s3c2410_usbdev_load,
|
||||||
s3c2410_usbdev_init,
|
s3c2410_usbdev_save, NULL, &module ) ) {
|
||||||
s3c2410_usbdev_exit,
|
|
||||||
s3c2410_usbdev_reset,
|
|
||||||
s3c2410_usbdev_load,
|
|
||||||
s3c2410_usbdev_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
#include "s3c2410.h"
|
#include "s3c2410.h"
|
||||||
#include "s3c2410_intc.h"
|
#include "s3c2410_intc.h"
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t wtcon;
|
uint32_t wtcon;
|
||||||
uint32_t wtdat;
|
uint32_t wtdat;
|
||||||
|
@ -28,21 +27,17 @@ typedef struct {
|
||||||
x49gp_timer_t* timer;
|
x49gp_timer_t* timer;
|
||||||
} s3c2410_watchdog_t;
|
} s3c2410_watchdog_t;
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_data_init( s3c2410_watchdog_t* watchdog )
|
||||||
s3c2410_watchdog_data_init(s3c2410_watchdog_t *watchdog)
|
|
||||||
{
|
{
|
||||||
s3c2410_offset_t regs[] = {
|
s3c2410_offset_t regs[] = { S3C2410_OFFSET( WATCHDOG, WTCON, 0x8021, watchdog->wtcon ),
|
||||||
S3C2410_OFFSET(WATCHDOG, WTCON, 0x8021, watchdog->wtcon),
|
|
||||||
S3C2410_OFFSET( WATCHDOG, WTDAT, 0x8000, watchdog->wtdat ),
|
S3C2410_OFFSET( WATCHDOG, WTDAT, 0x8000, watchdog->wtdat ),
|
||||||
S3C2410_OFFSET(WATCHDOG, WTCNT, 0x8000, watchdog->wtcnt)
|
S3C2410_OFFSET( WATCHDOG, WTCNT, 0x8000, watchdog->wtcnt ) };
|
||||||
};
|
|
||||||
|
|
||||||
memset( watchdog, 0, sizeof( s3c2410_watchdog_t ) );
|
memset( watchdog, 0, sizeof( s3c2410_watchdog_t ) );
|
||||||
|
|
||||||
watchdog->regs = malloc( sizeof( regs ) );
|
watchdog->regs = malloc( sizeof( regs ) );
|
||||||
if ( NULL == watchdog->regs ) {
|
if ( NULL == watchdog->regs ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +47,7 @@ s3c2410_watchdog_data_init(s3c2410_watchdog_t *watchdog)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_watchdog_tick( void* data )
|
||||||
s3c2410_watchdog_tick(void *data)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = data;
|
s3c2410_watchdog_t* watchdog = data;
|
||||||
x49gp_t* x49gp = watchdog->x49gp;
|
x49gp_t* x49gp = watchdog->x49gp;
|
||||||
|
@ -100,8 +94,7 @@ s3c2410_watchdog_tick(void *data)
|
||||||
x49gp_mod_timer( watchdog->timer, x49gp_get_clock() + watchdog->interval );
|
x49gp_mod_timer( watchdog->timer, x49gp_get_clock() + watchdog->interval );
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long
|
unsigned long s3c2410_watchdog_next_interrupt( x49gp_t* x49gp )
|
||||||
s3c2410_watchdog_next_interrupt(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = x49gp->s3c2410_watchdog;
|
s3c2410_watchdog_t* watchdog = x49gp->s3c2410_watchdog;
|
||||||
unsigned long irq;
|
unsigned long irq;
|
||||||
|
@ -126,15 +119,14 @@ s3c2410_watchdog_next_interrupt(x49gp_t *x49gp)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_WATCHDOG
|
#ifdef DEBUG_S3C2410_WATCHDOG
|
||||||
printf("WATCHDOG: wtcnt %u, interval %lu, expires %llu, next irq %lu\n",
|
printf( "WATCHDOG: wtcnt %u, interval %lu, expires %llu, next irq %lu\n", watchdog->wtcnt, watchdog->interval,
|
||||||
watchdog->wtcnt, watchdog->interval, (unsigned long long) (x49gp_timer_pending(watchdog->timer) ? x49gp_timer_expires(watchdog->timer) : 0), irq);
|
( unsigned long long )( x49gp_timer_pending( watchdog->timer ) ? x49gp_timer_expires( watchdog->timer ) : 0 ), irq );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return irq;
|
return irq;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_update( s3c2410_watchdog_t* watchdog )
|
||||||
s3c2410_watchdog_update(s3c2410_watchdog_t *watchdog)
|
|
||||||
{
|
{
|
||||||
uint32_t pre, mux;
|
uint32_t pre, mux;
|
||||||
|
|
||||||
|
@ -158,8 +150,7 @@ s3c2410_watchdog_update(s3c2410_watchdog_t *watchdog)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t s3c2410_watchdog_read( void* opaque, target_phys_addr_t offset )
|
||||||
s3c2410_watchdog_read(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = opaque;
|
s3c2410_watchdog_t* watchdog = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -170,18 +161,15 @@ s3c2410_watchdog_read(void *opaque, target_phys_addr_t offset)
|
||||||
|
|
||||||
reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
|
reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_WATCHDOG
|
#ifdef DEBUG_S3C2410_WATCHDOG
|
||||||
printf("read %s [%08x] %s [%08lx] data %08x\n",
|
printf( "read %s [%08x] %s [%08lx] data %08x\n", "s3c2410-watchdog", S3C2410_WATCHDOG_BASE, reg->name, ( unsigned long )offset,
|
||||||
"s3c2410-watchdog", S3C2410_WATCHDOG_BASE,
|
*( reg->datap ) );
|
||||||
reg->name, (unsigned long) offset, *(reg->datap));
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return *( reg->datap );
|
return *( reg->datap );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void s3c2410_watchdog_write( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
s3c2410_watchdog_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = opaque;
|
s3c2410_watchdog_t* watchdog = opaque;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -193,9 +181,7 @@ s3c2410_watchdog_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
|
reg = S3C2410_OFFSET_ENTRY( watchdog, offset );
|
||||||
|
|
||||||
#ifdef DEBUG_S3C2410_WATCHDOG
|
#ifdef DEBUG_S3C2410_WATCHDOG
|
||||||
printf("write %s [%08x] %s [%08lx] data %08x\n",
|
printf( "write %s [%08x] %s [%08lx] data %08x\n", "s3c2410-watchdog", S3C2410_WATCHDOG_BASE, reg->name, ( unsigned long )offset, data );
|
||||||
"s3c2410-watchdog", S3C2410_WATCHDOG_BASE,
|
|
||||||
reg->name, (unsigned long) offset, data);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*( reg->datap ) = data;
|
*( reg->datap ) = data;
|
||||||
|
@ -210,8 +196,7 @@ s3c2410_watchdog_write(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_watchdog_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = module->user_data;
|
s3c2410_watchdog_t* watchdog = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -228,8 +213,7 @@ s3c2410_watchdog_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
if ( NULL == reg->name )
|
if ( NULL == reg->name )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (x49gp_module_get_u32(module, key, reg->name,
|
if ( x49gp_module_get_u32( module, key, reg->name, reg->reset, reg->datap ) )
|
||||||
reg->reset, reg->datap))
|
|
||||||
error = -EAGAIN;
|
error = -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,8 +222,7 @@ s3c2410_watchdog_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
s3c2410_watchdog_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = module->user_data;
|
s3c2410_watchdog_t* watchdog = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -261,8 +244,7 @@ s3c2410_watchdog_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
s3c2410_watchdog_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog = module->user_data;
|
s3c2410_watchdog_t* watchdog = module->user_data;
|
||||||
s3c2410_offset_t* reg;
|
s3c2410_offset_t* reg;
|
||||||
|
@ -286,22 +268,11 @@ s3c2410_watchdog_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *s3c2410_watchdog_readfn[] =
|
static CPUReadMemoryFunc* s3c2410_watchdog_readfn[] = { s3c2410_watchdog_read, s3c2410_watchdog_read, s3c2410_watchdog_read };
|
||||||
{
|
|
||||||
s3c2410_watchdog_read,
|
|
||||||
s3c2410_watchdog_read,
|
|
||||||
s3c2410_watchdog_read
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *s3c2410_watchdog_writefn[] =
|
static CPUWriteMemoryFunc* s3c2410_watchdog_writefn[] = { s3c2410_watchdog_write, s3c2410_watchdog_write, s3c2410_watchdog_write };
|
||||||
{
|
|
||||||
s3c2410_watchdog_write,
|
|
||||||
s3c2410_watchdog_write,
|
|
||||||
s3c2410_watchdog_write
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_init( x49gp_module_t* module )
|
||||||
s3c2410_watchdog_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog;
|
s3c2410_watchdog_t* watchdog;
|
||||||
int iotype;
|
int iotype;
|
||||||
|
@ -312,8 +283,7 @@ s3c2410_watchdog_init(x49gp_module_t *module)
|
||||||
|
|
||||||
watchdog = malloc( sizeof( s3c2410_watchdog_t ) );
|
watchdog = malloc( sizeof( s3c2410_watchdog_t ) );
|
||||||
if ( NULL == watchdog ) {
|
if ( NULL == watchdog ) {
|
||||||
fprintf(stderr, "%s: %s:%u: Out of memory\n",
|
fprintf( stderr, "%s: %s:%u: Out of memory\n", module->x49gp->progname, __FUNCTION__, __LINE__ );
|
||||||
module->x49gp->progname, __FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
if ( s3c2410_watchdog_data_init( watchdog ) ) {
|
if ( s3c2410_watchdog_data_init( watchdog ) ) {
|
||||||
|
@ -326,11 +296,9 @@ s3c2410_watchdog_init(x49gp_module_t *module)
|
||||||
watchdog->x49gp = module->x49gp;
|
watchdog->x49gp = module->x49gp;
|
||||||
module->x49gp->s3c2410_watchdog = watchdog;
|
module->x49gp->s3c2410_watchdog = watchdog;
|
||||||
|
|
||||||
watchdog->timer = x49gp_new_timer(X49GP_TIMER_VIRTUAL,
|
watchdog->timer = x49gp_new_timer( X49GP_TIMER_VIRTUAL, s3c2410_watchdog_tick, watchdog );
|
||||||
s3c2410_watchdog_tick, watchdog);
|
|
||||||
|
|
||||||
iotype = cpu_register_io_memory(s3c2410_watchdog_readfn,
|
iotype = cpu_register_io_memory( s3c2410_watchdog_readfn, s3c2410_watchdog_writefn, watchdog );
|
||||||
s3c2410_watchdog_writefn, watchdog);
|
|
||||||
#ifdef DEBUG_S3C2410_WATCHDOG
|
#ifdef DEBUG_S3C2410_WATCHDOG
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
#endif
|
#endif
|
||||||
|
@ -338,8 +306,7 @@ s3c2410_watchdog_init(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int s3c2410_watchdog_exit( x49gp_module_t* module )
|
||||||
s3c2410_watchdog_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
s3c2410_watchdog_t* watchdog;
|
s3c2410_watchdog_t* watchdog;
|
||||||
|
|
||||||
|
@ -360,18 +327,12 @@ s3c2410_watchdog_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_s3c2410_watchdog_init( x49gp_t* x49gp )
|
||||||
x49gp_s3c2410_watchdog_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "s3c2410-watchdog",
|
if ( x49gp_module_init( x49gp, "s3c2410-watchdog", s3c2410_watchdog_init, s3c2410_watchdog_exit, s3c2410_watchdog_reset,
|
||||||
s3c2410_watchdog_init,
|
s3c2410_watchdog_load, s3c2410_watchdog_save, NULL, &module ) ) {
|
||||||
s3c2410_watchdog_exit,
|
|
||||||
s3c2410_watchdog_reset,
|
|
||||||
s3c2410_watchdog_load,
|
|
||||||
s3c2410_watchdog_save,
|
|
||||||
NULL, &module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
147
src/sram.c
147
src/sram.c
|
@ -33,9 +33,8 @@ typedef struct {
|
||||||
|
|
||||||
#define SATURN( r ) ( ( target_phys_addr_t ) & ( ( saturn_cpu_t* )0 )->r )
|
#define SATURN( r ) ( ( target_phys_addr_t ) & ( ( saturn_cpu_t* )0 )->r )
|
||||||
|
|
||||||
#if defined(DEBUG_X49GP_SYSRAM_READ) || defined(DEBUG_X49GP_SYSRAM_WRITE) || \
|
#if defined( DEBUG_X49GP_SYSRAM_READ ) || defined( DEBUG_X49GP_SYSRAM_WRITE ) || defined( DEBUG_X49GP_IRAM_READ ) || \
|
||||||
defined(DEBUG_X49GP_IRAM_READ) || defined(DEBUG_X49GP_IRAM_WRITE) || \
|
defined( DEBUG_X49GP_IRAM_WRITE ) || defined( DEBUG_X49GP_ERAM_READ ) || defined( DEBUG_X49GP_ERAM_WRITE )
|
||||||
defined(DEBUG_X49GP_ERAM_READ) || defined(DEBUG_X49GP_ERAM_WRITE)
|
|
||||||
# define DEBUG_X49GP_SRAM 1
|
# define DEBUG_X49GP_SRAM 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -49,8 +48,7 @@ typedef struct {
|
||||||
|
|
||||||
#ifdef DEBUG_X49GP_SRAM
|
#ifdef DEBUG_X49GP_SRAM
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t saturn_map_s2a( saturn_cpu_t* saturn, uint32_t saddr )
|
||||||
saturn_map_s2a(saturn_cpu_t *saturn, uint32_t saddr)
|
|
||||||
{
|
{
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
|
|
||||||
|
@ -61,8 +59,7 @@ saturn_map_s2a(saturn_cpu_t *saturn, uint32_t saddr)
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t saturn_peek( saturn_cpu_t* saturn, uint32_t saddr, uint32_t size )
|
||||||
saturn_peek(saturn_cpu_t *saturn, uint32_t saddr, uint32_t size)
|
|
||||||
{
|
{
|
||||||
uint32_t addr, rot, mask, data;
|
uint32_t addr, rot, mask, data;
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
|
@ -85,14 +82,9 @@ saturn_peek(saturn_cpu_t *saturn, uint32_t saddr, uint32_t size)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t saturn_peek_address( saturn_cpu_t* saturn, uint32_t saddr ) { return saturn_peek( saturn, saddr, 5 ); }
|
||||||
saturn_peek_address(saturn_cpu_t *saturn, uint32_t saddr)
|
|
||||||
{
|
|
||||||
return saturn_peek(saturn, saddr, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int hxs2real( int hxs )
|
||||||
hxs2real(int hxs)
|
|
||||||
{
|
{
|
||||||
int n = 0, c = 1;
|
int n = 0, c = 1;
|
||||||
|
|
||||||
|
@ -104,8 +96,7 @@ hxs2real(int hxs)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char* real_number( saturn_cpu_t* saturn, uint32_t saddr, char* buffer, int ml, int xl )
|
||||||
real_number(saturn_cpu_t *saturn, uint32_t saddr, char *buffer, int ml, int xl)
|
|
||||||
{
|
{
|
||||||
char* p = buffer;
|
char* p = buffer;
|
||||||
char fmt[ 20 ];
|
char fmt[ 20 ];
|
||||||
|
@ -208,8 +199,7 @@ real_number(saturn_cpu_t *saturn, uint32_t saddr, char *buffer, int ml, int xl)
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t dump_object( x49gp_t* x49gp, x49gp_sram_t* sram, uint32_t saddr )
|
||||||
dump_object(x49gp_t *x49gp, x49gp_sram_t *sram, uint32_t saddr)
|
|
||||||
{
|
{
|
||||||
saturn_cpu_t* saturn = ( sram->data + 0x3340 );
|
saturn_cpu_t* saturn = ( sram->data + 0x3340 );
|
||||||
char buffer[ 128 ];
|
char buffer[ 128 ];
|
||||||
|
@ -239,8 +229,7 @@ dump_object(x49gp_t *x49gp, x49gp_sram_t *sram, uint32_t saddr)
|
||||||
n = saturn_peek( saturn, pc, 5 );
|
n = saturn_peek( saturn, pc, 5 );
|
||||||
pc += 5;
|
pc += 5;
|
||||||
if ( n <= 16 ) {
|
if ( n <= 16 ) {
|
||||||
printf(" #%08x%08xh", saturn_peek(saturn, pc + 8, 8),
|
printf( " #%08x%08xh", saturn_peek( saturn, pc + 8, 8 ), saturn_peek( saturn, pc + 0, 8 ) );
|
||||||
saturn_peek(saturn, pc + 0, 8));
|
|
||||||
} else {
|
} else {
|
||||||
printf( " C#" );
|
printf( " C#" );
|
||||||
for ( i = 0; i < n; i++ ) {
|
for ( i = 0; i < n; i++ ) {
|
||||||
|
@ -266,14 +255,12 @@ dump_object(x49gp_t *x49gp, x49gp_sram_t *sram, uint32_t saddr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x02e92:
|
case 0x02e92:
|
||||||
printf(" <%03x %03x>", saturn_peek(saturn, pc + 0, 3),
|
printf( " <%03x %03x>", saturn_peek( saturn, pc + 0, 3 ), saturn_peek( saturn, pc + 3, 3 ) );
|
||||||
saturn_peek(saturn, pc + 3, 3));
|
|
||||||
pc += 6;
|
pc += 6;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x026ac:
|
case 0x026ac:
|
||||||
printf(" <%03x %04x>", saturn_peek(saturn, pc + 0, 3),
|
printf( " <%03x %04x>", saturn_peek( saturn, pc + 0, 3 ), saturn_peek( saturn, pc + 3, 4 ) );
|
||||||
saturn_peek(saturn, pc + 3, 4));
|
|
||||||
pc += 7;
|
pc += 7;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -311,8 +298,7 @@ dump_object(x49gp_t *x49gp, x49gp_sram_t *sram, uint32_t saddr)
|
||||||
return pc - saddr;
|
return pc - saddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void debug_saturn( x49gp_t* x49gp, x49gp_sram_t* sram )
|
||||||
debug_saturn(x49gp_t *x49gp, x49gp_sram_t *sram)
|
|
||||||
{
|
{
|
||||||
saturn_cpu_t* saturn = ( sram->data + 0x3340 );
|
saturn_cpu_t* saturn = ( sram->data + 0x3340 );
|
||||||
uint32_t sp, se;
|
uint32_t sp, se;
|
||||||
|
@ -361,7 +347,6 @@ debug_saturn(x49gp_t *x49gp, x49gp_sram_t *sram)
|
||||||
printf( "SATURN: RSTK %02u: %05x\n", i, se );
|
printf( "SATURN: RSTK %02u: %05x\n", i, se );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
depth = ( saturn_peek_address( saturn, SAT_EDITLINE ) - saturn_peek_address( saturn, SAT_DSKTOP ) - 5 ) / 5;
|
depth = ( saturn_peek_address( saturn, SAT_EDITLINE ) - saturn_peek_address( saturn, SAT_DSKTOP ) - 5 ) / 5;
|
||||||
|
|
||||||
printf( "SATURN: depth %d\n", depth );
|
printf( "SATURN: depth %d\n", depth );
|
||||||
|
@ -382,8 +367,7 @@ debug_saturn(x49gp_t *x49gp, x49gp_sram_t *sram)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t sram_get_word( void* opaque, target_phys_addr_t offset )
|
||||||
sram_get_word(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
uint32_t data;
|
uint32_t data;
|
||||||
|
@ -415,8 +399,7 @@ sram_get_word(void *opaque, target_phys_addr_t offset)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t sram_get_halfword( void* opaque, target_phys_addr_t offset )
|
||||||
sram_get_halfword(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
unsigned short data;
|
unsigned short data;
|
||||||
|
@ -442,8 +425,7 @@ sram_get_halfword(void *opaque, target_phys_addr_t offset)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t
|
static uint32_t sram_get_byte( void* opaque, target_phys_addr_t offset )
|
||||||
sram_get_byte(void *opaque, target_phys_addr_t offset)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
unsigned char data;
|
unsigned char data;
|
||||||
|
@ -469,14 +451,12 @@ sram_get_byte(void *opaque, target_phys_addr_t offset)
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void sram_put_word( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
sram_put_word(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
|
|
||||||
if ( offset == 0x00000a1c ) {
|
if ( offset == 0x00000a1c ) {
|
||||||
printf("write SRAM 4 at offset %08x: %08x (pc %08x)\n",
|
printf( "write SRAM 4 at offset %08x: %08x (pc %08x)\n", offset, data, sram->x49gp->env->regs[ 15 ] );
|
||||||
offset, data, sram->x49gp->env->regs[15]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_saturn( sram->x49gp, sram );
|
debug_saturn( sram->x49gp, sram );
|
||||||
|
@ -515,8 +495,7 @@ sram_put_word(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
stl_p( sram->data + offset, data );
|
stl_p( sram->data + offset, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void sram_put_halfword( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
sram_put_halfword(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
|
|
||||||
|
@ -541,8 +520,7 @@ sram_put_halfword(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
stw_p( sram->data + offset, data );
|
stw_p( sram->data + offset, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void sram_put_byte( void* opaque, target_phys_addr_t offset, uint32_t data )
|
||||||
sram_put_byte(void *opaque, target_phys_addr_t offset, uint32_t data)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = opaque;
|
x49gp_sram_t* sram = opaque;
|
||||||
|
|
||||||
|
@ -567,24 +545,13 @@ sram_put_byte(void *opaque, target_phys_addr_t offset, uint32_t data)
|
||||||
stb_p( sram->data + offset, data );
|
stb_p( sram->data + offset, data );
|
||||||
}
|
}
|
||||||
|
|
||||||
static CPUReadMemoryFunc *sram_readfn[] =
|
static CPUReadMemoryFunc* sram_readfn[] = { sram_get_byte, sram_get_halfword, sram_get_word };
|
||||||
{
|
|
||||||
sram_get_byte,
|
|
||||||
sram_get_halfword,
|
|
||||||
sram_get_word
|
|
||||||
};
|
|
||||||
|
|
||||||
static CPUWriteMemoryFunc *sram_writefn[] =
|
static CPUWriteMemoryFunc* sram_writefn[] = { sram_put_byte, sram_put_halfword, sram_put_word };
|
||||||
{
|
|
||||||
sram_put_byte,
|
|
||||||
sram_put_halfword,
|
|
||||||
sram_put_word
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* DEBUG_X49GP_SRAM */
|
#endif /* DEBUG_X49GP_SRAM */
|
||||||
|
|
||||||
static int
|
static int sram_load( x49gp_module_t* module, GKeyFile* key )
|
||||||
sram_load(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = module->user_data;
|
x49gp_sram_t* sram = module->user_data;
|
||||||
char* filename;
|
char* filename;
|
||||||
|
@ -594,15 +561,12 @@ sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
error = x49gp_module_get_filename(module, key, "filename", "sram",
|
error = x49gp_module_get_filename( module, key, "filename", "sram", &( sram->filename ), &filename );
|
||||||
&(sram->filename), &filename);
|
|
||||||
|
|
||||||
sram->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
sram->fd = open( filename, O_RDWR | O_CREAT, 0644 );
|
||||||
if ( sram->fd < 0 ) {
|
if ( sram->fd < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: open %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: open %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -610,38 +574,28 @@ sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
sram->size = 0x00080000;
|
sram->size = 0x00080000;
|
||||||
if ( ftruncate( sram->fd, sram->size ) < 0 ) {
|
if ( ftruncate( sram->fd, sram->size ) < 0 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: ftruncate %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: ftruncate %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( sram->fd );
|
close( sram->fd );
|
||||||
sram->fd = -1;
|
sram->fd = -1;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
sram->data = mmap(phys_ram_base + sram->offset, sram->size,
|
sram->data = mmap( phys_ram_base + sram->offset, sram->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, sram->fd, 0 );
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
|
|
||||||
sram->fd, 0);
|
|
||||||
if ( sram->data == ( void* )-1 ) {
|
if ( sram->data == ( void* )-1 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: mmap %s: %s\n",
|
fprintf( stderr, "%s: %s:%u: mmap %s: %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( sram->fd );
|
close( sram->fd );
|
||||||
sram->fd = -1;
|
sram->fd = -1;
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
sram->shadow = mmap(phys_ram_base + sram->offset + sram->size,
|
sram->shadow =
|
||||||
sram->size,
|
mmap( phys_ram_base + sram->offset + sram->size, sram->size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, sram->fd, 0 );
|
||||||
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
|
|
||||||
sram->fd, 0);
|
|
||||||
if ( sram->shadow == ( void* )-1 ) {
|
if ( sram->shadow == ( void* )-1 ) {
|
||||||
error = -errno;
|
error = -errno;
|
||||||
fprintf(stderr, "%s: %s:%u: mmap %s (shadow): %s\n",
|
fprintf( stderr, "%s: %s:%u: mmap %s (shadow): %s\n", module->name, __FUNCTION__, __LINE__, filename, strerror( errno ) );
|
||||||
module->name, __FUNCTION__, __LINE__,
|
|
||||||
filename, strerror(errno));
|
|
||||||
g_free( filename );
|
g_free( filename );
|
||||||
close( sram->fd );
|
close( sram->fd );
|
||||||
sram->fd = -1;
|
sram->fd = -1;
|
||||||
|
@ -654,8 +608,7 @@ sram_load(x49gp_module_t *module, GKeyFile *key)
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sram_save( x49gp_module_t* module, GKeyFile* key )
|
||||||
sram_save(x49gp_module_t *module, GKeyFile *key)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram = module->user_data;
|
x49gp_sram_t* sram = module->user_data;
|
||||||
int error;
|
int error;
|
||||||
|
@ -668,23 +621,20 @@ sram_save(x49gp_module_t *module, GKeyFile *key)
|
||||||
|
|
||||||
error = msync( sram->data, sram->size, MS_ASYNC );
|
error = msync( sram->data, sram->size, MS_ASYNC );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: msync: %s\n",
|
fprintf( stderr, "%s:%u: msync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = fsync( sram->fd );
|
error = fsync( sram->fd );
|
||||||
if ( error ) {
|
if ( error ) {
|
||||||
fprintf(stderr, "%s:%u: fsync: %s\n",
|
fprintf( stderr, "%s:%u: fsync: %s\n", __FUNCTION__, __LINE__, strerror( errno ) );
|
||||||
__FUNCTION__, __LINE__, strerror(errno));
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sram_reset( x49gp_module_t* module, x49gp_reset_t reset )
|
||||||
sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
|
||||||
{
|
{
|
||||||
#ifdef DEBUG_X49GP_MODULES
|
#ifdef DEBUG_X49GP_MODULES
|
||||||
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
printf( "%s: %s:%u\n", module->name, __FUNCTION__, __LINE__ );
|
||||||
|
@ -693,8 +643,7 @@ sram_reset(x49gp_module_t *module, x49gp_reset_t reset)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sram_init( x49gp_module_t* module )
|
||||||
sram_init(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram;
|
x49gp_sram_t* sram;
|
||||||
|
|
||||||
|
@ -704,8 +653,7 @@ sram_init(x49gp_module_t *module)
|
||||||
|
|
||||||
sram = malloc( sizeof( x49gp_sram_t ) );
|
sram = malloc( sizeof( x49gp_sram_t ) );
|
||||||
if ( NULL == sram ) {
|
if ( NULL == sram ) {
|
||||||
fprintf(stderr, "%s:%u: Out of memory\n",
|
fprintf( stderr, "%s:%u: Out of memory\n", __FUNCTION__, __LINE__ );
|
||||||
__FUNCTION__, __LINE__);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
memset( sram, 0, sizeof( x49gp_sram_t ) );
|
memset( sram, 0, sizeof( x49gp_sram_t ) );
|
||||||
|
@ -727,29 +675,23 @@ sram_init(x49gp_module_t *module)
|
||||||
|
|
||||||
iotype = cpu_register_io_memory( 0, sram_readfn, sram_writefn, sram );
|
iotype = cpu_register_io_memory( 0, sram_readfn, sram_writefn, sram );
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
cpu_register_physical_memory(S3C2410_SRAM_BASE,
|
cpu_register_physical_memory( S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE, sram->offset | iotype | IO_MEM_ROMD );
|
||||||
S3C2410_SRAM_SIZE,
|
|
||||||
sram->offset | iotype | IO_MEM_ROMD);
|
|
||||||
|
|
||||||
iotype = cpu_register_io_memory( 0, sram_readfn, sram_writefn, sram );
|
iotype = cpu_register_io_memory( 0, sram_readfn, sram_writefn, sram );
|
||||||
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
printf( "%s: iotype %08x\n", __FUNCTION__, iotype );
|
||||||
cpu_register_physical_memory(S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE,
|
cpu_register_physical_memory( S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE, S3C2410_SRAM_SIZE,
|
||||||
S3C2410_SRAM_SIZE,
|
|
||||||
( sram->offset + S3C2410_SRAM_SIZE ) | iotype | IO_MEM_ROMD );
|
( sram->offset + S3C2410_SRAM_SIZE ) | iotype | IO_MEM_ROMD );
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
cpu_register_physical_memory(S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE,
|
cpu_register_physical_memory( S3C2410_SRAM_BASE, S3C2410_SRAM_SIZE, sram->offset | IO_MEM_RAM );
|
||||||
sram->offset | IO_MEM_RAM);
|
cpu_register_physical_memory( S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE, S3C2410_SRAM_SIZE,
|
||||||
cpu_register_physical_memory(S3C2410_SRAM_BASE + S3C2410_SRAM_SIZE,
|
|
||||||
S3C2410_SRAM_SIZE,
|
|
||||||
( sram->offset + S3C2410_SRAM_SIZE ) | IO_MEM_RAM );
|
( sram->offset + S3C2410_SRAM_SIZE ) | IO_MEM_RAM );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int sram_exit( x49gp_module_t* module )
|
||||||
sram_exit(x49gp_module_t *module)
|
|
||||||
{
|
{
|
||||||
x49gp_sram_t* sram;
|
x49gp_sram_t* sram;
|
||||||
|
|
||||||
|
@ -779,14 +721,11 @@ sram_exit(x49gp_module_t *module)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_sram_init( x49gp_t* x49gp )
|
||||||
x49gp_sram_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
x49gp_module_t* module;
|
x49gp_module_t* module;
|
||||||
|
|
||||||
if (x49gp_module_init(x49gp, "sram", sram_init, sram_exit,
|
if ( x49gp_module_init( x49gp, "sram", sram_init, sram_exit, sram_reset, sram_load, sram_save, NULL, &module ) ) {
|
||||||
sram_reset, sram_load, sram_save, NULL,
|
|
||||||
&module)) {
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
175
src/symbol.c
175
src/symbol.c
|
@ -9,144 +9,71 @@
|
||||||
|
|
||||||
#include "symbol.h"
|
#include "symbol.h"
|
||||||
|
|
||||||
static const cairo_path_data_t symbol_square_path_data[] =
|
static const cairo_path_data_t symbol_square_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.100 ), SYMBOL_LINE_TO( 0.500, 0.000 ),
|
||||||
{
|
SYMBOL_LINE_TO( 0.000, 0.500 ), SYMBOL_LINE_TO( -0.500, 0.000 ),
|
||||||
SYMBOL_MOVE_TO( 0.100, 0.100 ),
|
SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_LINE_TO( 0.500, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, 0.500 ),
|
|
||||||
SYMBOL_LINE_TO( -0.500, 0.000 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( square, 0.7, 0.0, 0.1, 0.1, 0.6, 0.6 );
|
SYMBOL( square, 0.7, 0.0, 0.1, 0.1, 0.6, 0.6 );
|
||||||
|
|
||||||
|
static const cairo_path_data_t symbol_triangleup_path_data[] = { SYMBOL_MOVE_TO( 0.100, 0.000 ), SYMBOL_LINE_TO( 0.800, 0.000 ),
|
||||||
static const cairo_path_data_t symbol_triangleup_path_data[] =
|
SYMBOL_LINE_TO( -0.400, 0.693 ), SYMBOL_CLOSE_PATH() };
|
||||||
{
|
|
||||||
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 ),
|
||||||
static const cairo_path_data_t symbol_triangleright_path_data[] =
|
SYMBOL_LINE_TO( 0.693, -0.400 ), SYMBOL_CLOSE_PATH() };
|
||||||
{
|
|
||||||
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 );
|
SYMBOL( triangleright, 0.893, 0.0, 0.1, 0.0, 0.793, 0.8 );
|
||||||
|
|
||||||
|
static const cairo_path_data_t symbol_arrowleftdblfull_path_data[] = {
|
||||||
static const cairo_path_data_t symbol_arrowleftdblfull_path_data[] =
|
SYMBOL_MOVE_TO( 0.100, 0.370 ), SYMBOL_LINE_TO( 0.652, 0.500 ), SYMBOL_LINE_TO( 0.000, -0.250 ), SYMBOL_LINE_TO( 1.000, 0.000 ),
|
||||||
{
|
SYMBOL_LINE_TO( 0.000, -0.500 ), SYMBOL_LINE_TO( -1.000, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.250 ), SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_MOVE_TO( 0.100, 0.370 ),
|
|
||||||
SYMBOL_LINE_TO( 0.652, 0.500 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.250 ),
|
|
||||||
SYMBOL_LINE_TO( 1.000, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.500 ),
|
|
||||||
SYMBOL_LINE_TO( -1.000, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.250 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( arrowleftdblfull, 1.852, 0.0, 0.1, -0.13, 1.752, 0.87 );
|
SYMBOL( arrowleftdblfull, 1.852, 0.0, 0.1, -0.13, 1.752, 0.87 );
|
||||||
|
|
||||||
static const cairo_path_data_t symbol_uparrowleft_path_data[] =
|
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_MOVE_TO( 0.100, 0.500 ),
|
SYMBOL_LINE_TO( 0.000, -0.550 ), SYMBOL_LINE_TO( -0.100, 0.000 ),
|
||||||
SYMBOL_LINE_TO( 0.600, 0.200 ),
|
SYMBOL_LINE_TO( 0.000, 0.450 ), SYMBOL_LINE_TO( -0.400, 0.000 ),
|
||||||
SYMBOL_LINE_TO( 0.000, -0.150 ),
|
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_LINE_TO( 0.500, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.550 ),
|
|
||||||
SYMBOL_LINE_TO( -0.100, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, 0.450 ),
|
|
||||||
SYMBOL_LINE_TO( -0.400, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.150 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( uparrowleft, 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_uparrowright_path_data[] = { SYMBOL_MOVE_TO( 1.200, 0.500 ), SYMBOL_LINE_TO( -0.600, 0.200 ),
|
||||||
static const cairo_path_data_t symbol_uparrowright_path_data[] =
|
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_MOVE_TO( 1.200, 0.500 ),
|
SYMBOL_LINE_TO( 0.000, 0.450 ), SYMBOL_LINE_TO( 0.400, 0.000 ),
|
||||||
SYMBOL_LINE_TO( -0.600, 0.200 ),
|
SYMBOL_LINE_TO( 0.000, -0.150 ), SYMBOL_CLOSE_PATH() };
|
||||||
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( uparrowright, 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 ),
|
||||||
static const cairo_path_data_t symbol_tick_path_data[] =
|
SYMBOL_LINE_TO( 0.150, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.450 ),
|
||||||
{
|
SYMBOL_CLOSE_PATH() };
|
||||||
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 );
|
SYMBOL( tick, 0.35, 0.0, 0.1, 0.4, 0.25, 0.85 );
|
||||||
|
|
||||||
|
static const cairo_path_data_t symbol_radical_path_data[] = { SYMBOL_MOVE_TO( 0.000, 0.500 ), SYMBOL_LINE_TO( 0.214, 0.100 ),
|
||||||
static const cairo_path_data_t symbol_radical_path_data[] =
|
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_MOVE_TO( 0.000, 0.500 ),
|
SYMBOL_LINE_TO( -0.281, -1.050 ), SYMBOL_LINE_TO( -0.287, 0.616 ),
|
||||||
SYMBOL_LINE_TO( 0.214, 0.100 ),
|
SYMBOL_LINE_TO( -0.123, -0.057 ), SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_LINE_TO( 0.213, -0.456 ),
|
|
||||||
SYMBOL_LINE_TO( 0.229, 0.856 ),
|
|
||||||
SYMBOL_LINE_TO( 0.077, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.100 ),
|
|
||||||
SYMBOL_LINE_TO( -0.281, -1.050 ),
|
|
||||||
SYMBOL_LINE_TO( -0.287, 0.616 ),
|
|
||||||
SYMBOL_LINE_TO( -0.123, -0.057 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( radical, 0.733, 0.0, 0.0, -0.15, 0.733, 1.0 );
|
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 ),
|
||||||
static const cairo_path_data_t symbol_overscore_path_data[] =
|
SYMBOL_LINE_TO( 0.000, -0.100 ), SYMBOL_LINE_TO( -0.900, 0.000 ),
|
||||||
{
|
SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_MOVE_TO( 0.000, 1.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.900, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, -0.100 ),
|
|
||||||
SYMBOL_LINE_TO( -0.900, 0.000 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( overscore, 0.8, 0.0, 0.0, 0.9, 0.9, 1.0 );
|
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 ),
|
||||||
static const cairo_path_data_t symbol_minus_path_data[] =
|
SYMBOL_LINE_TO( 0.500, 0.000 ), SYMBOL_LINE_TO( 0.000, -0.118 ),
|
||||||
{
|
SYMBOL_CLOSE_PATH() };
|
||||||
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 );
|
SYMBOL( minus, 0.6, 0.0, 0.05, 0.312, 0.55, 0.430 );
|
||||||
|
|
||||||
|
static const cairo_path_data_t symbol_divide_path_data[] = { SYMBOL_MOVE_TO( 0.050, 0.312 ),
|
||||||
static const cairo_path_data_t symbol_divide_path_data[] =
|
|
||||||
{
|
|
||||||
SYMBOL_MOVE_TO( 0.050, 0.312 ),
|
|
||||||
SYMBOL_LINE_TO( 0.000, 0.118 ),
|
SYMBOL_LINE_TO( 0.000, 0.118 ),
|
||||||
SYMBOL_LINE_TO( 0.500, 0.000 ),
|
SYMBOL_LINE_TO( 0.500, 0.000 ),
|
||||||
SYMBOL_LINE_TO( 0.000, -0.118 ),
|
SYMBOL_LINE_TO( 0.000, -0.118 ),
|
||||||
|
@ -160,24 +87,16 @@ static const cairo_path_data_t symbol_divide_path_data[] =
|
||||||
SYMBOL_LINE_TO( 0.000, 0.135 ),
|
SYMBOL_LINE_TO( 0.000, 0.135 ),
|
||||||
SYMBOL_LINE_TO( 0.135, 0.000 ),
|
SYMBOL_LINE_TO( 0.135, 0.000 ),
|
||||||
SYMBOL_LINE_TO( 0.000, -0.135 ),
|
SYMBOL_LINE_TO( 0.000, -0.135 ),
|
||||||
SYMBOL_CLOSE_PATH()
|
SYMBOL_CLOSE_PATH() };
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( divide, 0.6, 0.0, 0.05, 0.069, 0.55, 0.673 );
|
SYMBOL( divide, 0.6, 0.0, 0.05, 0.069, 0.55, 0.673 );
|
||||||
|
|
||||||
|
static const cairo_path_data_t symbol_divisionslash_path_data[] = { SYMBOL_MOVE_TO( 0.050, 0.000 ), SYMBOL_LINE_TO( 0.345, 0.739 ),
|
||||||
static const cairo_path_data_t symbol_divisionslash_path_data[] =
|
SYMBOL_LINE_TO( 0.130, 0.000 ), SYMBOL_LINE_TO( -0.345, -0.739 ),
|
||||||
{
|
SYMBOL_CLOSE_PATH() };
|
||||||
SYMBOL_MOVE_TO( 0.050, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( 0.345, 0.739 ),
|
|
||||||
SYMBOL_LINE_TO( 0.130, 0.000 ),
|
|
||||||
SYMBOL_LINE_TO( -0.345, -0.739 ),
|
|
||||||
SYMBOL_CLOSE_PATH()
|
|
||||||
};
|
|
||||||
|
|
||||||
SYMBOL( divisionslash, 0.575, 0.000, 0.050, 0.000, 0.525, 0.739 );
|
SYMBOL( divisionslash, 0.575, 0.000, 0.050, 0.000, 0.525, 0.739 );
|
||||||
|
|
||||||
|
|
||||||
CONTROL( beginsuperscript, 0.0, 0.5, 1.0, 0.8 );
|
CONTROL( beginsuperscript, 0.0, 0.5, 1.0, 0.8 );
|
||||||
CONTROL( endsuperscript, 0.0, 0.5, 1.25, 1.0 );
|
CONTROL( endsuperscript, 0.0, 0.5, 1.25, 1.0 );
|
||||||
|
|
||||||
|
@ -191,14 +110,12 @@ CONTROL(kern_m7, -0.7, 0.0, 1.0, 1.0);
|
||||||
CONTROL( kern_m8, -0.8, 0.0, 1.0, 1.0 );
|
CONTROL( kern_m8, -0.8, 0.0, 1.0, 1.0 );
|
||||||
CONTROL( kern_m9, -0.9, 0.0, 1.0, 1.0 );
|
CONTROL( kern_m9, -0.9, 0.0, 1.0, 1.0 );
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* name;
|
const char* name;
|
||||||
const x49gp_symbol_t* symbol;
|
const x49gp_symbol_t* symbol;
|
||||||
} symbol_name_t;
|
} symbol_name_t;
|
||||||
|
|
||||||
static const symbol_name_t symbol_names[] =
|
static const symbol_name_t symbol_names[] = {
|
||||||
{
|
|
||||||
{".notdef", &symbol_square },
|
{".notdef", &symbol_square },
|
||||||
{"arrowleftdblfull", &symbol_arrowleftdblfull},
|
{"arrowleftdblfull", &symbol_arrowleftdblfull},
|
||||||
{"divide", &symbol_divide },
|
{"divide", &symbol_divide },
|
||||||
|
@ -227,8 +144,7 @@ static const symbol_name_t symbol_names[] =
|
||||||
};
|
};
|
||||||
#define NR_SYMBOLS ( sizeof( symbol_names ) / sizeof( symbol_names[ 0 ] ) - 1 )
|
#define NR_SYMBOLS ( sizeof( symbol_names ) / sizeof( symbol_names[ 0 ] ) - 1 )
|
||||||
|
|
||||||
int
|
int symbol_lookup_glyph_by_name( const char* name, int namelen, gunichar* glyph )
|
||||||
symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
|
|
||||||
{
|
{
|
||||||
const symbol_name_t* symname;
|
const symbol_name_t* symname;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
@ -239,8 +155,7 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
|
||||||
|
|
||||||
symname = symbol_names;
|
symname = symbol_names;
|
||||||
while ( symname->name ) {
|
while ( symname->name ) {
|
||||||
if ((strlen(symname->name) == namelen) &&
|
if ( ( strlen( symname->name ) == namelen ) && !strncmp( symname->name, name, namelen ) ) {
|
||||||
!strncmp(symname->name, name, namelen)) {
|
|
||||||
if ( glyph ) {
|
if ( glyph ) {
|
||||||
*glyph = 0xe000 + i;
|
*glyph = 0xe000 + i;
|
||||||
}
|
}
|
||||||
|
@ -254,8 +169,7 @@ symbol_lookup_glyph_by_name(const char *name, int namelen, gunichar *glyph)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const x49gp_symbol_t *
|
const x49gp_symbol_t* symbol_get_by_glyph( gunichar glyph )
|
||||||
symbol_get_by_glyph(gunichar glyph)
|
|
||||||
{
|
{
|
||||||
int index = glyph - 0xe000;
|
int index = glyph - 0xe000;
|
||||||
|
|
||||||
|
@ -266,8 +180,7 @@ symbol_get_by_glyph(gunichar glyph)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const x49gp_symbol_t *
|
const x49gp_symbol_t* symbol_get_by_name( const char* name )
|
||||||
symbol_get_by_name(const char *name)
|
|
||||||
{
|
{
|
||||||
gunichar glyph;
|
gunichar glyph;
|
||||||
|
|
||||||
|
|
59
src/symbol.h
59
src/symbol.h
|
@ -24,41 +24,52 @@ typedef struct {
|
||||||
} x49gp_symbol_t;
|
} x49gp_symbol_t;
|
||||||
|
|
||||||
#define SYMBOL_MOVE_TO( x, y ) \
|
#define SYMBOL_MOVE_TO( x, y ) \
|
||||||
{ header: { CAIRO_PATH_MOVE_TO, 2 } }, \
|
{ \
|
||||||
{ point: { x, y } }
|
header : { CAIRO_PATH_MOVE_TO, 2 } \
|
||||||
|
}, \
|
||||||
|
{ \
|
||||||
|
point: \
|
||||||
|
{ \
|
||||||
|
x, y \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define SYMBOL_LINE_TO( x, y ) \
|
#define SYMBOL_LINE_TO( x, y ) \
|
||||||
{ header: { CAIRO_PATH_LINE_TO, 2 } }, \
|
{ \
|
||||||
{ point: { x, y } }
|
header : { CAIRO_PATH_LINE_TO, 2 } \
|
||||||
|
}, \
|
||||||
|
{ \
|
||||||
|
point: \
|
||||||
|
{ \
|
||||||
|
x, y \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define SYMBOL_CURVE_TO( x1, y1, x2, y2, x3, y3 ) \
|
#define SYMBOL_CURVE_TO( x1, y1, x2, y2, x3, y3 ) \
|
||||||
{ header: { CAIRO_PATH_CURVE_TO, 4 } }, \
|
{ \
|
||||||
{ point: { x1, y1 } }, \
|
header : { CAIRO_PATH_CURVE_TO, 4 } \
|
||||||
{ point: { x2, y2 } }, \
|
}, \
|
||||||
{ point: { x3, y3 } }
|
{ point : { x1, y1 } }, { point : { x2, y2 } }, \
|
||||||
|
{ \
|
||||||
|
point: \
|
||||||
|
{ \
|
||||||
|
x3, y3 \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define SYMBOL_CLOSE_PATH() \
|
#define SYMBOL_CLOSE_PATH() \
|
||||||
{ header: { CAIRO_PATH_CLOSE_PATH, 1 } }
|
{ \
|
||||||
|
header : { CAIRO_PATH_CLOSE_PATH, 1 } \
|
||||||
|
}
|
||||||
|
|
||||||
#define SYMBOL( name, x_advance, y_advance, llx, lly, urx, ury ) \
|
#define SYMBOL( name, x_advance, y_advance, llx, lly, urx, ury ) \
|
||||||
static const symbol_path_t symbol_##name##_path = \
|
static const symbol_path_t symbol_##name##_path = { symbol_##name##_path_data, \
|
||||||
{ \
|
sizeof( symbol_##name##_path_data ) / sizeof( cairo_path_data_t ) }; \
|
||||||
symbol_##name##_path_data, \
|
|
||||||
sizeof(symbol_##name##_path_data) / sizeof(cairo_path_data_t) \
|
|
||||||
}; \
|
|
||||||
\
|
\
|
||||||
static const x49gp_symbol_t symbol_##name = \
|
static const x49gp_symbol_t symbol_##name = { x_advance, y_advance, llx, lly, urx, ury, 1.0, 1.0, &symbol_##name##_path }
|
||||||
{ \
|
|
||||||
x_advance, y_advance, llx, lly, urx, ury, 1.0, 1.0, \
|
|
||||||
&symbol_##name##_path \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define CONTROL( name, x_advance, y_advance, prescale, postscale ) \
|
#define CONTROL( name, x_advance, y_advance, prescale, postscale ) \
|
||||||
static const x49gp_symbol_t symbol_##name = \
|
static const x49gp_symbol_t symbol_##name = { x_advance, y_advance, 0.0, 0.0, 0.0, 0.0, prescale, postscale, NULL }
|
||||||
{ \
|
|
||||||
x_advance, y_advance, 0.0, 0.0, 0.0, 0.0, \
|
|
||||||
prescale, postscale, NULL \
|
|
||||||
}
|
|
||||||
|
|
||||||
int symbol_lookup_glyph_by_name( const char* name, int namelen, gunichar* );
|
int symbol_lookup_glyph_by_name( const char* name, int namelen, gunichar* );
|
||||||
|
|
||||||
|
|
99
src/timer.c
99
src/timer.c
|
@ -42,8 +42,7 @@ int64_t ticks_per_sec = 1000000;
|
||||||
|
|
||||||
static x49gp_timer_t* x49gp_timer_lists[ 2 ];
|
static x49gp_timer_t* x49gp_timer_lists[ 2 ];
|
||||||
|
|
||||||
int64_t
|
int64_t x49gp_get_clock( void )
|
||||||
x49gp_get_clock(void)
|
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
int64_t us;
|
int64_t us;
|
||||||
|
@ -55,8 +54,7 @@ x49gp_get_clock(void)
|
||||||
return us;
|
return us;
|
||||||
}
|
}
|
||||||
|
|
||||||
x49gp_timer_t *
|
x49gp_timer_t* x49gp_new_timer( long type, x49gp_timer_cb_t cb, void* user_data )
|
||||||
x49gp_new_timer(long type, x49gp_timer_cb_t cb, void *user_data)
|
|
||||||
{
|
{
|
||||||
x49gp_timer_t* ts;
|
x49gp_timer_t* ts;
|
||||||
|
|
||||||
|
@ -73,14 +71,9 @@ x49gp_new_timer(long type, x49gp_timer_cb_t cb, void *user_data)
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_free_timer( x49gp_timer_t* ts ) { free( ts ); }
|
||||||
x49gp_free_timer(x49gp_timer_t *ts)
|
|
||||||
{
|
|
||||||
free(ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void x49gp_del_timer( x49gp_timer_t* ts )
|
||||||
x49gp_del_timer(x49gp_timer_t *ts)
|
|
||||||
{
|
{
|
||||||
x49gp_timer_t **pt, *t;
|
x49gp_timer_t **pt, *t;
|
||||||
|
|
||||||
|
@ -99,8 +92,7 @@ x49gp_del_timer(x49gp_timer_t *ts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void x49gp_mod_timer( x49gp_timer_t* ts, int64_t expires )
|
||||||
x49gp_mod_timer(x49gp_timer_t *ts, int64_t expires)
|
|
||||||
{
|
{
|
||||||
x49gp_timer_t **pt, *t;
|
x49gp_timer_t **pt, *t;
|
||||||
|
|
||||||
|
@ -122,8 +114,7 @@ x49gp_mod_timer(x49gp_timer_t *ts, int64_t expires)
|
||||||
*pt = ts;
|
*pt = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_timer_pending( x49gp_timer_t* ts )
|
||||||
x49gp_timer_pending(x49gp_timer_t *ts)
|
|
||||||
{
|
{
|
||||||
x49gp_timer_t* t;
|
x49gp_timer_t* t;
|
||||||
|
|
||||||
|
@ -135,14 +126,9 @@ x49gp_timer_pending(x49gp_timer_t *ts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t
|
int64_t x49gp_timer_expires( x49gp_timer_t* ts ) { return ts->expires; }
|
||||||
x49gp_timer_expires(x49gp_timer_t *ts)
|
|
||||||
{
|
|
||||||
return ts->expires;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int x49gp_timer_expired( x49gp_timer_t* timer_head, int64_t current_time )
|
||||||
x49gp_timer_expired(x49gp_timer_t *timer_head, int64_t current_time)
|
|
||||||
{
|
{
|
||||||
if ( NULL == timer_head )
|
if ( NULL == timer_head )
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -151,44 +137,22 @@ x49gp_timer_expired(x49gp_timer_t *timer_head, int64_t current_time)
|
||||||
|
|
||||||
/* LD TEMPO HACK */
|
/* LD TEMPO HACK */
|
||||||
|
|
||||||
QEMUTimer *
|
QEMUTimer* qemu_new_timer( QEMUClock* clock, QEMUTimerCB cb, void* opaque )
|
||||||
qemu_new_timer(QEMUClock *clock, QEMUTimerCB cb, void *opaque)
|
|
||||||
{
|
{
|
||||||
return ( void* )x49gp_new_timer( ( long )clock, cb, opaque );
|
return ( void* )x49gp_new_timer( ( long )clock, cb, opaque );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void qemu_free_timer( QEMUTimer* ts ) { return x49gp_free_timer( ( void* )ts ); }
|
||||||
qemu_free_timer(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
return x49gp_free_timer((void *) ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void qemu_mod_timer( QEMUTimer* ts, int64_t expire_time ) { return x49gp_mod_timer( ( void* )ts, expire_time ); }
|
||||||
qemu_mod_timer(QEMUTimer *ts, int64_t expire_time)
|
|
||||||
{
|
|
||||||
return x49gp_mod_timer((void *) ts, expire_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void qemu_del_timer( QEMUTimer* ts ) { return x49gp_del_timer( ( void* )ts ); }
|
||||||
qemu_del_timer(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
return x49gp_del_timer((void *) ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int qemu_timer_pending( QEMUTimer* ts ) { return x49gp_timer_pending( ( void* )ts ); }
|
||||||
qemu_timer_pending(QEMUTimer *ts)
|
|
||||||
{
|
|
||||||
return x49gp_timer_pending((void *) ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
int64_t
|
int64_t qemu_get_clock( QEMUClock* clock ) { return x49gp_get_clock(); }
|
||||||
qemu_get_clock(QEMUClock *clock)
|
|
||||||
{
|
|
||||||
return x49gp_get_clock();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void x49gp_run_timers( x49gp_timer_t** ptimer_head, int64_t current_time )
|
||||||
x49gp_run_timers(x49gp_timer_t **ptimer_head, int64_t current_time)
|
|
||||||
{
|
{
|
||||||
x49gp_timer_t* ts;
|
x49gp_timer_t* ts;
|
||||||
|
|
||||||
|
@ -209,21 +173,17 @@ x49gp_run_timers(x49gp_timer_t **ptimer_head, int64_t current_time)
|
||||||
// printf("%s: timers done\n", __FUNCTION__);
|
// printf("%s: timers done\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void x49gp_alarm_handler( int sig )
|
||||||
x49gp_alarm_handler(int sig)
|
|
||||||
{
|
{
|
||||||
if (x49gp_timer_expired(x49gp_timer_lists[X49GP_TIMER_VIRTUAL],
|
if ( x49gp_timer_expired( x49gp_timer_lists[ X49GP_TIMER_VIRTUAL ], x49gp_get_clock() ) ||
|
||||||
x49gp_get_clock()) ||
|
x49gp_timer_expired( x49gp_timer_lists[ X49GP_TIMER_REALTIME ], x49gp_get_clock() ) ) {
|
||||||
x49gp_timer_expired(x49gp_timer_lists[X49GP_TIMER_REALTIME],
|
|
||||||
x49gp_get_clock())) {
|
|
||||||
if ( cpu_single_env && !cpu_single_env->exit_request ) {
|
if ( cpu_single_env && !cpu_single_env->exit_request ) {
|
||||||
cpu_exit( cpu_single_env );
|
cpu_exit( cpu_single_env );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void x49gp_main_loop_wait( x49gp_t* x49gp, int timeout )
|
||||||
x49gp_main_loop_wait(x49gp_t *x49gp, int timeout)
|
|
||||||
{
|
{
|
||||||
// printf("%s: timeout: %d\n", __FUNCTION__, timeout);
|
// printf("%s: timeout: %d\n", __FUNCTION__, timeout);
|
||||||
|
|
||||||
|
@ -233,18 +193,15 @@ x49gp_main_loop_wait(x49gp_t *x49gp, int timeout)
|
||||||
poll( NULL, 0, timeout );
|
poll( NULL, 0, timeout );
|
||||||
|
|
||||||
if ( x49gp->arm_idle != X49GP_ARM_OFF ) {
|
if ( x49gp->arm_idle != X49GP_ARM_OFF ) {
|
||||||
x49gp_run_timers(&x49gp_timer_lists[X49GP_TIMER_VIRTUAL],
|
x49gp_run_timers( &x49gp_timer_lists[ X49GP_TIMER_VIRTUAL ], x49gp_get_clock() );
|
||||||
x49gp_get_clock());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x49gp_run_timers(&x49gp_timer_lists[X49GP_TIMER_REALTIME],
|
x49gp_run_timers( &x49gp_timer_lists[ X49GP_TIMER_REALTIME ], x49gp_get_clock() );
|
||||||
x49gp_get_clock());
|
|
||||||
|
|
||||||
// printf("%s: done\n", __FUNCTION__);
|
// printf("%s: done\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_main_loop( x49gp_t* x49gp )
|
||||||
x49gp_main_loop(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
int prev_idle;
|
int prev_idle;
|
||||||
int ret, timeout;
|
int ret, timeout;
|
||||||
|
@ -258,15 +215,14 @@ x49gp_main_loop(x49gp_t *x49gp)
|
||||||
#endif
|
#endif
|
||||||
ret = cpu_exec( x49gp->env );
|
ret = cpu_exec( x49gp->env );
|
||||||
#ifdef DEBUG_X49GP_TIMER_IDLE
|
#ifdef DEBUG_X49GP_TIMER_IDLE
|
||||||
printf("%lld: %s: cpu_exec(): %d, PC %08x\n", (unsigned long long) x49gp_get_clock(), __FUNCTION__, ret, x49gp->env->regs[15]);
|
printf( "%lld: %s: cpu_exec(): %d, PC %08x\n", ( unsigned long long )x49gp_get_clock(), __FUNCTION__, ret,
|
||||||
|
x49gp->env->regs[ 15 ] );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( x49gp->env->regs[ 15 ] == 0x8620 ) {
|
if ( x49gp->env->regs[ 15 ] == 0x8620 ) {
|
||||||
printf( "PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[ 15 ], 0x08000a0c,
|
printf( "PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[ 15 ], 0x08000a0c,
|
||||||
* ((uint32_t *) &x49gp->sram[0x0a00]),
|
*( ( uint32_t* )&x49gp->sram[ 0x0a00 ] ), *( ( uint32_t* )&x49gp->sram[ 0x0a04 ] ),
|
||||||
* ((uint32_t *) &x49gp->sram[0x0a04]),
|
*( ( uint32_t* )&x49gp->sram[ 0x0a08 ] ), *( ( uint32_t* )&x49gp->sram[ 0x0a0c ] ) );
|
||||||
* ((uint32_t *) &x49gp->sram[0x0a08]),
|
|
||||||
* ((uint32_t *) &x49gp->sram[0x0a0c]));
|
|
||||||
*( ( uint32_t* )&x49gp->sram[ 0x0a0c ] ) = 0x00000000;
|
*( ( uint32_t* )&x49gp->sram[ 0x0a0c ] ) = 0x00000000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,8 +253,7 @@ printf("PC %08x: SRAM %08x: %08x %08x %08x <%08x>\n", x49gp->env->regs[15], 0x08
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int x49gp_timer_init( x49gp_t* x49gp )
|
||||||
x49gp_timer_init(x49gp_t *x49gp)
|
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
struct itimerval it;
|
struct itimerval it;
|
||||||
|
|
|
@ -94,12 +94,10 @@
|
||||||
|
|
||||||
#include "bitmaps/tiny__i.xbm"
|
#include "bitmaps/tiny__i.xbm"
|
||||||
|
|
||||||
const bitmap_font_t tiny_font =
|
const bitmap_font_t tiny_font = {
|
||||||
{
|
|
||||||
7,
|
7,
|
||||||
-3,
|
-3,
|
||||||
{
|
{ GLYPH( tiny, notdef ),
|
||||||
GLYPH(tiny, notdef),
|
|
||||||
|
|
||||||
SPACE( "space", 4, 0 ),
|
SPACE( "space", 4, 0 ),
|
||||||
GLYPH( tiny, quotedbl ),
|
GLYPH( tiny, quotedbl ),
|
||||||
|
@ -201,6 +199,5 @@ const bitmap_font_t tiny_font =
|
||||||
SPACE( "kern-6", -6, -6 ),
|
SPACE( "kern-6", -6, -6 ),
|
||||||
SPACE( "kern-7", -7, -7 ),
|
SPACE( "kern-7", -7, -7 ),
|
||||||
|
|
||||||
{ NULL }
|
{ NULL } }
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
71
src/x49gp.h
71
src/x49gp.h
|
@ -23,17 +23,9 @@
|
||||||
extern uint8_t* phys_ram_base;
|
extern uint8_t* phys_ram_base;
|
||||||
extern int phys_ram_size;
|
extern int phys_ram_size;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { X49GP_ARM_RUN = 0, X49GP_ARM_SLEEP, X49GP_ARM_OFF } x49gp_arm_idle_t;
|
||||||
X49GP_ARM_RUN = 0,
|
|
||||||
X49GP_ARM_SLEEP,
|
|
||||||
X49GP_ARM_OFF
|
|
||||||
} x49gp_arm_idle_t;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { X49GP_RESET_POWER_ON = 0, X49GP_RESET_POWER_OFF, X49GP_RESET_WATCHDOG } x49gp_reset_t;
|
||||||
X49GP_RESET_POWER_ON = 0,
|
|
||||||
X49GP_RESET_POWER_OFF,
|
|
||||||
X49GP_RESET_WATCHDOG
|
|
||||||
} x49gp_reset_t;
|
|
||||||
|
|
||||||
struct __x49gp_module_s__;
|
struct __x49gp_module_s__;
|
||||||
typedef struct __x49gp_module_s__ x49gp_module_t;
|
typedef struct __x49gp_module_s__ x49gp_module_t;
|
||||||
|
@ -55,12 +47,7 @@ struct __x49gp_module_s__ {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { X49GP_REINIT_NONE = 0, X49GP_REINIT_REBOOT_ONLY, X49GP_REINIT_FLASH, X49GP_REINIT_FLASH_FULL } x49gp_reinit_t;
|
||||||
X49GP_REINIT_NONE = 0,
|
|
||||||
X49GP_REINIT_REBOOT_ONLY,
|
|
||||||
X49GP_REINIT_FLASH,
|
|
||||||
X49GP_REINIT_FLASH_FULL
|
|
||||||
} x49gp_reinit_t;
|
|
||||||
|
|
||||||
struct __x49gp_s__ {
|
struct __x49gp_s__ {
|
||||||
CPUARMState* env;
|
CPUARMState* env;
|
||||||
|
@ -110,46 +97,26 @@ struct __x49gp_s__ {
|
||||||
|
|
||||||
extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );
|
extern void x49gp_set_idle( x49gp_t*, x49gp_arm_idle_t idle );
|
||||||
|
|
||||||
extern int x49gp_module_init(x49gp_t *x49gp, const char *name,
|
extern int x49gp_module_init( x49gp_t* x49gp, const char* name, int ( *init )( x49gp_module_t* ), int ( *exit )( x49gp_module_t* ),
|
||||||
int (*init)(x49gp_module_t *),
|
int ( *reset )( x49gp_module_t*, x49gp_reset_t ), int ( *load )( x49gp_module_t*, GKeyFile* ),
|
||||||
int (*exit)(x49gp_module_t *),
|
int ( *save )( x49gp_module_t*, GKeyFile* ), void* user_data, x49gp_module_t** module );
|
||||||
int (*reset)(x49gp_module_t *, x49gp_reset_t),
|
|
||||||
int (*load)(x49gp_module_t *, GKeyFile *),
|
|
||||||
int (*save)(x49gp_module_t *, GKeyFile *),
|
|
||||||
void *user_data, x49gp_module_t **module);
|
|
||||||
|
|
||||||
extern int x49gp_module_register( x49gp_module_t* module );
|
extern int x49gp_module_register( x49gp_module_t* module );
|
||||||
extern int x49gp_module_unregister( x49gp_module_t* module );
|
extern int x49gp_module_unregister( x49gp_module_t* module );
|
||||||
|
|
||||||
extern int x49gp_module_get_filename(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_get_filename( x49gp_module_t* module, GKeyFile*, const char*, char*, char**, char** );
|
||||||
const char *, char *, char **,
|
extern int x49gp_module_set_filename( x49gp_module_t* module, GKeyFile*, const char*, const char* );
|
||||||
char **);
|
extern int x49gp_module_get_int( x49gp_module_t* module, GKeyFile*, const char*, int, int* );
|
||||||
extern int x49gp_module_set_filename(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_set_int( x49gp_module_t* module, GKeyFile*, const char*, int );
|
||||||
const char *, const char *);
|
extern int x49gp_module_get_uint( x49gp_module_t* module, GKeyFile*, const char*, unsigned int, unsigned int* );
|
||||||
extern int x49gp_module_get_int(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_set_uint( x49gp_module_t* module, GKeyFile*, const char*, unsigned int );
|
||||||
const char *, int, int *);
|
extern int x49gp_module_get_u32( x49gp_module_t* module, GKeyFile*, const char*, uint32_t, uint32_t* );
|
||||||
extern int x49gp_module_set_int(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_set_u32( x49gp_module_t* module, GKeyFile*, const char*, uint32_t );
|
||||||
const char *, int);
|
extern int x49gp_module_get_u64( x49gp_module_t* module, GKeyFile*, const char*, uint64_t, uint64_t* );
|
||||||
extern int x49gp_module_get_uint(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_set_u64( x49gp_module_t* module, GKeyFile*, const char*, uint64_t );
|
||||||
const char *,
|
extern int x49gp_module_get_string( x49gp_module_t* module, GKeyFile*, const char*, char*, char** );
|
||||||
unsigned int, unsigned int *);
|
extern int x49gp_module_set_string( x49gp_module_t* module, GKeyFile*, const char*, const char* );
|
||||||
extern int x49gp_module_set_uint(x49gp_module_t *module, GKeyFile *,
|
extern int x49gp_module_open_rodata( x49gp_module_t* module, const char* name, char** path );
|
||||||
const char *, unsigned int);
|
|
||||||
extern int x49gp_module_get_u32(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, uint32_t, uint32_t *);
|
|
||||||
extern int x49gp_module_set_u32(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, uint32_t);
|
|
||||||
extern int x49gp_module_get_u64(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, uint64_t, uint64_t *);
|
|
||||||
extern int x49gp_module_set_u64(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, uint64_t);
|
|
||||||
extern int x49gp_module_get_string(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, char *, char **);
|
|
||||||
extern int x49gp_module_set_string(x49gp_module_t *module, GKeyFile *,
|
|
||||||
const char *, const char *);
|
|
||||||
extern int x49gp_module_open_rodata(x49gp_module_t *module,
|
|
||||||
const char *name,
|
|
||||||
char **path);
|
|
||||||
|
|
||||||
extern void s3c2410_sdi_unmount( x49gp_t* x49gp );
|
extern void s3c2410_sdi_unmount( x49gp_t* x49gp );
|
||||||
extern int s3c2410_sdi_mount( x49gp_t* x49gp, char* filename );
|
extern int s3c2410_sdi_mount( x49gp_t* x49gp, char* filename );
|
||||||
|
|
|
@ -43,12 +43,7 @@ typedef enum {
|
||||||
UI_SHAPE_MAX
|
UI_SHAPE_MAX
|
||||||
} x49gp_ui_shape_t;
|
} x49gp_ui_shape_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum { UI_LAYOUT_LEFT = 0, UI_LAYOUT_LEFT_NO_SPACE, UI_LAYOUT_BELOW, UI_LAYOUT_MAX } x49gp_ui_layout_t;
|
||||||
UI_LAYOUT_LEFT = 0,
|
|
||||||
UI_LAYOUT_LEFT_NO_SPACE,
|
|
||||||
UI_LAYOUT_BELOW,
|
|
||||||
UI_LAYOUT_MAX
|
|
||||||
} x49gp_ui_layout_t;
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UI_CALCULATOR_HP49GP = 0,
|
UI_CALCULATOR_HP49GP = 0,
|
||||||
|
@ -57,7 +52,6 @@ typedef enum {
|
||||||
UI_CALCULATOR_HP50G_NEWRPL
|
UI_CALCULATOR_HP50G_NEWRPL
|
||||||
} x49gp_ui_calculator_t;
|
} x49gp_ui_calculator_t;
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char* label;
|
const char* label;
|
||||||
const char* letter;
|
const char* letter;
|
||||||
|
|
Loading…
Reference in a new issue