Home > other >  O have greatly explain ji-wen Yang teacher chapter 10 protected mode T10-5. Asm look not to know a f
O have greatly explain ji-wen Yang teacher chapter 10 protected mode T10-5. Asm look not to know a f

Time:10-01

First of all, the following code compiled using masm5.0 or tasm2.0 all can generate t10-5. Obj, next reoccupy tlink. Exe t10/3-5. Obj can correctly generated exe file,

In order to facilitate understanding, I put the book on the specification of this example also posted, so convenient greatly the fast identify problems
Don't understand the place is marked off in the comments section of the code



; T10-5. ASM 
; Demonstration task switching and tasks within the privilege level transformation
The include 386 SCD. ASM
. 386 p
; The global descriptor table
GDTSEG SEGMENT PARA USE16
GDT LABEL BYTE
Dummy descriptor & lt;>
Normal descriptor & lt; FFFFH 0, 0, 0, atdw, 0 & gt;
Normal_sel=normal - GDT
Effgdt label byte
Demotss descriptor & lt; Demotsslen - 1, demotssseg at386tss, & gt;
Demotss_sel=demotss - GDT
Demoldtab descriptor & lt; Demoldtlen - 1, demoldtseg atldt, & gt;
Demoldt_sel=demoldtab - GDT
; Temporary task the task status of segment descriptor
Temptss descriptor & lt; Temptsslen - 1, temptssseg, at386tss + dpl2, & gt;
Temptss_sel=temptss - GDT
; Temporary task code
Tempcode descriptor & lt; 0 FFFFH, tempcodeseg, atce, & gt;
Tempcode_sel=tempcode - GDT
; The subroutine code segment descriptor
Subr descriptor & lt; Subrlen - 1, subrseg, atce + d32, & gt;
Subr_sel=subr GDT + rpl3

Videobuff descriptor & lt; FFFFH 0, 0, 0, + atdw f00h + dpl3, 0 & gt;
Video_sel=videobuff - GDT
Gdnum=($- effgdt)/(size descriptor)
Gdtlen=$- GDT
Gdtseg ends

; Task status of demonstration task
DemoTSSSEG segment para use16
Dd 0; Link words
Dd DemoStack0LEN; Level 0 stack pointer
Dw DemoStack0_SEL, 0
Dd 0; Level 1 stack pointer
Dw? , 0
Dd DemoStack2LEN; Level 2 stack pointer
DW Demostack2_sel, 0
Dd 0; Cr3,
Dw demobegin, 0; The eip
Dd 0; Eflags
Dd 0; Eax
Dd 0; Ecx
Dd 0; Edx
Dd 0; Ebx
Dd DemoStack2LEN; Esp
Dd 0; Ebp
Dd 0; Esi
Dd 0 b8000h; Edi
Dw video_sel, 0; Es
Dw DemoCode_sel, 0; Cs
Dw DemoStack2_sel, 0; Ss
Dw DemoData_sel, 0; Ds
Dw ToDLDT_SEL, 0; Fs
Dw ToTTSS_SEL, 0; Gs
Dw DemoLDT_SEL, 0; LDTR
Dw 0
Dw + $2; I/O permission bitmap pointer
The db 0 FFH; End of the I/O permission bitmap byte
DemoTSSLEN=$
DemoTSSSEG ends

; Demonstration task of local descriptor table LDT
DemoLDTSEG segment para use16
Demoldt label byte
Demostack0 descriptor & lt; Demostack0len - 1, demostack0seg, atdw + d32, & gt;
Demostack0_sel=(demostack0 - demoldt) + til
Demostack2 descriptor & lt; Demostack2len - 1, demostack2seg, atdw + + dpl2 d32, & gt;
Demostack2_sel=(demostack2 - demoldt) + til + rpl2
; The demo code segment descriptor
Democode descriptor & lt; Democodelen - 1, democodeseg, atce + + dpl2 d32, & gt;
Democode_sel=(democode - demoldt) + til + rpl2
; The demonstration data segment descriptor
Demodata descriptor & lt; Demodatalen - 1, demodataseg, atdw + + dpl3 d32, & gt;
Demodata_sel=(demodata - demoldt) + til
; The LDT as common descriptors of the description of data (DPL=2)
Todldt descriptor & lt; Demoldtlen - 1, demoldtseg, atdw + dpl2, & gt;
Todldt_sel=(todldt - demoldt) + til
; The TSS as common descriptors of the description of data (DPL=2)
TOTTSS descriptor & lt; Temptsslen - 1, temptssseg, atdw + dpl2, & gt;
Tottss_sel=(tottss - demoldt) + til
DemoLDNUM=($- demoldt)/(size descriptor)
; Pointing to the subroutine calls subrb door (DPL=3)
Tosubr gate & lt; Subrb subr_sel, 0, + dpl3 at386cgat, 0 & gt;
Tosubr_sel=(tosubr - demoldt) + til + rpl2
; Temporary tasks to the task of temp door (DPL=3)
Totempt gate & lt; Temptss_sel 0, 0, + dpl3 attaskgat, 0 & gt;
Totempt_sel=(totempt - demoldt) + til
Demoldtlen=$- demoldt
Demoldtseg ends
; Demonstration task level 0 stack
DemoStack0SEG segment para use32
Demostack0len=1024
The db demostack0len dup (0)
Demostack0seg ends

DemoStack2SEG segment para use32
Demostack2len=512
The db demostack2len dup (0)
Demostack2seg ends

; Demonstration task data segment
DemoDataSEG segment para use32
The message db 'Value=' https://bbs.csdn.net/topics/, 0
Demodatalen=$
Demodataseg ends

Subrseg segment para use32
Cs: assume subrseg
The subrb proc far
Push ebp
Mov ebp, esp
Pushad
Mov eax, [ebp + 12]
Mov esi, eax
Mov ah, 7
JMP short subr2
Subr1: stosw
Subr2: lodsb
The or al, al
JNZ subr1
Mov edx, [ebp + 16]
Mov ecx, 8
Subr3: rol edx, 4
Mov al, dl
Call htoasc
Stosw
Loop subr3
Popad
Pop ebp
Ret 8
Subrb endp

Htoasc proc
And al, 0 fh
The add al, 90 h
Daa
The adc al, 40 h
Daa
Ret
Htoasc endp
Subrlen=$
Subrseg ends

DemoCodeSEG segment para use32
Cs: assume DemoCodeSEG
DemoBegin:
Mov fs: tosubr. Dcount, 2; ? 2 don't understand, the segment register here is what is the fs
Gs: push dword PTR temptask. Treip; ? 3 don't understand, the segment register here is why gs
Push offset Message
Call32 tosubr_sel, 0; This sub function can read
Assume the ds: temptssseg
Push gs
Pop the ds; 4 look not to understand, why push gs and then pop the ds
Mov ax, normal_sel
Mov temptask TRDS, ax
Mov temptask tres, ax
Mov temptask TRFS, ax
Mov temptask TRGS, ax
Mov temptask TRSS, ax
Jump32 totempt_sel, 0; 5 don't understand place, here is totempt_sel selector for the corresponding period of temptssseg, and period of temptssseg is a not initialise the structure of the
; Body, how to jump in the past?
DemoCodeLEN=$
DemoCodeSEG ends

Temptssseg segment para use16
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related