Coder Social home page Coder Social logo

os67's Introduction

OS67

OS67 is a unix-like toy kernel, which comes with some user routines. (x86 based)

OS67

Build requirements

Platform: Linux

  • gnu make
  • nasm
  • gcc
  • binutils(ld, objcopy)
  • mkfs
  • bochs 2.6.7+

How to compile

git clone https://github.com/SilverRainZ/OS67.git
cd OS67
make init   # only for first time
make fs     # build root file system and user routines, root privilege required
make        # build kernel
make run    # run with bochs

Syscalls list

int _fork();
int _exit();
int _wait();
int _pipe(int *fd);
int _read(int fd, char *addr, uint32_t n);
int _kill(int pid);
int _exec(char *path, char **argv);
int _fstat(int fd, struct stat *stat);
int _chdir(char *path);
int _dup(int fd);
int _getpid();
int _sleep(uint32_t sec);
int _uptime();
int _open(char *path, uint32_t mode);
int _write(int fd, char *addr, uint32_t n);
int _mknod(char *path, uint32_t di);
int _unlink(char *path);
int _link(char *old, char *new);
int _mkdir(char *path);
int _close(int fd);

User routines list

  • sh: a simple shell, support IO redirect and pipe
  • ls: list files
  • cat: read from stdin and send it to stdout
  • mkdir: make directory
  • rm: remove file
  • ...

Write youself a user routine

  • add a new file in usr/: touch usr/newroutine.c
  • add a new value to UPROGS variable in Makefile as follow:
- UPROGS =  bin/cinit bin/sh bin/cat bin/ls bin/mkdir bin/rm
+ UPROGS =  bin/cinit bin/sh bin/cat bin/ls bin/mkdir bin/rm bin/newroutine
  • in newroutine.c you can use these header files:
    • usys.h: system call interfaces
    • uio.h: basic input output functions
    • string.h: basic string operate functions
  • make fs && make run then you can run your user routine

Bug report

See Issues · SilverRainZ/OS67

Please paste the kernel logs in the issue.

Uncomment macro __LOG_ON as follow to enable logging of specific file:

- // #define __LOG_ON 1
+ #define __LOG_ON 1

License

GNU General Public License Version 3

References

Thanks to

Just for fun.

os67's People

Contributors

aesophor avatar silverrainz avatar timgates42 avatar wjk13720041 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

os67's Issues

输入和执行命令有机率导致键盘失灵或者 Panic。

当执行用户级别的 getchar() 时,过多地调用 printl() 打印 log 似乎会导致奇怪的 panic,比如 Invaild OPCode 或者 GenernalPortection,亦可能导致键盘无响应:无法进入 kb_handle() 函数,而时钟中断正常。

如果将 printl() 替换为空语句,问题似乎不再出现,但是现在 log 仍然非常需要,因此暂不改动。
这可能和 printl() 中的 IO 操作比较耗时有关系。

  #ifdef __LOG_ON
- #define printl(...) _printl(__VA_ARGS__)
+ #define printl(...) ;
  #else
- #define printl(...) _print_null(__VA_ARGS__)
+ #define printl(...) ;
  #endif

Kernel panics and cannot find find module X

========================================================================
                       Bochs x86 Emulator 2.6.11
              Built from SVN snapshot on January 5, 2020
                Timestamp: Sun Jan  5 08:36:00 CET 2020
