Commit Graph

1774 Commits

Author SHA1 Message Date
Zihao Yu 423b48194d native,cte: protect "physical memory" from user space 2020-02-13 14:45:34 +08:00
Yanyan Jiang 9ebdc1c2d3
Merge pull request #93 from jiangyy/fceux-refactor
apps,fceux: call FCEUD_GetTime() instead of uptime()
2020-02-13 13:18:36 +08:00
Zihao Yu ae2d7515f1 apps,fceux: call FCEUD_GetTime() instead of uptime()
* make it easier to port
2020-02-13 03:19:44 +08:00
Zihao Yu 4234611e49
Merge pull request #92 from jiangyy/os2020-fixes
ready for os2020 merge
2020-02-13 03:10:50 +08:00
Yanyan Jiang 51fc597119 klib: change assert() to _halt() to avoid link error without printf 2020-02-13 00:59:45 +08:00
Yanyan Jiang 80b7a8e272 os-export: fix export file issues 2020-02-13 00:44:38 +08:00
Yanyan Jiang 00bafc5e4c os-export: fix export file issues 2020-02-13 00:39:36 +08:00
Yanyan Jiang d1bed51677 x86-qemu: remove debug option; will be taught in class 2020-02-13 00:22:21 +08:00
Yanyan Jiang ae20f1b96f x86-qemu: fall back to tcg 2020-02-12 23:26:23 +08:00
Yanyan Jiang 5f438debfa x86-qemu: get memory by cmos 2020-02-12 22:48:13 +08:00
Yanyan Jiang 7f272c2414 export: refactor os export 2020-02-12 20:54:32 +08:00
Yanyan Jiang f0c4f05bf5 fceux,litenes: fix makefile to work on fresh build 2020-02-12 20:34:48 +08:00
Zihao Yu 7e484d8af8
Merge pull request #90 from jiangyy/native-exit
native,platform: exit gracefully when smp=1
2020-02-12 19:26:03 +08:00
Zihao Yu 3f003e387f Merge branch 'master' into native-exit 2020-02-12 19:19:13 +08:00
Zihao Yu 547062e8ea
Merge pull request #91 from jiangyy/fixes
dynamic page size for native
2020-02-12 19:16:59 +08:00
Zihao Yu 57ab1f765c native,platform: exit gracefully when smp=1 and clean the shm file 2020-02-12 19:15:18 +08:00
Yanyan Jiang 1f53c21965 native: pagesize is now determined at runtime 2020-02-12 17:10:11 +08:00
Yanyan Jiang 36679280c5
Merge pull request #89 from jiangyy/nemu-new-api
Nemu new api
2020-02-12 17:05:50 +08:00
Zihao Yu 6af2c43a92 libs,klib,int64: add __clzsi2/__ctzsi2 for riscv32 to link 2020-02-12 15:45:35 +08:00
Zihao Yu 15514cb3f1 navy,trm: fix compile error 2020-02-12 15:45:10 +08:00
Zihao Yu e7ffbae3a9 Revert "riscv32-nemu: add integer library functions to pass linking"
This reverts commit aca9a5dd6d.
2020-02-12 15:43:29 +08:00
Zihao Yu d72ed0ca11 *-nemu,vme: update to the latest semantics
* the size unit of pgalloc_f() is byte
* set as->area to the uvm address space to let OS determine where the
  user stack is located
* change c->as to store as->ptr
* do not switch to NULL address space, just return
* _kcontext() should set c->ptr to NULL
* let _map() check whether va and pa are aligned by PGSIZE
2020-02-12 15:09:39 +08:00
Zihao Yu 5f1691ce97 *-nemu,cte: do not allow event handler to return NULL context 2020-02-12 14:56:09 +08:00
Zihao Yu bddf8239be *-nemu,cte: support stack switching from user to kernel
* To support stack switching from user to kernel with a software-based
  method, we need the following
  (1) something to identify whether the trap comes from user or kernel
  space
  (2) the kernel stack to switch to
  (3) something to identify whether the trap returns to user or kernel
  space
  (4) the user stack to resume to

* In mips32,
  + We use $k0 to achieve (1) + (2). When a trap is taken, first examine
    $k0. If it is 0, the trap comes from kernel space and there is no
    need to perform stack switching. If it is not 0, it must store the
    kernel stack to switch to. Then we set $k0 to 0 to support nested
    traps.
  + We use $sp's saving slot in the context structure to achive (3) +
    (4). If it is 0, the trap is going to return to kernel and there is
    no need to perform stack switching. Also there is no need to update
    $k0 since it is still 0. If it is not 0, it must store the user
    stack to switch to. Before switching back to user stack, we should
    also set $k0 to the current $sp as the kernel stack. At the next
    time a trap is taken, we will switch to such $sp.
  + The remaining is to correct initialize $k0 and $sp's saving slot.

* riscv32 is similar to mips32, except that we use sscratch to achieve
  (1) + (2)

