深入理解计算机系统 Number1

(1)  The source program is a sequence of bits, each with a value of 0 or 1, organized in 8-bit chunks called bytes. Each byte represents some text character in the program.

(2) Most modern systems represent text characters using the ASCII standard that represents each character with a unique byte-sized integer value,and .c program is stored in a file as a sequence of bytes. Each byte has an integer value that corresponds to some character.

(3) All information in a system — including disk files, programs stored in memory, user data stored in memory, and data transferred across a network— is represented as a bunch of bits. The only thing that distinguishes different data objects is the context in which we view them. For example, in different contexts, the same sequence of bytes might represent an integer, floating point number, character string, or machine instruction.

(4) the individual C statements must be translated by other programs into a sequence of low-level machine-language instructions. These instructions are then packaged in a form called an executable object program, and stored as a binary disk file. Object programs are also referred to as executable object files.

(5)The programs that perform the four phases ( preprocessor, compiler, assembler, and linker) are known collectively as the compilation system.

                                          

Preprocessing phase. The preprocessor (cpp)modifies the original C program according to directives that begin with the # character.

Compilation phase. The compiler (cc1) translates the text file hello.i into the text file hello.s, which contains an assembly-language program.

Assembly phase. the assembler (as) translates hello.s into machine-language instructions,packages them in a form known as a relocatable object program, and stores the result in the object file hello.o. The hello.o file is a binary file whose bytes encode machine language instructions rather than characters.

Linking phase. Notice that our hello program calls the printf function, which is part of the standard C library provided by every C compiler.The printf function resides in a separate precompiled object file called printf.o, which must somehow be merged with our hello.o program.Thelinker (ld) handles this merging.

(6) Hardware Organization of a System

                                        

Buses: Running throughout the system is a collection of electrical conduits called buses that carry bytes of information back and forth between the components.

I/O devices: Input/output (I/O) devices are the system’s connection to the external world.

Each I/O device is connected to the I/O bus by either a controller or an adapter. The distinction between the two is mainly one of packaging. Controllers are chip sets in the device itself or on the system’s main printed circuit board (often called the motherboard). An adapter is a card that plugs into a slot on the motherboard.Regardless, the purpose of each is to transfer information back and forth between the I/O bus and an I/O device.

Main memory: The main memory is a temporary storage device that holds both a program and the data it manipulates while the processor is executing the program. Physically, main memory consists of a collection of Dynamic Random Access Memory (DRAM) chips. Logically, memory is organized as a linear array of bytes, each
with its own unique address (array index) starting at zero.

In general, each of the machine instructions that constitute a program can consist of a variable number of bytes. The sizes of data items that correspond to C program variables vary according to type. For example, on an Intel machine running Linux, data of type short requires two bytes, types int, float, and long four bytes, and type double eight bytes.

Processor: The central processing unit (CPU), or simply processor, is the engine that interprets (or executes) instructions stored in main memory. At its core is a word-sized storage device (or register) called the program counter (PC). At any point in time, the PC points at (contains the address of) some machine-language instruction in main memory

From the time that power is applied to the system, until the time that the power is shut off, the processor blindly and repeatedly performs the same basic task, over and over and over: It reads the instruction from memory pointed at by the program counter (PC), interprets the bits in the instruction, performs some simple operation dictated by the instruction, and then updates the PC to point to the next instruction, which may or may not be contiguous in memory to the instruction that was just executed.

There are only a few of these simple operations, and they revolve around main memory, the register file, and the arithmetic/logic unit (ALU). The register file is a small storage device that consists of a collection of word-sized registers, each with its own unique name. The ALU computes new data and address values.

Here are some examples of the simple operations that the CPU might carry out at the request of an instruction:

Load: Copy a byte or a word from main memory into a register, overwriting the previous contents of the register.

Store: Copy the a byte or a word from a register to a location in main memory, overwriting the previous contents of that location.

Update: Copy the contents of two registers to the ALU, which adds the two words together and stores the result in a register, overwriting the previous contents of that register.

I/O Read: Copy a byte or a word from an I/O device into a register.

I/O Write: Copy a byte or a word from a register to an I/O device.

Jump: Extract a word from the instruction itself and copy that word into the program counter (PC),overwriting the previous value of the PC.

(7)Running a Program

   Step 1   we type the characters hello at the keyboard, the shell program reads each one into a register, and then stores it in memory

 

                                    

   step2:  When we hit the enter key on the keyboard, the shell knows that we have finished typing the command.The shell then loads the executable hello file by executing a sequence of instructions that copies the code and data in the hello object file from disk to main memory.

                                      

  Step3: Once the code and data in the hello object file are loaded into memory, the processor begins executing the machine-language instructions in the hello program’s main routine. These instruction copy the bytes in the ”hello, world\n” string from memory to the register file, and from there to the display device,
