{"id":50842512,"url":"https://github.com/wtznc/os","last_synced_at":"2026-06-14T07:06:21.321Z","repository":{"id":357895198,"uuid":"914458430","full_name":"wtznc/os","owner":"wtznc","description":"Operating System in 1000 Lines (work in progress)","archived":false,"fork":false,"pushed_at":"2026-05-14T17:31:28.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-05-14T19:35:42.383Z","etag":null,"topics":["assembly","kernel","low-level","os"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wtznc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-01-09T16:29:08.000Z","updated_at":"2026-05-14T17:31:32.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wtznc/os","commit_stats":null,"previous_names":["wtznc/os"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/wtznc/os","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtznc%2Fos","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtznc%2Fos/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtznc%2Fos/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtznc%2Fos/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wtznc","download_url":"https://codeload.github.com/wtznc/os/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wtznc%2Fos/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34312294,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-14T02:00:07.365Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["assembly","kernel","low-level","os"],"created_at":"2026-06-14T07:06:20.505Z","updated_at":"2026-06-14T07:06:21.302Z","avatar_url":"https://github.com/wtznc.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# os\n\n## Notes\n\nStudy notes that go with this repo live in [`notes/`](./notes):\n\n- [`notes/RISC-V 101.md`](./notes/RISC-V%20101.md) — primer on the 32-bit RISC-V ISA: assembly basics, registers, memory access, branches, function calls, and the stack.\n- [`notes/INSTRUCTIONS.md`](./notes/INSTRUCTIONS.md) — concise reference of the RISC-V instructions used throughout the project, grouped by purpose (arithmetic, memory, branches, function calls, stack).\n- [`notes/BOOT.md`](./notes/BOOT.md) — what happens before the kernel runs: OpenSBI / SBI, example QEMU boot output, monitor shortcuts, and the linker script.\n\n## Later:\n1. `lld` deepdive\n2. `qemu` deepdive\n3.  try `riscv64` instead of `riscv32`\n4. what are the all instructions in `riscv32`? (see `llvm-objdump -d` output)\n5. what are all the registers in `riscv32`? (see `llvm-objdump -d` output)\n\n## Tools:\n- `clang` - C compiler, needs support for 32-bit RISC-V CPU\n- `lld` - LLVM linker, bundles compiled object files into an executable\n- `llvm-objcopy` - Object file editor, comes with the `llvm` package\n- `llvm-objdump` - A disassembler, comes with the `llvm` package\n- `llvm-readelf` - An ELF file reader, comes with the `llvm` package\n- `qemu-system-riscv32` - 32-bit RISC-V CPU emulator, it's part of `qemu` package\n- [Compiler Explorer](https://godbolt.org) - useful tool for learning assembly, as I type C code it shows the corresponding assembly code. By default it uses x86-64 CPU assembly. Specify `RISC-V rv32gc clang (trunk)` in the right pane to output 32-bit RISC-V assembly.\n    - also we can specify options like `-O0` (optimization off) or `-O2` (optimization on) to see how the assembly code changes.\n\n## Setup (macOS)\n\nApple's bundled `clang` does not include the `riscv32` target,\n```\n$ clang --print-targets\n  Registered Targets:\n    aarch64    - AArch64 (little endian)\n    aarch64_32 - AArch64 (little endian ILP32)\n    aarch64_be - AArch64 (big endian)\n    arm        - ARM\n    arm64      - ARM64 (little endian)\n    arm64_32   - ARM64 (little endian ILP32)\n    armeb      - ARM (big endian)\n    thumb      - Thumb\n    thumbeb    - Thumb (big endian)\n    x86        - 32-bit X86: Pentium-Pro and above\n    x86-64     - 64-bit X86: EM64T and AMD64\n```\n\n so install Homebrew's LLVM (which is built with all targets) plus `lld` and `qemu`:\n\n```sh\nbrew install llvm lld qemu\n```\n\nVerify the RISC-V target is available:\n\n```sh\n$(brew --prefix llvm)/bin/clang -print-targets | grep riscv\n    riscv32     - 32-bit RISC-V\n    riscv32be   - 32-bit big endian RISC-V\n    riscv64     - 64-bit RISC-V\n    riscv64be   - 64-bit big endian RISC-V\n```\n\nUse the Homebrew toolchain by full path in `run.sh` (don't shadow Apple's clang globally):\n\n```sh\n/opt/homebrew/opt/llvm/bin/clang        # Apple Silicon\n/usr/local/opt/llvm/bin/clang           # Intel Mac\n```\n\nIf a shell session needs `llvm-objcopy` etc. on PATH:\n\n```sh\nexport PATH=\"$(brew --prefix llvm)/bin:$PATH\"\n```\n\n## Running\n\n```sh\n./run.sh\n```\n## QEMU `virt` machine\n\nEven though it does not exist in the real world, it's simple and very similar to real devices. I can emulate on it for free, no need to buy a physical hardware. When I encounter debugging issues, I can read QEMU's source code, or attach a debugger to the QEMU process to investigate what's wrong.\n\n[QEMU documentation](https://www.qemu.org/docs/master/system/riscv/virt.html)\n\nQEMU console: \n`Ctrl-A` then `c`; type `quit` to exit.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtznc%2Fos","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwtznc%2Fos","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwtznc%2Fos/lists"}