Commit graph

70 commits

Author SHA1 Message Date
Frans Kaashoek 322990649b x 2018-09-29 08:29:34 -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 907f23a5bb Add mikecat's argp test 2016-09-26 07:54:02 -04:00
Frans Kaashoek aff0c8d5c7 set iomb to forbid i/o instructions from user space
add to test that they indeed trap in user space
thanks to pablogventura@gmail.com and nwolovick@gmail.com
2016-08-26 08:20:11 -04:00
Frans Kaashoek 7894fcd217 Remove trailing white space with:
for f in *.{h,c}; do sed -i .sed 's/[[:blank:]]*$//' $f; done
(Thanks to Nicolás Wolovick)
2016-08-25 09:13:00 -04:00
Robert Morris 48aa917403 i think this is a working concurrent logging scheme 2014-08-28 05:57:47 -04:00
Robert Morris 2c56547272 every iput() and namei() must be inside a transaction 2014-08-04 13:06:48 -04:00
Austin Clements d73dd097a5 Fix compile error on newer gcc's 2011-09-30 15:28:33 -04:00
Robert Morris 371ab7fa96 inaccessible page under the user stack page, to help exec deal w/ too-large args 2011-09-01 13:25:34 -04:00
Robert Morris 5a23692444 fix usertests to correctly test what happens when you call
exec() with arguments that don't fit on a single page.
2011-09-01 12:02:49 -04:00
Robert Morris 5e08357827 enterpgdir -> entrypgdir 2011-08-30 20:50:19 -04:00
Robert Morris 327cc21fba make dirlookup and dirlink more similar 2011-08-19 13:30:57 -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
Frans Kaashoek 11b7438b10 Speedup sbrk tst a bit (forking 100Mbyte processes is slow) 2011-08-08 09:20:29 -04:00
Frans Kaashoek 6479766334 Adjust sbrk test for large user address spaces
All tests pass
2011-08-07 23:03:48 -04:00
Russ Cox cf4b1ad90b xv6: formatting, cleanup, rev5 (take 2) 2011-02-19 21:17:55 -05: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
Robert Morris a9183883b8 map kernel instructions r/o 2010-09-20 06:00:22 -04:00
Robert Morris 05d66b0629 my comment is wrong, exec handles BSS fine 2010-09-19 13:47:52 -04:00
Austin Clements b1d41d6788 Remove the stack guard page. Processes are now contiguous from 0 to proc->sz, which means our syscall argument validation is correct. Add a pointer validation test and remove the stack test, which tested for the guard page. 2010-09-01 16:46:37 -04:00
Austin Clements b0751a3e9b Space police 2010-09-01 00:41:25 -04:00
Austin Clements dd645ef119 Cleanup if allocuvm fails to alloc. Add a test. 2010-08-31 21:49:49 -04:00
Robert Morris 789b508d53 uptime() sys call for benchmarking
increase PHYSTOP
2010-08-11 14:34:45 -04:00
Robert Morris 83d2db91f7 allow sbrk(-x) to de-allocate user memory 2010-08-10 17:08:41 -04:00
Robert Morris c4cc10da7e fix corner cases in exec of ELF
put an invalid page below the stack
have fork() handle invalid pages
2010-08-06 11:12:18 -04:00
Robert Morris eb18645f17 fix allocuvm() to handle sbrk() with non-page-granularity argument
(maybe this never worked, but it works now)
2010-08-05 12:10:54 -04:00
rsc 34295f461a group locks into structs they protect.
few naming nits.
2009-05-31 05:12:21 +00:00
rsc d522571068 make slow bigdir last test 2007-09-27 12:29:06 +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 56c1a151d2 debugging prints 2007-09-26 23:24:23 +00:00
rsc e0e7d07e5a test that fork fails gracefully 2007-08-24 20:20:23 +00:00
rtm 2036534834 add missing iput() at end of _namei() 2007-08-24 14:56:17 +00:00
rtm b55513796f oops, O_CREATE doesn't truncate, so holes can't exist, thus no bug 2007-08-24 12:55:15 +00:00
rtm 3d5f21ee1f test concurrent open/unlink of same file (ok)
test files with holes (not ok)
2007-08-24 12:19:13 +00:00
rsc c88bf235fe check unlink of non-empty directory 2007-08-22 02:21:22 +00:00
rsc 2d61a40b20 bug in usertests! 2007-08-20 21:00:20 +00:00
rsc 5e03dd86c8 add test for rm . 2007-08-10 17:53:09 +00:00
rsc dca5b5ca2e avoid assignments in declarations 2007-08-10 17:17:42 +00:00
rsc c664dd5d23 missing void 2007-08-08 09:32:39 +00:00
rsc 115e177400 standardize on not using unsigned keyword 2007-08-08 09:30:48 +00:00
rsc f3c393ba9f fix tests 2006-09-07 20:06:08 +00:00
rsc 0517a730db remove bogus test 2006-09-07 15:31:40 +00:00
rsc 6c8acf9e04 check super-long lookups 2006-09-07 15:15:46 +00:00
kaashoek a64cd81342 one regression test program 2006-09-07 13:23:41 +00:00
rsc 9e9bcaf143 standardize various * conventions 2006-09-06 17:27:19 +00:00
rtm dfcc5b997c prune unneeded panics and debug output 2006-08-29 19:06:37 +00:00
rtm 3b95801add i broke sbrk, fix it 2006-08-29 17:01:40 +00:00
kaashoek 74493bf446 kill user process when it generates an unhandled trap (e.g., 13)
fix bug in test code of malloc
2006-08-25 00:43:17 +00:00