- remove old boot code
This commit is contained in:
mtabachenko 2013-08-11 16:46:33 +00:00
parent c8a4dd3037
commit 8248128cde
5 changed files with 10 additions and 167 deletions

View File

@ -39,11 +39,8 @@
#include "movie.h"
#include "readwrite.h"
#include "MMU_timing.h"
#ifdef _NEW_BOOT
#include "firmware.h"
#include "encrypt.h"
#endif
#ifdef DO_ASSERT_UNALIGNED
#define ASSERT_UNALIGNED(x) assert(x)
@ -51,13 +48,9 @@
#define ASSERT_UNALIGNED(x)
#endif
#ifdef _NEW_BOOT
//#define _LOG_NEW_BOOT
_KEY1 key1(&MMU.ARM7_BIOS[0x0030]);
_KEY2 key2;
#endif
//http://home.utah.edu/~nahaj/factoring/isqrt.c.html
static u64 isqrt (u64 x) {
@ -1013,9 +1006,7 @@ void MMU_Reset()
MMU.SPI_CNT = 0;
MMU.AUX_SPI_CNT = 0;
#ifdef _NEW_BOOT
reconstruct(&key2);
#endif
MMU.WRAMCNT = 0;
@ -1324,28 +1315,10 @@ void FASTCALL MMU_writeToGCControl(u32 val)
nds_dscard& card = MMU.dscard[PROCNUM];
#ifdef _NEW_BOOT
card.delay = 0;
#endif
memcpy(&card.command[0], &MMU.MMU_MEM[PROCNUM][0x40][0x1A8], 8);
card.blocklen = 0;
#ifndef _NEW_BOOT
slot1_device.write32(PROCNUM,0xFFFFFFFF,val); //Special case for some flashcarts
if(card.blocklen==0x01020304) return;
if ((val & 0x80000000) == 0)
{
card.address = 0;
card.transfer_count = 0;
val &= 0x7F7FFFFF;
T1WriteLong(MMU.MMU_MEM[PROCNUM][0x40], 0x1A4, val);
return;
}
#else
if ((val & (1 << 15)) != 0)
{
#ifdef _LOG_NEW_BOOT
@ -1372,7 +1345,6 @@ void FASTCALL MMU_writeToGCControl(u32 val)
T1WriteLong(MMU.MMU_MEM[PROCNUM][0x40], 0x1A4, val & 0x7F7FFFFF);
return;
}
#endif
u32 shift = ((val >> 24) & 0x07);
if(shift == 7)
@ -1408,7 +1380,6 @@ void FASTCALL MMU_writeToGCControl(u32 val)
break;
case 0x3C: //Switch to KEY1 mode
#ifdef _NEW_BOOT
{
u32 gameID = MMU_read32(PROCNUM, 0x027FFE0C);
key1.init(gameID, 2, 0x08);
@ -1420,11 +1391,6 @@ void FASTCALL MMU_writeToGCControl(u32 val)
card.mode = CardMode_KEY1;
card.transfer_count = 0;
}
#else
printf("ARM%c: Activate unsupported KEY1 encryption mode\n", PROCNUM?'7':'9');
card.mode = CardMode_KEY1;
card.transfer_count = 0;
#endif
break;
default:
//fall through to the special slot1 handler
@ -1435,7 +1401,6 @@ void FASTCALL MMU_writeToGCControl(u32 val)
else
if (card.mode == CardMode_KEY1 || card.mode == CardMode_KEY2)
{
#ifdef _NEW_BOOT
u32 gameID = MMU_read32(PROCNUM, 0x027FFE0C);
u32 chipID = MMU_read32(PROCNUM, 0x027FF800);
u64 cmd = bswap64(*(u64 *)&card.command[0]);
@ -1467,7 +1432,6 @@ void FASTCALL MMU_writeToGCControl(u32 val)
printf("ARM%c: Get secure are block: area %04X, src %08X, dst %08X, len %08X, bsize %08X|%08X\n", PROCNUM?'7':'9', area, src, dst, len, size, size2);
#endif
card.address = addr;
//card.delay = 0x910;
}
break;
@ -1496,30 +1460,15 @@ void FASTCALL MMU_writeToGCControl(u32 val)
slot1_device.write32(PROCNUM, REG_GCROMCTRL, val);
break;
}
#else
card.address = 0;
card.transfer_count = 0;
printf("ARM%c: Activate unsupported KEY2 encryption mode\n", PROCNUM?'7':'9');
card.mode = CardMode_KEY2;
card.transfer_count = 0;
#endif
}
else
if (card.mode == CardMode_DATA_LOAD)
{
#ifdef _NEW_BOOT
//u64 cmd = bswap64(*(u64 *)&card.command[0]);
//*(u64*)&card.command[0] = bswap64(cmd);
slot1_device.write32(PROCNUM, REG_GCROMCTRL, val);
#ifdef _LOG_NEW_BOOT
if (fp_dis7)
fprintf(fp_dis7, "ARM%c: main data mode cmd %02X (addr %08X, len %08X)\n", PROCNUM?'7':'9', card.command[0], card.address, card.transfer_count);
printf("ARM%c: main data mode cmd %02X (addr %08X, len %08X)\n", PROCNUM?'7':'9', card.command[0], card.address, card.transfer_count);
#endif
#else
INFO("Cartridge: KEY2 load data mode unsupported.\n");
card.address = 0;
card.transfer_count = 0;
#endif
}
@ -1542,24 +1491,9 @@ u32 FASTCALL MMU_readFromGCControl()
{
nds_dscard& card = MMU.dscard[PROCNUM];
#ifdef _NEW_BOOT
u32 val = T1ReadLong(MMU.MMU_MEM[PROCNUM][0x40], 0x1A4);
if (card.delay > 0)
{
card.delay--;
if (card.delay == 0)
{
val &= 0x7F7FFFFF;
T1WriteLong(MMU.MMU_MEM[PROCNUM][0x40], 0x1A4, val);
}
}
return val;
#else
card.delay = 0;
return T1ReadLong(MMU.MMU_MEM[PROCNUM][0x40], 0x1A4);
#endif
}
template<int PROCNUM>
@ -2494,11 +2428,7 @@ void DmaController::doCopy()
if(nds.VCount==191) enable = 0;
}
#ifdef _NEW_BOOT
if(startmode == EDMAMode_Card) todo = MMU.dscard[PROCNUM].transfer_count / sz;
#else
if(startmode == EDMAMode_Card) todo *= 0x80;
#endif
if(startmode == EDMAMode_GXFifo) todo = std::min(todo,(u32)112);
//determine how we're going to copy
@ -4240,17 +4170,6 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val)
#endif
//The NDS7 register can be written to only from code executed in BIOS.
if (NDS_ARM7.instruct_adr > 0x3FFF) return;
#ifndef _NEW_BOOT
// hack for patched firmwares
if (val == 1)
{
if (_MMU_ARM7_read08(REG_POSTFLG) != 0)
break;
_MMU_write32<ARMCPU_ARM9>(0x27FFE24, gameInfo.header.ARM9exe);
_MMU_write32<ARMCPU_ARM7>(0x27FFE34, gameInfo.header.ARM7exe);
}
#endif
break;
case REG_HALTCNT:

