Article View: alt.msdos.programmer
Article #1391How to enter Protected Mode from Assembly. 1 Q.
From: SIR P/L
Date: Thu, 05 May 1994 05:27
Date: Thu, 05 May 1994 05:27
134 lines
5405 bytes
5405 bytes
Hello everybody,
What follows is my idea of all that is necessary to switch
a 486 (or 386 for that matter) into "Flat" protected-mode.
IT does NOT work.
I would be *most* grateful if anyone could take a look at it
and give me some idea what I'm doing wrong. It simply hangs the machine, and
the top left-hand corner of the screen remains un-changed.
I'm using MASM 6, but this should work on most versions of
most assemblers that accept protected mode instructions.
Alternativly, if anyone has a tiny .EXE or .COM program to (1) switch
the CPU into protected mode, and (2) execute some trivial instructions in an
endless loop, I'd love to get a copy. I'm much better with .ASM when I've got
some working code to disect.
All help grately appreciated.
Chris.
sir@usage.csd.unsw.oz.au
PAGE ,132 ;Wide output
TITLE Empty .EXE skeleton for protected mode
.RADIX 16 ;Numbers I type in are HEX by default
INCLUDE MACROS.ASM ;My pre-built functions
SKEL segment para public 'CODE' ;Where the stuff will be starting from
public START
assume CS:SKEL, DS:DATA, ES:DATA, SS:STACK
.486p ;Allow protected-mode and 486 instructions.
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
PE_FLAG equ 1
data_selc equ 20h
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
CLR macro reg ;This is here because I'm a 6809 veteran and
sub reg,reg ;It's a beautiful macro, so why not ? (sub faster than xor)
endm
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
DATA segment para public 'DATA' ;Will be placed directly after the CODE
gdt_desc qword ?
gdt_tab dw 0,0,0,0
dw 0FFFFh,0,9200h,8Fh
dq 0
Intro db 'Switching into Linear protected-mode now.$'
DATA ends
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
STACK_SIZE equ 1000h
STACK segment para stack 'STACK' ;Will be placed directly after the DATA
db (STACK_SIZE) dup(?)
STACK ends
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
START proc near ;Everything starts from here.
PSP_SEG equ 24h
ENV_SEG equ 2ch
STI ;enable interrupts
MOV AX,DATA ;Get the right segments pointing to
MOV DS,AX ;the right places
MOV ES,AX
CLR AX
CLI ;Disable interrupts
OUT 0A0h,AL ;Disable NMI too
mov dx,offset Intro
mov ah,9
int 21h
; MOV EAX,OFFSET GDT_DESC
mov eax,offset gdt_tab
AND EAX,0FFFFh
LGDT fword ptr [EAX]
mov ax,bx
or al,pe_flag
lmsw ax
clr eax
mov al,data_selc
mov ds,ax
mov ss,ax
mov es,ax
mov fs,ax
mov gs,ax
jmp far ptr c_startup
;Exit to DOS when complete (obviously never called)
MOV AH,4CH
INT 21H
RET
c_startup: mov esp,eax
mov eax,0b8000h
mov edi,eax
inc dword ptr[edi]
MOV AL,1
OUT 0A0h,AL
STI
@@: inc dword ptr[edi]
jmp @B
;etc
hlt
START endp
;zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
SKEL ends
end START
Chris Drake.
sir@usage.csd.unsw.oz.au
Technical Details
Message-ID:
<1994May5.052710.9875@usage.csd.unsw.OZ.AU>Path:
arc1-ca.pugleaf.net!gmd.de!nntp.gmd.de!dearn!blekul11!psuvm!news.cac.psu.edu!howland.reston.ans.net!EU.net!sunic! trane.uninett.no!nac.no!ifi.uio.no!wabbit.cc.uow.edu.au!metro!usage!sirShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f6aa,6994a0d4e02e984d,start X-Google-Attributes: gid10f6aa,public X-Google-Thread: ffec8,6994a0d4e02e984d,start X-Google-Attributes: gidffec8,public X-Google-Thread: 10d683,6994a0d4e02e984d,start X-Google-Attributes: gid10d683,public X-Google-Thread: fe306,6994a0d4e02e984d,start X-Google-Attributes: gidfe306,public X-Google-Thread: ff6a6,6994a0d4e02e984d,start X-Google-Attributes: gidff6a6,public X-Google-Thread: 102bfa,6994a0d4e02e984d,start X-Google-Attributes: gid102bfa,public X-Google-Thread: 10bb54,6994a0d4e02e984d,start X-Google-Attributes: gid10bb54,public X-Google-ArrivalTime: 1994-05-05 00:52:13 PST Newsgroups: alt.msdos.programmer,alt.2600,comp.sys.ibm.pc.programmer,comp.os.msdos.programmer,rec.games.programmer,aus.computers.ibm-pc,comp.sys.ibm.pc.hardware Path: arc1-ca.pugleaf.net!gmd.de!nntp.gmd.de!dearn!blekul11!psuvm!news.cac.psu.edu!howland.reston.ans.net!EU.net!sunic! trane.uninett.no!nac.no!ifi.uio.no!wabbit.cc.uow.edu.au!metro!usage!sir From: sir@usage.csd.unsw.OZ.AU (SIR P/L) Subject: How to enter Protected Mode from Assembly. 1 Q. Message-ID: <1994May5.052710.9875@usage.csd.unsw.OZ.AU> Keywords: protected mode .ASM assembler flat 486 386 Organization: University of New South Wales Date: Thu, 5 May 1994 05:27:10 GMT Lines: 134