Computer Hardware Notes

Introduction to OS

  • MMU: This scheme requires re- mapping memory addresses on the fly to convert the address the program gener- ated to the physical address in RAM where the word is located. This mapping is done by a part of the CPU called the MMU (Memory Management Unit), as shown in Fig. 1-6.
  • The latter is needed so that any SATA disk controller can handle any SATA disk, for example. SATA stands for Serial ATA and ATA in turn stands for AT Attachment. In case you are curious what AT stands for, this was IBM’s second generation ‘‘Personal Computer Advanced Technology’’ built around the then-extremely-potent 6-MHz 80286 processor that the company introduced in 1984.
  • The software that talks to a controller, giving it commands and accepting responses, is called a device driver.
  • Drivers usually run in Kernel mode: There are three ways the driver can be put into the kernel. The first way is to relink the kernel with the new driver and then reboot the system. Many older UNIX systems work like this. The second way is to make an entry in an operating system file telling it that it needs the driver and then reboot the system. At boot time, the operating system goes and finds the drivers it needs and loads them. Windows works this way. The third way is for the operating system to be able to accept new drivers while running and install them on the fly without the need to reboot. This way used to be rare but is becoming much more common now. Hot-pluggable devices, such as USB and IEEE 1394 devices (discussed below), always need dy- namically loaded drivers.
  • OS I/O, 1,Polling, 2, Interupt, 3, DMA
  • The main bus is the PCIe (Peripheral Component Interconnect Express) bus:The PCIe bus was invented by Intel as a successor to the older PCI bus, which in turn was a replacement for the original ISA (Industry Standard Architecture) bus. Capable of transferring tens of gigabits per second, PCIe is much faster than its predecessors.
  • PCI is serial, PCIe is packet based
  • DMI (Direct Media Interface) bus.
  • The USB (Universal Serial Bus) was invented to attach all the slow I/O de- vices, such as the keyboard and mouse, to the computer. However, calling a mod- ern USB 3.0 device humming along at 5 Gbps ‘‘slow’’ may not come naturally for the generation that grew up with 8-Mbps ISA as the main bus in the first IBM PCs. (PCIe 64gigabits)
  • USB 有接地和供电功能.


  • A key concept in all operating systems is the process. A process is basically a program in execution. Associated with each process is its address space, a list of memory locations from 0 to some maximum, which the process can read and write.
  • In many operating systems, all the information about each process, other than the contents of its own address space, is stored in an oper- ating system table called the process table, which is an array of structures, one for each process currently in existence. –每个process有个header pointer
  • alarm signal sent by cpu to process, and suspend process
  • UID for users, GID for groups. Parent and children processes share same UID
  • Superuser is one UID

Address Space


  • The last feature we will discuss in this overview relates to both processes and files: pipes. A pipe is a sort of pseudofile that can be used to connect two proc- esses

Security and Protection

  • rwx permissions


  • prompt
  • date > file (put output to file)
  • sort <file1 >file2 (invokes the sort program with input taken from file1 and output sent to file2)
  • cat file1 file2 file3 | sort >/dev/lp (invokes the cat program to concatenate three files and send the output to sort to arrange all the lines in alphabetical order. The output of sort is redirected to the file /dev/lp, typically the printer.)
  • cat file1 file2 file3 | sort >/dev/lp & (sort and do it in background)