* A real x86 uses DPL + TSS to achieve (1) + (2), and iret to achieve
  (3) + (4). But this is complicated for students. Therefore we use a
  nearly software-based solution.
  + We use a global variable __am_ksp to achieve (1) + (2), and a new
    member `usp` which next to `eip` in the context structure to achieve
    (3) + (4).
  + We will still push part of context on the user stack before we
    switch to the kernel stack when a trap is taken. There is no way to
    avoid this, since x86 leverages hardware stack. We should move the
    values pushed on the user stack to the kernel stack after we switch
    to it, and store the stack pointer right before the trap is taken to
    `usp`, pretending the whole context is pushed totally on the kernel
    stack.
  + Trouble comes when we are going to return to user space. Switching
    back to user stack and popping eflags/cs/eip should be performed
    atomically. We can never achieve this with any software-based
    solution. Therefore we modify the behavior of the iret instruction
    to a customized version:
      temp <- pop();
      standard_iret();
      if (temp != 0) esp <- temp;
    This is why we require the new `usp` member should be next to `eip`
    in the context structure.
  + Note that the customized version of iret still does not write
    memory. Thus it will not hurt the process of DiffTest in NEMU by
    using `difftest_skip_ref()` to let QEMU skip the iret instruciton
    and perform register synchronization. But we need to synchronize
    eflags, too.
2020-02-12 14:51:29 +08:00
Zihao Yu f99a5d42e5
Merge pull request #88 from jiangyy/os-export
ready to export to OS2020
2020-02-12 00:16:06 +08:00
Zihao Yu 04ca51d531
Merge pull request #86 from jiangyy/fixes
Minor code fixes
2020-02-12 00:03:29 +08:00
Yanyan Jiang 1ce24984bf amtest: vmtest work for both native and qemu 2020-02-11 22:56:22 +08:00
Yanyan Jiang 6052c6a596 a full export 2020-02-11 14:43:40 +00:00
Yanyan Jiang d38a0a20de nes-roms: rewrite script using pathlib 2020-02-11 14:34:44 +00:00
Yanyan Jiang d38cdcb0d2 vme: add short readme for MPE 2020-02-11 21:40:19 +08:00
Yanyan Jiang a1d5f80602 vme: add a check to make sure mkstemp will not leave junks in / 2020-02-11 13:02:31 +00:00
Yanyan Jiang bfd47e199c vme: use mkstemp to surpress warning; update test code 2020-02-11 12:56:16 +00:00
Zihao Yu 955e903bd4 am,x86-nemu,cte: remove error code in _Context 2020-02-11 18:17:29 +08:00
Zihao Yu 526da7b029
Merge pull request #85 from jiangyy/native-ustack
Native ustack
2020-02-11 09:05:23 +08:00
Zihao Yu fccdf292df *-nemu,cte: support _kcontext() with arg 2020-02-10 15:10:44 +08:00
Zihao Yu 4bd8eea09d native,platform: move pmem to 0x3000000
* To run apps in PA3, we have the following convention
  * TRM should guaruntee the address of 0x3000000/0x83000000 is
    avaliable.
  * Navy-apps will link apps to this address.
  * Nanos-lite use naive_uload() to directly call `_start()` in libc
    with the AM boot stack.
  * `_start` in libc should initialize the frame pointer, then directly
    calls `call_main()`.
  * `call_main()` does not parse arguments on the stack, and set up
    empty argc/argv/envp, then call `main()`. Therefore we do not
    support passing arguments to `main()` at this time.
  * Exceptions are handled on the AM boot stack.
* Now native and *-nemu all support naive_uload().
2020-02-10 13:27:48 +08:00
Zihao Yu 97f4d7cd87 tests,klibtest,printf_test: only enable longlong test in 64bit-arch 2020-02-10 13:26:09 +08:00
Zihao Yu aca9a5dd6d riscv32-nemu: add integer library functions to pass linking
* they are called in __udivmoddi4(), which is used with uint64_t
  division in klib/src/stdio.c
2020-02-10 13:22:36 +08:00
Zihao Yu c2c8e24392 *-nemu: update cte/vme to the latest AM API 2020-02-10 13:19:54 +08:00
Zihao Yu 23dacb751e libs,klib,klib-macros: fix RANGE 2020-02-10 12:57:49 +08:00
Zihao Yu e0e082bd6a native,cte: remove redundant instruction in __am_kcontext_start 2020-02-08 21:47:18 +08:00
Zihao Yu 2fb8c708c6 native,cte: support user stack 2020-02-08 21:12:56 +08:00
Zihao Yu d8cdbd9bf0 native,platform: setup the signal stack before saving the example context
* The signal stack is per-ucontext. Switching ucontext will also affect
  the signal stack.
2020-02-08 21:10:52 +08:00
Zihao Yu 747732337b native,cte: save/restore context completely with signal handler
* setcontext() will only restore those which will be saved in getcontext()
* Signal handler will atomically restore everything in ucontext. This
  greatly simplifies the trap code, and also makes it possible to return
  to user space while switching to the user stack.
2020-02-08 21:02:24 +08:00
Zihao Yu 1cc983b512 native,cte: use alternative stack for signal handling
* we can not handle signal with ustack which may cause pagefault
2020-02-08 20:11:23 +08:00
Zihao Yu da842bd755 native,cte: refactor the code constructing context in signal handler
* it is safer to use C type
2020-02-08 17:25:46 +08:00
Zihao Yu d49f9f61bf native: adapt to latest AM API 2020-02-08 16:57:17 +08:00
Yanyan Jiang 03ac3bfaff
Merge pull request #84 from jiangyy/cte-new-api
Cte new api
2020-02-08 15:39:37 +08:00
Zihao Yu 435ed0e0ed x86-qemu,cte: rename _kcontext_start to __am_kcontext_start
* it is AM-internal
2020-02-08 15:35:31 +08:00
Zihao Yu 1d392f9767 am: rollback _kcontext()/_ucontext() to the original version
* but we still introduce _kcontext_start() to set up arg for _kcontext(),
  this makes _kcontext() only push the constructed _Context at kstack.end
2020-02-08 15:16:01 +08:00