‫What is protected, Moate?
‫Protected mode is a process, a state enacts 86 architectures, this process, a state gives four gigabyte
‫of address space and much more protected modes can provide memory and hardware protection.
‫There are different memory.
‫Schemes for gigabytes of memory are directly addressable.
‫Let's explain a little bit about the memory and hardware protection that you have in protected mode.
‫So protective mode allows you to protect memory from being accessed and it also allows you to protect
‫hardware from being accessed from user programs.
‫And how this works is you have different protection levels in your processor.
‫We have what is known as ring zero.
‫This is the most privileged ring.
‫You can do anything with this ring.
‫You can talk with hardware, you can destroy memory, you can write memory anywhere you like, overwriting
‫things that shouldn't be.
‫This is ring zero.
‫The kernel runs on ring zero.
‫Then you have ring one and two, which are generally not used, but they can be used for device drivers.
‫Then you have ring three.
‫This is the least privileged ring.
‫You put the processor into ring three when you're running, use a code.
‫This prevents user programs from overriding kernel memory, from talking with hardware, directly from
‫accessing memory of other programs and using privileged instructions such as the STI to start the interrupts
‫and the ally to clear the interrupts ring three uses cannot use those instructions in and out.
‫Instructions are also restricted.
‫Ring three cannot use them.
‫In fact, how use a program to talk to the colonel is is they cause and interrupts.
‫Right.
‫And then by causing an interrupt, the process can put itself back into ring zero so that it can begin
‫running the interrupt code on the Colonel.
‫Obviously it's then the Colonel's responsibility to go back into ring three again and continue running
‫the user program.
‫So there's also different memory schemes in protective mode.
‫Our segment registers becomes selective registers and the other memory scheme we have is paging.
‫So this allows you to remap memory addresses.
‫So address Coxie or Zero actually points at some other address, for example.
‫We'll discuss that in a moment.
‫So let's first discuss the selective memory scheme.
‫So our segment registers become selective registers and the selectors point to data structures that
‫describe memory ranges and the permissions, you know, the ring level required to access a given range.
‫So this is what the structure looks like.
‫And unfortunately, numbers don't fit perfectly into these bytes.
‫So you will have to rely on a bit of bitwise logic to get the base and limit set correctly and so on.
‫But we can discuss more on all that later.
‫So the paging memory scheme is the most common scheme for all operating systems and Col's.
‫Most Col's and operating systems implement this memory scheme.
‫So this memory screen scheme is absolutely amazing because what you have is you have virtual addresses
‫and you can point those virtual addresses to physical addresses and memory protections is also easier
‫to control.
‫So, for example, if you look at this table, you can see in the page directory address zero zero zero
‫that points to paste table zero.
‫Right.
‫And then the address, zero zero zero in the page table points to address zero x two four be zero zero
‫zero write in real memory.
‫So if you actually access address zero, you're actually accessing that address zero two four be zero
‫zero zero and so on.
‫Right.
‫If you if you access address zero zero one, you're accessing address zero to four B zero zero one.
‫Right.
‫This is how paging works is fantastic because it allows all programs to believe their load is at the
‫same address.
‫It also allows you to completely map out all of the user programs in memory.
‫So it makes it impossible for a user program to see the address space of another program that's running.
‫As far as the program is concerned, it's the only program running.
‫It can't see anything else with this memory scheme.
‫We can actually map multiple processes at the same address, zero x 400000, for example.
‫Now, in the real memory, obviously they're in different places, but the virtual memory we can make
‫zero four hundred thousand point to the process one's memory while process one is currently being executed.
‫And as soon as we execute process to.
‫We can swap the page table and page directories so that Xerox 400000 now points to process two's memory,
‫right?
‫It is a fantastic feature and is very important in modern operating systems.
‫But this is way down the line.
‫You probably don't know what I'm saying right now, but don't worry, because the page memory scheme
‫will discuss that way down the line.
‫There's plenty you need to learn before we get onto that.
‫But Pageonce, generally simple, is basically a directory of pointers to page tables, essentially.
‫And then we have a page table entries and we can point to real memory.
‫And I should also note that any any virtual addresses and physical addresses of those virtual addresses
‫point to they all need to be traversable by four, nine, six.
‫If there's any remainder, then it won't work.
‫Right.
‫So they need to divide perfectly into four, nine six.
‫So protective mode also gives us four gigabytes of addressable memory.
‫So we gain access to 32 bit instructions and we can easily work with 32 registers such as X, X and
‫so on.
‫We can also address up to four gigabytes of memory at any time, and we are no longer limited to the
‫one megabyte of memory provided by real mode.
‫So at this point in time, when we switch to protected, we're essentially writing a 32 bit kernel that
‫can run through to code.
‫So you know how you have 32 bit system, 64 bit systems.
‫What we're writing a 32 bit system.