========================================================================
00000000000i[      ] debugger using rc file 'script/bochsinit'.
00000000000i[      ] LTDL_LIBRARY_PATH not set. using compile time default '/usr/lib/bochs/plugins'
00000000000i[      ] BXSHARE not set. using compile time default '/usr/share/bochs'
00000000000i[      ] lt_dlhandle is 0x55f5baa93c80
00000000000i[PLUGIN] loaded plugin libbx_unmapped.so
00000000000i[      ] lt_dlhandle is 0x55f5baa94bb0
00000000000i[PLUGIN] loaded plugin libbx_biosdev.so
00000000000i[      ] lt_dlhandle is 0x55f5baa95550
00000000000i[PLUGIN] loaded plugin libbx_speaker.so
00000000000i[      ] lt_dlhandle is 0x55f5baa98190
00000000000i[PLUGIN] loaded plugin libbx_extfpuirq.so
00000000000i[      ] lt_dlhandle is 0x55f5baa98960
00000000000i[PLUGIN] loaded plugin libbx_parallel.so
00000000000i[      ] lt_dlhandle is 0x55f5baa9a5c0
00000000000i[PLUGIN] loaded plugin libbx_serial.so
00000000000i[      ] lt_dlhandle is 0x55f5baa9e9c0
00000000000i[PLUGIN] loaded plugin libbx_gameport.so
00000000000i[      ] lt_dlhandle is 0x55f5baa9f1f0
00000000000i[PLUGIN] loaded plugin libbx_iodebug.so
00000000000i[      ] reading configuration from script/bochsrc.bxrc
00000000000i[      ] lt_dlhandle is (nil)
00000000000p[      ] >>PANIC<< dlopen failed for module 'x' (libbx_x.so): file not found
========================================================================

I am on linux mint and have made no modifications to the OS whatsoever.

运行make run时报错

我安装的Bochs是2012年的2.6
创建文件系统的时候

我把bximage bin/rootfs.img -hd=10M -imgmode=flat -mode=create -q改为了bximage bin/rootfs.img -hd -size=10M -mode="flat" -q,不然也是无法运行make fs,报错是说bximage不识别-hd10M的指令。

改完就可以编译内核了。但是不能运行Bochs,导致make run错误

bx_dbg_read_linear: physical memory read error (phy=0x0000000000000000, lin=0x0000000000000000)
00000000000i[CTRL ] quit_sim called with exit code 1

想问问,是什么原因造成的。是不是因为包升级导致接口改变什么的。

It crashes when building fs:

I will show what it's actually shouting to me though (using UBUNTU 22.04 jammy jellyfish):
rm -f bin/rootfs.img bximage bin/rootfs.img -hd=10M -imgmode=flat -mode=create -q Unknown option: -mode=create make: *** [Makefile:80: fs] Error 1

gdt初始化问题(gdt initialization problem)

最近参考了本项目一些部分来构建自己的操作系统,但是发现在gdt的初始化有问题。如下是 /kern/gdt.c:gdt_init() 中的内容:

    /* null descriptor */
    gdt_install(0, 0, 0, 0, 0);  
    /* kernel code segment type: code addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_KCODE, 0, 0xfffff, AC_RW|AC_EX|AC_DPL_KERN|AC_PR, GDT_GR|GDT_SZ);
    /* kernel data segment type: data addr: 0 limit: 4G gran: 4KB sz: bit 32bit */
    gdt_install(SEL_KDATA, 0, 0xfffff, AC_RW|AC_DPL_KERN|AC_PR, GDT_GR|GDT_SZ); 
    /* user code segment type: code addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_UCODE, 0, 0xfffff, AC_RW|AC_EX|AC_DPL_USER|AC_PR, GDT_GR|GDT_SZ); 
    /* user code segment type: data addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_UDATA, 0, 0xfffff, AC_RW|AC_DPL_USER|AC_PR, GDT_GR|GDT_SZ); 

这4个段描述符都没有设置 S 位,其对应的都是属于系统段,而非代码段或数据段。
个人的系统在采用该初始化程序初始化gdt后,后续的初始化失败,直接重置到0x7c00。将其设置 S 位后,系统正常运行。如下:

/* null descriptor */
    gdt_install(0, 0, 0, 0, 0);  
    /* kernel code segment type: code addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_KCODE, 0, 0xfffff, AC_RW|AC_EX|AC_DPL_KERN|AC_PR|**AC_RE**, GDT_GR|GDT_SZ);
    /* kernel data segment type: data addr: 0 limit: 4G gran: 4KB sz: bit 32bit */
    gdt_install(SEL_KDATA, 0, 0xfffff, AC_RW|AC_DPL_KERN|AC_PR|**AC_RE**, GDT_GR|GDT_SZ); 
    /* user code segment type: code addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_UCODE, 0, 0xfffff, AC_RW|AC_EX|AC_DPL_USER|AC_PR|**AC_RE**, GDT_GR|GDT_SZ); 
    /* user code segment type: data addr: 0 limit: 4G gran: 4KB sz: 32bit */
    gdt_install(SEL_UDATA, 0, 0xfffff, AC_RW|AC_DPL_USER|AC_PR|**AC_RE**, GDT_GR|GDT_SZ); 

