Type names (uint32 -> u32, e.t.c.)
This commit is contained in:
parent
f5b93ef12f
commit
362d5adeb2
39 changed files with 485 additions and 489 deletions
118
kernel/riscv.h
118
kernel/riscv.h
|
|
@ -1,10 +1,10 @@
|
|||
#ifndef __ASSEMBLER__
|
||||
|
||||
// which hart (core) is this?
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_mhartid()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, mhartid" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
|
@ -17,16 +17,16 @@ r_mhartid()
|
|||
#define MSTATUS_MPP_U (0L << 11)
|
||||
#define MSTATUS_MIE (1L << 3) // machine-mode interrupt enable.
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_mstatus()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, mstatus" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_mstatus(uint64 x)
|
||||
w_mstatus(u64 x)
|
||||
{
|
||||
asm volatile("csrw mstatus, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ w_mstatus(uint64 x)
|
|||
// instruction address to which a return from
|
||||
// exception will go.
|
||||
static inline void
|
||||
w_mepc(uint64 x)
|
||||
w_mepc(u64 x)
|
||||
{
|
||||
asm volatile("csrw mepc, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -48,31 +48,31 @@ w_mepc(uint64 x)
|
|||
#define SSTATUS_SIE (1L << 1) // Supervisor Interrupt Enable
|
||||
#define SSTATUS_UIE (1L << 0) // User Interrupt Enable
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_sstatus()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, sstatus" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_sstatus(uint64 x)
|
||||
w_sstatus(u64 x)
|
||||
{
|
||||
asm volatile("csrw sstatus, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
// Supervisor Interrupt Pending
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_sip()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, sip" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_sip(uint64 x)
|
||||
w_sip(u64 x)
|
||||
{
|
||||
asm volatile("csrw sip, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -81,16 +81,16 @@ w_sip(uint64 x)
|
|||
#define SIE_SEIE (1L << 9) // external
|
||||
#define SIE_STIE (1L << 5) // timer
|
||||
#define SIE_SSIE (1L << 1) // software
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_sie()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, sie" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_sie(uint64 x)
|
||||
w_sie(u64 x)
|
||||
{
|
||||
asm volatile("csrw sie, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -99,16 +99,16 @@ w_sie(uint64 x)
|
|||
#define MIE_MEIE (1L << 11) // external
|
||||
#define MIE_MTIE (1L << 7) // timer
|
||||
#define MIE_MSIE (1L << 3) // software
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_mie()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, mie" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_mie(uint64 x)
|
||||
w_mie(u64 x)
|
||||
{
|
||||
asm volatile("csrw mie, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -117,45 +117,45 @@ w_mie(uint64 x)
|
|||
// instruction address to which a return from
|
||||
// exception will go.
|
||||
static inline void
|
||||
w_sepc(uint64 x)
|
||||
w_sepc(u64 x)
|
||||
{
|
||||
asm volatile("csrw sepc, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_sepc()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, sepc" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// Machine Exception Delegation
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_medeleg()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, medeleg" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_medeleg(uint64 x)
|
||||
w_medeleg(u64 x)
|
||||
{
|
||||
asm volatile("csrw medeleg, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
// Machine Interrupt Delegation
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_mideleg()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, mideleg" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_mideleg(uint64 x)
|
||||
w_mideleg(u64 x)
|
||||
{
|
||||
asm volatile("csrw mideleg, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -163,35 +163,35 @@ w_mideleg(uint64 x)
|
|||
// Supervisor Trap-Vector Base Address
|
||||
// low two bits are mode.
|
||||
static inline void
|
||||
w_stvec(uint64 x)
|
||||
w_stvec(u64 x)
|
||||
{
|
||||
asm volatile("csrw stvec, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_stvec()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, stvec" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// Machine-mode interrupt vector
|
||||
static inline void
|
||||
w_mtvec(uint64 x)
|
||||
w_mtvec(u64 x)
|
||||
{
|
||||
asm volatile("csrw mtvec, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
// Physical Memory Protection
|
||||
static inline void
|
||||
w_pmpcfg0(uint64 x)
|
||||
w_pmpcfg0(u64 x)
|
||||
{
|
||||
asm volatile("csrw pmpcfg0, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_pmpaddr0(uint64 x)
|
||||
w_pmpaddr0(u64 x)
|
||||
{
|
||||
asm volatile("csrw pmpaddr0, %0" : : "r" (x));
|
||||
}
|
||||
|
|
@ -199,68 +199,68 @@ w_pmpaddr0(uint64 x)
|
|||
// use riscv's sv39 page table scheme.
|
||||
#define SATP_SV39 (8L << 60)
|
||||
|
||||
#define MAKE_SATP(pagetable) (SATP_SV39 | (((uint64)pagetable) >> 12))
|
||||
#define MAKE_SATP(pagetable) (SATP_SV39 | (((u64)pagetable) >> 12))
|
||||
|
||||
// supervisor address translation and protection;
|
||||
// holds the address of the page table.
|
||||
static inline void
|
||||
w_satp(uint64 x)
|
||||
w_satp(u64 x)
|
||||
{
|
||||
asm volatile("csrw satp, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_satp()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, satp" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_mscratch(uint64 x)
|
||||
w_mscratch(u64 x)
|
||||
{
|
||||
asm volatile("csrw mscratch, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
// Supervisor Trap Cause
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_scause()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, scause" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// Supervisor Trap Value
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_stval()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, stval" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// Machine-mode Counter-Enable
|
||||
static inline void
|
||||
w_mcounteren(uint64 x)
|
||||
w_mcounteren(u64 x)
|
||||
{
|
||||
asm volatile("csrw mcounteren, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_mcounteren()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, mcounteren" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// machine-mode cycle counter
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_time()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("csrr %0, time" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
|
@ -283,38 +283,38 @@ intr_off()
|
|||
static inline int
|
||||
intr_get()
|
||||
{
|
||||
uint64 x = r_sstatus();
|
||||
u64 x = r_sstatus();
|
||||
return (x & SSTATUS_SIE) != 0;
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_sp()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("mv %0, sp" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
// read and write tp, the thread pointer, which xv6 uses to hold
|
||||
// this core's hartid (core number), the index into cpus[].
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_tp()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("mv %0, tp" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
||||
static inline void
|
||||
w_tp(uint64 x)
|
||||
w_tp(u64 x)
|
||||
{
|
||||
asm volatile("mv tp, %0" : : "r" (x));
|
||||
}
|
||||
|
||||
static inline uint64
|
||||
static inline u64
|
||||
r_ra()
|
||||
{
|
||||
uint64 x;
|
||||
u64 x;
|
||||
asm volatile("mv %0, ra" : "=r" (x) );
|
||||
return x;
|
||||
}
|
||||
|
|
@ -327,8 +327,8 @@ sfence_vma()
|
|||
asm volatile("sfence.vma zero, zero");
|
||||
}
|
||||
|
||||
typedef uint64 pte_t;
|
||||
typedef uint64 *pagetable_t; // 512 PTEs
|
||||
typedef u64 pte_t;
|
||||
typedef u64 *pagetable_t; // 512 PTEs
|
||||
|
||||
#endif // __ASSEMBLER__
|
||||
|
||||
|
|
@ -345,7 +345,7 @@ typedef uint64 *pagetable_t; // 512 PTEs
|
|||
#define PTE_U (1L << 4) // user can access
|
||||
|
||||
// shift a physical address to the right place for a PTE.
|
||||
#define PA2PTE(pa) ((((uint64)pa) >> 12) << 10)
|
||||
#define PA2PTE(pa) ((((u64)pa) >> 12) << 10)
|
||||
|
||||
#define PTE2PA(pte) (((pte) >> 10) << 12)
|
||||
|
||||
|
|
@ -354,7 +354,7 @@ typedef uint64 *pagetable_t; // 512 PTEs
|
|||
// extract the three 9-bit page table indices from a virtual address.
|
||||
#define PXMASK 0x1FF // 9 bits
|
||||
#define PXSHIFT(level) (PGSHIFT+(9*(level)))
|
||||
#define PX(level, va) ((((uint64) (va)) >> PXSHIFT(level)) & PXMASK)
|
||||
#define PX(level, va) ((((u64) (va)) >> PXSHIFT(level)) & PXMASK)
|
||||
|
||||
// one beyond the highest possible virtual address.
|
||||
// MAXVA is actually one bit less than the max allowed by
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue