Commit graph

89 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
Frans Kaashoek 4f14d8d1e5 Commit to running on an SMP (perhaps with only 1 core). Remove most code
from picirq.c and remove timer.c completely.  Update runoff.list.
2017-08-09 07:44:51 -04:00
Frans Kaashoek c9fa90f7e5 A tiny bit of clean up (e.g., move code searching cpu array from lapic.c into
mycpu() in proc.c.
2017-02-01 20:36:41 -05:00
Frans Kaashoek 2e2d14c235 use panic 2017-02-01 19:21:43 -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
Frans Kaashoek b7fed77b7b Fix a few lines that runoff is complaining about that they are too long 2016-09-02 14:59:00 -04:00
Frans Kaashoek ae15515d80 APIC IDs may not be consecutive and start from zero, so we cannot really use it
as a direct index into cpus.  Record apicid in struct cpu and have cpunum() look
for it. Replace cpu->id with cpunum() everywhere, and replace cpu->id with cpu->apicid.
Thanks to Xi Wang.
2016-09-02 08:31:13 -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
Frans Kaashoek 50edfe1412 nits 2015-11-15 13:40:42 -05:00
Nathaniel Wesley Filardo 5906118897 Remove console input.lock
Use cons.lock for everything.  This eliminates the possibility that two CPUS
independently, simultaneously manipulate the CRTC in cgaputc.
2015-11-15 13:28:43 -05:00
Nathaniel Wesley Filardo 02530a4859 Add sanity check panic for CRTC interactions 2015-11-15 13:28:15 -05:00
Austin Clements 9b59dc44dc Remove unused 'state' variable that broke the build in recent gcc's 2011-09-07 16:39:27 -04:00
Austin Clements c6c0cb82c4 Fix same wonky pagebreak bug in console.c 2011-09-02 15:35:49 -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 c5f5387351 fixes from Peter Froehlich 2011-02-28 09:32:20 -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
Austin Clements 8440dbfee1 Get consoleintr back on one page 2010-09-02 18:54:50 -04:00
Austin Clements 08eef9eae5 Get cgaputc and consputc back on the same page 2010-09-02 18:50:49 -04:00
Austin Clements b0751a3e9b Space police 2010-09-01 00:41:25 -04:00
Austin Clements 5efca9054f Tab police 2010-09-01 00:32:27 -04:00
Austin Clements 29d8c2eebb Handle backspace on serial input and output better. Better solutions are welcome. 2009-09-30 22:32:50 -04:00
Austin Clements 3adc415471 Hack to make newlines on the serial port work 2009-09-20 23:09:59 -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
rsc 34295f461a group locks into structs they protect.
few naming nits.
2009-05-31 05:12:21 +00:00
rsc 74afa70d30 Add serial port input/output.
Delete parallel port output.
Works well with qemu -nographic mode.
2009-05-31 00:24:11 +00:00
rsc 2157576107 be consistent: no underscores in function names 2009-03-08 22:07:13 +00:00
kolya 289bbef733 minor cleanup 2008-10-12 20:19:16 +00:00
kolya 02cc595f28 clean up circular buffers, so pipe can queue 512 bytes rather than 511 2008-08-22 00:26:22 +00:00
kolya 5c5470a2fa fix obvious printf nits after reading through code 2008-08-21 23:24:02 +00:00
rsc aefc13f8ba nit 2007-09-27 20:25:32 +00:00
rsc 75506c6655 use console lock 2007-09-27 12:29:25 +00:00
rtm fbd8857d4d make new Homework 8 work 2007-08-30 18:21:35 +00:00
rsc 37321196a4 oops - broke circular buffer 2007-08-30 18:20:53 +00:00
rsc eb52c7de1d comments; rename irq_ to pic_ 2007-08-28 19:04:36 +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 c1b100e930 nits 2007-08-28 18:23:48 +00:00
rsc d844f0f9d9 Change dev read/write functions
to take inode* instead of minor number.

Unlock console inode during console_read
and console_write.  Otherwise background
processes cannot write to console while the
shell is reading it waiting for input.
2007-08-28 17:49:49 +00:00
rsc 51c0c1a8fe avoid double echo 2007-08-28 04:26:19 +00:00
rsc e6ffaa9d8e oops 2007-08-28 04:13:40 +00:00
rsc f0d11fea82 Move keyboard code into kbd.c; add backspace handling. 2007-08-28 03:28:13 +00:00
rsc 558ab49f13 delete unnecessary #include lines 2007-08-27 23:26:33 +00:00
rsc 97ac612fb1 nits 2007-08-24 20:28:08 +00:00
rsc fe5f50a03d fixes 2007-08-14 19:41:01 +00:00
rsc 5e8c5d8bb8 formatting; split kbd constants into kbd.h 2007-08-14 19:31:16 +00:00
rsc b6095304b7 Make cp a magic symbol. 2007-08-10 16:37:27 +00:00
rsc f2f062da61 check p->killed for long-lived sleeps 2007-08-08 10:29:42 +00:00