forked from xuos/xiuos
test cache
This commit is contained in:
parent
c60f29277a
commit
50dab7b553
|
@ -74,7 +74,7 @@ Modification:
|
||||||
|
|
||||||
#include "cortex_a9.h"
|
#include "cortex_a9.h"
|
||||||
|
|
||||||
#define NR_CPU 4
|
#define NR_CPU 1
|
||||||
|
|
||||||
__attribute__((always_inline)) static inline uint32_t user_mode()
|
__attribute__((always_inline)) static inline uint32_t user_mode()
|
||||||
{
|
{
|
||||||
|
|
|
@ -232,15 +232,15 @@ static struct DCacheDone dcache_done = {
|
||||||
struct ICacheDone* hardkernel_icache_init(struct TraceTag* hardkernel_tag)
|
struct ICacheDone* hardkernel_icache_init(struct TraceTag* hardkernel_tag)
|
||||||
{
|
{
|
||||||
/* init icache */
|
/* init icache */
|
||||||
// icache_done.enable();
|
icache_done.enable();
|
||||||
icache_done.disable();
|
// icache_done.disable();
|
||||||
return &icache_done;
|
return &icache_done;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DCacheDone* hardkernel_dcache_init(struct TraceTag* hardkernel_tag)
|
struct DCacheDone* hardkernel_dcache_init(struct TraceTag* hardkernel_tag)
|
||||||
{
|
{
|
||||||
/* init dcache */
|
/* init dcache */
|
||||||
// dcache_done.enable();
|
dcache_done.enable();
|
||||||
dcache_done.disable();
|
// dcache_done.disable();
|
||||||
return &dcache_done;
|
return &dcache_done;
|
||||||
}
|
}
|
|
@ -95,7 +95,9 @@ void handle_undefined_instruction(struct trapframe* tf)
|
||||||
extern void context_switch(struct context**, struct context*);
|
extern void context_switch(struct context**, struct context*);
|
||||||
void dabort_handler(struct trapframe* r)
|
void dabort_handler(struct trapframe* r)
|
||||||
{
|
{
|
||||||
|
if (!is_spinlock_locked(&whole_kernel_lock)) {
|
||||||
spinlock_lock(&whole_kernel_lock);
|
spinlock_lock(&whole_kernel_lock);
|
||||||
|
}
|
||||||
uint32_t dfs, dfa;
|
uint32_t dfs, dfa;
|
||||||
|
|
||||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 0" : "=r"(dfs)::);
|
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 0" : "=r"(dfs)::);
|
||||||
|
@ -120,7 +122,9 @@ void dabort_handler(struct trapframe* r)
|
||||||
|
|
||||||
void iabort_handler(struct trapframe* r)
|
void iabort_handler(struct trapframe* r)
|
||||||
{
|
{
|
||||||
|
if (!is_spinlock_locked(&whole_kernel_lock)) {
|
||||||
spinlock_lock(&whole_kernel_lock);
|
spinlock_lock(&whole_kernel_lock);
|
||||||
|
}
|
||||||
uint32_t ifs, ifa;
|
uint32_t ifs, ifa;
|
||||||
|
|
||||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 1" : "=r"(ifs)::);
|
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 1" : "=r"(ifs)::);
|
||||||
|
|
|
@ -20,7 +20,9 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
|
#include "multicores.h"
|
||||||
#include "spinlock.h"
|
#include "spinlock.h"
|
||||||
|
#include "task.h"
|
||||||
#include "trap_common.h"
|
#include "trap_common.h"
|
||||||
|
|
||||||
bool module_spinlock_use_intr_init(void)
|
bool module_spinlock_use_intr_init(void)
|
||||||
|
@ -56,3 +58,8 @@ void spinlock_unlock(struct spinlock* lock)
|
||||||
{
|
{
|
||||||
_spinlock_unlock(lock);
|
_spinlock_unlock(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_spinlock_locked(struct spinlock* lock)
|
||||||
|
{
|
||||||
|
return lock->owner_cpu != SPINLOCK_STATE_UNLOCK;
|
||||||
|
}
|
|
@ -42,3 +42,4 @@ bool module_spinlock_use_intr_init(void);
|
||||||
void spinlock_init(struct spinlock* lock, char* name);
|
void spinlock_init(struct spinlock* lock, char* name);
|
||||||
void spinlock_lock(struct spinlock* lock);
|
void spinlock_lock(struct spinlock* lock);
|
||||||
void spinlock_unlock(struct spinlock* lock);
|
void spinlock_unlock(struct spinlock* lock);
|
||||||
|
bool is_spinlock_locked(struct spinlock* lock);
|
|
@ -82,6 +82,11 @@ static void tlb_flush_range(uintptr_t vstart, int len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void tlb_flush_all()
|
||||||
|
{
|
||||||
|
CLEARTLB(0);
|
||||||
|
}
|
||||||
|
|
||||||
static struct MmuCommonDone mmu_common_done = {
|
static struct MmuCommonDone mmu_common_done = {
|
||||||
.MmuDevPteAttr = GetDevPteAttr,
|
.MmuDevPteAttr = GetDevPteAttr,
|
||||||
.MmuPdeAttr = GetPdeAttr,
|
.MmuPdeAttr = GetPdeAttr,
|
||||||
|
@ -91,6 +96,7 @@ static struct MmuCommonDone mmu_common_done = {
|
||||||
|
|
||||||
.LoadPgdirCrit = load_pgdir_critical,
|
.LoadPgdirCrit = load_pgdir_critical,
|
||||||
.LoadPgdir = load_pgdir,
|
.LoadPgdir = load_pgdir,
|
||||||
|
.TlbFlushAll = tlb_flush_all,
|
||||||
.TlbFlush = tlb_flush_range,
|
.TlbFlush = tlb_flush_range,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,20 +30,6 @@ Modification:
|
||||||
#include "mmu.h"
|
#include "mmu.h"
|
||||||
#include "mmu_common.h"
|
#include "mmu_common.h"
|
||||||
|
|
||||||
void GetDevPteAttr(uintptr_t* attr)
|
|
||||||
{
|
|
||||||
static char init = 0;
|
|
||||||
static PageTblEntry dev_pte_attr;
|
|
||||||
if (init == 0) {
|
|
||||||
init = 1;
|
|
||||||
|
|
||||||
dev_pte_attr.entry = 0;
|
|
||||||
dev_pte_attr.desc_type = PAGE_4K;
|
|
||||||
dev_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
|
||||||
}
|
|
||||||
*attr = dev_pte_attr.entry;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GetUsrPteAttr(uintptr_t* attr)
|
void GetUsrPteAttr(uintptr_t* attr)
|
||||||
{
|
{
|
||||||
static char init = 0;
|
static char init = 0;
|
||||||
|
@ -55,6 +41,7 @@ void GetUsrPteAttr(uintptr_t* attr)
|
||||||
usr_pte_attr.desc_type = PAGE_4K;
|
usr_pte_attr.desc_type = PAGE_4K;
|
||||||
usr_pte_attr.B = 1;
|
usr_pte_attr.B = 1;
|
||||||
usr_pte_attr.C = 1;
|
usr_pte_attr.C = 1;
|
||||||
|
usr_pte_attr.S = 1;
|
||||||
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
||||||
}
|
}
|
||||||
*attr = usr_pte_attr.entry;
|
*attr = usr_pte_attr.entry;
|
||||||
|
@ -68,12 +55,28 @@ void GetUsrDevPteAttr(uintptr_t* attr)
|
||||||
init = 1;
|
init = 1;
|
||||||
|
|
||||||
usr_pte_attr.entry = 0;
|
usr_pte_attr.entry = 0;
|
||||||
|
usr_pte_attr.S = 1;
|
||||||
usr_pte_attr.desc_type = PAGE_4K;
|
usr_pte_attr.desc_type = PAGE_4K;
|
||||||
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
||||||
}
|
}
|
||||||
*attr = usr_pte_attr.entry;
|
*attr = usr_pte_attr.entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GetDevPteAttr(uintptr_t* attr)
|
||||||
|
{
|
||||||
|
static char init = 0;
|
||||||
|
static PageTblEntry dev_pte_attr;
|
||||||
|
if (init == 0) {
|
||||||
|
init = 1;
|
||||||
|
|
||||||
|
dev_pte_attr.entry = 0;
|
||||||
|
dev_pte_attr.S = 1;
|
||||||
|
dev_pte_attr.desc_type = PAGE_4K;
|
||||||
|
dev_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
||||||
|
}
|
||||||
|
*attr = dev_pte_attr.entry;
|
||||||
|
}
|
||||||
|
|
||||||
void GetKernPteAttr(uintptr_t* attr)
|
void GetKernPteAttr(uintptr_t* attr)
|
||||||
{
|
{
|
||||||
static char init = 0;
|
static char init = 0;
|
||||||
|
@ -85,6 +88,7 @@ void GetKernPteAttr(uintptr_t* attr)
|
||||||
kern_pte_attr.desc_type = PAGE_4K;
|
kern_pte_attr.desc_type = PAGE_4K;
|
||||||
kern_pte_attr.B = 1;
|
kern_pte_attr.B = 1;
|
||||||
kern_pte_attr.C = 1;
|
kern_pte_attr.C = 1;
|
||||||
|
kern_pte_attr.S = 1;
|
||||||
kern_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
kern_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
||||||
}
|
}
|
||||||
*attr = kern_pte_attr.entry;
|
*attr = kern_pte_attr.entry;
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct MmuCommonDone
|
||||||
|
|
||||||
void (*LoadPgdirCrit)(uintptr_t pgdir_paddr, struct TraceTag*);
|
void (*LoadPgdirCrit)(uintptr_t pgdir_paddr, struct TraceTag*);
|
||||||
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
||||||
|
void (*TlbFlushAll)();
|
||||||
void (*TlbFlush)(uintptr_t vaddr, int len);
|
void (*TlbFlush)(uintptr_t vaddr, int len);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,11 +19,10 @@
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
struct Session session;
|
struct Session session;
|
||||||
printf("connecting MemFS\n");
|
printf("init: connecting MemFS\n");
|
||||||
while (connect_session(&session, "MemFS", 8092) < 0) {
|
while (connect_session(&session, "MemFS", 8092) < 0)
|
||||||
printf("connecting MemFS\n");
|
;
|
||||||
}
|
printf("init: connect MemFS success\n");
|
||||||
printf("connect MemFS success\n");
|
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
char* shell_task_param[2] = { "/shell", 0 };
|
char* shell_task_param[2] = { "/shell", 0 };
|
||||||
|
|
|
@ -58,18 +58,6 @@ void configure_cpu(uint32_t cpu)
|
||||||
// arm_icache_enable();
|
// arm_icache_enable();
|
||||||
// arm_icache_invalidate();
|
// arm_icache_invalidate();
|
||||||
|
|
||||||
// struct TraceTag main_icache_tag, main_dcache_tag;
|
|
||||||
// AchieveResourceTag(&main_icache_tag, &hardkernel_tag, "icache-ac-resource");
|
|
||||||
// AchieveResourceTag(&main_dcache_tag, &hardkernel_tag, "dcache-ac-resource");
|
|
||||||
// struct ICacheDone* p_icache_driver = AchieveResource(&main_icache_tag);
|
|
||||||
// struct DCacheDone* p_dcache_driver = AchieveResource(&main_dcache_tag);
|
|
||||||
// // p_dcache_driver->enable();
|
|
||||||
// // p_dcache_driver->invalidateall();
|
|
||||||
// // p_icache_driver->enable();
|
|
||||||
// // p_icache_driver->invalidateall();
|
|
||||||
// p_dcache_driver->disable();
|
|
||||||
// p_icache_driver->disable();
|
|
||||||
|
|
||||||
// Invalidate SCU copy of TAG RAMs
|
// Invalidate SCU copy of TAG RAMs
|
||||||
scu_secure_invalidate(cpu, all_ways);
|
scu_secure_invalidate(cpu, all_ways);
|
||||||
|
|
||||||
|
@ -138,7 +126,6 @@ int main(void)
|
||||||
show_xizi_bar();
|
show_xizi_bar();
|
||||||
|
|
||||||
int cpu_count = NR_CPU;
|
int cpu_count = NR_CPU;
|
||||||
;
|
|
||||||
for (int i = 1; i < cpu_count; i++) {
|
for (int i = 1; i < cpu_count; i++) {
|
||||||
// start secondary cpus
|
// start secondary cpus
|
||||||
cpu_start_secondary(i);
|
cpu_start_secondary(i);
|
||||||
|
@ -156,12 +143,38 @@ int main(void)
|
||||||
assert(AchieveResourceTag(&scheduler_rights.mmu_driver_tag, &hardkernel_tag, "mmu-ac-resource"));
|
assert(AchieveResourceTag(&scheduler_rights.mmu_driver_tag, &hardkernel_tag, "mmu-ac-resource"));
|
||||||
assert(AchieveResourceTag(&scheduler_rights.intr_driver_tag, &hardkernel_tag, "intr-ac-resource"));
|
assert(AchieveResourceTag(&scheduler_rights.intr_driver_tag, &hardkernel_tag, "intr-ac-resource"));
|
||||||
|
|
||||||
|
struct TraceTag main_icache_tag, main_dcache_tag;
|
||||||
|
AchieveResourceTag(&main_icache_tag, &hardkernel_tag, "icache-ac-resource");
|
||||||
|
AchieveResourceTag(&main_dcache_tag, &hardkernel_tag, "dcache-ac-resource");
|
||||||
|
struct ICacheDone* p_icache_driver = AchieveResource(&main_icache_tag);
|
||||||
|
struct DCacheDone* p_dcache_driver = AchieveResource(&main_dcache_tag);
|
||||||
|
|
||||||
core_init_done |= (1 << cpu_id);
|
core_init_done |= (1 << cpu_id);
|
||||||
LOG_PRINTF("CPU %d init done\n", cpu_id);
|
LOG_PRINTF("CPU %d init done\n", cpu_id);
|
||||||
spinlock_unlock(&whole_kernel_lock);
|
spinlock_unlock(&whole_kernel_lock);
|
||||||
|
|
||||||
while (core_init_done != (1 << NR_CPU) - 1)
|
while (core_init_done != (1 << NR_CPU) - 1)
|
||||||
;
|
;
|
||||||
|
DEBUG_PRINTF("%d", cpu_id);
|
||||||
|
|
||||||
|
// scu_enable();
|
||||||
|
// configure_cpu(cpu_id);
|
||||||
|
// p_dcache_driver->enable();
|
||||||
|
// p_icache_driver->enable();
|
||||||
|
|
||||||
|
// spinlock_lock(&whole_kernel_lock);
|
||||||
|
// p_dcache_driver->flushall();
|
||||||
|
// spinlock_unlock(&whole_kernel_lock);
|
||||||
|
|
||||||
|
// while (true) {
|
||||||
|
// spinlock_lock(&whole_kernel_lock);
|
||||||
|
// DEBUG("CPU: %d\n", cpu_id);
|
||||||
|
// secondary_cpu_load_kern_pgdir(&scheduler_rights.mmu_driver_tag, NULL);
|
||||||
|
// CLEARTLB(0);
|
||||||
|
// p_dcache_driver->flushall();
|
||||||
|
// spinlock_unlock(&whole_kernel_lock);
|
||||||
|
// }
|
||||||
|
|
||||||
xizi_task_manager.task_scheduler(scheduler_rights);
|
xizi_task_manager.task_scheduler(scheduler_rights);
|
||||||
|
|
||||||
// never reached
|
// never reached
|
||||||
|
|
|
@ -105,8 +105,10 @@ static uintptr_t map_task_share_page(struct TaskMicroDescriptor* task, const uin
|
||||||
}
|
}
|
||||||
if (task == cur_cpu()->task) {
|
if (task == cur_cpu()->task) {
|
||||||
p_mmu_driver->TlbFlush(vaddr, 2 * nr_pages * PAGE_SIZE);
|
p_mmu_driver->TlbFlush(vaddr, 2 * nr_pages * PAGE_SIZE);
|
||||||
|
|
||||||
/// @todo clean range rather than all
|
/// @todo clean range rather than all
|
||||||
p_dcache_done->flushall();
|
// p_dcache_done->flushall();
|
||||||
|
p_dcache_done->invalidateall();
|
||||||
// p_dcache_done->flush(vaddr, vaddr + 2 * nr_pages * PAGE_SIZE);
|
// p_dcache_done->flush(vaddr, vaddr + 2 * nr_pages * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
return vaddr;
|
return vaddr;
|
||||||
|
@ -129,8 +131,10 @@ uintptr_t task_map_pages(struct TaskMicroDescriptor* task, const uintptr_t vaddr
|
||||||
}
|
}
|
||||||
if (task == cur_cpu()->task) {
|
if (task == cur_cpu()->task) {
|
||||||
p_mmu_driver->TlbFlush(vaddr, nr_pages * PAGE_SIZE);
|
p_mmu_driver->TlbFlush(vaddr, nr_pages * PAGE_SIZE);
|
||||||
|
|
||||||
/// @todo clean range rather than all
|
/// @todo clean range rather than all
|
||||||
p_dcache_done->flushall();
|
// p_dcache_done->flushall();
|
||||||
|
p_dcache_done->invalidateall();
|
||||||
// p_dcache_done->flush(vaddr, vaddr + nr_pages * PAGE_SIZE);
|
// p_dcache_done->flush(vaddr, vaddr + nr_pages * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,8 +151,10 @@ void unmap_task_share_pages(struct TaskMicroDescriptor* task, const uintptr_t ta
|
||||||
xizi_pager.unmap_pages(task->pgdir.pd_addr, task_vaddr + (nr_pages * PAGE_SIZE), nr_pages * PAGE_SIZE);
|
xizi_pager.unmap_pages(task->pgdir.pd_addr, task_vaddr + (nr_pages * PAGE_SIZE), nr_pages * PAGE_SIZE);
|
||||||
if (task == cur_cpu()->task) {
|
if (task == cur_cpu()->task) {
|
||||||
p_mmu_driver->TlbFlush(task_vaddr, 2 * nr_pages * PAGE_SIZE);
|
p_mmu_driver->TlbFlush(task_vaddr, 2 * nr_pages * PAGE_SIZE);
|
||||||
|
|
||||||
/// @todo clean range rather than all
|
/// @todo clean range rather than all
|
||||||
p_dcache_done->flushall();
|
// p_dcache_done->flushall();
|
||||||
|
p_dcache_done->invalidateall();
|
||||||
// p_dcache_done->flush(task_vaddr, task_vaddr + 2 * nr_pages * PAGE_SIZE);
|
// p_dcache_done->flush(task_vaddr, task_vaddr + 2 * nr_pages * PAGE_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,6 @@ void intr_irq_dispatch(struct trapframe* tf)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
spinlock_lock(&whole_kernel_lock);
|
spinlock_lock(&whole_kernel_lock);
|
||||||
DSB();
|
|
||||||
// DEBUG("CPU %d in\n", cur_cpuid());
|
|
||||||
|
|
||||||
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
|
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
|
||||||
if (LIKELY(current_task != NULL)) {
|
if (LIKELY(current_task != NULL)) {
|
||||||
|
@ -95,7 +93,6 @@ void intr_irq_dispatch(struct trapframe* tf)
|
||||||
}
|
}
|
||||||
assert(current_task == cur_cpu()->task);
|
assert(current_task == cur_cpu()->task);
|
||||||
|
|
||||||
// DEBUG("CPU %d out\n", cur_cpuid());
|
|
||||||
spinlock_unlock(&whole_kernel_lock);
|
spinlock_unlock(&whole_kernel_lock);
|
||||||
p_intr_driver->cpu_irq_enable();
|
p_intr_driver->cpu_irq_enable();
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,8 +53,7 @@ void software_irq_dispatch(struct trapframe* tf)
|
||||||
|
|
||||||
p_intr_driver->cpu_irq_disable();
|
p_intr_driver->cpu_irq_disable();
|
||||||
spinlock_lock(&whole_kernel_lock);
|
spinlock_lock(&whole_kernel_lock);
|
||||||
DSB();
|
|
||||||
// DEBUG("CPU %d in\n", cur_cpuid());
|
|
||||||
// get current task
|
// get current task
|
||||||
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
|
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
|
||||||
/// @todo: Handle dead task
|
/// @todo: Handle dead task
|
||||||
|
@ -81,7 +80,6 @@ void software_irq_dispatch(struct trapframe* tf)
|
||||||
panic("Exit reaches");
|
panic("Exit reaches");
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG("CPU %d out\n", cur_cpuid());
|
|
||||||
spinlock_unlock(&whole_kernel_lock);
|
spinlock_unlock(&whole_kernel_lock);
|
||||||
p_intr_driver->cpu_irq_enable();
|
p_intr_driver->cpu_irq_enable();
|
||||||
}
|
}
|
Loading…
Reference in New Issue