mirror of
https://github.com/Creased/RCM-Emulator.git
synced 2026-12-06 02:48:11 +01:00
Boot Linux on CPU0
This commit is contained in:
1 parent
d5bf5922ed
commit
20949b4242
21 files changed
+1865
-25
No files matched your search
@@ -0,0 +1,297 @@
|
||||
// Generated from the Tegra X1 TRM (DP-07225-001 v1.3p), chapter 5.2:
|
||||
// CLK_RST_CONTROLLER register reset values, unknown bits as 0.
|
||||
// Regenerate with trm_car_resets.py; do not edit by hand.
|
||||
#ifndef T210_CAR_RESET_H
|
||||
#define T210_CAR_RESET_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
struct CarReset { uint16_t off; uint32_t val; const char *name; };
|
||||
static const CarReset kCarReset[] = {
|
||||
{0x000, 0x00000000, "RST_SOURCE"},
|
||||
{0x004, 0x1CD3D000, "RST_DEVICES_L"},
|
||||
{0x008, 0x87D1F320, "RST_DEVICES_H"},
|
||||
{0x00C, 0x828EC5FA, "RST_DEVICES_U"},
|
||||
{0x010, 0x80000130, "CLK_OUT_ENB_L"},
|
||||
{0x014, 0x00000080, "CLK_OUT_ENB_H"},
|
||||
{0x018, 0x01F00200, "CLK_OUT_ENB_U"},
|
||||
{0x024, 0x00000000, "SUPER_CCLK_DIVIDER"},
|
||||
{0x028, 0x10000000, "SCLK_BURST_POLICY"},
|
||||
{0x02C, 0x00000000, "SUPER_SCLK_DIVIDER"},
|
||||
{0x030, 0x00000000, "CLK_SYSTEM_RATE"},
|
||||
{0x044, 0x00000000, "CLK_MASK_ARM"},
|
||||
{0x048, 0x00000000, "MISC_CLK_ENB"},
|
||||
{0x050, 0x500003F1, "OSC_CTRL"},
|
||||
{0x05C, 0x00000000, "OSC_FREQ_DET_STATUS"},
|
||||
{0x068, 0x00005C00, "PLLE_SS_CNTL"},
|
||||
{0x06C, 0x00000010, "PLLE_MISC1"},
|
||||
{0x080, 0x00108002, "PLLC_BASE"},
|
||||
{0x084, 0x00000002, "PLLC_OUT"},
|
||||
{0x088, 0x40000000, "PLLC_MISC"},
|
||||
{0x08C, 0x08000000, "PLLC_MISC_1"},
|
||||
{0x090, 0x00002A02, "PLLM_BASE"},
|
||||
{0x098, 0x00000000, "PLLM_MISC1"},
|
||||
{0x09C, 0x00000010, "PLLM_MISC2"},
|
||||
{0x0A0, 0x00115408, "PLLP_BASE"},
|
||||
{0x0A4, 0x00000002, "PLLP_OUTA"},
|
||||
{0x0A8, 0x00020002, "PLLP_OUTB"},
|
||||
{0x0AC, 0x00040000, "PLLP_MISC"},
|
||||
{0x0B0, 0x00803003, "PLLA_BASE"},
|
||||
{0x0B4, 0x00000002, "PLLA_OUT"},
|
||||
{0x0B8, 0x00000000, "PLLA_MISC1"},
|
||||
{0x0BC, 0x12000000, "PLLA_MISC"},
|
||||
{0x0C0, 0x00011902, "PLLU_BASE"},
|
||||
{0x0C4, 0x00020002, "PLLU_OUTA"},
|
||||
{0x0C8, 0x00000000, "PLLU_MISC1"},
|
||||
{0x0CC, 0x00000000, "PLLU_MISC"},
|
||||
{0x0D0, 0x00211001, "PLLD_BASE"},
|
||||
{0x0D8, 0x00000000, "PLLD_MISC1"},
|
||||
{0x0DC, 0x00000000, "PLLD_MISC"},
|
||||
{0x0E0, 0x00002401, "PLLX_BASE"},
|
||||
{0x0E4, 0x00000000, "PLLX_MISC"},
|
||||
{0x0E8, 0x0E007D02, "PLLE_BASE"},
|
||||
{0x0EC, 0x00000000, "PLLE_MISC"},
|
||||
{0x0F0, 0x00000000, "PLLE_SS_CNTL1"},
|
||||
{0x0F4, 0x00000000, "PLLE_SS_CNTL2"},
|
||||
{0x0F8, 0x00000000, "LVL2_CLK_GATE_OVRA"},
|
||||
{0x0FC, 0x00000000, "LVL2_CLK_GATE_OVRB"},
|
||||
{0x100, 0xD0000000, "CLK_SOURCE_I2S2"},
|
||||
{0x104, 0xD0000000, "CLK_SOURCE_I2S3"},
|
||||
{0x108, 0xC0000000, "CLK_SOURCE_SPDIF_OUT"},
|
||||
{0x10C, 0x00000000, "CLK_SOURCE_SPDIF_IN"},
|
||||
{0x110, 0xC0000000, "CLK_SOURCE_PWM"},
|
||||
{0x118, 0xC0000000, "CLK_SOURCE_SPI2"},
|
||||
{0x11C, 0xC0000000, "CLK_SOURCE_SPI3"},
|
||||
{0x124, 0xC0000000, "CLK_SOURCE_I2C1"},
|
||||
{0x134, 0xC0000000, "CLK_SOURCE_SPI1"},
|
||||
{0x138, 0xC0000000, "CLK_SOURCE_DISP1"},
|
||||
{0x13C, 0xC0000000, "CLK_SOURCE_DISP2"},
|
||||
{0x144, 0xC0000000, "CLK_SOURCE_ISP"},
|
||||
{0x148, 0x80000000, "CLK_SOURCE_VI"},
|
||||
{0x150, 0xC0000000, "CLK_SOURCE_SDMMC1"},
|
||||
{0x154, 0xC0000000, "CLK_SOURCE_SDMMC2"},
|
||||
{0x164, 0xC0000000, "CLK_SOURCE_SDMMC4"},
|
||||
{0x178, 0xC0000002, "CLK_SOURCE_UARTA"},
|
||||
{0x17C, 0xC0000002, "CLK_SOURCE_UARTB"},
|
||||
{0x180, 0x80000000, "CLK_SOURCE_HOST1X"},
|
||||
{0x198, 0xC0000000, "CLK_SOURCE_I2C2"},
|
||||
{0x1A0, 0xC0000002, "CLK_SOURCE_UARTC"},
|
||||
{0x1A8, 0x80000000, "CLK_SOURCE_VI_SENSOR"},
|
||||
{0x1B4, 0xC0000000, "CLK_SOURCE_SPI4"},
|
||||
{0x1B8, 0xC0000000, "CLK_SOURCE_I2C3"},
|
||||
{0x1BC, 0xC0000000, "CLK_SOURCE_SDMMC3"},
|
||||
{0x1C0, 0xC0000002, "CLK_SOURCE_UARTD"},
|
||||
{0x1CC, 0xC0000000, "CLK_SOURCE_OWR"},
|
||||
{0x1D4, 0xC0000000, "CLK_SOURCE_CSITE"},
|
||||
{0x1D8, 0xD0000000, "CLK_SOURCE_I2S1"},
|
||||
{0x1DC, 0x00000000, "CLK_SOURCE_DTV"},
|
||||
{0x1F4, 0xC0000000, "CLK_SOURCE_TSEC"},
|
||||
{0x1F8, 0xC0000000, "CLK_SOURCE_LA"},
|
||||
{0x1FC, 0x00000000, "CLK_SPARE2"},
|
||||
{0x280, 0x23000780, "CLK_OUT_ENB_X"},
|
||||
{0x284, 0x23000780, "CLK_ENB_X_SET"},
|
||||
{0x288, 0x23000780, "CLK_ENB_X_CLR"},
|
||||
{0x28C, 0x01E42049, "RST_DEVICES_X"},
|
||||
{0x290, 0x01E42049, "RST_DEV_X_SET"},
|
||||
{0x294, 0x01E42049, "RST_DEV_X_CLR"},
|
||||
{0x298, 0x00000300, "CLK_OUT_ENB_Y"},
|
||||
{0x29C, 0x00000300, "CLK_ENB_Y_SET"},
|
||||
{0x2A0, 0x00000300, "CLK_ENB_Y_CLR"},
|
||||
{0x2A4, 0x0FE9F0DD, "RST_DEVICES_Y"},
|
||||
{0x2A8, 0x0FE9F0DD, "RST_DEV_Y_SET"},
|
||||
{0x2AC, 0x0FE9F0DD, "RST_DEV_Y_CLR"},
|
||||
{0x2F4, 0x00000001, "DFLL_BASE"},
|
||||
{0x304, 0x1CD3D000, "RST_DEV_L_CLR"},
|
||||
{0x308, 0x87D1F320, "RST_DEV_H_SET"},
|
||||
{0x30C, 0x87D1F327, "RST_DEV_H_CLR"},
|
||||
{0x310, 0x828EC5FA, "RST_DEV_U_SET"},
|
||||
{0x314, 0x828EC5FA, "RST_DEV_U_CLR"},
|
||||
{0x320, 0x80000130, "CLK_ENB_L_SET"},
|
||||
{0x324, 0x80000130, "CLK_ENB_L_CLR"},
|
||||
{0x328, 0x00000080, "CLK_ENB_H_SET"},
|
||||
{0x32C, 0x00000080, "CLK_ENB_H_CLR"},
|
||||
{0x330, 0x01F80200, "CLK_ENB_U_SET"},
|
||||
{0x334, 0x01F00200, "CLK_ENB_U_CLR"},
|
||||
{0x33C, 0x00000000, "CCPLEX_PG_SM_OVRD"},
|
||||
{0x340, 0x2000FEEF, "RST_CPU_CMPLX_SET"},
|
||||
{0x358, 0xFF818080, "RST_DEVICES_V"},
|
||||
{0x35C, 0x190077FF, "RST_DEVICES_W"},
|
||||
{0x360, 0x00400008, "CLK_OUT_ENB_V"},
|
||||
{0x364, 0x402000FC, "CLK_OUT_ENB_W"},
|
||||
{0x368, 0x10000000, "CCLKG_BURST_POLICY"},
|
||||
{0x36C, 0x00000000, "SUPER_CCLKG_DIVIDER"},
|
||||
{0x374, 0x00000000, "SUPER_CCLKLP_DIVIDER"},
|
||||
{0x380, 0x00000010, "CPU_SOFTRST_CTRL"},
|
||||
{0x384, 0x00040004, "CPU_SOFTRST_CTRL1"},
|
||||
{0x388, 0x07000200, "CPU_SOFTRST_CTRL2"},
|
||||
{0x3A0, 0x00000000, "LVL2_CLK_GATE_OVRC"},
|
||||
{0x3A4, 0x00000000, "LVL2_CLK_GATE_OVRD"},
|
||||
{0x3B4, 0xC0000000, "CLK_SOURCE_MSELECT"},
|
||||
{0x3B8, 0xC0000000, "CLK_SOURCE_TSENSOR"},
|
||||
{0x3BC, 0xD0000000, "CLK_SOURCE_I2S4"},
|
||||
{0x3C0, 0xD0000000, "CLK_SOURCE_I2S5"},
|
||||
{0x3C4, 0xC0000000, "CLK_SOURCE_I2C4"},
|
||||
{0x3D0, 0xD0000000, "CLK_SOURCE_AHUB"},
|
||||
{0x3E4, 0xC0000000, "CLK_SOURCE_HDA2CODEC_2X"},
|
||||
{0x3E8, 0xC0000000, "CLK_SOURCE_ACTMON"},
|
||||
{0x3EC, 0x60000000, "CLK_SOURCE_EXTPERIPH1"},
|
||||
{0x3F0, 0x60000000, "CLK_SOURCE_EXTPERIPH2"},
|
||||
{0x3F4, 0x60000000, "CLK_SOURCE_EXTPERIPH3"},
|
||||
{0x3FC, 0xC0000000, "CLK_SOURCE_I2C_SLOW"},
|
||||
{0x410, 0xC0000000, "CLK_SOURCE_SOR1"},
|
||||
{0x414, 0x00000000, "CLK_SOURCE_SOR0"},
|
||||
{0x420, 0xC0000000, "CLK_SOURCE_SATA_OOB"},
|
||||
{0x424, 0xC1000000, "CLK_SOURCE_SATA"},
|
||||
{0x428, 0xC0000000, "CLK_SOURCE_HDA"},
|
||||
{0x430, 0xFF818080, "RST_DEV_V_SET"},
|
||||
{0x434, 0xFF818080, "RST_DEV_V_CLR"},
|
||||
{0x438, 0x190077FF, "RST_DEV_W_SET"},
|
||||
{0x43C, 0x190077FF, "RST_DEV_W_CLR"},
|
||||
{0x440, 0x00400008, "CLK_ENB_V_SET"},
|
||||
{0x444, 0x00400008, "CLK_ENB_V_CLR"},
|
||||
{0x448, 0x402000FC, "CLK_ENB_W_SET"},
|
||||
{0x44C, 0x402000FC, "CLK_ENB_W_CLR"},
|
||||
{0x450, 0x2000FEEF, "RST_CPUG_CMPLX_SET"},
|
||||
{0x454, 0x2000FEEF, "RST_CPUG_CMPLX_CLR"},
|
||||
{0x460, 0x00000000, "CLK_CPUG_CMPLX_SET"},
|
||||
{0x464, 0x00000000, "CLK_CPUG_CMPLX_CLR"},
|
||||
{0x470, 0x00000000, "CPU_CMPLX_STATUS"},
|
||||
{0x47C, 0x00000000, "INTMASK"},
|
||||
{0x488, 0x00318015, "UTMIP_PLL_CFG2"},
|
||||
{0x48C, 0x00002070, "PLLE_AUX"},
|
||||
{0x494, 0x00011400, "SATA_PLL_CFG1"},
|
||||
{0x4A0, 0x00000000, "AUDIO_SYNC_CLK_I2S1"},
|
||||
{0x4A4, 0x00000000, "AUDIO_SYNC_CLK_I2S2"},
|
||||
{0x4A8, 0x00000000, "AUDIO_SYNC_CLK_I2S3"},
|
||||
{0x4AC, 0x00000000, "AUDIO_SYNC_CLK_I2S4"},
|
||||
{0x4B0, 0x00000000, "AUDIO_SYNC_CLK_I2S5"},
|
||||
{0x4B4, 0x00000000, "AUDIO_SYNC_CLK_SPDIF"},
|
||||
{0x4B8, 0x00041401, "PLLD2_BASE"},
|
||||
{0x4BC, 0x40000000, "PLLD2_MISC"},
|
||||
{0x4C0, 0x00000000, "UTMIP_PLL_CFG3"},
|
||||
{0x4C4, 0x00004104, "PLLREFE_BASE"},
|
||||
{0x4C8, 0x00000000, "PLLREFE_MISC"},
|
||||
{0x4CC, 0x00020002, "PLLREFE_OUT"},
|
||||
{0x4D0, 0x00000000, "CPU_FINETRIM_BYP"},
|
||||
{0x4D4, 0x00000000, "CPU_FINETRIM_SELECT"},
|
||||
{0x4D8, 0x00000000, "CPU_FINETRIM_DR"},
|
||||
{0x4DC, 0x00000000, "CPU_FINETRIM_DF"},
|
||||
{0x4E0, 0x00000000, "CPU_FINETRIM_F"},
|
||||
{0x4E4, 0x00000000, "CPU_FINETRIM_R"},
|
||||
{0x4E8, 0x00108002, "PLLC2_BASE"},
|
||||
{0x4EC, 0x40000000, "PLLC2_MISC"},
|
||||
{0x4F0, 0x08000000, "PLLC2_MISC_1"},
|
||||
{0x4F4, 0x1F720005, "PLLC2_MISC_2"},
|
||||
{0x4F8, 0x000000C4, "PLLC2_MISC_3"},
|
||||
{0x4FC, 0x00108002, "PLLC3_BASE"},
|
||||
{0x500, 0x40000000, "PLLC3_MISC"},
|
||||
{0x504, 0x08000000, "PLLC3_MISC_1"},
|
||||
{0x508, 0x1F720005, "PLLC3_MISC_2"},
|
||||
{0x50C, 0x000000C4, "PLLC3_MISC_3"},
|
||||
{0x510, 0x00000000, "PLLX_MISC_1"},
|
||||
{0x514, 0x00000000, "PLLX_MISC_2"},
|
||||
{0x518, 0x00000008, "PLLX_MISC_3"},
|
||||
{0x520, 0x00000014, "XUSBIO_PLL_CFG1"},
|
||||
{0x524, 0x00000105, "PLLE_AUX1"},
|
||||
{0x528, 0x00000053, "PLLP_RESHIFT"},
|
||||
{0x52C, 0x0000000F, "UTMIPLL_HW_PWRDN_CFG0"},
|
||||
{0x530, 0x0000008D, "PLLU_HW_PWRDN_CFG0"},
|
||||
{0x534, 0x8002A80F, "XUSB_PLL_CFG0"},
|
||||
{0x53C, 0x00000002, "CLK_CPU_MISC"},
|
||||
{0x540, 0x00000002, "CLK_CPUG_MISC"},
|
||||
{0x548, 0x00000001, "PLLX_HW_CTRL_CFG"},
|
||||
{0x54C, 0x00000000, "PLLX_SW_RAMP_CFG"},
|
||||
{0x550, 0x00000000, "PLLX_HW_CTRL_STATUS"},
|
||||
{0x554, 0x00000000, "LVL2_CLK_GATE_OVRE"},
|
||||
{0x55C, 0x00000000, "SPARE_REG0"},
|
||||
{0x560, 0x00000000, "AUDIO_SYNC_CLK_DMIC1"},
|
||||
{0x564, 0x00000000, "AUDIO_SYNC_CLK_DMIC2"},
|
||||
{0x570, 0x10000000, "PLLD2_SS_CFG"},
|
||||
{0x574, 0x00000000, "PLLD2_SS_CTRL1"},
|
||||
{0x578, 0x00000000, "PLLD2_SS_CTRL2"},
|
||||
{0x594, 0x40000000, "PLLDP_MISC"},
|
||||
{0x598, 0x10000000, "PLLDP_SS_CFG"},
|
||||
{0x59C, 0x00000000, "PLLDP_SS_CTRL1"},
|
||||
{0x5A0, 0x00000000, "PLLDP_SS_CTRL2"},
|
||||
{0x5A4, 0x000C2302, "PLLC4_BASE"},
|
||||
{0x5A8, 0x40000000, "PLLC4_MISC"},
|
||||
{0x5C4, 0x00000000, "CLK_SPARE0"},
|
||||
{0x5C8, 0x00000000, "CLK_SPARE1"},
|
||||
{0x5CC, 0x00000000, "GPU_ISOB_CTRL"},
|
||||
{0x5D0, 0x1F720005, "PLLC_MISC_2"},
|
||||
{0x5D4, 0x000000C4, "PLLC_MISC_3"},
|
||||
{0x5D8, 0x00000000, "PLLA_MISC2"},
|
||||
{0x5E4, 0x00000002, "PLLC4_OUT"},
|
||||
{0x5E8, 0x00002A02, "PLLMB_BASE"},
|
||||
{0x5EC, 0x00010000, "PLLMB_MISC1"},
|
||||
{0x5F0, 0x00000000, "PLLX_MISC_4"},
|
||||
{0x5F4, 0x00000000, "PLLX_MISC_5"},
|
||||
{0x600, 0x00000000, "CLK_SOURCE_XUSB_CORE_HOST"},
|
||||
{0x604, 0x00000000, "CLK_SOURCE_XUSB_FALCON"},
|
||||
{0x608, 0x00000000, "CLK_SOURCE_XUSB_FS"},
|
||||
{0x60C, 0x00000000, "CLK_SOURCE_XUSB_CORE_DEV"},
|
||||
{0x610, 0x04000000, "CLK_SOURCE_XUSB_SS"},
|
||||
{0x614, 0xC0000000, "CLK_SOURCE_CILAB"},
|
||||
{0x618, 0xC0000000, "CLK_SOURCE_CILCD"},
|
||||
{0x61C, 0xC0000000, "CLK_SOURCE_CILEF"},
|
||||
{0x620, 0xC0000000, "CLK_SOURCE_DSIA_LP"},
|
||||
{0x624, 0xC0000000, "CLK_SOURCE_DSIB_LP"},
|
||||
{0x628, 0x40000000, "CLK_SOURCE_ENTROPY"},
|
||||
{0x62C, 0xD0000000, "CLK_SOURCE_DVFS_REF"},
|
||||
{0x630, 0xD0000000, "CLK_SOURCE_DVFS_SOC"},
|
||||
{0x640, 0x60000000, "CLK_SOURCE_EMC_LATENCY"},
|
||||
{0x644, 0x40000000, "CLK_SOURCE_SOC_THERM"},
|
||||
{0x64C, 0x00000000, "CLK_SOURCE_DMIC1"},
|
||||
{0x650, 0x00000000, "CLK_SOURCE_DMIC2"},
|
||||
{0x658, 0x80000000, "CLK_SOURCE_VI_SENSOR2"},
|
||||
{0x65C, 0xC0000000, "CLK_SOURCE_I2C6"},
|
||||
{0x660, 0xC0000000, "CLK_SOURCE_MIPIBIF"},
|
||||
{0x664, 0x60000000, "CLK_SOURCE_EMC_DLL"},
|
||||
{0x66C, 0x00000000, "CLK_SOURCE_UART_FST_MIPI_CAL"},
|
||||
{0x678, 0xC0000000, "CLK_SOURCE_VIC"},
|
||||
{0x67C, 0x00030000, "PLLP_OUTC"},
|
||||
{0x680, 0x30000000, "PLLP_MISC1"},
|
||||
{0x694, 0x00000000, "CLK_SOURCE_SDMMC_LEGACY_TM"},
|
||||
{0x698, 0xE0000000, "CLK_SOURCE_NVDEC"},
|
||||
{0x69C, 0xE0000000, "CLK_SOURCE_NVJPG"},
|
||||
{0x6A0, 0x80000000, "CLK_SOURCE_NVENC"},
|
||||
{0x6A4, 0x00108002, "PLLA1_BASE"},
|
||||
{0x6A8, 0x40000000, "PLLA1_MISC"},
|
||||
{0x6AC, 0x08000000, "PLLA1_MISC_1"},
|
||||
{0x6B0, 0x1F720005, "PLLA1_MISC_2"},
|
||||
{0x6B4, 0x000000C4, "PLLA1_MISC_3"},
|
||||
{0x6B8, 0x00000000, "AUDIO_SYNC_CLK_DMIC3"},
|
||||
{0x6BC, 0x00000000, "CLK_SOURCE_DMIC3"},
|
||||
{0x6C0, 0xC0000000, "CLK_SOURCE_APE"},
|
||||
{0x6C4, 0xC0000000, "CLK_SOURCE_QSPI"},
|
||||
{0x6C8, 0xC0000000, "CLK_SOURCE_VI_I2C"},
|
||||
{0x6CC, 0x00000000, "CLK_SOURCE_USB2_HSIC_TRK"},
|
||||
{0x6D0, 0x00000000, "CLK_SOURCE_PEX_SATA_USB_RX_BYP"},
|
||||
{0x6D4, 0x40000000, "CLK_SOURCE_MAUD"},
|
||||
{0x6D8, 0xC0000000, "CLK_SOURCE_TSECB"},
|
||||
{0x6DC, 0x00000002, "CLK_CPUG_MISC1"},
|
||||
{0x6E0, 0x10006666, "ACLK_BURST_POLICY"},
|
||||
{0x6E4, 0x00000000, "SUPER_ACLK_DIVIDER"},
|
||||
{0x6E8, 0x80000000, "NVENC_SUPER_CLK_DIVIDER"},
|
||||
{0x6EC, 0x80000000, "VI_SUPER_CLK_DIVIDER"},
|
||||
{0x6F0, 0x80000000, "VIC_SUPER_CLK_DIVIDER"},
|
||||
{0x6F4, 0x80000000, "NVDEC_SUPER_CLK_DIVIDER"},
|
||||
{0x6F8, 0x80000000, "ISP_SUPER_CLK_DIVIDER"},
|
||||
{0x6FC, 0x80000000, "ISPB_SUPER_CLK_DIVIDER"},
|
||||
{0x700, 0x80000000, "NVJPG_SUPER_CLK_DIVIDER"},
|
||||
{0x704, 0x80000000, "SE_SUPER_CLK_DIVIDER"},
|
||||
{0x708, 0x80000000, "TSEC_SUPER_CLK_DIVIDER"},
|
||||
{0x70C, 0x80000000, "TSECB_SUPER_CLK_DIVIDER"},
|
||||
{0x710, 0xC0000002, "CLK_SOURCE_UARTAPE"},
|
||||
{0x714, 0x00000000, "CLK_CPUG_MISC2"},
|
||||
{0x718, 0xC0000000, "CLK_SOURCE_DBGAPB"},
|
||||
{0x71C, 0x001FFFFF, "CLK_CCPLEX_CC4_RET_CLK_ENB"},
|
||||
{0x720, 0x00000400, "ACTMON_CPU_CLK"},
|
||||
{0x724, 0x60000000, "CLK_SOURCE_EMC_SAFE"},
|
||||
{0x728, 0x00000C00, "SDMMC2_PLLC4_OUT0_SHAPER_CTRL"},
|
||||
{0x72C, 0x00000C00, "SDMMC2_PLLC4_OUT1_SHAPER_CTRL"},
|
||||
{0x730, 0x00000C00, "SDMMC2_PLLC4_OUT2_SHAPER_CTRL"},
|
||||
{0x734, 0x00000C00, "SDMMC2_DIV_CLK_SHAPER_CTRL"},
|
||||
};
|
||||
|
||||
#endif
|
||||
+484
-19
@@ -1,7 +1,10 @@
|
||||
#include "ccplex.h"
|
||||
#include "bpmp.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@@ -12,6 +15,7 @@
|
||||
#include "memory_map.h"
|
||||
#include "mmio.h"
|
||||
#include "pcie.h"
|
||||
#include "gic.h"
|
||||
|
||||
// ==========================================================================
|
||||
// Registers (bdk soc/clock.h, soc/t210.h, soc/pmc.h; Tegra X1 TRM ch.5/16)
|
||||
@@ -138,6 +142,16 @@ struct Model {
|
||||
uint64_t bus_accesses = 0;
|
||||
uint32_t boots = 0;
|
||||
const char *last_refusal = nullptr;
|
||||
|
||||
// Generic timer (ARM ARM D11): the EL1 physical and virtual timers.
|
||||
uint64_t cntp_cval = 0, cntv_cval = 0, cntvoff = 0;
|
||||
uint32_t cntp_ctl = 0, cntv_ctl = 0, cntkctl = 0, cnthctl = 0;
|
||||
|
||||
// An interrupt found pending and unmasked at a block boundary: the run
|
||||
// stops there and ccplex_run() takes it.
|
||||
bool irq_take = false;
|
||||
uint64_t irqs_taken = 0, syncs_taken = 0, smcs = 0;
|
||||
uint32_t xlat_gen = 1; // bumped when TTBR/TCR/SCTLR change
|
||||
};
|
||||
|
||||
Model m;
|
||||
@@ -151,10 +165,201 @@ struct CodePage {
|
||||
};
|
||||
std::vector<std::unique_ptr<CodePage>> code_pages;
|
||||
uint64_t last_code_page = ~0ULL;
|
||||
uc_hook h_block, h_unmapped, h_intr;
|
||||
uc_hook h_block, h_unmapped, h_intr, h_mrs, h_msr;
|
||||
|
||||
bool held() { return (m.rst_cpug & (RST_CPU0_MASK | RST_NONCPU)) != 0; }
|
||||
|
||||
// ---- Generic timer -------------------------------------------------------
|
||||
//
|
||||
// The A57s' system counter runs from the 19.2 MHz TSC on the Tegra X1 (the
|
||||
// device tree's arch timer node says 19200000), so the count is CPU0's own
|
||||
// clock in those units: deterministic, like everything else here. Every
|
||||
// access to the timer registers is answered from this model; QEMU's own
|
||||
// timers never see one.
|
||||
static constexpr uint64_t CNT_HZ = 19200000;
|
||||
|
||||
uint64_t cnt_now() { return m.ns * 12 / 625; } // ns * 19.2e6 / 1e9
|
||||
|
||||
// TMR10..13 (see ccplex.h): PTV bit 31 EN, bit 30 PER, 28:0 the count of
|
||||
// microseconds in the n+1 scheme (TRM 8.7.1); PCR bit 30 clears the
|
||||
// interrupt. Kept with CPU0 because only its clock times them.
|
||||
struct CpuTmr { uint32_t ptv = 0; uint64_t armed_ns = 0; bool pending = false; };
|
||||
CpuTmr cpu_tmr[4];
|
||||
|
||||
uint64_t tmr_deadline(const CpuTmr &t) {
|
||||
return t.armed_ns + ((uint64_t)(t.ptv & 0x1FFFFFFF) + 1) * 1000;
|
||||
}
|
||||
|
||||
void cpu_tmrs_update() {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
CpuTmr &t = cpu_tmr[i];
|
||||
if ((t.ptv & (1u << 31)) && m.ns >= tmr_deadline(t)) {
|
||||
t.pending = true;
|
||||
if (t.ptv & (1u << 30)) {
|
||||
uint64_t per = ((uint64_t)(t.ptv & 0x1FFFFFFF) + 1) * 1000;
|
||||
while (tmr_deadline(t) <= m.ns)
|
||||
t.armed_ns += per;
|
||||
} else {
|
||||
t.ptv &= ~(1u << 31);
|
||||
}
|
||||
}
|
||||
gic_set_spi(176 + i, t.pending);
|
||||
}
|
||||
}
|
||||
uint64_t ns_of_cnt(uint64_t c) {
|
||||
return c > UINT64_MAX / 625 ? UINT64_MAX : (c * 625 + 11) / 12;
|
||||
}
|
||||
|
||||
void timers_update() {
|
||||
cpu_tmrs_update();
|
||||
uint64_t p = cnt_now(), v = p - m.cntvoff;
|
||||
bool pt = (m.cntp_ctl & 1) && p >= m.cntp_cval;
|
||||
bool vt = (m.cntv_ctl & 1) && v >= m.cntv_cval;
|
||||
gic_set_ppi(GIC_PPI_PTIMER, pt && !(m.cntp_ctl & 2));
|
||||
gic_set_ppi(GIC_PPI_VTIMER, vt && !(m.cntv_ctl & 2));
|
||||
}
|
||||
|
||||
// When the next unmasked timer fires, on CPU0's clock; UINT64_MAX for never.
|
||||
uint64_t next_timer_ns() {
|
||||
uint64_t t = UINT64_MAX;
|
||||
for (const CpuTmr &c : cpu_tmr)
|
||||
if (c.ptv & (1u << 31))
|
||||
t = std::min(t, tmr_deadline(c));
|
||||
if ((m.cntp_ctl & 3) == 1)
|
||||
t = std::min(t, ns_of_cnt(m.cntp_cval));
|
||||
if ((m.cntv_ctl & 3) == 1) {
|
||||
uint64_t c = m.cntv_cval + m.cntvoff;
|
||||
if (c >= m.cntv_cval) // no wrap
|
||||
t = std::min(t, ns_of_cnt(c));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
// ---- EL1&0 stage-1 translation ---------------------------------------------
|
||||
//
|
||||
// Only for the emulator's own peeks (is the last instruction of a block a
|
||||
// WFI?), so 4 KiB granules only, which is what Linux and the stubs use. A
|
||||
// small direct-mapped cache, emptied when the translation registers change.
|
||||
uint64_t cp_read(uc_engine *uc, uint32_t op0, uint32_t op1, uint32_t crn,
|
||||
uint32_t crm, uint32_t op2) {
|
||||
uc_arm64_cp_reg r = {crn, crm, op0, op1, op2, 0};
|
||||
uc_reg_read(uc, UC_ARM64_REG_CP_REG, &r);
|
||||
return r.val;
|
||||
}
|
||||
|
||||
void cp_write(uc_engine *uc, uint32_t op0, uint32_t op1, uint32_t crn,
|
||||
uint32_t crm, uint32_t op2, uint64_t val) {
|
||||
uc_arm64_cp_reg r = {crn, crm, op0, op1, op2, val};
|
||||
uc_reg_write(uc, UC_ARM64_REG_CP_REG, &r);
|
||||
}
|
||||
|
||||
const uint8_t *host_ptr(uint64_t a, uint32_t len);
|
||||
|
||||
bool walk_va(uc_engine *uc, uint64_t va, uint64_t *pa) {
|
||||
uint64_t sctlr = cp_read(uc, 3, 0, 1, 0, 0);
|
||||
if (!(sctlr & 1)) {
|
||||
*pa = va;
|
||||
return true;
|
||||
}
|
||||
uint64_t tcr = cp_read(uc, 3, 0, 2, 0, 2);
|
||||
bool hi = (va >> 55) & 1;
|
||||
uint64_t ttbr = hi ? cp_read(uc, 3, 0, 2, 0, 1) : cp_read(uc, 3, 0, 2, 0, 0);
|
||||
unsigned tsz = hi ? (tcr >> 16) & 0x3F : tcr & 0x3F;
|
||||
unsigned tg = hi ? (tcr >> 30) & 3 : (tcr >> 14) & 3;
|
||||
if ((hi && tg != 2) || (!hi && tg != 0))
|
||||
return false; // not a 4 KiB granule
|
||||
unsigned va_bits = 64 - tsz;
|
||||
if (va_bits < 25 || va_bits > 48)
|
||||
return false;
|
||||
int levels = (int)(va_bits - 12 + 8) / 9;
|
||||
uint64_t table = ttbr & 0x0000FFFFFFFFF000ULL;
|
||||
for (int lvl = 4 - levels; lvl <= 3; lvl++) {
|
||||
unsigned shift = 12 + 9 * (3 - lvl);
|
||||
uint64_t idx = (va >> shift) & 0x1FF;
|
||||
const uint8_t *p = host_ptr(table + idx * 8, 8);
|
||||
if (!p)
|
||||
return false;
|
||||
uint64_t d;
|
||||
memcpy(&d, p, 8);
|
||||
if (!(d & 1))
|
||||
return false;
|
||||
if (lvl == 3 || !(d & 2)) {
|
||||
if (lvl == 3 && !(d & 2))
|
||||
return false;
|
||||
uint64_t mask = (1ULL << shift) - 1;
|
||||
*pa = (d & 0x0000FFFFFFFFF000ULL & ~mask) | (va & mask);
|
||||
return true;
|
||||
}
|
||||
table = d & 0x0000FFFFFFFFF000ULL;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
struct XlatEntry { uint64_t va_page; uint64_t pa_page; uint32_t gen; };
|
||||
XlatEntry xlat_cache[1024];
|
||||
|
||||
bool va_to_pa(uc_engine *uc, uint64_t va, uint64_t *pa) {
|
||||
uint64_t page = va >> 12;
|
||||
XlatEntry &e = xlat_cache[page & 1023];
|
||||
if (e.gen == m.xlat_gen && e.va_page == page) {
|
||||
*pa = (e.pa_page << 12) | (va & 0xFFF);
|
||||
return true;
|
||||
}
|
||||
uint64_t p;
|
||||
if (!walk_va(uc, va & ~0xFFFULL, &p))
|
||||
return false;
|
||||
e = {page, p >> 12, m.xlat_gen};
|
||||
*pa = p | (va & 0xFFF);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool read_insn(uc_engine *uc, uint64_t va, uint32_t *insn) {
|
||||
uint64_t pa;
|
||||
if (!va_to_pa(uc, va, &pa))
|
||||
return false;
|
||||
const uint8_t *p = host_ptr(pa, 4);
|
||||
if (!p)
|
||||
return false;
|
||||
memcpy(insn, p, 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- Exception entry ---------------------------------------------------------
|
||||
//
|
||||
// Unicorn never delivers guest exceptions (see the reset-entry note), so the
|
||||
// model takes them itself: SPSR/ELR/ESR, PSTATE, then the vector. Only to
|
||||
// EL1 from EL1 on SP_EL1, which is every exception a kernel without
|
||||
// userspace or hypervisor takes - and it is the case where the translator's
|
||||
// cached EL stays right, because the EL does not change.
|
||||
enum ExcKind { EXC_SYNC = 0, EXC_IRQ = 1, EXC_FIQ = 2, EXC_SERROR = 3 };
|
||||
|
||||
bool take_exception(uc_engine *uc, uint64_t ret_pc, ExcKind kind,
|
||||
uint32_t esr, uint64_t far) {
|
||||
uint64_t ps = 0, vbar = 0;
|
||||
uc_reg_read(uc, UC_ARM64_REG_PSTATE, &ps);
|
||||
unsigned el = (ps >> 2) & 3;
|
||||
if (el != 1 || !(ps & 1)) {
|
||||
printf("[ccplex] CPU0 exception (kind %d, ESR 0x%08X) at PC=0x%llX from "
|
||||
"EL%u%c: only EL1h->EL1 entry is modelled, CPU0 halted\n", kind,
|
||||
esr, (unsigned long long)ret_pc, el, (ps & 1) ? 'h' : 't');
|
||||
fflush(stdout);
|
||||
return false;
|
||||
}
|
||||
uc_reg_read(uc, UC_ARM64_REG_VBAR_EL1, &vbar);
|
||||
cp_write(uc, 3, 0, 4, 0, 0, ps); // SPSR_EL1
|
||||
uc_reg_write(uc, UC_ARM64_REG_ELR_EL1, &ret_pc);
|
||||
if (kind == EXC_SYNC) {
|
||||
uint64_t e = esr;
|
||||
uc_reg_write(uc, UC_ARM64_REG_ESR_EL1, &e);
|
||||
uc_reg_write(uc, UC_ARM64_REG_FAR_EL1, &far);
|
||||
}
|
||||
uint64_t nps = (ps & 0xF0000000ULL) | 0x3C0 | 0x5; // EL1h, DAIF masked
|
||||
uc_reg_write(uc, UC_ARM64_REG_PSTATE, &nps);
|
||||
uint64_t vec = vbar + 0x200 + 0x80 * (uint64_t)kind;
|
||||
uc_reg_write(uc, UC_ARM64_REG_PC, &vec);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint64_t entry_vector() {
|
||||
return ((uint64_t)m.sb_rst_hi << 32) | (m.sb_rst_lo & ~1u);
|
||||
}
|
||||
@@ -290,28 +495,158 @@ void hook_block(uc_engine *uc, uint64_t address, uint32_t size, void *) {
|
||||
commit_pending();
|
||||
if (m.wfe_next) {
|
||||
// The block that just ran ended in WFE/WFI: the core sleeps until
|
||||
// something wakes it. Nothing in this model sends it an event, so it
|
||||
// sleeps to the end of the slice and resumes - a spurious wake-up, which
|
||||
// the architecture allows, and which a `for(;;) wfe;` park loop turns
|
||||
// straight back into sleep. Without this that loop would spin through
|
||||
// hundreds of millions of instructions per emulated second.
|
||||
// something wakes it - an interrupt, which here means a timer firing or
|
||||
// a device line the GIC already holds. With neither in sight it sleeps
|
||||
// to the end of the slice and resumes, a spurious wake-up the
|
||||
// architecture allows and a `for(;;) wfe;` park loop turns straight back
|
||||
// into sleep. Without this that loop would spin through hundreds of
|
||||
// millions of instructions per emulated second.
|
||||
m.wfe_next = false;
|
||||
if (m.ns < m.target_ns)
|
||||
m.ns = m.target_ns;
|
||||
if (!gic_irq_pending()) {
|
||||
uint64_t wake = std::min(m.target_ns, next_timer_ns());
|
||||
if (wake > m.ns)
|
||||
m.ns = wake;
|
||||
}
|
||||
}
|
||||
timers_update();
|
||||
g_state->emu_usec = m.ns / 1000;
|
||||
if (m.ns >= m.target_ns || m.kill_pending) {
|
||||
uc_emu_stop(uc);
|
||||
return;
|
||||
}
|
||||
if (gic_irq_pending()) {
|
||||
uint64_t ps = 0;
|
||||
uc_reg_read(uc, UC_ARM64_REG_PSTATE, &ps);
|
||||
if (!(ps & (1u << 7))) { // PSTATE.I clear: take it before this block
|
||||
m.irq_take = true;
|
||||
uc_emu_stop(uc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
note_code_page(address);
|
||||
// Every A64 instruction is four bytes.
|
||||
m.pending = size >= 4 ? size / 4 : 1;
|
||||
if (const uint8_t *p = host_ptr(address + size - 4, 4)) {
|
||||
uint32_t last;
|
||||
memcpy(&last, p, 4);
|
||||
uint32_t last;
|
||||
if (read_insn(uc, address + size - 4, &last))
|
||||
m.wfe_next = (last == A64_WFE || last == A64_WFI);
|
||||
}
|
||||
|
||||
// ---- System registers --------------------------------------------------------
|
||||
//
|
||||
// MRS/MSR of the generic timer are answered here (and skipped by Unicorn);
|
||||
// writes to the translation registers also empty the emulator's VA cache.
|
||||
bool is(const uc_arm64_cp_reg *r, uint32_t op0, uint32_t op1, uint32_t crn,
|
||||
uint32_t crm, uint32_t op2) {
|
||||
return r->op0 == op0 && r->op1 == op1 && r->crn == crn && r->crm == crm &&
|
||||
r->op2 == op2;
|
||||
}
|
||||
|
||||
uint32_t hook_mrs(uc_engine *uc, uc_arm64_reg reg, const uc_arm64_cp_reg *r,
|
||||
void *) {
|
||||
if (r->op0 != 3 || r->crn != 14)
|
||||
return 0;
|
||||
uint64_t p = cnt_now(), v = p - m.cntvoff, out;
|
||||
if (is(r, 3, 3, 14, 0, 0)) out = CNT_HZ; // CNTFRQ_EL0
|
||||
else if (is(r, 3, 3, 14, 0, 1)) out = p; // CNTPCT_EL0
|
||||
else if (is(r, 3, 3, 14, 0, 2)) out = v; // CNTVCT_EL0
|
||||
else if (is(r, 3, 3, 14, 2, 0)) out = (uint32_t)(m.cntp_cval - p);
|
||||
else if (is(r, 3, 3, 14, 2, 1)) out = m.cntp_ctl | (((m.cntp_ctl & 1) && p >= m.cntp_cval) ? 4 : 0);
|
||||
else if (is(r, 3, 3, 14, 2, 2)) out = m.cntp_cval;
|
||||
else if (is(r, 3, 3, 14, 3, 0)) out = (uint32_t)(m.cntv_cval - v);
|
||||
else if (is(r, 3, 3, 14, 3, 1)) out = m.cntv_ctl | (((m.cntv_ctl & 1) && v >= m.cntv_cval) ? 4 : 0);
|
||||
else if (is(r, 3, 3, 14, 3, 2)) out = m.cntv_cval;
|
||||
else if (is(r, 3, 0, 14, 1, 0)) out = m.cntkctl; // CNTKCTL_EL1
|
||||
else if (is(r, 3, 4, 14, 0, 3)) out = m.cntvoff; // CNTVOFF_EL2
|
||||
else if (is(r, 3, 4, 14, 1, 0)) out = m.cnthctl; // CNTHCTL_EL2
|
||||
else return 0;
|
||||
if (reg != UC_ARM64_REG_XZR)
|
||||
uc_reg_write(uc, reg, &out);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint32_t hook_msr(uc_engine *uc, uc_arm64_reg reg, const uc_arm64_cp_reg *r,
|
||||
void *) {
|
||||
(void)reg;
|
||||
(void)uc;
|
||||
if (r->op0 == 3 && r->op1 == 0 && ((r->crn == 2 && r->crm == 0 && r->op2 <= 2) ||
|
||||
(r->crn == 1 && r->crm == 0 && r->op2 == 0))) {
|
||||
m.xlat_gen++; // TTBR0/TTBR1/TCR/SCTLR_EL1
|
||||
return 0;
|
||||
}
|
||||
if (r->op0 != 3 || r->crn != 14)
|
||||
return 0;
|
||||
uint64_t p = cnt_now(), v = p - m.cntvoff, val = r->val;
|
||||
if (is(r, 3, 3, 14, 0, 0)) ; // CNTFRQ: fixed
|
||||
else if (is(r, 3, 3, 14, 2, 0)) m.cntp_cval = p + (uint64_t)(int64_t)(int32_t)val;
|
||||
else if (is(r, 3, 3, 14, 2, 1)) m.cntp_ctl = val & 3;
|
||||
else if (is(r, 3, 3, 14, 2, 2)) m.cntp_cval = val;
|
||||
else if (is(r, 3, 3, 14, 3, 0)) m.cntv_cval = v + (uint64_t)(int64_t)(int32_t)val;
|
||||
else if (is(r, 3, 3, 14, 3, 1)) m.cntv_ctl = val & 3;
|
||||
else if (is(r, 3, 3, 14, 3, 2)) m.cntv_cval = val;
|
||||
else if (is(r, 3, 0, 14, 1, 0)) m.cntkctl = (uint32_t)val;
|
||||
else if (is(r, 3, 4, 14, 0, 3)) m.cntvoff = val;
|
||||
else if (is(r, 3, 4, 14, 1, 0)) m.cnthctl = (uint32_t)val;
|
||||
else return 0;
|
||||
timers_update();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---- PSCI (ARM DEN 0022), answered on SMC -------------------------------------
|
||||
//
|
||||
// On a Switch the secure monitor (ATF) answers these; here the emulator is
|
||||
// the monitor. One core is modelled, so CPU_ON is refused.
|
||||
void psci_call(uc_engine *uc) {
|
||||
uint64_t x0 = 0, x1 = 0, ret;
|
||||
uc_reg_read(uc, UC_ARM64_REG_X0, &x0);
|
||||
uc_reg_read(uc, UC_ARM64_REG_X1, &x1);
|
||||
uint32_t fid = (uint32_t)x0;
|
||||
m.smcs++;
|
||||
switch (fid) {
|
||||
case 0x84000000: ret = 0x00010000; break; // PSCI_VERSION 1.0
|
||||
case 0x84000006: ret = 2; break; // MIGRATE_INFO_TYPE: none
|
||||
case 0x8400000A: { // PSCI_FEATURES
|
||||
uint32_t q = (uint32_t)x1;
|
||||
ret = (q == 0x84000000 || q == 0x84000001 || q == 0xC4000001 ||
|
||||
q == 0x84000002 || q == 0x84000003 || q == 0xC4000003 ||
|
||||
q == 0x84000004 || q == 0xC4000004 || q == 0x84000006 ||
|
||||
q == 0x84000008 || q == 0x84000009 || q == 0x8400000A) ? 0 : (uint64_t)-1;
|
||||
break;
|
||||
}
|
||||
case 0x84000001: case 0xC4000001: ret = 0; break; // CPU_SUSPEND: a WFI
|
||||
case 0x84000003: case 0xC4000003: ret = (uint64_t)-3; break; // CPU_ON: DENIED
|
||||
case 0x84000004: case 0xC4000004: ret = (x1 & 0xFF) == 0 ? 0 : 1; break; // AFFINITY_INFO
|
||||
case 0x84000002: // CPU_OFF
|
||||
printf("[ccplex] PSCI CPU_OFF from CPU0\n");
|
||||
m.kill_pending = true;
|
||||
m.kill_reason = "PSCI CPU_OFF";
|
||||
uc_emu_stop(uc);
|
||||
ret = 0;
|
||||
break;
|
||||
case 0x84000008: // SYSTEM_OFF
|
||||
case 0x84000009: // SYSTEM_RESET
|
||||
printf("[ccplex] PSCI %s from CPU0\n", fid == 0x84000008 ? "SYSTEM_OFF" : "SYSTEM_RESET");
|
||||
m.kill_pending = true;
|
||||
m.kill_reason = fid == 0x84000008 ? "PSCI SYSTEM_OFF" : "PSCI SYSTEM_RESET";
|
||||
uc_emu_stop(uc);
|
||||
ret = 0;
|
||||
break;
|
||||
default: {
|
||||
static uint32_t seen[32];
|
||||
static int nseen;
|
||||
bool known = false;
|
||||
for (int i = 0; i < nseen; i++)
|
||||
known |= seen[i] == fid;
|
||||
if (!known && nseen < 32) {
|
||||
seen[nseen++] = fid;
|
||||
printf("[ccplex] SMC 0x%08X (x1=0x%llX) not implemented, returns NOT_SUPPORTED\n",
|
||||
fid, (unsigned long long)x1);
|
||||
fflush(stdout);
|
||||
}
|
||||
ret = (uint64_t)-1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
uc_reg_write(uc, UC_ARM64_REG_X0, &ret);
|
||||
}
|
||||
|
||||
bool hook_unmapped(uc_engine *uc, uc_mem_type type, uint64_t address, int size,
|
||||
@@ -320,6 +655,22 @@ bool hook_unmapped(uc_engine *uc, uc_mem_type type, uint64_t address, int size,
|
||||
(void)value;
|
||||
uint64_t pc = 0;
|
||||
uc_reg_read(uc, UC_ARM64_REG_PC, &pc);
|
||||
// The peripheral band decodes everywhere on the APB/AHB: a register the
|
||||
// emulator does not model reads back what was written, as it does for the
|
||||
// BPMP. Undecoded space outside it (the PCIe apertures' holes, nothing at
|
||||
// all) still wedges the core.
|
||||
if (address >= 0x50000000 && address < 0x80000000 &&
|
||||
type != UC_MEM_FETCH_UNMAPPED) {
|
||||
static std::vector<uint64_t> told;
|
||||
uint64_t page = address & ~0xFFFULL;
|
||||
if (std::find(told.begin(), told.end(), page) == told.end() && told.size() < 512) {
|
||||
told.push_back(page);
|
||||
printf("[ccplex] CPU0 first access to unmodelled page 0x%08llX (PC=0x%llX)\n",
|
||||
(unsigned long long)page, (unsigned long long)pc);
|
||||
fflush(stdout);
|
||||
}
|
||||
return mmio_map_page(uc, g_state, page);
|
||||
}
|
||||
const char *kind = type == UC_MEM_FETCH_UNMAPPED ? "fetch"
|
||||
: type == UC_MEM_WRITE_UNMAPPED ? "write"
|
||||
: "read";
|
||||
@@ -330,16 +681,54 @@ bool hook_unmapped(uc_engine *uc, uc_mem_type type, uint64_t address, int size,
|
||||
printf("[ccplex] CPU0 %s of unmapped 0x%llX at PC=0x%llX: nothing answers, "
|
||||
"CPU0 wedged\n", kind, (unsigned long long)address,
|
||||
(unsigned long long)pc);
|
||||
{
|
||||
uint64_t pa = 0;
|
||||
bool ok = walk_va(uc, address, &pa);
|
||||
printf("[ccplex] SCTLR_EL1 %08llX TCR_EL1 %llX TTBR0 %llX TTBR1 %llX; walk %s 0x%llX\n",
|
||||
(unsigned long long)cp_read(uc, 3, 0, 1, 0, 0),
|
||||
(unsigned long long)cp_read(uc, 3, 0, 2, 0, 2),
|
||||
(unsigned long long)cp_read(uc, 3, 0, 2, 0, 0),
|
||||
(unsigned long long)cp_read(uc, 3, 0, 2, 0, 1), ok ? "->" : "failed",
|
||||
(unsigned long long)pa);
|
||||
}
|
||||
fflush(stdout);
|
||||
return false;
|
||||
}
|
||||
|
||||
void hook_intr(uc_engine *uc, uint32_t intno, void *) {
|
||||
// Unicorn does not deliver guest exceptions (see the reset-entry note),
|
||||
// so a fault cannot reach the stub's own vectors. Say what happened and
|
||||
// stop the core rather than resume past the faulting instruction.
|
||||
// Unicorn does not deliver guest exceptions (see the reset-entry note).
|
||||
// SMC is answered here (PSCI) and execution goes on after it; BRK and
|
||||
// undefined instructions are taken to EL1's own vectors, which is how a
|
||||
// kernel's WARN() and BUG() work. Anything else stops the core rather
|
||||
// than resume past the faulting instruction.
|
||||
uint64_t pc = 0;
|
||||
uc_reg_read(uc, UC_ARM64_REG_PC, &pc);
|
||||
uint32_t insn = 0;
|
||||
if (intno == 13 || intno == 12) { // EXCP_SMC (QEMU 5: 13)
|
||||
if (read_insn(uc, pc - 4, &insn) && (insn & 0xFFE0001F) == 0xD4000003) {
|
||||
psci_call(uc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (intno == 11 && read_insn(uc, pc - 4, &insn) && (insn & 0xFFE0001F) == 0xD4000002) {
|
||||
uint64_t r = (uint64_t)-1; // HVC with no hypervisor
|
||||
uc_reg_write(uc, UC_ARM64_REG_X0, &r);
|
||||
return;
|
||||
}
|
||||
if (intno == 7 && read_insn(uc, pc, &insn) && (insn & 0xFFE0001F) == 0xD4200000) {
|
||||
uint32_t esr = (0x3Cu << 26) | (1u << 25) | ((insn >> 5) & 0xFFFF);
|
||||
m.syncs_taken++;
|
||||
if (take_exception(uc, pc, EXC_SYNC, esr, 0))
|
||||
return;
|
||||
}
|
||||
if (intno == 1) { // EXCP_UDEF
|
||||
m.syncs_taken++;
|
||||
if (read_insn(uc, pc, &insn))
|
||||
printf("[ccplex] CPU0 undefined instruction 0x%08X at PC=0x%llX, taken to EL1\n",
|
||||
insn, (unsigned long long)pc);
|
||||
if (take_exception(uc, pc, EXC_SYNC, (1u << 25), 0))
|
||||
return;
|
||||
}
|
||||
static const char *names[] = {"?", "UDEF", "SWI", "PREFETCH_ABORT",
|
||||
"DATA_ABORT", "IRQ", "FIQ", "BKPT", "EXIT",
|
||||
"KERNEL_TRAP", "HVC", "HYP_TRAP", "SMC"};
|
||||
@@ -362,6 +751,11 @@ bool start_cpu0(EmuState *state) {
|
||||
return false;
|
||||
}
|
||||
uc_ctl_set_cpu_model(uc, UC_CPU_ARM64_A57);
|
||||
#if UC_API_MAJOR > 2 || (UC_API_MAJOR == 2 && UC_API_MINOR >= 1)
|
||||
// Translate through the guest's own page tables (the 2.1 default, set
|
||||
// explicitly): a kernel runs with its MMU on.
|
||||
uc_ctl_tlb_mode(uc, UC_TLB_CPU);
|
||||
#endif
|
||||
|
||||
// IRAM, DRAM and TZRAM are the same host memory the BPMP engine maps, so
|
||||
// a stub the BPMP copies into DRAM and the mailbox both cores poll are one
|
||||
@@ -397,6 +791,15 @@ bool start_cpu0(EmuState *state) {
|
||||
uc_hook_add(uc, &h_unmapped, UC_HOOK_MEM_UNMAPPED, (void *)hook_unmapped,
|
||||
nullptr, 1, 0);
|
||||
uc_hook_add(uc, &h_intr, UC_HOOK_INTR, (void *)hook_intr, nullptr, 1, 0);
|
||||
uc_hook_add(uc, &h_mrs, UC_HOOK_INSN, (void *)hook_mrs, nullptr, 1, 0,
|
||||
UC_ARM64_INS_MRS);
|
||||
if (!getenv("RCM_EMU_NO_MSR_HOOK"))
|
||||
uc_hook_add(uc, &h_msr, UC_HOOK_INSN, (void *)hook_msr, nullptr, 1, 0,
|
||||
UC_ARM64_INS_MSR);
|
||||
m.cntp_cval = m.cntv_cval = m.cntvoff = 0;
|
||||
m.cntp_ctl = m.cntv_ctl = m.cntkctl = m.cnthctl = 0;
|
||||
m.irq_take = false;
|
||||
m.xlat_gen++;
|
||||
|
||||
m.uc = uc;
|
||||
m.pc = RESET_TRAMPOLINE;
|
||||
@@ -572,6 +975,21 @@ void ccplex_bus_tick(EmuState *state) {
|
||||
|
||||
uint64_t ccplex_now_us() { return m.ns / 1000; }
|
||||
|
||||
void ccplex_tmr_write(uint32_t off, uint32_t val) {
|
||||
if (off < 0x90 || off >= 0xB0)
|
||||
return;
|
||||
CpuTmr &t = cpu_tmr[(off - 0x90) / 8];
|
||||
if ((off - 0x90) % 8 == 4) { // PCR
|
||||
if (val & (1u << 30)) {
|
||||
t.pending = false;
|
||||
gic_set_spi(176 + (int)((off - 0x90) / 8), false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
t.ptv = val; // PTV: (re)armed now
|
||||
t.armed_ns = m.ns;
|
||||
}
|
||||
|
||||
bool ccplex_cpu0_running() { return m.cpu0 == Cpu0::Running && m.uc; }
|
||||
|
||||
void ccplex_run(EmuState *state, uint64_t until_us) {
|
||||
@@ -601,18 +1019,65 @@ void ccplex_run(EmuState *state, uint64_t until_us) {
|
||||
m.target_ns = target;
|
||||
m.in_run = true;
|
||||
|
||||
drop_stale_code();
|
||||
// The BPMP can only rewrite CPU0's code while it runs; parked, it cannot,
|
||||
// and comparing hundreds of kernel pages before every slice is the one
|
||||
// thing that would make a booted kernel crawl.
|
||||
if (!state->bpmp_halted)
|
||||
drop_stale_code();
|
||||
|
||||
// `until` is an address an A64 PC can never hold (it is not 4-aligned).
|
||||
// 0 would make a branch to address 0 end every slice before it starts.
|
||||
uc_err err = uc_emu_start(m.uc, m.pc, ~0ULL, 0, 0);
|
||||
|
||||
commit_pending();
|
||||
uc_reg_read(m.uc, UC_ARM64_REG_PC, &m.pc);
|
||||
uc_err err;
|
||||
for (;;) {
|
||||
err = uc_emu_start(m.uc, m.pc, ~0ULL, 0, 0);
|
||||
commit_pending();
|
||||
uc_reg_read(m.uc, UC_ARM64_REG_PC, &m.pc);
|
||||
if (err != UC_ERR_OK || m.kill_pending || m.cpu0 != Cpu0::Running || !m.irq_take)
|
||||
break;
|
||||
// An interrupt was pending and unmasked at the block that starts at PC:
|
||||
// take it there, then carry on with the slice from the vector.
|
||||
m.irq_take = false;
|
||||
m.irqs_taken++;
|
||||
if (!take_exception(m.uc, m.pc, EXC_IRQ, 0, 0)) {
|
||||
m.cpu0 = Cpu0::Hung;
|
||||
break;
|
||||
}
|
||||
uc_reg_read(m.uc, UC_ARM64_REG_PC, &m.pc);
|
||||
if (m.ns >= m.target_ns)
|
||||
break;
|
||||
}
|
||||
m.in_run = false;
|
||||
g_bus_master = prev;
|
||||
state->emu_usec = bpmp_usec;
|
||||
|
||||
// RCM_EMU_CPU0_PROFILE=1: one line every second of real time with where
|
||||
// CPU0 is, how much it ran and how many interrupts it took - enough to
|
||||
// tell a hung kernel from a slow one.
|
||||
{
|
||||
static int prof = -1;
|
||||
static uint64_t last_wall = 0, last_ret = 0;
|
||||
if (prof < 0)
|
||||
prof = getenv("RCM_EMU_CPU0_PROFILE") ? 1 : 0;
|
||||
if (prof) {
|
||||
uint64_t wall = (uint64_t)std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
if (wall - last_wall >= 1000) {
|
||||
last_wall = wall;
|
||||
printf("[cpu0prof] t=%llu us pc=0x%llX retired=%llu (+%llu) irqs=%llu syncs=%llu smcs=%llu gic=%d\n",
|
||||
(unsigned long long)(m.ns / 1000), (unsigned long long)m.pc,
|
||||
(unsigned long long)m.retired, (unsigned long long)(m.retired - last_ret),
|
||||
(unsigned long long)m.irqs_taken, (unsigned long long)m.syncs_taken,
|
||||
(unsigned long long)m.smcs, gic_highest_pending());
|
||||
last_ret = m.retired;
|
||||
char g27[160];
|
||||
gic_describe(GIC_PPI_VTIMER, g27, sizeof(g27));
|
||||
printf("[cpu0prof] vtimer ctl %u cval %llu cnt %llu; %s\n", m.cntv_ctl,
|
||||
(unsigned long long)m.cntv_cval, (unsigned long long)(cnt_now() - m.cntvoff), g27);
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m.kill_pending) {
|
||||
m.kill_pending = false;
|
||||
const char *why = m.kill_reason ? m.kill_reason : "stopped";
|
||||
|
||||
@@ -58,6 +58,11 @@ void ccplex_bus_tick(EmuState *state);
|
||||
// True while CPU0 is out of reset and executing (not parked on a hung bus).
|
||||
bool ccplex_cpu0_running();
|
||||
|
||||
// TMR10..TMR13 (TMR base + 0x90..0xAF): the timers Tegra210 kernels use as
|
||||
// per-CPU clock event devices. Their interrupts go to GIC SPI 176..179 on
|
||||
// CPU0's clock.
|
||||
void ccplex_tmr_write(uint32_t off, uint32_t val);
|
||||
|
||||
// Run CPU0 until its clock reaches `until_us` - the BPMP's current time.
|
||||
void ccplex_run(EmuState *state, uint64_t until_us);
|
||||
|
||||
|
||||
+307
@@ -0,0 +1,307 @@
|
||||
#include "gic.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
/*
|
||||
* GIC-400 model. See gic.h. Register offsets and reset values: ARM IHI 0048B
|
||||
* (GICv2 architecture) ch.4, GIC-400 TRM (DDI 0471B) table 3-1 / 3-6.
|
||||
*/
|
||||
|
||||
namespace {
|
||||
|
||||
struct Gic {
|
||||
uint32_t dctlr = 0;
|
||||
uint32_t cctlr = 0;
|
||||
uint32_t pmr = 0;
|
||||
uint32_t bpr = 2;
|
||||
uint32_t group[GIC_NR_IRQS / 32] = {};
|
||||
bool enabled[GIC_NR_IRQS] = {};
|
||||
bool latched[GIC_NR_IRQS] = {}; // edge, SGI or software-set pending
|
||||
bool line[GIC_NR_IRQS] = {}; // level input
|
||||
bool active[GIC_NR_IRQS] = {};
|
||||
uint8_t prio[GIC_NR_IRQS] = {};
|
||||
uint8_t target[GIC_NR_IRQS] = {};
|
||||
uint8_t cfg[GIC_NR_IRQS] = {}; // 2 bits each, bit 1 set = edge
|
||||
// Active priorities, most recent last: the running priority is the
|
||||
// highest (numerically lowest) of them.
|
||||
int stack[GIC_NR_IRQS] = {};
|
||||
int depth = 0;
|
||||
};
|
||||
|
||||
Gic g;
|
||||
|
||||
// CPU0 asks "is an interrupt pending?" before every translated block, so the
|
||||
// answer is cached and recomputed only after something changed.
|
||||
bool g_dirty = true;
|
||||
int g_best = 1023;
|
||||
bool g_line_up = false;
|
||||
|
||||
bool is_edge(int id) { return id < 16 || (g.cfg[id] & 2); }
|
||||
|
||||
bool pending(int id) {
|
||||
if (g.latched[id])
|
||||
return true;
|
||||
return !is_edge(id) && g.line[id];
|
||||
}
|
||||
|
||||
int running_prio() {
|
||||
int p = 0x100;
|
||||
for (int i = 0; i < g.depth; i++)
|
||||
if (g.prio[g.stack[i]] < p)
|
||||
p = g.prio[g.stack[i]];
|
||||
return p;
|
||||
}
|
||||
|
||||
int best_scan() {
|
||||
int bestid = 1023, bestp = 0x100;
|
||||
for (int id = 0; id < GIC_NR_IRQS; id++) {
|
||||
if (!g.enabled[id] || g.active[id] || !pending(id))
|
||||
continue;
|
||||
if (g.prio[id] < bestp) {
|
||||
bestp = g.prio[id];
|
||||
bestid = id;
|
||||
}
|
||||
}
|
||||
return bestid;
|
||||
}
|
||||
|
||||
int best() {
|
||||
if (g_dirty) {
|
||||
g_best = best_scan();
|
||||
g_line_up = false;
|
||||
if ((g.dctlr & 3) && (g.cctlr & 3) && g_best != 1023)
|
||||
g_line_up = g.prio[g_best] < g.pmr && g.prio[g_best] < running_prio();
|
||||
g_dirty = false;
|
||||
}
|
||||
return g_best;
|
||||
}
|
||||
|
||||
uint32_t bits_read(const bool *v, uint32_t word) {
|
||||
uint32_t r = 0;
|
||||
for (int b = 0; b < 32; b++)
|
||||
if (v[word * 32 + b])
|
||||
r |= 1u << b;
|
||||
return r;
|
||||
}
|
||||
|
||||
uint32_t pend_read(uint32_t word) {
|
||||
uint32_t r = 0;
|
||||
for (int b = 0; b < 32; b++)
|
||||
if (pending(word * 32 + b))
|
||||
r |= 1u << b;
|
||||
return r;
|
||||
}
|
||||
|
||||
// Byte-array registers (priority, targets) accessed by byte or by word.
|
||||
uint32_t bytes_read(const uint8_t *a, uint32_t off, unsigned size) {
|
||||
uint32_t r = 0;
|
||||
for (unsigned i = 0; i < size && off + i < GIC_NR_IRQS; i++)
|
||||
r |= (uint32_t)a[off + i] << (8 * i);
|
||||
return r;
|
||||
}
|
||||
|
||||
void bytes_write(uint8_t *a, uint32_t off, unsigned size, uint32_t v,
|
||||
uint8_t mask) {
|
||||
for (unsigned i = 0; i < size && off + i < GIC_NR_IRQS; i++)
|
||||
a[off + i] = (uint8_t)((v >> (8 * i)) & mask);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void gic_reset() {
|
||||
g = Gic();
|
||||
g_dirty = true;
|
||||
for (int id = 0; id < 32; id++)
|
||||
g.target[id] = 0x01; // banked: reads this CPU's own bit
|
||||
for (int id = 0; id < 16; id++)
|
||||
g.enabled[id] = true; // SGIs are always enabled on GIC-400
|
||||
for (int id = 16; id < 32; id++)
|
||||
g.cfg[id] = 0; // PPIs level
|
||||
}
|
||||
|
||||
uint32_t gic_dist_read(uint32_t off, unsigned size) {
|
||||
if (off >= 0x400 && off < 0x400 + GIC_NR_IRQS)
|
||||
return bytes_read(g.prio, off - 0x400, size);
|
||||
if (off >= 0x800 && off < 0x800 + GIC_NR_IRQS) {
|
||||
uint32_t i = off - 0x800;
|
||||
if (i < 32)
|
||||
return bytes_read(g.target, i, size);
|
||||
return bytes_read(g.target, i, size);
|
||||
}
|
||||
uint32_t w = (off & 0x7F) >> 2;
|
||||
switch (off & ~0x7Fu) {
|
||||
case 0x080: return w < GIC_NR_IRQS / 32 ? g.group[w] : 0;
|
||||
case 0x100: case 0x180: return w < GIC_NR_IRQS / 32 ? bits_read(g.enabled, w) : 0;
|
||||
case 0x200: case 0x280: return w < GIC_NR_IRQS / 32 ? pend_read(w) : 0;
|
||||
case 0x300: case 0x380: return w < GIC_NR_IRQS / 32 ? bits_read(g.active, w) : 0;
|
||||
default: break;
|
||||
}
|
||||
if (off >= 0xC00 && off < 0xC00 + GIC_NR_IRQS / 4) {
|
||||
uint32_t base = (off - 0xC00) * 4, r = 0;
|
||||
for (int i = 0; i < 16; i++)
|
||||
r |= (uint32_t)(g.cfg[base + i] & 3) << (2 * i);
|
||||
return r;
|
||||
}
|
||||
switch (off) {
|
||||
case 0x000: return g.dctlr;
|
||||
case 0x004: return (1u << 10) | (3u << 5) | (GIC_NR_IRQS / 32 - 1); // SecExt, 4 CPUs
|
||||
case 0x008: return 0x0200143B; // GIC-400, implementer ARM
|
||||
case 0xFE8: return 0x2B; // PIDR2: GICv2
|
||||
case 0xFD0: return 0x04;
|
||||
case 0xFE0: return 0x90;
|
||||
case 0xFE4: return 0xB4;
|
||||
case 0xFEC: return 0x00;
|
||||
case 0xFF0: return 0x0D;
|
||||
case 0xFF4: return 0xF0;
|
||||
case 0xFF8: return 0x05;
|
||||
case 0xFFC: return 0xB1;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gic_dist_write(uint32_t off, unsigned size, uint32_t val) {
|
||||
g_dirty = true;
|
||||
if (off >= 0x400 && off < 0x400 + GIC_NR_IRQS) {
|
||||
bytes_write(g.prio, off - 0x400, size, val, 0xF8); // 5 priority bits
|
||||
return;
|
||||
}
|
||||
if (off >= 0x800 && off < 0x800 + GIC_NR_IRQS) {
|
||||
uint32_t i = off - 0x800;
|
||||
if (i >= 32)
|
||||
bytes_write(g.target, i, size, val, 0xFF);
|
||||
return;
|
||||
}
|
||||
if (off >= 0xC00 && off < 0xC00 + GIC_NR_IRQS / 4) {
|
||||
uint32_t base = (off - 0xC00) * 4;
|
||||
for (int i = 0; i < 16; i++)
|
||||
if (base + i >= 16) // SGI configuration is read-only
|
||||
g.cfg[base + i] = (uint8_t)((val >> (2 * i)) & 3);
|
||||
return;
|
||||
}
|
||||
uint32_t w = (off & 0x7F) >> 2;
|
||||
bool inrange = w < GIC_NR_IRQS / 32;
|
||||
switch (off & ~0x7Fu) {
|
||||
case 0x080: if (inrange) g.group[w] = val; return;
|
||||
case 0x100:
|
||||
if (inrange) for (int b = 0; b < 32; b++) if (val & (1u << b)) g.enabled[w * 32 + b] = true;
|
||||
return;
|
||||
case 0x180:
|
||||
if (inrange) for (int b = 0; b < 32; b++)
|
||||
if ((val & (1u << b)) && w * 32 + b >= 16) g.enabled[w * 32 + b] = false;
|
||||
return;
|
||||
case 0x200:
|
||||
if (inrange) for (int b = 0; b < 32; b++) if (val & (1u << b)) g.latched[w * 32 + b] = true;
|
||||
return;
|
||||
case 0x280:
|
||||
if (inrange) for (int b = 0; b < 32; b++) if (val & (1u << b)) g.latched[w * 32 + b] = false;
|
||||
return;
|
||||
case 0x300:
|
||||
if (inrange) for (int b = 0; b < 32; b++) if (val & (1u << b)) g.active[w * 32 + b] = true;
|
||||
return;
|
||||
case 0x380:
|
||||
if (inrange) for (int b = 0; b < 32; b++) if (val & (1u << b)) g.active[w * 32 + b] = false;
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
switch (off) {
|
||||
case 0x000: g.dctlr = val & 3; return;
|
||||
case 0xF00: { // GICD_SGIR
|
||||
int id = val & 0xF;
|
||||
uint32_t filter = (val >> 24) & 3, targets = (val >> 16) & 0xFF;
|
||||
bool to_me = filter == 2 || (filter == 0 && (targets & 1));
|
||||
if (to_me)
|
||||
g.latched[id] = true;
|
||||
return;
|
||||
}
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t gic_cpu_read(uint32_t off, unsigned size) {
|
||||
(void)size;
|
||||
if (off == 0x0C || off == 0x20)
|
||||
g_dirty = true;
|
||||
switch (off) {
|
||||
case 0x00: return g.cctlr;
|
||||
case 0x04: return g.pmr;
|
||||
case 0x08: return g.bpr;
|
||||
case 0x0C: case 0x20: { // IAR / AIAR: acknowledge
|
||||
if (!(g.dctlr & 3) || !(g.cctlr & 3))
|
||||
return 1023;
|
||||
int id = best();
|
||||
if (id == 1023 || g.prio[id] >= g.pmr || g.prio[id] >= running_prio())
|
||||
return 1023;
|
||||
g.active[id] = true;
|
||||
g.latched[id] = false;
|
||||
if (g.depth < GIC_NR_IRQS)
|
||||
g.stack[g.depth++] = id;
|
||||
return (uint32_t)id; // SGI source CPU field: CPU0, i.e. 0
|
||||
}
|
||||
case 0x14: return (uint32_t)(running_prio() & 0xFF);
|
||||
case 0x18: case 0x28: return (uint32_t)best();
|
||||
case 0x1C: return g.bpr;
|
||||
case 0xFC: return 0x0202143B; // GICC_IIDR, GIC-400
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void gic_cpu_write(uint32_t off, unsigned size, uint32_t val) {
|
||||
(void)size;
|
||||
g_dirty = true;
|
||||
switch (off) {
|
||||
case 0x00: g.cctlr = val & 0x3FF; return;
|
||||
case 0x04: g.pmr = val & 0xF8; return;
|
||||
case 0x08: case 0x1C: g.bpr = val & 7; return;
|
||||
case 0x10: case 0x24: case 0x1000: { // EOIR / AEOIR / DIR
|
||||
int id = (int)(val & 0x3FF);
|
||||
if (id >= GIC_NR_IRQS)
|
||||
return;
|
||||
g.active[id] = false;
|
||||
for (int i = g.depth - 1; i >= 0; i--)
|
||||
if (g.stack[i] == id) {
|
||||
memmove(&g.stack[i], &g.stack[i + 1], (g.depth - i - 1) * sizeof(int));
|
||||
g.depth--;
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
|
||||
void gic_set_spi(int spi, bool level) {
|
||||
int id = 32 + spi;
|
||||
if (spi < 0 || id >= GIC_NR_IRQS)
|
||||
return;
|
||||
if (g.line[id] == level)
|
||||
return;
|
||||
if (level && is_edge(id))
|
||||
g.latched[id] = true; // rising edge of an edge-configured line
|
||||
g.line[id] = level;
|
||||
g_dirty = true;
|
||||
}
|
||||
|
||||
void gic_set_ppi(int id, bool level) {
|
||||
if (id < 16 || id >= 32 || g.line[id] == level)
|
||||
return;
|
||||
g.line[id] = level;
|
||||
g_dirty = true;
|
||||
}
|
||||
|
||||
bool gic_irq_pending() {
|
||||
best();
|
||||
return g_line_up;
|
||||
}
|
||||
|
||||
int gic_highest_pending() { return best(); }
|
||||
|
||||
void gic_describe(int id, char *buf, unsigned n) {
|
||||
if (id < 0 || id >= GIC_NR_IRQS) {
|
||||
snprintf(buf, n, "?");
|
||||
return;
|
||||
}
|
||||
snprintf(buf, n, "dctlr %u cctlr %u pmr %02X id%d en %d line %d latch %d act %d prio %02X depth %d",
|
||||
g.dctlr, g.cctlr, g.pmr, id, g.enabled[id], g.line[id], g.latched[id],
|
||||
g.active[id], g.prio[id], g.depth);
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#ifndef T210_GIC_H
|
||||
#define T210_GIC_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
/*
|
||||
* GIC-400 - the interrupt controller in front of the CCPLEX (Tegra X1 TRM
|
||||
* ch.3; ARM IHI 0048B, GICv2). Distributor at 0x50041000, CPU interface at
|
||||
* 0x50042000 (8 KiB: GICC_DIR is at +0x1000).
|
||||
*
|
||||
* One CPU interface is modelled: CPU0 is the only core the emulator runs.
|
||||
* Security is not: both groups behave as one, which is all a kernel booted
|
||||
* non-secure ever sees. Peripherals drive level lines (gic_set_spi); SGIs
|
||||
* and edge-configured interrupts latch.
|
||||
*/
|
||||
|
||||
constexpr uint64_t GICD_BASE = 0x50041000;
|
||||
constexpr uint64_t GICD_SIZE = 0x1000;
|
||||
constexpr uint64_t GICC_BASE = 0x50042000;
|
||||
constexpr uint64_t GICC_SIZE = 0x2000;
|
||||
|
||||
constexpr int GIC_NR_IRQS = 256; // 32 private + 224 SPIs (ITLinesNumber 7)
|
||||
constexpr int GIC_PPI_VTIMER = 27; // EL1 virtual timer
|
||||
constexpr int GIC_PPI_PTIMER = 30; // EL1 physical (non-secure) timer
|
||||
|
||||
void gic_reset();
|
||||
uint32_t gic_dist_read(uint32_t off, unsigned size);
|
||||
void gic_dist_write(uint32_t off, unsigned size, uint32_t val);
|
||||
uint32_t gic_cpu_read(uint32_t off, unsigned size);
|
||||
void gic_cpu_write(uint32_t off, unsigned size, uint32_t val);
|
||||
|
||||
// A peripheral's interrupt line. `spi` is the SPI number as device trees
|
||||
// write it (<GIC_SPI n ...>); the interrupt ID is 32 + n.
|
||||
void gic_set_spi(int spi, bool level);
|
||||
// A private peripheral interrupt line (ID 16..31) of CPU0.
|
||||
void gic_set_ppi(int id, bool level);
|
||||
|
||||
// CPU0's nIRQ: something enabled, pending, not active and above the
|
||||
// priority mask and the running priority.
|
||||
bool gic_irq_pending();
|
||||
|
||||
// For the log: the interrupt ID that IRQ would deliver, or 1023.
|
||||
int gic_highest_pending();
|
||||
|
||||
// One line of the distributor and CPU interface state for interrupt `id`.
|
||||
void gic_describe(int id, char *buf, unsigned n);
|
||||
|
||||
#endif // T210_GIC_H
|
||||
+36
-2
@@ -8,6 +8,7 @@
|
||||
#include "bpmp.h"
|
||||
#include "ccplex.h"
|
||||
#include "pcie.h"
|
||||
#include "gic.h"
|
||||
#include "usb.h"
|
||||
#include "regcache.h"
|
||||
#include "se_engine.h"
|
||||
@@ -3198,6 +3199,8 @@ static constexpr uint32_t TMR_EN = 1u << 31, TMR_PER = 1u << 30;
|
||||
|
||||
static void tmr_write(EmuState *state, uint64_t addr, uint32_t val) {
|
||||
uint32_t off = (uint32_t)(addr - TMR_BASE);
|
||||
if (off >= 0x90 && off < 0xB0) // TMR10..13: CPU clock event timers
|
||||
ccplex_tmr_write(off, val);
|
||||
for (int t = 0; t < 10; t++)
|
||||
if (off == kTmrPtv[t] && (val & TMR_EN))
|
||||
tmr_armed_us[t] = state->emu_usec;
|
||||
@@ -3391,6 +3394,19 @@ static const CarBank *car_bank_of(uint32_t off) {
|
||||
// The EMC clock as CAR sets it (EMC section below).
|
||||
static uint32_t emc_rate_khz();
|
||||
|
||||
#include "car_reset.h"
|
||||
static uint32_t car_trm_reset(uint32_t off) {
|
||||
static uint32_t table[0x800 / 4];
|
||||
static bool built = false;
|
||||
if (!built) {
|
||||
for (const CarReset &r : kCarReset)
|
||||
if (r.off < 0x800)
|
||||
table[r.off / 4] = r.val;
|
||||
built = true;
|
||||
}
|
||||
return off < 0x800 ? table[off / 4] : 0;
|
||||
}
|
||||
|
||||
uint32_t clk_rst_read(EmuState *state, uint64_t addr) {
|
||||
uint32_t offset = (uint32_t)(addr - CLK_RST_BASE);
|
||||
if (const CarBank *b = car_bank_of(offset)) {
|
||||
@@ -3582,8 +3598,11 @@ uint32_t clk_rst_read(EmuState *state, uint64_t addr) {
|
||||
return v;
|
||||
}
|
||||
// Everything else is a plain R/W register (the CLK_SOURCE_* dividers,
|
||||
// PLL MISC words, ...): it reads back what was written.
|
||||
return mmio_regs.get(addr);
|
||||
// PLL MISC words, ...): it reads back what was written, and its TRM reset
|
||||
// value until then (car_reset.h). A kernel's clock driver reads hundreds
|
||||
// of these to find each clock's parent; 0 is a reset value the hardware
|
||||
// never has for many (a super clock's burst policy BUG()s in STANDBY).
|
||||
return mmio_regs.get(addr, car_trm_reset(offset));
|
||||
}
|
||||
|
||||
// A CLK_SOURCE_EMC write is the CAR/EMC clock-change handshake (EMC below).
|
||||
@@ -4702,6 +4721,10 @@ uint32_t mmio_bus_read(EmuState *state, uint64_t address, unsigned size) {
|
||||
return sysreg_read(state, address);
|
||||
if (address >= BPMP_CACHE_BASE && address < BPMP_CACHE_BASE + BPMP_CACHE_SIZE)
|
||||
return bpmp_cache_read(state, address);
|
||||
if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE)
|
||||
return gic_dist_read((uint32_t)(address - GICD_BASE), size);
|
||||
if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE)
|
||||
return gic_cpu_read((uint32_t)(address - GICC_BASE), size);
|
||||
if (address >= SOC_THERM_BASE && address < SOC_THERM_BASE + SOC_THERM_SIZE)
|
||||
return soc_therm_read(state, address);
|
||||
if (address >= FLOW_CTLR_BASE && address < FLOW_CTLR_BASE + FLOW_CTLR_SIZE)
|
||||
@@ -4873,6 +4896,10 @@ void mmio_bus_write(EmuState *state, uint64_t address, unsigned size,
|
||||
} else if (address >= BPMP_CACHE_BASE &&
|
||||
address < BPMP_CACHE_BASE + BPMP_CACHE_SIZE) {
|
||||
bpmp_cache_write(state, address, val);
|
||||
} else if (address >= GICD_BASE && address < GICD_BASE + GICD_SIZE) {
|
||||
gic_dist_write((uint32_t)(address - GICD_BASE), size, val);
|
||||
} else if (address >= GICC_BASE && address < GICC_BASE + GICC_SIZE) {
|
||||
gic_cpu_write((uint32_t)(address - GICC_BASE), size, val);
|
||||
} else if (address >= SOC_THERM_BASE &&
|
||||
address < SOC_THERM_BASE + SOC_THERM_SIZE) {
|
||||
soc_therm_write(state, address, val);
|
||||
@@ -5030,6 +5057,8 @@ const struct {
|
||||
{USB_OTG_BASE, USB_OTG_SIZE},
|
||||
{XUSB_DEV_BASE, XUSB_DEV_SIZE},
|
||||
{MSELECT_BASE, MSELECT_SIZE},
|
||||
// GIC-400 distributor, CPU interface and the virtualisation pages.
|
||||
{GICD_BASE, 0x7000},
|
||||
// PCIe. T210 puts the root complex at the BOTTOM of the address map,
|
||||
// below every other peripheral.
|
||||
{PCIE_BLOCK_BASE, PCIE_BLOCK_SIZE},
|
||||
@@ -5100,6 +5129,10 @@ void mmio_map_bus(uc_engine *uc, EmuState *state) {
|
||||
uc_mem_map_ptr(uc, TZRAM_BASE, TZRAM_SIZE, UC_PROT_ALL, g_tzram);
|
||||
}
|
||||
|
||||
bool mmio_map_page(uc_engine *uc, EmuState *state, uint64_t page) {
|
||||
return map_window(uc, state, page & ~0xFFFULL, 0x1000) == UC_ERR_OK;
|
||||
}
|
||||
|
||||
void mmio_unmap_bus(uc_engine *uc) {
|
||||
g_windows.erase(std::remove_if(g_windows.begin(), g_windows.end(),
|
||||
[uc](const std::unique_ptr<MmioWindow> &w) {
|
||||
@@ -5114,6 +5147,7 @@ void mmio_init(uc_engine *uc, EmuState *state) {
|
||||
mmio_map_bus(uc, state);
|
||||
pcie_reset(state);
|
||||
ccplex_reset(state);
|
||||
gic_reset();
|
||||
sdhci_reset_regs(sdhci_regs[0]);
|
||||
sdhci_reset_regs(sdhci_regs[1]);
|
||||
dc_reset(state);
|
||||
|
||||
@@ -36,6 +36,9 @@ void mmio_init(uc_engine *uc, EmuState *state);
|
||||
void mmio_map_bus(uc_engine *uc, EmuState *state);
|
||||
// Forget the windows mapped into `uc`, before that engine is closed.
|
||||
void mmio_unmap_bus(uc_engine *uc);
|
||||
// Map one 4 KiB page of the peripheral band as a register window (CPU0's
|
||||
// first access to a block the emulator does not model).
|
||||
bool mmio_map_page(uc_engine *uc, EmuState *state, uint64_t page);
|
||||
|
||||
// The shared dispatch both engines' MMIO callbacks funnel into. `size` is the
|
||||
// access width in bytes (1, 2 or 4).
|
||||
|
||||
Reference in new issue
Block a user