├── .gitignore ├── Makefile ├── README.md ├── init.sh ├── nanos-lite ├── .gitignore ├── Makefile ├── README.md ├── include │ ├── common.h │ ├── debug.h │ ├── fs.h │ ├── memory.h │ └── proc.h └── src │ ├── .gitignore │ ├── device.c │ ├── fs.c │ ├── initrd.S │ ├── irq.c │ ├── loader.c │ ├── main.c │ ├── mm.c │ ├── proc.c │ ├── ramdisk.c │ └── syscall.c ├── navy-apps ├── .gitignore ├── Makefile ├── Makefile.app ├── Makefile.check ├── Makefile.compile ├── Makefile.lib ├── README.md ├── apps │ ├── am-apps │ │ └── Makefile │ ├── init │ │ ├── Makefile │ │ └── init.cpp │ ├── litenes │ │ ├── Makefile │ │ ├── include │ │ │ ├── common.h │ │ │ ├── cpu.h │ │ │ ├── fce.h │ │ │ ├── memory.h │ │ │ ├── mmc.h │ │ │ ├── ppu.h │ │ │ └── psg.h │ │ └── src │ │ │ ├── common.c │ │ │ ├── cpu-addressing.c │ │ │ ├── cpu.c │ │ │ ├── fce.c │ │ │ ├── memory.c │ │ │ ├── mmc.c │ │ │ ├── ppu.c │ │ │ └── psg.c │ ├── lua │ │ ├── Makefile │ │ ├── include │ │ │ ├── lapi.h │ │ │ ├── lauxlib.h │ │ │ ├── lcode.h │ │ │ ├── lctype.h │ │ │ ├── ldebug.h │ │ │ ├── ldo.h │ │ │ ├── lfunc.h │ │ │ ├── lgc.h │ │ │ ├── llex.h │ │ │ ├── llimits.h │ │ │ ├── lmem.h │ │ │ ├── lobject.h │ │ │ ├── lopcodes.h │ │ │ ├── lparser.h │ │ │ ├── lprefix.h │ │ │ ├── lstate.h │ │ │ ├── lstring.h │ │ │ ├── ltable.h │ │ │ ├── ltm.h │ │ │ ├── lua.h │ │ │ ├── luaconf.h │ │ │ ├── lualib.h │ │ │ ├── lundump.h │ │ │ ├── lvm.h │ │ │ └── lzio.h │ │ └── src │ │ │ ├── lapi.c │ │ │ ├── lauxlib.c │ │ │ ├── lbaselib.c │ │ │ ├── lbitlib.c │ │ │ ├── lcode.c │ │ │ ├── lcorolib.c │ │ │ ├── lctype.c │ │ │ ├── ldblib.c │ │ │ ├── ldebug.c │ │ │ ├── ldo.c │ │ │ ├── ldump.c │ │ │ ├── lfunc.c │ │ │ ├── lgc.c │ │ │ ├── linit.c │ │ │ ├── liolib.c │ │ │ ├── llex.c │ │ │ ├── lmathlib.c │ │ │ ├── lmem.c │ │ │ ├── loadlib.c │ │ │ ├── lobject.c │ │ │ ├── lopcodes.c │ │ │ ├── loslib.c │ │ │ ├── lparser.c │ │ │ ├── lstate.c │ │ │ ├── lstring.c │ │ │ ├── lstrlib.c │ │ │ ├── ltable.c │ │ │ ├── ltablib.c │ │ │ ├── ltm.c │ │ │ ├── lua.c │ │ │ ├── lundump.c │ │ │ ├── lutf8lib.c │ │ │ ├── lvm.c │ │ │ └── lzio.c │ ├── nterm │ │ ├── Makefile │ │ ├── include │ │ │ └── nterm.h │ │ └── src │ │ │ ├── main.cpp │ │ │ └── term.cpp │ ├── nwm │ │ ├── Makefile │ │ ├── include │ │ │ ├── nwm.h │ │ │ └── winimpl.h │ │ └── src │ │ │ ├── events.cpp │ │ │ ├── main.cpp │ │ │ ├── window.cpp │ │ │ └── wm.cpp │ ├── pal │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ ├── FLOAT.h │ │ │ ├── _common.h │ │ │ ├── ascii.h │ │ │ ├── battle.h │ │ │ ├── big5font.h │ │ │ ├── common.h │ │ │ ├── ending.h │ │ │ ├── fight.h │ │ │ ├── font.h │ │ │ ├── game.h │ │ │ ├── gbfont.h │ │ │ ├── getopt.h │ │ │ ├── global.h │ │ │ ├── hal.h │ │ │ ├── input.h │ │ │ ├── itemmenu.h │ │ │ ├── magicmenu.h │ │ │ ├── main.h │ │ │ ├── main_PSP.h │ │ │ ├── map.h │ │ │ ├── midi.h │ │ │ ├── palcommon.h │ │ │ ├── palette.h │ │ │ ├── play.h │ │ │ ├── res.h │ │ │ ├── rixplay.h │ │ │ ├── rngplay.h │ │ │ ├── scene.h │ │ │ ├── script.h │ │ │ ├── sound.h │ │ │ ├── text.h │ │ │ ├── ui.h │ │ │ ├── uibattle.h │ │ │ ├── uigame.h │ │ │ ├── util.h │ │ │ └── video.h │ │ └── src │ │ │ ├── FLOAT │ │ │ └── FLOAT.c │ │ │ ├── battle │ │ │ ├── battle.c │ │ │ └── fight.c │ │ │ ├── device │ │ │ ├── input.c │ │ │ ├── palette.c │ │ │ └── video.c │ │ │ ├── game │ │ │ ├── game.c │ │ │ ├── play.c │ │ │ └── script.c │ │ │ ├── global │ │ │ ├── global.c │ │ │ ├── palcommon.c │ │ │ └── res.c │ │ │ ├── hal │ │ │ └── hal.c │ │ │ ├── main.c │ │ │ ├── misc │ │ │ ├── ending.c │ │ │ ├── rngplay.c │ │ │ ├── util.c │ │ │ └── yj1.c │ │ │ ├── pal-main.c │ │ │ ├── scene │ │ │ ├── map.c │ │ │ └── scene.c │ │ │ ├── ui │ │ │ ├── font.c │ │ │ ├── itemmenu.c │ │ │ ├── magicmenu.c │ │ │ ├── text.c │ │ │ ├── ui.c │ │ │ ├── uibattle.c │ │ │ └── uigame.c │ │ │ └── unuse │ │ │ ├── midi.c │ │ │ ├── rixplay.c │ │ │ ├── sdl.c │ │ │ └── sound.c │ ├── slider │ │ ├── Makefile │ │ ├── README.md │ │ ├── slides │ │ │ ├── .gitignore │ │ │ └── convert.sh │ │ └── src │ │ │ └── main.cpp │ └── typing │ │ ├── Makefile │ │ ├── README.md │ │ ├── draw.c │ │ ├── font.c │ │ ├── game.c │ │ ├── game.h │ │ └── keyboard.c ├── fsimg │ ├── etc │ │ └── init │ └── share │ │ ├── fonts │ │ ├── Courier-10.bdf │ │ ├── Courier-11.bdf │ │ ├── Courier-12.bdf │ │ ├── Courier-13.bdf │ │ ├── Courier-7.bdf │ │ ├── Courier-8.bdf │ │ └── Courier-9.bdf │ │ ├── games │ │ ├── nes │ │ │ ├── battlecity.nes │ │ │ ├── circus.nes │ │ │ ├── kungfu.nes │ │ │ ├── loderunner.nes │ │ │ └── mario.nes │ │ └── pal.tbz │ │ ├── pictures │ │ └── projectn.bmp │ │ └── texts │ │ └── num ├── libs │ ├── libc │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ ├── _ansi.h │ │ │ ├── _newlib_version.h │ │ │ ├── _syslist.h │ │ │ ├── alloca.h │ │ │ ├── ar.h │ │ │ ├── argz.h │ │ │ ├── assert.h │ │ │ ├── complex.h │ │ │ ├── cpio.h │ │ │ ├── ctype.h │ │ │ ├── devctl.h │ │ │ ├── dirent.h │ │ │ ├── elf.h │ │ │ ├── envlock.h │ │ │ ├── envz.h │ │ │ ├── errno.h │ │ │ ├── fastmath.h │ │ │ ├── fcntl.h │ │ │ ├── fdlibm.h │ │ │ ├── fnmatch.h │ │ │ ├── getopt.h │ │ │ ├── glob.h │ │ │ ├── grp.h │ │ │ ├── iconv.h │ │ │ ├── ieeefp.h │ │ │ ├── inttypes.h │ │ │ ├── langinfo.h │ │ │ ├── libgen.h │ │ │ ├── limits.h │ │ │ ├── locale.h │ │ │ ├── machine │ │ │ │ ├── _arc4random.h │ │ │ │ ├── _default_types.h │ │ │ │ ├── _endian.h │ │ │ │ ├── _time.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 │ │ │ ├── memory.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 │ │ │ ├── ssp │ │ │ │ ├── ssp.h │ │ │ │ ├── stdio.h │ │ │ │ ├── stdlib.h │ │ │ │ ├── string.h │ │ │ │ ├── strings.h │ │ │ │ ├── unistd.h │ │ │ │ └── wchar.h │ │ │ ├── stdatomic.h │ │ │ ├── stdint.h │ │ │ ├── stdio.h │ │ │ ├── stdio_ext.h │ │ │ ├── stdlib.h │ │ │ ├── string.h │ │ │ ├── strings.h │ │ │ ├── sys │ │ │ │ ├── _default_fcntl.h │ │ │ │ ├── _intsup.h │ │ │ │ ├── _pthreadtypes.h │ │ │ │ ├── _sigset.h │ │ │ │ ├── _stdint.h │ │ │ │ ├── _timespec.h │ │ │ │ ├── _timeval.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 │ │ │ │ ├── select.h │ │ │ │ ├── signal.h │ │ │ │ ├── stat.h │ │ │ │ ├── stdio.h │ │ │ │ ├── string.h │ │ │ │ ├── syslimits.h │ │ │ │ ├── termios.h │ │ │ │ ├── time.h │ │ │ │ ├── timeb.h │ │ │ │ ├── times.h │ │ │ │ ├── timespec.h │ │ │ │ ├── tree.h │ │ │ │ ├── types.h │ │ │ │ ├── unistd.h │ │ │ │ ├── utime.h │ │ │ │ ├── utmp.h │ │ │ │ └── wait.h │ │ │ ├── tar.h │ │ │ ├── termios.h │ │ │ ├── tgmath.h │ │ │ ├── threads.h │ │ │ ├── time.h │ │ │ ├── unctrl.h │ │ │ ├── unistd.h │ │ │ ├── utime.h │ │ │ ├── utmp.h │ │ │ ├── wchar.h │ │ │ ├── wctype.h │ │ │ ├── wordexp.h │ │ │ └── xlocale.h │ │ └── src │ │ │ ├── argz │ │ │ ├── argz_add.c │ │ │ ├── argz_add_sep.c │ │ │ ├── argz_append.c │ │ │ ├── argz_count.c │ │ │ ├── argz_create.c │ │ │ ├── argz_create_sep.c │ │ │ ├── argz_delete.c │ │ │ ├── argz_extract.c │ │ │ ├── argz_insert.c │ │ │ ├── argz_next.c │ │ │ ├── argz_replace.c │ │ │ ├── argz_stringify.c │ │ │ ├── buf_findstr.c │ │ │ ├── buf_findstr.h │ │ │ ├── dummy.c │ │ │ ├── envz_add.c │ │ │ ├── envz_entry.c │ │ │ ├── envz_get.c │ │ │ ├── envz_merge.c │ │ │ ├── envz_remove.c │ │ │ └── envz_strip.c │ │ │ ├── ctype │ │ │ ├── caseconv.t │ │ │ ├── categories.c │ │ │ ├── categories.cat │ │ │ ├── categories.h │ │ │ ├── categories.t │ │ │ ├── ctype_.c │ │ │ ├── ctype_.h │ │ │ ├── ctype_cp.h │ │ │ ├── ctype_iso.h │ │ │ ├── isalnum.c │ │ │ ├── isalnum_l.c │ │ │ ├── isalpha.c │ │ │ ├── isalpha_l.c │ │ │ ├── isascii.c │ │ │ ├── isascii_l.c │ │ │ ├── isblank.c │ │ │ ├── isblank_l.c │ │ │ ├── iscntrl.c │ │ │ ├── iscntrl_l.c │ │ │ ├── isdigit.c │ │ │ ├── isdigit_l.c │ │ │ ├── islower.c │ │ │ ├── islower_l.c │ │ │ ├── isprint.c │ │ │ ├── isprint_l.c │ │ │ ├── ispunct.c │ │ │ ├── ispunct_l.c │ │ │ ├── isspace.c │ │ │ ├── isspace_l.c │ │ │ ├── isupper.c │ │ │ ├── isupper_l.c │ │ │ ├── iswalnum.c │ │ │ ├── iswalnum_l.c │ │ │ ├── iswalpha.c │ │ │ ├── iswalpha_l.c │ │ │ ├── iswblank.c │ │ │ ├── iswblank_l.c │ │ │ ├── iswcntrl.c │ │ │ ├── iswcntrl_l.c │ │ │ ├── iswctype.c │ │ │ ├── iswctype_l.c │ │ │ ├── iswdigit.c │ │ │ ├── iswdigit_l.c │ │ │ ├── iswgraph.c │ │ │ ├── iswgraph_l.c │ │ │ ├── iswlower.c │ │ │ ├── iswlower_l.c │ │ │ ├── iswprint.c │ │ │ ├── iswprint_l.c │ │ │ ├── iswpunct.c │ │ │ ├── iswpunct_l.c │ │ │ ├── iswspace.c │ │ │ ├── iswspace_l.c │ │ │ ├── iswupper.c │ │ │ ├── iswupper_l.c │ │ │ ├── iswxdigit.c │ │ │ ├── iswxdigit_l.c │ │ │ ├── isxdigit.c │ │ │ ├── isxdigit_l.c │ │ │ ├── jp2uc.c │ │ │ ├── jp2uc.h │ │ │ ├── local.h │ │ │ ├── toascii.c │ │ │ ├── toascii_l.c │ │ │ ├── tolower.c │ │ │ ├── tolower_l.c │ │ │ ├── toupper.c │ │ │ ├── toupper_l.c │ │ │ ├── towctrans.c │ │ │ ├── towctrans_l.c │ │ │ ├── towlower.c │ │ │ ├── towlower_l.c │ │ │ ├── towupper.c │ │ │ ├── towupper_l.c │ │ │ ├── wctrans.c │ │ │ ├── wctrans_l.c │ │ │ ├── wctype.c │ │ │ └── wctype_l.c │ │ │ ├── errno │ │ │ └── errno.c │ │ │ ├── libm │ │ │ ├── common │ │ │ │ ├── acoshl.c │ │ │ │ ├── acosl.c │ │ │ │ ├── asinhl.c │ │ │ │ ├── asinl.c │ │ │ │ ├── atan2l.c │ │ │ │ ├── atanhl.c │ │ │ │ ├── atanl.c │ │ │ │ ├── cbrtl.c │ │ │ │ ├── ceill.c │ │ │ │ ├── copysignl.c │ │ │ │ ├── cosf.c │ │ │ │ ├── coshl.c │ │ │ │ ├── cosl.c │ │ │ │ ├── erfcl.c │ │ │ │ ├── erfl.c │ │ │ │ ├── exp.c │ │ │ │ ├── exp2.c │ │ │ │ ├── exp2l.c │ │ │ │ ├── exp_data.c │ │ │ │ ├── expl.c │ │ │ │ ├── expm1l.c │ │ │ │ ├── fabsl.c │ │ │ │ ├── fdiml.c │ │ │ │ ├── floorl.c │ │ │ │ ├── fmal.c │ │ │ │ ├── fmaxl.c │ │ │ │ ├── fminl.c │ │ │ │ ├── fmodl.c │ │ │ │ ├── frexpl.c │ │ │ │ ├── hypotl.c │ │ │ │ ├── ilogbl.c │ │ │ │ ├── isgreater.c │ │ │ │ ├── ldexpl.c │ │ │ │ ├── lgammal.c │ │ │ │ ├── llrintl.c │ │ │ │ ├── llroundl.c │ │ │ │ ├── local.h │ │ │ │ ├── log.c │ │ │ │ ├── log10l.c │ │ │ │ ├── log1pl.c │ │ │ │ ├── log2.c │ │ │ │ ├── log2_data.c │ │ │ │ ├── log2l.c │ │ │ │ ├── log_data.c │ │ │ │ ├── logbl.c │ │ │ │ ├── logl.c │ │ │ │ ├── lrintl.c │ │ │ │ ├── lroundl.c │ │ │ │ ├── math_config.h │ │ │ │ ├── math_err.c │ │ │ │ ├── math_errf.c │ │ │ │ ├── modfl.c │ │ │ │ ├── nanl.c │ │ │ │ ├── nearbyintl.c │ │ │ │ ├── nextafterl.c │ │ │ │ ├── nexttoward.c │ │ │ │ ├── nexttowardf.c │ │ │ │ ├── nexttowardl.c │ │ │ │ ├── pow.c │ │ │ │ ├── pow_log_data.c │ │ │ │ ├── powl.c │ │ │ │ ├── remainderl.c │ │ │ │ ├── remquol.c │ │ │ │ ├── rintl.c │ │ │ │ ├── roundl.c │ │ │ │ ├── s_cbrt.c │ │ │ │ ├── s_copysign.c │ │ │ │ ├── s_exp10.c │ │ │ │ ├── s_expm1.c │ │ │ │ ├── s_fdim.c │ │ │ │ ├── s_finite.c │ │ │ │ ├── s_fma.c │ │ │ │ ├── s_fmax.c │ │ │ │ ├── s_fmin.c │ │ │ │ ├── s_fpclassify.c │ │ │ │ ├── s_ilogb.c │ │ │ │ ├── s_infinity.c │ │ │ │ ├── s_isinf.c │ │ │ │ ├── s_isinfd.c │ │ │ │ ├── s_isnan.c │ │ │ │ ├── s_isnand.c │ │ │ │ ├── s_lib_ver.c │ │ │ │ ├── s_llrint.c │ │ │ │ ├── s_llround.c │ │ │ │ ├── s_log1p.c │ │ │ │ ├── s_log2.c │ │ │ │ ├── s_logb.c │ │ │ │ ├── s_lrint.c │ │ │ │ ├── s_lround.c │ │ │ │ ├── s_matherr.c │ │ │ │ ├── s_modf.c │ │ │ │ ├── s_nan.c │ │ │ │ ├── s_nearbyint.c │ │ │ │ ├── s_nextafter.c │ │ │ │ ├── s_pow10.c │ │ │ │ ├── s_remquo.c │ │ │ │ ├── s_rint.c │ │ │ │ ├── s_round.c │ │ │ │ ├── s_scalbln.c │ │ │ │ ├── s_scalbn.c │ │ │ │ ├── s_signbit.c │ │ │ │ ├── s_trunc.c │ │ │ │ ├── scalblnl.c │ │ │ │ ├── scalbnl.c │ │ │ │ ├── sf_cbrt.c │ │ │ │ ├── sf_copysign.c │ │ │ │ ├── sf_exp.c │ │ │ │ ├── sf_exp10.c │ │ │ │ ├── sf_exp2.c │ │ │ │ ├── sf_exp2_data.c │ │ │ │ ├── sf_expm1.c │ │ │ │ ├── sf_fdim.c │ │ │ │ ├── sf_finite.c │ │ │ │ ├── sf_fma.c │ │ │ │ ├── sf_fmax.c │ │ │ │ ├── sf_fmin.c │ │ │ │ ├── sf_fpclassify.c │ │ │ │ ├── sf_ilogb.c │ │ │ │ ├── sf_infinity.c │ │ │ │ ├── sf_isinf.c │ │ │ │ ├── sf_isinff.c │ │ │ │ ├── sf_isnan.c │ │ │ │ ├── sf_isnanf.c │ │ │ │ ├── sf_llrint.c │ │ │ │ ├── sf_llround.c │ │ │ │ ├── sf_log.c │ │ │ │ ├── sf_log1p.c │ │ │ │ ├── sf_log2.c │ │ │ │ ├── sf_log2_data.c │ │ │ │ ├── sf_log_data.c │ │ │ │ ├── sf_logb.c │ │ │ │ ├── sf_lrint.c │ │ │ │ ├── sf_lround.c │ │ │ │ ├── sf_modf.c │ │ │ │ ├── sf_nan.c │ │ │ │ ├── sf_nearbyint.c │ │ │ │ ├── sf_nextafter.c │ │ │ │ ├── sf_pow.c │ │ │ │ ├── sf_pow10.c │ │ │ │ ├── sf_pow_log2_data.c │ │ │ │ ├── sf_remquo.c │ │ │ │ ├── sf_rint.c │ │ │ │ ├── sf_round.c │ │ │ │ ├── sf_scalbln.c │ │ │ │ ├── sf_scalbn.c │ │ │ │ ├── sf_trunc.c │ │ │ │ ├── sincosf.c │ │ │ │ ├── sincosf.h │ │ │ │ ├── sincosf_data.c │ │ │ │ ├── sinf.c │ │ │ │ ├── sinhl.c │ │ │ │ ├── sinl.c │ │ │ │ ├── sl_finite.c │ │ │ │ ├── sqrtl.c │ │ │ │ ├── tanhl.c │ │ │ │ ├── tanl.c │ │ │ │ ├── tgammal.c │ │ │ │ └── truncl.c │ │ │ ├── complex │ │ │ │ ├── cabs.c │ │ │ │ ├── cabsf.c │ │ │ │ ├── cabsl.c │ │ │ │ ├── cacos.c │ │ │ │ ├── cacosf.c │ │ │ │ ├── cacosh.c │ │ │ │ ├── cacoshf.c │ │ │ │ ├── cacoshl.c │ │ │ │ ├── cacosl.c │ │ │ │ ├── carg.c │ │ │ │ ├── cargf.c │ │ │ │ ├── cargl.c │ │ │ │ ├── casin.c │ │ │ │ ├── casinf.c │ │ │ │ ├── casinh.c │ │ │ │ ├── casinhf.c │ │ │ │ ├── casinhl.c │ │ │ │ ├── casinl.c │ │ │ │ ├── catan.c │ │ │ │ ├── catanf.c │ │ │ │ ├── catanh.c │ │ │ │ ├── catanhf.c │ │ │ │ ├── catanhl.c │ │ │ │ ├── catanl.c │ │ │ │ ├── ccos.c │ │ │ │ ├── ccosf.c │ │ │ │ ├── ccosh.c │ │ │ │ ├── ccoshf.c │ │ │ │ ├── ccoshl.c │ │ │ │ ├── ccosl.c │ │ │ │ ├── cephes_subr.c │ │ │ │ ├── cephes_subr.h │ │ │ │ ├── cephes_subrf.c │ │ │ │ ├── cephes_subrf.h │ │ │ │ ├── cephes_subrl.c │ │ │ │ ├── cephes_subrl.h │ │ │ │ ├── cexp.c │ │ │ │ ├── cexpf.c │ │ │ │ ├── cexpl.c │ │ │ │ ├── cimag.c │ │ │ │ ├── cimagf.c │ │ │ │ ├── cimagl.c │ │ │ │ ├── clog.c │ │ │ │ ├── clog10.c │ │ │ │ ├── clog10f.c │ │ │ │ ├── clogf.c │ │ │ │ ├── clogl.c │ │ │ │ ├── complex.tex │ │ │ │ ├── conj.c │ │ │ │ ├── conjf.c │ │ │ │ ├── conjl.c │ │ │ │ ├── cpow.c │ │ │ │ ├── cpowf.c │ │ │ │ ├── cpowl.c │ │ │ │ ├── cproj.c │ │ │ │ ├── cprojf.c │ │ │ │ ├── cprojl.c │ │ │ │ ├── creal.c │ │ │ │ ├── crealf.c │ │ │ │ ├── creall.c │ │ │ │ ├── csin.c │ │ │ │ ├── csinf.c │ │ │ │ ├── csinh.c │ │ │ │ ├── csinhf.c │ │ │ │ ├── csinhl.c │ │ │ │ ├── csinl.c │ │ │ │ ├── csqrt.c │ │ │ │ ├── csqrtf.c │ │ │ │ ├── csqrtl.c │ │ │ │ ├── ctan.c │ │ │ │ ├── ctanf.c │ │ │ │ ├── ctanh.c │ │ │ │ ├── ctanhf.c │ │ │ │ ├── ctanhl.c │ │ │ │ └── ctanl.c │ │ │ ├── math │ │ │ │ ├── e_acos.c │ │ │ │ ├── e_acosh.c │ │ │ │ ├── e_asin.c │ │ │ │ ├── e_atan2.c │ │ │ │ ├── e_atanh.c │ │ │ │ ├── e_cosh.c │ │ │ │ ├── e_exp.c │ │ │ │ ├── e_fmod.c │ │ │ │ ├── e_hypot.c │ │ │ │ ├── e_j0.c │ │ │ │ ├── e_j1.c │ │ │ │ ├── e_jn.c │ │ │ │ ├── e_log.c │ │ │ │ ├── e_log10.c │ │ │ │ ├── e_pow.c │ │ │ │ ├── e_rem_pio2.c │ │ │ │ ├── e_remainder.c │ │ │ │ ├── e_scalb.c │ │ │ │ ├── e_sinh.c │ │ │ │ ├── e_sqrt.c │ │ │ │ ├── ef_acos.c │ │ │ │ ├── ef_acosh.c │ │ │ │ ├── ef_asin.c │ │ │ │ ├── ef_atan2.c │ │ │ │ ├── ef_atanh.c │ │ │ │ ├── ef_cosh.c │ │ │ │ ├── ef_exp.c │ │ │ │ ├── ef_fmod.c │ │ │ │ ├── ef_hypot.c │ │ │ │ ├── ef_j0.c │ │ │ │ ├── ef_j1.c │ │ │ │ ├── ef_jn.c │ │ │ │ ├── ef_log.c │ │ │ │ ├── ef_log10.c │ │ │ │ ├── ef_pow.c │ │ │ │ ├── ef_rem_pio2.c │ │ │ │ ├── ef_remainder.c │ │ │ │ ├── ef_scalb.c │ │ │ │ ├── ef_sinh.c │ │ │ │ ├── ef_sqrt.c │ │ │ │ ├── el_hypot.c │ │ │ │ ├── er_gamma.c │ │ │ │ ├── er_lgamma.c │ │ │ │ ├── erf_gamma.c │ │ │ │ ├── erf_lgamma.c │ │ │ │ ├── k_cos.c │ │ │ │ ├── k_rem_pio2.c │ │ │ │ ├── k_sin.c │ │ │ │ ├── k_standard.c │ │ │ │ ├── k_tan.c │ │ │ │ ├── kf_cos.c │ │ │ │ ├── kf_rem_pio2.c │ │ │ │ ├── kf_sin.c │ │ │ │ ├── kf_tan.c │ │ │ │ ├── math.tex │ │ │ │ ├── s_asinh.c │ │ │ │ ├── s_atan.c │ │ │ │ ├── s_ceil.c │ │ │ │ ├── s_cos.c │ │ │ │ ├── s_erf.c │ │ │ │ ├── s_fabs.c │ │ │ │ ├── s_floor.c │ │ │ │ ├── s_frexp.c │ │ │ │ ├── s_ldexp.c │ │ │ │ ├── s_signif.c │ │ │ │ ├── s_sin.c │ │ │ │ ├── s_tan.c │ │ │ │ ├── s_tanh.c │ │ │ │ ├── sf_asinh.c │ │ │ │ ├── sf_atan.c │ │ │ │ ├── sf_ceil.c │ │ │ │ ├── sf_cos.c │ │ │ │ ├── sf_erf.c │ │ │ │ ├── sf_fabs.c │ │ │ │ ├── sf_floor.c │ │ │ │ ├── sf_frexp.c │ │ │ │ ├── sf_ldexp.c │ │ │ │ ├── sf_signif.c │ │ │ │ ├── sf_sin.c │ │ │ │ ├── sf_tan.c │ │ │ │ ├── sf_tanh.c │ │ │ │ ├── w_acos.c │ │ │ │ ├── w_acosh.c │ │ │ │ ├── w_asin.c │ │ │ │ ├── w_atan2.c │ │ │ │ ├── w_atanh.c │ │ │ │ ├── w_cosh.c │ │ │ │ ├── w_drem.c │ │ │ │ ├── w_exp.c │ │ │ │ ├── w_exp2.c │ │ │ │ ├── w_fmod.c │ │ │ │ ├── w_gamma.c │ │ │ │ ├── w_hypot.c │ │ │ │ ├── w_j0.c │ │ │ │ ├── w_j1.c │ │ │ │ ├── w_jn.c │ │ │ │ ├── w_lgamma.c │ │ │ │ ├── w_log.c │ │ │ │ ├── w_log10.c │ │ │ │ ├── w_pow.c │ │ │ │ ├── w_remainder.c │ │ │ │ ├── w_scalb.c │ │ │ │ ├── w_sincos.c │ │ │ │ ├── w_sinh.c │ │ │ │ ├── w_sqrt.c │ │ │ │ ├── w_tgamma.c │ │ │ │ ├── wf_acos.c │ │ │ │ ├── wf_acosh.c │ │ │ │ ├── wf_asin.c │ │ │ │ ├── wf_atan2.c │ │ │ │ ├── wf_atanh.c │ │ │ │ ├── wf_cosh.c │ │ │ │ ├── wf_drem.c │ │ │ │ ├── wf_exp.c │ │ │ │ ├── wf_exp2.c │ │ │ │ ├── wf_fmod.c │ │ │ │ ├── wf_gamma.c │ │ │ │ ├── wf_hypot.c │ │ │ │ ├── wf_j0.c │ │ │ │ ├── wf_j1.c │ │ │ │ ├── wf_jn.c │ │ │ │ ├── wf_lgamma.c │ │ │ │ ├── wf_log.c │ │ │ │ ├── wf_log10.c │ │ │ │ ├── wf_log2.c │ │ │ │ ├── wf_pow.c │ │ │ │ ├── wf_remainder.c │ │ │ │ ├── wf_scalb.c │ │ │ │ ├── wf_sincos.c │ │ │ │ ├── wf_sinh.c │ │ │ │ ├── wf_sqrt.c │ │ │ │ ├── wf_tgamma.c │ │ │ │ ├── wr_gamma.c │ │ │ │ ├── wr_lgamma.c │ │ │ │ ├── wrf_gamma.c │ │ │ │ └── wrf_lgamma.c │ │ │ └── mathfp │ │ │ │ ├── README │ │ │ │ ├── e_acosh.c │ │ │ │ ├── e_atanh.c │ │ │ │ ├── e_hypot.c │ │ │ │ ├── e_j0.c │ │ │ │ ├── e_j1.c │ │ │ │ ├── e_remainder.c │ │ │ │ ├── e_scalb.c │ │ │ │ ├── ef_acosh.c │ │ │ │ ├── ef_atanh.c │ │ │ │ ├── ef_hypot.c │ │ │ │ ├── ef_j0.c │ │ │ │ ├── ef_j1.c │ │ │ │ ├── ef_remainder.c │ │ │ │ ├── ef_scalb.c │ │ │ │ ├── er_gamma.c │ │ │ │ ├── er_lgamma.c │ │ │ │ ├── erf_gamma.c │ │ │ │ ├── erf_lgamma.c │ │ │ │ ├── mathfp.tex │ │ │ │ ├── s_acos.c │ │ │ │ ├── s_asin.c │ │ │ │ ├── s_asine.c │ │ │ │ ├── s_asinh.c │ │ │ │ ├── s_atan.c │ │ │ │ ├── s_atan2.c │ │ │ │ ├── s_atangent.c │ │ │ │ ├── s_ceil.c │ │ │ │ ├── s_cos.c │ │ │ │ ├── s_cosh.c │ │ │ │ ├── s_erf.c │ │ │ │ ├── s_exp.c │ │ │ │ ├── s_exp2.c │ │ │ │ ├── s_fabs.c │ │ │ │ ├── s_floor.c │ │ │ │ ├── s_fmod.c │ │ │ │ ├── s_frexp.c │ │ │ │ ├── s_ispos.c │ │ │ │ ├── s_ldexp.c │ │ │ │ ├── s_log.c │ │ │ │ ├── s_log10.c │ │ │ │ ├── s_logarithm.c │ │ │ │ ├── s_mathcnst.c │ │ │ │ ├── s_numtest.c │ │ │ │ ├── s_pow.c │ │ │ │ ├── s_signif.c │ │ │ │ ├── s_sin.c │ │ │ │ ├── s_sincos.c │ │ │ │ ├── s_sine.c │ │ │ │ ├── s_sineh.c │ │ │ │ ├── s_sinf.c │ │ │ │ ├── s_sinh.c │ │ │ │ ├── s_sqrt.c │ │ │ │ ├── s_tan.c │ │ │ │ ├── s_tanh.c │ │ │ │ ├── s_tgamma.c │ │ │ │ ├── sf_acos.c │ │ │ │ ├── sf_asin.c │ │ │ │ ├── sf_asine.c │ │ │ │ ├── sf_asinh.c │ │ │ │ ├── sf_atan.c │ │ │ │ ├── sf_atan2.c │ │ │ │ ├── sf_atangent.c │ │ │ │ ├── sf_ceil.c │ │ │ │ ├── sf_cos.c │ │ │ │ ├── sf_cosh.c │ │ │ │ ├── sf_erf.c │ │ │ │ ├── sf_exp.c │ │ │ │ ├── sf_exp2.c │ │ │ │ ├── sf_fabs.c │ │ │ │ ├── sf_floor.c │ │ │ │ ├── sf_fmod.c │ │ │ │ ├── sf_frexp.c │ │ │ │ ├── sf_ispos.c │ │ │ │ ├── sf_ldexp.c │ │ │ │ ├── sf_log.c │ │ │ │ ├── sf_log10.c │ │ │ │ ├── sf_logarithm.c │ │ │ │ ├── sf_numtest.c │ │ │ │ ├── sf_pow.c │ │ │ │ ├── sf_signif.c │ │ │ │ ├── sf_sin.c │ │ │ │ ├── sf_sincos.c │ │ │ │ ├── sf_sine.c │ │ │ │ ├── sf_sineh.c │ │ │ │ ├── sf_sinh.c │ │ │ │ ├── sf_sqrt.c │ │ │ │ ├── sf_tan.c │ │ │ │ ├── sf_tanh.c │ │ │ │ ├── sf_tgamma.c │ │ │ │ ├── w_cabs.c │ │ │ │ ├── w_drem.c │ │ │ │ ├── w_jn.c │ │ │ │ ├── wf_cabs.c │ │ │ │ ├── wf_drem.c │ │ │ │ ├── wf_jn.c │ │ │ │ └── zmath.h │ │ │ ├── locale │ │ │ ├── duplocale.c │ │ │ ├── freelocale.c │ │ │ ├── lctype.c │ │ │ ├── lmessages.c │ │ │ ├── lmonetary.c │ │ │ ├── lnumeric.c │ │ │ ├── locale.c │ │ │ ├── localeconv.c │ │ │ ├── newlocale.c │ │ │ ├── nl_langinfo.c │ │ │ ├── setlocale.h │ │ │ ├── timelocal.c │ │ │ └── uselocale.c │ │ │ ├── misc │ │ │ ├── __dprintf.c │ │ │ ├── ffs.c │ │ │ ├── fini.c │ │ │ ├── init.c │ │ │ ├── lock.c │ │ │ └── unctrl.c │ │ │ ├── platform │ │ │ ├── cpp.cpp │ │ │ ├── crt0.c │ │ │ └── setjmp │ │ │ │ ├── amd64.S │ │ │ │ ├── mips32.S │ │ │ │ └── x86.S │ │ │ ├── posix │ │ │ ├── COPYRIGHT │ │ │ ├── _isatty.c │ │ │ ├── cclass.h │ │ │ ├── closedir.c │ │ │ ├── cname.h │ │ │ ├── collate.c │ │ │ ├── collate.h │ │ │ ├── collcmp.c │ │ │ ├── creat.c │ │ │ ├── engine.t │ │ │ ├── execl.c │ │ │ ├── execle.c │ │ │ ├── execlp.c │ │ │ ├── execv.c │ │ │ ├── execve.c │ │ │ ├── execvp.c │ │ │ ├── fnmatch.c │ │ │ ├── glob.c │ │ │ ├── isatty.c │ │ │ ├── namespace.h │ │ │ ├── opendir.c │ │ │ ├── popen.c │ │ │ ├── posix_spawn.c │ │ │ ├── readdir.c │ │ │ ├── readdir_r.c │ │ │ ├── regcomp.c │ │ │ ├── regerror.c │ │ │ ├── regex2.h │ │ │ ├── regexec.c │ │ │ ├── regfree.c │ │ │ ├── rewinddir.c │ │ │ ├── rune.h │ │ │ ├── runetype.h │ │ │ ├── scandir.c │ │ │ ├── seekdir.c │ │ │ ├── sleep.c │ │ │ ├── sysexits.h │ │ │ ├── telldir.c │ │ │ ├── un-namespace.h │ │ │ ├── usleep.c │ │ │ ├── utils.h │ │ │ ├── wordexp.c │ │ │ ├── wordexp2.h │ │ │ └── wordfree.c │ │ │ ├── reent │ │ │ ├── closer.c │ │ │ ├── execr.c │ │ │ ├── fcntlr.c │ │ │ ├── fstat64r.c │ │ │ ├── fstatr.c │ │ │ ├── getreent.c │ │ │ ├── gettimeofdayr.c │ │ │ ├── impure.c │ │ │ ├── isattyr.c │ │ │ ├── linkr.c │ │ │ ├── lseek64r.c │ │ │ ├── lseekr.c │ │ │ ├── mkdirr.c │ │ │ ├── open64r.c │ │ │ ├── openr.c │ │ │ ├── readr.c │ │ │ ├── reent.c │ │ │ ├── renamer.c │ │ │ ├── sbrkr.c │ │ │ ├── signalr.c │ │ │ ├── signgam.c │ │ │ ├── stat64r.c │ │ │ ├── statr.c │ │ │ ├── timesr.c │ │ │ ├── unlinkr.c │ │ │ └── writer.c │ │ │ ├── search │ │ │ ├── bsd_qsort_r.c │ │ │ ├── bsearch.c │ │ │ ├── db_local.h │ │ │ ├── extern.h │ │ │ ├── hash.c │ │ │ ├── hash.h │ │ │ ├── hash_bigkey.c │ │ │ ├── hash_buf.c │ │ │ ├── hash_func.c │ │ │ ├── hash_log2.c │ │ │ ├── hash_page.c │ │ │ ├── hcreate.c │ │ │ ├── hcreate_r.c │ │ │ ├── page.h │ │ │ ├── qsort.c │ │ │ ├── qsort_r.c │ │ │ ├── tdelete.c │ │ │ ├── tdestroy.c │ │ │ ├── tfind.c │ │ │ ├── tsearch.c │ │ │ └── twalk.c │ │ │ ├── signal │ │ │ ├── psignal.c │ │ │ ├── raise.c │ │ │ └── signal.c │ │ │ ├── ssp │ │ │ ├── chk_fail.c │ │ │ ├── gets_chk.c │ │ │ ├── memcpy_chk.c │ │ │ ├── memmove_chk.c │ │ │ ├── mempcpy_chk.c │ │ │ ├── memset_chk.c │ │ │ ├── snprintf_chk.c │ │ │ ├── sprintf_chk.c │ │ │ ├── stack_protector.c │ │ │ ├── stpcpy_chk.c │ │ │ ├── stpncpy_chk.c │ │ │ ├── strcat_chk.c │ │ │ ├── strcpy_chk.c │ │ │ ├── strncat_chk.c │ │ │ ├── strncpy_chk.c │ │ │ ├── vsnprintf_chk.c │ │ │ └── vsprintf_chk.c │ │ │ ├── stdio │ │ │ ├── asiprintf.c │ │ │ ├── asniprintf.c │ │ │ ├── asnprintf.c │ │ │ ├── asprintf.c │ │ │ ├── clearerr.c │ │ │ ├── clearerr_u.c │ │ │ ├── diprintf.c │ │ │ ├── dprintf.c │ │ │ ├── fclose.c │ │ │ ├── fcloseall.c │ │ │ ├── fdopen.c │ │ │ ├── feof.c │ │ │ ├── feof_u.c │ │ │ ├── ferror.c │ │ │ ├── ferror_u.c │ │ │ ├── fflush.c │ │ │ ├── fflush_u.c │ │ │ ├── fgetc.c │ │ │ ├── fgetc_u.c │ │ │ ├── fgetpos.c │ │ │ ├── fgets.c │ │ │ ├── fgets_u.c │ │ │ ├── fgetwc.c │ │ │ ├── fgetwc_u.c │ │ │ ├── fgetws.c │ │ │ ├── fgetws_u.c │ │ │ ├── fileno.c │ │ │ ├── fileno_u.c │ │ │ ├── findfp.c │ │ │ ├── fiprintf.c │ │ │ ├── fiscanf.c │ │ │ ├── flags.c │ │ │ ├── floatio.h │ │ │ ├── fmemopen.c │ │ │ ├── fopen.c │ │ │ ├── fopencookie.c │ │ │ ├── fprintf.c │ │ │ ├── fpurge.c │ │ │ ├── fputc.c │ │ │ ├── fputc_u.c │ │ │ ├── fputs.c │ │ │ ├── fputs_u.c │ │ │ ├── fputwc.c │ │ │ ├── fputwc_u.c │ │ │ ├── fputws.c │ │ │ ├── fputws_u.c │ │ │ ├── fread.c │ │ │ ├── fread_u.c │ │ │ ├── freopen.c │ │ │ ├── fscanf.c │ │ │ ├── fseek.c │ │ │ ├── fseeko.c │ │ │ ├── fsetlocking.c │ │ │ ├── fsetpos.c │ │ │ ├── ftell.c │ │ │ ├── ftello.c │ │ │ ├── funopen.c │ │ │ ├── fvwrite.c │ │ │ ├── fvwrite.h │ │ │ ├── fwalk.c │ │ │ ├── fwide.c │ │ │ ├── fwprintf.c │ │ │ ├── fwrite.c │ │ │ ├── fwrite_u.c │ │ │ ├── fwscanf.c │ │ │ ├── getc.c │ │ │ ├── getc_u.c │ │ │ ├── getchar.c │ │ │ ├── getchar_u.c │ │ │ ├── getdelim.c │ │ │ ├── getline.c │ │ │ ├── gets.c │ │ │ ├── getw.c │ │ │ ├── getwc.c │ │ │ ├── getwc_u.c │ │ │ ├── getwchar.c │ │ │ ├── getwchar_u.c │ │ │ ├── iprintf.c │ │ │ ├── iscanf.c │ │ │ ├── local.h │ │ │ ├── makebuf.c │ │ │ ├── mktemp.c │ │ │ ├── open_memstream.c │ │ │ ├── perror.c │ │ │ ├── printf.c │ │ │ ├── putc.c │ │ │ ├── putc_u.c │ │ │ ├── putchar.c │ │ │ ├── putchar_u.c │ │ │ ├── puts.c │ │ │ ├── putw.c │ │ │ ├── putwc.c │ │ │ ├── putwc_u.c │ │ │ ├── putwchar.c │ │ │ ├── putwchar_u.c │ │ │ ├── refill.c │ │ │ ├── remove.c │ │ │ ├── rename.c │ │ │ ├── rewind.c │ │ │ ├── rget.c │ │ │ ├── scanf.c │ │ │ ├── sccl.c │ │ │ ├── setbuf.c │ │ │ ├── setbuffer.c │ │ │ ├── setlinebuf.c │ │ │ ├── setvbuf.c │ │ │ ├── siprintf.c │ │ │ ├── siscanf.c │ │ │ ├── sniprintf.c │ │ │ ├── snprintf.c │ │ │ ├── sprintf.c │ │ │ ├── sscanf.c │ │ │ ├── stdio.c │ │ │ ├── stdio_ext.c │ │ │ ├── svfiprintf.c │ │ │ ├── svfiscanf.c │ │ │ ├── svfprintf.c │ │ │ ├── svfscanf.c │ │ │ ├── swprintf.c │ │ │ ├── swscanf.c │ │ │ ├── tmpfile.c │ │ │ ├── tmpnam.c │ │ │ ├── ungetc.c │ │ │ ├── ungetwc.c │ │ │ ├── vasiprintf.c │ │ │ ├── vasniprintf.c │ │ │ ├── vasnprintf.c │ │ │ ├── vasprintf.c │ │ │ ├── vdiprintf.c │ │ │ ├── vdprintf.c │ │ │ ├── vfieeefp.h │ │ │ ├── vfiprintf.c │ │ │ ├── vfiscanf.c │ │ │ ├── vfprintf.c │ │ │ ├── vfprintf.t │ │ │ ├── vfscanf.c │ │ │ ├── vfscanf.t │ │ │ ├── vfwprintf.c │ │ │ ├── vfwscanf.c │ │ │ ├── viprintf.c │ │ │ ├── viscanf.c │ │ │ ├── vprintf.c │ │ │ ├── vscanf.c │ │ │ ├── vsiprintf.c │ │ │ ├── vsiscanf.c │ │ │ ├── vsniprintf.c │ │ │ ├── vsnprintf.c │ │ │ ├── vsprintf.c │ │ │ ├── vsscanf.c │ │ │ ├── vswprintf.c │ │ │ ├── vswscanf.c │ │ │ ├── vwprintf.c │ │ │ ├── vwscanf.c │ │ │ ├── wbuf.c │ │ │ ├── wprintf.c │ │ │ ├── wscanf.c │ │ │ └── wsetup.c │ │ │ ├── stdlib │ │ │ ├── _Exit.c │ │ │ ├── __adjust.c │ │ │ ├── __atexit.c │ │ │ ├── __call_atexit.c │ │ │ ├── __exp10.c │ │ │ ├── __ten_mu.c │ │ │ ├── a64l.c │ │ │ ├── abort.c │ │ │ ├── abs.c │ │ │ ├── aligned_alloc.c │ │ │ ├── arc4random.c │ │ │ ├── arc4random.h │ │ │ ├── arc4random_uniform.c │ │ │ ├── assert.c │ │ │ ├── atexit.c │ │ │ ├── atexit.h │ │ │ ├── atof.c │ │ │ ├── atoff.c │ │ │ ├── atoi.c │ │ │ ├── atol.c │ │ │ ├── atoll.c │ │ │ ├── btowc.c │ │ │ ├── calloc.c │ │ │ ├── callocr.c │ │ │ ├── cfreer.c │ │ │ ├── chacha_private.h │ │ │ ├── cxa_atexit.c │ │ │ ├── cxa_finalize.c │ │ │ ├── div.c │ │ │ ├── drand48.c │ │ │ ├── dtoa.c │ │ │ ├── dtoastub.c │ │ │ ├── ecvtbuf.c │ │ │ ├── efgcvt.c │ │ │ ├── environ.c │ │ │ ├── envlock.c │ │ │ ├── eprintf.c │ │ │ ├── erand48.c │ │ │ ├── exit.c │ │ │ ├── freer.c │ │ │ ├── gdtoa-gethex.c │ │ │ ├── gdtoa-hexnan.c │ │ │ ├── gdtoa.h │ │ │ ├── getenv.c │ │ │ ├── getenv_r.c │ │ │ ├── getopt.c │ │ │ ├── getsubopt.c │ │ │ ├── imaxabs.c │ │ │ ├── imaxdiv.c │ │ │ ├── itoa.c │ │ │ ├── jrand48.c │ │ │ ├── l64a.c │ │ │ ├── labs.c │ │ │ ├── lcong48.c │ │ │ ├── ldiv.c │ │ │ ├── ldtoa.c │ │ │ ├── llabs.c │ │ │ ├── lldiv.c │ │ │ ├── local.h │ │ │ ├── lrand48.c │ │ │ ├── malign.c │ │ │ ├── malignr.c │ │ │ ├── mallinfor.c │ │ │ ├── malloc.c │ │ │ ├── mallocr.c │ │ │ ├── mallocr.t │ │ │ ├── malloptr.c │ │ │ ├── mallstatsr.c │ │ │ ├── mbctype.h │ │ │ ├── mblen.c │ │ │ ├── mblen_r.c │ │ │ ├── mbrlen.c │ │ │ ├── mbrtowc.c │ │ │ ├── mbsinit.c │ │ │ ├── mbsnrtowcs.c │ │ │ ├── mbsrtowcs.c │ │ │ ├── mbstowcs.c │ │ │ ├── mbstowcs_r.c │ │ │ ├── mbtowc.c │ │ │ ├── mbtowc_r.c │ │ │ ├── mlock.c │ │ │ ├── mprec.c │ │ │ ├── mprec.h │ │ │ ├── mrand48.c │ │ │ ├── msize.c │ │ │ ├── msizer.c │ │ │ ├── mstats.c │ │ │ ├── mtrim.c │ │ │ ├── nano-mallocr.c │ │ │ ├── nrand48.c │ │ │ ├── on_exit.c │ │ │ ├── on_exit_args.c │ │ │ ├── on_exit_args.h │ │ │ ├── putenv.c │ │ │ ├── putenv_r.c │ │ │ ├── pvallocr.c │ │ │ ├── quick_exit.c │ │ │ ├── rand.c │ │ │ ├── rand48.c │ │ │ ├── rand48.h │ │ │ ├── rand_r.c │ │ │ ├── random.c │ │ │ ├── realloc.c │ │ │ ├── reallocarray.c │ │ │ ├── reallocf.c │ │ │ ├── reallor.c │ │ │ ├── rpmatch.c │ │ │ ├── sb_charsets.c │ │ │ ├── seed48.c │ │ │ ├── setenv.c │ │ │ ├── setenv_r.c │ │ │ ├── srand48.c │ │ │ ├── std.h │ │ │ ├── strtod.c │ │ │ ├── strtodg.c │ │ │ ├── strtoimax.c │ │ │ ├── strtol.c │ │ │ ├── strtold.c │ │ │ ├── strtoll.c │ │ │ ├── strtoll_r.c │ │ │ ├── strtorx.c │ │ │ ├── strtoul.c │ │ │ ├── strtoull.c │ │ │ ├── strtoull_r.c │ │ │ ├── strtoumax.c │ │ │ ├── system.c │ │ │ ├── utoa.c │ │ │ ├── valloc.c │ │ │ ├── vallocr.c │ │ │ ├── wcrtomb.c │ │ │ ├── wcsnrtombs.c │ │ │ ├── wcsrtombs.c │ │ │ ├── wcstod.c │ │ │ ├── wcstoimax.c │ │ │ ├── wcstol.c │ │ │ ├── wcstold.c │ │ │ ├── wcstoll.c │ │ │ ├── wcstoll_r.c │ │ │ ├── wcstombs.c │ │ │ ├── wcstombs_r.c │ │ │ ├── wcstoul.c │ │ │ ├── wcstoull.c │ │ │ ├── wcstoull_r.c │ │ │ ├── wcstoumax.c │ │ │ ├── wctob.c │ │ │ ├── wctomb.c │ │ │ └── wctomb_r.c │ │ │ ├── string │ │ │ ├── ambiguous.t │ │ │ ├── bcmp.c │ │ │ ├── bcopy.c │ │ │ ├── bzero.c │ │ │ ├── combining.t │ │ │ ├── explicit_bzero.c │ │ │ ├── ffsl.c │ │ │ ├── ffsll.c │ │ │ ├── fls.c │ │ │ ├── flsl.c │ │ │ ├── flsll.c │ │ │ ├── gnu_basename.c │ │ │ ├── index.c │ │ │ ├── local.h │ │ │ ├── memccpy.c │ │ │ ├── memchr.c │ │ │ ├── memcmp.c │ │ │ ├── memcpy.c │ │ │ ├── memmem.c │ │ │ ├── memmove.c │ │ │ ├── mempcpy.c │ │ │ ├── memrchr.c │ │ │ ├── memset.c │ │ │ ├── rawmemchr.c │ │ │ ├── rindex.c │ │ │ ├── stpcpy.c │ │ │ ├── stpncpy.c │ │ │ ├── str-two-way.h │ │ │ ├── strcasecmp.c │ │ │ ├── strcasecmp_l.c │ │ │ ├── strcasestr.c │ │ │ ├── strcat.c │ │ │ ├── strchr.c │ │ │ ├── strchrnul.c │ │ │ ├── strcmp.c │ │ │ ├── strcoll.c │ │ │ ├── strcoll_l.c │ │ │ ├── strcpy.c │ │ │ ├── strcspn.c │ │ │ ├── strdup.c │ │ │ ├── strdup_r.c │ │ │ ├── strerror.c │ │ │ ├── strerror_r.c │ │ │ ├── strlcat.c │ │ │ ├── strlcpy.c │ │ │ ├── strlen.c │ │ │ ├── strlwr.c │ │ │ ├── strncasecmp.c │ │ │ ├── strncasecmp_l.c │ │ │ ├── strncat.c │ │ │ ├── strncmp.c │ │ │ ├── strncpy.c │ │ │ ├── strndup.c │ │ │ ├── strndup_r.c │ │ │ ├── strnlen.c │ │ │ ├── strnstr.c │ │ │ ├── strpbrk.c │ │ │ ├── strrchr.c │ │ │ ├── strsep.c │ │ │ ├── strsignal.c │ │ │ ├── strspn.c │ │ │ ├── strstr.c │ │ │ ├── strtok.c │ │ │ ├── strtok_r.c │ │ │ ├── strupr.c │ │ │ ├── strverscmp.c │ │ │ ├── strxfrm.c │ │ │ ├── strxfrm_l.c │ │ │ ├── swab.c │ │ │ ├── timingsafe_bcmp.c │ │ │ ├── timingsafe_memcmp.c │ │ │ ├── u_strerr.c │ │ │ ├── wcpcpy.c │ │ │ ├── wcpncpy.c │ │ │ ├── wcscasecmp.c │ │ │ ├── wcscasecmp_l.c │ │ │ ├── wcscat.c │ │ │ ├── wcschr.c │ │ │ ├── wcscmp.c │ │ │ ├── wcscoll.c │ │ │ ├── wcscoll_l.c │ │ │ ├── wcscpy.c │ │ │ ├── wcscspn.c │ │ │ ├── wcsdup.c │ │ │ ├── wcslcat.c │ │ │ ├── wcslcpy.c │ │ │ ├── wcslen.c │ │ │ ├── wcsncasecmp.c │ │ │ ├── wcsncasecmp_l.c │ │ │ ├── wcsncat.c │ │ │ ├── wcsncmp.c │ │ │ ├── wcsncpy.c │ │ │ ├── wcsnlen.c │ │ │ ├── wcspbrk.c │ │ │ ├── wcsrchr.c │ │ │ ├── wcsspn.c │ │ │ ├── wcsstr.c │ │ │ ├── wcstok.c │ │ │ ├── wcswidth.c │ │ │ ├── wcsxfrm.c │ │ │ ├── wcsxfrm_l.c │ │ │ ├── wcwidth.c │ │ │ ├── wide.t │ │ │ ├── wmemchr.c │ │ │ ├── wmemcmp.c │ │ │ ├── wmemcpy.c │ │ │ ├── wmemmove.c │ │ │ ├── wmempcpy.c │ │ │ ├── wmemset.c │ │ │ └── xpg_strerror_r.c │ │ │ ├── syscalls │ │ │ ├── sysclose.c │ │ │ ├── sysexecve.c │ │ │ ├── sysfcntl.c │ │ │ ├── sysfork.c │ │ │ ├── sysfstat.c │ │ │ ├── sysgetpid.c │ │ │ ├── sysgettod.c │ │ │ ├── sysisatty.c │ │ │ ├── syskill.c │ │ │ ├── syslink.c │ │ │ ├── syslseek.c │ │ │ ├── sysopen.c │ │ │ ├── sysread.c │ │ │ ├── syssbrk.c │ │ │ ├── sysstat.c │ │ │ ├── systimes.c │ │ │ ├── sysunlink.c │ │ │ ├── syswait.c │ │ │ └── syswrite.c │ │ │ ├── time │ │ │ ├── asctime.c │ │ │ ├── asctime_r.c │ │ │ ├── clock.c │ │ │ ├── ctime.c │ │ │ ├── ctime_r.c │ │ │ ├── difftime.c │ │ │ ├── gettzinfo.c │ │ │ ├── gmtime.c │ │ │ ├── gmtime_r.c │ │ │ ├── lcltime.c │ │ │ ├── lcltime_r.c │ │ │ ├── local.h │ │ │ ├── mktime.c │ │ │ ├── month_lengths.c │ │ │ ├── strftime.c │ │ │ ├── strptime.c │ │ │ ├── time.c │ │ │ ├── tzcalc_limits.c │ │ │ ├── tzlock.c │ │ │ ├── tzset.c │ │ │ ├── tzset_r.c │ │ │ ├── tzvars.c │ │ │ └── wcsftime.c │ │ │ └── unix │ │ │ ├── basename.c │ │ │ ├── dirname.c │ │ │ ├── getcwd.c │ │ │ ├── getlogin.c │ │ │ ├── getpass.c │ │ │ ├── getpwent.c │ │ │ ├── getut.c │ │ │ ├── pread.c │ │ │ ├── pwrite.c │ │ │ ├── sigset.c │ │ │ ├── ttyname.c │ │ │ ├── ttyname.h │ │ │ └── ttyname_r.c │ ├── libfont │ │ ├── Makefile │ │ ├── fonts │ │ │ ├── convert │ │ │ └── courier_10_pitch.ttf │ │ ├── include │ │ │ └── font.h │ │ └── src │ │ │ └── font.cpp │ ├── libndl │ │ ├── Makefile │ │ ├── include │ │ │ └── ndl.h │ │ └── src │ │ │ ├── bmp.c │ │ │ └── ndl.c │ └── libos │ │ ├── Makefile │ │ ├── README.md │ │ └── src │ │ ├── nanos.c │ │ ├── native.cpp │ │ └── syscall.h └── tests │ ├── bmp │ ├── Makefile │ └── main.cpp │ ├── dummy │ ├── Makefile │ └── dummy.c │ ├── events │ ├── Makefile │ └── events.c │ ├── hello │ ├── Makefile │ └── hello.c │ └── text │ ├── Makefile │ └── text.c ├── nemu ├── .code.c ├── .gitignore ├── Makefile ├── Makefile.git ├── README.md ├── include │ ├── common.h │ ├── cpu │ │ ├── cc.h │ │ ├── decode.h │ │ ├── exec.h │ │ ├── reg.h │ │ ├── relop.h │ │ ├── rtl-wrapper.h │ │ └── rtl.h │ ├── debug.h │ ├── device │ │ ├── mmio.h │ │ └── port-io.h │ ├── macro.h │ ├── memory │ │ ├── memory.h │ │ └── mmu.h │ ├── monitor │ │ ├── expr.h │ │ ├── monitor.h │ │ └── watchpoint.h │ ├── nemu.h │ └── util │ │ └── c_op.h ├── runall.sh ├── src │ ├── cpu │ │ ├── decode │ │ │ ├── decode.c │ │ │ └── modrm.c │ │ ├── exec │ │ │ ├── all-instr.h │ │ │ ├── arith.c │ │ │ ├── cc.c │ │ │ ├── control.c │ │ │ ├── data-mov.c │ │ │ ├── exec.c │ │ │ ├── logic.c │ │ │ ├── prefix.c │ │ │ ├── relop.c │ │ │ ├── special.c │ │ │ └── system.c │ │ ├── intr.c │ │ └── reg.c │ ├── device │ │ ├── device.c │ │ ├── io │ │ │ ├── mmio.c │ │ │ └── port-io.c │ │ ├── keyboard.c │ │ ├── serial.c │ │ ├── timer.c │ │ └── vga.c │ ├── main.c │ ├── memory │ │ └── memory.c │ ├── misc │ │ └── logo.c │ └── monitor │ │ ├── cpu-exec.c │ │ ├── debug │ │ ├── expr.c │ │ ├── ui.c │ │ └── watchpoint.c │ │ ├── diff-test │ │ ├── diff-test.c │ │ ├── diff-test.h │ │ └── ref.c │ │ └── monitor.c ├── test.c └── tools │ ├── gen-expr │ ├── .gitignore │ ├── Makefile │ ├── gen-expr.c │ └── test.c │ └── qemu-diff │ ├── Makefile │ ├── include │ ├── common.h │ └── protocol.h │ └── src │ ├── diff-test.c │ ├── gdb-host.c │ └── protocol.c ├── nexus-am ├── .gitignore ├── Makefile ├── Makefile.app ├── Makefile.check ├── Makefile.compile ├── Makefile.lib ├── README.md ├── am │ ├── Makefile │ ├── am.h │ ├── amdev.h │ ├── amtrace.h │ └── arch │ │ ├── am_native-navy │ │ ├── native │ │ ├── README.md │ │ ├── img │ │ │ ├── build │ │ │ └── run │ │ ├── include │ │ │ └── arch.h │ │ └── src │ │ │ ├── cte.c │ │ │ ├── dev │ │ │ ├── input.c │ │ │ ├── timer.c │ │ │ └── video.c │ │ │ ├── ioe.c │ │ │ ├── platform.cpp │ │ │ ├── trap.S │ │ │ ├── trm.c │ │ │ └── vme.c │ │ ├── x86-navy │ │ ├── README.md │ │ ├── img │ │ │ ├── Makefile.navy │ │ │ ├── build │ │ │ └── run │ │ ├── include │ │ │ └── arch.h │ │ └── src │ │ │ └── trm.c │ │ └── x86-nemu │ │ ├── README.md │ │ ├── img │ │ ├── boot │ │ │ ├── Makefile │ │ │ └── start.S │ │ ├── build │ │ ├── loader.ld │ │ └── run │ │ ├── include │ │ ├── arch.h │ │ ├── x86-nemu.h │ │ └── x86.h │ │ └── src │ │ ├── cte.c │ │ ├── devices │ │ ├── input.c │ │ ├── timer.c │ │ └── video.c │ │ ├── ioe.c │ │ ├── trap.S │ │ ├── trm.c │ │ └── vme.c ├── apps │ ├── coremark │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ ├── core_portme.h │ │ │ └── coremark.h │ │ └── src │ │ │ ├── core_list_join.c │ │ │ ├── core_main.c │ │ │ ├── core_matrix.c │ │ │ ├── core_portme.c │ │ │ ├── core_state.c │ │ │ └── core_util.c │ ├── dhrystone │ │ ├── Makefile │ │ └── dry.c │ ├── hello │ │ ├── Makefile │ │ ├── README.md │ │ └── hello.c │ ├── litenes │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ ├── common.h │ │ │ ├── cpu.h │ │ │ ├── fce.h │ │ │ ├── memory.h │ │ │ ├── mmc.h │ │ │ ├── ppu.h │ │ │ └── psg.h │ │ └── src │ │ │ ├── common.c │ │ │ ├── cpu-addressing.c │ │ │ ├── cpu.c │ │ │ ├── fce.c │ │ │ ├── mmc.c │ │ │ ├── ppu.c │ │ │ ├── psg.c │ │ │ └── rom_mario.c │ ├── microbench │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ └── benchmark.h │ │ └── src │ │ │ ├── 15pz │ │ │ ├── 15pz.cpp │ │ │ ├── heap.h │ │ │ └── puzzle.h │ │ │ ├── bench.c │ │ │ ├── bf │ │ │ └── bf.c │ │ │ ├── dinic │ │ │ └── dinic.cpp │ │ │ ├── fib │ │ │ └── fib.c │ │ │ ├── lzip │ │ │ ├── lzip.c │ │ │ ├── quicklz.c │ │ │ └── quicklz.h │ │ │ ├── md5 │ │ │ └── md5.c │ │ │ ├── qsort │ │ │ └── qsort.c │ │ │ ├── queen │ │ │ └── queen.c │ │ │ ├── sieve │ │ │ └── sieve.c │ │ │ └── ssort │ │ │ └── ssort.cpp │ ├── slider │ │ ├── Makefile │ │ ├── image.S │ │ ├── images │ │ │ ├── litenes.bin │ │ │ └── projectn.bin │ │ └── main.cpp │ └── typing │ │ ├── Makefile │ │ ├── README.md │ │ ├── draw.c │ │ ├── font.c │ │ ├── game.c │ │ ├── game.h │ │ └── keyboard.c ├── docs │ ├── .gitignore │ ├── Makefile │ ├── README.md │ └── src │ │ ├── 00-preface │ │ └── preface.md │ │ ├── 01-C.md │ │ ├── 02-motivation.md │ │ ├── 03-hw-program.md │ │ ├── 04-fun-with-io.md │ │ ├── 05-context.md │ │ └── title.txt ├── libs │ ├── compiler-rt │ │ ├── Makefile │ │ ├── divdi3.c │ │ ├── divmoddi4.c │ │ ├── int_endianness.h │ │ ├── int_lib.h │ │ ├── int_types.h │ │ ├── int_util.h │ │ ├── moddi3.c │ │ ├── udivdi3.c │ │ ├── udivmoddi4.c │ │ └── umoddi3.c │ ├── fixmath │ │ ├── Makefile │ │ ├── README.md │ │ ├── include │ │ │ ├── fix16.h │ │ │ ├── fix16.hpp │ │ │ ├── fix16_trig_sin_lut.h │ │ │ ├── fixmath.h │ │ │ ├── fract32.h │ │ │ ├── int64.h │ │ │ └── uint32.h │ │ └── src │ │ │ ├── fix16.c │ │ │ ├── fix16_exp.c │ │ │ ├── fix16_sqrt.c │ │ │ ├── fix16_str.c │ │ │ ├── fix16_trig.c │ │ │ ├── fract32.c │ │ │ └── uint32.c │ ├── imgui │ │ ├── Makefile │ │ ├── include │ │ │ ├── imconfig.h │ │ │ ├── imgui.h │ │ │ ├── imgui_internal.h │ │ │ ├── stb_rect_pack.h │ │ │ ├── stb_textedit.h │ │ │ └── stb_truetype.h │ │ └── src │ │ │ ├── imgui.cpp │ │ │ ├── imgui_demo.cpp │ │ │ └── imgui_draw.cpp │ └── klib │ │ ├── Makefile │ │ ├── include │ │ └── klib.h │ │ └── src │ │ ├── cpp.c │ │ ├── io.c │ │ ├── stdio.c │ │ ├── stdlib.c │ │ └── string.c └── tests │ ├── cachetest │ ├── Makefile │ └── tests │ │ ├── access-cache.c │ │ ├── access.c │ │ ├── cache-flush.c │ │ └── pingpong.c │ ├── cputest │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── include │ │ └── trap.h │ └── tests │ │ ├── add-longlong.c │ │ ├── add.c │ │ ├── bit.c │ │ ├── bubble-sort.c │ │ ├── div.c │ │ ├── dummy.c │ │ ├── fact.c │ │ ├── fib.c │ │ ├── goldbach.c │ │ ├── hello-str.c │ │ ├── if-else.c │ │ ├── leap-year.c │ │ ├── load-store.c │ │ ├── matrix-mul.c │ │ ├── max.c │ │ ├── min3.c │ │ ├── mov-c.c │ │ ├── movsx.c │ │ ├── mul-longlong.c │ │ ├── pascal.c │ │ ├── prime.c │ │ ├── quick-sort.c │ │ ├── recursion.c │ │ ├── select-sort.c │ │ ├── shift.c │ │ ├── shuixianhua.c │ │ ├── string.c │ │ ├── sub-longlong.c │ │ ├── sum.c │ │ ├── switch.c │ │ ├── to-lower-case.c │ │ ├── unalign.c │ │ └── wanshu.c │ ├── ctetest │ ├── Makefile │ └── main.c │ ├── floattest │ ├── Makefile │ └── main.cpp │ ├── fuzz │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── instgen.py │ ├── run │ └── trap.h │ ├── guitest │ ├── Makefile │ └── guitest.cpp │ ├── ioetest │ ├── Makefile │ └── main.c │ ├── keytest │ ├── Makefile │ └── main.cpp │ ├── mipstest │ ├── Makefile │ ├── include │ │ └── trap.h │ └── tests │ │ └── clz.c │ ├── mptest │ ├── Makefile │ ├── dbg.txt │ ├── debug │ ├── main.c │ └── run │ ├── segmenttest │ ├── Makefile │ ├── initrd.S │ └── main.c │ ├── timetest │ ├── Makefile │ └── main.c │ ├── tracetest │ ├── Makefile │ ├── main.c │ └── run │ ├── videotest │ ├── Makefile │ └── main.cpp │ └── vmtest │ ├── Makefile │ ├── dbg.txt │ ├── debug │ └── main.c ├── recover.sh ├── setup.sh └── submit.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.* 2 | * 3 | !*/ 4 | !Makefile 5 | !README.md 6 | !.gitignore 7 | !init.sh 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | include nemu/Makefile.git 2 | 3 | default: 4 | @echo "Please run 'make' under any subprojects to compile." 5 | 6 | clean: 7 | -$(MAKE) -C nemu clean 8 | -$(MAKE) -C nexus-am clean 9 | -$(MAKE) -C nanos-lite clean 10 | -$(MAKE) -C navy-apps clean 11 | 12 | submit: clean 13 | git gc 14 | STUID=$(STUID) STUNAME=$(STUNAME) bash submit.sh 15 | 16 | setup: 17 | STUID=$(STUID) STUNAME=$(STUNAME) bash setup.sh 18 | 19 | recover: 20 | STUID=$(STUID) STUNAME=$(STUNAME) bash recover.sh 21 | 22 | 23 | .PHONY: default clean submit 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ICS2018 Programming Assignment 2 | 3 | This project is the programming assignment of the class ICS(Introduction to Computer System) in Department of Computer Science and Technology, Nanjing University. 4 | 5 | For the guide of this programming assignment, 6 | refer to http://nju-ics.gitbooks.io/ics2018-programming-assignment/content/ 7 | 8 | To initialize, run 9 | ```bash 10 | bash init.sh 11 | ``` 12 | 13 | The following subprojects/components are included. Some of them are not fully implemented. 14 | * [NEMU](https://github.com/NJU-ProjectN/nemu) 15 | * [Nexus-am](https://github.com/NJU-ProjectN/nexus-am) 16 | * [Nanos-lite](https://github.com/NJU-ProjectN/nanos-lite) 17 | * [Navy-apps](https://github.com/NJU-ProjectN/navy-apps) 18 | -------------------------------------------------------------------------------- /nanos-lite/.gitignore: -------------------------------------------------------------------------------- 1 | *.* 2 | * 3 | !*/ 4 | !Makefile* 5 | !*.[cSh] 6 | !.gitignore 7 | !README.md 8 | -------------------------------------------------------------------------------- /nanos-lite/README.md: -------------------------------------------------------------------------------- 1 | # Nanos-lite 2 | 3 | Nanos-lite is the simplified version of Nanos (http://cslab.nju.edu.cn/opsystem). 4 | It is ported to the [AM project](https://github.com/NJU-ProjectN/nexus-am.git). 5 | It is a two-tasking operating system with the following features 6 | * ramdisk device drivers 7 | * raw program loader 8 | * memory management with paging 9 | * a simple file system 10 | * with fix number and size of files 11 | * without directory 12 | * some device files 13 | * 8 system calls 14 | * open, read, write, lseek, close, brk, exit, execve 15 | * scheduler with two tasks 16 | -------------------------------------------------------------------------------- /nanos-lite/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | /* Uncomment these macros to enable corresponding functionality. */ 5 | #define HAS_CTE 6 | #define HAS_VME 7 | 8 | #include 9 | #include 10 | #include "debug.h" 11 | #include "unistd.h" 12 | 13 | typedef char bool; 14 | #define true 1 15 | #define false 0 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nanos-lite/include/debug.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H__ 2 | #define __DEBUG_H__ 3 | 4 | #include "common.h" 5 | 6 | #define Log(format, ...) \ 7 | printf("\33[1;35m[%s,%d,%s] " format "\33[0m\n", \ 8 | __FILE__, __LINE__, __func__, ## __VA_ARGS__) 9 | 10 | #define panic(format, ...) \ 11 | do { \ 12 | Log("\33[1;31msystem panic: " format, ## __VA_ARGS__); \ 13 | _halt(1); \ 14 | } while (0) 15 | 16 | #ifdef assert 17 | # undef assert 18 | #endif 19 | 20 | #define assert(cond) \ 21 | do { \ 22 | if (!(cond)) { \ 23 | panic("Assertion failed: %s", #cond); \ 24 | } \ 25 | } while (0) 26 | 27 | #define TODO() panic("please implement me") 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /nanos-lite/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_H__ 2 | #define __MEMORY_H__ 3 | 4 | #include "common.h" 5 | 6 | #ifndef PGSIZE 7 | #define PGSIZE 4096 8 | #endif 9 | 10 | #define PG_ALIGN __attribute((aligned(PGSIZE))) 11 | 12 | #define PGMASK (PGSIZE - 1) // Mask for bit ops 13 | #define PGROUNDUP(sz) (((sz)+PGSIZE-1) & ~PGMASK) 14 | #define PGROUNDDOWN(a) (((a)) & ~PGMASK) 15 | 16 | void* new_page(size_t); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /nanos-lite/include/proc.h: -------------------------------------------------------------------------------- 1 | #ifndef __PROC_H__ 2 | #define __PROC_H__ 3 | 4 | #include "common.h" 5 | #include "memory.h" 6 | 7 | #define STACK_SIZE (8 * PGSIZE) 8 | 9 | typedef union { 10 | uint8_t stack[STACK_SIZE] PG_ALIGN; 11 | struct { 12 | _Context *cp; 13 | _Protect as; 14 | uintptr_t cur_brk; 15 | // we do not free memory, so use `max_brk' to determine when to call _map() 16 | uintptr_t max_brk; 17 | }; 18 | } PCB; 19 | 20 | extern PCB *current, *fg_pcb; 21 | extern PCB *pcbs[4]; 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /nanos-lite/src/.gitignore: -------------------------------------------------------------------------------- 1 | files.h 2 | syscall.h 3 | -------------------------------------------------------------------------------- /nanos-lite/src/initrd.S: -------------------------------------------------------------------------------- 1 | .section .data 2 | .global ramdisk_start, ramdisk_end 3 | ramdisk_start: 4 | .incbin "build/ramdisk.img" 5 | ramdisk_end: 6 | -------------------------------------------------------------------------------- /nanos-lite/src/irq.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | _Context* do_syscall(_Context *c); 4 | _Context* schedule(_Context *prev); 5 | 6 | static _Context* do_event(_Event e, _Context* c) { 7 | // printf("event: %d\n", e.event); 8 | switch (e.event) { 9 | case _EVENT_IRQ_TIMER: _yield(); break; 10 | case _EVENT_YIELD: return schedule(c); 11 | case _EVENT_SYSCALL: do_syscall(c); return NULL; 12 | default: panic("Unhandled event ID = %d", e.event); 13 | } 14 | 15 | return NULL; 16 | } 17 | 18 | void init_irq(void) { 19 | Log("Initializing interrupt/exception handler..."); 20 | _cte_init(do_event); 21 | } 22 | -------------------------------------------------------------------------------- /nanos-lite/src/main.c: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | void init_mm(void); 4 | void init_ramdisk(void); 5 | void init_device(void); 6 | void init_irq(void); 7 | void init_fs(void); 8 | void init_proc(void); 9 | 10 | int main() { 11 | #ifdef HAS_VME 12 | init_mm(); 13 | #endif 14 | 15 | Log("'Hello World!' from Nanos-lite"); 16 | Log("Build time: %s, %s", __TIME__, __DATE__); 17 | 18 | init_ramdisk(); 19 | 20 | init_device(); 21 | 22 | #ifdef HAS_CTE 23 | init_irq(); 24 | #endif 25 | 26 | init_fs(); 27 | 28 | init_proc(); 29 | 30 | #ifdef HAS_CTE 31 | _yield(); 32 | #endif 33 | 34 | panic("Should not reach here"); 35 | } 36 | -------------------------------------------------------------------------------- /navy-apps/.gitignore: -------------------------------------------------------------------------------- 1 | !* 2 | !*.* 3 | .* 4 | !.gitignore 5 | *.o 6 | *.a 7 | *.d 8 | *.img 9 | build/ 10 | /fsimg/bin/ 11 | /fsimg/dev/ 12 | /fsimg/share/games/pal/ 13 | -------------------------------------------------------------------------------- /navy-apps/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.check 2 | 3 | APPS = init pal litenes slider 4 | TESTS = bmp dummy events hello text 5 | 6 | APPS_ALL = $(addprefix $(NAVY_HOME)/apps/, $(APPS)) $(addprefix $(NAVY_HOME)/tests/, $(TESTS)) 7 | 8 | .PHONY: fsimg $(APPS_ALL) clean 9 | 10 | fsimg: $(APPS_ALL) 11 | 12 | $(APPS_ALL): %: 13 | -$(MAKE) -C $@ install 14 | 15 | clean: 16 | $(foreach app, $(APPS_ALL), $(MAKE) -C $(app) clean ;) 17 | $(foreach lib, $(shell ls libs/), $(MAKE) -C $(NAVY_HOME)/libs/$(lib) clean ;) 18 | rm -f fsimg/bin/* 19 | -------------------------------------------------------------------------------- /navy-apps/Makefile.check: -------------------------------------------------------------------------------- 1 | ISA ?= native 2 | ifeq ($(NAVY_HOME), ) 3 | $(error Must set NAVY_HOME environment variable) 4 | endif 5 | 6 | $(shell mkdir -p $(NAVY_HOME)/fsimg/bin/ $(NAVY_HOME)/fsimg/dev/) 7 | -------------------------------------------------------------------------------- /navy-apps/Makefile.lib: -------------------------------------------------------------------------------- 1 | include $(NAVY_HOME)/Makefile.check 2 | 3 | LIB_DIR ?= $(shell pwd) 4 | INC_DIR += $(LIB_DIR)/include/ 5 | DST_DIR ?= $(LIB_DIR)/build/$(ISA)/ 6 | ARCHIVE ?= $(LIB_DIR)/build/$(NAME)-$(ISA).a 7 | 8 | .DEFAULT_GOAL = $(ARCHIVE) 9 | 10 | ifneq ($(ISA), native) 11 | LIBS += libc 12 | endif 13 | INC_DIR += $(addsuffix /include/, $(addprefix $(NAVY_HOME)/libs/, $(LIBS))) 14 | 15 | $(shell mkdir -p $(DST_DIR)) 16 | 17 | include $(NAVY_HOME)/Makefile.compile 18 | 19 | $(ARCHIVE): $(OBJS) 20 | @echo + AR $@ 21 | @ar rcs $(ARCHIVE) $(OBJS) 22 | 23 | .PHONY: clean 24 | clean: 25 | rm -rf $(LIB_DIR)/build/ 26 | -------------------------------------------------------------------------------- /navy-apps/apps/am-apps/Makefile: -------------------------------------------------------------------------------- 1 | include $(NAVY_HOME)/Makefile.check 2 | 3 | APPS = coremark dhrystone hello microbench slider typing litenes 4 | TESTS = videotest 5 | 6 | APPS_ALL = $(addprefix $(AM_HOME)/apps/, $(APPS)) $(addprefix $(AM_HOME)/tests/, $(TESTS)) 7 | 8 | install: $(APPS_ALL) 9 | 10 | .PHONY: $(APPS_ALL) clean 11 | 12 | $(APPS_ALL): %: 13 | -$(MAKE) -C $@ ARCH=$(ISA)-navy 14 | 15 | clean: 16 | $(foreach app, $(APPS_ALL), $(MAKE) -C ARCH=$(ISA)-navy clean ;) 17 | -------------------------------------------------------------------------------- /navy-apps/apps/init/Makefile: -------------------------------------------------------------------------------- 1 | NAME = init 2 | SRCS = init.cpp 3 | LIBS += libndl libfont 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/Makefile: -------------------------------------------------------------------------------- 1 | NAME = litenes 2 | SRCS = $(shell find src/ -name "*.c") 3 | LIBS += libndl 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/include/fce.h: -------------------------------------------------------------------------------- 1 | #ifndef FCE_H 2 | #define FCE_H 3 | 4 | #include 5 | 6 | #define FPS 60 7 | #define W 256 8 | #define H 240 9 | 10 | extern byte canvas[H][W]; 11 | 12 | void fce_update_screen(); 13 | 14 | extern char rom_mario_nes[]; 15 | extern char rom_kungfu_nes[]; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef MEM_H 2 | #define MEM_H 3 | 4 | #include "common.h" 5 | #include "mmc.h" 6 | 7 | // Single byte 8 | byte memory_readb(word address); 9 | void memory_writeb(word address, byte data); 10 | 11 | // Two bytes (word), LSB first 12 | word memory_readw(word address); 13 | void memory_writew(word address, word data); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/include/mmc.h: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | byte mmc_read(word address); 4 | void mmc_write(word address, byte data); 5 | void mmc_copy(word address, byte *source, int length); 6 | void mmc_append_chr_rom_page(byte *source); 7 | 8 | extern byte mmc_id; 9 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/include/psg.h: -------------------------------------------------------------------------------- 1 | // #define psg_io_read(...) 0xFF 2 | // #define psg_io_write(...) /**/ 3 | 4 | #include "common.h" 5 | 6 | #ifndef PSG_H 7 | #define PSG_H 8 | 9 | extern unsigned char psg_joy1[8]; 10 | 11 | byte psg_io_read(word address); 12 | void psg_io_write(word address, byte data); 13 | 14 | #endif -------------------------------------------------------------------------------- /navy-apps/apps/litenes/src/mmc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MMC_MAX_PAGE_COUNT 1 6 | 7 | byte mmc_id; 8 | 9 | byte mmc_chr_pages[MMC_MAX_PAGE_COUNT][0x2000]; 10 | int mmc_chr_pages_number; 11 | 12 | byte memory[0x10000]; 13 | 14 | inline byte mmc_read(word address) 15 | { 16 | return memory[address]; 17 | } 18 | 19 | inline void mmc_write(word address, byte data) 20 | { 21 | memory[address] = data; 22 | } 23 | 24 | inline void mmc_copy(word address, byte *source, int length) 25 | { 26 | memcpy(&memory[address], source, length); 27 | } 28 | 29 | inline void mmc_append_chr_rom_page(byte *source) 30 | { 31 | memcpy(&mmc_chr_pages[mmc_chr_pages_number++][0], source, 0x2000); 32 | } 33 | -------------------------------------------------------------------------------- /navy-apps/apps/litenes/src/psg.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static byte prev_write; 4 | static int p = 10; 5 | int keydown[10]; 6 | 7 | inline byte psg_io_read(word address) 8 | { 9 | // Joystick 1 10 | if (address == 0x4016) { 11 | if (p++ < 9) { 12 | return keydown[p]; 13 | // p | 1 2 3 4 5 6 7 8 14 | // key | A B SELECT START UP DOWN LEFT RIGHT 15 | return 0; 16 | } 17 | } 18 | return 0; 19 | } 20 | 21 | inline void psg_io_write(word address, byte data) 22 | { 23 | if (address == 0x4016) { 24 | if ((data & 1) == 0 && prev_write == 1) { 25 | // strobe 26 | p = 0; 27 | } 28 | } 29 | prev_write = data & 1; 30 | } 31 | -------------------------------------------------------------------------------- /navy-apps/apps/lua/Makefile: -------------------------------------------------------------------------------- 1 | NAME = lua 2 | SRCS = $(shell find src/ -name "*.c") 3 | CFLAGS += -DLUA_USE_C89 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/lua/include/lapi.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** $Id: lapi.h,v 2.9 2015/03/06 19:49:50 roberto Exp $ 3 | ** Auxiliary functions from Lua API 4 | ** See Copyright Notice in lua.h 5 | */ 6 | 7 | #ifndef lapi_h 8 | #define lapi_h 9 | 10 | 11 | #include "llimits.h" 12 | #include "lstate.h" 13 | 14 | #define api_incr_top(L) {L->top++; api_check(L, L->top <= L->ci->top, \ 15 | "stack overflow");} 16 | 17 | #define adjustresults(L,nres) \ 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } 19 | 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ 21 | "not enough elements in the stack") 22 | 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /navy-apps/apps/nterm/Makefile: -------------------------------------------------------------------------------- 1 | NAME = nterm 2 | SRCS = src/main.cpp src/term.cpp 3 | LIBS += libfont libndl 4 | 5 | export NWM_APP 6 | include $(NAVY_HOME)/Makefile.app 7 | -------------------------------------------------------------------------------- /navy-apps/apps/nwm/Makefile: -------------------------------------------------------------------------------- 1 | NAME = nwm 2 | SRCS = $(shell find src/ -name "*.c" -o -name "*.cpp") 3 | LIBS += libfont 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/Makefile: -------------------------------------------------------------------------------- 1 | NAME = pal 2 | SRCS = $(shell find src/ -name "*.c") 3 | LIBS += libndl 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/README.md: -------------------------------------------------------------------------------- 1 | # PAL 2 | 3 | This is a fork of Wei Mingzhi's SDLPAL(https://github.com/CecilHarvey/sdlpal). 4 | It is ported to Navy-apps. 5 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/include/FLOAT.h: -------------------------------------------------------------------------------- 1 | #ifndef __FLOAT_H__ 2 | #define __FLOAT_H__ 3 | 4 | typedef int FLOAT; 5 | 6 | static inline int F2int(FLOAT a) { 7 | return (a >> 16); 8 | } 9 | 10 | static inline FLOAT int2F(int a) { 11 | return (a << 16); 12 | } 13 | 14 | static inline FLOAT F_mul_int(FLOAT a, int b) { 15 | return a * b; 16 | } 17 | 18 | static inline FLOAT F_div_int(FLOAT a, int b) { 19 | return a / b; 20 | } 21 | 22 | FLOAT f2F(float); 23 | FLOAT F_mul_F(FLOAT, FLOAT); 24 | FLOAT F_div_F(FLOAT, FLOAT); 25 | FLOAT Fabs(FLOAT); 26 | FLOAT Fsqrt(FLOAT); 27 | FLOAT Fpow(FLOAT, FLOAT); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | #include 5 | #include 6 | 7 | typedef uint8_t bool; 8 | 9 | #define true 1 10 | #define false 0 11 | 12 | #define Log(args...) do { fprintf(stderr, args); fprintf(stderr, "\n"); } while (0) 13 | 14 | void SDL_WaitUntil(uint32_t tick); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/src/pal-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main_loop(); 4 | void hal_init(); 5 | 6 | int 7 | main(void) { 8 | Log("game start!"); 9 | 10 | hal_init(); 11 | main_loop(); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/apps/pal/src/unuse/sdl.c: -------------------------------------------------------------------------------- 1 | #include "hal.h" 2 | 3 | int SDL_PollEvent(SDL_Event *event) { 4 | return 0; 5 | } 6 | 7 | int SDL_LockSurface(SDL_Surface *surface) { 8 | return 0; 9 | } 10 | 11 | void SDL_UnlockSurface(SDL_Surface *surface) { 12 | } 13 | 14 | int SDL_ShowCursor(int toggle) { 15 | return 0; 16 | } 17 | 18 | int SDL_SaveBMP(SDL_Surface *surface, const char *file) { 19 | return 0; 20 | } 21 | 22 | int SDL_Init(uint32_t flags) { 23 | return 0; 24 | } 25 | 26 | char *SDL_GetError(void) { 27 | static char msg[] = "SDL_GetError is not implemented"; 28 | return msg; 29 | } 30 | 31 | void SDL_WM_SetCaption(const char *title, const char *icon) { 32 | return; 33 | } 34 | 35 | void SDL_Quit(void) { 36 | return; 37 | } 38 | -------------------------------------------------------------------------------- /navy-apps/apps/slider/Makefile: -------------------------------------------------------------------------------- 1 | NAME = slider 2 | SRCS = $(shell find src/ -name "*.c" -o -name "*.cpp") 3 | LIBS += libndl 4 | 5 | include $(NAVY_HOME)/Makefile.app 6 | -------------------------------------------------------------------------------- /navy-apps/apps/slider/README.md: -------------------------------------------------------------------------------- 1 | # Slider 2 | 3 | 1. copy slides.pdf to `slides/` 4 | 2. run `convert.sh` 5 | -------------------------------------------------------------------------------- /navy-apps/apps/slider/slides/.gitignore: -------------------------------------------------------------------------------- 1 | *.bmp 2 | *.pdf 3 | -------------------------------------------------------------------------------- /navy-apps/apps/slider/slides/convert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | convert slides.pdf \ 4 | -sharpen "0x1.0" \ 5 | -type truecolor -resize 400x300 slides.bmp 6 | 7 | mkdir -p $NAVY_HOME/fsimg/share/slides/ 8 | cp *.bmp $NAVY_HOME/fsimg/share/slides/ 9 | -------------------------------------------------------------------------------- /navy-apps/apps/typing/Makefile: -------------------------------------------------------------------------------- 1 | NAME = typing 2 | SRCS = game.c draw.c font.c keyboard.c 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /navy-apps/apps/typing/README.md: -------------------------------------------------------------------------------- 1 | # Typing Game 2 | 3 | 最简单的打字小游戏。 4 | 5 | 这是[NJU 2013 oslab0的演示游戏](https://github.com/NJU-ProjectN/os-lab0)的AM移植版本。 6 | 需要正确的IOE (计时、绘图、键盘)。 7 | -------------------------------------------------------------------------------- /navy-apps/fsimg/etc/init: -------------------------------------------------------------------------------- 1 | #!/bin/init 2 | -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/nes/battlecity.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/nes/battlecity.nes -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/nes/circus.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/nes/circus.nes -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/nes/kungfu.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/nes/kungfu.nes -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/nes/loderunner.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/nes/loderunner.nes -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/nes/mario.nes: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/nes/mario.nes -------------------------------------------------------------------------------- /navy-apps/fsimg/share/games/pal.tbz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/games/pal.tbz -------------------------------------------------------------------------------- /navy-apps/fsimg/share/pictures/projectn.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/fsimg/share/pictures/projectn.bmp -------------------------------------------------------------------------------- /navy-apps/libs/libc/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libc 2 | SRCS = $(shell find src/ -name "*.c" -o -name "*.S" -o -name "*.cpp") 3 | 4 | # fix compilation in ubuntu 16.04 5 | CFLAGS = -U_FORTIFY_SOURCE 6 | 7 | include $(NAVY_HOME)/Makefile.lib 8 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/_newlib_version.h: -------------------------------------------------------------------------------- 1 | /* dummy file for external tools to use. Real file is created by 2 | newlib configuration. */ 3 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 * alloca (size_t); 19 | #endif 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/dirent.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIRENT_H_ 2 | #define _DIRENT_H_ 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | #include 7 | #include 8 | 9 | #if !defined(MAXNAMLEN) && __BSD_VISIBLE 10 | #define MAXNAMLEN 1024 11 | #endif 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | #endif /*_DIRENT_H_*/ 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 __env_lock (struct _reent *reent); 13 | void __env_unlock (struct _reent *reent); 14 | 15 | #endif /* _INCLUDE_ENVLOCK_H_ */ 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/_arc4random.h: -------------------------------------------------------------------------------- 1 | /* Use default implementation, see arc4random.h */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/_time.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TIME_H_ 2 | #error "must be included via " 3 | #endif /* !_SYS_TIME_H_ */ 4 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $Id$ 3 | */ 4 | 5 | #ifndef _MACHINE__TYPES_H 6 | #define _MACHINE__TYPES_H 7 | #include 8 | #endif 9 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/ansi.h: -------------------------------------------------------------------------------- 1 | /* dummy header file to support BSD compiler */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/param.h: -------------------------------------------------------------------------------- 1 | /* Place holder for machine-specific param.h. */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/termios.h: -------------------------------------------------------------------------------- 1 | #define __MAX_BAUD B4000000 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACHTIME_H_ 2 | #define _MACHTIME_H_ 3 | 4 | #if defined(__rtems__) || defined(__VISIUM__) || defined(__riscv) 5 | #define _CLOCKS_PER_SEC_ 1000000 6 | #elif defined(__aarch64__) || defined(__arm__) || defined(__thumb__) 7 | #define _CLOCKS_PER_SEC_ 100 8 | #endif 9 | 10 | #ifdef __SPU__ 11 | #include 12 | int nanosleep (const struct timespec *, struct timespec *); 13 | #endif 14 | 15 | #endif /* _MACHTIME_H_ */ 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/machine/types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Newlib targets may provide an own version of this file in their machine 3 | * directory to add custom user types for . 4 | */ 5 | #ifndef _SYS_TYPES_H 6 | #error "must be included via " 7 | #endif /* !_SYS_TYPES_H */ 8 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef _MEMORY_H 2 | #define _MEMORY_H 3 | #include 4 | #endif /* !_MEMORY_H */ 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/newlib.h: -------------------------------------------------------------------------------- 1 | /* dummy file for external tools to use. Real file is created by 2 | newlib configuration. */ 3 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | #ifdef __GNUC__ 15 | void longjmp (jmp_buf __jmpb, int __retval) 16 | __attribute__ ((__noreturn__)); 17 | #else 18 | void longjmp (jmp_buf __jmpb, int __retval); 19 | #endif 20 | int setjmp (jmp_buf __jmpb); 21 | 22 | _END_STD_C 23 | 24 | #endif /* _SETJMP_H_ */ 25 | 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/sys/custom_file.h: -------------------------------------------------------------------------------- 1 | #error System-specific custom_file.h is missing. 2 | 3 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/sys/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_FCNTL_H_ 2 | #define _SYS_FCNTL_H_ 3 | #include 4 | #endif 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/sys/file.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | int getrusage (int, struct rusage*); 15 | 16 | #endif 17 | 18 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | #if !defined(__clock_t_defined) && !defined(_CLOCK_T_DECLARED) 11 | typedef _CLOCK_T_ clock_t; 12 | #define __clock_t_defined 13 | #define _CLOCK_T_DECLARED 14 | #endif 15 | 16 | /* Get Process Times, P1003.1b-1993, p. 92 */ 17 | struct tms { 18 | clock_t tms_utime; /* user time */ 19 | clock_t tms_stime; /* system time */ 20 | clock_t tms_cutime; /* user time, children */ 21 | clock_t tms_cstime; /* system time, children */ 22 | }; 23 | 24 | clock_t times (struct tms *); 25 | #ifdef _COMPILING_NEWLIB 26 | clock_t _times (struct tms *); 27 | #endif 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | #endif /* !_SYS_TIMES_H */ 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/termios.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | #include 5 | #ifdef __cplusplus 6 | } 7 | #endif 8 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/unistd.h: -------------------------------------------------------------------------------- 1 | #ifndef _UNISTD_H_ 2 | #define _UNISTD_H_ 3 | 4 | # include 5 | 6 | #endif /* _UNISTD_H_ */ 7 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/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 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/utmp.h: -------------------------------------------------------------------------------- 1 | #ifdef __cplusplus 2 | extern "C" { 3 | #endif 4 | #include 5 | #ifdef __cplusplus 6 | } 7 | #endif 8 | 9 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/include/xlocale.h: -------------------------------------------------------------------------------- 1 | /* Definition of opaque POSIX-1.2008 type locale_t for userspace. */ 2 | 3 | #ifndef _XLOCALE_H 4 | #define _XLOCALE_H 5 | 6 | #include 7 | #include 8 | 9 | struct __locale_t; 10 | typedef struct __locale_t *locale_t; 11 | 12 | #endif /* _XLOCALE_H */ 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/argz_add.c: -------------------------------------------------------------------------------- 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 | #include 10 | #include 11 | #include 12 | 13 | error_t 14 | argz_add (char **argz, 15 | size_t *argz_len, 16 | const char *str) 17 | { 18 | int len_to_add = 0; 19 | size_t last = *argz_len; 20 | 21 | if (str == NULL) 22 | return 0; 23 | 24 | len_to_add = strlen(str) + 1; 25 | *argz_len += len_to_add; 26 | 27 | if(!(*argz = (char *)realloc(*argz, *argz_len))) 28 | return ENOMEM; 29 | 30 | memcpy(*argz + last, str, len_to_add); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/argz_append.c: -------------------------------------------------------------------------------- 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 | #include 10 | #include 11 | #include 12 | 13 | error_t 14 | argz_append (char **argz, 15 | size_t *argz_len, 16 | const char *buf, 17 | size_t buf_len) 18 | { 19 | if (buf_len) 20 | { 21 | size_t last = *argz_len; 22 | 23 | *argz_len += buf_len; 24 | 25 | if(!(*argz = (char *)realloc(*argz, *argz_len))) 26 | return ENOMEM; 27 | 28 | memcpy(*argz + last, buf, buf_len); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/argz_count.c: -------------------------------------------------------------------------------- 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 <_ansi.h> 8 | #include 9 | #include 10 | #include 11 | 12 | size_t 13 | argz_count (const char *argz, 14 | size_t argz_len) 15 | { 16 | int i; 17 | size_t count = 0; 18 | 19 | for (i = 0; i < argz_len; i++) 20 | { 21 | if (argz[i] == '\0') 22 | count++; 23 | } 24 | return count; 25 | } 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/argz_extract.c: -------------------------------------------------------------------------------- 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 | #include 10 | 11 | void 12 | argz_extract (char *argz, 13 | size_t argz_len, 14 | char **argv) 15 | { 16 | size_t i = 0; 17 | int j = 0; 18 | const size_t count = argz_count(argz, argz_len); 19 | 20 | if (argz_len > 1) 21 | for (i = argz_len - 2; i > 0; i--) 22 | { 23 | if (argz[i] == '\0') 24 | { 25 | j++; 26 | argv[count - j] = &argz[i + 1]; 27 | } 28 | } 29 | argv[0] = &argz[0]; 30 | argv[count] = NULL; 31 | } 32 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/argz_stringify.c: -------------------------------------------------------------------------------- 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 <_ansi.h> 8 | #include 9 | #include 10 | #include 11 | 12 | void 13 | argz_stringify (char *argz, 14 | size_t argz_len, 15 | int sep) 16 | { 17 | size_t i; 18 | 19 | /* len includes trailing \0, which we don't want to replace. */ 20 | if (argz_len > 1) 21 | for (i = 0; i < argz_len - 1; i++) 22 | { 23 | if (argz[i] == '\0') 24 | argz[i] = sep; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/buf_findstr.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 | 9 | /* Find string str in buffer buf of length buf_len. Point buf to 10 | character after string, or set it to NULL if end of buffer is 11 | reached. Return 1 if found, 0 if not. */ 12 | int _buf_findstr(const char *str, char **buf, size_t *buf_len); 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/argz/dummy.c: -------------------------------------------------------------------------------- 1 | /* empty stub to allow objectlist.awk.in to be created */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/categories.cat: -------------------------------------------------------------------------------- 1 | CAT_Cc, 2 | CAT_Cf, 3 | CAT_Cs, 4 | CAT_LC, 5 | CAT_Ll, 6 | CAT_Lm, 7 | CAT_Lo, 8 | CAT_Lt, 9 | CAT_Lu, 10 | CAT_Mc, 11 | CAT_Me, 12 | CAT_Mn, 13 | CAT_Nd, 14 | CAT_Nl, 15 | CAT_No, 16 | CAT_Pc, 17 | CAT_Pd, 18 | CAT_Pe, 19 | CAT_Pf, 20 | CAT_Pi, 21 | CAT_Po, 22 | CAT_Ps, 23 | CAT_Sc, 24 | CAT_Sk, 25 | CAT_Sm, 26 | CAT_So, 27 | CAT_Zl, 28 | CAT_Zp, 29 | CAT_Zs, 30 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/categories.h: -------------------------------------------------------------------------------- 1 | /* category data */ 2 | 3 | enum category { 4 | #include "categories.cat" 5 | }; 6 | 7 | extern enum category category(wint_t ucs); 8 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/ctype_.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if (defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE)) || defined (__CYGWIN__) 4 | #define ALLOW_NEGATIVE_CTYPE_INDEX 5 | #endif 6 | 7 | #ifdef ALLOW_NEGATIVE_CTYPE_INDEX 8 | 9 | #ifndef __CYGWIN__ 10 | extern const char _ctype_b[]; 11 | #else 12 | extern char _ctype_b[]; 13 | #endif 14 | # define DEFAULT_CTYPE_PTR ((char *) _ctype_b + 127) 15 | 16 | #else /* !ALLOW_NEGATIVE_CTYPE_INDEX */ 17 | 18 | /* _ctype_ is declared in . */ 19 | # define DEFAULT_CTYPE_PTR ((char *) _ctype_) 20 | 21 | #endif /* !ALLOW_NEGATIVE_CTYPE_INDEX */ 22 | 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isalnum_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isalnum_l 5 | 6 | int 7 | isalnum_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L|_N); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isalpha_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isalpha_l 5 | 6 | int 7 | isalpha_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & (_U|_L); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isascii_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isascii_l 5 | 6 | int 7 | isascii_l (int c, struct __locale_t *locale) 8 | { 9 | return c >= 0 && c < 128; 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isblank_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isblank_l 5 | 6 | int 7 | isblank_l (int c, struct __locale_t *locale) 8 | { 9 | return (__locale_ctype_ptr_l (locale)[c+1] & _B) || (c == '\t'); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iscntrl_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef iscntrl_l 5 | 6 | int 7 | iscntrl_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & _C; 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isdigit_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isdigit_l 5 | 6 | int 7 | isdigit_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & _N; 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/islower_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef islower_l 5 | 6 | int 7 | islower_l (int c, struct __locale_t *locale) 8 | { 9 | return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _L; 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isprint_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isgraph_l 5 | 6 | int 7 | isgraph_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N); 10 | } 11 | 12 | #undef isprint_l 13 | 14 | int 15 | isprint_l (int c, struct __locale_t *locale) 16 | { 17 | return __locale_ctype_ptr_l (locale)[c+1] & (_P|_U|_L|_N|_B); 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/ispunct_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef ispunct_l 5 | 6 | int 7 | ispunct_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & _P; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isspace_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isspace_l 5 | 6 | int 7 | isspace_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & _S; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isupper_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef isupper_l 5 | 6 | int 7 | isupper_l (int c, struct __locale_t *locale) 8 | { 9 | return (__locale_ctype_ptr_l (locale)[c+1] & (_U|_L)) == _U; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswalnum_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswalnum_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | //return iswalpha (c) || iswdigit (c); 13 | c = _jp2uc_l (c, locale); 14 | enum category cat = category (c); 15 | return cat == CAT_LC || cat == CAT_Lu || cat == CAT_Ll || cat == CAT_Lt 16 | || cat == CAT_Lm || cat == CAT_Lo 17 | || cat == CAT_Nl // Letter_Number 18 | || cat == CAT_Nd // Decimal_Number 19 | ; 20 | #else 21 | return c < (wint_t)0x100 ? isalnum (c) : 0; 22 | #endif /* _MB_CAPABLE */ 23 | } 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswalpha_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswalpha_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | return cat == CAT_LC || cat == CAT_Lu || cat == CAT_Ll || cat == CAT_Lt 15 | || cat == CAT_Lm || cat == CAT_Lo 16 | || cat == CAT_Nl // Letter_Number 17 | ; 18 | #else 19 | return c < (wint_t)0x100 ? isalpha (c) : 0; 20 | #endif /* _MB_CAPABLE */ 21 | } 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswblank_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswblank_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | // exclude ""? 15 | return cat == CAT_Zs 16 | || c == '\t'; 17 | #else 18 | return c < 0x100 ? isblank (c) : 0; 19 | #endif /* _MB_CAPABLE */ 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswcntrl_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswcntrl_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | return cat == CAT_Cc 15 | || cat == CAT_Zl || cat == CAT_Zp // Line/Paragraph Separator 16 | ; 17 | #else 18 | return c < 0x100 ? iscntrl (c) : 0; 19 | #endif /* _MB_CAPABLE */ 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswdigit_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | int 5 | iswdigit_l (wint_t c, struct __locale_t *locale) 6 | { 7 | return c >= (wint_t)'0' && c <= (wint_t)'9'; 8 | } 9 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswgraph_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include "local.h" 5 | #include "categories.h" 6 | 7 | int 8 | iswgraph_l (wint_t c, struct __locale_t *locale) 9 | { 10 | #ifdef _MB_CAPABLE 11 | //return iswprint (c, locale) && !iswspace (c, locale); 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | return cat != -1 15 | && cat != CAT_Cc && cat != CAT_Cf 16 | && cat != CAT_Cs // Surrogate 17 | && cat != CAT_Zs 18 | && cat != CAT_Zl && cat != CAT_Zp // Line/Paragraph Separator 19 | ; 20 | #else 21 | return iswprint_l (c, locale) && !iswspace_l (c, locale); 22 | #endif /* _MB_CAPABLE */ 23 | } 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswlower_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswlower_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | // The wide-character class "lower" contains at least those characters wc 14 | // which are equal to towlower(wc) and different from towupper(wc). 15 | enum category cat = category (c); 16 | return cat == CAT_Ll || (cat == CAT_LC && towlower (c) == c); 17 | #else 18 | return c < 0x100 ? islower (c) : 0; 19 | #endif /* _MB_CAPABLE */ 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswprint_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswprint_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | return cat != -1 15 | && cat != CAT_Cc && cat != CAT_Cf 16 | && cat != CAT_Cs // Surrogate 17 | ; 18 | #else 19 | return c < (wint_t)0x100 ? isprint (c) : 0; 20 | #endif /* _MB_CAPABLE */ 21 | } 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswspace_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswspace_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | enum category cat = category (c); 14 | // exclude ""? 15 | return cat == CAT_Zs 16 | || cat == CAT_Zl || cat == CAT_Zp // Line/Paragraph Separator 17 | || (c >= 0x9 && c <= 0xD); 18 | #else 19 | return c < 0x100 ? isspace (c) : 0; 20 | #endif /* _MB_CAPABLE */ 21 | } 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswupper_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | #include "categories.h" 7 | 8 | int 9 | iswupper_l (wint_t c, struct __locale_t *locale) 10 | { 11 | #ifdef _MB_CAPABLE 12 | c = _jp2uc_l (c, locale); 13 | // The wide-character class "upper" contains at least those characters wc 14 | // which are equal to towupper(wc) and different from towlower(wc). 15 | enum category cat = category (c); 16 | return cat == CAT_Lu || (cat == CAT_LC && towupper (c) == c); 17 | #else 18 | return c < 0x100 ? isupper (c) : 0; 19 | #endif /* _MB_CAPABLE */ 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/iswxdigit_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | int 5 | iswxdigit_l (wint_t c, struct __locale_t *locale) 6 | { 7 | return ((c >= (wint_t)'0' && c <= (wint_t)'9') || 8 | (c >= (wint_t)'a' && c <= (wint_t)'f') || 9 | (c >= (wint_t)'A' && c <= (wint_t)'F')); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/isxdigit_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | 5 | #undef isxdigit_l 6 | int 7 | isxdigit_l (int c, struct __locale_t *locale) 8 | { 9 | return __locale_ctype_ptr_l (locale)[c+1] & ((_X)|(_N)); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/toascii_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | #undef toascii_l 5 | 6 | int 7 | toascii_l (int c, struct __locale_t *locale) 8 | { 9 | return c & 0177; 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/towlower_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include 5 | #include "local.h" 6 | 7 | wint_t 8 | towlower_l (wint_t c, struct __locale_t *locale) 9 | { 10 | #ifdef _MB_CAPABLE 11 | return towctrans_l (c, WCT_TOLOWER, locale); 12 | #else 13 | return towlower (c); 14 | #endif /* _MB_CAPABLE */ 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/towupper_l.c: -------------------------------------------------------------------------------- 1 | /* Modified (m) 2017 Thomas Wolff: revise Unicode and locale/wchar handling */ 2 | #include <_ansi.h> 3 | #include 4 | #include "local.h" 5 | 6 | wint_t 7 | towupper_l (wint_t c, struct __locale_t *locale) 8 | { 9 | #ifdef _MB_CAPABLE 10 | return towctrans_l (c, WCT_TOUPPER, locale); 11 | #else 12 | return towupper (c); 13 | #endif /* _MB_CAPABLE */ 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/wctrans_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | wctrans_t 5 | wctrans_l (const char *c, struct __locale_t *locale) 6 | { 7 | /* We're using a locale-independent representation of upper/lower case 8 | based on Unicode data. Thus, the locale doesn't matter. */ 9 | return wctrans (c); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ctype/wctype_l.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | 4 | wctype_t 5 | wctype_l (const char *c, struct __locale_t *locale) 6 | { 7 | return wctype (c); 8 | } 9 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/errno/errno.c: -------------------------------------------------------------------------------- 1 | /* The errno variable is stored in the reentrancy structure. This 2 | function returns its address for use by the macro errno defined in 3 | errno.h. */ 4 | 5 | #include 6 | #include 7 | 8 | #ifndef _REENT_ONLY 9 | 10 | int * 11 | __errno () 12 | { 13 | return &_REENT->_errno; 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/local.h: -------------------------------------------------------------------------------- 1 | /* placeholder for future usage. */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/s_isinf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * isinf(x) returns 1 if x is infinity, else 0; 3 | * no branching! 4 | * 5 | * isinf is a macro in the C99 standard. It was previously 6 | * implemented as a function by newlib and is declared as such in 7 | * . Newlib supplies it here as a function if the user 8 | * chooses to use it instead of the C99 macro. 9 | */ 10 | 11 | #include "fdlibm.h" 12 | #include 13 | 14 | #ifndef _DOUBLE_IS_32BITS 15 | 16 | #undef isinf 17 | 18 | int 19 | isinf (double x) 20 | { 21 | __int32_t hx,lx; 22 | EXTRACT_WORDS(hx,lx,x); 23 | hx &= 0x7fffffff; 24 | hx |= (__uint32_t)(lx|(-lx))>>31; 25 | hx = 0x7ff00000 - hx; 26 | return 1 - (int)((__uint32_t)(hx|(-hx))>>31); 27 | } 28 | 29 | #endif /* _DOUBLE_IS_32BITS */ 30 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/s_isinfd.c: -------------------------------------------------------------------------------- 1 | /* 2 | * __isinfd(x) returns 1 if x is infinity, else 0; 3 | * no branching! 4 | * Added by Cygnus Support. 5 | */ 6 | 7 | #include "fdlibm.h" 8 | 9 | #ifndef _DOUBLE_IS_32BITS 10 | 11 | int 12 | __isinfd (double x) 13 | { 14 | __int32_t hx,lx; 15 | EXTRACT_WORDS(hx,lx,x); 16 | hx &= 0x7fffffff; 17 | hx |= (__uint32_t)(lx|(-lx))>>31; 18 | hx = 0x7ff00000 - hx; 19 | return 1 - (int)((__uint32_t)(hx|(-hx))>>31); 20 | } 21 | 22 | #endif /* _DOUBLE_IS_32BITS */ 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/sf_infinity.c: -------------------------------------------------------------------------------- 1 | /* 2 | * infinityf () returns the representation of infinity. 3 | * Added by Cygnus Support. 4 | */ 5 | 6 | #include "fdlibm.h" 7 | 8 | float infinityf() 9 | { 10 | float x; 11 | 12 | SET_FLOAT_WORD(x,0x7f800000); 13 | return x; 14 | } 15 | 16 | #ifdef _DOUBLE_IS_32BITS 17 | 18 | double infinity() 19 | { 20 | return (double) infinityf(); 21 | } 22 | 23 | #endif /* defined(_DOUBLE_IS_32BITS) */ 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/sf_isinf.c: -------------------------------------------------------------------------------- 1 | /* 2 | * isinff(x) returns 1 if x is +-infinity, else 0; 3 | * 4 | * isinf is a macro in the C99 standard. It was previously 5 | * implemented as isinf and isinff functions by newlib and are still declared 6 | * as such in . Newlib supplies it here as a function if the user 7 | * chooses to use it instead of the C99 macro. 8 | */ 9 | 10 | #include "fdlibm.h" 11 | #include 12 | 13 | #undef isinff 14 | 15 | int 16 | isinff (float x) 17 | { 18 | __int32_t ix; 19 | GET_FLOAT_WORD(ix,x); 20 | ix &= 0x7fffffff; 21 | return FLT_UWORD_IS_INFINITE(ix); 22 | } 23 | 24 | #ifdef _DOUBLE_IS_32BITS 25 | 26 | #undef isinf 27 | 28 | int 29 | isinf (double x) 30 | { 31 | return isinff((float) x); 32 | } 33 | 34 | #endif /* defined(_DOUBLE_IS_32BITS) */ 35 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/sf_isinff.c: -------------------------------------------------------------------------------- 1 | /* 2 | * __isinff(x) returns 1 if x is +-infinity, else 0; 3 | * Added by Cygnus Support. 4 | */ 5 | 6 | #include "fdlibm.h" 7 | 8 | int 9 | __isinff (float x) 10 | { 11 | __int32_t ix; 12 | GET_FLOAT_WORD(ix,x); 13 | ix &= 0x7fffffff; 14 | return FLT_UWORD_IS_INFINITE(ix); 15 | } 16 | 17 | #ifdef _DOUBLE_IS_32BITS 18 | 19 | int 20 | __isinfd (double x) 21 | { 22 | return __isinff((float) x); 23 | } 24 | 25 | #endif /* defined(_DOUBLE_IS_32BITS) */ 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/common/sf_nan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * nanf () returns a nan. 3 | * Added by Cygnus Support. 4 | */ 5 | 6 | #include "fdlibm.h" 7 | 8 | float nanf(const char *unused) 9 | { 10 | float x; 11 | 12 | #if __GNUC_PREREQ (3, 3) 13 | x = __builtin_nanf(""); 14 | #else 15 | SET_FLOAT_WORD(x,0x7fc00000); 16 | #endif 17 | return x; 18 | } 19 | 20 | #ifdef _DOUBLE_IS_32BITS 21 | 22 | double nan(const char *arg) 23 | { 24 | return (double) nanf(arg); 25 | } 26 | 27 | #endif /* defined(_DOUBLE_IS_32BITS) */ 28 | 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cabsf.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cabsf.c,v 1.1 2007/08/20 16:01:30 drochner Exp $ */ 2 | 3 | /* 4 | * Written by Matthias Drochner . 5 | * Public domain. 6 | * 7 | * imported and modified include for newlib 2010/10/03 8 | * Marco Atzeri 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | float 15 | cabsf(float complex z) 16 | { 17 | 18 | return hypotf( crealf(z), cimagf(z) ); 19 | } 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cabsl.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 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 | long double 11 | cabsl (long double complex z) 12 | { 13 | #ifdef _LDBL_EQ_DBL 14 | return cabs (z); 15 | #else 16 | return hypotl (creall (z), cimagl (z)); 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cargf.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cargf.c,v 1.1 2007/08/20 16:01:31 drochner Exp $ */ 2 | 3 | /* 4 | * Written by Matthias Drochner . 5 | * Public domain. 6 | * 7 | * imported and modified include for newlib 2010/10/03 8 | * Marco Atzeri 9 | */ 10 | 11 | #include 12 | #include 13 | 14 | float 15 | cargf(float complex z) 16 | { 17 | 18 | return atan2f( cimagf(z), crealf(z) ); 19 | } 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cargl.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cargl.c,v 1.1 2014/10/10 00:48:18 christos Exp $ */ 2 | 3 | /* 4 | * Public domain. 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | long double 11 | cargl(long double complex z) 12 | { 13 | #ifdef _LDBL_EQ_DBL 14 | return carg (z); 15 | #else 16 | return atan2l (cimagl (z), creall (z)); 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cephes_subr.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cephes_subr.h,v 1.1 2007/08/20 16:01:33 drochner Exp $ */ 2 | 3 | void _cchsh(double, double *, double *); 4 | double _redupi(double); 5 | double _ctans(double complex); 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cephes_subrf.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cephes_subrf.h,v 1.1 2007/08/20 16:01:34 drochner Exp $ */ 2 | 3 | void _cchshf(float, float *, float *); 4 | float _redupif(float); 5 | float _ctansf(float complex); 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cephes_subrl.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cephes_subrl.h,v 1.1 2014/10/10 00:48:18 christos Exp $ */ 2 | 3 | void _cchshl(long double, long double *, long double *); 4 | long double _redupil(long double); 5 | long double _ctansl(long double complex); 6 | 7 | #define M_PIL 3.14159265358979323846264338327950280e+00L 8 | #define M_PI_2L 1.57079632679489661923132169163975140e+00L 9 | 10 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cimagf.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cimagf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ 2 | 3 | /* 4 | * Written by Matthias Drochner . 5 | * Public domain. 6 | * 7 | * imported and modified include for newlib 2010/10/03 8 | * Marco Atzeri 9 | */ 10 | 11 | #include 12 | #include "fdlibm.h" 13 | 14 | float 15 | cimagf(float complex z) 16 | { 17 | float_complex w = { .z = z }; 18 | 19 | return (IMAG_PART(w)); 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/cimagl.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 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 "fdlibm.h" 9 | 10 | long double 11 | cimagl (long double complex z) 12 | { 13 | long_double_complex w = { .z = z }; 14 | 15 | return IMAG_PART (w); 16 | } 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/clog10f.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | float complex 5 | clog10f(float complex z) 6 | { 7 | float complex w; 8 | float p, rr; 9 | 10 | rr = cabsf(z); 11 | p = log10f(rr); 12 | rr = atan2f(cimagf(z), crealf(z)) * (float) M_IVLN10; 13 | w = p + rr * I; 14 | return w; 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/conjf.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: conjf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ 2 | 3 | /* 4 | * Written by Matthias Drochner . 5 | * Public domain. 6 | * 7 | * imported and modified include for newlib 2010/10/03 8 | * Marco Atzeri 9 | */ 10 | 11 | #include 12 | #include "fdlibm.h" 13 | 14 | float complex 15 | conjf(float complex z) 16 | { 17 | float_complex w = { .z = z }; 18 | 19 | IMAG_PART(w) = -IMAG_PART(w); 20 | 21 | return (w.z); 22 | } 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/crealf.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: crealf.c,v 1.2 2010/09/15 16:11:29 christos Exp $ */ 2 | 3 | /* 4 | * Written by Matthias Drochner . 5 | * Public domain. 6 | * 7 | * imported and modified include for newlib 2010/10/03 8 | * Marco Atzeri 9 | */ 10 | 11 | #include 12 | #include "fdlibm.h" 13 | 14 | float 15 | crealf(float complex z) 16 | { 17 | float_complex w = { .z = z }; 18 | 19 | return (REAL_PART(w)); 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/complex/creall.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 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 "fdlibm.h" 9 | 10 | long double 11 | creall (long double complex z) 12 | { 13 | long_double_complex w = { .z = z }; 14 | 15 | return (REAL_PART(w)); 16 | } 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/math/el_hypot.c: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2015 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 "fdlibm.h" 8 | 9 | long double 10 | __ieee754_hypotl (long double x, long double y) 11 | { 12 | #ifdef _LDBL_EQ_DBL 13 | return __ieee754_hypot (x, y); 14 | #else 15 | /* Keep it simple for now... */ 16 | return sqrtl ((x * x) + (y * y)); 17 | #endif 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/math/w_drem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * drem() wrapper for remainder(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | double 11 | drem(x, y) 12 | double x, y; 13 | { 14 | return remainder(x, y); 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/math/w_sincos.c: -------------------------------------------------------------------------------- 1 | /* sincos -- currently no more efficient than two separate calls to 2 | sin and cos. */ 3 | 4 | #include "fdlibm.h" 5 | #include 6 | 7 | #ifndef _DOUBLE_IS_32BITS 8 | 9 | #ifdef __STDC__ 10 | void sincos(double x, double *sinx, double *cosx) 11 | #else 12 | void sincos(x, sinx, cosx) 13 | double x; 14 | double *sinx; 15 | double *cosx; 16 | #endif 17 | { 18 | *sinx = sin (x); 19 | *cosx = cos (x); 20 | } 21 | 22 | #endif /* defined(_DOUBLE_IS_32BITS) */ 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/math/wf_drem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dremf() wrapper for remainderf(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | float 11 | #ifdef __STDC__ 12 | dremf(float x, float y) 13 | #else 14 | dremf(x, y) 15 | float x, y; 16 | #endif 17 | { 18 | return remainderf(x, y); 19 | } 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/README: -------------------------------------------------------------------------------- 1 | This directory was an experiment to use floating-point operations to implement 2 | the math library when a processor had a floating-point instruction set. The 3 | experiment was a failure in that some of the algorithms chosen (e.g. recursive 4 | algorithms for sin/cos, etc..) are too simple and do not provide proper accuracy 5 | nor handle very large or very small inputs adequately. 6 | 7 | The code is considered moth-balled. The stable math library routines can be 8 | found in libm/math and the configuration option to use this has been removed. 9 | 10 | If you wish to experiment with the concept, please feel free and report back if 11 | you have major improvements. 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_asin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_asin.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Arcsine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * arcsine of x 11 | * 12 | * Description: 13 | * This routine returns the arcsine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | double 23 | asin (double x) 24 | { 25 | return (asine (x, 0)); 26 | } 27 | 28 | #endif /* _DOUBLE_IS_32BITS */ 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_cos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_cos.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Cosine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * cosine of x 11 | * 12 | * Description: 13 | * This routine returns the cosine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | double 23 | cos (double x) 24 | { 25 | return (sine (x, 1)); 26 | } 27 | 28 | #endif /* _DOUBLE_IS_32BITS */ 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_exp2.c: -------------------------------------------------------------------------------- 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 "fdlibm.h" 8 | 9 | #ifndef _DOUBLE_IS_32BITS 10 | 11 | double 12 | exp2 (double x) 13 | { 14 | return pow(2.0, x); 15 | } 16 | 17 | #endif /* _DOUBLE_IS_32BITS */ 18 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_log.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_log.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Logarithm 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * natural logarithm of x 11 | * 12 | * Description: 13 | * This routine returns the natural logarithm of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | double 23 | log (double x) 24 | { 25 | return (logarithm (x, 0)); 26 | } 27 | 28 | #endif /* _DOUBLE_IS_32BITS */ 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_mathcnst.c: -------------------------------------------------------------------------------- 1 | /* @(#)z_mathcnst.c 1.0 98/08/13 */ 2 | 3 | #include "zmath.h" 4 | #include "fdlibm.h" 5 | 6 | double BIGX = 7.09782712893383973096e+02; 7 | double SMALLX = -7.45133219101941108420e+02; 8 | double z_rooteps = 7.4505859692e-9; 9 | float z_rooteps_f = 1.7263349182589107e-4; 10 | 11 | ufloat z_hugeval_f = { 0x7f800000 }; 12 | ufloat z_infinity_f = { 0x7f800000 }; 13 | ufloat z_notanum_f = { 0xffd00000 }; 14 | 15 | #ifdef __IEEE_BIG_ENDIAN 16 | udouble z_hugeval = { 0x7ff00000, 0 }; 17 | udouble z_infinity = { 0x7ff00000, 0 }; 18 | udouble z_notanum = { 0xfff80000, 0 }; 19 | #else /* __IEEE_LITTLE_ENDIAN */ 20 | udouble z_hugeval = { 0, 0x7ff00000 }; 21 | udouble z_infinity = { 0, 0x7ff00000 }; 22 | udouble z_notanum = { 0, 0xfff80000 }; 23 | #endif /* __IEEE_LITTLE_ENDIAN */ 24 | 25 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_sin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sin.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * sine of x 11 | * 12 | * Description: 13 | * This routine returns the sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | double 23 | sin (double x) 24 | { 25 | return (sine (x, 0)); 26 | } 27 | 28 | #endif /* _DOUBLE_IS_32BITS */ 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_sincos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sin.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * sine of x 11 | * 12 | * Description: 13 | * This routine returns the sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | void 23 | sincos (double x, 24 | double *sinx, 25 | double *cosx) 26 | { 27 | *sinx = sin (x); 28 | *cosx = cos (x); 29 | } 30 | 31 | #endif /* _DOUBLE_IS_32BITS */ 32 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_sinf.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sinf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * sine of x 11 | * 12 | * Description: 13 | * This routine returns the sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | sinf (float x) 22 | { 23 | return (sinef (x, 0)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double sin (double x) 29 | { 30 | return (double) sinf ((float) x); 31 | } 32 | 33 | #endif /* _DOUBLE_IS_32BITS */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/s_sinh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sinh.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Hyperbolic Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * hyperbolic sine of x 11 | * 12 | * Description: 13 | * This routine returns the hyperbolic sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | #ifndef _DOUBLE_IS_32BITS 21 | 22 | double 23 | sinh (double x) 24 | { 25 | return (sineh (x, 0)); 26 | } 27 | 28 | #endif /* _DOUBLE_IS_32BITS */ 29 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_acos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_acosf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Arccosine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * arccosine of x 11 | * 12 | * Description: 13 | * This routine returns the arccosine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | acosf (float x) 22 | { 23 | return (asinef (x, 1)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | double acos (double x) 28 | { 29 | return (double) asinef ((float) x, 1); 30 | } 31 | 32 | #endif /* defined(_DOUBLE_IS_32BITS) */ 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_asin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_asinf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Arcsine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * arcsine of x 11 | * 12 | * Description: 13 | * This routine returns the arcsine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | asinf (float x) 22 | { 23 | return (asinef (x, 0)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double asin (double x) 29 | { 30 | return (double) asinef ((float) x, 0); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_atan2.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_atan2f.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Arctangent2 5 | * 6 | * Input: 7 | * v, u - floating point values 8 | * 9 | * Output: 10 | * arctan2 of v / u 11 | * 12 | * Description: 13 | * This routine returns the arctan2 of v / u. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | atan2f (float v, 22 | float u) 23 | { 24 | return (atangentf (0.0, v, u, 1)); 25 | } 26 | 27 | #ifdef _DOUBLE_IS_32BITS 28 | double atan2 (double v, double u) 29 | { 30 | return (double) atangentf (0.0, (float) v, (float) u, 1); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_cos.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_cosf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Cosine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * cosine of x 11 | * 12 | * Description: 13 | * This routine returns the cosine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | cosf (float x) 22 | { 23 | return (sinef (x, 1)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double cos (double x) 29 | { 30 | return (double) sinef ((float) x, 1); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_cosh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_coshf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Hyperbolic Cosine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * hyperbolic cosine of x 11 | * 12 | * Description: 13 | * This routine returns the hyperbolic cosine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | coshf (float x) 22 | { 23 | return (sinehf (x, 1)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | double cosh (double x) 28 | { 29 | return (double) sinehf ((float) x, 1); 30 | } 31 | 32 | #endif /* defined(_DOUBLE_IS_32BITS) */ 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_exp2.c: -------------------------------------------------------------------------------- 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 "fdlibm.h" 8 | 9 | float 10 | exp2f (float x) 11 | { 12 | return powf(2.0, x); 13 | } 14 | 15 | #ifdef _DOUBLE_IS_32BITS 16 | 17 | double exp2 (double x) 18 | { 19 | return (double) exp2f ((float) x); 20 | } 21 | 22 | #endif /* _DOUBLE_IS_32BITS */ 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_log.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_logf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Logarithm 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * natural logarithm of x 11 | * 12 | * Description: 13 | * This routine returns the natural logarithm of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | logf (float x) 22 | { 23 | return (logarithmf (x, 0)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double log (double x) 29 | { 30 | return (double) logf ((float) x); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_log10.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_log10f.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Logarithm 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * logarithm of x 11 | * 12 | * Description: 13 | * This routine returns the logarithm of x (base 10). 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | log10f (float x) 22 | { 23 | return (logarithmf (x, 1)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double log10 (double x) 29 | { 30 | return (double) log10f ((float) x); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_sin.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sinf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * sine of x 11 | * 12 | * Description: 13 | * This routine returns the sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | sinf (float x) 22 | { 23 | return (sinef (x, 0)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double sin (double x) 29 | { 30 | return (double) sinef ((float) x, 0); 31 | } 32 | 33 | #endif /* defined(_DOUBLE_IS_32BITS) */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/sf_sinh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)z_sinhf.c 1.0 98/08/13 */ 3 | /****************************************************************** 4 | * Hyperbolic Sine 5 | * 6 | * Input: 7 | * x - floating point value 8 | * 9 | * Output: 10 | * hyperbolic sine of x 11 | * 12 | * Description: 13 | * This routine returns the hyperbolic sine of x. 14 | * 15 | *****************************************************************/ 16 | 17 | #include "fdlibm.h" 18 | #include "zmath.h" 19 | 20 | float 21 | sinhf (float x) 22 | { 23 | return (sinehf (x, 0)); 24 | } 25 | 26 | #ifdef _DOUBLE_IS_32BITS 27 | 28 | double sinh (double x) 29 | { 30 | return (double) sinhf ((float) x); 31 | } 32 | 33 | #endif /* _DOUBLE_IS_32BITS */ 34 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/w_cabs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cabs() wrapper for hypot(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | struct complex { 11 | double x; 12 | double y; 13 | }; 14 | 15 | double 16 | cabs(z) 17 | struct complex z; 18 | { 19 | return hypot(z.x, z.y); 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/w_drem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * drem() wrapper for remainder(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | double 11 | drem(x, y) 12 | double x, y; 13 | { 14 | return remainder(x, y); 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/wf_cabs.c: -------------------------------------------------------------------------------- 1 | /* 2 | * cabsf() wrapper for hypotf(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | struct complex { 11 | float x; 12 | float y; 13 | }; 14 | 15 | float 16 | cabsf(z) 17 | struct complex z; 18 | { 19 | return hypotf(z.x, z.y); 20 | } 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/libm/mathfp/wf_drem.c: -------------------------------------------------------------------------------- 1 | /* 2 | * dremf() wrapper for remainderf(). 3 | * 4 | * Written by J.T. Conklin, 5 | * Placed into the Public Domain, 1994. 6 | */ 7 | 8 | #include "fdlibm.h" 9 | 10 | float 11 | #ifdef __STDC__ 12 | dremf(float x, float y) 13 | #else 14 | dremf(x, y) 15 | float x, y; 16 | #endif 17 | { 18 | return remainderf(x, y); 19 | } 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/misc/ffs.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---find first bit set in a word 4 | 5 | INDEX 6 | ffs 7 | 8 | SYNOPSIS 9 | #include 10 | int ffs(int <[word]>); 11 | 12 | DESCRIPTION 13 | 14 | <> returns the first bit set in a word. 15 | 16 | RETURNS 17 | <> returns 0 if <[c]> is 0, 1 if <[c]> is odd, 2 if <[c]> is a multiple of 18 | 2, etc. 19 | 20 | PORTABILITY 21 | <> is not ANSI C. 22 | 23 | No supporting OS subroutines are required. */ 24 | 25 | #include 26 | 27 | int 28 | ffs(int i) 29 | { 30 | 31 | return (__builtin_ffs(i)); 32 | } 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/platform/cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void *operator new (size_t size) { 4 | return malloc(size); 5 | } 6 | 7 | void *operator new[](size_t size) { 8 | return malloc(size); 9 | } 10 | 11 | void operator delete(void *p) { 12 | free(p); 13 | } 14 | 15 | void operator delete[](void *p) { 16 | free(p); 17 | } 18 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/platform/crt0.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[], char *envp[]); 5 | extern char **environ; 6 | 7 | __attribute__((section(".text.unlikely"))) void _start(int argc, char *argv[], char *envp[]) { 8 | char *env[] = {NULL}; 9 | environ = env; 10 | exit(main(argc, argv, env)); 11 | assert(0); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/_isatty.c: -------------------------------------------------------------------------------- 1 | /* isatty.c */ 2 | 3 | /* Dumb implementation so programs will at least run. */ 4 | 5 | #include 6 | #include 7 | 8 | int 9 | _isatty (int fd) 10 | { 11 | struct stat buf; 12 | 13 | if (fstat (fd, &buf) < 0) { 14 | errno = EBADF; 15 | return 0; 16 | } 17 | if (S_ISCHR (buf.st_mode)) 18 | return 1; 19 | errno = ENOTTY; 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/creat.c: -------------------------------------------------------------------------------- 1 | /* creat() "system call" */ 2 | 3 | /* This is needed by f2c and therefore the SPEC benchmarks. */ 4 | 5 | #include 6 | 7 | int 8 | creat (const char *path, 9 | mode_t mode) 10 | { 11 | return open (path, O_WRONLY | O_CREAT | O_TRUNC, mode); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/execlp.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_EXECVE 2 | 3 | /* execlp.c */ 4 | 5 | /* This and the other exec*.c files in this directory require 6 | the target to provide the _execve syscall. */ 7 | 8 | #include <_ansi.h> 9 | #include 10 | 11 | 12 | #include 13 | 14 | int 15 | execlp (const char *path, 16 | const char *arg0, ...) 17 | 18 | 19 | { 20 | int i; 21 | va_list args; 22 | const char *argv[256]; 23 | 24 | va_start (args, arg0); 25 | argv[0] = arg0; 26 | i = 1; 27 | do 28 | argv[i] = va_arg (args, const char *); 29 | while (argv[i++] != NULL); 30 | va_end (args); 31 | 32 | return execvp (path, (char * const *) argv); 33 | } 34 | 35 | #endif /* !_NO_EXECVE */ 36 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/execv.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_EXECVE 2 | 3 | /* execv.c */ 4 | 5 | /* This and the other exec*.c files in this directory require 6 | the target to provide the _execve syscall. */ 7 | 8 | #include <_ansi.h> 9 | #include 10 | 11 | /* Only deal with a pointer to environ, to work around subtle bugs with shared 12 | libraries and/or small data systems where the user declares his own 13 | 'environ'. */ 14 | static char ***p_environ = &environ; 15 | 16 | int 17 | execv (const char *path, 18 | char * const argv[]) 19 | { 20 | return _execve (path, (char * const *) argv, *p_environ); 21 | } 22 | 23 | #endif /* !_NO_EXECVE */ 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/execve.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_EXECVE 2 | 3 | /* execve.c */ 4 | 5 | /* This and the other exec*.c files in this directory require 6 | the target to provide the _execve syscall. */ 7 | 8 | 9 | #include 10 | 11 | 12 | int 13 | execve (const char *path, 14 | char * const argv[], 15 | char * const envp[]) 16 | { 17 | return _execve (path, argv, envp); 18 | } 19 | 20 | #endif /* !_NO_EXECVE */ 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/isatty.c: -------------------------------------------------------------------------------- 1 | /* isatty.c */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | isatty (int fd) 8 | { 9 | return _isatty (fd); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/sleep.c: -------------------------------------------------------------------------------- 1 | /* libc/posix/sleep.c - sleep function */ 2 | 3 | /* Written 2000 by Werner Almesberger */ 4 | 5 | #ifdef HAVE_NANOSLEEP 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | unsigned sleep(unsigned seconds) 12 | { 13 | struct timespec ts; 14 | 15 | ts.tv_sec = seconds; 16 | ts.tv_nsec = 0; 17 | if (!nanosleep(&ts,&ts)) return 0; 18 | if (errno == EINTR) return ts.tv_sec; 19 | return -1; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/usleep.c: -------------------------------------------------------------------------------- 1 | /* libc/posix/usleep.c - usleep function */ 2 | 3 | /* Written 2002 by Jeff Johnston */ 4 | 5 | #ifdef HAVE_NANOSLEEP 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | int usleep(useconds_t useconds) 12 | { 13 | struct timespec ts; 14 | 15 | ts.tv_sec = (long int)useconds / 1000000; 16 | ts.tv_nsec = ((long int)useconds % 1000000) * 1000; 17 | if (!nanosleep(&ts,&ts)) return 0; 18 | if (errno == EINTR) return ts.tv_sec; 19 | return -1; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/posix/wordexp2.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2012 by Peter Rosin. 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 | #ifndef _WORDEXP2_H_ 7 | 8 | struct ewords_entry { 9 | SLIST_ENTRY(ewords_entry) next; 10 | char ewords[1]; 11 | }; 12 | 13 | typedef struct { 14 | SLIST_HEAD(ewords_head, ewords_entry) list; 15 | char *we_wordv[1]; 16 | } ext_wordv_t; 17 | 18 | #define WE_WORDV_TO_EXT_WORDV(wordv) \ 19 | (ext_wordv_t *)((void *)(wordv) - offsetof(ext_wordv_t, we_wordv)) 20 | 21 | #endif /* !_WORDEXP2_H_ */ 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/reent/getreent.c: -------------------------------------------------------------------------------- 1 | /* default reentrant pointer when multithread enabled */ 2 | 3 | #ifdef GETREENT_PROVIDED 4 | 5 | int _dummy_getreent; 6 | 7 | #else 8 | 9 | #include <_ansi.h> 10 | #include 11 | 12 | #ifdef __getreent 13 | #undef __getreent 14 | #endif 15 | 16 | struct _reent * 17 | __getreent (void) 18 | { 19 | return _impure_ptr; 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/reent/signgam.c: -------------------------------------------------------------------------------- 1 | /* The signgam variable is stored in the reentrancy structure. This 2 | function returns its address for use by the macro signgam defined in 3 | math.h. */ 4 | 5 | #include 6 | #include 7 | 8 | #ifndef _REENT_ONLY 9 | 10 | int * 11 | __signgam (void) 12 | { 13 | return &_REENT_SIGNGAM(_REENT); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/search/bsd_qsort_r.c: -------------------------------------------------------------------------------- 1 | #define I_AM_QSORT_R 2 | #include "qsort.c" 3 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ssp/chk_fail.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void 6 | __attribute__((__noreturn__)) 7 | __chk_fail(void) 8 | { 9 | char msg[] = "*** buffer overflow detected ***: terminated\n"; 10 | write (2, msg, strlen (msg)); 11 | raise (SIGABRT); 12 | _exit (127); 13 | } 14 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/ssp/mempcpy_chk.c: -------------------------------------------------------------------------------- 1 | #define _GNU_SOURCE 2 | #include 3 | #include 4 | #include 5 | 6 | #undef mempcpy 7 | 8 | void *__mempcpy_chk(void * __restrict, const void * __restrict, size_t, size_t); 9 | 10 | void * 11 | __mempcpy_chk(void * __restrict dst, const void * __restrict src, size_t len, 12 | size_t slen) 13 | { 14 | if (len > slen) 15 | __chk_fail(); 16 | 17 | if (__ssp_overlap((const char *)src, (const char *)dst, len)) 18 | __chk_fail(); 19 | 20 | return mempcpy(dst, src, len); 21 | } 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/svfiprintf.c: -------------------------------------------------------------------------------- 1 | #define INTEGER_ONLY 2 | #define STRING_ONLY 3 | 4 | #include "vfprintf.t" 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/svfiscanf.c: -------------------------------------------------------------------------------- 1 | #define INTEGER_ONLY 2 | #define STRING_ONLY 3 | 4 | #include "vfscanf.t" 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/svfprintf.c: -------------------------------------------------------------------------------- 1 | #define STRING_ONLY 2 | 3 | #include "vfprintf.t" 4 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/svfscanf.c: -------------------------------------------------------------------------------- 1 | #define STRING_ONLY 2 | 3 | #include "vfscanf.t" 4 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/vfiprintf.c: -------------------------------------------------------------------------------- 1 | #define INTEGER_ONLY 2 | 3 | #include "vfprintf.t" 4 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/vfiscanf.c: -------------------------------------------------------------------------------- 1 | #define INTEGER_ONLY 2 | 3 | #include "vfscanf.t" 4 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/vfprintf.c: -------------------------------------------------------------------------------- 1 | #include "vfprintf.t" 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdio/vfscanf.c: -------------------------------------------------------------------------------- 1 | #include "vfscanf.t" 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/__exp10.c: -------------------------------------------------------------------------------- 1 | /* 2 | * compute 10**x by successive squaring. 3 | */ 4 | 5 | #include <_ansi.h> 6 | #include "std.h" 7 | 8 | double 9 | __exp10 (unsigned x) 10 | { 11 | static const double powtab[] = 12 | {1.0, 13 | 10.0, 14 | 100.0, 15 | 1000.0, 16 | 10000.0}; 17 | 18 | if (x < (sizeof (powtab) / sizeof (double))) 19 | return powtab[x]; 20 | else if (x & 1) 21 | { 22 | return 10.0 * __exp10 (x - 1); 23 | } 24 | else 25 | { 26 | double n = __exp10 (x / 2); 27 | return n * n; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/__ten_mu.c: -------------------------------------------------------------------------------- 1 | /* 2 | * [atw] multiply 64 bit accumulator by 10 and add digit. 3 | * The KA/CA way to do this should be to use 4 | * a 64-bit integer internally and use "adjust" to 5 | * convert it to float at the end of processing. 6 | */ 7 | 8 | #include <_ansi.h> 9 | #include "std.h" 10 | 11 | int 12 | __ten_mul (double *acc, 13 | int digit) 14 | { 15 | /* 16 | * [atw] Crude, but effective (at least on a KB)... 17 | */ 18 | 19 | *acc *= 10; 20 | *acc += digit; 21 | 22 | return 0; /* no overflow */ 23 | } 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/abs.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---integer absolute value (magnitude) 4 | 5 | INDEX 6 | abs 7 | 8 | SYNOPSIS 9 | #include 10 | int abs(int <[i]>); 11 | 12 | DESCRIPTION 13 | <> returns 14 | @tex 15 | $|x|$, 16 | @end tex 17 | the absolute value of <[i]> (also called the magnitude 18 | of <[i]>). That is, if <[i]> is negative, the result is the opposite 19 | of <[i]>, but if <[i]> is nonnegative the result is <[i]>. 20 | 21 | The similar function <> uses and returns <> rather than <> values. 22 | 23 | RETURNS 24 | The result is a nonnegative integer. 25 | 26 | PORTABILITY 27 | <> is ANSI. 28 | 29 | No supporting OS subroutines are required. 30 | */ 31 | 32 | #include 33 | 34 | int 35 | abs (int i) 36 | { 37 | return (i < 0) ? -i : i; 38 | } 39 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/atexit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Common definitions for atexit-like routines 3 | */ 4 | 5 | enum __atexit_types 6 | { 7 | __et_atexit, 8 | __et_onexit, 9 | __et_cxa 10 | }; 11 | 12 | void __call_exitprocs (int, void *); 13 | int __register_exitproc (int, void (*fn) (void), void *, void *); 14 | 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/atoff.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include <_ansi.h> 3 | 4 | float 5 | atoff (const char *s) 6 | { 7 | return strtof (s, NULL); 8 | } 9 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/atol.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Andy Wilson, 2-Oct-89. 3 | */ 4 | 5 | #include 6 | #include <_ansi.h> 7 | 8 | #ifndef _REENT_ONLY 9 | long 10 | atol (const char *s) 11 | { 12 | return strtol (s, NULL, 10); 13 | } 14 | #endif /* !_REENT_ONLY */ 15 | 16 | long 17 | _atol_r (struct _reent *ptr, const char *s) 18 | { 19 | return _strtol_r (ptr, s, NULL, 10); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/btowc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "local.h" 7 | 8 | wint_t 9 | btowc (int c) 10 | { 11 | mbstate_t mbs; 12 | int retval = 0; 13 | wchar_t pwc; 14 | unsigned char b; 15 | 16 | if (c == EOF) 17 | return WEOF; 18 | 19 | b = (unsigned char)c; 20 | 21 | /* Put mbs in initial state. */ 22 | memset (&mbs, '\0', sizeof (mbs)); 23 | 24 | _REENT_CHECK_MISC(_REENT); 25 | 26 | retval = __MBTOWC (_REENT, &pwc, (const char *) &b, 1, &mbs); 27 | 28 | if (retval != 0 && retval != 1) 29 | return WEOF; 30 | 31 | return (wint_t)pwc; 32 | } 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/callocr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_CALLOC 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/cfreer.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_CFREE 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/cxa_finalize.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation if __cxa_finalize. 3 | */ 4 | 5 | 6 | #include 7 | #include 8 | #include "atexit.h" 9 | 10 | /* 11 | * Call registered exit handlers. If D is null then all handlers are called, 12 | * otherwise only the handlers from that DSO are called. 13 | */ 14 | 15 | void 16 | __cxa_finalize (void * d) 17 | { 18 | __call_exitprocs (0, d); 19 | } 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/drand48.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993 Martin Birgmeier 3 | * All rights reserved. 4 | * 5 | * You may redistribute unmodified or modified versions of this source 6 | * code provided that the above copyright notice and this and the 7 | * following conditions are retained. 8 | * 9 | * This software is provided ``as is'', and comes with no warranties 10 | * of any kind. I shall in no event be liable for anything that happens 11 | * to anyone/anything when using this software. 12 | */ 13 | 14 | #include "rand48.h" 15 | 16 | double 17 | _drand48_r (struct _reent *r) 18 | { 19 | _REENT_CHECK_RAND48(r); 20 | return _erand48_r(r, __rand48_seed); 21 | } 22 | 23 | #ifndef _REENT_ONLY 24 | double 25 | drand48 (void) 26 | { 27 | return _drand48_r (_REENT); 28 | } 29 | #endif /* !_REENT_ONLY */ 30 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/dtoastub.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include 3 | #include 4 | #include 5 | 6 | /* Nothing in newlib actually *calls* dtoa, they all call _dtoa_r, so this 7 | is a safe way of providing it to the user. */ 8 | #ifndef _REENT_ONLY 9 | 10 | char * 11 | __dtoa (double d, 12 | int mode, 13 | int ndigits, 14 | int *decpt, 15 | int *sign, 16 | char **rve) 17 | { 18 | return _dtoa_r (_REENT, d, mode, ndigits, decpt, sign, rve); 19 | } 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/freer.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_FREE 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/malign.c: -------------------------------------------------------------------------------- 1 | #ifndef MALLOC_PROVIDED 2 | /* malign.c -- a wrapper for memalign_r. */ 3 | 4 | #include <_ansi.h> 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef _REENT_ONLY 10 | 11 | void * 12 | memalign (size_t align, 13 | size_t nbytes) 14 | { 15 | return _memalign_r (_REENT, align, nbytes); 16 | } 17 | 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/malignr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MEMALIGN 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mallinfor.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MALLINFO 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mallocr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MALLOC 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/malloptr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MALLOPT 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mallstatsr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MALLOC_STATS 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mbctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _MBCTYPE_H_ 2 | 3 | #define _MBCTYPE_H_ 4 | 5 | /* escape character used for JIS encoding */ 6 | #define ESC_CHAR 0x1b 7 | 8 | /* functions used to support SHIFT_JIS, EUC-JP, and JIS multibyte encodings */ 9 | 10 | int _issjis1 (int c); 11 | int _issjis2 (int c); 12 | int _iseucjp (int c); 13 | int _isjis (int c); 14 | 15 | #define _issjis1(c) (((c) >= 0x81 && (c) <= 0x9f) || ((c) >= 0xe0 && (c) <= 0xef)) 16 | #define _issjis2(c) (((c) >= 0x40 && (c) <= 0x7e) || ((c) >= 0x80 && (c) <= 0xfc)) 17 | #define _iseucjp1(c) ((c) == 0x8e || (c) == 0x8f || ((c) >= 0xa1 && (c) <= 0xfe)) 18 | #define _iseucjp2(c) ((c) >= 0xa1 && (c) <= 0xfe) 19 | #define _isjis(c) ((c) >= 0x21 && (c) <= 0x7e) 20 | 21 | #endif /* _MBCTYPE_H_ */ 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mbrlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | size_t 9 | mbrlen(const char *__restrict s, size_t n, mbstate_t *__restrict ps) 10 | { 11 | #ifdef _MB_CAPABLE 12 | if (ps == NULL) 13 | { 14 | struct _reent *reent = _REENT; 15 | 16 | _REENT_CHECK_MISC(reent); 17 | ps = &(_REENT_MBRLEN_STATE(reent)); 18 | } 19 | #endif 20 | 21 | return mbrtowc(NULL, s, n, ps); 22 | } 23 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mbsinit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int 8 | mbsinit(const mbstate_t *ps) 9 | { 10 | if (ps == NULL || ps->__count == 0) 11 | return 1; 12 | else 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mbsrtowcs.c: -------------------------------------------------------------------------------- 1 | /* doc in mbsnrtowcs.c */ 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | size_t 11 | _mbsrtowcs_r (struct _reent *r, 12 | wchar_t *dst, 13 | const char **src, 14 | size_t len, 15 | mbstate_t *ps) 16 | { 17 | return _mbsnrtowcs_r (r, dst, src, (size_t) -1, len, ps); 18 | } 19 | 20 | #ifndef _REENT_ONLY 21 | size_t 22 | mbsrtowcs (wchar_t *__restrict dst, 23 | const char **__restrict src, 24 | size_t len, 25 | mbstate_t *__restrict ps) 26 | { 27 | return _mbsnrtowcs_r (_REENT, dst, src, (size_t) -1, len, ps); 28 | } 29 | #endif /* !_REENT_ONLY */ 30 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/msize.c: -------------------------------------------------------------------------------- 1 | #ifndef MALLOC_PROVIDED 2 | /* msize.c -- a wrapper for malloc_usable_size. */ 3 | 4 | #include <_ansi.h> 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef _REENT_ONLY 10 | 11 | size_t 12 | malloc_usable_size (void *ptr) 13 | { 14 | return _malloc_usable_size_r (_REENT, ptr); 15 | } 16 | 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/msizer.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_MALLOC_USABLE_SIZE 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/mtrim.c: -------------------------------------------------------------------------------- 1 | #ifndef MALLOC_PROVIDED 2 | /* mtrim.c -- a wrapper for malloc_trim. */ 3 | 4 | #include <_ansi.h> 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef _REENT_ONLY 10 | 11 | int 12 | malloc_trim (size_t pad) 13 | { 14 | return _malloc_trim_r (_REENT, pad); 15 | } 16 | 17 | #endif 18 | #endif 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/on_exit_args.h: -------------------------------------------------------------------------------- 1 | #ifndef NEWLIB_CYGWIN_NEWLIB_LIBC_STDLIB_ON_EXIT_ARGS_H_ 2 | #define NEWLIB_CYGWIN_NEWLIB_LIBC_STDLIB_ON_EXIT_ARGS_H_ 3 | 4 | #include 5 | 6 | #ifdef _REENT_SMALL 7 | 8 | extern struct _on_exit_args * const __on_exit_args; 9 | 10 | #endif /* def _REENT_SMALL */ 11 | 12 | #endif /* def NEWLIB_CYGWIN_NEWLIB_LIBC_STDLIB_ON_EXIT_ARGS_H_ */ 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/pvallocr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_PVALLOC 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/realloc.c: -------------------------------------------------------------------------------- 1 | #ifdef MALLOC_PROVIDED 2 | int _dummy_realloc = 1; 3 | #else 4 | /* realloc.c -- a wrapper for realloc_r. */ 5 | 6 | #include <_ansi.h> 7 | #include 8 | #include 9 | #include 10 | 11 | #ifndef _REENT_ONLY 12 | 13 | void * 14 | realloc (void *ap, 15 | size_t nbytes) 16 | { 17 | return _realloc_r (_REENT, ap, nbytes); 18 | } 19 | 20 | #endif 21 | #endif /* MALLOC_PROVIDED */ 22 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/reallor.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_REALLOC 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/strtoll_r.c: -------------------------------------------------------------------------------- 1 | /* dummy */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/strtoull_r.c: -------------------------------------------------------------------------------- 1 | /* dummy */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/valloc.c: -------------------------------------------------------------------------------- 1 | #ifndef MALLOC_PROVIDED 2 | /* valloc.c -- a wrapper for valloc_r and pvalloc_r. */ 3 | 4 | #include <_ansi.h> 5 | #include 6 | #include 7 | #include 8 | 9 | #ifndef _REENT_ONLY 10 | 11 | void * 12 | valloc (size_t nbytes) 13 | { 14 | return _valloc_r (_REENT, nbytes); 15 | } 16 | 17 | void * 18 | pvalloc (size_t nbytes) 19 | { 20 | return _pvalloc_r (_REENT, nbytes); 21 | } 22 | 23 | #endif 24 | #endif 25 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/vallocr.c: -------------------------------------------------------------------------------- 1 | #define INTERNAL_NEWLIB 2 | #define HAVE_MMAP 0 3 | #define DEFINE_VALLOC 4 | 5 | #include "mallocr.t" 6 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/wcsrtombs.c: -------------------------------------------------------------------------------- 1 | /* Doc in wcsnrtombs.c */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | size_t 8 | _wcsrtombs_r (struct _reent *r, 9 | char *dst, 10 | const wchar_t **src, 11 | size_t len, 12 | mbstate_t *ps) 13 | { 14 | return _wcsnrtombs_r (r, dst, src, (size_t) -1, len, ps); 15 | } 16 | 17 | #ifndef _REENT_ONLY 18 | size_t 19 | wcsrtombs (char *__restrict dst, 20 | const wchar_t **__restrict src, 21 | size_t len, 22 | mbstate_t *__restrict ps) 23 | { 24 | return _wcsnrtombs_r (_REENT, dst, src, (size_t) -1, len, ps); 25 | } 26 | #endif /* !_REENT_ONLY */ 27 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/wcstoll_r.c: -------------------------------------------------------------------------------- 1 | /* dummy */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/wcstoull_r.c: -------------------------------------------------------------------------------- 1 | /* dummy */ 2 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/stdlib/wctob.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "local.h" 7 | 8 | int 9 | wctob (wint_t wc) 10 | { 11 | struct _reent *reent; 12 | mbstate_t mbs; 13 | unsigned char pmb[MB_LEN_MAX]; 14 | 15 | if (wc == WEOF) 16 | return EOF; 17 | 18 | /* Put mbs in initial state. */ 19 | memset (&mbs, '\0', sizeof (mbs)); 20 | 21 | reent = _REENT; 22 | _REENT_CHECK_MISC(reent); 23 | 24 | return __WCTOMB (reent, (char *) pmb, wc, &mbs) == 1 ? (int) pmb[0] : EOF; 25 | } 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/bcopy.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---copy memory regions 4 | 5 | SYNOPSIS 6 | #include 7 | void bcopy(const void *<[in]>, void *<[out]>, size_t <[n]>); 8 | 9 | DESCRIPTION 10 | This function copies <[n]> bytes from the memory region 11 | pointed to by <[in]> to the memory region pointed to by 12 | <[out]>. 13 | 14 | This function is implemented in term of <>. 15 | 16 | PORTABILITY 17 | <> requires no supporting OS subroutines. 18 | 19 | QUICKREF 20 | bcopy - pure 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | void 27 | bcopy (const void *b1, 28 | void *b2, 29 | size_t length) 30 | { 31 | memmove (b2, b1, length); 32 | } 33 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/bzero.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---initialize memory to zero 4 | 5 | INDEX 6 | bzero 7 | 8 | SYNOPSIS 9 | #include 10 | void bzero(void *<[b]>, size_t <[length]>); 11 | 12 | DESCRIPTION 13 | <> initializes <[length]> bytes of memory, starting at address 14 | <[b]>, to zero. 15 | 16 | RETURNS 17 | <> does not return a result. 18 | 19 | PORTABILITY 20 | <> is in the Berkeley Software Distribution. 21 | Neither ANSI C nor the System V Interface Definition (Issue 2) require 22 | <>. 23 | 24 | <> requires no supporting OS subroutines. 25 | */ 26 | 27 | #include 28 | 29 | void 30 | bzero(void *b, size_t length) 31 | { 32 | 33 | memset(b, 0, length); 34 | } 35 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/explicit_bzero.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */ 2 | /* 3 | * Public domain. 4 | * Written by Ted Unangst 5 | */ 6 | 7 | #include 8 | 9 | /* 10 | * explicit_bzero - don't let the compiler optimize away bzero 11 | */ 12 | void 13 | explicit_bzero(void *p, size_t n) 14 | { 15 | bzero(p, n); 16 | } 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/gnu_basename.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_BASENAME 2 | /* Copyright 2015 Red Hat, Inc. 3 | * Permission to use, copy, modify, and distribute this software 4 | * is freely granted, provided that this notice is preserved. 5 | */ 6 | 7 | /* The differences with the POSIX version (unix/basename.c): 8 | * - declared in (instead of ); 9 | * - the argument is never modified, and therefore is marked const; 10 | * - the empty string is returned if path is an empty string, "/", or ends 11 | * with a trailing slash. 12 | */ 13 | 14 | #include 15 | 16 | char * 17 | __gnu_basename (const char *path) 18 | { 19 | char *p; 20 | if ((p = strrchr (path, '/'))) 21 | return p + 1; 22 | return (char *) path; 23 | } 24 | 25 | #endif /* !_NO_BASENAME */ 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/local.h: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | #include "../ctype/local.h" 3 | 4 | /* internal function to compute width of wide char. */ 5 | int __wcwidth (wint_t); 6 | 7 | /* 8 | Taken from glibc: 9 | Add the compiler optimization to inhibit loop transformation to library 10 | calls. This is used to avoid recursive calls in memset and memmove 11 | default implementations. 12 | */ 13 | #ifdef _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL 14 | # define __inhibit_loop_to_libcall \ 15 | __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns"))) 16 | #else 17 | # define __inhibit_loop_to_libcall 18 | #endif 19 | 20 | 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strdup.c: -------------------------------------------------------------------------------- 1 | #ifndef _REENT_ONLY 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | char * 8 | strdup (const char *str) 9 | { 10 | return _strdup_r (_REENT, str); 11 | } 12 | 13 | #endif /* !_REENT_ONLY */ 14 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strdup_r.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | char * 6 | _strdup_r (struct _reent *reent_ptr, 7 | const char *str) 8 | { 9 | size_t len = strlen (str) + 1; 10 | char *copy = _malloc_r (reent_ptr, len); 11 | if (copy) 12 | { 13 | memcpy (copy, str, len); 14 | } 15 | return copy; 16 | } 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strlwr.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---force string to lowercase 4 | 5 | INDEX 6 | strlwr 7 | 8 | SYNOPSIS 9 | #include 10 | char *strlwr(char *<[a]>); 11 | 12 | DESCRIPTION 13 | <> converts each character in the string at <[a]> to 14 | lowercase. 15 | 16 | RETURNS 17 | <> returns its argument, <[a]>. 18 | 19 | PORTABILITY 20 | <> is not widely portable. 21 | 22 | <> requires no supporting OS subroutines. 23 | 24 | QUICKREF 25 | strlwr 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | char * 32 | strlwr (char *s) 33 | { 34 | unsigned char *ucs = (unsigned char *) s; 35 | for ( ; *ucs != '\0'; ucs++) 36 | { 37 | *ucs = tolower(*ucs); 38 | } 39 | return s; 40 | } 41 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strndup.c: -------------------------------------------------------------------------------- 1 | #ifndef _REENT_ONLY 2 | 3 | #include <_ansi.h> 4 | #include 5 | #include 6 | #include 7 | 8 | char * 9 | strndup (const char *str, 10 | size_t n) 11 | { 12 | return _strndup_r (_REENT, str, n); 13 | } 14 | 15 | #endif /* !_REENT_ONLY */ 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strndup_r.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | char * 6 | _strndup_r (struct _reent *reent_ptr, 7 | const char *str, 8 | size_t n) 9 | { 10 | const char *ptr = str; 11 | size_t len; 12 | char *copy; 13 | 14 | while (n-- > 0 && *ptr) 15 | ptr++; 16 | 17 | len = ptr - str; 18 | 19 | copy = _malloc_r (reent_ptr, len + 1); 20 | if (copy) 21 | { 22 | memcpy (copy, str, len); 23 | copy[len] = '\0'; 24 | } 25 | return copy; 26 | } 27 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strsep.c: -------------------------------------------------------------------------------- 1 | /* BSD strsep function */ 2 | 3 | /* Copyright 2002, Red Hat Inc. */ 4 | 5 | /* undef STRICT_ANSI so that strsep prototype will be defined */ 6 | #undef __STRICT_ANSI__ 7 | #include 8 | #include <_ansi.h> 9 | #include 10 | 11 | extern char *__strtok_r (char *, const char *, char **, int); 12 | 13 | char * 14 | strsep (register char **source_ptr, 15 | register const char *delim) 16 | { 17 | return __strtok_r (*source_ptr, delim, source_ptr, 0); 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/strupr.c: -------------------------------------------------------------------------------- 1 | /* 2 | FUNCTION 3 | <>---force string to uppercase 4 | 5 | INDEX 6 | strupr 7 | 8 | SYNOPSIS 9 | #include 10 | char *strupr(char *<[a]>); 11 | 12 | DESCRIPTION 13 | <> converts each character in the string at <[a]> to 14 | uppercase. 15 | 16 | RETURNS 17 | <> returns its argument, <[a]>. 18 | 19 | PORTABILITY 20 | <> is not widely portable. 21 | 22 | <> requires no supporting OS subroutines. 23 | 24 | QUICKREF 25 | strupr 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | char * 32 | strupr (char *s) 33 | { 34 | unsigned char *ucs = (unsigned char *) s; 35 | for ( ; *ucs != '\0'; ucs++) 36 | { 37 | *ucs = toupper(*ucs); 38 | } 39 | return s; 40 | } 41 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/u_strerr.c: -------------------------------------------------------------------------------- 1 | #include <_ansi.h> 2 | 3 | char * 4 | _user_strerror (int errnum, 5 | int internal, 6 | int *errptr) 7 | { 8 | /* prevent warning about unused parameters */ 9 | (void) errnum; 10 | (void) internal; 11 | (void) errptr; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/string/xpg_strerror_r.c: -------------------------------------------------------------------------------- 1 | /* POSIX variant of strerror_r. */ 2 | #undef __STRICT_ANSI__ 3 | #include 4 | #include 5 | 6 | int 7 | __xpg_strerror_r (int errnum, 8 | char *buffer, 9 | size_t n) 10 | { 11 | char *error; 12 | int result = 0; 13 | 14 | if (!n) 15 | return ERANGE; 16 | error = _strerror_r (_REENT, errnum, 1, &result); 17 | if (strlen (error) >= n) 18 | { 19 | memcpy (buffer, error, n - 1); 20 | buffer[n - 1] = '\0'; 21 | return ERANGE; 22 | } 23 | strcpy (buffer, error); 24 | return (result || *error) ? result : EINVAL; 25 | } 26 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysclose.c: -------------------------------------------------------------------------------- 1 | /* connector for close */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | close (int fd) 8 | { 9 | return _close_r (_REENT, fd); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysexecve.c: -------------------------------------------------------------------------------- 1 | /* connector for execve */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | execve (const char *name, 8 | char *const argv[], 9 | char *const env[]) 10 | { 11 | return _execve_r (_REENT, name, argv, env); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysfcntl.c: -------------------------------------------------------------------------------- 1 | /* connector for fcntl */ 2 | /* only called from stdio/fdopen.c, so arg can be int. */ 3 | 4 | #include 5 | #include 6 | 7 | int 8 | fcntl (int fd, 9 | int flag, 10 | int arg) 11 | { 12 | #ifdef HAVE_FCNTL 13 | return _fcntl_r (_REENT, fd, flag, arg); 14 | #else /* !HAVE_FCNTL */ 15 | errno = ENOSYS; 16 | return -1; 17 | #endif /* !HAVE_FCNTL */ 18 | } 19 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysfork.c: -------------------------------------------------------------------------------- 1 | /* connector for fork */ 2 | 3 | /* Don't define this if NO_FORK. See for example libc/sys/win32/spawn.c. */ 4 | 5 | #ifndef NO_FORK 6 | 7 | #include 8 | #include 9 | 10 | int 11 | fork (void) 12 | { 13 | return _fork_r (_REENT); 14 | } 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysfstat.c: -------------------------------------------------------------------------------- 1 | /* connector for fstat */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int 8 | fstat (int fd, 9 | struct stat *pstat) 10 | { 11 | return _fstat_r (_REENT, fd, pstat); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysgetpid.c: -------------------------------------------------------------------------------- 1 | /* connector for getpid */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | getpid (void) 8 | { 9 | return _getpid_r (_REENT); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysgettod.c: -------------------------------------------------------------------------------- 1 | /* connector for gettimeofday */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int 8 | gettimeofday (struct timeval *ptimeval, 9 | void *ptimezone) 10 | { 11 | return _gettimeofday_r (_REENT, ptimeval, ptimezone); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysisatty.c: -------------------------------------------------------------------------------- 1 | /* connector for isatty */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | isatty (int fd) 8 | { 9 | #ifdef REENTRANT_SYSCALLS_PROVIDED 10 | return _isatty_r (_REENT, fd); 11 | #else 12 | return _isatty (fd); 13 | #endif 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syskill.c: -------------------------------------------------------------------------------- 1 | /* connector for kill */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | kill (int pid, 8 | int sig) 9 | { 10 | return _kill_r (_REENT, pid, sig); 11 | } 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syslink.c: -------------------------------------------------------------------------------- 1 | /* connector for link */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | link (const char *old, 8 | const char *new) 9 | { 10 | return _link_r (_REENT, old, new); 11 | } 12 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syslseek.c: -------------------------------------------------------------------------------- 1 | /* connector for lseek */ 2 | 3 | #include 4 | #include 5 | 6 | off_t 7 | lseek (int fd, 8 | off_t pos, 9 | int whence) 10 | { 11 | return _lseek_r (_REENT, fd, pos, whence); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysopen.c: -------------------------------------------------------------------------------- 1 | /* connector for open */ 2 | 3 | #include 4 | #include 5 | 6 | 7 | /* The prototype in uses ..., so we must correspond. */ 8 | 9 | #include 10 | 11 | int 12 | open (const char *file, 13 | int flags, ...) 14 | { 15 | va_list ap; 16 | int ret; 17 | 18 | va_start (ap, flags); 19 | ret = _open_r (_REENT, file, flags, va_arg (ap, int)); 20 | va_end (ap); 21 | return ret; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysread.c: -------------------------------------------------------------------------------- 1 | /* connector for read */ 2 | 3 | #include 4 | #include 5 | 6 | _READ_WRITE_RETURN_TYPE 7 | read (int fd, 8 | void *buf, 9 | size_t cnt) 10 | { 11 | return _read_r (_REENT, fd, buf, cnt); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syssbrk.c: -------------------------------------------------------------------------------- 1 | /* connector for sbrk */ 2 | 3 | #include 4 | #include 5 | 6 | extern void *_sbrk_r (struct _reent *, ptrdiff_t); 7 | extern void *_sbrk (ptrdiff_t); 8 | 9 | void * 10 | sbrk (ptrdiff_t incr) 11 | { 12 | return _sbrk_r (_REENT, incr); 13 | } 14 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysstat.c: -------------------------------------------------------------------------------- 1 | /* connector for stat */ 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int 8 | stat (const char *file, 9 | struct stat *pstat) 10 | { 11 | return _stat_r (_REENT, file, pstat); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/systimes.c: -------------------------------------------------------------------------------- 1 | /* connector for times */ 2 | 3 | #include 4 | #include 5 | 6 | clock_t 7 | times (struct tms *buf) 8 | { 9 | return _times_r (_REENT, buf); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/sysunlink.c: -------------------------------------------------------------------------------- 1 | /* connector for unlink */ 2 | 3 | #include 4 | #include 5 | 6 | int 7 | unlink (const char *file) 8 | { 9 | return _unlink_r (_REENT, file); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syswait.c: -------------------------------------------------------------------------------- 1 | /* connector for wait */ 2 | 3 | #include 4 | #include 5 | 6 | pid_t 7 | wait (int *status) 8 | { 9 | return _wait_r (_REENT, status); 10 | } 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/syscalls/syswrite.c: -------------------------------------------------------------------------------- 1 | /* connector for write */ 2 | 3 | #include 4 | #include 5 | 6 | _READ_WRITE_RETURN_TYPE 7 | write (int fd, 8 | const void *buf, 9 | size_t cnt) 10 | { 11 | return _write_r (_REENT, fd, buf, cnt); 12 | } 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/asctime_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * asctime_r.c 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | char * 9 | asctime_r (const struct tm *__restrict tim_p, 10 | char *__restrict result) 11 | { 12 | static const char day_name[7][3] = { 13 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" 14 | }; 15 | static const char mon_name[12][3] = { 16 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", 17 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 18 | }; 19 | 20 | siprintf (result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", 21 | day_name[tim_p->tm_wday], 22 | mon_name[tim_p->tm_mon], 23 | tim_p->tm_mday, tim_p->tm_hour, tim_p->tm_min, 24 | tim_p->tm_sec, 1900 + tim_p->tm_year); 25 | return result; 26 | } 27 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/ctime_r.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ctime_r.c 3 | */ 4 | 5 | #include 6 | 7 | char * 8 | ctime_r (const time_t * tim_p, 9 | char * result) 10 | 11 | { 12 | struct tm tm; 13 | return asctime_r (localtime_r (tim_p, &tm), result); 14 | } 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/difftime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * difftime.c 3 | * Original Author: G. Haley 4 | */ 5 | 6 | /* 7 | FUNCTION 8 | <>---subtract two times 9 | 10 | INDEX 11 | difftime 12 | 13 | SYNOPSIS 14 | #include 15 | double difftime(time_t <[tim1]>, time_t <[tim2]>); 16 | 17 | DESCRIPTION 18 | Subtracts the two times in the arguments: `<<<[tim1]> - <[tim2]>>>'. 19 | 20 | RETURNS 21 | The difference (in seconds) between <[tim2]> and <[tim1]>, as a <>. 22 | 23 | PORTABILITY 24 | ANSI C requires <>, and defines its result to be in seconds 25 | in all implementations. 26 | 27 | <> requires no supporting OS subroutines. 28 | */ 29 | 30 | #include 31 | 32 | double 33 | difftime (time_t tim1, 34 | time_t tim2) 35 | { 36 | return (double)(tim1 - tim2); 37 | } 38 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/gettzinfo.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "local.h" 3 | 4 | /* Shared timezone information for libc/time functions. */ 5 | static __tzinfo_type tzinfo = {1, 0, 6 | { {'J', 0, 0, 0, 0, (time_t)0, 0L }, 7 | {'J', 0, 0, 0, 0, (time_t)0, 0L } 8 | } 9 | }; 10 | 11 | __tzinfo_type * 12 | __gettzinfo (void) 13 | { 14 | return &tzinfo; 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/month_lengths.c: -------------------------------------------------------------------------------- 1 | /* 2 | * month_lengths.c 3 | * 4 | * Array __month_lengths[] is (indirectly) needed by tzset(), mktime(), 5 | * gmtime() and localtime(). To break any dependencies, this array is moved to 6 | * separate source file. 7 | */ 8 | 9 | #include "local.h" 10 | 11 | const int __month_lengths[2][MONSPERYEAR] = { 12 | {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}, 13 | {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} 14 | } ; 15 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/strptime.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/libs/libc/src/time/strptime.c -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/time/tzvars.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Global timezone variables. */ 4 | 5 | /* Default timezone to GMT */ 6 | char *_tzname[2] = {"GMT", "GMT"}; 7 | int _daylight = 0; 8 | long _timezone = 0; 9 | 10 | 11 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/unix/basename.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_BASENAME 2 | /* Copyright 2005 Shaun Jackman 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 | char* 11 | basename (char *path) 12 | { 13 | char *p; 14 | if( path == NULL || *path == '\0' ) 15 | return "."; 16 | p = path + strlen(path) - 1; 17 | while( *p == '/' ) { 18 | if( p == path ) 19 | return path; 20 | *p-- = '\0'; 21 | } 22 | while( p >= path && *p != '/' ) 23 | p--; 24 | return p + 1; 25 | } 26 | 27 | #endif /* !_NO_BASENAME */ 28 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/unix/dirname.c: -------------------------------------------------------------------------------- 1 | #ifndef _NO_DIRNAME 2 | 3 | /* Copyright 2005 Shaun Jackman 4 | * Permission to use, copy, modify, and distribute this software 5 | * is freely granted, provided that this notice is preserved. 6 | */ 7 | 8 | #include 9 | #include 10 | 11 | char * 12 | dirname (char *path) 13 | { 14 | char *p; 15 | if( path == NULL || *path == '\0' ) 16 | return "."; 17 | p = path + strlen(path) - 1; 18 | while( *p == '/' ) { 19 | if( p == path ) 20 | return path; 21 | *p-- = '\0'; 22 | } 23 | while( p >= path && *p != '/' ) 24 | p--; 25 | return 26 | p < path ? "." : 27 | p == path ? "/" : 28 | (*p = '\0', path); 29 | } 30 | 31 | #endif /* !_NO_DIRNAME */ 32 | -------------------------------------------------------------------------------- /navy-apps/libs/libc/src/unix/ttyname.h: -------------------------------------------------------------------------------- 1 | /* Common defines for ttyname.c and ttyname_r.c */ 2 | 3 | #include /* For MAXNAMLEN */ 4 | #include /* For _PATH_DEV */ 5 | 6 | #define TTYNAME_BUFSIZE (sizeof (_PATH_DEV) + MAXNAMLEN) 7 | -------------------------------------------------------------------------------- /navy-apps/libs/libfont/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libfont 2 | SRCS = $(shell find src/ -name "*.c" -o -name "*.cpp") 3 | 4 | include $(NAVY_HOME)/Makefile.lib 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libfont/fonts/convert: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for size in 7 8 9 10 11 12 13 4 | do 5 | otf2bdf courier_10_pitch.ttf -l "0_255" -p $(( ${size} + 1 )) > ${NAVY_HOME}/initrd/fonts/Courier-${size}.bdf 6 | done 7 | -------------------------------------------------------------------------------- /navy-apps/libs/libfont/fonts/courier_10_pitch.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/navy-apps/libs/libfont/fonts/courier_10_pitch.ttf -------------------------------------------------------------------------------- /navy-apps/libs/libfont/include/font.h: -------------------------------------------------------------------------------- 1 | #ifndef __FONT_H__ 2 | #define __FONT_H__ 3 | 4 | #include 5 | 6 | class Font { 7 | private: 8 | int w1, h1; 9 | void create(uint32_t ch, int *bbx, uint32_t *bitmap, int count); 10 | 11 | public: 12 | const char *name; 13 | int w, h; 14 | uint32_t *font[256]; 15 | 16 | Font(const char *filename); 17 | ~Font(); 18 | }; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /navy-apps/libs/libndl/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libndl 2 | SRCS = $(shell find src/ -name "*.c") 3 | 4 | include $(NAVY_HOME)/Makefile.lib 5 | -------------------------------------------------------------------------------- /navy-apps/libs/libos/Makefile: -------------------------------------------------------------------------------- 1 | NAME = libos 2 | SRCS = src/nanos.c 3 | 4 | ifeq ($(ISA), native) 5 | build/native.so: src/native.cpp 6 | mkdir -p build/ 7 | g++ -std=c++11 -O1 -fPIC -shared -o build/native.so src/native.cpp -ldl -lSDL2 8 | 9 | else 10 | include $(NAVY_HOME)/Makefile.lib 11 | endif 12 | 13 | -------------------------------------------------------------------------------- /navy-apps/libs/libos/src/syscall.h: -------------------------------------------------------------------------------- 1 | #ifndef __SYSCALL_H__ 2 | #define __SYSCALL_H__ 3 | 4 | enum { 5 | SYS_exit, 6 | SYS_yield, 7 | SYS_open, 8 | SYS_read, 9 | SYS_write, 10 | SYS_kill, 11 | SYS_getpid, 12 | SYS_close, 13 | SYS_lseek, 14 | SYS_brk, 15 | SYS_fstat, 16 | SYS_time, 17 | SYS_signal, 18 | SYS_execve, 19 | SYS_fork, 20 | SYS_link, 21 | SYS_unlink, 22 | SYS_wait, 23 | SYS_times, 24 | SYS_gettimeofday 25 | }; 26 | 27 | extern char end; 28 | extern intptr_t program_brk; 29 | #endif 30 | -------------------------------------------------------------------------------- /navy-apps/tests/bmp/Makefile: -------------------------------------------------------------------------------- 1 | NAME = bmptest 2 | SRCS = main.cpp 3 | LIBS += libndl 4 | 5 | export NWM_APP 6 | include $(NAVY_HOME)/Makefile.app 7 | -------------------------------------------------------------------------------- /navy-apps/tests/bmp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() { 6 | NDL_Bitmap *bmp = (NDL_Bitmap*)malloc(sizeof(NDL_Bitmap)); 7 | NDL_LoadBitmap(bmp, "/share/pictures/projectn.bmp"); 8 | assert(bmp->pixels); 9 | NDL_OpenDisplay(bmp->w, bmp->h); 10 | NDL_DrawRect(bmp->pixels, 0, 0, bmp->w, bmp->h); 11 | NDL_Render(); 12 | NDL_CloseDisplay(); 13 | while (1); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /navy-apps/tests/dummy/Makefile: -------------------------------------------------------------------------------- 1 | NAME = dummy 2 | SRCS = dummy.c 3 | 4 | include $(NAVY_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /navy-apps/tests/dummy/dummy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SYS_yield 1 4 | extern int _syscall_(int, uintptr_t, uintptr_t, uintptr_t); 5 | 6 | int main() { 7 | return _syscall_(SYS_yield, 0, 0, 0); 8 | } 9 | -------------------------------------------------------------------------------- /navy-apps/tests/events/Makefile: -------------------------------------------------------------------------------- 1 | NAME = events 2 | SRCS = events.c 3 | 4 | include $(NAVY_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /navy-apps/tests/events/events.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | FILE *fp = fopen("/dev/events", "r"); 5 | volatile int j = 0; 6 | while(1) { 7 | j ++; 8 | if (j == 1000000) { 9 | char buf[256]; 10 | char *p = buf, ch; 11 | while ((ch = fgetc(fp)) != -1) { 12 | *p ++ = ch; 13 | if(ch == '\n') { 14 | *p = '\0'; 15 | break; 16 | } 17 | } 18 | p = buf; 19 | 20 | printf("receive event: %s", buf); 21 | j = 0; 22 | } 23 | } 24 | 25 | fclose(fp); 26 | return 0; 27 | } 28 | 29 | -------------------------------------------------------------------------------- /navy-apps/tests/hello/Makefile: -------------------------------------------------------------------------------- 1 | NAME = hello 2 | SRCS = hello.c 3 | 4 | include $(NAVY_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /navy-apps/tests/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | write(1, "Hello World!\n", 13); 6 | int i = 2; 7 | volatile int j = 0; 8 | while (1) { 9 | j ++; 10 | if (j == 10000) { 11 | printf("Hello World from Navy-apps for the %dth time!\n", i ++); 12 | j = 0; 13 | } 14 | } 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /navy-apps/tests/text/Makefile: -------------------------------------------------------------------------------- 1 | NAME = text 2 | SRCS = text.c 3 | 4 | include $(NAVY_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nemu/.code.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { unsigned result = (1878149490); printf("%u", result); return 0; } -------------------------------------------------------------------------------- /nemu/.gitignore: -------------------------------------------------------------------------------- 1 | *.* 2 | * 3 | !*/ 4 | !Makefile* 5 | !*.[cSh] 6 | !.gitignore 7 | !README.md 8 | !runall.sh 9 | -------------------------------------------------------------------------------- /nemu/Makefile.git: -------------------------------------------------------------------------------- 1 | STUID = U201514716 2 | STUNAME = 罗海旻 3 | 4 | # DO NOT modify the following code!!! 5 | 6 | GITFLAGS = -q --author='tracer-ics2018 ' --no-verify --allow-empty 7 | 8 | # prototype: git_commit(msg) 9 | define git_commit 10 | -@git add .. -A --ignore-errors 11 | -@while (test -e .git/index.lock); do sleep 0.1; done 12 | -@(echo "> $(1)" && echo $(STUID) && id -un && uname -a && uptime && (head -c 20 /dev/urandom | hexdump -v -e '"%02x"') && echo) | git commit -F - $(GITFLAGS) 13 | -@sync 14 | endef 15 | -------------------------------------------------------------------------------- /nemu/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | // #define DEBUG 5 | // #define DIFF_TEST 6 | 7 | #if _SHARE 8 | // do not enable these features while building a reference design 9 | #undef DIFF_TEST 10 | #undef DEBUG 11 | #endif 12 | 13 | /* You will define this macro in PA2 */ 14 | #define HAS_IOE 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | typedef uint8_t bool; 21 | 22 | typedef uint32_t rtlreg_t; 23 | 24 | typedef uint32_t paddr_t; 25 | typedef uint32_t vaddr_t; 26 | 27 | typedef uint16_t ioaddr_t; 28 | 29 | #define false 0 30 | #define true 1 31 | 32 | #include "debug.h" 33 | #include "macro.h" 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /nemu/include/cpu/cc.h: -------------------------------------------------------------------------------- 1 | #ifndef __CC_H__ 2 | #define __CC_H__ 3 | 4 | static inline const char* get_cc_name(int subcode) { 5 | static const char *cc_name[] = { 6 | "o", "no", "b", "nb", 7 | "e", "ne", "be", "nbe", 8 | "s", "ns", "p", "np", 9 | "l", "nl", "le", "nle" 10 | }; 11 | return cc_name[subcode]; 12 | } 13 | 14 | void rtl_setcc(rtlreg_t*, uint8_t); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /nemu/include/cpu/relop.h: -------------------------------------------------------------------------------- 1 | #ifndef __RELOP_H__ 2 | #define __RELOP_H__ 3 | 4 | // relation operation 5 | enum { 6 | // +-- unsign 7 | // | +-- sign 8 | // | | +-- equal 9 | // | | | +-- invert 10 | // | | | | 11 | RELOP_FALSE = 0 | 0 | 0 | 0, 12 | RELOP_TRUE = 0 | 0 | 0 | 1, 13 | RELOP_EQ = 0 | 0 | 2 | 0, 14 | RELOP_NE = 0 | 0 | 2 | 1, 15 | 16 | RELOP_LT = 0 | 4 | 0 | 0, 17 | RELOP_LE = 0 | 4 | 2 | 0, 18 | RELOP_GT = 0 | 4 | 2 | 1, 19 | RELOP_GE = 0 | 4 | 0 | 1, 20 | 21 | RELOP_LTU = 8 | 0 | 0 | 0, 22 | RELOP_LEU = 8 | 0 | 2 | 0, 23 | RELOP_GTU = 8 | 0 | 2 | 1, 24 | RELOP_GEU = 8 | 0 | 0 | 1, 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /nemu/include/device/mmio.h: -------------------------------------------------------------------------------- 1 | #ifndef __MMIO_H__ 2 | #define __MMIO_H__ 3 | 4 | #include "common.h" 5 | 6 | typedef void(*mmio_callback_t)(paddr_t, int, bool); 7 | 8 | void* add_mmio_map(paddr_t, int, mmio_callback_t); 9 | int is_mmio(paddr_t); 10 | 11 | uint32_t mmio_read(paddr_t, int, int); 12 | void mmio_write(paddr_t, int, uint32_t, int); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /nemu/include/device/port-io.h: -------------------------------------------------------------------------------- 1 | #ifndef __PORT_IO_H__ 2 | #define __PORT_IO_H__ 3 | 4 | #include "common.h" 5 | 6 | typedef void(*pio_callback_t)(ioaddr_t, int, bool); 7 | 8 | void* add_pio_map(ioaddr_t, int, pio_callback_t); 9 | 10 | uint32_t pio_read_l(ioaddr_t addr); 11 | uint32_t pio_read_w(ioaddr_t addr); 12 | uint32_t pio_read_b(ioaddr_t addr); 13 | void pio_write_l(ioaddr_t addr, uint32_t data); 14 | void pio_write_w(ioaddr_t addr, uint32_t data); 15 | void pio_write_b(ioaddr_t addr, uint32_t data); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /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 | 13 | #endif 14 | -------------------------------------------------------------------------------- /nemu/include/memory/memory.h: -------------------------------------------------------------------------------- 1 | #ifndef __MEMORY_H__ 2 | #define __MEMORY_H__ 3 | 4 | #include "common.h" 5 | 6 | extern uint8_t pmem[]; 7 | 8 | /* convert the guest physical address in the guest program to host virtual address in NEMU */ 9 | #define guest_to_host(p) ((void *)(pmem + (unsigned)p)) 10 | /* convert the host virtual address in NEMU to guest physical address in the guest program */ 11 | #define host_to_guest(p) ((paddr_t)((void *)p - (void *)pmem)) 12 | 13 | uint32_t vaddr_read(vaddr_t, int); 14 | uint32_t paddr_read(paddr_t, int); 15 | void vaddr_write(vaddr_t, uint32_t, int); 16 | void paddr_write(paddr_t, uint32_t, int); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /nemu/include/monitor/expr.h: -------------------------------------------------------------------------------- 1 | #ifndef __EXPR_H__ 2 | #define __EXPR_H__ 3 | 4 | #include "common.h" 5 | 6 | uint32_t expr(char *, bool *); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /nemu/include/monitor/monitor.h: -------------------------------------------------------------------------------- 1 | #ifndef __MONITOR_H__ 2 | #define __MONITOR_H__ 3 | 4 | enum { NEMU_STOP, NEMU_RUNNING, NEMU_END, NEMU_ABORT }; 5 | extern int nemu_state; 6 | 7 | #define ENTRY_START 0x100000 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /nemu/include/monitor/watchpoint.h: -------------------------------------------------------------------------------- 1 | #ifndef __WATCHPOINT_H__ 2 | #define __WATCHPOINT_H__ 3 | 4 | #include "common.h" 5 | 6 | typedef struct watchpoint { 7 | int NO; 8 | struct watchpoint *next; 9 | 10 | /* TODO: Add more members if necessary */ 11 | char expression[1024]; 12 | uint32_t old_value; 13 | 14 | 15 | } WP; 16 | 17 | WP* new_wp(); 18 | 19 | void free_wp(int n); 20 | 21 | WP* get_wp_head(); 22 | 23 | WP* get_free_head(); 24 | 25 | WP* check_watchpoints(); 26 | 27 | WP* print_watchpoints(); 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /nemu/include/nemu.h: -------------------------------------------------------------------------------- 1 | #ifndef __NEMU_H__ 2 | #define __NEMU_H__ 3 | 4 | #include "common.h" 5 | #include "memory/memory.h" 6 | #include "cpu/reg.h" 7 | #include "device/mmio.h" 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /nemu/include/util/c_op.h: -------------------------------------------------------------------------------- 1 | #ifndef __C_OP_H__ 2 | #define __C_OP_H__ 3 | 4 | #define c_add(a, b) ((a) + (b)) 5 | #define c_sub(a, b) ((a) - (b)) 6 | #define c_and(a, b) ((a) & (b)) 7 | #define c_or(a, b) ((a) | (b)) 8 | #define c_xor(a, b) ((a) ^ (b)) 9 | #define c_shl(a, b) ((a) << (b)) 10 | #define c_shr(a, b) ((a) >> (b)) 11 | #define c_sar(a, b) ((int32_t)(a) >> (b)) 12 | #define c_mul_lo(a, b) ((a) * (b)) 13 | #define c_mul_hi(a, b) (((uint64_t)(a) * (uint64_t)(b)) >> 32) 14 | #define c_imul_lo(a, b) ((int32_t)(a) * (int32_t)(b)) 15 | #define c_imul_hi(a, b) (((int64_t)(int32_t)(a) * (int64_t)(int32_t)(b)) >> 32) 16 | #define c_div_q(a, b) ((a) / (b)) 17 | #define c_div_r(a, b) ((a) % (b)) 18 | #define c_idiv_q(a, b) ((int32_t)(a) / (int32_t)(b)) 19 | #define c_idiv_r(a, b) ((int32_t)(a) % (int32_t)(b)) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /nemu/src/cpu/exec/prefix.c: -------------------------------------------------------------------------------- 1 | #include "cpu/exec.h" 2 | 3 | make_EHelper(real); 4 | 5 | make_EHelper(operand_size) { 6 | decoding.is_operand_size_16 = true; 7 | exec_real(eip); 8 | decoding.is_operand_size_16 = false; 9 | } 10 | -------------------------------------------------------------------------------- /nemu/src/device/timer.c: -------------------------------------------------------------------------------- 1 | #include "device/port-io.h" 2 | #include "monitor/monitor.h" 3 | #include 4 | 5 | #define RTC_PORT 0x48 // Note that this is not the standard 6 | 7 | void timer_intr() { 8 | if (nemu_state == NEMU_RUNNING) { 9 | extern void dev_raise_intr(void); 10 | dev_raise_intr(); 11 | } 12 | } 13 | 14 | static uint32_t *rtc_port_base; 15 | 16 | void rtc_io_handler(ioaddr_t addr, int len, bool is_write) { 17 | if (!is_write) { 18 | struct timeval now; 19 | gettimeofday(&now, NULL); 20 | uint32_t seconds = now.tv_sec; 21 | uint32_t useconds = now.tv_usec; 22 | rtc_port_base[0] = seconds * 1000 + (useconds + 500) / 1000; 23 | } 24 | } 25 | 26 | void init_timer() { 27 | rtc_port_base = add_pio_map(RTC_PORT, 4, rtc_io_handler); 28 | } 29 | -------------------------------------------------------------------------------- /nemu/src/monitor/diff-test/diff-test.h: -------------------------------------------------------------------------------- 1 | #ifndef __DIFF_TEST_H__ 2 | #define __DIFF_TEST_H__ 3 | 4 | #define DIFFTEST_REG_SIZE (sizeof(uint32_t) * 9) // GRPs + EIP 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /nemu/src/monitor/diff-test/ref.c: -------------------------------------------------------------------------------- 1 | #include "nemu.h" 2 | #include "diff-test.h" 3 | 4 | void cpu_exec(uint64_t); 5 | 6 | void difftest_memcpy_from_dut(paddr_t dest, void *src, size_t n) { 7 | memcpy(guest_to_host(dest), src, n); 8 | } 9 | 10 | void difftest_getregs(void *r) { 11 | memcpy(r, &cpu, DIFFTEST_REG_SIZE); 12 | } 13 | 14 | void difftest_setregs(const void *r) { 15 | memcpy(&cpu, r, DIFFTEST_REG_SIZE); 16 | } 17 | 18 | void difftest_exec(uint64_t n) { 19 | cpu_exec(n); 20 | } 21 | 22 | void difftest_init(void) { 23 | } 24 | -------------------------------------------------------------------------------- /nemu/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char const *argv[]) 5 | { 6 | /* code */ 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /nemu/tools/gen-expr/.gitignore: -------------------------------------------------------------------------------- 1 | .code.c 2 | -------------------------------------------------------------------------------- /nemu/tools/gen-expr/Makefile: -------------------------------------------------------------------------------- 1 | APP=gen-expr 2 | 3 | $(APP): gen-expr.c 4 | gcc -O2 -Wall -Werror -o $@ $< 5 | 6 | .PHONY: clean 7 | clean: 8 | -rm $(APP) .code.c .expr 9 | -------------------------------------------------------------------------------- /nemu/tools/gen-expr/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int t = -5; 5 | unsigned int ut = (unsigned int)t; 6 | printf("%x\n", (unsigned int)t); 7 | unsigned int tt = ut & 0xffff; 8 | int ttt = (unsigned int)(short)tt; 9 | printf("%08x\n", ttt); 10 | unsigned short a = 10; 11 | int b = -1; 12 | printf("%08x\n", a-b); 13 | 14 | printf("%u\n", (363729771)*175863475); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /nemu/tools/qemu-diff/include/common.h: -------------------------------------------------------------------------------- 1 | #ifndef __COMMON_H__ 2 | #define __COMMON_H__ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | typedef uint8_t bool; 12 | #define true 1 13 | #define false 0 14 | 15 | #include "protocol.h" 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /nexus-am/.gitignore: -------------------------------------------------------------------------------- 1 | !* 2 | !*.* 3 | .* 4 | !.gitignore 5 | *~ 6 | *.a 7 | *.o 8 | *.d 9 | *.pyc 10 | *.ini 11 | *.log 12 | tags 13 | cscope.* 14 | build/ 15 | -------------------------------------------------------------------------------- /nexus-am/Makefile: -------------------------------------------------------------------------------- 1 | include Makefile.check 2 | 3 | AM_HOME ?= $(shell pwd) 4 | 5 | all: 6 | @$(MAKE) -C am 7 | 8 | # clean everything 9 | ALLMAKE = $(dir $(shell find . -mindepth 2 -name "Makefile")) 10 | $(ALLMAKE): 11 | -@$(MAKE) -s -C $@ clean 12 | 13 | clean: $(ALLMAKE) 14 | 15 | .PHONY: all clean $(ALLMAKE) 16 | -------------------------------------------------------------------------------- /nexus-am/Makefile.check: -------------------------------------------------------------------------------- 1 | ifneq ($(MAKECMDGOALS),clean) # ignore check for make clean 2 | 3 | ifeq ($(AM_HOME),) # AM_HOME must exist 4 | $(error Environment variable AM_HOME must be defined.) 5 | endif 6 | 7 | # ARCH ?= native 8 | ARCH ?= x86-nemu 9 | ARCHS = $(shell ls $(AM_HOME)/am/arch/) 10 | 11 | ifeq ($(filter $(ARCHS), $(ARCH)), ) # ARCH must be valid 12 | $(error Invalid ARCH. Supported: $(ARCHS)) 13 | endif 14 | 15 | endif 16 | -------------------------------------------------------------------------------- /nexus-am/Makefile.lib: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/Makefile.check 2 | $(info Building $(NAME) [$(ARCH)]) 3 | 4 | LIB_DIR ?= $(shell pwd) 5 | INC_DIR += $(LIB_DIR)/include/ 6 | DST_DIR ?= $(LIB_DIR)/build/$(ARCH)/ 7 | ARCHIVE ?= $(LIB_DIR)/build/$(NAME)-$(ARCH).a 8 | 9 | .DEFAULT_GOAL = $(ARCHIVE) 10 | 11 | INC_DIR += $(addsuffix /include/, $(addprefix $(AM_HOME)/libs/, $(LIBS))) 12 | 13 | CFLAGS += -fdata-sections -ffunction-sections -fno-builtin 14 | 15 | $(shell mkdir -p $(DST_DIR)) 16 | 17 | include $(AM_HOME)/Makefile.compile 18 | 19 | $(ARCHIVE): $(OBJS) 20 | @echo + AR $@ 21 | @ar rcs $(ARCHIVE) $(OBJS) 22 | 23 | .PHONY: clean 24 | clean: 25 | rm -rf $(LIB_DIR)/build/ 26 | -------------------------------------------------------------------------------- /nexus-am/am/Makefile: -------------------------------------------------------------------------------- 1 | NAME = am 2 | SRCS = $(shell find -L ./arch/$(ARCH)/src/ -name "*.c" -o -name "*.cpp" -o -name "*.S") 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.lib 5 | -------------------------------------------------------------------------------- /nexus-am/am/arch/am_native-navy: -------------------------------------------------------------------------------- 1 | x86-navy -------------------------------------------------------------------------------- /nexus-am/am/arch/native/img/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEST=$1 4 | shift 5 | 6 | g++ -pie -o "$DEST" -Wl,--start-group $@ -Wl,--end-group -lSDL2 -lGL -lrt 7 | -------------------------------------------------------------------------------- /nexus-am/am/arch/native/img/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | $1 4 | -------------------------------------------------------------------------------- /nexus-am/am/arch/native/include/arch.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define false 0 8 | #define true 1 9 | 10 | #ifndef __USE_GNU 11 | # define __USE_GNU 12 | #endif 13 | 14 | #include 15 | 16 | struct _Context { 17 | union { 18 | uint8_t pad[1024]; 19 | struct { 20 | ucontext_t uc; 21 | void *prot; 22 | }; 23 | }; 24 | uintptr_t rax; 25 | uintptr_t rip; 26 | }; 27 | 28 | #define GPR1 rax 29 | #define GPR2 uc.uc_mcontext.gregs[REG_RSI] 30 | #define GPR3 uc.uc_mcontext.gregs[REG_RDX] 31 | #define GPR4 uc.uc_mcontext.gregs[REG_RCX] 32 | #define GPRx rax 33 | 34 | #define PGSHIFT 12 35 | #define PGSIZE (1 << PGSHIFT) 36 | 37 | #undef __USE_GNU 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /nexus-am/am/arch/native/src/trap.S: -------------------------------------------------------------------------------- 1 | .global ret_from_trap 2 | .global asm_trap 3 | 4 | asm_trap: 5 | # getcontext() does not preserve %rax, save it manually 6 | pushq %rax 7 | # must have sizeof(ucontect_t) < 1024 8 | subq $1024, %rsp 9 | 10 | movq %rsp, %rdi 11 | call irq_handle 12 | 13 | ret_from_trap: 14 | 15 | addq $1024, %rsp 16 | popq %rax 17 | retq 18 | -------------------------------------------------------------------------------- /nexus-am/am/arch/native/src/trm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | extern void platform_dummy(); 6 | void _trm_init() { 7 | platform_dummy(); 8 | } 9 | 10 | void _putc(char ch) { 11 | putchar(ch); 12 | } 13 | 14 | void _halt(int code) { 15 | printf("Exit (%d)\n", code); 16 | exit(code); 17 | } 18 | 19 | _Area _heap; 20 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/README.md: -------------------------------------------------------------------------------- 1 | # Navy 2 | 3 | Only has TRM + IOE. 4 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/img/Makefile.navy: -------------------------------------------------------------------------------- 1 | LIBS += libndl 2 | include $(NAVY_HOME)/Makefile.app 3 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/img/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DEST=$1 4 | shift 5 | 6 | tmp=`basename $DEST -navy` 7 | ISA=`echo $tmp | grep -o '[^-]*$'` 8 | NAME=`basename $tmp -$ISA` 9 | 10 | mkfile=`pwd`/Makefile.navy 11 | echo "NAME = $NAME-am" > $mkfile 12 | echo "APP = $DEST" >> $mkfile 13 | echo "OBJS = $@" >> $mkfile 14 | cat $AM_HOME/am/arch/x86-navy/img/Makefile.navy >> $mkfile 15 | 16 | make install -f $mkfile ISA=$ISA 17 | 18 | rm $mkfile 19 | 20 | exit 21 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/img/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Cannot run: should be loaded by an OS" 4 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/include/arch.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | #include 5 | #include 6 | 7 | #define false 0 8 | #define true 1 9 | 10 | struct _Context { 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-navy/src/trm.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void _trm_init() { 4 | } 5 | 6 | void _putc(char ch) { 7 | } 8 | 9 | void _halt(int code) { 10 | } 11 | 12 | _Area _heap; 13 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/README.md: -------------------------------------------------------------------------------- 1 | # X86-NEMU 2 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/img/boot/Makefile: -------------------------------------------------------------------------------- 1 | start.o: start.S 2 | gcc -m32 -fno-pic -ffunction-sections -MMD -c start.S -o start.o 3 | 4 | -include start.d 5 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/img/boot/start.S: -------------------------------------------------------------------------------- 1 | .section entry, "ax" 2 | .globl _start 3 | .type _start, @function 4 | 5 | _start: 6 | mov $0, %ebp 7 | mov $_stack_pointer, %esp 8 | call _trm_init # never return 9 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/img/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DIR=${AM_HOME}/am/arch/x86-nemu/img 4 | DEST=$1 5 | shift 6 | 7 | make -C $DIR/boot -s 8 | 9 | ld -melf_i386 --gc-sections -T $DIR/loader.ld -e _start -o $DEST $DIR/boot/start.o --start-group $@ --end-group 10 | objdump -d $DEST > $DEST.txt 11 | 12 | objcopy -S --set-section-flags .bss=alloc,contents -O binary $DEST $DEST.bin 13 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/img/loader.ld: -------------------------------------------------------------------------------- 1 | SECTIONS { 2 | . = 0x100000; 3 | .text : { 4 | *(entry) 5 | *(.text*) 6 | } 7 | etext = .; 8 | _etext = .; 9 | .rodata : { 10 | *(.rodata*) 11 | } 12 | .data : { 13 | *(.data*) 14 | } 15 | edata = .; 16 | _edata = .; 17 | .bss : { 18 | *(.bss*) 19 | } 20 | end = .; 21 | _end = .; 22 | _heap_start = ALIGN(4096); 23 | _stack_pointer = 0x7c00; 24 | _heap_end = 0x8000000; 25 | } 26 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/img/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make -C $NEMU_HOME run ARGS="-b -l `dirname $1`/nemu-log.txt $1.bin" 4 | # make -C $NEMU_HOME run ARGS="-l `dirname $1`/nemu-log.txt $1.bin" 5 | 6 | # make -C $NEMU_HOME gdb ARGS="-b -l `dirname $1`/nemu-log.txt $1.bin" 7 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/include/arch.h: -------------------------------------------------------------------------------- 1 | #ifndef __ARCH_H__ 2 | #define __ARCH_H__ 3 | 4 | #include 5 | 6 | #define PMEM_SIZE (128 * 1024 * 1024) 7 | #define PGSIZE 4096 // Bytes mapped by a page 8 | 9 | typedef uint32_t size_t; 10 | 11 | struct _Context { 12 | 13 | struct _Protect *prot; 14 | uintptr_t edi, esi, ebp, esp, ebx, edx, ecx, eax; 15 | int irq; 16 | uintptr_t err, eip, cs, eflags; 17 | // uintptr_t esp; 18 | }; 19 | 20 | #define GPR1 eax 21 | #define GPR2 ebx 22 | #define GPR3 ecx 23 | #define GPR4 edx 24 | #define GPRx eip 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/include/x86-nemu.h: -------------------------------------------------------------------------------- 1 | #ifndef __X86_NEMU_H__ 2 | #define __X86_NEMU_H__ 3 | 4 | #ifndef __ASSEMBLER__ 5 | /* The following code will be included if the source file is a "*.c" file. */ 6 | 7 | #include 8 | 9 | #endif 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/src/devices/input.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define KEYBORD_PORT 0x60 5 | 6 | size_t input_read(uintptr_t reg, void *buf, size_t size) { 7 | switch (reg) { 8 | case _DEVREG_INPUT_KBD: { 9 | _KbdReg *kbd = (_KbdReg *)buf; 10 | uint32_t p = inl(KEYBORD_PORT); 11 | kbd->keydown = ((p & 0x8000) == 0) ? 0: 1; 12 | kbd->keycode = p; 13 | return sizeof(_KbdReg); 14 | } 15 | } 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/src/trap.S: -------------------------------------------------------------------------------- 1 | #----|-------entry-------|-errorcode-|---irq id---|---handler---| 2 | .globl vecsys; vecsys: pushl $0; pushl $0x80; jmp asm_trap 3 | .globl vectrap; vectrap: pushl $0; pushl $0x81; jmp asm_trap 4 | .globl irq0; irq0: pushl $0; pushl $32; jmp asm_trap 5 | .globl vecnull; vecnull: pushl $0; pushl $-1; jmp asm_trap 6 | 7 | asm_trap: 8 | pushal 9 | 10 | pushl $0 # for prot 11 | 12 | pushl %esp 13 | call irq_handle 14 | 15 | movl %eax, %esp # for context 16 | 17 | # addl $4, %esp 18 | 19 | addl $4, %esp 20 | popal 21 | addl $8, %esp 22 | 23 | iret 24 | -------------------------------------------------------------------------------- /nexus-am/am/arch/x86-nemu/src/trm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define SERIAL_PORT 0x3f8 5 | 6 | extern char _heap_start; 7 | extern char _heap_end; 8 | extern int main(); 9 | 10 | _Area _heap = { 11 | .start = &_heap_start, 12 | .end = &_heap_end, 13 | }; 14 | 15 | void _putc(char ch) { 16 | while ((inb(SERIAL_PORT + 5) & 0x20) == 0); 17 | outb(SERIAL_PORT, ch); 18 | } 19 | 20 | void _halt(int code) { 21 | __asm__ volatile(".byte 0xd6" : :"a"(code)); 22 | 23 | // should not reach here 24 | while (1); 25 | } 26 | 27 | void _trm_init() { 28 | int ret = main(); 29 | _halt(ret); 30 | } 31 | -------------------------------------------------------------------------------- /nexus-am/apps/coremark/Makefile: -------------------------------------------------------------------------------- 1 | NAME = coremark 2 | SRCS = $(shell find -L ./src/ -name "*.c") 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/apps/coremark/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/nexus-am/apps/coremark/README.md -------------------------------------------------------------------------------- /nexus-am/apps/dhrystone/Makefile: -------------------------------------------------------------------------------- 1 | NAME = dhrystone 2 | SRCS = dry.c 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/apps/hello/Makefile: -------------------------------------------------------------------------------- 1 | NAME = hello 2 | SRCS = hello.c 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /nexus-am/apps/hello/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | 3 | 最简单的Hello World程序,使用`_putc`打印一些字符,然后`_halt(0)`终止。 4 | 5 | 能够运行在任何实现了AM (Turing Machine)的平台上。 6 | 7 | ## 编译指南 8 | 9 | 编译前需要设置环境变量AM_HOME为AM项目所在的**绝对路径**。 10 | 11 | 编译时用`make ARCH=xxx`指定具体的体系结构。 -------------------------------------------------------------------------------- /nexus-am/apps/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print(const char *s) { 4 | for (; *s; s ++) { 5 | _putc(*s); 6 | } 7 | } 8 | int main() { 9 | for (int i = 0; i < 10; i ++) { 10 | print("Hello World!\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /nexus-am/apps/litenes/Makefile: -------------------------------------------------------------------------------- 1 | NAME = litenes 2 | SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp" -o -name "*.S") 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /nexus-am/apps/litenes/README.md: -------------------------------------------------------------------------------- 1 | # LiteNES 2 | 3 | Nintendo Entertainment System模拟器。故意做了一些错误的实现以提高性能(所以部分图形显示不正确)。 4 | 5 | 内置Super Mario Bros游戏ROM (mario.c)。 6 | 7 | 操作方式: 8 | 9 | * T — SELECT 10 | * Y — START 11 | * G — A键 12 | * H — B键 13 | * W/S/A/D — UP/DOWN/LEFT/RIGHT 14 | 15 | 需要正确的IOE (绘图、定时)。 -------------------------------------------------------------------------------- /nexus-am/apps/litenes/include/fce.h: -------------------------------------------------------------------------------- 1 | #ifndef FCE_H 2 | #define FCE_H 3 | 4 | #include 5 | #include 6 | 7 | #define FPS 60 8 | #define W 256 9 | #define H 240 10 | 11 | int fce_load_rom(char *rom); 12 | void fce_init(); 13 | void fce_run(); 14 | void fce_update_screen(); 15 | 16 | extern byte canvas[257][520]; 17 | extern int frame_cnt; 18 | 19 | extern char rom_mario_nes[]; 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /nexus-am/apps/litenes/include/mmc.h: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | 3 | byte mmc_read(word address); 4 | void mmc_write(word address, byte data); 5 | void mmc_copy(word address, byte *source, int length); 6 | void mmc_append_chr_rom_page(byte *source); 7 | 8 | extern byte mmc_id; 9 | -------------------------------------------------------------------------------- /nexus-am/apps/litenes/include/psg.h: -------------------------------------------------------------------------------- 1 | // #define psg_io_read(...) 0xFF 2 | // #define psg_io_write(...) /**/ 3 | 4 | #include "common.h" 5 | 6 | #ifndef PSG_H 7 | #define PSG_H 8 | 9 | extern unsigned char psg_joy1[8]; 10 | 11 | byte psg_io_read(word address); 12 | void psg_io_write(word address, byte data); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /nexus-am/apps/litenes/src/mmc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define MMC_MAX_PAGE_COUNT 1 6 | 7 | byte mmc_id; 8 | 9 | byte mmc_chr_pages[MMC_MAX_PAGE_COUNT][0x2000]; 10 | int mmc_chr_pages_number; 11 | 12 | byte memory[0x10000]; 13 | 14 | inline byte mmc_read(word address) 15 | { 16 | return memory[address]; 17 | } 18 | 19 | inline void mmc_write(word address, byte data) 20 | { 21 | memory[address] = data; 22 | } 23 | 24 | inline void mmc_copy(word address, byte *source, int length) 25 | { 26 | memcpy(&memory[address], source, length); 27 | } 28 | 29 | inline void mmc_append_chr_rom_page(byte *source) 30 | { 31 | memcpy(&mmc_chr_pages[mmc_chr_pages_number++][0], source, 0x2000); 32 | } 33 | -------------------------------------------------------------------------------- /nexus-am/apps/microbench/Makefile: -------------------------------------------------------------------------------- 1 | NAME = microbench 2 | SRCS = $(shell find -L ./src/ -name "*.c" -o -name "*.cpp") 3 | 4 | INPUT ?= REF 5 | CFLAGS += -DSETTING_$(INPUT) 6 | CXXFLAGS += -DSETTING_$(INPUT) 7 | 8 | include $(AM_HOME)/Makefile.app 9 | -------------------------------------------------------------------------------- /nexus-am/apps/microbench/src/lzip/lzip.c: -------------------------------------------------------------------------------- 1 | #include "quicklz.h" 2 | #include 3 | 4 | static int SIZE; 5 | 6 | static qlz_state_compress *state; 7 | static char *blk; 8 | static char *compress; 9 | static int len; 10 | 11 | void bench_lzip_prepare() { 12 | SIZE = setting->size; 13 | bench_srand(1); 14 | state = bench_alloc(sizeof(qlz_state_compress)); 15 | blk = bench_alloc(SIZE); 16 | compress = bench_alloc(SIZE + 400); 17 | for (int i = 0; i < SIZE; i ++) { 18 | blk[i] = 'a' + bench_rand() % 26; 19 | } 20 | } 21 | 22 | void bench_lzip_run() { 23 | len = qlz_compress(blk, compress, SIZE, state); 24 | } 25 | 26 | int bench_lzip_validate() { 27 | return checksum(compress, compress + len) == setting->checksum; 28 | } 29 | 30 | -------------------------------------------------------------------------------- /nexus-am/apps/microbench/src/queen/queen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static unsigned int FULL; 4 | 5 | static unsigned int dfs(unsigned int row, unsigned int ld, unsigned int rd) { 6 | if (row == FULL) { 7 | return 1; 8 | } else { 9 | unsigned int pos = FULL & (~(row | ld | rd)), ans = 0; 10 | while (pos) { 11 | unsigned int p = (pos & (~pos + 1)); 12 | pos -= p; 13 | ans += dfs(row | p, (ld | p) << 1, (rd | p) >> 1); 14 | } 15 | return ans; 16 | } 17 | } 18 | 19 | static unsigned int ans; 20 | 21 | void bench_queen_prepare() { 22 | ans = 0; 23 | FULL = (1 << setting->size) - 1; 24 | } 25 | 26 | void bench_queen_run() { 27 | ans = dfs(0, 0, 0); 28 | } 29 | 30 | int bench_queen_validate() { 31 | return ans == setting->checksum; 32 | } 33 | -------------------------------------------------------------------------------- /nexus-am/apps/slider/Makefile: -------------------------------------------------------------------------------- 1 | NAME = slider 2 | SRCS = main.c image.S 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/apps/slider/image.S: -------------------------------------------------------------------------------- 1 | .section .data 2 | .global image, image_end 3 | image: 4 | .incbin "images/projectn.bin" 5 | .incbin "images/litenes.bin" 6 | image_end: 7 | -------------------------------------------------------------------------------- /nexus-am/apps/slider/images/litenes.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/nexus-am/apps/slider/images/litenes.bin -------------------------------------------------------------------------------- /nexus-am/apps/slider/images/projectn.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NonlinearTime/Nemu/66fd26a51490535198c0bc26d9858d604846d5af/nexus-am/apps/slider/images/projectn.bin -------------------------------------------------------------------------------- /nexus-am/apps/slider/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern uint32_t image[][400][300]; 5 | extern uint32_t image_end[][400][300]; 6 | #define NR_IMG (image_end - image) 7 | 8 | void display_image(int i) { 9 | draw_rect(&image[i][0][0], 0, 0, 400, 300); 10 | draw_sync(); 11 | } 12 | 13 | int main() { 14 | _ioe_init(); 15 | 16 | int i = 0; 17 | unsigned long last = 0; 18 | unsigned long current; 19 | 20 | display_image(i); 21 | 22 | while (true) { 23 | current = uptime(); 24 | if (current - last > 5000) { 25 | // change image every 5s 26 | i = (i + 1) % NR_IMG; 27 | display_image(i); 28 | last = current; 29 | } 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /nexus-am/apps/typing/Makefile: -------------------------------------------------------------------------------- 1 | NAME = typing 2 | SRCS = game.c draw.c font.c keyboard.c 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/apps/typing/README.md: -------------------------------------------------------------------------------- 1 | # Typing Game 2 | 3 | 最简单的打字小游戏。 4 | 5 | 这是[NJU 2013 oslab0的演示游戏](https://github.com/NJU-ProjectN/os-lab0)的AM移植版本。 6 | 需要正确的IOE (计时、绘图、键盘)。 7 | -------------------------------------------------------------------------------- /nexus-am/docs/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.pdf 3 | -------------------------------------------------------------------------------- /nexus-am/docs/Makefile: -------------------------------------------------------------------------------- 1 | MDS = $(shell find -s src -name "*.md") 2 | OUTPUT = ambook.html 3 | 4 | RENDER_LIST = $(foreach f, $(MDS), $(f) .blankline) 5 | 6 | all: 7 | @mkdir -p build/ 8 | pandoc -f markdown+footnotes \ 9 | -t html src/title.txt $(RENDER_LIST) > $(OUTPUT) 10 | -------------------------------------------------------------------------------- /nexus-am/docs/README.md: -------------------------------------------------------------------------------- 1 | # 文档编写规范 2 | 3 | ## 语法 4 | 5 | [Pandoc Markdown (具有多种扩展功能的markdown)](http://pandoc.org/MANUAL.html#pandocs-markdown)。 6 | 7 | ## 文档组织 8 | 9 | `src/` - 所有的文档。文档按照字典顺序排序拼接起来,就得到完整的文档。 10 | -------------------------------------------------------------------------------- /nexus-am/docs/src/00-preface/preface.md: -------------------------------------------------------------------------------- 1 | # 前言 2 | 3 | 为什么会有AM? 4 | 5 | 致谢。 -------------------------------------------------------------------------------- /nexus-am/docs/src/01-C.md: -------------------------------------------------------------------------------- 1 | # 重新定义C语言 2 | 3 | ## 计算机硬件 4 | 5 | x86, MIPS, 指令执行,状态机模型。 6 | 7 | ## C Runtime作为抽象计算机 8 | 9 | > 为什么需要C?因为硬件太复杂,人理解不了。 10 | 11 | 指令集设计成现在这个样子,很大程度上兼顾了历史包袱(兼容性)、执行速度、硬件实现的代价和可行性等。在这几个目标之间,满足“好编程”这件事情就不那么重要了。 12 | 13 | C定义了“内存”,一个字节数组。 14 | 15 | PC和内存就可以定义C语言的semantics。 16 | 17 | (PC, M) => (PC1, M1) => ... 18 | 19 | 这就对应了我们“阅读程序写结果”。有些行为是undefined,比如越界、溢出等等。 20 | 21 | ## C AM在硬件上的执行 22 | 23 | (x86为例) 24 | 25 | 硬件会维护M,但也会有一些附加的状态(比如寄存器),但总体来说,(PC, M)是一定有的,这样人类才能理解的了程序的行为。 26 | 27 | 编译器未必严格按照语义的“步骤”执行,比如 28 | 29 | for (int i = 1; i <= 100; i++) sum += i; 30 | 31 | 可以被优化成 32 | 33 | sum += 5050; 34 | 35 | 但总有一个点语义会能对应上。 36 | 37 | C的一个很大的优势就在于,他相对于硬件比较低级,有内存,所以很多时候能“看到汇编”,从而能控制机器的行为。也很容易搞砸(UB)。 38 | -------------------------------------------------------------------------------- /nexus-am/docs/src/03-hw-program.md: -------------------------------------------------------------------------------- 1 | # 在计算机硬件上编程 2 | 3 | 以前学的写C程序,都是写完,按一个键(编译运行),在OS上运行。 4 | 5 | 但C也可以在硬件上运行。 6 | 7 | 听起来很可怕,这里有一个思维翻转的过程:我们觉得在机器上编程很可怕,因为机器有很多细节(specs, 约定)我们都不知道。 8 | 9 | 但其实我们(system)要做的事情,就是做抽象,把复杂的东西简化了,做成C runtime。 10 | 11 | ## Minimal C Runtime 12 | 13 | 就是刚才说的,能执行semantics。 14 | 15 | 多一个putchar()。 16 | 17 | 这个就能干很多事了。 18 | 19 | ## Playing with AM (minimal C runtime) 20 | 21 | 例子:自己写了个CPU,非常简陋。 22 | 23 | 但可以做很多事。[^hw-1] 24 | 25 | [^hw-1]: Hello. 26 | 27 | ::::: {.sidebar} 28 | MIPS32 implementation 29 | ::::: 30 | 31 | ::::: {.sidebar} 32 | x86 implementation 33 | ::::: -------------------------------------------------------------------------------- /nexus-am/docs/src/04-fun-with-io.md: -------------------------------------------------------------------------------- 1 | # Have fun with I/O Devices 2 | 3 | 只能putchar(),有些无聊。 4 | 5 | 计算机里有很多I/O设备,平时都是不能直接访问的(都是通过神秘的库函数,你也不知道发生了什么)。 6 | 7 | 但在bare metal上,就可以直接访问了。 8 | 9 | ## 什么是I/O设备? 10 | 11 | 读/写/控制 12 | 13 | (实际复杂得多,省略一万字) 14 | 15 | ## AM IO API 16 | 17 | ## Fun with I/O 18 | 19 | (LiteNES) 20 | 21 | 因为是抽象的I/O层,所以写一份代码,可以在本地、自己的cpu、各种东西上跑![^1] 22 | 23 | [^1]: Here is the footnote. -------------------------------------------------------------------------------- /nexus-am/docs/src/05-context.md: -------------------------------------------------------------------------------- 1 | # 上下文管理 2 | 3 | 但无论如何,都没有调出我们的框架。 4 | 5 | (PC, M) - 根据PC执行 -> (PC1, M1), ... 6 | 7 | 如果碰到死循环,就死了。 8 | 9 | 怎么跳出呢? 10 | 11 | ## 中断 {#intr} 12 | 13 | See [Section XX](#intr). -------------------------------------------------------------------------------- /nexus-am/docs/src/title.txt: -------------------------------------------------------------------------------- 1 | --- 2 | title: 抽象计算机编程手册 3 | author: 蒋炎岩 余子濠 4 | --- -------------------------------------------------------------------------------- /nexus-am/libs/compiler-rt/Makefile: -------------------------------------------------------------------------------- 1 | NAME = compiler-rt 2 | SRCS = $(shell find . -name "*.c") 3 | include $(AM_HOME)/Makefile.lib 4 | -------------------------------------------------------------------------------- /nexus-am/libs/compiler-rt/divmoddi4.c: -------------------------------------------------------------------------------- 1 | /*===-- divmoddi4.c - Implement __divmoddi4 --------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __divmoddi4 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: a / b, *rem = a % b */ 18 | 19 | COMPILER_RT_ABI di_int 20 | __divmoddi4(di_int a, di_int b, di_int* rem) 21 | { 22 | di_int d = __divdi3(a,b); 23 | *rem = a - (d*b); 24 | return d; 25 | } 26 | -------------------------------------------------------------------------------- /nexus-am/libs/compiler-rt/udivdi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- udivdi3.c - Implement __udivdi3 -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __udivdi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: a / b */ 18 | 19 | COMPILER_RT_ABI du_int 20 | __udivdi3(du_int a, du_int b) 21 | { 22 | return __udivmoddi4(a, b, 0); 23 | } 24 | -------------------------------------------------------------------------------- /nexus-am/libs/compiler-rt/umoddi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- umoddi3.c - Implement __umoddi3 -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __umoddi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: a % b */ 18 | 19 | COMPILER_RT_ABI du_int 20 | __umoddi3(du_int a, du_int b) 21 | { 22 | du_int r; 23 | __udivmoddi4(a, b, &r); 24 | return r; 25 | } 26 | -------------------------------------------------------------------------------- /nexus-am/libs/fixmath/Makefile: -------------------------------------------------------------------------------- 1 | NAME = fixmath 2 | SRCS = $(shell find -L ./src/ -name "*.c") 3 | include $(AM_HOME)/Makefile.lib 4 | -------------------------------------------------------------------------------- /nexus-am/libs/fixmath/README.md: -------------------------------------------------------------------------------- 1 | # Fix16 2 | 3 | Ported from [libfixmath](https://code.google.com/p/libfixmath) 4 | 5 | The copyright belongs to the original authors (Ben Brewer). 6 | 7 | ## Use 8 | 9 | `#include ` 10 | -------------------------------------------------------------------------------- /nexus-am/libs/fixmath/include/fixmath.h: -------------------------------------------------------------------------------- 1 | #ifndef __libfixmath_fixmath_h__ 2 | #define __libfixmath_fixmath_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | /*! 10 | \file fixmath.h 11 | \brief Functions to perform fast accurate fixed-point math operations. 12 | */ 13 | 14 | #include "uint32.h" 15 | #include "int64.h" 16 | #include "fract32.h" 17 | #include "fix16.h" 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /nexus-am/libs/fixmath/include/uint32.h: -------------------------------------------------------------------------------- 1 | #ifndef __libfixmath_uint32_h__ 2 | #define __libfixmath_uint32_h__ 3 | 4 | #ifdef __cplusplus 5 | extern "C" 6 | { 7 | #endif 8 | 9 | #include 10 | 11 | /*! Performs an unsigned log-base2 on the specified unsigned integer and returns the result. 12 | */ 13 | extern uint32_t uint32_log2(uint32_t inVal); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /nexus-am/libs/fixmath/src/uint32.c: -------------------------------------------------------------------------------- 1 | #include "uint32.h" 2 | 3 | 4 | 5 | uint32_t uint32_log2(uint32_t inVal) { 6 | if(inVal == 0) 7 | return 0; 8 | uint32_t tempOut = 0; 9 | if(inVal >= (1 << 16)) { inVal >>= 16; tempOut += 16; } 10 | if(inVal >= (1 << 8)) { inVal >>= 8; tempOut += 8; } 11 | if(inVal >= (1 << 4)) { inVal >>= 4; tempOut += 4; } 12 | if(inVal >= (1 << 2)) { inVal >>= 2; tempOut += 2; } 13 | if(inVal >= (1 << 1)) { tempOut += 1; } 14 | return tempOut; 15 | } 16 | -------------------------------------------------------------------------------- /nexus-am/libs/imgui/Makefile: -------------------------------------------------------------------------------- 1 | NAME = imgui 2 | SRCS = src/imgui.cpp src/imgui_draw.cpp src/imgui_demo.cpp 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.lib 5 | -------------------------------------------------------------------------------- /nexus-am/libs/klib/Makefile: -------------------------------------------------------------------------------- 1 | NAME = klib 2 | SRCS = src/stdio.c \ 3 | src/string.c \ 4 | src/cpp.c \ 5 | src/stdlib.c \ 6 | src/io.c 7 | include $(AM_HOME)/Makefile.lib 8 | -------------------------------------------------------------------------------- /nexus-am/libs/klib/src/cpp.c: -------------------------------------------------------------------------------- 1 | #include "klib.h" 2 | 3 | #ifndef __ISA_NATIVE__ 4 | 5 | void __dso_handle() { 6 | } 7 | 8 | void __cxa_guard_acquire() { 9 | } 10 | 11 | void __cxa_guard_release() { 12 | } 13 | 14 | 15 | void __cxa_atexit() { 16 | assert(0); 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /nexus-am/libs/klib/src/stdlib.c: -------------------------------------------------------------------------------- 1 | static unsigned long int next = 1; 2 | 3 | int rand(void) { 4 | // RAND_MAX assumed to be 32767 5 | next = next * 1103515245 + 12345; 6 | return (unsigned int)(next/65536) % 32768; 7 | } 8 | 9 | void srand(unsigned int seed) { 10 | next = seed; 11 | } 12 | -------------------------------------------------------------------------------- /nexus-am/tests/cachetest/Makefile: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/Makefile.check 2 | .PHONY: all run clean latest $(ALL) 3 | 4 | ALL = $(basename $(notdir $(shell find tests/. -name "*.c"))) 5 | 6 | all: $(addprefix Makefile., $(ALL)) 7 | @echo "" $(ALL) 8 | 9 | $(ALL): %: Makefile.% 10 | 11 | Makefile.%: tests/%.c latest 12 | @/bin/echo -e "NAME = $*\nSRCS = $<\nLIBS += klib\ninclude $${AM_HOME}/Makefile.app" > $@ 13 | -@make -s -f $@ ARCH=$(ARCH) $(MAKECMDGOALS) 14 | -@rm -f Makefile.$* 15 | 16 | run: all 17 | 18 | clean: 19 | rm -rf Makefile.* build/ 20 | 21 | latest: 22 | -------------------------------------------------------------------------------- /nexus-am/tests/cachetest/tests/access-cache.c: -------------------------------------------------------------------------------- 1 | #include "klib.h" 2 | 3 | int main() { 4 | int round = 30; 5 | static char arr[4 * 1024 * 1024]; 6 | for (int i = 0; i < round; i++) 7 | arr[i * 64] = i; 8 | for (int i = 0; i < round; i++) 9 | assert(arr[i * 64] == (char)i); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /nexus-am/tests/cachetest/tests/access.c: -------------------------------------------------------------------------------- 1 | #include "klib.h" 2 | 3 | int ans[64] = {0}; 4 | 5 | int main() { 6 | int i = 0; 7 | for (i = 0; i < 64; i++) 8 | ans[i] = 64 - i; 9 | for (i = 0; i < 64; i++) 10 | assert(ans[i] == 64 - i); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/.gitignore: -------------------------------------------------------------------------------- 1 | /Makefile.* 2 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/Makefile: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/Makefile.check 2 | .PHONY: all run clean latest $(ALL) 3 | 4 | ALL = $(basename $(notdir $(shell find tests/. -name "*.c"))) 5 | 6 | all: $(addprefix Makefile., $(ALL)) 7 | @echo "" $(ALL) 8 | 9 | $(ALL): %: Makefile.% 10 | 11 | Makefile.%: tests/%.c latest 12 | @/bin/echo -e "NAME = $*\nSRCS = $<\nLIBS += klib\ninclude $${AM_HOME}/Makefile.app" > $@ 13 | -@make -s -f $@ ARCH=$(ARCH) $(MAKECMDGOALS) 14 | -@rm -f Makefile.$* 15 | 16 | run: all 17 | 18 | clean: 19 | rm -rf Makefile.* build/ 20 | 21 | latest: 22 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/README.md: -------------------------------------------------------------------------------- 1 | # CPUTest 2 | 3 | 批量编译大量独立的测试小程序。 4 | 5 | 约定:**程序最终执行到`_halt(0)`为正确,其他情况为错误**。 6 | 7 | 用途: 8 | 9 | * 配合一键仿真程序在CPU实现修改后快速进行回归测试。 10 | * 为一键上板提供可运行的ELF binary。 11 | 12 | ## 编译测试程序 13 | 14 | 使用`make ARCH=native`用`native`体系结构编译所有测试程序。 15 | 16 | 如果需要单独编译一个程序,可以使用`make ARCH=mips32-minimal ALL=sum`,单独编译`sum`。 17 | 18 | 可以通过`make ARCH=x86-nemu run`进行批量测试,需要相应arch中的run脚本在一个测试成功后可以自动退出。 19 | 20 | ## 添加新的测试程序 21 | 22 | 每个测试程序只能有一个C文件,放在`tests/`目录下。 23 | 24 | `trap.h`里有一些可以使用的函数,比如`nemu_assert`。 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/include/trap.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRAP_H__ 2 | #define __TRAP_H__ 3 | 4 | #include 5 | #include 6 | 7 | __attribute__((noinline)) 8 | void nemu_assert(int cond) { 9 | if (!cond) _halt(1); 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/bubble-sort.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 20 4 | 5 | int a[N] = {2, 12, 14, 6, 13, 15, 16, 10, 0, 18, 11, 19, 9, 1, 7, 5, 4, 3, 8, 17}; 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 | nemu_assert(i == N); 29 | 30 | bubble_sort(); 31 | 32 | for(i = 0; i < N; i ++) { 33 | nemu_assert(a[i] == i); 34 | } 35 | 36 | nemu_assert(i == N); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/div.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 10 4 | int a[N]; 5 | 6 | int main() { 7 | int i, j; 8 | for(i = 0; i < N; i ++) 9 | a[i] = i; 10 | for(i = 0; i < N; i ++) 11 | for(j = 1; j < N + 1; j ++) 12 | a[i] *= j; 13 | for(i = 0; i < N; i ++) 14 | for(j = 1; j < N + 1; j ++) 15 | a[i] /= j; 16 | 17 | for(i = 0; i < N; i ++) 18 | nemu_assert(a[i] == i); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/dummy.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 | return 0; 19 | } 20 | 21 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 | nemu_assert(i == 40); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/goldbach.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 goldbach(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 <= 30; n += 2) { 30 | nemu_assert(goldbach(n) == 1); 31 | } 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/hello-str.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | char buf[128]; 4 | 5 | int main() { 6 | sprintf(buf, "%s", "Hello world!\n"); 7 | nemu_assert(strcmp(buf, "Hello world!\n") == 0); 8 | 9 | sprintf(buf, "%d + %d = %d\n", 1, 1, 2); 10 | nemu_assert(strcmp(buf, "1 + 1 = 2\n") == 0); 11 | 12 | sprintf(buf, "%d + %d = %d\n", 2, 10, 12); 13 | nemu_assert(strcmp(buf, "2 + 10 = 12\n") == 0); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 | nemu_assert(i == NR_DATA); 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/movsx.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int A[10]; 4 | int b; 5 | signed 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 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/pascal.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 31 4 | 5 | int a[N]; 6 | 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}; 7 | 8 | int main() { 9 | int i, j; 10 | int t0, t1; 11 | a[0] = a[1] = 1; 12 | 13 | for(i = 2; i < N; i ++) { 14 | t0 = 1; 15 | for(j = 1; j < i; j ++) { 16 | t1 = a[j]; 17 | a[j] = t0 + t1; 18 | t0 = t1; 19 | } 20 | a[i] = 1; 21 | } 22 | 23 | for(j = 0; j < N; j ++) { 24 | nemu_assert(a[j] == ans[j]); 25 | } 26 | 27 | nemu_assert(j == N); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/prime.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int ans[] = {101, 103, 107, 109, 113, 127, 131, 137, 139, 149}; 4 | 5 | int main() { 6 | int m, i, n = 0; 7 | int prime; 8 | for(m = 101; m <= 150; 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 == 10); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/select-sort.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | #define N 20 4 | 5 | int a[N] = {2, 12, 14, 6, 13, 15, 16, 10, 0, 18, 11, 19, 9, 1, 7, 5, 4, 3, 8, 17}; 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 | nemu_assert(i == N); 32 | 33 | select_sort(); 34 | 35 | for(i = 0; i < N; i ++) { 36 | nemu_assert(a[i] == i); 37 | } 38 | 39 | nemu_assert(i == N); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/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 < 500; 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 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/string.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | char *s[] = { 4 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 5 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", 6 | "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 7 | ", World!\n", 8 | "Hello, World!\n", 9 | "#####" 10 | }; 11 | 12 | char str1[] = "Hello"; 13 | char str[20]; 14 | 15 | int main() { 16 | nemu_assert(strcmp(s[0], s[2]) == 0); 17 | nemu_assert(strcmp(s[0], s[1]) == -1); 18 | nemu_assert(strcmp(s[0] + 1, s[1] + 1) == -1); 19 | nemu_assert(strcmp(s[0] + 2, s[1] + 2) == -1); 20 | nemu_assert(strcmp(s[0] + 3, s[1] + 3) == -1); 21 | 22 | //strcpy(str, str1); 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 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/sum.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int main() { 4 | int i = 1; 5 | volatile int sum = 0; 6 | while(i <= 100) { 7 | sum += i; 8 | i ++; 9 | } 10 | 11 | nemu_assert(sum == 5050); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/switch.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int switch_case(int n) { 4 | int ret; 5 | switch(n) { 6 | case 0: ret = 0; break; 7 | case 1: ret = 2; break; 8 | case 2: case 3: ret = 5; break; 9 | case 4: case 5: case 6: case 7: ret = 8; break; 10 | case 8: case 9: case 10: case 11: ret = 10; break; 11 | case 12: ret = 15; break; 12 | default: ret = -1; break; 13 | } 14 | 15 | return ret; 16 | } 17 | 18 | int ans[] = {-1, 0, 2, 5, 5, 8, 8, 8, 8, 10, 10, 10, 10, 15, -1}; 19 | 20 | int main() { 21 | int i; 22 | for(i = 0; i < 15; i ++) { 23 | nemu_assert(switch_case(i - 1) == ans[i]); 24 | } 25 | 26 | nemu_assert(i == 15); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/unalign.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | unsigned x = 0xffffffff; 4 | unsigned char buf[16]; 5 | 6 | int main() { 7 | 8 | for(int i = 0; i < 4; i++) { 9 | *((volatile unsigned*)(buf + 3)) = 0xaabbccdd; 10 | 11 | x = *((volatile unsigned*)(buf + 3)); 12 | nemu_assert(x == 0xaabbccdd); 13 | 14 | buf[0] = buf[1] = 0; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /nexus-am/tests/cputest/tests/wanshu.c: -------------------------------------------------------------------------------- 1 | #include "trap.h" 2 | 3 | int ans[] = {6, 28}; 4 | 5 | int main() { 6 | int n, sum, i, k = 0; 7 | for(n = 1; n < 30; 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 == 2); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /nexus-am/tests/ctetest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = ctetest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/floattest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = floattest 2 | SRCS = main.cpp 3 | LIBS += klib fixmath 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/fuzz/.gitignore: -------------------------------------------------------------------------------- 1 | /main.c 2 | -------------------------------------------------------------------------------- /nexus-am/tests/fuzz/Makefile: -------------------------------------------------------------------------------- 1 | NAME = fuzz 2 | SRCS = main.c 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /nexus-am/tests/fuzz/README.md: -------------------------------------------------------------------------------- 1 | # 随机程序生成器 2 | 3 | (待完善) 4 | 5 | ## 使用方法 6 | 7 | 运行`./run ARCH=native`会自动生成一个随机程序、编译成`main.c`并编译。 8 | 9 | ## 原理 10 | 11 | 产生具有一定随机性的程序,用来压力测试CPU正确性。 12 | 13 | `instgen.py`的运行流程: 14 | 15 | 1. 指定参数(基本块数量、数组个数、全局变量列表) 16 | 2. 生成一个随机的函数`f()`,会对全局状态进行读取/运算 17 | 3. 将`f()`粘贴到一个临时文件里,在本地编译运行(`gcc -m32`),打印最终变量的值。 18 | 4. 将变量值生成的assert粘贴到`main.c`。 19 | 20 | -------------------------------------------------------------------------------- /nexus-am/tests/fuzz/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | python instgen.py > main.c && make ARCH=mips32-minimal 4 | tail -n 20 main.c 5 | -------------------------------------------------------------------------------- /nexus-am/tests/fuzz/trap.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRAP_H__ 2 | #define __TRAP_H__ 3 | 4 | #include 5 | 6 | #define HIT_GOOD_TRAP \ 7 | do { \ 8 | _halt(0); \ 9 | } while (0) 10 | 11 | __attribute__((noinline)) 12 | void nemu_assert(int cond) { 13 | if (!cond) _halt(1); 14 | } 15 | 16 | #define assert(cond) \ 17 | do { \ 18 | nemu_assert(cond); \ 19 | } while (0) 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /nexus-am/tests/guitest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = guitest 2 | SRCS = guitest.cpp 3 | LIBS = klib imgui 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/ioetest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = ioetest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/keytest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = keytest 2 | SRCS = main.cpp 3 | LIBS = klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/keytest/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #define NAME(key) \ 6 | [_KEY_##key] = #key, 7 | 8 | const char *names[256] = { 9 | [_KEY_NONE] = "NONE", 10 | _KEYS(NAME) 11 | }; 12 | int main() { 13 | _ioe_init(); 14 | 15 | while (1) { 16 | int key = read_key(); 17 | bool down = false; 18 | if (key & 0x8000) { 19 | key ^= 0x8000; 20 | down = true; 21 | } 22 | if (key != _KEY_NONE) { 23 | printf("Get key: %d %s %s\n", key, names[key], down ? "down" : "up"); 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /nexus-am/tests/mipstest/Makefile: -------------------------------------------------------------------------------- 1 | include $(AM_HOME)/Makefile.check 2 | .PHONY: all run clean latest $(ALL) 3 | 4 | ALL = $(basename $(notdir $(shell find tests/. -name "*.c"))) 5 | 6 | all: $(addprefix Makefile., $(ALL)) 7 | @echo "" $(ALL) 8 | 9 | $(ALL): %: Makefile.% 10 | 11 | Makefile.%: tests/%.c latest 12 | @/bin/echo -e "NAME = $*\nSRCS = $<\nLIBS += klib\ninclude $${AM_HOME}/Makefile.app" > $@ 13 | -@make -s -f $@ ARCH=$(ARCH) $(MAKECMDGOALS) 14 | -@rm -f Makefile.$* 15 | 16 | run: all 17 | 18 | clean: 19 | rm -rf Makefile.* build/ 20 | 21 | latest: 22 | -------------------------------------------------------------------------------- /nexus-am/tests/mipstest/include/trap.h: -------------------------------------------------------------------------------- 1 | #ifndef __TRAP_H__ 2 | #define __TRAP_H__ 3 | 4 | #include 5 | #include 6 | 7 | __attribute__((noinline)) 8 | void nemu_assert(int cond) { 9 | if (!cond) _halt(1); 10 | } 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /nexus-am/tests/mptest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = mptest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/mptest/dbg.txt: -------------------------------------------------------------------------------- 1 | file build/mptest-x86-qemu.o 2 | target remote :1234 3 | hb mp_entry 4 | c 5 | -------------------------------------------------------------------------------- /nexus-am/tests/mptest/debug: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make 4 | qemu-system-i386 \ 5 | -gdb tcp::1234 -S -smp 4 \ 6 | -chardev stdio,mux=on,id=char0 \ 7 | -chardev file,path=trace.log,id=char1 \ 8 | -serial chardev:char0 \ 9 | -serial chardev:char1 \ 10 | build/mptest-x86-qemu & 11 | pid=$? 12 | gdb -x dbg.txt; kill -9 ${pid} 13 | -------------------------------------------------------------------------------- /nexus-am/tests/mptest/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | make || exit 3 | 4 | rm -f trace.log 5 | qemu-system-i386 \ 6 | -smp 6 \ 7 | -chardev stdio,mux=on,id=char0 \ 8 | -chardev file,path=trace.log,id=char1 \ 9 | -serial chardev:char0 \ 10 | -serial chardev:char1 \ 11 | build/mptest-x86-qemu; hd trace.log 12 | -------------------------------------------------------------------------------- /nexus-am/tests/segmenttest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = segmenttest 2 | SRCS = main.c initrd.S 3 | LIBS += klib compiler-rt 4 | ARCH ?= mips32-npc 5 | 6 | TESTCASE = load-store 7 | INITRD_S = initrd.S 8 | 9 | TESTBIN = $(AM_HOME)/tests/cputest/build/$(TESTCASE)-$(ARCH).bin 10 | 11 | $(TESTBIN): $(AM_HOME)/tests/cputest/tests/$(TESTCASE).c 12 | make -s -C $(@D)/.. ARCH=$(ARCH) 13 | 14 | $(INITRD_S): $(TESTBIN) 15 | @cp $< build/fsimg 16 | @touch $@ 17 | echo + $@ 18 | 19 | include $(AM_HOME)/Makefile.app 20 | -------------------------------------------------------------------------------- /nexus-am/tests/segmenttest/initrd.S: -------------------------------------------------------------------------------- 1 | .section .data 2 | .global __fsimg_start, __fsimg_end 3 | __fsimg_start: 4 | .incbin "build/fsimg" 5 | __fsimg_end: 6 | -------------------------------------------------------------------------------- /nexus-am/tests/timetest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = timetest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/timetest/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | _RTCReg rtc; 7 | _ioe_init(); 8 | int sec = 1; 9 | while (1) { 10 | while(uptime() < 1000 * sec) ; 11 | get_timeofday(&rtc); 12 | printf("%d-%d-%d %02d:%02d:%02d GMT (", rtc.year, rtc.month, rtc.day, rtc.hour, rtc.minute, rtc.second); 13 | if (sec == 1) { 14 | printf("%d second).\n", sec); 15 | } else { 16 | printf("%d seconds).\n", sec); 17 | } 18 | sec ++; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /nexus-am/tests/tracetest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = tracetest 2 | SRCS = main.c 3 | include $(AM_HOME)/Makefile.app 4 | -------------------------------------------------------------------------------- /nexus-am/tests/tracetest/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | make ARCH=x86-qemu && \ 3 | qemu-system-i386 \ 4 | -chardev stdio,mux=on,id=char0 \ 5 | -chardev file,path=trace.log,id=char1 \ 6 | -serial chardev:char0 \ 7 | -serial chardev:char1 \ 8 | build/tracetest-x86-qemu 9 | hd trace.log 10 | -------------------------------------------------------------------------------- /nexus-am/tests/videotest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = videotest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/vmtest/Makefile: -------------------------------------------------------------------------------- 1 | NAME = vmtest 2 | SRCS = main.c 3 | LIBS += klib 4 | include $(AM_HOME)/Makefile.app 5 | -------------------------------------------------------------------------------- /nexus-am/tests/vmtest/dbg.txt: -------------------------------------------------------------------------------- 1 | file build/vmtest-x86-qemu.o 2 | target remote :1234 3 | hb *0x60000000 4 | c 5 | -------------------------------------------------------------------------------- /nexus-am/tests/vmtest/debug: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | make 4 | qemu-system-i386 -gdb tcp::1234 -S build/vmtest-x86-qemu -serial stdio & 5 | pid=$? 6 | gdb -x dbg.txt; kill -9 ${pid} 7 | -------------------------------------------------------------------------------- /submit.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | [ -z ${STUID} ] && echo "STUID must be set (RTFM)" && exit 4 | [ -z ${STUNAME} ] && echo "STUNAME must be set (RTFM)" && exit 5 | echo -n "The task to be submitted > " 6 | read task 7 | 8 | cwd=${PWD##*/} 9 | echo "${STUID} (${STUNAME}) submitting ${task}..." 10 | 11 | wiki='https://dssl.cun.io/teach/api/uploads/' 12 | 13 | tarball=$(mktemp -q).tar.bz2 14 | bash -c "cd .. && tar cj ${cwd} > ${tarball}" 15 | curl -F "task=${task}" -F "id=${STUID}" -F "name=${STUNAME}" -F "submission=@${tarball}" ${wiki}upload 16 | --------------------------------------------------------------------------------