fix kernel
This commit is contained in:
parent
d2f42f7366
commit
f2430e99bb
|
@ -2,7 +2,8 @@
|
|||
|
||||
#include "include/types.h"
|
||||
#include "include/fpioa.h"
|
||||
|
||||
#include "include/riscv.h"
|
||||
#include "include/defs.h"
|
||||
/* Copyright 2018 Canaan Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
@ -4935,4 +4936,5 @@ void fpioa_pin_init() {
|
|||
fpioa_set_function(26, FUNC_SPI0_D1);
|
||||
fpioa_set_function(32, FUNC_GPIOHS7);
|
||||
fpioa_set_function(29, FUNC_SPI0_SS3);
|
||||
printf("fpioa_pin_init\n");
|
||||
}
|
|
@ -113,7 +113,7 @@ void yield(void);
|
|||
int either_copyout(int user_dst, uint64 dst, void *src, uint64 len);
|
||||
int either_copyin(void *dst, int user_src, uint64 src, uint64 len);
|
||||
void procdump(void);
|
||||
void test_proc_init(void);
|
||||
void test_proc_init(int);
|
||||
|
||||
// swtch.S
|
||||
void swtch(struct context*, struct context*);
|
||||
|
|
|
@ -43,16 +43,13 @@ main(unsigned long hartid, unsigned long dtb_pa)
|
|||
// fileinit(); // file table
|
||||
//virtio_disk_init(); // emulated hard disk
|
||||
// userinit(); // first user process
|
||||
test_proc_init(); // test porc init
|
||||
test_proc_init(5); // test porc init
|
||||
|
||||
// test_kalloc(); // test kalloc
|
||||
// test_vm(hartid); // test kernel pagetable
|
||||
test_kalloc(); // test kalloc
|
||||
test_vm(hartid); // test kernel pagetable
|
||||
// test_sdcard();
|
||||
|
||||
printf("hart 0 init done\n");
|
||||
// scheduler();
|
||||
// while (1) {
|
||||
// }
|
||||
for(int i = 1; i < NCPU; i++) {
|
||||
unsigned long mask = 1 << i;
|
||||
sbi_send_ipi(&mask);
|
||||
|
@ -66,11 +63,11 @@ main(unsigned long hartid, unsigned long dtb_pa)
|
|||
;
|
||||
__sync_synchronize();
|
||||
printfinit(); // init a lock for printf
|
||||
// printf("hart %d enter main()...\n", hartid);
|
||||
printf("hart %d enter main()...\n", hartid);
|
||||
kvminithart();
|
||||
trapinithart();
|
||||
device_init(dtb_pa, hartid);
|
||||
// printf("hart 1 init done\n");
|
||||
printf("hart 1 init done\n");
|
||||
}
|
||||
scheduler();
|
||||
|
||||
|
|
|
@ -244,56 +244,20 @@ uchar printhello[] = {
|
|||
};
|
||||
|
||||
|
||||
void test_proc_init() {
|
||||
void test_proc_init(int proc_num) {
|
||||
if(proc_num > NPROC) panic("test_proc_init\n");
|
||||
struct proc *p;
|
||||
|
||||
for(int i = 0; i < proc_num; i++) {
|
||||
p = allocproc();
|
||||
initproc = p;
|
||||
|
||||
uvminit(p->pagetable, (uchar*)printhello, sizeof(printhello));
|
||||
p->sz = PGSIZE;
|
||||
|
||||
p->trapframe->epc = 0x0;
|
||||
p->trapframe->sp = PGSIZE;
|
||||
|
||||
safestrcpy(p->name, "test_code_0", sizeof(p->name));
|
||||
|
||||
safestrcpy(p->name, "test_code", sizeof(p->name));
|
||||
p->state = RUNNABLE;
|
||||
|
||||
release(&p->lock);
|
||||
|
||||
struct proc *p1;
|
||||
|
||||
p1 = allocproc();
|
||||
|
||||
uvminit(p1->pagetable, (uchar*)printhello, sizeof(printhello));
|
||||
p1->sz = PGSIZE;
|
||||
|
||||
p1->trapframe->epc = 0x0;
|
||||
p1->trapframe->sp = PGSIZE;
|
||||
|
||||
safestrcpy(p1->name, "test_code_1", sizeof(p1->name));
|
||||
|
||||
p1->state = RUNNABLE;
|
||||
|
||||
release(&p1->lock);
|
||||
|
||||
struct proc *p2;
|
||||
|
||||
p2 = allocproc();
|
||||
|
||||
uvminit(p2->pagetable, (uchar*)printhello, sizeof(printhello));
|
||||
p2->sz = PGSIZE;
|
||||
|
||||
p2->trapframe->epc = 0x0;
|
||||
p2->trapframe->sp = PGSIZE;
|
||||
|
||||
safestrcpy(p2->name, "test_code_2", sizeof(p2->name));
|
||||
|
||||
p2->state = RUNNABLE;
|
||||
|
||||
release(&p2->lock);
|
||||
|
||||
}
|
||||
initproc = proc;
|
||||
printf("[test_proc]test_proc init done\n");
|
||||
}
|
||||
|
||||
|
@ -640,7 +604,7 @@ forkret(void)
|
|||
first = 0;
|
||||
// fsinit(ROOTDEV);
|
||||
}
|
||||
printf("[forket]call usertrapret\n");
|
||||
// printf("[forket]call usertrapret\n");
|
||||
usertrapret();
|
||||
}
|
||||
|
||||
|
|
|
@ -151,6 +151,6 @@ syscall(void)
|
|||
|
||||
uint64
|
||||
sys_test(void) {
|
||||
printf("hello world from proc %d\n", myproc()->pid);
|
||||
printf("hello world from proc %d, core %d\n", myproc()->pid, r_tp());
|
||||
return 0;
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
#include "include/sbi.h"
|
||||
#include "include/sdcard.h"
|
||||
|
||||
extern uint64 etext;
|
||||
extern char etext[];
|
||||
extern struct proc *initproc;
|
||||
void test_kalloc() {
|
||||
char *mem = kalloc();
|
||||
|
@ -21,31 +21,6 @@ void test_kalloc() {
|
|||
kfree(mem);
|
||||
}
|
||||
|
||||
void ptesprint(pagetable_t pagetable, int level){
|
||||
// there are 2^9 = 512 PTEs in a page table.
|
||||
for(int i = 0; i < 512; i++){
|
||||
pte_t pte = pagetable[i];
|
||||
if(pte & PTE_V){
|
||||
for(int j = 0; j < level-1; j++)
|
||||
printf(".. ");
|
||||
printf("..%d: pte %p pa %p\n", i, pte, PTE2PA(pte));
|
||||
}
|
||||
if((pte & PTE_V) && (pte & (PTE_R|PTE_W|PTE_X)) == 0){
|
||||
// this PTE points to a lower-level page table.
|
||||
uint64 child = PTE2PA(pte);
|
||||
ptesprint((pagetable_t)child, level+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int vmprint(pagetable_t pagetable){
|
||||
|
||||
printf("page table %p\n", pagetable);
|
||||
ptesprint(pagetable, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_vm(unsigned long hart_id) {
|
||||
printf("[test_vm]UART:\n");
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", UART0, kvmpa(UART0));
|
||||
|
@ -71,10 +46,10 @@ void test_vm(unsigned long hart_id) {
|
|||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", KERNBASE + 0x2000, kvmpa(KERNBASE + 0x2000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", KERNBASE + 0x3000, kvmpa(KERNBASE + 0x3000));
|
||||
printf("[test_vm]etext:\n");
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", etext, kvmpa(etext));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", etext + 0x1000, kvmpa(etext + 0x1000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", etext + 0x2000, kvmpa(etext + 0x2000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", etext + 0x3000, kvmpa(etext + 0x3000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", (uint64)etext, kvmpa((uint64)etext));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", (uint64)etext + 0x1000, kvmpa((uint64)etext + 0x1000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", (uint64)etext + 0x2000, kvmpa((uint64)etext + 0x2000));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", (uint64)etext + 0x3000, kvmpa((uint64)etext + 0x3000));
|
||||
printf("[test_vm]trampoline:\n");
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", TRAMPOLINE, kvmpa(TRAMPOLINE));
|
||||
printf("[test_vm](kvmpa) va: %p, pa: %p\n", TRAMPOLINE + PGSIZE - 1, kvmpa(TRAMPOLINE + PGSIZE - 1));
|
||||
|
|
|
@ -231,7 +231,8 @@ devintr()
|
|||
w_sip(r_sip() & ~2);
|
||||
|
||||
return 2;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -227,9 +227,9 @@ uvminit(pagetable_t pagetable, uchar *src, uint sz)
|
|||
memset(mem, 0, PGSIZE);
|
||||
mappages(pagetable, 0, PGSIZE, (uint64)mem, PTE_W|PTE_R|PTE_X|PTE_U);
|
||||
memmove(mem, src, sz);
|
||||
for (int i = 0; i < sz; i ++) {
|
||||
printf("[uvminit]mem: %p, %x\n", mem + i, mem[i]);
|
||||
}
|
||||
// for (int i = 0; i < sz; i ++) {
|
||||
// printf("[uvminit]mem: %p, %x\n", mem + i, mem[i]);
|
||||
// }
|
||||
}
|
||||
|
||||
// Allocate PTEs and physical memory to grow process from oldsz to
|
||||
|
|
|
@ -4,10 +4,10 @@ ENTRY( _entry )
|
|||
SECTIONS
|
||||
{
|
||||
/*
|
||||
* ensure that entry.S / _entry is at 0x80200000,
|
||||
* ensure that entry.S / _entry is at 0x800200000,
|
||||
* where qemu's -kernel jumps.
|
||||
*/
|
||||
. = 0x80200000;
|
||||
. = 0x80020000;
|
||||
|
||||
.text : {
|
||||
*(.text .text.*)
|
||||
|
|
Loading…
Reference in New Issue