CSAPP学习笔记-第一章 A Tour of Computer Systems

185 阅读1分钟

1.1

信息都是由bits和context组成的

1.2

image.png 从程序员写的C程序到可执行文件需要经过以下四个步骤(以hello.c文件为例):

1 Preprocessing phase

预处理器(cpp)根据'#'标记引入其他文件的内容,生成hello.i文件

2 Compilation phase

将hello.i编译成汇编文件hello.s

3 Assembly phase

将hello.s转换为机器语言指令,存到hello.o

4 Linking phase

将系统内容方法合入hello.o,生成可执行文件hello

1.4 Hardware Organization

image.png

1

  • Buses: 电子导管
  • word sizes:跟随机器变化,32位机器为4bytes,64位机器为8bytes
  • I/O devices
  • Main Memory: 一般为DRAM(dynamic random access memory)
  • CPU: PC用于指向某条main memory的指令,register file是放置指令的存储设备,ALU(arithmetic/logic unit)是计算单元,计算新数据和地址
    • Load: 从main memory copy a byte or word到register,覆盖之前的值
    • Store: 从register copy a byte or word到main memory,覆盖之前的值
    • Operate: copy两个register到ALU,执行逻辑运算,然后存储到register,覆盖之前的值
    • Jump: 从指令本身抽出一个word,copy到PC,覆盖之前的值(我理解是复制地址,跳到合适的位置)
  • 执行hello的过程 image.png image.png image.png

1.5 缓存

image.png image.png

1.7 Operating System

解决两个问题:

  • 防止硬件被应用程序误用
  • 提供简单统一的机制来处理复杂的、不同的硬件 image.png context switch: 进程间切换,context含有PC、register和main memory等信息 image.png

以hello执行为例:

  • shell独自运行,等待输入
  • 用户输入后,shell执行系统调用将控制权交给OS
  • OS保存shell上下文,创建一个hello进程,然后把控制权交给hello进程
  • hello进程执行完成后,OS恢复shell上下文,把控制权交给shell进程

虚拟内存 image.png