5.1.13 · D1 · HinglishInstruction Set Architecture (ISA)

FoundationsSystem vs user mode and privilege levels

2,131 words10 min read↑ Read in English

5.1.13 · D1 · Hardware › Instruction Set Architecture (ISA) › System vs user mode and privilege levels

Is page par kuch bhi assume nahi kiya gaya hai. Parent topic padhne se pehle tumhe kuch words aur pictures ki ek chhoti si toolkit chahiye. Hum har ek cheez zero se build karte hain, ek aisi order mein jahan har naya idea sirf pehle waale ideas par hi tikta hai.


0. "CPU instruction" hota kya hai?

Neeche figure dekho. Ek program bas memory mein bethe aise numbered commands ki ek lambi list hai. CPU inhe ek-ek karke chalta rehta hai.

Figure — System vs user mode and privilege levels

1. Program Counter (PC)

Ek ungli ki tarah soch jo ek to-do list ki ek line par point kar rahi hai. Normally ungli ek-ek line neeche khiskti rehti hai. "Jump" karna matlab hai ungli ko kheench kar kisi bilkul alag line par le jaana.


2. Registers

Ek muthi bhar labeled cups ki tarah socho jo seedha tumhare desk par hain, versus ek warehouse (RAM) jo town ke dusre chhor par hai.


3. Status Register (PSW)

Figure — System vs user mode and privilege levels

Figure mein, ek register fields kehlaane waale chhote labeled slots mein baanta hua hai. Un fields mein se ek hai mode bit jise hum aage build karte hain.


4. Bit, aur "mode bit"


5. Privileged vs unprivileged instructions

Ek do-shelf tool ki tasveer socho. Bottom shelf (add, copy) koi bhi use kar sakta hai. Top shelf (halt, remap) par ek lock laga hai, aur sirf kernel ke paas key hai — key ka matlab hai "mode bit = kernel".


6. Decode — check ka woh pal

Figure — System vs user mode and privilege levels

Figure pipeline dikhata hai: fetch → decode → execute. Privilege check decode par hota hai, kyunki enforcement dangerous effect se pehle aani chahiye. Baad mein check karna aisa hai jaise crash ke baad driver's licence check karo.


7. Trap / Exception

Ek trapdoor ki tasveer socho. Galat tile par kadam rakho (ek illegal instruction) aur tum seedha principal's office (kernel handler) mein gir jaate ho, chahe tumne chaha ho ya nahi.


8. Controlled doorway — system call


9. Atomic

Light switch flip karne ki tasveer socho: yeh ya off hai ya on, kabhi "half flipped" nahi jise koi beech mein pakad sake.


10. Rings / Exception Levels — ek bit ko generalize karna

Figure — System vs user mode and privilege levels

Figure: nested circles, innermost = sabse zyada trusted. Dekho Protection rings (x86) / Exception Levels (ARM).


Prerequisite map

instruction and opcode

decode

program counter PC

system call doorway

registers

status register PSW

mode bit

privileged vs unprivileged

trap exception

atomic

rings and levels

System vs user mode


Equipment checklist

Khud ko test karo — tum tab ready ho jab har reveal se wahi match ho jo tum kehte.

Opcode kya hota hai?
Woh chhota number jo instruction ki shuru mein hota hai aur batata hai ki kaunsa command hai — "verb."
Program Counter mein kya hota hai?
Us agli instruction ka memory address jo run hogi; ek jump isme nayi value likhta hai.
Mode bit RAM ki jagah register mein kyun store karte hain?
Registers instant padhne ke liye hote hain (check har instruction par run hota hai) aur register protected hai — user code use likh nahi sakta.
Privileged instruction kya hoti hai?
Woh instruction jo CPU tab hi execute karta hai jab mode bit kernel mode kahe.
Privilege check pipeline ke kis stage par hota hai, aur kyun?
Decode par — execute se pehle — taaki kisi forbidden instruction ka effect kabhi na ho.
Trap/exception kya hota hai?
CPU ka built-in reaction jo kernel mode mein switch karta hai aur ek illegal instruction run karne ki jagah ek fixed OS handler par jump karta hai.
User→kernel transition atomic kyun hona chahiye?
Taaki koi attacker apna code kernel mode mein mode switch aur jump ke beech interleave na kar sake.
Ring numbering mein sabse zyada privileged kaun sa hai?
Sabse chhota number (Ring 0) — inner ring, sabse zyada trusted.