mirror of
https://github.com/ps5-linux/ps5-linux-loader.git
synced 2026-05-09 08:28:27 +00:00
initial commit support 3.xx and 4.xx
This commit is contained in:
37
shellcode_hypervisor/main.c
Normal file
37
shellcode_hypervisor/main.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "main.h"
|
||||
#include "../include/config.h"
|
||||
#include "boot_linux.h"
|
||||
#include "utils.h"
|
||||
#include <cpuid.h>
|
||||
#include <machine/atomic.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
__attribute__((section(".entry_point"), naked)) uint32_t main(void) {
|
||||
|
||||
// We enter this function after CR3 was updated to 1:1 mapping
|
||||
// We need to point RSP/RBP to a good known valid address
|
||||
uint32_t ebax, ebx, ecx, edx;
|
||||
uint32_t cpu_id;
|
||||
|
||||
__asm__ volatile("cpuid"
|
||||
: "=a"(ebax), "=b"(ebx), "=c"(ecx), "=d"(edx)
|
||||
: "a"(1));
|
||||
|
||||
cpu_id = (ebx >> 24) & 0xFF;
|
||||
|
||||
// We point to a location after the main linux boot code
|
||||
// Each CPU should have a different location
|
||||
uintptr_t new_rsp =
|
||||
(uintptr_t)hv_base_rsp + ((uint64_t)(cpu_id)*hv_stack_size);
|
||||
|
||||
// WARNING: This invalidates current local variables
|
||||
__asm__ volatile("movq %0, %%rsp \n\t"
|
||||
"movq %%rsp, %%rbp \n\t"
|
||||
:
|
||||
: "r"(new_rsp)
|
||||
: "rsp", "rbp", "memory");
|
||||
|
||||
entry();
|
||||
}
|
||||
Reference in New Issue
Block a user