{"id":20105027,"url":"https://github.com/misyltoad/riscv-vscript","last_synced_at":"2025-03-02T17:43:44.088Z","repository":{"id":64089054,"uuid":"573205331","full_name":"misyltoad/riscv-vscript","owner":"misyltoad","description":"A port of mini-rv32ima to VScript (Squirrel 3)","archived":false,"fork":false,"pushed_at":"2022-12-01T23:34:56.000Z","size":2378,"stargazers_count":54,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-13T04:44:46.281Z","etag":null,"topics":["risc-v","riscv","rv32ima","small","source-engine","squirrel","squirrel-lang","team-fortress-2","tf2","valve-games","vscript"],"latest_commit_sha":null,"homepage":"","language":"Squirrel","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/misyltoad.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-12-01T23:29:09.000Z","updated_at":"2024-11-23T20:16:21.000Z","dependencies_parsed_at":"2023-01-14T22:00:21.903Z","dependency_job_id":null,"html_url":"https://github.com/misyltoad/riscv-vscript","commit_stats":null,"previous_names":["misyltoad/riscv-vscript"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misyltoad%2Friscv-vscript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misyltoad%2Friscv-vscript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misyltoad%2Friscv-vscript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/misyltoad%2Friscv-vscript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/misyltoad","download_url":"https://codeload.github.com/misyltoad/riscv-vscript/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241549061,"owners_count":19980474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["risc-v","riscv","rv32ima","small","source-engine","squirrel","squirrel-lang","team-fortress-2","tf2","valve-games","vscript"],"created_at":"2024-11-13T17:45:38.485Z","updated_at":"2025-03-02T17:43:44.062Z","avatar_url":"https://github.com/misyltoad.png","language":"Squirrel","funding_links":[],"categories":[],"sub_categories":[],"readme":"# riscv-vscript (mini-rv32ima-sq)\n## *You heard of the TF2 Linux port, now get ready for the Linux TF2 port!*\n\n\n**Click below for the YouTube video showing off this project.**\n\n[![Writing a Really Tiny RISC-V Emulator](https://img.youtube.com/vi/zi6osAtyaio/0.jpg)](https://www.youtube.com/watch?v=zi6osAtyaio)\n\n# What\nriscv-vscript is a port of [mini-rv32ima](https://github.com/cnlohr/mini-rv32ima) to VScript (Squirrel3) that:\n - Implements a RISC-V rv32ima/Zifencei+Zicsr (and partial su) with CLINT and MMIO.\n - Is about 600 lines of code (including signed-ness helpers but excluding callbacks + usage)\n - (For more info see [mini-rv32ima](https://github.com/cnlohr/mini-rv32ima))\n - Absolutely not conformant or tested in any way.\n - Easily extensible to run your own risc-v code and plumb your own things.\n - Written in Squirrel3 and runs inside of Team Fortress 2.\n - Yes. You can run Linux, and sha256sum, etc all inside of Team Fortress 2 now.\n\nBy default when you execute the script, it will boot into a Linux environment.\nThe device tree (dtb) + system image is stored inside of riscv_data.nut inside of an array of hex bytes values.\n\nIt is functional in that it can run Linux, sha256sum, coremark etc and give accurate results.\n\n## Speed\n\nIt is pretty slow, but that's primarily due to the Think rate being limited to 0.1s.\n\nIf you don't use Think and let it run and block the main thread, it runs pretty fast and is quite responsive/interactive -- but obviously that isn't desirable as it would hang the server :P\n\n# Screenshots\n\n![](/assets/image_0.png)\n*please disregard the blatant lack of support for color codes*\n![](/assets/image_1.png)\n![](/assets/image_2.png)\n\n## More info\n\nThis is basically just a raw port of mini-rv32ima to Squirrel3.\nRather annoying as Squirrel has no fixed/small size or unsigned types... only `\u003e\u003e\u003e` for unsigned shift. (ie. non-sign-extend)\nSo we have to emulate all of that and all the logic for it is '*fun*'.\nWe map the player_say game event to map player text to the UART interface.\n\nIt supports basically everything you could ever want, but do\nnot consider it in any way conformant.\nIt can boot the Linux kernel, run coremark, run sha256sum and get\na correct results, etc.\nIt can even shutdown with `halt -f` and it actually shuts down\nthe risc-v computer and cleans up the entity responsible for\nthe Think function.\n\nI was very close to giving up many times writing this code.\nLuckily mini-rv32ima has a single-step register dump mode.\nAll of the debugging was done via enabling single-step, and a fixed elapsed_us\nand diff-ing the single-step outputs to see where we diverge.\n\nSpecial thanks to cnlohr for nerdsniping me with this tiny rv32 implementation\nI was very surprised how understandable it was, and how little it takes\nto have a rv32 implementation capable of actually being usable!\n\nThis code was all made in a tea-infused 6 hour coding session.\n\n## Some Notes\n\n**Due to Squirrel having no 64-bit or unsigned types...**\n\nunsigned less than is implemented by splitting the number into two signed 16-bit components and doing the comparison that way.\n\nmulh is emulated by treating it as a 64-bit mul in 16-bit parts.\n\ndivu is emulated in an interesting way... \n\nmodu is treated the same as normal mod for now.\nSo far nothing has relied on the signed-ness semantics of this yet.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisyltoad%2Friscv-vscript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmisyltoad%2Friscv-vscript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmisyltoad%2Friscv-vscript/lists"}