├── README.assets ├── arch.png ├── computer.png ├── know.png └── project.excalidraw ├── README.md ├── linux-0.1.1-labs ├── labs │ ├── how_to_debug │ │ ├── debug_asm.assets │ │ │ ├── README.md │ │ │ ├── b.png │ │ │ ├── c.png │ │ │ ├── image.png │ │ │ ├── info_break.png │ │ │ ├── n.png │ │ │ ├── r.png │ │ │ ├── u.png │ │ │ ├── uid977658-20190618-1560852351872.png │ │ │ └── xp.png │ │ └── debug_asm.md │ ├── lab_0_env │ │ ├── README.assets │ │ │ ├── uid871732-20201025-1603626488528 │ │ │ ├── uid871732-20201025-1603626504750 │ │ │ ├── uid977658-20190618-1560851599079 │ │ │ ├── uid977658-20190618-1560851871452 │ │ │ ├── uid977658-20190618-1560852351872 │ │ │ ├── uid977658-20190618-1560853330438 │ │ │ ├── userid19614labid568time1423992747491 │ │ │ └── userid19614labid568time1423993300541 │ │ └── README.md │ ├── lab_1_boot │ │ ├── README.assets │ │ │ ├── uid977658-20190620-1561019062246.png │ │ │ ├── uid977658-20190620-1561019664446.png │ │ │ ├── userid13labid374time1421133578290.png │ │ │ ├── userid13labid374time1421133611337.png │ │ │ ├── userid13labid374time1421133630447.png │ │ │ └── userid13labid374time1421133648517.png │ │ ├── README.md │ │ └── code │ │ │ └── linux-0.11 │ │ │ ├── Makefile │ │ │ ├── boot │ │ │ ├── bootsect.s │ │ │ ├── head.s │ │ │ └── setup.s │ │ │ ├── tags │ │ │ └── tools │ │ │ └── build.c │ ├── lab_2_system_call │ │ ├── .DS_Store │ │ ├── README.assets │ │ │ ├── 929457-20161229210613367-1902103210.png │ │ │ ├── Image_20220524113222.png │ │ │ ├── Image_20220527170429.png │ │ │ ├── Image_20220527170538.png │ │ │ ├── README.md │ │ │ ├── gate.png │ │ │ ├── gate_format.png │ │ │ ├── idt.png │ │ │ ├── image.png │ │ │ └── table.png │ │ ├── README.md │ │ └── code │ │ │ ├── .DS_Store │ │ │ ├── include-in-hdc │ │ │ ├── unistd.h │ │ │ └── who.h │ │ │ ├── linux-0.11 │ │ │ ├── .DS_Store │ │ │ ├── include │ │ │ │ └── linux │ │ │ │ │ └── sys.h │ │ │ └── kernel │ │ │ │ ├── Makefile │ │ │ │ ├── system_call.s │ │ │ │ └── who.c │ │ │ └── testwho.c │ ├── lab_3_track_of_process │ │ ├── README.assets │ │ │ └── README.md │ │ ├── README.md │ │ └── code │ │ │ ├── exit.c │ │ │ ├── fork.c │ │ │ ├── main.c │ │ │ ├── printk.c │ │ │ ├── process.c │ │ │ ├── process.log │ │ │ └── sched.c │ ├── lab_4_switch_of_process │ │ ├── README.assets │ │ │ ├── README.md │ │ │ ├── userid19614labid571time1424053399458.png │ │ │ ├── userid19614labid571time1424053507670.png │ │ │ ├── userid19614labid571time1424053856897.png │ │ │ └── userid19614labid571time1424053880667.png │ │ ├── README.md │ │ └── code │ │ │ ├── fork.c │ │ │ ├── sched.c │ │ │ ├── sched.h │ │ │ ├── system_call.s │ │ │ └── 疑问与解答.txt │ ├── lab_5_semaphore │ │ ├── README.md │ │ └── code │ │ │ ├── include │ │ │ ├── linux │ │ │ │ └── sys.h │ │ │ └── unistd.h │ │ │ ├── kernel │ │ │ ├── Makefile │ │ │ ├── sys_sem.c │ │ │ └── system_call.s │ │ │ └── pc.c │ ├── lab_6_memory │ │ ├── README.assets │ │ │ ├── README.md │ │ │ ├── boch1.jpg │ │ │ ├── boch2.jpg │ │ │ ├── boch3.jpg │ │ │ ├── change_ldt.png │ │ │ ├── get_free_page.png │ │ │ ├── malloc_and_free.png │ │ │ ├── page.jpg │ │ │ ├── seg_desc.jpg │ │ │ ├── seg_index.jpg │ │ │ ├── share.jpg │ │ │ └── user_memory.png │ │ ├── README.md │ │ └── code │ │ │ ├── consumer.c │ │ │ ├── include │ │ │ ├── linux │ │ │ │ └── sys.h │ │ │ └── unistd.h │ │ │ ├── kernel │ │ │ ├── Makefile │ │ │ ├── sys_sem.c │ │ │ ├── sys_shm.c │ │ │ └── system_call.s │ │ │ ├── mm │ │ │ └── memory.c │ │ │ └── producer.c │ ├── lab_7_device │ │ ├── README.md │ │ └── code │ │ │ └── kernel │ │ │ └── chr_dev │ │ │ ├── console.c │ │ │ ├── keyboard.S │ │ │ └── tty_io.c │ └── lab_8_file_system │ │ ├── README.assets │ │ └── README.md │ │ ├── README.md │ │ └── code │ │ ├── fs │ │ ├── Makefile │ │ ├── namei.c │ │ ├── proc.c │ │ └── read_write.c │ │ ├── include │ │ └── sys │ │ │ └── stat.h │ │ └── init │ │ └── main.c ├── linux-0.1.1 │ ├── Makefile │ ├── boot │ │ ├── bootsect.s │ │ ├── head.s │ │ └── setup.s │ ├── fs │ │ ├── Makefile │ │ ├── bitmap.c │ │ ├── block_dev.c │ │ ├── buffer.c │ │ ├── char_dev.c │ │ ├── exec.c │ │ ├── fcntl.c │ │ ├── file_dev.c │ │ ├── file_table.c │ │ ├── inode.c │ │ ├── ioctl.c │ │ ├── namei.c │ │ ├── open.c │ │ ├── pipe.c │ │ ├── read_write.c │ │ ├── stat.c │ │ ├── super.c │ │ └── truncate.c │ ├── include │ │ ├── a.out.h │ │ ├── asm │ │ │ ├── io.h │ │ │ ├── memory.h │ │ │ ├── segment.h │ │ │ └── system.h │ │ ├── const.h │ │ ├── ctype.h │ │ ├── errno.h │ │ ├── fcntl.h │ │ ├── linux │ │ │ ├── config.h │ │ │ ├── fdreg.h │ │ │ ├── fs.h │ │ │ ├── hdreg.h │ │ │ ├── head.h │ │ │ ├── kernel.h │ │ │ ├── mm.h │ │ │ ├── sched.h │ │ │ ├── sched.h.cur1 │ │ │ ├── sched.h.old │ │ │ ├── sys.h │ │ │ └── tty.h │ │ ├── signal.h │ │ ├── stdarg.h │ │ ├── stddef.h │ │ ├── string.h │ │ ├── sys │ │ │ ├── stat.h │ │ │ ├── times.h │ │ │ ├── types.h │ │ │ ├── utsname.h │ │ │ └── wait.h │ │ ├── termios.h │ │ ├── time.h │ │ ├── unistd.h │ │ └── utime.h │ ├── init │ │ └── main.c │ ├── kernel │ │ ├── Makefile │ │ ├── asm.s │ │ ├── blk_drv │ │ │ ├── Makefile │ │ │ ├── blk.h │ │ │ ├── floppy.c │ │ │ ├── hd.c │ │ │ ├── ll_rw_blk.c │ │ │ └── ramdisk.c │ │ ├── chr_drv │ │ │ ├── Makefile │ │ │ ├── console.c │ │ │ ├── rs_io.s │ │ │ ├── serial.c │ │ │ ├── tty_io.c │ │ │ └── tty_ioctl.c │ │ ├── exit.c │ │ ├── fork.c │ │ ├── math │ │ │ ├── Makefile │ │ │ └── math_emulate.c │ │ ├── mktime.c │ │ ├── panic.c │ │ ├── printk.c │ │ ├── sched.c │ │ ├── signal.c │ │ ├── sys.c │ │ ├── system_call.s │ │ ├── traps.c │ │ └── vsprintf.c │ ├── lib │ │ ├── Makefile │ │ ├── _exit.c │ │ ├── close.c │ │ ├── ctype.c │ │ ├── dup.c │ │ ├── errno.c │ │ ├── execve.c │ │ ├── malloc.c │ │ ├── open.c │ │ ├── setsid.c │ │ ├── string.c │ │ ├── wait.c │ │ └── write.c │ ├── mm │ │ ├── Makefile │ │ ├── memory.c │ │ └── page.s │ ├── tags │ └── tools │ │ └── build.c ├── linux_0.1.1_注释 │ ├── Linux内核完全注释(修正版v3.0) (1).docx │ ├── Linux内核完全注释(修正版v3.0).pdf │ └── README.md └── 问题排查记录 │ ├── README.md │ └── 系统调用 │ └── README.md └── theory ├── 0. 操作系统历史 ├── README.assets │ ├── Dennis_Ritchie.jpg │ ├── Ken_Thompson.jpg │ ├── README.md │ ├── computer_1.jpg │ ├── computer_2.jpg │ ├── gnu.jpg │ ├── go.jpg │ ├── linux.jpg │ ├── memory_depart.jpg │ ├── minix.jpg │ ├── os_desc.jpg │ ├── os_loc.jpg │ └── process_of_c2.jpg └── README.md ├── 1. 启动 ├── README.assets │ ├── README.md │ ├── bios_and_boot.excalidraw │ ├── bios_and_bootsect.png │ ├── head.png │ ├── image_after_head.png │ ├── image_after_main.png │ ├── image_after_setup.png │ ├── image_s.excalidraw │ ├── image_s.png │ ├── page_p.png │ ├── processes.png │ ├── setup.excalidraw │ ├── setup.png │ ├── why_move_code.png │ └── why_start_from_0x7c.png └── README.md ├── 10. 大数据 └── README.md ├── 2. 中断与系统调用 └── README.md ├── 3. 进程 ├── 1. 进程定义及诞生原因 │ └── README.md ├── 10. 线程状态 │ └── README.md ├── 11. iowait │ └── README.md ├── 2. 进程结构 │ ├── README.assets │ │ ├── README.md │ │ ├── simple_struct_of_task.png │ │ ├── simple_structure_of_task.excalidraw │ │ ├── structure_of_task.excalidraw │ │ └── structure_of_task.png │ └── README.md ├── 3. 0号进程与1号进程 │ └── README.md ├── 4. fork │ ├── README.assets │ │ ├── PBC.png │ │ ├── README.md │ │ ├── copy_on_write.png │ │ └── copy_page_tables.png │ └── README.md ├── 5. 进程生命周期及调度 │ ├── README.assets │ │ └── README.md │ └── README.md ├── 6. 进程信号处理 │ ├── README.assets │ │ ├── README.md │ │ ├── do_signal.png │ │ ├── kill.png │ │ ├── r_sig_d.png │ │ ├── sa_restorer1.png │ │ ├── sa_restorer2.png │ │ ├── sigs.png │ │ └── stack_of_do_signal.png │ └── README.md ├── 7. 会话及进程组 │ ├── README.assets │ │ ├── README.md │ │ ├── session1.png │ │ └── session2.png │ └── README.md ├── 8. 进程同步——信号量 │ └── README.md ├── 9. 多线程同步 │ ├── README.assets │ │ ├── README.md │ │ ├── jmm_barrier.png │ │ ├── sync.png │ │ └── volatile_barrier.png │ └── README.md └── README.md ├── 4. 内存管理 ├── 1. 实模式与保护模式(分页) │ └── README.md ├── 2. 内核内存管理 │ └── README.md ├── 3. Java读写为什么要在堆内堆外进行拷贝 │ └── README.md └── README.md ├── 5. 设备管理 ├── 1. 字符设备驱动程序(char device) │ ├── README.assets │ │ ├── README.md │ │ ├── console.png │ │ ├── devs.png │ │ ├── kernel_chr_drv.png │ │ ├── process_of_char_dev.png │ │ ├── read_and_write_series.png │ │ ├── rs_io1.png │ │ ├── rs_write_1.png │ │ ├── rs_write_2.png │ │ ├── serise.png │ │ └── support_tty.png │ └── README.md ├── 2. 块设备驱动程序(block driver) │ ├── README.assets │ │ ├── README.md │ │ ├── blk_devs.png │ │ ├── block_and_file.png │ │ ├── block_operation.png │ │ ├── do_XX_request.png │ │ └── kernel_blk_drv.png │ └── README.md ├── README.assets │ ├── README.md │ └── devices.png └── README.md ├── 6. 文件系统 ├── 1. 虚拟文件系统 │ ├── README.assets │ │ ├── Linux.Generic.Block.Layer.pdf │ │ ├── Linux.Kernel.Cache.pdf │ │ ├── Linux.Kernel.IO.Scheduler.pdf │ │ ├── Linux.Kernel.Read.Procedure.pdf │ │ ├── Linux.Kernel.Write.Procedure.pdf │ │ ├── Linux.Virtual.Filesystem.pdf │ │ ├── README.md │ │ ├── VFS.png │ │ └── vfs-frame-look.png │ └── README.md ├── README.assets │ ├── README.md │ └── file_sys.png ├── README.md └── 附 1: 解析FAT32文件系统 │ ├── README.assets │ ├── README.md │ ├── boot_sec_of_fat.png │ ├── fat_struct.png │ ├── fat_table.png │ ├── fatinfo.png │ ├── long_dir_table.png │ └── short_dir_table.png │ └── README.md ├── 7. 虚拟化 ├── 1. 容器级别轻量级虚拟化 │ ├── 1. namespace │ │ └── README.md │ ├── 2. cgroup │ │ └── README.md │ ├── 3. chroot │ │ └── README.md │ └── 4. 容器网络 │ │ └── README.md ├── 2. 全虚拟化 │ ├── 1. KVM │ │ └── README.md │ ├── 2. 全虚拟化网络 │ │ └── README.md │ └── README.md ├── 3. OpenStack │ └── README.md ├── 4. K8S │ └── README.md ├── 5. 虚拟化隔离性对比 │ └── README.md ├── 6. 虚拟化损耗对比 │ └── README.md ├── 7. 虚拟化技术未来畅想 │ └── README.md └── README.md ├── 8. 网络 └── README.md ├── 9. 操作系统的发展 └── README.md ├── 附0:8bit计算机仿真(MIPS指令) ├── README.md ├── compute_of_8bit.circ └── logisim-generic-2.7.1.jar ├── 附1:硬件相关 ├── CPU(Intel)及计算机发展历史 │ ├── README.assets │ │ ├── 101-电子计算机的兴起.pdf │ │ ├── README.md │ │ ├── history_of_cpu.excalidraw │ │ └── history_of_cpu.png │ └── README.md ├── 中断与系统调用 │ ├── README.assets │ │ ├── 805-内部中断分类说明.pdf │ │ ├── README.md │ │ ├── aburt.png │ │ ├── change.png │ │ ├── change_.png │ │ ├── exs.png │ │ ├── exs_num.png │ │ ├── fault.png │ │ ├── gate.png │ │ ├── gate_format.png │ │ ├── idt.png │ │ ├── idt_table.png │ │ ├── init_idt_in_main.png │ │ ├── int.png │ │ ├── interrupt_process.png │ │ ├── interrupt_service.png │ │ ├── interrupt_space.png │ │ ├── interrupt_table.png │ │ ├── interrupt_table_of_protect_mode.png │ │ ├── interrupt_vector.png │ │ ├── sched_init.png │ │ ├── trap.png │ │ └── trapinit.png │ └── README.md ├── 实模式与保护模式 │ ├── README.assets │ │ ├── GDTR.excalidraw │ │ ├── GDTR.png │ │ ├── GDT_LDT.excalidraw │ │ ├── GDT_LDT.png │ │ ├── README.md │ │ ├── TI0.excalidraw │ │ ├── TI0.html │ │ ├── TI0.svg │ │ ├── TI1.excalidraw │ │ ├── TI1.html │ │ ├── TI1.svg │ │ ├── page.excalidraw │ │ ├── page.png │ │ ├── price_of_memory.png │ │ ├── protect_mode_address.excalidraw │ │ ├── protect_mode_address.png │ │ ├── segment.excalidraw │ │ ├── segment.png │ │ ├── segment_description.excalidraw │ │ ├── segment_description.png │ │ ├── segment_selector.excalidraw │ │ ├── segment_selector.excalidraw.png │ │ ├── type.excalidraw │ │ ├── type.png │ │ ├── vertual_address.png │ │ └── vertual_address_space.png │ └── README.md └── 寄存器(x86架构) │ ├── README.assets │ ├── README.md │ ├── register.excalidraw │ └── register.excalidraw.svg │ └── README.md ├── 附2:C语言相关 ├── C变量与常量及其指针 │ └── README.md ├── C语言GDB调试 │ └── README.md ├── C语言变量内存位置及m指令寻址方式 │ └── README.md ├── C语言编译与标准库、系统调用 │ ├── README.assets │ │ ├── C_compile.excalidraw │ │ ├── C_compile.png │ │ ├── README.md │ │ ├── dyc1.png │ │ ├── dyc2.png │ │ ├── ex.png │ │ ├── ex_h_t.png │ │ ├── gcc.excalidraw │ │ ├── gcc.png │ │ ├── relocatable_0.png │ │ ├── relocatable_1.png │ │ ├── runtime.png │ │ ├── short.png │ │ └── usage_of_link.png │ └── README.md └── 函数调用机制 │ ├── README.assets │ ├── README.md │ ├── stack_frame.png │ └── stack_of_func.png │ └── README.md ├── 附3:其他 ├── C语言栈帧与Java栈帧 │ └── README.md └── Why X86 比起 ARM 更费电 │ └── README.md └── 附4:文章精选 └── README.md /README.assets/arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/README.assets/arch.png -------------------------------------------------------------------------------- /README.assets/computer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/README.assets/computer.png -------------------------------------------------------------------------------- /README.assets/know.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/README.assets/know.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 前言 2 | 3 | ![电脑](README.assets/computer.png) 4 | 5 | 操作系统,其蕴含了大量精巧的设计。完全理解操作系统,应该是很多程序员都想做的事情,但是每当我们想要去学习操作系统,了解其奥秘时,都会被里面 晦涩难懂的设计和一些闻所未闻的名词劝退。即使没有被劝退,非常痛苦的看完一本晦涩难懂的操作系统的书籍后,也会发现自己好像只是理解了一点操作系统的皮毛,并没有对其有一个很透彻的理解。而且时间长了之后,那些好不容易学到的"皮毛"也会被时间带来的“遗忘之风”吹散。 6 | 7 | 而且操作系统不仅要求对底层的硬件知识有一定的了解,对于汇编语言、C语言、数据结构与算法都需要有一定的基础。这些基础里面任何一个看起来都需要很长的时间去学习。因此完全理解操作系统,变成了一件非常非常困难的事情。而且在国内,由于操作系统的相关书籍水平参差不齐,大学的课程也大都将多个科目分开讲授,没有从实践的角度去解释清楚各个科目之间的联系,因此完全理解操作系统更是变得尤其困难。 8 | 9 | ![结构](README.assets/know.png) 10 | 11 | 但是近几年随着国内教育的变革,以及国内一些年轻的、怀着理想的程序员们可以在视频软件(如:B站) 上发布自己对一些知识的理解,并尝试用十分通俗易懂且形象的方式将其呈现出来。“星星之火,可以燎原。”这些微小的变化与努力汇集到一起,使得我们如果想要系统性地学习与了解操作系统,变得没有那么困难。下面是我自己整理的一些课程: 12 | 13 | [编程前你最好了解的基本硬件和计算机基础知识(模拟电路)](https://www.bilibili.com/video/BV1774114798?spm_id_from=333.999.0.0) 14 | 15 | [编程前你最好了解的基本硬件和计算机基础知识(数字电路)](https://www.bilibili.com/video/BV1Hi4y1t7zY?spm_id_from=333.999.0.0) 16 | 17 | [从0到1设计一台计算机](https://www.bilibili.com/video/BV1wi4y157D3?spm_id_from=333.999.0.0) 18 | 19 | [北京大学精品公开课:计算机组成与设计](https://www.bilibili.com/video/BV1tp4y197Av?spm_id_from=333.999.0.0) 20 | 21 | [操作系统(哈工大李治军老师)](https://www.bilibili.com/video/BV1d4411v7u7?spm_id_from=333.999.0.0) 22 | 23 | [《一个64位操作系统的设计与实现》](https://book.douban.com/subject/30222325/) 24 | 25 | [深入理解计算机系统(动画视频)](https://www.bilibili.com/video/BV1cD4y1D7uR?spm_id_from=333.999.0.0) 26 | 27 | [深入理解计算机系统(原书第3版)](https://www.baidu.com/link?url=LJBXAsJR1IDH_HU4Tnx1pUI25c7bjsIFAUxJQ61zheYRSsQqB2_5j8CKu-fYwdKHhvU3qsLeMPd7eW6_MS4K2a&wd=&eqid=92946e37000e3797000000066280ca29) 28 | 29 | 这些课程大多形象具体,老师们授课由浅入深,风格诙谐幽默,让晦涩难懂的东西变得通俗易懂。另一方面,老师们的课程也不仅仅局限于将技术讲明白,更多地是将整个计算机的历史娓娓道来,讲述了一个简单的开闭电路如何一步一步构造成如今这个几乎无所不能的计算机。整个过程中,我们会发现原来计算机的历史不只是微软抄袭了苹果的某些技术,苹果又剽窃了某某实验室的技术。这些或许只是整个计算机发展长河里的一个很小的浪花,而在这条长河里我们更多地是会看到,前辈们如何一个踩在另一个人的肩膀上,从而汇聚成一个庞大的巨人,他们每一个人都是这个巨人的一部分,每一个人都让这个巨人的高度再增加那么一点。 而学习整个课程,就是跟着老师们的脚步一步一步领略这个巨人的智慧。 30 | 31 | 这些课程的学习顺序,大家可以按照 模电——> 数电 ——> 从0到1设计与实现计算机——> 计算机组成原理(北大)——>操作系统(哈工大)——>《一个64位操作系统的设计与实现》的顺序,并以《深入理解计算机系统》为辅助材料来进行学习。诚然,这是一个漫长的过程,但是大家按照这个顺序去学习,必然会有一定的收获。快餐式的学习一定会伴随着快餐式的遗忘,唯有缓慢地长期地系统性地学习才会为自己带来真正的成长,对一些知识也会有自己的理解。另外系统性地了解过去,站在现在的节点才能更好地看到未来,而不置于被当下一些迷雾所蒙蔽,看不到整个计算机依然宏伟的未来。 32 | 33 | ![学习结构](README.assets/arch.png) 34 | 35 | 而本项目除了介绍上面这些课程以外,主要记录了操作系统的学习过程中对于李治军老师讲授的操作系统课程中的 linux0.1.1进行扩展的一些实验说明及代码,以及记录了学习过程中的一些自己的想法与收获。如果哪些地方有问题,也欢迎各位指出来,一起进行学习与讨论。 36 | 37 | ## 项目结构说明 38 | 39 | - linux-0.1.1-labs : 在linux-0.1.1上做的一些实验。 40 | 41 | - theory : 操作系统相关理论。 42 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/b.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/c.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/image.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/info_break.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/info_break.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/n.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/r.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/u.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/u.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/uid977658-20190618-1560852351872.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/uid977658-20190618-1560852351872.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/xp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/how_to_debug/debug_asm.assets/xp.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/how_to_debug/debug_asm.md: -------------------------------------------------------------------------------- 1 | ## ASM调试 2 | 3 | ### 开始asm调试 4 | 汇编级调试需要执行命令: 5 | ``` 6 | # 确认在 oslab 目录下 7 | $ cd ~/oslab/ 8 | 9 | # 运行脚本前确定已经关闭刚刚运行的 Bochs 10 | $ ./dbg-asm 11 | ``` 12 | > 汇编级调试的启动之后 Bochs 是黑屏,这是正常的。 13 | ### 常用命令介绍 14 | #### 设置断点`b` 15 | > 格式: b 内存地址 16 | 17 | 如: b 0x7c00,在线性地址0x7c00处设置断点。 18 | 19 | ##### 示例 20 | ![示例](./debug_asm.assets/b.png) 21 | #### 查看设置过的断点`info break` 22 | > 格式:info break 23 | 24 | ##### 示例 25 | ![示例](./debug_asm.assets/info_break.png) 26 | #### 继续执行`c` 27 | > 格式: c 28 | ##### 示例 29 | ![示例](./debug_asm.assets/c.png) 30 | #### 执行下一行代码`n` 31 | > 格式: n 32 | 33 | 它和单步执行类似,单步执行遇到循环和函数时会跳转到内部,而n命令会执行完循环和函数,类似于step over,这样在遇到大量的循环或者较长的函数时,可以用n命令来执行到下一行。 34 | 35 | n命令能跳转到下一行是因为loop或者call执行有明显的结束标记(前者通过cx寄存器,后者通ret指令),如果遇到用jmp语句写的循环这种情况,没有明显结束标记的,可以用下面的u命令反汇编代码的地址,找到循环的下一行指令的地址,然后给该地址加一个断点就能达到同样的效果。 36 | ##### 示例 37 | ![示例](./debug_asm.assets/n.png) 38 | #### 反编译`u` 39 | > 格式: u /20 0x7c00 或者 u 40 | 直接使用u命令会反汇编当前执行的指令,它可以加参数, u /反汇编数量 起始地址 ,如 u /20 0x7c00 就是从0x7c00处开始,反汇编20条指令,如果没有起始地址就是从当前地址开始。 41 | 42 | 它还可以反汇编一个范围的代码,u 起始地址 结束地址 ,如u 0x7c00 0x7cff 就是反汇编0x7c00到0x7cff的代码。 43 | ##### 示例 44 | ![示例](./debug_asm.assets/u.png) 45 | #### 查看内存`xp` 46 | > 格式: xp /nuf 地址 查看物理地址处的内存内容。 47 | ``` 48 | n 指定要显示的内存单元的数量 49 | u 显示的内存单元的大小,如下参数之一 50 | b 单个字节 51 | h 半个字(2 字节) 52 | w 一个字(4 字节) 53 | f 打印的格式。如下类型之一: 54 | x 按照十六进制形式打印 55 | d 按照十进制形式打印 56 | u 以无符号的10进制打印 57 | o 按照八进制形式打印 58 | t 按照二进制形式打印 59 | c 按照字符制形式打印 60 | ``` 61 | ##### 示例 62 | ![示例](./debug_asm.assets/xp.png) 63 | #### 查看寄存器`r` 64 | 汇编代码中,调试最常用的功能就是查看寄存器的内容。 65 | ``` 66 | r 查看通用寄存器 67 | sreg 查看段寄存器 68 | creg 查看控制寄存器 69 | dreg 查看调试寄存器 70 | info cpu 查看所有寄存器 71 | ``` 72 | ##### 示例 73 | ![示例](./debug_asm.assets/r.png) 74 | ### help如何使用 75 | 可以用命令 help 来查看调试系统用的基本命令。更详细的信息请查阅 Bochs 使用手册。 76 | ![help](./debug_asm.assets/uid977658-20190618-1560852351872.png) 77 | 78 | ### 不错的博客 79 | - [Bochs调试常用命令](https://petpwiuta.github.io/2020/05/09/Bochs%E8%B0%83%E8%AF%95%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/) 80 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid871732-20201025-1603626488528: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid871732-20201025-1603626488528 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid871732-20201025-1603626504750: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid871732-20201025-1603626504750 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560851599079: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560851599079 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560851871452: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560851871452 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560852351872: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560852351872 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560853330438: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/uid977658-20190618-1560853330438 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/userid19614labid568time1423992747491: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/userid19614labid568time1423992747491 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_0_env/README.assets/userid19614labid568time1423993300541: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_0_env/README.assets/userid19614labid568time1423993300541 -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/uid977658-20190620-1561019062246.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/uid977658-20190620-1561019062246.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/uid977658-20190620-1561019664446.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/uid977658-20190620-1561019664446.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133578290.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133578290.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133611337.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133611337.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133630447.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133630447.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133648517.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_1_boot/README.assets/userid13labid374time1421133648517.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_1_boot/code/linux-0.11/boot/bootsect.s: -------------------------------------------------------------------------------- 1 | SETUPLEN=2 2 | SETUPSEG=0x07e0 3 | entry _start 4 | _start: 5 | ! read cursor pos , pos will be in dx 6 | mov ah,#0x03 7 | xor bh,bh 8 | int 0x10 9 | 10 | ! show msg1 11 | ! cx is the length of msg1 12 | mov cx,#38 13 | 14 | ! es:bp is the address of msg1 15 | mov bp,#msg1 16 | mov ax,#0x07c0 17 | mov es,ax 18 | 19 | ! page 0, attribute7 (normal) 20 | mov bx,#0x0007 21 | 22 | ! write string, move cursor 23 | mov ax,#0x1301 24 | int 0x10 25 | 26 | load_setup: 27 | !set driver(0) and header(0) 28 | mov dx,#0x0000 29 | 30 | !set track(0) and sector(2) 31 | mov cx,#0x0002 32 | 33 | !set load to where() 34 | mov bx,#0x0200 35 | mov ax,#0x0200+SETUPLEN 36 | 37 | ! use int 0x13 to load from disk 38 | int 0x13 39 | 40 | !ok_load_setup: ok - continue 41 | jnc ok_load_setup 42 | 43 | !reset the diskette 44 | mov dx,#0x0000 45 | mov ax,#0x0000 46 | int 0x13 47 | 48 | !load again 49 | jmp load_setup 50 | 51 | ok_load_setup: 52 | !jump to setup 53 | jmpi 0, SETUPSEG 54 | 55 | msg1: 56 | .byte 13,10 57 | .ascii "Hello world!I,m WithoutOS! ^_< ! " 58 | .byte 13,10,13,10 59 | 60 | .org 510 ! org is used to specific physic address 61 | boot_flag: 62 | .word 0xAA55 63 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/.DS_Store -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/929457-20161229210613367-1902103210.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/929457-20161229210613367-1902103210.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220524113222.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220524113222.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220527170429.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220527170429.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220527170538.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/Image_20220527170538.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/gate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/gate.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/gate_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/gate_format.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/idt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/idt.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/image.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/README.assets/table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/README.assets/table.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/code/.DS_Store -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/include-in-hdc/who.h: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/who.c 3 | * 4 | * (C) 2022 Without 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall2(int,iam,int,fd,int,size) 11 | 12 | _syscall1(int,whoami,int,size) 13 | 14 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/linux-0.11/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_2_system_call/code/linux-0.11/.DS_Store -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/linux-0.11/include/linux/sys.h: -------------------------------------------------------------------------------- 1 | extern int sys_setup(); 2 | extern int sys_exit(); 3 | extern int sys_fork(); 4 | extern int sys_read(); 5 | extern int sys_write(); 6 | extern int sys_open(); 7 | extern int sys_close(); 8 | extern int sys_waitpid(); 9 | extern int sys_creat(); 10 | extern int sys_link(); 11 | extern int sys_unlink(); 12 | extern int sys_execve(); 13 | extern int sys_chdir(); 14 | extern int sys_time(); 15 | extern int sys_mknod(); 16 | extern int sys_chmod(); 17 | extern int sys_chown(); 18 | extern int sys_break(); 19 | extern int sys_stat(); 20 | extern int sys_lseek(); 21 | extern int sys_getpid(); 22 | extern int sys_mount(); 23 | extern int sys_umount(); 24 | extern int sys_setuid(); 25 | extern int sys_getuid(); 26 | extern int sys_stime(); 27 | extern int sys_ptrace(); 28 | extern int sys_alarm(); 29 | extern int sys_fstat(); 30 | extern int sys_pause(); 31 | extern int sys_utime(); 32 | extern int sys_stty(); 33 | extern int sys_gtty(); 34 | extern int sys_access(); 35 | extern int sys_nice(); 36 | extern int sys_ftime(); 37 | extern int sys_sync(); 38 | extern int sys_kill(); 39 | extern int sys_rename(); 40 | extern int sys_mkdir(); 41 | extern int sys_rmdir(); 42 | extern int sys_dup(); 43 | extern int sys_pipe(); 44 | extern int sys_times(); 45 | extern int sys_prof(); 46 | extern int sys_brk(); 47 | extern int sys_setgid(); 48 | extern int sys_getgid(); 49 | extern int sys_signal(); 50 | extern int sys_geteuid(); 51 | extern int sys_getegid(); 52 | extern int sys_acct(); 53 | extern int sys_phys(); 54 | extern int sys_lock(); 55 | extern int sys_ioctl(); 56 | extern int sys_fcntl(); 57 | extern int sys_mpx(); 58 | extern int sys_setpgid(); 59 | extern int sys_ulimit(); 60 | extern int sys_uname(); 61 | extern int sys_umask(); 62 | extern int sys_chroot(); 63 | extern int sys_ustat(); 64 | extern int sys_dup2(); 65 | extern int sys_getppid(); 66 | extern int sys_getpgrp(); 67 | extern int sys_setsid(); 68 | extern int sys_sigaction(); 69 | extern int sys_sgetmask(); 70 | extern int sys_ssetmask(); 71 | extern int sys_setreuid(); 72 | extern int sys_setregid(); 73 | extern int sys_iam(); 74 | extern int sys_whoami(); 75 | 76 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 77 | sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link, 78 | sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod, 79 | sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount, 80 | sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm, 81 | sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access, 82 | sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir, 83 | sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid, 84 | sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys, 85 | sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit, 86 | sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid, 87 | sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask, 88 | sys_setreuid,sys_setregid,sys_iam,sys_whoami }; 89 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/linux-0.11/kernel/who.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/who.c 3 | * 4 | * (C) 2022 Without 5 | */ 6 | 7 | #include 8 | 9 | static char buf[24]; 10 | 11 | int sys_iam(const char * name,int name_size){ 12 | printk("Step 1 : Sys_iam begin. name_address: %d , buf_address: %d , name_size: %d,buf: %s.\r\n", name,buf, name_size,buf); 13 | __asm__( 14 | //mov before change eds 15 | "movl %0,%%edi\n\t" 16 | "movl $0x17,%%edx\n\t" 17 | "mov %%dx,%%ds\n\t" 18 | "movl %1,%%esi\n\t" 19 | // copy 20 | "cld\n\t" 21 | "rep\n\t" 22 | "movsb\n\t" 23 | "movl $0x10,%%edx\n\t" 24 | "mov %%dx,%%ds\n\t" 25 | :: 26 | "m"(buf),"m"(name),"c"(name_size)); 27 | 28 | printk("Step 2 : Sys_iam end. buf: %s .\r\n", buf); 29 | return 1; 30 | } 31 | 32 | int sys_whoami(unsigned int size){ 33 | printk("sys_whoami: %s.\r\n", buf); 34 | return 1; 35 | } 36 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_2_system_call/code/testwho.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char * name = "Without"; 7 | printf("call iam\r\n"); 8 | iam(name,7); 9 | printf("call iam end\r\n"); 10 | printf("call whoami\r\n"); 11 | whoami(7); 12 | printf("call whoami end\r\n"); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_3_track_of_process/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_3_track_of_process/code/printk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/printk.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * When in kernel-mode, we cannot use printf, as fs is liable to 9 | * point to 'interesting' things. Make a printf with fs-saving, and 10 | * all is well. 11 | */ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | static char buf[1024]; 19 | 20 | extern int vsprintf(char * buf, const char * fmt, va_list args); 21 | 22 | int printk(const char *fmt, ...) 23 | { 24 | va_list args; 25 | int i; 26 | 27 | va_start(args, fmt); 28 | i=vsprintf(buf,fmt,args); 29 | va_end(args); 30 | __asm__("push %%fs\n\t" 31 | "push %%ds\n\t" 32 | "pop %%fs\n\t" 33 | "pushl %0\n\t" 34 | "pushl $buf\n\t" 35 | "pushl $0\n\t" 36 | "call tty_write\n\t" 37 | "addl $8,%%esp\n\t" 38 | "popl %0\n\t" 39 | "pop %%fs" 40 | ::"r" (i):"ax","cx","dx"); 41 | return i; 42 | } 43 | 44 | /* 45 | * write by sunner 46 | */ 47 | static char logbuf[1024]; 48 | int fprintk(int fd, const char *fmt, ...) 49 | { 50 | va_list args; 51 | int count; 52 | struct file * file; 53 | struct m_inode * inode; 54 | va_start(args, fmt); 55 | count=vsprintf(logbuf, fmt, args); 56 | va_end(args); 57 | if (fd < 3) 58 | /* 如果输出到stdout或stderr,直接调用sys_write即可 */ 59 | { 60 | __asm__("push %%fs\n\t" 61 | "push %%ds\n\t" 62 | "pop %%fs\n\t" 63 | "pushl %0\n\t" 64 | "pushl $logbuf\n\t" /* 注意对于Windows环境来说,是_logbuf,下同 */ 65 | "pushl %1\n\t" 66 | "call sys_write\n\t" /* 注意对于Windows环境来说,是_sys_write,下同 */ 67 | "addl $8,%%esp\n\t" 68 | "popl %0\n\t" 69 | "pop %%fs" 70 | ::"r" (count),"r" (fd):"ax","cx","dx"); 71 | } 72 | else 73 | /* 假定>=3的描述符都与文件关联。事实上,还存在很多其它情况,这里并没有考虑。*/ 74 | { 75 | if (!(file=task[0]->filp[fd])) /* 从进程0的文件描述符表中得到文件句柄 */ 76 | return 0; 77 | inode=file->f_inode; 78 | __asm__("push %%fs\n\t" 79 | "push %%ds\n\t" 80 | "pop %%fs\n\t" 81 | "pushl %0\n\t" 82 | "pushl $logbuf\n\t" 83 | "pushl %1\n\t" 84 | "pushl %2\n\t" 85 | "call file_write\n\t" 86 | "addl $12,%%esp\n\t" 87 | "popl %0\n\t" 88 | "pop %%fs" 89 | ::"r" (count),"r" (file),"r" (inode):"ax","cx","dx"); 90 | } 91 | return count; 92 | } -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_3_track_of_process/code/process.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define HZ 100 8 | 9 | void cpuio_bound(int last, int cpu_time, int io_time); 10 | /* 11 | 1. 所有子进程都并行运行,每个子进程的实际运行时间一般不超过30秒; 12 | 2. 父进程向标准输出打印所有子进程的id,并在所有子进程都退出后才退出; 13 | */ 14 | int main(int argc, char * argv[]) 15 | { 16 | pid_t n_proc[10]; /*10个子进程 PID*/ 17 | int i; 18 | for(i=0;i<10;i++) 19 | { 20 | n_proc[i] = fork(); 21 | /*子进程*/ 22 | if(n_proc[i] == 0) 23 | { 24 | cpuio_bound(20,2*i,20-2*i); /*每个子进程都占用20s*/ 25 | return 0; /*执行完cpuio_bound 以后,结束该子进程*/ 26 | } 27 | /*fork 失败*/ 28 | else if(n_proc[i] < 0 ) 29 | { 30 | printf("Failed to fork child process %d!\n",i+1); 31 | return -1; 32 | } 33 | /*父进程继续fork*/ 34 | } 35 | /*打印所有子进程PID*/ 36 | for(i=0;i<10;i++) 37 | printf("Child PID: %d\n",n_proc[i]); 38 | /*等待所有子进程完成*/ 39 | wait(&i); /*Linux 0.11 上 gcc要求必须有一个参数, gcc3.4+则不需要*/ 40 | return 0; 41 | } 42 | 43 | /* 44 | * 此函数按照参数占用CPU和I/O时间 45 | * last: 函数实际占用CPU和I/O的总时间,不含在就绪队列中的时间,>=0是必须的 46 | * cpu_time: 一次连续占用CPU的时间,>=0是必须的 47 | * io_time: 一次I/O消耗的时间,>=0是必须的 48 | * 如果last > cpu_time + io_time,则往复多次占用CPU和I/O 49 | * 所有时间的单位为秒 50 | */ 51 | void cpuio_bound(int last, int cpu_time, int io_time) 52 | { 53 | struct tms start_time, current_time; 54 | clock_t utime, stime; 55 | int sleep_time; 56 | 57 | while (last > 0) 58 | { 59 | /* CPU Burst */ 60 | times(&start_time); 61 | /* 其实只有t.tms_utime才是真正的CPU时间。但我们是在模拟一个 62 | * 只在用户状态运行的CPU大户,就像“for(;;);”。所以把t.tms_stime 63 | * 加上很合理。*/ 64 | do 65 | { 66 | times(¤t_time); 67 | utime = current_time.tms_utime - start_time.tms_utime; 68 | stime = current_time.tms_stime - start_time.tms_stime; 69 | } while ( ( (utime + stime) / HZ ) < cpu_time ); 70 | last -= cpu_time; 71 | 72 | if (last <= 0 ) 73 | break; 74 | 75 | /* IO Burst */ 76 | /* 用sleep(1)模拟1秒钟的I/O操作 */ 77 | sleep_time=0; 78 | while (sleep_time < io_time) 79 | { 80 | sleep(1); 81 | sleep_time++; 82 | } 83 | last -= sleep_time; 84 | } 85 | } -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053399458.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053399458.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053507670.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053507670.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053856897.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053856897.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053880667.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_4_switch_of_process/README.assets/userid19614labid571time1424053880667.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_4_switch_of_process/code/疑问与解答.txt: -------------------------------------------------------------------------------- 1 | 0、未修改前的代码fork时,需要拷贝内核栈吗?不拷贝的话,为什么?拷贝的话,代码在哪里? 2 | 3 | 不拷贝,因为未修改前的代码在switch时直接通过tss转换到新进程,而在fork时tss中填写的cs ip 直接为用户态的代码段,因此switch将直接将新进程转换到用户态。 4 | 而修改后的代码由于不能通过tss恢复寄存器的值,故需要通过first_run_after_fork来恢复寄存器的值。 5 | 6 | 7 | 1、针对下面的代码片段: 8 | 9 | movl tss,%ecx 10 | addl $4096,%ebx 11 | movl %ebx,ESP0(%ecx) 12 | 回答问题: 13 | 14 | (1)为什么要加 4096; 15 | 16 | 答:4096=4kB,在linux0.11中,一个进程的内核栈和该进程的PCB段是放在一块大小为4KB的内存段中的,其中该内存段的高地址开始是内核栈,低地址开始是PCB段。ebx是指向一个进程的PCB,偏移4096后便指向了另一个进程的PCB.栈结构如下: 17 | 18 | 在这里插入图片描述 19 | 20 | (2)为什么没有设置 tss 中的 ss0。 21 | 22 | SS0、SS1和SS2分别是0、1和2特权级的栈段选择子。这里用不着特权级为0的内核段。此时唯一的tss的目的就是:在中断处理时,能够找到当前进程的内核栈的位置。 23 | 24 | 2、针对下面代码片段 25 | 26 | *(--krnstack) = ebp; 27 | *(--krnstack) = ecx; 28 | *(--krnstack) = ebx; 29 | *(--krnstack) = 0; 30 | 回答问题 31 | 32 | 1、子进程第一次执行时,eax=?为什么要等于这个数?哪里的工作让 eax 等于这样一个数? 33 | 34 | eax = 0;其实就是将内核栈用用于返回给eax寄存器的内容置为0,最后eax的内容会返回给fork函数 35 | 36 | 2、这段代码中的 ebx 和 ecx 来自哪里,是什么含义,为什么要通过这些代码将其写到子进程的内核栈中? 37 | 38 | 答:ebx和ecx来自copy_process()的形参,形参的来源是各个段寄存器。对于fork函数而言,子进程是父进程的拷贝,就是要让父子进程共用同一个代码、数据和堆栈。 39 | 40 | 3、这段代码中的 ebp 来自哪里,是什么含义,为什么要做这样的设置?可以不设置吗?为什么? 41 | 42 | ebp是用户栈地址,一定要设置,不设置子进程就没有用户栈了。 43 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_5_semaphore/code/include/linux/sys.h: -------------------------------------------------------------------------------- 1 | extern int sys_setup(); 2 | extern int sys_exit(); 3 | extern int sys_fork(); 4 | extern int sys_read(); 5 | extern int sys_write(); 6 | extern int sys_open(); 7 | extern int sys_close(); 8 | extern int sys_waitpid(); 9 | extern int sys_creat(); 10 | extern int sys_link(); 11 | extern int sys_unlink(); 12 | extern int sys_execve(); 13 | extern int sys_chdir(); 14 | extern int sys_time(); 15 | extern int sys_mknod(); 16 | extern int sys_chmod(); 17 | extern int sys_chown(); 18 | extern int sys_break(); 19 | extern int sys_stat(); 20 | extern int sys_lseek(); 21 | extern int sys_getpid(); 22 | extern int sys_mount(); 23 | extern int sys_umount(); 24 | extern int sys_setuid(); 25 | extern int sys_getuid(); 26 | extern int sys_stime(); 27 | extern int sys_ptrace(); 28 | extern int sys_alarm(); 29 | extern int sys_fstat(); 30 | extern int sys_pause(); 31 | extern int sys_utime(); 32 | extern int sys_stty(); 33 | extern int sys_gtty(); 34 | extern int sys_access(); 35 | extern int sys_nice(); 36 | extern int sys_ftime(); 37 | extern int sys_sync(); 38 | extern int sys_kill(); 39 | extern int sys_rename(); 40 | extern int sys_mkdir(); 41 | extern int sys_rmdir(); 42 | extern int sys_dup(); 43 | extern int sys_pipe(); 44 | extern int sys_times(); 45 | extern int sys_prof(); 46 | extern int sys_brk(); 47 | extern int sys_setgid(); 48 | extern int sys_getgid(); 49 | extern int sys_signal(); 50 | extern int sys_geteuid(); 51 | extern int sys_getegid(); 52 | extern int sys_acct(); 53 | extern int sys_phys(); 54 | extern int sys_lock(); 55 | extern int sys_ioctl(); 56 | extern int sys_fcntl(); 57 | extern int sys_mpx(); 58 | extern int sys_setpgid(); 59 | extern int sys_ulimit(); 60 | extern int sys_uname(); 61 | extern int sys_umask(); 62 | extern int sys_chroot(); 63 | extern int sys_ustat(); 64 | extern int sys_dup2(); 65 | extern int sys_getppid(); 66 | extern int sys_getpgrp(); 67 | extern int sys_setsid(); 68 | extern int sys_sigaction(); 69 | extern int sys_sgetmask(); 70 | extern int sys_ssetmask(); 71 | extern int sys_setreuid(); 72 | extern int sys_setregid(); 73 | extern int sys_sem_open(); 74 | extern int sys_sem_wait(); 75 | extern int sys_sem_post(); 76 | extern int sys_sem_unlink(); 77 | 78 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 79 | sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link, 80 | sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod, 81 | sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount, 82 | sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm, 83 | sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access, 84 | sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir, 85 | sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid, 86 | sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys, 87 | sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit, 88 | sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid, 89 | sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask, 90 | sys_setreuid,sys_setregid,sys_sem_open,sys_sem_wait,sys_sem_post, 91 | sys_sem_unlink }; 92 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch1.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch2.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/boch3.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/change_ldt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/change_ldt.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/get_free_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/get_free_page.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/malloc_and_free.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/malloc_and_free.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/page.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/page.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/seg_desc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/seg_desc.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/seg_index.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/seg_index.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/share.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/share.jpg -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/README.assets/user_memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/labs/lab_6_memory/README.assets/user_memory.png -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/code/consumer.c: -------------------------------------------------------------------------------- 1 | #define __LIBRARY__ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | _syscall2(sem*,sem_open,const char *,name,unsigned int,value); 9 | _syscall1(int,sem_wait,sem*,sem); 10 | _syscall1(int,sem_post,sem*,sem); 11 | _syscall1(int,sem_unlink,const char *,name); 12 | _syscall1(void*,shmat,int,shmid); 13 | _syscall1(int,shmget,char*,name); 14 | 15 | #define NUMBER 20 /*打出数字总数*/ 16 | #define BUFSIZE 10 /*缓冲区大小*/ 17 | 18 | sem *empty, *full, *mutex; 19 | 20 | int *buffer; 21 | 22 | int init(); 23 | 24 | void clean(); 25 | 26 | int main() 27 | { 28 | int i,data; 29 | int read_index = 0; /*从缓冲区读取位置*/ 30 | 31 | if(!init()) 32 | { 33 | perror("Fail to init!\n"); 34 | return -1; 35 | } 36 | 37 | for( i = 0; i < NUMBER; i++ ) 38 | { 39 | sem_wait(full); 40 | sem_wait(mutex); 41 | 42 | data = buffer[read_index]; 43 | read_index = (read_index + 1) % BUFSIZE; 44 | 45 | sem_post(mutex); 46 | sem_post(empty); 47 | /*消费资源*/ 48 | printf("pid : %d, num: %d\n",getpid(),data); 49 | fflush(stdout); 50 | } 51 | 52 | clean(); 53 | 54 | return 0; 55 | } 56 | 57 | 58 | int init() 59 | { 60 | int shmid; 61 | /*打开信号量*/ 62 | if((mutex = sem_open("carpelamutex",1)) == SEM_FAILED) 63 | { 64 | perror("sem_open() error!\n"); 65 | return -1; 66 | } 67 | if((empty = sem_open("carpelaempty",10)) == SEM_FAILED) 68 | { 69 | perror("sem_open() error!\n"); 70 | return -1; 71 | } 72 | if((full = sem_open("carpelafull",0)) == SEM_FAILED) 73 | { 74 | perror("sem_open() error!\n"); 75 | return -1; 76 | } 77 | 78 | /*打开共享内存*/ 79 | shmid = shmget("buffer"); 80 | if(shmid == -1) 81 | { 82 | return -1; 83 | } 84 | buffer = (int*) shmat(shmid); 85 | } 86 | 87 | void clean() 88 | { 89 | /*释放信号量*/ 90 | sem_unlink("carpelafull"); 91 | sem_unlink("carpelaempty"); 92 | sem_unlink("carpelamutex"); 93 | } 94 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/code/include/linux/sys.h: -------------------------------------------------------------------------------- 1 | extern int sys_setup(); 2 | extern int sys_exit(); 3 | extern int sys_fork(); 4 | extern int sys_read(); 5 | extern int sys_write(); 6 | extern int sys_open(); 7 | extern int sys_close(); 8 | extern int sys_waitpid(); 9 | extern int sys_creat(); 10 | extern int sys_link(); 11 | extern int sys_unlink(); 12 | extern int sys_execve(); 13 | extern int sys_chdir(); 14 | extern int sys_time(); 15 | extern int sys_mknod(); 16 | extern int sys_chmod(); 17 | extern int sys_chown(); 18 | extern int sys_break(); 19 | extern int sys_stat(); 20 | extern int sys_lseek(); 21 | extern int sys_getpid(); 22 | extern int sys_mount(); 23 | extern int sys_umount(); 24 | extern int sys_setuid(); 25 | extern int sys_getuid(); 26 | extern int sys_stime(); 27 | extern int sys_ptrace(); 28 | extern int sys_alarm(); 29 | extern int sys_fstat(); 30 | extern int sys_pause(); 31 | extern int sys_utime(); 32 | extern int sys_stty(); 33 | extern int sys_gtty(); 34 | extern int sys_access(); 35 | extern int sys_nice(); 36 | extern int sys_ftime(); 37 | extern int sys_sync(); 38 | extern int sys_kill(); 39 | extern int sys_rename(); 40 | extern int sys_mkdir(); 41 | extern int sys_rmdir(); 42 | extern int sys_dup(); 43 | extern int sys_pipe(); 44 | extern int sys_times(); 45 | extern int sys_prof(); 46 | extern int sys_brk(); 47 | extern int sys_setgid(); 48 | extern int sys_getgid(); 49 | extern int sys_signal(); 50 | extern int sys_geteuid(); 51 | extern int sys_getegid(); 52 | extern int sys_acct(); 53 | extern int sys_phys(); 54 | extern int sys_lock(); 55 | extern int sys_ioctl(); 56 | extern int sys_fcntl(); 57 | extern int sys_mpx(); 58 | extern int sys_setpgid(); 59 | extern int sys_ulimit(); 60 | extern int sys_uname(); 61 | extern int sys_umask(); 62 | extern int sys_chroot(); 63 | extern int sys_ustat(); 64 | extern int sys_dup2(); 65 | extern int sys_getppid(); 66 | extern int sys_getpgrp(); 67 | extern int sys_setsid(); 68 | extern int sys_sigaction(); 69 | extern int sys_sgetmask(); 70 | extern int sys_ssetmask(); 71 | extern int sys_setreuid(); 72 | extern int sys_setregid(); 73 | extern int sys_sem_open(); 74 | extern int sys_sem_wait(); 75 | extern int sys_sem_post(); 76 | extern int sys_sem_unlink(); 77 | extern int sys_shmget(); 78 | extern void* sys_shmat(); 79 | 80 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 81 | sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link, 82 | sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod, 83 | sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount, 84 | sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm, 85 | sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access, 86 | sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir, 87 | sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid, 88 | sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys, 89 | sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit, 90 | sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid, 91 | sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask, 92 | sys_setreuid,sys_setregid, sys_sem_open, sys_sem_wait, sys_sem_post, 93 | sys_sem_unlink, sys_shmget, sys_shmat }; 94 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/code/kernel/sys_shm.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #define SHM_LIMITED 20 8 | #define SHM_NAME_SIZE_LIMITED 20 9 | 10 | struct share_memory 11 | { 12 | char name[SHM_NAME_SIZE_LIMITED]; 13 | long physic_addr; 14 | int occupied; 15 | } share_mamerys[SHM_LIMITED]; 16 | 17 | int shm_index(char *name_in_kernal) 18 | { 19 | int i; 20 | for(i=0; ibrk 75 | put_page(share_mamerys[shmid].physic_addr,current->brk + current->start_code); 76 | v_addr_start = current->brk; 77 | 78 | // add 4K(size of page) to current->brk 79 | current->brk = current->brk + 4 * 1024L; 80 | 81 | return (void*)v_addr_start; 82 | } 83 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_6_memory/code/producer.c: -------------------------------------------------------------------------------- 1 | #define __LIBRARY__ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | _syscall2(sem*,sem_open,const char *,name,unsigned int,value); 9 | _syscall1(int,sem_wait,sem*,sem); 10 | _syscall1(int,sem_post,sem*,sem); 11 | _syscall1(int,sem_unlink,const char *,name); 12 | _syscall1(void*,shmat,int,shmid); 13 | _syscall1(int,shmget,char*,name); 14 | 15 | #define NUMBER 20 /*打出数字总数*/ 16 | #define BUFSIZE 10 /*缓冲区大小*/ 17 | 18 | sem *empty, *full, *mutex; 19 | 20 | int *buffer; 21 | 22 | int init(); 23 | 24 | void clean(); 25 | 26 | int main() 27 | { 28 | int i; 29 | int write_index = 0; /*写入缓冲区位置*/ 30 | 31 | if(!init()) 32 | { 33 | perror("Fail to init!\n"); 34 | return -1; 35 | } 36 | 37 | /*生产者进程*/ 38 | for( i = 0 ; i < NUMBER; i++) 39 | { 40 | sem_wait(empty); 41 | sem_wait(mutex); 42 | buffer[write_index] = i; 43 | write_index = ( write_index + 1)% BUFSIZE; 44 | sem_post(mutex); 45 | sem_post(full); 46 | } 47 | return 0; 48 | } 49 | 50 | int init() 51 | { 52 | int shmid; 53 | /*打开信号量*/ 54 | if((mutex = sem_open("carpelamutex",1)) == SEM_FAILED) 55 | { 56 | perror("sem_open() error!\n"); 57 | return -1; 58 | } 59 | if((empty = sem_open("carpelaempty",10)) == SEM_FAILED) 60 | { 61 | perror("sem_open() error!\n"); 62 | return -1; 63 | } 64 | if((full = sem_open("carpelafull",0)) == SEM_FAILED) 65 | { 66 | perror("sem_open() error!\n"); 67 | return -1; 68 | } 69 | 70 | /*打开共享内存*/ 71 | shmid = shmget("buffer"); 72 | if(shmid == -1) 73 | { 74 | return -1; 75 | } 76 | buffer = (int*) shmat(shmid); 77 | } 78 | 79 | void clean() 80 | { 81 | /*释放信号量*/ 82 | sem_unlink("carpelafull"); 83 | sem_unlink("carpelaempty"); 84 | sem_unlink("carpelamutex"); 85 | } 86 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_7_device/README.md: -------------------------------------------------------------------------------- 1 | # 终端设备的控制 2 | ## 课程说明 3 | 本实验是 操作系统之外设与文件系统 - 网易云课堂 的配套实验,推荐大家进行实验之前先学习相关课程: 4 | 5 | - L26 I/O 与显示器 6 | - L27 键盘 7 | 8 | > Tips:点击上方文字中的超链接或者输入 https://mooc.study.163.com/course/1000002009#/info 进入理论课程的学习。 如果网易云上的课程无法查看,也可以看 Bilibili 上的 操作系统哈尔滨工业大学李治军老师。 9 | 10 | ## 实验目的 11 | - 加深对操作系统设备管理基本原理的认识,实践键盘中断、扫描码等概念; 12 | - 通过实践掌握 Linux 0.11 对键盘终端和显示器终端的处理过程。 13 | 14 | ## 实验内容 15 | 本实验的基本内容是修改 Linux 0.11 的终端设备处理代码,对键盘输入和字符显示进行非常规的控制。 16 | 17 | 在初始状态,一切如常。用户按一次 F12 后,把应用程序向终端输出所有字母都替换为“*”。用户再按一次 F12,又恢复正常。第三次按 F12,再进行输出替换。依此类推。 18 | 19 | 以 ls 命令为例: 20 | 21 | 正常情况: 22 | ```shell 23 | # ls 24 | hello.c hello.o hello 25 | ``` 26 | 第一次按 F12,然后输入 ls: 27 | ```shell 28 | # ** 29 | *****.* *****.* ***** 30 | ``` 31 | 第二次按 F12,然后输入 ls: 32 | ```shell 33 | # ls 34 | hello.c hello.o hello 35 | ``` 36 | 第三次按 F12,然后输入 ls: 37 | ```shell 38 | # ** 39 | *****.* *****.* ***** 40 | ``` 41 | ## 实验提示 42 | 本实验需要修改 Linux 0.11 的终端设备处理代码(`kernel/chr_drv/console.c` 文件),对键盘输入和字符显示进行非常规的控制。 43 | ### 键盘输入处理过程 44 | 键盘 I/O 是典型的中断驱动,在 `kernel/chr_drv/console.c` 文件中: 45 | ```c 46 | void con_init(void) //控制台的初始化 47 | { 48 | // 键盘中断响应函数设为 keyboard_interrupt 49 | set_trap_gate(0x21, &keyboard_interrupt); 50 | } 51 | ``` 52 | 所以每次按键有动作,`keyboard_interrupt` 函数就会被调用,它在文件 `kernel/chr_drv/keyboard.S`(注意,扩展名是大写的 S)中实现。 53 | 54 | 所有与键盘输入相关的功能都是在此文件中实现的,所以本实验的部分功能也可以在此文件中实现。 55 | 56 | 简单说,`keyboard_interrupt` 被调用后,会将键盘扫描码做为下标,调用数组 `key_table` 保存的与该按键对应的响应函数。 57 | 58 | ### 输出字符的控制 59 | `printf()` 等输出函数最终都是调用 `write()` 系统调用,所以控制好 `write()`,就能控制好输出字符。 60 | 61 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_8_file_system/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_8_file_system/code/fs/proc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define set_bit(bitnr,addr) ({ \ 9 | register int __res ; \ 10 | __asm__("bt %2,%3;setb %%al":"=a" (__res):"a" (0),"r" (bitnr),"m" (*(addr))); \ 11 | __res; }) 12 | 13 | char info_buf[4096] ={'\0'}; 14 | 15 | extern int vsprintf(char * buf, const char * fmt, va_list args); 16 | 17 | int sprintf(char *buf, const char *fmt, ...) 18 | { 19 | va_list args; int i; 20 | va_start(args, fmt); 21 | i=vsprintf(buf, fmt, args); 22 | va_end(args); 23 | return i; 24 | } 25 | 26 | int get_psinfo() 27 | { 28 | int read = 0; 29 | read += sprintf(info_buf+read,"%s","pid\tstate\tfather\tpriority\tcounter\tstart_time\n"); 30 | struct task_struct **p; 31 | for(p = &FIRST_TASK ; p <= &LAST_TASK ; ++p) 32 | if (*p != NULL) 33 | { 34 | read += sprintf(info_buf+read,"%d\t",(*p)->pid); 35 | read += sprintf(info_buf+read,"%d\t",(*p)->state); 36 | read += sprintf(info_buf+read,"%d\t",(*p)->father); 37 | read += sprintf(info_buf+read,"%d\t",(*p)->priority); 38 | read += sprintf(info_buf+read,"%d\t",(*p)->counter); 39 | read += sprintf(info_buf+read,"%d\n",(*p)->start_time); 40 | } 41 | return read; 42 | } 43 | 44 | int proc_read(int dev, unsigned long * pos, char * buf, int count) 45 | { 46 | 47 | int i; 48 | if(*pos == 0) 49 | { 50 | if(dev == 0) 51 | get_psinfo(); 52 | else{ 53 | panic("Unknown dev!"); 54 | } 55 | } 56 | for(i=0;i 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | extern int rw_char(int rw,int dev, char * buf, int count, off_t * pos); 16 | extern int read_pipe(struct m_inode * inode, char * buf, int count); 17 | extern int write_pipe(struct m_inode * inode, char * buf, int count); 18 | extern int block_read(int dev, off_t * pos, char * buf, int count); 19 | extern int block_write(int dev, off_t * pos, char * buf, int count); 20 | extern int file_read(struct m_inode * inode, struct file * filp, 21 | char * buf, int count); 22 | extern int file_write(struct m_inode * inode, struct file * filp, 23 | char * buf, int count); 24 | 25 | int sys_lseek(unsigned int fd,off_t offset, int origin) 26 | { 27 | struct file * file; 28 | int tmp; 29 | 30 | if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode) 31 | || !IS_SEEKABLE(MAJOR(file->f_inode->i_dev))) 32 | return -EBADF; 33 | if (file->f_inode->i_pipe) 34 | return -ESPIPE; 35 | switch (origin) { 36 | case 0: 37 | if (offset<0) return -EINVAL; 38 | file->f_pos=offset; 39 | break; 40 | case 1: 41 | if (file->f_pos+offset<0) return -EINVAL; 42 | file->f_pos += offset; 43 | break; 44 | case 2: 45 | if ((tmp=file->f_inode->i_size+offset) < 0) 46 | return -EINVAL; 47 | file->f_pos = tmp; 48 | break; 49 | default: 50 | return -EINVAL; 51 | } 52 | return file->f_pos; 53 | } 54 | 55 | int sys_read(unsigned int fd,char * buf,int count) 56 | { 57 | struct file * file; 58 | struct m_inode * inode; 59 | 60 | if (fd>=NR_OPEN || count<0 || !(file=current->filp[fd])) 61 | return -EINVAL; 62 | if (!count) 63 | return 0; 64 | verify_area(buf,count); 65 | inode = file->f_inode; 66 | if (inode->i_pipe) 67 | return (file->f_mode&1)?read_pipe(inode,buf,count):-EIO; 68 | if (S_ISCHR(inode->i_mode)) 69 | return rw_char(READ,inode->i_zone[0],buf,count,&file->f_pos); 70 | if (S_ISBLK(inode->i_mode)) 71 | return block_read(inode->i_zone[0],&file->f_pos,buf,count); 72 | if (S_ISPROC(inode->i_mode)) 73 | return proc_read(inode->i_zone[0],&file->f_pos,buf,count); 74 | if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode)) { 75 | if (count+file->f_pos > inode->i_size) 76 | count = inode->i_size - file->f_pos; 77 | if (count<=0) 78 | return 0; 79 | return file_read(inode,file,buf,count); 80 | } 81 | printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode); 82 | return -EINVAL; 83 | } 84 | 85 | int sys_write(unsigned int fd,char * buf,int count) 86 | { 87 | struct file * file; 88 | struct m_inode * inode; 89 | 90 | if (fd>=NR_OPEN || count <0 || !(file=current->filp[fd])) 91 | return -EINVAL; 92 | if (!count) 93 | return 0; 94 | inode=file->f_inode; 95 | if (inode->i_pipe) 96 | return (file->f_mode&2)?write_pipe(inode,buf,count):-EIO; 97 | if (S_ISCHR(inode->i_mode)) 98 | return rw_char(WRITE,inode->i_zone[0],buf,count,&file->f_pos); 99 | if (S_ISBLK(inode->i_mode)) 100 | return block_write(inode->i_zone[0],&file->f_pos,buf,count); 101 | if (S_ISREG(inode->i_mode)) 102 | return file_write(inode,file,buf,count); 103 | printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode); 104 | return -EINVAL; 105 | } 106 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/labs/lab_8_file_system/code/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_STAT_H 2 | #define _SYS_STAT_H 3 | 4 | #include 5 | 6 | struct stat { 7 | dev_t st_dev; 8 | ino_t st_ino; 9 | umode_t st_mode; 10 | nlink_t st_nlink; 11 | uid_t st_uid; 12 | gid_t st_gid; 13 | dev_t st_rdev; 14 | off_t st_size; 15 | time_t st_atime; 16 | time_t st_mtime; 17 | time_t st_ctime; 18 | }; 19 | 20 | #define S_IFMT 00170000 21 | #define S_IFREG 0100000 22 | #define S_IFBLK 0060000 23 | #define S_IFDIR 0040000 24 | #define S_IFPROC 0030000 25 | #define S_IFCHR 0020000 26 | #define S_IFIFO 0010000 27 | #define S_ISUID 0004000 28 | #define S_ISGID 0002000 29 | #define S_ISVTX 0001000 30 | 31 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 32 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 33 | #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 34 | #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 35 | #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 36 | #define S_ISPROC(m) (((m) & S_IFMT) == S_IFPROC) 37 | 38 | #define S_IRWXU 00700 39 | #define S_IRUSR 00400 40 | #define S_IWUSR 00200 41 | #define S_IXUSR 00100 42 | 43 | #define S_IRWXG 00070 44 | #define S_IRGRP 00040 45 | #define S_IWGRP 00020 46 | #define S_IXGRP 00010 47 | 48 | #define S_IRWXO 00007 49 | #define S_IROTH 00004 50 | #define S_IWOTH 00002 51 | #define S_IXOTH 00001 52 | 53 | extern int chmod(const char *_path, mode_t mode); 54 | extern int fstat(int fildes, struct stat *stat_buf); 55 | extern int mkdir(const char *_path, mode_t mode); 56 | extern int mkfifo(const char *_path, mode_t mode); 57 | extern int stat(const char *filename, struct stat *stat_buf); 58 | extern mode_t umask(mode_t mask); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/block_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/block_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int block_write(int dev, long * pos, char * buf, int count) 15 | { 16 | int block = *pos >> BLOCK_SIZE_BITS; 17 | int offset = *pos & (BLOCK_SIZE-1); 18 | int chars; 19 | int written = 0; 20 | struct buffer_head * bh; 21 | register char * p; 22 | 23 | while (count>0) { 24 | chars = BLOCK_SIZE - offset; 25 | if (chars > count) 26 | chars=count; 27 | if (chars == BLOCK_SIZE) 28 | bh = getblk(dev,block); 29 | else 30 | bh = breada(dev,block,block+1,block+2,-1); 31 | block++; 32 | if (!bh) 33 | return written?written:-EIO; 34 | p = offset + bh->b_data; 35 | offset = 0; 36 | *pos += chars; 37 | written += chars; 38 | count -= chars; 39 | while (chars-->0) 40 | *(p++) = get_fs_byte(buf++); 41 | bh->b_dirt = 1; 42 | brelse(bh); 43 | } 44 | return written; 45 | } 46 | 47 | int block_read(int dev, unsigned long * pos, char * buf, int count) 48 | { 49 | int block = *pos >> BLOCK_SIZE_BITS; 50 | int offset = *pos & (BLOCK_SIZE-1); 51 | int chars; 52 | int read = 0; 53 | struct buffer_head * bh; 54 | register char * p; 55 | 56 | while (count>0) { 57 | chars = BLOCK_SIZE-offset; 58 | if (chars > count) 59 | chars = count; 60 | if (!(bh = breada(dev,block,block+1,block+2,-1))) 61 | return read?read:-EIO; 62 | block++; 63 | p = offset + bh->b_data; 64 | offset = 0; 65 | *pos += chars; 66 | read += chars; 67 | count -= chars; 68 | while (chars-->0) 69 | put_fs_byte(*(p++),buf++); 70 | brelse(bh); 71 | } 72 | return read; 73 | } 74 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/char_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/char_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | extern int tty_read(unsigned minor,char * buf,int count); 17 | extern int tty_write(unsigned minor,char * buf,int count); 18 | 19 | typedef int (*crw_ptr)(int rw,unsigned minor,char * buf,int count,off_t * pos); 20 | 21 | static int rw_ttyx(int rw,unsigned minor,char * buf,int count,off_t * pos) 22 | { 23 | return ((rw==READ)?tty_read(minor,buf,count): 24 | tty_write(minor,buf,count)); 25 | } 26 | 27 | static int rw_tty(int rw,unsigned minor,char * buf,int count, off_t * pos) 28 | { 29 | if (current->tty<0) 30 | return -EPERM; 31 | return rw_ttyx(rw,current->tty,buf,count,pos); 32 | } 33 | 34 | static int rw_ram(int rw,char * buf, int count, off_t *pos) 35 | { 36 | return -EIO; 37 | } 38 | 39 | static int rw_mem(int rw,char * buf, int count, off_t * pos) 40 | { 41 | return -EIO; 42 | } 43 | 44 | static int rw_kmem(int rw,char * buf, int count, off_t * pos) 45 | { 46 | return -EIO; 47 | } 48 | 49 | static int rw_port(int rw,char * buf, int count, off_t * pos) 50 | { 51 | int i=*pos; 52 | 53 | while (count-->0 && i<65536) { 54 | if (rw==READ) 55 | put_fs_byte(inb(i),buf++); 56 | else 57 | outb(get_fs_byte(buf++),i); 58 | i++; 59 | } 60 | i -= *pos; 61 | *pos += i; 62 | return i; 63 | } 64 | 65 | static int rw_memory(int rw, unsigned minor, char * buf, int count, off_t * pos) 66 | { 67 | switch(minor) { 68 | case 0: 69 | return rw_ram(rw,buf,count,pos); 70 | case 1: 71 | return rw_mem(rw,buf,count,pos); 72 | case 2: 73 | return rw_kmem(rw,buf,count,pos); 74 | case 3: 75 | return (rw==READ)?0:count; /* rw_null */ 76 | case 4: 77 | return rw_port(rw,buf,count,pos); 78 | default: 79 | return -EIO; 80 | } 81 | } 82 | 83 | #define NRDEVS ((sizeof (crw_table))/(sizeof (crw_ptr))) 84 | 85 | static crw_ptr crw_table[]={ 86 | NULL, /* nodev */ 87 | rw_memory, /* /dev/mem etc */ 88 | NULL, /* /dev/fd */ 89 | NULL, /* /dev/hd */ 90 | rw_ttyx, /* /dev/ttyx */ 91 | rw_tty, /* /dev/tty */ 92 | NULL, /* /dev/lp */ 93 | NULL}; /* unnamed pipes */ 94 | 95 | int rw_char(int rw,int dev, char * buf, int count, off_t * pos) 96 | { 97 | crw_ptr call_addr; 98 | 99 | if (MAJOR(dev)>=NRDEVS) 100 | return -ENODEV; 101 | if (!(call_addr=crw_table[MAJOR(dev)])) 102 | return -ENODEV; 103 | return call_addr(rw,MINOR(dev),buf,count,pos); 104 | } 105 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/fcntl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/fcntl.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* #include */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | 16 | extern int sys_close(int fd); 17 | 18 | static int dupfd(unsigned int fd, unsigned int arg) 19 | { 20 | if (fd >= NR_OPEN || !current->filp[fd]) 21 | return -EBADF; 22 | if (arg >= NR_OPEN) 23 | return -EINVAL; 24 | while (arg < NR_OPEN) 25 | if (current->filp[arg]) 26 | arg++; 27 | else 28 | break; 29 | if (arg >= NR_OPEN) 30 | return -EMFILE; 31 | current->close_on_exec &= ~(1<filp[arg] = current->filp[fd])->f_count++; 33 | return arg; 34 | } 35 | 36 | int sys_dup2(unsigned int oldfd, unsigned int newfd) 37 | { 38 | sys_close(newfd); 39 | return dupfd(oldfd,newfd); 40 | } 41 | 42 | int sys_dup(unsigned int fildes) 43 | { 44 | return dupfd(fildes,0); 45 | } 46 | 47 | int sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) 48 | { 49 | struct file * filp; 50 | 51 | if (fd >= NR_OPEN || !(filp = current->filp[fd])) 52 | return -EBADF; 53 | switch (cmd) { 54 | case F_DUPFD: 55 | return dupfd(fd,arg); 56 | case F_GETFD: 57 | return (current->close_on_exec>>fd)&1; 58 | case F_SETFD: 59 | if (arg&1) 60 | current->close_on_exec |= (1<close_on_exec &= ~(1<f_flags; 66 | case F_SETFL: 67 | filp->f_flags &= ~(O_APPEND | O_NONBLOCK); 68 | filp->f_flags |= arg & (O_APPEND | O_NONBLOCK); 69 | return 0; 70 | case F_GETLK: case F_SETLK: case F_SETLKW: 71 | return -1; 72 | default: 73 | return -1; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/file_dev.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/file_dev.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #define MIN(a,b) (((a)<(b))?(a):(b)) 15 | #define MAX(a,b) (((a)>(b))?(a):(b)) 16 | 17 | int file_read(struct m_inode * inode, struct file * filp, char * buf, int count) 18 | { 19 | int left,chars,nr; 20 | struct buffer_head * bh; 21 | 22 | if ((left=count)<=0) 23 | return 0; 24 | while (left) { 25 | if ((nr = bmap(inode,(filp->f_pos)/BLOCK_SIZE))) { 26 | if (!(bh=bread(inode->i_dev,nr))) 27 | break; 28 | } else 29 | bh = NULL; 30 | nr = filp->f_pos % BLOCK_SIZE; 31 | chars = MIN( BLOCK_SIZE-nr , left ); 32 | filp->f_pos += chars; 33 | left -= chars; 34 | if (bh) { 35 | char * p = nr + bh->b_data; 36 | while (chars-->0) 37 | put_fs_byte(*(p++),buf++); 38 | brelse(bh); 39 | } else { 40 | while (chars-->0) 41 | put_fs_byte(0,buf++); 42 | } 43 | } 44 | inode->i_atime = CURRENT_TIME; 45 | return (count-left)?(count-left):-ERROR; 46 | } 47 | 48 | int file_write(struct m_inode * inode, struct file * filp, char * buf, int count) 49 | { 50 | off_t pos; 51 | int block,c; 52 | struct buffer_head * bh; 53 | char * p; 54 | int i=0; 55 | 56 | /* 57 | * ok, append may not work when many processes are writing at the same time 58 | * but so what. That way leads to madness anyway. 59 | */ 60 | if (filp->f_flags & O_APPEND) 61 | pos = inode->i_size; 62 | else 63 | pos = filp->f_pos; 64 | while (ii_dev,block))) 68 | break; 69 | c = pos % BLOCK_SIZE; 70 | p = c + bh->b_data; 71 | bh->b_dirt = 1; 72 | c = BLOCK_SIZE-c; 73 | if (c > count-i) c = count-i; 74 | pos += c; 75 | if (pos > inode->i_size) { 76 | inode->i_size = pos; 77 | inode->i_dirt = 1; 78 | } 79 | i += c; 80 | while (c-->0) 81 | *(p++) = get_fs_byte(buf++); 82 | brelse(bh); 83 | } 84 | inode->i_mtime = CURRENT_TIME; 85 | if (!(filp->f_flags & O_APPEND)) { 86 | filp->f_pos = pos; 87 | inode->i_ctime = CURRENT_TIME; 88 | } 89 | return (i?i:-1); 90 | } 91 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/file_table.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/file_table.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | struct file file_table[NR_FILE]; 10 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/ioctl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/ioctl.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* #include */ 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | extern int tty_ioctl(int dev, int cmd, int arg); 14 | 15 | typedef int (*ioctl_ptr)(int dev,int cmd,int arg); 16 | 17 | #define NRDEVS ((sizeof (ioctl_table))/(sizeof (ioctl_ptr))) 18 | 19 | static ioctl_ptr ioctl_table[]={ 20 | NULL, /* nodev */ 21 | NULL, /* /dev/mem */ 22 | NULL, /* /dev/fd */ 23 | NULL, /* /dev/hd */ 24 | tty_ioctl, /* /dev/ttyx */ 25 | tty_ioctl, /* /dev/tty */ 26 | NULL, /* /dev/lp */ 27 | NULL}; /* named pipes */ 28 | 29 | 30 | int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg) 31 | { 32 | struct file * filp; 33 | int dev,mode; 34 | 35 | if (fd >= NR_OPEN || !(filp = current->filp[fd])) 36 | return -EBADF; 37 | mode=filp->f_inode->i_mode; 38 | if (!S_ISCHR(mode) && !S_ISBLK(mode)) 39 | return -EINVAL; 40 | dev = filp->f_inode->i_zone[0]; 41 | if (MAJOR(dev) >= NRDEVS) 42 | return -ENODEV; 43 | if (!ioctl_table[MAJOR(dev)]) 44 | return -ENOTTY; 45 | return ioctl_table[MAJOR(dev)](dev,cmd,arg); 46 | } 47 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/pipe.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/pipe.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include /* for get_free_page */ 11 | #include 12 | 13 | int read_pipe(struct m_inode * inode, char * buf, int count) 14 | { 15 | int chars, size, read = 0; 16 | 17 | while (count>0) { 18 | while (!(size=PIPE_SIZE(*inode))) { 19 | wake_up(&inode->i_wait); 20 | if (inode->i_count != 2) /* are there any writers? */ 21 | return read; 22 | sleep_on(&inode->i_wait); 23 | } 24 | chars = PAGE_SIZE-PIPE_TAIL(*inode); 25 | if (chars > count) 26 | chars = count; 27 | if (chars > size) 28 | chars = size; 29 | count -= chars; 30 | read += chars; 31 | size = PIPE_TAIL(*inode); 32 | PIPE_TAIL(*inode) += chars; 33 | PIPE_TAIL(*inode) &= (PAGE_SIZE-1); 34 | while (chars-->0) 35 | put_fs_byte(((char *)inode->i_size)[size++],buf++); 36 | } 37 | wake_up(&inode->i_wait); 38 | return read; 39 | } 40 | 41 | int write_pipe(struct m_inode * inode, char * buf, int count) 42 | { 43 | int chars, size, written = 0; 44 | 45 | while (count>0) { 46 | while (!(size=(PAGE_SIZE-1)-PIPE_SIZE(*inode))) { 47 | wake_up(&inode->i_wait); 48 | if (inode->i_count != 2) { /* no readers */ 49 | current->signal |= (1<<(SIGPIPE-1)); 50 | return written?written:-1; 51 | } 52 | sleep_on(&inode->i_wait); 53 | } 54 | chars = PAGE_SIZE-PIPE_HEAD(*inode); 55 | if (chars > count) 56 | chars = count; 57 | if (chars > size) 58 | chars = size; 59 | count -= chars; 60 | written += chars; 61 | size = PIPE_HEAD(*inode); 62 | PIPE_HEAD(*inode) += chars; 63 | PIPE_HEAD(*inode) &= (PAGE_SIZE-1); 64 | while (chars-->0) 65 | ((char *)inode->i_size)[size++]=get_fs_byte(buf++); 66 | } 67 | wake_up(&inode->i_wait); 68 | return written; 69 | } 70 | 71 | int sys_pipe(unsigned long * fildes) 72 | { 73 | struct m_inode * inode; 74 | struct file * f[2]; 75 | int fd[2]; 76 | int i,j; 77 | 78 | j=0; 79 | for(i=0;j<2 && if_count++; 82 | if (j==1) 83 | f[0]->f_count=0; 84 | if (j<2) 85 | return -1; 86 | j=0; 87 | for(i=0;j<2 && ifilp[i]) { 89 | current->filp[ fd[j]=i ] = f[j]; 90 | j++; 91 | } 92 | if (j==1) 93 | current->filp[fd[0]]=NULL; 94 | if (j<2) { 95 | f[0]->f_count=f[1]->f_count=0; 96 | return -1; 97 | } 98 | if (!(inode=get_pipe_inode())) { 99 | current->filp[fd[0]] = 100 | current->filp[fd[1]] = NULL; 101 | f[0]->f_count = f[1]->f_count = 0; 102 | return -1; 103 | } 104 | f[0]->f_inode = f[1]->f_inode = inode; 105 | f[0]->f_pos = f[1]->f_pos = 0; 106 | f[0]->f_mode = 1; /* read */ 107 | f[1]->f_mode = 2; /* write */ 108 | put_fs_long(fd[0],0+fildes); 109 | put_fs_long(fd[1],1+fildes); 110 | return 0; 111 | } 112 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/read_write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/read_write.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | extern int rw_char(int rw,int dev, char * buf, int count, off_t * pos); 16 | extern int read_pipe(struct m_inode * inode, char * buf, int count); 17 | extern int write_pipe(struct m_inode * inode, char * buf, int count); 18 | extern int block_read(int dev, off_t * pos, char * buf, int count); 19 | extern int block_write(int dev, off_t * pos, char * buf, int count); 20 | extern int file_read(struct m_inode * inode, struct file * filp, 21 | char * buf, int count); 22 | extern int file_write(struct m_inode * inode, struct file * filp, 23 | char * buf, int count); 24 | 25 | int sys_lseek(unsigned int fd,off_t offset, int origin) 26 | { 27 | struct file * file; 28 | int tmp; 29 | 30 | if (fd >= NR_OPEN || !(file=current->filp[fd]) || !(file->f_inode) 31 | || !IS_SEEKABLE(MAJOR(file->f_inode->i_dev))) 32 | return -EBADF; 33 | if (file->f_inode->i_pipe) 34 | return -ESPIPE; 35 | switch (origin) { 36 | case 0: 37 | if (offset<0) return -EINVAL; 38 | file->f_pos=offset; 39 | break; 40 | case 1: 41 | if (file->f_pos+offset<0) return -EINVAL; 42 | file->f_pos += offset; 43 | break; 44 | case 2: 45 | if ((tmp=file->f_inode->i_size+offset) < 0) 46 | return -EINVAL; 47 | file->f_pos = tmp; 48 | break; 49 | default: 50 | return -EINVAL; 51 | } 52 | return file->f_pos; 53 | } 54 | 55 | int sys_read(unsigned int fd,char * buf,int count) 56 | { 57 | struct file * file; 58 | struct m_inode * inode; 59 | 60 | if (fd>=NR_OPEN || count<0 || !(file=current->filp[fd])) 61 | return -EINVAL; 62 | if (!count) 63 | return 0; 64 | verify_area(buf,count); 65 | inode = file->f_inode; 66 | if (inode->i_pipe) 67 | return (file->f_mode&1)?read_pipe(inode,buf,count):-EIO; 68 | if (S_ISCHR(inode->i_mode)) 69 | return rw_char(READ,inode->i_zone[0],buf,count,&file->f_pos); 70 | if (S_ISBLK(inode->i_mode)) 71 | return block_read(inode->i_zone[0],&file->f_pos,buf,count); 72 | if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode)) { 73 | if (count+file->f_pos > inode->i_size) 74 | count = inode->i_size - file->f_pos; 75 | if (count<=0) 76 | return 0; 77 | return file_read(inode,file,buf,count); 78 | } 79 | printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode); 80 | return -EINVAL; 81 | } 82 | 83 | int sys_write(unsigned int fd,char * buf,int count) 84 | { 85 | struct file * file; 86 | struct m_inode * inode; 87 | 88 | if (fd>=NR_OPEN || count <0 || !(file=current->filp[fd])) 89 | return -EINVAL; 90 | if (!count) 91 | return 0; 92 | inode=file->f_inode; 93 | if (inode->i_pipe) 94 | return (file->f_mode&2)?write_pipe(inode,buf,count):-EIO; 95 | if (S_ISCHR(inode->i_mode)) 96 | return rw_char(WRITE,inode->i_zone[0],buf,count,&file->f_pos); 97 | if (S_ISBLK(inode->i_mode)) 98 | return block_write(inode->i_zone[0],&file->f_pos,buf,count); 99 | if (S_ISREG(inode->i_mode)) 100 | return file_write(inode,file,buf,count); 101 | printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode); 102 | return -EINVAL; 103 | } 104 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/stat.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/stat.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | static void cp_stat(struct m_inode * inode, struct stat * statbuf) 16 | { 17 | struct stat tmp; 18 | int i; 19 | 20 | verify_area(statbuf,sizeof (* statbuf)); 21 | tmp.st_dev = inode->i_dev; 22 | tmp.st_ino = inode->i_num; 23 | tmp.st_mode = inode->i_mode; 24 | tmp.st_nlink = inode->i_nlinks; 25 | tmp.st_uid = inode->i_uid; 26 | tmp.st_gid = inode->i_gid; 27 | tmp.st_rdev = inode->i_zone[0]; 28 | tmp.st_size = inode->i_size; 29 | tmp.st_atime = inode->i_atime; 30 | tmp.st_mtime = inode->i_mtime; 31 | tmp.st_ctime = inode->i_ctime; 32 | for (i=0 ; i= NR_OPEN || !(f=current->filp[fd]) || !(inode=f->f_inode)) 53 | return -EBADF; 54 | cp_stat(inode,statbuf); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/fs/truncate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/fs/truncate.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | 11 | static void free_ind(int dev,int block) 12 | { 13 | struct buffer_head * bh; 14 | unsigned short * p; 15 | int i; 16 | 17 | if (!block) 18 | return; 19 | if ((bh=bread(dev,block))) { 20 | p = (unsigned short *) bh->b_data; 21 | for (i=0;i<512;i++,p++) 22 | if (*p) 23 | free_block(dev,*p); 24 | brelse(bh); 25 | } 26 | free_block(dev,block); 27 | } 28 | 29 | static void free_dind(int dev,int block) 30 | { 31 | struct buffer_head * bh; 32 | unsigned short * p; 33 | int i; 34 | 35 | if (!block) 36 | return; 37 | if ((bh=bread(dev,block))) { 38 | p = (unsigned short *) bh->b_data; 39 | for (i=0;i<512;i++,p++) 40 | if (*p) 41 | free_ind(dev,*p); 42 | brelse(bh); 43 | } 44 | free_block(dev,block); 45 | } 46 | 47 | void truncate(struct m_inode * inode) 48 | { 49 | int i; 50 | 51 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode))) 52 | return; 53 | for (i=0;i<7;i++) 54 | if (inode->i_zone[i]) { 55 | free_block(inode->i_dev,inode->i_zone[i]); 56 | inode->i_zone[i]=0; 57 | } 58 | free_ind(inode->i_dev,inode->i_zone[7]); 59 | free_dind(inode->i_dev,inode->i_zone[8]); 60 | inode->i_zone[7] = inode->i_zone[8] = 0; 61 | inode->i_size = 0; 62 | inode->i_dirt = 1; 63 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/asm/io.h: -------------------------------------------------------------------------------- 1 | #define outb(value,port) \ 2 | __asm__ ("outb %%al,%%dx"::"a" (value),"d" (port)) 3 | 4 | 5 | #define inb(port) ({ \ 6 | unsigned char _v; \ 7 | __asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \ 8 | _v; \ 9 | }) 10 | 11 | #define outb_p(value,port) \ 12 | __asm__ ("outb %%al,%%dx\n" \ 13 | "\tjmp 1f\n" \ 14 | "1:\tjmp 1f\n" \ 15 | "1:"::"a" (value),"d" (port)) 16 | 17 | #define inb_p(port) ({ \ 18 | unsigned char _v; \ 19 | __asm__ volatile ("inb %%dx,%%al\n" \ 20 | "\tjmp 1f\n" \ 21 | "1:\tjmp 1f\n" \ 22 | "1:":"=a" (_v):"d" (port)); \ 23 | _v; \ 24 | }) 25 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/asm/memory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * NOTE!!! memcpy(dest,src,n) assumes ds=es=normal data segment. This 3 | * goes for all kernel functions (ds=es=kernel space, fs=local data, 4 | * gs=null), as well as for all well-behaving user programs (ds=es= 5 | * user data space). This is NOT a bug, as any user program that changes 6 | * es deserves to die if it isn't careful. 7 | */ 8 | #define memcpy(dest,src,n) ({ \ 9 | void * _res = dest; \ 10 | __asm__ ("cld;rep;movsb" \ 11 | ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \ 12 | ); \ 13 | _res; \ 14 | }) 15 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/asm/segment.h: -------------------------------------------------------------------------------- 1 | static inline unsigned char get_fs_byte(const char * addr) 2 | { 3 | unsigned register char _v; 4 | 5 | __asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr)); 6 | return _v; 7 | } 8 | 9 | static inline unsigned short get_fs_word(const unsigned short *addr) 10 | { 11 | unsigned short _v; 12 | 13 | __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr)); 14 | return _v; 15 | } 16 | 17 | static inline unsigned long get_fs_long(const unsigned long *addr) 18 | { 19 | unsigned long _v; 20 | 21 | __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \ 22 | return _v; 23 | } 24 | 25 | static inline void put_fs_byte(char val,char *addr) 26 | { 27 | __asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr)); 28 | } 29 | 30 | static inline void put_fs_word(short val,short * addr) 31 | { 32 | __asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr)); 33 | } 34 | 35 | static inline void put_fs_long(unsigned long val,unsigned long * addr) 36 | { 37 | __asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr)); 38 | } 39 | 40 | /* 41 | * Someone who knows GNU asm better than I should double check the followig. 42 | * It seems to work, but I don't know if I'm doing something subtly wrong. 43 | * --- TYT, 11/24/91 44 | * [ nothing wrong here, Linus ] 45 | */ 46 | 47 | static inline unsigned long get_fs() 48 | { 49 | unsigned short _v; 50 | __asm__("mov %%fs,%%ax":"=a" (_v):); 51 | return _v; 52 | } 53 | 54 | static inline unsigned long get_ds() 55 | { 56 | unsigned short _v; 57 | __asm__("mov %%ds,%%ax":"=a" (_v):); 58 | return _v; 59 | } 60 | 61 | static inline void set_fs(unsigned long val) 62 | { 63 | __asm__("mov %0,%%fs"::"a" ((unsigned short) val)); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/asm/system.h: -------------------------------------------------------------------------------- 1 | #define move_to_user_mode() \ 2 | __asm__ ("movl %%esp,%%eax\n\t" \ 3 | "pushl $0x17\n\t" \ 4 | "pushl %%eax\n\t" \ 5 | "pushfl\n\t" \ 6 | "pushl $0x0f\n\t" \ 7 | "pushl $1f\n\t" \ 8 | "iret\n" \ 9 | "1:\tmovl $0x17,%%eax\n\t" \ 10 | "movw %%ax,%%ds\n\t" \ 11 | "movw %%ax,%%es\n\t" \ 12 | "movw %%ax,%%fs\n\t" \ 13 | "movw %%ax,%%gs" \ 14 | :::"ax") 15 | 16 | #define sti() __asm__ ("sti"::) 17 | #define cli() __asm__ ("cli"::) 18 | #define nop() __asm__ ("nop"::) 19 | 20 | #define iret() __asm__ ("iret"::) 21 | 22 | #define _set_gate(gate_addr,type,dpl,addr) \ 23 | __asm__ ("movw %%dx,%%ax\n\t" \ 24 | "movw %0,%%dx\n\t" \ 25 | "movl %%eax,%1\n\t" \ 26 | "movl %%edx,%2" \ 27 | : \ 28 | : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \ 29 | "o" (*((char *) (gate_addr))), \ 30 | "o" (*(4+(char *) (gate_addr))), \ 31 | "d" ((char *) (addr)),"a" (0x00080000)) 32 | 33 | #define set_intr_gate(n,addr) \ 34 | _set_gate(&idt[n],14,0,addr) 35 | 36 | #define set_trap_gate(n,addr) \ 37 | _set_gate(&idt[n],15,0,addr) 38 | 39 | #define set_system_gate(n,addr) \ 40 | _set_gate(&idt[n],15,3,addr) 41 | 42 | #define _set_seg_desc(gate_addr,type,dpl,base,limit) {\ 43 | *(gate_addr) = ((base) & 0xff000000) | \ 44 | (((base) & 0x00ff0000)>>16) | \ 45 | ((limit) & 0xf0000) | \ 46 | ((dpl)<<13) | \ 47 | (0x00408000) | \ 48 | ((type)<<8); \ 49 | *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \ 50 | ((limit) & 0x0ffff); } 51 | 52 | #define _set_tssldt_desc(n,addr,type) \ 53 | __asm__ ("movw $104,%1\n\t" \ 54 | "movw %%ax,%2\n\t" \ 55 | "rorl $16,%%eax\n\t" \ 56 | "movb %%al,%3\n\t" \ 57 | "movb $" type ",%4\n\t" \ 58 | "movb $0x00,%5\n\t" \ 59 | "movb %%ah,%6\n\t" \ 60 | "rorl $16,%%eax" \ 61 | ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \ 62 | "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \ 63 | ) 64 | 65 | #define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x89") 66 | #define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x82") 67 | 68 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/const.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONST_H 2 | #define _CONST_H 3 | 4 | #define BUFFER_END 0x200000 5 | 6 | #define I_TYPE 0170000 7 | #define I_DIRECTORY 0040000 8 | #define I_REGULAR 0100000 9 | #define I_BLOCK_SPECIAL 0060000 10 | #define I_CHAR_SPECIAL 0020000 11 | #define I_NAMED_PIPE 0010000 12 | #define I_SET_UID_BIT 0004000 13 | #define I_SET_GID_BIT 0002000 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/ctype.h: -------------------------------------------------------------------------------- 1 | #ifndef _CTYPE_H 2 | #define _CTYPE_H 3 | 4 | #define _U 0x01 /* upper */ 5 | #define _L 0x02 /* lower */ 6 | #define _D 0x04 /* digit */ 7 | #define _C 0x08 /* cntrl */ 8 | #define _P 0x10 /* punct */ 9 | #define _S 0x20 /* white space (space/lf/tab) */ 10 | #define _X 0x40 /* hex digit */ 11 | #define _SP 0x80 /* hard space (0x20) */ 12 | 13 | extern unsigned char _ctype[]; 14 | extern char _ctmp; 15 | 16 | #define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D)) 17 | #define isalpha(c) ((_ctype+1)[c]&(_U|_L)) 18 | #define iscntrl(c) ((_ctype+1)[c]&(_C)) 19 | #define isdigit(c) ((_ctype+1)[c]&(_D)) 20 | #define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D)) 21 | #define islower(c) ((_ctype+1)[c]&(_L)) 22 | #define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP)) 23 | #define ispunct(c) ((_ctype+1)[c]&(_P)) 24 | #define isspace(c) ((_ctype+1)[c]&(_S)) 25 | #define isupper(c) ((_ctype+1)[c]&(_U)) 26 | #define isxdigit(c) ((_ctype+1)[c]&(_D|_X)) 27 | 28 | #define isascii(c) (((unsigned) c)<=0x7f) 29 | #define toascii(c) (((unsigned) c)&0x7f) 30 | 31 | #define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp) 32 | #define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp) 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/errno.h: -------------------------------------------------------------------------------- 1 | #ifndef _ERRNO_H 2 | #define _ERRNO_H 3 | 4 | /* 5 | * ok, as I hadn't got any other source of information about 6 | * possible error numbers, I was forced to use the same numbers 7 | * as minix. 8 | * Hopefully these are posix or something. I wouldn't know (and posix 9 | * isn't telling me - they want $$$ for their f***ing standard). 10 | * 11 | * We don't use the _SIGN cludge of minix, so kernel returns must 12 | * see to the sign by themselves. 13 | * 14 | * NOTE! Remember to change strerror() if you change this file! 15 | */ 16 | 17 | extern int errno; 18 | 19 | #define ERROR 99 20 | #define EPERM 1 21 | #define ENOENT 2 22 | #define ESRCH 3 23 | #define EINTR 4 24 | #define EIO 5 25 | #define ENXIO 6 26 | #define E2BIG 7 27 | #define ENOEXEC 8 28 | #define EBADF 9 29 | #define ECHILD 10 30 | #define EAGAIN 11 31 | #define ENOMEM 12 32 | #define EACCES 13 33 | #define EFAULT 14 34 | #define ENOTBLK 15 35 | #define EBUSY 16 36 | #define EEXIST 17 37 | #define EXDEV 18 38 | #define ENODEV 19 39 | #define ENOTDIR 20 40 | #define EISDIR 21 41 | #define EINVAL 22 42 | #define ENFILE 23 43 | #define EMFILE 24 44 | #define ENOTTY 25 45 | #define ETXTBSY 26 46 | #define EFBIG 27 47 | #define ENOSPC 28 48 | #define ESPIPE 29 49 | #define EROFS 30 50 | #define EMLINK 31 51 | #define EPIPE 32 52 | #define EDOM 33 53 | #define ERANGE 34 54 | #define EDEADLK 35 55 | #define ENAMETOOLONG 36 56 | #define ENOLCK 37 57 | #define ENOSYS 38 58 | #define ENOTEMPTY 39 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/fcntl.h: -------------------------------------------------------------------------------- 1 | #ifndef _FCNTL_H 2 | #define _FCNTL_H 3 | 4 | #include 5 | 6 | /* open/fcntl - NOCTTY, NDELAY isn't implemented yet */ 7 | #define O_ACCMODE 00003 8 | #define O_RDONLY 00 9 | #define O_WRONLY 01 10 | #define O_RDWR 02 11 | #define O_CREAT 00100 /* not fcntl */ 12 | #define O_EXCL 00200 /* not fcntl */ 13 | #define O_NOCTTY 00400 /* not fcntl */ 14 | #define O_TRUNC 01000 /* not fcntl */ 15 | #define O_APPEND 02000 16 | #define O_NONBLOCK 04000 /* not fcntl */ 17 | #define O_NDELAY O_NONBLOCK 18 | 19 | /* Defines for fcntl-commands. Note that currently 20 | * locking isn't supported, and other things aren't really 21 | * tested. 22 | */ 23 | #define F_DUPFD 0 /* dup */ 24 | #define F_GETFD 1 /* get f_flags */ 25 | #define F_SETFD 2 /* set f_flags */ 26 | #define F_GETFL 3 /* more flags (cloexec) */ 27 | #define F_SETFL 4 28 | #define F_GETLK 5 /* not implemented */ 29 | #define F_SETLK 6 30 | #define F_SETLKW 7 31 | 32 | /* for F_[GET|SET]FL */ 33 | #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ 34 | 35 | /* Ok, these are locking features, and aren't implemented at any 36 | * level. POSIX wants them. 37 | */ 38 | #define F_RDLCK 0 39 | #define F_WRLCK 1 40 | #define F_UNLCK 2 41 | 42 | /* Once again - not implemented, but ... */ 43 | struct flock { 44 | short l_type; 45 | short l_whence; 46 | off_t l_start; 47 | off_t l_len; 48 | pid_t l_pid; 49 | }; 50 | 51 | extern int creat(const char * filename,mode_t mode); 52 | extern int fcntl(int fildes,int cmd, ...); 53 | extern int open(const char * filename, int flags, ...); 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/config.h: -------------------------------------------------------------------------------- 1 | #ifndef _CONFIG_H 2 | #define _CONFIG_H 3 | 4 | /* 5 | * The root-device is no longer hard-coded. You can change the default 6 | * root-device by changing the line ROOT_DEV = XXX in boot/bootsect.s 7 | */ 8 | 9 | /* 10 | * define your keyboard here - 11 | * KBD_FINNISH for Finnish keyboards 12 | * KBD_US for US-type 13 | * KBD_GR for German keyboards 14 | * KBD_FR for Frech keyboard 15 | */ 16 | #define KBD_US 17 | /*#define KBD_GR */ 18 | /*#define KBD_FR */ 19 | /*#define KBD_FINNISH */ 20 | 21 | /* 22 | * Normally, Linux can get the drive parameters from the BIOS at 23 | * startup, but if this for some unfathomable reason fails, you'd 24 | * be left stranded. For this case, you can define HD_TYPE, which 25 | * contains all necessary info on your harddisk. 26 | * 27 | * The HD_TYPE macro should look like this: 28 | * 29 | * #define HD_TYPE { head, sect, cyl, wpcom, lzone, ctl} 30 | * 31 | * In case of two harddisks, the info should be sepatated by 32 | * commas: 33 | * 34 | * #define HD_TYPE { h,s,c,wpcom,lz,ctl },{ h,s,c,wpcom,lz,ctl } 35 | */ 36 | /* 37 | This is an example, two drives, first is type 2, second is type 3: 38 | 39 | #define HD_TYPE { 4,17,615,300,615,8 }, { 6,17,615,300,615,0 } 40 | 41 | NOTE: ctl is 0 for all drives with heads<=8, and ctl=8 for drives 42 | with more than 8 heads. 43 | 44 | If you want the BIOS to tell what kind of drive you have, just 45 | leave HD_TYPE undefined. This is the normal thing to do. 46 | */ 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/fdreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains some defines for the floppy disk controller. 3 | * Various sources. Mostly "IBM Microcomputers: A Programmers 4 | * Handbook", Sanches and Canton. 5 | */ 6 | #ifndef _FDREG_H 7 | #define _FDREG_H 8 | 9 | extern int ticks_to_floppy_on(unsigned int nr); 10 | extern void floppy_on(unsigned int nr); 11 | extern void floppy_off(unsigned int nr); 12 | extern void floppy_select(unsigned int nr); 13 | extern void floppy_deselect(unsigned int nr); 14 | 15 | /* Fd controller regs. S&C, about page 340 */ 16 | #define FD_STATUS 0x3f4 17 | #define FD_DATA 0x3f5 18 | #define FD_DOR 0x3f2 /* Digital Output Register */ 19 | #define FD_DIR 0x3f7 /* Digital Input Register (read) */ 20 | #define FD_DCR 0x3f7 /* Diskette Control Register (write)*/ 21 | 22 | /* Bits of main status register */ 23 | #define STATUS_BUSYMASK 0x0F /* drive busy mask */ 24 | #define STATUS_BUSY 0x10 /* FDC busy */ 25 | #define STATUS_DMA 0x20 /* 0- DMA mode */ 26 | #define STATUS_DIR 0x40 /* 0- cpu->fdc */ 27 | #define STATUS_READY 0x80 /* Data reg ready */ 28 | 29 | /* Bits of FD_ST0 */ 30 | #define ST0_DS 0x03 /* drive select mask */ 31 | #define ST0_HA 0x04 /* Head (Address) */ 32 | #define ST0_NR 0x08 /* Not Ready */ 33 | #define ST0_ECE 0x10 /* Equipment chech error */ 34 | #define ST0_SE 0x20 /* Seek end */ 35 | #define ST0_INTR 0xC0 /* Interrupt code mask */ 36 | 37 | /* Bits of FD_ST1 */ 38 | #define ST1_MAM 0x01 /* Missing Address Mark */ 39 | #define ST1_WP 0x02 /* Write Protect */ 40 | #define ST1_ND 0x04 /* No Data - unreadable */ 41 | #define ST1_OR 0x10 /* OverRun */ 42 | #define ST1_CRC 0x20 /* CRC error in data or addr */ 43 | #define ST1_EOC 0x80 /* End Of Cylinder */ 44 | 45 | /* Bits of FD_ST2 */ 46 | #define ST2_MAM 0x01 /* Missing Addess Mark (again) */ 47 | #define ST2_BC 0x02 /* Bad Cylinder */ 48 | #define ST2_SNS 0x04 /* Scan Not Satisfied */ 49 | #define ST2_SEH 0x08 /* Scan Equal Hit */ 50 | #define ST2_WC 0x10 /* Wrong Cylinder */ 51 | #define ST2_CRC 0x20 /* CRC error in data field */ 52 | #define ST2_CM 0x40 /* Control Mark = deleted */ 53 | 54 | /* Bits of FD_ST3 */ 55 | #define ST3_HA 0x04 /* Head (Address) */ 56 | #define ST3_TZ 0x10 /* Track Zero signal (1=track 0) */ 57 | #define ST3_WP 0x40 /* Write Protect */ 58 | 59 | /* Values for FD_COMMAND */ 60 | #define FD_RECALIBRATE 0x07 /* move to track 0 */ 61 | #define FD_SEEK 0x0F /* seek track */ 62 | #define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */ 63 | #define FD_WRITE 0xC5 /* write with MT, MFM */ 64 | #define FD_SENSEI 0x08 /* Sense Interrupt Status */ 65 | #define FD_SPECIFY 0x03 /* specify HUT etc */ 66 | 67 | /* DMA commands */ 68 | #define DMA_READ 0x46 69 | #define DMA_WRITE 0x4A 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/hdreg.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This file contains some defines for the AT-hd-controller. 3 | * Various sources. Check out some definitions (see comments with 4 | * a ques). 5 | */ 6 | #ifndef _HDREG_H 7 | #define _HDREG_H 8 | 9 | /* Hd controller regs. Ref: IBM AT Bios-listing */ 10 | #define HD_DATA 0x1f0 /* _CTL when writing */ 11 | #define HD_ERROR 0x1f1 /* see err-bits */ 12 | #define HD_NSECTOR 0x1f2 /* nr of sectors to read/write */ 13 | #define HD_SECTOR 0x1f3 /* starting sector */ 14 | #define HD_LCYL 0x1f4 /* starting cylinder */ 15 | #define HD_HCYL 0x1f5 /* high byte of starting cyl */ 16 | #define HD_CURRENT 0x1f6 /* 101dhhhh , d=drive, hhhh=head */ 17 | #define HD_STATUS 0x1f7 /* see status-bits */ 18 | #define HD_PRECOMP HD_ERROR /* same io address, read=error, write=precomp */ 19 | #define HD_COMMAND HD_STATUS /* same io address, read=status, write=cmd */ 20 | 21 | #define HD_CMD 0x3f6 22 | 23 | /* Bits of HD_STATUS */ 24 | #define ERR_STAT 0x01 25 | #define INDEX_STAT 0x02 26 | #define ECC_STAT 0x04 /* Corrected error */ 27 | #define DRQ_STAT 0x08 28 | #define SEEK_STAT 0x10 29 | #define WRERR_STAT 0x20 30 | #define READY_STAT 0x40 31 | #define BUSY_STAT 0x80 32 | 33 | /* Values for HD_COMMAND */ 34 | #define WIN_RESTORE 0x10 35 | #define WIN_READ 0x20 36 | #define WIN_WRITE 0x30 37 | #define WIN_VERIFY 0x40 38 | #define WIN_FORMAT 0x50 39 | #define WIN_INIT 0x60 40 | #define WIN_SEEK 0x70 41 | #define WIN_DIAGNOSE 0x90 42 | #define WIN_SPECIFY 0x91 43 | 44 | /* Bits for HD_ERROR */ 45 | #define MARK_ERR 0x01 /* Bad address mark ? */ 46 | #define TRK0_ERR 0x02 /* couldn't find track 0 */ 47 | #define ABRT_ERR 0x04 /* ? */ 48 | #define ID_ERR 0x10 /* ? */ 49 | #define ECC_ERR 0x40 /* ? */ 50 | #define BBD_ERR 0x80 /* ? */ 51 | 52 | struct partition { 53 | unsigned char boot_ind; /* 0x80 - active (unused) */ 54 | unsigned char head; /* ? */ 55 | unsigned char sector; /* ? */ 56 | unsigned char cyl; /* ? */ 57 | unsigned char sys_ind; /* ? */ 58 | unsigned char end_head; /* ? */ 59 | unsigned char end_sector; /* ? */ 60 | unsigned char end_cyl; /* ? */ 61 | unsigned int start_sect; /* starting sector counting from 0 */ 62 | unsigned int nr_sects; /* nr of sectors in partition */ 63 | }; 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/head.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEAD_H 2 | #define _HEAD_H 3 | 4 | typedef struct desc_struct { 5 | unsigned long a,b; 6 | } desc_table[256]; 7 | 8 | extern unsigned long pg_dir[1024]; 9 | extern desc_table idt,gdt; 10 | 11 | #define GDT_NUL 0 12 | #define GDT_CODE 1 13 | #define GDT_DATA 2 14 | #define GDT_TMP 3 15 | 16 | #define LDT_NUL 0 17 | #define LDT_CODE 1 18 | #define LDT_DATA 2 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/kernel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 'kernel.h' contains some often-used function prototypes etc 3 | */ 4 | void verify_area(void * addr,int count); 5 | volatile void panic(const char * str); 6 | int printf(const char * fmt, ...); 7 | int printk(const char * fmt, ...); 8 | int tty_write(unsigned ch,char * buf,int count); 9 | void * malloc(unsigned int size); 10 | void free_s(void * obj, int size); 11 | 12 | #define free(x) free_s((x), 0) 13 | 14 | /* 15 | * This is defined as a macro, but at some point this might become a 16 | * real subroutine that sets a flag if it returns true (to do 17 | * BSD-style accounting where the process is flagged if it uses root 18 | * privs). The implication of this is that you should do normal 19 | * permissions checks first, and check suser() last. 20 | */ 21 | #define suser() (current->euid == 0) 22 | 23 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/mm.h: -------------------------------------------------------------------------------- 1 | #ifndef _MM_H 2 | #define _MM_H 3 | 4 | #define PAGE_SIZE 4096 5 | 6 | extern unsigned long get_free_page(void); 7 | extern unsigned long put_page(unsigned long page,unsigned long address); 8 | extern void free_page(unsigned long addr); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/sys.h: -------------------------------------------------------------------------------- 1 | extern int sys_setup(); 2 | extern int sys_exit(); 3 | extern int sys_fork(); 4 | extern int sys_read(); 5 | extern int sys_write(); 6 | extern int sys_open(); 7 | extern int sys_close(); 8 | extern int sys_waitpid(); 9 | extern int sys_creat(); 10 | extern int sys_link(); 11 | extern int sys_unlink(); 12 | extern int sys_execve(); 13 | extern int sys_chdir(); 14 | extern int sys_time(); 15 | extern int sys_mknod(); 16 | extern int sys_chmod(); 17 | extern int sys_chown(); 18 | extern int sys_break(); 19 | extern int sys_stat(); 20 | extern int sys_lseek(); 21 | extern int sys_getpid(); 22 | extern int sys_mount(); 23 | extern int sys_umount(); 24 | extern int sys_setuid(); 25 | extern int sys_getuid(); 26 | extern int sys_stime(); 27 | extern int sys_ptrace(); 28 | extern int sys_alarm(); 29 | extern int sys_fstat(); 30 | extern int sys_pause(); 31 | extern int sys_utime(); 32 | extern int sys_stty(); 33 | extern int sys_gtty(); 34 | extern int sys_access(); 35 | extern int sys_nice(); 36 | extern int sys_ftime(); 37 | extern int sys_sync(); 38 | extern int sys_kill(); 39 | extern int sys_rename(); 40 | extern int sys_mkdir(); 41 | extern int sys_rmdir(); 42 | extern int sys_dup(); 43 | extern int sys_pipe(); 44 | extern int sys_times(); 45 | extern int sys_prof(); 46 | extern int sys_brk(); 47 | extern int sys_setgid(); 48 | extern int sys_getgid(); 49 | extern int sys_signal(); 50 | extern int sys_geteuid(); 51 | extern int sys_getegid(); 52 | extern int sys_acct(); 53 | extern int sys_phys(); 54 | extern int sys_lock(); 55 | extern int sys_ioctl(); 56 | extern int sys_fcntl(); 57 | extern int sys_mpx(); 58 | extern int sys_setpgid(); 59 | extern int sys_ulimit(); 60 | extern int sys_uname(); 61 | extern int sys_umask(); 62 | extern int sys_chroot(); 63 | extern int sys_ustat(); 64 | extern int sys_dup2(); 65 | extern int sys_getppid(); 66 | extern int sys_getpgrp(); 67 | extern int sys_setsid(); 68 | extern int sys_sigaction(); 69 | extern int sys_sgetmask(); 70 | extern int sys_ssetmask(); 71 | extern int sys_setreuid(); 72 | extern int sys_setregid(); 73 | 74 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 75 | sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link, 76 | sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod, 77 | sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount, 78 | sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm, 79 | sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access, 80 | sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir, 81 | sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid, 82 | sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys, 83 | sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit, 84 | sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid, 85 | sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask, 86 | sys_setreuid,sys_setregid }; 87 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/linux/tty.h: -------------------------------------------------------------------------------- 1 | /* 2 | * 'tty.h' defines some structures used by tty_io.c and some defines. 3 | * 4 | * NOTE! Don't touch this without checking that nothing in rs_io.s or 5 | * con_io.s breaks. Some constants are hardwired into the system (mainly 6 | * offsets into 'tty_queue' 7 | */ 8 | 9 | #ifndef _TTY_H 10 | #define _TTY_H 11 | 12 | #include 13 | 14 | #define TTY_BUF_SIZE 1024 15 | 16 | struct tty_queue { 17 | unsigned long data; 18 | unsigned long head; 19 | unsigned long tail; 20 | struct task_struct * proc_list; 21 | char buf[TTY_BUF_SIZE]; 22 | }; 23 | 24 | #define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1)) 25 | #define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1)) 26 | #define EMPTY(a) ((a).head == (a).tail) 27 | #define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1)) 28 | #define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)]) 29 | #define FULL(a) (!LEFT(a)) 30 | #define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1)) 31 | #define GETCH(queue,c) \ 32 | (void)({c=(queue).buf[(queue).tail];INC((queue).tail);}) 33 | #define PUTCH(c,queue) \ 34 | (void)({(queue).buf[(queue).head]=(c);INC((queue).head);}) 35 | 36 | #define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR]) 37 | #define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT]) 38 | #define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE]) 39 | #define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL]) 40 | #define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF]) 41 | #define START_CHAR(tty) ((tty)->termios.c_cc[VSTART]) 42 | #define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP]) 43 | #define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP]) 44 | 45 | struct tty_struct { 46 | struct termios termios; 47 | int pgrp; 48 | int stopped; 49 | void (*write)(struct tty_struct * tty); 50 | struct tty_queue read_q; 51 | struct tty_queue write_q; 52 | struct tty_queue secondary; 53 | }; 54 | 55 | extern struct tty_struct tty_table[]; 56 | 57 | /* intr=^C quit=^| erase=del kill=^U 58 | eof=^D vtime=\0 vmin=\1 sxtc=\0 59 | start=^Q stop=^S susp=^Z eol=\0 60 | reprint=^R discard=^U werase=^W lnext=^V 61 | eol2=\0 62 | */ 63 | #define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0" 64 | 65 | void rs_init(void); 66 | void con_init(void); 67 | void tty_init(void); 68 | 69 | int tty_read(unsigned c, char * buf, int n); 70 | int tty_write(unsigned c, char * buf, int n); 71 | 72 | void rs_write(struct tty_struct * tty); 73 | void con_write(struct tty_struct * tty); 74 | 75 | void copy_to_cooked(struct tty_struct * tty); 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/signal.h: -------------------------------------------------------------------------------- 1 | #ifndef _SIGNAL_H 2 | #define _SIGNAL_H 3 | 4 | #include 5 | 6 | typedef int sig_atomic_t; 7 | typedef unsigned int sigset_t; /* 32 bits */ 8 | 9 | #define _NSIG 32 10 | #define NSIG _NSIG 11 | 12 | #define SIGHUP 1 13 | #define SIGINT 2 14 | #define SIGQUIT 3 15 | #define SIGILL 4 16 | #define SIGTRAP 5 17 | #define SIGABRT 6 18 | #define SIGIOT 6 19 | #define SIGUNUSED 7 20 | #define SIGFPE 8 21 | #define SIGKILL 9 22 | #define SIGUSR1 10 23 | #define SIGSEGV 11 24 | #define SIGUSR2 12 25 | #define SIGPIPE 13 26 | #define SIGALRM 14 27 | #define SIGTERM 15 28 | #define SIGSTKFLT 16 29 | #define SIGCHLD 17 30 | #define SIGCONT 18 31 | #define SIGSTOP 19 32 | #define SIGTSTP 20 33 | #define SIGTTIN 21 34 | #define SIGTTOU 22 35 | 36 | /* Ok, I haven't implemented sigactions, but trying to keep headers POSIX */ 37 | #define SA_NOCLDSTOP 1 38 | #define SA_NOMASK 0x40000000 39 | #define SA_ONESHOT 0x80000000 40 | 41 | #define SIG_BLOCK 0 /* for blocking signals */ 42 | #define SIG_UNBLOCK 1 /* for unblocking signals */ 43 | #define SIG_SETMASK 2 /* for setting the signal mask */ 44 | 45 | #define SIG_DFL ((void (*)(int))0) /* default signal handling */ 46 | #define SIG_IGN ((void (*)(int))1) /* ignore signal */ 47 | 48 | struct sigaction { 49 | void (*sa_handler)(int); 50 | sigset_t sa_mask; 51 | int sa_flags; 52 | void (*sa_restorer)(void); 53 | }; 54 | 55 | void (*signal(int _sig, void (*_func)(int)))(int); 56 | int raise(int sig); 57 | int kill(pid_t pid, int sig); 58 | int sigaddset(sigset_t *mask, int signo); 59 | int sigdelset(sigset_t *mask, int signo); 60 | int sigemptyset(sigset_t *mask); 61 | int sigfillset(sigset_t *mask); 62 | int sigismember(sigset_t *mask, int signo); /* 1 - is, 0 - not, -1 error */ 63 | int sigpending(sigset_t *set); 64 | int sigprocmask(int how, sigset_t *set, sigset_t *oldset); 65 | int sigsuspend(sigset_t *sigmask); 66 | int sigaction(int sig, struct sigaction *act, struct sigaction *oldact); 67 | 68 | #endif /* _SIGNAL_H */ 69 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/stdarg.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDARG_H 2 | #define _STDARG_H 3 | 4 | typedef char *va_list; 5 | 6 | /* Amount of space required in an argument list for an arg of type TYPE. 7 | TYPE may alternatively be an expression whose type is used. */ 8 | 9 | #define __va_rounded_size(TYPE) \ 10 | (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) 11 | 12 | #ifndef __sparc__ 13 | #define va_start(AP, LASTARG) \ 14 | (AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) 15 | #else 16 | #define va_start(AP, LASTARG) \ 17 | (__builtin_saveregs (), \ 18 | AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG))) 19 | #endif 20 | 21 | void va_end (va_list); /* Defined in gnulib */ 22 | #define va_end(AP) 23 | 24 | #define va_arg(AP, TYPE) \ 25 | (AP += __va_rounded_size (TYPE), \ 26 | *((TYPE *) (AP - __va_rounded_size (TYPE)))) 27 | 28 | #endif /* _STDARG_H */ 29 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/stddef.h: -------------------------------------------------------------------------------- 1 | #ifndef _STDDEF_H 2 | #define _STDDEF_H 3 | 4 | #ifndef _PTRDIFF_T 5 | #define _PTRDIFF_T 6 | typedef long ptrdiff_t; 7 | #endif 8 | 9 | #ifndef _SIZE_T 10 | #define _SIZE_T 11 | typedef unsigned long size_t; 12 | #endif 13 | 14 | #undef NULL 15 | #define NULL ((void *)0) 16 | 17 | #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/sys/stat.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_STAT_H 2 | #define _SYS_STAT_H 3 | 4 | #include 5 | 6 | struct stat { 7 | dev_t st_dev; 8 | ino_t st_ino; 9 | umode_t st_mode; 10 | nlink_t st_nlink; 11 | uid_t st_uid; 12 | gid_t st_gid; 13 | dev_t st_rdev; 14 | off_t st_size; 15 | time_t st_atime; 16 | time_t st_mtime; 17 | time_t st_ctime; 18 | }; 19 | 20 | #define S_IFMT 00170000 21 | #define S_IFREG 0100000 22 | #define S_IFBLK 0060000 23 | #define S_IFDIR 0040000 24 | #define S_IFCHR 0020000 25 | #define S_IFIFO 0010000 26 | #define S_ISUID 0004000 27 | #define S_ISGID 0002000 28 | #define S_ISVTX 0001000 29 | 30 | #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 31 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 32 | #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) 33 | #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) 34 | #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) 35 | 36 | #define S_IRWXU 00700 37 | #define S_IRUSR 00400 38 | #define S_IWUSR 00200 39 | #define S_IXUSR 00100 40 | 41 | #define S_IRWXG 00070 42 | #define S_IRGRP 00040 43 | #define S_IWGRP 00020 44 | #define S_IXGRP 00010 45 | 46 | #define S_IRWXO 00007 47 | #define S_IROTH 00004 48 | #define S_IWOTH 00002 49 | #define S_IXOTH 00001 50 | 51 | extern int chmod(const char *_path, mode_t mode); 52 | extern int fstat(int fildes, struct stat *stat_buf); 53 | extern int mkdir(const char *_path, mode_t mode); 54 | extern int mkfifo(const char *_path, mode_t mode); 55 | extern int stat(const char *filename, struct stat *stat_buf); 56 | extern mode_t umask(mode_t mask); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/sys/times.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIMES_H 2 | #define _TIMES_H 3 | 4 | #include 5 | 6 | struct tms { 7 | time_t tms_utime; 8 | time_t tms_stime; 9 | time_t tms_cutime; 10 | time_t tms_cstime; 11 | }; 12 | 13 | extern time_t times(struct tms * tp); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/sys/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_TYPES_H 2 | #define _SYS_TYPES_H 3 | 4 | #ifndef _SIZE_T 5 | #define _SIZE_T 6 | typedef unsigned int size_t; 7 | #endif 8 | 9 | #ifndef _TIME_T 10 | #define _TIME_T 11 | typedef long time_t; 12 | #endif 13 | 14 | #ifndef _PTRDIFF_T 15 | #define _PTRDIFF_T 16 | typedef long ptrdiff_t; 17 | #endif 18 | 19 | #ifndef NULL 20 | #define NULL ((void *) 0) 21 | #endif 22 | 23 | typedef int pid_t; 24 | typedef unsigned short uid_t; 25 | typedef unsigned char gid_t; 26 | typedef unsigned short dev_t; 27 | typedef unsigned short ino_t; 28 | typedef unsigned short mode_t; 29 | typedef unsigned short umode_t; 30 | typedef unsigned char nlink_t; 31 | typedef int daddr_t; 32 | typedef long off_t; 33 | typedef unsigned char u_char; 34 | typedef unsigned short ushort; 35 | 36 | typedef struct { int quot,rem; } div_t; 37 | typedef struct { long quot,rem; } ldiv_t; 38 | 39 | struct ustat { 40 | daddr_t f_tfree; 41 | ino_t f_tinode; 42 | char f_fname[6]; 43 | char f_fpack[6]; 44 | }; 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/sys/utsname.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_UTSNAME_H 2 | #define _SYS_UTSNAME_H 3 | 4 | #include 5 | 6 | struct utsname { 7 | char sysname[9]; 8 | char nodename[9]; 9 | char release[9]; 10 | char version[9]; 11 | char machine[9]; 12 | }; 13 | 14 | extern int uname(struct utsname * utsbuf); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/sys/wait.h: -------------------------------------------------------------------------------- 1 | #ifndef _SYS_WAIT_H 2 | #define _SYS_WAIT_H 3 | 4 | #include 5 | 6 | #define _LOW(v) ( (v) & 0377) 7 | #define _HIGH(v) ( ((v) >> 8) & 0377) 8 | 9 | /* options for waitpid, WUNTRACED not supported */ 10 | #define WNOHANG 1 11 | #define WUNTRACED 2 12 | 13 | #define WIFEXITED(s) (!((s)&0xFF) 14 | #define WIFSTOPPED(s) (((s)&0xFF)==0x7F) 15 | #define WEXITSTATUS(s) (((s)>>8)&0xFF) 16 | #define WTERMSIG(s) ((s)&0x7F) 17 | #define WSTOPSIG(s) (((s)>>8)&0xFF) 18 | #define WIFSIGNALED(s) (((unsigned int)(s)-1 & 0xFFFF) < 0xFF) 19 | 20 | pid_t wait(int *stat_loc); 21 | pid_t waitpid(pid_t pid, int *stat_loc, int options); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/time.h: -------------------------------------------------------------------------------- 1 | #ifndef _TIME_H 2 | #define _TIME_H 3 | 4 | #ifndef _TIME_T 5 | #define _TIME_T 6 | typedef long time_t; 7 | #endif 8 | 9 | #ifndef _SIZE_T 10 | #define _SIZE_T 11 | typedef unsigned int size_t; 12 | #endif 13 | 14 | #define CLOCKS_PER_SEC 100 15 | 16 | typedef long clock_t; 17 | 18 | struct tm { 19 | int tm_sec; 20 | int tm_min; 21 | int tm_hour; 22 | int tm_mday; 23 | int tm_mon; 24 | int tm_year; 25 | int tm_wday; 26 | int tm_yday; 27 | int tm_isdst; 28 | }; 29 | 30 | clock_t clock(void); 31 | time_t time(time_t * tp); 32 | double difftime(time_t time2, time_t time1); 33 | time_t mktime(struct tm * tp); 34 | 35 | char * asctime(const struct tm * tp); 36 | char * ctime(const time_t * tp); 37 | struct tm * gmtime(const time_t *tp); 38 | struct tm *localtime(const time_t * tp); 39 | size_t strftime(char * s, size_t smax, const char * fmt, const struct tm * tp); 40 | void tzset(void); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/include/utime.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTIME_H 2 | #define _UTIME_H 3 | 4 | #include /* I know - shouldn't do this, but .. */ 5 | 6 | struct utimbuf { 7 | time_t actime; 8 | time_t modtime; 9 | }; 10 | 11 | extern int utime(const char *filename, struct utimbuf *times); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/asm.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/asm.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * asm.s contains the low-level code for most hardware faults. 9 | * page_exception is handled by the mm, so that isn't here. This 10 | * file also handles (hopefully) fpu-exceptions due to TS-bit, as 11 | * the fpu must be properly saved/resored. This hasn't been tested. 12 | */ 13 | 14 | .globl divide_error,debug,nmi,int3,overflow,bounds,invalid_op 15 | .globl double_fault,coprocessor_segment_overrun 16 | .globl invalid_TSS,segment_not_present,stack_segment 17 | .globl general_protection,coprocessor_error,irq13,reserved 18 | 19 | divide_error: 20 | pushl $do_divide_error 21 | no_error_code: 22 | xchgl %eax,(%esp) 23 | pushl %ebx 24 | pushl %ecx 25 | pushl %edx 26 | pushl %edi 27 | pushl %esi 28 | pushl %ebp 29 | push %ds 30 | push %es 31 | push %fs 32 | pushl $0 # "error code" 33 | lea 44(%esp),%edx 34 | pushl %edx 35 | movl $0x10,%edx 36 | mov %dx,%ds 37 | mov %dx,%es 38 | mov %dx,%fs 39 | call *%eax 40 | addl $8,%esp 41 | pop %fs 42 | pop %es 43 | pop %ds 44 | popl %ebp 45 | popl %esi 46 | popl %edi 47 | popl %edx 48 | popl %ecx 49 | popl %ebx 50 | popl %eax 51 | iret 52 | 53 | debug: 54 | pushl $do_int3 # _do_debug 55 | jmp no_error_code 56 | 57 | nmi: 58 | pushl $do_nmi 59 | jmp no_error_code 60 | 61 | int3: 62 | pushl $do_int3 63 | jmp no_error_code 64 | 65 | overflow: 66 | pushl $do_overflow 67 | jmp no_error_code 68 | 69 | bounds: 70 | pushl $do_bounds 71 | jmp no_error_code 72 | 73 | invalid_op: 74 | pushl $do_invalid_op 75 | jmp no_error_code 76 | 77 | coprocessor_segment_overrun: 78 | pushl $do_coprocessor_segment_overrun 79 | jmp no_error_code 80 | 81 | reserved: 82 | pushl $do_reserved 83 | jmp no_error_code 84 | 85 | irq13: 86 | pushl %eax 87 | xorb %al,%al 88 | outb %al,$0xF0 89 | movb $0x20,%al 90 | outb %al,$0x20 91 | jmp 1f 92 | 1: jmp 1f 93 | 1: outb %al,$0xA0 94 | popl %eax 95 | jmp coprocessor_error 96 | 97 | double_fault: 98 | pushl $do_double_fault 99 | error_code: 100 | xchgl %eax,4(%esp) # error code <-> %eax 101 | xchgl %ebx,(%esp) # &function <-> %ebx 102 | pushl %ecx 103 | pushl %edx 104 | pushl %edi 105 | pushl %esi 106 | pushl %ebp 107 | push %ds 108 | push %es 109 | push %fs 110 | pushl %eax # error code 111 | lea 44(%esp),%eax # offset 112 | pushl %eax 113 | movl $0x10,%eax 114 | mov %ax,%ds 115 | mov %ax,%es 116 | mov %ax,%fs 117 | call *%ebx 118 | addl $8,%esp 119 | pop %fs 120 | pop %es 121 | pop %ds 122 | popl %ebp 123 | popl %esi 124 | popl %edi 125 | popl %edx 126 | popl %ecx 127 | popl %ebx 128 | popl %eax 129 | iret 130 | 131 | invalid_TSS: 132 | pushl $do_invalid_TSS 133 | jmp error_code 134 | 135 | segment_not_present: 136 | pushl $do_segment_not_present 137 | jmp error_code 138 | 139 | stack_segment: 140 | pushl $do_stack_segment 141 | jmp error_code 142 | 143 | general_protection: 144 | pushl $do_general_protection 145 | jmp error_code 146 | 147 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/blk_drv/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel block device drivers. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-m elf_i386 -x 13 | CC =gcc-3.4 -march=i386 14 | CFLAGS =-m32 -g -Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../../include 16 | CPP =gcc-3.4 -E -nostdinc -I../../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = ll_rw_blk.o floppy.o hd.o ramdisk.o 28 | 29 | blk_drv.a: $(OBJS) 30 | $(AR) rcs blk_drv.a $(OBJS) 31 | sync 32 | 33 | clean: 34 | rm -f core *.o *.a tmp_make 35 | for i in *.c;do rm -f `basename $$i .c`.s;done 36 | 37 | dep: 38 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 39 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 40 | $(CPP) -M $$i;done) >> tmp_make 41 | cp tmp_make Makefile 42 | 43 | ### Dependencies: 44 | floppy.s floppy.o: floppy.c ../../include/linux/sched.h ../../include/linux/head.h \ 45 | ../../include/linux/fs.h ../../include/sys/types.h \ 46 | ../../include/linux/mm.h ../../include/signal.h \ 47 | ../../include/linux/kernel.h ../../include/linux/fdreg.h \ 48 | ../../include/asm/system.h ../../include/asm/io.h \ 49 | ../../include/asm/segment.h blk.h 50 | hd.s hd.o: hd.c ../../include/linux/config.h ../../include/linux/sched.h \ 51 | ../../include/linux/head.h ../../include/linux/fs.h \ 52 | ../../include/sys/types.h ../../include/linux/mm.h \ 53 | ../../include/signal.h ../../include/linux/kernel.h \ 54 | ../../include/linux/hdreg.h ../../include/asm/system.h \ 55 | ../../include/asm/io.h ../../include/asm/segment.h blk.h 56 | ll_rw_blk.s ll_rw_blk.o: ll_rw_blk.c ../../include/errno.h \ 57 | ../../include/linux/sched.h ../../include/linux/head.h \ 58 | ../../include/linux/fs.h ../../include/sys/types.h \ 59 | ../../include/linux/mm.h ../../include/signal.h \ 60 | ../../include/linux/kernel.h ../../include/asm/system.h blk.h 61 | ramdisk.s ramdisk.o: ramdisk.c ../../include/string.h ../../include/linux/config.h \ 62 | ../../include/linux/sched.h ../../include/linux/head.h \ 63 | ../../include/linux/fs.h ../../include/sys/types.h \ 64 | ../../include/linux/mm.h ../../include/signal.h \ 65 | ../../include/linux/kernel.h ../../include/asm/system.h \ 66 | ../../include/asm/segment.h ../../include/asm/memory.h blk.h 67 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/blk_drv/ramdisk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/blk_drv/ramdisk.c 3 | * 4 | * Written by Theodore Ts'o, 12/2/91 5 | */ 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define MAJOR_NR 1 18 | #include "blk.h" 19 | 20 | char *rd_start; 21 | int rd_length = 0; 22 | 23 | void do_rd_request(void) 24 | { 25 | int len; 26 | char *addr; 27 | 28 | INIT_REQUEST; 29 | addr = rd_start + (CURRENT->sector << 9); 30 | len = CURRENT->nr_sectors << 9; 31 | if ((MINOR(CURRENT->dev) != 1) || (addr+len > rd_start+rd_length)) { 32 | end_request(0); 33 | goto repeat; 34 | } 35 | if (CURRENT-> cmd == WRITE) { 36 | (void ) memcpy(addr, 37 | CURRENT->buffer, 38 | len); 39 | } else if (CURRENT->cmd == READ) { 40 | (void) memcpy(CURRENT->buffer, 41 | addr, 42 | len); 43 | } else 44 | panic("unknown ramdisk-command"); 45 | end_request(1); 46 | goto repeat; 47 | } 48 | 49 | /* 50 | * Returns amount of memory which needs to be reserved. 51 | */ 52 | long rd_init(long mem_start, int length) 53 | { 54 | int i; 55 | char *cp; 56 | 57 | blk_dev[MAJOR_NR].request_fn = DEVICE_REQUEST; 58 | rd_start = (char *) mem_start; 59 | rd_length = length; 60 | cp = rd_start; 61 | for (i=0; i < length; i++) 62 | *cp++ = '\0'; 63 | return(length); 64 | } 65 | 66 | /* 67 | * If the root device is the ram disk, try to load it. 68 | * In order to do this, the root device is originally set to the 69 | * floppy, and we later change it to be ram disk. 70 | */ 71 | void rd_load(void) 72 | { 73 | struct buffer_head *bh; 74 | struct super_block s; 75 | int block = 256; /* Start at block 256 */ 76 | int i = 1; 77 | int nblocks; 78 | char *cp; /* Move pointer */ 79 | 80 | if (!rd_length) 81 | return; 82 | printk("Ram disk: %d bytes, starting at 0x%x\n", rd_length, 83 | (int) rd_start); 84 | if (MAJOR(ROOT_DEV) != 2) 85 | return; 86 | bh = breada(ROOT_DEV,block+1,block,block+2,-1); 87 | if (!bh) { 88 | printk("Disk error while looking for ramdisk!\n"); 89 | return; 90 | } 91 | *((struct d_super_block *) &s) = *((struct d_super_block *) bh->b_data); 92 | brelse(bh); 93 | if (s.s_magic != SUPER_MAGIC) 94 | /* No ram disk image present, assume normal floppy boot */ 95 | return; 96 | nblocks = s.s_nzones << s.s_log_zone_size; 97 | if (nblocks > (rd_length >> BLOCK_SIZE_BITS)) { 98 | printk("Ram disk image too big! (%d blocks, %d avail)\n", 99 | nblocks, rd_length >> BLOCK_SIZE_BITS); 100 | return; 101 | } 102 | printk("Loading %d bytes into ram disk... 0000k", 103 | nblocks << BLOCK_SIZE_BITS); 104 | cp = rd_start; 105 | while (nblocks) { 106 | if (nblocks > 2) 107 | bh = breada(ROOT_DEV, block, block+1, block+2, -1); 108 | else 109 | bh = bread(ROOT_DEV, block); 110 | if (!bh) { 111 | printk("I/O error on block %d, aborting load\n", 112 | block); 113 | return; 114 | } 115 | (void) memcpy(cp, bh->b_data, BLOCK_SIZE); 116 | brelse(bh); 117 | printk("\010\010\010\010\010%4dk",i); 118 | cp += BLOCK_SIZE; 119 | block++; 120 | nblocks--; 121 | i++; 122 | } 123 | printk("\010\010\010\010\010done \n"); 124 | ROOT_DEV=0x0101; 125 | } 126 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/chr_drv/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel character device drivers. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as --32 11 | LD =ld 12 | LDFLAGS =-m elf_i386 -x 13 | CC =gcc-3.4 -march=i386 14 | CFLAGS =-m32 -g -Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../../include 16 | CPP =gcc-3.4 -m32 -g -E -nostdinc -I../../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = tty_io.o console.o keyboard.o serial.o rs_io.o \ 28 | tty_ioctl.o 29 | 30 | chr_drv.a: $(OBJS) 31 | $(AR) rcs chr_drv.a $(OBJS) 32 | sync 33 | 34 | keyboard.s: keyboard.S ../../include/linux/config.h 35 | $(CPP) -traditional keyboard.S -o keyboard.s 36 | 37 | clean: 38 | rm -f core *.o *.a tmp_make keyboard.s 39 | for i in *.c;do rm -f `basename $$i .c`.s;done 40 | 41 | dep: 42 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 43 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 44 | $(CPP) -M $$i;done) >> tmp_make 45 | cp tmp_make Makefile 46 | 47 | ### Dependencies: 48 | console.s console.o: console.c ../../include/linux/sched.h \ 49 | ../../include/linux/head.h ../../include/linux/fs.h \ 50 | ../../include/sys/types.h ../../include/linux/mm.h \ 51 | ../../include/signal.h ../../include/linux/tty.h \ 52 | ../../include/termios.h ../../include/asm/io.h \ 53 | ../../include/asm/system.h 54 | serial.s serial.o: serial.c ../../include/linux/tty.h ../../include/termios.h \ 55 | ../../include/linux/sched.h ../../include/linux/head.h \ 56 | ../../include/linux/fs.h ../../include/sys/types.h \ 57 | ../../include/linux/mm.h ../../include/signal.h \ 58 | ../../include/asm/system.h ../../include/asm/io.h 59 | tty_io.s tty_io.o: tty_io.c ../../include/ctype.h ../../include/errno.h \ 60 | ../../include/signal.h ../../include/sys/types.h \ 61 | ../../include/linux/sched.h ../../include/linux/head.h \ 62 | ../../include/linux/fs.h ../../include/linux/mm.h \ 63 | ../../include/linux/tty.h ../../include/termios.h \ 64 | ../../include/asm/segment.h ../../include/asm/system.h 65 | tty_ioctl.s tty_ioctl.o: tty_ioctl.c ../../include/errno.h ../../include/termios.h \ 66 | ../../include/linux/sched.h ../../include/linux/head.h \ 67 | ../../include/linux/fs.h ../../include/sys/types.h \ 68 | ../../include/linux/mm.h ../../include/signal.h \ 69 | ../../include/linux/kernel.h ../../include/linux/tty.h \ 70 | ../../include/asm/io.h ../../include/asm/segment.h \ 71 | ../../include/asm/system.h 72 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/chr_drv/rs_io.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/rs_io.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * rs_io.s 9 | * 10 | * This module implements the rs232 io interrupts. 11 | */ 12 | 13 | .text 14 | .globl rs1_interrupt,rs2_interrupt 15 | 16 | size = 1024 /* must be power of two ! 17 | and must match the value 18 | in tty_io.c!!! */ 19 | 20 | /* these are the offsets into the read/write buffer structures */ 21 | rs_addr = 0 22 | head = 4 23 | tail = 8 24 | proc_list = 12 25 | buf = 16 26 | 27 | startup = 256 /* chars left in write queue when we restart it */ 28 | 29 | /* 30 | * These are the actual interrupt routines. They look where 31 | * the interrupt is coming from, and take appropriate action. 32 | */ 33 | .align 2 34 | rs1_interrupt: 35 | pushl $table_list+8 36 | jmp rs_int 37 | .align 2 38 | rs2_interrupt: 39 | pushl $table_list+16 40 | rs_int: 41 | pushl %edx 42 | pushl %ecx 43 | pushl %ebx 44 | pushl %eax 45 | push %es 46 | push %ds /* as this is an interrupt, we cannot */ 47 | pushl $0x10 /* know that bs is ok. Load it */ 48 | pop %ds 49 | pushl $0x10 50 | pop %es 51 | movl 24(%esp),%edx 52 | movl (%edx),%edx 53 | movl rs_addr(%edx),%edx 54 | addl $2,%edx /* interrupt ident. reg */ 55 | rep_int: 56 | xorl %eax,%eax 57 | inb %dx,%al 58 | testb $1,%al 59 | jne end 60 | cmpb $6,%al /* this shouldn't happen, but ... */ 61 | ja end 62 | movl 24(%esp),%ecx 63 | pushl %edx 64 | subl $2,%edx 65 | call jmp_table(,%eax,2) /* NOTE! not *4, bit0 is 0 already */ 66 | popl %edx 67 | jmp rep_int 68 | end: movb $0x20,%al 69 | outb %al,$0x20 /* EOI */ 70 | pop %ds 71 | pop %es 72 | popl %eax 73 | popl %ebx 74 | popl %ecx 75 | popl %edx 76 | addl $4,%esp # jump over _table_list entry 77 | iret 78 | 79 | jmp_table: 80 | .long modem_status,write_char,read_char,line_status 81 | 82 | .align 2 83 | modem_status: 84 | addl $6,%edx /* clear intr by reading modem status reg */ 85 | inb %dx,%al 86 | ret 87 | 88 | .align 2 89 | line_status: 90 | addl $5,%edx /* clear intr by reading line status reg. */ 91 | inb %dx,%al 92 | ret 93 | 94 | .align 2 95 | read_char: 96 | inb %dx,%al 97 | movl %ecx,%edx 98 | subl $table_list,%edx 99 | shrl $3,%edx 100 | movl (%ecx),%ecx # read-queue 101 | movl head(%ecx),%ebx 102 | movb %al,buf(%ecx,%ebx) 103 | incl %ebx 104 | andl $size-1,%ebx 105 | cmpl tail(%ecx),%ebx 106 | je 1f 107 | movl %ebx,head(%ecx) 108 | 1: pushl %edx 109 | call do_tty_interrupt 110 | addl $4,%esp 111 | ret 112 | 113 | .align 2 114 | write_char: 115 | movl 4(%ecx),%ecx # write-queue 116 | movl head(%ecx),%ebx 117 | subl tail(%ecx),%ebx 118 | andl $size-1,%ebx # nr chars in queue 119 | je write_buffer_empty 120 | cmpl $startup,%ebx 121 | ja 1f 122 | movl proc_list(%ecx),%ebx # wake up sleeping process 123 | testl %ebx,%ebx # is there any? 124 | je 1f 125 | movl $0,(%ebx) 126 | 1: movl tail(%ecx),%ebx 127 | movb buf(%ecx,%ebx),%al 128 | outb %al,%dx 129 | incl %ebx 130 | andl $size-1,%ebx 131 | movl %ebx,tail(%ecx) 132 | cmpl head(%ecx),%ebx 133 | je write_buffer_empty 134 | ret 135 | .align 2 136 | write_buffer_empty: 137 | movl proc_list(%ecx),%ebx # wake up sleeping process 138 | testl %ebx,%ebx # is there any? 139 | je 1f 140 | movl $0,(%ebx) 141 | 1: incl %edx 142 | inb %dx,%al 143 | jmp 1f 144 | 1: jmp 1f 145 | 1: andb $0xd,%al /* disable transmit interrupt */ 146 | outb %al,%dx 147 | ret 148 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/chr_drv/serial.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/serial.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * serial.c 9 | * 10 | * This module implements the rs232 io functions 11 | * void rs_write(struct tty_struct * queue); 12 | * void rs_init(void); 13 | * and all interrupts pertaining to serial IO. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define WAKEUP_CHARS (TTY_BUF_SIZE/4) 22 | 23 | extern void rs1_interrupt(void); 24 | extern void rs2_interrupt(void); 25 | 26 | static void init(int port) 27 | { 28 | outb_p(0x80,port+3); /* set DLAB of line control reg */ 29 | outb_p(0x30,port); /* LS of divisor (48 -> 2400 bps */ 30 | outb_p(0x00,port+1); /* MS of divisor */ 31 | outb_p(0x03,port+3); /* reset DLAB */ 32 | outb_p(0x0b,port+4); /* set DTR,RTS, OUT_2 */ 33 | outb_p(0x0d,port+1); /* enable all intrs but writes */ 34 | (void)inb(port); /* read data port to reset things (?) */ 35 | } 36 | 37 | void rs_init(void) 38 | { 39 | set_intr_gate(0x24,rs1_interrupt); 40 | set_intr_gate(0x23,rs2_interrupt); 41 | init(tty_table[1].read_q.data); 42 | init(tty_table[2].read_q.data); 43 | outb(inb_p(0x21)&0xE7,0x21); 44 | } 45 | 46 | /* 47 | * This routine gets called when tty_write has put something into 48 | * the write_queue. It must check wheter the queue is empty, and 49 | * set the interrupt register accordingly 50 | * 51 | * void _rs_write(struct tty_struct * tty); 52 | */ 53 | void rs_write(struct tty_struct * tty) 54 | { 55 | cli(); 56 | if (!EMPTY(tty->write_q)) 57 | outb(inb_p(tty->write_q.data+1)|0x02,tty->write_q.data+1); 58 | sti(); 59 | } 60 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/math/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for the FREAX-kernel character device drivers. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-m elf_i386 -x 13 | CC =gcc-3.4 -march=i386 14 | CFLAGS =-m32 -g -Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../../include 16 | CPP =gcc-3.4 -E -nostdinc -I../../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = math_emulate.o 28 | 29 | math.a: $(OBJS) 30 | $(AR) rcs math.a $(OBJS) 31 | sync 32 | 33 | clean: 34 | rm -f core *.o *.a tmp_make 35 | for i in *.c;do rm -f `basename $$i .c`.s;done 36 | 37 | dep: 38 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 39 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 40 | $(CPP) -M $$i;done) >> tmp_make 41 | cp tmp_make Makefile 42 | 43 | ### Dependencies: 44 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/math/math_emulate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/math/math_emulate.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This directory should contain the math-emulation code. 9 | * Currently only results in a signal. 10 | */ 11 | 12 | #include 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | void math_emulate(long edi, long esi, long ebp, long sys_call_ret, 19 | long eax,long ebx,long ecx,long edx, 20 | unsigned short fs,unsigned short es,unsigned short ds, 21 | unsigned long eip,unsigned short cs,unsigned long eflags, 22 | unsigned short ss, unsigned long esp) 23 | { 24 | unsigned char first, second; 25 | 26 | /* 0x0007 means user code space */ 27 | if (cs != 0x000F) { 28 | printk("math_emulate: %04x:%08x\n\r",cs,eip); 29 | panic("Math emulation needed in kernel"); 30 | } 31 | first = get_fs_byte((char *)((*&eip)++)); 32 | second = get_fs_byte((char *)((*&eip)++)); 33 | printk("%04x:%08x %02x %02x\n\r",cs,eip-2,first,second); 34 | current->signal |= 1<<(SIGFPE-1); 35 | } 36 | 37 | void math_error(void) 38 | { 39 | __asm__("fnclex"); 40 | if (last_task_used_math) 41 | last_task_used_math->signal |= 1<<(SIGFPE-1); 42 | } 43 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/mktime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/mktime.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | /* 10 | * This isn't the library routine, it is only used in the kernel. 11 | * as such, we don't care about years<1970 etc, but assume everything 12 | * is ok. Similarly, TZ etc is happily ignored. We just do everything 13 | * as easily as possible. Let's find something public for the library 14 | * routines (although I think minix times is public). 15 | */ 16 | /* 17 | * PS. I hate whoever though up the year 1970 - couldn't they have gotten 18 | * a leap-year instead? I also hate Gregorius, pope or no. I'm grumpy. 19 | */ 20 | #define MINUTE 60 21 | #define HOUR (60*MINUTE) 22 | #define DAY (24*HOUR) 23 | #define YEAR (365*DAY) 24 | 25 | /* interestingly, we assume leap-years */ 26 | static int month[12] = { 27 | 0, 28 | DAY*(31), 29 | DAY*(31+29), 30 | DAY*(31+29+31), 31 | DAY*(31+29+31+30), 32 | DAY*(31+29+31+30+31), 33 | DAY*(31+29+31+30+31+30), 34 | DAY*(31+29+31+30+31+30+31), 35 | DAY*(31+29+31+30+31+30+31+31), 36 | DAY*(31+29+31+30+31+30+31+31+30), 37 | DAY*(31+29+31+30+31+30+31+31+30+31), 38 | DAY*(31+29+31+30+31+30+31+31+30+31+30) 39 | }; 40 | 41 | long kernel_mktime(struct tm * tm) 42 | { 43 | long res; 44 | int year; 45 | 46 | year = tm->tm_year - 70; 47 | /* magic offsets (y+1) needed to get leapyears right.*/ 48 | res = YEAR*year + DAY*((year+1)/4); 49 | res += month[tm->tm_mon]; 50 | /* and (y+2) here. If it wasn't a leap-year, we have to adjust */ 51 | if (tm->tm_mon>1 && ((year+2)%4)) 52 | res -= DAY; 53 | res += DAY*(tm->tm_mday-1); 54 | res += HOUR*tm->tm_hour; 55 | res += MINUTE*tm->tm_min; 56 | res += tm->tm_sec; 57 | return res; 58 | } 59 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/panic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/panic.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * This function is used through-out the kernel (includeinh mm and fs) 9 | * to indicate a major problem. 10 | */ 11 | #define PANIC 12 | 13 | #include 14 | #include 15 | 16 | void sys_sync(void); /* it's really int */ 17 | 18 | volatile void panic(const char * s) 19 | { 20 | printk("Kernel panic: %s\n\r",s); 21 | if (current == task[0]) 22 | printk("In swapper task - not syncing\n\r"); 23 | else 24 | sys_sync(); 25 | for(;;); 26 | } 27 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/printk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/printk.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * When in kernel-mode, we cannot use printf, as fs is liable to 9 | * point to 'interesting' things. Make a printf with fs-saving, and 10 | * all is well. 11 | */ 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | static char buf[1024]; 18 | 19 | extern int vsprintf(char * buf, const char * fmt, va_list args); 20 | 21 | int printk(const char *fmt, ...) 22 | { 23 | va_list args; 24 | int i; 25 | 26 | va_start(args, fmt); 27 | i=vsprintf(buf,fmt,args); 28 | va_end(args); 29 | __asm__("push %%fs\n\t" 30 | "push %%ds\n\t" 31 | "pop %%fs\n\t" 32 | "pushl %0\n\t" 33 | "pushl $buf\n\t" 34 | "pushl $0\n\t" 35 | "call tty_write\n\t" 36 | "addl $8,%%esp\n\t" 37 | "popl %0\n\t" 38 | "pop %%fs" 39 | ::"r" (i):"ax","cx","dx"); 40 | return i; 41 | } 42 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/kernel/signal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/kernel/signal.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | volatile void do_exit(int error_code); 14 | 15 | int sys_sgetmask() 16 | { 17 | return current->blocked; 18 | } 19 | 20 | int sys_ssetmask(int newmask) 21 | { 22 | int old=current->blocked; 23 | 24 | current->blocked = newmask & ~(1<<(SIGKILL-1)); 25 | return old; 26 | } 27 | 28 | static inline void save_old(char * from,char * to) 29 | { 30 | int i; 31 | 32 | verify_area(to, sizeof(struct sigaction)); 33 | for (i=0 ; i< sizeof(struct sigaction) ; i++) { 34 | put_fs_byte(*from,to); 35 | from++; 36 | to++; 37 | } 38 | } 39 | 40 | static inline void get_new(char * from,char * to) 41 | { 42 | int i; 43 | 44 | for (i=0 ; i< sizeof(struct sigaction) ; i++) 45 | *(to++) = get_fs_byte(from++); 46 | } 47 | 48 | int sys_signal(int signum, long handler, long restorer) 49 | { 50 | struct sigaction tmp; 51 | 52 | if (signum<1 || signum>32 || signum==SIGKILL) 53 | return -1; 54 | tmp.sa_handler = (void (*)(int)) handler; 55 | tmp.sa_mask = 0; 56 | tmp.sa_flags = SA_ONESHOT | SA_NOMASK; 57 | tmp.sa_restorer = (void (*)(void)) restorer; 58 | handler = (long) current->sigaction[signum-1].sa_handler; 59 | current->sigaction[signum-1] = tmp; 60 | return handler; 61 | } 62 | 63 | int sys_sigaction(int signum, const struct sigaction * action, 64 | struct sigaction * oldaction) 65 | { 66 | struct sigaction tmp; 67 | 68 | if (signum<1 || signum>32 || signum==SIGKILL) 69 | return -1; 70 | tmp = current->sigaction[signum-1]; 71 | get_new((char *) action, 72 | (char *) (signum-1+current->sigaction)); 73 | if (oldaction) 74 | save_old((char *) &tmp,(char *) oldaction); 75 | if (current->sigaction[signum-1].sa_flags & SA_NOMASK) 76 | current->sigaction[signum-1].sa_mask = 0; 77 | else 78 | current->sigaction[signum-1].sa_mask |= (1<<(signum-1)); 79 | return 0; 80 | } 81 | 82 | void do_signal(long signr,long eax, long ebx, long ecx, long edx, 83 | long fs, long es, long ds, 84 | long eip, long cs, long eflags, 85 | unsigned long * esp, long ss) 86 | { 87 | unsigned long sa_handler; 88 | long old_eip=eip; 89 | struct sigaction * sa = current->sigaction + signr - 1; 90 | int longs; 91 | unsigned long * tmp_esp; 92 | 93 | sa_handler = (unsigned long) sa->sa_handler; 94 | if (sa_handler==1) 95 | return; 96 | if (!sa_handler) { 97 | if (signr==SIGCHLD) 98 | return; 99 | else 100 | do_exit(1<<(signr-1)); 101 | } 102 | if (sa->sa_flags & SA_ONESHOT) 103 | sa->sa_handler = NULL; 104 | *(&eip) = sa_handler; 105 | longs = (sa->sa_flags & SA_NOMASK)?7:8; 106 | *(&esp) -= longs; 107 | verify_area(esp,longs*4); 108 | tmp_esp=esp; 109 | put_fs_long((long) sa->sa_restorer,tmp_esp++); 110 | put_fs_long(signr,tmp_esp++); 111 | if (!(sa->sa_flags & SA_NOMASK)) 112 | put_fs_long(current->blocked,tmp_esp++); 113 | put_fs_long(eax,tmp_esp++); 114 | put_fs_long(ecx,tmp_esp++); 115 | put_fs_long(edx,tmp_esp++); 116 | put_fs_long(eflags,tmp_esp++); 117 | put_fs_long(old_eip,tmp_esp++); 118 | current->blocked |= sa->sa_mask; 119 | } 120 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for some libs needed in the kernel. 3 | # 4 | # Note! Dependencies are done automagically by 'make dep', which also 5 | # removes any old dependencies. DON'T put your own dependencies here 6 | # unless it's something special (ie not a .c file). 7 | # 8 | 9 | AR =ar 10 | AS =as 11 | LD =ld 12 | LDFLAGS =-m elf_i386 -x 13 | CC =gcc-3.4 -march=i386 14 | CFLAGS =-m32 -g -Wall -O -fstrength-reduce -fomit-frame-pointer \ 15 | -finline-functions -nostdinc -I../include 16 | CPP =gcc-3.4 -E -nostdinc -I../include 17 | 18 | .c.s: 19 | $(CC) $(CFLAGS) \ 20 | -S -o $*.s $< 21 | .s.o: 22 | $(AS) -o $*.o $< 23 | .c.o: 24 | $(CC) $(CFLAGS) \ 25 | -c -o $*.o $< 26 | 27 | OBJS = ctype.o _exit.o open.o close.o errno.o write.o dup.o setsid.o \ 28 | execve.o wait.o string.o malloc.o 29 | 30 | lib.a: $(OBJS) 31 | $(AR) rcs lib.a $(OBJS) 32 | sync 33 | 34 | clean: 35 | rm -f core *.o *.a tmp_make 36 | for i in *.c;do rm -f `basename $$i .c`.s;done 37 | 38 | dep: 39 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 40 | (for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \ 41 | $(CPP) -M $$i;done) >> tmp_make 42 | cp tmp_make Makefile 43 | 44 | ### Dependencies: 45 | _exit.s _exit.o : _exit.c ../include/unistd.h ../include/sys/stat.h \ 46 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 47 | ../include/utime.h 48 | close.s close.o : close.c ../include/unistd.h ../include/sys/stat.h \ 49 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 50 | ../include/utime.h 51 | ctype.s ctype.o : ctype.c ../include/ctype.h 52 | dup.s dup.o : dup.c ../include/unistd.h ../include/sys/stat.h \ 53 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 54 | ../include/utime.h 55 | errno.s errno.o : errno.c 56 | execve.s execve.o : execve.c ../include/unistd.h ../include/sys/stat.h \ 57 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 58 | ../include/utime.h 59 | malloc.s malloc.o : malloc.c ../include/linux/kernel.h ../include/linux/mm.h \ 60 | ../include/asm/system.h 61 | open.s open.o : open.c ../include/unistd.h ../include/sys/stat.h \ 62 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 63 | ../include/utime.h ../include/stdarg.h 64 | setsid.s setsid.o : setsid.c ../include/unistd.h ../include/sys/stat.h \ 65 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 66 | ../include/utime.h 67 | string.s string.o : string.c ../include/string.h 68 | wait.s wait.o : wait.c ../include/unistd.h ../include/sys/stat.h \ 69 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 70 | ../include/utime.h ../include/sys/wait.h 71 | write.s write.o : write.c ../include/unistd.h ../include/sys/stat.h \ 72 | ../include/sys/types.h ../include/sys/times.h ../include/sys/utsname.h \ 73 | ../include/utime.h 74 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/_exit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/_exit.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | volatile void _exit(int exit_code) 11 | { 12 | __asm__("int $0x80"::"a" (__NR_exit),"b" (exit_code)); 13 | } 14 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/close.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/close.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall1(int,close,int,fd) 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/ctype.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/ctype.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #include 8 | 9 | char _ctmp; 10 | unsigned char _ctype[] = {0x00, /* EOF */ 11 | _C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */ 12 | _C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */ 13 | _C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */ 14 | _C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */ 15 | _S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */ 16 | _P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */ 17 | _D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */ 18 | _D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */ 19 | _P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */ 20 | _U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */ 21 | _U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */ 22 | _U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */ 23 | _P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */ 24 | _L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */ 25 | _L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */ 26 | _L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */ 27 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */ 28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */ 29 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160-175 */ 30 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176-191 */ 31 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192-207 */ 32 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208-223 */ 33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224-239 */ 34 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* 240-255 */ 35 | 36 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/dup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/dup.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall1(int,dup,int,fd) 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/errno.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/errno.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | int errno; 8 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/execve.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/execve.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall3(int,execve,const char *,file,char **,argv,char **,envp) 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/open.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/open.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | #include 10 | 11 | int open(const char * filename, int flag, ...) 12 | { 13 | register int res; 14 | va_list arg; 15 | 16 | va_start(arg,flag); 17 | __asm__("int $0x80" 18 | :"=a" (res) 19 | :"0" (__NR_open),"b" (filename),"c" (flag), 20 | "d" (va_arg(arg,int))); 21 | if (res>=0) 22 | return res; 23 | errno = -res; 24 | return -1; 25 | } 26 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/setsid.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/setsid.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall0(pid_t,setsid) 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/string.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/string.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #ifndef __GNUC__ 8 | #error I want gcc! 9 | #endif 10 | 11 | #define extern 12 | #define inline 13 | #define __LIBRARY__ 14 | #include 15 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/wait.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/wait.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | #include 10 | 11 | _syscall3(pid_t,waitpid,pid_t,pid,int *,wait_stat,int,options) 12 | 13 | pid_t wait(int * wait_stat) 14 | { 15 | return waitpid(-1,wait_stat,0); 16 | } 17 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/lib/write.c: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/lib/write.c 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | #define __LIBRARY__ 8 | #include 9 | 10 | _syscall3(int,write,int,fd,const char *,buf,off_t,count) 11 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/mm/Makefile: -------------------------------------------------------------------------------- 1 | CC =gcc-3.4 -march=i386 2 | CFLAGS =-m32 -g -Wall -O -fstrength-reduce -fomit-frame-pointer \ 3 | -finline-functions -nostdinc -I../include 4 | AS =as --32 5 | AR =ar 6 | LD =ld 7 | LDFLAGS =-m elf_i386 8 | CPP =gcc-3.4 -E -nostdinc -I../include 9 | 10 | .c.o: 11 | $(CC) $(CFLAGS) \ 12 | -c -o $*.o $< 13 | .s.o: 14 | $(AS) -o $*.o $< 15 | .c.s: 16 | $(CC) $(CFLAGS) \ 17 | -S -o $*.s $< 18 | 19 | OBJS = memory.o page.o 20 | 21 | all: mm.o 22 | 23 | mm.o: $(OBJS) 24 | $(LD) -m elf_i386 -r -o mm.o $(OBJS) 25 | 26 | clean: 27 | rm -f core *.o *.a tmp_make 28 | for i in *.c;do rm -f `basename $$i .c`.s;done 29 | 30 | dep: 31 | sed '/\#\#\# Dependencies/q' < Makefile > tmp_make 32 | (for i in *.c;do $(CPP) -M $$i;done) >> tmp_make 33 | cp tmp_make Makefile 34 | 35 | ### Dependencies: 36 | memory.o: memory.c ../include/signal.h ../include/sys/types.h \ 37 | ../include/asm/system.h ../include/linux/sched.h \ 38 | ../include/linux/head.h ../include/linux/fs.h ../include/linux/mm.h \ 39 | ../include/linux/kernel.h 40 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux-0.1.1/mm/page.s: -------------------------------------------------------------------------------- 1 | /* 2 | * linux/mm/page.s 3 | * 4 | * (C) 1991 Linus Torvalds 5 | */ 6 | 7 | /* 8 | * page.s contains the low-level page-exception code. 9 | * the real work is done in mm.c 10 | */ 11 | 12 | .globl page_fault 13 | 14 | page_fault: 15 | xchgl %eax,(%esp) 16 | pushl %ecx 17 | pushl %edx 18 | push %ds 19 | push %es 20 | push %fs 21 | movl $0x10,%edx 22 | mov %dx,%ds 23 | mov %dx,%es 24 | mov %dx,%fs 25 | movl %cr2,%edx 26 | pushl %edx 27 | pushl %eax 28 | testl $1,%eax 29 | jne 1f 30 | call do_no_page 31 | jmp 2f 32 | 1: call do_wp_page 33 | 2: addl $8,%esp 34 | pop %fs 35 | pop %es 36 | pop %ds 37 | popl %edx 38 | popl %ecx 39 | popl %eax 40 | iret 41 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux_0.1.1_注释/Linux内核完全注释(修正版v3.0) (1).docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/linux_0.1.1_注释/Linux内核完全注释(修正版v3.0) (1).docx -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux_0.1.1_注释/Linux内核完全注释(修正版v3.0).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/linux-0.1.1-labs/linux_0.1.1_注释/Linux内核完全注释(修正版v3.0).pdf -------------------------------------------------------------------------------- /linux-0.1.1-labs/linux_0.1.1_注释/README.md: -------------------------------------------------------------------------------- 1 | 2 | linux_0.1.1_注释 3 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/问题排查记录/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /linux-0.1.1-labs/问题排查记录/系统调用/README.md: -------------------------------------------------------------------------------- 1 | # m(address) 的寻址问题 2 | 3 | > m(address) 中填写的变量寻址时: 4 | > - 如果该引用在栈中(即在方法中定义),则按照ss:address的方式进行寻址。 5 | > 6 | > - 如果该内存在数据段中(即为全局变量),则将按照 ds:address 的方式进行寻址。 7 | > 8 | > 因此,如果要对数据段中的数据进行操作时,如果修改了ds,要格外注意当前的 address 是否属于当前 ds 段。 9 | 10 | ## 示例 11 | 如:将 用户空间数据 拷贝到 内核空间数据: 12 | 13 | 错误做法,赋值edi前,就将ds修改,导致错误(buf 为内核空间): 14 | 15 | ```c 16 | static char buf[24]; 17 | 18 | int sys_iam(const char * name,int name_size){ 19 | printk("Step 1 : Sys_iam begin. name_address: %d , buf_address: %d , name_size: %d,buf: %s.\r\n", name,buf, name_size,buf); 20 | __asm__( 21 | // 赋值edi前,就将ds修改,导致错误 22 | "movl $0x17,%%edx\n\t" 23 | "mov %%dx,%%ds\n\t" 24 | "movl %0,%%edi\n\t" 25 | "movl %1,%%esi\n\t" 26 | // copy 27 | "cld\n\t" 28 | "rep\n\t" 29 | "movsb\n\t" 30 | "movl $0x10,%%edx\n\t" 31 | "mov %%dx,%%ds\n\t" 32 | :: 33 | "m"(buf),"m"(name),"c"(name_size)); 34 | 35 | printk("Step 2 : Sys_iam end. buf: %s .\r\n", buf); 36 | return 1; 37 | } 38 | ``` 39 | 40 | 正确做法,赋值edi后,再修改ds,没有错误(buf 为内核空间): 41 | 42 | ```c 43 | static char buf[24]; 44 | 45 | int sys_iam(const char * name,int name_size){ 46 | printk("Step 1 : Sys_iam begin. name_address: %d , buf_address: %d , name_size: %d,buf: %s.\r\n", name,buf, name_size,buf); 47 | __asm__( 48 | // 赋值edi后,再修改ds,没有错误 49 | "movl %0,%%edi\n\t" 50 | "movl $0x17,%%edx\n\t" 51 | "mov %%dx,%%ds\n\t" 52 | "movl %1,%%esi\n\t" 53 | // copy 54 | "cld\n\t" 55 | "rep\n\t" 56 | "movsb\n\t" 57 | "movl $0x10,%%edx\n\t" 58 | "mov %%dx,%%ds\n\t" 59 | :: 60 | "m"(buf_address),"m"(name),"c"(name_size)); 61 | 62 | printk("Step 2 : Sys_iam end. buf: %s .\r\n", buf); 63 | return 1; 64 | } 65 | ``` 66 | 67 | 或者也可以这样(即将`buf_address`先拷贝到栈中): 68 | ```c 69 | int sys_iam(const char * name,int name_size){ 70 | printk("Step 1 : Sys_iam begin. name_address: %d , buf_address: %d , name_size: %d,buf: %s.\r\n", name,buf, name_size,buf); 71 | //将`buf_address`先拷贝到栈中 72 | int buf_address = buf; 73 | __asm__( 74 | // src 75 | "movl $0x17,%%edx\n\t" 76 | "mov %%dx,%%ds\n\t" 77 | "movl %0,%%edi\n\t" 78 | "movl %1,%%esi\n\t" 79 | // copy 80 | "cld\n\t" 81 | "rep\n\t" 82 | "movsb\n\t" 83 | "movl $0x10,%%edx\n\t" 84 | "mov %%dx,%%ds\n\t" 85 | :: 86 | "m"(buf_address),"m"(name),"c"(name_size)); 87 | 88 | printk("Step 2 : Sys_iam end. buf: %s .\r\n", buf); 89 | return 1; 90 | } 91 | ``` 92 | -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/Dennis_Ritchie.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/Dennis_Ritchie.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/Ken_Thompson.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/Ken_Thompson.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/computer_1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/computer_1.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/computer_2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/computer_2.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/gnu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/gnu.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/go.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/go.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/linux.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/linux.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/memory_depart.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/memory_depart.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/minix.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/minix.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/os_desc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/os_desc.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/os_loc.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/os_loc.jpg -------------------------------------------------------------------------------- /theory/0. 操作系统历史/README.assets/process_of_c2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/0. 操作系统历史/README.assets/process_of_c2.jpg -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/bios_and_bootsect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/bios_and_bootsect.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/head.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/image_after_head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/image_after_head.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/image_after_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/image_after_main.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/image_after_setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/image_after_setup.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/image_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/image_s.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/page_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/page_p.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/processes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/processes.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/setup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/setup.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/why_move_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/why_move_code.png -------------------------------------------------------------------------------- /theory/1. 启动/README.assets/why_start_from_0x7c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/1. 启动/README.assets/why_start_from_0x7c.png -------------------------------------------------------------------------------- /theory/10. 大数据/README.md: -------------------------------------------------------------------------------- 1 | # 大数据发展 2 | ## Google三架马车 3 | - GFS:分布式文件系统 4 | - MapReduce:分布式计算,将大任务拆解成可以在多台机器上执行的小任务 5 | - BigTable:Nosql 6 | ## Hadoop(雅虎开源) 7 | - HDFS 8 | - MapReduce 9 | - YARN 10 | ## Hive 11 | 将SQL解析成MapReduce任务,运行在HDSF上。 12 | ## Spark 13 | - RDD(弹性分布式数据集) 14 | - 内存计算(速度快,但成本较磁盘高) 15 | - DAG(MapReduce的Plus版本,根据RDD宽窄依赖划分Stage,多个Stage构成DAG,每个Stage为多个并行任务) 16 | - SparkSQL(基于RDD和DAG) 17 | - SparkStream(微批处理) 18 | - SparkMLlib(丰富的机器学习库) 19 | - SparkGraphX(图计算库) 20 | -------------------------------------------------------------------------------- /theory/2. 中断与系统调用/README.md: -------------------------------------------------------------------------------- 1 | ## 中断的概念及初期实现 2 | - [点击跳转到中断与系统调用](https://github.com/lcdzhao/operating_system/tree/master/theory/%E9%99%841%EF%BC%9A%E7%A1%AC%E4%BB%B6%E7%9B%B8%E5%85%B3/%E4%B8%AD%E6%96%AD%E4%B8%8E%E7%B3%BB%E7%BB%9F%E8%B0%83%E7%94%A8) 3 | 4 | ## 中断的发展 5 | - [深入理解Linux中断机制](https://blog.csdn.net/orangeboyye/article/details/125747908?spm=1001.2014.3001.5502) 6 | -------------------------------------------------------------------------------- /theory/3. 进程/1. 进程定义及诞生原因/README.md: -------------------------------------------------------------------------------- 1 | # 什么是进程 2 | 进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础。 3 | 4 | 在早期面向进程设计的计算机结构中,进程是程序的基本执行实体;在当代面向线程设计的计算机结构中,进程是线程的容器。 5 | 6 | 程序是指令、数据及其组织形式的描述,进程是程序的实体。 7 | 8 | # 进程诞生的原因 9 | 最早的操作系统是单道批处理的,但是经常会出现cpu要等待IO的情况,从而降低了CPU的利用率。 10 | 11 | 后来在Bell(贝尔实验室), MIT(麻省理工学院人工智能实验室), GE(General Electric,通用电气)联合建立Multics操作系统 引入多道批处理,而程序在执行的过程中又会因为共享资源而导致程序在执行的过程中相互限制; 12 | 13 | 所有后来引入进程用来给程序提供一个抽象的概念,他能申请道系统资源并且独立给程序提供资源,从而解决原来的程序之间因为资源共享而相互影响的问题。这样就可以提高系统资源的隔离性和系统的处理能力 14 | -------------------------------------------------------------------------------- /theory/3. 进程/10. 线程状态/README.md: -------------------------------------------------------------------------------- 1 | # 线程的状态有哪几种 2 | 这个问题相信很多人在面试中都被问过,看起来是一个非常简单的问题,但是实际上这个问题并没有表面上这么简单,因为这个问题的答案从不同层次来回答都是不一样的。 3 | 4 | ## 操作系统源码层面 5 | 操作系统的代码直接对接底层硬件,其运行在业务代码与硬件之间(在《Unix编程艺术》中被称为胶和层),故其在源码层面定义的线程状态侧重于如何在这个胶和层描述清楚一个线程,故其几个核心的状态为: 6 | 7 | - Running(对应教科书中的 Ready 和 Running) 8 | - Interruptable 9 | - Uninterruptable 10 | - Stop 11 | - Zombie 12 | 13 | ## 教科书层面 14 | 教科书层面更倾向于给读者将一个线程的运行过程描述清楚,故其更加偏向于容易理解,其定义的状态与操作系统源码中定义的线程状态并不一一对应,具体为: 15 | 16 | - Create (在高级语言中刚创建还没start()的线程并未创建出操作系统中的线程,start()时才开始创建操作系统的线程并运行。操作系统初始化中的线程状态为Uninterruptable,初始化结束后状态即改为Running,开始参与调度) 17 | - Ready 18 | - Running 19 | - Blocked (对应操作系统中的Interruptable及Uninterruptable) 20 | - Terminate 21 | 22 | 23 | ## 高级语言层面(以JAVA为例) 24 | 高级语言层面,以Java为例,其为操作系统与程序员之间的桥梁,即要能够与操作系统的状态有一定的对应关系,又要屏蔽掉一些操作系统的复杂度,让程序员更易理解,故其与操作系统源码中定义的线程状态也不一一对应,具体为: 25 | 26 | - New (刚New出来还没start()的线程还未创建出操作系统中的线程,start()时才开始创建操作系统的线程并运行。操作系统初始化中的线程状态为Uninterruptable,初始化结束后状态即改为Running,开始参与调度) 27 | - Running (包含操作系统中的Running及IO产生的Interruptable与Uninterruptable,由于在java层面并不关心操作系统层面的资源问题,仅关心语言层面定义的Blocked(锁阻塞)及Wait、Time_wait,故操作系统IO产生的Interruptable与Uninterruptable被Java视为Running) 28 | - Wait (反应到操作系统层面为 Interruptable) 29 | - Timed_wait (反应到操作系统层面为 Interruptable) 30 | - Blocked (未获取到Java语言层面的锁,和操作系统层管理的硬件资源之间没有直接关系,反应到操作系统层面为 Interruptable) 31 | - Terminate 32 | -------------------------------------------------------------------------------- /theory/3. 进程/11. iowait/README.md: -------------------------------------------------------------------------------- 1 | https://zhuanlan.zhihu.com/p/407333624 2 | -------------------------------------------------------------------------------- /theory/3. 进程/2. 进程结构/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/2. 进程结构/README.assets/simple_struct_of_task.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/2. 进程结构/README.assets/simple_struct_of_task.png -------------------------------------------------------------------------------- /theory/3. 进程/2. 进程结构/README.assets/structure_of_task.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/2. 进程结构/README.assets/structure_of_task.png -------------------------------------------------------------------------------- /theory/3. 进程/2. 进程结构/README.md: -------------------------------------------------------------------------------- 1 | # 进程结构 2 | ## Linux进程地址空间与进程内存布局详解 3 | [Linux进程地址空间与进程内存布局详解](https://zhuanlan.zhihu.com/p/348171413?utm_id=0) 4 | ## 进程结构 5 | ![simple_struct_of_task](README.assets/simple_struct_of_task.png) 6 | 7 | ##### 进程结构图说明 8 | 1)用户态虚拟内存: 9 | 10 | - 页表目录(虚拟内存的映射表):页表目录的起始物理地址存放在 `task_struct -> tss -> cr3` 11 | 12 | - `LDT`(代码段、数据段的段描述符): 对应 `task_struct -> ldt[3]`,其起始物理地址存放在 `task_struct -> tss -> ldt` 13 | 14 | 2)内核态内核栈起始位置: 15 | - 内核栈的起始位置:存放在 `task_struct -> tss -> esp0` 16 | 17 | 3)进程相关运行信息: 18 | 19 | - `task_struct`:对应 `task_struct` 本身,在Linux中内核空间有一个变量`task_struct *current`一直对应着当前CPU正在运行的进程的`task_struct` 20 | 21 | - cs、ss、es...等寄存器的值:存放在 `task_struct -> tss`中的各个项 22 | 23 | ##### 如何让CPU运行进程 24 | 结合进程结构图说明,我们可以看出,要让CPU执行某个进程时,需要: 25 | 26 | 1)加载用户态虚拟内存寻址相关的信息: 27 | 28 | - 将`LDT`在GDT中的偏移地址通过`lldt`指令放到`LDTR`寄存器中去(用于硬件保护模式寻址) 29 | 30 | - 将`TSS`中存放的当前进程的页表目录起始地址放入 `CR3` 寄存器中,用于 CPU 找到当前进程虚拟内存空间与物理内存的映射。(例外:0号进程首次初始化及运行时不需要,因为`CR3`已经在`setup`开启分页模式时已经指定。) 31 | 32 | 2)定位进程内核栈: 33 | 34 | - 将`TSS`在GDT中的偏移地址通过`ltr`指令放到`TR`寄存器中去(用TSS中的esp0索引内核栈起始位置) 35 | 36 | 3)加载进程运行时信息: 37 | 38 | - 将内核空间空间的current指向要运行的进程,便于操作系统对于当前进程的状态随时进行查询与修改 39 | 40 | - 将进程运行过程中保存的各个寄存器的值都加载到相应的寄存器中去(例外:0号进程首次初始化及运行时不需要,因为cs,eip等寄存器已经是其当前的代码位置,且其他寄存器的值也已经加载到寄存器中了)。 41 | 42 | ## 对比通过TSS切换线程与内核栈切换的代码的异同 43 | 通过对比通过TSS切换线程与内核栈切换的代码的异同,来加深对于进程结构的理解: 44 | [点击跳转:对比通过TSS切换线程与内核栈切换的代码的异同](https://github.com/lcdzhao/operating_system/blob/master/linux-0.1.1-labs/labs/lab_4_switch_of_process/README.md#%E5%AF%B9%E6%AF%94%E9%80%9A%E8%BF%87tss%E5%88%87%E6%8D%A2%E7%BA%BF%E7%A8%8B%E4%B8%8E%E5%86%85%E6%A0%B8%E6%A0%88%E5%88%87%E6%8D%A2%E7%9A%84%E4%BB%A3%E7%A0%81%E7%9A%84%E5%BC%82%E5%90%8C) 45 | 46 | 47 | ### 进程运行时结构与内存详细图解 48 | 49 | ![structure_of_task](README.assets/structure_of_task.png) 50 | 51 | ## 关于进程结构的一些问题 52 | - **为什么要将内核空间投射到用户虚拟地址**? 53 | 54 | 因为 32 位操作系统总共就只有4个G内存,如果不将内核空间投射到用户虚拟地址空间的话,用户进程(从概念上也会误导程序员)会误以为自己拥有4GB空间可以占用。于是将4GB空间全部占用,而这4GB空间又会映射到真实的物理地址空间。而真实的物理地址空间最大也只有4GB,而且一部分已经用于存放内核代码及数据。因此不能够让用户占满4GB。最优雅的解决方案便是:将内核空间直接映射到虚拟内存中去,用户进程访问时直接报错。这样直观上就能让操作系统用户既能感受到 完整的虚拟内存 的大小,又不会去试图占满整个内存空间。 55 | 56 | - **为啥内核空间要映射到最高的一部分内存**? 57 | 58 | 便于用户使用,从0去使用地址肯定会让用户更加舒服,也符合用户使用内存地址的直觉。 59 | 60 | - **Linux 0.11 有没有这样去将内核空间映射到用户虚拟地址空间中去**? 61 | 62 | 没有,因为Linux 0.11的策略是将 4GB 空间划分为很多个64MB的空间(这种划分方式是典型的第三代计算机刚出现时操作系统普遍的一种划分方式,详见[第三台计算机——多道技术](https://github.com/lcdzhao/operating_system/tree/master/theory/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/0.%20%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F%E5%8E%86%E5%8F%B2#%E5%A4%9A%E9%81%93%E6%8A%80%E6%9C%AF))。 每个进程最多占用64MB空间。故不存在有进程占满物理地址空间的情况。所以也就没有必要让用户意识到内核内核空间的存在。所以Linux 0.11 的每个进程多多64MB的虚拟地址空间均为用户空间。 63 | -------------------------------------------------------------------------------- /theory/3. 进程/4. fork/README.assets/PBC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/4. fork/README.assets/PBC.png -------------------------------------------------------------------------------- /theory/3. 进程/4. fork/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/4. fork/README.assets/copy_on_write.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/4. fork/README.assets/copy_on_write.png -------------------------------------------------------------------------------- /theory/3. 进程/4. fork/README.assets/copy_page_tables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/4. fork/README.assets/copy_page_tables.png -------------------------------------------------------------------------------- /theory/3. 进程/5. 进程生命周期及调度/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/do_signal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/do_signal.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/kill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/kill.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/r_sig_d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/r_sig_d.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/sa_restorer1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/sa_restorer1.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/sa_restorer2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/sa_restorer2.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/sigs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/sigs.png -------------------------------------------------------------------------------- /theory/3. 进程/6. 进程信号处理/README.assets/stack_of_do_signal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/6. 进程信号处理/README.assets/stack_of_do_signal.png -------------------------------------------------------------------------------- /theory/3. 进程/7. 会话及进程组/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/7. 会话及进程组/README.assets/session1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/7. 会话及进程组/README.assets/session1.png -------------------------------------------------------------------------------- /theory/3. 进程/7. 会话及进程组/README.assets/session2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/7. 会话及进程组/README.assets/session2.png -------------------------------------------------------------------------------- /theory/3. 进程/7. 会话及进程组/README.md: -------------------------------------------------------------------------------- 1 | ## 1. 会话及进程组概述 2 | 3 | ![session1](README.assets/session1.png) 4 | 5 | ![session2](README.assets/session2.png) 6 | 7 | ## 2. 相关源码实现 8 | ### 2.1 初始化 session 与 进程组 9 | #### 2.1.1 初始化会话 10 | 在`kernel/sys.c`中: 11 | 12 | ```c 13 | int sys_setsid(void) 14 | { 15 | if (current->leader && !suser()) 16 | return -EPERM; 17 | current->leader = 1; 18 | current->session = current->pgrp = current->pid; 19 | current->tty = -1; 20 | return current->pgrp; 21 | } 22 | ``` 23 | 24 | ### 2.1.2 初始化进程组 25 | 在`kernel/sys.c`中: 26 | 27 | ```c 28 | /* 29 | * Linus 的这段注释很可爱... ^_^ 30 | * 31 | * This needs some heave checking ... 32 | * I just haven't get the stomach for it. I also don't fully 33 | * understand sessions/pgrp etc. Let somebody who does explain it. 34 | */ 35 | int sys_setpgid(int pid, int pgid) 36 | { 37 | int i; 38 | 39 | // 如果 pid 为 0, 则说明是要给当前进程设置 pgid 40 | if (!pid) 41 | pid = current->pid; 42 | 43 | // 如果 pgid 为 0, 则说明 pgid 为当前进程的 pid 44 | if (!pgid) 45 | pgid = current->pid; 46 | 47 | //遍历找到 pid 对应的进程 48 | for (i=0 ; ipid==pid) { 50 | // 如果那个进程为 leader,则其不能设置 pgid 51 | if (task[i]->leader) 52 | return -EPERM; 53 | 54 | // 如果那个进程 和 当前进程不属于同一个 session, 则不允许设置pid 55 | if (task[i]->session != current->session) 56 | return -EPERM; 57 | // 设置pid 58 | task[i]->pgrp = pgid; 59 | return 0; 60 | } 61 | return -ESRCH; 62 | } 63 | ``` 64 | 65 | ### 2.2 `kill` session 与 进程组 66 | 67 | #### 2.2.1 `kill` session 68 | 在`kernel/exit.c`中: 69 | ```c 70 | static void kill_session(void) 71 | { 72 | struct task_struct **p = NR_TASKS + task; 73 | 74 | // 遍历所有进程,如果被便遍历到的进程的session和当前进程的session一致 75 | // 则修改信号,被修改信号后的进程当被调度到,然后进行信号处理时,其将被信号处理相关逻辑结束 76 | while (--p > &FIRST_TASK) { 77 | if (*p && (*p)->session == current->session) 78 | (*p)->signal |= 1<<(SIGHUP-1); 79 | } 80 | } 81 | ``` 82 | #### 2.2.2 `kill` 进程组 83 | 84 | 在`kernel/exit.c`中: 85 | ```c 86 | int sys_kill(int pid,int sig) 87 | { 88 | struct task_struct **p = NR_TASKS + task; 89 | int err, retval = 0; 90 | 91 | // pid == 0,就给pgrp为当前进程pid的所有进程发送信号(当前进程的pgrp也为当前进程的pid) 92 | if (!pid) while (--p > &FIRST_TASK) { 93 | if (*p && (*p)->pgrp == current->pid) 94 | if ((err=send_sig(sig,*p,1))) 95 | retval = err; 96 | } 97 | // pid > 0, 就给pgrp为 pid 的所有进程发送信号 98 | else if (pid>0) while (--p > &FIRST_TASK) { 99 | if (*p && (*p)->pid == pid) 100 | if ((err=send_sig(sig,*p,0))) 101 | retval = err; 102 | } 103 | // pid == -1, 就给所有进程发送信号 104 | else if (pid == -1) while (--p > &FIRST_TASK) { 105 | if ((err = send_sig(sig,*p,0))) 106 | retval = err; 107 | } 108 | // pid = 非-1的负数, 就给pgrp为 -pid 的所有进程发送信号 109 | else while (--p > &FIRST_TASK) 110 | if (*p && (*p)->pgrp == -pid) 111 | if ((err = send_sig(sig,*p,0))) 112 | retval = err; 113 | return retval; 114 | } 115 | ``` 116 | -------------------------------------------------------------------------------- /theory/3. 进程/9. 多线程同步/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/3. 进程/9. 多线程同步/README.assets/jmm_barrier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/9. 多线程同步/README.assets/jmm_barrier.png -------------------------------------------------------------------------------- /theory/3. 进程/9. 多线程同步/README.assets/sync.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/9. 多线程同步/README.assets/sync.png -------------------------------------------------------------------------------- /theory/3. 进程/9. 多线程同步/README.assets/volatile_barrier.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/3. 进程/9. 多线程同步/README.assets/volatile_barrier.png -------------------------------------------------------------------------------- /theory/3. 进程/README.md: -------------------------------------------------------------------------------- 1 | 本目录下的文件夹下的文章更加注重实践,很多部分会直接和源码结合来进行讲解,如果理论部分不是很熟悉的话,可以先参看: 2 | 3 | [清华大学——操作系统](https://www.bilibili.com/video/BV1uW411f72n?p=37) 中的第 7, 8, 9, 10, 11 章节。 4 | -------------------------------------------------------------------------------- /theory/4. 内存管理/1. 实模式与保护模式(分页)/README.md: -------------------------------------------------------------------------------- 1 | ## [点击跳转到 实模式与保护模式](https://github.com/lcdzhao/operating_system/tree/master/theory/%E9%99%841%EF%BC%9A%E7%A1%AC%E4%BB%B6%E7%9B%B8%E5%85%B3/%E5%AE%9E%E6%A8%A1%E5%BC%8F%E4%B8%8E%E4%BF%9D%E6%8A%A4%E6%A8%A1%E5%BC%8F) 2 | 3 | ## [malloc,vmalloc,kmalloc区别 ](https://blog.csdn.net/alzzw/article/details/101901323) 4 | 5 | ## [malloc 原理](https://blog.csdn.net/AngelDg/article/details/111825900) 6 | -------------------------------------------------------------------------------- /theory/4. 内存管理/3. Java读写为什么要在堆内堆外进行拷贝/README.md: -------------------------------------------------------------------------------- 1 | # Java读写为什么要在堆内堆外进行拷贝 2 | 感觉很多余,很傻逼 3 | 4 | //TODO OpenJdk 源码 5 | 6 | //TODO JVM提供了临界写的方法(安全点),如果操作系统写阻塞,会导致JVM一直无法进行垃圾回收,如果JVM长时间不能进行垃圾回收,那么即使没有内存泄漏,也会导致OOM(或者内存分配的地方一直阻塞住),是大问题,会导致JAVA不完善。 7 | 8 | //那可以仅仅把这块内存hold住,仅让JVM不回收这块内存不。理论上可以,但是可能会导致垃圾回收的机制比较复杂,识别哪一块内存要hold住比较简单,一个字段就可以表明,但是如何在清理的过程中,hold住这块内存是比较复杂的,比如:标记复制算法 要考虑有一块不能复制(处理起来很恶心),标记移动算法 也要考虑移动的时候得把这块空间避开(处理起来也比较恶心的)。 9 | -------------------------------------------------------------------------------- /theory/4. 内存管理/README.md: -------------------------------------------------------------------------------- 1 | 本目录下的文件夹下的文章更加注重实践,很多部分会直接和源码结合来进行讲解,如果理论部分不是很熟悉的话,可以先参看: 2 | 3 | [清华大学——操作系统](https://www.bilibili.com/video/BV1uW411f72n?p=13) 中的第 3, 4, 5, 6 章节。 4 | -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/console.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/console.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/devs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/devs.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/kernel_chr_drv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/kernel_chr_drv.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/process_of_char_dev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/process_of_char_dev.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/read_and_write_series.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/read_and_write_series.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_io1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_io1.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_write_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_write_1.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_write_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/rs_write_2.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/serise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/serise.png -------------------------------------------------------------------------------- /theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/support_tty.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/1. 字符设备驱动程序(char device)/README.assets/support_tty.png -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/blk_devs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/blk_devs.png -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/block_and_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/block_and_file.png -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/block_operation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/block_operation.png -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/do_XX_request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/do_XX_request.png -------------------------------------------------------------------------------- /theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/kernel_blk_drv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/2. 块设备驱动程序(block driver)/README.assets/kernel_blk_drv.png -------------------------------------------------------------------------------- /theory/5. 设备管理/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/5. 设备管理/README.assets/devices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/5. 设备管理/README.assets/devices.png -------------------------------------------------------------------------------- /theory/5. 设备管理/README.md: -------------------------------------------------------------------------------- 1 | # 设备管理 2 | ## 计算机组成原理层面 3 | > 北京大学 《计算机组成》 陆俊林 —— 9.1 - 9.6 4 | 5 | https://www.bilibili.com/video/BV1VE411o7nx?p=52&vd_source=afbe39567defad401c79f6fbb57691cf 6 | 7 | ## 操作系统层面 8 | 操作系统的主要功能之一就是与周边的输入输出设备进行通信,采用统一的接口来控制这些外围设 备。操作系统的所有设备可以粗略地分成两种类型:块设备(block device)和字符型设备(character device)。 9 | 10 | - 块设备:是一种可以以固定大小的数据块为单位**进行寻址和访问**的设备,例如硬盘设备和软盘设备。 11 | - 字符设备:是一种以字符流作为操作对象的设备,**不能进行寻址操作**。例如打印机设备、网络接口设备和终端设备。 12 | 13 | 为了便于管理和访问,操作系统将这些设备统一地以设备号进行分类。在 Linux 0.11 内核中设备 被分成 7 类,即共有 7 个设备号(0 到6)。每个类型中的设备可再根据子(从、次)设备号来加以进一 步区别。下表中列出了各个设备号的设备类型和相关的设备。从表中可以看出某些设备(内存设备) 既可以作为块设备也可以作为字符设备进行访问。 14 | 15 | ![devices](README.assets/devices.png) 16 | 17 | ## 设备的读与写 18 | 在`Linux`中,**一切皆文件**。故和文件读写一样,设备的读写也被包含在系统调用`sys_read`和`sys_write`中。其具体源码分析如下: 19 | ### 源码分析 20 | 在`include/linux/sys.h`中指定`sys_read`为4号系统调用,`sys_write`为5号系统调用: 21 | 22 | ```c 23 | /* ... 省略其他代码 */ 24 | extern int sys_read(); 25 | extern int sys_write(); 26 | /* ... 省略其他代码 */ 27 | 28 | fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read, 29 | sys_write, /* ... 省略其他代码 */ } 30 | ``` 31 | 32 | `sys_read()`在`fs/read_write.c`中,其具体调用设备相对应的驱动函数: 33 | 34 | ```c 35 | /* ... 省略其他代码 */ 36 | 37 | int sys_read(unsigned int fd,char * buf,int count) 38 | { 39 | struct file * file; 40 | struct m_inode * inode; 41 | 42 | if (fd>=NR_OPEN || count<0 || !(file=current->filp[fd])) 43 | return -EINVAL; 44 | if (!count) 45 | return 0; 46 | verify_area(buf,count); 47 | inode = file->f_inode; 48 | if (inode->i_pipe) 49 | return (file->f_mode&1)?read_pipe(inode,buf,count):-EIO; 50 | if (S_ISCHR(inode->i_mode)) 51 | return rw_char(READ,inode->i_zone[0],buf,count,&file->f_pos); //调用字符设备读 52 | if (S_ISBLK(inode->i_mode)) 53 | return block_read(inode->i_zone[0],&file->f_pos,buf,count); //调用块设备读 54 | if (S_ISDIR(inode->i_mode) || S_ISREG(inode->i_mode)) { 55 | if (count+file->f_pos > inode->i_size) 56 | count = inode->i_size - file->f_pos; 57 | if (count<=0) 58 | return 0; 59 | return file_read(inode,file,buf,count); 60 | } 61 | printk("(Read)inode->i_mode=%06o\n\r",inode->i_mode); 62 | return -EINVAL; 63 | } 64 | ``` 65 | 66 | `sys_write()`在`fs/read_write.c`中,其具体调用设备相对应的驱动函数: 67 | 68 | ```c 69 | /* ... 省略其他代码 */ 70 | 71 | int sys_write(unsigned int fd,char * buf,int count) 72 | { 73 | struct file * file; 74 | struct m_inode * inode; 75 | 76 | if (fd>=NR_OPEN || count <0 || !(file=current->filp[fd])) 77 | return -EINVAL; 78 | if (!count) 79 | return 0; 80 | inode=file->f_inode; 81 | if (inode->i_pipe) 82 | return (file->f_mode&2)?write_pipe(inode,buf,count):-EIO; 83 | if (S_ISCHR(inode->i_mode)) 84 | return rw_char(WRITE,inode->i_zone[0],buf,count,&file->f_pos); //调用字符设备写 85 | if (S_ISBLK(inode->i_mode)) 86 | return block_write(inode->i_zone[0],&file->f_pos,buf,count); //调用块设备写 87 | if (S_ISREG(inode->i_mode)) 88 | return file_write(inode,file,buf,count); 89 | printk("(Write)inode->i_mode=%06o\n\r",inode->i_mode); 90 | return -EINVAL; 91 | } 92 | 93 | /* ... 省略其他代码 */ 94 | ``` 95 | 96 | ## 字符设备驱动程序(char device) 97 | [点击跳转](https://github.com/lcdzhao/operating_system/tree/master/theory/5.%20%E8%AE%BE%E5%A4%87%E7%AE%A1%E7%90%86/1.%20%E5%AD%97%E7%AC%A6%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F(char%20device)) 98 | ## 块设备驱动程序(block driver) 99 | [点击跳转](https://github.com/lcdzhao/operating_system/tree/master/theory/5.%20%E8%AE%BE%E5%A4%87%E7%AE%A1%E7%90%86/2.%20%E5%9D%97%E8%AE%BE%E5%A4%87%E9%A9%B1%E5%8A%A8%E7%A8%8B%E5%BA%8F(block%20driver)) 100 | 101 | -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Generic.Block.Layer.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Generic.Block.Layer.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Cache.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Cache.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.IO.Scheduler.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.IO.Scheduler.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Read.Procedure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Read.Procedure.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Write.Procedure.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Kernel.Write.Procedure.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Virtual.Filesystem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/Linux.Virtual.Filesystem.pdf -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/VFS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/VFS.png -------------------------------------------------------------------------------- /theory/6. 文件系统/1. 虚拟文件系统/README.assets/vfs-frame-look.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/1. 虚拟文件系统/README.assets/vfs-frame-look.png -------------------------------------------------------------------------------- /theory/6. 文件系统/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/6. 文件系统/README.assets/file_sys.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/README.assets/file_sys.png -------------------------------------------------------------------------------- /theory/6. 文件系统/README.md: -------------------------------------------------------------------------------- 1 | # 文件系统概述 2 | > 内容来自《一个64位操作系统的设计与实现》 3 | 4 | ## 历史 5 | **在没有文件这一概念之前,存储介质的容量极小,数据往往独占存储设备并连续保存在其中**。随着存储设备容量的急剧增长,它们已经有能力同时为多个设备提供数据存储空间。随着数据的持续增长,存储介质为设备划分的数据存储空间会产生数据覆盖或空间划分不合理等现象,因此才会使用文件和文件系统来解决此类现象。 6 | 文件是一个抽象的概念,它有组织地将多个数据块管理起来,以确保有足够的存储空间容纳数据。 7 | 8 | 9 | ## 文件 10 | 一个文件通常由**文件信息**和**数据**两部分组成,其中: 11 | 12 | - 文件信息:记录着文件的使用时间、文件名、文件长度、数据扇区索引等内容。 13 | - 数据区:记录着文件保存的实际数据。 14 | 15 | 当文件的个数达到一定数量级后,管理文件就变成一件非常复杂的事情,如果借助文件系统来管理文件可使问题变得简单许多。 16 | 17 | ## 文件系统 18 | 文件系统通常会包含**超级块、目录项、数据区**三部分,它们各司其职将所有文件有组织地管理起来,在逻辑上呈现出多叉的树状结构,下图是文件系统的整体结构示意图。 19 | 20 | ![file_sys](README.assets/file_sys.png) 21 | 22 | 从上图描述的文件系统整体结构可以看出,**超级块是文件系统的顶层信息结构**,而**目录项和数据区则维护着从根目录延伸出的所有路径分支**,这些概念的解释如下: 23 | 24 | - 超级块(Super Block):超级块或称启动扇区、引导扇区等,它主要用于**记录文件系统的全局信息**。**不同文件系统对文件和扇区的管理策略各不相同,从而导致超级块的结构千差万别**。 25 | 26 | - 目录项(Directory Entry):**目录项也会因文件系统的不同类型而千差万别**,总体来说,其主要作用是为了**保存目录的名字、长度、属性、数据块索引表以及相关操作时间**等信息。文件**在文件系统里的组织结构通常情况下与目录相同**,它们都使用目录项统一进行管理,我们只需**使用属性信息里的标志位便可对两者加以区分**。**数据块索引表记录着文件数据与数据块的线性映射关系,不同文件系统的索引方式千差万别**,比如,FAT类文件系统采用类似单向链表的一维索引方式,而EXT类文件系统则采用类似页表的二维索引方式。 27 | 28 | - 数据区(Data Block):文件与目录的不同最终体现在数据区,虽然两者保存的都是数据,但目录中保存的是维护目录层级关系的子目录项,这些子目录项可代表文件或子目录。目录项如此往复地逐层堆砌便形成了文件系统的树状结构。 29 | 30 | 以上三个概念是对文件系统结构的高度概括,但由于每款文件系统的结构迥异,在它们的设计过程中其他辅助性概念还会引入。 31 | -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/boot_sec_of_fat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/boot_sec_of_fat.png -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fat_struct.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fat_struct.png -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fat_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fat_table.png -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fatinfo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/fatinfo.png -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/long_dir_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/long_dir_table.png -------------------------------------------------------------------------------- /theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/short_dir_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/6. 文件系统/附 1: 解析FAT32文件系统/README.assets/short_dir_table.png -------------------------------------------------------------------------------- /theory/7. 虚拟化/1. 容器级别轻量级虚拟化/1. namespace/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## 文章讲解 3 | 4 | - [Docker 基础技术之 Linux namespace 详解](https://mp.weixin.qq.com/s/10HgkUE14wVI_RNmFdqkzA) 5 | 6 | - [Docker 基础技术之 Linux namespace 源码分析](https://mp.weixin.qq.com/s/czZsAmp6nTt6JPuOAytgcw) 7 | 8 | 对network namespace理解不了,可以看:[理解linux network namespace](https://blog.csdn.net/u014634338/article/details/119343985) 9 | 10 | ## 实验 11 | https://www.bilibili.com/video/BV1oi4y1F7sb?p=4&vd_source=afbe39567defad401c79f6fbb57691cf 12 | 13 | 14 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/1. 容器级别轻量级虚拟化/2. cgroup/README.md: -------------------------------------------------------------------------------- 1 | ## 文章讲解 2 | - [Docker 基础技术之 Linux cgroups 详解](https://mp.weixin.qq.com/s/bSmYy4EqoVY0msgSB1ZN5w) 3 | 4 | ## 实验 5 | https://www.bilibili.com/video/BV1oi4y1F7sb?p=5 6 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/1. 容器级别轻量级虚拟化/3. chroot/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/1. 容器级别轻量级虚拟化/4. 容器网络/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/2. 全虚拟化/1. KVM/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/2. 全虚拟化/2. 全虚拟化网络/README.md: -------------------------------------------------------------------------------- 1 | #### vhost:虚拟机进入内核 2 | 3 | https://cloud.tencent.com/developer/article/1075600 4 | 5 | #### vertio vhost vhost-user 6 | 7 | https://blog.csdn.net/Rong_Toa/article/details/115287676 8 | 9 | #### 四种模式 10 | https://cloud.tencent.com/developer/article/1508613 11 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/2. 全虚拟化/README.md: -------------------------------------------------------------------------------- 1 | https://github.com/yifengyou/learn-kvm 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/3. OpenStack/README.md: -------------------------------------------------------------------------------- 1 | https://www.xjimmy.com/study_openstack 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/4. K8S/README.md: -------------------------------------------------------------------------------- 1 | 【云原生Java架构师的第一课K8s+Docker+KubeSphere+DevOps-哔哩哔哩】 https://b23.tv/ItfXzlg 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/5. 虚拟化隔离性对比/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/6. 虚拟化损耗对比/README.md: -------------------------------------------------------------------------------- 1 | ## KVM Docker 裸金属 性能对比 2 | https://mp.weixin.qq.com/s/__2bJidH3y_RHnz2cjHqSg 3 | 4 | ## KVM 5 | ### 理论上哪些部分会有损耗 6 | #### CPU 7 | 8 | #### 内存 9 | 10 | #### 磁盘 11 | 12 | #### IO 13 | ##### 文件IO 14 | 15 | ##### 网络IO 16 | 17 | ## Docker 18 | 19 | ### 理论上哪些部分会有损耗 20 | #### CPU 21 | 22 | #### 内存 23 | 24 | #### 磁盘 25 | 26 | #### IO 27 | ##### 文件IO 28 | 29 | ##### 网络IO 30 | 31 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/7. 虚拟化技术未来畅想/README.md: -------------------------------------------------------------------------------- 1 | 所谓理想的虚拟化,即:完美的隔离性 以及 零损耗(CPU、内存、磁盘、IO) 2 | -------------------------------------------------------------------------------- /theory/7. 虚拟化/README.md: -------------------------------------------------------------------------------- 1 | ## 大纲 2 | 请阅读完大纲的所有文章后再进一步阅读其他文章。 3 | 4 | - [10年资深架构师谈Linux上容器背后的虚拟化解决方案](https://dbaplus.cn/news-72-526-1.html) 5 | > 这篇文章中讲了现今使用的技术都有哪些以及他们的关系。阅读时可以忽略源码相关部分,专注于这篇文章对于各个技术的简介。 6 | -------------------------------------------------------------------------------- /theory/8. 网络/README.md: -------------------------------------------------------------------------------- 1 | - tcp write与read: 2 | https://www.cnblogs.com/tianzeng/p/9347612.html 3 | - 三次握手: 4 | https://mp.weixin.qq.com/s?__biz=MjM5Njg5NDgwNA==&mid=2247485862&idx=1&sn=1f3a92b8fd5fbc14c4d073d04c6d44ed&chksm=a6e3089d9194818bbd9ab3582bd7e7b7f2d83892833d088d8d1c514cbf145b9ee8f0f3b4be81&scene=178&cur_album_id=1532487451997454337#rd 5 | - 四次挥手:https://www.xiaolincoding.com/network/3_tcp/tcp_interview.html 6 | - TCP参数调优:https://zhuanlan.zhihu.com/p/436979513 7 | - TCP调优Linux参数:https://github.com/mykubernetes/linux/blob/master/Linux%20%E7%B3%BB%E7%BB%9F%E5%86%85%E6%A0%B8%E5%8F%82%E6%95%B0%E8%B0%83%E4%BC%98%20.md 8 | - restclient:https://segmentfault.com/a/1190000041579589?u_atoken=a09c3bef-aa17-43cb-9113-e64a1b96f20d&u_asession=01_UbaQ2FO440xQsMImes2gvDimlgn1n3HUkMYGWkfZ60zFcat-sKVI2S9n8bgqz0OX0KNBwm7Lovlpxjd_P_q4JsKWYrT3W_NKPr8w6oU7K_NjkBRHlacoC3rFvSkj9VP2l7GVvsUm1O1dQ3kAgydYmBkFo3NEHBv0PZUm6pbxQU&u_asig=05Q8crcoTkvttMf0fF8w8FcZSAm2yJB0QFPSzVhaSfsAe8UUalUWI2lKZE3H2qLRQsqhoQcyQ4ZFWgEVEaoJ_lk5mUSjJIH6qzlP05OG4_lnx65M36R-WgtB1HlMja2S0V57avcN8hY_5SonE3CRrWG0utiQpymu_JFbKZmYRukH79JS7q8ZD7Xtz2Ly-b0kmuyAKRFSVJkkdwVUnyHAIJzbrHLeFTomnyhLRJDsmjgW48bHo1_CKXsRndTENfMZ3laSuCIIsUrXvoQJBX3FajR-3h9VXwMyh6PgyDIVSG1W_rxOfw9VyQd3yV2qeND9XtntxszIC-jZ3XnMw67JPJQzSNiHGFenKy64MFvqOP_ZgoLCJGtJVdmJKZOO90Wf8gmWspDxyAEEo4kbsryBKb9Q&u_aref=UP%2BFIvJUuI6NVMhfXB2w2EvcyDQ%3D 9 | - netty:https://github.com/Snailclimb/netty-practical-tutorial/blob/master/docs/3-Netty%E6%A0%B8%E5%BF%83%E7%BB%84%E4%BB%B6%E5%88%86%E6%9E%90.md 10 | - DPDK:https://cloud.tencent.com/developer/article/1198333 11 | - 网络发包过程: 12 | https://mp.weixin.qq.com/s?__biz=MjM5Njg5NDgwNA==&mid=2247485146&idx=1&sn=e5bfc79ba915df1f6a8b32b87ef0ef78&chksm=a6e307e191948ef748dc73a4b9a862a22ce1db806a486afce57475d4331d905827d6ca161711&scene=178&cur_album_id=1532487451997454337#rd 13 | - 网络收包流程: 14 | https://mp.weixin.qq.com/s/GoYDsfy9m0wRoXi_NCfCmg 15 | - 剖析Netty与Redis(多线程与单线程)内部网络实现原理: 16 | https://mp.weixin.qq.com/s?__biz=MjM5Njg5NDgwNA==&mid=2247489696&idx=1&sn=1d7877a7b5d3dbc993c2ed61db5c0ae3&chksm=a6e3199b9194908da28400956356b0a6dcb04bd5754debf80ef4be5f0607b433756cdce2ae39&scene=178&cur_album_id=1532487451997454337#rd 17 | - ebpf(ebpf vs dpdk): http://arthurchiao.art/blog/advanced-bpf-kernel-features-for-container-age-zh/#32-%E8%BD%AC%E5%8F%91%E6%80%A7%E8%83%BD%E5%AF%B9%E6%AF%94xdp-vs-dpdk 18 | -------------------------------------------------------------------------------- /theory/9. 操作系统的发展/README.md: -------------------------------------------------------------------------------- 1 | # 操作系统的发展 2 | Linux 0.11 是一个汇聚了无数人智慧结晶才诞生的产物,其已经是一个无比精妙的系统了。不过现在距离 Linux 0.11 的诞生已经过去几十年了,操作系统和硬件虽然没有什么彻头彻尾的变动,但是很多方面做的却比以前更加完美了,当然完美的代价是代码变得极其复杂,晦涩难懂,这里不展开源码讲解,我想大概谈一谈这些变动的大方向。 3 | 4 | 核心的大方向其实也就只有两个,一个是减少没有必要的资源消耗,二是虚拟化。 5 | 6 | - 减少没有必要的资源消耗:操作系统的资源大的来讲,主要有:CPU 内存 磁盘 网络几个方面,下面我们来看看这一块的发展: 7 | 8 | - 减少 CPU 消耗:这块我们从硬件和软件方面分别来谈: 9 | - 硬件方面: 10 | - X86 将指令翻译为 精简指令集 再使用流水线; 11 | - MESI 协议 与 InvalidateQueue及WriteBuffer 的结合; 12 | - 更丰富的DMA模块。 13 | - 减少系统调用本身的消耗,从 INT 中断发起系统调用 到 sysent 发起系统调用。 14 | - ...... 15 | 16 | - 软件方面:软件方面除了操作系统的代码本身更加卓越,其执行比以前更节省CPU资源以外,用户态可感知到的主要为:操作系统尽可能地减少了用户态代码完成一项任务所需要的调用系统调用的次数,关于减少系统调用次数,基本上下面有三种优化思路: 17 | - 第一种思路:减少没有必要进行系统调用,这一类大多借助 mmap,创建共享内存,将一部分内核空间的访问权限交给用户空间,仅把需要保护的操作保护起来。如: 18 | - 从 poll select 到 epoll 19 | - 从 信号量 到 futex(运行在用户态的线程仅在需要暂停或者继续时,才需要使用系统调用) 20 | - ...... 21 | - 第二种思路:彻底不进行系统调用,这种思路比较激进,会让操作系统的隔离性变差,并丢失部分操作系统本身的功能,会直接影响到其他应用程序的运行,但是部分特殊场景下可以节省大量的CPU资源,如:DPDK结合LVS将LVS性能提升10倍左右。(不过未来这一部分场景中的很多应该会逐渐被eBPF所取代,eBPF即是第三种减少系统调用的方法) 22 | - 第三种思路:将一部分安全的用户态代码放入内核态执行,即为eBPF技术(被誉为操作系统近50年来最大的改动),facebook的基于 eBPF 的开源负载均衡器 katran 性能达到 dpvs 同一级别,同时又不丢失操作系统的隔离性和部分操作系统本身的功能。 23 | 24 | 25 | - 减少内存消耗:虚拟内存的诞生不光巧妙地实现了进程的内存隔离性,更帮助操作系统极大地节约了内存的使用。不过虚拟内存技术在Linux 0.11 中已经存在,也许是因为虚拟内存技术太过优秀,在用户态的内存分配方面,操作系统基本没有变化(当然C语言标准库的malloc函数内部可能有变化,不过这块不属于操作系统的内存分配,故其变化不包含在该篇文章中),有变化的只有内核态中内存分配,具体如下: 26 | - 内核从一开始内存分配至少一页,需要内核编程人员自己去分割这一页内存,变为可以根据不同大小的需求分配内存,发展出 buddy 内存管理系统,针对不同大小均可快速分配相应大小的内存,如:slab等等。 27 | 28 | 29 | 30 | - 虚拟化: 31 | - 容器技术: 32 | - namespace 33 | - cgroup 34 | - chroot 35 | 36 | - 内核虚拟化 37 | - KVM 38 | -------------------------------------------------------------------------------- /theory/附0:8bit计算机仿真(MIPS指令)/README.md: -------------------------------------------------------------------------------- 1 | ## 文件说明 2 | - compute_of_8bit.circ 为 8 bit计算机仿真电路 3 | - logisim-generic-2.7.1.jar 为logisim的jar包 4 | - 汇编编译器:[XComputerAssember](https://github.com/lcdzhao/XComputerAssember) 5 | 6 | ## 8 bit 计算机仿真相关课程 7 | 8 | - [编程前你最好了解的基本硬件和计算机基础知识(模拟电路)](https://www.bilibili.com/video/BV1774114798?spm_id_from=333.999.0.0) 9 | 10 | - [编程前你最好了解的基本硬件和计算机基础知识(数字电路)](https://www.bilibili.com/video/BV1Hi4y1t7zY?spm_id_from=333.999.0.0) 11 | 12 | - [从0到1设计一台计算机](https://www.bilibili.com/video/BV1wi4y157D3?spm_id_from=333.999.0.0) 13 | -------------------------------------------------------------------------------- /theory/附0:8bit计算机仿真(MIPS指令)/logisim-generic-2.7.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附0:8bit计算机仿真(MIPS指令)/logisim-generic-2.7.1.jar -------------------------------------------------------------------------------- /theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.assets/101-电子计算机的兴起.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.assets/101-电子计算机的兴起.pdf -------------------------------------------------------------------------------- /theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.assets/history_of_cpu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.assets/history_of_cpu.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/CPU(Intel)及计算机发展历史/README.md: -------------------------------------------------------------------------------- 1 | - 电子计算机发展历史:[ 计算机兴起历史(部分使用了下面Intel的CPU,可以对照着来进行学习) ](README.assets/101-电子计算机的兴起.pdf) 2 | 3 | - CPU 博物馆:[CPU world](https://www.cpu-world.com/CPUs/CPU.html) 4 | 5 | 6 | ![history_of_cpu](README.assets/history_of_cpu.png) 7 | -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/805-内部中断分类说明.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/805-内部中断分类说明.pdf -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/aburt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/aburt.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/change.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/change.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/change_.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/change_.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/exs.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/exs.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/exs_num.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/exs_num.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/fault.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/fault.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/gate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/gate.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/gate_format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/gate_format.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/idt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/idt.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/idt_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/idt_table.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/init_idt_in_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/init_idt_in_main.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/int.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/int.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_process.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_process.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_service.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_service.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_space.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_space.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_table.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_table.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_table_of_protect_mode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_table_of_protect_mode.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_vector.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/interrupt_vector.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/sched_init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/sched_init.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/trap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/trap.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/中断与系统调用/README.assets/trapinit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/中断与系统调用/README.assets/trapinit.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/GDTR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/GDTR.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/GDT_LDT.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/GDT_LDT.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/page.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/price_of_memory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/price_of_memory.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/protect_mode_address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/protect_mode_address.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/segment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/segment.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/segment_description.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/segment_description.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/segment_selector.excalidraw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/segment_selector.excalidraw.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/type.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/type.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/vertual_address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/vertual_address.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/实模式与保护模式/README.assets/vertual_address_space.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附1:硬件相关/实模式与保护模式/README.assets/vertual_address_space.png -------------------------------------------------------------------------------- /theory/附1:硬件相关/寄存器(x86架构)/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附1:硬件相关/寄存器(x86架构)/README.md: -------------------------------------------------------------------------------- 1 | # 寄存器是什么 2 | 寄存器是**CPU内部用来存放数据的一些小型存储区域,用来暂时存放参与运算的数据和运算结果**。 3 | 4 | 其实寄存器就是一种常用的时序逻辑电路,但这种时序逻辑电路只包含存储电路。寄存器的存储电路是由锁存器或触发器构成的,因为一个锁存器或触发器能存储1位二进制数,所以由N个锁存器或触发器可以构成N位寄存器。寄存器是中央处理器内的组成部分。寄存器是有限存储容量的高速存储部件,它们可用来暂存指令、数据和位址。 5 | # 为什么要有寄存器 6 | 正常情况下,CPU 执行命令的过程为:取指——>译码——>执行——>访存(需要访存时才会有)——>回写。 7 | 8 | 但是如果没有寄存器,那么在执行阶段需要的数据也需要进行访存,而且是每一个命令都需要访存,这会使得一个命令的执行周期变得很长。 9 | 10 | 实际上在CPU执行命令的过程中,有很多数据在很长时间中都是不会进行变化的,且会频繁被CPU使用,如果这一部分数据都去进行访存的话,那么会耗费的时间将会很长,但是**如果将这些数据存放在寄存器中,那么只需要在第一次加载数据到寄存器时才需要进行访存,而其他时间都可以直接从寄存器中读取数据(十分快速)**。故:寄存器成为了CPU的一个重要组件。 11 | # 寄存器的硬件电路 12 | [寄存器——ele实验室](https://www.bilibili.com/video/BV1wi4y157D3?p=5) 13 | # x86架构的寄存器有哪些 14 | ![寄存器分类](README.assets/register.excalidraw.svg) 15 | -------------------------------------------------------------------------------- /theory/附2:C语言相关/C变量与常量及其指针/README.md: -------------------------------------------------------------------------------- 1 | # C变量与常量及指针的关系 2 | 变量与常量都是存在于某个内存位置,其都可以获取到存放位置的具体内存地址。这没有什么不同,区别是常量的存放位置是只读的,而变量的存放位置可读也可写。 3 | 4 | 而不是 常量和汇编中的立即数一样,在编译期就确定好了,在运行期执行一下立即数赋值指令就直接用就行了,整个过程不用访问内存。但实际是常量也存放在某个地址,使用时也需要访问内存才能拿到。 5 | 6 | 编译器对常量进行了优化,避免用户直接拿到存放常量的内存地址。 7 | 8 | 这块的设计感觉并不完美,对字符串的处理和对其他类型的处理好像还有一点不太一样,具体不要太纠结,设计的也不完美,很多大佬都搞不明白。所以咱们有个感觉就行,这本身就是一个缺陷的设计,大概是在平衡灵活和安全之间(或者是为了新老版本兼容)才出现的设计吧。所以大概有个上面说的这个感觉就行,不要死抠。要是有大佬知道历史背景和原因这些的话,可以提个PR,修改一下这篇文章。 9 | 10 | > - 字符串:char[] p与char * p,两者实际都是在某个内存位置存放了字符串启始地址。但是&p前者拿到的是字符串本身的启始地址(大概率是编译器做的优化,即:编译器通过这种方式来实现不允许获取到前者的地址,从而在编译期避免了常量被修改),而后者拿到的是存放字符串启始地址的地址。但前后p(都为字符串本身的启始地址) 获取到的值都是一样的,且*p(都为首个字符) 获取到的值也都是一样的。 11 | > 12 | > - 其他类型:常量及常量指针及指针常量:https://blog.csdn.net/jackystudio/article/details/11519817 13 | 14 | -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言GDB调试/README.md: -------------------------------------------------------------------------------- 1 | [C语言调试](https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/gdb.html) 2 | -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/C_compile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/C_compile.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/dyc1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/dyc1.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/dyc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/dyc2.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/ex.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/ex.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/ex_h_t.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/ex_h_t.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/gcc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/gcc.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/relocatable_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/relocatable_0.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/relocatable_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/relocatable_1.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/runtime.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/runtime.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/short.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/short.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/usage_of_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/C语言编译与标准库、系统调用/README.assets/usage_of_link.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/函数调用机制/README.assets/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /theory/附2:C语言相关/函数调用机制/README.assets/stack_frame.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/函数调用机制/README.assets/stack_frame.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/函数调用机制/README.assets/stack_of_func.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lcdzhao/operating_system/9b9bcd0cb26e3db4eebfbf838e48ff02cc0dd8f9/theory/附2:C语言相关/函数调用机制/README.assets/stack_of_func.png -------------------------------------------------------------------------------- /theory/附2:C语言相关/函数调用机制/README.md: -------------------------------------------------------------------------------- 1 | # 函数调用机制 2 | > PS: 更详细的细节见 Linux内核完全注释(修正版v3.0) 第三章第四小节。 3 | 4 | 5 | ![函数调用帧结构](README.assets/stack_frame.png) 6 | 7 | ![函数调用帧](README.assets/stack_of_func.png) 8 | 9 | -------------------------------------------------------------------------------- /theory/附3:其他/C语言栈帧与Java栈帧/README.md: -------------------------------------------------------------------------------- 1 | [C语言栈帧与Java栈帧](https://blog.csdn.net/qq_37465188/article/details/125368365?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22125368365%22%2C%22source%22%3A%22qq_37465188%22%7D&ctrtid=0r6Az) 2 | -------------------------------------------------------------------------------- /theory/附3:其他/Why X86 比起 ARM 更费电/README.md: -------------------------------------------------------------------------------- 1 | ## Why X86 比起 ARM 更费电 2 | X86 将 CISC 转化为 RISC,过程耗电。如果Intel能像苹果一样写操作系统,就不会把这个转译的工作放到运行期去做了。需要太多功耗,且每次运行应用每次都需要去转译。 3 | 4 | 而苹果为了兼容M1芯片,则不光推出了自己的编译器,还能将X86架构的应用直接转译成ARM指令集。 5 | 6 | 这有点像Restlight的能在启动时初始化好的事情就不要放到运行时去重复运行。 7 | -------------------------------------------------------------------------------- /theory/附4:文章精选/README.md: -------------------------------------------------------------------------------- 1 | - [深入理解操作系统系列 —— 程磊](https://blog.csdn.net/orangeboyye?type=blog) 2 | --------------------------------------------------------------------------------