├── LICENSE ├── README.md ├── lab ├── binary-bomb-lab │ ├── 171830635.txt │ ├── bomb │ └── bomb.c ├── buffer-overflow-attack-lab │ ├── bang.txt │ ├── boom.txt │ ├── bufbomb │ ├── fizz.txt │ ├── hex2raw │ ├── kaboom.txt │ ├── makecookie │ └── smoke.txt ├── data-lab │ ├── Makefile │ ├── bits.c │ ├── bits.h │ ├── btest.c │ ├── btest.h │ ├── decl.c │ ├── dlc │ ├── fshow.c │ ├── ishow.c │ └── tests.c └── link-lab │ ├── main.o │ ├── phase1.o │ ├── phase2.o │ ├── phase3.o │ ├── phase3_patch.o │ ├── phase4.o │ ├── phase5.o │ └── phase6.o └── pa2018_fall ├── Makefile ├── include ├── config.h └── trap.h ├── kernel ├── Makefile ├── include │ ├── common.h │ ├── debug.h │ ├── memory.h │ ├── x86.h │ └── x86 │ │ ├── cpu.h │ │ ├── io.h │ │ └── memory.h ├── src │ ├── driver │ │ └── ide │ │ │ ├── cache.c │ │ │ ├── disk.c │ │ │ ├── dma.c │ │ │ ├── dma.h │ │ │ └── ide.c │ ├── elf │ │ └── elf.c │ ├── fs │ │ └── fs.c │ ├── irq │ │ ├── do_irq.S │ │ ├── i8259.c │ │ ├── idt.c │ │ └── irq_handle.c │ ├── lib │ │ ├── misc.c │ │ ├── printk.c │ │ └── serial.c │ ├── main.c │ ├── memory │ │ ├── kvm.c │ │ ├── mm.c │ │ ├── mm_malloc.o │ │ └── vmem.c │ └── syscall │ │ └── do_syscall.c └── start │ ├── start.S │ └── start.txt ├── libs ├── nemu-ref │ ├── include │ │ ├── cpu-ref │ │ │ ├── alu_ref.h │ │ │ ├── fpu_ref.h │ │ │ ├── instr_helper_ref.h │ │ │ └── instr_ref.h │ │ ├── scoring.h │ │ └── test │ │ │ └── reg_alu_fpu_test_score.h │ └── lib-nemu-ref.a └── newlib │ ├── include │ ├── _ansi.h │ ├── _syslist.h │ ├── alloca.h │ ├── ar.h │ ├── argz.h │ ├── assert.h │ ├── complex.h │ ├── ctype.h │ ├── dirent.h │ ├── envlock.h │ ├── envz.h │ ├── errno.h │ ├── fastmath.h │ ├── fcntl.h │ ├── fnmatch.h │ ├── getopt.h │ ├── glob.h │ ├── grp.h │ ├── iconv.h │ ├── ieeefp.h │ ├── inttypes.h │ ├── langinfo.h │ ├── libgen.h │ ├── limits.h │ ├── locale.h │ ├── machine │ │ ├── _default_types.h │ │ ├── _types.h │ │ ├── ansi.h │ │ ├── endian.h │ │ ├── fastmath.h │ │ ├── ieeefp.h │ │ ├── malloc.h │ │ ├── param.h │ │ ├── setjmp-dj.h │ │ ├── setjmp.h │ │ ├── stdlib.h │ │ ├── termios.h │ │ ├── time.h │ │ └── types.h │ ├── malloc.h │ ├── math.h │ ├── newlib.h │ ├── paths.h │ ├── pthread.h │ ├── pwd.h │ ├── reent.h │ ├── regdef.h │ ├── regex.h │ ├── rpc │ │ ├── types.h │ │ └── xdr.h │ ├── sched.h │ ├── search.h │ ├── setjmp.h │ ├── signal.h │ ├── spawn.h │ ├── stdatomic.h │ ├── stdint.h │ ├── stdio.h │ ├── stdio_ext.h │ ├── stdlib.h │ ├── string.h │ ├── strings.h │ ├── sys │ │ ├── _default_fcntl.h │ │ ├── _types.h │ │ ├── cdefs.h │ │ ├── config.h │ │ ├── custom_file.h │ │ ├── dir.h │ │ ├── dirent.h │ │ ├── errno.h │ │ ├── fcntl.h │ │ ├── features.h │ │ ├── file.h │ │ ├── iconvnls.h │ │ ├── lock.h │ │ ├── param.h │ │ ├── queue.h │ │ ├── reent.h │ │ ├── resource.h │ │ ├── sched.h │ │ ├── signal.h │ │ ├── stat.h │ │ ├── stdio.h │ │ ├── string.h │ │ ├── syslimits.h │ │ ├── time.h │ │ ├── timeb.h │ │ ├── times.h │ │ ├── types.h │ │ ├── unistd.h │ │ ├── utime.h │ │ └── wait.h │ ├── tar.h │ ├── termios.h │ ├── tgmath.h │ ├── time.h │ ├── unctrl.h │ ├── unistd.h │ ├── utime.h │ ├── utmp.h │ ├── wchar.h │ ├── wctype.h │ └── wordexp.h │ └── libc.a ├── nemu ├── Makefile ├── include │ ├── cpu │ │ ├── alu.h │ │ ├── cpu.h │ │ ├── fpu.h │ │ ├── instr.h │ │ ├── instr │ │ │ ├── adc.h │ │ │ ├── add.h │ │ │ ├── and.h │ │ │ ├── call.h │ │ │ ├── cli.h │ │ │ ├── cmp.h │ │ │ ├── dec.h │ │ │ ├── div.h │ │ │ ├── flags.h │ │ │ ├── group.h │ │ │ ├── idiv.h │ │ │ ├── imul.h │ │ │ ├── in.h │ │ │ ├── inc.h │ │ │ ├── int.h │ │ │ ├── iret.h │ │ │ ├── jmp.h │ │ │ ├── lea.h │ │ │ ├── leave.h │ │ │ ├── lgdt.h │ │ │ ├── lidt.h │ │ │ ├── mov.h │ │ │ ├── mul.h │ │ │ ├── neg.h │ │ │ ├── not.h │ │ │ ├── or.h │ │ │ ├── out.h │ │ │ ├── pop.h │ │ │ ├── push.h │ │ │ ├── ret.h │ │ │ ├── sbb.h │ │ │ ├── set.h │ │ │ ├── shift.h │ │ │ ├── special.h │ │ │ ├── sti.h │ │ │ ├── stoc.h │ │ │ ├── sub.h │ │ │ ├── test.h │ │ │ ├── x87.h │ │ │ └── xor.h │ │ ├── instr_helper.h │ │ ├── intr.h │ │ ├── modrm.h │ │ ├── operand.h │ │ ├── reg.h │ │ ├── reg_fpu.h │ │ └── sib.h │ ├── device │ │ ├── audio.h │ │ ├── i8259_pic.h │ │ ├── ide.h │ │ ├── keyboard.h │ │ ├── mm_io.h │ │ ├── port_io.h │ │ ├── sdl.h │ │ ├── serial.h │ │ ├── timer.h │ │ └── vga.h │ ├── macro.h │ ├── memory │ │ ├── cache.h │ │ ├── memory.h │ │ └── mmu │ │ │ ├── page.h │ │ │ ├── segment.h │ │ │ └── tlb.h │ ├── monitor │ │ ├── breakpoint.h │ │ └── ui.h │ ├── nemu.h │ └── test │ │ └── reg_alu_fpu_test.h └── src │ ├── cpu │ ├── alu.c │ ├── cpu.c │ ├── decode │ │ ├── debug.c │ │ ├── modrm.c │ │ ├── opcode.c │ │ ├── opcode_ref.c │ │ ├── operand.c │ │ └── sib.c │ ├── fpu.c │ ├── instr │ │ ├── adc.c │ │ ├── add.c │ │ ├── and.c │ │ ├── bt.c │ │ ├── call.c │ │ ├── cbw.c │ │ ├── cli.c │ │ ├── cltd.c │ │ ├── cmov.c │ │ ├── cmp.c │ │ ├── cmps.c │ │ ├── data_size.c │ │ ├── dec.c │ │ ├── div.c │ │ ├── flags.c │ │ ├── group.c │ │ ├── hlt.c │ │ ├── idiv.c │ │ ├── imul.c │ │ ├── in.c │ │ ├── inc.c │ │ ├── int.c │ │ ├── inv.c │ │ ├── iret.c │ │ ├── jcc.c │ │ ├── jmp.c │ │ ├── lea.c │ │ ├── leave.c │ │ ├── lgdt.c │ │ ├── lidt.c │ │ ├── mov.c │ │ ├── movs.c │ │ ├── mul.c │ │ ├── neg.c │ │ ├── nemu_trap.c │ │ ├── nop.c │ │ ├── not.c │ │ ├── opcode_2_byte.c │ │ ├── or.c │ │ ├── out.c │ │ ├── pop.c │ │ ├── push.c │ │ ├── rep_repe.c │ │ ├── ret.c │ │ ├── sar.c │ │ ├── sbb.c │ │ ├── setcc.c │ │ ├── shl.c │ │ ├── shr.c │ │ ├── sti.c │ │ ├── stos.c │ │ ├── sub.c │ │ ├── test.c │ │ ├── x87.c │ │ └── xor.c │ ├── intr.c │ ├── reg.c │ └── test │ │ ├── alu_test.c │ │ └── fpu_test.c │ ├── device │ ├── dev │ │ ├── audio.c │ │ ├── ide.c │ │ ├── keyboard.c │ │ ├── serial.c │ │ ├── timer.c │ │ ├── vga-palette.c │ │ └── vga.c │ ├── i8259_pic.c │ ├── io │ │ ├── mm_io.c │ │ └── port_io.c │ └── sdl.c │ ├── main.c │ ├── memory │ ├── cache.c │ ├── memory.c │ └── mmu │ │ ├── page.c │ │ ├── segment.c │ │ └── tlb.c │ ├── monitor │ ├── breakpoint.c │ ├── elf.c │ ├── expr.c │ └── ui.c │ └── parse_args.c ├── scripts ├── emotion_dialog.sh ├── gitmonitor.sh ├── make_emotion.sh ├── score_testcases │ ├── 30000 │ │ ├── 32_keyboard_inline │ │ ├── 32_keyboard_inline.img │ │ ├── add │ │ ├── add-longlong │ │ ├── add-longlong.img │ │ ├── add.img │ │ ├── bit │ │ ├── bit.img │ │ ├── bubble-sort │ │ ├── bubble-sort.img │ │ ├── echo │ │ ├── echo.img │ │ ├── fact │ │ ├── fact.img │ │ ├── fib │ │ ├── fib.img │ │ ├── gotbaha │ │ ├── gotbaha.img │ │ ├── hello-inline │ │ ├── hello-inline.img │ │ ├── hello-str │ │ ├── hello-str.img │ │ ├── if-else │ │ ├── if-else.img │ │ ├── leap-year │ │ ├── leap-year.img │ │ ├── matrix-mul │ │ ├── matrix-mul-small │ │ ├── matrix-mul-small.img │ │ ├── matrix-mul.img │ │ ├── max │ │ ├── max.img │ │ ├── min3 │ │ ├── min3.img │ │ ├── mov │ │ ├── mov-c │ │ ├── mov-c.img │ │ ├── mov-cmp │ │ ├── mov-cmp.img │ │ ├── mov-jcc │ │ ├── mov-jcc.img │ │ ├── mov.img │ │ ├── movsx │ │ ├── movsx.img │ │ ├── mul-longlong │ │ ├── mul-longlong.img │ │ ├── pascal │ │ ├── pascal.img │ │ ├── prime │ │ ├── prime.img │ │ ├── quick-sort │ │ ├── quick-sort.img │ │ ├── select-sort │ │ ├── select-sort.img │ │ ├── shuixianhua │ │ ├── shuixianhua.img │ │ ├── string │ │ ├── string.img │ │ ├── struct │ │ ├── struct.img │ │ ├── sub-longlong │ │ ├── sub-longlong.img │ │ ├── sum │ │ ├── sum.img │ │ ├── test-float │ │ ├── test-float.img │ │ ├── wanshu │ │ └── wanshu.img │ ├── 60000 │ │ ├── 32_keyboard_inline │ │ ├── add │ │ ├── add-longlong │ │ ├── bit │ │ ├── bubble-sort │ │ ├── echo │ │ ├── fact │ │ ├── fib │ │ ├── gotbaha │ │ ├── hello-inline │ │ ├── hello-str │ │ ├── if-else │ │ ├── leap-year │ │ ├── matrix-mul │ │ ├── matrix-mul-small │ │ ├── max │ │ ├── min3 │ │ ├── mov │ │ ├── mov-c │ │ ├── mov-cmp │ │ ├── mov-jcc │ │ ├── movsx │ │ ├── mul-longlong │ │ ├── pascal │ │ ├── prime │ │ ├── quick-sort │ │ ├── select-sort │ │ ├── shuixianhua │ │ ├── string │ │ ├── struct │ │ ├── sub-longlong │ │ ├── sum │ │ ├── test-float │ │ └── wanshu │ ├── game │ └── page │ │ ├── 32_keyboard_inline │ │ ├── add │ │ ├── add-longlong │ │ ├── bit │ │ ├── bubble-sort │ │ ├── echo │ │ ├── fact │ │ ├── fib │ │ ├── gotbaha │ │ ├── hello-inline │ │ ├── hello-str │ │ ├── if-else │ │ ├── leap-year │ │ ├── matrix-mul │ │ ├── matrix-mul-small │ │ ├── max │ │ ├── min3 │ │ ├── mov │ │ ├── mov-c │ │ ├── mov-cmp │ │ ├── mov-jcc │ │ ├── movsx │ │ ├── mul-longlong │ │ ├── pascal │ │ ├── prime │ │ ├── quick-sort │ │ ├── select-sort │ │ ├── shuixianhua │ │ ├── string │ │ ├── struct │ │ ├── sub-longlong │ │ ├── sum │ │ ├── test-float │ │ └── wanshu ├── submit ├── update └── upload_tracking └── testcase ├── Makefile ├── src ├── 32_keyboard_inline.c ├── add-longlong.c ├── add.c ├── bit.c ├── bubble-sort.c ├── echo.c ├── fact.c ├── fib.c ├── gotbaha.c ├── hello-inline.c ├── hello-str.c ├── if-else.c ├── leap-year.c ├── matrix-mul-small.c ├── matrix-mul.c ├── max.c ├── min3.c ├── mov-c.c ├── mov-cmp.S ├── mov-jcc.c ├── mov.S ├── movsx.c ├── mul-longlong.c ├── pascal.c ├── prime.c ├── quick-sort.c ├── select-sort.c ├── shuixianhua.c ├── string.c ├── struct.c ├── sub-longlong.c ├── sum.c ├── test-float.c └── wanshu.c └── start.S /README.md: -------------------------------------------------------------------------------- 1 | # NJU-ICS 2 | 南京大学计算机系统基础PA和Lab 3 | -------------------------------------------------------------------------------- /lab/binary-bomb-lab/171830635.txt: -------------------------------------------------------------------------------- 1 | 33 51 105 77 2 | DRAM stores each bit as charge on a capacitor. 3 | 207 104 53 27 14 8 5 3 4 | 23 704 5 | 10 354NYoIVEl 6 | acdeffg 7 | 5 2 3 4 1 7 6 8 8 | 35 9 | 10 | -------------------------------------------------------------------------------- /lab/binary-bomb-lab/bomb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/binary-bomb-lab/bomb -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/bang.txt: -------------------------------------------------------------------------------- 1 | 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 2 | a1 78 d1 04 08 /* movl 0x804d178,%eax */ 3 | a3 80 d1 04 08 /* movl %eax,0x804d180 */ 4 | c7 04 24 46 8c 04 08 /* movl $0x8048c46,(%esp) */ 5 | c3 /* ret */ 6 | 02 be 68 55 /* 0x5568be02 */ 7 | -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/boom.txt: -------------------------------------------------------------------------------- 1 | 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 2 | a1 78 d1 04 08 /* movl 0x804d178,%eax */ 3 | 68 b4 8c 04 08 /* push $0x8048cb4 */ 4 | c3 /* ret */ 5 | 30 be 68 55 /* 0x5568be30 */ 6 | 05 be 68 55 /* 0x5568be05 */ 7 | -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/bufbomb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/buffer-overflow-attack-lab/bufbomb -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/fizz.txt: -------------------------------------------------------------------------------- 1 | 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 39 39 39 39 f5 8b 04 08 39 39 39 39 87 4d 6b 3b 2 | -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/hex2raw: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/buffer-overflow-attack-lab/hex2raw -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/makecookie: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/buffer-overflow-attack-lab/makecookie -------------------------------------------------------------------------------- /lab/buffer-overflow-attack-lab/smoke.txt: -------------------------------------------------------------------------------- 1 | 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 36 39 39 39 39 c8 8b 04 08 2 | -------------------------------------------------------------------------------- /lab/data-lab/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile that builds btest and other helper programs for the NJU:ICS data lab 3 | # 4 | CC = gcc 5 | CFLAGS = -O -Wall -m32 6 | LIBS = -lm 7 | 8 | all: btest fshow ishow 9 | 10 | btest: btest.c bits.c decl.c tests.c btest.h bits.h 11 | $(CC) $(CFLAGS) $(LIBS) -o btest bits.c btest.c decl.c tests.c 12 | 13 | fshow: fshow.c 14 | $(CC) $(CFLAGS) -o fshow fshow.c 15 | 16 | ishow: ishow.c 17 | $(CC) $(CFLAGS) -o ishow ishow.c 18 | 19 | # Forces a recompile. Used by the driver program. 20 | btestexplicit: 21 | $(CC) $(CFLAGS) $(LIBS) -o btest bits.c btest.c decl.c tests.c 22 | 23 | clean: 24 | rm -f *.o btest fshow ishow *~ 25 | 26 | 27 | -------------------------------------------------------------------------------- /lab/data-lab/btest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * CS:APP Data Lab 3 | */ 4 | 5 | /* Declare different function types */ 6 | typedef int (*funct_t) (void); 7 | typedef int (*funct1_t)(int); 8 | typedef int (*funct2_t)(int, int); 9 | typedef int (*funct3_t)(int, int, int); 10 | 11 | /* Combine all the information about a function and its tests as structure */ 12 | typedef struct { 13 | char *name; /* String name */ 14 | funct_t solution_funct; /* Function */ 15 | funct_t test_funct; /* Test function */ 16 | int args; /* Number of function arguments */ 17 | char *ops; /* List of legal operators. Special case: "$" for floating point */ 18 | int op_limit; /* Max number of ops allowed in solution */ 19 | int rating; /* Problem rating (1 -- 4) */ 20 | int arg_ranges[3][2]; /* Argument ranges. Always defined for 3 args, even if */ 21 | /* the function takes fewer. Special case: First arg */ 22 | /* must be set to {1,1} for f.p. puzzles */ 23 | } test_rec, *test_ptr; 24 | 25 | extern test_rec test_set[]; 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /lab/data-lab/dlc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/data-lab/dlc -------------------------------------------------------------------------------- /lab/link-lab/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/main.o -------------------------------------------------------------------------------- /lab/link-lab/phase1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase1.o -------------------------------------------------------------------------------- /lab/link-lab/phase2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase2.o -------------------------------------------------------------------------------- /lab/link-lab/phase3.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase3.o -------------------------------------------------------------------------------- /lab/link-lab/phase3_patch.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase3_patch.o -------------------------------------------------------------------------------- /lab/link-lab/phase4.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase4.o -------------------------------------------------------------------------------- /lab/link-lab/phase5.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase5.o -------------------------------------------------------------------------------- /lab/link-lab/phase6.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/lab/link-lab/phase6.o -------------------------------------------------------------------------------- /pa2018_fall/include/config.h: -------------------------------------------------------------------------------- 1 | #ifndef __PA_CONFIG_H__ 2 | #define __PA_CONFIG_H__ 3 | 4 | // reference implementations, only for debugging, do not submit when defined 5 | //#define NEMU_REF_ALU 6 | //#define NEMU_REF_INSTR 7 | 8 | 9 | // PA 2 10 | 11 | 12 | // PA 3 13 | //#define CACHE_ENABLED 14 | #define IA32_SEG // protect mode enable 15 | #define IA32_PAGE // virtual memory management is now complete 16 | //#define TLB_ENABLED 17 | 18 | // PA 4 19 | #define IA32_INTR // tells NEMU and Kernel that we are ready for handling exceptions(traps only) and interrupts 20 | #define HAS_DEVICE_TIMER 21 | #define HAS_DEVICE_SERIAL // the disturbing 'nemu trap output:' tag will be removed 22 | #define HAS_DEVICE_IDE // the loader will load the elf from the hard disk instead of mem disk 23 | #define HAS_DEVICE_KEYBOARD // keyboard input 24 | #define HAS_DEVICE_VGA // we then have display 25 | #define HAS_DEVICE_AUDIO // audio, this is experimental, need to enable when submit pa-4-3 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /pa2018_fall/include/trap.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRAP_H__ 2 | #define __TRAP_H__ 3 | 4 | #define concat_temp(x, y) x ## y 5 | #define concat(x, y) concat_temp(x, y) 6 | 7 | #ifndef __ASSEMBLER__ 8 | 9 | #define HIT_GOOD_TRAP \ 10 | asm volatile(".byte 0x82" : : "a" (0)) 11 | 12 | #define HIT_BAD_TRAP \ 13 | asm volatile(".byte 0x82" : : "a" (1)) 14 | 15 | #define CHECK_POINT \ 16 | asm volatile(".byte 0x82" : : "a" (110)) 17 | 18 | #define nemu_assert(cond) \ 19 | do { \ 20 | if( !(cond) ) HIT_BAD_TRAP; \ 21 | } while(0); 22 | 23 | #define BREAK_POINT \ 24 | asm volatile(".byte 0xF1"); 25 | 26 | #else 27 | 28 | #define HIT_GOOD_TRAP \ 29 | movl $0, %eax; \ 30 | .byte 0x82 31 | 32 | #define HIT_BAD_TRAP \ 33 | movl $1, %eax; \ 34 | .byte 0x82 35 | 36 | #define CHECK_POINT \ 37 | movl $110, %eax; \ 38 | .byte 0x82 39 | 40 | #define nemu_assert(reg, val) \ 41 | cmp $val, %reg; \ 42 | je concat(label,__LINE__); HIT_BAD_TRAP; concat(label,__LINE__): 43 | 44 | #define BREAK_POINT \ 45 | .byte 0xF1 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/Makefile: -------------------------------------------------------------------------------- 1 | LIB_COMMON_DIR = ../libs 2 | NEWLIBC_DIR = $(LIB_COMMON_DIR)/newlib 3 | 4 | CC = gcc 5 | CFLAGS = -m32 -MMD -Wall -Werror -march=i386 -fno-builtin -fno-omit-frame-pointer -fno-stack-protector -I./include -I../include -I$(NEWLIBC_DIR)/include 6 | ASFLAGS = -m32 -MMD -I./include -I../include 7 | #LDFLAGS = -Ttext=0x30000 -m elf_i386 # before page 8 | LDFLAGS = -Ttext=0xc0030000 -m elf_i386 9 | 10 | CSRC = $(shell find ./src -name "*.c") 11 | SSRC = $(shell find ./src -name "*.S") 12 | 13 | OBJS = $(SSRC:.S=.o) $(CSRC:.c=.o) 14 | START_OBJ = start/start.o 15 | MM_MALLOC_OBJ = src/memory/mm_malloc.o 16 | ALL_OBJS = $(OBJS) $(START_OBJ) 17 | 18 | NEWLIBC = $(NEWLIBC_DIR)/libc.a 19 | 20 | kernel: $(ALL_OBJS) ../include/config.h Makefile 21 | ld $(LDFLAGS) -e start -o kernel $(START_OBJ) $(OBJS) $(MM_MALLOC_OBJ) $(NEWLIBC) 22 | #objcopy -S -O binary --set-start 0x0 kernel kernel.img 23 | objcopy -S -O binary kernel kernel.img 24 | 25 | -include $(ALL_OBJS:.o=.d) 26 | 27 | clean: 28 | -rm -f kernel kernel.img $(ALL_OBJS) $(ALL_OBJS:.o=.d) 29 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | #include "config.h" 5 | #include "trap.h" 6 | 7 | #ifndef __ASSEMBLER__ 8 | /* The following code will be included if the source file is a "*.c" file. */ 9 | 10 | 11 | #include 12 | #include 13 | 14 | typedef uint8_t bool; 15 | 16 | #define true 1 17 | #define false 0 18 | 19 | #define NULL ((void *)0) 20 | 21 | #include "debug.h" 22 | 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/include/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H__ 2 | #define __DEBUG_H__ 3 | 4 | #include "common.h" 5 | #include "x86.h" 6 | 7 | #define KERNEL_LABEL " {kernel} " 8 | 9 | void printk(const char *, ...); 10 | 11 | #define Log(format, ...) \ 12 | printk("\33[1;35m[%s,%d,%s]" KERNEL_LABEL format "\33[0m\n", \ 13 | __FILE__, __LINE__, __func__, ## __VA_ARGS__); \ 14 | 15 | #define panic(format, ...) \ 16 | do { \ 17 | Log("\33[1;31msystem panic: " format, ## __VA_ARGS__); \ 18 | HIT_BAD_TRAP; \ 19 | } while(0) 20 | 21 | #define assert(cond) \ 22 | do { \ 23 | if(!(cond)) { \ 24 | panic("Assertion failed: %s", #cond); \ 25 | } \ 26 | } while(0) 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_H__ 2 | #define __MEMORY_H__ 3 | 4 | #include "common.h" 5 | 6 | #ifdef IA32_PAGE 7 | #define KOFFSET 0xC0000000 8 | #else 9 | #define KOFFSET 0 10 | #endif 11 | 12 | #define va_to_pa(addr) ((void*)(((uint32_t)(addr)) - KOFFSET)) 13 | #define pa_to_va(addr) ((void*)(((uint32_t)(addr)) + KOFFSET)) 14 | 15 | /* the maxinum loader size is 16MB */ 16 | #define KMEM (16 * 1024 * 1024) 17 | 18 | /* NEMU has 128MB physical memory */ 19 | #define PHY_MEM (128 * 1024 * 1024) 20 | 21 | #define make_invalid_pde() 0 22 | #define make_invalid_pte() 0 23 | #define make_pde(addr) ((((uint32_t)(addr)) & 0xfffff000) | 0x7) 24 | #define make_pte(addr) ((((uint32_t)(addr)) & 0xfffff000) | 0x7) 25 | 26 | uint32_t mm_malloc(uint32_t, int len); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/include/x86.h: -------------------------------------------------------------------------------- 1 | #ifndef __X86_H__ 2 | #define __X86_H__ 3 | 4 | #include "x86/cpu.h" 5 | #include "x86/io.h" 6 | #include "x86/memory.h" 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/include/x86/io.h: -------------------------------------------------------------------------------- 1 | #ifndef __X86_IO_H__ 2 | #define __X86_IO_H__ 3 | 4 | #include 5 | 6 | static inline uint8_t 7 | in_byte(uint16_t port) { 8 | uint8_t data; 9 | asm volatile("in %1, %0" : "=a"(data) : "d"(port)); 10 | return data; 11 | } 12 | 13 | static inline uint32_t 14 | in_long(uint16_t port) { 15 | uint32_t data; 16 | asm volatile("in %1, %0" : "=a"(data) : "d"(port)); 17 | return data; 18 | } 19 | 20 | static inline void 21 | out_byte(uint16_t port, uint8_t data) { 22 | asm volatile("out %%al, %%dx" : : "a"(data), "d"(port)); 23 | } 24 | 25 | static inline void 26 | out_long(uint16_t port, uint32_t data) { 27 | asm volatile("out %%eax, %%dx" : : "a"(data), "d"(port)); 28 | } 29 | 30 | static inline uint16_t 31 | in_word(uint16_t port) { 32 | uint16_t data; 33 | asm volatile("in %1, %0" : "=a"(data) : "d"(port)); 34 | return data; 35 | } 36 | 37 | static inline void 38 | out_word(uint16_t port, uint16_t data) { 39 | asm volatile("out %%al, %%dx" : : "a"(data), "d"(port)); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/driver/ide/dma.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "memory.h" 3 | #include "x86.h" 4 | 5 | #define BMR_PORT 0xc040 6 | 7 | struct { 8 | uint32_t addr; 9 | uint16_t byte_cnt; 10 | uint16_t pad0 :15; 11 | uint16_t eot :1; 12 | } PRD; 13 | 14 | void 15 | dma_prepare(void *buf) { 16 | uint32_t addr = (uint32_t)va_to_pa(buf); 17 | 18 | PRD.addr = addr; 19 | PRD.byte_cnt = 512; 20 | PRD.eot = 1; 21 | PRD.pad0 = 0; 22 | 23 | uint32_t PRD_addr = (uint32_t)va_to_pa(&PRD); 24 | out_long(BMR_PORT + 4, PRD_addr); 25 | } 26 | 27 | void 28 | dma_issue_read(void) { 29 | out_byte(BMR_PORT, in_byte(BMR_PORT) | 0x1 | 0x8); 30 | } 31 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/driver/ide/dma.h: -------------------------------------------------------------------------------- 1 | #ifndef __DMA_H__ 2 | #define __DMA_H__ 3 | 4 | #define BMR_PORT 0xc040 5 | 6 | void dma_prepare(void *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/driver/ide/ide.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | #define WRITEBACK_TIME 1 /* writeback cache for every 1 second */ 4 | #define HZ 100 5 | 6 | void cache_init(void); 7 | void cache_writeback(void); 8 | uint8_t read_byte(uint32_t); 9 | void write_byte(uint32_t, uint8_t); 10 | 11 | void add_irq_handle(int, void (*)(void)); 12 | 13 | /* The loader acts as a monolithic kernel, therefore we do not need 14 | * to translate the address ``buf'' from the user process to a physical 15 | * one, which is necessary for a microkernel. 16 | */ 17 | void ide_read(uint8_t *buf, uint32_t offset, uint32_t len) { 18 | uint32_t i; 19 | for (i = 0; i < len; i ++) { 20 | buf[i] = read_byte(offset + i); 21 | } 22 | } 23 | 24 | void ide_write(uint8_t *buf, uint32_t offset, uint32_t len) { 25 | uint32_t i; 26 | for (i = 0; i < len; i ++) { 27 | write_byte(offset + i, buf[i]); 28 | } 29 | } 30 | 31 | static void 32 | ide_writeback(void) { 33 | static uint32_t counter = 0; 34 | counter ++; 35 | if (counter == WRITEBACK_TIME * HZ) { 36 | cache_writeback(); 37 | counter = 0; 38 | } 39 | } 40 | 41 | static volatile int has_ide_intr; 42 | 43 | static void 44 | ide_intr(void) { 45 | has_ide_intr = 1; 46 | } 47 | 48 | void 49 | clear_ide_intr(void) { 50 | has_ide_intr = 0; 51 | } 52 | 53 | void 54 | wait_ide_intr(void) { 55 | while(has_ide_intr == 0) { 56 | wait_intr(); 57 | } 58 | 59 | clear_ide_intr(); 60 | } 61 | 62 | void 63 | init_ide(void) { 64 | cache_init(); 65 | add_irq_handle(0, ide_writeback); 66 | add_irq_handle(14, ide_intr); 67 | } 68 | 69 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/elf/elf.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "memory.h" 3 | #include "string.h" 4 | 5 | #include 6 | 7 | #ifdef HAS_DEVICE_IDE 8 | #define ELF_OFFSET_IN_DISK 0 9 | #endif 10 | 11 | #define STACK_SIZE (1 << 20) 12 | 13 | void ide_read(uint8_t *, uint32_t, uint32_t); 14 | void create_video_mapping(); 15 | uint32_t get_ucr3(); 16 | 17 | uint32_t loader() { 18 | Elf32_Ehdr *elf; 19 | Elf32_Phdr *ph, *eph; 20 | 21 | #ifdef HAS_DEVICE_IDE 22 | uint8_t buf[4096]; 23 | ide_read(buf, ELF_OFFSET_IN_DISK, 4096); 24 | elf = (void*)buf; 25 | Log("ELF loading from hard disk."); 26 | #else 27 | elf = (void *)0x0; 28 | Log("ELF loading from ram disk."); 29 | #endif 30 | 31 | /* Load each program segment */ 32 | ph = (void *)elf + elf->e_phoff; 33 | eph = ph + elf->e_phnum; 34 | for(; ph < eph; ph ++) { 35 | if(ph->p_type == PT_LOAD) { 36 | //panic("Please implement the loader"); 37 | uint32_t paddr=mm_malloc(ph->p_vaddr,ph->p_memsz); 38 | ide_read((uint8_t *)paddr,ph->p_offset,ph->p_filesz); 39 | //memcpy((void*)paddr,(void*)ph->p_offset,ph->p_filesz); 40 | //if(ph->p_memsz>ph->p_filesz) 41 | //memset((void*)paddr+ph->p_filesz,0,ph->p_memsz-ph->p_filesz); 42 | 43 | #ifdef IA32_PAGE 44 | /* Record the program break for future use */ 45 | extern uint32_t brk; 46 | uint32_t new_brk = ph->p_vaddr + ph->p_memsz - 1; 47 | if(brk < new_brk) { brk = new_brk; } 48 | #endif 49 | } 50 | } 51 | 52 | volatile uint32_t entry = elf->e_entry; 53 | 54 | #ifdef IA32_PAGE 55 | mm_malloc(KOFFSET - STACK_SIZE, STACK_SIZE); 56 | #ifdef HAS_DEVICE_VGA 57 | create_video_mapping(); 58 | #endif 59 | write_cr3(get_ucr3()); 60 | #endif 61 | return entry; 62 | } 63 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/irq/i8259.c: -------------------------------------------------------------------------------- 1 | #include "x86.h" 2 | 3 | #define PORT_PIC_MASTER 0x20 4 | #define PORT_PIC_SLAVE 0xA0 5 | #define IRQ_SLAVE 2 6 | 7 | void init_i8259(void) { 8 | /* mask all interrupts */ 9 | out_byte(PORT_PIC_MASTER + 1, 0xFF); 10 | out_byte(PORT_PIC_SLAVE + 1 , 0xFF); 11 | 12 | /* start initialization */ 13 | out_byte(PORT_PIC_MASTER, 0x11); 14 | out_byte(PORT_PIC_MASTER + 1, 32); 15 | out_byte(PORT_PIC_MASTER + 1, 1 << 2); 16 | out_byte(PORT_PIC_MASTER + 1, 0x3); 17 | out_byte(PORT_PIC_SLAVE, 0x11); 18 | out_byte(PORT_PIC_SLAVE + 1, 32 + 8); 19 | out_byte(PORT_PIC_SLAVE + 1, 2); 20 | out_byte(PORT_PIC_SLAVE + 1, 0x3); 21 | out_byte(PORT_PIC_MASTER, 0x68); 22 | out_byte(PORT_PIC_MASTER, 0x0A); 23 | out_byte(PORT_PIC_SLAVE, 0x68); 24 | out_byte(PORT_PIC_SLAVE, 0x0A); 25 | } 26 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/irq/irq_handle.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "x86.h" 3 | 4 | #define NR_IRQ_HANDLE 32 5 | 6 | /* There are no more than 16(actually, 3) kinds of hardward interrupts. */ 7 | #define NR_HARD_INTR 16 8 | 9 | struct IRQ_t { 10 | void (*routine)(void); 11 | struct IRQ_t *next; 12 | }; 13 | 14 | static struct IRQ_t handle_pool[NR_IRQ_HANDLE]; 15 | static struct IRQ_t *handles[NR_HARD_INTR]; 16 | static int handle_count = 0; 17 | 18 | void do_syscall(TrapFrame *); 19 | 20 | void 21 | add_irq_handle(int irq, void (*func)(void) ) { 22 | assert(irq < NR_HARD_INTR); 23 | assert(handle_count <= NR_IRQ_HANDLE); 24 | 25 | struct IRQ_t *ptr; 26 | ptr = &handle_pool[handle_count ++]; /* get a free handler */ 27 | ptr->routine = func; 28 | ptr->next = handles[irq]; /* insert into the linked list */ 29 | handles[irq] = ptr; 30 | } 31 | 32 | void irq_handle(TrapFrame *tf) { 33 | int irq = tf->irq; 34 | 35 | if (irq < 0) { 36 | panic("Unhandled exception!"); 37 | } else if (irq == 0x80) { 38 | do_syscall(tf); 39 | } else if (irq < 1000) { 40 | panic("Unexpected exception #%d at eip = %x", irq, tf->eip); 41 | } else if (irq >= 1000) { 42 | int irq_id = irq - 1000; 43 | assert(irq_id < NR_HARD_INTR); 44 | //if(irq_id == 0) panic("You have hit a timer interrupt, remove this panic after you've figured out how the control flow gets here."); 45 | 46 | struct IRQ_t *f = handles[irq_id]; 47 | 48 | while (f != NULL) { /* call handlers one by one */ 49 | f->routine(); 50 | f = f->next; 51 | } 52 | } 53 | } 54 | 55 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/lib/misc.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | /* This function is defined only to make the newlibc linkable. 4 | * Without it, errors will be reported during linking. 5 | * But the execution flow should not reach here. 6 | */ 7 | void* sbrk(int incr) { 8 | assert(0); 9 | return NULL; 10 | } 11 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/lib/printk.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include 3 | 4 | //void serial_printc(char); 5 | size_t fs_write(int fd, void *buf, size_t len); 6 | 7 | /* __attribute__((__noinline__)) here is to disable inlining for this function to avoid some optimization problems for gcc 4.7 */ 8 | void __attribute__((__noinline__)) 9 | printk(const char *ctl, ...) { 10 | static char buf[256]; 11 | void *args = (void **)&ctl + 1; 12 | int len = vsnprintf(buf, 256, ctl, args); 13 | 14 | fs_write(1, buf, len); 15 | 16 | /* 17 | int i; 18 | for(i = 0; i < len; i ++) { 19 | serial_printc(buf[i]); 20 | } 21 | */ 22 | } 23 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/lib/serial.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "x86.h" 3 | 4 | #define SERIAL_PORT 0x3F8 5 | 6 | void 7 | init_serial(void) {} 8 | 9 | static inline int 10 | serial_idle(void) { 11 | return (in_byte(SERIAL_PORT + 5) & 0x20) != 0; 12 | } 13 | 14 | void 15 | serial_printc(char ch) { 16 | while (!serial_idle()); // wait untile serial is idle 17 | // print 'ch' via out instruction here 18 | // HIT_BAD_TRAP; 19 | out_byte(SERIAL_PORT, ch); 20 | } 21 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/memory/mm.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "memory.h" 3 | #include 4 | 5 | PDE updir[NR_PDE] align_to_page; 6 | CR3 ucr3; 7 | 8 | PDE* get_updir() { return updir; } 9 | uint32_t get_ucr3() { return ucr3.val; } 10 | 11 | PDE* get_kpdir(); 12 | 13 | uint32_t brk = 0; 14 | 15 | /* The brk() system call handler. */ 16 | void mm_brk(uint32_t new_brk) { 17 | if(new_brk > brk) { 18 | mm_malloc(brk, new_brk - brk); 19 | } 20 | brk = new_brk; 21 | } 22 | 23 | void init_mm() { 24 | PDE *kpdir = get_kpdir(); 25 | 26 | /* make all PDE invalid */ 27 | memset(updir, 0, NR_PDE * sizeof(PDE)); 28 | 29 | /* create the same mapping above 0xc0000000 as the kernel mapping does */ 30 | memcpy(&updir[KOFFSET / PT_SIZE], &kpdir[KOFFSET / PT_SIZE], 31 | (PHY_MEM / PT_SIZE) * sizeof(PDE)); 32 | 33 | ucr3.val = (uint32_t)va_to_pa((uint32_t)updir) & ~0x3ff; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/memory/mm_malloc.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/kernel/src/memory/mm_malloc.o -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/memory/vmem.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "memory.h" 3 | #include 4 | 5 | #define VMEM_ADDR 0xa0000 6 | #define SCR_SIZE (320 * 200) 7 | #define NR_PT ((SCR_SIZE + PT_SIZE - 1) / PT_SIZE) // number of page tables to cover the vmem 8 | 9 | PDE* get_updir(); 10 | PTE table[1024] align_to_page; 11 | 12 | void create_video_mapping() { 13 | 14 | /* TODO: create an identical mapping from virtual memory area 15 | * [0xa0000, 0xa0000 + SCR_SIZE) to physical memeory area 16 | * [0xa0000, 0xa0000 + SCR_SIZE) for user program. You may define 17 | * some page tables to create this mapping. 18 | */ 19 | //[0xa0000, 0xafa00) 20 | PDE *pdir = (PDE *)va_to_pa(get_updir()); 21 | PTE *ptable = (PTE *)va_to_pa(table); 22 | pdir[0].val = make_pde(ptable); 23 | ptable += 0xa0; 24 | for(uint32_t i = 0xa0; i <= 0xaf; i ++) { 25 | ptable->val = make_pte(i << 12); 26 | ptable ++; 27 | } 28 | //panic("please implement me"); 29 | } 30 | 31 | void video_mapping_write_test() { 32 | int i; 33 | uint32_t *buf = (void *)VMEM_ADDR; 34 | for(i = 0; i < SCR_SIZE / 4; i ++) { 35 | buf[i] = i; 36 | } 37 | } 38 | 39 | void video_mapping_read_test() { 40 | int i; 41 | uint32_t *buf = (void *)VMEM_ADDR; 42 | for(i = 0; i < SCR_SIZE / 4; i ++) { 43 | assert(buf[i] == i); 44 | } 45 | } 46 | 47 | void video_mapping_clear() { 48 | memset((void *)VMEM_ADDR, 0, SCR_SIZE); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/src/syscall/do_syscall.c: -------------------------------------------------------------------------------- 1 | #include "x86.h" 2 | 3 | #include 4 | 5 | void add_irq_handle(int, void (*)(void)); 6 | void mm_brk(uint32_t); 7 | int fs_open(const char *, int); 8 | ssize_t fs_read(int, uint8_t *, uint32_t); 9 | ssize_t fs_write(int, uint8_t *, uint32_t); 10 | off_t fs_lseek(int, off_t, int); 11 | int fs_close(int); 12 | 13 | static void sys_brk(TrapFrame *tf) { 14 | #ifdef IA32_PAGE 15 | mm_brk(tf->ebx); 16 | #endif 17 | tf->eax = 0; 18 | } 19 | 20 | static void sys_open(TrapFrame *tf) { 21 | tf->eax = fs_open((void *)tf->ebx, tf->ecx); 22 | } 23 | 24 | static void sys_read(TrapFrame *tf) { 25 | tf->eax = fs_read(tf->ebx, (void*)tf->ecx, tf->edx); 26 | } 27 | 28 | static void sys_write(TrapFrame *tf) { 29 | tf->eax = fs_write(tf->ebx, (void*)tf->ecx, tf->edx); 30 | } 31 | 32 | static void sys_lseek(TrapFrame *tf) { 33 | tf->eax = fs_lseek(tf->ebx, tf->ecx, tf->edx); 34 | } 35 | 36 | static void sys_close(TrapFrame *tf) { 37 | tf->eax = fs_close(tf->ebx); 38 | } 39 | 40 | void do_syscall(TrapFrame *tf) { 41 | switch(tf->eax) { 42 | case 0: 43 | cli(); 44 | add_irq_handle(tf->ebx, (void*)tf->ecx); 45 | sti(); 46 | break; 47 | case SYS_brk: sys_brk(tf); break; 48 | case SYS_open: sys_open(tf); break; 49 | case SYS_read: sys_read(tf); break; 50 | case SYS_write: sys_write(tf); break; 51 | case SYS_lseek: sys_lseek(tf); break; 52 | case SYS_close: sys_close(tf); break; 53 | default: panic("Unhandled system call: id = %d", tf->eax); 54 | } 55 | } 56 | 57 | -------------------------------------------------------------------------------- /pa2018_fall/kernel/start/start.txt: -------------------------------------------------------------------------------- 1 | 2 | start.o: file format elf32-i386 3 | 4 | 5 | Disassembly of section .text: 6 | 7 | 00000000 : 8 | 0: 0f 01 15 4c 00 00 40 lgdtl 0x4000004c 9 | 7: 0f 20 c0 mov %cr0,%eax 10 | a: 83 c8 01 or $0x1,%eax 11 | d: 0f 22 c0 mov %eax,%cr0 12 | 10: ea 17 00 00 40 08 00 ljmp $0x8,$0x40000017 13 | 14 | 00000017 : 15 | 17: 66 b8 10 00 mov $0x10,%ax 16 | 1b: 8e d8 mov %eax,%ds 17 | 1d: 8e c0 mov %eax,%es 18 | 1f: 8e d0 mov %eax,%ss 19 | 21: bd 00 00 00 00 mov $0x0,%ebp 20 | 26: bc 00 00 00 08 mov $0x8000000,%esp 21 | 2b: 83 ec 10 sub $0x10,%esp 22 | 2e: e9 fc ff ff ff jmp 2f 23 | 33: 90 nop 24 | 25 | 00000034 : 26 | ... 27 | 3c: ff (bad) 28 | 3d: ff 00 incl (%eax) 29 | 3f: 00 00 add %al,(%eax) 30 | 41: 9a cf 00 ff ff 00 00 lcall $0x0,$0xffff00cf 31 | 48: 00 .byte 0x0 32 | 49: 92 xchg %eax,%edx 33 | 4a: cf iret 34 | ... 35 | 36 | 0000004c : 37 | 4c: 17 pop %ss 38 | 4d: 00 34 00 add %dh,(%eax,%eax,1) 39 | 50: 00 .byte 0x0 40 | 51: 40 inc %eax 41 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/include/cpu-ref/alu_ref.h: -------------------------------------------------------------------------------- 1 | #ifndef __ALU_REF_H__ 2 | #define __ALU_REF_H__ 3 | 4 | uint32_t __ref_alu_add(uint32_t src, uint32_t dest, size_t data_size); 5 | uint32_t __ref_alu_adc(uint32_t src, uint32_t dest, size_t data_size); 6 | uint32_t __ref_alu_sub(uint32_t src, uint32_t dest, size_t data_size); 7 | uint32_t __ref_alu_sbb(uint32_t src, uint32_t dest, size_t data_size); 8 | uint32_t __ref_alu_and(uint32_t src, uint32_t dest, size_t data_size); 9 | uint32_t __ref_alu_xor(uint32_t src, uint32_t dest, size_t data_size); 10 | uint32_t __ref_alu_or(uint32_t src, uint32_t dest, size_t data_size); 11 | uint32_t __ref_alu_shl(uint32_t src, uint32_t dest, size_t data_size); 12 | uint32_t __ref_alu_shr(uint32_t src, uint32_t dest, size_t data_size); 13 | uint32_t __ref_alu_sar(uint32_t src, uint32_t dest, size_t data_size); 14 | uint32_t __ref_alu_sal(uint32_t src, uint32_t dest, size_t data_size); 15 | uint64_t __ref_alu_mul(uint32_t src, uint32_t dest, size_t data_size); 16 | int64_t __ref_alu_imul(int32_t src, int32_t dest, size_t data_size); 17 | uint32_t __ref_alu_div(uint64_t src, uint64_t dest, size_t data_size); 18 | int32_t __ref_alu_idiv(int64_t src, int64_t dest, size_t data_size); 19 | uint32_t __ref_alu_mod(uint64_t src, uint64_t dest); 20 | int32_t __ref_alu_imod(int64_t src, int64_t dest); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/include/cpu-ref/fpu_ref.h: -------------------------------------------------------------------------------- 1 | #ifndef __FPU_REF_H__ 2 | #define __FPU_REF_H__ 3 | #include 4 | void set_ref(); 5 | uint32_t __ref_internal_float_add(uint32_t b, uint32_t a); 6 | uint32_t __ref_internal_float_sub(uint32_t b, uint32_t a); 7 | uint32_t __ref_internal_float_mul(uint32_t b, uint32_t a); 8 | uint32_t __ref_internal_float_div(uint32_t b, uint32_t a); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/include/cpu-ref/instr_helper_ref.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_HELPER_REF_H__ 2 | #define __INSTR_HELPER_REF_H__ 3 | 4 | #include 5 | 6 | //reference 7 | // macro for making an instruction entry 8 | #define make_instr_func_ref(name) int concat(__ref_, name)(uint32_t eip, uint8_t opcode) 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/include/scoring.h: -------------------------------------------------------------------------------- 1 | #ifndef __SCORING_H__ 2 | #define __SCORING_H__ 3 | 4 | void clear_ref(); 5 | void set_ref(); 6 | int get_ref(); 7 | 8 | // write trap info 9 | void score_trap(); 10 | void score_expr(); 11 | 12 | // nemu config 13 | void score_set_ia32_seg(); 14 | void score_set_ia32_page(); 15 | void score_set_tlb_enabled(); 16 | void score_set_cache_enabled(); 17 | void score_set_ia32_intr(); 18 | void score_set_has_device_timer(); 19 | void score_set_has_device_serial(); 20 | void score_set_has_device_ide(); 21 | void score_set_has_device_keyboard(); 22 | void score_set_has_device_vga(); 23 | void score_set_has_device_audio(); 24 | void score_fix_config(); // prevent further changes to config log 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/include/test/reg_alu_fpu_test_score.h: -------------------------------------------------------------------------------- 1 | #ifndef __REG_ALU_FPU_TEST_SCORE_H__ 2 | #define __REG_ALU_FPU_TEST_SCORE_H__ 3 | 4 | // test for registers 5 | void __score_reg_test(); 6 | 7 | // test for alu 8 | void __score_alu_test_add(); 9 | void __score_alu_test_adc(); 10 | void __score_alu_test_sub(); 11 | void __score_alu_test_sbb(); 12 | void __score_alu_test_and(); 13 | void __score_alu_test_or(); 14 | void __score_alu_test_xor(); 15 | void __score_alu_test_shl(); 16 | void __score_alu_test_shr(); 17 | void __score_alu_test_sal(); 18 | void __score_alu_test_sar(); 19 | void __score_alu_test_mul(); 20 | void __score_alu_test_div(); 21 | void __score_alu_test_imul(); 22 | void __score_alu_test_idiv(); 23 | 24 | // test for fpu 25 | 26 | void __score_init_fpu_test(); 27 | void __score_fpu_test_add(); 28 | void __score_fpu_test_sub(); 29 | void __score_fpu_test_mul(); 30 | void __score_fpu_test_div(); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /pa2018_fall/libs/nemu-ref/lib-nemu-ref.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/libs/nemu-ref/lib-nemu-ref.a -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/_syslist.h: -------------------------------------------------------------------------------- 1 | /* internal use only -- mapping of "system calls" for libraries that lose 2 | and only provide C names, so that we end up in violation of ANSI */ 3 | #ifndef __SYSLIST_H 4 | #define __SYSLIST_H 5 | 6 | #ifdef MISSING_SYSCALL_NAMES 7 | #define _close close 8 | #define _execve execve 9 | #define _fcntl fcntl 10 | #define _fork fork 11 | #define _fstat fstat 12 | #define _getpid getpid 13 | #define _gettimeofday gettimeofday 14 | #define _isatty isatty 15 | #define _kill kill 16 | #define _link link 17 | #define _lseek lseek 18 | #define _mkdir mkdir 19 | #define _open open 20 | #define _read read 21 | #define _sbrk sbrk 22 | #define _stat stat 23 | #define _times times 24 | #define _unlink unlink 25 | #define _wait wait 26 | #define _write write 27 | #endif /* MISSING_SYSCALL_NAMES */ 28 | 29 | #if defined MISSING_SYSCALL_NAMES || !defined HAVE_OPENDIR 30 | /* If the system call interface is missing opendir, readdir, and 31 | closedir, there is an implementation of these functions in 32 | libc/posix that is implemented using open, getdents, and close. 33 | Note, these functions are currently not in the libc/syscalls 34 | directory. */ 35 | #define _opendir opendir 36 | #define _readdir readdir 37 | #define _closedir closedir 38 | #endif /* MISSING_SYSCALL_NAMES || !HAVE_OPENDIR */ 39 | 40 | #endif /* !__SYSLIST_H_ */ 41 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/alloca.h: -------------------------------------------------------------------------------- 1 | /* libc/include/alloca.h - Allocate memory on stack */ 2 | 3 | /* Written 2000 by Werner Almesberger */ 4 | /* Rearranged for general inclusion by stdlib.h. 5 | 2001, Corinna Vinschen */ 6 | 7 | #ifndef _NEWLIB_ALLOCA_H 8 | #define _NEWLIB_ALLOCA_H 9 | 10 | #include "_ansi.h" 11 | #include 12 | 13 | #undef alloca 14 | 15 | #ifdef __GNUC__ 16 | #define alloca(size) __builtin_alloca(size) 17 | #else 18 | void * _EXFUN(alloca,(size_t)); 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/argz.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. 2 | * 3 | * Permission to use, copy, modify, and distribute this software 4 | * is freely granted, provided that this notice is preserved. 5 | */ 6 | 7 | #ifndef _ARGZ_H_ 8 | #define _ARGZ_H_ 9 | 10 | #include 11 | #include 12 | 13 | #include "_ansi.h" 14 | 15 | _BEGIN_STD_C 16 | 17 | /* The newlib implementation of these functions assumes that sizeof(char) == 1. */ 18 | error_t argz_create (char *const argv[], char **argz, size_t *argz_len); 19 | error_t argz_create_sep (const char *string, int sep, char **argz, size_t *argz_len); 20 | size_t argz_count (const char *argz, size_t argz_len); 21 | void argz_extract (char *argz, size_t argz_len, char **argv); 22 | void argz_stringify (char *argz, size_t argz_len, int sep); 23 | error_t argz_add (char **argz, size_t *argz_len, const char *str); 24 | error_t argz_add_sep (char **argz, size_t *argz_len, const char *str, int sep); 25 | error_t argz_append (char **argz, size_t *argz_len, const char *buf, size_t buf_len); 26 | error_t argz_delete (char **argz, size_t *argz_len, char *entry); 27 | error_t argz_insert (char **argz, size_t *argz_len, char *before, const char *entry); 28 | char * argz_next (char *argz, size_t argz_len, const char *entry); 29 | error_t argz_replace (char **argz, size_t *argz_len, const char *str, const char *with, unsigned *replace_count); 30 | 31 | _END_STD_C 32 | 33 | #endif /* _ARGZ_H_ */ 34 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | assert.h 3 | */ 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | 9 | #include "_ansi.h" 10 | 11 | #undef assert 12 | 13 | #ifdef NDEBUG /* required by ANSI standard */ 14 | # define assert(__e) ((void)0) 15 | #else 16 | # define assert(__e) ((__e) ? (void)0 : __assert_func (__FILE__, __LINE__, \ 17 | __ASSERT_FUNC, #__e)) 18 | 19 | # ifndef __ASSERT_FUNC 20 | /* Use g++'s demangled names in C++. */ 21 | # if defined __cplusplus && defined __GNUC__ 22 | # define __ASSERT_FUNC __PRETTY_FUNCTION__ 23 | 24 | /* C99 requires the use of __func__. */ 25 | # elif __STDC_VERSION__ >= 199901L 26 | # define __ASSERT_FUNC __func__ 27 | 28 | /* Older versions of gcc don't have __func__ but can use __FUNCTION__. */ 29 | # elif __GNUC__ >= 2 30 | # define __ASSERT_FUNC __FUNCTION__ 31 | 32 | /* failed to detect __func__ support. */ 33 | # else 34 | # define __ASSERT_FUNC ((char *) 0) 35 | # endif 36 | # endif /* !__ASSERT_FUNC */ 37 | #endif /* !NDEBUG */ 38 | 39 | void _EXFUN(__assert, (const char *, int, const char *) 40 | _ATTRIBUTE ((__noreturn__))); 41 | void _EXFUN(__assert_func, (const char *, int, const char *, const char *) 42 | _ATTRIBUTE ((__noreturn__))); 43 | 44 | #if __STDC_VERSION__ >= 201112L && !defined __cplusplus 45 | # define static_assert _Static_assert 46 | #endif 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIRENT_H_ 2 | #define _DIRENT_H_ 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | #include 7 | 8 | #if !defined(MAXNAMLEN) && !defined(_POSIX_SOURCE) 9 | #define MAXNAMLEN 1024 10 | #endif 11 | 12 | #ifdef __cplusplus 13 | } 14 | #endif 15 | #endif /*_DIRENT_H_*/ 16 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/envlock.h: -------------------------------------------------------------------------------- 1 | /* envlock.h -- header file for env routines. */ 2 | 3 | #ifndef _INCLUDE_ENVLOCK_H_ 4 | #define _INCLUDE_ENVLOCK_H_ 5 | 6 | #include <_ansi.h> 7 | #include 8 | 9 | #define ENV_LOCK __env_lock(reent_ptr) 10 | #define ENV_UNLOCK __env_unlock(reent_ptr) 11 | 12 | void _EXFUN(__env_lock,(struct _reent *reent)); 13 | void _EXFUN(__env_unlock,(struct _reent *reent)); 14 | 15 | #endif /* _INCLUDE_ENVLOCK_H_ */ 16 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/envz.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved. 2 | * 3 | * Permission to use, copy, modify, and distribute this software 4 | * is freely granted, provided that this notice is preserved. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | /* The newlib implementation of these functions assumes that sizeof(char) == 1. */ 11 | char * envz_entry (const char *envz, size_t envz_len, const char *name); 12 | char * envz_get (const char *envz, size_t envz_len, const char *name); 13 | error_t envz_add (char **envz, size_t *envz_len, const char *name, const char *value); 14 | error_t envz_merge (char **envz, size_t *envz_len, const char *envz2, size_t envz2_len, int override); 15 | void envz_remove(char **envz, size_t *envz_len, const char *name); 16 | void envz_strip (char **envz, size_t *envz_len); 17 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef __ERRNO_H__ 2 | #define __ERRNO_H__ 3 | 4 | #ifndef __error_t_defined 5 | typedef int error_t; 6 | #define __error_t_defined 1 7 | #endif 8 | 9 | #include 10 | 11 | #endif /* !__ERRNO_H__ */ 12 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/fastmath.h: -------------------------------------------------------------------------------- 1 | #ifndef _FASTMATH_H_ 2 | #ifdef __cplusplus 3 | extern "C" { 4 | #endif 5 | #define _FASTMATH_H_ 6 | 7 | #include 8 | #include 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | #endif /* _FASTMATH_H_ */ 14 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/libgen.h: -------------------------------------------------------------------------------- 1 | /* 2 | * libgen.h - defined by XPG4 3 | */ 4 | 5 | #ifndef _LIBGEN_H_ 6 | #define _LIBGEN_H_ 7 | 8 | #include "_ansi.h" 9 | #include 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | char *_EXFUN(basename, (char *)); 16 | char *_EXFUN(dirname, (char *)); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* _LIBGEN_H_ */ 23 | 24 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/locale.h: -------------------------------------------------------------------------------- 1 | /* 2 | locale.h 3 | Values appropriate for the formatting of monetary and other 4 | numberic quantities. 5 | */ 6 | 7 | #ifndef _LOCALE_H_ 8 | #define _LOCALE_H_ 9 | 10 | #include "_ansi.h" 11 | 12 | #define __need_NULL 13 | #include 14 | 15 | #define LC_ALL 0 16 | #define LC_COLLATE 1 17 | #define LC_CTYPE 2 18 | #define LC_MONETARY 3 19 | #define LC_NUMERIC 4 20 | #define LC_TIME 5 21 | #define LC_MESSAGES 6 22 | 23 | _BEGIN_STD_C 24 | 25 | struct lconv 26 | { 27 | char *decimal_point; 28 | char *thousands_sep; 29 | char *grouping; 30 | char *int_curr_symbol; 31 | char *currency_symbol; 32 | char *mon_decimal_point; 33 | char *mon_thousands_sep; 34 | char *mon_grouping; 35 | char *positive_sign; 36 | char *negative_sign; 37 | char int_frac_digits; 38 | char frac_digits; 39 | char p_cs_precedes; 40 | char p_sep_by_space; 41 | char n_cs_precedes; 42 | char n_sep_by_space; 43 | char p_sign_posn; 44 | char n_sign_posn; 45 | char int_n_cs_precedes; 46 | char int_n_sep_by_space; 47 | char int_n_sign_posn; 48 | char int_p_cs_precedes; 49 | char int_p_sep_by_space; 50 | char int_p_sign_posn; 51 | }; 52 | 53 | #ifndef _REENT_ONLY 54 | char *_EXFUN(setlocale,(int category, const char *locale)); 55 | struct lconv *_EXFUN(localeconv,(void)); 56 | #endif 57 | 58 | struct _reent; 59 | char *_EXFUN(_setlocale_r,(struct _reent *, int category, const char *locale)); 60 | struct lconv *_EXFUN(_localeconv_r,(struct _reent *)); 61 | 62 | _END_STD_C 63 | 64 | #endif /* _LOCALE_H_ */ 65 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id: _types.h,v 1.3 2007/09/07 21:16:25 jjohnstn Exp $ 3 | */ 4 | 5 | #ifndef _MACHINE__TYPES_H 6 | #define _MACHINE__TYPES_H 7 | #include 8 | #endif 9 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/ansi.h: -------------------------------------------------------------------------------- 1 | /* dummy header file to support BSD compiler */ 2 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACHINE_ENDIAN_H__ 2 | 3 | #include 4 | 5 | #ifndef BIG_ENDIAN 6 | #define BIG_ENDIAN 4321 7 | #endif 8 | #ifndef LITTLE_ENDIAN 9 | #define LITTLE_ENDIAN 1234 10 | #endif 11 | 12 | #ifndef BYTE_ORDER 13 | #if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BYTES_LITTLE_ENDIAN) 14 | #define BYTE_ORDER LITTLE_ENDIAN 15 | #else 16 | #define BYTE_ORDER BIG_ENDIAN 17 | #endif 18 | #endif 19 | 20 | #endif /* __MACHINE_ENDIAN_H__ */ 21 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/malloc.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACHMALLOC_H_ 2 | #define _MACHMALLOC_H_ 3 | 4 | /* place holder so platforms may add malloc.h extensions */ 5 | 6 | #endif /* _MACHMALLOC_H_ */ 7 | 8 | 9 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/param.h: -------------------------------------------------------------------------------- 1 | /* Place holder for machine-specific param.h. */ 2 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/setjmp-dj.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1991 DJ Delorie 3 | * All rights reserved. 4 | * 5 | * Redistribution, modification, and use in source and binary forms is permitted 6 | * provided that the above copyright notice and following paragraph are 7 | * duplicated in all such forms. 8 | * 9 | * This file is distributed WITHOUT ANY WARRANTY; without even the implied 10 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 | */ 12 | 13 | /* Modified to use SETJMP_DJ_H rather than SETJMP_H to avoid 14 | conflicting with setjmp.h. Ian Taylor, Cygnus support, April, 15 | 1993. */ 16 | 17 | #ifndef _SETJMP_DJ_H_ 18 | #define _SETJMP_DJ_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef struct { 25 | unsigned long eax; 26 | unsigned long ebx; 27 | unsigned long ecx; 28 | unsigned long edx; 29 | unsigned long esi; 30 | unsigned long edi; 31 | unsigned long ebp; 32 | unsigned long esp; 33 | unsigned long eip; 34 | } jmp_buf[1]; 35 | 36 | extern int setjmp(jmp_buf); 37 | extern void longjmp(jmp_buf, int); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/stdlib.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACHSTDLIB_H_ 2 | #define _MACHSTDLIB_H_ 3 | 4 | /* place holder so platforms may add stdlib.h extensions */ 5 | 6 | #endif /* _MACHSTDLIB_H_ */ 7 | 8 | 9 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/termios.h: -------------------------------------------------------------------------------- 1 | #define __MAX_BAUD B4000000 2 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACHTIME_H_ 2 | #define _MACHTIME_H_ 3 | 4 | #if defined(__rtems__) 5 | #define _CLOCKS_PER_SEC_ sysconf(_SC_CLK_TCK) 6 | #else /* !__rtems__ */ 7 | #if defined(__aarch64__) || defined(__arm__) || defined(__thumb__) 8 | #define _CLOCKS_PER_SEC_ 100 9 | #endif 10 | #endif /* !__rtems__ */ 11 | 12 | #ifdef __SPU__ 13 | #include 14 | int nanosleep (const struct timespec *, struct timespec *); 15 | #endif 16 | 17 | #endif /* _MACHTIME_H_ */ 18 | 19 | 20 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/machine/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACHTYPES_H_ 2 | #define _MACHTYPES_H_ 3 | 4 | /* 5 | * The following section is RTEMS specific and is needed to more 6 | * closely match the types defined in the BSD machine/types.h. 7 | * This is needed to let the RTEMS/BSD TCP/IP stack compile. 8 | */ 9 | #if defined(__rtems__) 10 | #include 11 | #endif 12 | 13 | #define _CLOCK_T_ unsigned long /* clock() */ 14 | #define _TIME_T_ long /* time() */ 15 | #define _CLOCKID_T_ unsigned long 16 | #define _TIMER_T_ unsigned long 17 | 18 | #ifndef _HAVE_SYSTYPES 19 | typedef long int __off_t; 20 | typedef int __pid_t; 21 | #ifdef __GNUC__ 22 | __extension__ typedef long long int __loff_t; 23 | #else 24 | typedef long int __loff_t; 25 | #endif 26 | #endif 27 | 28 | #endif /* _MACHTYPES_H_ */ 29 | 30 | 31 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/newlib.h: -------------------------------------------------------------------------------- 1 | /* dummy file for external tools to use. Real file is created by 2 | newlib configuration. */ 3 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/paths.h: -------------------------------------------------------------------------------- 1 | #ifndef _PATHS_H_ 2 | #define _PATHS_H_ 3 | 4 | #define _PATH_DEV "/dev/" 5 | #define _PATH_DEVNULL "/dev/null" 6 | #define _PATH_DEVZERO "/dev/zero" 7 | #define _PATH_BSHELL "/bin/sh" 8 | 9 | #endif /* _PATHS_H_ */ 10 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/regdef.h: -------------------------------------------------------------------------------- 1 | /* regdef.h -- define register names. */ 2 | 3 | /* This is a standard include file for MIPS targets. Other target 4 | probably don't define it, and attempts to include this file will 5 | fail. */ 6 | 7 | #include 8 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/search.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $ */ 2 | /* $FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $ */ 3 | 4 | /* 5 | * Written by J.T. Conklin 6 | * Public domain. 7 | */ 8 | 9 | #ifndef _SEARCH_H_ 10 | #define _SEARCH_H_ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | typedef struct entry { 17 | char *key; 18 | void *data; 19 | } ENTRY; 20 | 21 | typedef enum { 22 | FIND, ENTER 23 | } ACTION; 24 | 25 | typedef enum { 26 | preorder, 27 | postorder, 28 | endorder, 29 | leaf 30 | } VISIT; 31 | 32 | #ifdef _SEARCH_PRIVATE 33 | typedef struct node { 34 | char *key; 35 | struct node *llink, *rlink; 36 | } node_t; 37 | #endif 38 | 39 | struct hsearch_data 40 | { 41 | struct internal_head *htable; 42 | size_t htablesize; 43 | }; 44 | 45 | #ifndef __compar_fn_t_defined 46 | #define __compar_fn_t_defined 47 | typedef int (*__compar_fn_t) (const void *, const void *); 48 | #endif 49 | 50 | __BEGIN_DECLS 51 | int hcreate(size_t); 52 | void hdestroy(void); 53 | ENTRY *hsearch(ENTRY, ACTION); 54 | int hcreate_r(size_t, struct hsearch_data *); 55 | void hdestroy_r(struct hsearch_data *); 56 | int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); 57 | void *tdelete(const void *__restrict, void **__restrict, __compar_fn_t); 58 | void tdestroy (void *, void (*)(void *)); 59 | void *tfind(const void *, void **, __compar_fn_t); 60 | void *tsearch(const void *, void **, __compar_fn_t); 61 | void twalk(const void *, void (*)(const void *, VISIT, int)); 62 | __END_DECLS 63 | 64 | #endif /* !_SEARCH_H_ */ 65 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/setjmp.h: -------------------------------------------------------------------------------- 1 | /* 2 | setjmp.h 3 | stubs for future use. 4 | */ 5 | 6 | #ifndef _SETJMP_H_ 7 | #define _SETJMP_H_ 8 | 9 | #include "_ansi.h" 10 | #include 11 | 12 | _BEGIN_STD_C 13 | 14 | void _EXFUN(longjmp,(jmp_buf __jmpb, int __retval)); 15 | int _EXFUN(setjmp,(jmp_buf __jmpb)); 16 | 17 | _END_STD_C 18 | 19 | #endif /* _SETJMP_H_ */ 20 | 21 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIGNAL_H_ 2 | #define _SIGNAL_H_ 3 | 4 | #include "_ansi.h" 5 | #include 6 | 7 | _BEGIN_STD_C 8 | 9 | typedef int sig_atomic_t; /* Atomic entity type (ANSI) */ 10 | #ifndef _POSIX_SOURCE 11 | typedef _sig_func_ptr sig_t; /* BSD naming */ 12 | typedef _sig_func_ptr sighandler_t; /* glibc naming */ 13 | #endif /* !_POSIX_SOURCE */ 14 | 15 | #define SIG_DFL ((_sig_func_ptr)0) /* Default action */ 16 | #define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */ 17 | #define SIG_ERR ((_sig_func_ptr)-1) /* Error return */ 18 | 19 | struct _reent; 20 | 21 | _sig_func_ptr _EXFUN(_signal_r, (struct _reent *, int, _sig_func_ptr)); 22 | int _EXFUN(_raise_r, (struct _reent *, int)); 23 | 24 | #ifndef _REENT_ONLY 25 | _sig_func_ptr _EXFUN(signal, (int, _sig_func_ptr)); 26 | int _EXFUN(raise, (int)); 27 | void _EXFUN(psignal, (int, const char *)); 28 | #endif 29 | 30 | _END_STD_C 31 | 32 | #endif /* _SIGNAL_H_ */ 33 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/strings.h: -------------------------------------------------------------------------------- 1 | /* 2 | * strings.h 3 | * 4 | * Definitions for string operations. 5 | */ 6 | 7 | #ifndef _STRINGS_H_ 8 | #define _STRINGS_H_ 9 | 10 | #include "_ansi.h" 11 | #include 12 | 13 | #include /* for size_t */ 14 | 15 | _BEGIN_STD_C 16 | 17 | #if !defined __STRICT_ANSI__ && _POSIX_VERSION < 200809L 18 | /* 19 | * Marked LEGACY in Open Group Base Specifications Issue 6/IEEE Std 1003.1-2004 20 | * Removed from Open Group Base Specifications Issue 7/IEEE Std 1003.1-2008 21 | */ 22 | int _EXFUN(bcmp,(const void *, const void *, size_t)); 23 | void _EXFUN(bcopy,(const void *, void *, size_t)); 24 | void _EXFUN(bzero,(void *, size_t)); 25 | char *_EXFUN(index,(const char *, int)); 26 | char *_EXFUN(rindex,(const char *, int)); 27 | #endif /* ! __STRICT_ANSI__ */ 28 | 29 | int _EXFUN(ffs,(int)); 30 | int _EXFUN(strcasecmp,(const char *, const char *)); 31 | int _EXFUN(strncasecmp,(const char *, const char *, size_t)); 32 | 33 | _END_STD_C 34 | 35 | #endif /* _STRINGS_H_ */ 36 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/custom_file.h: -------------------------------------------------------------------------------- 1 | #error System-specific custom_file.h is missing. 2 | 3 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/dir.h: -------------------------------------------------------------------------------- 1 | /* BSD predecessor of POSIX.1 and struct dirent */ 2 | 3 | #ifndef _SYS_DIR_H_ 4 | #define _SYS_DIR_H_ 5 | 6 | #include 7 | 8 | #define direct dirent 9 | 10 | #endif /*_SYS_DIR_H_*/ 11 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/dirent.h: -------------------------------------------------------------------------------- 1 | /* includes , which is this file. On a 2 | system which supports , this file is overridden by 3 | dirent.h in the libc/sys/.../sys directory. On a system which does 4 | not support , we will get this file which uses #error to force 5 | an error. */ 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | #error " not supported" 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_FCNTL_H_ 2 | #define _SYS_FCNTL_H_ 3 | #include 4 | #endif 5 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/file.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/lock.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYS_LOCK_H__ 2 | #define __SYS_LOCK_H__ 3 | 4 | /* dummy lock routines for single-threaded aps */ 5 | 6 | typedef int _LOCK_T; 7 | typedef int _LOCK_RECURSIVE_T; 8 | 9 | #include <_ansi.h> 10 | 11 | #define __LOCK_INIT(class,lock) static int lock = 0; 12 | #define __LOCK_INIT_RECURSIVE(class,lock) static int lock = 0; 13 | #define __lock_init(lock) (_CAST_VOID 0) 14 | #define __lock_init_recursive(lock) (_CAST_VOID 0) 15 | #define __lock_close(lock) (_CAST_VOID 0) 16 | #define __lock_close_recursive(lock) (_CAST_VOID 0) 17 | #define __lock_acquire(lock) (_CAST_VOID 0) 18 | #define __lock_acquire_recursive(lock) (_CAST_VOID 0) 19 | #define __lock_try_acquire(lock) (_CAST_VOID 0) 20 | #define __lock_try_acquire_recursive(lock) (_CAST_VOID 0) 21 | #define __lock_release(lock) (_CAST_VOID 0) 22 | #define __lock_release_recursive(lock) (_CAST_VOID 0) 23 | 24 | #endif /* __SYS_LOCK_H__ */ 25 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/param.h: -------------------------------------------------------------------------------- 1 | /* This is a dummy file, not customized for any 2 | particular system. If there is a param.h in libc/sys/SYSDIR/sys, 3 | it will override this one. */ 4 | 5 | #ifndef _SYS_PARAM_H 6 | # define _SYS_PARAM_H 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #ifndef HZ 14 | # define HZ (60) 15 | #endif 16 | #ifndef NOFILE 17 | # define NOFILE (60) 18 | #endif 19 | #ifndef PATHSIZE 20 | # define PATHSIZE (1024) 21 | #endif 22 | 23 | #define MAXPATHLEN PATH_MAX 24 | 25 | #define MAX(a,b) ((a) > (b) ? (a) : (b)) 26 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/resource.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_RESOURCE_H_ 2 | #define _SYS_RESOURCE_H_ 3 | 4 | #include 5 | 6 | #define RUSAGE_SELF 0 /* calling process */ 7 | #define RUSAGE_CHILDREN -1 /* terminated child processes */ 8 | 9 | struct rusage { 10 | struct timeval ru_utime; /* user time used */ 11 | struct timeval ru_stime; /* system time used */ 12 | }; 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/stdio.h: -------------------------------------------------------------------------------- 1 | #ifndef _NEWLIB_STDIO_H 2 | #define _NEWLIB_STDIO_H 3 | 4 | #include 5 | #include 6 | 7 | /* Internal locking macros, used to protect stdio functions. In the 8 | general case, expand to nothing. Use __SSTR flag in FILE _flags to 9 | detect if FILE is private to sprintf/sscanf class of functions; if 10 | set then do nothing as lock is not initialised. */ 11 | #if !defined(_flockfile) 12 | #ifndef __SINGLE_THREAD__ 13 | # define _flockfile(fp) (((fp)->_flags & __SSTR) ? 0 : __lock_acquire_recursive((fp)->_lock)) 14 | #else 15 | # define _flockfile(fp) (_CAST_VOID 0) 16 | #endif 17 | #endif 18 | 19 | #if !defined(_funlockfile) 20 | #ifndef __SINGLE_THREAD__ 21 | # define _funlockfile(fp) (((fp)->_flags & __SSTR) ? 0 : __lock_release_recursive((fp)->_lock)) 22 | #else 23 | # define _funlockfile(fp) (_CAST_VOID 0) 24 | #endif 25 | #endif 26 | 27 | #endif /* _NEWLIB_STDIO_H */ 28 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/string.h: -------------------------------------------------------------------------------- 1 | /* This is a dummy used as a placeholder for 2 | systems that need to have a special header file. */ 3 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/timeb.h: -------------------------------------------------------------------------------- 1 | /* timeb.h -- An implementation of the standard Unix file. 2 | Written by Ian Lance Taylor 3 | Public domain; no rights reserved. 4 | 5 | declares the structure used by the ftime function, as 6 | well as the ftime function itself. Newlib does not provide an 7 | implementation of ftime. */ 8 | 9 | #ifndef _SYS_TIMEB_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define _SYS_TIMEB_H 16 | 17 | #include <_ansi.h> 18 | #include 19 | 20 | #ifndef __time_t_defined 21 | typedef _TIME_T_ time_t; 22 | #define __time_t_defined 23 | #endif 24 | 25 | struct timeb 26 | { 27 | time_t time; 28 | unsigned short millitm; 29 | short timezone; 30 | short dstflag; 31 | }; 32 | 33 | extern int ftime _PARAMS ((struct timeb *)); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif /* ! defined (_SYS_TIMEB_H) */ 40 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/times.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIMES_H 2 | #ifdef __cplusplus 3 | extern "C" { 4 | #endif 5 | #define _SYS_TIMES_H 6 | 7 | #include <_ansi.h> 8 | #include 9 | 10 | #ifndef __clock_t_defined 11 | typedef _CLOCK_T_ clock_t; 12 | #define __clock_t_defined 13 | #endif 14 | 15 | /* Get Process Times, P1003.1b-1993, p. 92 */ 16 | struct tms { 17 | clock_t tms_utime; /* user time */ 18 | clock_t tms_stime; /* system time */ 19 | clock_t tms_cutime; /* user time, children */ 20 | clock_t tms_cstime; /* system time, children */ 21 | }; 22 | 23 | clock_t _EXFUN(times,(struct tms *)); 24 | #ifdef _COMPILING_NEWLIB 25 | clock_t _EXFUN(_times,(struct tms *)); 26 | #endif 27 | 28 | #ifdef __cplusplus 29 | } 30 | #endif 31 | #endif /* !_SYS_TIMES_H */ 32 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/utime.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UTIME_H 2 | #define _SYS_UTIME_H 3 | 4 | /* This is a dummy file, not customized for any 5 | particular system. If there is a utime.h in libc/sys/SYSDIR/sys, 6 | it will override this one. */ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | struct utimbuf 13 | { 14 | time_t actime; 15 | time_t modtime; 16 | }; 17 | 18 | #ifdef __cplusplus 19 | }; 20 | #endif 21 | 22 | #endif /* _SYS_UTIME_H */ 23 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_WAIT_H 2 | #define _SYS_WAIT_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | #define WNOHANG 1 11 | #define WUNTRACED 2 12 | 13 | /* A status looks like: 14 | <2 bytes info> <2 bytes code> 15 | 16 | == 0, child has exited, info is the exit value 17 | == 1..7e, child has exited, info is the signal number. 18 | == 7f, child has stopped, info was the signal number. 19 | == 80, there was a core dump. 20 | */ 21 | 22 | #define WIFEXITED(w) (((w) & 0xff) == 0) 23 | #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f)) 24 | #define WIFSTOPPED(w) (((w) & 0xff) == 0x7f) 25 | #define WEXITSTATUS(w) (((w) >> 8) & 0xff) 26 | #define WTERMSIG(w) ((w) & 0x7f) 27 | #define WSTOPSIG WEXITSTATUS 28 | 29 | pid_t wait (int *); 30 | pid_t waitpid (pid_t, int *, int); 31 | 32 | #ifdef _COMPILING_NEWLIB 33 | pid_t _wait (int *); 34 | #endif 35 | 36 | /* Provide prototypes for most of the _ names that are 37 | provided in newlib for some compilers. */ 38 | pid_t _wait (int *); 39 | 40 | #ifdef __cplusplus 41 | }; 42 | #endif 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/tar.h: -------------------------------------------------------------------------------- 1 | /* 2 | * tar.h 3 | */ 4 | 5 | #ifndef _TAR_H 6 | #define _TAR_H 7 | 8 | /* General definitions */ 9 | #define TMAGIC "ustar" /* ustar plus null byte. */ 10 | #define TMAGLEN 6 /* Length of the above. */ 11 | #define TVERSION "00" /* 00 without a null byte. */ 12 | #define TVERSLEN 2 /* Length of the above. */ 13 | 14 | /* Typeflag field definitions */ 15 | #define REGTYPE '0' /* Regular file. */ 16 | #define AREGTYPE '\0' /* Regular file. */ 17 | #define LNKTYPE '1' /* Link. */ 18 | #define SYMTYPE '2' /* Symbolic link. */ 19 | #define CHRTYPE '3' /* Character special. */ 20 | #define BLKTYPE '4' /* Block special. */ 21 | #define DIRTYPE '5' /* Directory. */ 22 | #define FIFOTYPE '6' /* FIFO special. */ 23 | #define CONTTYPE '7' /* Reserved. */ 24 | 25 | /* Mode field bit definitions (octal) */ 26 | #define TSUID 04000 /* Set UID on execution. */ 27 | #define TSGID 02000 /* Set GID on execution. */ 28 | #define TSVTX 01000 /* On directories, restricted deletion flag. */ 29 | #define TUREAD 00400 /* Read by owner. */ 30 | #define TUWRITE 00200 /* Write by owner. */ 31 | #define TUEXEC 00100 /* Execute/search by owner. */ 32 | #define TGREAD 00040 /* Read by group. */ 33 | #define TGWRITE 00020 /* Write by group. */ 34 | #define TGEXEC 00010 /* Execute/search by group. */ 35 | #define TOREAD 00004 /* Read by other. */ 36 | #define TOWRITE 00002 /* Write by other. */ 37 | #define TOEXEC 00001 /* Execute/search by other. */ 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/termios.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | #include 5 | #ifdef __cplusplus 6 | } 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNISTD_H_ 2 | #define _UNISTD_H_ 3 | 4 | # include 5 | 6 | #endif /* _UNISTD_H_ */ 7 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/utime.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | 5 | #include <_ansi.h> 6 | 7 | /* The utime function is defined in libc/sys//sys if it exists. */ 8 | #include 9 | 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/utmp.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | #include 5 | #ifdef __cplusplus 6 | } 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/include/wctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _WCTYPE_H_ 2 | #define _WCTYPE_H_ 3 | 4 | #include <_ansi.h> 5 | #include 6 | 7 | #define __need_wint_t 8 | #include 9 | 10 | #ifndef WEOF 11 | # define WEOF ((wint_t)-1) 12 | #endif 13 | 14 | _BEGIN_STD_C 15 | 16 | #ifndef _WCTYPE_T 17 | #define _WCTYPE_T 18 | typedef int wctype_t; 19 | #endif 20 | 21 | #ifndef _WCTRANS_T 22 | #define _WCTRANS_T 23 | typedef int wctrans_t; 24 | #endif 25 | 26 | int _EXFUN(iswalpha, (wint_t)); 27 | int _EXFUN(iswalnum, (wint_t)); 28 | int _EXFUN(iswblank, (wint_t)); 29 | int _EXFUN(iswcntrl, (wint_t)); 30 | int _EXFUN(iswctype, (wint_t, wctype_t)); 31 | int _EXFUN(iswdigit, (wint_t)); 32 | int _EXFUN(iswgraph, (wint_t)); 33 | int _EXFUN(iswlower, (wint_t)); 34 | int _EXFUN(iswprint, (wint_t)); 35 | int _EXFUN(iswpunct, (wint_t)); 36 | int _EXFUN(iswspace, (wint_t)); 37 | int _EXFUN(iswupper, (wint_t)); 38 | int _EXFUN(iswxdigit, (wint_t)); 39 | wint_t _EXFUN(towctrans, (wint_t, wctrans_t)); 40 | wint_t _EXFUN(towupper, (wint_t)); 41 | wint_t _EXFUN(towlower, (wint_t)); 42 | wctrans_t _EXFUN(wctrans, (const char *)); 43 | wctype_t _EXFUN(wctype, (const char *)); 44 | 45 | _END_STD_C 46 | 47 | #endif /* _WCTYPE_H_ */ 48 | -------------------------------------------------------------------------------- /pa2018_fall/libs/newlib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/libs/newlib/libc.a -------------------------------------------------------------------------------- /pa2018_fall/nemu/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | 3 | CC := gcc 4 | LD := ld 5 | CFLAGS := -ggdb3 -MMD -MP -Wall -Werror -O2 -I./include -I../include -I../libs -I../libs/nemu-ref/include 6 | LDFLAGS := -lreadline -lSDL 7 | 8 | CFILES := $(shell find src/ -name "*.c") 9 | OBJS := $(CFILES:.c=.o) 10 | IFILES := $(CFILES:.c=.i) 11 | 12 | nemu: $(OBJS) ../include/config.h 13 | $(CC) -o nemu $(OBJS) ../libs/nemu-ref/lib-nemu-ref.a $(LDFLAGS) 14 | 15 | %.i: %.c 16 | $(CC) $(CFLAGS) -E -o $@ $< 17 | 18 | clean: 19 | -rm -f nemu $(OBJS) $(IFILES) $(OBJS:.o=.d) 20 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/cpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __CPU_H__ 2 | #define __CPU_H__ 3 | 4 | // interface for cpu functions 5 | 6 | #include "nemu.h" 7 | #include "cpu/reg.h" 8 | #include "cpu/alu.h" 9 | #include "cpu/reg_fpu.h" 10 | 11 | extern CPU_STATE cpu; 12 | 13 | // initialize the cpu states 14 | void init_cpu(); 15 | 16 | // execute n instructions starting from the current eip 17 | // change eip according to the length of the instruction in each step 18 | void exec(uint32_t n); 19 | 20 | // execute an instruction pointed by the current eip 21 | // return the length of the instruction 22 | int exec_inst(); 23 | 24 | void set_CF_add(uint32_t result,uint32_t src,size_t data_size); 25 | void set_CF_adc(uint32_t result,uint32_t src,size_t data_size); 26 | void set_CF_sub(uint32_t result,uint32_t src,size_t data_size); 27 | void set_CF_sbb(uint32_t result,uint32_t src,size_t data_size); 28 | 29 | void set_ZF(uint32_t result,size_t data_size); 30 | 31 | void set_SF(uint32_t result,size_t data_size); 32 | 33 | void set_PF(uint32_t result); 34 | 35 | void set_OF_add(uint32_t result,uint32_t src,uint32_t dest,size_t data_size); 36 | void set_OF_sub(uint32_t result,uint32_t src,uint32_t dest,size_t data_size); 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/fpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __FPU_H__ 2 | #define __FPU_H__ 3 | 4 | #include "cpu/cpu.h" 5 | #include "cpu/reg_fpu.h" 6 | #include 7 | 8 | extern FPU fpu; 9 | extern CPU_STATE cpu; 10 | 11 | #define P_ZERO_F 0X0 12 | #define N_ZERO_F 0X80000000 13 | #define P_INF_F 0X7f800000 14 | #define N_INF_F 0Xff800000 15 | #define P_NAN_F 0X7fc00000 16 | #define N_NAN_F 0Xffc00000 17 | 18 | typedef struct { 19 | uint32_t a; 20 | uint32_t b; 21 | uint32_t res; 22 | } CORNER_CASE_RULE; 23 | 24 | void fpu_load(uint32_t val); 25 | uint32_t fpu_store(); 26 | uint32_t fpu_peek(); 27 | void fpu_add(uint32_t val); 28 | void fpu_add_idx(uint32_t idx, uint32_t store_idx); 29 | void fpu_sub(uint32_t val); 30 | void fpu_mul(uint32_t val); 31 | void fpu_mul_idx(uint32_t idx, uint32_t store_idx); 32 | void fpu_div(uint32_t val); 33 | void fpu_xch(uint32_t idx); 34 | void fpu_copy(uint32_t idx); 35 | void fpu_cmp(uint32_t idx); 36 | void fpu_cmpi(uint32_t idx); 37 | 38 | // a + b 39 | uint32_t internal_float_add(uint32_t b, uint32_t a); 40 | // a - b 41 | uint32_t internal_float_sub(uint32_t b, uint32_t a); 42 | // a * b 43 | uint32_t internal_float_mul(uint32_t b, uint32_t a); 44 | // a / b 45 | uint32_t internal_float_div(uint32_t b, uint32_t a); 46 | 47 | //void fpu_test(); 48 | #endif 49 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/adc.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_ADC_H__ 2 | #define __INSTR_ADC_H__ 3 | 4 | make_instr_func(adc_r2rm_b); 5 | make_instr_func(adc_r2rm_v); 6 | make_instr_func(adc_rm2r_b); 7 | make_instr_func(adc_rm2r_v); 8 | make_instr_func(adc_i2a_b); 9 | make_instr_func(adc_i2a_v); 10 | make_instr_func(adc_i2rm_b); 11 | make_instr_func(adc_i2rm_v); 12 | make_instr_func(adc_i2rm_bv); 13 | 14 | #endif 15 | 16 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/add.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_ADD_H__ 2 | #define __INSTR_ADD_H__ 3 | 4 | make_instr_func(add_r2rm_b); 5 | make_instr_func(add_r2rm_v); 6 | make_instr_func(add_rm2r_b); 7 | make_instr_func(add_rm2r_v); 8 | make_instr_func(add_i2a_b); 9 | make_instr_func(add_i2a_v); 10 | make_instr_func(add_i2rm_b); 11 | make_instr_func(add_i2rm_v); 12 | make_instr_func(add_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/and.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_AND_H__ 2 | #define __INSTR_AND_H__ 3 | 4 | make_instr_func(and_r2rm_b); 5 | make_instr_func(and_r2rm_v); 6 | make_instr_func(and_rm2r_b); 7 | make_instr_func(and_rm2r_v); 8 | make_instr_func(and_i2a_b); 9 | make_instr_func(and_i2a_v); 10 | make_instr_func(and_i2rm_b); 11 | make_instr_func(and_i2rm_v); 12 | make_instr_func(and_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/call.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_CALL_H__ 2 | #define __INSTR_CALL_H__ 3 | 4 | make_instr_func(call_near); 5 | make_instr_func(call_near_indirect); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/cli.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_CLI_H__ 2 | #define __INSTR_CLI_H__ 3 | 4 | make_instr_func(cli); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/cmp.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_CMP_H__ 2 | #define __INSTR_CMP_H__ 3 | 4 | make_instr_func(cmp_r2rm_b); 5 | make_instr_func(cmp_r2rm_v); 6 | make_instr_func(cmp_rm2r_b); 7 | make_instr_func(cmp_rm2r_v); 8 | make_instr_func(cmp_i2a_b); 9 | make_instr_func(cmp_i2a_v); 10 | make_instr_func(cmp_i2rm_b); 11 | make_instr_func(cmp_i2rm_v); 12 | make_instr_func(cmp_i2rm_bv); 13 | make_instr_func(cmps_v); 14 | make_instr_func(cmps_b); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/dec.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_DEC_H__ 2 | #define __INSTR_DEC_H__ 3 | 4 | make_instr_func(dec_r_v); 5 | make_instr_func(dec_rm_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/div.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_DIV_H__ 2 | #define __INSTR_DIV_H__ 3 | 4 | make_instr_func(div_rm2a_b); 5 | make_instr_func(div_rm2a_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/flags.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_FLAGS_H__ 2 | #define __INSTR_FLAGS_H__ 3 | 4 | make_instr_func(cld); 5 | make_instr_func(clc); 6 | make_instr_func(sahf); 7 | make_instr_func(bt_r2rm_v); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/idiv.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_IDIV_H__ 2 | #define __INSTR_IDIV_H__ 3 | 4 | make_instr_func(idiv_rm2a_b); 5 | make_instr_func(idiv_rm2a_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/imul.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_IMUL_H__ 2 | #define __INSTR_IMUL_H__ 3 | 4 | make_instr_func(imul_rm2a_b); 5 | make_instr_func(imul_rm2a_v); 6 | make_instr_func(imul_rm2r_v); 7 | make_instr_func(imul_irm2r_v); 8 | make_instr_func(imul_i8rm2r_v); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/in.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_IN_H__ 2 | #define __INSTR_IN_H__ 3 | 4 | make_instr_func(in_b); 5 | make_instr_func(in_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/inc.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_INC_H__ 2 | #define __INSTR_INC_H__ 3 | 4 | make_instr_func(inc_r_v); 5 | make_instr_func(inc_rm_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/int.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_INT_H__ 2 | #define __INSTR_INT_H__ 3 | 4 | make_instr_func(int_); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/iret.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_IRET_H__ 2 | #define __INSTR_IRET_H__ 3 | 4 | make_instr_func(iret); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/jmp.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_JMP_H__ 2 | #define __INSTR_JMP_H__ 3 | 4 | make_instr_func(jmp_near); 5 | make_instr_func(jmp_near_indirect); 6 | make_instr_func(jmp_far_imm); 7 | make_instr_func(jmp_short); 8 | make_instr_func(jo_short_); 9 | make_instr_func(jno_short_); 10 | make_instr_func(jb_short_); 11 | make_instr_func(jae_short_); 12 | make_instr_func(je_short_); 13 | make_instr_func(jne_short_); 14 | make_instr_func(jna_short_); 15 | make_instr_func(ja_short_); 16 | make_instr_func(js_short_); 17 | make_instr_func(jns_short_); 18 | make_instr_func(jp_short_); 19 | make_instr_func(jnp_short_); 20 | make_instr_func(jl_short_); 21 | make_instr_func(jge_short_); 22 | make_instr_func(jle_short_); 23 | make_instr_func(jg_short_); 24 | make_instr_func(jo_near); 25 | make_instr_func(jno_near); 26 | make_instr_func(jb_near); 27 | make_instr_func(jae_near); 28 | make_instr_func(je_near); 29 | make_instr_func(jne_near); 30 | make_instr_func(jna_near); 31 | make_instr_func(ja_near); 32 | make_instr_func(js_near); 33 | make_instr_func(jns_near); 34 | make_instr_func(jp_near); 35 | make_instr_func(jnp_near); 36 | make_instr_func(jl_near); 37 | make_instr_func(jge_near); 38 | make_instr_func(jle_near); 39 | make_instr_func(jg_near); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/lea.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_LEA_H__ 2 | #define __INSTR_LEA_H__ 3 | 4 | make_instr_func(lea); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/leave.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_LEAVE_H__ 2 | #define __INSTR_LEAVE_H__ 3 | 4 | make_instr_func(leave); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/lgdt.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_LGDT_H__ 2 | #define __INSTR_LGDT_H__ 3 | 4 | make_instr_func(lgdt); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/lidt.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_LIDT_H__ 2 | #define __INSTR_LIDT_H__ 3 | 4 | make_instr_func(lidt); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/mov.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_MOV_H__ 2 | #define __INSTR_MOV_H__ 3 | 4 | make_instr_func(mov_r2rm_b); 5 | make_instr_func(mov_r2rm_v); 6 | make_instr_func(mov_rm2r_b); 7 | make_instr_func(mov_rm2r_v); 8 | make_instr_func(mov_i2rm_b); 9 | make_instr_func(mov_i2rm_v); 10 | make_instr_func(mov_i2r_b); 11 | make_instr_func(mov_i2r_v); 12 | make_instr_func(mov_o2a_b); 13 | make_instr_func(mov_o2a_v); 14 | make_instr_func(mov_a2o_b); 15 | make_instr_func(mov_a2o_v); 16 | make_instr_func(mov_c2r_l); 17 | make_instr_func(mov_r2c_l); 18 | make_instr_func(mov_rm2s_w); 19 | make_instr_func(mov_zrm82r_v); 20 | make_instr_func(mov_zrm162r_l); 21 | make_instr_func(mov_srm82r_v); 22 | make_instr_func(mov_srm162r_l); 23 | 24 | make_instr_func(movs_v); 25 | make_instr_func(movs_b); 26 | 27 | make_instr_func(cmova_rm2r_v); 28 | make_instr_func(cmovae_rm2r_v); 29 | make_instr_func(cmovb_rm2r_v); 30 | make_instr_func(cmovbe_rm2r_v); 31 | make_instr_func(cmovg_rm2r_v); 32 | make_instr_func(cmovge_rm2r_v); 33 | make_instr_func(cmovl_rm2r_v); 34 | make_instr_func(cmovle_rm2r_v); 35 | make_instr_func(cmovne_rm2r_v); 36 | make_instr_func(cmovno_rm2r_v); 37 | make_instr_func(cmovnp_rm2r_v); 38 | make_instr_func(cmovns_rm2r_v); 39 | make_instr_func(cmovo_rm2r_v); 40 | make_instr_func(cmovp_rm2r_v); 41 | make_instr_func(cmovs_rm2r_v); 42 | make_instr_func(cmove_rm2r_v); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/mul.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_MUL_H__ 2 | #define __INSTR_MUL_H__ 3 | 4 | make_instr_func(mul_rm2a_b); 5 | make_instr_func(mul_rm2a_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/neg.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_NEG_H__ 2 | #define __INSTR_NEG_H__ 3 | 4 | make_instr_func(neg_rm_b); 5 | make_instr_func(neg_rm_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/not.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_NOT_H__ 2 | #define __INSTR_NOT_H__ 3 | 4 | make_instr_func(not_rm_b); 5 | make_instr_func(not_rm_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/or.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_OR_H__ 2 | #define __INSTR_OR_H__ 3 | 4 | make_instr_func(or_r2rm_b); 5 | make_instr_func(or_r2rm_v); 6 | make_instr_func(or_rm2r_b); 7 | make_instr_func(or_rm2r_v); 8 | make_instr_func(or_i2a_b); 9 | make_instr_func(or_i2a_v); 10 | make_instr_func(or_i2rm_b); 11 | make_instr_func(or_i2rm_v); 12 | make_instr_func(or_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/out.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_OUT_H__ 2 | #define __INSTR_OUT_H__ 3 | 4 | make_instr_func(out_b); 5 | make_instr_func(out_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/pop.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_POP_H__ 2 | #define __INSTR_POP_H__ 3 | 4 | make_instr_func(pop_r_v); 5 | make_instr_func(pop_rm_v); 6 | make_instr_func(pop_i_b); 7 | make_instr_func(pop_i_v); 8 | make_instr_func(popa); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/push.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_PUSH_H__ 2 | #define __INSTR_PUSH_H__ 3 | 4 | make_instr_func(push_r_v); 5 | make_instr_func(push_rm_v); 6 | make_instr_func(push_i_b); 7 | make_instr_func(push_i_v); 8 | make_instr_func(pusha); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/ret.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_RET_H__ 2 | #define __INSTR_RET_H__ 3 | 4 | make_instr_func(ret_near); 5 | make_instr_func(ret_near_imm16); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/sbb.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_SBB_H__ 2 | #define __INSTR_SBB_H__ 3 | 4 | make_instr_func(sbb_r2rm_b); 5 | make_instr_func(sbb_r2rm_v); 6 | make_instr_func(sbb_rm2r_b); 7 | make_instr_func(sbb_rm2r_v); 8 | make_instr_func(sbb_i2a_b); 9 | make_instr_func(sbb_i2a_v); 10 | make_instr_func(sbb_i2rm_b); 11 | make_instr_func(sbb_i2rm_v); 12 | make_instr_func(sbb_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/set.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_SET_H__ 2 | #define __INSTR_SET_H__ 3 | 4 | make_instr_func(seto_b); 5 | make_instr_func(setno_b); 6 | make_instr_func(setc_b); 7 | make_instr_func(setae_b); 8 | make_instr_func(sete_b); 9 | make_instr_func(setne_b); 10 | make_instr_func(setbe_b); 11 | make_instr_func(seta_b); 12 | make_instr_func(sets_b); 13 | make_instr_func(setns_b); 14 | make_instr_func(setp_b); 15 | make_instr_func(setnp_b); 16 | make_instr_func(setl_b); 17 | make_instr_func(setge_b); 18 | make_instr_func(setle_b); 19 | make_instr_func(setg_b); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/shift.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_SHIFT_H__ 2 | #define __INSTR_SHIFT_H__ 3 | 4 | make_instr_func(shl_i2rm_bv); 5 | make_instr_func(shl_i2rm_b); 6 | make_instr_func(shl_rm_v); 7 | make_instr_func(shl_rm_b); 8 | make_instr_func(shl_c2rm_bv); 9 | make_instr_func(shl_c2rm_b); 10 | 11 | make_instr_func(shr_i2rm_bv); 12 | make_instr_func(shr_i2rm_b); 13 | make_instr_func(shr_rm_v); 14 | make_instr_func(shr_rm_b); 15 | make_instr_func(shr_c2rm_bv); 16 | make_instr_func(shr_c2rm_b); 17 | 18 | make_instr_func(sar_i2rm_bv); 19 | make_instr_func(sar_i2rm_b); 20 | make_instr_func(sar_rm_v); 21 | make_instr_func(sar_rm_b); 22 | make_instr_func(sar_c2rm_bv); 23 | make_instr_func(sar_c2rm_b); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/special.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_SPECIAL_H__ 2 | #define __INSTR_SPECIAL_H__ 3 | 4 | 5 | make_instr_func(inv); 6 | make_instr_func(nemu_trap); 7 | make_instr_func(break_point); 8 | make_instr_func(nop); 9 | make_instr_func(data_size_16); 10 | make_instr_func(rep_repe); 11 | make_instr_func(cltd); 12 | make_instr_func(hlt); 13 | make_instr_func(opcode_2_byte); 14 | make_instr_func(cbw_a_v); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/sti.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_STI_H__ 2 | #define __INSTR_STI_H__ 3 | 4 | make_instr_func(sti); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/stoc.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_STOC_H__ 2 | #define __INSTR_STOC_H__ 3 | 4 | make_instr_func(stos_b); 5 | make_instr_func(stos_v); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/sub.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_SUB_H__ 2 | #define __INSTR_SUB_H__ 3 | 4 | make_instr_func(sub_r2rm_b); 5 | make_instr_func(sub_r2rm_v); 6 | make_instr_func(sub_rm2r_b); 7 | make_instr_func(sub_rm2r_v); 8 | make_instr_func(sub_i2a_b); 9 | make_instr_func(sub_i2a_v); 10 | make_instr_func(sub_i2rm_b); 11 | make_instr_func(sub_i2rm_v); 12 | make_instr_func(sub_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/test.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_TEST_H__ 2 | #define __INSTR_TEST_H__ 3 | 4 | make_instr_func(test_r2rm_b); 5 | make_instr_func(test_r2rm_v); 6 | make_instr_func(test_i2rm_b); 7 | make_instr_func(test_i2rm_v); 8 | make_instr_func(test_i2a_b); 9 | make_instr_func(test_i2a_v); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/x87.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_X87_H__ 2 | #define __INSTR_X87_H__ 3 | 4 | make_instr_func(x87_fldx); 5 | make_instr_func(x87_flds); 6 | make_instr_func(x87_fldl); 7 | make_instr_func(x87_fstps); 8 | make_instr_func(x87_fsts); 9 | make_instr_func(x87_fstx); 10 | make_instr_func(x87_fstpx); 11 | make_instr_func(x87_fadds); 12 | make_instr_func(x87_faddx); 13 | make_instr_func(x87_faddlx); 14 | make_instr_func(x87_fsubs); 15 | make_instr_func(x87_fmuls); 16 | make_instr_func(x87_fmullx); 17 | make_instr_func(x87_fdivs); 18 | make_instr_func(x87_fxch); 19 | make_instr_func(x87_fucom); 20 | make_instr_func(x87_fucomp); 21 | make_instr_func(x87_fucompp); 22 | make_instr_func(x87_fucomi); 23 | make_instr_func(x87_fucomip); 24 | make_instr_func(x87_fnstsw); 25 | make_instr_func(x87_fnstcw); 26 | make_instr_func(x87_fistpl); 27 | make_instr_func(x87_fildl); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/instr/xor.h: -------------------------------------------------------------------------------- 1 | #ifndef __INSTR_XOR_H__ 2 | #define __INSTR_XOR_H__ 3 | 4 | make_instr_func(xor_r2rm_b); 5 | make_instr_func(xor_r2rm_v); 6 | make_instr_func(xor_rm2r_b); 7 | make_instr_func(xor_rm2r_v); 8 | make_instr_func(xor_i2a_b); 9 | make_instr_func(xor_i2a_v); 10 | make_instr_func(xor_i2rm_b); 11 | make_instr_func(xor_i2rm_v); 12 | make_instr_func(xor_i2rm_bv); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/intr.h: -------------------------------------------------------------------------------- 1 | #ifndef __INTR_H__ 2 | #define __INTR_H__ 3 | 4 | #include "nemu.h" 5 | #include "device/i8259_pic.h" 6 | 7 | typedef union GateDescriptor { 8 | struct { 9 | uint32_t offset_15_0 : 16; 10 | uint32_t selector : 16; 11 | uint32_t pad0 : 8; 12 | uint32_t type : 4; 13 | uint32_t system : 1; 14 | uint32_t privilege_level : 2; 15 | uint32_t present : 1; 16 | uint32_t offset_31_16 : 16; 17 | }; 18 | uint32_t val[2]; 19 | } GateDesc; 20 | 21 | void raise_intr(uint8_t intr_no); 22 | void raise_sw_intr(uint8_t intr_no); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/modrm.h: -------------------------------------------------------------------------------- 1 | #ifndef __MOD_RM__ 2 | #define __MOD_RM__ 3 | 4 | #include "cpu/operand.h" 5 | 6 | typedef union { 7 | struct { 8 | uint32_t rm :3; 9 | uint32_t reg_opcode :3; 10 | uint32_t mod :2; 11 | }; 12 | uint8_t val; 13 | }MODRM; 14 | 15 | 16 | 17 | 18 | 19 | // The following functions parses the ModR/M byte and the possible following SIB and displacement bytes. 20 | // Return the number of bytes read during parsing the ModR/M byte. 21 | // Note they are only responsible for getting the type and addr of the 22 | // operands, not the values. 23 | int modrm_r_rm(uint32_t eip, OPERAND * r, OPERAND * rm); 24 | int modrm_opcode_rm(uint32_t eip, uint8_t * opcode, OPERAND * rm); 25 | int modrm_opcode(uint32_t eip, uint8_t * opcode); 26 | int modrm_rm(uint32_t eip, OPERAND * rm); 27 | #endif 28 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/operand.h: -------------------------------------------------------------------------------- 1 | #ifndef __OPERAND_H__ 2 | #define __OPERAND_H__ 3 | 4 | #include "nemu.h" 5 | #include "cpu/cpu.h" 6 | #include "memory/memory.h" 7 | 8 | // operand type for immediate number, register, and memory 9 | enum {OPR_IMM, OPR_REG, OPR_MEM, OPR_CREG, OPR_SREG}; 10 | 11 | #define MEM_ADDR_NA 0xffffffff 12 | 13 | //enum {MEM_ADDR_OFF, MEM_ADDR_SIB}; 14 | 15 | typedef struct { 16 | // uint32_t type; 17 | uint32_t disp; // hex 18 | uint32_t base; // register 19 | uint32_t index; // register 20 | uint32_t scale; // 1, 2, 4, 8 21 | } MEM_ADDR; // memory address details 22 | 23 | typedef struct { 24 | int type; 25 | uint32_t addr; 26 | uint8_t sreg; 27 | uint32_t val; 28 | size_t data_size; 29 | MEM_ADDR mem_addr; 30 | }OPERAND; 31 | 32 | extern OPERAND opr_src, opr_dest; 33 | 34 | // read the operand's value from its addr 35 | void operand_read(OPERAND * opr); 36 | 37 | // write the operand's value to its addr 38 | void operand_write(OPERAND * opr); 39 | void operand_write_cr0(OPERAND * opr); 40 | 41 | void parse_operand_address(OPERAND * opr, char * str); 42 | void clear_operand_mem_addr(OPERAND * opr); 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/reg_fpu.h: -------------------------------------------------------------------------------- 1 | #ifndef __REG_FPU_H__ 2 | #define __REG_FPU_H__ 3 | 4 | #include "nemu.h" 5 | 6 | typedef union { 7 | struct { 8 | uint32_t ie :1; 9 | uint32_t de :1; 10 | uint32_t ze :1; 11 | uint32_t oe :1; 12 | uint32_t ue :1; 13 | uint32_t pe :1; 14 | uint32_t sf :1; 15 | uint32_t es :1; 16 | uint32_t c0 :1; 17 | uint32_t c1 :1; 18 | uint32_t c2 :1; 19 | uint32_t top :3; 20 | uint32_t c3 :1; 21 | uint32_t b :1; 22 | 23 | }; 24 | uint16_t val; 25 | }FPU_STATUS_WORD; 26 | 27 | typedef union { 28 | struct { 29 | uint32_t im :1; 30 | uint32_t dm :1; 31 | uint32_t zm :1; 32 | uint32_t om :1; 33 | uint32_t um :1; 34 | uint32_t pm :1; 35 | uint32_t resv_0 :2; 36 | uint32_t pc :2; 37 | uint32_t rc :2; 38 | uint32_t x :1; 39 | uint32_t resv_1 :3; 40 | }; 41 | uint16_t val; 42 | }FPU_CTRL_WORD; 43 | 44 | typedef union { 45 | struct { 46 | uint32_t fraction :23; 47 | uint32_t exponent :8; 48 | uint32_t sign :1; 49 | }; 50 | float fval; 51 | uint32_t val; 52 | }FLOAT; 53 | 54 | typedef struct { 55 | FLOAT regStack[8]; 56 | FPU_STATUS_WORD status; 57 | FPU_CTRL_WORD control; 58 | }FPU; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/cpu/sib.h: -------------------------------------------------------------------------------- 1 | #ifndef __SIB_H__ 2 | #define __SIB_H__ 3 | 4 | #include "nemu.h" 5 | #include "cpu/operand.h" 6 | 7 | typedef union { 8 | struct { 9 | uint32_t base :3; 10 | uint32_t index :3; 11 | uint32_t ss :2; 12 | }; 13 | uint8_t val; 14 | }SIB; 15 | 16 | 17 | // given the sib byte, parse it and obtain the address 18 | //uint32_t parse_sib(SIB s); 19 | //int parse_sib(uint32_t eip, uint32_t mod, uint32_t * sibaddr, uint8_t * sibsreg); 20 | int parse_sib(uint32_t eip, uint32_t mod, OPERAND * opr); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/audio.h: -------------------------------------------------------------------------------- 1 | #ifndef __AUDIO_H__ 2 | #define __AUDIO_H__ 3 | 4 | #include "nemu.h" 5 | #include "device/port_io.h" 6 | #include 7 | 8 | #define AUDIO_DATA 0xC0 9 | #define AUDIO_CTL 0xC1 10 | #define AUDIO_IRQ 2 11 | 12 | make_pio_handler(audio_io_handler); 13 | 14 | void audio_start(); 15 | void audio_stop(); 16 | 17 | #endif 18 | 19 | 20 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/i8259_pic.h: -------------------------------------------------------------------------------- 1 | #ifndef __I8259_PIC_H__ 2 | #define __I8259_PIC_H__ 3 | 4 | 5 | #include "nemu.h" 6 | 7 | #define IRQ_BASE 32 8 | #define I8259_NO_INTR 255 9 | 10 | // get interrupt number 11 | uint8_t i8259_query_intr_no(); 12 | 13 | // called by device (keyboard) to raise an interrupt with irq number 14 | void i8259_raise_intr(uint8_t irq_no); 15 | 16 | // called by cpu after the cpu has received the interrupt 17 | void i8259_ack_intr(); 18 | 19 | void i8259_init(); 20 | 21 | void i8259_destroy(); 22 | #endif 23 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/ide.h: -------------------------------------------------------------------------------- 1 | #ifndef __HARD_DISK_H__ 2 | #define __HARD_DISK_H__ 3 | 4 | #include "nemu.h" 5 | #include "device/port_io.h" 6 | 7 | #define IDE_PORT_BASE 0x1F0 8 | 9 | //#define BMR_PORT_BASE 0xc040 10 | 11 | #define IDE_IRQ 14 12 | 13 | 14 | // init the hard disk by loading the file needed 15 | void init_ide(const char * file_to_load); 16 | 17 | make_pio_handler(handler_ide); 18 | make_pio_handler(handler_bmr); 19 | 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/mm_io.h: -------------------------------------------------------------------------------- 1 | #ifndef __MM_IO_H__ 2 | #define __MM_IO_H__ 3 | 4 | #include "nemu.h" 5 | 6 | typedef void(*mmio_callback_t)(uint32_t hwaddr, size_t len, bool isWrite); 7 | 8 | void* add_mmio_map(uint32_t hwaddr, size_t len, mmio_callback_t callback); 9 | void clear_mmio_map(); 10 | int is_mmio(uint32_t hwaddr); 11 | 12 | uint32_t mmio_read(uint32_t hwaddr, size_t len, int map_NO); 13 | void mmio_write(uint32_t hwaddr, size_t len, uint32_t data, int map_NO); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/port_io.h: -------------------------------------------------------------------------------- 1 | #ifndef __PORT_IO_H__ 2 | #define __PORT_IO_H__ 3 | 4 | #include "nemu.h" 5 | 6 | // macro for making a port io handler 7 | #define make_pio_handler(name) void name(uint16_t port, size_t len, bool is_write) 8 | 9 | // port io handler 10 | typedef void (*pio_handler)(uint16_t port, size_t len, bool is_write); 11 | 12 | // called by the out instruction 13 | void pio_write(uint16_t port, size_t len, uint32_t data); 14 | 15 | // called by the in instruction 16 | uint32_t pio_read(uint16_t port, size_t len); 17 | 18 | // write value to an io port, internal use only 19 | void write_io_port(uint16_t port, size_t len, uint32_t data); 20 | 21 | // read value from an io port, internal use only 22 | uint32_t read_io_port(uint16_t port, size_t len); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/sdl.h: -------------------------------------------------------------------------------- 1 | #ifndef __SDL_H__ 2 | #define __SDL_H__ 3 | 4 | void init_sdl(); 5 | void close_sdl(); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/serial.h: -------------------------------------------------------------------------------- 1 | #ifndef __SERIAL_H__ 2 | #define __SERIAL_H__ 3 | 4 | #include "device/port_io.h" 5 | 6 | #define SERIAL_PORT 0x3F8 7 | 8 | make_pio_handler(handler_serial); 9 | 10 | void init_serial(); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/timer.h: -------------------------------------------------------------------------------- 1 | #ifndef __TIMER_H__ 2 | #define __TIMER_H__ 3 | 4 | #include "nemu.h" 5 | #include "device/port_io.h" 6 | 7 | #define TIMER_PORT 0X40 8 | #define TIMER_IRQ 0x0 9 | 10 | void timer_intr(); 11 | make_pio_handler(handler_timer); 12 | void timer_start(int hz); 13 | void timer_stop(); 14 | #endif 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/device/vga.h: -------------------------------------------------------------------------------- 1 | #ifndef __VGA_H__ 2 | #define __VGA_H__ 3 | 4 | #include "nemu.h" 5 | #include "device/port_io.h" 6 | #include 7 | 8 | #define SCREEN_ROW 400 9 | #define SCREEN_COL 640 10 | #define VGA_HZ 25 11 | 12 | #define VGA_DAC_READ_INDEX 0x3C7 13 | #define VGA_DAC_WRITE_INDEX 0x3C8 14 | #define VGA_DAC_DATA 0x3C9 15 | 16 | #define VGA_CRTC_INDEX 0x3D4 17 | #define VGA_CRTC_DATA 0x3D5 18 | 19 | extern SDL_Surface *real_screen; 20 | extern SDL_Surface *screen; 21 | 22 | extern uint8_t (*pixel_buf) [SCREEN_COL]; 23 | 24 | static inline void draw_pixel(int x, int y, uint8_t color_idx) { 25 | assert(x >= 0 && x < SCREEN_COL && y >= 0 && y < SCREEN_ROW); 26 | pixel_buf[y][x] = color_idx; 27 | } 28 | 29 | typedef union { 30 | uint32_t val; 31 | struct { 32 | uint8_t r, g, b, a; 33 | }; 34 | } Color; 35 | 36 | extern Color palette[]; 37 | 38 | void update_screen(); 39 | void vga_init(); 40 | void vga_close(); 41 | 42 | 43 | 44 | make_pio_handler(vga_dac_io_handler); 45 | make_pio_handler(vga_crtc_io_handler); 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/macro.h: -------------------------------------------------------------------------------- 1 | #ifndef __MACRO_H__ 2 | #define __MACRO_H__ 3 | 4 | #define str_temp(x) #x 5 | #define str(x) str_temp(x) 6 | 7 | #define concat_temp(x, y) x ## y 8 | #define concat(x, y) concat_temp(x, y) 9 | #define concat3(x, y, z) concat(concat(x, y), z) 10 | #define concat4(x, y, z, w) concat3(concat(x, y), z, w) 11 | #define concat5(x, y, z, v, w) concat4(concat(x, y), z, v, w) 12 | #define concat6(x, y, z, v, w, u) concat5(concat(x, y), z, v, w, u) 13 | #define concat7(x, y, z, v, w, u, h) concat6(concat(x, y), z, v, w, u, h) 14 | 15 | #define rw1byte(addr) (*(uint8_t *)(addr)) 16 | #define rw2byte(addr) (*(uint16_t *)(addr)) 17 | #define rw3byte(addr) (rw1byte(addr) | (rw2byte((void*)(addr) + 1) << 8)) 18 | #define rw4byte(addr) (*(uint32_t *)(addr)) 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/memory/cache.h: -------------------------------------------------------------------------------- 1 | #ifndef __CACHE_H 2 | #define __CACHE_H 3 | 4 | #include "nemu.h" 5 | 6 | typedef struct { 7 | bool valid; 8 | uint32_t sign; 9 | uint8_t block[64]; 10 | }CacheLine; 11 | 12 | void init_cache(); 13 | uint32_t cache_read(paddr_t paddr, size_t len, CacheLine* cache); 14 | void cache_write(paddr_t paddr, size_t len, uint32_t data, CacheLine* cache); 15 | 16 | extern CacheLine Cache[]; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/memory/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_H__ 2 | #define __MEMORY_H__ 3 | 4 | #include "nemu.h" 5 | #include "memory/mmu/segment.h" 6 | #include "memory/mmu/page.h" 7 | #include "memory/mmu/tlb.h" 8 | 9 | // 1MB memory 10 | #define MEM_SIZE_B 128*1024*1024 11 | 12 | extern uint8_t hw_mem[]; 13 | extern uint64_t hw_mem_access_time; 14 | 15 | #define hwa_to_va(p) ((void *)(hw_mem+(unsigned)p)) 16 | 17 | // read memory with physical address and size of bytes 18 | uint32_t paddr_read(paddr_t paddr, size_t len); 19 | 20 | // write data to memory with physical address and size of bytes 21 | void paddr_write(paddr_t paddr, size_t len, uint32_t data); 22 | 23 | // read memory with linear address and size of bytes 24 | uint32_t laddr_read(laddr_t laddr, size_t len); 25 | 26 | // write data to memory with linear address and size of bytes 27 | void laddr_write(laddr_t laddr, size_t len, uint32_t data); 28 | 29 | // read memory with virtual address and size of bytes 30 | uint32_t vaddr_read(vaddr_t vaddr, uint8_t sreg, size_t len); 31 | 32 | // write data to memory with virtual address and size of bytes 33 | void vaddr_write(vaddr_t vaddr, uint8_t sreg, size_t len, uint32_t data); 34 | 35 | // initialize the memory by clearing it 36 | void init_mem(); 37 | 38 | // fetch an instruction 39 | uint32_t instr_fetch(vaddr_t vaddr, size_t len); 40 | 41 | // print memory start from physical address addr and size len bytes 42 | //void mem_print(uint32_t addr, size_t len); 43 | uint8_t * get_mem_addr(); 44 | 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/memory/mmu/segment.h: -------------------------------------------------------------------------------- 1 | #ifndef __SEGMENT_H__ 2 | #define __SEGMENT_H__ 3 | 4 | typedef union SegmentDescriptor { 5 | struct { 6 | uint32_t limit_15_0 : 16; 7 | uint32_t base_15_0 : 16; 8 | uint32_t base_23_16 : 8; 9 | uint32_t type : 4; 10 | uint32_t segment_type : 1; 11 | uint32_t privilege_level : 2; 12 | uint32_t present : 1; 13 | uint32_t limit_19_16 : 4; 14 | uint32_t soft_use : 1; 15 | uint32_t operation_size : 1; 16 | uint32_t pad0 : 1; 17 | uint32_t granularity : 1; 18 | uint32_t base_31_24 : 8; 19 | }; 20 | uint32_t val[2]; 21 | } SegDesc; 22 | 23 | uint32_t segment_translate(uint32_t vaddr, uint8_t sreg); 24 | void load_sreg(uint8_t sreg); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/memory/mmu/tlb.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLB_H__ 2 | #define __TLB_H__ 3 | 4 | uint32_t tlb_read(laddr_t); 5 | void init_all_tlb(); 6 | void make_all_tlb(); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/monitor/breakpoint.h: -------------------------------------------------------------------------------- 1 | #ifndef __BREAKPOINT_H__ 2 | #define __BREAKPOINT_H__ 3 | 4 | #include "nemu.h" 5 | 6 | #define INT3_CODE 0xf1 7 | 8 | enum {IDLE, HIT, RE_EXEC}; 9 | 10 | enum {BREAKPOINT, WATCHPOINT}; 11 | 12 | typedef struct breakpoint { 13 | uint8_t ori_byte : 8; 14 | bool enable : 1; 15 | bool in_use : 1; 16 | int NO : 22; 17 | 18 | union { 19 | vaddr_t addr; 20 | struct { 21 | char *expr; 22 | uint32_t old_val; 23 | uint32_t new_val; 24 | }; 25 | }; 26 | int type; 27 | struct breakpoint *next; 28 | 29 | /* TODO: Add more member if necessary */ 30 | 31 | 32 | } BP; 33 | 34 | int set_breakpoint(vaddr_t); 35 | bool delete_breakpoint(int); 36 | void delete_all_breakpoint(); 37 | void list_breakpoint(); 38 | 39 | BP* find_breakpoint(vaddr_t); 40 | void resume_breakpoints(); 41 | void mask_breakpoints(); 42 | 43 | 44 | int set_watchpoint(char *e); 45 | BP* scan_watchpoint(); 46 | 47 | void load_elf_tables(const char *); 48 | void init_regex(); 49 | void init_bp_list(); 50 | 51 | uint32_t expr(char *, bool *); 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/monitor/ui.h: -------------------------------------------------------------------------------- 1 | #ifndef __UI_H__ 2 | #define __UI_H__ 3 | 4 | #include "nemu.h" 5 | 6 | void ui_mainloop(bool autorun); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/nemu.h: -------------------------------------------------------------------------------- 1 | #ifndef __NEMU2_H__ 2 | #define __NEMU2_H__ 3 | 4 | #include "macro.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | enum {NEMU_STOP, NEMU_RUN, NEMU_READY, NEMU_BREAK}; 13 | 14 | extern int nemu_state; 15 | 16 | typedef uint8_t bool; 17 | typedef uint32_t paddr_t; 18 | typedef uint32_t laddr_t; 19 | typedef uint32_t vaddr_t; 20 | 21 | typedef uint16_t ioaddr_t; 22 | 23 | extern bool verbose; 24 | 25 | typedef union { 26 | struct { 27 | uint32_t low; 28 | uint32_t high; 29 | }; 30 | uint64_t val; 31 | } UINT64_T; 32 | 33 | #define true 1 34 | #define false 0 35 | 36 | inline static void memcpy_with_mask(void *dest, const void *src, size_t len, uint8_t *mask) { 37 | int i; 38 | for(i = 0; i < len; i ++) { 39 | if(mask[i]) { 40 | ((uint8_t *)dest)[i] = ((uint8_t *)src)[i]; 41 | } 42 | } 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/include/test/reg_alu_fpu_test.h: -------------------------------------------------------------------------------- 1 | #ifndef __REG_ALU_FPU_TEST_H__ 2 | #define __REG_ALU_FPU_TEST_H__ 3 | 4 | // test for registers 5 | void reg_test(); 6 | 7 | // test for alu 8 | void alu_test_add(); 9 | void alu_test_adc(); 10 | void alu_test_sub(); 11 | void alu_test_sbb(); 12 | void alu_test_and(); 13 | void alu_test_or(); 14 | void alu_test_xor(); 15 | void alu_test_shl(); 16 | void alu_test_shr(); 17 | void alu_test_sal(); 18 | void alu_test_sar(); 19 | void alu_test_mul(); 20 | void alu_test_div(); 21 | void alu_test_imul(); 22 | void alu_test_idiv(); 23 | 24 | // test for fpu 25 | 26 | void init_fpu_test(); 27 | void fpu_test_add(); 28 | void fpu_test_sub(); 29 | void fpu_test_mul(); 30 | void fpu_test_div(); 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/adc.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_adc(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(adc, r, rm, b) 13 | make_instr_impl_2op(adc, r, rm, v) 14 | make_instr_impl_2op(adc, rm, r, b) 15 | make_instr_impl_2op(adc, rm, r, v) 16 | make_instr_impl_2op(adc, i, a, b) 17 | make_instr_impl_2op(adc, i, a, v) 18 | make_instr_impl_2op(adc, i, rm, b) 19 | make_instr_impl_2op(adc, i, rm, v) 20 | make_instr_impl_2op(adc, i, rm, bv) 21 | 22 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/add.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_add(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(add, r, rm, b) 13 | make_instr_impl_2op(add, r, rm, v) 14 | make_instr_impl_2op(add, rm, r, b) 15 | make_instr_impl_2op(add, rm, r, v) 16 | make_instr_impl_2op(add, i, a, b) 17 | make_instr_impl_2op(add, i, a, v) 18 | make_instr_impl_2op(add, i, rm, b) 19 | make_instr_impl_2op(add, i, rm, v) 20 | make_instr_impl_2op(add, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/and.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_and(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(and, r, rm, b) 13 | make_instr_impl_2op(and, r, rm, v) 14 | make_instr_impl_2op(and, rm, r, b) 15 | make_instr_impl_2op(and, rm, r, v) 16 | make_instr_impl_2op(and, i, a, b) 17 | make_instr_impl_2op(and, i, a, v) 18 | make_instr_impl_2op(and, i, rm, b) 19 | make_instr_impl_2op(and, i, rm, v) 20 | make_instr_impl_2op(and, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/bt.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | cpu.eflags.CF = (opr_dest.val >> opr_src.val) & 0x1; 7 | } 8 | 9 | make_instr_impl_2op(bt, r, rm, v); 10 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/call.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(call_near) { 4 | OPERAND rel,mem; 5 | rel.data_size=data_size; 6 | rel.type=OPR_IMM; 7 | rel.sreg=SREG_CS; 8 | rel.addr=cpu.eip+1; 9 | operand_read(&rel); 10 | print_asm_1("call", "", 1+data_size/8, &rel); 11 | cpu.esp-=data_size/8; 12 | mem.data_size=data_size; 13 | mem.type=OPR_MEM; 14 | mem.sreg=SREG_DS; 15 | mem.addr=cpu.esp; 16 | mem.val=cpu.eip+1+data_size/8; 17 | operand_write(&mem); 18 | int offset=sign_ext(rel.val, data_size); 19 | cpu.eip+=offset+1+data_size/8; 20 | return 0; 21 | } 22 | 23 | make_instr_func(call_near_indirect){ 24 | int len=1; 25 | OPERAND rel,mem; 26 | rel.data_size=data_size; 27 | len+=modrm_rm(eip+1, &rel); 28 | operand_read(&rel); 29 | print_asm_1("call", "", len, &rel); 30 | cpu.esp-=data_size/8; 31 | mem.data_size=data_size; 32 | mem.type=OPR_MEM; 33 | mem.sreg=SREG_DS; 34 | mem.addr=cpu.esp; 35 | mem.val=cpu.eip+len; 36 | operand_write(&mem); 37 | if(data_size==16) 38 | cpu.eip=rel.val&0xFFFF; 39 | else 40 | cpu.eip=rel.val; 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cbw.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | operand_read(&opr_src); 5 | if(opr_src.data_size == 16) { 6 | opr_src.val = sign_ext(opr_src.val, 8); 7 | } else { 8 | opr_src.val = sign_ext(opr_src.val, 16); 9 | } 10 | operand_write(&opr_src); 11 | } 12 | 13 | make_instr_impl_1op(cbw, a, v); 14 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cli.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(cli) { 4 | cpu.eflags.IF=0; 5 | print_asm_0("cli", "", 1); 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cltd.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(cltd) { 4 | OPERAND ax, dx; 5 | ax.type = OPR_REG; 6 | dx.type = OPR_REG; 7 | 8 | ax.data_size = data_size; 9 | dx.data_size = data_size; 10 | 11 | ax.addr = REG_AX; 12 | dx.addr = REG_DX; 13 | 14 | operand_read(&ax); 15 | int temp = (int) ax.val; 16 | 17 | uint32_t dxval = 0; 18 | if(temp < 0) { 19 | dxval = ~dxval; 20 | } 21 | dx.val = dxval; 22 | operand_write(&dx); 23 | 24 | print_asm_0("cltd", "", 1); 25 | return 1; 26 | } 27 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cmov.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op_cc_pass() { 4 | operand_read(&opr_src); 5 | opr_dest.val = opr_src.val; 6 | operand_write(&opr_dest); 7 | } 8 | 9 | static void instr_execute_2op_cc_fail() { /*Do nothing*/ } 10 | 11 | make_instr_impl_2op_cc(cmov, rm, r, v, a) 12 | make_instr_impl_2op_cc(cmov, rm, r, v, ae) 13 | make_instr_impl_2op_cc(cmov, rm, r, v, b) 14 | make_instr_impl_2op_cc(cmov, rm, r, v, be) 15 | make_instr_impl_2op_cc(cmov, rm, r, v, g) 16 | make_instr_impl_2op_cc(cmov, rm, r, v, ge) 17 | make_instr_impl_2op_cc(cmov, rm, r, v, l) 18 | make_instr_impl_2op_cc(cmov, rm, r, v, le) 19 | make_instr_impl_2op_cc(cmov, rm, r, v, ne) 20 | make_instr_impl_2op_cc(cmov, rm, r, v, no) 21 | make_instr_impl_2op_cc(cmov, rm, r, v, np) 22 | make_instr_impl_2op_cc(cmov, rm, r, v, ns) 23 | make_instr_impl_2op_cc(cmov, rm, r, v, o) 24 | make_instr_impl_2op_cc(cmov, rm, r, v, p) 25 | make_instr_impl_2op_cc(cmov, rm, r, v, s) 26 | make_instr_impl_2op_cc(cmov, rm, r, v, e) 27 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cmp.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | alu_sub(opr_src.val,opr_dest.val,data_size); 9 | } 10 | 11 | make_instr_impl_2op(cmp, r, rm, b) 12 | make_instr_impl_2op(cmp, r, rm, v) 13 | make_instr_impl_2op(cmp, rm, r, b) 14 | make_instr_impl_2op(cmp, rm, r, v) 15 | make_instr_impl_2op(cmp, i, a, b) 16 | make_instr_impl_2op(cmp, i, a, v) 17 | make_instr_impl_2op(cmp, i, rm, b) 18 | make_instr_impl_2op(cmp, i, rm, v) 19 | make_instr_impl_2op(cmp, i, rm, bv) 20 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/cmps.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(cmps_v) { 4 | OPERAND msi, mdi; 5 | msi.data_size = mdi.data_size = data_size; 6 | msi.type = mdi.type = OPR_MEM; 7 | msi.sreg = mdi.sreg = SREG_DS; 8 | msi.addr = cpu.gpr[REG_ESI]._32; 9 | mdi.addr = cpu.gpr[REG_EDI]._32; 10 | operand_read(&msi); 11 | operand_read(&mdi); 12 | alu_sub(mdi.val, msi.val, data_size); 13 | int incDec = 0; 14 | incDec = cpu.eflags.DF == 0 ? data_size / 8 : -data_size / 8; 15 | cpu.gpr[REG_ESI]._32 += incDec; 16 | cpu.gpr[REG_EDI]._32 += incDec; 17 | 18 | print_asm_0("cmps (%%edi), (%%esi)", "", 1); 19 | return 1; 20 | } 21 | 22 | make_instr_func(cmps_b) { 23 | OPERAND msi, mdi; 24 | msi.data_size = mdi.data_size = 8; 25 | msi.type = mdi.type = OPR_MEM; 26 | msi.sreg = mdi.sreg = SREG_DS; 27 | msi.addr = cpu.gpr[REG_ESI]._32; 28 | mdi.addr = cpu.gpr[REG_EDI]._32; 29 | operand_read(&msi); 30 | operand_read(&mdi); 31 | alu_sub(mdi.val, msi.val, data_size); 32 | int incDec = 0; 33 | incDec = cpu.eflags.DF == 0 ? 1 : -1; 34 | cpu.gpr[REG_ESI]._32 += incDec; 35 | cpu.gpr[REG_EDI]._32 += incDec; 36 | print_asm_0("cmps (%%edi), (%%esi)", "", 1); 37 | return 1; 38 | } 39 | 40 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/data_size.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | extern uint8_t data_size; 4 | 5 | make_instr_func(data_size_16) { 6 | uint8_t op_code = 0; 7 | int len = 0; 8 | data_size = 16; 9 | op_code = instr_fetch(eip + 1, 1); 10 | #ifdef NEMU_REF_INSTR 11 | len = __ref_opcode_entry[op_code](eip + 1, op_code); 12 | #else 13 | len = opcode_entry[op_code](eip + 1, op_code); 14 | #endif 15 | data_size = 32; 16 | return 1 + len; 17 | } 18 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/dec.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | operand_read(&opr_src); 5 | opr_src.val = alu_sub(1,opr_src.val,data_size); 6 | operand_write(&opr_src); 7 | } 8 | 9 | make_instr_impl_1op(dec, r, v) 10 | make_instr_impl_1op(dec, rm, v) 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/flags.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(cld) { 4 | cpu.eflags.DF = 0; 5 | print_asm_0("cld", "", 1); 6 | return 1; 7 | } 8 | 9 | make_instr_func(clc) { 10 | cpu.eflags.CF = 0; 11 | print_asm_0("clc", "", 1); 12 | return 1; 13 | } 14 | 15 | make_instr_func(sahf) { 16 | cpu.eflags.val = (cpu.eflags.val & 0xffff0000) | cpu.gpr[0]._8[1]; 17 | print_asm_0("sahf", "", 1); 18 | return 1; 19 | } 20 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/group.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | #define make_group_impl(name) \ 4 | make_instr_func(name) { \ 5 | uint8_t op_code; \ 6 | modrm_opcode(eip + 1, &op_code); \ 7 | return concat(name, _entry)[op_code](eip, op_code); \ 8 | } 9 | #define make_group_impl_ref(name) \ 10 | make_instr_func(name) { \ 11 | uint8_t op_code; \ 12 | modrm_opcode(eip + 1, &op_code); \ 13 | return concat3(__ref_, name, _entry)[op_code](eip, op_code); \ 14 | } 15 | 16 | #ifdef NEMU_REF_INSTR 17 | #define make_group_impl_cond make_group_impl_ref 18 | #else 19 | #define make_group_impl_cond make_group_impl 20 | #endif 21 | 22 | make_group_impl_cond(group_1_b); 23 | make_group_impl_cond(group_1_v); 24 | make_group_impl_cond(group_1_bv); 25 | make_group_impl_cond(group_2_b); 26 | make_group_impl_cond(group_2_v); 27 | make_group_impl_cond(group_2_1b); 28 | make_group_impl_cond(group_2_1v); 29 | make_group_impl_cond(group_2_cb); 30 | make_group_impl_cond(group_2_cv); 31 | make_group_impl_cond(group_3_b); 32 | make_group_impl_cond(group_3_v); 33 | make_group_impl_cond(group_5_indirect); 34 | make_group_impl_cond(group_7); 35 | make_group_impl_cond(group_x87_d8); 36 | make_group_impl_cond(group_x87_d9); 37 | make_group_impl_cond(group_x87_da); 38 | make_group_impl_cond(group_x87_db); 39 | make_group_impl_cond(group_x87_dc); 40 | make_group_impl_cond(group_x87_dd); 41 | make_group_impl_cond(group_x87_de); 42 | make_group_impl_cond(group_x87_df); 43 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/hlt.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | #include 4 | 5 | static int HLT_Thread(void * ptr) { 6 | #ifdef HAS_DEVICE_TIMER 7 | while(!cpu.intr && nemu_state != NEMU_STOP) { 8 | SDL_Delay(1); 9 | } 10 | #endif 11 | return 0; 12 | } 13 | 14 | make_instr_func(hlt) { 15 | SDL_Thread *thread; 16 | print_asm_0("hlt", "", 1); 17 | thread = SDL_CreateThread(HLT_Thread, (void *)NULL); 18 | 19 | if (NULL == thread) { 20 | printf("\nSDL_CreateThread for HLT failed: %s\n", SDL_GetError()); 21 | } else { 22 | SDL_WaitThread(thread, NULL); 23 | } 24 | return 1; 25 | } 26 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/in.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | #include "device/port_io.h" 3 | 4 | make_instr_func(in_b) { 5 | print_asm_0("in", "b", 1); 6 | cpu.eax = pio_read(cpu.edx, 1); 7 | return 1; 8 | } 9 | 10 | make_instr_func(in_v) { 11 | print_asm_0("in", (data_size == 16)?"w":"l", 1); 12 | cpu.eax = pio_read(cpu.edx, data_size/8); 13 | return 1; 14 | } 15 | 16 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/inc.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | operand_read(&opr_src); 5 | opr_src.val = alu_add(1,opr_src.val,data_size); 6 | operand_write(&opr_src); 7 | } 8 | 9 | make_instr_impl_1op(inc, r, v) 10 | make_instr_impl_1op(inc, rm, v) 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/int.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | #include "cpu/intr.h" 3 | 4 | make_instr_func(int_) { 5 | OPERAND rel; 6 | rel.type = OPR_IMM; 7 | rel.sreg = SREG_CS; 8 | rel.data_size = 8; 9 | rel.addr = eip + 1; 10 | operand_read(&rel); 11 | print_asm_1("int", "", 2, &rel); 12 | raise_sw_intr(rel.val); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/iret.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | #include "cpu/intr.h" 3 | 4 | make_instr_func(iret) { 5 | print_asm_0("iret", "", 1); 6 | cpu.eip=vaddr_read(cpu.esp,SREG_SS,4); 7 | cpu.esp+=4; 8 | cpu.cs.val=vaddr_read(cpu.esp,SREG_SS,2); 9 | cpu.esp+=2; 10 | cpu.eflags.val=vaddr_read(cpu.esp,SREG_SS,4); 11 | cpu.esp+=4; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/jcc.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op_cc_pass() { 4 | operand_read(&opr_src); 5 | cpu.eip += sign_ext(opr_src.val, opr_src.data_size); 6 | } 7 | 8 | static void instr_execute_1op_cc_fail() {/* Do nothing */} 9 | 10 | #define jcc_helper(suffix) \ 11 | make_instr_impl_1op_cc(j, i, suffix, e) \ 12 | make_instr_impl_1op_cc(j, i, suffix, a) \ 13 | make_instr_impl_1op_cc(j, i, suffix, b) \ 14 | make_instr_impl_1op_cc(j, i, suffix, g) \ 15 | make_instr_impl_1op_cc(j, i, suffix, l) \ 16 | make_instr_impl_1op_cc(j, i, suffix, o) \ 17 | make_instr_impl_1op_cc(j, i, suffix, p) \ 18 | make_instr_impl_1op_cc(j, i, suffix, s) \ 19 | make_instr_impl_1op_cc(j, i, suffix, ae) \ 20 | make_instr_impl_1op_cc(j, i, suffix, ge) \ 21 | make_instr_impl_1op_cc(j, i, suffix, le) \ 22 | make_instr_impl_1op_cc(j, i, suffix, na) \ 23 | make_instr_impl_1op_cc(j, i, suffix, ne) \ 24 | make_instr_impl_1op_cc(j, i, suffix, no) \ 25 | make_instr_impl_1op_cc(j, i, suffix, np) \ 26 | make_instr_impl_1op_cc(j, i, suffix, ns) \ 27 | 28 | jcc_helper(near) 29 | jcc_helper(short_) 30 | make_instr_impl_1op_cc(j, i, short_, ecxz) 31 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/jmp.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(jmp_near) { 4 | OPERAND rel; 5 | rel.type = OPR_IMM; 6 | rel.sreg = SREG_CS; 7 | rel.data_size = data_size; 8 | rel.addr = eip + 1; 9 | operand_read(&rel); 10 | print_asm_1("jmp", "", 2, &rel); 11 | cpu.eip += sign_ext(rel.val, data_size); 12 | return 1 + data_size / 8; 13 | } 14 | 15 | make_instr_func(jmp_near_indirect) { 16 | int len = 1; 17 | OPERAND rel; 18 | rel.data_size = data_size; 19 | len += modrm_rm(eip + 1, &rel); 20 | operand_read(&rel); 21 | print_asm_1("jmp", "", len, &rel); 22 | if(data_size == 16) 23 | cpu.eip = rel.val & 0xFFFF; 24 | else 25 | cpu.eip = rel.val; 26 | return 0; 27 | } 28 | 29 | make_instr_func(jmp_short) { 30 | OPERAND rel; 31 | rel.type = OPR_IMM; 32 | rel.sreg = SREG_CS; 33 | rel.data_size = 8; 34 | rel.addr = eip + 1; 35 | operand_read(&rel); 36 | print_asm_1("jmp", "", 2, &rel); 37 | cpu.eip += sign_ext(rel.val, rel.data_size); 38 | return 2; 39 | } 40 | 41 | make_instr_func(jmp_far_imm) { 42 | OPERAND rel; 43 | rel.type = OPR_IMM; 44 | rel.sreg = SREG_CS; 45 | rel.data_size = 32; 46 | rel.addr = eip + 1; 47 | operand_read(&rel); 48 | print_asm_1("jmp", "", 7, &rel); 49 | if(data_size == 16) 50 | cpu.eip = rel.val & 0xFFFF; 51 | else 52 | cpu.eip = rel.val; 53 | cpu.cs.val = instr_fetch(eip + 5, 2); 54 | load_sreg(1); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/lea.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | make_instr_func(lea) { 3 | int len = 1; 4 | opr_src.data_size = opr_dest.data_size = data_size; 5 | len += modrm_r_rm(eip + 1, &opr_dest, &opr_src); 6 | print_asm_2("lea", opr_dest.data_size == 8 ? "b" : (opr_dest.data_size == 16 ? "w" : "l"), len, &opr_src, &opr_dest); 7 | opr_dest.val = opr_src.addr; 8 | operand_write(&opr_dest); 9 | return len; 10 | } 11 | 12 | 13 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/leave.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(leave) { 4 | cpu.esp=cpu.ebp; 5 | OPERAND mem; 6 | mem.data_size=data_size; 7 | mem.type=OPR_MEM; 8 | mem.sreg=SREG_DS; 9 | mem.addr=cpu.esp; 10 | operand_read(&mem); 11 | cpu.ebp=mem.val; 12 | cpu.esp+=data_size/8; 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/lgdt.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(lgdt) { 4 | int len=1; 5 | OPERAND rel; 6 | len+=modrm_rm(eip+1,&rel); 7 | //printf("addr:%x",rel.addr); 8 | rel.data_size=16; 9 | operand_read(&rel); 10 | cpu.gdtr.limit=rel.val; 11 | //printf("limit:%x\n",rel.val); 12 | rel.addr+=2; 13 | rel.data_size=32; 14 | operand_read(&rel); 15 | //printf("base:%x\n",rel.val); 16 | cpu.gdtr.base=rel.val; 17 | //printf("len:%x\n",len); 18 | print_asm_1("lgdt", "", len, &rel); 19 | return len; 20 | } 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/lidt.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(lidt) { 4 | int len=1; 5 | OPERAND rel; 6 | len+=modrm_rm(eip+1,&rel); 7 | rel.data_size=16; 8 | operand_read(&rel); 9 | cpu.idtr.limit=rel.val; 10 | rel.addr+=2; 11 | rel.data_size=32; 12 | operand_read(&rel); 13 | cpu.idtr.base=rel.val; 14 | print_asm_1("lidt", "", len, &rel); 15 | return len; 16 | } 17 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/movs.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(movs_v) { 4 | OPERAND msi, mdi; 5 | msi.type = mdi.type = OPR_MEM; 6 | msi.sreg = mdi.sreg = SREG_DS; 7 | msi.data_size = mdi.data_size = data_size; 8 | msi.addr = cpu.gpr[REG_ESI]._32; 9 | mdi.addr = cpu.gpr[REG_EDI]._32; 10 | operand_read(&msi); 11 | mdi.val = msi.val; 12 | operand_write(&mdi); 13 | int incDec = 0; 14 | incDec = cpu.eflags.DF == 0 ? data_size / 8 : -data_size / 8; 15 | cpu.gpr[REG_ESI]._32 += incDec; 16 | cpu.gpr[REG_EDI]._32 += incDec; 17 | print_asm_0("movs (%%edi), (%%esi)", "", 1); 18 | return 1; 19 | } 20 | 21 | make_instr_func(movs_b) { 22 | OPERAND msi, mdi; 23 | msi.type = mdi.type = OPR_MEM; 24 | msi.sreg = mdi.sreg = SREG_DS; 25 | msi.data_size = mdi.data_size = 8; 26 | msi.addr = cpu.gpr[REG_ESI]._32; 27 | mdi.addr = cpu.gpr[REG_EDI]._32; 28 | operand_read(&msi); 29 | mdi.val = msi.val; 30 | operand_write(&mdi); 31 | int incDec = 0; 32 | incDec = cpu.eflags.DF == 0 ? 1 : -1; 33 | cpu.gpr[REG_ESI]._32 += incDec; 34 | cpu.gpr[REG_EDI]._32 += incDec; 35 | print_asm_0("movs (%%edi), (%%esi)", "", 1); 36 | return 1; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/neg.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | operand_read(&opr_src); 5 | if(opr_src.val==0) 6 | cpu.eflags.CF=0; 7 | else 8 | cpu.eflags.CF=1; 9 | opr_src.val=-opr_src.val; 10 | operand_write(&opr_src); 11 | } 12 | 13 | make_instr_impl_1op(neg, rm, b) 14 | make_instr_impl_1op(neg, rm, v) 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/nemu_trap.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | #include 3 | #include 4 | 5 | make_instr_func(nemu_trap) { 6 | int i = 0; 7 | switch(cpu.eax) { 8 | case 4: 9 | printf("\e[0;31mnemu trap output: \e[0m"); 10 | for(i = 0; i < cpu.edx ; i++) { 11 | putchar((char) vaddr_read(cpu.ecx + i, SREG_DS, 1)); 12 | } 13 | break; 14 | case 110: 15 | score_trap(); 16 | break; 17 | default: 18 | printf("nemu: HIT %s TRAP at eip = 0x%08x\n", (cpu.eax == 0 ? "\e[0;32mGOOD\e[0m" : "\e[0;31mBAD\e[0m"), eip); 19 | if(get_ref()) { 20 | printf("\e[0;31mYou have used reference implementation, DO NOT submit this version.\e[0m\n"); 21 | } 22 | nemu_state = NEMU_STOP; 23 | score_trap(); 24 | break; 25 | } 26 | return 1; 27 | } 28 | 29 | make_instr_func(break_point) { 30 | printf("hit breakpoint at eip = 0x%08x\n", cpu.eip); 31 | nemu_state = NEMU_BREAK; 32 | return 1; 33 | } 34 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/nop.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(nop) { 4 | print_asm_0("nop", "", 1); 5 | return 1; 6 | } 7 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/not.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | operand_read(&opr_src); 5 | opr_src.val = ~opr_src.val; 6 | operand_write(&opr_src); 7 | } 8 | 9 | make_instr_impl_1op(not, rm, v) 10 | make_instr_impl_1op(not, rm, b) 11 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/opcode_2_byte.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(opcode_2_byte) { 4 | int len = 1; 5 | uint8_t op = instr_fetch(eip + 1, 1); 6 | #ifdef NEMU_REF_INSTR 7 | len += __ref_opcode_2_byte_entry[op](eip + 1, op); 8 | #else 9 | len += opcode_2_byte_entry[op](eip + 1, op); 10 | #endif 11 | return len; 12 | } 13 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/or.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_or(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(or, r, rm, b) 13 | make_instr_impl_2op(or, r, rm, v) 14 | make_instr_impl_2op(or, rm, r, b) 15 | make_instr_impl_2op(or, rm, r, v) 16 | make_instr_impl_2op(or, i, a, b) 17 | make_instr_impl_2op(or, i, a, v) 18 | make_instr_impl_2op(or, i, rm, b) 19 | make_instr_impl_2op(or, i, rm, v) 20 | make_instr_impl_2op(or, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/out.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | #include "device/port_io.h" 3 | 4 | make_instr_func(out_b) { 5 | print_asm_0("out", "b", 1); 6 | pio_write(cpu.edx, 1, cpu.eax); 7 | return 1; 8 | } 9 | 10 | make_instr_func(out_v) { 11 | print_asm_0("out", (data_size == 16)?"w":"l", 1); 12 | pio_write(cpu.edx, data_size/8, cpu.eax); 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/pop.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op() { 4 | opr_dest.type=OPR_MEM; 5 | opr_dest.sreg=SREG_DS; 6 | opr_dest.addr=cpu.esp; 7 | operand_read(&opr_dest); 8 | opr_src.val=opr_dest.val; 9 | operand_write(&opr_src); 10 | cpu.esp+=32/8; 11 | } 12 | 13 | make_instr_impl_1op(pop, r, v) 14 | make_instr_impl_1op(pop, rm, v) 15 | make_instr_impl_1op(pop, i, b) 16 | make_instr_impl_1op(pop, i, v) 17 | 18 | make_instr_func(popa) { 19 | print_asm_0("popa", "", 1); 20 | opr_src.data_size=32; 21 | opr_src.type=OPR_MEM; 22 | opr_src.sreg=SREG_DS; 23 | 24 | opr_src.addr=cpu.esp; 25 | operand_read(&opr_src); 26 | cpu.edi=opr_src.val; 27 | cpu.esp+=32/8; 28 | 29 | opr_src.addr=cpu.esp; 30 | operand_read(&opr_src); 31 | cpu.esi=opr_src.val; 32 | cpu.esp+=32/8; 33 | 34 | opr_src.addr=cpu.esp; 35 | operand_read(&opr_src); 36 | cpu.ebp=opr_src.val; 37 | cpu.esp+=32/8; 38 | 39 | cpu.esp+=32/8; 40 | 41 | opr_src.addr=cpu.esp; 42 | operand_read(&opr_src); 43 | cpu.ebx=opr_src.val; 44 | cpu.esp+=32/8; 45 | 46 | opr_src.addr=cpu.esp; 47 | operand_read(&opr_src); 48 | cpu.edx=opr_src.val; 49 | cpu.esp+=32/8; 50 | 51 | opr_src.addr=cpu.esp; 52 | operand_read(&opr_src); 53 | cpu.ecx=opr_src.val; 54 | cpu.esp+=32/8; 55 | 56 | opr_src.addr=cpu.esp; 57 | operand_read(&opr_src); 58 | cpu.eax=opr_src.val; 59 | cpu.esp+=32/8; 60 | 61 | return 1; 62 | } 63 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/rep_repe.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(rep_repe) { 4 | int len = 1; 5 | uint8_t op = instr_fetch(eip + 1, 1); 6 | print_asm_0("rep", "", len + 1); 7 | if(op == 0xc3) { 8 | // reference http://repzret.org/p/repzret/ 9 | opcode_entry[op](eip + 1, op); 10 | return 0; 11 | } 12 | while(cpu.gpr[REG_ECX]._32 != 0) { 13 | opcode_entry[op](eip + 1, op); 14 | cpu.gpr[REG_ECX]._32 --; 15 | /**/ 16 | if((op == 0xA6 || op == 0xA7 || op == 0xAE || op == 0xAF) && cpu.eflags.ZF == 1) { 17 | break; 18 | } 19 | } 20 | return len + 1; 21 | } 22 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/ret.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(ret_near) { 4 | print_asm_0("ret", "", 1); 5 | OPERAND mem; 6 | mem.data_size=data_size; 7 | mem.type=OPR_MEM; 8 | mem.sreg=SREG_DS; 9 | mem.addr=cpu.esp; 10 | operand_read(&mem); 11 | cpu.eip=mem.val; 12 | cpu.esp+=data_size/8; 13 | return 0; 14 | } 15 | 16 | make_instr_func(ret_near_imm16) { 17 | print_asm_0("ret", "", 3); 18 | OPERAND mem; 19 | mem.data_size=data_size; 20 | mem.type=OPR_MEM; 21 | mem.sreg=SREG_DS; 22 | mem.addr=cpu.esp; 23 | operand_read(&mem); 24 | cpu.eip=mem.val; 25 | int offset=sign_ext(instr_fetch(eip+1,2),16); 26 | cpu.esp+=data_size/8+offset; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/sar.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_dest.val = alu_sar(opr_src.val, opr_dest.val, opr_dest.data_size); 7 | operand_write(&opr_dest); 8 | } 9 | 10 | make_instr_impl_2op(sar, i, rm, b) 11 | make_instr_impl_2op(sar, i, rm, bv) 12 | make_instr_impl_2op(sar, c, rm, b) 13 | make_instr_impl_2op(sar, c, rm, bv) 14 | 15 | static void instr_execute_1op() { 16 | operand_read(&opr_src); 17 | opr_src.val = alu_sar(1, opr_src.val, opr_src.data_size); 18 | operand_write(&opr_src); 19 | } 20 | 21 | make_instr_impl_1op(sar, rm, b) 22 | make_instr_impl_1op(sar, rm, v) 23 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/sbb.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_sbb(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(sbb, r, rm, b) 13 | make_instr_impl_2op(sbb, r, rm, v) 14 | make_instr_impl_2op(sbb, rm, r, b) 15 | make_instr_impl_2op(sbb, rm, r, v) 16 | make_instr_impl_2op(sbb, i, a, b) 17 | make_instr_impl_2op(sbb, i, a, v) 18 | make_instr_impl_2op(sbb, i, rm, b) 19 | make_instr_impl_2op(sbb, i, rm, v) 20 | make_instr_impl_2op(sbb, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/setcc.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_1op_cc_pass() { 4 | opr_src.val = 1; 5 | operand_write(&opr_src); 6 | } 7 | 8 | static void instr_execute_1op_cc_fail() { 9 | opr_src.val = 0; 10 | operand_write(&opr_src); 11 | } 12 | 13 | make_instr_impl_1op_cc(set, rm, b, ne) 14 | make_instr_impl_1op_cc(set, rm, b, a) 15 | make_instr_impl_1op_cc(set, rm, b, ae) 16 | make_instr_impl_1op_cc(set, rm, b, be) 17 | make_instr_impl_1op_cc(set, rm, b, c) 18 | make_instr_impl_1op_cc(set, rm, b, e) 19 | make_instr_impl_1op_cc(set, rm, b, g) 20 | make_instr_impl_1op_cc(set, rm, b, ge) 21 | make_instr_impl_1op_cc(set, rm, b, l) 22 | make_instr_impl_1op_cc(set, rm, b, le) 23 | make_instr_impl_1op_cc(set, rm, b, no) 24 | make_instr_impl_1op_cc(set, rm, b, np) 25 | make_instr_impl_1op_cc(set, rm, b, ns) 26 | make_instr_impl_1op_cc(set, rm, b, o) 27 | make_instr_impl_1op_cc(set, rm, b, p) 28 | make_instr_impl_1op_cc(set, rm, b, s) 29 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/shl.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_dest.val = alu_shl(opr_src.val, opr_dest.val, opr_dest.data_size); 7 | operand_write(&opr_dest); 8 | } 9 | 10 | make_instr_impl_2op(shl, i, rm, b) 11 | make_instr_impl_2op(shl, i, rm, bv) 12 | make_instr_impl_2op(shl, c, rm, b) 13 | make_instr_impl_2op(shl, c, rm, bv) 14 | 15 | static void instr_execute_1op() { 16 | operand_read(&opr_src); 17 | opr_src.val = alu_shl(1, opr_src.val, opr_src.data_size); 18 | operand_write(&opr_src); 19 | } 20 | 21 | make_instr_impl_1op(shl, rm, b) 22 | make_instr_impl_1op(shl, rm, v) 23 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/shr.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_dest.val = alu_shr(opr_src.val, opr_dest.val, opr_dest.data_size); 7 | operand_write(&opr_dest); 8 | } 9 | 10 | make_instr_impl_2op(shr, i, rm, b) 11 | make_instr_impl_2op(shr, i, rm, bv) 12 | make_instr_impl_2op(shr, c, rm, b) 13 | make_instr_impl_2op(shr, c, rm, bv) 14 | 15 | static void instr_execute_1op() { 16 | operand_read(&opr_src); 17 | opr_src.val = alu_shr(1, opr_src.val, opr_src.data_size); 18 | operand_write(&opr_src); 19 | } 20 | 21 | make_instr_impl_1op(shr, rm, b) 22 | make_instr_impl_1op(shr, rm, v) 23 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/sti.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(sti) { 4 | cpu.eflags.IF=1; 5 | print_asm_0("sti", "", 1); 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/stos.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | make_instr_func(stos_b) { 4 | OPERAND al, mdi; 5 | al.type = OPR_REG; 6 | al.data_size = 8; 7 | al.addr = REG_AL; 8 | 9 | mdi.type = OPR_MEM; 10 | mdi.sreg = SREG_ES; 11 | mdi.data_size = 8; 12 | mdi.addr = cpu.gpr[REG_EDI]._32; 13 | 14 | operand_read(&al); 15 | mdi.val = al.val; 16 | int incDec = 0; 17 | incDec = cpu.eflags.DF == 0 ? 1 : -1; 18 | cpu.gpr[REG_EDI]._32 += incDec; 19 | operand_write(&mdi); 20 | print_asm_0("stos", "", 1); 21 | return 1; 22 | } 23 | 24 | make_instr_func(stos_v) { 25 | OPERAND al, mdi; 26 | al.type = OPR_REG; 27 | al.data_size = data_size; 28 | al.addr = REG_AX; 29 | 30 | mdi.type = OPR_MEM; 31 | mdi.sreg = SREG_ES; 32 | mdi.data_size = data_size; 33 | mdi.addr = cpu.gpr[REG_EDI]._32; 34 | 35 | operand_read(&al); 36 | mdi.val = al.val; 37 | int incDec = 0; 38 | incDec = cpu.eflags.DF == 0 ? data_size / 8 : -data_size / 8; 39 | cpu.gpr[REG_EDI]._32 += incDec; 40 | operand_write(&mdi); 41 | print_asm_0("stos", "", 1); 42 | return 1; 43 | } 44 | 45 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/sub.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_sub(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(sub, r, rm, b) 13 | make_instr_impl_2op(sub, r, rm, v) 14 | make_instr_impl_2op(sub, rm, r, b) 15 | make_instr_impl_2op(sub, rm, r, v) 16 | make_instr_impl_2op(sub, i, a, b) 17 | make_instr_impl_2op(sub, i, a, v) 18 | make_instr_impl_2op(sub, i, rm, b) 19 | make_instr_impl_2op(sub, i, rm, v) 20 | make_instr_impl_2op(sub, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/test.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | alu_and(opr_src.val,opr_dest.val,data_size); 7 | } 8 | 9 | make_instr_impl_2op(test, r, rm, b) 10 | make_instr_impl_2op(test, r, rm, v) 11 | make_instr_impl_2op(test, i, rm, b) 12 | make_instr_impl_2op(test, i, rm, v) 13 | make_instr_impl_2op(test, i, a, b) 14 | make_instr_impl_2op(test, i, a, v) 15 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/instr/xor.c: -------------------------------------------------------------------------------- 1 | #include "cpu/instr.h" 2 | 3 | static void instr_execute_2op() { 4 | operand_read(&opr_src); 5 | operand_read(&opr_dest); 6 | opr_src.val = sign_ext(opr_src.val,opr_src.data_size); 7 | opr_dest.val = sign_ext(opr_dest.val,opr_dest.data_size); 8 | opr_dest.val = alu_xor(opr_src.val,opr_dest.val,data_size); 9 | operand_write(&opr_dest); 10 | } 11 | 12 | make_instr_impl_2op(xor, r, rm, b) 13 | make_instr_impl_2op(xor, r, rm, v) 14 | make_instr_impl_2op(xor, rm, r, b) 15 | make_instr_impl_2op(xor, rm, r, v) 16 | make_instr_impl_2op(xor, i, a, b) 17 | make_instr_impl_2op(xor, i, a, v) 18 | make_instr_impl_2op(xor, i, rm, b) 19 | make_instr_impl_2op(xor, i, rm, v) 20 | make_instr_impl_2op(xor, i, rm, bv) 21 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/cpu/intr.c: -------------------------------------------------------------------------------- 1 | #include "cpu/intr.h" 2 | #include "cpu/instr.h" 3 | #include "memory/memory.h" 4 | 5 | 6 | void raise_intr(uint8_t intr_no) { 7 | #ifdef IA32_INTR 8 | uint32_t addr=(uint32_t)hw_mem+page_translate(segment_translate(cpu.idtr.base+8*intr_no,SREG_DS)); 9 | GateDesc* gatedesc=(void*)addr; 10 | cpu.esp-=4; 11 | vaddr_write(cpu.esp,SREG_DS,4,cpu.eflags.val); 12 | cpu.esp-=2; 13 | vaddr_write(cpu.esp,SREG_DS,2,cpu.cs.val); 14 | cpu.esp-=4; 15 | vaddr_write(cpu.esp,SREG_DS,4,cpu.eip); 16 | if(gatedesc->type==0xe) 17 | cpu.eflags.IF=1; 18 | else if(gatedesc->type==0xf) 19 | cpu.eflags.IF=0; 20 | cpu.eip=(gatedesc->offset_31_16<<16)+gatedesc->offset_15_0; 21 | #endif 22 | } 23 | 24 | void raise_sw_intr(uint8_t intr_no) { 25 | // return address is the next instruction 26 | cpu.eip += 2; 27 | raise_intr(intr_no); 28 | } 29 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/device/dev/serial.c: -------------------------------------------------------------------------------- 1 | #include "nemu.h" 2 | #include "device/serial.h" 3 | 4 | 5 | make_pio_handler(handler_serial) { 6 | if(is_write) { 7 | assert(len == 1); 8 | #ifdef HAS_DEVICE_SERIAL 9 | if(port == SERIAL_PORT) { // offset == 0 10 | char c = (char)read_io_port(port, 1); 11 | putc(c, stdout); 12 | fflush(stdout); 13 | } 14 | #endif 15 | } 16 | } 17 | 18 | void init_serial() { 19 | // serial port always free 20 | write_io_port(SERIAL_PORT + 5, 1, 0x20); 21 | } 22 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/device/dev/timer.c: -------------------------------------------------------------------------------- 1 | #include "nemu.h" 2 | #include "device/timer.h" 3 | #include "device/i8259_pic.h" 4 | 5 | #include 6 | 7 | static bool timer_active = false; 8 | 9 | void timer_intr() { 10 | if(nemu_state == NEMU_RUN) { 11 | i8259_raise_intr(TIMER_IRQ); // multi-thread safe 12 | } 13 | } 14 | 15 | static int TIMER_Thread(void* hz) { 16 | int delay = 1000 / *(int*)hz; 17 | while(timer_active) { 18 | timer_intr(); 19 | SDL_Delay(delay); 20 | } 21 | return 0; 22 | } 23 | 24 | // start a timer with hz Hz 25 | void timer_start(int hz) { 26 | timer_active = true; 27 | SDL_CreateThread(TIMER_Thread, (void*) &hz); 28 | } 29 | 30 | void timer_stop() { 31 | timer_active = false; 32 | } 33 | 34 | make_pio_handler(handler_timer) {} 35 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/device/i8259_pic.c: -------------------------------------------------------------------------------- 1 | #include "nemu.h" 2 | #include "cpu/cpu.h" 3 | #include "device/i8259_pic.h" 4 | 5 | #include 6 | 7 | static uint8_t i8259_intr_no = I8259_NO_INTR; 8 | 9 | static SDL_mutex* i8259_mutex; 10 | 11 | uint8_t i8259_query_intr_no() { 12 | return i8259_intr_no; 13 | } 14 | 15 | void i8259_raise_intr(uint8_t irq_no) { 16 | // this is the only place i8259_intr_no and cpu.intr is set 17 | while(SDL_LockMutex(i8259_mutex) != 0) { 18 | if(nemu_state == NEMU_STOP) return; 19 | SDL_Delay(1); 20 | } 21 | // the i8259_mutex is to protect the i8259_intr_no and cpu.intr 22 | if(i8259_intr_no == I8259_NO_INTR || 23 | (i8259_intr_no != I8259_NO_INTR && irq_no > i8259_intr_no - IRQ_BASE)) { 24 | // priority 25 | i8259_intr_no = irq_no + IRQ_BASE; 26 | //printf("i8259 raise %d, %d\n", irq_no, i8259_intr_no); 27 | } 28 | #ifdef IA32_INTR 29 | cpu.intr = 1; 30 | #endif 31 | SDL_UnlockMutex(i8259_mutex); // unlock 32 | } 33 | 34 | void i8259_ack_intr() { 35 | while(SDL_LockMutex(i8259_mutex) != 0) { 36 | if(nemu_state == NEMU_STOP) return; 37 | SDL_Delay(1); 38 | } 39 | i8259_intr_no = I8259_NO_INTR; 40 | #ifdef IA32_INTR 41 | cpu.intr = 0; 42 | #endif 43 | SDL_UnlockMutex(i8259_mutex); // unlock 44 | } 45 | 46 | void i8259_init() { 47 | i8259_mutex = SDL_CreateMutex(); 48 | i8259_intr_no = I8259_NO_INTR; 49 | assert(i8259_mutex); 50 | } 51 | 52 | void i8259_destroy() { 53 | SDL_DestroyMutex(i8259_mutex); 54 | } 55 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/memory/mmu/page.c: -------------------------------------------------------------------------------- 1 | #include "cpu/cpu.h" 2 | #include "memory/memory.h" 3 | 4 | // translate from linear address to physical address 5 | paddr_t page_translate(laddr_t laddr) { 6 | #ifndef TLB_ENABLED 7 | uint32_t dir = (laddr >> 22) & 0x3ff; 8 | uint32_t page = (laddr >> 12) & 0x3ff; 9 | uint32_t offset = laddr & 0xfff; 10 | PDE *pdir = (PDE *)(hw_mem + (cpu.cr3.pdtr << 12) + (dir << 2)); 11 | PTE *ptable = (PTE *)(hw_mem + (pdir->page_frame << 12) + (page << 2)); 12 | assert(pdir->present==1); 13 | assert(ptable->present==1); 14 | return (ptable->page_frame << 12) + offset; 15 | #else 16 | return tlb_read(laddr) | (laddr & PAGE_MASK);; 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /pa2018_fall/nemu/src/memory/mmu/segment.c: -------------------------------------------------------------------------------- 1 | #include "cpu/cpu.h" 2 | #include "memory/memory.h" 3 | 4 | // return the linear address from the virtual address and segment selector 5 | uint32_t segment_translate(uint32_t offset, uint8_t sreg) { 6 | /* TODO: perform segment translation from virtual address to linear address 7 | * by reading the invisible part of the segment register 'sreg' 8 | */ 9 | uint32_t base=cpu.cache[sreg].base; 10 | return base+offset; 11 | } 12 | 13 | // load the invisible part of a segment register 14 | void load_sreg(uint8_t sreg) { 15 | /* TODO: load the invisibile part of the segment register 'sreg' by reading the GDT. 16 | * The visible part of 'sreg' should be assigned by mov or ljmp already. 17 | */ 18 | uint32_t addr=(uint32_t)hw_mem+cpu.gdtr.base+8*cpu.segReg[sreg].index; 19 | SegDesc* segdesc=(void*)addr; 20 | uint32_t base=(segdesc->base_31_24<<24)+(segdesc->base_23_16<<16)+segdesc->base_15_0; 21 | uint32_t limit=(segdesc->limit_19_16<<16)+segdesc->limit_15_0; 22 | uint32_t privilege_level=segdesc->privilege_level; 23 | assert(base==0); 24 | assert(limit==0xFFFFF); 25 | assert(segdesc->granularity==1); 26 | cpu.cache[sreg].base=base; 27 | cpu.cache[sreg].limit=limit; 28 | cpu.cache[sreg].privilege_level=privilege_level; 29 | } 30 | -------------------------------------------------------------------------------- /pa2018_fall/scripts/emotion_dialog.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd ~ 3 | if [ ! -d "/.pa-nemu/" ]; then 4 | mkdir .pa-nemu/ 5 | fi 6 | if [ ! -d "/.pa-nemu/emotion/" ]; then 7 | mkdir .pa-nemu/emotion/ 8 | fi 9 | 10 | cd .pa-nemu/emotion/ 11 | 12 | T=$[$(date +%s%N)/1000000] 13 | time=$(date "+%Y-%m-%d-%H:%M:%S") 14 | 15 | dialog --nocancel --title "你当前状态和情绪如何?" --menu "\n鼠标或方向键选择,点击OK或回车确定, 请认真做答, 若不想做可以选择跳过, 谢谢参与!" 20 30 10 1 "跳过" 2 "能应对挑战 比较投入" 3 "遇到点问题 有些困惑" 4 "问题卡住了 感到沮丧" 5 "学不下去了 觉得无趣" 2>_m.txt 16 | 17 | M=$(cat _m.txt) 18 | 19 | #一小时内免打扰 20 | if [ $M = "1" ]; then 21 | dialog --nocancel --menu "是否希望一小时内免打扰?" 15 20 10 1 "YES" 2 "NO" 2>_m.txt 22 | D=$(cat _m.txt) 23 | echo $D" "$T > Disturb.txt 24 | 25 | else 26 | #dialog --nocancel --menu "程度如何?" 20 30 10 1 "1(一点点)" 2 "2" 3 "3" 4 "4" 5 "5(非常)" 2>_m.txt 27 | #N=$(cat _m.txt) 28 | 29 | case $M in 30 | "2") 31 | M="flow" 32 | ;; 33 | "3") 34 | M="confused" 35 | ;; 36 | "4") 37 | M="furstrated" 38 | ;; 39 | "5") 40 | M="bored" 41 | ;; 42 | esac 43 | 44 | dialog --nocancel --default-item "4" --menu "就过去15分钟所做的PA内容,感觉挑战难度有多高?\n鼠标或方向键选择, 点击OK或回车确定, 请认真做答, 谢谢参与!" 20 30 10 1 "1(很低)" 2 "2" 3 "3" 4 "4(中等)" 5 "5" 6 "6" 7 "7(很高)" 2>_m.txt 45 | CN=$(cat _m.txt) 46 | 47 | dialog --nocancel --default-item "4" --menu "就过去15分钟所做的PA内容,感觉自己应对挑战能力有多强?\n鼠标或方向键选择, 点击OK或回车确定, 请认真做答, 谢谢参与!" 20 30 10 1 "1(很低)" 2 "2" 3 "3" 4 "4(中等)" 5 "5" 6 "6" 7 "7(很高)" 2>_m.txt 48 | SN=$(cat _m.txt) 49 | 50 | #echo $T" "${M}" "${N}" "$time >> ${T}_emotion.txt 51 | echo $T" "${M}" "${CN}" "${SN}" "$time >> ${T}_emotion.txt 52 | echo $T > DoNotFreq.txt 53 | fi 54 | 55 | rm -f _m.txt 56 | -------------------------------------------------------------------------------- /pa2018_fall/scripts/gitmonitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #User,StudentID,PA_path,Server_IP 4 | 5 | 6 | 7 | time_ID=$(date "+%Y-%m-%d") 8 | Log_path=/home/$User/.pa-nemu/tracking/$time_ID"_$Student_ID".log 9 | Track_path=/home/$User/.pa-nemu/tracking/ 10 | CommitID=0 11 | 12 | function gitmonitor(){ 13 | if [ ! -d $Track_path ]; then 14 | mkdir $Track_path 15 | fi 16 | #echo "111" >>/home/$User/a.txt 17 | git add . -A 18 | check_results=`git commit -m "monitor test" --author="monitor"` 19 | res=`echo $check_results | grep -E 'nothing to commit, working tree clean'` 20 | if [ ! -z "$res" ] 21 | then 22 | time=$(date "+%Y-%m-%d %H:%M:%S") 23 | else 24 | current=`date "+%Y-%m-%d %H:%M:%S"` 25 | timeStamp=`date -d "$current" +%s` 26 | #将current转换为时间戳,精确到毫秒 27 | currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) 28 | git commit -m "monitor test" --amend --author='monitor' 29 | CommitID=`git rev-parse --short HEAD` 30 | echo "#----------------------------------------------------# " >> $Log_path 31 | echo $currentTimeStamp >> $Log_path 32 | git show $CommitID |tee $Log_path -a 33 | echo "#----------------------------------------------------# " >> $Log_path 34 | fi 35 | } 36 | if [ -d $PA_PATH ]; then 37 | cd $PA_PATH 38 | gitmonitor 39 | /home/$User/.pa-nemu/scripts/upload_tracking $Student_ID $Server_IP 40 | fi 41 | -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/32_keyboard_inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/32_keyboard_inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/32_keyboard_inline.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/32_keyboard_inline.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/add -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/add-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/add-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/add-longlong.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/add-longlong.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/add.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/add.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/bit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/bit -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/bit.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/bit.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/bubble-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/bubble-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/bubble-sort.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/bubble-sort.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/echo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/echo -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/echo.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/echo.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/fact: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/fact -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/fact.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/fact.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/fib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/fib -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/fib.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/fib.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/gotbaha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/gotbaha -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/gotbaha.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/gotbaha.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/hello-inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/hello-inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/hello-inline.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/hello-inline.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/hello-str: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/hello-str -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/hello-str.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/hello-str.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/if-else: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/if-else -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/if-else.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/if-else.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/leap-year: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/leap-year -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/leap-year.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/leap-year.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/matrix-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/matrix-mul -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/matrix-mul-small: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/matrix-mul-small -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/matrix-mul-small.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/matrix-mul-small.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/matrix-mul.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/matrix-mul.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/max: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/max -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/max.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/max.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/min3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/min3 -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/min3.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/min3.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-c -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-c.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-c.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-cmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-cmp -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-cmp.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-cmp.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-jcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-jcc -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov-jcc.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov-jcc.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mov.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mov.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/movsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/movsx -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/movsx.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/movsx.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mul-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mul-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/mul-longlong.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/mul-longlong.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/pascal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/pascal -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/pascal.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/pascal.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/prime -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/prime.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/prime.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/quick-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/quick-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/quick-sort.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/quick-sort.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/select-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/select-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/select-sort.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/select-sort.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/shuixianhua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/shuixianhua -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/shuixianhua.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/shuixianhua.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/string -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/string.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/string.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/struct -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/struct.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/struct.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/sub-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/sub-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/sub-longlong.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/sub-longlong.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/sum -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/sum.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/sum.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/test-float: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/test-float -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/test-float.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/test-float.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/wanshu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/wanshu -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/30000/wanshu.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/30000/wanshu.img -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/32_keyboard_inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/32_keyboard_inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/add -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/add-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/add-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/bit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/bit -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/bubble-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/bubble-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/echo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/echo -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/fact: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/fact -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/fib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/fib -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/gotbaha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/gotbaha -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/hello-inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/hello-inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/hello-str: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/hello-str -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/if-else: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/if-else -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/leap-year: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/leap-year -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/matrix-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/matrix-mul -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/matrix-mul-small: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/matrix-mul-small -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/max: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/max -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/min3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/min3 -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/mov -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/mov-c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/mov-c -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/mov-cmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/mov-cmp -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/mov-jcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/mov-jcc -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/movsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/movsx -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/mul-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/mul-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/pascal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/pascal -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/prime -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/quick-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/quick-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/select-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/select-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/shuixianhua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/shuixianhua -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/string -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/struct -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/sub-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/sub-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/sum -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/test-float: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/test-float -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/60000/wanshu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/60000/wanshu -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/game: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/game -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/32_keyboard_inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/32_keyboard_inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/add -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/add-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/add-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/bit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/bit -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/bubble-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/bubble-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/echo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/echo -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/fact: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/fact -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/fib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/fib -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/gotbaha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/gotbaha -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/hello-inline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/hello-inline -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/hello-str: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/hello-str -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/if-else: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/if-else -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/leap-year: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/leap-year -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/matrix-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/matrix-mul -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/matrix-mul-small: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/matrix-mul-small -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/max: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/max -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/min3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/min3 -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/mov: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/mov -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/mov-c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/mov-c -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/mov-cmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/mov-cmp -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/mov-jcc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/mov-jcc -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/movsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/movsx -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/mul-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/mul-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/pascal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/pascal -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/prime -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/quick-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/quick-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/select-sort: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/select-sort -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/shuixianhua: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/shuixianhua -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/string -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/struct -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/sub-longlong: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/sub-longlong -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/sum: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/sum -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/test-float: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/test-float -------------------------------------------------------------------------------- /pa2018_fall/scripts/score_testcases/page/wanshu: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/score_testcases/page/wanshu -------------------------------------------------------------------------------- /pa2018_fall/scripts/submit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/submit -------------------------------------------------------------------------------- /pa2018_fall/scripts/update: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/update -------------------------------------------------------------------------------- /pa2018_fall/scripts/upload_tracking: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GeeeekExplorer/NJU-ICS/269ab2beeed1d7fdff02cf15460f16552ec9a17f/pa2018_fall/scripts/upload_tracking -------------------------------------------------------------------------------- /pa2018_fall/testcase/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: testcase clean 2 | 3 | CC := gcc 4 | LD := ld 5 | CFLAGS := -ggdb3 -MMD -MP -Wall -m32 -march=i386 -fno-builtin -fno-stack-protector -I../include -I../libs/newlib/include 6 | 7 | #LDFLAGS := -m elf_i386 -e start -Ttext=0x30000 8 | #LDFLAGS := -m elf_i386 -e start -Ttext=0x60000 9 | LDFLAGS := -m elf_i386 -e start 10 | 11 | SFILES := $(shell find src/ -name "*.S") 12 | CFILES := $(shell find src/ -name "*.c") 13 | 14 | SOBJS := $(SFILES:.S=.o) 15 | COBJS := $(CFILES:.c=.o) 16 | 17 | SBINS := $(SFILES:.S=) 18 | CBINS := $(CFILES:.c=) 19 | 20 | testcase: start.o $(SOBJS) $(COBJS) $(SBINS) $(CBINS) Makefile 21 | 22 | %.o: %.c 23 | $(CC) $(CFLAGS) -c -o $@ $< 24 | 25 | %.o: %.S 26 | $(CC) $(CFLAGS) -c -o $@ $< 27 | 28 | %: %.o 29 | $(LD) $(LDFLAGS) -o $@ src/start.o $< ../libs/newlib/libc.a 30 | cp $@ $(addprefix bin/,$(notdir $@)) 31 | objcopy -S -O binary -B i386 $(addprefix bin/,$(notdir $@)) $(addprefix bin/,$(notdir $@)).img 32 | 33 | start.o: start.S 34 | $(CC) $(CFLAGS) -c -o src/start.o start.S 35 | 36 | 37 | clean: 38 | -rm -f $(SOBJS) $(SOBJS:.o=.d) src/start.o src/start.d 39 | -rm -f $(COBJS) $(COBJS:.o=.d) 40 | -rm -f $(SBINS) 41 | -rm -f $(CBINS) 42 | -rm -f -r bin/ 43 | mkdir bin/ 44 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/32_keyboard_inline.c: -------------------------------------------------------------------------------- 1 | const char str[] = "Keyboard Testing!\n"; 2 | 3 | int main() { 4 | while(1) { 5 | asm volatile ( "movl $4, %eax;" // system call ID, 4 = SYS_write 6 | "movl $1, %ebx;" // file descriptor, 1 = stdout 7 | "movl $str, %ecx;" // buffer address 8 | "movl $19, %edx;" // length 9 | "int $0x80;" 10 | "hlt;" ); // wait until an interrupt comes 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/add.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int test_data[] = {0, 1, 2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; 4 | int ans[] = {0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x1, 0x2, 0x3, 0x80000000, 0x80000001, 0x80000002, 0xffffffff, 0, 0x2, 0x3, 0x4, 0x80000001, 0x80000002, 0x80000003, 0, 0x1, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x80000000, 0x80000001, 0x80000002, 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000001, 0x80000002, 0x80000003, 0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0xfffffffe, 0xffffffff, 0, 0x7ffffffd, 0x7ffffffe, 0x7fffffff, 0xfffffffc, 0xfffffffd, 0xffffffff, 0, 0x1, 0x7ffffffe, 0x7fffffff, 0x80000000, 0xfffffffd, 0xfffffffe}; 5 | #define NR_DATA (sizeof(test_data) / sizeof(test_data[0])) 6 | 7 | int main() { 8 | int i, j, ans_idx = 0; 9 | for(i = 0; i < NR_DATA; i ++) { 10 | for(j = 0; j < NR_DATA; j ++) { 11 | //BREAK_POINT; 12 | nemu_assert((test_data[i] + test_data[j]) == ans[ans_idx ++]); 13 | } 14 | } 15 | 16 | nemu_assert(i == NR_DATA); 17 | nemu_assert(j == NR_DATA); 18 | 19 | HIT_GOOD_TRAP; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/bit.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | typedef unsigned char uint8_t; 4 | typedef char bool; 5 | 6 | bool getbit(void *buf, int offset){ 7 | int byte = offset >> 3; 8 | offset &= 7; 9 | uint8_t mask = 1 << offset; 10 | return (((uint8_t *)buf)[byte] & mask) != 0; 11 | } 12 | 13 | void setbit(void *buf, int offset, bool bit){ 14 | int byte = offset >> 3; 15 | offset &= 7; 16 | uint8_t mask = 1 << offset; 17 | 18 | uint8_t *p = buf + byte; 19 | *p = (bit == 0 ? (*p & ~mask) : (*p | mask)); 20 | // bit = bit == 0 ? 1 : 0; 21 | // nemu_assert(getbit(buf, offset) == bit); 22 | } 23 | 24 | int main() { 25 | uint8_t buf[2]; 26 | 27 | buf[0] = 0xaa; 28 | nemu_assert(getbit(buf, 0) == 0); 29 | nemu_assert(getbit(buf, 1) == 1); 30 | nemu_assert(getbit(buf, 2) == 0); 31 | nemu_assert(getbit(buf, 3) == 1); 32 | nemu_assert(getbit(buf, 4) == 0); 33 | nemu_assert(getbit(buf, 5) == 1); 34 | nemu_assert(getbit(buf, 6) == 0); 35 | nemu_assert(getbit(buf, 7) == 1); 36 | 37 | setbit(buf, 8, 1); 38 | setbit(buf, 9, 0); 39 | setbit(buf, 10, 1); 40 | setbit(buf, 11, 0); 41 | setbit(buf, 12, 1); 42 | setbit(buf, 13, 0); 43 | setbit(buf, 14, 1); 44 | setbit(buf, 15, 0); 45 | nemu_assert(buf[1] == 0x55); 46 | 47 | HIT_GOOD_TRAP; 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/bubble-sort.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 100 4 | 5 | int a[N] = {81, 37, 64, 23, 38, 65, 56, 15, 8, 33, 85, 39, 71, 12, 77, 6, 82, 89, 80, 35, 0, 59, 73, 4, 61, 30, 74, 69, 13, 42, 68, 63, 9, 29, 47, 36, 99, 25, 21, 14, 60, 3, 2, 18, 26, 83, 53, 5, 43, 67, 88, 70, 76, 92, 94, 48, 34, 49, 66, 95, 78, 62, 32, 52, 16, 72, 27, 28, 22, 40, 84, 91, 96, 57, 87, 51, 98, 1, 10, 11, 24, 20, 19, 31, 7, 97, 50, 86, 79, 17, 75, 55, 93, 44, 58, 54, 45, 41, 90, 46}; 6 | 7 | void bubble_sort() { 8 | int i, j, t; 9 | for(j = 0; j < N; j ++) { 10 | for(i = 0; i < N - 1 - j; i ++) { 11 | if(a[i] > a[i + 1]) { 12 | t = a[i]; 13 | a[i] = a[i + 1]; 14 | a[i + 1] = t; 15 | } 16 | } 17 | } 18 | } 19 | 20 | int main() { 21 | bubble_sort(); 22 | 23 | int i; 24 | for(i = 0; i < N; i ++) { 25 | nemu_assert(a[i] == i); 26 | } 27 | 28 | bubble_sort(); 29 | 30 | for(i = 0; i < N; i ++) { 31 | nemu_assert(a[i] == i); 32 | } 33 | 34 | HIT_GOOD_TRAP; 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/fact.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int f[15]; 4 | int ans[] = {1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600}; 5 | 6 | int fact(int n) { 7 | if(n == 0 || n == 1) return 1; 8 | else return fact(n - 1) * n; 9 | } 10 | 11 | int main() { 12 | int i; 13 | for(i = 0; i < 13; i ++) { 14 | f[i] = fact(i); 15 | nemu_assert(f[i] == ans[i]); 16 | } 17 | 18 | HIT_GOOD_TRAP; 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/fib.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int fib[40] = {1, 1}; 4 | int ans[] = {1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155}; 5 | 6 | int main() { 7 | int i; 8 | for(i = 2; i < 40; i ++) { 9 | fib[i] = fib[i - 1] + fib[i - 2]; 10 | nemu_assert(fib[i] == ans[i]); 11 | } 12 | 13 | HIT_GOOD_TRAP; 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/gotbaha.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int is_prime(int n) { 4 | if(n < 2) return 0; 5 | 6 | int i; 7 | for(i = 2; i < n; i ++) { 8 | if(n % i == 0) { 9 | return 0; 10 | } 11 | } 12 | 13 | return 1; 14 | } 15 | 16 | int gotbaha(int n) { 17 | int i; 18 | for(i = 2; i < n; i ++) { 19 | if(is_prime(i) && is_prime(n - i)) { 20 | return 1; 21 | } 22 | } 23 | 24 | return 0; 25 | } 26 | 27 | int main() { 28 | int n; 29 | for(n = 4; n <= 100; n += 2) { 30 | nemu_assert(gotbaha(n) == 1); 31 | } 32 | 33 | HIT_GOOD_TRAP; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/hello-inline.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | const char str[] = "Hello, world!\n"; 4 | 5 | int main() { 6 | asm volatile ( "movl $4, %eax;" // system call ID, 4 = SYS_write 7 | "movl $1, %ebx;" // file descriptor, 1 = stdout 8 | "movl $str, %ecx;" // buffer address 9 | "movl $14, %edx;" // length 10 | "int $0x80"); 11 | HIT_GOOD_TRAP; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/hello-str.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "trap.h" 4 | 5 | char buf[128]; 6 | 7 | /* This function is defined only to make the newlibc linkable. 8 | * Without it, errors will be reported during linking. 9 | * But the execution flow should not reach here. 10 | */ 11 | void *sbrk(int incr) { 12 | nemu_assert(0); 13 | return NULL; 14 | } 15 | 16 | int main() { 17 | sprintf(buf, "%s", "Hello world!\n"); 18 | nemu_assert(strcmp(buf, "Hello world!\n") == 0); 19 | 20 | sprintf(buf, "%d + %d = %d\n", 1, 1, 2); 21 | nemu_assert(strcmp(buf, "1 + 1 = 2\n") == 0); 22 | 23 | sprintf(buf, "%d + %d = %d\n", 2, 10, 12); 24 | nemu_assert(strcmp(buf, "2 + 10 = 12\n") == 0); 25 | 26 | HIT_GOOD_TRAP; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/if-else.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int if_else(int n) { 4 | int cost; 5 | if(n > 500) cost = 150; 6 | else if(n > 300) cost = 100; 7 | else if(n > 100) cost = 75; 8 | else if(n > 50) cost = 50; 9 | else cost = 0; 10 | 11 | return cost; 12 | } 13 | 14 | int test_data[] = {-1, 0, 49, 50, 51, 99, 100, 101, 299, 300, 301, 499, 500, 501}; 15 | int ans[] = {0, 0, 0, 0, 50, 50, 50, 75, 75, 75, 100, 100, 100, 150}; 16 | 17 | #define NR_DATA (sizeof(test_data) / sizeof(test_data[0])) 18 | 19 | int main() { 20 | int i, ans_idx = 0; 21 | for(i = 0; i < NR_DATA; i ++) { 22 | nemu_assert(if_else(test_data[i]) == ans[ans_idx ++]); 23 | } 24 | 25 | HIT_GOOD_TRAP; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/leap-year.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int is_leap_year(int n) { 4 | return (n % 4 == 0 && n % 100 != 0) || (n % 400 == 0); 5 | } 6 | 7 | int ans[] = {0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0}; 8 | 9 | int main() { 10 | int i; 11 | for(i = 0; i < 125; i ++) { 12 | nemu_assert(is_leap_year(i + 1890) == ans[i]); 13 | } 14 | 15 | HIT_GOOD_TRAP; 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/max.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int max(int x, int y) { 4 | int z; 5 | if(x > y) { z = x; } 6 | else { z = y; } 7 | return z; 8 | } 9 | 10 | int test_data[] = {0, 1, 2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; 11 | int ans[] = {0, 0x1, 0x2, 0x7fffffff, 0, 0, 0, 0, 0x1, 0x1, 0x2, 0x7fffffff, 0x1, 0x1, 0x1, 0x1, 0x2, 0x2, 0x2, 0x7fffffff, 0x2, 0x2, 0x2, 0x2, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0, 0x1, 0x2, 0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0, 0x1, 0x2, 0x7fffffff, 0x80000001, 0x80000001, 0xfffffffe, 0xffffffff, 0, 0x1, 0x2, 0x7fffffff, 0xfffffffe, 0xfffffffe, 0xfffffffe, 0xffffffff, 0, 0x1, 0x2, 0x7fffffff, 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff}; 12 | 13 | #define NR_DATA (sizeof(test_data) / sizeof(test_data[0])) 14 | 15 | int main() { 16 | int i, j, ans_idx = 0; 17 | for(i = 0; i < NR_DATA; i ++) { 18 | for(j = 0; j < NR_DATA; j ++) { 19 | nemu_assert(max(test_data[i], test_data[j]) == ans[ans_idx ++]); 20 | } 21 | } 22 | 23 | HIT_GOOD_TRAP; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/mov-c.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int A[10]; 4 | int b; 5 | 6 | int main() { 7 | A[0] = 0; 8 | A[1] = 1; 9 | A[2] = 2; 10 | A[3] = 3; 11 | A[4] = 4; 12 | 13 | b = A[3]; 14 | A[5] = b; 15 | 16 | nemu_assert(A[0] == 0); 17 | nemu_assert(A[1] == 1); 18 | nemu_assert(A[2] == 2); 19 | nemu_assert(A[3] == 3); 20 | nemu_assert(A[4] == 4); 21 | nemu_assert(b == 3); 22 | nemu_assert(A[5] == 3); 23 | 24 | HIT_GOOD_TRAP; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/mov-jcc.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int A[10]; 4 | int b; 5 | 6 | int main() { 7 | A[0] = 0; 8 | A[1] = 1; 9 | A[2] = 2; 10 | A[3] = 3; 11 | A[4] = 4; 12 | 13 | b = A[3]; 14 | A[5] = b; 15 | 16 | nemu_assert(A[0] == 0); 17 | nemu_assert(A[1] >= 1); 18 | nemu_assert(A[2] <= 2); 19 | nemu_assert(A[3] > 2); 20 | nemu_assert(A[4] < 5); 21 | nemu_assert(b == 3); 22 | nemu_assert(A[5] != 6); 23 | 24 | HIT_GOOD_TRAP; 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/movsx.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int A[10]; 4 | int b; 5 | char C[10]; 6 | int main() { 7 | A[0] = 0; 8 | A[1] = 1; 9 | A[2] = 2; 10 | A[3] = 3; 11 | A[4] = 4; 12 | 13 | b = A[3]; 14 | A[5] = b; 15 | C[0] = 'a'; 16 | nemu_assert(C[0] == 'a'); 17 | C[1] = C[0]; 18 | nemu_assert(C[1] == 'a'); 19 | A[0] = (int)C[0]; 20 | nemu_assert(A[0] == 'a'); 21 | C[1] = 0x80; 22 | A[0] = (int)C[1]; 23 | nemu_assert(A[1] == 1); 24 | nemu_assert(A[2] == 2); 25 | nemu_assert(A[3] == 3); 26 | nemu_assert(A[4] == 4); 27 | nemu_assert(b == 3); 28 | nemu_assert(A[5] == 3); 29 | nemu_assert(C[1] == 0xffffff80); 30 | nemu_assert(A[0] == 0xffffff80); 31 | 32 | HIT_GOOD_TRAP; 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/mul-longlong.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | long long mul(long long a,long long b) { 4 | long long ans = a*b; 5 | return ans; 6 | } 7 | 8 | int test_data[] = { -1364082006, 1157693227, -2022600529, 301212728}; 9 | long long ans[] = { 1860719719092984036LL, -1579188499418773362LL, 2758992986934981174LL, -410878862242972368LL, 1340253607841673529LL, -2341550933349917083LL, 348711935091793256LL, 4090912899911079841LL, -609233022994333112LL, 90729107509201984LL}; 10 | 11 | #define NR_DATA (sizeof(test_data) / sizeof(test_data[0])) 12 | 13 | int main() { 14 | int i,j,ans_idx = 0; 15 | int loop = 0; 16 | for (i = 0;i < NR_DATA;i++) { 17 | for (j = i;j < NR_DATA;j++) { 18 | //nemu_assert(0); 19 | nemu_assert(ans[ans_idx++] == mul(test_data[i],test_data[j])); 20 | loop ++; 21 | } 22 | } 23 | 24 | nemu_assert(loop == NR_DATA * (NR_DATA + 1) / 2); 25 | HIT_GOOD_TRAP; 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/pascal.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | //#include "stdio.h" 3 | 4 | #define N 31 5 | // #define N 3 6 | 7 | int a[N][N]; 8 | int ans[] = {1, 30, 435, 4060, 27405, 142506, 593775, 2035800, 5852925, 14307150, 30045015, 54627300, 86493225, 119759850, 145422675, 155117520, 145422675, 119759850, 86493225, 54627300, 30045015, 14307150, 5852925, 2035800, 593775, 142506, 27405, 4060, 435, 30, 1}; 9 | //int ans[] = {1, 2, 1}; 10 | 11 | int main() { 12 | int i, j; 13 | for(i = 0; i < N; i ++) { 14 | a[i][0] = a[i][i] = 1; 15 | nemu_assert(a[i][0] == 1); 16 | nemu_assert(a[i][i] == 1); 17 | } 18 | 19 | 20 | for(i = 2; i < N; i ++) { 21 | for(j = 1; j < i; j ++) { 22 | a[i][j] = a[i - 1][j - 1] + a[i - 1][j]; 23 | } 24 | } 25 | 26 | for(j = 0; j <= 30; j ++) { 27 | nemu_assert(a[30][j] == ans[j]); 28 | } 29 | 30 | 31 | HIT_GOOD_TRAP; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/prime.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int ans[] = {101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199}; 4 | 5 | int main() { 6 | int m, i, n = 0; 7 | int prime; 8 | for(m = 101; m <= 200; m += 2) { 9 | prime = 1; 10 | for(i = 2; i < m; i ++) { 11 | if(m % i == 0) { 12 | prime = 0; 13 | break; 14 | } 15 | } 16 | if(prime) { 17 | nemu_assert(i == ans[n]); 18 | n ++; 19 | } 20 | } 21 | 22 | nemu_assert(n == 21); 23 | 24 | HIT_GOOD_TRAP; 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/quick-sort.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 100 4 | 5 | int a[N] = {81, 37, 64, 23, 38, 65, 56, 15, 8, 33, 85, 39, 71, 12, 77, 6, 82, 89, 80, 35, 0, 59, 73, 4, 61, 30, 74, 69, 13, 42, 68, 63, 9, 29, 47, 36, 99, 25, 21, 14, 60, 3, 2, 18, 26, 83, 53, 5, 43, 67, 88, 70, 76, 92, 94, 48, 34, 49, 66, 95, 78, 62, 32, 52, 16, 72, 27, 28, 22, 40, 84, 91, 96, 57, 87, 51, 98, 1, 10, 11, 24, 20, 19, 31, 7, 97, 50, 86, 79, 17, 75, 55, 93, 44, 58, 54, 45, 41, 90, 46}; 6 | 7 | int partition(int *a, int p, int q) { 8 | int pivot = a[p]; 9 | int i = p, j = q; 10 | while(i < j) { 11 | while(i < j && a[j] > pivot) j --; 12 | a[i] = a[j]; 13 | 14 | while(i < j && a[i] <= pivot) i ++; 15 | a[j] = a[i]; 16 | } 17 | 18 | a[i] = pivot; 19 | return i; 20 | } 21 | 22 | void quick_sort(int *a, int p, int q) { 23 | if(p >= q) return; 24 | 25 | int m = partition(a, p, q); 26 | quick_sort(a, p, m - 1); 27 | quick_sort(a, m + 1, q); 28 | } 29 | 30 | int main() { 31 | quick_sort(a, 0, N - 1); 32 | 33 | int i; 34 | for(i = 0; i < N; i ++) { 35 | nemu_assert(a[i] == i); 36 | } 37 | 38 | quick_sort(a, 0, N - 1); 39 | 40 | for(i = 0; i < N; i ++) { 41 | nemu_assert(a[i] == i); 42 | } 43 | 44 | HIT_GOOD_TRAP; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/select-sort.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 100 4 | 5 | int a[N] = {81, 37, 64, 23, 38, 65, 56, 15, 8, 33, 85, 39, 71, 12, 77, 6, 82, 89, 80, 35, 0, 59, 73, 4, 61, 30, 74, 69, 13, 42, 68, 63, 9, 29, 47, 36, 99, 25, 21, 14, 60, 3, 2, 18, 26, 83, 53, 5, 43, 67, 88, 70, 76, 92, 94, 48, 34, 49, 66, 95, 78, 62, 32, 52, 16, 72, 27, 28, 22, 40, 84, 91, 96, 57, 87, 51, 98, 1, 10, 11, 24, 20, 19, 31, 7, 97, 50, 86, 79, 17, 75, 55, 93, 44, 58, 54, 45, 41, 90, 46}; 6 | 7 | void select_sort() { 8 | int i, j, k, t; 9 | for(i = 0; i < N - 1; i ++) { 10 | k = i; 11 | for(j = i + 1; j < N; j ++) { 12 | if(a[j] < a[k]) { 13 | k = j; 14 | } 15 | } 16 | 17 | t = a[i]; 18 | a[i] = a[k]; 19 | a[k] = t; 20 | } 21 | } 22 | 23 | int main() { 24 | select_sort(); 25 | 26 | int i; 27 | for(i = 0; i < N; i ++) { 28 | nemu_assert(a[i] == i); 29 | } 30 | 31 | select_sort(); 32 | 33 | for(i = 0; i < N; i ++) { 34 | nemu_assert(a[i] == i); 35 | } 36 | 37 | HIT_GOOD_TRAP; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/shuixianhua.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int ans[] = {153, 370, 371, 407}; 4 | 5 | int cube(int n) { 6 | return n * n * n; 7 | } 8 | 9 | int main() { 10 | int n, n2, n1, n0; 11 | int k = 0; 12 | for(n = 100; n < 1000; n ++) { 13 | n2 = n / 100; 14 | n1 = (n / 10) % 10; 15 | n0 = n % 10; 16 | 17 | if(n == cube(n2) + cube(n1) + cube(n0)) { 18 | nemu_assert(n == ans[k]); 19 | k ++; 20 | } 21 | } 22 | 23 | nemu_assert(k == 4); 24 | 25 | HIT_GOOD_TRAP; 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/string.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | #include 3 | 4 | char *s[] = { 5 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 6 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", 7 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 8 | ", World!\n", 9 | "Hello, World!\n", 10 | "#####" 11 | }; 12 | 13 | char str1[] = "Hello"; 14 | char str[20]; 15 | 16 | int main() { 17 | nemu_assert(strcmp(s[0], s[2]) == 0); 18 | nemu_assert(strcmp(s[0], s[1]) == -1); 19 | nemu_assert(strcmp(s[0] + 1, s[1] + 1) == -1); 20 | nemu_assert(strcmp(s[0] + 2, s[1] + 2) == -1); 21 | nemu_assert(strcmp(s[0] + 3, s[1] + 3) == -1); 22 | 23 | nemu_assert(strcmp( strcat(strcpy(str, str1), s[3]), s[4]) == 0); 24 | 25 | nemu_assert(memcmp(memset(str, '#', 5), s[5], 5) == 0); 26 | 27 | HIT_GOOD_TRAP; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/struct.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 100 4 | 5 | struct dummy { 6 | int pad1[N]; 7 | char pad2[N]; 8 | } d; 9 | 10 | struct dummy fun(struct dummy a) { 11 | return a; 12 | } 13 | 14 | int main() { 15 | int i; 16 | for(i = 0; i < N; i ++) { 17 | d.pad1[i] = i + 128; 18 | d.pad2[i] = i; 19 | } 20 | 21 | struct dummy t = fun(d); 22 | 23 | for(i = 0; i < N; i ++) { 24 | nemu_assert(t.pad1[i] == i + 128); 25 | nemu_assert(t.pad2[i] == i); 26 | } 27 | 28 | HIT_GOOD_TRAP; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/sum.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int main() { 4 | int i = 1, sum = 0; 5 | while(i <= 100) { 6 | sum += i; 7 | i ++; 8 | } 9 | 10 | nemu_assert(sum == 5050); 11 | HIT_GOOD_TRAP; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/test-float.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int main() { 4 | 5 | float a = 1.2, b = 1; 6 | float c = a + b; 7 | if(c == 2.2) 8 | ; 9 | else 10 | HIT_BAD_TRAP; 11 | c = a * b; 12 | if(c == 1.2) 13 | ; 14 | else 15 | HIT_BAD_TRAP; 16 | 17 | c = a / b; 18 | if(c == 1.2) 19 | ; 20 | else 21 | HIT_BAD_TRAP; 22 | 23 | c = a - b; 24 | if(c == 0.2) // this will fail, and also fails for native program, interesting, can be used as a quiz 25 | ; 26 | else 27 | HIT_BAD_TRAP; 28 | 29 | 30 | HIT_GOOD_TRAP; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/src/wanshu.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int ans[] = {6, 28, 496}; 4 | 5 | int main() { 6 | int n, sum, i, k = 0; 7 | for(n = 1; n < 500; n ++) { 8 | sum = 0; 9 | for(i = 1; i < n; i ++) { 10 | if(n % i == 0) { 11 | sum += i; 12 | } 13 | } 14 | 15 | if(sum == n) { 16 | nemu_assert(n == ans[k]); 17 | k ++; 18 | } 19 | } 20 | 21 | nemu_assert(k == 3); 22 | 23 | HIT_GOOD_TRAP; 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /pa2018_fall/testcase/start.S: -------------------------------------------------------------------------------- 1 | .globl start 2 | start: 3 | jmp main # never return 4 | --------------------------------------------------------------------------------