View File

@ -448,13 +448,11 @@ static void loadrom(std::string fname) {
gameInfo.resize(size);
#ifdef _NEW_BOOT
extern NDS_SLOT1_TYPE slot1_device_type;
if (slot1_device_type == NDS_SLOT1_NONE)
memset(gameInfo.romdata, 0xFF, size);
else
#endif
fread(gameInfo.romdata,1,size,inf);
gameInfo.fillGap();
@ -573,19 +571,6 @@ int NDS_LoadROM(const char *filename, const char *physicalName, const char *logi
if (ret < 1)
return ret;
#ifndef _NEW_BOOT
//decrypt if necessary..
//but this is untested and suspected to fail on big endian, so lets not support this on big endian
#ifndef WORDS_BIGENDIAN
bool okRom = DecryptSecureArea((u8*)gameInfo.romdata,gameInfo.romsize);
if(!okRom) {
printf("Specified file is not a valid rom\n");
return -1;
}
#endif
#endif
if (cheatSearch)
cheatSearch->close();
FCEUI_StopMovie();
@ -601,9 +586,7 @@ int NDS_LoadROM(const char *filename, const char *physicalName, const char *logi
INFO("ROM internal name: %s\n", gameInfo.ROMname);
INFO("ROM developer: %s\n", getDeveloperNameByID(gameInfo.header.makerCode).c_str());
#ifdef _NEW_BOOT
gameInfo.storeSecureArea();
#endif
memset(buf, 0, MAX_PATH);
strcpy(buf, path.pathToModule);
@ -2531,7 +2514,6 @@ void NDS_Reset()
if (NDS_ARM7.BIOS_loaded && NDS_ARM9.BIOS_loaded && CommonSettings.BootFromFirmware && fw_success)
{
#ifdef _NEW_BOOT
gameInfo.restoreSecureArea();
firmware->loadSettings();
@ -2558,54 +2540,11 @@ void NDS_Reset()
TSCal.adc.height = (TSCal.adc.y2 - TSCal.adc.y1);
TSCal.scr.width = (TSCal.scr.x2 - TSCal.scr.x1);
TSCal.scr.height = (TSCal.scr.y2 - TSCal.scr.y1);
#else
_MMU_write08<ARMCPU_ARM9>(REG_WRAMCNT,3);
firmware->unpack();
//Copy secure area to memory if needed.
//could we get a comment about what's going on here?
//how does this stuff get copied before anything ever even runs?
//does it get mapped straight to the rom somehow?
//This code could be made more clear too.
if ((header->ARM9src >= 0x4000) && (header->ARM9src < 0x8000))
{
u32 src = header->ARM9src;
u32 dst = header->ARM9cpy;
u32 size = (0x8000 - src) >> 2;
for (u32 i = 0; i < size; i++)
{
_MMU_write32<ARMCPU_ARM9>(dst, T1ReadLong(MMU.CART_ROM, src));
src += 4; dst += 4;
}
}
//TODO someone describe why here
if (firmware->patched)
{
armcpu_init(&NDS_ARM7, 0x00000008);
armcpu_init(&NDS_ARM9, 0xFFFF0008);
}
else
{
//set the cpus to an initial state with their respective firmware program entrypoints
armcpu_init(&NDS_ARM7, firmware->ARM7bootAddr);
armcpu_init(&NDS_ARM9, firmware->ARM9bootAddr);
}
//set REG_POSTFLG to the value indicating pre-firmware status
MMU.ARM9_REG[0x300] = 0;
MMU.ARM7_REG[0x300] = 0;
goto _fake_boot;
#endif
}
else
{
//fake firmware boot-up process
#ifdef _NEW_BOOT
gameInfo.restoreSecureArea();
//decrypt if necessary..
//but this is untested and suspected to fail on big endian, so lets not support this on big endian
@ -2616,7 +2555,6 @@ void NDS_Reset()
printf("Specified file is not a valid rom\n");
return;
}
#endif
#endif
//according to smea, this is initialized to 3 by the time we get into a user game program. who does this?
//well, the firmware load process is about to write a boot program into SIWRAM for the arm7. so we need it setup by now.
@ -2664,17 +2602,14 @@ void NDS_Reset()
MMU.ARM9_REG[0x300] = 1;
MMU.ARM7_REG[0x300] = 1;
_fake_boot:
//Setup a copy of the firmware user settings in memory.
//(this is what the DS firmware would do).
{
u8 temp_buffer[NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT];
int fw_index;
u8 temp_buffer[NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT];
int fw_index;
if ( copy_firmware_user_data( temp_buffer, MMU.fw.data)) {
for ( fw_index = 0; fw_index < NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT; fw_index++)
_MMU_write08<ARMCPU_ARM9>(0x027FFC80 + fw_index, temp_buffer[fw_index]);
}
if ( copy_firmware_user_data( temp_buffer, MMU.fw.data)) {
for ( fw_index = 0; fw_index < NDS_FW_USER_SETTINGS_MEM_BYTE_COUNT; fw_index++)
_MMU_write08<ARMCPU_ARM9>(0x027FFC80 + fw_index, temp_buffer[fw_index]);
}
// Copy the whole header to Main RAM 0x27FFE00 on startup. (http://nocash.emubase.de/gbatek.htm#dscartridgeheader)
@ -2734,7 +2669,6 @@ _fake_boot:
//and how theyre named in desmume to match them up correctly. i just guessed.
}
#ifndef _NEW_BOOT
//--------------------------------
//setup the homebrew argv
//this is useful for nitrofs apps which are emulating themselves via cflash
@ -2759,7 +2693,6 @@ _fake_boot:
_MMU_write08<ARMCPU_ARM9>(kCommandline+i, rompath[i]);
_MMU_write08<ARMCPU_ARM9>(kCommandline+rompath.size(), 0);
//--------------------------------
#endif
delete header;

View File

@ -28,10 +28,8 @@ static BOOL slot1_init() { return (TRUE); }
static void slot1_reset()
{
// Write the header checksum to memory (the firmware needs it to see the cart)
#ifdef _NEW_BOOT
if (!CommonSettings.BootFromFirmware)
#endif
_MMU_write16<ARMCPU_ARM9>(0x027FF808, 0);
_MMU_write16<ARMCPU_ARM9>(0x027FF808, 0);
}
static void slot1_close() {}

View File

@ -28,10 +28,8 @@ static BOOL init() { return (TRUE); }
static void reset()
{
// Write the header checksum to memory (the firmware needs it to see the cart)
#ifdef _NEW_BOOT
if (!CommonSettings.BootFromFirmware)
#endif
_MMU_write16<ARMCPU_ARM9>(0x027FF808, T1ReadWord(MMU.CART_ROM, 0x15E));
_MMU_write16<ARMCPU_ARM9>(0x027FF808, T1ReadWord(MMU.CART_ROM, 0x15E));
}
static void close() {}
@ -94,7 +92,6 @@ static void write32_GCROMCTRL(u8 PROCNUM, u32 val)
{
case 0xB7: // Encrypted Data Read (B7aaaaaaaa000000h) - len 200h bytes
card.address = (card.command[1] << 24) | (card.command[2] << 16) | (card.command[3] << 8) | card.command[4];
card.transfer_count = 0x200;
break;
case 0xB8: // 3nd Get ROM Chip ID - len 4 bytes
@ -153,13 +150,9 @@ static u32 read32_GCDATAIN(u8 PROCNUM)
// 3rd byte - Reserved/zero (probably upper bits of chip size)
// 4th byte - Bit7: Secure Area Block transfer mode (8x200h or 1000h)
#ifdef _NEW_BOOT
u32 chipID = 0;
if (CommonSettings.BootFromFirmware)
chipID = 0x00000000 | 0x00000000 | 0x00000F00 | 0x000000C2;;
#else
u32 chipID = 0;
#endif
// Note: the BIOS stores the chip ID in main memory
// Most games continuously compare the chip ID with
@ -214,9 +207,7 @@ static u32 read32_GCDATAIN(u8 PROCNUM)
}
break;
default:
#ifdef _NEW_BOOT
printf("ARM%c: SLOT1 invalid command %02X (read)\n", PROCNUM?'7':'9', cmd);
#endif
//printf("ARM%c: SLOT1 invalid command %02X (read)\n", PROCNUM?'7':'9', cmd);
return 0;
} //switch(card.command[0])
} //read32_GCDATAIN

View File

@ -6493,6 +6493,8 @@ LRESULT CALLBACK EmulationSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, L
EnableWindow(cur, enable);
cur = GetDlgItem(hDlg, IDC_FIRMWAREBOOT);
EnableWindow(cur, (enable && IsDlgButtonChecked(hDlg, IDC_USEEXTBIOS)));
cur = GetDlgItem(hDlg, IDC_FIRMWAREEXTUSER);
EnableWindow(cur, (enable && IsDlgButtonChecked(hDlg, IDC_USEEXTFIRMWARE)));
}
return TRUE;