Commit graph

51 commits

Author SHA1 Message Date
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
Robert Morris
4638cabf8c fix runoff complaints about pagination and long lines 2017-08-29 14:11:59 -04:00
Frans Kaashoek
da3b931ddb Thanks Anton Burtsev <aburtsev@uci.edu> 2017-08-08 19:42:51 -04:00
Robert Morris
a7c03bd914 p2v -> P2V 2016-08-24 13:40:06 -04:00
Robert Morris
c092540e39 eliminate enter_alloc -- use kalloc for everything 2011-09-13 13:14:52 -04:00
Frans Kaashoek
3682474f77 delete dead code 2011-08-21 21:14:29 -04:00
Frans Kaashoek
5f069dcf2f Switch back to #define for PHYSTOP. Using the E820 to retrieve the memory map is too complicated (must be done in 16-bit real-mode, probably enlarged bootblock beyond 512 bytes, and a #define requires less explanation). 2011-08-16 20:23:17 -04:00
Frans Kaashoek
c3dcf47966 Clean up memlayout.h
Get rid of last instances of linear address and "la"
Get ready for detecting physical memory dynamically
2011-08-16 15:47:22 -04:00
Frans Kaashoek
a4b213cf49 Avoid "boot" in xv6 2011-08-15 20:11:13 -04:00
Frans Kaashoek
66ba8079c7 Use static page table for boot, mapping first 4Mbyte; no more segment trick
Allocate proper kernel page table immediately in main using boot allocator
Remove pginit
Simplify address space layout a tiny bit
More to come (e.g., superpages to simplify static table)
2011-08-09 21:37:35 -04:00
Frans Kaashoek
547c28fc1e Don't map IO space in the user part of the address space
Passes all tests now (but need to update usertests to allow for more than 640k)
2011-07-31 21:27:02 -04:00
Frans Kaashoek
9aa0337dc1 Map kernel high
Very important to give qemu memory through PHYSTOP :(
2011-07-29 07:31:27 -04:00
Russ Cox
417c37115e more trivial cleanup 2011-01-11 13:51:40 -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
4587b35847 exec questions 2010-09-19 07:18:42 -04:00
Robert Morris
23c3e52c2f Merge branch 'master' of git+ssh://amsterdam.csail.mit.edu/home/am0/6.828/xv6 2010-08-31 19:21:52 -04:00
Robert Morris
3597d5dc70 oops. last minute simplicifaction to kalloc(). 2010-08-31 19:21:33 -04:00
Austin Clements
5048762c7e Page break kalloc.c 2010-08-31 17:52:03 -04:00
Robert Morris
8d774afb2d no more pminit, or ELF header at 0x10000
kinit() knows about end and PHYSTOP
map all of kernel read/write (rather than r/o instructions)
thanks, austin
2010-08-31 15:39:25 -04:00
Robert Morris
7d7dc9331b kalloc/kfree now only a page at a time
do not keep sorted contiguous free list
2010-08-31 12:54:47 -04:00
Robert Morris
789b508d53 uptime() sys call for benchmarking
increase PHYSTOP
2010-08-11 14:34:45 -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
Frans Kaashoek
af03ab142d a few nits
passes all tests on two-processor smp
2010-07-23 12:52:50 -04:00
Frans Kaashoek
74c82bc158 nits 2010-07-02 17:45:37 -04:00
Frans Kaashoek
40889627ba Initial version of single-cpu xv6 with page tables 2010-07-02 14:51:53 -04:00
Russ Cox
f9a06440ab rearrangements and cleanup for text 2009-07-11 19:26:01 -07:00
rsc
34295f461a group locks into structs they protect.
few naming nits.
2009-05-31 05:12:21 +00:00
rsc
558ab49f13 delete unnecessary #include lines 2007-08-27 23:26:33 +00:00
rsc
e0240674f5 make kfree loop same as kalloc 2007-08-27 12:50:36 +00:00
rtm
902b13f5d6 simplify ide queuing
nits in comments
2007-08-24 19:32:36 +00:00
rsc
4bc5056c19 formatting, simplify 2007-08-14 19:05:48 +00:00
rsc
3d145283a2 tweak kalloc 2007-08-10 17:02:36 +00:00
rsc
b6095304b7 Make cp a magic symbol. 2007-08-10 16:37:27 +00:00
kaashoek
8e1d1ec934 some comment changes 2006-09-08 14:36:44 +00:00
rsc
31085bb416 more comments 2006-09-07 14:12:30 +00:00
rsc
d4c64e5d43 writeable => writable 2006-09-06 18:06:04 +00:00
rsc
f552738889 no /* */ comments 2006-09-06 17:50:20 +00:00
rsc
9e9bcaf143 standardize various * conventions 2006-09-06 17:27:19 +00:00
rtm
82537b7156 nits 2006-09-04 11:52:36 +00:00
rtm
2aa4c3bc29 complain if no disk 1
lots of cleanup
2006-08-30 18:55:06 +00:00
rtm
5be0039ce9 interrupts could be recursive since lapic_eoi() called before rti
so fast interrupts overflow the kernel stack
fix: cli() before lapic_eoi()
2006-08-10 22:08:14 +00:00
rtm
32630628a9 open() 2006-07-29 09:35:02 +00:00
rsc
b5ee516575 add uint and standardize on typedefs instead of unsigned 2006-07-17 01:52:13 +00:00
rsc
c54c79267f nitpicks 2006-07-17 01:25:22 +00:00
rsc
84d79573da more idiomatic c 2006-07-16 16:05:37 +00:00
rtm
8148b6ee53 i think my cmpxchg use was wrong in acquire
nesting cli/sti: release shouldn't always enable interrupts
separate setup of lapic from starting of other cpus, so cpu() works earlier
flag to disable locking in console output
make locks work even when curproc==0
(still crashes in clock interrupt)
2006-07-12 11:15:38 +00:00
rtm
4e8f237be8 no more big kernel lock
succeeds at usertests.c pipe test
2006-07-12 01:48:35 +00:00
rtm
b548df152b pre-empt both user and kernel, in clock interrupt
usertest.c tests pre-emption
kill()
2006-07-11 17:39:45 +00:00
rtm
8b4e2a08fe swtch saves callee-saved registers
swtch idles on per-CPU stack, not on calling process's stack
fix pipe bugs
usertest.c tests pipes, fork, exit, close
2006-07-01 21:26:01 +00:00