{"id":23349973,"url":"https://github.com/heng30/toy-os","last_synced_at":"2026-05-19T06:06:27.081Z","repository":{"id":269046994,"uuid":"897131816","full_name":"heng30/toy-os","owner":"heng30","description":"玩具内核（学习项目）","archived":false,"fork":false,"pushed_at":"2025-02-01T09:47:50.000Z","size":27340,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-06T13:46:26.586Z","etag":null,"topics":["assembly","c","kernel","toy-os"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heng30.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-12-02T04:49:17.000Z","updated_at":"2025-01-15T08:24:20.000Z","dependencies_parsed_at":"2024-12-20T15:21:58.737Z","dependency_job_id":"f35b5ee5-9627-4feb-a2aa-88594ab541c7","html_url":"https://github.com/heng30/toy-os","commit_stats":null,"previous_names":["heng30/toy-os"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/heng30/toy-os","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heng30%2Ftoy-os","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heng30%2Ftoy-os/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heng30%2Ftoy-os/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heng30%2Ftoy-os/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heng30","download_url":"https://codeload.github.com/heng30/toy-os/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heng30%2Ftoy-os/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33204110,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"online","status_checked_at":"2026-05-19T02:00:06.763Z","response_time":58,"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","c","kernel","toy-os"],"created_at":"2024-12-21T08:14:24.326Z","updated_at":"2026-05-19T06:06:27.049Z","avatar_url":"https://github.com/heng30.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"![0.png](./screenshot/0.png)\n\n这是一个根据[Linux操作系统-构建自己的内核](https://www.bilibili.com/video/BV1VJ41157wq?spm_id_from=333.788.videopod.episodes\u0026vd_source=da23da82658adda9cbdfd045a9e6daf7)课程的学习项目。\n\n### 实现的功能\n- 运行在保护模式下，不支持分页功能\n- 处理鼠标和键盘输入\n- 简单的定时器\n- 简单的内存管理\n- 简单的图层管理，保证图层及时刷新\n- 简单的任务调度\n- 支持系统调用\n- 类似于fat32的只读文件系统\n- 一个输入框，可以输入和删除字符\n- 一个简易的终端，支持：`cls, ls, cat, mem, free` 命令\n- 支持运行外部命令, 外部命令运行在特权级3, 拥有自己的代码段和数据段. 并且内核能够处理外部程序的异常\n- 快捷键`ctrl+k`结束正在运行的外部命令（有概率出现bug, 目前没有找到原因）\n- 快捷键`ctrl+q`关闭焦点窗口\n- 快捷键`ctrl+tab`切换焦点窗口\n\n### 如何使用该项目？\n- 编译软盘镜像：`make`\n- 启动`virtualbox`，创建一个虚拟机，虚拟机以软盘启动。软盘加载`build/disk.img`作为启动镜像.\n\n![1.png](./screenshot/1.png)\n\n![1.png](./screenshot/2.png)\n\n### 构建工具\n- gcc: `gcc (GCC) 13.3.0`\n- objconv: `Object file converter version 2.54 for x86 and x86-64 platforms`\n- nasm: `NASM version 2.16.03 compiled on Apr 17 2024`\n\n### 注意事项\n- 无法使用函数指针，会运行错误\n\n- 整个结构体赋值会出问题，导致整个程序异常退出。应该是objconv反汇编出问题。\n```\nstruct Foo {\n    int a;\n    int b;\n}\n\nFoo a = { .a = 0, .b = 0 };\nFoo b = a; // 此处会出问题，可能导致内核在刚启动就异常退出，而不是代码运行到此处\n```\n\n- 条件分支语句太长可能会出异常, 如`if/else if/else`和`swich`语句\n\n- 不要把变量的指针作为获取函数内部状态的参数，反汇编的代码出问题\n```\nvoid foo(int *flag) {\n    *flag = 1;\n}\n\nint flag = 0;\nfoo(\u0026flag);\nassert(flag == 1); // 此处会出错，flag的值依然为0\n```\n\n- 关中断和开中断的使用?\n    - 在中断函数\n    ```\n        int eflags = io_load_eflags();\n        io_cli(); // 暂时停止接收中断信号\n        // 中断代码\n        io_store_eflags(eflags); // 恢复接收中断信号\n    ```\n\n    - 在非中断函数\n    ````\n        io_cli();\n        // 代码\n        io_sti();\n    ````\n\n### 参考\n- [30天自制操作系统](https://github.com/oddman2017/haribote)\n- [Linux操作系统-构建自己的内核](https://www.bilibili.com/video/BV1VJ41157wq?spm_id_from=333.788.videopod.episodes\u0026vd_source=da23da82658adda9cbdfd045a9e6daf7)\n- [课程代码github](https://github.com/wycl16514)\n- [BookOS](https://github.com/hzcx998/BookOS)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheng30%2Ftoy-os","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheng30%2Ftoy-os","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheng30%2Ftoy-os/lists"}