一、总论
1.1 软硬件分工
首先先明确,异常处理流是一个需要软硬件协作的流程。如果仅仅掌握了计组的知识,是没有办法对于异常处理流有一个很好的认识的。但是如果掌握了操作系统知识,而没有掌握计组知识,则不会有任何的实现负担。这是因为在 CPU 层面已经将异常处理流的硬件部分封装起来了(整个封装过程就是 P7,可以看到 P7 还是很难的),我们只要了解一下 CPU 提供给操作系统的接口,就可以利用这些接口提供的信息和功能完成异常处理流的软件部分。这是完全没有问题的。
我们有如下示意图:
Just like the picture on this PowerPoint, today we are going to tell a romantic love story, the main characters of the story are Wallis (that is, the lady on the left side of the picture) and Edward (that is, the gentleman on the right side of the picture). Interestingly, even their initials together are the romantic “WE”. But believe me, their story is far more legendary than the coincidence of names.
I believe that we have more or less seen Qiong Yao’s novels or idol dramas, in which the heroes are very outstanding, they can give more than 100,000 dollars of money to the girl of their choice.They often talk about sending the Eiffel Tower and large square feet of the building.
为了不让读者懵逼(主要是我自己也懵逼),所以特地整理一下在后面会用到术语。
我们电脑上有个东西叫做内存,他的大小比较小,像我的电脑就是 16 GB 的。它是由 ROM 和 RAM 组成的(“组成”可能不太严谨)。他也被叫做主存,我们为了访问他,所以需要给他的存储空间进行编号,这种编号被叫做物理地址。
我们电脑上还有个东西叫做外存,他的大小比较大,像我的电脑是 256 GB的。它可以是磁盘,也可以是固态硬盘,还可以是 U 盘。我们访问它,也是需要对它的存储空间进行编号的,拿磁盘举例,我们一般用“分区-扇区”的系统来描述我们在访问磁盘的哪个区域。总之它是一个不在这一章重点讲的东西。
这是 types.h
文件,主要是给一些基本的数据类型起一个简单一点的别名。
/* $OpenBSD: types.h,v 1.12 1997/11/30 18:50:18 millert Exp $ */
/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
#ifndef _INC_TYPES_H_
#define _INC_TYPES_H_
#ifndef NULL
#define NULL ((void *) 0)
#endif /* !NULL */
typedef unsigned char u_int8_t;
typedef short int16_t;
typedef unsigned short u_int16_t;
typedef int int32_t;
typedef unsigned int u_int32_t;
typedef long long int64_t;
typedef unsigned long long u_int64_t;
typedef int32_t register_t;
typedef unsigned char u_char;
typedef unsigned short u_short;
typedef unsigned int u_int;
typedef unsigned long u_long;
typedef u_int64_t u_quad_t; /* quads */
typedef int64_t quad_t;
typedef quad_t * qaddr_t;
#define MIN(_a, _b) \
({ \
typeof(_a) __a = (_a); \
typeof(_b) __b = (_b); \
__a <= __b ? __a : __b; \
})
/* Static assert, for compile-time assertion checking */
#define static_assert(c) switch (c) case 0: case(c):
#define offsetof(type, member) ((size_t)(&((type *)0)->member))
/* Rounding; only works for n = power of two */
#define ROUND(a, n) (((((u_long)(a))+(n)-1)) & ~((n)-1))
#define ROUNDDOWN(a, n) (((u_long)(a)) & ~((n)-1))
#endif /* !_INC_TYPES_H_ */