hust-os / xv6-k210 Goto Github PK
View Code? Open in Web Editor NEWPort XV6 to K210 board!
License: MIT License
Port XV6 to K210 board!
License: MIT License
请问我在挂载SD卡的时候 挂载点如何选择 内核写入sd卡的内容是什么 是用户态生成的可执行文件么
目前我们计划在内核中加入动态的分配机制,用于更灵活的PCB、entry(文件系统)、buf(文件系统)等的管理机制
现有的Panic,我指的是xv6-k210 kernel中的panic()
函数,严格来说只是使当前的核进入死循环。而我们希望能够能够在Panic的时候同时“停止”k210的两个核。
这可能会需要向panic()
中引入适当的核间中断机制?
如果没有实现缓存一致性,多核运行可能会有问题吧?
make run platform=qemu, 出现错误, system shutdown scheduled due to RustSBI panic
When I tried to run the kernel on qemu, as a result, I got this error message below.
qemu-system-riscv64: Some ROM regions are overlapping
These ROM regions might have been loaded by direct user request or by default.
They could be BIOS/firmware images, a guest kernel, initrd or some other file loaded into guest memory.
Check whether you intended to load all this guest code, and whether it has been built to load to the correct addresses.
The following two regions overlap (in the memory address space):
./bootloader/SBI/sbi-qemu ELF program header segment 0 (addresses 0x0000000080000000 - 0x00000000800193e8)
fdt (addresses 0x0000000080000000 - 0x0000000080100000)
make: *** [Makefile:152: run] Error 1
It seems that there are some errors with the booting phase. Can you help me fix it? Thanks. Below are some of my compliling system informations.
.............. ********@kali
..,;:ccc,. -------------
......''';lxO. OS: Kali GNU/Linux Rolling x86_64
.....''''..........,:ld; Host: VMware Virtual Platform None
.';;;:::;,,.x, Kernel: 5.16.0-kali5-amd64
..'''. 0Xxoc:,. ... Uptime: 6 mins
.... ,ONkc;,;cokOdc',. Packages: 2991 (dpkg)
. OMo ':ddo. Shell: zsh 5.8.1
dMc :OO; Resolution: 1718x900
0M. .:o. DE: Xfce 4.16
;Wd WM: Xfwm4
;XO, WM Theme: Kali-Dark
,d0Odlc;,.. Theme: Kali-Dark [GTK2/3]
..',;:cdOOd::,. Icons: Flat-Remix-Blue-Dark [GTK2/3]
.:d;.':;. Terminal: qterminal
'd, .' Terminal Font: FiraCode 10
;l .. CPU: Intel i7-9750H (8) @ 2.592GHz
.o GPU: 00:0f.0 VMware SVGA II Adapter
c Memory: 649MiB / 11940MiB
.'
.
qemu-riscv64 version 5.0.0
Copyright (c) 2003-2020 Fabrice Bellard and the QEMU Project developers
QEMU emulator version 6.2.0 (Debian 1:6.2+dfsg-2)
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
rustc 1.61.0-nightly (1bfe40d11 2022-03-18)
riscv64-unknown-elf-gcc (gca312387ab1) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
既然proc的kpagetable既有用户地址空间和内核地址空间,这样显得pagetable就多余了,在限制用户地址空间小于0x80000000的前提下,删除pagetable也能正常工作?这样每个进程的pagetable的0,1项对应用户地址空间的映射,后面的项对应内核空间的映射。只保留一个页表的话可以简化vm.c的代码?
我们希望能给出一个统一的rustsbi实现用于统一QEMU和k210两个平台
在make build platform=qemu和make fs后,使用命令:qemu-system-riscv64 -machine virt -bios default -m 128M -nographic -kernel target/kernel
会进入到xv6-qemu,但是提示panic: could not find virtio disk
backtrace:
0x000000008020017c
0x0000000080206f90
0x0000000080204fb6
0x0000000080200aa0
这个该怎么办呢?
运行在qemu-system-riscv64上,模拟器是基于k210的板子吗
现阶段的xv6使用一段定长的PCB数组来存储所有的进程控制信息,并使用简单的轮询机制从数组中选择下一个可执行的进程。这样的策略尽管结实有效,但显然不够优雅和灵活。在引入了动态内存分配机制后,xv6应该能够根据需要分配PCB,并通过更加灵活的方式——链表——将这些PCB组织起来等待调度。
在现阶段的VFS和Scheduler搞好之后,进行一次较大规模的代码整理,主要是整理代码和编写文档。
qemu-system-riscv64 -machine virt -kernel target/kernel -m 6M -nographic -smp 2 -bios ./sbi/sbi-qemu -drive file=fs.img,if=none,format=raw,id=x0 -device virtio-blk-device,drive=x0,bus=virtio-mmio-bus.0
ekernel: 0x8000f000
heap_start: 0x8001a000
heap_size: 0x4000
trap init
|\ __ \ |\ \ |\ \ |\ \ |\ __ \ |\ \ |\ __ \ |\ \
\ \ |\ \ \ ___|\ \ \ \ _| \ \ |\ \ \ _|\ \ |\ /\ \ \
\ \ \ _ \ \ \ \ \ \ \ __ \ _ \ \ __ \ \ \
\ \ ___| ||\ \ \ \ \ ___ \ \ \ \ \||\ \ \ |\ \ \ \
\ _\ _\ \ _\ _\ _\ _\ _\ \ _\ _
|| |_\|| |_______| |||||_\|_______| ||
|| |_____|
[PsicaSBI]: Version 0.4
mideleg: 0x222, medeleg: 0xb1ab
Extension: RV64ACDFIMSU
PsicaSBI hartid 0 ready
(-. (
-. .-') ('-. _ .-')
( OO ). (OO ) .( OO) ( OO) ( '.( OO )
(/. _)-. ,--(/ ,. \ ,--. ()---_) (,------. ,--. ,--.) ,--. ,--.
\ .' / \ \ /(__/ / .' .-') ' .-. ' | .---' |
.' | | | | |
\ /\ \ \ / / . / -. ( OO) ,| | | | | | | | | | | .-')
\ \ | \ ' /, | .-. ' (,------. (| | | | (| '--. | |'.'| | | ||( OO )
.' _) \ /__)' \ | | '------' | | | | | .--' | | | | | | | -' / / .'. \ \ / \
' / ' '-' '-. | ---. | | | | (' '-'(_.-' '--' '--'
-' ----'
-----'--' ------'
--' --'
-----'
hart 0 init done
PsicaSBI hartid 1 ready
hart 1 init done
scause 0x000000000000000d
sepc=0x000000008002560c stval=0x0000000000000020 hart=0
pid: 2, name: initcode
[trap]: hart 0 at kernel/trap/trap.c: 236
[panic]: kerneltrap
backtrace:
0x000000008002033e
0x000000008002fbd8
0x000000008002f7a0
0x000000008002bba0
0x000000008002ec22
0x000000008002cefa
我clone的是这个链接https://github.com/oscomp/2021oscomp-best-kernel-design-impl/tree/2021-xv6
运行make sdcard、
$ make sdcard sd=/dev/sdc
flashing into sd card...
524288+0 records in
524288+0 records out
268435456 bytes (268 MB, 256 MiB) copied, 0.974044 s, 276 MB/s
连接板子,make run,
$ make run
0+1 records in
0+1 records out
53335 bytes (53 kB, 52 KiB) copied, 0.00043795 s, 122 MB/s
Segmentation fault (core dumped)
make: *** [Makefile:148: run] Error 139
在与@AtomHeartCoder讨论之后,我们认为可以在调度器中引入任务(Task)支持。任务控制块的一个草稿如下
struct task {
struct list _node; // 与链表有关的域
struct proc *process; // 指向自己的进程控制块
enum task_status status; // 当前任务的运行状态
int tid; // 类似于PID,当前任务的ID
struct context context; // 上下文,用于调度
struct trapframe *tf; // 用于中断时保护现场
}
任务基于进程,不同的任务之间可能属于同一个进程。而一个进程控制块中主要是包含了当前进程的地址空间信息(页表和segment链表),属于同一个进程的任务共享这些信息,所以在调度器在这些任务之间进行调度时就不需要刷新TLB,这可以进一步地加快调度的速度。
main主分支的eput函数实现是这样的
void eput(struct dirent *entry)
{
acquire(&ecache.lock);
if (entry != &root && entry->valid != 0 && entry->ref == 1) {
// ref == 1 means no other process can have entry locked,
// so this acquiresleep() won't block (or deadlock).
acquiresleep(&entry->lock);
entry->next->prev = entry->prev;
entry->prev->next = entry->next;
entry->next = root.next;
entry->prev = &root;
root.next->prev = entry;
root.next = entry;
release(&ecache.lock);
if (entry->valid == -1) { // this means some one has called eremove()
etrunc(entry);
} else {
elock(entry->parent); // 为什么不在此之前释放entry->lock ?
eupdate(entry);
eunlock(entry->parent);
}
releasesleep(&entry->lock);
// Once entry->ref decreases down to 0, we can't guarantee the entry->parent field remains unchanged.
// Because eget() may take the entry away and write it.
struct dirent *eparent = entry->parent;
acquire(&ecache.lock);
entry->ref--;
release(&ecache.lock); // 在查看entry->ref == 0 之前释放是否安全?
if (entry->ref == 0) {
eput(eparent);
}
return;
}
entry->ref--;
release(&ecache.lock);
}
在函数第二次释放ecache.lock后才查看enrty->ref == 0 是否安全(原文件694行)? 设想进程B执行entry->ref--之后,ref变为0,释放了ecache.lock锁之后,另一个进程A调用eget函数尝试获取一个目录块,恰好eget选中了这个刚释放的目录块,此时ref=1,因此进程B不再执行eput(eparent)便返回,这样会导致eparent的ref计数出现问题?
一方面,Kendryte提供的spi.c
对于xv6-k210的应用场景来说过于庞杂。原本的代码中考虑了很多在xv6-k210中大概率不会被用到的情况。另一方面,我们也希望通过重写spi.c
来彻底消化SD卡驱动的协议栈。最后,我们还希望能够在新的代码中使用kmemalloc.c
提供的动态内存分配功能。
但考虑到现有的spi.c
模块其实跑得还挺好的,也许这项工作尚不太急?(笑
原句是:
if((sstatus & SSTATUS_SPP) == 0)
panic("kerneltrap: not from supervisor mode");
问题:(sstatus & SSTATUS_SPP) = 0 不是意味着sstatus第8位是0么?0意味着是用户态,说明中断是来自用户态,那么为什么要panic?
谢谢!
在多核的情况的,使用printf
或是panic
函数进行串口输出,有时会出现两个核的输出发生混淆的现象。这为多核情况下的调试带来了困难:输出有时会混淆到难以辨别的程度。
为了解决这一问题,我个人觉得应该要对console
设备引入更加完善的锁机制,以保证一次输出的原子性。
已经将user中elf文件导入SD卡中 启动时会报错panic:init exiting 请问是什么问题 _init文件也导入sd卡中了
目前xv6-k210的初始化流程还存在一些问题。主要表示为一些结构体数据(如struct cpu cpus[])在启动时为被初始化。计划在未来对xv6-k210中的这类问题通过一次commit统一解决。
描述
参考此 repo 实现的 SD 卡读写程序,在 sdcard_write_sector()
函数中出现 sdcard: invalid response token
错误。
错误信息
sdcard: invalid response token
截图
复现
clone https://gitlab.eduxiji.net/PTRNULL/simplekernel_oscomp_2021.git
,按照 RUN.md 中的描述运行(K210)即可观察到。
diff
代码位于 https://gitlab.eduxiji.net/PTRNULL/simplekernel_oscomp_2021/-/blob/master/src/drv/sdcard/sdcard.c
修改了数据类型
uint8
-> uint8_t
uint16
-> uint16_t
uint32
-> uint32_t
uint64
-> uint64_t
注释了锁相关代码
注释了 static struct sleeplock sdcard_lock
相关定义,以及依赖它的函数。
有时在K210上启动系统时会出现第一次无法正确启动SD卡的问题。按下板子上的reset键后才能正确启动。这个问题在之前并不突出,最近却变的频发。可能是由于SD卡初始化时部分流程的等待时间太短所致(初始化中采用while循环等待初始化的SD_CMD命令生效)。
我现在已经有了测试样例的文件夹riscv64,该怎么在qemu上跑通测试呢,该将他放在哪里,且用什么指令行呢
请教下应该怎么样设置编译参数,才能使自己写的程序能在这个系统上运行呢?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.