silverrainz / os67 Goto Github PK
View Code? Open in Web Editor NEWAn unix-like toy kernel
License: GNU General Public License v3.0
An unix-like toy kernel
License: GNU General Public License v3.0
大佬,方便留QQ么,有些loader和ld脚本的问题想问一下大佬,内容有点多,想深入♂交谈一番
最近参考了本项目一些部分来构建自己的操作系统,但是发现在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 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.
我安装的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
想问问,是什么原因造成的。是不是因为包升级导致接口改变什么的。
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放上来,希望大佬给指点指点
当执行用户级别的 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
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.
大佬您好,我想请问下为什么 gdt.c 里面 kernel/user 的 code/data segment 都是 0~0xfffff 呢?
https://github.com/SilverRainZ/OS67/blob/master/kern/gdt.c#L56
这样的话 code 和 data segement 重叠了,是不是就没办法防止code段被其他程序写入?
如果想明确的把他们分开,有没有什么比较好的办法呢?还是大佬觉得初学时先别在意这问题?
谢谢大佬
构建fs时,提示有错
构建环境:
Ubuntu 16.04
执行类似 ls | cat
的命令后,可能直接返回到提示符 $
,并在下次执行命令时输出。
或者在 sh 执行 get_cmd
时继续输出(类似 linux 下执行 cat longfile &
的效果)
之后有机率出现内存不足的错误……
宁可开 issue 也不愿意去找 bug
猜测可能是因为这个的问题: e430c07
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
在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)
建议修改这两个文件的名字。
bootsect.asm 文件 retry 下的最后一条语句应该跳回retry重新读取,而不是继续读下一块的数据
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.