2016-12-05 10:02:29 -07:00
|
|
|
/*
|
|
|
|
Copyright 2016-2017 StapleButter
|
|
|
|
|
|
|
|
This file is part of melonDS.
|
|
|
|
|
|
|
|
melonDS is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free
|
|
|
|
Software Foundation, either version 3 of the License, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
2016-12-03 08:13:04 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "NDS.h"
|
2016-12-05 15:17:03 -07:00
|
|
|
#include "ARM.h"
|
2016-12-06 09:32:51 -07:00
|
|
|
#include "CP15.h"
|
2016-12-03 08:13:04 -07:00
|
|
|
|
2016-12-05 10:02:29 -07:00
|
|
|
|
2016-12-05 15:17:03 -07:00
|
|
|
// derp
|
|
|
|
namespace NDS
|
|
|
|
{
|
|
|
|
extern ARM* ARM9;
|
|
|
|
}
|
|
|
|
|
2016-12-03 08:13:04 -07:00
|
|
|
namespace CP15
|
|
|
|
{
|
|
|
|
|
|
|
|
u32 Control;
|
|
|
|
|
|
|
|
u32 DTCMSetting, ITCMSetting;
|
|
|
|
|
|
|
|
|
|
|
|
void Reset()
|
|
|
|
{
|
|
|
|
Control = 0x78; // dunno
|
|
|
|
|
|
|
|
DTCMSetting = 0;
|
|
|
|
ITCMSetting = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void UpdateDTCMSetting()
|
|
|
|
{
|
|
|
|
if (Control & (1<<16))
|
|
|
|
{
|
|
|
|
NDS::ARM9DTCMBase = DTCMSetting & 0xFFFFF000;
|
2016-12-05 09:08:24 -07:00
|
|
|
NDS::ARM9DTCMSize = 0x200 << ((DTCMSetting >> 1) & 0x1F);
|
2016-12-06 09:32:51 -07:00
|
|
|
printf("DTCM [%08X] enabled at %08X, size %X\n", DTCMSetting, NDS::ARM9DTCMBase, NDS::ARM9DTCMSize);
|
2016-12-03 08:13:04 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NDS::ARM9DTCMBase = 0xFFFFFFFF;
|
|
|
|
NDS::ARM9DTCMSize = 0;
|
|
|
|
printf("DTCM disabled\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateITCMSetting()
|
|
|
|
{
|
|
|
|
if (Control & (1<<18))
|
|
|
|
{
|
2016-12-05 09:08:24 -07:00
|
|
|
NDS::ARM9ITCMSize = 0x200 << ((ITCMSetting >> 1) & 0x1F);
|
2016-12-06 09:32:51 -07:00
|
|
|
printf("ITCM [%08X] enabled at %08X, size %X\n", ITCMSetting, 0, NDS::ARM9ITCMSize);
|
2016-12-03 08:13:04 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NDS::ARM9ITCMSize = 0;
|
|
|
|
printf("ITCM disabled\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Write(u32 id, u32 val)
|
|
|
|
{
|
2017-01-30 10:36:11 -07:00
|
|
|
//printf("CP15 write op %03X %08X %08X\n", id, val, NDS::ARM9->R[15]);
|
|
|
|
|
2016-12-03 08:13:04 -07:00
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 0x100:
|
|
|
|
val &= 0x000FF085;
|
|
|
|
Control &= ~0x000FF085;
|
|
|
|
Control |= val;
|
|
|
|
UpdateDTCMSetting();
|
|
|
|
UpdateITCMSetting();
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2016-12-05 15:17:03 -07:00
|
|
|
case 0x704:
|
2016-12-23 13:22:22 -07:00
|
|
|
case 0x782:
|
2016-12-05 15:17:03 -07:00
|
|
|
NDS::ARM9->Halt(1);
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2017-01-15 20:47:37 -07:00
|
|
|
case 0x761:
|
|
|
|
//printf("inval data cache %08X\n", val);
|
|
|
|
return;
|
|
|
|
case 0x762:
|
|
|
|
printf("inval data cache SI\n");
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 0x7A1:
|
2017-01-16 18:29:25 -07:00
|
|
|
//printf("flush data cache %08X\n", val);
|
2017-01-15 20:47:37 -07:00
|
|
|
return;
|
|
|
|
case 0x7A2:
|
|
|
|
printf("flush data cache SI\n");
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
2016-12-03 08:13:04 -07:00
|
|
|
case 0x910:
|
|
|
|
DTCMSetting = val;
|
|
|
|
UpdateDTCMSetting();
|
|
|
|
return;
|
|
|
|
case 0x911:
|
|
|
|
ITCMSetting = val;
|
|
|
|
UpdateITCMSetting();
|
|
|
|
return;
|
|
|
|
}
|
2017-01-15 20:47:37 -07:00
|
|
|
|
|
|
|
//printf("unknown CP15 write op %03X %08X\n", id, val);
|
2016-12-03 08:13:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 Read(u32 id)
|
|
|
|
{
|
|
|
|
switch (id)
|
|
|
|
{
|
|
|
|
case 0x000: // CPU ID
|
|
|
|
case 0x003:
|
|
|
|
case 0x004:
|
|
|
|
case 0x005:
|
|
|
|
case 0x006:
|
|
|
|
case 0x007:
|
|
|
|
return 0x41059461;
|
|
|
|
|
|
|
|
case 0x001:
|
|
|
|
// cache type. todo
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 0x002: // TCM size
|
|
|
|
return (6 << 6) | (5 << 18);
|
|
|
|
|
|
|
|
|
|
|
|
case 0x100: // control reg
|
|
|
|
return Control;
|
|
|
|
|
|
|
|
|
|
|
|
case 0x910:
|
|
|
|
return DTCMSetting;
|
|
|
|
case 0x911:
|
|
|
|
return ITCMSetting;
|
|
|
|
}
|
|
|
|
|
2017-01-15 20:47:37 -07:00
|
|
|
printf("unknown CP15 read op %03X\n", id);
|
2016-12-03 08:13:04 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|