Index

SchoolNotes

  1. CS225
    1. OOP
      1. Inheritance
      2. R-Value References
    2. Misc Notes
    3. Size/Offsets of Structs/Classes
    4. Week 4
  2. CS200
    1. Introduction
    2. Scan Conversion
    3. Quiz 01
  3. GAM200
    1. Notes
  4. CS180
    1. Introduction
    2. Memory
    3. ELF Format
    4. History of Computers
    5. Stuff to Research
    6. Quiz To-Do
    7. OS Architectures
    8. Week 3
    9. Week 4
    10. Week 5
    11. Week 6 (Threads)

Week 3

User Mode vs Kernel Mode

User Mode cannot access privileged instructions.

1. Kernel Mode
In Kernel mode, the executing code has complete and unrestricted access to the underlying hardware. It can execute any CPU instruction and reference any memory address. Kernel mode is generally reserved for the lowest-level, most trusted functions of the operating system. Crashes in kernel mode are catastrophic; they will halt the entire PC.

2. User Mode
In User mode, the executing code has no ability to directly access hardware or reference memory. Code running in user mode must delegate to system APIs to access hardware or memory. Due to the protection afforded by this sort of isolation, crashes in user mode are always recoverable. Most of the code running on your computer will execute in user mode.




----------

Writing to a file - System callls required

Write, Read, Open, Close


----------

If you want to port from one platform to another, for example, Windows to Linux, and you're using windows library functions, then the porting is not so simple, obviously.

There are two types of portability:
- Binary level
→ Harder to port, obviously
- Source code level

--------------------


Different kinds of kernel architecture:

Monolithic: All code in OS runs in kernel mode (More efficient, requires no kernel change, but less stability) (Less stability because everything is talking to each other with kernel mode commands, if one is corrupted then the system's screwed)
Micro Kernel:
- Small part of OS as kernel
- Important services running as processes outside in user mode
- In order for the processes to talk to each other they require system calls (kernel change)
- More stability
Hybrid:
Combination of the above two.
Exo-Kernel: Don't need to know, but has been talked about by MIT for years.
→ Commands can control hardware - risky.

Windows Win95, 98 and ME are monolithic
Windows NT 4.0, 2000, XP and beyond are micro kernel


--------------------


Hard modularity:
- Slower speed
- Code is contained within specific individual programs
- If something crashes, other programs can still continue running
-
Soft modularity:
- Better speed
- Code is dependent on other code
- If something crashes, the entire program crashes


--------------------


Snapshot view

Assume a process using the CPU at a point in time.
- What are the “resources” that the running program would be using
→ Memory
→ Registers
→ P.C.
→ Instruction Decoder
→ ALU
→ I/O
→ Files


--------------------


In Linux there are 2 different stacks: user stack and kernel stack.
User stack is where the PC and other variables are stored.
Kernel stack is used to resolve ISRs.


--------------------


Context saving and restoring
When a program get interrupted, it needs to save its current process and then switch to the ISR, and restore it once the ISR is resolved.
This is call context saving and restoring
Automatic (no instructions involved)

HW saving then SW saving

What happen if CPU don't suppose HW saving?
HW MUST support some kind of saving
It must save at least the PC and SP
It must save them before ISR runs

Hw saves context to stack

Where does it save to:
PC is stored in PCB
SP is stored in PCB

When doing context switching, the values in the Register must be saved before switching, and restore after restoring.
The important registers to save are: PC and Stack Pointer
Other Regs are General Purpose regs, Floating pointer Stack, Status Flag

Context of a process:
The minimum data that must be saved before another code is executed.
The context is saved before switching control to the ISR



In Linux?, there are 2 different stacks that is assigned to a process: user stack and kernel stack.
User stack is where the PC and other variables are stored.
Kernel stack is used to resolved ISRs.

--------------------

Process state transitions

P1 is running in the CPU.
Interrupt comes in, P1 is suspended.
Serve the interrupt.
Needs to know what the process is doing at that stage, and thus we need states to describe where they are.

--------------------


return and exit are different because return will not return the status code to the parent.

return exits from the function while exit exits from the program.
In main function executing return 0; statement or calling exit(0) function will call the registered atexit handlers and will cause program termination.