[add] laos using xv6-riscv thought

This commit is contained in:
bLueriVerLHR
2023-05-18 00:05:52 +08:00
parent 399c978c09
commit 5d31bf294c
21 changed files with 462 additions and 22 deletions

28
laos/src/kernel/Makefile Normal file
View File

@@ -0,0 +1,28 @@
CURNAME := kernel
BUILD_DIR := $(TOP_BUILD_DIR)/$(CURNAME)
CSRC := $(wildcard *.c)
OBJS := $(patsubst %.c,%.o,$(CSRC))
BUILD_OBJS := $(addprefix $(BUILD_DIR)/,$(OBJS))
ASSRC := $(wildcard *.S)
ASOBJ := $(patsubst %.S,%.o,$(ASSRC))
BUILD_ASOBJ := $(addprefix $(BUILD_DIR)/,$(ASOBJ))
.PHONY: build all message
all: message build
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
$(BUILD_OBJS): $(BUILD_DIR)/%.o:%.c $(BUILD_DIR)
@$(CC) -c -o $@ $< $(CPPFLAGS) $(CFLAGS)
$(BUILD_ASOBJ): $(BUILD_DIR)/%.o:%.S $(BUILD_DIR)
@$(CC) -c -o $@ $< $(CPPFLAGS) $(CFLAGS)
build: $(BUILD_OBJS) $(BUILD_ASOBJ)
message:
@echo "building $(CURNAME)"

20
laos/src/kernel/entry.S Normal file
View File

@@ -0,0 +1,20 @@
#include "asm.h"
.section .entry
.global _entry
_entry:
# set up a stack for C.
# stack0 is declared in start.c,
# with a 4096-byte stack per CPU.
# sp = stack0 + (hartid * 4096)
la.global $sp, stack0
lu12i.w $a0, (1024*4 >> 12) & 0xfffff
addi.w $a0, $a0, 1024*4 & 0xfff
csrrd $a1, CPUID
addi.w $a1, $a1, 1
mul.w $a0, $a0, $a1
add.w $sp, $sp, $a0
# jump to start() in start.c
bl start
spin:
b spin

1
laos/src/kernel/kalloc.c Normal file
View File

@@ -0,0 +1 @@
extern char end[];

3
laos/src/kernel/main.c Normal file
View File

@@ -0,0 +1,3 @@
void main() {
}

7
laos/src/kernel/start.c Normal file
View File

@@ -0,0 +1,7 @@
#include "common.h"
__attribute__ ((aligned (16))) char stack0[4096 * NCPU];
void start() {
}

1
laos/src/kernel/vm.c Normal file
View File

@@ -0,0 +1 @@
extern char etext[];