Commit graph

56 commits

Author SHA1 Message Date
Robert Morris 50cbc75102 first shell prints $ prompt, though no console input yet 2019-06-01 05:33:38 -04:00
Robert Morris 7fd1f1eb0a exec compiles but argstr() doesn't work yet 2019-05-31 12:43:20 -04:00
Robert Morris 2ec1959fd1 fork/wait/exit work 2019-05-31 09:45:59 -04:00
Frans Kaashoek ab0db651af Checkpoint port of xv6 to x86-64. Passed usertests on 2 processors a few times.
The x86-64 doesn't just add two levels to page tables to support 64 bit
addresses, but is a different processor. For example, calling conventions,
system calls, and segmentation are different from 32-bit x86. Segmentation is
basically gone, but gs/fs in combination with MSRs can be used to hold a
per-core pointer. In general, x86-64 is more straightforward than 32-bit
x86. The port uses code from sv6 and the xv6 "rsc-amd64" branch.

A summary of the changes is as follows:

- Booting: switch to grub instead of xv6's bootloader (pass -kernel to qemu),
because xv6's boot loader doesn't understand 64bit ELF files.  And, we don't
care anymore about booting.

- Makefile: use -m64 instead of -m32 flag for gcc, delete boot loader, xv6.img,
bochs, and memfs. For now dont' use -O2, since usertests with -O2 is bigger than
MAXFILE!

- Update gdb.tmpl to be for i386 or x86-64

- Console/printf: use stdarg.h and treat 64-bit addresses different from ints
  (32-bit)

- Update elfhdr to be 64 bit

- entry.S/entryother.S: add code to switch to 64-bit mode: build a simple page
table in 32-bit mode before switching to 64-bit mode, share code for entering
boot processor and APs, and tweak boot gdt.  The boot gdt is the gdt that the
kernel proper also uses. (In 64-bit mode, the gdt/segmentation and task state
mostly disappear.)

- exec.c: fix passing argv (64-bit now instead of 32-bit).

- initcode.c: use syscall instead of int.

- kernel.ld: load kernel very high, in top terabyte.  64 bits is a lot of
address space!

- proc.c: initial return is through new syscall path instead of trapret.

- proc.h: update struct cpu to have some scratch space since syscall saves less
state than int, update struct context to reflect x86-64 calling conventions.

- swtch: simplify for x86-64 calling conventions.

- syscall: add fetcharg to handle x86-64 calling convetions (6 arguments are
passed through registers), and fetchaddr to read a 64-bit value from user space.

- sysfile: update to handle pointers from user space (e.g., sys_exec), which are
64 bits.

- trap.c: no special trap vector for sys calls, because x86-64 has a different
plan for system calls.

- trapasm: one plan for syscalls and one plan for traps (interrupt and
exceptions). On x86-64, the kernel is responsible for switching user/kernel
stacks. To do, xv6 keeps some scratch space in the cpu structure, and uses MSR
GS_KERN_BASE to point to the core's cpu structure (using swapgs).

- types.h: add uint64, and change pde_t to uint64

- usertests: exit() when fork fails, which helped in tracking down one of the
bugs in the switch from 32-bit to 64-bit

- vectors: update to make them 64 bits

- vm.c: use bootgdt in kernel too, program MSRs for syscalls and core-local
state (for swapgs), walk 4 levels in walkpgdir, add DEVSPACETOP, use task
segment to set kernel stack for interrupts (but simpler than in 32-bit mode),
add an extra argument to freevm (size of user part of address space) to avoid
checking all entries till KERNBASE (there are MANY TB before the top 1TB).

- x86: update trapframe to have 64-bit entries, which is what the processor
pushes on syscalls and traps.  simplify lgdt and lidt, using struct desctr,
which needs the gcc directives packed and aligned.