关于编译运行项目的问题

貌似bochs已经更新了,make run的时候,会报错
bx_dbg_read_linear: physical memory read error (phy=0x0000000000000000,lin=0x0000000000000000)
Screen Shot 2020-01-06 at 15 06 40
希望可以就这个问题解答一下,谢谢!

boot代码问题

bootsect.asm 文件 retry 下的最后一条语句应该跳回retry重新读取,而不是继续读下一块的数据

使用管道后输入输出不同步

执行类似 ls | cat 的命令后,可能直接返回到提示符 $,并在下次执行命令时输出。
或者在 sh 执行 get_cmd 时继续输出(类似 linux 下执行 cat longfile & 的效果)
之后有机率出现内存不足的错误……

宁可开 issue 也不愿意去找 bug

猜测可能是因为这个的问题: e430c07

大佬,关于内核我有些问题

1.我现在理解的内核加载是:bootloader把软盘里的内容加载到内存,然后跳转到ELF文件找到入口执行内核程序,但是不太清楚这里elf是自行进入脚本ld文件设置的入口还是需要我们给定入口位置

2.我现在是把bootloader分为boot和loader来写,boot主要把程序加载到内存,loader主要改显示模式,加载GDT表,开A20和切换保护模式等,我现在内存中的结构大概如此:
;0x7c00 boot
;0x7e00 loader
;0x8200 bios信息
;0x10000 内核

而GDT表现在是这样:
;gdt表
gdt: ;基地址 大小限制 这段的属性
gdt_null: Descriptor 0, 0, 0 ;空记录(基)
gdt_code: Descriptor 0, 0xfffff-1, DA_C+DA_32+DA_LIMIT_4K ;代码段
gdt_data: Descriptor 0, 0xfffff-1, DA_DRW+DA_32+DA_LIMIT_4K ;数据段

gdtLenght equ $-gdt
gdtLimit dw gdtLenght-1
gdtAddress dd gdt

;gdt选择子
selgdt_code equ gdt_code-gdt_null
selgdt_data equ gdt_data-gdt_null

然后我现在lgdt [gdtLimit] 后打算跳到内核执行
jmp dword selgdt_code:0x10000

但是貌似bochs又跳回了boot未启动的部分,也就是说重新加载了一遍程序,我想问一下大佬这里跳转部分我应该怎么做。bochs的GDT表好像和设置的不太一样,我现在总结出可能出现的问题:

1.我GDT设置有问题,基地址跳错位置了
2.我GDT表没设置上去
3.我跳转有问题
4.我从软盘加载到内存时候有问题

而其中内核加载到的内存地址我是boot中通过先将loader加载到0x7e00后将剩余部分全部加载到0x1000:0开始的位置

我下面会把boot和loader放上来,希望大佬给指点指点

cat has a wrong name

The name cat is for concatenate, just like the word concat in other languages. Let's call the current cat kitten for it only reads a file.

关于dev/con.c和inc/con.h的问题

在Windows下clone这个repo,会出现不能创建名叫con的文件的问题。

error: unable to create file dev/con.c (No such file or directory)
error: unable to create file inc/con.h (No such file or directory)

建议修改这两个文件的名字。

TODO

  • fix bugs
  • use buddy algorithm
  • any more?

构建错误

构建fs时,提示有错
构建环境:
Ubuntu 16.04

有些问题想问大佬

大佬,方便留QQ么,有些loader和ld脚本的问题想问一下大佬,内容有点多,想深入♂交谈一番

如何创建内核线程

很高兴有这么一个资源来学习,先感谢,在阅读代码的过程中没有找到创建内核线程的接口,是没有这个接口吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.