mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-02 10:59:15 +00:00
kernel: add aarch64 architecture support
Signed-off-by: EnderIce2 <enderice2@protonmail.com>
This commit is contained in:
@ -163,8 +163,6 @@ namespace CPU
|
||||
"jmp CPUStopLoop");
|
||||
#elif defined(__aarch64__)
|
||||
asmv("CPUStopLoop:\n"
|
||||
"cpsid i\n"
|
||||
"wfe\n"
|
||||
"wfi\n"
|
||||
"b CPUStopLoop");
|
||||
#endif
|
||||
@ -1078,44 +1076,32 @@ namespace CPU
|
||||
{
|
||||
struct TrapFrame
|
||||
{
|
||||
uint64_t x0; // General purpose
|
||||
uint64_t x1; // General purpose
|
||||
uint64_t x2; // General purpose
|
||||
uint64_t x3; // General purpose
|
||||
uint64_t x4; // General purpose
|
||||
uint64_t x5; // General purpose
|
||||
uint64_t x6; // General purpose
|
||||
uint64_t x7; // General purpose
|
||||
uint64_t x8; // General purpose
|
||||
uint64_t x9; // General purpose
|
||||
uint64_t x10; // General purpose
|
||||
uint64_t x11; // General purpose
|
||||
uint64_t x12; // General purpose
|
||||
uint64_t x13; // General purpose
|
||||
uint64_t x14; // General purpose
|
||||
uint64_t x15; // General purpose
|
||||
uint64_t x16; // General purpose
|
||||
uint64_t x17; // General purpose
|
||||
uint64_t x18; // General purpose
|
||||
uint64_t x19; // General purpose
|
||||
uint64_t x20; // General purpose
|
||||
uint64_t x21; // General purpose
|
||||
uint64_t x22; // General purpose
|
||||
uint64_t x23; // General purpose
|
||||
uint64_t x24; // General purpose
|
||||
uint64_t x25; // General purpose
|
||||
uint64_t x26; // General purpose
|
||||
uint64_t x27; // General purpose
|
||||
uint64_t x28; // General purpose
|
||||
uint64_t x[31];
|
||||
uint64_t SP; /* Stack Pointer */
|
||||
uint64_t ELR; /* Exception Link Register */
|
||||
uint64_t ESR; /* Exception Syndrome Register */
|
||||
uint64_t FAR; /* Fault Address Register */
|
||||
uint64_t SPSR; /* Saved Program Status Register */
|
||||
};
|
||||
|
||||
uint64_t fp; // Frame Pointer (meant for stack frames)
|
||||
uint64_t lr; // Link Register
|
||||
struct SchedulerFrame
|
||||
{
|
||||
uint64_t x[31];
|
||||
uint64_t SP; /* Stack Pointer */
|
||||
uint64_t ELR; /* Exception Link Register */
|
||||
uint64_t ESR; /* Exception Syndrome Register */
|
||||
uint64_t FAR; /* Fault Address Register */
|
||||
uint64_t SPSR; /* Saved Program Status Register */
|
||||
};
|
||||
|
||||
uint64_t sp; // Stack Pointer
|
||||
uint64_t pc; // Program Counter
|
||||
uint64_t pstate; // Processor State (flags)
|
||||
uint64_t esr; // Exception Syndrome Register
|
||||
uint64_t far; // Fault Address Register
|
||||
struct ExceptionFrame
|
||||
{
|
||||
uint64_t x[31];
|
||||
uint64_t SP; /* Stack Pointer */
|
||||
uint64_t ELR; /* Exception Link Register */
|
||||
uint64_t ESR; /* Exception Syndrome Register */
|
||||
uint64_t FAR; /* Fault Address Register */
|
||||
uint64_t SPSR; /* Saved Program Status Register */
|
||||
};
|
||||
}
|
||||
|
||||
@ -1145,7 +1131,7 @@ namespace CPU
|
||||
*/
|
||||
typedef aarch64::TrapFrame TrapFrame;
|
||||
typedef aarch64::SchedulerFrame SchedulerFrame;
|
||||
typedef aarch64::TrapFrame ExceptionFrame;
|
||||
typedef aarch64::ExceptionFrame ExceptionFrame;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -55,13 +55,11 @@ typedef uint64_t cpuid_t;
|
||||
#define __amd_cpuid_init(leaf) \
|
||||
CPUID##leaf() \
|
||||
{ \
|
||||
assert(!"cpuid not implemented for this architecture"); \
|
||||
}
|
||||
|
||||
#define __amd_cpuid_init2(leaf, leaf2, suffix) \
|
||||
CPUID##leaf##suffix() \
|
||||
{ \
|
||||
assert(!"cpuid not implemented for this architecture"); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -55,13 +55,11 @@ typedef uint64_t cpuid_t;
|
||||
#define __intel_cpuid_init(leaf) \
|
||||
CPUID##leaf() \
|
||||
{ \
|
||||
assert(!"cpuid not implemented for this architecture"); \
|
||||
}
|
||||
|
||||
#define __intel_cpuid_init2(leaf, leaf2, suffix) \
|
||||
CPUID##leaf##suffix() \
|
||||
{ \
|
||||
assert(!"cpuid not implemented for this architecture"); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -40,6 +40,15 @@ static inline scarg syscall0(scarg syscall)
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0");
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(x0)
|
||||
: "r"(x8)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -65,6 +74,15 @@ static inline scarg syscall1(scarg syscall, scarg arg1)
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -91,6 +109,16 @@ static inline scarg syscall2(scarg syscall, scarg arg1, scarg arg2)
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
register long x1 __asm__("x1") = arg2;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0), "r"(x1)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -118,6 +146,17 @@ static inline scarg syscall3(scarg syscall, scarg arg1, scarg arg2, scarg arg3)
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
register long x1 __asm__("x1") = arg2;
|
||||
register long x2 __asm__("x2") = arg3;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0), "r"(x1), "r"(x2)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -147,6 +186,18 @@ static inline scarg syscall4(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
register long x1 __asm__("x1") = arg2;
|
||||
register long x2 __asm__("x2") = arg3;
|
||||
register long x3 __asm__("x3") = arg4;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -178,6 +229,19 @@ static inline scarg syscall5(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
register long x1 __asm__("x1") = arg2;
|
||||
register long x2 __asm__("x2") = arg3;
|
||||
register long x3 __asm__("x3") = arg4;
|
||||
register long x4 __asm__("x4") = arg5;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
@ -211,6 +275,20 @@ static inline scarg syscall6(scarg syscall, scarg arg1, scarg arg2, scarg arg3,
|
||||
: "rcx", "r11", "memory");
|
||||
#elif defined(__i386__)
|
||||
#warning "i386 syscall wrapper not implemented"
|
||||
#elif defined(__arm__)
|
||||
#warning "arm syscall wrapper not implemented"
|
||||
#elif defined(__aarch64__)
|
||||
register long x8 __asm__("x8") = syscall;
|
||||
register long x0 __asm__("x0") = arg1;
|
||||
register long x1 __asm__("x1") = arg2;
|
||||
register long x2 __asm__("x2") = arg3;
|
||||
register long x3 __asm__("x3") = arg4;
|
||||
register long x4 __asm__("x4") = arg5;
|
||||
register long x5 __asm__("x5") = arg6;
|
||||
__asm__ __volatile__("svc 0"
|
||||
: "=r"(ret)
|
||||
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
|
||||
: "memory", "cc");
|
||||
#else
|
||||
#error "Unsupported architecture"
|
||||
#endif
|
||||
|
@ -60,8 +60,13 @@ typedef struct SyscallsFrame
|
||||
uint32_t StackPointer;
|
||||
uint32_t StackSegment;
|
||||
#elif defined(__aarch64__)
|
||||
uint32_t ReturnAddress;
|
||||
uint32_t StackPointer;
|
||||
uint64_t ReturnAddress; /* x0 */
|
||||
uint64_t x[30];
|
||||
uint64_t StackPointer;
|
||||
uint64_t ExceptionLinkRegister;
|
||||
uint64_t ExceptionSyndromeRegister;
|
||||
uint64_t FaultAddressRegister;
|
||||
uint64_t SavedProgramStatusRegister;
|
||||
#endif
|
||||
|
||||
uintptr_t ReturnValue() const
|
||||
@ -71,7 +76,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return ax;
|
||||
#elif defined(__aarch64__)
|
||||
return x0;
|
||||
return x[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -82,7 +87,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return di;
|
||||
#elif defined(__aarch64__)
|
||||
return x0;
|
||||
return x[0];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -93,7 +98,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return cx;
|
||||
#elif defined(__aarch64__)
|
||||
return x1;
|
||||
return x[1];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -104,7 +109,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return dx;
|
||||
#elif defined(__aarch64__)
|
||||
return x2;
|
||||
return x[2];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -115,7 +120,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return si;
|
||||
#elif defined(__aarch64__)
|
||||
return x3;
|
||||
return x[3];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -126,7 +131,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return di;
|
||||
#elif defined(__aarch64__)
|
||||
return x4;
|
||||
return x[4];
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -137,7 +142,7 @@ typedef struct SyscallsFrame
|
||||
#elif defined(__i386__)
|
||||
return bp;
|
||||
#elif defined(__aarch64__)
|
||||
return x5;
|
||||
return x[5];
|
||||
#endif
|
||||
}
|
||||
} SyscallsFrame;
|
||||
|
@ -358,12 +358,13 @@ namespace Tasking
|
||||
CPU::SchedulerFrame Registers{};
|
||||
#if defined(__amd64__)
|
||||
uintptr_t ShadowGSBase, GSBase, FSBase;
|
||||
__aligned(16) CPU::x64::FXState FPU;
|
||||
#elif defined(__i386__)
|
||||
uintptr_t ShadowGSBase, GSBase, FSBase;
|
||||
#elif defined(__aarch64__)
|
||||
uintptr_t Registers; // TODO
|
||||
#endif
|
||||
__aligned(16) CPU::x64::FXState FPU;
|
||||
#elif defined(__aarch64__)
|
||||
uintptr_t __todo; // TODO
|
||||
#endif
|
||||
|
||||
/* Info & Security info */
|
||||
struct
|
||||
|
Reference in New Issue
Block a user