fix a problem with end. make uartputc() wait until h/w is ready.

This commit is contained in:
Robert Morris 2019-06-04 10:43:45 -04:00
parent b78894f34e
commit 0e131b2263
11 changed files with 32 additions and 23 deletions

1
defs.h
View file

@ -179,7 +179,6 @@ int uartgetc(void);
// vm.c
void kvminit(void);
void kvmswitch(void);
pagetable_t uvmcreate(void);
void uvminit(pagetable_t, char *, uint);
uint64 uvmalloc(pagetable_t, uint64, uint64);

View file

@ -27,8 +27,6 @@ void
kinit()
{
initlock(&kmem.lock, "kmem");
if(PHYSTOP > RAMDISK)
panic("kinit");
freerange(end, (void*)PHYSTOP);
}
@ -76,7 +74,7 @@ kalloc(void)
if(r)
kmem.freelist = r->next;
release(&kmem.lock);
memset((char*)r, 5, PGSIZE); // fill with junk
if(r)
memset((char*)r, 5, PGSIZE); // fill with junk
return (void*)r;
}

View file

@ -26,8 +26,6 @@ SECTIONS
}
bss : {
*(.bss)
PROVIDE(end = .);
}
. = ALIGN(0x1000);
PROVIDE(end = .);
}

View file

@ -2,6 +2,7 @@
// qemu -machine virt is set up like this:
// 00001000 -- boot ROM, provided by qemu
// 0C000000 -- PLIC
// 10000000 -- uart0 registers
// 80000000 -- boot ROM jumps here in machine mode
// -kernel loads the kernel here
@ -26,7 +27,7 @@
// for use by the kernel and user pages
// from physical address 0x80000000 to PHYSTOP.
#define KERNBASE 0x80000000L
#define PHYSTOP (KERNBASE + 64*1024*1024)
#define PHYSTOP (KERNBASE + 128*1024*1024)
// map the trampoline page to the highest address,
// in both user and kernel space.

2
proc.c
View file

@ -360,7 +360,7 @@ scheduler(void)
for(;;){
// Enable interrupts on this processor.
intr_on();
// Loop over process table looking for process to run.
acquire(&ptable.lock);
for(p = ptable.proc; p < &ptable.proc[NPROC]; p++){

16
riscv.h
View file

@ -132,6 +132,14 @@ w_stvec(uint64 x)
asm("csrw stvec, %0" : : "r" (x));
}
static inline uint64
r_stvec()
{
uint64 x;
asm("csrr %0, stvec" : "=r" (x) );
return x;
}
// use riscv's sv39 page table scheme.
#define SATP_SV39 (8L << 60)
@ -201,6 +209,14 @@ intr_get()
return (x & SSTATUS_SIE) != 0;
}
static inline uint64
r_sp()
{
uint64 x;
asm("mv %0, sp" : "=r" (x) );
return x;
}
#define PGSIZE 4096 // bytes per page
#define PGSHIFT 12 // bits of offset within a page

View file

@ -6,7 +6,7 @@
void main();
// entry.S uses this as the initial stack.
char stack0[4096];
__attribute__ ((aligned (16))) char stack0[4096];
// entry.S jumps here in machine mode on stack0.
void

View file

@ -39,6 +39,7 @@ sys_sbrk(void)
if(argint(0, &n) < 0)
return -1;
printf("sbrk(%d), sz was %d\n", n, (int)myproc()->sz);
addr = myproc()->sz;
if(growproc(n) < 0)
return -1;

2
trap.c
View file

@ -108,7 +108,7 @@ usertrapret(void)
// interrupts and exceptions from kernel code go here,
// on whatever the current kernel stack is.
// must be 4-byte aligned to fit in stvec.
void __attribute__ ((aligned (4)))
void
kerneltrap()
{
uint64 sstatus = r_sstatus();

3
uart.c
View file

@ -46,6 +46,9 @@ uartinit(void)
void
uartputc(int c)
{
// wait for Transmit Holding Empty to be set in LSR.
while((*R(5) & (1 << 5)) == 0)
;
*R(0) = c;
}

15
vm.c
View file

@ -33,12 +33,11 @@ kvminit()
// PLIC
mappages(kernel_pagetable, PLIC, 0x4000000,
PLIC, PTE_R | PTE_W);
// map kernel text executable and read-only.
mappages(kernel_pagetable, KERNBASE, (uint64)etext-KERNBASE,
KERNBASE, PTE_R | PTE_X);
// map kernel data and the physical RAM we'll make use of.
mappages(kernel_pagetable, (uint64)etext, PHYSTOP-(uint64)etext,
(uint64)etext, PTE_R | PTE_W);
@ -52,14 +51,8 @@ kvminit()
mappages(kernel_pagetable, TRAMPOLINE, PGSIZE,
(uint64)trampout, PTE_R | PTE_X);
kvmswitch();
}
// Switch h/w page table register to the kernel's page table,
// and enable paging.
void
kvmswitch(void)
{
// Switch h/w page table register to the kernel's page table,
// and enable paging.
w_satp(MAKE_SATP(kernel_pagetable));
}
@ -214,7 +207,7 @@ uvmalloc(pagetable_t pagetable, uint64 oldsz, uint64 newsz)
for(; a < newsz; a += PGSIZE){
mem = kalloc();
if(mem == 0){
uvmdealloc(pagetable, newsz, oldsz);
uvmdealloc(pagetable, a, oldsz);
return 0;
}
memset(mem, 0, PGSIZE);