TODO:
- use int32 instead of int?
- simplify curproc(). xv6 has per-cpu state again, but this time it must have it.
- avoid repetition in walkpgdir
- fix validateint() in usertests.c
- fix bugs (e.g., observed one a case of entering kernel with invalid gs or proc
2018-09-23 08:35:30 -04:00
Frans Kaashoek fbb4c09444 Read curproc from cpu structure, but be careful because after a schedule event
myproc() points to a different thread.

   myproc();
   sched();
   myproc();  // this proc maybe different than the one before sched

Thus, in a function that operates on one thread better to retrieve the
current process once at the start of the function.
2017-01-31 20:21:14 -05:00
Frans Kaashoek abf847a083 Start of an experiment to remove the use of gs for cpu local variables. 2017-01-31 17:47:16 -05:00
Frans Kaashoek dec637bc59 Replace I_BUSY with sleep locks 2016-09-11 20:59:57 -04:00
Peter H. Froehlich 1ccb5a6fca Remove unused variable, nits. 2016-08-18 11:15:56 -04:00
Robert Morris 71453f72f2 a start at concurrent FS system calls 2014-08-27 17:15:30 -04:00
Robert Morris 2c56547272 every iput() and namei() must be inside a transaction 2014-08-04 13:06:48 -04:00
Austin Clements 9d59eb0151 Make fetchint and fetchstr use proc instead of taking a struct proc
Previously, these were inconsistent: they used their struct proc
argument for bounds checking, but always copied the argument from the
current address space (and hence the current process).  Drop the
struct proc argument and always use the current proc.

Suggested by Carmi Merimovich.
2012-02-17 23:20:13 -05:00
Robert Morris 12abb1a561 don't let dirty blocks be evicted from cache! 2011-10-14 10:23:23 -04:00
Austin Clements 4e015d81aa Shorten sys_unlink a little; create now fits in column 2011-09-02 15:20:27 -04:00
Frans Kaashoek 1ddfbbb194 Revert "Introduce and use sleeplocks instead of BUSY flags"
My changes have a race with re-used bufs and the code doesn't seem to get shorter
Keep the changes that fixed ip->off race

This reverts commit 3a5fa7ed90.

Conflicts:

	defs.h
	file.c
	file.h
2011-08-29 17:18:40 -04:00
Frans Kaashoek 3a5fa7ed90 Introduce and use sleeplocks instead of BUSY flags
Remove I_BUSY, B_BUSY, and intrans defs and usages
One spinlock per buf to avoid ugly loop in bget
fix race in filewrite (don't update f->off after releasing lock)
2011-08-26 10:08:29 -04:00
Robert Morris 5053dd6a6d avoid deadlock by calling begin_trans() before locking any inodes 2011-08-15 12:44:20 -04:00
Robert Morris 2e59046362 log write() data
usertest for big write()s
push begin_trans/commit_trans down into syscalls
2011-08-12 09:25:39 -04:00
Russ Cox 1a81e38b17 make new code like old code
Variable declarations at top of function,
separate from initialization.

Use == 0 instead of ! for checking pointers.

Consistent spacing around {, *, casts.

Declare 0-parameter functions as (void) not ().

Integer valued functions return -1 on failure, 0 on success.
2011-01-11 13:01:13 -05:00
Robert Morris 4655d42e3b copyout() copies data to a va in a pagetable, for exec() &c
usertest that passes too many arguments, break exec
2010-09-27 16:14:33 -04:00
Frans Kaashoek 40889627ba Initial version of single-cpu xv6 with page tables 2010-07-02 14:51:53 -04:00
Russ Cox 48755214c9 assorted fixes:
* rename c/cp to cpu/proc
 * rename cpu.context to cpu.scheduler
 * fix some comments
 * formatting for printout
2009-08-30 23:02:08 -07:00
Russ Cox 0aef891495 shuffle and tweak for formatting.
pdf has very good page breaks now.
would be a good copy for fall 2009.
2009-08-08 01:07:30 -07:00
Russ Cox f9a06440ab rearrangements and cleanup for text 2009-07-11 19:26:01 -07:00
rsc f3685aa391 simplify 2009-05-31 02:07:51 +00:00
kolya 15a2693637 try harder to get directory refcounts right 2008-10-17 12:42:13 +00:00
kolya f3e87bc838 make mkdir crash-safer, as noticed by many students on midterm 2008-10-16 15:18:49 +00:00
rsc 666f58c711 believe it or not, this was working
the macro expansion of "char *cp;" turned into
char *(curproc[cpu()]);  which declares a dynamically
sized array of char* called curproc.

so then &cp == &(curproc[cpu()]) was actually a
stack variable as "expected".  it was one past the
end of the array, but the implicit alloca allocated
more than was necessary.

do not tell me that making cp a #define was a bad idea.
there are worse problems to fix.  more on that later.
2007-09-27 05:13:10 +00:00
rsc 5516be1fed spaces around else for rtm 2007-08-28 18:37:41 +00:00
rsc e4d6a21165 more consistent spacing 2007-08-28 18:32:08 +00:00
rsc 7834cca604 remove _ from pipe; be like file 2007-08-28 04:22:35 +00:00
rsc 3a2310f746 make code match comment 2007-08-27 23:53:17 +00:00
rsc 64c4737477 make code match comment 2007-08-27 23:53:17 +00:00
rsc 558ab49f13 delete unnecessary #include lines 2007-08-27 23:26:33 +00:00
rsc 603deefc6b oops 2007-08-27 16:06:15 +00:00
rsc e79b16598c nits 2007-08-27 14:39:50 +00:00
rsc 1ccff18b24 fileincref -> filedup (consistent with idup) 2007-08-27 14:35:09 +00:00
rsc 8d2e9a4867 shuffle for formatting 2007-08-24 22:17:54 +00:00
rsc aa6824ab64 remove unused variable 2007-08-24 20:59:43 +00:00
rsc 07090dd705 Remove struct uinode.
Remove type arg to mknod (assume T_DEV).
2007-08-24 20:54:23 +00:00
rsc eaea18cb9c PDF at http://am.lcs.mit.edu/~rsc/xv6.pdf
Various changes made while offline.

 + bwrite sector argument is redundant; use b->sector.
 + reformatting of files for nicer PDF page breaks
 + distinguish between locked, unlocked inodes in type signatures
 + change FD_FILE to FD_INODE
 + move userinit (nee proc0init) to proc.c
 + move ROOTDEV to param.h
 + always parenthesize sizeof argument
2007-08-22 06:01:32 +00:00
rsc bd39955ecc ARGMAX -> MAXARGS 2007-08-21 20:01:11 +00:00
rsc f32f3638f4 Various cleanup:
- Got rid of dummy proc[0].  Now proc[0] is init.
 - Added initcode.S to exec /init, so that /init is
   just a regular binary.
 - Moved exec out of sysfile to exec.c
 - Moved code dealing with fs guts (like struct inode)
   from sysfile.c to fs.c.  Code dealing with system call
   arguments stays in sysfile.c
 - Refactored directory routines in fs.c; should be simpler.
 - Changed iget to return *unlocked* inode structure.
   This solves the lookup-then-use race in namei
   without introducing deadlocks.
   It also enabled getting rid of the dummy proc[0].
2007-08-21 19:22:08 +00:00
rsc e2a620da49 checkpoint - simpler namei interface 2007-08-20 19:37:15 +00:00
rsc dca5b5ca2e avoid assignments in declarations 2007-08-10 17:17:42 +00:00
rsc b6095304b7 Make cp a magic symbol. 2007-08-10 16:37:27 +00:00
rsc 806f4c11f7 oops 2007-08-09 17:53:03 +00:00
rsc 9583b476bf try to use cp only for curproc[cpu()] 2007-08-09 17:32:40 +00:00
rsc 7366e042d9 save process name for debugging 2007-08-08 08:38:11 +00:00
rsc 19297caf0d fix ide, pit interfaces 2006-09-07 15:29:54 +00:00
rsc 70c3260dc4 fix pipe bug 2006-09-07 14:38:56 +00:00