xv6 | Working through OS development course
kandi X-RAY | xv6 Summary
kandi X-RAY | xv6 Summary
Working through OS development course
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of xv6
xv6 Key Features
xv6 Examples and Code Snippets
Community Discussions
Trending Discussions on xv6
QUESTION
As we know, xv6 doesn't let a spinlock be acquired twice (even by a process itself).
I am trying to add this feature which lets a process to acquire a lock more than once.
In order to reach this, I am adding an attribute called lock_holder_pid
to the struct spinlock
which is supposed to hold the pid of the process which has acquired this lock.
The only file I have changed is spinlock.c
Here is my new acquire()
function:
ANSWER
Answered 2021-Jun-10 at 09:15This is simply because you are trying to have access to a field of a null struct (myproc()->pid
).
As you may know, myproc()
returns a process running on the current processor. If you look at main.c
, you may notice that the bootstrap processor starts running there. Therefore, if we can find a function which calls the acquire()
function before setting up the first process, the problem will be solved.
If you take a close look at the kinit1
function, you can realize that the acquire
function is called in it. Consequently, we found a function that uses the acquire
function, even before initializing the ptable
struct. Therefore, when you try to access the myproc()
value, it is not initialized yet.
QUESTION
Despite consulting the documentation, I still can't understand this line:swtch(&c->scheduler, &p->context);
.
My question: I know this line is to switch p->context, including save registers and restore registers, but I can't understand the pc
change in this process, that is what execution order of this code? After theswtch(&c->scheduler, &p->context);
is executed, is it immedidate to execute c->proc = 0;
, then the effect of executing c->proc=p;
disappears? I am confused now.
code link: https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/proc.c line 456
...ANSWER
Answered 2021-Jun-04 at 13:21This is literally the code that was so confusing that its original authors wrote "You are not expected to understand this" in the comments, so don't feel bad for not understanding it.
The key thing you may have missed is that p->context
contains an address where swtch
is to resume execution of process p
. It's set up, for instance, here:
QUESTION
This looks really simple, a pipe between, parent will write to a pipe at write end of the pipe, and the child will read from the pipe in a while loop, and print what has read, but my program failed to stop...
...ANSWER
Answered 2021-Apr-11 at 06:32It did stop — the parent exited and produced the prompt from the shell in the messed up output before the child printed "The number is 3 from the child 4":
QUESTION
The question is about persistent validity of code segment selector while switching from real mode to protected mode on intel i386. The switching code is as follows (excerpted from bootasm.S
of xv6 x86 version):
...
ANSWER
Answered 2021-Apr-07 at 04:43The modern reference is the Intel Software Developer's Manual, Volume 3A, Section 9.9.1, "Switching to protected mode".
Intel isn't big on explaining how magic works internally. What it says, and all you need to know, is that if your movl %eax, %cr0
is immediately followed by a far jump or far call, then everything will work. If you put any other instruction there, then "random failures can occur" (their wording).
As it says, %cs
continues to hold its previous value, and presumably that's the value that would be pushed on the stack if you did a far call as the instruction after movl %eax, %cr0
. (Where the stack would be is another interesting question - I think everyone uses the jump instead so it rarely comes up.) But for this one instruction it evidently isn't used as a selector in the usual way.
One guess as to how it might work: we know that in protected mode, there are hidden registers that store the segment attributes, and are reloaded from the descriptor table when you load a segment register. So the movl %eax, %cr0
might cause the hidden register corresponding to %cs
to be loaded with attributes of a segment whose base address is the linear address of the current 16-bit segment: e.g. if %cs
contained 0x1234
then it could be a segment with base address 0x12340
. But the %cs
register itself could be left alone, temporarily not matching its hidden counterpart. Then if the high bits of %eip
are zeroed, the next instruction would be fetched from the right place. That instruction is required to be the long jump which will reload %cs
as well as the hidden segment attribute register.
It's also possible that it just sets some internal flag that says "even though in protected mode, fetch the next instruction according to real-mode address translation". Then this flag gets cleared when a far jump occurs, or after one instruction has been fetched, or something like that.
QUESTION
I'm using VMware Workstation 15 Pro on Windows 10. The guest OS is Linux 18.04.5 LTS. In guest Linux, I downloaded xv6 using command: git clone git://github.com/mit-pdos/xv6-public.git
. After building xv6 using make
, I run make qemu-nox-gdb
. However, the xv6 freezes inside qemu. No prompt printed out. No response to any key input. But if I remove gdb
, everything works well.
output image
PS: I have update and upgrade everything in Linux, including qemu, git, gdb, nasm, etc.
...ANSWER
Answered 2021-Mar-29 at 18:07That QEMU commandline tells QEMU "don't run anything, instead, stop and wait for a connection from gdb". The makefile printed a message for you: "Now run 'gdb'". Have you run gdb and connected it to QEMU? (Probably there should be some tutorial or other info with xv6 that explains more about how to do this.)
QUESTION
I have been reading the makefile of xv6 project. I want to put all the user programs into a folder to keep the project tidy. I can not find where it compiles the user programs. I know that when i run: make fs.img; it will compile the user programs, but i can not find any commands to do so. I also want all the kernel code to go into a directory called "kernel".
Is there a feature in make that allows automatic compilation or is there just something I'm not seeing. And could anyone suggest any make docs to help me understand this makefile.
My Makefile:
...ANSWER
Answered 2021-Mar-25 at 12:30All make systems (as required by POSIX) have a number of built-in rules including rules that know how to compile object files from C files.
For information on GNU make's built-in rules you can review the manual.
QUESTION
I'm trying to set up xv6 on Ubuntu 18.04.5 but there is an error during make qemu
:
ANSWER
Answered 2021-Mar-20 at 12:23Everything went right after I upgraded Ubuntu to version 20.04.2 :)
QUESTION
On Ubuntu 20.04, I installed the xv6 project using the page Tools Used in 6.828
...ANSWER
Answered 2021-Mar-20 at 06:47This has been mentioned in Tools Used in 6.S081
At this moment in time, it seems that the package qemu-system-misc has received an update that breaks its compatibility with our kernel. If you run make qemu and the script appears to hang after
QUESTION
I'm running on Ubuntu 20.04 host and try to remote debug xv6 kernel running locally under qemu emulator.
I run :
- gdb kernel
- target remote localhost:26000
I get :
Remote debugging using localhost:26000 warning: Selected architecture i386 is not compatible with reported target architecture i386:x86-64 warning: Architecture rejected target-supplied description Remote 'g' packet reply is too long (expected 312 bytes, got 608 bytes): 0000000000000000000000000000000000000000000000006306000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f0ff0000000000000200000000f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007f0300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000801f0000 (gdb)
Any idea how can I solve this problem ?
Thanks!
Gil
...ANSWER
Answered 2020-Oct-11 at 15:21Use the following command in gdb:
QUESTION
I'm trying to implement ps command in xv6 (adding system call), I have followed the process of making one and in the end while using the command "make qemu-nox" to finally test the system call i get the following errors
...ANSWER
Answered 2020-Aug-30 at 17:23The compiler is claiming that you're in a function named "cps()" on line 9 of your file cat.c, which is obviously not what that function is named. It's also complaining about an issue in user.h itself. This is the clue that the problem is not directly in your cat.c file, but somewhere in the headers it is including (probably in user.h).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install xv6
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page