【操作系统】 Operation System 第二章:操作系统基础操作

2.1 操作系统的启动

(1)CPU, I/O, 内存通过总线连接。
(2)DISK:存放OS;
BIOS:基本I/O处理系统( basic I/O system); Bootloader: 加载OS到内存中。
(3)当电脑通电时,段寄存器CS和指令寄存器IP能够确定一个内存地址,例如CS:IP = 0xf000:fff0.
(4)POST(加电自检),寻找显卡和执行BIOS。(显示器,键盘…是否正常)。
(5)步骤:
-BIOS: 将Bootloader从磁盘的磁盘的引导扇区(512字节)加载到0x7c00;跳转到CS:IP=0000:7c00的内存区域(以便下一步)
-Bootloader:将操作系统的代码和数据从硬盘加载到内存中;跳转到操作系统的起始地址。
在这里插入图片描述
(6)系统调用:(来源于应用程序)应用程序主动向操作系统发出服务请求。
(7)异常:(来源于不良的应用程序)非法指令或其它花的处理状态(e.g.内存出错)。
(8)中断:(来源于外设)来自不同的硬件设备的计时器和网络的中断。

(9)为什么应用程序不能直接访问硬件而是通过操作系统?
-计算机运行时,内核是被信任的第三方。
-只有内核可以执行特权指令。
-为了方便应用程序。

(10)讨论的问题:操作系统如何设计和实现中断/异常和系统调用;他们三者的区别和特点。

(11)产生的源头
-中断:外设(键盘/鼠标/网卡/声卡/显卡,可以产生各种事件)
-异常:应用程序意想不到的行为(e.g.异常,恶意程序,应用程序需要的资源未得到满足)
-系统调用(system call):应用程序请求操作提供服务(e.g.打开/关闭/读写文件,发送网络包)

(12)处理时间
-中断:异步;
-异常:同步;
-系统调用:同步或异步。

(13)响应
-中断:持续,对用户应用程序时透明的
-异常:杀死或者重新执行意想不到的应用程序指令
-系统调用:等待和持续

2.2 中断/异常和系统调用

(1)中断/异常处理机制
中断是外设的事件,异常是CPU的事件;中断/异常迫使CPU访问一些被中断和异常服务访问的功能。

(2)中断处理机制
硬件:设置中断标记(CPU初始化)
-将内部/外部事件设置中断标记;
-中断事件的ID(程序访问的中断向量地址)
软件(操作系统):
-保存当前处理状态
-中断服务程序处理
-清除中断标记
-恢复之前保存的处理状态

(3)异常处理机制
异常:异常编号
-保存现场
-异常处理:杀死产生异常的程序;重新执行异常指令
-恢复现场

(4)系统调用
-一条指令会触发一个系统调用

-程序访问主要是通过高层次的API接口而不是直接进行系统调用。

-通常情况下,存在与每个系统调用相关的序号,系统调用接口根据这些序号来维护表的索引。
-系统调用接口调用内核态中预期的系统调用,并返回系统调用的状态和其它任何返回值。
-用户不需要知道系统调用是如何实现的,只需要获取API和了解操作新系统将什么作为返回结果。操作系统接口的细节大部分都隐藏在API中,并通过运行程序支持的库来管理。

-用户态:应用程序在执行的过程中,CPU执行的特权级的状态(很低,不能访问特殊机器指令和IO)。
-内核态:应用程序在执行的过程中,CPU执行的特权级的状态(高,操作系统可以执行CPU任何一条指令)。
-系统调用时涉及到特权级从用户态到内核态的转换,应用程序和操作系统有各自的堆栈,这两个变化比函数调用的开销更大,但更安全和可靠。(而程序调用是在一个栈空间实现参数的调用和返回)。

(4)跨越操作系统边界的开销
-在执行时间上超过程序调用
-开销包括:
建立中断/异常/系统调用号与对应服务例程映射关系的初始化开销;
建立内核堆栈(操作系统和应用程序的堆栈不一样);
验证参数(操作系统会检查数据);
内核态映射到用户态的地址空间,更新页面映射权限(内存拷贝开销);
内核态独立地址空间TLB。

参考资料
https://www.bilibili.com/video/av6538245?from=search&seid=436175425155932048

  • 37
    点赞
  • 66
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
A modern computer system consists of one or more processors, some main memory, disks, printers, a keyboard, a display, network interfaces, and other input/output devices. All in all, a complex system. Writing programs that keep track of all these components and use them correctly, let alone optimally, is an extremely difficult job. For this reason, computers are equipped with a layer of software called the operating system, whose job is to manage all these devices and provide user programs with a simpler interface to the hardware. These systems are the subject of this book. The placement of the operating system is shown in Fig. 1-1. At the bottom is the hardware, which, in many cases, is itself composed of two or more levels (or layers). The lowest level contains physical devices, consisting of integrated circuit chips, wires, power supplies, cathode ray tubes, and similar physical devices. How these are constructed and how they work are the provinces of the electrical engineer. Next comes the microarchitecture level, in which the physical devices are grouped together to form functional units. Typically this level contains some registers internal to the CPU (Central Processing Unit) and a data path containing an arithmetic logic unit. In each clock cycle, one or two operands are fetched from the registers and combined in the arithmetic logic unit (for example, by addition or Boolean AND). The result is stored in one or more registers. On some machines, the operation of the data path is controlled by software, called the microprogram. On other machines, it is controlled directly by hardware circuits.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值