├── README.md ├── lab1 ├── code │ ├── cal │ ├── cal.asm │ ├── cal.o │ ├── lib.asm │ └── 截图.png ├── osHomework │ ├── bochsrc │ └── boot.asm └── 实验要求 │ ├── 8086寻址方式和指令系统·一个最简操作系统的实现.pdf │ ├── nasm基本语法.pptx │ ├── 实验一要求.pdf │ ├── 操作系统实验简介.pptx │ └── 问答题.md ├── lab2 ├── .idea │ └── workspace.xml ├── lab2 │ ├── .idea │ │ ├── .gitignore │ │ ├── encodings.xml │ │ ├── lab2.iml │ │ ├── misc.xml │ │ └── modules.xml │ ├── CMakeLists.txt │ ├── a.img │ ├── catLong.png │ ├── catShort.png │ ├── cmake-build-debug │ │ ├── CMakeCache.txt │ │ ├── CMakeFiles │ │ │ ├── 3.19.2 │ │ │ │ ├── CMakeCCompiler.cmake │ │ │ │ ├── CMakeCXXCompiler.cmake │ │ │ │ ├── CMakeDetermineCompilerABI_C.bin │ │ │ │ ├── CMakeDetermineCompilerABI_CXX.bin │ │ │ │ ├── CMakeRCCompiler.cmake │ │ │ │ ├── CMakeSystem.cmake │ │ │ │ ├── CompilerIdC │ │ │ │ │ ├── CMakeCCompilerId.c │ │ │ │ │ ├── CMakeCCompilerId.exe │ │ │ │ │ └── CMakeCCompilerId.obj │ │ │ │ └── CompilerIdCXX │ │ │ │ │ ├── CMakeCXXCompilerId.cpp │ │ │ │ │ ├── CMakeCXXCompilerId.exe │ │ │ │ │ └── CMakeCXXCompilerId.obj │ │ │ ├── CMakeDirectoryInformation.cmake │ │ │ ├── CMakeOutput.log │ │ │ ├── Makefile.cmake │ │ │ ├── Makefile2 │ │ │ ├── TargetDirectories.txt │ │ │ ├── clion-environment.txt │ │ │ ├── clion-log.txt │ │ │ ├── cmake.check_cache │ │ │ ├── lab2.dir │ │ │ │ ├── CXX.includecache │ │ │ │ ├── DependInfo.cmake │ │ │ │ ├── build.make │ │ │ │ ├── cmake_clean.cmake │ │ │ │ ├── code │ │ │ │ │ └── main.cpp.obj │ │ │ │ ├── depend.internal │ │ │ │ ├── depend.make │ │ │ │ ├── embed.manifest │ │ │ │ ├── flags.make │ │ │ │ ├── intermediate.manifest │ │ │ │ ├── manifest.rc │ │ │ │ ├── manifest.res │ │ │ │ ├── objects1.rsp │ │ │ │ ├── progress.make │ │ │ │ └── vc140.pdb │ │ │ └── progress.marks │ │ ├── Makefile │ │ ├── Testing │ │ │ └── Temporary │ │ │ │ └── LastTest.log │ │ ├── cmake_install.cmake │ │ ├── lab2.cbp │ │ ├── lab2.exe │ │ ├── lab2.ilk │ │ └── lab2.pdb │ ├── code │ │ ├── main.cpp │ │ ├── makefile │ │ ├── my_print.asm │ │ ├── my_print.o │ │ └── output │ ├── ls-l.png │ └── ls.png └── 实验要求 │ ├── 2021 操作系统实验(二).pdf │ ├── FAT12.pptx │ ├── gcc+nasm.pptx │ ├── 实模式与保护模式.pdf │ └── 静态链接动态链接.pptx ├── lab3 ├── code │ ├── .vscode │ │ ├── c_cpp_properties.json │ │ └── settings.json │ ├── Makefile │ ├── a.img │ ├── bochsrc │ ├── boot │ │ ├── boot.asm │ │ ├── boot.bin │ │ ├── include │ │ │ ├── fat12hdr.inc │ │ │ ├── load.inc │ │ │ └── pm.inc │ │ ├── loader.asm │ │ └── loader.bin │ ├── include │ │ ├── console.h │ │ ├── const.h │ │ ├── global.h │ │ ├── keyboard.h │ │ ├── keymap.h │ │ ├── proc.h │ │ ├── protect.h │ │ ├── proto.h │ │ ├── sconst.inc │ │ ├── string.h │ │ ├── tty.h │ │ └── type.h │ ├── kernel.bin │ ├── kernel │ │ ├── clock.c │ │ ├── console.c │ │ ├── global.c │ │ ├── i8259.c │ │ ├── kernel.asm │ │ ├── keyboard.c │ │ ├── main.c │ │ ├── proc.c │ │ ├── protect.c │ │ ├── start.c │ │ ├── syscall.asm │ │ └── tty.c │ └── lib │ │ ├── klib.c │ │ ├── kliba.asm │ │ └── string.asm ├── 实验要求 │ ├── 2021 操作系统实验.pdf │ ├── 操作系统2021 IO.pdf │ ├── 操作系统2021 中断与异常.pptx │ └── 操作系统2021 实验三 实模式和保护模式下的中断.pptx └── 截图 │ ├── 回车和tab.png │ ├── 查找.png │ └── 输入.png └── lab4 ├── code ├── Makefile ├── a.img ├── bochsrc ├── boot │ ├── boot.asm │ ├── boot.bin │ ├── include │ │ ├── fat12hdr.inc │ │ ├── load.inc │ │ └── pm.inc │ ├── loader.asm │ └── loader.bin ├── include │ ├── const.h │ ├── global.h │ ├── proc.h │ ├── protect.h │ ├── proto.h │ ├── sconst.inc │ ├── string.h │ └── type.h ├── kernel.bin ├── kernel │ ├── clock.c │ ├── global.c │ ├── i8259.c │ ├── kernel.asm │ ├── keyboard.c │ ├── main.c │ ├── proc.c │ ├── protect.c │ ├── start.c │ └── syscall.asm └── lib │ ├── klib.c │ ├── kliba.asm │ └── string.asm ├── 实验要求 ├── 操作系统2021实验四要求.pdf └── 操作系统2021实验四问题小结.pdf ├── 截图 ├── 写优先.png ├── 读优先.png └── 防饿死.png ├── 说明文档.md └── 说明文档.pdf /README.md: -------------------------------------------------------------------------------- 1 | # OSLAB-NJUSE 2 | 2021南京大学软件学院OS实验 3 | 4 | ### lab1 5 | 6 | 搭建bochs环境,利用nasm汇编语言实现大数加减、大叔乘法 7 | 8 | ### lab2 9 | 10 | 编写一个fat12镜像查看工具 11 | 12 | ### lab3 13 | 14 | 利用已有操作系统内核,添加代码实现输入输出到控制台,包含撤销和查找操作。 15 | 16 | ### lab4 17 | 18 | 在已有操作系统内核的基础上,实现进程创建与调度。包括读写者问题。 19 | -------------------------------------------------------------------------------- /lab1/code/cal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/code/cal -------------------------------------------------------------------------------- /lab1/code/cal.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/code/cal.o -------------------------------------------------------------------------------- /lab1/code/lib.asm: -------------------------------------------------------------------------------- 1 | SECTION .text 2 | global _start 3 | 4 | 5 | ;计算字符串长度 6 | slen: 7 | push ebx 8 | mov ebx, eax 9 | 10 | nextchar: 11 | cmp byte[eax], 0 12 | jz finished 13 | inc eax 14 | jmp nextchar 15 | 16 | finished: 17 | sub eax, ebx 18 | pop ebx 19 | ret 20 | 21 | 22 | ;打印字符串 23 | sprint: 24 | push edx 25 | push ecx 26 | push ebx 27 | push eax 28 | call slen 29 | 30 | mov edx, eax 31 | pop eax ;eax保存要打印字符串的起始地址 32 | 33 | mov ecx, eax 34 | mov ebx, 1 35 | mov eax, 4 36 | int 80h 37 | 38 | mov eax, ecx 39 | pop ebx 40 | pop ecx 41 | pop edx 42 | ret 43 | 44 | sprintLF: 45 | call sprint ;打印字符串 46 | 47 | push eax 48 | mov eax, 0Ah ;eax保存换行符 49 | push eax 50 | mov eax, esp ;eax保存换行符的地址 51 | call sprint 52 | pop eax 53 | pop eax 54 | ret 55 | 56 | quit: 57 | mov ebx, 0 58 | mov eax, 1 59 | int 80h 60 | ret 61 | 62 | iprint: 63 | push eax 64 | push ecx 65 | push edx 66 | push esi 67 | mov ecx, 0 68 | 69 | ;统计要打印的整数的长度,并且加上每位加上48转为ascii格式后压栈 70 | divideLoop: 71 | inc ecx 72 | mov edx, 0 73 | mov esi, 10 74 | idiv esi 75 | add edx, 48 76 | push edx 77 | cmp eax, 0 78 | jnz divideLoop 79 | 80 | printLoop: 81 | dec ecx 82 | mov eax, esp ;eax保存了要打印的数字的指针 83 | call sprint 84 | pop eax 85 | cmp ecx, 0 86 | jnz printLoop 87 | 88 | pop esi 89 | pop edx 90 | pop ecx 91 | pop eax 92 | ret 93 | 94 | iprintLF: 95 | call iprint 96 | 97 | push eax 98 | mov eax, 0Ah 99 | push eax 100 | mov eax, esp 101 | call sprint 102 | pop eax 103 | pop eax 104 | ret 105 | 106 | 107 | Reverse: 108 | push ebx 109 | push ecx 110 | push edx 111 | push eax ;eax指向计算结果的开头 112 | call slen 113 | mov ebx, eax ;ebx存有长度 114 | dec ebx ;eax指向结果末尾 115 | pop eax 116 | push eax 117 | add eax, ebx 118 | mov ebx, eax 119 | pop eax 120 | push eax 121 | 122 | ;call iprintLF 123 | ;mov eax, ebx 124 | ;call iprintLF 125 | 126 | Loop: 127 | mov cl, byte[eax] 128 | mov dl, byte[ebx] 129 | mov byte[eax], dl 130 | mov byte[ebx], cl 131 | inc eax 132 | dec ebx 133 | cmp eax, ebx 134 | jl Loop 135 | 136 | 137 | pop eax 138 | pop edx 139 | pop ecx 140 | pop ebx 141 | ret 142 | 143 | 144 | 145 | -------------------------------------------------------------------------------- /lab1/code/截图.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/code/截图.png -------------------------------------------------------------------------------- /lab1/osHomework/bochsrc: -------------------------------------------------------------------------------- 1 | megs: 32 2 | display_library: sdl 3 | floppya: 1_44=a.img, status=inserted 4 | boot: floppy 5 | -------------------------------------------------------------------------------- /lab1/osHomework/boot.asm: -------------------------------------------------------------------------------- 1 | org 07c00h 2 | mov ax, cs 3 | mov ds, ax 4 | mov es, ax 5 | call DispStr 6 | jmp $ 7 | DispStr: 8 | mov ax, BootMessage 9 | mov bp, ax 10 | mov cx, 16 11 | mov ax, 01301h 12 | mov bx, 000ch 13 | mov dl, 0 14 | int 10h 15 | ret 16 | BootMessage: db "Hello OS" 17 | times 510-($-$$) db 0 18 | dw 0xaa55 19 | -------------------------------------------------------------------------------- /lab1/实验要求/8086寻址方式和指令系统·一个最简操作系统的实现.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/实验要求/8086寻址方式和指令系统·一个最简操作系统的实现.pdf -------------------------------------------------------------------------------- /lab1/实验要求/nasm基本语法.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/实验要求/nasm基本语法.pptx -------------------------------------------------------------------------------- /lab1/实验要求/实验一要求.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/实验要求/实验一要求.pdf -------------------------------------------------------------------------------- /lab1/实验要求/操作系统实验简介.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab1/实验要求/操作系统实验简介.pptx -------------------------------------------------------------------------------- /lab1/实验要求/问答题.md: -------------------------------------------------------------------------------- 1 | 1. 请简述 8086 系列的发展历史 2 | 3 | 1. 从Intel 4004发展出了Intel 8008处理器 4 | 2. 1978年推出了16位微处理器8086,20位地址线 5 | 3. 1982年发布80286,主频提高到12MHz 6 | 4. 1985年发布80386,处理器32位,地址线32位 7 | 5. 1989年发布80486,1993年发布586并改名奔腾 8 | 9 | 2. 说明小端和大端的区别,并说明 8086 系列采用了哪种方式? 10 | 1. 大端:数据的高字节存在内存的低地址;小端:数据的高字节存在高地址 11 | 2. 8086采用的是小端存储 12 | 13 | 3. 8086 有哪五类寄存器,请分别举例说明其作用? 14 | 15 | 1. 数据寄存器(AX, BX, CX, DX):例如CX可以被用作计数器,利用CX来指定循环的次数;AX作为累加器,在除法时保存被除数的低16位,除法结束,可以保存除法的结果 16 | 17 | 2. 指针寄存器(BP, SP):BP是指针寄存器,通常BP寄存器在间接寻址中使用,操作数在堆栈段中,由SS段寄存器和BP组合形成操作数的地址,即BP中存放现行堆栈段中一个数据区的“基址”的偏移量,所以称BP为基址指针。 18 | 19 | 3. 变址寄存器(SI, DI):SI是源变址寄存器,用来存放相对于DS段之源变址指针 20 | 21 | 4. 控制寄存器(IP, FLAG):FLAG是标志寄存器,用来存储相关指令的某些执行结果,为CPU执行相关指令提供行为依据(ZF, CF之类的) 22 | 23 | 5. 段寄存器(CS, DS, SS, ES):DS用来存储要访问数据的段地址 24 | 25 | ![image-20211022162529706](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022162529706.png) 26 | 27 | ![image-20211022164010428](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164010428.png) 28 | 29 | 4. 什么是寻址?立即寻址和直接寻址的区别是什么? 30 | 31 | 找到操作数的地址以取出操作数 32 | 33 | 立即寻址直接给出了操作数,没有寻址 34 | 35 | 直接寻址给出了操作数的地址,用[]取数 36 | 37 | 38 | 39 | 40 | 41 | 5. 请举例说明寄存器间接寻址、寄存器相对寻址、基址加变址寻址、相对基址加变址寻址四种方式的区别 42 | 43 | ![image-20211022164146227](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164146227.png) 44 | 45 | ![image-20211022164153558](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164153558.png) 46 | 47 | 6. 请分别简述 MOV 指令和 LEA 指令的用法和作用? 48 | 49 | ![image-20211022164644321](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164644321.png) 50 | 51 | ![image-20211022164714687](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164714687.png) 52 | 53 | ![image-20211022164852711](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164852711.png) 54 | 55 | 7. 请说出主程序与子程序之间至少三种参数传递方式 56 | 57 | ![image-20211022164938547](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022164938547.png) 58 | 59 | 8. 如何处理输入和输出,代码中哪里体现出来? 60 | 61 | 9. 有哪些段寄存器 62 | 63 | ![image-20211022165127300](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165127300.png) 64 | 65 | 10. 通过什么寄存器保存前一次的运算结果,在代码中哪里体现出来。 66 | 67 | 68 | 69 | 11. 解释 boot.asm 文件中,org 0700h 的作用 70 | 71 | ![image-20211022165207946](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165207946.png) 72 | 73 | ![image-20211022165221307](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165221307.png) 74 | 75 | 12. boot.bin 应该放在软盘的哪一个扇区?为什么? 76 | 77 | 第一个扇区 78 | 79 | ![image-20211022165346425](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165346425.png) 80 | 81 | 13. loader 的作用有哪些? 82 | 83 | ![image-20211022165450862](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165450862.png) 84 | 85 | ![image-20211022165459732](C:\Users\XiaYu\AppData\Roaming\Typora\typora-user-images\image-20211022165459732.png) 86 | 87 | 14. 解释 NASM 语言中 [ ] 的作用 88 | 89 | 在nasm中,任何不被`[]`括起来的标签or变量是地址。访问标签中的内容必须用`[]` 90 | 91 | 15. 解释语句 times 510-($-$$),为什么是 510? $ 和 $$ 分别表示什么? 92 | 93 | `$` 表示程序当前位置的地址,也就是0x7c09 94 | 95 | `$$` 表示程序被编译后的开始地址,也就是0x7c00 96 | 97 | 表示在这个程序后填充0,直到达到510字节,然后加上结束标志位0xAA55正好是512字节,满一个扇区 98 | 99 | 16. 解释配置文件 bochsrc 文件中如下参数的含义 100 | * megs:how much memory the emulated machine will have,This option sets the 'guest' and 'host' memory parameters to the same value 101 | * display_library: the code that displays the Bochs VGA screen,使用sdl运行VGA屏幕 102 | * floppya: 指定哪个文件作为软盘映像, first drive 103 | * boot: this defines the boot sequence -------------------------------------------------------------------------------- /lab2/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 23 | 24 | 25 | 26 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 48 | 49 | 50 | 51 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 1636361833342 65 | 75 | 76 | 77 | 78 | 80 | -------------------------------------------------------------------------------- /lab2/lab2/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /../../../../:\share\lab2\.idea/dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /lab2/lab2/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /lab2/lab2/.idea/lab2.iml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /lab2/lab2/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lab2/lab2/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /lab2/lab2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | project(lab2) 3 | 4 | set(CMAKE_CXX_STANDARD 14) 5 | 6 | add_executable(lab2 7 | code/main.cpp) 8 | -------------------------------------------------------------------------------- /lab2/lab2/a.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/a.img -------------------------------------------------------------------------------- /lab2/lab2/catLong.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/catLong.png -------------------------------------------------------------------------------- /lab2/lab2/catShort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/catShort.png -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_COMPILER "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe") 2 | set(CMAKE_C_COMPILER_ARG1 "") 3 | set(CMAKE_C_COMPILER_ID "MSVC") 4 | set(CMAKE_C_COMPILER_VERSION "19.16.27045.0") 5 | set(CMAKE_C_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_C_COMPILER_WRAPPER "") 7 | set(CMAKE_C_STANDARD_COMPUTED_DEFAULT "90") 8 | set(CMAKE_C_COMPILE_FEATURES "c_std_90;c_std_99;c_std_11;c_function_prototypes;c_variadic_macros") 9 | set(CMAKE_C90_COMPILE_FEATURES "c_std_90;c_function_prototypes") 10 | set(CMAKE_C99_COMPILE_FEATURES "c_std_99;c_variadic_macros") 11 | set(CMAKE_C11_COMPILE_FEATURES "c_std_11") 12 | 13 | set(CMAKE_C_PLATFORM_ID "Windows") 14 | set(CMAKE_C_SIMULATE_ID "") 15 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT "") 16 | set(CMAKE_C_SIMULATE_VERSION "") 17 | set(CMAKE_C_COMPILER_ARCHITECTURE_ID X86) 18 | 19 | set(MSVC_C_ARCHITECTURE_ID X86) 20 | 21 | set(CMAKE_AR "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/lib.exe") 22 | set(CMAKE_C_COMPILER_AR "") 23 | set(CMAKE_RANLIB "") 24 | set(CMAKE_C_COMPILER_RANLIB "") 25 | set(CMAKE_LINKER "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/link.exe") 26 | set(CMAKE_MT "D:/Windows Kits/10/bin/10.0.17763.0/x86/mt.exe") 27 | set(CMAKE_COMPILER_IS_GNUCC ) 28 | set(CMAKE_C_COMPILER_LOADED 1) 29 | set(CMAKE_C_COMPILER_WORKS TRUE) 30 | set(CMAKE_C_ABI_COMPILED TRUE) 31 | set(CMAKE_COMPILER_IS_MINGW ) 32 | set(CMAKE_COMPILER_IS_CYGWIN ) 33 | if(CMAKE_COMPILER_IS_CYGWIN) 34 | set(CYGWIN 1) 35 | set(UNIX 1) 36 | endif() 37 | 38 | set(CMAKE_C_COMPILER_ENV_VAR "CC") 39 | 40 | if(CMAKE_COMPILER_IS_MINGW) 41 | set(MINGW 1) 42 | endif() 43 | set(CMAKE_C_COMPILER_ID_RUN 1) 44 | set(CMAKE_C_SOURCE_FILE_EXTENSIONS c;m) 45 | set(CMAKE_C_IGNORE_EXTENSIONS h;H;o;O;obj;OBJ;def;DEF;rc;RC) 46 | set(CMAKE_C_LINKER_PREFERENCE 10) 47 | 48 | # Save compiler ABI information. 49 | set(CMAKE_C_SIZEOF_DATA_PTR "4") 50 | set(CMAKE_C_COMPILER_ABI "") 51 | set(CMAKE_C_LIBRARY_ARCHITECTURE "") 52 | 53 | if(CMAKE_C_SIZEOF_DATA_PTR) 54 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_C_SIZEOF_DATA_PTR}") 55 | endif() 56 | 57 | if(CMAKE_C_COMPILER_ABI) 58 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_C_COMPILER_ABI}") 59 | endif() 60 | 61 | if(CMAKE_C_LIBRARY_ARCHITECTURE) 62 | set(CMAKE_LIBRARY_ARCHITECTURE "") 63 | endif() 64 | 65 | set(CMAKE_C_CL_SHOWINCLUDES_PREFIX "") 66 | if(CMAKE_C_CL_SHOWINCLUDES_PREFIX) 67 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_C_CL_SHOWINCLUDES_PREFIX}") 68 | endif() 69 | 70 | 71 | 72 | 73 | 74 | set(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES "") 75 | set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "") 76 | set(CMAKE_C_IMPLICIT_LINK_DIRECTORIES "") 77 | set(CMAKE_C_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 78 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeCXXCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_CXX_COMPILER "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe") 2 | set(CMAKE_CXX_COMPILER_ARG1 "") 3 | set(CMAKE_CXX_COMPILER_ID "MSVC") 4 | set(CMAKE_CXX_COMPILER_VERSION "19.16.27045.0") 5 | set(CMAKE_CXX_COMPILER_VERSION_INTERNAL "") 6 | set(CMAKE_CXX_COMPILER_WRAPPER "") 7 | set(CMAKE_CXX_STANDARD_COMPUTED_DEFAULT "14") 8 | set(CMAKE_CXX_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters;cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates;cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates;cxx_std_17;cxx_std_20") 9 | set(CMAKE_CXX98_COMPILE_FEATURES "cxx_std_98;cxx_template_template_parameters") 10 | set(CMAKE_CXX11_COMPILE_FEATURES "cxx_std_11;cxx_alias_templates;cxx_alignas;cxx_alignof;cxx_attributes;cxx_auto_type;cxx_constexpr;cxx_decltype;cxx_decltype_incomplete_return_types;cxx_default_function_template_args;cxx_defaulted_functions;cxx_defaulted_move_initializers;cxx_delegating_constructors;cxx_deleted_functions;cxx_enum_forward_declarations;cxx_explicit_conversions;cxx_extended_friend_declarations;cxx_extern_templates;cxx_final;cxx_func_identifier;cxx_generalized_initializers;cxx_inheriting_constructors;cxx_inline_namespaces;cxx_lambdas;cxx_local_type_template_args;cxx_long_long_type;cxx_noexcept;cxx_nonstatic_member_init;cxx_nullptr;cxx_override;cxx_range_for;cxx_raw_string_literals;cxx_reference_qualified_functions;cxx_right_angle_brackets;cxx_rvalue_references;cxx_sizeof_member;cxx_static_assert;cxx_strong_enums;cxx_thread_local;cxx_trailing_return_types;cxx_unicode_literals;cxx_uniform_initialization;cxx_unrestricted_unions;cxx_user_literals;cxx_variadic_macros;cxx_variadic_templates") 11 | set(CMAKE_CXX14_COMPILE_FEATURES "cxx_std_14;cxx_aggregate_default_initializers;cxx_attribute_deprecated;cxx_binary_literals;cxx_contextual_conversions;cxx_decltype_auto;cxx_digit_separators;cxx_generic_lambdas;cxx_lambda_init_captures;cxx_relaxed_constexpr;cxx_return_type_deduction;cxx_variable_templates") 12 | set(CMAKE_CXX17_COMPILE_FEATURES "cxx_std_17") 13 | set(CMAKE_CXX20_COMPILE_FEATURES "cxx_std_20") 14 | 15 | set(CMAKE_CXX_PLATFORM_ID "Windows") 16 | set(CMAKE_CXX_SIMULATE_ID "") 17 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT "") 18 | set(CMAKE_CXX_SIMULATE_VERSION "") 19 | set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID X86) 20 | 21 | set(MSVC_CXX_ARCHITECTURE_ID X86) 22 | 23 | set(CMAKE_AR "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/lib.exe") 24 | set(CMAKE_CXX_COMPILER_AR "") 25 | set(CMAKE_RANLIB "") 26 | set(CMAKE_CXX_COMPILER_RANLIB "") 27 | set(CMAKE_LINKER "D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/link.exe") 28 | set(CMAKE_MT "D:/Windows Kits/10/bin/10.0.17763.0/x86/mt.exe") 29 | set(CMAKE_COMPILER_IS_GNUCXX ) 30 | set(CMAKE_CXX_COMPILER_LOADED 1) 31 | set(CMAKE_CXX_COMPILER_WORKS TRUE) 32 | set(CMAKE_CXX_ABI_COMPILED TRUE) 33 | set(CMAKE_COMPILER_IS_MINGW ) 34 | set(CMAKE_COMPILER_IS_CYGWIN ) 35 | if(CMAKE_COMPILER_IS_CYGWIN) 36 | set(CYGWIN 1) 37 | set(UNIX 1) 38 | endif() 39 | 40 | set(CMAKE_CXX_COMPILER_ENV_VAR "CXX") 41 | 42 | if(CMAKE_COMPILER_IS_MINGW) 43 | set(MINGW 1) 44 | endif() 45 | set(CMAKE_CXX_COMPILER_ID_RUN 1) 46 | set(CMAKE_CXX_SOURCE_FILE_EXTENSIONS C;M;c++;cc;cpp;cxx;m;mm;CPP) 47 | set(CMAKE_CXX_IGNORE_EXTENSIONS inl;h;hpp;HPP;H;o;O;obj;OBJ;def;DEF;rc;RC) 48 | 49 | foreach (lang C OBJC OBJCXX) 50 | if (CMAKE_${lang}_COMPILER_ID_RUN) 51 | foreach(extension IN LISTS CMAKE_${lang}_SOURCE_FILE_EXTENSIONS) 52 | list(REMOVE_ITEM CMAKE_CXX_SOURCE_FILE_EXTENSIONS ${extension}) 53 | endforeach() 54 | endif() 55 | endforeach() 56 | 57 | set(CMAKE_CXX_LINKER_PREFERENCE 30) 58 | set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 1) 59 | 60 | # Save compiler ABI information. 61 | set(CMAKE_CXX_SIZEOF_DATA_PTR "4") 62 | set(CMAKE_CXX_COMPILER_ABI "") 63 | set(CMAKE_CXX_LIBRARY_ARCHITECTURE "") 64 | 65 | if(CMAKE_CXX_SIZEOF_DATA_PTR) 66 | set(CMAKE_SIZEOF_VOID_P "${CMAKE_CXX_SIZEOF_DATA_PTR}") 67 | endif() 68 | 69 | if(CMAKE_CXX_COMPILER_ABI) 70 | set(CMAKE_INTERNAL_PLATFORM_ABI "${CMAKE_CXX_COMPILER_ABI}") 71 | endif() 72 | 73 | if(CMAKE_CXX_LIBRARY_ARCHITECTURE) 74 | set(CMAKE_LIBRARY_ARCHITECTURE "") 75 | endif() 76 | 77 | set(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX "") 78 | if(CMAKE_CXX_CL_SHOWINCLUDES_PREFIX) 79 | set(CMAKE_CL_SHOWINCLUDES_PREFIX "${CMAKE_CXX_CL_SHOWINCLUDES_PREFIX}") 80 | endif() 81 | 82 | 83 | 84 | 85 | 86 | set(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES "") 87 | set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") 88 | set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "") 89 | set(CMAKE_CXX_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "") 90 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeDetermineCompilerABI_C.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeDetermineCompilerABI_C.bin -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeDetermineCompilerABI_CXX.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeDetermineCompilerABI_CXX.bin -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeRCCompiler.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_RC_COMPILER "D:/Windows Kits/10/bin/10.0.17763.0/x86/rc.exe") 2 | set(CMAKE_RC_COMPILER_ARG1 "") 3 | set(CMAKE_RC_COMPILER_LOADED 1) 4 | set(CMAKE_RC_SOURCE_FILE_EXTENSIONS rc;RC) 5 | set(CMAKE_RC_OUTPUT_EXTENSION .res) 6 | set(CMAKE_RC_COMPILER_ENV_VAR "RC") 7 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CMakeSystem.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_HOST_SYSTEM "Windows-10.0.19043") 2 | set(CMAKE_HOST_SYSTEM_NAME "Windows") 3 | set(CMAKE_HOST_SYSTEM_VERSION "10.0.19043") 4 | set(CMAKE_HOST_SYSTEM_PROCESSOR "AMD64") 5 | 6 | 7 | 8 | set(CMAKE_SYSTEM "Windows-10.0.19043") 9 | set(CMAKE_SYSTEM_NAME "Windows") 10 | set(CMAKE_SYSTEM_VERSION "10.0.19043") 11 | set(CMAKE_SYSTEM_PROCESSOR "AMD64") 12 | 13 | set(CMAKE_CROSSCOMPILING "FALSE") 14 | 15 | set(CMAKE_SYSTEM_LOADED 1) 16 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdC/CMakeCCompilerId.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdC/CMakeCCompilerId.exe -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdC/CMakeCCompilerId.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdC/CMakeCCompilerId.obj -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.exe -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.obj -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | # Relative path conversion top directories. 5 | set(CMAKE_RELATIVE_PATH_TOP_SOURCE "G:/share/lab2/lab2") 6 | set(CMAKE_RELATIVE_PATH_TOP_BINARY "G:/share/lab2/lab2/cmake-build-debug") 7 | 8 | 9 | # The C and CXX include file regular expressions for this directory. 10 | set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 11 | set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 12 | set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 13 | set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 14 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/CMakeOutput.log: -------------------------------------------------------------------------------- 1 | The system is: Windows - 10.0.19043 - AMD64 2 | Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded. 3 | Compiler: D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe 4 | Build flags: 5 | Id flags: 6 | 7 | The output was: 8 | 0 9 | 用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.16.27045 版 10 | 版权所有(C) Microsoft Corporation。保留所有权利。 11 | 12 | CMakeCCompilerId.c 13 | Microsoft (R) Incremental Linker Version 14.16.27045.0 14 | Copyright (C) Microsoft Corporation. All rights reserved. 15 | 16 | /out:CMakeCCompilerId.exe 17 | CMakeCCompilerId.obj 18 | 19 | 20 | Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.exe" 21 | 22 | Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.obj" 23 | 24 | The C compiler identification is MSVC, found in "G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdC/CMakeCCompilerId.exe" 25 | 26 | Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded. 27 | Compiler: D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe 28 | Build flags: 29 | Id flags: 30 | 31 | The output was: 32 | 0 33 | 用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.16.27045 版 34 | 版权所有(C) Microsoft Corporation。保留所有权利。 35 | 36 | CMakeCXXCompilerId.cpp 37 | Microsoft (R) Incremental Linker Version 14.16.27045.0 38 | Copyright (C) Microsoft Corporation. All rights reserved. 39 | 40 | /out:CMakeCXXCompilerId.exe 41 | CMakeCXXCompilerId.obj 42 | 43 | 44 | Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.exe" 45 | 46 | Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.obj" 47 | 48 | The CXX compiler identification is MSVC, found in "G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/3.19.2/CompilerIdCXX/CMakeCXXCompilerId.exe" 49 | 50 | Detecting C compiler ABI info compiled with the following output: 51 | Change Dir: G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/CMakeTmp 52 | 53 | Run Build Command(s):nmake /nologo cmTC_0e463\fast && D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe -f CMakeFiles\cmTC_0e463.dir\build.make /nologo -L CMakeFiles\cmTC_0e463.dir\build 54 | Building C object CMakeFiles/cmTC_0e463.dir/CMakeCCompilerABI.c.obj 55 | D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe @C:\Users\XiaYu\AppData\Local\Temp\nm2286.tmp 56 | CMakeCCompilerABI.c 57 | Linking C executable cmTC_0e463.exe 58 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_0e463.dir --rc="D:\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.17763.0\x86\mt.exe" --manifests -- D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\cmTC_0e463.dir\objects1.rsp @C:\Users\XiaYu\AppData\Local\Temp\nm2314.tmp 59 | 60 | 61 | 62 | Detecting CXX compiler ABI info compiled with the following output: 63 | Change Dir: G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/CMakeTmp 64 | 65 | Run Build Command(s):nmake /nologo cmTC_00d6d\fast && D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\HostX86\x86\nmake.exe -f CMakeFiles\cmTC_00d6d.dir\build.make /nologo -L CMakeFiles\cmTC_00d6d.dir\build 66 | Building CXX object CMakeFiles/cmTC_00d6d.dir/CMakeCXXCompilerABI.cpp.obj 67 | D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe @C:\Users\XiaYu\AppData\Local\Temp\nm2833.tmp 68 | CMakeCXXCompilerABI.cpp 69 | Linking CXX executable cmTC_00d6d.exe 70 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_00d6d.dir --rc="D:\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.17763.0\x86\mt.exe" --manifests -- D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\cmTC_00d6d.dir\objects1.rsp @C:\Users\XiaYu\AppData\Local\Temp\nm28FF.tmp 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/Makefile2: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | 7 | .PHONY : default_target 8 | 9 | #============================================================================= 10 | # Special targets provided by cmake. 11 | 12 | # Disable implicit rules so canonical targets will work. 13 | .SUFFIXES: 14 | 15 | 16 | .SUFFIXES: .hpux_make_needs_suffix_list 17 | 18 | 19 | # Command-line flag to silence nested $(MAKE). 20 | $(VERBOSE)MAKESILENT = -s 21 | 22 | #Suppress display of executed commands. 23 | $(VERBOSE).SILENT: 24 | 25 | # A target that is always out of date. 26 | cmake_force: 27 | 28 | .PHONY : cmake_force 29 | 30 | #============================================================================= 31 | # Set environment variables for the build. 32 | 33 | !IF "$(OS)" == "Windows_NT" 34 | NULL= 35 | !ELSE 36 | NULL=nul 37 | !ENDIF 38 | SHELL = cmd.exe 39 | 40 | # The CMake executable. 41 | CMAKE_COMMAND = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe 42 | 43 | # The command to remove a file. 44 | RM = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E rm -f 45 | 46 | # Escaping for special characters. 47 | EQUALS = = 48 | 49 | # The top-level source directory on which CMake was run. 50 | CMAKE_SOURCE_DIR = G:\share\lab2\lab2 51 | 52 | # The top-level build directory on which CMake was run. 53 | CMAKE_BINARY_DIR = G:\share\lab2\lab2\cmake-build-debug 54 | 55 | #============================================================================= 56 | # Directory level rules for the build root directory 57 | 58 | # The main recursive "all" target. 59 | all: CMakeFiles\lab2.dir\all 60 | 61 | .PHONY : all 62 | 63 | # The main recursive "preinstall" target. 64 | preinstall: 65 | 66 | .PHONY : preinstall 67 | 68 | # The main recursive "clean" target. 69 | clean: CMakeFiles\lab2.dir\clean 70 | 71 | .PHONY : clean 72 | 73 | #============================================================================= 74 | # Target rules for target CMakeFiles/lab2.dir 75 | 76 | # All Build rule for target. 77 | CMakeFiles\lab2.dir\all: 78 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\depend 79 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\build 80 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=G:\share\lab2\lab2\cmake-build-debug\CMakeFiles --progress-num=1,2 "Built target lab2" 81 | .PHONY : CMakeFiles\lab2.dir\all 82 | 83 | # Build rule for subdir invocation for target. 84 | CMakeFiles\lab2.dir\rule: cmake_check_build_system 85 | $(CMAKE_COMMAND) -E cmake_progress_start G:\share\lab2\lab2\cmake-build-debug\CMakeFiles 2 86 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\all 87 | $(CMAKE_COMMAND) -E cmake_progress_start G:\share\lab2\lab2\cmake-build-debug\CMakeFiles 0 88 | .PHONY : CMakeFiles\lab2.dir\rule 89 | 90 | # Convenience name for target. 91 | lab2: CMakeFiles\lab2.dir\rule 92 | 93 | .PHONY : lab2 94 | 95 | # clean rule for target. 96 | CMakeFiles\lab2.dir\clean: 97 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\clean 98 | .PHONY : CMakeFiles\lab2.dir\clean 99 | 100 | #============================================================================= 101 | # Special targets to cleanup operation of make. 102 | 103 | # Special rule to run CMake to check the build system integrity. 104 | # No rule that depends on this can have commands that come from listfiles 105 | # because they might be regenerated. 106 | cmake_check_build_system: 107 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0 108 | .PHONY : cmake_check_build_system 109 | 110 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- 1 | G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir 2 | G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/edit_cache.dir 3 | G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/rebuild_cache.dir 4 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/clion-environment.txt: -------------------------------------------------------------------------------- 1 | ToolSet: 15.0 (local)@D:\VisualStudio2017\vs 2 | Options: 3 | 4 | Options: -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/clion-log.txt: -------------------------------------------------------------------------------- 1 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - NMake Makefiles" G:\share\lab2\lab2 2 | -- The C compiler identification is MSVC 19.16.27045.0 3 | -- The CXX compiler identification is MSVC 19.16.27045.0 4 | -- Detecting C compiler ABI info 5 | -- Detecting C compiler ABI info - done 6 | -- Check for working C compiler: D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped 7 | -- Detecting C compile features 8 | -- Detecting C compile features - done 9 | -- Detecting CXX compiler ABI info 10 | -- Detecting CXX compiler ABI info - done 11 | -- Check for working CXX compiler: D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe - skipped 12 | -- Detecting CXX compile features 13 | -- Detecting CXX compile features - done 14 | -- Configuring done 15 | -- Generating done 16 | -- Build files have been written to: G:/share/lab2/lab2/cmake-build-debug 17 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/cmake.check_cache: -------------------------------------------------------------------------------- 1 | # This file is generated by cmake for dependency checking of the CMakeCache.txt file 2 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/CXX.includecache: -------------------------------------------------------------------------------- 1 | #IncludeRegexLine: ^[ ]*[#%][ ]*(include|import)[ ]*[<"]([^">]+)([">]) 2 | 3 | #IncludeRegexScan: ^.*$ 4 | 5 | #IncludeRegexComplain: ^$ 6 | 7 | #IncludeRegexTransform: 8 | 9 | G:/share/lab2/lab2/code/main.cpp 10 | fstream 11 | - 12 | iostream 13 | - 14 | string 15 | - 16 | vector 17 | - 18 | queue 19 | - 20 | 21 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/DependInfo.cmake: -------------------------------------------------------------------------------- 1 | # The set of languages for which implicit dependencies are needed: 2 | set(CMAKE_DEPENDS_LANGUAGES 3 | "CXX" 4 | ) 5 | # The set of files for implicit dependencies of each language: 6 | set(CMAKE_DEPENDS_CHECK_CXX 7 | "G:/share/lab2/lab2/code/main.cpp" "G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/code/main.cpp.obj" 8 | ) 9 | set(CMAKE_CXX_COMPILER_ID "MSVC") 10 | 11 | # The include file search paths: 12 | set(CMAKE_CXX_TARGET_INCLUDE_PATH 13 | ) 14 | 15 | # Targets to which this target links. 16 | set(CMAKE_TARGET_LINKED_INFO_FILES 17 | ) 18 | 19 | # Fortran module output directory. 20 | set(CMAKE_Fortran_TARGET_MODULE_DIR "") 21 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/build.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | # Delete rule output on recipe failure. 5 | .DELETE_ON_ERROR: 6 | 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canonical targets will work. 12 | .SUFFIXES: 13 | 14 | 15 | .SUFFIXES: .hpux_make_needs_suffix_list 16 | 17 | 18 | # Command-line flag to silence nested $(MAKE). 19 | $(VERBOSE)MAKESILENT = -s 20 | 21 | #Suppress display of executed commands. 22 | $(VERBOSE).SILENT: 23 | 24 | # A target that is always out of date. 25 | cmake_force: 26 | 27 | .PHONY : cmake_force 28 | 29 | #============================================================================= 30 | # Set environment variables for the build. 31 | 32 | !IF "$(OS)" == "Windows_NT" 33 | NULL= 34 | !ELSE 35 | NULL=nul 36 | !ENDIF 37 | SHELL = cmd.exe 38 | 39 | # The CMake executable. 40 | CMAKE_COMMAND = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe 41 | 42 | # The command to remove a file. 43 | RM = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E rm -f 44 | 45 | # Escaping for special characters. 46 | EQUALS = = 47 | 48 | # The top-level source directory on which CMake was run. 49 | CMAKE_SOURCE_DIR = G:\share\lab2\lab2 50 | 51 | # The top-level build directory on which CMake was run. 52 | CMAKE_BINARY_DIR = G:\share\lab2\lab2\cmake-build-debug 53 | 54 | # Include any dependencies generated for this target. 55 | include CMakeFiles\lab2.dir\depend.make 56 | 57 | # Include the progress variables for this target. 58 | include CMakeFiles\lab2.dir\progress.make 59 | 60 | # Include the compile flags for this target's objects. 61 | include CMakeFiles\lab2.dir\flags.make 62 | 63 | CMakeFiles\lab2.dir\code\main.cpp.obj: CMakeFiles\lab2.dir\flags.make 64 | CMakeFiles\lab2.dir\code\main.cpp.obj: ..\code\main.cpp 65 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=G:\share\lab2\lab2\cmake-build-debug\CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/lab2.dir/code/main.cpp.obj" 66 | D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe @<< 67 | /nologo /TP $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) /FoCMakeFiles\lab2.dir\code\main.cpp.obj /FdCMakeFiles\lab2.dir\ /FS -c G:\share\lab2\lab2\code\main.cpp 68 | << 69 | 70 | CMakeFiles\lab2.dir\code\main.cpp.i: cmake_force 71 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/lab2.dir/code/main.cpp.i" 72 | D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe > CMakeFiles\lab2.dir\code\main.cpp.i @<< 73 | /nologo /TP $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E G:\share\lab2\lab2\code\main.cpp 74 | << 75 | 76 | CMakeFiles\lab2.dir\code\main.cpp.s: cmake_force 77 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/lab2.dir/code/main.cpp.s" 78 | D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\cl.exe @<< 79 | /nologo /TP $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) /FoNUL /FAs /FaCMakeFiles\lab2.dir\code\main.cpp.s /c G:\share\lab2\lab2\code\main.cpp 80 | << 81 | 82 | # Object files for target lab2 83 | lab2_OBJECTS = \ 84 | "CMakeFiles\lab2.dir\code\main.cpp.obj" 85 | 86 | # External object files for target lab2 87 | lab2_EXTERNAL_OBJECTS = 88 | 89 | lab2.exe: CMakeFiles\lab2.dir\code\main.cpp.obj 90 | lab2.exe: CMakeFiles\lab2.dir\build.make 91 | lab2.exe: CMakeFiles\lab2.dir\objects1.rsp 92 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=G:\share\lab2\lab2\cmake-build-debug\CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable lab2.exe" 93 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\lab2.dir --rc="D:\Windows Kits\10\bin\10.0.17763.0\x86\rc.exe" --mt="D:\Windows Kits\10\bin\10.0.17763.0\x86\mt.exe" --manifests -- D:\VisualStudio2017\vs\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\link.exe /nologo @CMakeFiles\lab2.dir\objects1.rsp @<< 94 | /out:lab2.exe /implib:lab2.lib /pdb:G:\share\lab2\lab2\cmake-build-debug\lab2.pdb /version:0.0 /machine:X86 /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib 95 | << 96 | 97 | # Rule to build all files generated by this target. 98 | CMakeFiles\lab2.dir\build: lab2.exe 99 | 100 | .PHONY : CMakeFiles\lab2.dir\build 101 | 102 | CMakeFiles\lab2.dir\clean: 103 | $(CMAKE_COMMAND) -P CMakeFiles\lab2.dir\cmake_clean.cmake 104 | .PHONY : CMakeFiles\lab2.dir\clean 105 | 106 | CMakeFiles\lab2.dir\depend: 107 | $(CMAKE_COMMAND) -E cmake_depends "NMake Makefiles" G:\share\lab2\lab2 G:\share\lab2\lab2 G:\share\lab2\lab2\cmake-build-debug G:\share\lab2\lab2\cmake-build-debug G:\share\lab2\lab2\cmake-build-debug\CMakeFiles\lab2.dir\DependInfo.cmake --color=$(COLOR) 108 | .PHONY : CMakeFiles\lab2.dir\depend 109 | 110 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/cmake_clean.cmake: -------------------------------------------------------------------------------- 1 | file(REMOVE_RECURSE 2 | "CMakeFiles/lab2.dir/code/main.cpp.obj" 3 | "lab2.exe" 4 | "lab2.exe.manifest" 5 | "lab2.lib" 6 | "lab2.pdb" 7 | ) 8 | 9 | # Per-language clean rules from dependency scanning. 10 | foreach(lang CXX) 11 | include(CMakeFiles/lab2.dir/cmake_clean_${lang}.cmake OPTIONAL) 12 | endforeach() 13 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/code/main.cpp.obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/code/main.cpp.obj -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/depend.internal: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | CMakeFiles/lab2.dir/code/main.cpp.obj 5 | G:/share/lab2/lab2/code/main.cpp 6 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/depend.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | CMakeFiles\lab2.dir\code\main.cpp.obj: ..\code\main.cpp 5 | 6 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/embed.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/flags.make: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | # compile CXX with D:/VisualStudio2017/vs/VC/Tools/MSVC/14.16.27023/bin/Hostx86/x86/cl.exe 5 | CXX_DEFINES = 6 | 7 | CXX_INCLUDES = 8 | 9 | CXX_FLAGS = /DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd -std:c++14 10 | 11 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/intermediate.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/manifest.rc: -------------------------------------------------------------------------------- 1 | #pragma code_page(65001) 2 | 1 /* CREATEPROCESS_MANIFEST_RESOURCE_ID */ 24 /* RT_MANIFEST */ "G:/share/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/embed.manifest" -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/manifest.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/manifest.res -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/objects1.rsp: -------------------------------------------------------------------------------- 1 | CMakeFiles/lab2.dir/code/main.cpp.obj 2 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/progress.make: -------------------------------------------------------------------------------- 1 | CMAKE_PROGRESS_1 = 1 2 | CMAKE_PROGRESS_2 = 2 3 | 4 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/vc140.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/CMakeFiles/lab2.dir/vc140.pdb -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/Makefile: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "NMake Makefiles" Generator, CMake Version 3.19 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | 7 | .PHONY : default_target 8 | 9 | # Allow only one "make -f Makefile2" at a time, but pass parallelism. 10 | .NOTPARALLEL: 11 | 12 | 13 | #============================================================================= 14 | # Special targets provided by cmake. 15 | 16 | # Disable implicit rules so canonical targets will work. 17 | .SUFFIXES: 18 | 19 | 20 | .SUFFIXES: .hpux_make_needs_suffix_list 21 | 22 | 23 | # Command-line flag to silence nested $(MAKE). 24 | $(VERBOSE)MAKESILENT = -s 25 | 26 | #Suppress display of executed commands. 27 | $(VERBOSE).SILENT: 28 | 29 | # A target that is always out of date. 30 | cmake_force: 31 | 32 | .PHONY : cmake_force 33 | 34 | #============================================================================= 35 | # Set environment variables for the build. 36 | 37 | !IF "$(OS)" == "Windows_NT" 38 | NULL= 39 | !ELSE 40 | NULL=nul 41 | !ENDIF 42 | SHELL = cmd.exe 43 | 44 | # The CMake executable. 45 | CMAKE_COMMAND = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe 46 | 47 | # The command to remove a file. 48 | RM = D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E rm -f 49 | 50 | # Escaping for special characters. 51 | EQUALS = = 52 | 53 | # The top-level source directory on which CMake was run. 54 | CMAKE_SOURCE_DIR = G:\share\lab2\lab2 55 | 56 | # The top-level build directory on which CMake was run. 57 | CMAKE_BINARY_DIR = G:\share\lab2\lab2\cmake-build-debug 58 | 59 | #============================================================================= 60 | # Targets provided globally by CMake. 61 | 62 | # Special rule for the target edit_cache 63 | edit_cache: 64 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..." 65 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe -E echo "No interactive CMake dialog available." 66 | .PHONY : edit_cache 67 | 68 | # Special rule for the target edit_cache 69 | edit_cache\fast: edit_cache 70 | 71 | .PHONY : edit_cache\fast 72 | 73 | # Special rule for the target rebuild_cache 74 | rebuild_cache: 75 | @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." 76 | D:\Jetbrains\apps\CLion\ch-0\211.6693.114\bin\cmake\win\bin\cmake.exe --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 77 | .PHONY : rebuild_cache 78 | 79 | # Special rule for the target rebuild_cache 80 | rebuild_cache\fast: rebuild_cache 81 | 82 | .PHONY : rebuild_cache\fast 83 | 84 | # The main all target 85 | all: cmake_check_build_system 86 | $(CMAKE_COMMAND) -E cmake_progress_start G:\share\lab2\lab2\cmake-build-debug\CMakeFiles G:\share\lab2\lab2\cmake-build-debug\\CMakeFiles\progress.marks 87 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) all 88 | $(CMAKE_COMMAND) -E cmake_progress_start G:\share\lab2\lab2\cmake-build-debug\CMakeFiles 0 89 | .PHONY : all 90 | 91 | # The main clean target 92 | clean: 93 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) clean 94 | .PHONY : clean 95 | 96 | # The main clean target 97 | clean\fast: clean 98 | 99 | .PHONY : clean\fast 100 | 101 | # Prepare targets for installation. 102 | preinstall: all 103 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) preinstall 104 | .PHONY : preinstall 105 | 106 | # Prepare targets for installation. 107 | preinstall\fast: 108 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) preinstall 109 | .PHONY : preinstall\fast 110 | 111 | # clear depends 112 | depend: 113 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 1 114 | .PHONY : depend 115 | 116 | #============================================================================= 117 | # Target rules for targets named lab2 118 | 119 | # Build rule for target. 120 | lab2: cmake_check_build_system 121 | $(MAKE) $(MAKESILENT) -f CMakeFiles\Makefile2 /nologo -$(MAKEFLAGS) lab2 122 | .PHONY : lab2 123 | 124 | # fast build rule for target. 125 | lab2\fast: 126 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\build 127 | .PHONY : lab2\fast 128 | 129 | code\main.obj: code\main.cpp.obj 130 | 131 | .PHONY : code\main.obj 132 | 133 | # target to build an object file 134 | code\main.cpp.obj: 135 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\code\main.cpp.obj 136 | .PHONY : code\main.cpp.obj 137 | 138 | code\main.i: code\main.cpp.i 139 | 140 | .PHONY : code\main.i 141 | 142 | # target to preprocess a source file 143 | code\main.cpp.i: 144 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\code\main.cpp.i 145 | .PHONY : code\main.cpp.i 146 | 147 | code\main.s: code\main.cpp.s 148 | 149 | .PHONY : code\main.s 150 | 151 | # target to generate assembly for a file 152 | code\main.cpp.s: 153 | $(MAKE) $(MAKESILENT) -f CMakeFiles\lab2.dir\build.make /nologo -$(MAKEFLAGS) CMakeFiles\lab2.dir\code\main.cpp.s 154 | .PHONY : code\main.cpp.s 155 | 156 | # Help Target 157 | help: 158 | @echo The following are some of the valid targets for this Makefile: 159 | @echo ... all (the default if no target is provided) 160 | @echo ... clean 161 | @echo ... depend 162 | @echo ... edit_cache 163 | @echo ... rebuild_cache 164 | @echo ... lab2 165 | @echo ... code/main.obj 166 | @echo ... code/main.i 167 | @echo ... code/main.s 168 | .PHONY : help 169 | 170 | 171 | 172 | #============================================================================= 173 | # Special targets to cleanup operation of make. 174 | 175 | # Special rule to run CMake to check the build system integrity. 176 | # No rule that depends on this can have commands that come from listfiles 177 | # because they might be regenerated. 178 | cmake_check_build_system: 179 | $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles\Makefile.cmake 0 180 | .PHONY : cmake_check_build_system 181 | 182 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/Testing/Temporary/LastTest.log: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/Testing/Temporary/LastTest.log -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: G:/share/lab2/lab2 2 | 3 | # Set the install prefix 4 | if(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | set(CMAKE_INSTALL_PREFIX "C:/Program Files (x86)/lab2") 6 | endif() 7 | string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | if(BUILD_TYPE) 12 | string(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | else() 15 | set(CMAKE_INSTALL_CONFIG_NAME "Debug") 16 | endif() 17 | message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | endif() 19 | 20 | # Set the component getting installed. 21 | if(NOT CMAKE_INSTALL_COMPONENT) 22 | if(COMPONENT) 23 | message(STATUS "Install component: \"${COMPONENT}\"") 24 | set(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | else() 26 | set(CMAKE_INSTALL_COMPONENT) 27 | endif() 28 | endif() 29 | 30 | # Is this installation the result of a crosscompile? 31 | if(NOT DEFINED CMAKE_CROSSCOMPILING) 32 | set(CMAKE_CROSSCOMPILING "FALSE") 33 | endif() 34 | 35 | if(CMAKE_INSTALL_COMPONENT) 36 | set(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 37 | else() 38 | set(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 39 | endif() 40 | 41 | string(REPLACE ";" "\n" CMAKE_INSTALL_MANIFEST_CONTENT 42 | "${CMAKE_INSTALL_MANIFEST_FILES}") 43 | file(WRITE "G:/share/lab2/lab2/cmake-build-debug/${CMAKE_INSTALL_MANIFEST}" 44 | "${CMAKE_INSTALL_MANIFEST_CONTENT}") 45 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/lab2.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 94 | 95 | -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/lab2.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/lab2.exe -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/lab2.ilk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/lab2.ilk -------------------------------------------------------------------------------- /lab2/lab2/cmake-build-debug/lab2.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/cmake-build-debug/lab2.pdb -------------------------------------------------------------------------------- /lab2/lab2/code/main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/code/main.cpp -------------------------------------------------------------------------------- /lab2/lab2/code/makefile: -------------------------------------------------------------------------------- 1 | output: main.cpp my_print.o 2 | g++ -std=c++11 main.cpp my_print.o -o output 3 | 4 | my_print.o: my_print.asm 5 | nasm -f elf my_print.asm 6 | -------------------------------------------------------------------------------- /lab2/lab2/code/my_print.asm: -------------------------------------------------------------------------------- 1 | global sprint 2 | 3 | 4 | 5 | ;计算字符串长度 6 | slen: 7 | push ebx 8 | mov ebx, eax 9 | 10 | nextchar: 11 | cmp byte[eax], 0 12 | jz finished 13 | inc eax 14 | jmp nextchar 15 | 16 | finished: 17 | sub eax, ebx 18 | pop ebx 19 | ret 20 | 21 | 22 | ;打印字符串 23 | sprint: 24 | 25 | mov eax, [esp + 4] ;eax指向待打印的字符串 26 | 27 | push eax 28 | call slen 29 | mov edx, eax ;edx保存长度 30 | pop eax 31 | mov ecx, eax 32 | mov ebx, 1 ;ecx保存要打印字符串的起始地址 33 | mov eax, 4 34 | int 80h 35 | 36 | 37 | ret 38 | -------------------------------------------------------------------------------- /lab2/lab2/code/my_print.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/code/my_print.o -------------------------------------------------------------------------------- /lab2/lab2/code/output: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/code/output -------------------------------------------------------------------------------- /lab2/lab2/ls-l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/ls-l.png -------------------------------------------------------------------------------- /lab2/lab2/ls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/lab2/ls.png -------------------------------------------------------------------------------- /lab2/实验要求/2021 操作系统实验(二).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/实验要求/2021 操作系统实验(二).pdf -------------------------------------------------------------------------------- /lab2/实验要求/FAT12.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/实验要求/FAT12.pptx -------------------------------------------------------------------------------- /lab2/实验要求/gcc+nasm.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/实验要求/gcc+nasm.pptx -------------------------------------------------------------------------------- /lab2/实验要求/实模式与保护模式.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/实验要求/实模式与保护模式.pdf -------------------------------------------------------------------------------- /lab2/实验要求/静态链接动态链接.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab2/实验要求/静态链接动态链接.pptx -------------------------------------------------------------------------------- /lab3/code/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Win32", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [ 9 | "_DEBUG", 10 | "UNICODE", 11 | "_UNICODE" 12 | ], 13 | "windowsSdkVersion": "10.0.17763.0", 14 | "compilerPath": "D:/microsoft internet download/MinGW/bin/gcc.exe", 15 | "cStandard": "c17", 16 | "cppStandard": "c++17", 17 | "intelliSenseMode": "linux-gcc-x86" 18 | } 19 | ], 20 | "version": 4 21 | } -------------------------------------------------------------------------------- /lab3/code/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "files.associations": { 3 | "malloc.h": "c", 4 | "proto.h": "c", 5 | "type.h": "c", 6 | "const.h": "c", 7 | "protect.h": "c", 8 | "tty.h": "c", 9 | "console.h": "c", 10 | "proc.h": "c", 11 | "global.h": "c", 12 | "keyboard.h": "c" 13 | }, 14 | "cmake.configureOnOpen": false 15 | } 16 | -------------------------------------------------------------------------------- /lab3/code/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Makefile for Orange'S # 3 | ######################### 4 | 5 | # Entry point of Orange'S 6 | # It must have the same value with 'KernelEntryPointPhyAddr' in load.inc! 7 | ENTRYPOINT = 0x30400 8 | 9 | # Offset of entry point in kernel file 10 | # It depends on ENTRYPOINT 11 | ENTRYOFFSET = 0x400 12 | 13 | # Programs, flags, etc. 14 | ASM = nasm 15 | DASM = ndisasm 16 | CC = gcc 17 | LD = ld 18 | ASMBFLAGS = -I boot/include/ 19 | ASMKFLAGS = -I include/ -f elf 20 | CFLAGS = -I include/ -c -fno-builtin -fno-stack-protector 21 | LDFLAGS = -s -Ttext $(ENTRYPOINT) 22 | DASMFLAGS = -u -o $(ENTRYPOINT) -e $(ENTRYOFFSET) 23 | 24 | # This Program 25 | ORANGESBOOT = boot/boot.bin boot/loader.bin 26 | ORANGESKERNEL = kernel.bin 27 | OBJS = kernel/kernel.o kernel/syscall.o kernel/start.o kernel/main.o\ 28 | kernel/clock.o kernel/keyboard.o kernel/tty.o kernel/console.o\ 29 | kernel/i8259.o kernel/global.o kernel/protect.o kernel/proc.o\ 30 | lib/kliba.o lib/klib.o lib/string.o 31 | DASMOUTPUT = kernel.bin.asm 32 | 33 | # All Phony Targets 34 | .PHONY : everything final image clean realclean disasm all buildimg 35 | 36 | # Default starting position 37 | nop : 38 | @echo "why not \`make image' huh? :)" 39 | 40 | everything : $(ORANGESBOOT) $(ORANGESKERNEL) 41 | 42 | all : realclean everything 43 | 44 | run : image 45 | bochs 46 | 47 | image : realclean everything clean buildimg 48 | 49 | clean : 50 | rm -f $(OBJS) 51 | 52 | realclean : 53 | rm -f $(OBJS) $(ORANGESBOOT) $(ORANGESKERNEL) 54 | 55 | disasm : 56 | $(DASM) $(DASMFLAGS) $(ORANGESKERNEL) > $(DASMOUTPUT) 57 | 58 | # We assume that "a.img" exists in current folder 59 | buildimg : 60 | dd if=boot/boot.bin of=a.img bs=512 count=1 conv=notrunc 61 | sudo mount -o loop a.img /mnt/floppy/ 62 | sudo cp -fv boot/loader.bin /mnt/floppy/ 63 | sudo cp -fv kernel.bin /mnt/floppy 64 | sudo umount /mnt/floppy 65 | 66 | boot/boot.bin : boot/boot.asm boot/include/load.inc boot/include/fat12hdr.inc 67 | $(ASM) $(ASMBFLAGS) -o $@ $< 68 | 69 | boot/loader.bin : boot/loader.asm boot/include/load.inc boot/include/fat12hdr.inc boot/include/pm.inc 70 | $(ASM) $(ASMBFLAGS) -o $@ $< 71 | 72 | $(ORANGESKERNEL) : $(OBJS) 73 | $(LD) $(LDFLAGS) -o $(ORANGESKERNEL) $(OBJS) 74 | 75 | kernel/kernel.o : kernel/kernel.asm include/sconst.inc 76 | $(ASM) $(ASMKFLAGS) -o $@ $< 77 | 78 | kernel/syscall.o : kernel/syscall.asm include/sconst.inc 79 | $(ASM) $(ASMKFLAGS) -o $@ $< 80 | 81 | kernel/start.o: kernel/start.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 82 | include/global.h 83 | $(CC) $(CFLAGS) -o $@ $< 84 | 85 | kernel/main.o: kernel/main.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 86 | include/global.h 87 | $(CC) $(CFLAGS) -o $@ $< 88 | 89 | kernel/clock.o: kernel/clock.c 90 | $(CC) $(CFLAGS) -o $@ $< 91 | 92 | kernel/keyboard.o: kernel/keyboard.c 93 | $(CC) $(CFLAGS) -o $@ $< 94 | 95 | kernel/tty.o: kernel/tty.c 96 | $(CC) $(CFLAGS) -o $@ $< 97 | 98 | kernel/console.o: kernel/console.c 99 | $(CC) $(CFLAGS) -o $@ $< 100 | 101 | kernel/i8259.o: kernel/i8259.c include/type.h include/const.h include/protect.h include/proto.h 102 | $(CC) $(CFLAGS) -o $@ $< 103 | 104 | kernel/global.o: kernel/global.c include/type.h include/const.h include/protect.h include/proc.h \ 105 | include/global.h include/proto.h 106 | $(CC) $(CFLAGS) -o $@ $< 107 | 108 | kernel/protect.o: kernel/protect.c include/type.h include/const.h include/protect.h include/proc.h include/proto.h \ 109 | include/global.h 110 | $(CC) $(CFLAGS) -o $@ $< 111 | 112 | kernel/proc.o: kernel/proc.c 113 | $(CC) $(CFLAGS) -o $@ $< 114 | 115 | lib/klib.o: lib/klib.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 116 | include/global.h 117 | $(CC) $(CFLAGS) -o $@ $< 118 | 119 | lib/kliba.o : lib/kliba.asm 120 | $(ASM) $(ASMKFLAGS) -o $@ $< 121 | 122 | lib/string.o : lib/string.asm 123 | $(ASM) $(ASMKFLAGS) -o $@ $< 124 | -------------------------------------------------------------------------------- /lab3/code/a.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/code/a.img -------------------------------------------------------------------------------- /lab3/code/bochsrc: -------------------------------------------------------------------------------- 1 | ############################################################### 2 | # Configuration file for Bochs 3 | ############################################################### 4 | 5 | # how much memory the emulated machine will have 6 | megs: 32 7 | 8 | # filename of ROM images 9 | romimage: file=/usr/share/bochs/BIOS-bochs-latest 10 | vgaromimage: file=/usr/share/vgabios/vgabios.bin 11 | 12 | # what disk images will be used 13 | floppya: 1_44=a.img, status=inserted 14 | 15 | # choose the boot disk. 16 | boot: a 17 | 18 | # where do we send log messages? 19 | # log: bochsout.txt 20 | 21 | # disable the mouse 22 | mouse: enabled=0 23 | 24 | # enable key mapping, using US layout as default. 25 | keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map 26 | -------------------------------------------------------------------------------- /lab3/code/boot/boot.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; boot.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | 9 | ;%define _BOOT_DEBUG_ ; 做 Boot Sector 时一定将此行注释掉!将此行打开后用 nasm Boot.asm -o Boot.com 做成一个.COM文件易于调试 10 | 11 | %ifdef _BOOT_DEBUG_ 12 | org 0100h ; 调试状态, 做成 .COM 文件, 可调试 13 | %else 14 | org 07c00h ; Boot 状态, Bios 将把 Boot Sector 加载到 0:7C00 处并开始执行 15 | %endif 16 | 17 | ;================================================================================================ 18 | %ifdef _BOOT_DEBUG_ 19 | BaseOfStack equ 0100h ; 调试状态下堆栈基地址(栈底, 从这个位置向低地址生长) 20 | %else 21 | BaseOfStack equ 07c00h ; Boot状态下堆栈基地址(栈底, 从这个位置向低地址生长) 22 | %endif 23 | 24 | %include "load.inc" 25 | ;================================================================================================ 26 | 27 | jmp short LABEL_START ; Start to boot. 28 | nop ; 这个 nop 不可少 29 | 30 | ; 下面是 FAT12 磁盘的头, 之所以包含它是因为下面用到了磁盘的一些信息 31 | %include "fat12hdr.inc" 32 | 33 | LABEL_START: 34 | mov ax, cs 35 | mov ds, ax 36 | mov es, ax 37 | mov ss, ax 38 | mov sp, BaseOfStack 39 | 40 | ; 清屏 41 | mov ax, 0600h ; AH = 6, AL = 0h 42 | mov bx, 0700h ; 黑底白字(BL = 07h) 43 | mov cx, 0 ; 左上角: (0, 0) 44 | mov dx, 0184fh ; 右下角: (80, 50) 45 | int 10h ; int 10h 46 | 47 | mov dh, 0 ; "Booting " 48 | call DispStr ; 显示字符串 49 | 50 | xor ah, ah ; ┓ 51 | xor dl, dl ; ┣ 软驱复位 52 | int 13h ; ┛ 53 | 54 | ; 下面在 A 盘的根目录寻找 LOADER.BIN 55 | mov word [wSectorNo], SectorNoOfRootDirectory 56 | LABEL_SEARCH_IN_ROOT_DIR_BEGIN: 57 | cmp word [wRootDirSizeForLoop], 0 ; ┓ 58 | jz LABEL_NO_LOADERBIN ; ┣ 判断根目录区是不是已经读完 59 | dec word [wRootDirSizeForLoop] ; ┛ 如果读完表示没有找到 LOADER.BIN 60 | mov ax, BaseOfLoader 61 | mov es, ax ; es <- BaseOfLoader 62 | mov bx, OffsetOfLoader ; bx <- OffsetOfLoader 于是, es:bx = BaseOfLoader:OffsetOfLoader 63 | mov ax, [wSectorNo] ; ax <- Root Directory 中的某 Sector 号 64 | mov cl, 1 65 | call ReadSector 66 | 67 | mov si, LoaderFileName ; ds:si -> "LOADER BIN" 68 | mov di, OffsetOfLoader ; es:di -> BaseOfLoader:0100 = BaseOfLoader*10h+100 69 | cld 70 | mov dx, 10h 71 | LABEL_SEARCH_FOR_LOADERBIN: 72 | cmp dx, 0 ; ┓循环次数控制, 73 | jz LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR ; ┣如果已经读完了一个 Sector, 74 | dec dx ; ┛就跳到下一个 Sector 75 | mov cx, 11 76 | LABEL_CMP_FILENAME: 77 | cmp cx, 0 78 | jz LABEL_FILENAME_FOUND ; 如果比较了 11 个字符都相等, 表示找到 79 | dec cx 80 | lodsb ; ds:si -> al 81 | cmp al, byte [es:di] 82 | jz LABEL_GO_ON 83 | jmp LABEL_DIFFERENT ; 只要发现不一样的字符就表明本 DirectoryEntry 不是 84 | ; 我们要找的 LOADER.BIN 85 | LABEL_GO_ON: 86 | inc di 87 | jmp LABEL_CMP_FILENAME ; 继续循环 88 | 89 | LABEL_DIFFERENT: 90 | and di, 0FFE0h ; else ┓ di &= E0 为了让它指向本条目开头 91 | add di, 20h ; ┃ 92 | mov si, LoaderFileName ; ┣ di += 20h 下一个目录条目 93 | jmp LABEL_SEARCH_FOR_LOADERBIN; ┛ 94 | 95 | LABEL_GOTO_NEXT_SECTOR_IN_ROOT_DIR: 96 | add word [wSectorNo], 1 97 | jmp LABEL_SEARCH_IN_ROOT_DIR_BEGIN 98 | 99 | LABEL_NO_LOADERBIN: 100 | mov dh, 2 ; "No LOADER." 101 | call DispStr ; 显示字符串 102 | %ifdef _BOOT_DEBUG_ 103 | mov ax, 4c00h ; ┓ 104 | int 21h ; ┛没有找到 LOADER.BIN, 回到 DOS 105 | %else 106 | jmp $ ; 没有找到 LOADER.BIN, 死循环在这里 107 | %endif 108 | 109 | LABEL_FILENAME_FOUND: ; 找到 LOADER.BIN 后便来到这里继续 110 | mov ax, RootDirSectors 111 | and di, 0FFE0h ; di -> 当前条目的开始 112 | add di, 01Ah ; di -> 首 Sector 113 | mov cx, word [es:di] 114 | push cx ; 保存此 Sector 在 FAT 中的序号 115 | add cx, ax 116 | add cx, DeltaSectorNo ; 这句完成时 cl 里面变成 LOADER.BIN 的起始扇区号 (从 0 开始数的序号) 117 | mov ax, BaseOfLoader 118 | mov es, ax ; es <- BaseOfLoader 119 | mov bx, OffsetOfLoader ; bx <- OffsetOfLoader 于是, es:bx = BaseOfLoader:OffsetOfLoader = BaseOfLoader * 10h + OffsetOfLoader 120 | mov ax, cx ; ax <- Sector 号 121 | 122 | LABEL_GOON_LOADING_FILE: 123 | push ax ; ┓ 124 | push bx ; ┃ 125 | mov ah, 0Eh ; ┃ 每读一个扇区就在 "Booting " 后面打一个点, 形成这样的效果: 126 | mov al, '.' ; ┃ 127 | mov bl, 0Fh ; ┃ Booting ...... 128 | int 10h ; ┃ 129 | pop bx ; ┃ 130 | pop ax ; ┛ 131 | 132 | mov cl, 1 133 | call ReadSector 134 | pop ax ; 取出此 Sector 在 FAT 中的序号 135 | call GetFATEntry 136 | cmp ax, 0FFFh 137 | jz LABEL_FILE_LOADED 138 | push ax ; 保存 Sector 在 FAT 中的序号 139 | mov dx, RootDirSectors 140 | add ax, dx 141 | add ax, DeltaSectorNo 142 | add bx, [BPB_BytsPerSec] 143 | jmp LABEL_GOON_LOADING_FILE 144 | LABEL_FILE_LOADED: 145 | 146 | mov dh, 1 ; "Ready." 147 | call DispStr ; 显示字符串 148 | 149 | ; ***************************************************************************************************** 150 | jmp BaseOfLoader:OffsetOfLoader ; 这一句正式跳转到已加载到内存中的 LOADER.BIN 的开始处 151 | ; 开始执行 LOADER.BIN 的代码 152 | ; Boot Sector 的使命到此结束 153 | ; ***************************************************************************************************** 154 | 155 | 156 | 157 | ;============================================================================ 158 | ;变量 159 | ;---------------------------------------------------------------------------- 160 | wRootDirSizeForLoop dw RootDirSectors ; Root Directory 占用的扇区数, 在循环中会递减至零. 161 | wSectorNo dw 0 ; 要读取的扇区号 162 | bOdd db 0 ; 奇数还是偶数 163 | 164 | ;============================================================================ 165 | ;字符串 166 | ;---------------------------------------------------------------------------- 167 | LoaderFileName db "LOADER BIN", 0 ; LOADER.BIN 之文件名 168 | ; 为简化代码, 下面每个字符串的长度均为 MessageLength 169 | MessageLength equ 9 170 | BootMessage: db "Booting "; 9字节, 不够则用空格补齐. 序号 0 171 | Message1 db "Ready. "; 9字节, 不够则用空格补齐. 序号 1 172 | Message2 db "No LOADER"; 9字节, 不够则用空格补齐. 序号 2 173 | ;============================================================================ 174 | 175 | 176 | ;---------------------------------------------------------------------------- 177 | ; 函数名: DispStr 178 | ;---------------------------------------------------------------------------- 179 | ; 作用: 180 | ; 显示一个字符串, 函数开始时 dh 中应该是字符串序号(0-based) 181 | DispStr: 182 | mov ax, MessageLength 183 | mul dh 184 | add ax, BootMessage 185 | mov bp, ax ; ┓ 186 | mov ax, ds ; ┣ ES:BP = 串地址 187 | mov es, ax ; ┛ 188 | mov cx, MessageLength ; CX = 串长度 189 | mov ax, 01301h ; AH = 13, AL = 01h 190 | mov bx, 0007h ; 页号为0(BH = 0) 黑底白字(BL = 07h) 191 | mov dl, 0 192 | int 10h ; int 10h 193 | ret 194 | 195 | 196 | ;---------------------------------------------------------------------------- 197 | ; 函数名: ReadSector 198 | ;---------------------------------------------------------------------------- 199 | ; 作用: 200 | ; 从第 ax 个 Sector 开始, 将 cl 个 Sector 读入 es:bx 中 201 | ReadSector: 202 | ; ----------------------------------------------------------------------- 203 | ; 怎样由扇区号求扇区在磁盘中的位置 (扇区号 -> 柱面号, 起始扇区, 磁头号) 204 | ; ----------------------------------------------------------------------- 205 | ; 设扇区号为 x 206 | ; ┌ 柱面号 = y >> 1 207 | ; x ┌ 商 y ┤ 208 | ; -------------- => ┤ └ 磁头号 = y & 1 209 | ; 每磁道扇区数 │ 210 | ; └ 余 z => 起始扇区号 = z + 1 211 | push bp 212 | mov bp, sp 213 | sub esp, 2 ; 辟出两个字节的堆栈区域保存要读的扇区数: byte [bp-2] 214 | 215 | mov byte [bp-2], cl 216 | push bx ; 保存 bx 217 | mov bl, [BPB_SecPerTrk] ; bl: 除数 218 | div bl ; y 在 al 中, z 在 ah 中 219 | inc ah ; z ++ 220 | mov cl, ah ; cl <- 起始扇区号 221 | mov dh, al ; dh <- y 222 | shr al, 1 ; y >> 1 (其实是 y/BPB_NumHeads, 这里BPB_NumHeads=2) 223 | mov ch, al ; ch <- 柱面号 224 | and dh, 1 ; dh & 1 = 磁头号 225 | pop bx ; 恢复 bx 226 | ; 至此, "柱面号, 起始扇区, 磁头号" 全部得到 ^^^^^^^^^^^^^^^^^^^^^^^^ 227 | mov dl, [BS_DrvNum] ; 驱动器号 (0 表示 A 盘) 228 | .GoOnReading: 229 | mov ah, 2 ; 读 230 | mov al, byte [bp-2] ; 读 al 个扇区 231 | int 13h 232 | jc .GoOnReading ; 如果读取错误 CF 会被置为 1, 这时就不停地读, 直到正确为止 233 | 234 | add esp, 2 235 | pop bp 236 | 237 | ret 238 | 239 | ;---------------------------------------------------------------------------- 240 | ; 函数名: GetFATEntry 241 | ;---------------------------------------------------------------------------- 242 | ; 作用: 243 | ; 找到序号为 ax 的 Sector 在 FAT 中的条目, 结果放在 ax 中 244 | ; 需要注意的是, 中间需要读 FAT 的扇区到 es:bx 处, 所以函数一开始保存了 es 和 bx 245 | GetFATEntry: 246 | push es 247 | push bx 248 | push ax 249 | mov ax, BaseOfLoader ; ┓ 250 | sub ax, 0100h ; ┣ 在 BaseOfLoader 后面留出 4K 空间用于存放 FAT 251 | mov es, ax ; ┛ 252 | pop ax 253 | mov byte [bOdd], 0 254 | mov bx, 3 255 | mul bx ; dx:ax = ax * 3 256 | mov bx, 2 257 | div bx ; dx:ax / 2 ==> ax <- 商, dx <- 余数 258 | cmp dx, 0 259 | jz LABEL_EVEN 260 | mov byte [bOdd], 1 261 | LABEL_EVEN:;偶数 262 | xor dx, dx ; 现在 ax 中是 FATEntry 在 FAT 中的偏移量. 下面来计算 FATEntry 在哪个扇区中(FAT占用不止一个扇区) 263 | mov bx, [BPB_BytsPerSec] 264 | div bx ; dx:ax / BPB_BytsPerSec ==> ax <- 商 (FATEntry 所在的扇区相对于 FAT 来说的扇区号) 265 | ; dx <- 余数 (FATEntry 在扇区内的偏移)。 266 | push dx 267 | mov bx, 0 ; bx <- 0 于是, es:bx = (BaseOfLoader - 100):00 = (BaseOfLoader - 100) * 10h 268 | add ax, SectorNoOfFAT1 ; 此句执行之后的 ax 就是 FATEntry 所在的扇区号 269 | mov cl, 2 270 | call ReadSector ; 读取 FATEntry 所在的扇区, 一次读两个, 避免在边界发生错误, 因为一个 FATEntry 可能跨越两个扇区 271 | pop dx 272 | add bx, dx 273 | mov ax, [es:bx] 274 | cmp byte [bOdd], 1 275 | jnz LABEL_EVEN_2 276 | shr ax, 4 277 | LABEL_EVEN_2: 278 | and ax, 0FFFh 279 | 280 | LABEL_GET_FAT_ENRY_OK: 281 | 282 | pop bx 283 | pop es 284 | ret 285 | ;---------------------------------------------------------------------------- 286 | 287 | times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节 288 | dw 0xaa55 ; 结束标志 289 | -------------------------------------------------------------------------------- /lab3/code/boot/boot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/code/boot/boot.bin -------------------------------------------------------------------------------- /lab3/code/boot/include/fat12hdr.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; fat12hdr.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | 9 | ; FAT12 磁盘的头 10 | ; ---------------------------------------------------------------------- 11 | BS_OEMName DB 'ForrestY' ; OEM String, 必须 8 个字节 12 | 13 | BPB_BytsPerSec DW 512 ; 每扇区字节数 14 | BPB_SecPerClus DB 1 ; 每簇多少扇区 15 | BPB_RsvdSecCnt DW 1 ; Boot 记录占用多少扇区 16 | BPB_NumFATs DB 2 ; 共有多少 FAT 表 17 | BPB_RootEntCnt DW 224 ; 根目录文件数最大值 18 | BPB_TotSec16 DW 2880 ; 逻辑扇区总数 19 | BPB_Media DB 0xF0 ; 媒体描述符 20 | BPB_FATSz16 DW 9 ; 每FAT扇区数 21 | BPB_SecPerTrk DW 18 ; 每磁道扇区数 22 | BPB_NumHeads DW 2 ; 磁头数(面数) 23 | BPB_HiddSec DD 0 ; 隐藏扇区数 24 | BPB_TotSec32 DD 0 ; 如果 wTotalSectorCount 是 0 由这个值记录扇区数 25 | 26 | BS_DrvNum DB 0 ; 中断 13 的驱动器号 27 | BS_Reserved1 DB 0 ; 未使用 28 | BS_BootSig DB 29h ; 扩展引导标记 (29h) 29 | BS_VolID DD 0 ; 卷序列号 30 | BS_VolLab DB 'OrangeS0.02'; 卷标, 必须 11 个字节 31 | BS_FileSysType DB 'FAT12 ' ; 文件系统类型, 必须 8个字节 32 | ;------------------------------------------------------------------------ 33 | 34 | 35 | ; ------------------------------------------------------------------------- 36 | ; 基于 FAT12 头的一些常量定义,如果头信息改变,下面的常量可能也要做相应改变 37 | ; ------------------------------------------------------------------------- 38 | FATSz equ 9 ; BPB_FATSz16 39 | RootDirSectors equ 14 ; 根目录占用空间: RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec; 但如果按照此公式代码过长 40 | SectorNoOfRootDirectory equ 19 ; Root Directory 的第一个扇区号 = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) 41 | SectorNoOfFAT1 equ 1 ; FAT1 的第一个扇区号 = BPB_RsvdSecCnt 42 | DeltaSectorNo equ 17 ; DeltaSectorNo = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) - 2 43 | ; 文件的开始Sector号 = DirEntry中的开始Sector号 + 根目录占用Sector数目 + DeltaSectorNo 44 | -------------------------------------------------------------------------------- /lab3/code/boot/include/load.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; load.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | 9 | BaseOfLoader equ 09000h ; LOADER.BIN 被加载到的位置 ---- 段地址 10 | OffsetOfLoader equ 0100h ; LOADER.BIN 被加载到的位置 ---- 偏移地址 11 | 12 | BaseOfLoaderPhyAddr equ BaseOfLoader * 10h ; LOADER.BIN 被加载到的位置 ---- 物理地址 (= BaseOfLoader * 10h) 13 | 14 | 15 | BaseOfKernelFile equ 08000h ; KERNEL.BIN 被加载到的位置 ---- 段地址 16 | OffsetOfKernelFile equ 0h ; KERNEL.BIN 被加载到的位置 ---- 偏移地址 17 | 18 | BaseOfKernelFilePhyAddr equ BaseOfKernelFile * 10h 19 | KernelEntryPointPhyAddr equ 030400h ; 注意:1、必须与 MAKEFILE 中参数 -Ttext 的值相等!! 20 | ; 2、这是个地址而非仅仅是个偏移,如果 -Ttext 的值为 0x400400,则它的值也应该是 0x400400。 21 | 22 | PageDirBase equ 200000h ; 页目录开始地址: 2M 23 | PageTblBase equ 201000h ; 页表开始地址: 2M + 4K 24 | 25 | -------------------------------------------------------------------------------- /lab3/code/boot/loader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/code/boot/loader.bin -------------------------------------------------------------------------------- /lab3/code/include/console.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | console.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_CONSOLE_H_ 9 | #define _ORANGES_CONSOLE_H_ 10 | 11 | /* CONSOLE */ 12 | typedef struct s_console 13 | { 14 | unsigned int current_start_addr; /* 当前显示到了什么位置 */ 15 | unsigned int original_addr; /* 当前控制台对应显存位置 */ 16 | unsigned int v_mem_limit; /* 当前控制台占的显存大小 */ 17 | unsigned int cursor; /* 当前光标位置 */ 18 | unsigned int isSearch; /*当前是否在查找过程中*/ 19 | unsigned int closed; 20 | } CONSOLE; 21 | 22 | #define SCR_UP 1 /* scroll forward */ 23 | #define SCR_DN -1 /* scroll backward */ 24 | 25 | #define SCREEN_SIZE (80 * 25) 26 | #define SCREEN_WIDTH 80 27 | 28 | #define DEFAULT_CHAR_COLOR 0x07 /* 0000 0111 黑底白字 */ 29 | #define SEARCH_CHAR_COLOR 0x04 /*黑底红字*/ 30 | 31 | #endif /* _ORANGES_CONSOLE_H_ */ 32 | -------------------------------------------------------------------------------- /lab3/code/include/const.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | const.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_CONST_H_ 9 | #define _ORANGES_CONST_H_ 10 | 11 | /* EXTERN */ 12 | #define EXTERN extern /* EXTERN is defined as extern except in global.c */ 13 | 14 | /* 函数类型 */ 15 | #define PUBLIC /* PUBLIC is the opposite of PRIVATE */ 16 | #define PRIVATE static /* PRIVATE x limits the scope of x */ 17 | 18 | /* Color */ 19 | /* 20 | * e.g. MAKE_COLOR(BLUE, RED) 21 | * MAKE_COLOR(BLACK, RED) | BRIGHT 22 | * MAKE_COLOR(BLACK, RED) | BRIGHT | FLASH 23 | */ 24 | #define BLACK 0x0 /* 0000 */ 25 | #define WHITE 0x7 /* 0111 */ 26 | #define RED 0x4 /* 0100 */ 27 | #define GREEN 0x2 /* 0010 */ 28 | #define BLUE 0x1 /* 0001 */ 29 | #define FLASH 0x80 /* 1000 0000 */ 30 | #define BRIGHT 0x08 /* 0000 1000 */ 31 | #define MAKE_COLOR(x, y) (x | y) /* MAKE_COLOR(Background,Foreground) */ 32 | 33 | /* GDT 和 IDT 中描述符的个数 */ 34 | #define GDT_SIZE 128 35 | #define IDT_SIZE 256 36 | 37 | /* 权限 */ 38 | #define PRIVILEGE_KRNL 0 39 | #define PRIVILEGE_TASK 1 40 | #define PRIVILEGE_USER 3 41 | /* RPL */ 42 | #define RPL_KRNL SA_RPL0 43 | #define RPL_TASK SA_RPL1 44 | #define RPL_USER SA_RPL3 45 | 46 | /* TTY */ 47 | #define NR_CONSOLES 1 /* consoles */ 48 | 49 | /* 8259A interrupt controller ports. */ 50 | #define INT_M_CTL 0x20 /* I/O port for interrupt controller */ 51 | #define INT_M_CTLMASK 0x21 /* setting bits in this port disables ints */ 52 | #define INT_S_CTL 0xA0 /* I/O port for second interrupt controller */ 53 | #define INT_S_CTLMASK 0xA1 /* setting bits in this port disables ints */ 54 | 55 | /* 8253/8254 PIT (Programmable Interval Timer) */ 56 | #define TIMER0 0x40 /* I/O port for timer channel 0 */ 57 | #define TIMER_MODE 0x43 /* I/O port for timer mode control */ 58 | #define RATE_GENERATOR 0x34 /* 00-11-010-0 : \ 59 | * Counter0 - LSB then MSB - rate generator - binary \ 60 | */ 61 | #define TIMER_FREQ 1193182L /* clock frequency for timer in PC and AT */ 62 | #define HZ 100 /* clock freq (software settable on IBM-PC) */ 63 | 64 | /* AT keyboard */ 65 | /* 8042 ports */ 66 | #define KB_DATA 0x60 /* I/O port for keyboard data \ 67 | Read : Read Output Buffer \ 68 | Write: Write Input Buffer(8042 Data&8048 Command) */ 69 | #define KB_CMD 0x64 /* I/O port for keyboard command \ 70 | Read : Read Status Register \ 71 | Write: Write Input Buffer(8042 Command) */ 72 | #define LED_CODE 0xED 73 | #define KB_ACK 0xFA 74 | 75 | /* VGA */ 76 | #define CRTC_ADDR_REG 0x3D4 /* CRT Controller Registers - Addr Register */ 77 | #define CRTC_DATA_REG 0x3D5 /* CRT Controller Registers - Data Register */ 78 | #define START_ADDR_H 0xC /* reg index of video mem start addr (MSB) */ 79 | #define START_ADDR_L 0xD /* reg index of video mem start addr (LSB) */ 80 | #define CURSOR_H 0xE /* reg index of cursor position (MSB) */ 81 | #define CURSOR_L 0xF /* reg index of cursor position (LSB) */ 82 | #define V_MEM_BASE 0xB8000 /* base of color video memory */ 83 | #define V_MEM_SIZE 0x8000 /* 32K: B8000H -> BFFFFH */ 84 | 85 | /* Hardware interrupts */ 86 | #define NR_IRQ 16 /* Number of IRQs */ 87 | #define CLOCK_IRQ 0 88 | #define KEYBOARD_IRQ 1 89 | #define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */ 90 | #define ETHER_IRQ 3 /* default ethernet interrupt vector */ 91 | #define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */ 92 | #define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */ 93 | #define XT_WINI_IRQ 5 /* xt winchester */ 94 | #define FLOPPY_IRQ 6 /* floppy disk */ 95 | #define PRINTER_IRQ 7 96 | #define AT_WINI_IRQ 14 /* at winchester */ 97 | 98 | /* system call */ 99 | #define NR_SYS_CALL 1 100 | 101 | #endif /* _ORANGES_CONST_H_ */ 102 | -------------------------------------------------------------------------------- /lab3/code/include/global.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | global.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | /* EXTERN is defined as extern except in global.c */ 9 | #ifdef GLOBAL_VARIABLES_HERE 10 | #undef EXTERN 11 | #define EXTERN 12 | #endif 13 | 14 | EXTERN int ticks; 15 | 16 | EXTERN int disp_pos; 17 | EXTERN u8 gdt_ptr[6]; // 0~15:Limit 16~47:Base 18 | EXTERN DESCRIPTOR gdt[GDT_SIZE]; 19 | EXTERN u8 idt_ptr[6]; // 0~15:Limit 16~47:Base 20 | EXTERN GATE idt[IDT_SIZE]; 21 | 22 | EXTERN u32 k_reenter; 23 | 24 | EXTERN TSS tss; 25 | EXTERN PROCESS *p_proc_ready; 26 | 27 | EXTERN int nr_current_console; 28 | 29 | extern PROCESS proc_table[]; 30 | extern char task_stack[]; 31 | extern TASK task_table[]; 32 | extern TASK user_proc_table[]; 33 | extern irq_handler irq_table[]; 34 | extern TTY tty_table[]; 35 | extern CONSOLE console_table[]; 36 | -------------------------------------------------------------------------------- /lab3/code/include/keyboard.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | keyboard.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, December, 2003 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_KEYBOARD_H_ 9 | #define _ORANGES_KEYBOARD_H_ 10 | 11 | 12 | /************************************************************************/ 13 | /* Macros Declaration */ 14 | /************************************************************************/ 15 | #define KB_IN_BYTES 32 /* size of keyboard input buffer */ 16 | #define MAP_COLS 3 /* Number of columns in keymap */ 17 | #define NR_SCAN_CODES 0x80 /* Number of scan codes (rows in keymap) */ 18 | 19 | #define FLAG_BREAK 0x0080 /* Break Code */ 20 | #define FLAG_EXT 0x0100 /* Normal function keys */ 21 | #define FLAG_SHIFT_L 0x0200 /* Shift key */ 22 | #define FLAG_SHIFT_R 0x0400 /* Shift key */ 23 | #define FLAG_CTRL_L 0x0800 /* Control key */ 24 | #define FLAG_CTRL_R 0x1000 /* Control key */ 25 | #define FLAG_ALT_L 0x2000 /* Alternate key */ 26 | #define FLAG_ALT_R 0x4000 /* Alternate key */ 27 | #define FLAG_PAD 0x8000 /* keys in num pad */ 28 | 29 | #define MASK_RAW 0x01FF /* raw key value = code passed to tty & MASK_RAW 30 | the value can be found either in the keymap column 0 31 | or in the list below */ 32 | 33 | /* Special keys */ 34 | #define ESC (0x01 + FLAG_EXT) /* Esc */ 35 | #define TAB (0x02 + FLAG_EXT) /* Tab */ 36 | #define ENTER (0x03 + FLAG_EXT) /* Enter */ 37 | #define BACKSPACE (0x04 + FLAG_EXT) /* BackSpace */ 38 | 39 | #define GUI_L (0x05 + FLAG_EXT) /* L GUI */ 40 | #define GUI_R (0x06 + FLAG_EXT) /* R GUI */ 41 | #define APPS (0x07 + FLAG_EXT) /* APPS */ 42 | 43 | /* Shift, Ctrl, Alt */ 44 | #define SHIFT_L (0x08 + FLAG_EXT) /* L Shift */ 45 | #define SHIFT_R (0x09 + FLAG_EXT) /* R Shift */ 46 | #define CTRL_L (0x0A + FLAG_EXT) /* L Ctrl */ 47 | #define CTRL_R (0x0B + FLAG_EXT) /* R Ctrl */ 48 | #define ALT_L (0x0C + FLAG_EXT) /* L Alt */ 49 | #define ALT_R (0x0D + FLAG_EXT) /* R Alt */ 50 | 51 | /* Lock keys */ 52 | #define CAPS_LOCK (0x0E + FLAG_EXT) /* Caps Lock */ 53 | #define NUM_LOCK (0x0F + FLAG_EXT) /* Number Lock */ 54 | #define SCROLL_LOCK (0x10 + FLAG_EXT) /* Scroll Lock */ 55 | 56 | /* Function keys */ 57 | #define F1 (0x11 + FLAG_EXT) /* F1 */ 58 | #define F2 (0x12 + FLAG_EXT) /* F2 */ 59 | #define F3 (0x13 + FLAG_EXT) /* F3 */ 60 | #define F4 (0x14 + FLAG_EXT) /* F4 */ 61 | #define F5 (0x15 + FLAG_EXT) /* F5 */ 62 | #define F6 (0x16 + FLAG_EXT) /* F6 */ 63 | #define F7 (0x17 + FLAG_EXT) /* F7 */ 64 | #define F8 (0x18 + FLAG_EXT) /* F8 */ 65 | #define F9 (0x19 + FLAG_EXT) /* F9 */ 66 | #define F10 (0x1A + FLAG_EXT) /* F10 */ 67 | #define F11 (0x1B + FLAG_EXT) /* F11 */ 68 | #define F12 (0x1C + FLAG_EXT) /* F12 */ 69 | 70 | /* Control Pad */ 71 | #define PRINTSCREEN (0x1D + FLAG_EXT) /* Print Screen */ 72 | #define PAUSEBREAK (0x1E + FLAG_EXT) /* Pause/Break */ 73 | #define INSERT (0x1F + FLAG_EXT) /* Insert */ 74 | #define DELETE (0x20 + FLAG_EXT) /* Delete */ 75 | #define HOME (0x21 + FLAG_EXT) /* Home */ 76 | #define END (0x22 + FLAG_EXT) /* End */ 77 | #define PAGEUP (0x23 + FLAG_EXT) /* Page Up */ 78 | #define PAGEDOWN (0x24 + FLAG_EXT) /* Page Down */ 79 | #define UP (0x25 + FLAG_EXT) /* Up */ 80 | #define DOWN (0x26 + FLAG_EXT) /* Down */ 81 | #define LEFT (0x27 + FLAG_EXT) /* Left */ 82 | #define RIGHT (0x28 + FLAG_EXT) /* Right */ 83 | 84 | /* ACPI keys */ 85 | #define POWER (0x29 + FLAG_EXT) /* Power */ 86 | #define SLEEP (0x2A + FLAG_EXT) /* Sleep */ 87 | #define WAKE (0x2B + FLAG_EXT) /* Wake Up */ 88 | 89 | /* Num Pad */ 90 | #define PAD_SLASH (0x2C + FLAG_EXT) /* / */ 91 | #define PAD_STAR (0x2D + FLAG_EXT) /* * */ 92 | #define PAD_MINUS (0x2E + FLAG_EXT) /* - */ 93 | #define PAD_PLUS (0x2F + FLAG_EXT) /* + */ 94 | #define PAD_ENTER (0x30 + FLAG_EXT) /* Enter */ 95 | #define PAD_DOT (0x31 + FLAG_EXT) /* . */ 96 | #define PAD_0 (0x32 + FLAG_EXT) /* 0 */ 97 | #define PAD_1 (0x33 + FLAG_EXT) /* 1 */ 98 | #define PAD_2 (0x34 + FLAG_EXT) /* 2 */ 99 | #define PAD_3 (0x35 + FLAG_EXT) /* 3 */ 100 | #define PAD_4 (0x36 + FLAG_EXT) /* 4 */ 101 | #define PAD_5 (0x37 + FLAG_EXT) /* 5 */ 102 | #define PAD_6 (0x38 + FLAG_EXT) /* 6 */ 103 | #define PAD_7 (0x39 + FLAG_EXT) /* 7 */ 104 | #define PAD_8 (0x3A + FLAG_EXT) /* 8 */ 105 | #define PAD_9 (0x3B + FLAG_EXT) /* 9 */ 106 | #define PAD_UP PAD_8 /* Up */ 107 | #define PAD_DOWN PAD_2 /* Down */ 108 | #define PAD_LEFT PAD_4 /* Left */ 109 | #define PAD_RIGHT PAD_6 /* Right */ 110 | #define PAD_HOME PAD_7 /* Home */ 111 | #define PAD_END PAD_1 /* End */ 112 | #define PAD_PAGEUP PAD_9 /* Page Up */ 113 | #define PAD_PAGEDOWN PAD_3 /* Page Down */ 114 | #define PAD_INS PAD_0 /* Ins */ 115 | #define PAD_MID PAD_5 /* Middle key */ 116 | #define PAD_DEL PAD_DOT /* Del */ 117 | 118 | 119 | /************************************************************************/ 120 | /* Stucture Definition */ 121 | /************************************************************************/ 122 | /* Keyboard structure, 1 per console. */ 123 | typedef struct s_kb { 124 | char* p_head; /* 指向缓冲区中下一个空闲位置 */ 125 | char* p_tail; /* 指向键盘任务应处理的字节 */ 126 | int count; /* 缓冲区中共有多少字节 */ 127 | char buf[KB_IN_BYTES]; /* 缓冲区 */ 128 | }KB_INPUT; 129 | 130 | 131 | 132 | #endif /* _ORANGES_KEYBOARD_H_ */ 133 | -------------------------------------------------------------------------------- /lab3/code/include/keymap.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | keymap.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, January, 2004 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | /********************************************************************/ 9 | /* "scan code" <--> "key" map. */ 10 | /* It should be and can only be included by keyboard.c! */ 11 | /********************************************************************/ 12 | 13 | #ifndef _ORANGES_KEYMAP_H_ 14 | #define _ORANGES_KEYMAP_H_ 15 | 16 | 17 | /* Keymap for US MF-2 keyboard. */ 18 | 19 | u32 keymap[NR_SCAN_CODES * MAP_COLS] = { 20 | 21 | /* scan-code !Shift Shift E0 XX */ 22 | /* ==================================================================== */ 23 | /* 0x00 - none */ 0, 0, 0, 24 | /* 0x01 - ESC */ ESC, ESC, 0, 25 | /* 0x02 - '1' */ '1', '!', 0, 26 | /* 0x03 - '2' */ '2', '@', 0, 27 | /* 0x04 - '3' */ '3', '#', 0, 28 | /* 0x05 - '4' */ '4', '$', 0, 29 | /* 0x06 - '5' */ '5', '%', 0, 30 | /* 0x07 - '6' */ '6', '^', 0, 31 | /* 0x08 - '7' */ '7', '&', 0, 32 | /* 0x09 - '8' */ '8', '*', 0, 33 | /* 0x0A - '9' */ '9', '(', 0, 34 | /* 0x0B - '0' */ '0', ')', 0, 35 | /* 0x0C - '-' */ '-', '_', 0, 36 | /* 0x0D - '=' */ '=', '+', 0, 37 | /* 0x0E - BS */ BACKSPACE, BACKSPACE, 0, 38 | /* 0x0F - TAB */ TAB, TAB, 0, 39 | /* 0x10 - 'q' */ 'q', 'Q', 0, 40 | /* 0x11 - 'w' */ 'w', 'W', 0, 41 | /* 0x12 - 'e' */ 'e', 'E', 0, 42 | /* 0x13 - 'r' */ 'r', 'R', 0, 43 | /* 0x14 - 't' */ 't', 'T', 0, 44 | /* 0x15 - 'y' */ 'y', 'Y', 0, 45 | /* 0x16 - 'u' */ 'u', 'U', 0, 46 | /* 0x17 - 'i' */ 'i', 'I', 0, 47 | /* 0x18 - 'o' */ 'o', 'O', 0, 48 | /* 0x19 - 'p' */ 'p', 'P', 0, 49 | /* 0x1A - '[' */ '[', '{', 0, 50 | /* 0x1B - ']' */ ']', '}', 0, 51 | /* 0x1C - CR/LF */ ENTER, ENTER, PAD_ENTER, 52 | /* 0x1D - l. Ctrl */ CTRL_L, CTRL_L, CTRL_R, 53 | /* 0x1E - 'a' */ 'a', 'A', 0, 54 | /* 0x1F - 's' */ 's', 'S', 0, 55 | /* 0x20 - 'd' */ 'd', 'D', 0, 56 | /* 0x21 - 'f' */ 'f', 'F', 0, 57 | /* 0x22 - 'g' */ 'g', 'G', 0, 58 | /* 0x23 - 'h' */ 'h', 'H', 0, 59 | /* 0x24 - 'j' */ 'j', 'J', 0, 60 | /* 0x25 - 'k' */ 'k', 'K', 0, 61 | /* 0x26 - 'l' */ 'l', 'L', 0, 62 | /* 0x27 - ';' */ ';', ':', 0, 63 | /* 0x28 - '\'' */ '\'', '"', 0, 64 | /* 0x29 - '`' */ '`', '~', 0, 65 | /* 0x2A - l. SHIFT */ SHIFT_L, SHIFT_L, 0, 66 | /* 0x2B - '\' */ '\\', '|', 0, 67 | /* 0x2C - 'z' */ 'z', 'Z', 0, 68 | /* 0x2D - 'x' */ 'x', 'X', 0, 69 | /* 0x2E - 'c' */ 'c', 'C', 0, 70 | /* 0x2F - 'v' */ 'v', 'V', 0, 71 | /* 0x30 - 'b' */ 'b', 'B', 0, 72 | /* 0x31 - 'n' */ 'n', 'N', 0, 73 | /* 0x32 - 'm' */ 'm', 'M', 0, 74 | /* 0x33 - ',' */ ',', '<', 0, 75 | /* 0x34 - '.' */ '.', '>', 0, 76 | /* 0x35 - '/' */ '/', '?', PAD_SLASH, 77 | /* 0x36 - r. SHIFT */ SHIFT_R, SHIFT_R, 0, 78 | /* 0x37 - '*' */ '*', '*', 0, 79 | /* 0x38 - ALT */ ALT_L, ALT_L, ALT_R, 80 | /* 0x39 - ' ' */ ' ', ' ', 0, 81 | /* 0x3A - CapsLock */ CAPS_LOCK, CAPS_LOCK, 0, 82 | /* 0x3B - F1 */ F1, F1, 0, 83 | /* 0x3C - F2 */ F2, F2, 0, 84 | /* 0x3D - F3 */ F3, F3, 0, 85 | /* 0x3E - F4 */ F4, F4, 0, 86 | /* 0x3F - F5 */ F5, F5, 0, 87 | /* 0x40 - F6 */ F6, F6, 0, 88 | /* 0x41 - F7 */ F7, F7, 0, 89 | /* 0x42 - F8 */ F8, F8, 0, 90 | /* 0x43 - F9 */ F9, F9, 0, 91 | /* 0x44 - F10 */ F10, F10, 0, 92 | /* 0x45 - NumLock */ NUM_LOCK, NUM_LOCK, 0, 93 | /* 0x46 - ScrLock */ SCROLL_LOCK, SCROLL_LOCK, 0, 94 | /* 0x47 - Home */ PAD_HOME, '7', HOME, 95 | /* 0x48 - CurUp */ PAD_UP, '8', UP, 96 | /* 0x49 - PgUp */ PAD_PAGEUP, '9', PAGEUP, 97 | /* 0x4A - '-' */ PAD_MINUS, '-', 0, 98 | /* 0x4B - Left */ PAD_LEFT, '4', LEFT, 99 | /* 0x4C - MID */ PAD_MID, '5', 0, 100 | /* 0x4D - Right */ PAD_RIGHT, '6', RIGHT, 101 | /* 0x4E - '+' */ PAD_PLUS, '+', 0, 102 | /* 0x4F - End */ PAD_END, '1', END, 103 | /* 0x50 - Down */ PAD_DOWN, '2', DOWN, 104 | /* 0x51 - PgDown */ PAD_PAGEDOWN, '3', PAGEDOWN, 105 | /* 0x52 - Insert */ PAD_INS, '0', INSERT, 106 | /* 0x53 - Delete */ PAD_DOT, '.', DELETE, 107 | /* 0x54 - Enter */ 0, 0, 0, 108 | /* 0x55 - ??? */ 0, 0, 0, 109 | /* 0x56 - ??? */ 0, 0, 0, 110 | /* 0x57 - F11 */ F11, F11, 0, 111 | /* 0x58 - F12 */ F12, F12, 0, 112 | /* 0x59 - ??? */ 0, 0, 0, 113 | /* 0x5A - ??? */ 0, 0, 0, 114 | /* 0x5B - ??? */ 0, 0, GUI_L, 115 | /* 0x5C - ??? */ 0, 0, GUI_R, 116 | /* 0x5D - ??? */ 0, 0, APPS, 117 | /* 0x5E - ??? */ 0, 0, 0, 118 | /* 0x5F - ??? */ 0, 0, 0, 119 | /* 0x60 - ??? */ 0, 0, 0, 120 | /* 0x61 - ??? */ 0, 0, 0, 121 | /* 0x62 - ??? */ 0, 0, 0, 122 | /* 0x63 - ??? */ 0, 0, 0, 123 | /* 0x64 - ??? */ 0, 0, 0, 124 | /* 0x65 - ??? */ 0, 0, 0, 125 | /* 0x66 - ??? */ 0, 0, 0, 126 | /* 0x67 - ??? */ 0, 0, 0, 127 | /* 0x68 - ??? */ 0, 0, 0, 128 | /* 0x69 - ??? */ 0, 0, 0, 129 | /* 0x6A - ??? */ 0, 0, 0, 130 | /* 0x6B - ??? */ 0, 0, 0, 131 | /* 0x6C - ??? */ 0, 0, 0, 132 | /* 0x6D - ??? */ 0, 0, 0, 133 | /* 0x6E - ??? */ 0, 0, 0, 134 | /* 0x6F - ??? */ 0, 0, 0, 135 | /* 0x70 - ??? */ 0, 0, 0, 136 | /* 0x71 - ??? */ 0, 0, 0, 137 | /* 0x72 - ??? */ 0, 0, 0, 138 | /* 0x73 - ??? */ 0, 0, 0, 139 | /* 0x74 - ??? */ 0, 0, 0, 140 | /* 0x75 - ??? */ 0, 0, 0, 141 | /* 0x76 - ??? */ 0, 0, 0, 142 | /* 0x77 - ??? */ 0, 0, 0, 143 | /* 0x78 - ??? */ 0, 0, 0, 144 | /* 0x78 - ??? */ 0, 0, 0, 145 | /* 0x7A - ??? */ 0, 0, 0, 146 | /* 0x7B - ??? */ 0, 0, 0, 147 | /* 0x7C - ??? */ 0, 0, 0, 148 | /* 0x7D - ??? */ 0, 0, 0, 149 | /* 0x7E - ??? */ 0, 0, 0, 150 | /* 0x7F - ??? */ 0, 0, 0 151 | }; 152 | 153 | 154 | /* 155 | 回车键: 把光标移到第一列 156 | 换行键: 把光标前进到下一行 157 | */ 158 | 159 | 160 | /*====================================================================================* 161 | Appendix: Scan code set 1 162 | *====================================================================================* 163 | 164 | KEY MAKE BREAK ----- KEY MAKE BREAK ----- KEY MAKE BREAK 165 | -------------------------------------------------------------------------------------- 166 | A 1E 9E 9 0A 8A [ 1A 9A 167 | B 30 B0 ` 29 89 INSERT E0,52 E0,D2 168 | C 2E AE - 0C 8C HOME E0,47 E0,C7 169 | D 20 A0 = 0D 8D PG UP E0,49 E0,C9 170 | E 12 92 \ 2B AB DELETE E0,53 E0,D3 171 | F 21 A1 BKSP 0E 8E END E0,4F E0,CF 172 | G 22 A2 SPACE 39 B9 PG DN E0,51 E0,D1 173 | H 23 A3 TAB 0F 8F U ARROW E0,48 E0,C8 174 | I 17 97 CAPS 3A BA L ARROW E0,4B E0,CB 175 | J 24 A4 L SHFT 2A AA D ARROW E0,50 E0,D0 176 | K 25 A5 L CTRL 1D 9D R ARROW E0,4D E0,CD 177 | L 26 A6 L GUI E0,5B E0,DB NUM 45 C5 178 | M 32 B2 L ALT 38 B8 KP / E0,35 E0,B5 179 | N 31 B1 R SHFT 36 B6 KP * 37 B7 180 | O 18 98 R CTRL E0,1D E0,9D KP - 4A CA 181 | P 19 99 R GUI E0,5C E0,DC KP + 4E CE 182 | Q 10 19 R ALT E0,38 E0,B8 KP EN E0,1C E0,9C 183 | R 13 93 APPS E0,5D E0,DD KP . 53 D3 184 | S 1F 9F ENTER 1C 9C KP 0 52 D2 185 | T 14 94 ESC 01 81 KP 1 4F CF 186 | U 16 96 F1 3B BB KP 2 50 D0 187 | V 2F AF F2 3C BC KP 3 51 D1 188 | W 11 91 F3 3D BD KP 4 4B CB 189 | X 2D AD F4 3E BE KP 5 4C CC 190 | Y 15 95 F5 3F BF KP 6 4D CD 191 | Z 2C AC F6 40 C0 KP 7 47 C7 192 | 0 0B 8B F7 41 C1 KP 8 48 C8 193 | 1 02 82 F8 42 C2 KP 9 49 C9 194 | 2 03 83 F9 43 C3 ] 1B 9B 195 | 3 04 84 F10 44 C4 ; 27 A7 196 | 4 05 85 F11 57 D7 ' 28 A8 197 | 5 06 86 F12 58 D8 , 33 B3 198 | 199 | 6 07 87 PRTSCRN E0,2A E0,B7 . 34 B4 200 | E0,37 E0,AA 201 | 202 | 7 08 88 SCROLL 46 C6 / 35 B5 203 | 204 | 8 09 89 PAUSE E1,1D,45 -NONE- 205 | E1,9D,C5 206 | 207 | 208 | ----------------- 209 | ACPI Scan Codes: 210 | ------------------------------------------- 211 | Key Make Code Break Code 212 | ------------------------------------------- 213 | Power E0, 5E E0, DE 214 | Sleep E0, 5F E0, DF 215 | Wake E0, 63 E0, E3 216 | 217 | 218 | ------------------------------- 219 | Windows Multimedia Scan Codes: 220 | ------------------------------------------- 221 | Key Make Code Break Code 222 | ------------------------------------------- 223 | Next Track E0, 19 E0, 99 224 | Previous Track E0, 10 E0, 90 225 | Stop E0, 24 E0, A4 226 | Play/Pause E0, 22 E0, A2 227 | Mute E0, 20 E0, A0 228 | Volume Up E0, 30 E0, B0 229 | Volume Down E0, 2E E0, AE 230 | Media Select E0, 6D E0, ED 231 | E-Mail E0, 6C E0, EC 232 | Calculator E0, 21 E0, A1 233 | My Computer E0, 6B E0, EB 234 | WWW Search E0, 65 E0, E5 235 | WWW Home E0, 32 E0, B2 236 | WWW Back E0, 6A E0, EA 237 | WWW Forward E0, 69 E0, E9 238 | WWW Stop E0, 68 E0, E8 239 | WWW Refresh E0, 67 E0, E7 240 | WWW Favorites E0, 66 E0, E6 241 | 242 | *=====================================================================================*/ 243 | 244 | 245 | 246 | #endif /* _ORANGES_KEYMAP_H_ */ 247 | 248 | -------------------------------------------------------------------------------- /lab3/code/include/proc.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proc.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | typedef struct s_stackframe 9 | { /* proc_ptr points here ↑ Low */ 10 | u32 gs; /* ┓ │ */ 11 | u32 fs; /* ┃ │ */ 12 | u32 es; /* ┃ │ */ 13 | u32 ds; /* ┃ │ */ 14 | u32 edi; /* ┃ │ */ 15 | u32 esi; /* ┣ pushed by save() │ */ 16 | u32 ebp; /* ┃ │ */ 17 | u32 kernel_esp; /* <- 'popad' will ignore it │ */ 18 | u32 ebx; /* ┃ ↑栈从高地址往低地址增长*/ 19 | u32 edx; /* ┃ │ */ 20 | u32 ecx; /* ┃ │ */ 21 | u32 eax; /* ┛ │ */ 22 | u32 retaddr; /* return address for assembly code save() │ */ 23 | u32 eip; /* ┓ │ */ 24 | u32 cs; /* ┃ │ */ 25 | u32 eflags; /* ┣ these are pushed by CPU during interrupt │ */ 26 | u32 esp; /* ┃ │ */ 27 | u32 ss; /* ┛ ┷High */ 28 | } STACK_FRAME; 29 | 30 | typedef struct s_proc 31 | { 32 | STACK_FRAME regs; /* process registers saved in stack frame */ 33 | 34 | u16 ldt_sel; /* gdt selector giving ldt base and limit */ 35 | DESCRIPTOR ldts[LDT_SIZE]; /* local descriptors for code and data */ 36 | 37 | int ticks; /* remained ticks */ 38 | int priority; 39 | 40 | u32 pid; /* process id passed in from MM */ 41 | char p_name[16]; /* name of the process */ 42 | } PROCESS; 43 | 44 | typedef struct s_task 45 | { 46 | task_f initial_eip; 47 | int stacksize; 48 | char name[32]; 49 | } TASK; 50 | 51 | /* Number of tasks & procs */ 52 | #define NR_TASKS 2 53 | #define NR_PROCS 3 54 | 55 | /* stacks of tasks */ 56 | #define STACK_SIZE_TTY 0x8000 57 | #define STACK_SIZE_CLEAN 0x8000 58 | #define STACK_SIZE_TESTA 0x8000 59 | #define STACK_SIZE_TESTB 0x8000 60 | #define STACK_SIZE_TESTC 0x8000 61 | 62 | #define STACK_SIZE_TOTAL (STACK_SIZE_TTY + \ 63 | STACK_SIZE_CLEAN + \ 64 | STACK_SIZE_TESTA + \ 65 | STACK_SIZE_TESTB + \ 66 | STACK_SIZE_TESTC) 67 | -------------------------------------------------------------------------------- /lab3/code/include/protect.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | protect.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_PROTECT_H_ 9 | #define _ORANGES_PROTECT_H_ 10 | 11 | 12 | /* 存储段描述符/系统段描述符 */ 13 | typedef struct s_descriptor /* 共 8 个字节 */ 14 | { 15 | u16 limit_low; /* Limit */ 16 | u16 base_low; /* Base */ 17 | u8 base_mid; /* Base */ 18 | u8 attr1; /* P(1) DPL(2) DT(1) TYPE(4) */ 19 | u8 limit_high_attr2; /* G(1) D(1) 0(1) AVL(1) LimitHigh(4) */ 20 | u8 base_high; /* Base */ 21 | }DESCRIPTOR; 22 | 23 | /* 门描述符 */ 24 | typedef struct s_gate 25 | { 26 | u16 offset_low; /* Offset Low */ 27 | u16 selector; /* Selector */ 28 | u8 dcount; /* 该字段只在调用门描述符中有效。 29 | 如果在利用调用门调用子程序时引起特权级的转换和堆栈的改变,需要将外层堆栈中的参数复制到内层堆栈。 30 | 该双字计数字段就是用于说明这种情况发生时,要复制的双字参数的数量。 */ 31 | u8 attr; /* P(1) DPL(2) DT(1) TYPE(4) */ 32 | u16 offset_high; /* Offset High */ 33 | }GATE; 34 | 35 | typedef struct s_tss { 36 | u32 backlink; 37 | u32 esp0; /* stack pointer to use during interrupt */ 38 | u32 ss0; /* " segment " " " " */ 39 | u32 esp1; 40 | u32 ss1; 41 | u32 esp2; 42 | u32 ss2; 43 | u32 cr3; 44 | u32 eip; 45 | u32 flags; 46 | u32 eax; 47 | u32 ecx; 48 | u32 edx; 49 | u32 ebx; 50 | u32 esp; 51 | u32 ebp; 52 | u32 esi; 53 | u32 edi; 54 | u32 es; 55 | u32 cs; 56 | u32 ss; 57 | u32 ds; 58 | u32 fs; 59 | u32 gs; 60 | u32 ldt; 61 | u16 trap; 62 | u16 iobase; /* I/O位图基址大于或等于TSS段界限,就表示没有I/O许可位图 */ 63 | /*u8 iomap[2];*/ 64 | }TSS; 65 | 66 | /* GDT */ 67 | /* 描述符索引 */ 68 | #define INDEX_DUMMY 0 // ┓ 69 | #define INDEX_FLAT_C 1 // ┣ LOADER 里面已经确定了的. 70 | #define INDEX_FLAT_RW 2 // ┃ 71 | #define INDEX_VIDEO 3 // ┛ 72 | #define INDEX_TSS 4 73 | #define INDEX_LDT_FIRST 5 74 | /* 选择子 */ 75 | #define SELECTOR_DUMMY 0 // ┓ 76 | #define SELECTOR_FLAT_C 0x08 // ┣ LOADER 里面已经确定了的. 77 | #define SELECTOR_FLAT_RW 0x10 // ┃ 78 | #define SELECTOR_VIDEO (0x18+3) // ┛<-- RPL=3 79 | #define SELECTOR_TSS 0x20 // TSS. 从外层跳到内存时 SS 和 ESP 的值从里面获得. 80 | #define SELECTOR_LDT_FIRST 0x28 81 | 82 | #define SELECTOR_KERNEL_CS SELECTOR_FLAT_C 83 | #define SELECTOR_KERNEL_DS SELECTOR_FLAT_RW 84 | #define SELECTOR_KERNEL_GS SELECTOR_VIDEO 85 | 86 | /* 每个任务有一个单独的 LDT, 每个 LDT 中的描述符个数: */ 87 | #define LDT_SIZE 2 88 | 89 | /* 描述符类型值说明 */ 90 | #define DA_32 0x4000 /* 32 位段 */ 91 | #define DA_LIMIT_4K 0x8000 /* 段界限粒度为 4K 字节 */ 92 | #define DA_DPL0 0x00 /* DPL = 0 */ 93 | #define DA_DPL1 0x20 /* DPL = 1 */ 94 | #define DA_DPL2 0x40 /* DPL = 2 */ 95 | #define DA_DPL3 0x60 /* DPL = 3 */ 96 | /* 存储段描述符类型值说明 */ 97 | #define DA_DR 0x90 /* 存在的只读数据段类型值 */ 98 | #define DA_DRW 0x92 /* 存在的可读写数据段属性值 */ 99 | #define DA_DRWA 0x93 /* 存在的已访问可读写数据段类型值 */ 100 | #define DA_C 0x98 /* 存在的只执行代码段属性值 */ 101 | #define DA_CR 0x9A /* 存在的可执行可读代码段属性值 */ 102 | #define DA_CCO 0x9C /* 存在的只执行一致代码段属性值 */ 103 | #define DA_CCOR 0x9E /* 存在的可执行可读一致代码段属性值 */ 104 | /* 系统段描述符类型值说明 */ 105 | #define DA_LDT 0x82 /* 局部描述符表段类型值 */ 106 | #define DA_TaskGate 0x85 /* 任务门类型值 */ 107 | #define DA_386TSS 0x89 /* 可用 386 任务状态段类型值 */ 108 | #define DA_386CGate 0x8C /* 386 调用门类型值 */ 109 | #define DA_386IGate 0x8E /* 386 中断门类型值 */ 110 | #define DA_386TGate 0x8F /* 386 陷阱门类型值 */ 111 | 112 | /* 选择子类型值说明 */ 113 | /* 其中, SA_ : Selector Attribute */ 114 | #define SA_RPL_MASK 0xFFFC 115 | #define SA_RPL0 0 116 | #define SA_RPL1 1 117 | #define SA_RPL2 2 118 | #define SA_RPL3 3 119 | 120 | #define SA_TI_MASK 0xFFFB 121 | #define SA_TIG 0 122 | #define SA_TIL 4 123 | 124 | /* 中断向量 */ 125 | #define INT_VECTOR_DIVIDE 0x0 126 | #define INT_VECTOR_DEBUG 0x1 127 | #define INT_VECTOR_NMI 0x2 128 | #define INT_VECTOR_BREAKPOINT 0x3 129 | #define INT_VECTOR_OVERFLOW 0x4 130 | #define INT_VECTOR_BOUNDS 0x5 131 | #define INT_VECTOR_INVAL_OP 0x6 132 | #define INT_VECTOR_COPROC_NOT 0x7 133 | #define INT_VECTOR_DOUBLE_FAULT 0x8 134 | #define INT_VECTOR_COPROC_SEG 0x9 135 | #define INT_VECTOR_INVAL_TSS 0xA 136 | #define INT_VECTOR_SEG_NOT 0xB 137 | #define INT_VECTOR_STACK_FAULT 0xC 138 | #define INT_VECTOR_PROTECTION 0xD 139 | #define INT_VECTOR_PAGE_FAULT 0xE 140 | #define INT_VECTOR_COPROC_ERR 0x10 141 | 142 | /* 中断向量 */ 143 | #define INT_VECTOR_IRQ0 0x20 144 | #define INT_VECTOR_IRQ8 0x28 145 | 146 | /* 系统调用 */ 147 | #define INT_VECTOR_SYS_CALL 0x90 148 | 149 | /* 宏 */ 150 | /* 线性地址 → 物理地址 */ 151 | #define vir2phys(seg_base, vir) (u32)(((u32)seg_base) + (u32)(vir)) 152 | 153 | 154 | #endif /* _ORANGES_PROTECT_H_ */ 155 | -------------------------------------------------------------------------------- /lab3/code/include/proto.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proto.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | /* klib.asm */ 9 | PUBLIC void out_byte(u16 port, u8 value); 10 | PUBLIC u8 in_byte(u16 port); 11 | PUBLIC void disp_str(char *info); 12 | PUBLIC void disp_color_str(char *info, int color); 13 | 14 | /* protect.c */ 15 | PUBLIC void init_prot(); 16 | PUBLIC u32 seg2phys(u16 seg); 17 | 18 | /* klib.c */ 19 | PUBLIC void delay(int time); 20 | 21 | /* kernel.asm */ 22 | void restart(); 23 | 24 | /* main.c */ 25 | void TestA(); 26 | void TestB(); 27 | void TestC(); 28 | 29 | /* i8259.c */ 30 | PUBLIC void put_irq_handler(int irq, irq_handler handler); 31 | PUBLIC void spurious_irq(int irq); 32 | 33 | /* clock.c */ 34 | PUBLIC void clock_handler(int irq); 35 | PUBLIC void init_clock(); 36 | 37 | /* keyboard.c */ 38 | PUBLIC void init_keyboard(); 39 | 40 | /* tty.c */ 41 | PUBLIC void task_clean_screen(); 42 | PUBLIC void task_tty(); 43 | PUBLIC void in_process(TTY *p_tty, u32 key); 44 | 45 | /* console.c */ 46 | PUBLIC void recover(TTY *p_tty); 47 | PUBLIC void revoke(TTY *p_tty); 48 | PUBLIC void clean_screen(TTY *p_tty); 49 | PUBLIC void out_char(CONSOLE *p_con, char ch); 50 | PUBLIC void scroll_screen(CONSOLE *p_con, int direction); 51 | 52 | /* 以下是系统调用相关 */ 53 | 54 | /* proc.c */ 55 | PUBLIC int sys_get_ticks(); /* sys_call */ 56 | 57 | /* syscall.asm */ 58 | PUBLIC void sys_call(); /* int_handler */ 59 | PUBLIC int get_ticks(); 60 | -------------------------------------------------------------------------------- /lab3/code/include/sconst.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; sconst.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | P_STACKBASE equ 0 9 | GSREG equ P_STACKBASE 10 | FSREG equ GSREG + 4 11 | ESREG equ FSREG + 4 12 | DSREG equ ESREG + 4 13 | EDIREG equ DSREG + 4 14 | ESIREG equ EDIREG + 4 15 | EBPREG equ ESIREG + 4 16 | KERNELESPREG equ EBPREG + 4 17 | EBXREG equ KERNELESPREG + 4 18 | EDXREG equ EBXREG + 4 19 | ECXREG equ EDXREG + 4 20 | EAXREG equ ECXREG + 4 21 | RETADR equ EAXREG + 4 22 | EIPREG equ RETADR + 4 23 | CSREG equ EIPREG + 4 24 | EFLAGSREG equ CSREG + 4 25 | ESPREG equ EFLAGSREG + 4 26 | SSREG equ ESPREG + 4 27 | P_STACKTOP equ SSREG + 4 28 | P_LDT_SEL equ P_STACKTOP 29 | P_LDT equ P_LDT_SEL + 4 30 | 31 | TSS3_S_SP0 equ 4 32 | 33 | INT_M_CTL equ 0x20 ; I/O port for interrupt controller 34 | INT_M_CTLMASK equ 0x21 ; setting bits in this port disables ints 35 | INT_S_CTL equ 0xA0 ; I/O port for second interrupt controller 36 | INT_S_CTLMASK equ 0xA1 ; setting bits in this port disables ints 37 | 38 | EOI equ 0x20 39 | 40 | ; 以下选择子值必须与 protect.h 中保持一致!!! 41 | SELECTOR_FLAT_C equ 0x08 ; LOADER 里面已经确定了的. 42 | SELECTOR_TSS equ 0x20 ; TSS. 从外层跳到内存时 SS 和 ESP 的值从里面获得. 43 | SELECTOR_KERNEL_CS equ SELECTOR_FLAT_C 44 | 45 | -------------------------------------------------------------------------------- /lab3/code/include/string.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | string.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | PUBLIC void* memcpy(void* p_dst, void* p_src, int size); 9 | PUBLIC void memset(void* p_dst, char ch, int size); 10 | -------------------------------------------------------------------------------- /lab3/code/include/tty.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | tty.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_TTY_H_ 9 | #define _ORANGES_TTY_H_ 10 | 11 | 12 | #define TTY_IN_BYTES 256 /* tty input queue size */ 13 | 14 | struct s_console; 15 | 16 | /* TTY */ 17 | typedef struct s_tty 18 | { 19 | u32 in_buf[TTY_IN_BYTES]; /* TTY 输入缓冲区 */ 20 | u32* p_inbuf_head; /* 指向缓冲区中下一个空闲位置 */ 21 | u32* p_inbuf_tail; /* 指向键盘任务应处理的键值 */ 22 | int inbuf_count; /* 缓冲区中已经填充了多少 */ 23 | 24 | struct s_console * p_console; 25 | }TTY; 26 | 27 | 28 | #endif /* _ORANGES_TTY_H_ */ 29 | -------------------------------------------------------------------------------- /lab3/code/include/type.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | type.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_TYPE_H_ 9 | #define _ORANGES_TYPE_H_ 10 | 11 | 12 | typedef unsigned int u32; 13 | typedef unsigned short u16; 14 | typedef unsigned char u8; 15 | 16 | 17 | typedef void (*int_handler) (); 18 | typedef void (*task_f) (); 19 | typedef void (*irq_handler) (int irq); 20 | 21 | typedef void* system_call; 22 | 23 | 24 | #endif /* _ORANGES_TYPE_H_ */ 25 | -------------------------------------------------------------------------------- /lab3/code/kernel.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/code/kernel.bin -------------------------------------------------------------------------------- /lab3/code/kernel/clock.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | clock.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "string.h" 12 | #include "proc.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | 19 | /*======================================================================* 20 | clock_handler 21 | *======================================================================*/ 22 | PUBLIC void clock_handler(int irq) 23 | { 24 | ticks++; 25 | p_proc_ready->ticks--; 26 | 27 | if (k_reenter != 0) { 28 | return; 29 | } 30 | 31 | if (p_proc_ready->ticks > 0) { 32 | return; 33 | } 34 | 35 | schedule(); 36 | 37 | } 38 | 39 | /*======================================================================* 40 | milli_delay 41 | *======================================================================*/ 42 | PUBLIC void milli_delay(int milli_sec) 43 | { 44 | int t = get_ticks(); 45 | 46 | while(((get_ticks() - t) * 1000 / HZ) < milli_sec) {} 47 | } 48 | 49 | /*======================================================================* 50 | init_clock 51 | *======================================================================*/ 52 | PUBLIC void init_clock() 53 | { 54 | /* 初始化 8253 PIT */ 55 | out_byte(TIMER_MODE, RATE_GENERATOR); 56 | out_byte(TIMER0, (u8) (TIMER_FREQ/HZ) ); 57 | out_byte(TIMER0, (u8) ((TIMER_FREQ/HZ) >> 8)); 58 | 59 | put_irq_handler(CLOCK_IRQ, clock_handler); /* 设定时钟中断处理程序 */ 60 | enable_irq(CLOCK_IRQ); /* 让8259A可以接收时钟中断 */ 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /lab3/code/kernel/global.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | global.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #define GLOBAL_VARIABLES_HERE 9 | 10 | #include "type.h" 11 | #include "const.h" 12 | #include "protect.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "proc.h" 16 | #include "global.h" 17 | #include "proto.h" 18 | 19 | PUBLIC PROCESS proc_table[NR_TASKS + NR_PROCS]; 20 | 21 | PUBLIC TASK task_table[NR_TASKS] = { 22 | {task_tty, STACK_SIZE_TTY, "tty"}, 23 | {task_clean_screen, STACK_SIZE_CLEAN, "clean"}}; 24 | 25 | PUBLIC TASK user_proc_table[NR_PROCS] = { 26 | {TestA, STACK_SIZE_TESTA, "TestA"}, 27 | {TestB, STACK_SIZE_TESTB, "TestB"}, 28 | {TestC, STACK_SIZE_TESTC, "TestC"}}; 29 | 30 | PUBLIC char task_stack[STACK_SIZE_TOTAL]; 31 | 32 | PUBLIC TTY tty_table[NR_CONSOLES]; 33 | PUBLIC CONSOLE console_table[NR_CONSOLES]; 34 | 35 | PUBLIC irq_handler irq_table[NR_IRQ]; 36 | 37 | PUBLIC system_call sys_call_table[NR_SYS_CALL] = {sys_get_ticks}; 38 | -------------------------------------------------------------------------------- /lab3/code/kernel/i8259.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | i8259.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | 9 | #include "type.h" 10 | #include "const.h" 11 | #include "protect.h" 12 | #include "proc.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | 19 | /*======================================================================* 20 | init_8259A 21 | *======================================================================*/ 22 | PUBLIC void init_8259A() 23 | { 24 | out_byte(INT_M_CTL, 0x11); // Master 8259, ICW1. 25 | out_byte(INT_S_CTL, 0x11); // Slave 8259, ICW1. 26 | out_byte(INT_M_CTLMASK, INT_VECTOR_IRQ0); // Master 8259, ICW2. 设置 '主8259' 的中断入口地址为 0x20. 27 | out_byte(INT_S_CTLMASK, INT_VECTOR_IRQ8); // Slave 8259, ICW2. 设置 '从8259' 的中断入口地址为 0x28 28 | out_byte(INT_M_CTLMASK, 0x4); // Master 8259, ICW3. IR2 对应 '从8259'. 29 | out_byte(INT_S_CTLMASK, 0x2); // Slave 8259, ICW3. 对应 '主8259' 的 IR2. 30 | out_byte(INT_M_CTLMASK, 0x1); // Master 8259, ICW4. 31 | out_byte(INT_S_CTLMASK, 0x1); // Slave 8259, ICW4. 32 | 33 | out_byte(INT_M_CTLMASK, 0xFF); // Master 8259, OCW1. 34 | out_byte(INT_S_CTLMASK, 0xFF); // Slave 8259, OCW1. 35 | 36 | int i; 37 | for (i = 0; i < NR_IRQ; i++) { 38 | irq_table[i] = spurious_irq; 39 | } 40 | } 41 | 42 | /*======================================================================* 43 | spurious_irq 44 | *======================================================================*/ 45 | PUBLIC void spurious_irq(int irq) 46 | { 47 | disp_str("spurious_irq: "); 48 | disp_int(irq); 49 | disp_str("\n"); 50 | } 51 | 52 | /*======================================================================* 53 | put_irq_handler 54 | *======================================================================*/ 55 | PUBLIC void put_irq_handler(int irq, irq_handler handler) 56 | { 57 | disable_irq(irq); 58 | irq_table[irq] = handler; 59 | } 60 | -------------------------------------------------------------------------------- /lab3/code/kernel/main.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | main.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "string.h" 12 | #include "proc.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | 19 | /*======================================================================* 20 | kernel_main 21 | *======================================================================*/ 22 | PUBLIC int kernel_main() 23 | { 24 | disp_str("-----\"kernel_main\" begins-----\n"); 25 | 26 | TASK* p_task = task_table; 27 | PROCESS* p_proc = proc_table; 28 | char* p_task_stack = task_stack + STACK_SIZE_TOTAL; 29 | u16 selector_ldt = SELECTOR_LDT_FIRST; 30 | int i; 31 | u8 privilege; 32 | u8 rpl; 33 | int eflags; 34 | for (i = 0; i < NR_TASKS+NR_PROCS; i++) { 35 | if (i < NR_TASKS) { /* 任务 */ 36 | p_task = task_table + i; 37 | privilege = PRIVILEGE_TASK; 38 | rpl = RPL_TASK; 39 | eflags = 0x1202; /* IF=1, IOPL=1, bit 2 is always 1 */ 40 | } 41 | else { /* 用户进程 */ 42 | p_task = user_proc_table + (i - NR_TASKS); 43 | privilege = PRIVILEGE_USER; 44 | rpl = RPL_USER; 45 | eflags = 0x202; /* IF=1, bit 2 is always 1 */ 46 | } 47 | 48 | strcpy(p_proc->p_name, p_task->name); // name of the process 49 | p_proc->pid = i; // pid 50 | 51 | p_proc->ldt_sel = selector_ldt; 52 | 53 | memcpy(&p_proc->ldts[0], &gdt[SELECTOR_KERNEL_CS >> 3], 54 | sizeof(DESCRIPTOR)); 55 | p_proc->ldts[0].attr1 = DA_C | privilege << 5; 56 | memcpy(&p_proc->ldts[1], &gdt[SELECTOR_KERNEL_DS >> 3], 57 | sizeof(DESCRIPTOR)); 58 | p_proc->ldts[1].attr1 = DA_DRW | privilege << 5; 59 | p_proc->regs.cs = (0 & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | rpl; 60 | p_proc->regs.ds = (8 & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | rpl; 61 | p_proc->regs.es = (8 & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | rpl; 62 | p_proc->regs.fs = (8 & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | rpl; 63 | p_proc->regs.ss = (8 & SA_RPL_MASK & SA_TI_MASK) | SA_TIL | rpl; 64 | p_proc->regs.gs = (SELECTOR_KERNEL_GS & SA_RPL_MASK) | rpl; 65 | 66 | p_proc->regs.eip = (u32)p_task->initial_eip; 67 | p_proc->regs.esp = (u32)p_task_stack; 68 | p_proc->regs.eflags = eflags; 69 | 70 | p_task_stack -= p_task->stacksize; 71 | p_proc++; 72 | p_task++; 73 | selector_ldt += 1 << 3; 74 | } 75 | 76 | proc_table[0].ticks = proc_table[0].priority = 15; 77 | proc_table[1].ticks = proc_table[1].priority = 5; 78 | proc_table[2].ticks = proc_table[2].priority = 3; 79 | 80 | k_reenter = 0; 81 | ticks = 0; 82 | 83 | p_proc_ready = proc_table; 84 | 85 | init_clock(); 86 | init_keyboard(); 87 | 88 | restart(); 89 | 90 | while(1){} 91 | } 92 | 93 | /*======================================================================* 94 | TestA 95 | *======================================================================*/ 96 | void TestA() 97 | { 98 | int i = 0; 99 | while (1) { 100 | /* disp_str("A."); */ 101 | milli_delay(10); 102 | } 103 | } 104 | 105 | /*======================================================================* 106 | TestB 107 | *======================================================================*/ 108 | void TestB() 109 | { 110 | int i = 0x1000; 111 | while(1){ 112 | /* disp_str("B."); */ 113 | milli_delay(10); 114 | } 115 | } 116 | 117 | /*======================================================================* 118 | TestB 119 | *======================================================================*/ 120 | void TestC() 121 | { 122 | int i = 0x2000; 123 | while(1){ 124 | /* disp_str("C."); */ 125 | milli_delay(10); 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /lab3/code/kernel/proc.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proc.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "tty.h" 12 | #include "console.h" 13 | #include "string.h" 14 | #include "proc.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | /*======================================================================* 19 | schedule 20 | *======================================================================*/ 21 | PUBLIC void schedule() 22 | { 23 | PROCESS* p; 24 | int greatest_ticks = 0; 25 | 26 | while (!greatest_ticks) { 27 | for (p = proc_table; p < proc_table+NR_TASKS+NR_PROCS; p++) { 28 | if (p->ticks > greatest_ticks) { 29 | greatest_ticks = p->ticks; 30 | p_proc_ready = p; 31 | } 32 | } 33 | 34 | if (!greatest_ticks) { 35 | for(p=proc_table;pticks = p->priority; 37 | } 38 | } 39 | } 40 | } 41 | 42 | /*======================================================================* 43 | sys_get_ticks 44 | *======================================================================*/ 45 | PUBLIC int sys_get_ticks() 46 | { 47 | return ticks; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /lab3/code/kernel/start.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | start.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "string.h" 12 | #include "proc.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | 19 | /*======================================================================* 20 | cstart 21 | *======================================================================*/ 22 | PUBLIC void cstart() 23 | { 24 | disp_str("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n-----\"cstart\" begins-----\n"); 25 | 26 | // 将 LOADER 中的 GDT 复制到新的 GDT 中 27 | memcpy( &gdt, // New GDT 28 | (void*)(*((u32*)(&gdt_ptr[2]))), // Base of Old GDT 29 | *((u16*)(&gdt_ptr[0])) + 1 // Limit of Old GDT 30 | ); 31 | // gdt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sgdt 以及 lgdt 的参数。 32 | u16* p_gdt_limit = (u16*)(&gdt_ptr[0]); 33 | u32* p_gdt_base = (u32*)(&gdt_ptr[2]); 34 | *p_gdt_limit = GDT_SIZE * sizeof(DESCRIPTOR) - 1; 35 | *p_gdt_base = (u32)&gdt; 36 | 37 | // idt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sidt 以及 lidt 的参数。 38 | u16* p_idt_limit = (u16*)(&idt_ptr[0]); 39 | u32* p_idt_base = (u32*)(&idt_ptr[2]); 40 | *p_idt_limit = IDT_SIZE * sizeof(GATE) - 1; 41 | *p_idt_base = (u32)&idt; 42 | 43 | init_prot(); 44 | 45 | disp_str("-----\"cstart\" finished-----\n"); 46 | } 47 | -------------------------------------------------------------------------------- /lab3/code/kernel/syscall.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; syscall.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | %include "sconst.inc" 9 | 10 | _NR_get_ticks equ 0 ; 要跟 global.c 中 sys_call_table 的定义相对应! 11 | INT_VECTOR_SYS_CALL equ 0x90 12 | 13 | ; 导出符号 14 | global get_ticks 15 | 16 | bits 32 17 | [section .text] 18 | 19 | ; ==================================================================== 20 | ; get_ticks 21 | ; ==================================================================== 22 | get_ticks: 23 | mov eax, _NR_get_ticks 24 | int INT_VECTOR_SYS_CALL 25 | ret 26 | 27 | -------------------------------------------------------------------------------- /lab3/code/kernel/tty.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | tty.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "string.h" 12 | #include "proc.h" 13 | #include "tty.h" 14 | #include "console.h" 15 | #include "global.h" 16 | #include "keyboard.h" 17 | #include "proto.h" 18 | 19 | #define TTY_FIRST (tty_table) 20 | #define TTY_END (tty_table + NR_CONSOLES) 21 | 22 | PRIVATE void init_tty(TTY *p_tty); 23 | PRIVATE void tty_do_read(TTY *p_tty); 24 | PRIVATE void tty_do_write(TTY *p_tty); 25 | PRIVATE void put_key(TTY *p_tty, u32 key); 26 | 27 | /*======================================================================* 28 | task_clean_screan 29 | *======================================================================*/ 30 | 31 | PUBLIC void task_clean_screen() 32 | { 33 | while (1) 34 | { 35 | milli_delay(200000); //设置清屏时间间隔为20s 36 | TTY *p_tty; 37 | for (p_tty = TTY_FIRST; p_tty < TTY_END; p_tty++) 38 | { 39 | if (p_tty->p_console->isSearch == 0) 40 | { 41 | clean_screen(p_tty); 42 | } 43 | } 44 | } 45 | } 46 | 47 | /*======================================================================* 48 | task_tty 49 | *======================================================================*/ 50 | PUBLIC void task_tty() 51 | { 52 | TTY *p_tty; 53 | 54 | init_keyboard(); 55 | 56 | for (p_tty = TTY_FIRST; p_tty < TTY_END; p_tty++) 57 | { 58 | init_tty(p_tty); 59 | } 60 | select_console(0); 61 | while (1) 62 | { 63 | for (p_tty = TTY_FIRST; p_tty < TTY_END; p_tty++) 64 | { 65 | tty_do_read(p_tty); 66 | tty_do_write(p_tty); 67 | } 68 | } 69 | } 70 | 71 | /*======================================================================* 72 | init_tty 73 | *======================================================================*/ 74 | PRIVATE void init_tty(TTY *p_tty) 75 | { 76 | p_tty->inbuf_count = 0; 77 | p_tty->p_inbuf_head = p_tty->p_inbuf_tail = p_tty->in_buf; 78 | 79 | init_screen(p_tty); 80 | } 81 | 82 | /*======================================================================* 83 | in_process 84 | *======================================================================*/ 85 | PUBLIC void in_process(TTY *p_tty, u32 key) 86 | { 87 | char output[2] = {'\0', '\0'}; 88 | 89 | if (p_tty->p_console->closed) 90 | { 91 | int raw_code = key & MASK_RAW; 92 | if (raw_code == ESC) 93 | { 94 | p_tty->p_console->closed = 0; //解除屏蔽 95 | //这里还要再写一个清除输入关键字的函数 96 | recover(p_tty); 97 | p_tty->p_console->isSearch = 0; //退出查找模式 98 | return; 99 | } 100 | else 101 | { 102 | return; 103 | } 104 | } 105 | 106 | if (!(key & FLAG_EXT)) 107 | { 108 | //不可打印字符中都添加了FLAG_EXT 109 | ///当前为可打印字符 110 | //两种ctrl、大小写的Z,共四种撤回的key 111 | if (key == 0x087A || key == 0x107A || key == 0x085A || key == 0x107A) 112 | { 113 | //CTRL+Z 114 | revoke(p_tty); 115 | } 116 | else 117 | { 118 | put_key(p_tty, key); //写入缓冲区 119 | } 120 | } 121 | else 122 | { 123 | int raw_code = key & MASK_RAW; 124 | switch (raw_code) 125 | { 126 | case ENTER: 127 | put_key(p_tty, '\n'); 128 | break; 129 | case BACKSPACE: 130 | put_key(p_tty, '\b'); 131 | break; 132 | case TAB: 133 | put_key(p_tty, '\t'); 134 | break; 135 | case UP: 136 | if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 137 | { 138 | scroll_screen(p_tty->p_console, SCR_DN); 139 | } 140 | break; 141 | case DOWN: 142 | if ((key & FLAG_SHIFT_L) || (key & FLAG_SHIFT_R)) 143 | { 144 | scroll_screen(p_tty->p_console, SCR_UP); 145 | } 146 | break; 147 | case ESC: 148 | if (p_tty->p_console->isSearch == 0) 149 | { 150 | p_tty->p_console->isSearch = 1; //进入查找模式 151 | } 152 | else 153 | { 154 | //这里也还要再写一个清除输入关键字的函数 155 | recover(p_tty); 156 | p_tty->p_console->isSearch = 0; //退出查找模式 157 | } 158 | break; 159 | case F1: 160 | case F2: 161 | case F3: 162 | case F4: 163 | case F5: 164 | case F6: 165 | case F7: 166 | case F8: 167 | case F9: 168 | case F10: 169 | case F11: 170 | case F12: 171 | /* Alt + F1~F12 */ 172 | if ((key & FLAG_ALT_L) || (key & FLAG_ALT_R)) 173 | { 174 | select_console(raw_code - F1); 175 | } 176 | break; 177 | default: 178 | break; 179 | } 180 | } 181 | } 182 | 183 | /*======================================================================* 184 | put_key 185 | *======================================================================*/ 186 | PRIVATE void put_key(TTY *p_tty, u32 key) 187 | { 188 | if (p_tty->inbuf_count < TTY_IN_BYTES) 189 | { 190 | *(p_tty->p_inbuf_head) = key; 191 | p_tty->p_inbuf_head++; 192 | if (p_tty->p_inbuf_head == p_tty->in_buf + TTY_IN_BYTES) 193 | { 194 | p_tty->p_inbuf_head = p_tty->in_buf; 195 | } 196 | p_tty->inbuf_count++; 197 | } 198 | } 199 | 200 | /*======================================================================* 201 | tty_do_read 202 | *======================================================================*/ 203 | PRIVATE void tty_do_read(TTY *p_tty) 204 | { 205 | if (is_current_console(p_tty->p_console)) 206 | { 207 | keyboard_read(p_tty); 208 | } 209 | } 210 | 211 | /*======================================================================* 212 | tty_do_write 213 | *======================================================================*/ 214 | PRIVATE void tty_do_write(TTY *p_tty) 215 | { 216 | if (p_tty->inbuf_count) 217 | { 218 | char ch = *(p_tty->p_inbuf_tail); 219 | p_tty->p_inbuf_tail++; 220 | if (p_tty->p_inbuf_tail == p_tty->in_buf + TTY_IN_BYTES) 221 | { 222 | p_tty->p_inbuf_tail = p_tty->in_buf; 223 | } 224 | p_tty->inbuf_count--; 225 | 226 | out_char(p_tty->p_console, ch); 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /lab3/code/lib/klib.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | klib.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "tty.h" 12 | #include "console.h" 13 | #include "string.h" 14 | #include "proc.h" 15 | #include "global.h" 16 | #include "proto.h" 17 | 18 | 19 | /*======================================================================* 20 | itoa 21 | *======================================================================*/ 22 | PUBLIC char * itoa(char * str, int num)/* 数字前面的 0 不被显示出来, 比如 0000B800 被显示成 B800 */ 23 | { 24 | char * p = str; 25 | char ch; 26 | int i; 27 | int flag = 0; 28 | 29 | *p++ = '0'; 30 | *p++ = 'x'; 31 | 32 | if(num == 0){ 33 | *p++ = '0'; 34 | } 35 | else{ 36 | for(i=28;i>=0;i-=4){ 37 | ch = (num >> i) & 0xF; 38 | if(flag || (ch > 0)){ 39 | flag = 1; 40 | ch += '0'; 41 | if(ch > '9'){ 42 | ch += 7; 43 | } 44 | *p++ = ch; 45 | } 46 | } 47 | } 48 | 49 | *p = 0; 50 | 51 | return str; 52 | } 53 | 54 | 55 | /*======================================================================* 56 | disp_int 57 | *======================================================================*/ 58 | PUBLIC void disp_int(int input) 59 | { 60 | char output[16]; 61 | itoa(output, input); 62 | disp_str(output); 63 | } 64 | 65 | /*======================================================================* 66 | delay 67 | *======================================================================*/ 68 | PUBLIC void delay(int time) 69 | { 70 | int i, j, k; 71 | for(k=0;k= 8 at the slave 8259 145 | disable_0: 146 | in al, INT_M_CTLMASK 147 | test al, ah 148 | jnz dis_already ; already disabled? 149 | or al, ah 150 | out INT_M_CTLMASK, al ; set bit at master 8259 151 | popf 152 | mov eax, 1 ; disabled by this function 153 | ret 154 | disable_8: 155 | in al, INT_S_CTLMASK 156 | test al, ah 157 | jnz dis_already ; already disabled? 158 | or al, ah 159 | out INT_S_CTLMASK, al ; set bit at slave 8259 160 | popf 161 | mov eax, 1 ; disabled by this function 162 | ret 163 | dis_already: 164 | popf 165 | xor eax, eax ; already disabled 166 | ret 167 | 168 | ; ======================================================================== 169 | ; void enable_irq(int irq); 170 | ; ======================================================================== 171 | ; Enable an interrupt request line by clearing an 8259 bit. 172 | ; Equivalent code: 173 | ; if(irq < 8){ 174 | ; out_byte(INT_M_CTLMASK, in_byte(INT_M_CTLMASK) & ~(1 << irq)); 175 | ; } 176 | ; else{ 177 | ; out_byte(INT_S_CTLMASK, in_byte(INT_S_CTLMASK) & ~(1 << irq)); 178 | ; } 179 | ; 180 | enable_irq: 181 | mov ecx, [esp + 4] ; irq 182 | pushf 183 | cli 184 | mov ah, ~1 185 | rol ah, cl ; ah = ~(1 << (irq % 8)) 186 | cmp cl, 8 187 | jae enable_8 ; enable irq >= 8 at the slave 8259 188 | enable_0: 189 | in al, INT_M_CTLMASK 190 | and al, ah 191 | out INT_M_CTLMASK, al ; clear bit at master 8259 192 | popf 193 | ret 194 | enable_8: 195 | in al, INT_S_CTLMASK 196 | and al, ah 197 | out INT_S_CTLMASK, al ; clear bit at slave 8259 198 | popf 199 | ret 200 | 201 | ; ======================================================================== 202 | ; void disable_int(); 203 | ; ======================================================================== 204 | disable_int: 205 | cli 206 | ret 207 | 208 | ; ======================================================================== 209 | ; void enable_int(); 210 | ; ======================================================================== 211 | enable_int: 212 | sti 213 | ret 214 | 215 | 216 | -------------------------------------------------------------------------------- /lab3/code/lib/string.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; string.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | [SECTION .text] 9 | 10 | ; 导出函数 11 | global memcpy 12 | global memset 13 | global strcpy 14 | 15 | 16 | ; ------------------------------------------------------------------------ 17 | ; void* memcpy(void* es:p_dst, void* ds:p_src, int size); 18 | ; ------------------------------------------------------------------------ 19 | memcpy: 20 | push ebp 21 | mov ebp, esp 22 | 23 | push esi 24 | push edi 25 | push ecx 26 | 27 | mov edi, [ebp + 8] ; Destination 28 | mov esi, [ebp + 12] ; Source 29 | mov ecx, [ebp + 16] ; Counter 30 | .1: 31 | cmp ecx, 0 ; 判断计数器 32 | jz .2 ; 计数器为零时跳出 33 | 34 | mov al, [ds:esi] ; ┓ 35 | inc esi ; ┃ 36 | ; ┣ 逐字节移动 37 | mov byte [es:edi], al ; ┃ 38 | inc edi ; ┛ 39 | 40 | dec ecx ; 计数器减一 41 | jmp .1 ; 循环 42 | .2: 43 | mov eax, [ebp + 8] ; 返回值 44 | 45 | pop ecx 46 | pop edi 47 | pop esi 48 | mov esp, ebp 49 | pop ebp 50 | 51 | ret ; 函数结束,返回 52 | ; memcpy 结束------------------------------------------------------------- 53 | 54 | 55 | ; ------------------------------------------------------------------------ 56 | ; void memset(void* p_dst, char ch, int size); 57 | ; ------------------------------------------------------------------------ 58 | memset: 59 | push ebp 60 | mov ebp, esp 61 | 62 | push esi 63 | push edi 64 | push ecx 65 | 66 | mov edi, [ebp + 8] ; Destination 67 | mov edx, [ebp + 12] ; Char to be putted 68 | mov ecx, [ebp + 16] ; Counter 69 | .1: 70 | cmp ecx, 0 ; 判断计数器 71 | jz .2 ; 计数器为零时跳出 72 | 73 | mov byte [edi], dl ; ┓ 74 | inc edi ; ┛ 75 | 76 | dec ecx ; 计数器减一 77 | jmp .1 ; 循环 78 | .2: 79 | 80 | pop ecx 81 | pop edi 82 | pop esi 83 | mov esp, ebp 84 | pop ebp 85 | 86 | ret ; 函数结束,返回 87 | ; ------------------------------------------------------------------------ 88 | 89 | 90 | ; ------------------------------------------------------------------------ 91 | ; char* strcpy(char* p_dst, char* p_src); 92 | ; ------------------------------------------------------------------------ 93 | strcpy: 94 | push ebp 95 | mov ebp, esp 96 | 97 | mov esi, [ebp + 12] ; Source 98 | mov edi, [ebp + 8] ; Destination 99 | 100 | .1: 101 | mov al, [esi] ; ┓ 102 | inc esi ; ┃ 103 | ; ┣ 逐字节移动 104 | mov byte [edi], al ; ┃ 105 | inc edi ; ┛ 106 | 107 | cmp al, 0 ; 是否遇到 '\0' 108 | jnz .1 ; 没遇到就继续循环,遇到就结束 109 | 110 | mov eax, [ebp + 8] ; 返回值 111 | 112 | pop ebp 113 | ret ; 函数结束,返回 114 | ; strcpy 结束------------------------------------------------------------- 115 | 116 | 117 | -------------------------------------------------------------------------------- /lab3/实验要求/2021 操作系统实验.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/实验要求/2021 操作系统实验.pdf -------------------------------------------------------------------------------- /lab3/实验要求/操作系统2021 IO.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/实验要求/操作系统2021 IO.pdf -------------------------------------------------------------------------------- /lab3/实验要求/操作系统2021 中断与异常.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/实验要求/操作系统2021 中断与异常.pptx -------------------------------------------------------------------------------- /lab3/实验要求/操作系统2021 实验三 实模式和保护模式下的中断.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/实验要求/操作系统2021 实验三 实模式和保护模式下的中断.pptx -------------------------------------------------------------------------------- /lab3/截图/回车和tab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/截图/回车和tab.png -------------------------------------------------------------------------------- /lab3/截图/查找.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/截图/查找.png -------------------------------------------------------------------------------- /lab3/截图/输入.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab3/截图/输入.png -------------------------------------------------------------------------------- /lab4/code/Makefile: -------------------------------------------------------------------------------- 1 | ######################### 2 | # Makefile for Orange'S # 3 | ######################### 4 | 5 | # Entry point of Orange'S 6 | # It must have the same value with 'KernelEntryPointPhyAddr' in load.inc! 7 | ENTRYPOINT = 0x30400 8 | 9 | # Offset of entry point in kernel file 10 | # It depends on ENTRYPOINT 11 | ENTRYOFFSET = 0x400 12 | 13 | # Programs, flags, etc. 14 | ASM = nasm 15 | DASM = ndisasm 16 | CC = gcc 17 | LD = ld 18 | ASMBFLAGS = -I boot/include/ 19 | ASMKFLAGS = -I include/ -f elf 20 | CFLAGS = -I include/ -c -fno-builtin -fno-stack-protector 21 | LDFLAGS = -s -Ttext $(ENTRYPOINT) 22 | DASMFLAGS = -u -o $(ENTRYPOINT) -e $(ENTRYOFFSET) 23 | 24 | # This Program 25 | ORANGESBOOT = boot/boot.bin boot/loader.bin 26 | ORANGESKERNEL = kernel.bin 27 | OBJS = kernel/kernel.o kernel/syscall.o kernel/start.o kernel/main.o\ 28 | kernel/clock.o kernel/keyboard.o\ 29 | kernel/i8259.o kernel/global.o kernel/protect.o kernel/proc.o\ 30 | lib/kliba.o lib/klib.o lib/string.o 31 | DASMOUTPUT = kernel.bin.asm 32 | 33 | # All Phony Targets 34 | .PHONY : everything final image clean realclean disasm all buildimg 35 | 36 | # Default starting position 37 | nop : 38 | @echo "why not \`make image' huh? :)" 39 | 40 | run : image 41 | bochs 42 | 43 | everything : $(ORANGESBOOT) $(ORANGESKERNEL) 44 | 45 | all : realclean everything 46 | 47 | image : realclean everything clean buildimg 48 | 49 | clean : 50 | rm -f $(OBJS) 51 | 52 | realclean : 53 | rm -f $(OBJS) $(ORANGESBOOT) $(ORANGESKERNEL) 54 | 55 | disasm : 56 | $(DASM) $(DASMFLAGS) $(ORANGESKERNEL) > $(DASMOUTPUT) 57 | 58 | # We assume that "a.img" exists in current folder 59 | buildimg : 60 | dd if=boot/boot.bin of=a.img bs=512 count=1 conv=notrunc 61 | sudo mount -o loop a.img /mnt/floppy/ 62 | sudo cp -fv boot/loader.bin /mnt/floppy/ 63 | sudo cp -fv kernel.bin /mnt/floppy 64 | sudo umount /mnt/floppy 65 | 66 | boot/boot.bin : boot/boot.asm boot/include/load.inc boot/include/fat12hdr.inc 67 | $(ASM) $(ASMBFLAGS) -o $@ $< 68 | 69 | boot/loader.bin : boot/loader.asm boot/include/load.inc boot/include/fat12hdr.inc boot/include/pm.inc 70 | $(ASM) $(ASMBFLAGS) -o $@ $< 71 | 72 | $(ORANGESKERNEL) : $(OBJS) 73 | $(LD) $(LDFLAGS) -o $(ORANGESKERNEL) $(OBJS) 74 | 75 | kernel/kernel.o : kernel/kernel.asm include/sconst.inc 76 | $(ASM) $(ASMKFLAGS) -o $@ $< 77 | 78 | kernel/syscall.o : kernel/syscall.asm include/sconst.inc 79 | $(ASM) $(ASMKFLAGS) -o $@ $< 80 | 81 | kernel/start.o: kernel/start.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 82 | include/global.h 83 | $(CC) $(CFLAGS) -o $@ $< 84 | 85 | kernel/main.o: kernel/main.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 86 | include/global.h 87 | $(CC) $(CFLAGS) -o $@ $< 88 | 89 | kernel/clock.o: kernel/clock.c 90 | $(CC) $(CFLAGS) -o $@ $< 91 | 92 | kernel/keyboard.o: kernel/keyboard.c 93 | $(CC) $(CFLAGS) -o $@ $< 94 | 95 | kernel/i8259.o: kernel/i8259.c include/type.h include/const.h include/protect.h include/proto.h 96 | $(CC) $(CFLAGS) -o $@ $< 97 | 98 | kernel/global.o: kernel/global.c include/type.h include/const.h include/protect.h include/proc.h \ 99 | include/global.h include/proto.h 100 | $(CC) $(CFLAGS) -o $@ $< 101 | 102 | kernel/protect.o: kernel/protect.c include/type.h include/const.h include/protect.h include/proc.h include/proto.h \ 103 | include/global.h 104 | $(CC) $(CFLAGS) -o $@ $< 105 | 106 | kernel/proc.o: kernel/proc.c 107 | $(CC) $(CFLAGS) -o $@ $< 108 | 109 | lib/klib.o: lib/klib.c include/type.h include/const.h include/protect.h include/string.h include/proc.h include/proto.h \ 110 | include/global.h 111 | $(CC) $(CFLAGS) -o $@ $< 112 | 113 | lib/kliba.o : lib/kliba.asm 114 | $(ASM) $(ASMKFLAGS) -o $@ $< 115 | 116 | lib/string.o : lib/string.asm 117 | $(ASM) $(ASMKFLAGS) -o $@ $< 118 | -------------------------------------------------------------------------------- /lab4/code/a.img: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/code/a.img -------------------------------------------------------------------------------- /lab4/code/bochsrc: -------------------------------------------------------------------------------- 1 | ############################################################### 2 | # Configuration file for Bochs 3 | ############################################################### 4 | 5 | # how much memory the emulated machine will have 6 | megs: 32 7 | 8 | # filename of ROM images 9 | romimage: file=/usr/share/bochs/BIOS-bochs-latest 10 | vgaromimage: file=/usr/share/vgabios/vgabios.bin 11 | 12 | # what disk images will be used 13 | floppya: 1_44=a.img, status=inserted 14 | 15 | # choose the boot disk. 16 | boot: a 17 | 18 | # where do we send log messages? 19 | # log: bochsout.txt 20 | 21 | # disable the mouse 22 | mouse: enabled=0 23 | 24 | # enable key mapping, using US layout as default. 25 | keyboard_mapping: enabled=1, map=/usr/share/bochs/keymaps/x11-pc-us.map 26 | -------------------------------------------------------------------------------- /lab4/code/boot/boot.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/code/boot/boot.bin -------------------------------------------------------------------------------- /lab4/code/boot/include/fat12hdr.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; fat12hdr.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | 9 | ; FAT12 磁盘的头 10 | ; ---------------------------------------------------------------------- 11 | BS_OEMName DB 'ForrestY' ; OEM String, 必须 8 个字节 12 | 13 | BPB_BytsPerSec DW 512 ; 每扇区字节数 14 | BPB_SecPerClus DB 1 ; 每簇多少扇区 15 | BPB_RsvdSecCnt DW 1 ; Boot 记录占用多少扇区 16 | BPB_NumFATs DB 2 ; 共有多少 FAT 表 17 | BPB_RootEntCnt DW 224 ; 根目录文件数最大值 18 | BPB_TotSec16 DW 2880 ; 逻辑扇区总数 19 | BPB_Media DB 0xF0 ; 媒体描述符 20 | BPB_FATSz16 DW 9 ; 每FAT扇区数 21 | BPB_SecPerTrk DW 18 ; 每磁道扇区数 22 | BPB_NumHeads DW 2 ; 磁头数(面数) 23 | BPB_HiddSec DD 0 ; 隐藏扇区数 24 | BPB_TotSec32 DD 0 ; 如果 wTotalSectorCount 是 0 由这个值记录扇区数 25 | 26 | BS_DrvNum DB 0 ; 中断 13 的驱动器号 27 | BS_Reserved1 DB 0 ; 未使用 28 | BS_BootSig DB 29h ; 扩展引导标记 (29h) 29 | BS_VolID DD 0 ; 卷序列号 30 | BS_VolLab DB 'OrangeS0.02'; 卷标, 必须 11 个字节 31 | BS_FileSysType DB 'FAT12 ' ; 文件系统类型, 必须 8个字节 32 | ;------------------------------------------------------------------------ 33 | 34 | 35 | ; ------------------------------------------------------------------------- 36 | ; 基于 FAT12 头的一些常量定义,如果头信息改变,下面的常量可能也要做相应改变 37 | ; ------------------------------------------------------------------------- 38 | FATSz equ 9 ; BPB_FATSz16 39 | RootDirSectors equ 14 ; 根目录占用空间: RootDirSectors = ((BPB_RootEntCnt * 32) + (BPB_BytsPerSec – 1)) / BPB_BytsPerSec; 但如果按照此公式代码过长 40 | SectorNoOfRootDirectory equ 19 ; Root Directory 的第一个扇区号 = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) 41 | SectorNoOfFAT1 equ 1 ; FAT1 的第一个扇区号 = BPB_RsvdSecCnt 42 | DeltaSectorNo equ 17 ; DeltaSectorNo = BPB_RsvdSecCnt + (BPB_NumFATs * FATSz) - 2 43 | ; 文件的开始Sector号 = DirEntry中的开始Sector号 + 根目录占用Sector数目 + DeltaSectorNo 44 | -------------------------------------------------------------------------------- /lab4/code/boot/include/load.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; load.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | 9 | BaseOfLoader equ 09000h ; LOADER.BIN 被加载到的位置 ---- 段地址 10 | OffsetOfLoader equ 0100h ; LOADER.BIN 被加载到的位置 ---- 偏移地址 11 | 12 | BaseOfLoaderPhyAddr equ BaseOfLoader * 10h ; LOADER.BIN 被加载到的位置 ---- 物理地址 (= BaseOfLoader * 10h) 13 | 14 | 15 | BaseOfKernelFile equ 08000h ; KERNEL.BIN 被加载到的位置 ---- 段地址 16 | OffsetOfKernelFile equ 0h ; KERNEL.BIN 被加载到的位置 ---- 偏移地址 17 | 18 | BaseOfKernelFilePhyAddr equ BaseOfKernelFile * 10h 19 | KernelEntryPointPhyAddr equ 030400h ; 注意:1、必须与 MAKEFILE 中参数 -Ttext 的值相等!! 20 | ; 2、这是个地址而非仅仅是个偏移,如果 -Ttext 的值为 0x400400,则它的值也应该是 0x400400。 21 | 22 | PageDirBase equ 200000h ; 页目录开始地址: 2M 23 | PageTblBase equ 201000h ; 页表开始地址: 2M + 4K 24 | 25 | -------------------------------------------------------------------------------- /lab4/code/boot/loader.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/code/boot/loader.bin -------------------------------------------------------------------------------- /lab4/code/include/const.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | const.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_CONST_H_ 9 | #define _ORANGES_CONST_H_ 10 | 11 | /* EXTERN */ 12 | #define EXTERN extern /* EXTERN is defined as extern except in global.c */ 13 | 14 | /* 函数类型 */ 15 | #define PUBLIC /* PUBLIC is the opposite of PRIVATE */ 16 | #define PRIVATE static /* PRIVATE x limits the scope of x */ 17 | 18 | /* Boolean */ 19 | #define TRUE 1 20 | #define FALSE 0 21 | 22 | /* Color */ 23 | /* 24 | * e.g. MAKE_COLOR(BLUE, RED) 25 | * MAKE_COLOR(BLACK, RED) | BRIGHT 26 | * MAKE_COLOR(BLACK, RED) | BRIGHT | FLASH 27 | */ 28 | #define BLACK 0x0 /* 0000 */ 29 | #define WHITE 0x7 /* 0111 */ 30 | #define RED 0x4 /* 0100 */ 31 | #define GREEN 0x2 /* 0010 */ 32 | #define BLUE 0x1 /* 0001 */ 33 | #define FLASH 0x80 /* 1000 0000 */ 34 | #define BRIGHT 0x08 /* 0000 1000 */ 35 | #define MAKE_COLOR(x, y) (x | y) /* MAKE_COLOR(Background,Foreground) */ 36 | 37 | /* GDT 和 IDT 中描述符的个数 */ 38 | #define GDT_SIZE 128 39 | #define IDT_SIZE 256 40 | 41 | /* 权限 */ 42 | #define PRIVILEGE_KRNL 0 43 | #define PRIVILEGE_TASK 1 44 | #define PRIVILEGE_USER 3 45 | /* RPL */ 46 | #define RPL_KRNL SA_RPL0 47 | #define RPL_TASK SA_RPL1 48 | #define RPL_USER SA_RPL3 49 | 50 | /* 8259A interrupt controller ports. */ 51 | #define INT_M_CTL 0x20 /* I/O port for interrupt controller */ 52 | #define INT_M_CTLMASK 0x21 /* setting bits in this port disables ints */ 53 | #define INT_S_CTL 0xA0 /* I/O port for second interrupt controller */ 54 | #define INT_S_CTLMASK 0xA1 /* setting bits in this port disables ints */ 55 | 56 | /* 8253/8254 PIT (Programmable Interval Timer) */ 57 | #define TIMER0 0x40 /* I/O port for timer channel 0 */ 58 | #define TIMER_MODE 0x43 /* I/O port for timer mode control */ 59 | #define RATE_GENERATOR 0x34 /* 00-11-010-0 : \ 60 | * Counter0 - LSB then MSB - rate generator - binary \ 61 | */ 62 | #define TIMER_FREQ 1193182L /* clock frequency for timer in PC and AT */ 63 | #define HZ 100 /* clock freq (software settable on IBM-PC) */ 64 | 65 | /* Hardware interrupts */ 66 | #define NR_IRQ 16 /* Number of IRQs */ 67 | #define CLOCK_IRQ 0 68 | #define KEYBOARD_IRQ 1 69 | #define CASCADE_IRQ 2 /* cascade enable for 2nd AT controller */ 70 | #define ETHER_IRQ 3 /* default ethernet interrupt vector */ 71 | #define SECONDARY_IRQ 3 /* RS232 interrupt vector for port 2 */ 72 | #define RS232_IRQ 4 /* RS232 interrupt vector for port 1 */ 73 | #define XT_WINI_IRQ 5 /* xt winchester */ 74 | #define FLOPPY_IRQ 6 /* floppy disk */ 75 | #define PRINTER_IRQ 7 76 | #define AT_WINI_IRQ 14 /* at winchester */ 77 | 78 | /* system call */ 79 | #define NR_SYS_CALL 5 //todo 80 | 81 | #endif /* _ORANGES_CONST_H_ */ 82 | 83 | #define MAX_WAIT_PROCESS 5 84 | #define MAX_SLEEP_PROCESS 6 85 | #define TIMESLICE 500 //每个时间片设为1s 86 | -------------------------------------------------------------------------------- /lab4/code/include/global.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | global.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | /* EXTERN is defined as extern except in global.c */ 9 | #ifdef GLOBAL_VARIABLES_HERE 10 | #undef EXTERN 11 | #define EXTERN 12 | #endif 13 | 14 | EXTERN int ticks; 15 | EXTERN int lastTicks; 16 | 17 | EXTERN int mode; 18 | EXTERN int readCount; 19 | EXTERN int writeCount; 20 | EXTERN int isBlockedF; 21 | 22 | EXTERN int disp_pos; 23 | EXTERN u8 gdt_ptr[6]; // 0~15:Limit 16~47:Base 24 | EXTERN DESCRIPTOR gdt[GDT_SIZE]; 25 | EXTERN u8 idt_ptr[6]; // 0~15:Limit 16~47:Base 26 | EXTERN GATE idt[IDT_SIZE]; 27 | 28 | EXTERN u32 k_reenter; 29 | 30 | EXTERN TSS tss; 31 | EXTERN PROCESS *p_proc_ready; 32 | 33 | extern PROCESS proc_table[]; 34 | extern char task_stack[]; 35 | extern TASK task_table[]; 36 | extern irq_handler irq_table[]; 37 | 38 | extern PROCESS *sleep_table[]; 39 | extern int sleep_size; 40 | 41 | extern SEMAPHORE rmutex; 42 | extern SEMAPHORE wmutex; 43 | extern SEMAPHORE rw_mutex; 44 | extern SEMAPHORE nr_readers; 45 | extern SEMAPHORE r; 46 | extern SEMAPHORE w; 47 | extern SEMAPHORE queue; 48 | 49 | extern SEMAPHORE specialMutex; 50 | 51 | extern int schedulable_queue[]; 52 | extern int schedulable_queue_size; 53 | 54 | void push(int); 55 | void remove(int); 56 | int find(); 57 | int numOfNotWorked(); 58 | void reWork(); -------------------------------------------------------------------------------- /lab4/code/include/proc.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proc.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | typedef struct s_stackframe 9 | { /* proc_ptr points here ↑ Low */ 10 | u32 gs; /* ┓ │ */ 11 | u32 fs; /* ┃ │ */ 12 | u32 es; /* ┃ │ */ 13 | u32 ds; /* ┃ │ */ 14 | u32 edi; /* ┃ │ */ 15 | u32 esi; /* ┣ pushed by save() │ */ 16 | u32 ebp; /* ┃ │ */ 17 | u32 kernel_esp; /* <- 'popad' will ignore it │ */ 18 | u32 ebx; /* ┃ ↑栈从高地址往低地址增长*/ 19 | u32 edx; /* ┃ │ */ 20 | u32 ecx; /* ┃ │ */ 21 | u32 eax; /* ┛ │ */ 22 | u32 retaddr; /* return address for assembly code save() │ */ 23 | u32 eip; /* ┓ │ */ 24 | u32 cs; /* ┃ │ */ 25 | u32 eflags; /* ┣ these are pushed by CPU during interrupt │ */ 26 | u32 esp; /* ┃ │ */ 27 | u32 ss; /* ┛ ┷High */ 28 | } STACK_FRAME; 29 | 30 | typedef struct s_proc 31 | { 32 | STACK_FRAME regs; /* process registers saved in stack frame */ 33 | 34 | u16 ldt_sel; /* gdt selector giving ldt base and limit */ 35 | DESCRIPTOR ldts[LDT_SIZE]; /* local descriptors for code and data */ 36 | 37 | int ticks; /* remained ticks */ 38 | int priority; 39 | 40 | int sleep_time; 41 | int isWaiting; 42 | int color; 43 | int hasWorked; 44 | /* int timeSlice; 45 | */ 46 | u32 pid; /* process id passed in from MM */ 47 | char p_name[16]; /* name of the process */ 48 | 49 | } PROCESS; 50 | 51 | typedef struct semaphore 52 | { 53 | int value; 54 | int size; 55 | char name[32]; 56 | PROCESS *list[MAX_WAIT_PROCESS]; 57 | } SEMAPHORE; 58 | 59 | typedef struct s_task 60 | { 61 | task_f initial_eip; 62 | int stacksize; 63 | char name[32]; 64 | } TASK; 65 | 66 | /* Number of tasks */ 67 | #define NR_TASKS 6 68 | 69 | /* stacks of tasks */ 70 | #define STACK_SIZE_ReadA 0x8000 71 | #define STACK_SIZE_ReadB 0x8000 72 | #define STACK_SIZE_ReadC 0x8000 73 | #define STACK_SIZE_WriteD 0x8000 74 | #define STACK_SIZE_WriteE 0x8000 75 | #define STACK_SZIE_F 0x8000 76 | 77 | #define STACK_SIZE_TOTAL (STACK_SIZE_ReadA + \ 78 | STACK_SIZE_ReadB + \ 79 | STACK_SIZE_ReadC + \ 80 | STACK_SIZE_WriteD + \ 81 | STACK_SIZE_WriteE + \ 82 | STACK_SZIE_F) 83 | -------------------------------------------------------------------------------- /lab4/code/include/protect.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | protect.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_PROTECT_H_ 9 | #define _ORANGES_PROTECT_H_ 10 | 11 | 12 | /* 存储段描述符/系统段描述符 */ 13 | typedef struct s_descriptor /* 共 8 个字节 */ 14 | { 15 | u16 limit_low; /* Limit */ 16 | u16 base_low; /* Base */ 17 | u8 base_mid; /* Base */ 18 | u8 attr1; /* P(1) DPL(2) DT(1) TYPE(4) */ 19 | u8 limit_high_attr2; /* G(1) D(1) 0(1) AVL(1) LimitHigh(4) */ 20 | u8 base_high; /* Base */ 21 | }DESCRIPTOR; 22 | 23 | /* 门描述符 */ 24 | typedef struct s_gate 25 | { 26 | u16 offset_low; /* Offset Low */ 27 | u16 selector; /* Selector */ 28 | u8 dcount; /* 该字段只在调用门描述符中有效。 29 | 如果在利用调用门调用子程序时引起特权级的转换和堆栈的改变,需要将外层堆栈中的参数复制到内层堆栈。 30 | 该双字计数字段就是用于说明这种情况发生时,要复制的双字参数的数量。 */ 31 | u8 attr; /* P(1) DPL(2) DT(1) TYPE(4) */ 32 | u16 offset_high; /* Offset High */ 33 | }GATE; 34 | 35 | typedef struct s_tss { 36 | u32 backlink; 37 | u32 esp0; /* stack pointer to use during interrupt */ 38 | u32 ss0; /* " segment " " " " */ 39 | u32 esp1; 40 | u32 ss1; 41 | u32 esp2; 42 | u32 ss2; 43 | u32 cr3; 44 | u32 eip; 45 | u32 flags; 46 | u32 eax; 47 | u32 ecx; 48 | u32 edx; 49 | u32 ebx; 50 | u32 esp; 51 | u32 ebp; 52 | u32 esi; 53 | u32 edi; 54 | u32 es; 55 | u32 cs; 56 | u32 ss; 57 | u32 ds; 58 | u32 fs; 59 | u32 gs; 60 | u32 ldt; 61 | u16 trap; 62 | u16 iobase; /* I/O位图基址大于或等于TSS段界限,就表示没有I/O许可位图 */ 63 | /*u8 iomap[2];*/ 64 | }TSS; 65 | 66 | /* GDT */ 67 | /* 描述符索引 */ 68 | #define INDEX_DUMMY 0 // ┓ 69 | #define INDEX_FLAT_C 1 // ┣ LOADER 里面已经确定了的. 70 | #define INDEX_FLAT_RW 2 // ┃ 71 | #define INDEX_VIDEO 3 // ┛ 72 | #define INDEX_TSS 4 73 | #define INDEX_LDT_FIRST 5 74 | /* 选择子 */ 75 | #define SELECTOR_DUMMY 0 // ┓ 76 | #define SELECTOR_FLAT_C 0x08 // ┣ LOADER 里面已经确定了的. 77 | #define SELECTOR_FLAT_RW 0x10 // ┃ 78 | #define SELECTOR_VIDEO (0x18+3) // ┛<-- RPL=3 79 | #define SELECTOR_TSS 0x20 // TSS. 从外层跳到内存时 SS 和 ESP 的值从里面获得. 80 | #define SELECTOR_LDT_FIRST 0x28 81 | 82 | #define SELECTOR_KERNEL_CS SELECTOR_FLAT_C 83 | #define SELECTOR_KERNEL_DS SELECTOR_FLAT_RW 84 | #define SELECTOR_KERNEL_GS SELECTOR_VIDEO 85 | 86 | /* 每个任务有一个单独的 LDT, 每个 LDT 中的描述符个数: */ 87 | #define LDT_SIZE 2 88 | 89 | /* 描述符类型值说明 */ 90 | #define DA_32 0x4000 /* 32 位段 */ 91 | #define DA_LIMIT_4K 0x8000 /* 段界限粒度为 4K 字节 */ 92 | #define DA_DPL0 0x00 /* DPL = 0 */ 93 | #define DA_DPL1 0x20 /* DPL = 1 */ 94 | #define DA_DPL2 0x40 /* DPL = 2 */ 95 | #define DA_DPL3 0x60 /* DPL = 3 */ 96 | /* 存储段描述符类型值说明 */ 97 | #define DA_DR 0x90 /* 存在的只读数据段类型值 */ 98 | #define DA_DRW 0x92 /* 存在的可读写数据段属性值 */ 99 | #define DA_DRWA 0x93 /* 存在的已访问可读写数据段类型值 */ 100 | #define DA_C 0x98 /* 存在的只执行代码段属性值 */ 101 | #define DA_CR 0x9A /* 存在的可执行可读代码段属性值 */ 102 | #define DA_CCO 0x9C /* 存在的只执行一致代码段属性值 */ 103 | #define DA_CCOR 0x9E /* 存在的可执行可读一致代码段属性值 */ 104 | /* 系统段描述符类型值说明 */ 105 | #define DA_LDT 0x82 /* 局部描述符表段类型值 */ 106 | #define DA_TaskGate 0x85 /* 任务门类型值 */ 107 | #define DA_386TSS 0x89 /* 可用 386 任务状态段类型值 */ 108 | #define DA_386CGate 0x8C /* 386 调用门类型值 */ 109 | #define DA_386IGate 0x8E /* 386 中断门类型值 */ 110 | #define DA_386TGate 0x8F /* 386 陷阱门类型值 */ 111 | 112 | /* 选择子类型值说明 */ 113 | /* 其中, SA_ : Selector Attribute */ 114 | #define SA_RPL_MASK 0xFFFC 115 | #define SA_RPL0 0 116 | #define SA_RPL1 1 117 | #define SA_RPL2 2 118 | #define SA_RPL3 3 119 | 120 | #define SA_TI_MASK 0xFFFB 121 | #define SA_TIG 0 122 | #define SA_TIL 4 123 | 124 | /* 中断向量 */ 125 | #define INT_VECTOR_DIVIDE 0x0 126 | #define INT_VECTOR_DEBUG 0x1 127 | #define INT_VECTOR_NMI 0x2 128 | #define INT_VECTOR_BREAKPOINT 0x3 129 | #define INT_VECTOR_OVERFLOW 0x4 130 | #define INT_VECTOR_BOUNDS 0x5 131 | #define INT_VECTOR_INVAL_OP 0x6 132 | #define INT_VECTOR_COPROC_NOT 0x7 133 | #define INT_VECTOR_DOUBLE_FAULT 0x8 134 | #define INT_VECTOR_COPROC_SEG 0x9 135 | #define INT_VECTOR_INVAL_TSS 0xA 136 | #define INT_VECTOR_SEG_NOT 0xB 137 | #define INT_VECTOR_STACK_FAULT 0xC 138 | #define INT_VECTOR_PROTECTION 0xD 139 | #define INT_VECTOR_PAGE_FAULT 0xE 140 | #define INT_VECTOR_COPROC_ERR 0x10 141 | 142 | /* 中断向量 */ 143 | #define INT_VECTOR_IRQ0 0x20 144 | #define INT_VECTOR_IRQ8 0x28 145 | 146 | /* 系统调用 */ 147 | #define INT_VECTOR_SYS_CALL 0x90 148 | 149 | /* 宏 */ 150 | /* 线性地址 → 物理地址 */ 151 | #define vir2phys(seg_base, vir) (u32)(((u32)seg_base) + (u32)(vir)) 152 | 153 | 154 | #endif /* _ORANGES_PROTECT_H_ */ 155 | -------------------------------------------------------------------------------- /lab4/code/include/proto.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proto.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "proc.h" 9 | 10 | /* klib.asm */ 11 | PUBLIC void out_byte(u16 port, u8 value); 12 | PUBLIC u8 in_byte(u16 port); 13 | PUBLIC void disp_str(char *info); 14 | PUBLIC void disp_color_str(char *info, int color); 15 | 16 | /* protect.c */ 17 | PUBLIC void init_prot(); 18 | PUBLIC u32 seg2phys(u16 seg); 19 | 20 | /* klib.c */ 21 | PUBLIC void delay(int time); 22 | PUBLIC void clean__screen(); 23 | 24 | /* kernel.asm */ 25 | void restart(); 26 | 27 | /* main.c */ 28 | void ReadA(); 29 | void ReadB(); 30 | void ReadC(); 31 | void WriteD(); 32 | void WriteE(); 33 | void F(); 34 | 35 | /* i8259.c */ 36 | PUBLIC void put_irq_handler(int irq, irq_handler handler); 37 | PUBLIC void spurious_irq(int irq); 38 | 39 | /* clock.c */ 40 | PUBLIC void clock_handler(int irq); 41 | PUBLIC void init_clock(); 42 | 43 | /* keyboard.c */ 44 | PUBLIC void init_keyboard(); 45 | 46 | /* 以下是系统调用相关 */ 47 | 48 | //todo 49 | /* proc.c */ 50 | PUBLIC int sys_get_ticks(); /* sys_call */ 51 | PUBLIC void sys_delay_milli_seconds(int); 52 | PUBLIC void sys_p(SEMAPHORE *s); 53 | PUBLIC void sys_v(SEMAPHORE *s); 54 | 55 | /* syscall.asm */ 56 | PUBLIC void sys_call(); /* int_handler */ 57 | PUBLIC int get_ticks(); 58 | PUBLIC void delay_milli_seconds(int); 59 | PUBLIC void print_str(char *); 60 | PUBLIC void P(SEMAPHORE *); 61 | PUBLIC void V(SEMAPHORE *); 62 | -------------------------------------------------------------------------------- /lab4/code/include/sconst.inc: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; sconst.inc 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | P_STACKBASE equ 0 9 | GSREG equ P_STACKBASE 10 | FSREG equ GSREG + 4 11 | ESREG equ FSREG + 4 12 | DSREG equ ESREG + 4 13 | EDIREG equ DSREG + 4 14 | ESIREG equ EDIREG + 4 15 | EBPREG equ ESIREG + 4 16 | KERNELESPREG equ EBPREG + 4 17 | EBXREG equ KERNELESPREG + 4 18 | EDXREG equ EBXREG + 4 19 | ECXREG equ EDXREG + 4 20 | EAXREG equ ECXREG + 4 21 | RETADR equ EAXREG + 4 22 | EIPREG equ RETADR + 4 23 | CSREG equ EIPREG + 4 24 | EFLAGSREG equ CSREG + 4 25 | ESPREG equ EFLAGSREG + 4 26 | SSREG equ ESPREG + 4 27 | P_STACKTOP equ SSREG + 4 28 | P_LDT_SEL equ P_STACKTOP 29 | P_LDT equ P_LDT_SEL + 4 30 | 31 | TSS3_S_SP0 equ 4 32 | 33 | INT_M_CTL equ 0x20 ; I/O port for interrupt controller 34 | INT_M_CTLMASK equ 0x21 ; setting bits in this port disables ints 35 | INT_S_CTL equ 0xA0 ; I/O port for second interrupt controller 36 | INT_S_CTLMASK equ 0xA1 ; setting bits in this port disables ints 37 | 38 | EOI equ 0x20 39 | 40 | ; 以下选择子值必须与 protect.h 中保持一致!!! 41 | SELECTOR_FLAT_C equ 0x08 ; LOADER 里面已经确定了的. 42 | SELECTOR_TSS equ 0x20 ; TSS. 从外层跳到内存时 SS 和 ESP 的值从里面获得. 43 | SELECTOR_KERNEL_CS equ SELECTOR_FLAT_C 44 | 45 | -------------------------------------------------------------------------------- /lab4/code/include/string.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | string.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | PUBLIC void *memcpy(void *p_dst, void *p_src, int size); 9 | PUBLIC void memset(void *p_dst, char ch, int size); 10 | -------------------------------------------------------------------------------- /lab4/code/include/type.h: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | type.h 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #ifndef _ORANGES_TYPE_H_ 9 | #define _ORANGES_TYPE_H_ 10 | 11 | typedef unsigned int u32; 12 | typedef unsigned short u16; 13 | typedef unsigned char u8; 14 | 15 | typedef void (*int_handler)(); 16 | typedef void (*task_f)(); 17 | typedef void (*irq_handler)(int irq); 18 | 19 | typedef void *system_call; 20 | 21 | #endif /* _ORANGES_TYPE_H_ */ 22 | -------------------------------------------------------------------------------- /lab4/code/kernel.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/code/kernel.bin -------------------------------------------------------------------------------- /lab4/code/kernel/clock.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | clock.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "proto.h" 12 | #include "string.h" 13 | #include "global.h" 14 | 15 | /*======================================================================* 16 | clock_handler 17 | *======================================================================*/ 18 | PUBLIC void clock_handler(int irq) 19 | { 20 | ticks++; 21 | /* p_proc_ready->ticks--; */ 22 | 23 | if (k_reenter != 0) 24 | { 25 | return; 26 | } 27 | 28 | for (int i = 0; i < NR_TASKS; i++) 29 | { 30 | if (proc_table[i].sleep_time > 0) 31 | { 32 | proc_table[i].sleep_time--; 33 | if (proc_table[i].sleep_time == 0) 34 | { 35 | //移入可调度队列 36 | push(proc_table[i].pid); 37 | } 38 | } 39 | } 40 | 41 | schedule(); 42 | } 43 | 44 | /*======================================================================* 45 | milli_delay 46 | *======================================================================*/ 47 | PUBLIC void milli_delay(int milli_sec) 48 | { 49 | int t = get_ticks(); //此函数是线程共享的,比如A线程和B线程都需要延迟20ms,然后A线程和B线程轮流被分配时间片,事实上在A的时间片里面B线程的延迟也在被及时,因为ticks对于每个线程是共享变化的 50 | 51 | while (((get_ticks() - t) * 1000 / HZ) < milli_sec) //todo 52 | { 53 | } 54 | } 55 | 56 | /*======================================================================* 57 | init_clock 58 | *======================================================================*/ 59 | PUBLIC void init_clock() 60 | { 61 | /* 初始化 8253 PIT */ 62 | out_byte(TIMER_MODE, RATE_GENERATOR); 63 | out_byte(TIMER0, (u8)(TIMER_FREQ / HZ)); 64 | out_byte(TIMER0, (u8)((TIMER_FREQ / HZ) >> 8)); 65 | 66 | put_irq_handler(CLOCK_IRQ, clock_handler); /* 设定时钟中断处理程序 */ 67 | enable_irq(CLOCK_IRQ); /* 让8259A可以接收时钟中断 */ 68 | } 69 | -------------------------------------------------------------------------------- /lab4/code/kernel/global.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | global.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #define GLOBAL_VARIABLES_HERE 9 | 10 | #include "type.h" 11 | #include "const.h" 12 | #include "protect.h" 13 | #include "proto.h" 14 | #include "global.h" 15 | 16 | PUBLIC PROCESS proc_table[NR_TASKS]; 17 | 18 | PUBLIC char task_stack[STACK_SIZE_TOTAL]; 19 | 20 | PUBLIC TASK task_table[NR_TASKS] = {{ReadA, STACK_SIZE_ReadA, "ReadA"}, 21 | {ReadB, STACK_SIZE_ReadB, "ReadB"}, 22 | {ReadC, STACK_SIZE_ReadC, "ReadC"}, 23 | {WriteD, STACK_SIZE_WriteD, "WriteD"}, 24 | {WriteE, STACK_SIZE_WriteE, "WriteE"}, 25 | {F, STACK_SZIE_F, "F"}}; //用户进程 26 | 27 | PUBLIC irq_handler irq_table[NR_IRQ]; //中断处理函数,其中0位置为始终中断处理 28 | 29 | //todo 30 | PUBLIC system_call sys_call_table[NR_SYS_CALL] = {sys_get_ticks, sys_delay_milli_seconds, disp_str, sys_p, sys_v}; //系统调用的函数 31 | 32 | SEMAPHORE rmutex = {1, 0, "rmutex"}; //读信号量,控制对于readCount进行互斥访问 33 | SEMAPHORE wmutex = {1, 0, "wmutex"}; //写信号量,控制对于writeCount的互斥访问 34 | SEMAPHORE rw_mutex = {1, 0, "rw_mutex"}; //读写信号量,是读写互斥锁,用于在读者优先中实现读写互斥 35 | SEMAPHORE nr_readers = {1, 0, "nr_readers"}; //读上限人数信号量,控制读上限人数 36 | SEMAPHORE r = {1, 0, "r"}; //写者优先中让写进程开始的时候申请阻塞读进程 37 | SEMAPHORE w = {1, 0, "w"}; //在写者优先中,允许至多一个写进程在写 38 | SEMAPHORE queue = {1, 0, "queue"}; //在写进程优先中,让多的信号量都在queue上排队,避免在r信号量上排长队使得写进程等待很久 39 | 40 | int schedulable_queue[NR_TASKS - 1] = {0, 1, 2, 3, 4}; //减去一个进程是因为F进程特殊判断来调用 41 | int schedulable_queue_size = NR_TASKS - 1; 42 | 43 | void push(int n) //添加新的就绪进程 44 | { 45 | schedulable_queue[schedulable_queue_size] = n; 46 | schedulable_queue_size++; 47 | } 48 | 49 | void remove(int n) //移出就绪进程 50 | { 51 | for (int i = n; i < schedulable_queue_size - 1; i++) 52 | { 53 | schedulable_queue[i] = schedulable_queue[i + 1]; 54 | } 55 | schedulable_queue_size--; 56 | } 57 | 58 | int find() 59 | { 60 | for (int i = 0; i < schedulable_queue_size; i++) 61 | { 62 | if (schedulable_queue[i] == p_proc_ready->pid) 63 | { 64 | return i; 65 | } 66 | } 67 | return -1; 68 | } 69 | 70 | int numOfNotWorked() 71 | { 72 | int notWorked = 0; 73 | for (int i = 0; i < schedulable_queue_size; i++) 74 | { 75 | if (proc_table[schedulable_queue[i]].hasWorked == 0) 76 | { 77 | notWorked++; 78 | } 79 | } 80 | return notWorked; //返回的是没有工作过的进程的数量 81 | } 82 | 83 | void reWork() 84 | { 85 | for (int i = 0; i < schedulable_queue_size; i++) 86 | { 87 | proc_table[schedulable_queue[i]].hasWorked = 0; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /lab4/code/kernel/i8259.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | i8259.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "proto.h" 12 | #include "global.h" 13 | 14 | /*======================================================================* 15 | init_8259A 16 | *======================================================================*/ 17 | PUBLIC void init_8259A() 18 | { 19 | out_byte(INT_M_CTL, 0x11); // Master 8259, ICW1. 20 | out_byte(INT_S_CTL, 0x11); // Slave 8259, ICW1. 21 | out_byte(INT_M_CTLMASK, INT_VECTOR_IRQ0); // Master 8259, ICW2. 设置 '主8259' 的中断入口地址为 0x20. 22 | out_byte(INT_S_CTLMASK, INT_VECTOR_IRQ8); // Slave 8259, ICW2. 设置 '从8259' 的中断入口地址为 0x28 23 | out_byte(INT_M_CTLMASK, 0x4); // Master 8259, ICW3. IR2 对应 '从8259'. 24 | out_byte(INT_S_CTLMASK, 0x2); // Slave 8259, ICW3. 对应 '主8259' 的 IR2. 25 | out_byte(INT_M_CTLMASK, 0x1); // Master 8259, ICW4. 26 | out_byte(INT_S_CTLMASK, 0x1); // Slave 8259, ICW4. 27 | 28 | out_byte(INT_M_CTLMASK, 0xFF); // Master 8259, OCW1. 29 | out_byte(INT_S_CTLMASK, 0xFF); // Slave 8259, OCW1. 30 | 31 | int i; 32 | for (i = 0; i < NR_IRQ; i++) 33 | { 34 | irq_table[i] = spurious_irq; 35 | } 36 | } 37 | 38 | /*======================================================================* 39 | spurious_irq 40 | *======================================================================*/ 41 | PUBLIC void spurious_irq(int irq) 42 | { 43 | disp_str("spurious_irq: "); 44 | disp_int(irq); 45 | disp_str("\n"); 46 | } 47 | 48 | /*======================================================================* 49 | put_irq_handler 50 | *======================================================================*/ 51 | PUBLIC void put_irq_handler(int irq, irq_handler handler) 52 | { 53 | disable_irq(irq); 54 | irq_table[irq] = handler; 55 | } 56 | -------------------------------------------------------------------------------- /lab4/code/kernel/keyboard.c: -------------------------------------------------------------------------------- 1 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 | keyboard.c 3 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 | Forrest Yu, 2005 5 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 6 | 7 | #include "type.h" 8 | #include "const.h" 9 | #include "protect.h" 10 | #include "proto.h" 11 | #include "string.h" 12 | #include "global.h" 13 | 14 | /*======================================================================* 15 | keyboard_handler 16 | *======================================================================*/ 17 | PUBLIC void keyboard_handler(int irq) 18 | { 19 | disp_str("*"); 20 | } 21 | 22 | /*======================================================================* 23 | init_keyboard 24 | *======================================================================*/ 25 | PUBLIC void init_keyboard() 26 | { 27 | put_irq_handler(KEYBOARD_IRQ, keyboard_handler); /*设定键盘中断处理程序*/ 28 | enable_irq(KEYBOARD_IRQ); /*开键盘中断*/ 29 | } 30 | -------------------------------------------------------------------------------- /lab4/code/kernel/proc.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | proc.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "proto.h" 12 | #include "string.h" 13 | #include "global.h" 14 | 15 | /*======================================================================* 16 | schedule 17 | *======================================================================*/ 18 | PUBLIC void schedule() 19 | { 20 | if (ticks - lastTicks >= 100) 21 | { 22 | lastTicks = ticks; 23 | p_proc_ready = proc_table + NR_TASKS - 1; //选中F进程 24 | isBlockedF = 0; 25 | return; 26 | } 27 | 28 | PROCESS *p; 29 | 30 | if (schedulable_queue_size == 0) 31 | { 32 | disp_str("no process is schedulable\n"); 33 | } 34 | else 35 | { 36 | if (!numOfNotWorked()) 37 | { 38 | reWork(); 39 | } 40 | 41 | do 42 | { 43 | int process = schedulable_queue[0]; 44 | p_proc_ready = proc_table + process; 45 | remove(0); //删除 46 | push(process); //移到队末 47 | } while (p_proc_ready->hasWorked == 1); 48 | 49 | /* int process = schedulable_queue[0]; 50 | p_proc_ready = proc_table + process; 51 | remove(0); //删除 52 | push(process); //移到队末 */ 53 | } 54 | } 55 | 56 | /*======================================================================* 57 | sys_get_ticks 58 | *======================================================================*/ 59 | PUBLIC int sys_get_ticks() 60 | { 61 | return ticks; 62 | } 63 | 64 | /*======================================================================* 65 | sys_delay_milli_seconds 66 | *======================================================================*/ 67 | PUBLIC void sys_delay_milli_seconds(int milli_second) //todo 68 | { 69 | p_proc_ready->sleep_time = milli_second; //睡眠时间以tick为单位,一个tick就是对应的一个ms 70 | int index = find(); //把该进程移出可调度队列 71 | if (index != -1) 72 | { 73 | remove(index); 74 | } 75 | schedule(); 76 | restart(); 77 | } 78 | 79 | PUBLIC void sys_p(SEMAPHORE *s) 80 | { 81 | s->value--; 82 | if (s->value < 0) 83 | { 84 | sleep(s); 85 | } 86 | } 87 | 88 | PUBLIC void sys_v(SEMAPHORE *s) 89 | { 90 | s->value++; 91 | if (s->value <= 0) 92 | { 93 | wakeup(s); 94 | } 95 | } 96 | 97 | void sleep(SEMAPHORE *s) 98 | { 99 | //需要将当前的进程从可调度队列中移除 100 | int index = find(); //先找到当前进程在可调度队列中的下标,然后再删除当前进程 101 | if (index != -1) 102 | { 103 | remove(index); //todo 104 | } 105 | 106 | /* disp_str(p_proc_ready->p_name); 107 | disp_str(" sleeps in "); 108 | disp_str(s->name); 109 | disp_str(" "); */ 110 | //disp_str("\n"); 111 | 112 | p_proc_ready->isWaiting = 1; 113 | s->list[s->size] = p_proc_ready; 114 | s->size++; 115 | 116 | schedule(); 117 | restart(); 118 | 119 | //天坑,我吐了,这边sleep之后,会继续返回main中执行P操作后面的命令,因为当前进程的时间片没有消耗完,所以需要在手动切换进程 120 | //把陷入等待的进程移到进程队列的末尾,因为其刚刚陷入等待,需要等待的时间最长 121 | /* for (PROCESS *p = p_proc_ready; p < proc_table + NR_TASKS - 1; p++) 122 | { 123 | *p = *(p + 1); 124 | } 125 | proc_table[NR_TASKS - 1] = temp; 126 | 127 | for (PROCESS *p = proc_table; p < proc_table + NR_TASKS; p++) 128 | { 129 | disp_str(p->p_name); 130 | } 131 | disp_str("\n"); 132 | schedule(); 133 | disp_str(p_proc_ready->p_name); 134 | disp_str(" is chosen\n"); 135 | restart(); */ 136 | 137 | //disp_str(p_proc_ready->p_name); 138 | } 139 | 140 | void wakeup(SEMAPHORE *s) 141 | { 142 | if (s->size > 0) 143 | { 144 | /* disp_str(p_proc_ready->p_name); 145 | disp_str(" wakes up "); 146 | disp_str(s->list[0]->p_name); 147 | disp_str(" in "); 148 | disp_str(s->name); 149 | disp_str(" "); */ 150 | //disp_str("\n"); 151 | 152 | push(s->list[0]->pid); //移入可调度队列 153 | 154 | s->list[0]->isWaiting = 0; //从当前信号量的等待队列中移出队首的等待进程 155 | for (int i = 0; i < s->size - 1; i++) 156 | { 157 | s->list[i] = s->list[i + 1]; 158 | } 159 | s->size--; 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /lab4/code/kernel/start.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | start.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "proto.h" 12 | #include "string.h" 13 | #include "global.h" 14 | 15 | /*======================================================================* 16 | cstart 17 | *======================================================================*/ 18 | PUBLIC void cstart() 19 | { 20 | disp_str("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n-----\"cstart\" begins-----\n"); 21 | 22 | // 将 LOADER 中的 GDT 复制到新的 GDT 中 23 | memcpy(&gdt, // New GDT 24 | (void *)(*((u32 *)(&gdt_ptr[2]))), // Base of Old GDT 25 | *((u16 *)(&gdt_ptr[0])) + 1 // Limit of Old GDT 26 | ); 27 | // gdt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sgdt 以及 lgdt 的参数。 28 | u16 *p_gdt_limit = (u16 *)(&gdt_ptr[0]); 29 | u32 *p_gdt_base = (u32 *)(&gdt_ptr[2]); 30 | *p_gdt_limit = GDT_SIZE * sizeof(DESCRIPTOR) - 1; 31 | *p_gdt_base = (u32)&gdt; 32 | 33 | // idt_ptr[6] 共 6 个字节:0~15:Limit 16~47:Base。用作 sidt 以及 lidt 的参数。 34 | u16 *p_idt_limit = (u16 *)(&idt_ptr[0]); 35 | u32 *p_idt_base = (u32 *)(&idt_ptr[2]); 36 | *p_idt_limit = IDT_SIZE * sizeof(GATE) - 1; 37 | *p_idt_base = (u32)&idt; 38 | 39 | init_prot(); 40 | 41 | disp_str("-----\"cstart\" finished-----\n"); 42 | } 43 | -------------------------------------------------------------------------------- /lab4/code/kernel/syscall.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; syscall.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | %include "sconst.inc" 9 | 10 | extern disp_str 11 | extern disp_int 12 | 13 | _NR_get_ticks equ 0 ; 要跟 global.c 中 sys_call_table 的定义相对应! 14 | _NR_delay_milli_seconds equ 1 ;todo 15 | _NT_print_str equ 2 16 | _NT_P equ 3 17 | _NT_V equ 4 18 | INT_VECTOR_SYS_CALL equ 0x90 19 | 20 | ; 导出符号 21 | global get_ticks 22 | global delay_milli_seconds ;//todo 23 | global print_str 24 | global P 25 | global V 26 | 27 | 28 | bits 32 29 | [section .text] 30 | 31 | ; ==================================================================== 32 | ; get_ticks 33 | ; ==================================================================== 34 | get_ticks: 35 | mov eax, _NR_get_ticks 36 | int INT_VECTOR_SYS_CALL 37 | ret 38 | 39 | ;//todo 40 | delay_milli_seconds: 41 | mov ebx, [esp + 4] ;ebx保存传过来的时间参数 42 | mov eax, _NR_delay_milli_seconds ;eax保存在系统调用函数表中的偏移量 43 | int INT_VECTOR_SYS_CALL ;调用系统调用 44 | ret 45 | 46 | print_str: 47 | mov ebx, [esp + 4] ;exb保存了指向字符串的指针 48 | mov eax, _NT_print_str 49 | int INT_VECTOR_SYS_CALL 50 | ret ;关于我没写ret指令造成的惨剧 51 | 52 | P: 53 | mov ebx, [esp + 4] ;ebx保存了指向信号量的指针 54 | mov eax, _NT_P 55 | int INT_VECTOR_SYS_CALL 56 | ret 57 | 58 | V: 59 | mov ebx, [esp + 4] 60 | mov eax, _NT_V 61 | int INT_VECTOR_SYS_CALL 62 | ret 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /lab4/code/lib/klib.c: -------------------------------------------------------------------------------- 1 | 2 | /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | klib.c 4 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | Forrest Yu, 2005 6 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ 7 | 8 | #include "type.h" 9 | #include "const.h" 10 | #include "protect.h" 11 | #include "proto.h" 12 | #include "string.h" 13 | #include "global.h" 14 | 15 | /*======================================================================* 16 | itoa 17 | *======================================================================*/ 18 | PUBLIC char *itoa(char *str, int num) /* 数字前面的 0 不被显示出来, 比如 0000B800 被显示成 B800 */ 19 | { 20 | char *p = str; 21 | char ch; 22 | int i; 23 | int flag = FALSE; 24 | 25 | *p++ = '0'; 26 | *p++ = 'x'; 27 | 28 | if (num == 0) 29 | { 30 | *p++ = '0'; 31 | } 32 | else 33 | { 34 | for (i = 28; i >= 0; i -= 4) 35 | { 36 | ch = (num >> i) & 0xF; 37 | if (flag || (ch > 0)) 38 | { 39 | flag = TRUE; 40 | ch += '0'; 41 | if (ch > '9') 42 | { 43 | ch += 7; 44 | } 45 | *p++ = ch; 46 | } 47 | } 48 | } 49 | 50 | *p = 0; 51 | 52 | return str; 53 | } 54 | 55 | /*======================================================================* 56 | disp_int 57 | *======================================================================*/ 58 | PUBLIC void disp_int(int input) 59 | { 60 | char output[16]; 61 | itoa(output, input); 62 | disp_str(output); 63 | } 64 | 65 | /*======================================================================* 66 | delay 67 | *======================================================================*/ 68 | PUBLIC void delay(int time) 69 | { 70 | int i, j, k; 71 | for (k = 0; k < time; k++) 72 | { 73 | /*for(i=0;i<10000;i++){ for Virtual PC */ 74 | for (i = 0; i < 10; i++) 75 | { /* for Bochs */ 76 | for (j = 0; j < 10000; j++) 77 | { 78 | } 79 | } 80 | } 81 | } 82 | 83 | PUBLIC void clean_screen() 84 | { 85 | disp_pos = 0; 86 | for (int i = 0; i < 80 * 25; i++) 87 | { 88 | disp_str(" "); 89 | } 90 | disp_pos = 0; 91 | } 92 | -------------------------------------------------------------------------------- /lab4/code/lib/kliba.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; klib.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | %include "sconst.inc" 9 | 10 | ; 导入全局变量 11 | extern disp_pos 12 | 13 | 14 | [SECTION .text] 15 | 16 | ; 导出函数 17 | global disp_str 18 | global disp_color_str 19 | global out_byte 20 | global in_byte 21 | global enable_irq 22 | global disable_irq 23 | global enable_int 24 | global disable_int 25 | 26 | ; ======================================================================== 27 | ; void disp_str(char * info); 28 | ; ======================================================================== 29 | disp_str: 30 | push ebp ;保存ebp 31 | mov ebp, esp ;把栈顶寄存器赋给栈基址寄存器 32 | 33 | mov esi, [ebp + 8] ; pszInfo ;要打印的字符串起始位置在esi中 34 | mov edi, [disp_pos] 35 | mov ah, 0Fh 36 | .1: 37 | lodsb 38 | test al, al 39 | jz .2 40 | cmp al, 0Ah ; 是回车吗? 41 | jnz .3 42 | push eax 43 | mov eax, edi 44 | mov bl, 160 45 | div bl 46 | and eax, 0FFh 47 | inc eax 48 | mov bl, 160 49 | mul bl 50 | mov edi, eax 51 | pop eax 52 | jmp .1 53 | .3: 54 | mov [gs:edi], ax 55 | add edi, 2 56 | jmp .1 57 | 58 | .2: 59 | mov [disp_pos], edi 60 | 61 | pop ebp 62 | ret 63 | 64 | ; ======================================================================== 65 | ; void disp_color_str(char * info, int color); 66 | ; ======================================================================== 67 | disp_color_str: 68 | push ebp 69 | mov ebp, esp 70 | 71 | mov esi, [ebp + 8] ; pszInfo 72 | mov edi, [disp_pos] 73 | mov ah, [ebp + 12] ; color 74 | .1: 75 | lodsb 76 | test al, al 77 | jz .2 78 | cmp al, 0Ah ; 是回车吗? 79 | jnz .3 80 | push eax 81 | mov eax, edi 82 | mov bl, 160 83 | div bl 84 | and eax, 0FFh 85 | inc eax 86 | mov bl, 160 87 | mul bl 88 | mov edi, eax 89 | pop eax 90 | jmp .1 91 | .3: 92 | mov [gs:edi], ax 93 | add edi, 2 94 | jmp .1 95 | 96 | .2: 97 | mov [disp_pos], edi 98 | 99 | pop ebp 100 | ret 101 | 102 | ; ======================================================================== 103 | ; void out_byte(u16 port, u8 value); 104 | ; ======================================================================== 105 | out_byte: 106 | mov edx, [esp + 4] ; port 107 | mov al, [esp + 4 + 4] ; value 108 | out dx, al 109 | nop ; 一点延迟 110 | nop 111 | ret 112 | 113 | ; ======================================================================== 114 | ; u8 in_byte(u16 port); 115 | ; ======================================================================== 116 | in_byte: 117 | mov edx, [esp + 4] ; port 118 | xor eax, eax 119 | in al, dx 120 | nop ; 一点延迟 121 | nop 122 | ret 123 | 124 | ; ======================================================================== 125 | ; void disable_irq(int irq); 126 | ; ======================================================================== 127 | ; Disable an interrupt request line by setting an 8259 bit. 128 | ; Equivalent code: 129 | ; if(irq < 8){ 130 | ; out_byte(INT_M_CTLMASK, in_byte(INT_M_CTLMASK) | (1 << irq)); 131 | ; } 132 | ; else{ 133 | ; out_byte(INT_S_CTLMASK, in_byte(INT_S_CTLMASK) | (1 << irq)); 134 | ; } 135 | disable_irq: 136 | mov ecx, [esp + 4] ; irq 137 | pushf 138 | cli 139 | mov ah, 1 140 | rol ah, cl ; ah = (1 << (irq % 8)) 141 | cmp cl, 8 142 | jae disable_8 ; disable irq >= 8 at the slave 8259 143 | disable_0: 144 | in al, INT_M_CTLMASK 145 | test al, ah 146 | jnz dis_already ; already disabled? 147 | or al, ah 148 | out INT_M_CTLMASK, al ; set bit at master 8259 149 | popf 150 | mov eax, 1 ; disabled by this function 151 | ret 152 | disable_8: 153 | in al, INT_S_CTLMASK 154 | test al, ah 155 | jnz dis_already ; already disabled? 156 | or al, ah 157 | out INT_S_CTLMASK, al ; set bit at slave 8259 158 | popf 159 | mov eax, 1 ; disabled by this function 160 | ret 161 | dis_already: 162 | popf 163 | xor eax, eax ; already disabled 164 | ret 165 | 166 | ; ======================================================================== 167 | ; void enable_irq(int irq); 168 | ; ======================================================================== 169 | ; Enable an interrupt request line by clearing an 8259 bit. 170 | ; Equivalent code: 171 | ; if(irq < 8){ 172 | ; out_byte(INT_M_CTLMASK, in_byte(INT_M_CTLMASK) & ~(1 << irq)); 173 | ; } 174 | ; else{ 175 | ; out_byte(INT_S_CTLMASK, in_byte(INT_S_CTLMASK) & ~(1 << irq)); 176 | ; } 177 | ; 178 | enable_irq: 179 | mov ecx, [esp + 4] ; irq 180 | pushf 181 | cli 182 | mov ah, ~1 183 | rol ah, cl ; ah = ~(1 << (irq % 8)) 184 | cmp cl, 8 185 | jae enable_8 ; enable irq >= 8 at the slave 8259 186 | enable_0: 187 | in al, INT_M_CTLMASK 188 | and al, ah 189 | out INT_M_CTLMASK, al ; clear bit at master 8259 190 | popf 191 | ret 192 | enable_8: 193 | in al, INT_S_CTLMASK 194 | and al, ah 195 | out INT_S_CTLMASK, al ; clear bit at slave 8259 196 | popf 197 | ret 198 | 199 | 200 | ; ======================================================================== 201 | ; void disable_int(); 202 | ; ======================================================================== 203 | disable_int: 204 | cli 205 | ret 206 | 207 | ; ======================================================================== 208 | ; void enable_int(); 209 | ; ======================================================================== 210 | enable_int: 211 | sti 212 | ret 213 | -------------------------------------------------------------------------------- /lab4/code/lib/string.asm: -------------------------------------------------------------------------------- 1 | 2 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 | ; string.asm 4 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 | ; Forrest Yu, 2005 6 | ; ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 | 8 | [SECTION .text] 9 | 10 | ; 导出函数 11 | global memcpy 12 | global memset 13 | global strcpy 14 | 15 | 16 | ; ------------------------------------------------------------------------ 17 | ; void* memcpy(void* es:p_dst, void* ds:p_src, int size); 18 | ; ------------------------------------------------------------------------ 19 | memcpy: 20 | push ebp 21 | mov ebp, esp 22 | 23 | push esi 24 | push edi 25 | push ecx 26 | 27 | mov edi, [ebp + 8] ; Destination 28 | mov esi, [ebp + 12] ; Source 29 | mov ecx, [ebp + 16] ; Counter 30 | .1: 31 | cmp ecx, 0 ; 判断计数器 32 | jz .2 ; 计数器为零时跳出 33 | 34 | mov al, [ds:esi] ; ┓ 35 | inc esi ; ┃ 36 | ; ┣ 逐字节移动 37 | mov byte [es:edi], al ; ┃ 38 | inc edi ; ┛ 39 | 40 | dec ecx ; 计数器减一 41 | jmp .1 ; 循环 42 | .2: 43 | mov eax, [ebp + 8] ; 返回值 44 | 45 | pop ecx 46 | pop edi 47 | pop esi 48 | mov esp, ebp 49 | pop ebp 50 | 51 | ret ; 函数结束,返回 52 | ; memcpy 结束------------------------------------------------------------- 53 | 54 | 55 | ; ------------------------------------------------------------------------ 56 | ; void memset(void* p_dst, char ch, int size); 57 | ; ------------------------------------------------------------------------ 58 | memset: 59 | push ebp 60 | mov ebp, esp 61 | 62 | push esi 63 | push edi 64 | push ecx 65 | 66 | mov edi, [ebp + 8] ; Destination 67 | mov edx, [ebp + 12] ; Char to be putted 68 | mov ecx, [ebp + 16] ; Counter 69 | .1: 70 | cmp ecx, 0 ; 判断计数器 71 | jz .2 ; 计数器为零时跳出 72 | 73 | mov byte [edi], dl ; ┓ 74 | inc edi ; ┛ 75 | 76 | dec ecx ; 计数器减一 77 | jmp .1 ; 循环 78 | .2: 79 | 80 | pop ecx 81 | pop edi 82 | pop esi 83 | mov esp, ebp 84 | pop ebp 85 | 86 | ret ; 函数结束,返回 87 | ; ------------------------------------------------------------------------ 88 | 89 | 90 | ; ------------------------------------------------------------------------ 91 | ; char* strcpy(char* p_dst, char* p_src); 92 | ; ------------------------------------------------------------------------ 93 | strcpy: 94 | push ebp 95 | mov ebp, esp 96 | 97 | mov esi, [ebp + 12] ; Source 98 | mov edi, [ebp + 8] ; Destination 99 | 100 | .1: 101 | mov al, [esi] ; ┓ 102 | inc esi ; ┃ 103 | ; ┣ 逐字节移动 104 | mov byte [edi], al ; ┃ 105 | inc edi ; ┛ 106 | 107 | cmp al, 0 ; 是否遇到 '\0' 108 | jnz .1 ; 没遇到就继续循环,遇到就结束 109 | 110 | mov eax, [ebp + 8] ; 返回值 111 | 112 | pop ebp 113 | ret ; 函数结束,返回 114 | ; strcpy 结束------------------------------------------------------------- 115 | 116 | 117 | -------------------------------------------------------------------------------- /lab4/实验要求/操作系统2021实验四要求.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/实验要求/操作系统2021实验四要求.pdf -------------------------------------------------------------------------------- /lab4/实验要求/操作系统2021实验四问题小结.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/实验要求/操作系统2021实验四问题小结.pdf -------------------------------------------------------------------------------- /lab4/截图/写优先.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/截图/写优先.png -------------------------------------------------------------------------------- /lab4/截图/读优先.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/截图/读优先.png -------------------------------------------------------------------------------- /lab4/截图/防饿死.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/截图/防饿死.png -------------------------------------------------------------------------------- /lab4/说明文档.md: -------------------------------------------------------------------------------- 1 | # 操作系统实验四说明文档 2 | 3 |
191850205 夏宇
4 | 5 | ## 添加系统调用实现进程休眠 6 | 7 | 在syscall.asm中添加如下代码 8 | 9 | ```nasm 10 | delay_milli_seconds: 11 | mov ebx, [esp + 4] ;ebx保存传过来的时间参数 12 | mov eax, _NR_delay_milli_seconds ;eax保存在系统调用函数表中的偏移量 13 | int INT_VECTOR_SYS_CALL ;调用系统调用 14 | ret 15 | ``` 16 | 17 | 在global.c的系统调用表中添加相应函数 18 | 19 | ```C 20 | PUBLIC system_call sys_call_table[NR_SYS_CALL] = {sys_get_ticks, sys_delay_milli_seconds, disp_str, sys_p, sys_v}; //系统调用的函数 21 | 22 | ``` 23 | 24 | 然后修改const.h中定义的系统调用数量,然后在proc.c中实现该系统调用函数 25 | 26 | ```C 27 | PUBLIC void sys_delay_milli_seconds(int milli_second) //todo 28 | { 29 | p_proc_ready->sleep_time = milli_second; //睡眠时间以tick为单位,一个tick就是对应的一个ms 30 | int index = find(); //把该进程移出可调度队列 31 | if (index != -1) 32 | { 33 | remove(index); 34 | } 35 | schedule(); 36 | restart(); 37 | } 38 | ``` 39 | 40 | 为了实现指定时间的休眠函数,我在进程结构体定义中添加了新的变量 ` int sleep_time;`,该变量记录了此进程需要休眠的时长,然后将此进程从就绪队列中移出,以保证此进程在休眠时间中不被调度。然后立即执行`schedule()`函数切换当前进程,接着执行`restart()`函数切换堆栈,实现进程的迁移。 41 | 42 | 为了实现进程的唤醒,我修改了clock.c中处理时钟中断的方法,在每次时钟中断发生时,检查所有进程,若有进程在休眠,则将其休眠时间片减一,如果休眠时间结束,则将其重新移入就绪队列 43 | 44 | ```C 45 | PUBLIC void clock_handler(int irq) 46 | { 47 | ticks++; 48 | /* p_proc_ready->ticks--; */ 49 | 50 | if (k_reenter != 0) 51 | { 52 | return; 53 | } 54 | 55 | for (int i = 0; i < NR_TASKS; i++) 56 | { 57 | if (proc_table[i].sleep_time > 0) 58 | { 59 | proc_table[i].sleep_time--; 60 | if (proc_table[i].sleep_time == 0) 61 | { 62 | //移入可调度队列 63 | push(proc_table[i].pid); 64 | } 65 | } 66 | } 67 | 68 | schedule(); 69 | } 70 | ``` 71 | 72 | 73 | 74 | ## 添加系统调用打印字符串 75 | 76 | 与上述添加系统调用方法一致。 77 | 78 | 在syscall.asm中添加系统调用 79 | 80 | ```nasm 81 | 82 | print_str: 83 | mov ebx, [esp + 4] 84 | mov eax, _NT_print_str 85 | int INT_VECTOR_SYS_CALL 86 | ret 87 | ``` 88 | 89 | 然后在global.c中的sys_call_table中添加系统调用函数 90 | 91 | 92 | 93 | ## 添加系统调用执行PV操作,并模拟实现读者写者问题 94 | 95 | ### 添加系统调用执行PV操作 96 | 97 | 定义信号量,其成员包括信号量的值,信号量队列的大小,信号量队列中排队的进程,还有一个是该信号量的名称,此名称是为了方便我debug使用的,实际运行中并不需要。 98 | 99 | ```C 100 | typedef struct semaphore 101 | { 102 | int value; 103 | int size; 104 | char name[32]; 105 | PROCESS *list[MAX_WAIT_PROCESS]; 106 | } SEMAPHORE; 107 | ``` 108 | 109 | 添加P、V操作的系统调用,与前面添加系统调用的方法一样,不再赘述 110 | 111 | #### P、V操作的实现 112 | 113 | 下面讲一下P、V操作的具体实现。 114 | 115 | 由于P、V操作都是原子性的,所以我将系统调用的P、V操作再次封装,在进入时关中断,在退出时开中断,以实现原子性的要求。 116 | 117 | ```C 118 | void atomicP(SEMAPHORE *s) 119 | { 120 | //disable_irq(CLOCK_IRQ); 121 | disable_int(); 122 | P(s); 123 | enable_int(); 124 | //enable_irq(CLOCK_IRQ); 125 | } 126 | 127 | void atomicV(SEMAPHORE *s) 128 | { 129 | //disable_irq(CLOCK_IRQ); 130 | disable_int(); 131 | V(s); 132 | enable_int(); 133 | //enable_irq(CLOCK_IRQ); 134 | } 135 | ``` 136 | 137 | P操作的具体实现。如果信号量足够则允许申请,否则执行`sleep()`函数,将当前进程从就绪队列中移出以保证当前进程不再被调度,然后执行`schedule()`和 `start()`方法切换进程。 138 | 139 | ```C 140 | PUBLIC void sys_p(SEMAPHORE *s) 141 | { 142 | s->value--; 143 | if (s->value < 0) 144 | { 145 | sleep(s); 146 | } 147 | } 148 | 149 | void sleep(SEMAPHORE *s) 150 | { 151 | //需要将当前的进程从可调度队列中移除 152 | int index = find(); //先找到当前进程在可调度队列中的下标,然后再删除当前进程 153 | if (index != -1) 154 | { 155 | remove(index); //todo 156 | } 157 | 158 | p_proc_ready->isWaiting = 1; 159 | s->list[s->size] = p_proc_ready; 160 | s->size++; 161 | 162 | schedule(); 163 | restart(); 164 | } 165 | ``` 166 | 167 | V操作的具体实现。首先释放信号量,然后唤醒等待此信号量的队首进程。 168 | 169 | ```C 170 | PUBLIC void sys_v(SEMAPHORE *s) 171 | { 172 | s->value++; 173 | if (s->value <= 0) 174 | { 175 | wakeup(s); 176 | } 177 | } 178 | 179 | void wakeup(SEMAPHORE *s) 180 | { 181 | if (s->size > 0) 182 | { 183 | push(s->list[0]->pid); //移入可调度队列 184 | 185 | s->list[0]->isWaiting = 0; //从当前信号量的等待队列中移出队首的等待进程 186 | for (int i = 0; i < s->size - 1; i++) 187 | { 188 | s->list[i] = s->list[i + 1]; 189 | } 190 | s->size--; 191 | } 192 | } 193 | 194 | 195 | ``` 196 | 197 | ### 模拟实现读者写者问题 198 | 199 | #### 添加进程 200 | 201 | ```C 202 | PUBLIC TASK task_table[NR_TASKS] = {{ReadA, STACK_SIZE_ReadA, "ReadA"}, 203 | {ReadB, STACK_SIZE_ReadB, "ReadB"}, 204 | {ReadC, STACK_SIZE_ReadC, "ReadC"}, 205 | {WriteD, STACK_SIZE_WriteD, "WriteD"}, 206 | {WriteE, STACK_SIZE_WriteE, "WriteE"}, 207 | {F, STACK_SZIE_F, "F"}}; //用户进程 208 | ``` 209 | 210 | #### 读优先的实现 211 | 212 | 读者优先饿死问题的解决在后续介绍 `schedule()`函数时说明 213 | 214 | 读操作 215 | 216 | ```C 217 | atomicP(&rmutex); 218 | if (readCount == 0) 219 | { 220 | 221 | atomicP(&rw_mutex); //有进程在读的时候不让其它进程写 222 | } 223 | readCount++; 224 | atomicV(&rmutex); 225 | 226 | atomicP(&nr_readers); 227 | disp_read_start(); 228 | 229 | //读操作消耗的时间片 230 | //milli_delay(slices * TIMESLICE); 231 | for (int i = 0; i < slices; i++) 232 | { 233 | disp_reading(); 234 | milli_delay(TIMESLICE); 235 | } 236 | 237 | disp_read_end(); 238 | atomicV(&nr_readers); 239 | 240 | atomicP(&rmutex); 241 | readCount--; 242 | if (readCount == 0) 243 | { 244 | atomicV(&rw_mutex); 245 | } 246 | atomicV(&rmutex); 247 | ``` 248 | 249 | 写操作 250 | 251 | ```C 252 | //读者优先 253 | atomicP(&rw_mutex); 254 | writeCount++; 255 | disp_write_start(); 256 | //milli_delay(slices * TIMESLICE); 257 | for (int i = 0; i < slices; i++) 258 | { 259 | disp_writing(); 260 | milli_delay(TIMESLICE); 261 | } 262 | disp_write_end(); 263 | writeCount--; 264 | atomicV(&rw_mutex); 265 | ``` 266 | 267 | #### 写者优先的实现 268 | 269 | 写者优先饿死问题的解决在后续介绍 `schedule()`函数时说明 270 | 271 | 读操作 272 | 273 | ```C 274 | //P(&queue); //增加queue信号量是为了防止r上有长队列,因为如果r上有长队列的话,如果有写进程,那么写进程要排很久的队 275 | P(&r); 276 | P(&rmutex); 277 | if (readCount == 0) 278 | { 279 | P(&w); 280 | } 281 | readCount++; 282 | V(&rmutex); 283 | V(&r); 284 | //V(&queue); 285 | 286 | atomicP(&nr_readers); 287 | disp_read_start(); 288 | 289 | //读操作消耗的时间片 290 | //milli_delay(slices * TIMESLICE); 291 | for (int i = 0; i < slices; i++) 292 | { 293 | disp_reading(); 294 | milli_delay(TIMESLICE); 295 | } 296 | 297 | disp_read_end(); 298 | atomicV(&nr_readers); 299 | 300 | atomicP(&rmutex); 301 | readCount--; 302 | if (readCount == 0) 303 | { 304 | atomicV(&w); 305 | } 306 | atomicV(&rmutex); 307 | ``` 308 | 309 | 写操作 310 | 311 | ```C 312 | P(&wmutex); 313 | if (writeCount == 0) 314 | { 315 | P(&r); //申请r锁 316 | } 317 | writeCount++; 318 | V(&wmutex); 319 | 320 | P(&w); 321 | disp_write_start(); 322 | //milli_delay(slices * TIMESLICE); 323 | for (int i = 0; i < slices; i++) 324 | { 325 | disp_writing(); 326 | milli_delay(TIMESLICE); 327 | } 328 | disp_write_end(); 329 | V(&w); 330 | 331 | P(&wmutex); 332 | writeCount--; 333 | if (writeCount == 0) 334 | { 335 | V(&r); 336 | } 337 | V(&wmutex); 338 | ``` 339 | 340 | #### F进程 341 | 342 | F进程是一个特殊的进程,它负责打印其余进程的运行,具体在 `schedule()`函数中说明。 343 | 344 | 345 | 346 | ### schedule()函数 347 | 348 | ```c 349 | PUBLIC void schedule() 350 | { 351 | if (ticks - lastTicks >= 100) 352 | { 353 | lastTicks = ticks; 354 | p_proc_ready = proc_table + NR_TASKS - 1; //选中F进程 355 | isBlockedF = 0; 356 | return; 357 | } 358 | 359 | PROCESS *p; 360 | 361 | if (schedulable_queue_size == 0) 362 | { 363 | disp_str("no process is schedulable\n"); 364 | } 365 | else 366 | { 367 | if (!numOfNotWorked()) 368 | { 369 | reWork(); 370 | } 371 | 372 | do 373 | { 374 | int process = schedulable_queue[0]; 375 | p_proc_ready = proc_table + process; 376 | remove(0); //删除 377 | push(process); //移到队末 378 | } while (p_proc_ready->hasWorked == 1); 379 | } 380 | } 381 | ``` 382 | 383 | 首先是F进程,对于F进程的调度,我特殊处理,检查上次调度F进程的时间与当前时间的差值,如果超过预设值,则强制将F进程设为运行态,并更新F进程的调度时间。 384 | 385 | 其次是读写优先防止饿死,我为每一个进程添加了一个变量 `int hasWorked;`来标识此进程是否在本轮调度中执行过,如果已经执行过,则不再给此进程分配时间片,一轮结束后,清空此变量,重新恢复调度。因为读写饿死问题是因为读者反复请求读,写者反复请求写,导致读优先写进程无法进入,写优先读进程无法进入,保证每个进程每轮调度一次即可解决该问题。 -------------------------------------------------------------------------------- /lab4/说明文档.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rain-xyy/OSLAB-NJUSE/89995df1d43121145e7570c223a834295e27ceeb/lab4/说明文档.pdf --------------------------------------------------------------------------------