Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

No extensible language will be universal. -- T. Cheatham


programming / comp.lang.asm.x86 / Re: Entering Protected Mode

SubjectAuthor
* Entering Protected ModeRick C. Hodgin
+* Re: Entering Protected Modewolfgang kern
|`- Re: Entering Protected ModeRick C. Hodgin
`* Re: Entering Protected Moderugxulo
 `* Re: Entering Protected ModeRick C. Hodgin
  `* Re: Entering Protected Modewolfgang kern
   `- Re: Entering Protected ModeRick C. Hodgin

1
Subject: Entering Protected Mode
From: Rick C. Hodgin
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Wed, 19 Jun 2019 15:25 UTC
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rick.c.h...@gmail.com (Rick C. Hodgin)
Newsgroups: comp.lang.asm.x86
Subject: Entering Protected Mode
Date: Wed, 19 Jun 2019 08:25:20 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 55
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Wed, 19 Jun 2019 15:25:21 +0000
Injection-Info: h2725194.stratoserver.net; posting-host="9fb5cd0a4e985bcff7634cac3595a438";
logging-data="19313"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195syPAD9qvPtx3Nhy0oVkZj1wFPITcP6Y="
User-Agent: G2/1.0
Cancel-Lock: sha1:uBeH4nuy3bB+NFmCn4rDAulVXvE=
View all headers
In my custom OS kernel, I use this code to enter protected mode:

    cli                               ; Clear interrupts
    mov     eax,cr0
    or      al,1
    mov     cr0,eax
;; Ok, we're in protected mode, still 16-bit code segment though
    jmp     $+2                       ; Clear the cache
    lidt    fword ptr IDT_ptr         ; Load IDT
    lgdt    fword ptr GDT_ptr         ; Load GDT
    xor     ax,ax
    lldt    ax                        ; Load LDT with NULL
    mov     ax,_sTSS                  ; Load TR
    ltr     ax
  ; Data segment registers
    mov     ax,_sDATA
    mov     ds,ax
    mov     es,ax
  ; Extra segment registers
    mov     ax,_sVGA
    mov     fs,ax
    mov     ax,_sMONO
    mov     gs,ax
  ; Stack
    mov     ax,_sSTACK
    mov     ss,ax
    mov     esp,_sSTACK_limit - 4
    sti

After this I push the new target address on the stack and issue
a RETF to go there.

On the line above after the ";; Ok, we're in protected mode..."
I issue a JMP $+2.  I remember when writing this code that it was
a requirement to clear the cache.

-----
My question today is ... why does that need to be done?  Is it
only because the pre-decoded instructions are operating in the
legacy sense of the prior real-mode decoding engine?  And now
they need to be re-decoded using the protected-mode decoding
scheme?

And if so, would it be possible to put enough NOP instructions
after the MOV CR0,EAX instruction where it enters protected mode
to cause the CPU to never need a JMP instruction to clear the
cache because the NOPs would simply flood-fill it and it would
automatically decode future cache line reads using the new mode?

I don't see any practical use for this knowledge, but I'm more
curious than anything.

--
Rick C. Hodgin



Subject: Re: Entering Protected Mode
From: wolfgang kern
Newsgroups: comp.lang.asm.x86
Organization: KESYS-development
Date: Mon, 1 Jul 2019 04:30 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: nowh...@nospicedham.never.at (wolfgang kern)
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Mon, 1 Jul 2019 06:30:08 +0200
Organization: KESYS-development
Lines: 53
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <qfc2ma$8a6$1@gioia.aioe.org>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
Reply-To: nowhere@never.at
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: h2725194.stratoserver.net; posting-host="2a862229cbceb77f7e39a432ec600b94";
logging-data="22221"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+H1hE7NVFvUxtHVnQVasdUxnzruBYudTo="
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:66.0) Gecko/20100101
Thunderbird/66.0
Cancel-Lock: sha1:pI8mq0We1Vraw+R8A8VnclpXygg=
View all headers
On 19.06.2019 17:25, Rick C. Hodgin wrote:
In my custom OS kernel, I use this code to enter protected mode:

     cli                               ; Clear interrupts
     mov     eax,cr0
     or      al,1
     mov     cr0,eax
;; Ok, we're in protected mode, still 16-bit code segment though

Not at all!
it will remain in true real mode until change of CS [JMPF/RETF/IRET]

     jmp     $+2                       ; Clear the cache
^redundant^

     lidt    fword ptr IDT_ptr         ; Load IDT
     lgdt    fword ptr GDT_ptr         ; Load GDT

f..kword? I use 16:32 loads for both above
and I have LGDT run once during boot and LIDT in front of the CR0 change to allow other mode switches use the same code.

     xor     ax,ax
     lldt    ax                        ; Load LDT with NULL

I don't care LDT because never used

     mov     ax,_sTSS                  ; Load TR
     ltr     ax
   ; Data segment registers
     mov     ax,_sDATA
     mov     ds,ax
     mov     es,ax
   ; Extra segment registers
     mov     ax,_sVGA
     mov     fs,ax
     mov     ax,_sMONO
     mov     gs,ax
   ; Stack
     mov     ax,_sSTACK
     mov     ss,ax
     mov     esp,_sSTACK_limit - 4
     sti

my setting: ds=es=fs=gs=4GB FLAT, ss=64K

After this I push the new target address on the stack and issue
a RETF to go there.

I do a JMP far imm 16:32 right after MOV CRo,eax.
__
wolfgang



Subject: Re: Entering Protected Mode
From: Rick C. Hodgin
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Mon, 1 Jul 2019 12:11 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rick.c.h...@gmail.com (Rick C. Hodgin)
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Mon, 1 Jul 2019 05:11:01 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 15
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <503232fa-ea36-4ee9-a1b3-e4717f3e2ec0@googlegroups.com>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com> <qfc2ma$8a6$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Mon, 01 Jul 2019 12:11:01 +0000
Injection-Info: h2725194.stratoserver.net; posting-host="2a862229cbceb77f7e39a432ec600b94";
logging-data="1781"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+fpxb3k2JlK2dAtqrQOAaf3h4a9BJ5oUo="
User-Agent: G2/1.0
Cancel-Lock: sha1:/Ia/Z3qKhNL46rykSk1KnX6/+OQ=
View all headers
On Monday, July 1, 2019 at 12:43:08 AM UTC-4, wolfgang kern wrote:
On 19.06.2019 17:25, Rick C. Hodgin wrote:
     lidt    fword ptr IDT_ptr         ; Load IDT
     lgdt    fword ptr GDT_ptr         ; Load GDT

[fword?]?

FAR WORD (a 16:32 pointer):

    Search for "fword ptr":
    http://bytepointer.com/masm/ml51_readme.htm

--
Rick C. Hodgin



Subject: Re: Entering Protected Mode
From: rugx...@nospicedham.gmail.com
Newsgroups: comp.lang.asm.x86
Organization: A noiseless patient Spider
Date: Wed, 3 Jul 2019 07:07 UTC
References: 1
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rugx...@nospicedham.gmail.com
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Wed, 3 Jul 2019 00:07:32 -0700 (PDT)
Organization: A noiseless patient Spider
Lines: 22
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <c8f82df7-fa14-4bc2-9e5f-349ce2c277ef@googlegroups.com>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Injection-Date: Wed, 03 Jul 2019 07:07:32 +0000
Injection-Info: h2725194.stratoserver.net; posting-host="82dfebdf204109107a1e5db0cca06678";
logging-data="2626"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Z2DNRBSiTHHvRSZR9BdWR+c5TWdHKheU="
User-Agent: G2/1.0
Cancel-Lock: sha1:KPEIgGKt0bTK1ymyuQU8DutjcQY=
View all headers
Hi,

On Wednesday, June 19, 2019 at 2:59:42 PM UTC-5, Rick C. Hodgin wrote:

On the line above after the ";; Ok, we're in protected mode..."
I issue a JMP $+2.  I remember when writing this code that it was
a requirement to clear the cache.

I know nothing of pmode. I've never coded anything in it directly.

My question today is ... why does that need to be done?

I don't see any practical use for this knowledge, but I'm more
curious than anything.

FreeDOS HIMEMX 3.32 had a bug where it wouldn't work on some old
386 laptops that two people still sometimes used (at the time).
IIRC, the unofficial fix (3.33, albeit without official maintainer)
was to add "jmp $+2". But it wasn't needed in newer cpus, apparently.

Is that what you meant?



Subject: Re: Entering Protected Mode
From: Rick C. Hodgin
Newsgroups: comp.lang.asm.x86
Organization: Liberty Software Foundation
Date: Wed, 3 Jul 2019 12:12 UTC
References: 1 2
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rick.c.h...@gmail.com (Rick C. Hodgin)
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Wed, 3 Jul 2019 08:12:46 -0400
Organization: Liberty Software Foundation
Lines: 48
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <qfi5uk$s43$1@dont-email.me>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
<c8f82df7-fa14-4bc2-9e5f-349ce2c277ef@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: h2725194.stratoserver.net; posting-host="d61d38e697fd231255818f1c53744ec6";
logging-data="10581"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XbFBQbknke9FXnuwY6Fo2V2wB0Nadpto="
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
Thunderbird/60.7.2
Cancel-Lock: sha1:sJD6vpr9wBAL1OCH01YSvWmOeKI=
View all headers
On 7/3/2019 3:07 AM, rugxulo@nospicedham.gmail.com wrote:
Hi,

On Wednesday, June 19, 2019 at 2:59:42 PM UTC-5, Rick C. Hodgin wrote:

On the line above after the ";; Ok, we're in protected mode..."
I issue a JMP $+2.  I remember when writing this code that it was
a requirement to clear the cache.

I know nothing of pmode. I've never coded anything in it directly.

My question today is ... why does that need to be done?

I don't see any practical use for this knowledge, but I'm more
curious than anything.

FreeDOS HIMEMX 3.32 had a bug where it wouldn't work on some old
386 laptops that two people still sometimes used (at the time).
IIRC, the unofficial fix (3.33, albeit without official maintainer)
was to add "jmp $+2". But it wasn't needed in newer cpus, apparently.

Is that what you meant?

Possibly.  My kernel was initially written in the mid-90s, and I would
have had books and resources from the late 80s I drew from to design it.

It's very likely I assembled code samples from those various sources
and added bits here and there until I got it to work, as creating my
kernel was a trial-and-error format making baby steps as I went.  I
would get to a certain point and put a particular character in the
upper-left of the screen to know it made it there.  Later I created
my real-mode debugger and could single-step through even the initial
boot sector code, which was awesome.

Until then I did a lot of this:

     mov     ax,0b800h
     mov     es,ax
     mov     word ptr es:[di],0072eh   ; Display a dot
   @@:
     hlt
     jmp     @B

That kind of thing. :-)

--
Rick C. Hodgin



Subject: Re: Entering Protected Mode
From: wolfgang kern
Newsgroups: comp.lang.asm.x86
Organization: KESYS-development
Date: Thu, 4 Jul 2019 07:10 UTC
References: 1 2 3
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: nowh...@nospicedham.never.at (wolfgang kern)
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Thu, 4 Jul 2019 09:10:57 +0200
Organization: KESYS-development
Lines: 23
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <qfk986$135j$1@gioia.aioe.org>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
<c8f82df7-fa14-4bc2-9e5f-349ce2c277ef@googlegroups.com>
<qfi5uk$s43$1@dont-email.me>
Reply-To: nowhere@never.at
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: h2725194.stratoserver.net; posting-host="d27b4eb8360231731e80bea910910754";
logging-data="23183"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/qDZbgmYyHubs+V/pDyVO2+wGdmHj+dU="
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:66.0) Gecko/20100101
Thunderbird/66.0
Cancel-Lock: sha1:mx9Xi1dNIBVBXBW2V0kRWs8V77I=
View all headers
On 03.07.2019 14:12, Rick C. Hodgin wrote:

....
Until then I did a lot of this:

     mov     ax,0b800h
     mov     es,ax
     mov     word ptr es:[di],0072eh   ; Display a dot
   @@:
     hlt
     jmp     @B

That kind of thing. :-)

this tell that it's still in realmode with text-mode 03.

for PM32 check:
;assume DS flat 4G

C7 05 00 80 0B 00 50 70   mov word [0x000b8000],0x7050 ;"P"
__
wolfgang



Subject: Re: Entering Protected Mode
From: Rick C. Hodgin
Newsgroups: comp.lang.asm.x86
Organization: Liberty Software Foundation
Date: Fri, 5 Jul 2019 16:56 UTC
References: 1 2 3 4
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: rick.c.h...@gmail.com (Rick C. Hodgin)
Newsgroups: comp.lang.asm.x86
Subject: Re: Entering Protected Mode
Date: Fri, 5 Jul 2019 12:56:23 -0400
Organization: Liberty Software Foundation
Lines: 50
Approved: fbkotler@myfairpoint.net - comp.lang.asm.x86 moderation team.
Message-ID: <qfnvab$349$1@dont-email.me>
References: <c1ee5ee2-5687-496f-8e19-e5a490a737eb@googlegroups.com>
<c8f82df7-fa14-4bc2-9e5f-349ce2c277ef@googlegroups.com>
<qfi5uk$s43$1@dont-email.me> <qfk986$135j$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: h2725194.stratoserver.net; posting-host="54fc8781ef565012533900bb934f9fca";
logging-data="22273"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18a0Z2MfFWDvuDfNmHKs0TOV4lQ8KaTkG4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101
Thunderbird/60.7.2
Cancel-Lock: sha1:EZ9WWCM8Zwu7aJY7ipAc8zF5S80=
View all headers
On 7/4/2019 3:10 AM, wolfgang kern wrote:
On 03.07.2019 14:12, Rick C. Hodgin wrote:

...
Until then I did a lot of this:

     mov     ax,0b800h
     mov     es,ax
     mov     word ptr es:[di],0072eh   ; Display a dot
   @@:
     hlt
     jmp     @B

That kind of thing. :-)

this tell that it's still in realmode with text-mode 03.

for PM32 check:
;assume DS flat 4G

C7 05 00 80 0B 00 50 70   mov word [0x000b8000],0x7050 ;"P"

In pmode I would do this:

     mov     ax,_sVGA
     mov     es,ax
     mov     word ptr es:[0],0072eh   ; Display a dot
   @@:
     hlt
     jmp     @B

I would use positions at X,Y from 0,0 (upper-left) across the
line horizontally to indicate what I went through.  In some
places I would use a "-" in others a "+" to indicate which
part of the code went through, etc.

My startup upper-left bar would look like this:

     ....-...+....

And so on.  It was an easy to way indicate it was working
without yet having keyboard and mouse functions, or even
decent video functions.

Later on I had full handlers and wrote code more or less
like we see in DOS.

--
Rick C. Hodgin



1
rocksolid light 0.7.2
clearneti2ptor