T
T
Type Programmer2018-11-17 15:08:21
assembler
Type Programmer, 2018-11-17 15:08:21

How does assembler addressing work in protected mode?

I can not understand some points in the code, the code goes into protected mode and displays the letter "A", I really need help.
The code:

use16
org 0x7c00
start:
  mov bx,pm_entry
  mov ax, 0x0003
  int 0x10
  in  al, 0x92
  or  al, 2
  out 0x92, al
  lgdt  [gdtr]
  cli                                 
  in  al, 0x70
  or  al, 0x80
  out 0x70, al
  mov  eax, cr0
  or   al, 1
  mov  cr0, eax
  jmp 00001000b:pm_entry
 

use32
pm_entry:
  mov  ax, cs
  mov  ds, ax
  mov  es, ax
 
  mov  edi, 0xB8000            
  mov  esi, msg                
  cld         
  mov al,'A'
  mov [edi],al

  jmp  $                  

gdt:
  db  0x00, 0x00, 0x00, 0x00, 0x00,      0x00,      0x00, 0x00
  db  0xFF, 0xFF, 0x00, 0x00, 0x00, 10011010b, 11001111b, 0x00
gdt_size  equ $ - gdt

gdtr:
  dw  gdt_size - 1
  dd  gdt
 
finish:
times 0x1FE-finish+start db 0
db   0x55, 0xAA

Can you tell me what the descriptor points to, that is, what is the address of the beginning of the segment that it defines?
I can't figure out exactly how this jump happens.
jmp 00001000b:pm_entry
use32
pm_entry:

The whole problem is that I do not understand the structure of the descriptor ..
db  0xFF, 0xFF, 0x00, 0x00, 0x00, 10011010b, 11001111b, 0x00

PS: Can you just explain step by step I will be very grateful, coding in real time is not something. I'm just a user who got into the assembler do not judge strictly

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2018-11-17
@MegaCraZy6

The whole problem is that I do not understand the structure of the descriptor ..

https://en.wikipedia.org/wiki/Global_Descriptor_Table what is the difficulty?
Segment limit: 0xfffff
Base address: 0x00000000
Type: 0xa
S: 1
DPL: 0
P: 1
A: 0
DB: 1
G:
1 this segment is valid (P = 1), non-system (S = 1), starts at address 0, covers 4G, executable and readable (Type = 0xa), accessible from protection ring 0 (DPL = 0), unread ( A = 0), with page granularity (G = 1).
I can't figure out exactly how this jump happens.
jmp 00001000b:pm_entry
use32
pm_entry:

0x8 gets into cs, i.e. CPL = 0, use 1st entry in GDT, in pc -- pm_entry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question