forked from xuos/xiuos
test cache
This commit is contained in:
parent
c60f29277a
commit
50dab7b553
|
@ -74,7 +74,7 @@ Modification:
|
|||
|
||||
#include "cortex_a9.h"
|
||||
|
||||
#define NR_CPU 4
|
||||
#define NR_CPU 1
|
||||
|
||||
__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)
|
||||
{
|
||||
/* init icache */
|
||||
// icache_done.enable();
|
||||
icache_done.disable();
|
||||
icache_done.enable();
|
||||
// icache_done.disable();
|
||||
return &icache_done;
|
||||
}
|
||||
|
||||
struct DCacheDone* hardkernel_dcache_init(struct TraceTag* hardkernel_tag)
|
||||
{
|
||||
/* init dcache */
|
||||
// dcache_done.enable();
|
||||
dcache_done.disable();
|
||||
dcache_done.enable();
|
||||
// dcache_done.disable();
|
||||
return &dcache_done;
|
||||
}
|
|
@ -95,7 +95,9 @@ void handle_undefined_instruction(struct trapframe* tf)
|
|||
extern void context_switch(struct context**, struct context*);
|
||||
void dabort_handler(struct trapframe* r)
|
||||
{
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
if (!is_spinlock_locked(&whole_kernel_lock)) {
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
}
|
||||
uint32_t dfs, dfa;
|
||||
|
||||
__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)
|
||||
{
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
if (!is_spinlock_locked(&whole_kernel_lock)) {
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
}
|
||||
uint32_t ifs, ifa;
|
||||
|
||||
__asm__ __volatile__("mrc p15, 0, %0, c5, c0, 1" : "=r"(ifs)::);
|
||||
|
|
|
@ -20,7 +20,9 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "assert.h"
|
||||
#include "multicores.h"
|
||||
#include "spinlock.h"
|
||||
#include "task.h"
|
||||
#include "trap_common.h"
|
||||
|
||||
bool module_spinlock_use_intr_init(void)
|
||||
|
@ -55,4 +57,9 @@ void _spinlock_unlock(struct spinlock* lock);
|
|||
void spinlock_unlock(struct spinlock* lock)
|
||||
{
|
||||
_spinlock_unlock(lock);
|
||||
}
|
||||
|
||||
bool is_spinlock_locked(struct spinlock* lock)
|
||||
{
|
||||
return lock->owner_cpu != SPINLOCK_STATE_UNLOCK;
|
||||
}
|
|
@ -41,4 +41,5 @@ struct spinlock { // Mutex.
|
|||
bool module_spinlock_use_intr_init(void);
|
||||
void spinlock_init(struct spinlock* lock, char* name);
|
||||
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 = {
|
||||
.MmuDevPteAttr = GetDevPteAttr,
|
||||
.MmuPdeAttr = GetPdeAttr,
|
||||
|
@ -91,6 +96,7 @@ static struct MmuCommonDone mmu_common_done = {
|
|||
|
||||
.LoadPgdirCrit = load_pgdir_critical,
|
||||
.LoadPgdir = load_pgdir,
|
||||
.TlbFlushAll = tlb_flush_all,
|
||||
.TlbFlush = tlb_flush_range,
|
||||
};
|
||||
|
||||
|
|
|
@ -30,20 +30,6 @@ Modification:
|
|||
#include "mmu.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)
|
||||
{
|
||||
static char init = 0;
|
||||
|
@ -55,6 +41,7 @@ void GetUsrPteAttr(uintptr_t* attr)
|
|||
usr_pte_attr.desc_type = PAGE_4K;
|
||||
usr_pte_attr.B = 1;
|
||||
usr_pte_attr.C = 1;
|
||||
usr_pte_attr.S = 1;
|
||||
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
||||
}
|
||||
*attr = usr_pte_attr.entry;
|
||||
|
@ -68,12 +55,28 @@ void GetUsrDevPteAttr(uintptr_t* attr)
|
|||
init = 1;
|
||||
|
||||
usr_pte_attr.entry = 0;
|
||||
usr_pte_attr.S = 1;
|
||||
usr_pte_attr.desc_type = PAGE_4K;
|
||||
usr_pte_attr.AP1_0 = AccessPermission_KernelUser;
|
||||
}
|
||||
*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)
|
||||
{
|
||||
static char init = 0;
|
||||
|
@ -85,6 +88,7 @@ void GetKernPteAttr(uintptr_t* attr)
|
|||
kern_pte_attr.desc_type = PAGE_4K;
|
||||
kern_pte_attr.B = 1;
|
||||
kern_pte_attr.C = 1;
|
||||
kern_pte_attr.S = 1;
|
||||
kern_pte_attr.AP1_0 = AccessPermission_KernelOnly;
|
||||
}
|
||||
*attr = kern_pte_attr.entry;
|
||||
|
|
|
@ -29,6 +29,7 @@ struct MmuCommonDone
|
|||
|
||||
void (*LoadPgdirCrit)(uintptr_t pgdir_paddr, struct TraceTag*);
|
||||
void (*LoadPgdir)(uintptr_t pgdir_paddr);
|
||||
void (*TlbFlushAll)();
|
||||
void (*TlbFlush)(uintptr_t vaddr, int len);
|
||||
};
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@
|
|||
int main(int argc, char* argv[])
|
||||
{
|
||||
struct Session session;
|
||||
printf("connecting MemFS\n");
|
||||
while (connect_session(&session, "MemFS", 8092) < 0) {
|
||||
printf("connecting MemFS\n");
|
||||
}
|
||||
printf("connect MemFS success\n");
|
||||
printf("init: connecting MemFS\n");
|
||||
while (connect_session(&session, "MemFS", 8092) < 0)
|
||||
;
|
||||
printf("init: connect MemFS success\n");
|
||||
|
||||
int fd;
|
||||
char* shell_task_param[2] = { "/shell", 0 };
|
||||
|
|
|
@ -58,18 +58,6 @@ void configure_cpu(uint32_t cpu)
|
|||
// arm_icache_enable();
|
||||
// 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
|
||||
scu_secure_invalidate(cpu, all_ways);
|
||||
|
||||
|
@ -138,7 +126,6 @@ int main(void)
|
|||
show_xizi_bar();
|
||||
|
||||
int cpu_count = NR_CPU;
|
||||
;
|
||||
for (int i = 1; i < cpu_count; i++) {
|
||||
// start secondary cpus
|
||||
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.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);
|
||||
LOG_PRINTF("CPU %d init done\n", cpu_id);
|
||||
spinlock_unlock(&whole_kernel_lock);
|
||||
|
||||
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);
|
||||
|
||||
// never reached
|
||||
|
|
|
@ -105,8 +105,10 @@ static uintptr_t map_task_share_page(struct TaskMicroDescriptor* task, const uin
|
|||
}
|
||||
if (task == cur_cpu()->task) {
|
||||
p_mmu_driver->TlbFlush(vaddr, 2 * nr_pages * PAGE_SIZE);
|
||||
|
||||
/// @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);
|
||||
}
|
||||
return vaddr;
|
||||
|
@ -129,8 +131,10 @@ uintptr_t task_map_pages(struct TaskMicroDescriptor* task, const uintptr_t vaddr
|
|||
}
|
||||
if (task == cur_cpu()->task) {
|
||||
p_mmu_driver->TlbFlush(vaddr, nr_pages * PAGE_SIZE);
|
||||
|
||||
/// @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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
if (task == cur_cpu()->task) {
|
||||
p_mmu_driver->TlbFlush(task_vaddr, 2 * nr_pages * PAGE_SIZE);
|
||||
|
||||
/// @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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,6 @@ void intr_irq_dispatch(struct trapframe* tf)
|
|||
return;
|
||||
}
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
DSB();
|
||||
// DEBUG("CPU %d in\n", cur_cpuid());
|
||||
|
||||
struct TaskMicroDescriptor* current_task = cur_cpu()->task;
|
||||
if (LIKELY(current_task != NULL)) {
|
||||
|
@ -95,7 +93,6 @@ void intr_irq_dispatch(struct trapframe* tf)
|
|||
}
|
||||
assert(current_task == cur_cpu()->task);
|
||||
|
||||
// DEBUG("CPU %d out\n", cur_cpuid());
|
||||
spinlock_unlock(&whole_kernel_lock);
|
||||
p_intr_driver->cpu_irq_enable();
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ void software_irq_dispatch(struct trapframe* tf)
|
|||
|
||||
p_intr_driver->cpu_irq_disable();
|
||||
spinlock_lock(&whole_kernel_lock);
|
||||
DSB();
|
||||
// DEBUG("CPU %d in\n", cur_cpuid());
|
||||
|
||||
// get current task
|
||||
struct TaskMicroDescriptor* cur_task = cur_cpu()->task;
|
||||
/// @todo: Handle dead task
|
||||
|
@ -81,7 +80,6 @@ void software_irq_dispatch(struct trapframe* tf)
|
|||
panic("Exit reaches");
|
||||
}
|
||||
|
||||
// DEBUG("CPU %d out\n", cur_cpuid());
|
||||
spinlock_unlock(&whole_kernel_lock);
|
||||
p_intr_driver->cpu_irq_enable();
|
||||
}
|
Loading…
Reference in New Issue