Questions tagged [protected-mode]

x86 protected mode allows system software to support virtual memory, paging and preemptive multi-tasking.

x86 protected mode allows system software to support virtual memory, paging and preemptive multi-tasking.

  • Protected mode was first added to the x86 architecture in 1982, with the release of Intel's 80286 processor, and later extended with the release of the 80386 processor in 1985.
  • To maintain backward compatibility, x86 processors begins executing instructions in real mode.

To enter protected mode:

  • The Global Descriptor Table (GDT) must first be created with a minimum of three entries: a null descriptor, a code segment descriptor and data segment descriptor.
  • In an IBM-compatible machine, the A20 line (21st address line) also must be enabled to allow the use of all the address lines so that the CPU can access beyond 1 megabyte of memory.
  • Then the PE bit must be set in the CR0 register and a far jump must be made to clear the prefetch input queue:
; set PE bit
mov eax, cr0
or eax, 1
mov cr0, eax

; far jump (cs = selector of code segment)
jmp cs:@pm

@pm:
; Now we are in PM.
214 questions
2
votes
1 answer

What's the difference between .code16 and .code32

I am learning to program a system core of i386 by watching some videos. I've known some procedures about entering protected mode: In a .code16 file, first I need to open A20 Address Line and changed CR0 register, and then I need to ljmp into a…
Markity
  • 193
  • 8
2
votes
0 answers

Creating a print function in C 32-bit protected mode

I've been trying to develop a small OS and managed to switch into protected mode, in order to write C code instead of assembly, but since this means I can't use interrupt 10h anymore, I have to write chars to the video memory address. So I tried…
Malormar
  • 21
  • 4
2
votes
1 answer

Use variable to offset text in 32-bit protected mode

I am trying to make a custom cursor for my 32-bit OS and would like to know how to offset a memory address (0xb800 for text) by a variable (0xb8000+XVAR). I tried the following but the text just diapered off my screen: mov al, ' ' mov ah, 0xff mov…
Markian
  • 322
  • 1
  • 12
2
votes
1 answer

x86 long mode specific instructions available on protected mode?

Hey I'm wondering about some instructions that should only be valid in longmode. For example 0f 20 55 - mov rbp, cr2. I'm referencing ref.x86asm.net xml mapping. According to the xml the mode of operation of this instruction is e which means: e…
Jorayen
  • 1,737
  • 2
  • 21
  • 52
2
votes
1 answer

What happens if we request multibyte data at the end of memory address?

I am learning assembly language and has a question regarding this. I have a bootloader in real mode where we can access memory upto 1 mb. What will happen if we request 2 byte data at the end location of 1 mb space,will it return only one byte or…
2
votes
2 answers

IE Protected Mode + SSL Login = No cookie for non-SSL pages

(FWIW, I've posted this question to my blog as well: http://blog.wolffmyren.com/2011/07/11/ie-protected-mode-ssl/) Does anyone know how to work around Internet Explorer Protected Mode limitations without requiring the end-user to add our site to the…
2
votes
2 answers

Entering 32-bit protected mode does not work as intended

So recently, I decided to try using 32-bit code instead of 16-bit code for my basic OS kernel. I tried to enter 32-bit protected mode, but it doesn't seem to work correctly. I use NASM for building and qemu for debugging, but when I debug it, the…
2
votes
2 answers

What's under 0x400000 in virtual memory?

When learning Linux Operating Systems, I know the following things: Real mode will use addresss under 0x10000 Protected mode use 4G for 32bit, and the user space can use 2/3 G The virtual memory for a program will start from 0x40000 to higher So,…
tyChen
  • 1,404
  • 8
  • 27
2
votes
0 answers

VESA BIOS Extensions: How to Change Resolution?

I just finished writing a small boot loader and kernel that switches into protected mode and sets up a basic physical and virtual memory manager: Currently, I'm displaying text onto the screen by writing to the video address 0xB8000 in memory.…
user541686
  • 205,094
  • 128
  • 528
  • 886
2
votes
0 answers

Why loading GDT in the following way works

I'm writing my own kernel and used this code to override global descriptor table set by bootloader. This is done in 32 bit protected mode. flush_gdt: lgdt [gdtr] jmp 0x08:complete_flush complete_flush: mov ax, 0x10 mov ds, ax …
jason
  • 45
  • 1
  • 7
2
votes
2 answers

MASM generating wrong call target in protected mode

I'm experiencing exceptions when calling functions that are at a lower memory address than the current function while in protected mode. The exception will vary depending on code configuration, sometimes a general protection fault, sometimes an…
bad
  • 939
  • 6
  • 18
2
votes
1 answer

Entering protected mode from a DOS program

I think i've read a dozen or so questions that are basically a duplicate of this one, but I still haven't found a solution. The desired result is to enter protected mode and halt with no faults. The problem i'm experiencing is a triple fault after…
bad
  • 939
  • 6
  • 18
2
votes
1 answer

Why must the MOV CR0 and JMP instructions come from a page that is identity mapped while switching to protected mode?

why we have to put the mov cr0 and jmp instructions into a page that is identity mapped? I have been using Google to search this question but I am not able to understand the results.
0xff
  • 23
  • 4
2
votes
0 answers

Far jump to 32-bit protected mode entry point causes QEMU to continually reboot

When far jumping into the main32 (my 32-bit entry point) QEMU starts rebooting the kernel constantly, like a loop. This is from a custom OS project composed of a 2 stage bootloader and the kernel, which is the faulty one. As an x86 emulator I'm…
Burst
  • 23
  • 4
2
votes
0 answers

Risk in switching between real and protected mode multiple times

For my custom bootloader project, I asked myself whether there is a risk or overhead in switching between real mode and protected mode multiple times. So far, I've been looking at the following questions: Switch to and from 16-bit Real Mode and…
CRoemheld
  • 889
  • 7
  • 26