mirror of
https://github.com/ps5-linux/ps5-linux-loader.git
synced 2026-07-16 01:50:40 +00:00
remove data_cave offset and use page alloc for sc args
This commit is contained in:
@@ -19,59 +19,6 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define MINI_SYSCORE_PID 1
|
||||
|
||||
uint64_t alloc_page(void) {
|
||||
void *page = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
||||
|
||||
// Fault it to force physical allocation
|
||||
*(uint8_t *)page = 0;
|
||||
|
||||
return vtophys_user((uintptr_t)page);
|
||||
}
|
||||
|
||||
void install_page(uintptr_t pml4, vm_offset_t va, vm_paddr_t pa, int bits) {
|
||||
uint64_t entry;
|
||||
|
||||
uintptr_t pml4e = pml4 + pmap_pml4e_index(va) * 8;
|
||||
entry = kread64(pml4e);
|
||||
if (!PAGE_P(entry)) {
|
||||
uint64_t page = alloc_page();
|
||||
entry = page | PG_B_RW | PG_B_P | bits;
|
||||
kwrite64(pml4e, entry);
|
||||
}
|
||||
|
||||
uintptr_t pdpe = pa_to_dmap(PAGE_PA(entry)) + pmap_pdpe_index(va) * 8;
|
||||
entry = kread64(pdpe);
|
||||
if (!(entry & PG_B_P)) {
|
||||
uint64_t page = alloc_page();
|
||||
entry = page | PG_B_RW | PG_B_P | bits;
|
||||
kwrite64(pdpe, entry);
|
||||
}
|
||||
|
||||
uintptr_t pde = pa_to_dmap(PAGE_PA(entry)) + pmap_pde_index(va) * 8;
|
||||
entry = kread64(pde);
|
||||
if (!(entry & PG_B_P)) {
|
||||
uint64_t page = alloc_page();
|
||||
entry = page | PG_B_RW | PG_B_P | bits;
|
||||
kwrite64(pde, entry);
|
||||
}
|
||||
|
||||
uintptr_t pte = pa_to_dmap(PAGE_PA(entry)) + pmap_pte_index(va) * 8;
|
||||
entry = pa | PG_B_RW | PG_B_P | bits;
|
||||
pte_store(pte, entry);
|
||||
}
|
||||
|
||||
void pte_store(uintptr_t ptep, uint64_t pte) {
|
||||
static_assert((PAGE_SIZE % 0x1000) == 0,
|
||||
"PAGE_SIZE should be a multiple of 0x1000");
|
||||
|
||||
for (uint64_t i = 0; i < (PAGE_SIZE / 0x1000); i++) {
|
||||
kwrite64(ptep + i * 8, pte + i * 0x1000);
|
||||
}
|
||||
}
|
||||
|
||||
const char *file_paths[] = {
|
||||
"/mnt/usb0/", "/mnt/usb1/", "/mnt/usb2/",
|
||||
"/mnt/usb3/", "/mnt/usb0/PS5/Linux/", "/mnt/usb1/PS5/Linux/",
|
||||
@@ -179,9 +126,6 @@ void trim_newline(char *s) {
|
||||
}
|
||||
|
||||
int fetch_linux(struct linux_info *info) {
|
||||
uintptr_t syscore_pmap = getpmap(kernel_get_proc(MINI_SYSCORE_PID));
|
||||
uintptr_t syscore_pml4 = kread64(syscore_pmap + 0x20);
|
||||
|
||||
char bzimage_path[256];
|
||||
char initrd_path[256];
|
||||
|
||||
@@ -269,16 +213,16 @@ int fetch_linux(struct linux_info *info) {
|
||||
|
||||
uint64_t page = alloc_page();
|
||||
kwrite(pa_to_dmap(page), info, sizeof(struct linux_info));
|
||||
install_page(syscore_pml4, kernel_cave_linux_info, page, 0);
|
||||
install_page_syscore(kernel_cave_linux_info, page, 0);
|
||||
|
||||
for (int i = 0; i < bzimage_size; i += PAGE_SIZE) {
|
||||
install_page(syscore_pml4, info->bzimage + i,
|
||||
vtophys_user((uintptr_t)bzimage + i), 0);
|
||||
install_page_syscore(info->bzimage + i,
|
||||
vtophys_user((uintptr_t)bzimage + i), 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < initrd_size; i += PAGE_SIZE) {
|
||||
install_page(syscore_pml4, info->initrd + i,
|
||||
vtophys_user((uintptr_t)initrd + i), 0);
|
||||
install_page_syscore(info->initrd + i, vtophys_user((uintptr_t)initrd + i),
|
||||
0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user