Lecture Notes for 4/9 Q: What was the point of this lecture? A: To see the distinction between the privilege level of the operating system, and the privilege level of users. Q: What was the point of last lecture? A: To see the relation between (cruddy) hardware and software. Lecture Topic: Memory virtualization, service spawning, & (a peek at) multiple processes Memory is split between the user side, and the system side. A program's address space is a subset of main memory. If a program in the user side tries to access memory outside of the user side an error is generated (specifically, a segment violation). This is because if a program was allowed to access memory on the system side it could do malicious things. It could tamper with or kill other processes, crash the OS, or any number of other nasty things. The operating systems memory space covers all of memory, system, and user side. Like memory, instructions are split as well. The two types of instructions are: - User instructions (unprivileged instructions, add, mult, divide) - System Instructions (privileged instructions, halt, handle interrupt, handle exception) On the CPU (in the "other stuff" section) there is the privilege bit. When it is set to 1 all instructions are allowed, and when set to 0, privileged instructions are not allowed. To tell the difference between system instructions, and user instructions, the first bit of the binary encoding of the instruction is used. Using the gates, the following table is encoded. 1st bit of Inst privilege bit 0 x - instruction allowed (user instructions are always allowed) 1 1 - instruction allowed (privilege bit enabled) 1 0 - instruction not allowed. Exception generated. Whenever an instruction generates an exception the privilege bit is flipped so that the exception can be handled. (Also set to 1 when a interrupt happens) Properties when privilege bit is set - available instruction set widens - available address space widens. The operating system isn't just a program that limits things. It also has services that reside on the system side of memory. To protect the security of the operating system, only the operating system can run these services. But programs in the user side have a way of signaling the operating system that they wish to have a service run. The way we have seen control transferred from the user side to the operating system side is when exceptions or interrupts are generated, and that's how services are called also (using interrupts specifically). When a user program wants a service to run, it makes a system call, which generates an interrupt, and waits for the service results. When control is transferred to the operating, it can actually do a number of things. In reality there are multiple programs running virtually at the same time, and the operating system controls how long each program runs for. Each process has its own address space, each independent of the other. Q: How are the multiple processes generated? A: An already running process spawns a new one. Using the fork( ) command, a program can make an exact copy of itself. Using the execv command, a program can change itself into a different program. Look up the details yourself, as you'll need them for the homework 1.