Directly entering PM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Directly entering PM

Post by mrkaktus »

Could I enter PM, and then in some ways detect size of RAM?

I mean that I want to go to PM without doing anything in RM. So I want detect from PM size of RAM (like by this ACPI function E801 in RM). And manage other stuff from there. Is this possible, or I need to do some things in RM that I can't do in PM ?
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Directly entering PM

Post by JAAman »

afaik, there is no way to use these functions in PMode -- they must be called from RMode
blackcatcoder
Member
Member
Posts: 132
Joined: Wed Nov 03, 2004 12:00 am
Location: Austria
Contact:

Re: Directly entering PM

Post by blackcatcoder »

use e820 method in real mode!
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Directly entering PM

Post by mrkaktus »

yes I know that I need to use e820 :) I just didn't remember the number so i write that one that i was thinking that is wright :P.

Ok, I need to use e820 to read memory map.
I also need to turn on A20 gate,
and I need to detect is processor 32bit
(I assume that processor must be in RM mode).
Then load kernel, set GDT, and enter PM.

I want to do all that things in bootloader.
To fit in 512 bytes i will not use FAT12 but direct kernel loading from sectors.
But I have one problem, detecting 386 or better processor (32bit support)
takes to much space in my code because I need to go with that detection
by 8086, 80286 and then test 80386.

So, is there some code to detect easily only that processor is:
-286 or earlier (16bit)
-386 or better (32bit/64bit)?

Did i need to do something more in RM that I cant do in PM ?
rexlunae
Member
Member
Posts: 134
Joined: Sun Oct 24, 2004 11:00 pm
Location: North Dakota, where the buffalo roam

Re: Directly entering PM

Post by rexlunae »

This might not work for you, but if you use GRUB as your bootloader, it can detect the memory available to you and pass that to your kernel. It also handles getting into PM and enabling A20, the tedious stuff that sucks to deal with.
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Directly entering PM

Post by mrkaktus »

PM is not a problem for me, thesame E820 or A20. I only need to find that processor detection code somewhere :). And I want to have fully independent OS that I could boot evrywhere just from Floppy.

So, if somebody knows such code for detection 32bit CPU please tell me.
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Directly entering PM

Post by carbonBased »

I too, when writing my own bootloader, tried to compress the 386+ detection code to make it as small as possible. I wasn't able to. The detection code is fairly long and tedious.

It's unreasonable, in my opinion, to try and get all this functionality into 512 bytes. It's fun to try, but eventually you'll need to load a second stage loader. Even my most minimal (and functional) loader ended up loading a sizeable second stage portion.

Cheers,
Jeff
Legend
Member
Member
Posts: 195
Joined: Tue Nov 02, 2004 12:00 am
Contact:

Re: Directly entering PM

Post by Legend »

You could directly probe the memory in pmode, but it might not be without other issues.
*post*
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Directly entering PM

Post by JAAman »

Code: Select all

   mov ax,0xF000
   pushf
   push ax
   popf
   pushf
   pop ax
   and ah,0xF0
   js    no386
   jz    no386
   popf
is386:
this is the smallest 386detect code i've seen js will jmp on sign: only on 8086/88

the jz will jump on bits 12-15 =0 only on 286

on the 386 the bits will be set high so it will not be zero and bit 15 will be forced to clear meaning sign=0 so if you get to the is386 lable then you have a 386
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Directly entering PM

Post by carbonBased »

Seems reasonable, but this method is not certified by intel to work, so there *may* be incompatibilties. I'm not speaking from experience, as I've never tried this... In fact, I'm very much impressed with the brieviety of this code, and am anxious to see the results... however, I've also never seen it in a formal doc, so I'm somewhat doubtful of it's widespead effect.

Cheers,
Jeff
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Directly entering PM

Post by JAAman »

it should always work

its the same as the intel method except the intel method checks to see if bits 12-14 can be changed --which is not neccessary:

the 286 chip in real mode will always have the last value loaded into bits 12-13-- they cannot be modified in real mode (and will always boot with them clear)

since the 286 is incapable of returning to real mode and bits 12-15 cannot be altered in real mode, they will ALWAYS contain the reset values (which are all clear)

i actually do have an intel page here that says bits 12-15 are always clear in real mode (document: Processor Identification and Feature Determination, section 10.2:Identification of Earlier Intel Architecture Processors, page 10-3) i don't have a document number though all i have is 1 printed page and a quick search on developer.intel.com didn't show any documents with the same name
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Directly entering PM

Post by mrkaktus »

Thank you for that code :). Now I am using this:

Code: Select all

     pushf                                           ; Odluz FLAGS na Stos
     xor ax,ax                                       ;\  
     push ax                                         ; |-Wyzeru FLAGS przy uzyciu AX
     popf                                            ;/
     pushf                                           ;\Pobierz stan FLAGS do AX
     pop ax                                          ;/
     popf                                            ; Przywruc FLAGS ze Stosu po tescie
     and ax, 0xF000                                  ; Czysc wszystkie bity oprucz 12 do 15
     cmp ax, 0xF000                                  ; Sprawdz czy ustawione na 1
     jne LEPSZY_86                                   ; Jak nie to nowszy lub rowny 286
       
         ; Jezeli dotarles tutaj to procesor jest 8086/88 lub 80186/188
         ; Zatrzymaj prace Bootloadera.
         jmp ERROR_1

     LEPSZY_86:                                      ; Sprawdz czy 286 czy lepszy
     pushf                                           ; Odluz FLAGS na Stos
     push 0xF000                                     ;\_Zapisz do FLAGS 0xF000
     popf                                            ;/
     pushf                                           ;\_Pobierz wartosc FLAGS 
     pop ax                                          ;/ spowrotem do AX
     popf                                            ; Przywruc FLAGS ze Stosu po tescie
     and ax, 0xF000                                  ;\_Sprawdz czy sa nadal wyzerowane
     cmp ax, 0                                       ;/
     jnz LEPSZY_286                                  ; Jezeli nie to lepszy od 286

         ; Jezeli dotarles tutaj to procesor jest 80286
         ; Zatrzymaj prace bootloadera
         jmp ERROR_1

     LEPSZY_286:                                     ; Procesor jest 32bitowy
:).

I have one more question. Did I need to turn on A20 before entering PM?
I was thinking about doing this in PM to take all metods, to have full compatibility.

So my main question is :

What I NEED to do in RM ?
User avatar
carbonBased
Member
Member
Posts: 382
Joined: Sat Nov 20, 2004 12:00 am
Location: Wellesley, Ontario, Canada
Contact:

Re: Directly entering PM

Post by carbonBased »

You can enable A20 at any time, rmode or pmode.

As I mentioned before (not sure if it's in this thread or not), if you want to use vm86, be sure to save off a copy of the rmode idt (granted, this can also be done in pmode, unless (like mine) your pmode initialization code overwrites it).

That's about it... there's not a whole lot *required* to be done in rmode.

Cheers,
Jeff
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Directly entering PM

Post by mrkaktus »

Thanks :) Now I only need to find A20 code that will work on my PCs :P
mrkaktus
Member
Member
Posts: 102
Joined: Thu Jan 06, 2005 12:00 am
Location: Poland - Gdansk
Contact:

Re: Directly entering PM

Post by mrkaktus »

Yeah! I have done this bootloader :).

It contains 32bit processor detection, 3 methods of RAM detection (E820, E801, 88), part that loads the Kernel and PM initialisation :). I just put GDT section as a block of mem that is loaded like a kernel from floppy to specified memory adress :)). Now I will work with that A20 gate.
Post Reply