Question

Which are instructions (for x86 chips) that can run only in kernel mode? I am trying to understand the practical difference between user and kernel mode. so far I understand that a part of address space is accessible only in kernel mode. this memory space contains drivers etc which should be protected from user programs. Also how is kernel mode actually implemented in CPU? is there a certain bit in CPU that turns 1 or something like that happens?

Edit : after the Answer has been provided below.

I am justing adding here part of the answer copied from the link mentioned in the answer.

Privileged Level Instructions

Instruction Description

LGDT Loads an address of a GDT into GDTR

LLDT Loads an address of a LDT into LDTR

LTR Loads a Task Register into TR

MOV Control Register Copy data and store in Control Registers

LMSW Load a new Machine Status WORD

CLTS Clear Task Switch Flag in Control Register CR0

MOV Debug Register Copy data and store in debug registers

INVD Invalidate Cache without writeback

INVLPG Invalidate TLB Entry

WBINVD Invalidate Cache with writeback

HLT Halt Processor

RDMSR Read Model Specific Registers (MSR)

WRMSR Write Model Specific Registers (MSR)

RDPMC Read Performance Monitoring Counter

RDTSC Read time Stamp Counter

Was it helpful?

Solution

This question is more directed to those who deal with very low level hardware details (say kernel programmers) than those who deal with high level issues often referred to as software developers. I will answer since I assume this is still Computer Science!

You will not want to run a user application and it suddenly erases everything on the screen, erases ALL data in your hard-drive, refuses any access to any hardware, take full control of CPU resources, and so on and in very unpleasant ways. The kernel is the master who controls user accesses to system utilities. Also if one user application fails then it will be 'alone' to die in peace! So viruses often target the kernel so to make meaningful damage.

Such protection cannot be efficiently done through software. That will require the Operating System to check every instruction of the user application, making sure there is none with evil intent! An example is one which tries to directly write into kernel memory space. For example trying to access memory at address 0 will generate an interrupt called General Protection Fault. Go to the link below and search for the text "Privileged Level Instructions".

Kernel mode is implemented by configuring system registers like the GDTR (Global Descriptor Table Register). Go to the link below and search for the title "Global Descriptor Table". Based on the configuration of this register the General Protection Fault interrupt is generated when privilege level is violated.

Link: http://www.brokenthorn.com/Resources/OSDev23.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top