where they are displayed on the screen.

                                          

(8)Caches Matter

physical laws: larger storage devices are slower than smaller storage devices. And faster devices are more expensive to build than their slower counterparts.

To deal with the processor-memory gap, system designers include smaller faster storage devices called caches that serve as temporary staging areas for information that the processor is likely to need in the near future.

                                     

 An L1 cache on the processor chip holds tens of thousands of bytes and can be accessed nearly as fast as the register file. A larger L2 cache with hundreds of thousands to millions of bytes is connected to the processor by a special bus. It might take 5 times longer for the process to access the L2 cache than the L1 cache, but this is still 5 to 10 times faster than accessing the main memory. The L1 and L2 caches are implemented with a hardware technology known as Static Random Access Memory (SRAM).

(9)Storage Devices Form a Hierarchy

                                                      

(10)The Operating System Manages the Hardware

operating system as a layer of software interposed between the application program and the hardware,All attempts by an application program to manipulate the hardware must go through the operating system.

                                               

The operating system has two primary purposes: (1) To protect the hardware from misuse by runaway applications,  (2) To provide applications with simple and uniform mechanisms for manipulating complicated and often wildly different low-level hardware devices.

The operating system achieves both goals via the fundamental abstractions:processes, virtual memory, and files.

                                                         

files are abstractions for I/O devices. Virtual memory is an abstraction for both the main memory and disk I/O devices. And processes are abstractions for the processor, main memory, and I/O devices.

Processes:When a program such as hello runs on a modern system, the operating system provides the illusion that the program is the only one running on the system. The program appears to have exclusive use of both the processor, main memory, and I/O devices. The processor appears to execute the instructions in the program,one after the other, without interruption. And the code and data of the program appear to be the only objects in the system’s memory.

A process is the operating system’s abstraction for a running program.

Threads: In modern system a process can actually consist of multiple execution units, called threads, each running in the context of the process and sharing the same code and global data.

Virtual Memory:Virtual memory is an abstraction that provides each process with the illusion that it has exclusive use of the main memory.

 Each process has the same uniform view of memory, which is known as its virtual address space.

                                                            

                                   

                                                                                     process virtual address space

the topmost 1/4 of the address space is reserved for code and data in the operating system that is common to all processes. The bottommost 3/4 of the address space holds the code and data defined by the user’s process. Note that addresses in the figure increase from bottom to the top.

Program code and data. Code begins at the same fixed address, followed by data locations that correspond to global C variables. The code and data areas are initialized directly from the contents of an executable object file.

Heap. The code and data areas are followed immediately by the run-time heap. Unlike the code and data areas, which are fixed in size once the process begins running, the heap expands and contracts dynamically at runtime as a result of calls to C standard library routines

Shared libraries. Near the middle of the address space is an area that holds the code and data for shared libraries such as the C standard library and the math library.

Stack. At the top of the user’s virtual address space is the user stack that the compiler uses to implement function calls. Like the heap, the user stack expands and contracts dynamically during the execution of the program. In particular, each time we call a function, the stack grows. Each time we return from a function, it contracts.

Kernel virtual memory. The kernel is the part of the operating system that is always resident in memory. The top 1/4 of the address space is reserved for the kernel. Application programs are not allowed to read or write the contents of this area or to directly call functions defined in the kernel code.

For virtual memory to work, a sophisticated interaction is required between the hardware and the operating system software, including a hardware translation of every address generated by the processor. The basic idea is to store the contents of a process’s virtual memory on disk, and then use the main memory as a cache for the disk.

Files:A Unix file is a sequence of bytes, nothing more and nothing less. Every I/O device, including disks,keyboards, displays, and even networks, is modeled as a file. All input and output in the system is performed by reading and writing files, using a set of operating system functions known as system calls.

(11)Systems CommunicateWith Other Systems Using Networks

When the system copies a sequence of bytes from mainmemory to the network adapter, the data flows across the network to another machine, instead of say, to a local disk drive. Similarly, the system can read data sent from other machines and copy this data to its main memory.

                                   

we type the ”hello” string to the telnet client and hit the enter key, the client sends the string to the telnet server. After the telnet server receives the string from the network, it passes it along to the remote shell program. Next, the remote shell runs the hello program, and passes the output line back to the telnet server. Finally, the telnet server forwards the output string across the network to the telnet client, which prints the output string on our local terminal.

                                          

(12)Summary

An important idea to take away from this discussion is that a system is more than just hardware. It is a collection of intertwined hardware and software components
that must work cooperate in order to achieve the ultimate goal of running application programs.

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值