fix clang18; Wextra; lots of stuff
This commit is contained in:
parent
f92a26f9f7
commit
db457ba1ba
14
SConstruct
14
SConstruct
@ -26,7 +26,7 @@ opts.AddVariables(
|
|||||||
)
|
)
|
||||||
|
|
||||||
env = Environment(options = opts,
|
env = Environment(options = opts,
|
||||||
tools = ['default', 'compilation_db'],
|
tools = ['default', 'compilation_db', 'clang'],
|
||||||
ENV = os.environ)
|
ENV = os.environ)
|
||||||
Help(opts.GenerateHelpText(env))
|
Help(opts.GenerateHelpText(env))
|
||||||
|
|
||||||
@ -75,14 +75,14 @@ if env["WITH_GPROF"] == "1":
|
|||||||
|
|
||||||
env.Append(CPPFLAGS = "-DBUILDTYPE=" + env["BUILDTYPE"])
|
env.Append(CPPFLAGS = "-DBUILDTYPE=" + env["BUILDTYPE"])
|
||||||
if env["BUILDTYPE"] == "DEBUG":
|
if env["BUILDTYPE"] == "DEBUG":
|
||||||
env.Append(CPPFLAGS = [ "-g", "-DDEBUG", "-Wall", "-O2",
|
env.Append(CPPFLAGS = [ "-g", "-DDEBUG", "-Wall", "-Wextra", "-Werror", "-O2",
|
||||||
"-Wno-deprecated-declarations" ])
|
"-Wno-deprecated-declarations", "-Wno-unused-parameter" ])
|
||||||
env.Append(LINKFLAGS = [ "-g" ])
|
env.Append(LINKFLAGS = [ "-g" ])
|
||||||
elif env["BUILDTYPE"] == "PERF":
|
elif env["BUILDTYPE"] == "PERF":
|
||||||
env.Append(CPPFLAGS = [ "-g", "-DNDEBUG", "-Wall", "-O2"])
|
env.Append(CPPFLAGS = [ "-g", "-DNDEBUG", "-Wall", "-Wextra", "-Werror", "-O2", "-Wno-unused-parameter"])
|
||||||
env.Append(LDFLAGS = [ "-g" ])
|
env.Append(LDFLAGS = [ "-g" ])
|
||||||
elif env["BUILDTYPE"] == "RELEASE":
|
elif env["BUILDTYPE"] == "RELEASE":
|
||||||
env.Append(CPPFLAGS = ["-DNDEBUG", "-Wall", "-O2"])
|
env.Append(CPPFLAGS = ["-DNDEBUG", "-Wall", "-Wextra", "-Werror", "-O2", "-Wno-unused-parameter"])
|
||||||
else:
|
else:
|
||||||
print("Error BUILDTYPE must be RELEASE or DEBUG")
|
print("Error BUILDTYPE must be RELEASE or DEBUG")
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
@ -150,8 +150,8 @@ if not conf.CheckCC():
|
|||||||
print('Your C compiler and/or environment is incorrectly configured.')
|
print('Your C compiler and/or environment is incorrectly configured.')
|
||||||
CheckFailed()
|
CheckFailed()
|
||||||
|
|
||||||
if not env["CCVERSION"].startswith("15."):
|
if not env["CCVERSION"].startswith("18."):
|
||||||
print('Only Clang 15 is supported')
|
print('Only Clang 18 is supported')
|
||||||
print('You are running: ' + env["CCVERSION"])
|
print('You are running: ' + env["CCVERSION"])
|
||||||
# CheckFailed()
|
# CheckFailed()
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
fputs(ctime(&t), stdout);
|
fputs(ctime(&t), stdout);
|
||||||
|
@ -30,7 +30,7 @@ dumpPacket()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
readPacket(NIC *nic)
|
readPacket(UNUSED NIC *nic)
|
||||||
{
|
{
|
||||||
uint64_t status;
|
uint64_t status;
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ static char buf[4096];
|
|||||||
static MBuf mbuf;
|
static MBuf mbuf;
|
||||||
|
|
||||||
void
|
void
|
||||||
writePacket(NIC *nic)
|
writePacket(UNUSED NIC *nic)
|
||||||
{
|
{
|
||||||
uint64_t status;
|
uint64_t status;
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ writePacket(NIC *nic)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
uint64_t status;
|
uint64_t status;
|
||||||
NIC nic;
|
NIC nic;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
void DispatchCommand(char *buf);
|
void DispatchCommand(char *buf);
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ main(int argc, const char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Cmd_Help(int argc, const char *argv[])
|
Cmd_Help(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
printf("bkpt Trigger a kernel breakpoint\n");
|
printf("bkpt Trigger a kernel breakpoint\n");
|
||||||
printf("exit Exit shell\n");
|
printf("exit Exit shell\n");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ elif (env["ARCH"] == "arm64"):
|
|||||||
src.append(src_arm64)
|
src.append(src_arm64)
|
||||||
src.append(src_common)
|
src.append(src_common)
|
||||||
|
|
||||||
libc_env.Append(CPPFLAGS = ['-nostdinc'])
|
libc_env.Append(CPPFLAGS = ['-nostdinc', "-Wno-sign-compare"])
|
||||||
libc_env.Append(CPPPATH = ['#build/include'])
|
libc_env.Append(CPPPATH = ['#build/include'])
|
||||||
|
|
||||||
libc_env.StaticLibrary("libc", src)
|
libc_env.StaticLibrary("libc", src)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint64_t status;
|
uint64_t status;
|
||||||
|
@ -15,7 +15,9 @@ src.append(src_common)
|
|||||||
src.append(env["CRTEND"])
|
src.append(env["CRTEND"])
|
||||||
|
|
||||||
init_env.Append(LINKFLAGS = ['-nostdlib'])
|
init_env.Append(LINKFLAGS = ['-nostdlib'])
|
||||||
init_env.Append(CPPFLAGS = ['-nostdinc', '-mno-sse'])
|
if init_env["ARCH"] == "amd64":
|
||||||
|
init_env.Append(CPPFLAGS = ['-mno-sse'])
|
||||||
|
init_env.Append(CPPFLAGS = ['-nostdinc'])
|
||||||
init_env.Append(CPPPATH = ['#build/include'])
|
init_env.Append(CPPPATH = ['#build/include'])
|
||||||
init_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
|
init_env.Append(LIBPATH = ['#build/lib/libc'], LIBS = ['c'])
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
uint64_t status;
|
uint64_t status;
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ src_arm64 = [
|
|||||||
"arm64/trap.c",
|
"arm64/trap.c",
|
||||||
"arm64/trapentry.S",
|
"arm64/trapentry.S",
|
||||||
"arm64/gic.c",
|
"arm64/gic.c",
|
||||||
|
"arm64/pdcache.c",
|
||||||
# Devices
|
# Devices
|
||||||
"dev/arm64/uart.c",
|
"dev/arm64/uart.c",
|
||||||
# Metal
|
# Metal
|
||||||
@ -111,13 +112,13 @@ src.append(src_common)
|
|||||||
kern_env.Append(LINKFLAGS = ['-T', ldscript[1:], '-nostdlib'])
|
kern_env.Append(LINKFLAGS = ['-T', ldscript[1:], '-nostdlib'])
|
||||||
kern_env.Append(CPPFLAGS = ['-D_KERNEL'])
|
kern_env.Append(CPPFLAGS = ['-D_KERNEL'])
|
||||||
kern_env.Append(CPPFLAGS = ['-ffreestanding', '-fno-builtin', '-nostdinc',
|
kern_env.Append(CPPFLAGS = ['-ffreestanding', '-fno-builtin', '-nostdinc',
|
||||||
'-mno-red-zone', '-std=c11', "-Wno-c2x-extensions"])
|
'-mno-red-zone', '-std=c2x', "-Wno-c2x-extensions"])
|
||||||
|
|
||||||
if env["ARCH"] == "amd64":
|
if env["ARCH"] == "amd64":
|
||||||
kern_env.Append(CPPFLAGS = ['-mno-mmx', '-mno-sse', '-mcmodel=large'])
|
kern_env.Append(CPPFLAGS = ['-mno-mmx', '-mno-sse', '-mcmodel=large'])
|
||||||
# '-target', 'amd64-orion-eabi'
|
# '-target', 'amd64-orion-eabi'
|
||||||
elif env["ARCH"] == "arm64":
|
elif env["ARCH"] == "arm64":
|
||||||
kern_env.Append(CPPFLAGS = ['-mcmodel=large', '-arch', 'armv8.1+nofp'])
|
kern_env.Append(CPPFLAGS = ['-mcmodel=large'])
|
||||||
|
|
||||||
kern_env.Append(CPPPATH = ['#build/include'])
|
kern_env.Append(CPPPATH = ['#build/include'])
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ Debug_Breakpoint(TrapFrame *tf)
|
|||||||
static void
|
static void
|
||||||
Debug_Registers(int argc, const char *argv[])
|
Debug_Registers(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
TrapFrame *tf = frames[CPU()];
|
UNUSED TrapFrame *tf = frames[CPU()];
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
int cpuNo = Debug_StrToInt(argv[1]);
|
int cpuNo = Debug_StrToInt(argv[1]);
|
||||||
@ -104,7 +104,7 @@ REGISTER_DBGCMD(registers, "Show CPU registers", Debug_Registers);
|
|||||||
static void
|
static void
|
||||||
Debug_Backtrace(int argc, const char *argv[])
|
Debug_Backtrace(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
TrapFrame *tf = frames[CPU()];
|
UNUSED TrapFrame *tf = frames[CPU()];
|
||||||
uint64_t *ptr;
|
uint64_t *ptr;
|
||||||
uint64_t rip;
|
uint64_t rip;
|
||||||
uint64_t rbp;
|
uint64_t rbp;
|
||||||
@ -143,7 +143,7 @@ Debug_SetBreakpoint(int argc, const char *argv[])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t addr = Debug_StrToInt(argv[1]);
|
UNUSED uint64_t addr = Debug_StrToInt(argv[1]);
|
||||||
|
|
||||||
kprintf("NOT IMPLEMENTED\n");
|
kprintf("NOT IMPLEMENTED\n");
|
||||||
}
|
}
|
||||||
@ -151,7 +151,7 @@ Debug_SetBreakpoint(int argc, const char *argv[])
|
|||||||
REGISTER_DBGCMD(bkpt, "Set breakpoint", Debug_SetBreakpoint);
|
REGISTER_DBGCMD(bkpt, "Set breakpoint", Debug_SetBreakpoint);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_ClearBreakpoint(int argc, const char *argv[])
|
Debug_ClearBreakpoint(int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
if (argc != 2) {
|
if (argc != 2) {
|
||||||
kprintf("clrbkpt [0-3]");
|
kprintf("clrbkpt [0-3]");
|
||||||
@ -164,7 +164,7 @@ Debug_ClearBreakpoint(int argc, const char *argv[])
|
|||||||
REGISTER_DBGCMD(clrbkpt, "Clear breakpoint", Debug_ClearBreakpoint);
|
REGISTER_DBGCMD(clrbkpt, "Clear breakpoint", Debug_ClearBreakpoint);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_ListBreakpoints(int argc, const char *argv[])
|
Debug_ListBreakpoints(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
kprintf("NOT IMPLEMENTED\n");
|
kprintf("NOT IMPLEMENTED\n");
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ Debug_ListBreakpoints(int argc, const char *argv[])
|
|||||||
REGISTER_DBGCMD(bkpts, "List breakpoint", Debug_ListBreakpoints);
|
REGISTER_DBGCMD(bkpts, "List breakpoint", Debug_ListBreakpoints);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Reboot(int argc, const char *argv[])
|
Debug_Reboot(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
kprintf("NOT IMPLEMENTED\n");
|
kprintf("NOT IMPLEMENTED\n");
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1092,7 @@ db_print_address(const char *seg, int size, int rex, struct i_addr *addrp)
|
|||||||
* and return updated location.
|
* and return updated location.
|
||||||
*/
|
*/
|
||||||
static uintptr_t
|
static uintptr_t
|
||||||
db_disasm_esc(uintptr_t loc, int inst, int rex, int short_addr, int size, const char *seg)
|
db_disasm_esc(uintptr_t loc, int inst, int rex, int short_addr, UNUSED int size, const char *seg)
|
||||||
{
|
{
|
||||||
int regmodrm;
|
int regmodrm;
|
||||||
const struct finst * fp;
|
const struct finst * fp;
|
||||||
@ -1183,7 +1183,7 @@ db_disasm_esc(uintptr_t loc, int inst, int rex, int short_addr, int size, const
|
|||||||
* next instruction.
|
* next instruction.
|
||||||
*/
|
*/
|
||||||
uintptr_t
|
uintptr_t
|
||||||
db_disasm(uintptr_t loc, bool altfmt)
|
db_disasm(uintptr_t loc, UNUSED bool altfmt)
|
||||||
{
|
{
|
||||||
int inst;
|
int inst;
|
||||||
int size;
|
int size;
|
||||||
|
@ -309,7 +309,7 @@ gic_wakeup_redist(uint32_t rdid)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
gic_is_valid_extspi(uint32_t rd, uint32_t ID)
|
gic_is_valid_extspi(UNUSED uint32_t rd, uint32_t ID)
|
||||||
{
|
{
|
||||||
uint32_t max_spi;
|
uint32_t max_spi;
|
||||||
// Check Ext SPI implemented
|
// Check Ext SPI implemented
|
||||||
|
@ -28,14 +28,6 @@
|
|||||||
#define ROUNDUP_PGSIZE(x) (((x) + LARGE_PGSIZE - 1) & ~LARGE_PGMASK)
|
#define ROUNDUP_PGSIZE(x) (((x) + LARGE_PGSIZE - 1) & ~LARGE_PGMASK)
|
||||||
#define ROUNDDOWN_PGSIZE(x) ((x) & ~LARGE_PGMASK)
|
#define ROUNDDOWN_PGSIZE(x) ((x) & ~LARGE_PGMASK)
|
||||||
|
|
||||||
#define PAGETABLE_ENTRIES 512
|
|
||||||
|
|
||||||
typedef uint64_t PageEntry;
|
|
||||||
|
|
||||||
typedef struct PageTable {
|
|
||||||
PageEntry entries[PAGETABLE_ENTRIES];
|
|
||||||
} PageTable;
|
|
||||||
|
|
||||||
/* SCTLR_EL1 */
|
/* SCTLR_EL1 */
|
||||||
#define SCTLR_M 0x00000001 /* MMU Enable */
|
#define SCTLR_M 0x00000001 /* MMU Enable */
|
||||||
#define SCTLR_A 0x00000002 /* Alignment Check */
|
#define SCTLR_A 0x00000002 /* Alignment Check */
|
||||||
|
@ -6,27 +6,43 @@
|
|||||||
#ifndef __ARM64OP_H__
|
#ifndef __ARM64OP_H__
|
||||||
#define __ARM64OP_H__
|
#define __ARM64OP_H__
|
||||||
|
|
||||||
static INLINE void enable_interrupts()
|
#include <stdint.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
static ALWAYS_INLINE INLINE void enable_interrupts()
|
||||||
{
|
{
|
||||||
__asm__ volatile("msr daifclr, #(0x0002)\n");
|
__asm__ volatile("msr daifclr, #(0x0002)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void disable_interrupts()
|
static ALWAYS_INLINE INLINE void disable_interrupts()
|
||||||
{
|
{
|
||||||
__asm__ volatile("msr daifset, #(0x0002)\n");
|
__asm__ volatile("msr daifset, #(0x0002)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void hlt()
|
static ALWAYS_INLINE INLINE void hlt()
|
||||||
{
|
{
|
||||||
__asm__ volatile("wfi");
|
__asm__ volatile("wfi");
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void pause()
|
static ALWAYS_INLINE INLINE void flushtlb()
|
||||||
|
{
|
||||||
|
uint64_t zero = 0;
|
||||||
|
__asm__ volatile (
|
||||||
|
"msr ttbr0_el1, %x0;"
|
||||||
|
"msr ttbr1_el1, %x0;"
|
||||||
|
"TLBI VMALLE1;"
|
||||||
|
:
|
||||||
|
: "r" (zero)
|
||||||
|
:
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static ALWAYS_INLINE INLINE void pause()
|
||||||
{
|
{
|
||||||
__asm__ volatile("yield");
|
__asm__ volatile("yield");
|
||||||
}
|
}
|
||||||
|
|
||||||
static INLINE void breakpoint()
|
static ALWAYS_INLINE INLINE void breakpoint()
|
||||||
{
|
{
|
||||||
__asm__ volatile("brk #0");
|
__asm__ volatile("brk #0");
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#if defined(IMPL_MROUTINE)
|
#if defined(IMPL_MROUTINE)
|
||||||
#undef IMPL_MROUTINE
|
#undef IMPL_MROUTINE
|
||||||
#define IMPL_MROUTINE(name, exit_flag) void MCODE _ ## name ## _impl(void); \
|
#define IMPL_MROUTINE(name) int MCODE _ ## name ## _impl(void); \
|
||||||
__asm__ ( \
|
__asm__ ( \
|
||||||
".section \"mcode\";" \
|
".section \"mcode\";" \
|
||||||
".globl " _METAL_STR(name) ";" \
|
".globl " _METAL_STR(name) ";" \
|
||||||
@ -28,14 +28,15 @@
|
|||||||
"mov x0, xzr;" \
|
"mov x0, xzr;" \
|
||||||
"ldr x0,=_" _METAL_STR(name) "_impl;" \
|
"ldr x0,=_" _METAL_STR(name) "_impl;" \
|
||||||
"blr x0;" \
|
"blr x0;" \
|
||||||
"ldr x0, [sp], #16;" \
|
"ldr x1, [sp], #16;" \
|
||||||
"mov sp, x0;" \
|
"mov sp, x1;" \
|
||||||
METAL_MEXIT_GAS(exit_flag) \
|
METAL_WMR_GAS(METAL_REG_MR0, AARCH_REG_X0) \
|
||||||
|
METAL_MEXIT_GAS(METAL_REG_MR0) \
|
||||||
); \
|
); \
|
||||||
void MCODE _ ## name ## _impl(void)
|
int MCODE _ ## name ## _impl(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define IMPL_SHORT_MROUTINE(name, exit_flag) void MCODE _ ## name ## _impl(void); \
|
#define IMPL_SHORT_MROUTINE(name) int MCODE _ ## name ## _impl(void); \
|
||||||
__asm__ ( \
|
__asm__ ( \
|
||||||
".section \"mcode\";" \
|
".section \"mcode\";" \
|
||||||
".globl " _METAL_STR(name) ";" \
|
".globl " _METAL_STR(name) ";" \
|
||||||
@ -44,9 +45,10 @@ void MCODE _ ## name ## _impl(void)
|
|||||||
"mov x0, xzr;" \
|
"mov x0, xzr;" \
|
||||||
"ldr x0,=_" _METAL_STR(name) "_impl;" \
|
"ldr x0,=_" _METAL_STR(name) "_impl;" \
|
||||||
"blr x0;" \
|
"blr x0;" \
|
||||||
METAL_MEXIT_GAS(exit_flag) \
|
METAL_WMR_GAS(METAL_REG_MR0, AARCH_REG_X0) \
|
||||||
|
METAL_MEXIT_GAS(METAL_REG_MR0) \
|
||||||
); \
|
); \
|
||||||
void MCODE _ ## name ## _impl(void)
|
int MCODE _ ## name ## _impl(void)
|
||||||
|
|
||||||
#define DECL_MVAR(type, name) type MDATA name
|
#define DECL_MVAR(type, name) type MDATA name
|
||||||
#define DECL_MVAR_ALIGNED(type, name, align) type ALIGNED(align) MDATA name
|
#define DECL_MVAR_ALIGNED(type, name, align) type ALIGNED(align) MDATA name
|
||||||
|
@ -128,18 +128,20 @@ extern "C" {
|
|||||||
); \
|
); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define METAL_MEXIT_ENCODING(flags) (0xd61f2400 | ((flags) << 0))
|
#define METAL_MEXIT_ENCODING(mreg) (0xd61f2400 | ((mreg) << 0))
|
||||||
#define METAL_MEXIT_GAS(flags) METAL_GAS_ENCODE(METAL_MEXIT_ENCODING(flags))
|
#define METAL_MEXIT_GAS(mreg) METAL_GAS_ENCODE(METAL_MEXIT_ENCODING(mreg))
|
||||||
#define METAL_MEXIT(flags) do { \
|
#define METAL_MEXIT(mreg) do { \
|
||||||
__asm__ volatile ( \
|
__asm__ volatile ( \
|
||||||
METAL_MEXIT_GAS(flags) \
|
METAL_MEXIT_GAS(mreg) \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
: \
|
: \
|
||||||
); } while(0)
|
); } while(0)
|
||||||
|
|
||||||
#define MEXIT_FLAG_IIM (1 << 1) // this mexit masks instruction intercept for the instruction returned to
|
#define MEXIT_FLAG_IIM (1 << 2) // this mexit masks instruction intercept for the first instruction after mexit
|
||||||
#define MEXIT_FLAG_RFI (1 << 0) // this mexit is a return from intercept (also restores CPSR from MSPSR)
|
#define MEXIT_FLAG_RFI (1 << 1) // this mexit is a return from intercept (also restores CPSR from MSPSR)
|
||||||
|
#define MEXIT_FLAG_ID (1 << 0) // this mexit masks interrupts for the first instruction after mexit
|
||||||
|
#define MEXIT_FLAG_EIM (1 << 3) // this mexit masks exception intercept for the first instruction after mexit
|
||||||
|
|
||||||
// do not provide C version of RAR/WAR for the current bank
|
// do not provide C version of RAR/WAR for the current bank
|
||||||
// can't decide which GP register to use as temp
|
// can't decide which GP register to use as temp
|
||||||
@ -311,16 +313,17 @@ extern "C" {
|
|||||||
METAL_RMR(METAL_REG_MO0 + idx, var); \
|
METAL_RMR(METAL_REG_MO0 + idx, var); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define DECL_MROUTINE(name) void __attribute__((aligned(16))) name(void)
|
#define DECL_MROUTINE(name) int __attribute__((aligned(16))) name(void)
|
||||||
#define IMPL_MROUTINE(name, exit_flag) void _ ## name ## _impl(void); \
|
#define IMPL_MROUTINE(name) int _ ## name ## _impl(void); \
|
||||||
__asm__ ( \
|
__asm__ ( \
|
||||||
".globl " _METAL_STR(name) ";" \
|
".globl " _METAL_STR(name) ";" \
|
||||||
".balign 16;" \
|
".balign 16;" \
|
||||||
_METAL_STR(name) ":;" \
|
_METAL_STR(name) ":;" \
|
||||||
"bl _" _METAL_STR(name) "_impl;" \
|
"bl _" _METAL_STR(name) "_impl;" \
|
||||||
METAL_MEXIT_GAS(exit_flag) \
|
METAL_WMR_GAS(METAL_REG_MR0, AARCH_REG_X0) \
|
||||||
|
METAL_MEXIT_GAS(METAL_REG_MR0) \
|
||||||
); \
|
); \
|
||||||
void _ ## name ## _impl(void)
|
int _ ## name ## _impl(void)
|
||||||
|
|
||||||
|
|
||||||
// mroutine table defs
|
// mroutine table defs
|
||||||
@ -372,12 +375,14 @@ struct exc_intercept_table {
|
|||||||
typedef uint64_t regval_t;
|
typedef uint64_t regval_t;
|
||||||
typedef regval_t msr_t;
|
typedef regval_t msr_t;
|
||||||
|
|
||||||
#define METAL_MSR_MASK_INIT (1ul << 63)
|
#define METAL_MSR_MASK_INIT (1ull << 63)
|
||||||
#define METAL_MSR_MASK_II (1ul << 62)
|
#define METAL_MSR_MASK_II (1ull << 62)
|
||||||
#define METAL_MSR_MASK_IM (1ul << 61)
|
#define METAL_MSR_MASK_IM (1ull << 61)
|
||||||
#define METAL_MSR_MASK_LV (0xfful)
|
#define METAL_MSR_MASK_EI (1ull << 60)
|
||||||
#define METAL_MSR_MASK_EI (1ul << 60)
|
#define METAL_MSR_MASK_EM (1ull << 59)
|
||||||
#define METAL_MSR_MASK_PD (1ul << 59)
|
#define METAL_MSR_MASK_PD (1ull << 58)
|
||||||
|
#define METAL_MSR_MASK_ID (1ull << 57)
|
||||||
|
#define METAL_MSR_MASK_LV (0xffull)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "machine/metalp.h"
|
||||||
#include <machine/metal.h>
|
#include <machine/metal.h>
|
||||||
|
|
||||||
DECL_MROUTINE(mrt_init);
|
DECL_MROUTINE(mrt_init);
|
||||||
#define MRT_INIT_IDX (1)
|
#define MRT_INIT_IDX (1)
|
||||||
|
|
||||||
DECL_MROUTINE(mrt_pf_handler);
|
DECL_MROUTINE(mrt_pf_itlb_handler);
|
||||||
#define MRT_PF_HANDLER_IDX (2)
|
#define MRT_PF_ITLB_HANDLER_IDX (2)
|
||||||
|
|
||||||
|
DECL_MROUTINE(mrt_pf_dtlb_handler);
|
||||||
|
#define MRT_PF_DTLB_HANDLER_IDX (3)
|
||||||
|
|
||||||
DECL_MROUTINE(mrt_dummy);
|
DECL_MROUTINE(mrt_dummy);
|
||||||
|
|
||||||
@ -14,7 +18,7 @@ DECL_MROUTINE(mrt_dummy);
|
|||||||
// int mrt_set_mptb(int ptbidx, regval_t val);
|
// int mrt_set_mptb(int ptbidx, regval_t val);
|
||||||
//
|
//
|
||||||
DECL_MROUTINE(mrt_set_mptb);
|
DECL_MROUTINE(mrt_set_mptb);
|
||||||
#define MRT_SET_MPTB_IDX (3)
|
#define MRT_SET_MPTB_IDX (4)
|
||||||
#define MRT_SET_MPTB_USER (0)
|
#define MRT_SET_MPTB_USER (0)
|
||||||
#define MRT_SET_MPTB_DMAP (1)
|
#define MRT_SET_MPTB_DMAP (1)
|
||||||
#define MRT_SET_MPTB_XMEM (2)
|
#define MRT_SET_MPTB_XMEM (2)
|
||||||
@ -27,9 +31,13 @@ DECL_MROUTINE(mrt_set_mptb);
|
|||||||
// void mrt_set_mtp(regval_t mtp);
|
// void mrt_set_mtp(regval_t mtp);
|
||||||
//
|
//
|
||||||
DECL_MROUTINE(mrt_set_mtp);
|
DECL_MROUTINE(mrt_set_mtp);
|
||||||
#define MRT_SET_MTP_IDX (4)
|
#define MRT_SET_MTP_IDX (5)
|
||||||
#define MRT_SET_MTP_ARG_MTP (0)
|
#define MRT_SET_MTP_ARG_MTP (0)
|
||||||
|
|
||||||
|
|
||||||
|
DECL_MROUTINE(mrt_wfi);
|
||||||
|
#define MRT_WFI_IDX (6)
|
||||||
|
|
||||||
extern DECL_MVAR(struct mroutine_table, mtl_mrt_tbl);
|
extern DECL_MVAR(struct mroutine_table, mtl_mrt_tbl);
|
||||||
extern DECL_MVAR(struct exc_intercept_table, mtl_exc_tbl);
|
extern DECL_MVAR(struct exc_intercept_table, mtl_exc_tbl);
|
||||||
|
|
||||||
|
@ -3,9 +3,6 @@
|
|||||||
#include <machine/pmap.h>
|
#include <machine/pmap.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
// 2048 buckets * 8 bytes / bucket = 16KB per page tbl = smallest page size
|
|
||||||
#define VM_PTBUCKETS (2048)
|
|
||||||
|
|
||||||
// 1GB page ident map region
|
// 1GB page ident map region
|
||||||
#define REGION_DMAP_PGSHIFT (30)
|
#define REGION_DMAP_PGSHIFT (30)
|
||||||
// 16K page userspace
|
// 16K page userspace
|
||||||
@ -21,10 +18,13 @@ struct vmpte {
|
|||||||
};
|
};
|
||||||
_Static_assert(sizeof(struct vmpte) == 8);
|
_Static_assert(sizeof(struct vmpte) == 8);
|
||||||
|
|
||||||
|
#define VM_PTBUCKETS (PGSIZE / sizeof(struct vmpte))
|
||||||
|
|
||||||
struct vmpt {
|
struct vmpt {
|
||||||
struct vmpte entries[VM_PTBUCKETS];
|
struct vmpte entries[VM_PTBUCKETS];
|
||||||
};
|
};
|
||||||
_Static_assert(sizeof(struct vmpt) == VM_PTBUCKETS * sizeof(struct vmpte));
|
_Static_assert(sizeof(struct vmpt) == VM_PTBUCKETS * sizeof(struct vmpte));
|
||||||
|
_Static_assert(sizeof(struct vmpt) == PGSIZE);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Page Table Entry (must be 8 bytes aligned)
|
// Page Table Entry (must be 8 bytes aligned)
|
||||||
|
7
sys/arm64/include/pdcache.h
Normal file
7
sys/arm64/include/pdcache.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
struct vmpd * pdcache_alloc();
|
||||||
|
|
||||||
|
void pdcache_free(struct vmpd * pd);
|
||||||
|
|
||||||
|
void pdcache_init();
|
@ -57,9 +57,9 @@
|
|||||||
|
|
||||||
typedef struct AS
|
typedef struct AS
|
||||||
{
|
{
|
||||||
PageTable *root;
|
struct vmpt *xmem_tbl;
|
||||||
uint64_t tables;
|
struct vmpt *dmap_tbl;
|
||||||
uint64_t mappings;
|
struct vmpt *user_tbl;
|
||||||
} AS;
|
} AS;
|
||||||
|
|
||||||
void PMap_Init();
|
void PMap_Init();
|
||||||
@ -79,7 +79,7 @@ bool PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags);
|
|||||||
bool PMap_Unmap(AS *as, uint64_t virt, uint64_t pages);
|
bool PMap_Unmap(AS *as, uint64_t virt, uint64_t pages);
|
||||||
|
|
||||||
// Manipulate Kernel Memory
|
// Manipulate Kernel Memory
|
||||||
void PMap_SystemLookup(uint64_t va, PageEntry **entry, int size);
|
// void PMap_SystemLookup(uint64_t va, PageEntry **entry, int size);
|
||||||
bool PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags);
|
bool PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags);
|
||||||
bool PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags);
|
bool PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags);
|
||||||
bool PMap_SystemUnmap(uint64_t virt, uint64_t pages);
|
bool PMap_SystemUnmap(uint64_t virt, uint64_t pages);
|
||||||
|
@ -21,7 +21,10 @@
|
|||||||
#include <sys/elf64.h>
|
#include <sys/elf64.h>
|
||||||
|
|
||||||
#include "../dev/console.h"
|
#include "../dev/console.h"
|
||||||
#include "machine/cpuop.h"
|
#include <machine/cpuop.h>
|
||||||
|
#include <machine/metal.h>
|
||||||
|
#include <machine/mrt.h>
|
||||||
|
#include <machine/pdcache.h>
|
||||||
|
|
||||||
extern void KTime_Init();
|
extern void KTime_Init();
|
||||||
extern void KTimer_Init();
|
extern void KTimer_Init();
|
||||||
@ -64,7 +67,7 @@ Machine_EarlyInit()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Machine_IdleThread(void *test)
|
Machine_IdleThread(UNUSED void *test)
|
||||||
{
|
{
|
||||||
while (1) { enable_interrupts(); hlt(); }
|
while (1) { enable_interrupts(); hlt(); }
|
||||||
}
|
}
|
||||||
@ -79,9 +82,6 @@ Machine_IdleThread(void *test)
|
|||||||
void Machine_Init()
|
void Machine_Init()
|
||||||
{
|
{
|
||||||
Machine_EarlyInit();
|
Machine_EarlyInit();
|
||||||
/*
|
|
||||||
* Initialize Processor State
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (gic_init() != 0) {
|
if (gic_init() != 0) {
|
||||||
PANIC("gic initialization failed!\n");
|
PANIC("gic initialization failed!\n");
|
||||||
@ -101,16 +101,17 @@ void Machine_Init()
|
|||||||
: "x0", "x1"
|
: "x0", "x1"
|
||||||
);
|
);
|
||||||
|
|
||||||
while(1) {
|
while(1){
|
||||||
hlt();
|
hlt();
|
||||||
};
|
}
|
||||||
|
|
||||||
//Machine_SyscallInit();
|
Machine_SyscallInit();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize Memory Allocation and Virtual Memory
|
* Initialize Memory Allocation and Virtual Memory
|
||||||
*/
|
*/
|
||||||
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
|
PAlloc_AddRegion(DMPA2VA(16*1024*1024), 16*1024*1024);
|
||||||
|
pdcache_init();
|
||||||
PMap_Init();
|
PMap_Init();
|
||||||
XMem_Init();
|
XMem_Init();
|
||||||
PAlloc_LateInit();
|
PAlloc_LateInit();
|
||||||
@ -120,7 +121,7 @@ void Machine_Init()
|
|||||||
* Initialize Time Keeping
|
* Initialize Time Keeping
|
||||||
*/
|
*/
|
||||||
KTime_Init();
|
KTime_Init();
|
||||||
RTC_Init(); // Finishes initializing KTime
|
//RTC_Init(); // Finishes initializing KTime
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize Interrupts
|
* Initialize Interrupts
|
||||||
|
@ -29,7 +29,7 @@ static uintptr_t memRegionLen[MAX_REGIONS];
|
|||||||
static int memRegionIdx;
|
static int memRegionIdx;
|
||||||
|
|
||||||
void
|
void
|
||||||
MachineBoot_Entry(unsigned long magic, unsigned long addr)
|
MachineBoot_Entry(UNUSED unsigned long magic, UNUSED unsigned long addr)
|
||||||
{
|
{
|
||||||
// initialize metal mode
|
// initialize metal mode
|
||||||
mtl_init();
|
mtl_init();
|
||||||
|
@ -162,14 +162,14 @@ MP_CrossCall(CrossCallCB cb, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
MPPing(void *arg)
|
MPPing(UNUSED void *arg)
|
||||||
{
|
{
|
||||||
//kprintf("CPU %d Ack\n", CPU());
|
//kprintf("CPU %d Ack\n", CPU());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_CrossCall(int argc, const char *argv[])
|
Debug_CrossCall(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
UnixEpochNS startTS, stopTS;
|
UnixEpochNS startTS, stopTS;
|
||||||
@ -190,7 +190,7 @@ Debug_CrossCall(int argc, const char *argv[])
|
|||||||
REGISTER_DBGCMD(crosscall, "Ping crosscall", Debug_CrossCall);
|
REGISTER_DBGCMD(crosscall, "Ping crosscall", Debug_CrossCall);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_CPUS(int argc, const char *argv[])
|
Debug_CPUS(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@ -204,7 +204,7 @@ Debug_CPUS(int argc, const char *argv[])
|
|||||||
REGISTER_DBGCMD(cpus, "Show MP information", Debug_CPUS);
|
REGISTER_DBGCMD(cpus, "Show MP information", Debug_CPUS);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_CPU(int argc, const char *argv[])
|
Debug_CPU(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
kprintf("CPU %d\n", CPU());
|
kprintf("CPU %d\n", CPU());
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "machine/metalp.h"
|
#include "machine/metalp.h"
|
||||||
|
#include <machine/metal.h>
|
||||||
#include <machine/mrt.h>
|
#include <machine/mrt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -8,11 +9,28 @@ DECL_MVAR(struct inst_intercept_table, mtl_inst_tbl);
|
|||||||
#define METAL_BOOTSTACK_SZ (4096)
|
#define METAL_BOOTSTACK_SZ (4096)
|
||||||
DECL_MVAR_ALIGNED(static char, mtl_bootstack[METAL_BOOTSTACK_SZ], METAL_BOOTSTACK_SZ);
|
DECL_MVAR_ALIGNED(static char, mtl_bootstack[METAL_BOOTSTACK_SZ], METAL_BOOTSTACK_SZ);
|
||||||
|
|
||||||
IMPL_SHORT_MROUTINE(mrt_dummy, 0)
|
IMPL_SHORT_MROUTINE(mrt_dummy)
|
||||||
{
|
{
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPL_SHORT_MROUTINE(mrt_init, 0)
|
IMPL_SHORT_MROUTINE(mrt_wfi)
|
||||||
|
{
|
||||||
|
unsigned int times;
|
||||||
|
METAL_MROUTINE_GETARG(0, times);
|
||||||
|
while (times > 0) {
|
||||||
|
__asm__ volatile (
|
||||||
|
"wfi;"
|
||||||
|
:
|
||||||
|
:
|
||||||
|
:
|
||||||
|
);
|
||||||
|
times--;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPL_SHORT_MROUTINE(mrt_init)
|
||||||
{
|
{
|
||||||
memset(&mtl_mrt_tbl, 0, sizeof(mtl_mrt_tbl));
|
memset(&mtl_mrt_tbl, 0, sizeof(mtl_mrt_tbl));
|
||||||
memset(&mtl_exc_tbl, 0, sizeof(mtl_exc_tbl));
|
memset(&mtl_exc_tbl, 0, sizeof(mtl_exc_tbl));
|
||||||
@ -21,57 +39,59 @@ IMPL_SHORT_MROUTINE(mrt_init, 0)
|
|||||||
// mroutine 0 - 8
|
// mroutine 0 - 8
|
||||||
mtl_mrt_tbl.entries[0] = MROUTINE_ENTRY_MAKE(mrt_dummy, 1);
|
mtl_mrt_tbl.entries[0] = MROUTINE_ENTRY_MAKE(mrt_dummy, 1);
|
||||||
mtl_mrt_tbl.entries[MRT_INIT_IDX] = MROUTINE_ENTRY_MAKE(mrt_init, 1);
|
mtl_mrt_tbl.entries[MRT_INIT_IDX] = MROUTINE_ENTRY_MAKE(mrt_init, 1);
|
||||||
mtl_mrt_tbl.entries[MRT_PF_HANDLER_IDX] = MROUTINE_ENTRY_MAKE(mrt_pf_handler, 1);
|
mtl_mrt_tbl.entries[MRT_PF_DTLB_HANDLER_IDX] = MROUTINE_ENTRY_MAKE(mrt_pf_dtlb_handler, 1);
|
||||||
|
mtl_mrt_tbl.entries[MRT_PF_ITLB_HANDLER_IDX] = MROUTINE_ENTRY_MAKE(mrt_pf_itlb_handler, 1);
|
||||||
mtl_mrt_tbl.entries[MRT_SET_MPTB_IDX] = MROUTINE_ENTRY_MAKE(mrt_set_mptb, 1);
|
mtl_mrt_tbl.entries[MRT_SET_MPTB_IDX] = MROUTINE_ENTRY_MAKE(mrt_set_mptb, 1);
|
||||||
mtl_mrt_tbl.entries[MRT_SET_MTP_IDX] = MROUTINE_ENTRY_MAKE(mrt_set_mtp, 1);
|
mtl_mrt_tbl.entries[MRT_SET_MTP_IDX] = MROUTINE_ENTRY_MAKE(mrt_set_mtp, 1);
|
||||||
|
mtl_mrt_tbl.entries[MRT_WFI_IDX] = MROUTINE_ENTRY_MAKE(mrt_wfi, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[0].esrbits = (0b100100 << 26) | (0b00100); // data abort, lv0 translation
|
mtl_exc_tbl.entries[0].esrbits = (0b100100 << 26) | (0b00100); // data abort, lv0 translation
|
||||||
mtl_exc_tbl.entries[0].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[0].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[0].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[0].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[1].esrbits = (0b100100 << 26) | (0b00101); // data abort, lv1 translation
|
mtl_exc_tbl.entries[1].esrbits = (0b100100 << 26) | (0b00101); // data abort, lv1 translation
|
||||||
mtl_exc_tbl.entries[1].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[1].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[1].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[1].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[2].esrbits = (0b100100 << 26) | (0b00110); // data abort, lv2 translation
|
mtl_exc_tbl.entries[2].esrbits = (0b100100 << 26) | (0b00110); // data abort, lv2 translation
|
||||||
mtl_exc_tbl.entries[2].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[2].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[2].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[2].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[3].esrbits = (0b100100 << 26) | (0b00111); // data abort, lv3 translation
|
mtl_exc_tbl.entries[3].esrbits = (0b100100 << 26) | (0b00111); // data abort, lv3 translation
|
||||||
mtl_exc_tbl.entries[3].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[3].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[3].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[3].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[4].esrbits = (0b100001 << 26) | (0b00100); // inst abort, lv0 translation
|
mtl_exc_tbl.entries[4].esrbits = (0b100001 << 26) | (0b00100); // inst abort, lv0 translation
|
||||||
mtl_exc_tbl.entries[4].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[4].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[4].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[4].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_ITLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[5].esrbits = (0b100001 << 26) | (0b00101); // inst abort, lv1 translation
|
mtl_exc_tbl.entries[5].esrbits = (0b100001 << 26) | (0b00101); // inst abort, lv1 translation
|
||||||
mtl_exc_tbl.entries[5].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[5].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[5].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[5].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_ITLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[6].esrbits = (0b100001 << 26) | (0b00110); // inst abort, lv2 translation
|
mtl_exc_tbl.entries[6].esrbits = (0b100001 << 26) | (0b00110); // inst abort, lv2 translation
|
||||||
mtl_exc_tbl.entries[6].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[6].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[6].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[6].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_ITLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[7].esrbits = (0b100001 << 26) | (0b00111); // inst abort, lv3 translation
|
mtl_exc_tbl.entries[7].esrbits = (0b100001 << 26) | (0b00111); // inst abort, lv3 translation
|
||||||
mtl_exc_tbl.entries[7].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[7].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[7].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[7].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_ITLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[8].esrbits = (0b100101 << 26) | (0b00100); // data abort, lv0 translation
|
mtl_exc_tbl.entries[8].esrbits = (0b100101 << 26) | (0b00100); // data abort, lv0 translation
|
||||||
mtl_exc_tbl.entries[8].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[8].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[8].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[8].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[9].esrbits = (0b100101 << 26) | (0b00101); // data abort, lv1 translation
|
mtl_exc_tbl.entries[9].esrbits = (0b100101 << 26) | (0b00101); // data abort, lv1 translation
|
||||||
mtl_exc_tbl.entries[9].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[9].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[9].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[9].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[10].esrbits = (0b100101 << 26) | (0b00110); // data abort, lv2 translation
|
mtl_exc_tbl.entries[10].esrbits = (0b100101 << 26) | (0b00110); // data abort, lv2 translation
|
||||||
mtl_exc_tbl.entries[10].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[10].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[10].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[10].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
mtl_exc_tbl.entries[11].esrbits = (0b100101 << 26) | (0b00111); // data abort, lv3 translation
|
mtl_exc_tbl.entries[11].esrbits = (0b100101 << 26) | (0b00111); // data abort, lv3 translation
|
||||||
mtl_exc_tbl.entries[11].esrmask = (0b111111 << 26) | (0b11111);
|
mtl_exc_tbl.entries[11].esrmask = (0b111111 << 26) | (0b11111);
|
||||||
mtl_exc_tbl.entries[11].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
mtl_exc_tbl.entries[11].ctrl = EXC_INTERCEPT_MAKE_CTRL(MRT_PF_DTLB_HANDLER_IDX, EXC_INTERCEPT_MODE_SYNC, 1);
|
||||||
|
|
||||||
// load mroutine table
|
// load mroutine table
|
||||||
void* tbl_addr = &mtl_mrt_tbl;
|
void* tbl_addr = &mtl_mrt_tbl;
|
||||||
@ -94,4 +114,6 @@ IMPL_SHORT_MROUTINE(mrt_init, 0)
|
|||||||
// temporary metal stack
|
// temporary metal stack
|
||||||
regval_t mstk = (regval_t)&mtl_bootstack[METAL_BOOTSTACK_SZ];
|
regval_t mstk = (regval_t)&mtl_bootstack[METAL_BOOTSTACK_SZ];
|
||||||
METAL_WMR(METAL_REG_MSTK, mstk);
|
METAL_WMR(METAL_REG_MSTK, mstk);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
@ -51,11 +51,15 @@ vmm_get_pd(paddr_t ptb, unsigned int pgshift, vaddr_t uva, paddr_t * out)
|
|||||||
METAL_PLDR64(cur, pte + offsetof(struct vmpte, first));
|
METAL_PLDR64(cur, pte + offsetof(struct vmpte, first));
|
||||||
|
|
||||||
vaddr_t curvaddr;
|
vaddr_t curvaddr;
|
||||||
|
uint64_t attr;
|
||||||
while (cur != (paddr_t)NULL) {
|
while (cur != (paddr_t)NULL) {
|
||||||
METAL_PLDR64(curvaddr, cur + offsetof(struct vmpd, vaddr));
|
METAL_PLDR64(curvaddr, cur + offsetof(struct vmpd, vaddr));
|
||||||
if (vm_get_pfn(curvaddr, pgshift) == pfn) {
|
if (vm_get_pfn(curvaddr, pgshift) == pfn) {
|
||||||
*out = cur;
|
METAL_PLDR64(attr, cur + offsetof(struct vmpd, attr));
|
||||||
return 0;
|
if (attr & VMPD_ATTR_P) {
|
||||||
|
*out = cur;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
METAL_PLDR64(cur, cur + offsetof(struct vmpd, next));
|
METAL_PLDR64(cur, cur + offsetof(struct vmpd, next));
|
||||||
}
|
}
|
||||||
@ -72,7 +76,7 @@ vmm_get_pd(paddr_t ptb, unsigned int pgshift, vaddr_t uva, paddr_t * out)
|
|||||||
// 0 if success
|
// 0 if success
|
||||||
//
|
//
|
||||||
static MCODE int
|
static MCODE int
|
||||||
vmm_map_page(vaddr_t uva)
|
vmm_map_page(vaddr_t uva, int itlb)
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
paddr_t ptb;
|
paddr_t ptb;
|
||||||
@ -126,7 +130,7 @@ vmm_map_page(vaddr_t uva)
|
|||||||
#define MAIR_NORMAL (0b11111111ul)
|
#define MAIR_NORMAL (0b11111111ul)
|
||||||
#define MAIR_DEV (0b0ul)
|
#define MAIR_DEV (0b0ul)
|
||||||
const regval_t extIAttrs =
|
const regval_t extIAttrs =
|
||||||
(1 << 0) | // itlb
|
((itlb & 0x1) << 0) | // itlb
|
||||||
(0b01 << 1) | // el1
|
(0b01 << 1) | // el1
|
||||||
(0b11 << 3) | // translv = 3
|
(0b11 << 3) | // translv = 3
|
||||||
(0b00 << 5) | // 4k page
|
(0b00 << 5) | // 4k page
|
||||||
@ -144,35 +148,37 @@ vmm_map_page(vaddr_t uva)
|
|||||||
METAL_WMR(METAL_REG_MR2, pgvaddr);
|
METAL_WMR(METAL_REG_MR2, pgvaddr);
|
||||||
METAL_WTLB(METAL_REG_MR0, METAL_REG_MR1, METAL_REG_MR2);
|
METAL_WTLB(METAL_REG_MR0, METAL_REG_MR1, METAL_REG_MR2);
|
||||||
|
|
||||||
const regval_t extDAttrs =
|
|
||||||
(0 << 0) | // dtlb
|
|
||||||
(0b01 << 1) | // el1
|
|
||||||
(0b11 << 3) | // translv = 3
|
|
||||||
(0b00 << 5) | // 4k page
|
|
||||||
(0x0 << 7) | // asid = 0
|
|
||||||
(0 << 23) | // hyp = 0
|
|
||||||
(0 << 24) | // vmid
|
|
||||||
(1ul << 40) | // ao = 1
|
|
||||||
((regval_t)aoid << 41) | // aoid
|
|
||||||
((dev ? MAIR_DEV : MAIR_NORMAL) << 43) | // mair
|
|
||||||
(1ul << 51) | // ns = 0
|
|
||||||
(1ul << 52); // nstid = 1
|
|
||||||
METAL_WMR(METAL_REG_MR1, extDAttrs);
|
|
||||||
METAL_WTLB(METAL_REG_MR0, METAL_REG_MR1, METAL_REG_MR2);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// flag: skip exception intercept on the next instruction upon mreturn
|
// flag: skip exception intercept on the next instruction upon mreturn
|
||||||
IMPL_MROUTINE(mrt_pf_handler, 1)
|
IMPL_MROUTINE(mrt_pf_dtlb_handler)
|
||||||
{
|
{
|
||||||
vaddr_t vaddr;
|
vaddr_t vaddr;
|
||||||
|
|
||||||
METAL_RMR(METAL_REG_MER2, vaddr);
|
METAL_RMR(METAL_REG_MER2, vaddr);
|
||||||
vmm_map_page(vaddr);
|
if (vmm_map_page(vaddr, false) == 0) {
|
||||||
|
// on successful translation just RFI
|
||||||
|
return MEXIT_FLAG_RFI;
|
||||||
|
} else {
|
||||||
|
// unsuccessful, cascade to the OS
|
||||||
|
return MEXIT_FLAG_RFI | MEXIT_FLAG_ID | MEXIT_FLAG_EIM;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
IMPL_MROUTINE(mrt_set_mptb, 0)
|
IMPL_MROUTINE(mrt_pf_itlb_handler)
|
||||||
|
{
|
||||||
|
vaddr_t vaddr;
|
||||||
|
|
||||||
|
METAL_RMR(METAL_REG_MER2, vaddr);
|
||||||
|
if (vmm_map_page(vaddr, true) == 0) {
|
||||||
|
return MEXIT_FLAG_RFI;
|
||||||
|
} else {
|
||||||
|
return MEXIT_FLAG_RFI | MEXIT_FLAG_ID | MEXIT_FLAG_EIM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IMPL_MROUTINE(mrt_set_mptb)
|
||||||
{
|
{
|
||||||
unsigned int idx;
|
unsigned int idx;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -199,12 +205,16 @@ IMPL_MROUTINE(mrt_set_mptb, 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
METAL_MROUTINE_SETRET(0, ret);
|
METAL_MROUTINE_SETRET(0, ret);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
IMPL_MROUTINE(mrt_set_mtp, 0)
|
IMPL_MROUTINE(mrt_set_mtp)
|
||||||
{
|
{
|
||||||
uint64_t mtp;
|
uint64_t mtp;
|
||||||
METAL_MROUTINE_GETARG(0, mtp);
|
METAL_MROUTINE_GETARG(0, mtp);
|
||||||
METAL_WMR(METAL_REG_MTP, mtp);
|
METAL_WMR(METAL_REG_MTP, mtp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
@ -82,13 +82,5 @@ void paging_init()
|
|||||||
|
|
||||||
|
|
||||||
// reset page tables
|
// reset page tables
|
||||||
uint64_t zero = 0;
|
flushtlb();
|
||||||
__asm__ volatile (
|
|
||||||
"msr ttbr0_el1, %x0;"
|
|
||||||
"msr ttbr1_el1, %x0;"
|
|
||||||
"TLBI VMALLE1;"
|
|
||||||
:
|
|
||||||
: "r" (zero)
|
|
||||||
:
|
|
||||||
);
|
|
||||||
}
|
}
|
@ -20,8 +20,8 @@ PCIGetAddr(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
|||||||
uint8_t
|
uint8_t
|
||||||
PCICfgRead8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
PCICfgRead8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
UNUSED uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -29,8 +29,8 @@ PCICfgRead8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
|||||||
uint16_t
|
uint16_t
|
||||||
PCICfgRead16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
PCICfgRead16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE + (reg & 0x2);
|
UNUSED uint16_t port = PCI_PORT_DATABASE + (reg & 0x2);
|
||||||
|
|
||||||
ASSERT((reg & 0x1) == 0);
|
ASSERT((reg & 0x1) == 0);
|
||||||
|
|
||||||
@ -40,8 +40,8 @@ PCICfgRead16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
|||||||
uint32_t
|
uint32_t
|
||||||
PCICfgRead32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
PCICfgRead32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE;
|
UNUSED uint16_t port = PCI_PORT_DATABASE;
|
||||||
|
|
||||||
ASSERT((reg & 0x3) == 0);
|
ASSERT((reg & 0x3) == 0);
|
||||||
|
|
||||||
@ -50,28 +50,28 @@ PCICfgRead32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg)
|
|||||||
|
|
||||||
void
|
void
|
||||||
PCICfgWrite8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
PCICfgWrite8(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
||||||
uint8_t data)
|
UNUSED uint8_t data)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
UNUSED uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PCICfgWrite16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
PCICfgWrite16(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
||||||
uint16_t data)
|
UNUSED uint16_t data)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
UNUSED uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PCICfgWrite32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
PCICfgWrite32(uint32_t bus, uint32_t slot, uint32_t func, uint32_t reg,
|
||||||
uint32_t data)
|
UNUSED uint32_t data)
|
||||||
{
|
{
|
||||||
uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
UNUSED uint32_t addr = PCIGetAddr(bus, slot, func, reg);
|
||||||
uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
UNUSED uint16_t port = PCI_PORT_DATABASE + (reg & 0x3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
131
sys/arm64/pdcache.c
Normal file
131
sys/arm64/pdcache.c
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <sys/kassert.h>
|
||||||
|
#include <sys/kmem.h>
|
||||||
|
#include <machine/paging.h>
|
||||||
|
#include <machine/pmap.h>
|
||||||
|
#include <sys/thread.h>
|
||||||
|
#include <sys/mutex.h>
|
||||||
|
#include <sys/spinlock.h>
|
||||||
|
|
||||||
|
struct pdcache_info {
|
||||||
|
void * next;
|
||||||
|
};
|
||||||
|
_Static_assert(sizeof(struct pdcache_info) <= sizeof(struct vmpd));
|
||||||
|
|
||||||
|
struct pdcache_desc {
|
||||||
|
struct pdcache_info * first;
|
||||||
|
unsigned long free;
|
||||||
|
unsigned long total;
|
||||||
|
Spinlock lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct pdcache_desc pdc;
|
||||||
|
|
||||||
|
static int
|
||||||
|
pdcache_init_region(void * region, unsigned long len, struct pdcache_info ** outf, struct pdcache_info ** outl, unsigned long * free)
|
||||||
|
{
|
||||||
|
if (len < sizeof(struct vmpd)) {
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long count = 0;
|
||||||
|
struct pdcache_info * first = NULL, * last = NULL;
|
||||||
|
while (true) {
|
||||||
|
if (len < sizeof(struct vmpd)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
len = len - sizeof(struct vmpd);
|
||||||
|
|
||||||
|
struct pdcache_info * info = (struct pdcache_info *)(region + len);
|
||||||
|
|
||||||
|
if (last == NULL) {
|
||||||
|
last = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->next = first;
|
||||||
|
first = info;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
*outf = first;
|
||||||
|
*outl = last;
|
||||||
|
*free = count;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
pdcache_grow()
|
||||||
|
{
|
||||||
|
ASSERT(Spinlock_IsHeld(&pdc.lock));
|
||||||
|
|
||||||
|
void * page = PAlloc_AllocPage();
|
||||||
|
if (page == NULL) {
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct pdcache_info * first, * last;
|
||||||
|
unsigned long free;
|
||||||
|
int ret;
|
||||||
|
// initialize the page
|
||||||
|
if ((ret = pdcache_init_region(page, (1 << PGSHIFT), &first, &last, &free)) != 0) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
pdc.free += free;
|
||||||
|
last->next = pdc.first;
|
||||||
|
pdc.first = first;
|
||||||
|
pdc.total += free;
|
||||||
|
|
||||||
|
kprintf("Growing pdcache: +%d nodes, total: %d nodes.\n", free, pdc.total);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocates a new pd and returns its vaddr
|
||||||
|
struct vmpd *
|
||||||
|
pdcache_alloc()
|
||||||
|
{
|
||||||
|
Spinlock_Lock(&pdc.lock);
|
||||||
|
if (pdc.free == 0) {
|
||||||
|
// we ran out
|
||||||
|
if (pdcache_grow() != 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ASSERT(pdc.free > 0 && pdc.first != NULL);
|
||||||
|
struct pdcache_info * cur = pdc.first;
|
||||||
|
pdc.first = cur->next;
|
||||||
|
Spinlock_Unlock(&pdc.lock);
|
||||||
|
|
||||||
|
memset(cur, 0, sizeof(struct vmpd));
|
||||||
|
|
||||||
|
return (struct vmpd *)cur;
|
||||||
|
}
|
||||||
|
|
||||||
|
// frees an existing pdcache
|
||||||
|
void
|
||||||
|
pdcache_free(struct vmpd * pd)
|
||||||
|
{
|
||||||
|
Spinlock_Lock(&pdc.lock);
|
||||||
|
struct pdcache_info * ret = (struct pdcache_info *)pd;
|
||||||
|
struct pdcache_info * old = pdc.first->next;
|
||||||
|
|
||||||
|
pdc.first = ret;
|
||||||
|
ret->next = old;
|
||||||
|
pdc.free++;
|
||||||
|
ASSERT(pdc.total >= pdc.free);
|
||||||
|
|
||||||
|
Spinlock_Unlock(&pdc.lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
pdcache_init()
|
||||||
|
{
|
||||||
|
Spinlock_Init(&pdc.lock, "pdcache lock", SPINLOCK_TYPE_NORMAL);
|
||||||
|
pdc.first = NULL;
|
||||||
|
pdc.free = 0;
|
||||||
|
pdc.total = 0;
|
||||||
|
}
|
199
sys/arm64/pmap.c
199
sys/arm64/pmap.c
@ -1,6 +1,7 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <sys/kconfig.h>
|
#include <sys/kconfig.h>
|
||||||
#include <sys/kassert.h>
|
#include <sys/kassert.h>
|
||||||
@ -12,37 +13,54 @@
|
|||||||
#include <machine/cpuop.h>
|
#include <machine/cpuop.h>
|
||||||
|
|
||||||
#include <machine/pmap.h>
|
#include <machine/pmap.h>
|
||||||
|
#include <machine/paging.h>
|
||||||
|
#include <machine/pdcache.h>
|
||||||
|
#include <machine/mrt.h>
|
||||||
|
|
||||||
AS systemAS;
|
AS systemAS;
|
||||||
AS *currentAS[MAX_CPUS];
|
AS *currentAS[MAX_CPUS];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PMapAllocPageTable --
|
||||||
|
*
|
||||||
|
* Allocates and initializes a page table.
|
||||||
|
*
|
||||||
|
* @return Newly created PageTable.
|
||||||
|
*/
|
||||||
|
static struct vmpt *
|
||||||
|
PMapAllocPageTable()
|
||||||
|
{
|
||||||
|
struct vmpt * vmpt = PAlloc_AllocPage();
|
||||||
|
if (vmpt) {
|
||||||
|
memset(vmpt, 0, sizeof(struct vmpt));
|
||||||
|
}
|
||||||
|
return vmpt;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
PMap_Init()
|
PMap_Init()
|
||||||
{
|
{
|
||||||
int i, j;
|
|
||||||
|
|
||||||
kprintf("Initializing PMAP ... ");
|
kprintf("Initializing PMAP ... ");
|
||||||
|
|
||||||
// Setup global state
|
// Setup global state
|
||||||
for (i = 0; i < MAX_CPUS; i++) {
|
for (int i = 0; i < MAX_CPUS; i++) {
|
||||||
currentAS[i] = 0;
|
currentAS[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate system page table
|
// Allocate system page table
|
||||||
systemAS.root = PAlloc_AllocPage();
|
systemAS.dmap_tbl = PMapAllocPageTable();
|
||||||
systemAS.tables = PAGETABLE_ENTRIES / 2 + 1;
|
systemAS.xmem_tbl = PMapAllocPageTable();
|
||||||
systemAS.mappings = 0;
|
|
||||||
|
|
||||||
if (!systemAS.root)
|
if (!systemAS.dmap_tbl)
|
||||||
PANIC("Cannot allocate system page table");
|
PANIC("Cannot allocate dmap page table");
|
||||||
|
if (!systemAS.xmem_tbl)
|
||||||
|
PANIC("Cannot allocate xmem page table");
|
||||||
|
|
||||||
// Setup system mappings
|
// Setup system mappings
|
||||||
PMap_SystemLMap(0x0, MEM_DIRECTMAP_BASE + 0x0,
|
PMap_SystemLMap(0x0, MEM_DIRECTMAP_BASE,
|
||||||
3*512, 0); // 3GB RWX
|
128, VMPD_ATTR_P | VMPD_ATTR_AO_KRW); // 128GB RWX
|
||||||
PMap_SystemLMap(0xC0000000, MEM_DIRECTMAP_BASE + 0xC0000000,
|
PMap_SystemLMap(0x0, MEM_DIRECTMAP_DEV_BASE,
|
||||||
512, 0); // 1GB RW + PCD
|
128, VMPD_ATTR_P | VMPD_ATTR_AO_KRW | VMPD_ATTR_DEV); // 128GB Device
|
||||||
PMap_SystemLMap(0x100000000, MEM_DIRECTMAP_BASE + 0x100000000,
|
|
||||||
60*512, 0); // 60GB RWX
|
|
||||||
|
|
||||||
PMap_LoadAS(&systemAS);
|
PMap_LoadAS(&systemAS);
|
||||||
|
|
||||||
@ -65,17 +83,14 @@ PMap_InitAP()
|
|||||||
AS*
|
AS*
|
||||||
PMap_NewAS()
|
PMap_NewAS()
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
AS *as = PAlloc_AllocPage();
|
AS *as = PAlloc_AllocPage();
|
||||||
|
|
||||||
if (!as)
|
if (!as)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
as->root = PAlloc_AllocPage();
|
as->dmap_tbl = systemAS.dmap_tbl;
|
||||||
as->tables = 1;
|
as->xmem_tbl = systemAS.xmem_tbl;
|
||||||
as->mappings = 0;
|
as->user_tbl = PMapAllocPageTable();
|
||||||
|
|
||||||
// NOT IMPLEMENTED
|
|
||||||
|
|
||||||
return as;
|
return as;
|
||||||
}
|
}
|
||||||
@ -90,6 +105,11 @@ PMap_NewAS()
|
|||||||
void
|
void
|
||||||
PMap_DestroyAS(AS *space)
|
PMap_DestroyAS(AS *space)
|
||||||
{
|
{
|
||||||
|
// free usertables
|
||||||
|
UNUSED struct vmpt * pt = space->user_tbl;
|
||||||
|
|
||||||
|
// release space itself
|
||||||
|
PAlloc_Release(space);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,23 +136,36 @@ PMap_CurrentAS()
|
|||||||
void
|
void
|
||||||
PMap_LoadAS(AS *space)
|
PMap_LoadAS(AS *space)
|
||||||
{
|
{
|
||||||
// Flush TLB
|
|
||||||
currentAS[CPU()] = space;
|
currentAS[CPU()] = space;
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
// set dmap region
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, MRT_SET_MPTB_DMAP);
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, space->dmap_tbl);
|
||||||
|
METAL_MENTER(MRT_SET_MPTB_IDX);
|
||||||
|
METAL_MROUTINE_GETRET(MRT_SET_MPTB_RET_STATUS, ret);
|
||||||
|
if (ret != 0)
|
||||||
|
PANIC("Failed to load DMAP page table.");
|
||||||
|
|
||||||
|
// set xmem region
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, MRT_SET_MPTB_XMEM);
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, space->xmem_tbl);
|
||||||
|
METAL_MENTER(MRT_SET_MPTB_IDX);
|
||||||
|
METAL_MROUTINE_GETRET(MRT_SET_MPTB_RET_STATUS, ret);
|
||||||
|
if (ret != 0)
|
||||||
|
PANIC("Failed to load XMEM page table.");
|
||||||
|
|
||||||
|
// set userspace
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, MRT_SET_MPTB_USER);
|
||||||
|
METAL_MROUTINE_SETARG(MRT_SET_MPTB_ARG_IDX, space->user_tbl);
|
||||||
|
METAL_MENTER(MRT_SET_MPTB_IDX);
|
||||||
|
METAL_MROUTINE_GETRET(MRT_SET_MPTB_RET_STATUS, ret);
|
||||||
|
if (ret != 0)
|
||||||
|
PANIC("Failed to load USER page table.");
|
||||||
|
|
||||||
|
flushtlb();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PMapAllocPageTable --
|
|
||||||
*
|
|
||||||
* Allocates and initializes a page table.
|
|
||||||
*
|
|
||||||
* @return Newly created PageTable.
|
|
||||||
*/
|
|
||||||
static PageTable *
|
|
||||||
PMapAllocPageTable()
|
|
||||||
{
|
|
||||||
NOT_IMPLEMENTED();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PMap_Translate --
|
* PMap_Translate --
|
||||||
@ -143,31 +176,12 @@ PMapAllocPageTable()
|
|||||||
* @param [in] va Virtual address we wish to translate.
|
* @param [in] va Virtual address we wish to translate.
|
||||||
*/
|
*/
|
||||||
uintptr_t
|
uintptr_t
|
||||||
PMap_Translate(AS *space, uintptr_t va)
|
PMap_Translate(UNUSED AS *space, UNUSED uintptr_t va)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* PMapLookupEntry --
|
|
||||||
*
|
|
||||||
* Lookup a virtual address in a page table and return a pointer to the page
|
|
||||||
* entry. This function allocates page tables as necessary to fill in the
|
|
||||||
* 4-level heirarchy.
|
|
||||||
*
|
|
||||||
* @param [in] space Address space to search.
|
|
||||||
* @param [in] va Virtual address to lookup.
|
|
||||||
* @param [out] entry Pointer will point to the PageEntry.
|
|
||||||
* @param [in] size Page size we want to use.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
PMapLookupEntry(AS *space, uint64_t va, PageEntry **entry, int size)
|
|
||||||
{
|
|
||||||
NOT_IMPLEMENTED();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PMap_Map --
|
* PMap_Map --
|
||||||
*
|
*
|
||||||
@ -183,7 +197,7 @@ PMapLookupEntry(AS *space, uint64_t va, PageEntry **entry, int size)
|
|||||||
* @retval false On failure
|
* @retval false On failure
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
PMap_Map(AS *as, uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
PMap_Map(UNUSED AS *as, UNUSED uint64_t phys, UNUSED uint64_t virt, UNUSED uint64_t pages, UNUSED uint64_t flags)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return true;
|
return true;
|
||||||
@ -202,7 +216,7 @@ PMap_Map(AS *as, uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
|||||||
* @retval false On failure
|
* @retval false On failure
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
PMap_Unmap(AS *as, uint64_t va, uint64_t pages)
|
PMap_Unmap(UNUSED AS *as, UNUSED uint64_t va, UNUSED uint64_t pages)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return true;
|
return true;
|
||||||
@ -223,7 +237,7 @@ PMap_Unmap(AS *as, uint64_t va, uint64_t pages)
|
|||||||
* @retval false On failure
|
* @retval false On failure
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags)
|
PMap_AllocMap(UNUSED AS *as, UNUSED uint64_t virt, UNUSED uint64_t len, UNUSED uint64_t flags)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return true;
|
return true;
|
||||||
@ -240,16 +254,16 @@ PMap_AllocMap(AS *as, uint64_t virt, uint64_t len, uint64_t flags)
|
|||||||
* @param [out] entry Pointer will point to the PageEntry.
|
* @param [out] entry Pointer will point to the PageEntry.
|
||||||
* @param [in] size Page size we want to use.
|
* @param [in] size Page size we want to use.
|
||||||
*/
|
*/
|
||||||
void
|
// void
|
||||||
PMap_SystemLookup(uint64_t va, PageEntry **entry, int size)
|
// PMap_SystemLookup(uint64_t va, PageEntry **entry, int size)
|
||||||
{
|
// {
|
||||||
PMapLookupEntry(&systemAS, va, entry, size);
|
// PMapLookupEntry(&systemAS, va, entry, size);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PMap_SystemLMap --
|
* PMap_SystemLMap --
|
||||||
*
|
*
|
||||||
* Map a range of large (64MB) physical pages to virtual pages in the kernel
|
* Map a range of large (1GB) physical pages to virtual pages in the kernel
|
||||||
* address space that is shared by all processes.
|
* address space that is shared by all processes.
|
||||||
*
|
*
|
||||||
* @param [in] phys Physical address.
|
* @param [in] phys Physical address.
|
||||||
@ -263,6 +277,26 @@ PMap_SystemLookup(uint64_t va, PageEntry **entry, int size)
|
|||||||
bool
|
bool
|
||||||
PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
|
PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
|
||||||
{
|
{
|
||||||
|
// virt address must be within the dmap (l map) region
|
||||||
|
if (virt < MEM_DIRECTMAP_BASE && virt >= MEM_DIRECTMAP_TOP) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (i < lpages) {
|
||||||
|
// allocate a new pd
|
||||||
|
struct vmpd * pd = pdcache_alloc();
|
||||||
|
if (pd == NULL) {
|
||||||
|
// XXX: if this fails and not the first page to be mapped
|
||||||
|
// the this function inflicts side effects
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pd->vaddr = virt & ~((1ull << REGION_DMAP_PGSHIFT) - 1) + i * (1ull << REGION_DMAP_PGSHIFT);
|
||||||
|
pd->paddr = phys & ~((1ull << REGION_DMAP_PGSHIFT) - 1) + i * (1ull << REGION_DMAP_PGSHIFT);
|
||||||
|
pd->attr = flags;
|
||||||
|
|
||||||
|
// vm_insert_pd(systemAS.dmap_tbl, pd, REGION_DMAP_PGSHIFT, DMVA2PA(pd));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -284,7 +318,28 @@ PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags)
|
|||||||
bool
|
bool
|
||||||
PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
// virt address must be within the dmap (l map) region
|
||||||
|
if (virt < MEM_XMAP_BASE && virt >= MEM_XMAP_TOP) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int i = 0;
|
||||||
|
while (i < pages) {
|
||||||
|
// allocate a new pd
|
||||||
|
struct vmpd * pd = pdcache_alloc();
|
||||||
|
if (pd == NULL) {
|
||||||
|
// XXX: if this fails and not the first page to be mapped
|
||||||
|
// the this function inflicts side effects
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pd->vaddr = virt & ~((1ull << REGION_XMEM_PGSHIFT) - 1) + i * (1ull << REGION_XMEM_PGSHIFT);
|
||||||
|
pd->paddr = phys & ~((1ull << REGION_XMEM_PGSHIFT) - 1) + i * (1ull << REGION_XMEM_PGSHIFT);
|
||||||
|
pd->attr = flags;
|
||||||
|
|
||||||
|
// vm_insert_pd(systemAS.xmem_tbl, pd, REGION_XMEM_PGSHIFT, DMVA2PA(pd));
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -294,26 +349,20 @@ PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages, uint64_t flags)
|
|||||||
* We do not currently use this!
|
* We do not currently use this!
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
PMap_SystemUnmap(uint64_t virt, uint64_t pages)
|
PMap_SystemUnmap(UNUSED uint64_t virt, UNUSED uint64_t pages)
|
||||||
{
|
{
|
||||||
NOT_IMPLEMENTED();
|
NOT_IMPLEMENTED();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static uint64_t
|
|
||||||
// AddrFromIJKL(uint64_t i, uint64_t j, uint64_t k, uint64_t l)
|
|
||||||
// {
|
|
||||||
// return (i << 39) | (j << HUGE_PGSHIFT) | (k << LARGE_PGSHIFT) | (l << PGSHIFT);
|
|
||||||
// }
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PMap_Dump(AS *space)
|
PMap_Dump(UNUSED AS *space)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_PMapDump(int argc, const char *argv[])
|
Debug_PMapDump(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
PMap_Dump(currentAS[CPU()]);
|
PMap_Dump(currentAS[CPU()]);
|
||||||
}
|
}
|
||||||
|
@ -24,8 +24,8 @@ Thread_InitArch(Thread *thr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Thread_SetupKThread(Thread *thr, void (*f)(),
|
Thread_SetupKThread(Thread *thr, UNUSED void (*f)(void *),
|
||||||
uintptr_t arg1, uintptr_t arg2, uintptr_t arg3)
|
UNUSED uintptr_t arg1, UNUSED uintptr_t arg2, UNUSED uintptr_t arg3)
|
||||||
{
|
{
|
||||||
// Initialize stack
|
// Initialize stack
|
||||||
uint64_t stacktop = thr->kstack + PGSIZE;
|
uint64_t stacktop = thr->kstack + PGSIZE;
|
||||||
@ -43,7 +43,7 @@ Thread_SetupKThread(Thread *thr, void (*f)(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
ThreadEnterUserLevelCB(uintptr_t arg1, uintptr_t arg2, uintptr_t arg3)
|
ThreadEnterUserLevelCB(UNUSED void * unused)
|
||||||
{
|
{
|
||||||
TrapFrame tf;
|
TrapFrame tf;
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ Time_GetTSCFreq()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_ReadTSC(int argc, const char *argv[])
|
Debug_ReadTSC(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
kprintf("RDTSC: %lld\n", Time_GetTSC());
|
kprintf("RDTSC: %lld\n", Time_GetTSC());
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ trap_entry(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Traps(int argc, const char *argv[])
|
Debug_Traps(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ AHCI_IssueCommand(AHCI *ahci, int port, SGArray *sga, void *cfis, int len)
|
|||||||
memcpy((void *)&ct->cfis[0], cfis, len);
|
memcpy((void *)&ct->cfis[0], cfis, len);
|
||||||
|
|
||||||
// Convert SGArray into PRDT
|
// Convert SGArray into PRDT
|
||||||
int i;
|
unsigned int i;
|
||||||
for (i = 0; i < sga->len; i++)
|
for (i = 0; i < sga->len; i++)
|
||||||
{
|
{
|
||||||
ct->prdt[i].dba = sga->entries[i].offset;
|
ct->prdt[i].dba = sga->entries[i].offset;
|
||||||
|
@ -110,7 +110,7 @@ Panic(const char *str)
|
|||||||
void
|
void
|
||||||
Console_Gets(char *str, size_t n)
|
Console_Gets(char *str, size_t n)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < (n - 1); i++)
|
for (i = 0; i < (n - 1); i++)
|
||||||
{
|
{
|
||||||
@ -197,7 +197,7 @@ Console_Read(Handle *handle, void *buf, uint64_t off, uint64_t len)
|
|||||||
int
|
int
|
||||||
Console_Write(Handle *handle, void *buf, uint64_t off, uint64_t len)
|
Console_Write(Handle *handle, void *buf, uint64_t off, uint64_t len)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
uintptr_t b = (uintptr_t)buf;
|
uintptr_t b = (uintptr_t)buf;
|
||||||
char kbuf[512];
|
char kbuf[512];
|
||||||
uint64_t nbytes = 0;
|
uint64_t nbytes = 0;
|
||||||
|
@ -72,7 +72,7 @@ O2FS_Mount(Disk *disk)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read bitmap
|
// Read bitmap
|
||||||
for (int i = 0; i < sb->bitmapSize; i++) {
|
for (unsigned int i = 0; i < sb->bitmapSize; i++) {
|
||||||
ASSERT(i < 16);
|
ASSERT(i < 16);
|
||||||
|
|
||||||
BufCacheEntry *bentry;
|
BufCacheEntry *bentry;
|
||||||
@ -141,7 +141,7 @@ O2FSBAlloc(VFS *fs)
|
|||||||
|
|
||||||
bitmap = bentry->buffer;
|
bitmap = bentry->buffer;
|
||||||
// XXX: Check for end of disk
|
// XXX: Check for end of disk
|
||||||
for (int b = 0; b < fs->blksize; b++) {
|
for (unsigned int b = 0; b < fs->blksize; b++) {
|
||||||
for (int bi = 0; bi < 8; bi++) {
|
for (int bi = 0; bi < 8; bi++) {
|
||||||
if (((bitmap[b] >> bi) & 0x1) == 0) {
|
if (((bitmap[b] >> bi) & 0x1) == 0) {
|
||||||
/* Set bit */
|
/* Set bit */
|
||||||
@ -268,7 +268,7 @@ O2FSGrowVNode(VNode *vn, uint64_t filesz)
|
|||||||
if (filesz > (vfs->blksize * 64))
|
if (filesz > (vfs->blksize * 64))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
for (int i = 0; i < ((filesz + vfs->blksize - 1) / vfs->blksize); i++) {
|
for (unsigned int i = 0; i < ((filesz + vfs->blksize - 1) / vfs->blksize); i++) {
|
||||||
if (bn->direct[i].offset == 0) {
|
if (bn->direct[i].offset == 0) {
|
||||||
uint64_t blkno = O2FSBAlloc(vfs);
|
uint64_t blkno = O2FSBAlloc(vfs);
|
||||||
if (blkno == 0) {
|
if (blkno == 0) {
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
#define __printflike(_fmt, _var) __attribute__((__format__(__printf__, _fmt, _var)))
|
#define __printflike(_fmt, _var) __attribute__((__format__(__printf__, _fmt, _var)))
|
||||||
|
|
||||||
#define offsetof(st, m) \
|
#define offsetof(st, m) \
|
||||||
((size_t)((char *)&((st *)0)->m - (char *)0))
|
__builtin_offsetof(st, m)
|
||||||
|
|
||||||
#endif /* __CDEFS_H__ */
|
#endif /* __CDEFS_H__ */
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ uint32_t LAPIC_CPU();
|
|||||||
|
|
||||||
#define CPU LAPIC_CPU
|
#define CPU LAPIC_CPU
|
||||||
#elif defined(__aarch64__)
|
#elif defined(__aarch64__)
|
||||||
static inline int ARM_CPU()
|
static inline unsigned int ARM_CPU()
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ void Thread_Dump(Thread *thr);
|
|||||||
|
|
||||||
// Platform functions
|
// Platform functions
|
||||||
void Thread_InitArch(Thread *thr);
|
void Thread_InitArch(Thread *thr);
|
||||||
void Thread_SetupKThread(Thread *thr, void (*f)(),
|
void Thread_SetupKThread(Thread *thr, void (*f)(void *),
|
||||||
uintptr_t arg1, uintptr_t arg2, uintptr_t arg3);
|
uintptr_t arg1, uintptr_t arg2, uintptr_t arg3);
|
||||||
void Thread_SetupUThread(Thread *thr, uint64_t rip, uint64_t arg);
|
void Thread_SetupUThread(Thread *thr, uint64_t rip, uint64_t arg);
|
||||||
void Thread_SwitchArch(Thread *oldthr, Thread *newthr);
|
void Thread_SwitchArch(Thread *oldthr, Thread *newthr);
|
||||||
|
@ -282,7 +282,7 @@ BufCache_Write(BufCacheEntry *entry)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_BufCache(int argc, const char *argv[])
|
Debug_BufCache(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
kprintf("Hits: %lld\n", cacheHit);
|
kprintf("Hits: %lld\n", cacheHit);
|
||||||
kprintf("Misses: %lld\n", cacheMiss);
|
kprintf("Misses: %lld\n", cacheMiss);
|
||||||
|
@ -50,7 +50,7 @@ Critical_Level()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Critical(int argc, const char *argv[])
|
Debug_Critical(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ Debug_GetValue(uintptr_t addr, int size, bool isSigned)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Debug_PrintSymbol(uintptr_t off, int strategy)
|
Debug_PrintSymbol(uintptr_t off, UNUSED int strategy)
|
||||||
{
|
{
|
||||||
kprintf("0x%llx", off);
|
kprintf("0x%llx", off);
|
||||||
}
|
}
|
||||||
@ -169,9 +169,9 @@ extern DebugCommand __kdbgcmd_start[];
|
|||||||
extern DebugCommand __kdbgcmd_end[];
|
extern DebugCommand __kdbgcmd_end[];
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Help(int argc, const char *argv[])
|
Debug_Help(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
uintptr_t i;
|
||||||
uintptr_t commands = (uintptr_t)&__kdbgcmd_end - (uintptr_t)&__kdbgcmd_start;
|
uintptr_t commands = (uintptr_t)&__kdbgcmd_end - (uintptr_t)&__kdbgcmd_start;
|
||||||
commands /= sizeof(DebugCommand);
|
commands /= sizeof(DebugCommand);
|
||||||
DebugCommand *cmds = (DebugCommand *)&__kdbgcmd_start;
|
DebugCommand *cmds = (DebugCommand *)&__kdbgcmd_start;
|
||||||
@ -281,7 +281,7 @@ Debug_Prompt()
|
|||||||
return; // Continue
|
return; // Continue
|
||||||
} else {
|
} else {
|
||||||
// execute command
|
// execute command
|
||||||
int i;
|
uintptr_t i;
|
||||||
uintptr_t commands = (uintptr_t)&__kdbgcmd_end - (uintptr_t)&__kdbgcmd_start;
|
uintptr_t commands = (uintptr_t)&__kdbgcmd_end - (uintptr_t)&__kdbgcmd_start;
|
||||||
commands /= sizeof(DebugCommand);
|
commands /= sizeof(DebugCommand);
|
||||||
DebugCommand *cmds = (DebugCommand *)&__kdbgcmd_start;
|
DebugCommand *cmds = (DebugCommand *)&__kdbgcmd_start;
|
||||||
|
@ -59,7 +59,7 @@ Disk_Flush(Disk *disk, void *buf, SGArray *sga, DiskCB cb, void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Disks(int argc, const char *argv[])
|
Debug_Disks(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
Disk *d;
|
Disk *d;
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ KTimeDaysInMonth(uint64_t year, uint64_t month)
|
|||||||
void
|
void
|
||||||
KTime_Fixup(KTime *tm)
|
KTime_Fixup(KTime *tm)
|
||||||
{
|
{
|
||||||
uint64_t m;
|
int m;
|
||||||
|
|
||||||
if (tm->yday == -1) {
|
if (tm->yday == -1) {
|
||||||
uint64_t yday = 0;
|
uint64_t yday = 0;
|
||||||
@ -77,7 +77,7 @@ KTime_ToEpoch(const KTime *tm)
|
|||||||
{
|
{
|
||||||
uint64_t days = 0;
|
uint64_t days = 0;
|
||||||
uint64_t secs = 0;
|
uint64_t secs = 0;
|
||||||
uint64_t y, m;
|
int y, m;
|
||||||
|
|
||||||
// Convert to UNIX epoch
|
// Convert to UNIX epoch
|
||||||
for (y = 1970; y < tm->year; y++) {
|
for (y = 1970; y < tm->year; y++) {
|
||||||
@ -210,7 +210,7 @@ KTime_GetEpochNS()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Date()
|
Debug_Date(UNUSED int argc, UNUSED const char * argv[])
|
||||||
{
|
{
|
||||||
UnixEpoch epoch = KTime_GetEpoch();
|
UnixEpoch epoch = KTime_GetEpoch();
|
||||||
KTime tm;
|
KTime tm;
|
||||||
@ -227,7 +227,7 @@ Debug_Date()
|
|||||||
REGISTER_DBGCMD(date, "Print date", Debug_Date);
|
REGISTER_DBGCMD(date, "Print date", Debug_Date);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Debug_Ticks()
|
Debug_Ticks(UNUSED int argc, UNUSED const char * argv[])
|
||||||
{
|
{
|
||||||
kprintf("Ticks Per Second: %lu\n", ticksPerSecond);
|
kprintf("Ticks Per Second: %lu\n", ticksPerSecond);
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ memcpy(void *dst, const void *src, size_t length)
|
|||||||
int
|
int
|
||||||
memcmp(const void *b1, const void *b2, size_t length)
|
memcmp(const void *b1, const void *b2, size_t length)
|
||||||
{
|
{
|
||||||
int i;
|
size_t i;
|
||||||
const char *c1 = (const char *)b1;
|
const char *c1 = (const char *)b1;
|
||||||
const char *c2 = (const char *)b2;
|
const char *c2 = (const char *)b2;
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ LoaderZeroSegment(AS *as, uintptr_t vaddr, uintptr_t len)
|
|||||||
* Load the ELF binary into the process belonging to the thread.
|
* Load the ELF binary into the process belonging to the thread.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
Loader_Load(Thread *thr, VNode *vn, void *buf, uint64_t len)
|
Loader_Load(Thread *thr, VNode *vn, void *buf, UNUSED uint64_t len)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const Elf64_Ehdr *ehdr;
|
const Elf64_Ehdr *ehdr;
|
||||||
|
@ -43,7 +43,7 @@ NIC_GetByID(uint64_t nicNo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Debug_NICs(int argc, const char *argv[])
|
Debug_NICs(UNUSED int argc, UNUSED const char *argv[])
|
||||||
{
|
{
|
||||||
NIC *n;
|
NIC *n;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include <sys/semaphore.h>
|
#include <sys/semaphore.h>
|
||||||
#include <sys/thread.h>
|
#include <sys/thread.h>
|
||||||
|
|
||||||
Spinlock semaListLock = { 0, 0, 0, 0, 0, 0, 0, 0, "Semaphore List" };
|
Spinlock semaListLock = { 0, 0, 0, 0, 0, 0, 0, 0, "Semaphore List", {0}, {0}};
|
||||||
LIST_HEAD(SemaListHead, Semaphore) semaList = LIST_HEAD_INITIALIZER(semaList);
|
LIST_HEAD(SemaListHead, Semaphore) semaList = LIST_HEAD_INITIALIZER(semaList);
|
||||||
|
|
||||||
extern uint64_t ticksPerSecond;
|
extern uint64_t ticksPerSecond;
|
||||||
|
@ -29,7 +29,7 @@ SGArray_Append(SGArray *sga, uint64_t off, uint64_t len)
|
|||||||
void
|
void
|
||||||
SGArray_Dump(SGArray *sga)
|
SGArray_Dump(SGArray *sga)
|
||||||
{
|
{
|
||||||
int i;
|
unsigned int i;
|
||||||
|
|
||||||
kprintf("--- SGArray Begin ---\n");
|
kprintf("--- SGArray Begin ---\n");
|
||||||
for (i = 0; i < sga->len; i++)
|
for (i = 0; i < sga->len; i++)
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "sys/queue.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -16,12 +17,15 @@
|
|||||||
|
|
||||||
#include <machine/atomic.h>
|
#include <machine/atomic.h>
|
||||||
#include <machine/cpu.h>
|
#include <machine/cpu.h>
|
||||||
|
#include <machine/metal.h>
|
||||||
#include <machine/cpuop.h>
|
#include <machine/cpuop.h>
|
||||||
|
|
||||||
Spinlock lockListLock = {
|
Spinlock lockListLock = {
|
||||||
0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0,
|
||||||
SPINLOCK_TYPE_NORMAL,
|
SPINLOCK_TYPE_NORMAL,
|
||||||
"SPINLOCK LIST",
|
"SPINLOCK LIST",
|
||||||
|
{0},
|
||||||
|
{0}
|
||||||
};
|
};
|
||||||
LIST_HEAD(LockListHead, Spinlock) lockList = LIST_HEAD_INITIALIZER(lockList);
|
LIST_HEAD(LockListHead, Spinlock) lockList = LIST_HEAD_INITIALIZER(lockList);
|
||||||
|
|
||||||
@ -35,7 +39,7 @@ Spinlock_EarlyInit()
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
for (c = 0; c < MAX_CPUS; c++) {
|
for (c = 0; c < MAX_CPUS; c++) {
|
||||||
TAILQ_INIT(&lockStack[c]);
|
//TAILQ_INIT(&lockStack[c]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,16 +63,18 @@ XMem_New()
|
|||||||
void
|
void
|
||||||
XMem_Destroy(XMem *xmem)
|
XMem_Destroy(XMem *xmem)
|
||||||
{
|
{
|
||||||
uintptr_t off;
|
NOT_IMPLEMENTED();
|
||||||
PageEntry *entry;
|
|
||||||
|
|
||||||
for (off = 0; off < xmem->length; off += PGSIZE) {
|
// uintptr_t off;
|
||||||
PMap_SystemLookup(xmem->base + off, &entry, PGSIZE);
|
// PageEntry *entry;
|
||||||
|
|
||||||
// Compute DM
|
// for (off = 0; off < xmem->length; off += PGSIZE) {
|
||||||
|
// PMap_SystemLookup(xmem->base + off, &entry, PGSIZE);
|
||||||
|
|
||||||
// Free Page
|
// // Compute DM
|
||||||
}
|
|
||||||
|
// // Free Page
|
||||||
|
// }
|
||||||
|
|
||||||
//PMap_SystemUnmap(virt, pages);
|
//PMap_SystemUnmap(virt, pages);
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <syscall.h>
|
#include <syscall.h>
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, const char *argv[])
|
main(UNUSED int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int origpid[10], pid[10];
|
int origpid[10], pid[10];
|
||||||
const char *program;
|
const char *program;
|
||||||
|
Loading…
Reference in New Issue
Block a user