System Calls

  • os two funs: Providing abstractions to user programs and managing computer’s resources
  • system call : count = read(fd, buffer, nbytes);
  • image
  • POSIX is an international standard, but issuing an system call is still machine dependent. POSIX has about 100 procedure calls. To a large extent, the services offered by these calls determine most of what the operating system has to do, since the resource management on personal com- puters is minimal (at least compared to big machines with multiple users).
  • TRAP instruction is to switch from user mode to kernel mode and start execution at a fixed address within the kernel.
  • A system call : trapping into kernel.
  • Processes Management:
    • Fork : the only way to create a new process in POSIX
    • All the variables have identical val- ues at the time of the fork, but since the parent’s data are copied to create the child, subsequent changes in one of them do not affect the other one. (The program text, which is unchangeable, is shared between parent and child.) The fork call returns a value, which is zero in the child and equal to the child’s PID (Process IDentifier) in the parent. Using the returned PID, the two processes can see which one is the parent process and which one is the child process.
    • folk 到哪行呼叫的,哪行分叉
    • To wait for the child to finish, the parent executes a waitpid system call, which just waits until the child terminates (any child if more than one exists).
    • image
    • execve has three parameters: the name of the file to be executed, a pointer to the argument array, and a pointer to the environment array.
    • exit, has one parameter, exit status 0-255 which is returned to parent via statloc in the waitpid system call.
    • Processes in UNIX have their memory divided up into three segments: the text segment (i.e., the program code), the data segment (i.e., the variables), and the stack segment.
    • brk specifies the new address where the data segment is to end. brk is not POSIX, programmers use malloc
  • File Management:
    • To create a new file, the O_CREAT parameter is used.
    • Files must close, otherwise can’t reuse subsequent open
    • The lseek call changes the value of the position pointer, so that subsequent calls to read or write can begin anywhere in the file.(position pointer needed for files)
    • Lseek has three parameters: the first is the file descriptor for the file, the sec- ond is a file position, and the third tells whether the file position is relative to the beginning of the file, the current position, or the end of the file. The value returned by lseek is the absolute position in the file (in bytes) after changing the pointer.
    • stat: see file mode, size, time of modification, and other info of a file.
  • Directory Management:
    • The first two calls, mkdir and rmdir, create and remove empty directories, respectively. (rm -rf)
    • link : 对某个文件建立索引,并事实转移,windows里没有这个功能, vista之后才支持
    • the mount system call allows two file systems to be merged into one.
  • Others:
    • chdir("/usr/ast/test");== cd
    • chmod("file", 0644);
  • Windows:
    • Win32 API (Application Programming Interface) that programmers are expected to use to get operating system services.
    • Windows: C++, kernel is in C
      Mac: Objective C, kernel is in C (IO PnP subsystem is Embedded C++)
      Linux: Most things are in C, many userland apps are in Python, KDE is all C++
    • As a consequence, with Windows it is impossible to see what is a system call (i.e., performed by the kernel) and what is simply a user-space library call. (in fact, what is a system call in one version of Windows may be done in user space in a different version, and vice versa. )
    • CreateProcess creates a new process. It does the combined work of fork and execve in UNIX. It has many parameters specifying the properties of the newly created process. Windows does not have a process hierarchy as UNIX does so there is no concept of a parent proc- ess and a child process. After a process is created, the creator and createe are equals. WaitForSingleObject is used to wait for an event. Many possible events can be waited for. If the parameter specifies a process, then the caller waits for the specified process to exit, which is done using ExitProcess.
    • image

Operating System Structure

  • The six designs of structures we will discuss here are monolithic systems, layered systems, microkernels, cli- ent-server systems, virtual machines, and exokernels.
  • Monolithic: the whole OS runs as a single program in kernel mode
    • no information hiding, every procedure is visible to other procedures
    • This organization suggests a basic structure for the operating system:
      • 1: A main program that invokes the requested service procedure.
      • 2: A set of service procedures that carry out the system calls.
      • 3: A set of utility procedures that help the service procedures.
  • OS: Linux, Unix are both monolithic kernel.
  • Layered Systems:
    • the THE system, a Dutch computer, 32K of 27-bit words, a batch time system too.
    • 有六个层级
    • Multics系统是better generalization of this layering concept (in MULTICS, the ring mechanism was very much present at run time and enforced by the hardware)
  • Microkernels
    • after layered approach, designers have a choice where to draw the kernel-user boundary.
    • Kernel should be small, user process can have less power so bugs are not fatal
    • on avg, 10 bugs/ 1000s lines of codes
    • kernel and user-space seperate will be good, since each bug crashs a component not os
    • common OSs do not use microkernels except OS X, most are real-time industrial, avionics. Others include SYmbian, MINIX3. MINIX3 breaks most of os into independent modules.
    • MINIX3 is a microkernel that is 12,000 lines of C and some 1400 lines of assembler. unlike monolithic design, a buggy audio driver can’t write on disk. Drivers run on user-space
    • on top drivers is user-mode layer containing the servers which do most of work of an os. User programs obtain OS services by sendnig short messages to the servers asking for the POSIX system calls.
    • Reincarnation server: to check if other servers and drivers are functioning correctly.
    • MACH is microkernel.

      MAC X and Windows are hybrid kernel, which is more closely related with monolithic kernel.

Monolithic kernel

All the parts of a kernel like the Scheduler, File System, Memory Management, Networking Stacks, Device Drivers, etc., are maintained in one unit within the kernel in Monolithic Kernel


  • Faster processing


  • Crash Insecure
  • Porting Inflexibility
  • Kernel Size explosion


  • MS-DOS, Unix, Linux

Micro kernel

Only the very important parts like IPC(Inter process Communication), basic scheduler, basic memory handling, basic I/O primitives etc., are put into the kernel. Communication happen via message passing. Others are maintained as server processes in User Space


-Crash Resistant

  • Portable
  • Smaller Size


  • Slower Processing due to additional Message Passing

Examples •Windows NT

  • Server-client systems
  • VM
    • These components are loaded on demand. In UNIX they are called shared libraries. In Windows they are called DLLs (Dynamic-Link Libraries). They have file extension .dll and the C:\Windows\system32 directory on Windows systems has well over 1000 of them.