From 7a58386b98636bb75eb0a530741b5447ae72ec1e Mon Sep 17 00:00:00 2001 From: Mateico <116546494+mateicoes@users.noreply.github.com> Date: Fri, 8 May 2026 15:26:27 +0200 Subject: [PATCH] devkit ram support --- include/utils.h | 14 +++++++++++++ shellcode_hypervisor/boot_linux.c | 15 +++++++++++--- shellcode_hypervisor/boot_linux.h | 6 ++++++ shellcode_kernel/kernel_code.c | 1 + source/loader.c | 1 + source/offsets.c | 34 +++++++++++++++---------------- source/utils.c | 29 ++++++++++++++++++++++++++ 7 files changed, 80 insertions(+), 20 deletions(-) diff --git a/include/utils.h b/include/utils.h index e6a3f3c..cb71235 100644 --- a/include/utils.h +++ b/include/utils.h @@ -42,6 +42,7 @@ struct linux_info { size_t initrd_size; size_t vram_size; char cmdline[2048]; + int kit_type; uintptr_t linux_info; // PA of linux_info }; @@ -156,4 +157,17 @@ void enter_rest_mode(void); #define DEBUG_PRINT(fmt, ...) #endif + +bool if_exists(const char* path); +bool sceKernelIsTestKit(void); +bool sceKernelIsDevKit(void); + +enum kit_type { + KIT_RETAIL, + KIT_TESTKIT, + KIT_DEVKIT +}; + +enum kit_type get_kit_type(void); + #endif diff --git a/shellcode_hypervisor/boot_linux.c b/shellcode_hypervisor/boot_linux.c index 78537aa..6050400 100644 --- a/shellcode_hypervisor/boot_linux.c +++ b/shellcode_hypervisor/boot_linux.c @@ -12,6 +12,7 @@ struct linux_info { size_t initrd_size; size_t vram_size; char cmdline[2048]; + int kit_type; }; static struct linux_info info; @@ -88,8 +89,16 @@ static void e820_memory_setup(struct boot_params *bp) { append_e820_table(bp, 0x0f0000000, 0x0f8000000, E820_TYPE_RESERVED); append_e820_table(bp, 0x100000000, VRAM_BASE, E820_TYPE_RAM); append_e820_table(bp, VRAM_BASE, 0x470000000, E820_TYPE_RESERVED); // VRAM - append_e820_table(bp, 0x470000000, 0x47f300000, E820_TYPE_RAM); - append_e820_table(bp, 0x47f300000, 0x480000000, E820_TYPE_RESERVED); + + // DevKits have 32GB + if (info.kit_type != KIT_DEVKIT) { + append_e820_table(bp, 0x470000000, 0x47f300000, E820_TYPE_RAM); + append_e820_table(bp, 0x47f300000, 0x480000000, E820_TYPE_RESERVED); + } + else { + append_e820_table(bp, 0x470000000, 0x87f300000, E820_TYPE_RAM); + append_e820_table(bp, 0x87f300000, 0x880000000, E820_TYPE_RESERVED); + } } void boot_linux(void) { @@ -124,7 +133,7 @@ void boot_linux(void) { memcpy((void *)kernel_pa, (void *)(info.bzimage + setup_size), kernel_size); - // printf("This is kernel_pa: "); print_val64(kernel_pa); printf("\n"); + void (*startup_64)(uint64_t physaddr, struct boot_params *bp) = (void *)(kernel_pa + 0x200); startup_64(kernel_pa, bp); diff --git a/shellcode_hypervisor/boot_linux.h b/shellcode_hypervisor/boot_linux.h index 452a36b..a98a65b 100644 --- a/shellcode_hypervisor/boot_linux.h +++ b/shellcode_hypervisor/boot_linux.h @@ -44,3 +44,9 @@ void entry(void); void boot_linux(void); + +enum kit_type { + KIT_RETAIL, + KIT_TESTKIT, + KIT_DEVKIT +}; \ No newline at end of file diff --git a/shellcode_kernel/kernel_code.c b/shellcode_kernel/kernel_code.c index 1c0b145..0920ef3 100644 --- a/shellcode_kernel/kernel_code.c +++ b/shellcode_kernel/kernel_code.c @@ -46,6 +46,7 @@ struct linux_info { size_t initrd_size; size_t vram_size; char cmdline[2048]; + int kit_type; }; static struct linux_info info; diff --git a/source/loader.c b/source/loader.c index cff9de2..563f9cf 100644 --- a/source/loader.c +++ b/source/loader.c @@ -220,6 +220,7 @@ int fetch_linux(struct linux_info *info) { info->initrd_size = initrd_size; info->vram_size = vram_size; strcpy(info->cmdline, cmdline); + info->kit_type = (int) get_kit_type(); uint64_t page = alloc_page(); kwrite(pa_to_dmap(page), info, sizeof(struct linux_info)); diff --git a/source/offsets.c b/source/offsets.c index 3434c99..bf93bfc 100644 --- a/source/offsets.c +++ b/source/offsets.c @@ -5,8 +5,8 @@ offset_list off_0300 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33175E0, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -37,8 +37,8 @@ offset_list off_0310 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33175E0, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -69,8 +69,8 @@ offset_list off_0320 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33175E0, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -101,8 +101,8 @@ offset_list off_0321 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33175E0, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -133,8 +133,8 @@ offset_list off_0400 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33C7680, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -165,8 +165,8 @@ offset_list off_0402 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33C7680, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -198,7 +198,7 @@ offset_list off_0403 = { .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, .KERNEL_CODE_CAVE = 0x500, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33C7680, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -229,8 +229,8 @@ offset_list off_0450 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33C7680, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, @@ -261,8 +261,8 @@ offset_list off_0451 = { .HV_VCPU_ARRAY_OFF = 0x5D0, .HV_VCPU_STRIDE = 0x320, .HV_VCPU_VMCB_PTR = 0x08, - .KERNEL_CODE_CAVE = 0x0043000, - .KERNEL_DATA_CAVE = 0x0043000 + 0xBBE300, + .KERNEL_CODE_CAVE = 0x500, + .KERNEL_DATA_CAVE = 0xC01300, .IOMMU_SOFTC = 0x33C7680, .VMSPACE_VM_VMID = 0x1E4, .VMSPACE_VM_PMAP = 0x1D0, diff --git a/source/utils.c b/source/utils.c index 8646bdc..1ea26d5 100644 --- a/source/utils.c +++ b/source/utils.c @@ -6,6 +6,7 @@ #include #include #include +#include /* Global Variables */ offset_list env_offset; @@ -247,4 +248,32 @@ void enter_rest_mode(void) { sceKernelNotifySystemSuspendStart(); sceKernelSetEventFlag(event, 0x400); sceKernelCloseEventFlag(&event); +} + + +// Kit type by EchoStretch +bool if_exists(const char* path) { + struct stat st; + return stat(path, &st) == 0; +} + +bool sceKernelIsTestKit(void) { + return if_exists("/system/priv/lib/libSceDeci5Ttyp.sprx"); +} + +bool sceKernelIsDevKit(void) { + return if_exists("/system/priv/lib/libSceDeci5Dtracep.sprx"); +} + +enum kit_type get_kit_type(void) { + if (sceKernelIsDevKit()) { + notify("DevKit detected\n"); + return KIT_DEVKIT; + } + if (sceKernelIsTestKit()) { + notify("TestKit detected\n"); + return KIT_TESTKIT; + } + notify("Retail console detected\n"); + return KIT_RETAIL; } \ No newline at end of file