Search
lxdream.org :: lxdream :: r1102:957b76b312cc
lxdream 0.9.1
released Jun 29
Download Now
changeset1102:957b76b312cc
parent1101:78e762cec843
child1103:de9ad2c0cf56
authornkeynes
dateSun Feb 21 11:11:30 2010 +1000 (10 years ago)
Split BIOS vectors into separate functions, implement parts of sysinfo and
flashrom calls
src/bios.c
1.1 --- a/src/bios.c Tue Feb 16 09:29:39 2010 +1000
1.2 +++ b/src/bios.c Sun Feb 21 11:11:30 2010 +1000
1.3 @@ -199,84 +199,168 @@
1.4 }
1.5
1.6 /**
1.7 - * Syscall list courtesy of Marcus Comstedt
1.8 + * Address of the system information block (in the flash rom). Also repeats
1.9 + * at FLASH_SYSINFO_SEGMENT+0xA0
1.10 */
1.11 +#define FLASH_SYSINFO_SEGMENT 0x0021a000
1.12 +#define FLASH_CONFIG_SEGMENT 0x0021c000
1.13 +#define FLASH_CONFIG_LENGTH 0x00004000
1.14 +#define FLASH_PARTITION_MAGIC "KATANA_FLASH____"
1.15
1.16 -void bios_syscall( uint32_t syscallid )
1.17 +/**
1.18 + * Locate the active config block. FIXME: This isn't completely correct, but it works
1.19 + * under at least some circumstances.
1.20 + */
1.21 +static char *bios_find_flash_config( sh4addr_t segment, uint32_t length )
1.22 +{
1.23 + char *start = mem_get_region(segment);
1.24 + char *p = start + 0x80;
1.25 + char *end = p + length;
1.26 + char *result = NULL;
1.27 +
1.28 + if( memcmp( start, FLASH_PARTITION_MAGIC, 16 ) != 0 )
1.29 + return NULL; /* Missing magic */
1.30 + while( p < end ) {
1.31 + if( p[0] == 0x05 && p[1] == 0 ) {
1.32 + result = p;
1.33 + }
1.34 + p += 0x40;
1.35 + }
1.36 + return result;
1.37 +}
1.38 +
1.39 +/**
1.40 + * Syscall information courtesy of Marcus Comstedt
1.41 + */
1.42 +static void bios_sysinfo_vector( uint32_t syscallid )
1.43 +{
1.44 + char *flash_segment, *flash_config;
1.45 + char *dest;
1.46 + DEBUG( "BIOS SYSINFO: r4 = %08X, r5 = %08X, r6 = %08x, r7= %08X", sh4r.r[4], sh4r.r[5], sh4r.r[6], sh4r.r[7] );
1.47 +
1.48 + switch( sh4r.r[7] ) {
1.49 + case 0: /* SYSINFO_INIT */
1.50 + /* Initialize the region 8c000068 .. 8c00007f from the flash rom
1.51 + * uint64_t system_id;
1.52 + * char [5] system_props;
1.53 + * char [3] zero_pad (?)
1.54 + * char [8] settings;
1.55 + **/
1.56 + flash_segment = mem_get_region(FLASH_SYSINFO_SEGMENT);
1.57 + flash_config = bios_find_flash_config(FLASH_CONFIG_SEGMENT,FLASH_CONFIG_LENGTH);
1.58 + dest = mem_get_region( 0x8c000068 );
1.59 + memset( dest, 0, 24 );
1.60 + memcpy( dest, flash_segment + 0x56, 8 );
1.61 + memcpy( dest + 8, flash_segment, 5 );
1.62 + if( flash_config != NULL ) {
1.63 + memcpy( dest+16, flash_config+2, 8 );
1.64 + }
1.65 + break;
1.66 + case 2: /* SYSINFO_ICON */
1.67 + /* Not supported yet */
1.68 + break;
1.69 + case 3: /* SYSINFO_ID */
1.70 + sh4r.r[0] = 0x8c000068;
1.71 + break;
1.72 + }
1.73 +}
1.74 +
1.75 +static void bios_flashrom_vector( uint32_t syscallid )
1.76 +{
1.77 + char *dest;
1.78 + DEBUG( "BIOS FLASHROM: r4 = %08X, r5 = %08X, r6 = %08x, r7= %08X", sh4r.r[4], sh4r.r[5], sh4r.r[6], sh4r.r[7] );
1.79 +
1.80 + switch( sh4r.r[7] ) {
1.81 + case 0: /* FLASHROM_INFO */
1.82 + break;
1.83 + case 1: /* FLASHROM_READ */
1.84 +
1.85 + break;
1.86 + case 2: /* FLASHROM_WRITE */
1.87 + break;
1.88 + case 3: /* FLASHROM_DELETE */
1.89 + break;
1.90 + }
1.91 +}
1.92 +
1.93 +static void bios_romfont_vector( uint32_t syscallid )
1.94 +{
1.95 + DEBUG( "BIOS ROMFONT: r4 = %08X, r5 = %08X, r6 = %08x, r7= %08X", sh4r.r[4], sh4r.r[5], sh4r.r[6], sh4r.r[7] );
1.96 + /* Not implemented */
1.97 +}
1.98 +
1.99 +static void bios_gdrom_vector( uint32_t syscallid )
1.100 {
1.101 gdrom_queue_entry_t cmd;
1.102
1.103 - switch( syscallid ) {
1.104 - case 0xB0: /* sysinfo */
1.105 - break;
1.106 - case 0xB4: /* Font */
1.107 - break;
1.108 - case 0xB8: /* Flash */
1.109 - break;
1.110 - case 0xBC: /* Misc/GD-Rom */
1.111 - switch( sh4r.r[6] ) {
1.112 - case 0: /* GD-Rom */
1.113 - switch( sh4r.r[7] ) {
1.114 - case 0: /* Send command */
1.115 - sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], sh4r.r[5] );
1.116 - break;
1.117 - case 1: /* Check command */
1.118 - cmd = bios_gdrom_get_command( sh4r.r[4] );
1.119 - if( cmd == NULL ) {
1.120 - sh4r.r[0] = GD_CMD_STATUS_NONE;
1.121 - } else {
1.122 - sh4r.r[0] = cmd->status;
1.123 - if( cmd->status == GD_CMD_STATUS_ERROR &&
1.124 - sh4r.r[5] != 0 ) {
1.125 - mem_copy_to_sh4( sh4r.r[5], (sh4ptr_t)&cmd->result, sizeof(cmd->result) );
1.126 - }
1.127 + DEBUG( "BIOS GDROM: r4 = %08X, r5 = %08X, r6 = %08x, r7= %08X", sh4r.r[4], sh4r.r[5], sh4r.r[6], sh4r.r[7] );
1.128 +
1.129 + switch( sh4r.r[6] ) {
1.130 + case 0: /* GD-Rom */
1.131 + switch( sh4r.r[7] ) {
1.132 + case 0: /* Send command */
1.133 + sh4r.r[0] = bios_gdrom_enqueue( sh4r.r[4], sh4r.r[5] );
1.134 + break;
1.135 + case 1: /* Check command */
1.136 + cmd = bios_gdrom_get_command( sh4r.r[4] );
1.137 + if( cmd == NULL ) {
1.138 + sh4r.r[0] = GD_CMD_STATUS_NONE;
1.139 + } else {
1.140 + sh4r.r[0] = cmd->status;
1.141 + if( cmd->status == GD_CMD_STATUS_ERROR &&
1.142 + sh4r.r[5] != 0 ) {
1.143 + mem_copy_to_sh4( sh4r.r[5], (sh4ptr_t)&cmd->result, sizeof(cmd->result) );
1.144 }
1.145 - break;
1.146 - case 2: /* Mainloop */
1.147 - bios_gdrom_run_queue();
1.148 - break;
1.149 - case 3: /* Init */
1.150 - bios_gdrom_init();
1.151 - break;
1.152 - case 4: /* Drive status */
1.153 - if( sh4r.r[4] != 0 ) {
1.154 - mem_copy_to_sh4( sh4r.r[4], (sh4ptr_t)&bios_gdrom_status,
1.155 - sizeof(bios_gdrom_status) );
1.156 - }
1.157 - sh4r.r[0] = 0;
1.158 - break;
1.159 - case 8: /* Abort command */
1.160 - cmd = bios_gdrom_get_command( sh4r.r[4] );
1.161 - if( cmd == NULL || cmd->status != GD_CMD_STATUS_ACTIVE ) {
1.162 - sh4r.r[0] = -1;
1.163 - } else {
1.164 - cmd->status = GD_CMD_STATUS_ABORT;
1.165 - sh4r.r[0] = 0;
1.166 - }
1.167 - break;
1.168 - case 9: /* Reset */
1.169 - break;
1.170 - case 10: /* Set mode */
1.171 - sh4r.r[0] = 0;
1.172 - break;
1.173 }
1.174 break;
1.175 - case -1: /* Misc */
1.176 + case 2: /* Mainloop */
1.177 + bios_gdrom_run_queue();
1.178 break;
1.179 - default: /* ??? */
1.180 - break;
1.181 + case 3: /* Init */
1.182 + bios_gdrom_init();
1.183 + break;
1.184 + case 4: /* Drive status */
1.185 + if( sh4r.r[4] != 0 ) {
1.186 + mem_copy_to_sh4( sh4r.r[4], (sh4ptr_t)&bios_gdrom_status,
1.187 + sizeof(bios_gdrom_status) );
1.188 + }
1.189 + sh4r.r[0] = 0;
1.190 + break;
1.191 + case 8: /* Abort command */
1.192 + cmd = bios_gdrom_get_command( sh4r.r[4] );
1.193 + if( cmd == NULL || cmd->status != GD_CMD_STATUS_ACTIVE ) {
1.194 + sh4r.r[0] = -1;
1.195 + } else {
1.196 + cmd->status = GD_CMD_STATUS_ABORT;
1.197 + sh4r.r[0] = 0;
1.198 + }
1.199 + break;
1.200 + case 9: /* Reset */
1.201 + break;
1.202 + case 10: /* Set mode */
1.203 + sh4r.r[0] = 0;
1.204 + break;
1.205 }
1.206 break;
1.207 - case 0xE0: /* Menu */
1.208 - switch( sh4r.r[7] ) {
1.209 - case 0:
1.210 - WARN( "Entering main program" );
1.211 - break;
1.212 - case 1:
1.213 - WARN( "Program aborted to DC menu");
1.214 - dreamcast_stop();
1.215 - break;
1.216 - }
1.217 + case -1: /* Misc */
1.218 + break;
1.219 + default: /* ??? */
1.220 + break;
1.221 + }
1.222 +}
1.223 +
1.224 +static void bios_menu_vector( uint32_t syscallid )
1.225 +{
1.226 + DEBUG( "BIOS MENU: r4 = %08X, r5 = %08X, r6 = %08x, r7= %08X", sh4r.r[4], sh4r.r[5], sh4r.r[6], sh4r.r[7] );
1.227 +
1.228 + switch( sh4r.r[4] ) {
1.229 + case 0:
1.230 + WARN( "Entering main program" );
1.231 + break;
1.232 + case 1:
1.233 + WARN( "Program aborted to DC menu");
1.234 + dreamcast_stop();
1.235 + break;
1.236 }
1.237 }
1.238
1.239 @@ -294,11 +378,11 @@
1.240 void bios_install( void )
1.241 {
1.242 bios_gdrom_init();
1.243 - syscall_add_hook_vector( 0xB0, 0x8C0000B0, bios_syscall );
1.244 - syscall_add_hook_vector( 0xB4, 0x8C0000B4, bios_syscall );
1.245 - syscall_add_hook_vector( 0xB8, 0x8C0000B8, bios_syscall );
1.246 - syscall_add_hook_vector( 0xBC, 0x8C0000BC, bios_syscall );
1.247 - syscall_add_hook_vector( 0xE0, 0x8C0000E0, bios_syscall );
1.248 + syscall_add_hook_vector( 0xB0, 0x8C0000B0, bios_sysinfo_vector );
1.249 + syscall_add_hook_vector( 0xB4, 0x8C0000B4, bios_romfont_vector );
1.250 + syscall_add_hook_vector( 0xB8, 0x8C0000B8, bios_flashrom_vector );
1.251 + syscall_add_hook_vector( 0xBC, 0x8C0000BC, bios_gdrom_vector );
1.252 + syscall_add_hook_vector( 0xE0, 0x8C0000E0, bios_menu_vector );
1.253 }
1.254
1.255 #define MIN_ISO_SECTORS 32
.