change something
This commit is contained in:
parent
5c661f5891
commit
5427ea1da0
26
Makefile
26
Makefile
|
@ -79,7 +79,7 @@ linker = ./linker/k210.ld
|
||||||
|
|
||||||
kendryte_sdk_lib = ./libkendryte.a
|
kendryte_sdk_lib = ./libkendryte.a
|
||||||
|
|
||||||
$T/kernel: $(OBJS) $(linker)
|
$T/kernel: $(OBJS) $(linker) $U/initcode $U/testcode_1 $U/testcode_2 $U/testcode_3 $U/testcode_4
|
||||||
@$(LD) $(LDFLAGS) -T $(linker) -o $T/kernel $(OBJS)
|
@$(LD) $(LDFLAGS) -T $(linker) -o $T/kernel $(OBJS)
|
||||||
@$(OBJDUMP) -S $T/kernel > $T/kernel.asm
|
@$(OBJDUMP) -S $T/kernel > $T/kernel.asm
|
||||||
@$(OBJDUMP) -t $T/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $T/kernel.sym
|
@$(OBJDUMP) -t $T/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $T/kernel.sym
|
||||||
|
@ -121,6 +121,30 @@ $U/initcode: $U/initcode.S
|
||||||
$(OBJCOPY) -S -O binary $U/initcode.out $U/initcode
|
$(OBJCOPY) -S -O binary $U/initcode.out $U/initcode
|
||||||
$(OBJDUMP) -S $U/initcode.o > $U/initcode.asm
|
$(OBJDUMP) -S $U/initcode.o > $U/initcode.asm
|
||||||
|
|
||||||
|
$U/testcode_1: $U/testcode_1.S
|
||||||
|
$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/testcode_1.S -o $U/testcode_1.o
|
||||||
|
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/testcode_1.out $U/testcode_1.o
|
||||||
|
$(OBJCOPY) -S -O binary $U/testcode_1.out $U/testcode_1
|
||||||
|
$(OBJDUMP) -S $U/testcode_1.o > $U/testcode_1.asm
|
||||||
|
|
||||||
|
$U/testcode_2: $U/testcode_2.S
|
||||||
|
$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/testcode_2.S -o $U/testcode_2.o
|
||||||
|
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/testcode_2.out $U/testcode_2.o
|
||||||
|
$(OBJCOPY) -S -O binary $U/testcode_2.out $U/testcode_2
|
||||||
|
$(OBJDUMP) -S $U/testcode_2.o > $U/testcode_2.asm
|
||||||
|
|
||||||
|
$U/testcode_3: $U/testcode_3.S
|
||||||
|
$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/testcode_3.S -o $U/testcode_3.o
|
||||||
|
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/testcode_3.out $U/testcode_3.o
|
||||||
|
$(OBJCOPY) -S -O binary $U/testcode_3.out $U/testcode_3
|
||||||
|
$(OBJDUMP) -S $U/testcode_3.o > $U/testcode_3.asm
|
||||||
|
|
||||||
|
$U/testcode_4: $U/testcode_4.S
|
||||||
|
$(CC) $(CFLAGS) -march=rv64g -nostdinc -I. -Ikernel -c $U/testcode_4.S -o $U/testcode_4.o
|
||||||
|
$(LD) $(LDFLAGS) -N -e start -Ttext 0 -o $U/testcode_4.out $U/testcode_4.o
|
||||||
|
$(OBJCOPY) -S -O binary $U/testcode_4.out $U/testcode_4
|
||||||
|
$(OBJDUMP) -S $U/testcode_4.o > $U/testcode_4.asm
|
||||||
|
|
||||||
tags: $(OBJS) _init
|
tags: $(OBJS) _init
|
||||||
@etags *.S *.c
|
@etags *.S *.c
|
||||||
|
|
||||||
|
|
|
@ -95,13 +95,14 @@ bget(uint dev, uint blockno)
|
||||||
struct buf*
|
struct buf*
|
||||||
bread(uint dev, uint blockno)
|
bread(uint dev, uint blockno)
|
||||||
{
|
{
|
||||||
|
// printf("run in bread\n");
|
||||||
struct buf *b;
|
struct buf *b;
|
||||||
|
|
||||||
b = bget(dev, blockno);
|
b = bget(dev, blockno);
|
||||||
if(!b->valid) {
|
if(!b->valid) {
|
||||||
// virtio_disk_rw(b, 0);
|
// virtio_disk_rw(b, 0);
|
||||||
uint64 sector = b->blockno * (BSIZE / 512);
|
|
||||||
memset(b->data, 0, sizeof(b->data));
|
memset(b->data, 0, sizeof(b->data));
|
||||||
|
uint64 sector = b->blockno * (BSIZE / 512);
|
||||||
if(sd_read_sector(b->data, sector, BSIZE / 512)) {
|
if(sd_read_sector(b->data, sector, BSIZE / 512)) {
|
||||||
panic("[bread]bread err\n");
|
panic("[bread]bread err\n");
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -37,15 +37,18 @@ readsb(int dev, struct superblock *sb)
|
||||||
bp = bread(dev, 1);
|
bp = bread(dev, 1);
|
||||||
memmove(sb, bp->data, sizeof(*sb));
|
memmove(sb, bp->data, sizeof(*sb));
|
||||||
brelse(bp);
|
brelse(bp);
|
||||||
|
// printf("readsb done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init fs
|
// Init fs
|
||||||
void
|
void
|
||||||
fsinit(int dev) {
|
fsinit(int dev) {
|
||||||
|
// printf("run in fsinit\n");
|
||||||
readsb(dev, &sb);
|
readsb(dev, &sb);
|
||||||
if(sb.magic != FSMAGIC)
|
// if(sb.magic != FSMAGIC)
|
||||||
panic("invalid file system");
|
// panic("invalid file system");
|
||||||
initlog(dev, &sb);
|
initlog(dev, &sb);
|
||||||
|
printf("fs init\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zero a block.
|
// Zero a block.
|
||||||
|
|
|
@ -56,6 +56,7 @@ static void commit();
|
||||||
void
|
void
|
||||||
initlog(int dev, struct superblock *sb)
|
initlog(int dev, struct superblock *sb)
|
||||||
{
|
{
|
||||||
|
// printf("run in initlog\n");
|
||||||
if (sizeof(struct logheader) >= BSIZE)
|
if (sizeof(struct logheader) >= BSIZE)
|
||||||
panic("initlog: too big logheader");
|
panic("initlog: too big logheader");
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ initlog(int dev, struct superblock *sb)
|
||||||
log.size = sb->nlog;
|
log.size = sb->nlog;
|
||||||
log.dev = dev;
|
log.dev = dev;
|
||||||
recover_from_log();
|
recover_from_log();
|
||||||
|
// printf("initlog done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy committed blocks from log to their home location
|
// Copy committed blocks from log to their home location
|
||||||
|
@ -87,6 +89,7 @@ install_trans(void)
|
||||||
static void
|
static void
|
||||||
read_head(void)
|
read_head(void)
|
||||||
{
|
{
|
||||||
|
// printf("run in read_head\n");
|
||||||
struct buf *buf = bread(log.dev, log.start);
|
struct buf *buf = bread(log.dev, log.start);
|
||||||
struct logheader *lh = (struct logheader *) (buf->data);
|
struct logheader *lh = (struct logheader *) (buf->data);
|
||||||
int i;
|
int i;
|
||||||
|
@ -95,6 +98,7 @@ read_head(void)
|
||||||
log.lh.block[i] = lh->block[i];
|
log.lh.block[i] = lh->block[i];
|
||||||
}
|
}
|
||||||
brelse(buf);
|
brelse(buf);
|
||||||
|
// printf("read_head done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write in-memory log header to disk.
|
// Write in-memory log header to disk.
|
||||||
|
@ -103,6 +107,7 @@ read_head(void)
|
||||||
static void
|
static void
|
||||||
write_head(void)
|
write_head(void)
|
||||||
{
|
{
|
||||||
|
// printf("run in write_head\n");
|
||||||
struct buf *buf = bread(log.dev, log.start);
|
struct buf *buf = bread(log.dev, log.start);
|
||||||
struct logheader *hb = (struct logheader *) (buf->data);
|
struct logheader *hb = (struct logheader *) (buf->data);
|
||||||
int i;
|
int i;
|
||||||
|
@ -112,6 +117,7 @@ write_head(void)
|
||||||
}
|
}
|
||||||
bwrite(buf);
|
bwrite(buf);
|
||||||
brelse(buf);
|
brelse(buf);
|
||||||
|
// printf("write_head done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#include "include/types.h"
|
#include "include/types.h"
|
||||||
#include "include/param.h"
|
#include "include/param.h"
|
||||||
#include "include/memlayout.h"
|
#include "include/memlayout.h"
|
||||||
|
@ -8,13 +7,19 @@
|
||||||
#include "include/sdcard.h"
|
#include "include/sdcard.h"
|
||||||
#include "include/fpioa.h"
|
#include "include/fpioa.h"
|
||||||
|
|
||||||
|
static inline void inithartid(unsigned long hartid) {
|
||||||
|
asm volatile("mv tp, %0" : : "r" (hartid & 0x1));
|
||||||
|
}
|
||||||
|
|
||||||
volatile static int started = 0;
|
volatile static int started = 0;
|
||||||
// start() jumps here in supervisor mode on all CPUs.
|
// start() jumps here in supervisor mode on all CPUs.
|
||||||
void
|
void
|
||||||
main(unsigned long hartid, unsigned long dtb_pa)
|
main(unsigned long hartid, unsigned long dtb_pa)
|
||||||
{
|
{
|
||||||
|
inithartid(hartid);
|
||||||
|
|
||||||
if (hartid == 0) {
|
if (hartid == 0) {
|
||||||
|
printfinit(); // init a lock for printf
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("xv6-k210 kernel is booting\n");
|
printf("xv6-k210 kernel is booting\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -29,22 +34,23 @@ main(unsigned long hartid, unsigned long dtb_pa)
|
||||||
device_init(dtb_pa, hartid);
|
device_init(dtb_pa, hartid);
|
||||||
fpioa_pin_init();
|
fpioa_pin_init();
|
||||||
sdcard_init();
|
sdcard_init();
|
||||||
// plicinit(); // set up interrupt controller
|
//plicinit(); // set up interrupt controller
|
||||||
// plicinithart(); // ask PLIC for device interrupts
|
//plicinithart(); // ask PLIC for device interrupts
|
||||||
binit(); // buffer cache
|
binit(); // buffer cache
|
||||||
iinit(); // inode cache
|
iinit(); // inode cache
|
||||||
fileinit(); // file table
|
fileinit(); // file table
|
||||||
// virtio_disk_init(); // emulated hard disk
|
//virtio_disk_init(); // emulated hard disk
|
||||||
userinit(); // first user process
|
userinit(); // first user process
|
||||||
|
|
||||||
|
// test_kalloc(); // test kalloc
|
||||||
|
// test_vm(hartid); // test kernel pagetable
|
||||||
test_kalloc(); // test kalloc
|
|
||||||
test_vm(hartid); // test kernel pagetable
|
|
||||||
// test_proc_init(); // test porc init
|
// test_proc_init(); // test porc init
|
||||||
test_sdcard();
|
// test_sdcard();
|
||||||
|
|
||||||
printf("hart 0 init done\n");
|
printf("hart 0 init done\n");
|
||||||
|
scheduler();
|
||||||
|
while (1) {
|
||||||
|
}
|
||||||
for(int i = 1; i < NCPU; i++) {
|
for(int i = 1; i < NCPU; i++) {
|
||||||
unsigned long mask = 1 << i;
|
unsigned long mask = 1 << i;
|
||||||
sbi_send_ipi(&mask);
|
sbi_send_ipi(&mask);
|
||||||
|
@ -57,7 +63,12 @@ main(unsigned long hartid, unsigned long dtb_pa)
|
||||||
while (started == 0)
|
while (started == 0)
|
||||||
;
|
;
|
||||||
__sync_synchronize();
|
__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");
|
||||||
}
|
}
|
||||||
scheduler();
|
scheduler();
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
112
kernel/proc.c
112
kernel/proc.c
|
@ -37,11 +37,11 @@ procinit(void)
|
||||||
// Map it high in memory, followed by an invalid
|
// Map it high in memory, followed by an invalid
|
||||||
// guard page.
|
// guard page.
|
||||||
char *pa = kalloc();
|
char *pa = kalloc();
|
||||||
printf("[procinit]kernel stack: %p\n", (uint64)pa);
|
// printf("[procinit]kernel stack: %p\n", (uint64)pa);
|
||||||
if(pa == 0)
|
if(pa == 0)
|
||||||
panic("kalloc");
|
panic("kalloc");
|
||||||
uint64 va = KSTACK((int) (p - proc));
|
uint64 va = KSTACK((int) (p - proc));
|
||||||
printf("[procinit]kvmmap va %p to pa %p\n", va, (uint64)pa);
|
// printf("[procinit]kvmmap va %p to pa %p\n", va, (uint64)pa);
|
||||||
kvmmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
|
kvmmap(va, (uint64)pa, PGSIZE, PTE_R | PTE_W);
|
||||||
p->kstack = va;
|
p->kstack = va;
|
||||||
}
|
}
|
||||||
|
@ -212,99 +212,73 @@ uchar initcode[] = {
|
||||||
0x00, 0x00, 0x00, 0x00
|
0x00, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// ffffffff80020e42: 04100513 li a0,65
|
|
||||||
// ffffffff80020e46: 4581 li a1,0
|
|
||||||
// ffffffff80020e48: 4601 li a2,0
|
|
||||||
// ffffffff80020e4a: 4681 li a3,0
|
|
||||||
// ffffffff80020e4c: 4885 li a7,1
|
|
||||||
// ffffffff80020e4e: 00000073 ecall
|
|
||||||
// ffffffff80020e52: 04200513 li a0,66
|
|
||||||
// ffffffff80020e56: 00000073 ecall
|
|
||||||
// ffffffff80020e5a: 04300513 li a0,67
|
|
||||||
// ffffffff80020e5e: 00000073 ecall
|
|
||||||
// ffffffff80020e62: 04400513 li a0,68
|
|
||||||
// ffffffff80020e66: 00000073 ecall
|
|
||||||
// ffffffff80020e6a: 4529 li a0,10
|
|
||||||
// ffffffff80020e6c: 00000073 ecall
|
|
||||||
|
|
||||||
uchar proc_test_code_1[] = {
|
uchar proc_test_code_1[] = {
|
||||||
0x13, 0x05, 0x10, 0x04, 0x81, 0x45, 0x01, 0x46,
|
0x13, 0x05, 0x10, 0x04, 0x93, 0x05, 0x00, 0x00, 0x13, 0x06, 0x00, 0x00, 0x93, 0x06, 0x00, 0x00,
|
||||||
0x81, 0x46, 0x85, 0x48, 0x73, 0x00, 0x00, 0x00,
|
0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
// uchar proc_test_code_1[] = {
|
|
||||||
|
|
||||||
// };
|
|
||||||
|
|
||||||
uchar proc_test_code_2[] = {
|
uchar proc_test_code_2[] = {
|
||||||
0x13, 0x05, 0x20, 0x04, 0x81, 0x45, 0x01, 0x46,
|
0x13, 0x05, 0x20, 0x04, 0x93, 0x05, 0x00, 0x00, 0x13, 0x06, 0x00, 0x00, 0x93, 0x06, 0x00, 0x00,
|
||||||
0x81, 0x46, 0x85, 0x48, 0x73, 0x00, 0x00, 0x00,
|
0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
uchar proc_test_code_3[] = {
|
uchar proc_test_code_3[] = {
|
||||||
0x13, 0x05, 0x30, 0x04, 0x81, 0x45, 0x01, 0x46,
|
0x13, 0x05, 0x30, 0x04, 0x93, 0x05, 0x00, 0x00, 0x13, 0x06, 0x00, 0x00, 0x93, 0x06, 0x00, 0x00,
|
||||||
0x81, 0x46, 0x85, 0x48, 0x73, 0x00, 0x00, 0x00,
|
0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
uchar proc_test_code_4[] = {
|
uchar proc_test_code_4[] = {
|
||||||
0x13, 0x05, 0x40, 0x04, 0x81, 0x45, 0x01, 0x46,
|
0x13, 0x05, 0x40, 0x04, 0x93, 0x05, 0x00, 0x00, 0x13, 0x06, 0x00, 0x00, 0x93, 0x06, 0x00, 0x00,
|
||||||
0x81, 0x46, 0x85, 0x48, 0x73, 0x00, 0x00, 0x00,
|
0x93, 0x08, 0x10, 0x00, 0x73, 0x00, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00
|
||||||
};
|
};
|
||||||
|
|
||||||
void test_proc_init() {
|
void test_proc_init() {
|
||||||
struct proc *p1;
|
struct proc *p1;
|
||||||
// struct proc *p2;
|
|
||||||
// struct proc *p3;
|
|
||||||
// struct proc *p4;
|
|
||||||
|
|
||||||
p1 = allocproc();
|
p1 = allocproc();
|
||||||
printf("[test_proc_init]allocproc: %p\n", p1);
|
|
||||||
// p2 = allocproc();
|
|
||||||
// p3 = allocproc();
|
|
||||||
// p4 = allocproc();
|
|
||||||
|
|
||||||
initproc = p1;
|
|
||||||
|
|
||||||
// allocate one user page and copy init's instructions
|
|
||||||
// and data into it.
|
|
||||||
uvminit(p1->pagetable, proc_test_code_1, sizeof(proc_test_code_1));
|
uvminit(p1->pagetable, proc_test_code_1, sizeof(proc_test_code_1));
|
||||||
// uvminit(p2->pagetable, proc_test_code_2, sizeof(proc_test_code_2));
|
// initproc = p1;
|
||||||
// uvminit(p3->pagetable, proc_test_code_3, sizeof(proc_test_code_3));
|
|
||||||
// uvminit(p4->pagetable, proc_test_code_4, sizeof(proc_test_code_4));
|
|
||||||
p1->sz = PGSIZE;
|
p1->sz = PGSIZE;
|
||||||
// p2->sz = PGSIZE;
|
|
||||||
// p3->sz = PGSIZE;
|
|
||||||
// p4->sz = PGSIZE;
|
|
||||||
|
|
||||||
// prepare for the very first "return" from kernel to user.
|
|
||||||
p1->trapframe->epc = 0; // user program counter
|
p1->trapframe->epc = 0; // user program counter
|
||||||
p1->trapframe->sp = PGSIZE; // user stack pointer
|
p1->trapframe->sp = PGSIZE; // user stack pointer
|
||||||
|
safestrcpy(p1->name, "proc_test_code_1", sizeof(p1->name));
|
||||||
|
p1->cwd = namei("/test");
|
||||||
|
p1->state = RUNNABLE;
|
||||||
|
release(&p1->lock);
|
||||||
|
printf("[test_proc_init]allocproc: %p\n", p1);
|
||||||
|
|
||||||
|
// struct proc *p2;
|
||||||
|
// p2 = allocproc();
|
||||||
|
// uvminit(p2->pagetable, proc_test_code_2, sizeof(proc_test_code_2));
|
||||||
|
// p2->sz = PGSIZE;
|
||||||
// p2->trapframe->epc = 0; // user program counter
|
// p2->trapframe->epc = 0; // user program counter
|
||||||
// p2->trapframe->sp = PGSIZE; // user stack pointer
|
// p2->trapframe->sp = PGSIZE; // user stack pointer
|
||||||
|
// safestrcpy(p2->name, "proc_test_code_2", sizeof(p2->name));
|
||||||
|
// p2->cwd = namei("/test");
|
||||||
|
// p2->state = RUNNABLE;
|
||||||
|
// release(&p2->lock);
|
||||||
|
|
||||||
|
// struct proc *p3;
|
||||||
|
// p3 = allocproc();
|
||||||
|
// uvminit(p3->pagetable, proc_test_code_3, sizeof(proc_test_code_3));
|
||||||
|
// p3->sz = PGSIZE;
|
||||||
// p3->trapframe->epc = 0; // user program counter
|
// p3->trapframe->epc = 0; // user program counter
|
||||||
// p3->trapframe->sp = PGSIZE; // user stack pointer
|
// p3->trapframe->sp = PGSIZE; // user stack pointer
|
||||||
|
// safestrcpy(p3->name, "proc_test_code_3", sizeof(p3->name));
|
||||||
|
// p3->cwd = namei("/test");
|
||||||
|
// p3->state = RUNNABLE;
|
||||||
|
// release(&p3->lock);
|
||||||
|
|
||||||
|
// struct proc *p4;
|
||||||
|
// p4 = allocproc();
|
||||||
|
// uvminit(p4->pagetable, proc_test_code_4, sizeof(proc_test_code_4));
|
||||||
|
// p4->sz = PGSIZE;
|
||||||
// p4->trapframe->epc = 0; // user program counter
|
// p4->trapframe->epc = 0; // user program counter
|
||||||
// p4->trapframe->sp = PGSIZE; // user stack pointer
|
// p4->trapframe->sp = PGSIZE; // user stack pointer
|
||||||
|
|
||||||
safestrcpy(p1->name, "proc_test_code_1", sizeof(p1->name));
|
|
||||||
// safestrcpy(p2->name, "proc_test_code_2", sizeof(p2->name));
|
|
||||||
// safestrcpy(p3->name, "proc_test_code_3", sizeof(p3->name));
|
|
||||||
// safestrcpy(p4->name, "proc_test_code_4", sizeof(p4->name));
|
// safestrcpy(p4->name, "proc_test_code_4", sizeof(p4->name));
|
||||||
|
|
||||||
p1->cwd = namei("/");
|
|
||||||
// p2->cwd = namei("/test");
|
|
||||||
// p3->cwd = namei("/test");
|
|
||||||
// p4->cwd = namei("/test");
|
// p4->cwd = namei("/test");
|
||||||
|
|
||||||
p1->state = RUNNABLE;
|
|
||||||
// p2->state = RUNNABLE;
|
|
||||||
// p3->state = RUNNABLE;
|
|
||||||
// p4->state = RUNNABLE;
|
// p4->state = RUNNABLE;
|
||||||
|
|
||||||
release(&p1->lock);
|
|
||||||
// release(&p2->lock);
|
|
||||||
// release(&p3->lock);
|
|
||||||
// release(&p4->lock);
|
// release(&p4->lock);
|
||||||
|
|
||||||
printf("[test_proc]test_proc init done\n");
|
printf("[test_proc]test_proc init done\n");
|
||||||
|
@ -322,6 +296,7 @@ userinit(void)
|
||||||
// allocate one user page and copy init's instructions
|
// allocate one user page and copy init's instructions
|
||||||
// and data into it.
|
// and data into it.
|
||||||
uvminit(p->pagetable, initcode, sizeof(initcode));
|
uvminit(p->pagetable, initcode, sizeof(initcode));
|
||||||
|
// uvminit(p->pagetable, proc_test_code_1, sizeof(proc_test_code_1));
|
||||||
p->sz = PGSIZE;
|
p->sz = PGSIZE;
|
||||||
|
|
||||||
// prepare for the very first "return" from kernel to user.
|
// prepare for the very first "return" from kernel to user.
|
||||||
|
@ -575,12 +550,11 @@ scheduler(void)
|
||||||
// Switch to chosen process. It is the process's job
|
// Switch to chosen process. It is the process's job
|
||||||
// to release its lock and then reacquire it
|
// to release its lock and then reacquire it
|
||||||
// before jumping back to us.
|
// before jumping back to us.
|
||||||
printf("[scheduler]found runnable proc: %d\n", p->pid);
|
printf("[scheduler]found runnable proc with pid: %d\n", p->pid);
|
||||||
// printf("%d\n", p->pid);
|
|
||||||
p->state = RUNNING;
|
p->state = RUNNING;
|
||||||
c->proc = p;
|
c->proc = p;
|
||||||
swtch(&c->context, &p->context);
|
swtch(&c->context, &p->context);
|
||||||
printf("[scheduler]return from user mode\n");
|
printf("[scheduler]return to shceduler\n");
|
||||||
// Process is done running for now.
|
// Process is done running for now.
|
||||||
// It should have changed its p->state before coming back.
|
// It should have changed its p->state before coming back.
|
||||||
c->proc = 0;
|
c->proc = 0;
|
||||||
|
@ -639,6 +613,7 @@ yield(void)
|
||||||
void
|
void
|
||||||
forkret(void)
|
forkret(void)
|
||||||
{
|
{
|
||||||
|
// printf("run in forkret\n");
|
||||||
static int first = 1;
|
static int first = 1;
|
||||||
|
|
||||||
// Still holding p->lock from scheduler.
|
// Still holding p->lock from scheduler.
|
||||||
|
@ -648,10 +623,11 @@ forkret(void)
|
||||||
// File system initialization must be run in the context of a
|
// File system initialization must be run in the context of a
|
||||||
// regular process (e.g., because it calls sleep), and thus cannot
|
// regular process (e.g., because it calls sleep), and thus cannot
|
||||||
// be run from main().
|
// be run from main().
|
||||||
|
printf("[forkret]first scheduling\n");
|
||||||
first = 0;
|
first = 0;
|
||||||
fsinit(ROOTDEV);
|
fsinit(ROOTDEV);
|
||||||
}
|
}
|
||||||
|
printf("[forket]call usertrapret\n");
|
||||||
usertrapret();
|
usertrapret();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ trapinithart(void)
|
||||||
void
|
void
|
||||||
usertrap(void)
|
usertrap(void)
|
||||||
{
|
{
|
||||||
|
printf("run in usertrap\n");
|
||||||
int which_dev = 0;
|
int which_dev = 0;
|
||||||
|
|
||||||
if((r_sstatus() & SSTATUS_SPP) != 0)
|
if((r_sstatus() & SSTATUS_SPP) != 0)
|
||||||
|
@ -96,6 +97,7 @@ usertrap(void)
|
||||||
void
|
void
|
||||||
usertrapret(void)
|
usertrapret(void)
|
||||||
{
|
{
|
||||||
|
printf("USERTRAPRET\n");
|
||||||
struct proc *p = myproc();
|
struct proc *p = myproc();
|
||||||
|
|
||||||
// we're about to switch the destination of traps from
|
// we're about to switch the destination of traps from
|
||||||
|
|
|
@ -23,7 +23,7 @@ SECTIONS
|
||||||
PROVIDE(etext = .);
|
PROVIDE(etext = .);
|
||||||
}
|
}
|
||||||
|
|
||||||
. = ALIGN(4K);
|
/* . = ALIGN(4K);
|
||||||
rodata_start = .;
|
rodata_start = .;
|
||||||
.rodata : {
|
.rodata : {
|
||||||
srodata = .;
|
srodata = .;
|
||||||
|
@ -46,7 +46,28 @@ SECTIONS
|
||||||
sbss_clear = .;
|
sbss_clear = .;
|
||||||
*(.sbss .bss .bss.*)
|
*(.sbss .bss .bss.*)
|
||||||
ebss_clear = .;
|
ebss_clear = .;
|
||||||
}
|
} */
|
||||||
|
|
||||||
|
.rodata : {
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.srodata .srodata.*) /* do not need to distinguish this from .rodata */
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.data : {
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.sdata .sdata.*) /* do not need to distinguish this from .data */
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.data .data.*)
|
||||||
|
}
|
||||||
|
|
||||||
|
.bss : {
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.sbss .sbss.*) /* do not need to distinguish this from .bss */
|
||||||
|
. = ALIGN(16);
|
||||||
|
*(.bss .bss.*)
|
||||||
|
}
|
||||||
|
|
||||||
. = ALIGN(4K);
|
. = ALIGN(4K);
|
||||||
PROVIDE(kernel_end = .);
|
PROVIDE(kernel_end = .);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Initial process that execs /init.
|
# Initial process that execs /init.
|
||||||
# This code runs in user space.
|
# This code runs in user space.
|
||||||
|
|
||||||
#include "syscall.h"
|
#include "include/syscall.h"
|
||||||
|
|
||||||
# exec(init, argv)
|
# exec(init, argv)
|
||||||
.globl start
|
.globl start
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Test process 1
|
||||||
|
# This code run in user space
|
||||||
|
|
||||||
|
.globl test_1
|
||||||
|
test_1:
|
||||||
|
li a0, 65
|
||||||
|
li a1, 0
|
||||||
|
li a2, 0
|
||||||
|
li a3, 0
|
||||||
|
li a7, 1
|
||||||
|
ecall
|
||||||
|
loop_1:
|
||||||
|
jal loop_1
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Test process 2
|
||||||
|
# This code run in user space
|
||||||
|
|
||||||
|
.globl test_2
|
||||||
|
test_2:
|
||||||
|
li a0, 66
|
||||||
|
li a1, 0
|
||||||
|
li a2, 0
|
||||||
|
li a3, 0
|
||||||
|
li a7, 1
|
||||||
|
ecall
|
||||||
|
loop_2:
|
||||||
|
jal loop_2
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Test process 3
|
||||||
|
# This code run in user space
|
||||||
|
|
||||||
|
.globl test_3
|
||||||
|
test_3:
|
||||||
|
li a0, 67
|
||||||
|
li a1, 0
|
||||||
|
li a2, 0
|
||||||
|
li a3, 0
|
||||||
|
li a7, 1
|
||||||
|
ecall
|
||||||
|
loop_3:
|
||||||
|
jal loop_3
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Test process 4
|
||||||
|
# This code run in user space
|
||||||
|
|
||||||
|
.globl test_4
|
||||||
|
test_4:
|
||||||
|
li a0, 68
|
||||||
|
li a1, 0
|
||||||
|
li a2, 0
|
||||||
|
li a3, 0
|
||||||
|
li a7, 1
|
||||||
|
ecall
|
||||||
|
loop_4:
|
||||||
|
jal loop_4
|
Loading…
Reference in New Issue