Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/qemu-config - Add config parameter to Makefile #280

Open
wants to merge 3 commits into
base: riscv
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
K=kernel
U=user

# 128M is the default for xv6 - Warning no trailing space after the number
RAM=128
# 3 is the default for xv6
CPUCOUNT=3



OBJS = \
$K/entry.o \
$K/start.o \
Expand Down Expand Up @@ -59,6 +66,8 @@ OBJDUMP = $(TOOLPREFIX)objdump
CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb -gdwarf-2
CFLAGS += -MD
CFLAGS += -mcmodel=medany
CFLAGS += -DMAXMEM=$(RAM)
CFLAGS += -DNCPU=$(CPUCOUNT)
# CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
CFLAGS += -fno-common -nostdlib
CFLAGS += -fno-builtin-strncpy -fno-builtin-strncmp -fno-builtin-strlen -fno-builtin-memset
Expand Down Expand Up @@ -160,10 +169,10 @@ QEMUGDB = $(shell if $(QEMU) -help | grep -q '^-gdb'; \
then echo "-gdb tcp::$(GDBPORT)"; \
else echo "-s -p $(GDBPORT)"; fi)
ifndef CPUS
CPUS := 3
CPUS := $(CPUCOUNT)
endif

QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m 128M -smp $(CPUS) -nographic
QEMUOPTS = -machine virt -bios none -kernel $K/kernel -m $(RAM)M -smp $(CPUS) -nographic
QEMUOPTS += -global virtio-mmio.force-legacy=false
QEMUOPTS += -drive file=fs.img,if=none,format=raw,id=x0
QEMUOPTS += -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
Expand Down
7 changes: 4 additions & 3 deletions kernel/entry.S
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "param.h"
# qemu -kernel loads the kernel at 0x80000000
# and causes each hart (i.e. CPU) to jump there.
# kernel.ld causes the following code to
Expand All @@ -7,10 +8,10 @@
_entry:
# set up a stack for C.
# stack0 is declared in start.c,
# with a 4096-byte stack per CPU.
# sp = stack0 + (hartid * 4096)
# with a CPUSTACKSIZE-kilobytes stack per CPU as definied in param.h.
# sp = stack0 + ((hartid + 1) * CPUSTACKSIZE)
la sp, stack0
li a0, 1024*4
li a0, 1024 * CPUSTACKSIZE
csrr a1, mhartid
addi a1, a1, 1
mul a0, a0, a1
Expand Down
2 changes: 2 additions & 0 deletions kernel/kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ kinit()
{
initlock(&kmem.lock, "kmem");
freerange(end, (void*)PHYSTOP);
// Output the start and end of Memory to see if change to RAM parameter in Makefile has an effect
printf("kinit: Memory start addr: %p, Memory end addr:%p\n",end, (void*)PHYSTOP);
}

void
Expand Down
2 changes: 1 addition & 1 deletion kernel/memlayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
// for use by the kernel and user pages
// from physical address 0x80000000 to PHYSTOP.
#define KERNBASE 0x80000000L
#define PHYSTOP (KERNBASE + 128*1024*1024)
#define PHYSTOP (KERNBASE + MAXMEM*1024*1024)

// map the trampoline page to the highest address,
// in both user and kernel space.
Expand Down
5 changes: 4 additions & 1 deletion kernel/param.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define CPUSTACKSIZE 4 // Stacksize in KB per CPU - Currently leave on 4 KB this is xv6 default
#define NPROC 64 // maximum number of processes
#define NCPU 8 // maximum number of CPUs
#define NOFILE 16 // open files per process
#define NFILE 100 // open files per system
#define NINODE 50 // maximum number of active i-nodes
Expand All @@ -13,3 +13,6 @@
#define MAXPATH 128 // maximum file path name
#define USERSTACK 1 // user stack pages

// Defined in Makefile, so it is dynamic based on the config for qemu
//#define NCPU 8 // maximum number of CPUs
//#define MAXMEM 128 // max Memory in megabyte
2 changes: 1 addition & 1 deletion kernel/start.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main();
void timerinit();

// entry.S needs one stack per CPU.
__attribute__ ((aligned (16))) char stack0[4096 * NCPU];
__attribute__ ((aligned (16))) char stack0[1024 * CPUSTACKSIZE * NCPU];

// entry.S jumps here in machine mode on stack0.
void
Expand Down