Hi,
When I compiled the following code with nasm-2.09.03, it generated a large size .com file. Please check it.
nasm pmtest3.asm -o pmtest3.com
pm.inc
;----------------------------------------------------------------------------
DA_32 EQU 4000h ; 32 ??
DA_DPL0 EQU 00h ; DPL = 0
DA_DPL1 EQU 20h ; DPL = 1
DA_DPL2 EQU 40h ; DPL = 2
DA_DPL3 EQU 60h ; DPL = 3
;----------------------------------------------------------------------------
; ???????????
;----------------------------------------------------------------------------
DA_DR EQU 90h ; ???????????
DA_DRW EQU 92h ; ????????????
DA_DRWA EQU 93h ; ???????????????
DA_C EQU 98h ; ????????????
DA_CR EQU 9Ah ; ??????????????
DA_CCO EQU 9Ch ; ??????????????
DA_CCOR EQU 9Eh ; ????????????????
;----------------------------------------------------------------------------
; ???????????
;----------------------------------------------------------------------------
DA_LDT EQU 82h ; ??????????
DA_TaskGate EQU 85h ; ??????
DA_386TSS EQU 89h ; ?? 386 ????????
DA_386CGate EQU 8Ch ; 386 ??????
DA_386IGate EQU 8Eh ; 386 ??????
DA_386TGate EQU 8Fh ; 386 ??????
;----------------------------------------------------------------------------
; ?????:
; ?????????????????????????????????????????????????
; ? 15 ? 14 ? 13 ? 12 ? 11 ? 10 ? 9 ? 8 ? 7 ? 6 ? 5 ? 4 ? 3 ? 2 ? 1 ? 0 ?
; ?????????????????????????????????????????????????
; ? ????? ? TI ? RPL ?
; ?????????????????????????????????????????????????
;
; RPL(Requested Privilege Level): ?????????????
;
; TI(Table Indicator): ?????????
; TI=0 ?????????GDT???????
; TI=1 ?????????LDT???????
;
;----------------------------------------------------------------------------
; ????????
; ??:
; SA_ : Selector Attribute
SA_RPL0 EQU 0 ; ?
SA_RPL1 EQU 1 ; ? RPL
SA_RPL2 EQU 2 ; ?
SA_RPL3 EQU 3 ; ?
SA_TIG EQU 0 ; ?TI
SA_TIL EQU 4 ; ?
;----------------------------------------------------------------------------
; ? ------------------------------------------------------------------------------------------------------
;
; ???
; usage: Descriptor Base, Limit, Attr
; Base: dd
; Limit: dd (low 20 bits available)
; Attr: dw (lower 4 bits of higher byte are always 0)
%macro Descriptor 3
dw %2 & 0FFFFh ; ??? 1 (2 ??)
dw %1 & 0FFFFh ; ??? 1 (2 ??)
db (%1 >> 16) & 0FFh ; ??? 2 (1 ??)
dw ((%2 >> 8) & 0F00h) | (%3 & 0F0FFh) ; ?? 1 + ??? 2 + ?? 2 (2 ??)
db (%1 >> 24) & 0FFh ; ??? 3 (1 ??)
%endmacro ; ? 8 ??
;
; ?
; usage: Gate Selector, Offset, DCount, Attr
; Selector: dw
; Offset: dd
; DCount: db
; Attr: db
%macro Gate 4
dw (%2 & 0FFFFh) ; ?? 1 (2 ??)
dw %1 ; ??? (2 ??)
dw (%3 & 1Fh) | ((%4 << 8) & 0FF00h) ; ?? (2 ??)
dw ((%2 >> 16) & 0FFFFh) ; ?? 2 (2 ??)
%endmacro ; ? 8 ??
; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pmtest3.asm
; ==========================================
; pmtest3.asm
; ?????nasm pmtest3.asm -o pmtest3.com
; ==========================================
%include "pm.inc" ; ??, ??, ??????
org 0100h
jmp LABEL_BEGIN
[SECTION .gdt]
; GDT
; ???, ??? , ??
LABEL_GDT: Descriptor 0, 0, 0 ; ????
LABEL_DESC_NORMAL: Descriptor 0, 0ffffh, DA_DRW ; Normal ???
LABEL_DESC_CODE32: Descriptor 0, SegCode32Len - 1, DA_C + DA_32 ; ???????, 32
LABEL_DESC_CODE16: Descriptor 0, 0ffffh, DA_C ; ???????, 16
LABEL_DESC_DATA: Descriptor 0, DataLen - 1, DA_DRW+DA_DPL1 ; Data
LABEL_DESC_STACK: Descriptor 0, TopOfStack, DA_DRWA + DA_32; Stack, 32 ?
LABEL_DESC_LDT: Descriptor 0, LDTLen - 1, DA_LDT ; LDT
LABEL_DESC_VIDEO: Descriptor 0B8000h, 0ffffh, DA_DRW ; ?????????
; GDT ??
GdtLen equ $ - LABEL_GDT ; GDT??
GdtPtr dw GdtLen - 1 ; GDT??
dd 0 ; GDT???
; GDT ???
SelectorNormal equ LABEL_DESC_NORMAL - LABEL_GDT
SelectorCode32 equ LABEL_DESC_CODE32 - LABEL_GDT
SelectorCode16 equ LABEL_DESC_CODE16 - LABEL_GDT
SelectorData equ LABEL_DESC_DATA - LABEL_GDT
SelectorStack equ LABEL_DESC_STACK - LABEL_GDT
SelectorLDT equ LABEL_DESC_LDT - LABEL_GDT
SelectorVideo equ LABEL_DESC_VIDEO - LABEL_GDT
; END of [SECTION .gdt]
[SECTION .data1] ; ???
ALIGN 32
[BITS 32]
LABEL_DATA:
SPValueInRealMode dw 0
; ???
PMMessage: db "In Protect Mode now. ^-^", 0 ; ?????????????
OffsetPMMessage equ PMMessage - $$
StrTest: db "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 0
OffsetStrTest equ StrTest - $$
DataLen equ $ - LABEL_DATA
; END of [SECTION .data1]
; ?????
[SECTION .gs]
ALIGN 32
[BITS 32]
LABEL_STACK:
times 512 db 0
TopOfStack equ $ - LABEL_STACK - 1
; END of [SECTION .gs]
[SECTION .s16]
[BITS 16]
LABEL_BEGIN:
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0100h
mov [LABEL_GO_BACK_TO_REAL+3], ax
mov [SPValueInRealMode], sp
; ??? 16 ????????
mov ax, cs
movzx eax, ax
shl eax, 4
add eax, LABEL_SEG_CODE16
mov word [LABEL_DESC_CODE16 + 2], ax
shr eax, 16
mov byte [LABEL_DESC_CODE16 + 4], al
mov byte [LABEL_DESC_CODE16 + 7], ah
; ??? 32 ????????
xor eax, eax
mov ax, cs
shl eax, 4
add eax, LABEL_SEG_CODE32
mov word [LABEL_DESC_CODE32 + 2], ax
shr eax, 16
mov byte [LABEL_DESC_CODE32 + 4], al
mov byte [LABEL_DESC_CODE32 + 7], ah
; ?????????
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_DATA
mov word [LABEL_DESC_DATA + 2], ax
shr eax, 16
mov byte [LABEL_DESC_DATA + 4], al
mov byte [LABEL_DESC_DATA + 7], ah
; ?????????
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_STACK
mov word [LABEL_DESC_STACK + 2], ax
shr eax, 16
mov byte [LABEL_DESC_STACK + 4], al
mov byte [LABEL_DESC_STACK + 7], ah
; ??? LDT ? GDT ?????
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_LDT
mov word [LABEL_DESC_LDT + 2], ax
shr eax, 16
mov byte [LABEL_DESC_LDT + 4], al
mov byte [LABEL_DESC_LDT + 7], ah
; ??? LDT ?????
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_CODE_A
mov word [LABEL_LDT_DESC_CODEA + 2], ax
shr eax, 16
mov byte [LABEL_LDT_DESC_CODEA + 4], al
mov byte [LABEL_LDT_DESC_CODEA + 7], ah
; ??? GDTR ???
xor eax, eax
mov ax, ds
shl eax, 4
add eax, LABEL_GDT ; eax <- gdt ???
mov dword [GdtPtr + 2], eax ; [GdtPtr + 2] <- gdt ???
; ?? GDTR
lgdt [GdtPtr]
; ???
cli
; ?????A20
in al, 92h
or al, 00000010b
out 92h, al
; ?????????
mov eax, cr0
or eax, 1
mov cr0, eax
; ????????
jmp dword SelectorCode32:0 ; ??????? SelectorCode32 ?? cs, ???? Code32Selector:0 ?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LABEL_REAL_ENTRY: ; ????????????????
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov sp, [SPValueInRealMode]
in al, 92h ; ?
and al, 11111101b ; ? ?? A20 ???
out 92h, al ; ?
sti ; ???
mov ax, 4c00h ; ?
int 21h ; ??? DOS
; END of [SECTION .s16]
[SECTION .s32]; 32 ?????. ??????.
[BITS 32]
LABEL_SEG_CODE32:
mov ax, SelectorData
mov ds, ax ; ??????
mov ax, SelectorVideo
mov gs, ax ; ??????
mov ax, SelectorStack
mov ss, ax ; ??????
mov esp, TopOfStack
; ?????????
mov ah, 0Ch ; 0000: ?? 1100: ??
xor esi, esi
xor edi, edi
mov esi, OffsetPMMessage ; ?????
mov edi, (80 * 10 + 0) * 2 ; ?????????? 10 ?, ? 0 ??
cld
.1:
lodsb
test al, al
jz .2
mov [gs:edi], ax
add edi, 2
jmp .1
.2: ; ????
call DispReturn
; Load LDT
mov ax, SelectorLDT
lldt ax
jmp SelectorLDTCodeA:0 ; ??????
; ------------------------------------------------------------------------
DispReturn:
push eax
push ebx
mov eax, edi
mov bl, 160
div bl
and eax, 0FFh
inc eax
mov bl, 160
mul bl
mov edi, eax
pop ebx
pop eax
ret
; DispReturn ??---------------------------------------------------------
SegCode32Len equ $ - LABEL_SEG_CODE32
; END of [SECTION .s32]
; 16 ?????. ? 32 ???????, ???????
[SECTION .s16code]
ALIGN 32
[BITS 16]
LABEL_SEG_CODE16:
; ?????:
mov ax, SelectorNormal
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov eax, cr0
and al, 11111110b
mov cr0, eax
LABEL_GO_BACK_TO_REAL:
jmp 0:LABEL_REAL_ENTRY ; ??????????????????
Code16Len equ $ - LABEL_SEG_CODE16
; END of [SECTION .s16code]
; LDT
[SECTION .ldt]
ALIGN 32
LABEL_LDT:
; ??? ??? ??
LABEL_LDT_DESC_CODEA: Descriptor 0, CodeALen - 1, DA_C + DA_32 ; Code, 32 ?
LDTLen equ $ - LABEL_LDT
; LDT ???
SelectorLDTCodeA equ LABEL_LDT_DESC_CODEA - LABEL_LDT + SA_TIL
; END of [SECTION .ldt]
; CodeA (LDT, 32 ?????)
[SECTION .la]
ALIGN 32
[BITS 32]
LABEL_CODE_A:
mov ax, SelectorVideo
mov gs, ax ; ??????(??)
mov edi, (80 * 12 + 0) * 2 ; ??? 10 ?, ? 0 ??
mov ah, 0Ch ; 0000: ?? 1100: ??
mov al, 'L'
mov [gs:edi], ax
; ????16??????????
jmp SelectorCode16:0
CodeALen equ $ - LABEL_CODE_A
; END of [SECTION .la]