OSDev.org

The Place to Start for Operating System Developers
It is currently Sat May 11, 2024 12:08 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: calling BIOS Interrupts from PMode
PostPosted: Fri Dec 08, 2006 5:51 pm 
Offline
Member
Member

Joined: Mon Oct 30, 2006 12:48 pm
Posts: 25
Since I don't want to include all storage drivers in the bootloader (loaded by the bootsector) I thought I might use the BIOS int 13h. The problem is that the bootsector has to enter PMode to setup the memory handlers and so on to know where to best put the kernel (1 MiB+ in size) so I can't use BIOS int 13h (also I want my OS to support all types of storage disks the computer can boot from therefor the BIOS it the best solution).
What I wonder is: Is switching from PMode -> Realmode the best solution or can i use V86 mode or does anyone has a better solution?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 08, 2006 7:47 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
I uses the going to real mode and back method in DexOS , its works very well, going to and from pmode every 512bytes, this on a floppy drive, is no slower than loading the same size file in windows from the floppy ,my descriptors are set on boot up to make real and pmode address the same.
It also lets me boot from USB fob, USB floppy, hdd, etc.
I have a very good pmode floppy driver, but its not used much.


Top
 Profile  
 
 Post subject: Re: calling BIOS Interrupts from PMode
PostPosted: Sat Dec 09, 2006 1:25 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Seven11 wrote:
Since I don't want to include all storage drivers in the bootloader (loaded by the bootsector) I thought I might use the BIOS int 13h. The problem is that the bootsector has to enter PMode to setup the memory handlers and so on to know where to best put the kernel (1 MiB+ in size) so I can't use BIOS int 13h (also I want my OS to support all types of storage disks the computer can boot from therefor the BIOS it the best solution).
What I wonder is: Is switching from PMode -> Realmode the best solution or can i use V86 mode or does anyone has a better solution?


For this I use "unreal mode", which is like real mode except one or more segment limits are changed to 4 GB.

In this case you need a buffer below 1 MB - fill the buffer full of data, copy the data anywhere you like, then repeat until everything is loaded.

To set it up, I use something like:

Code:
   call enableGateA20

;Load the GDT

        lgdt [tempGDT]

;Set GS as a flat segment that can access up to 4 GB

   cli
        mov eax,cr0            ;Turn protected mode on
   mov ebx,eax
        or al,1
        mov cr0,eax
   jmp .flush1
.flush1:
   mov ax,8            ;Set flat segment register
   mov gs,ax
   mov cr0,ebx            ;Turn protected mode off again
   jmp .flush2
.flush2:
   clr ax
   mov gs,ax
   sti

Code:
;Temporary GDT data (used for removing the 64 KB data segment limits)

         align 8
tempGDTaddress:      dw 0         ;Start of GDT null selector
tempGDT:      dw 0xff         ;GDT Limit
         dd tempGDTaddress

         dw 0xffff,0x0000   ;big data
         dw 0x9300,0x008f   ;bse=0 lim=4g rw


I only change the segment limit for GS, which is a little more hassle to use than DS and/or ES. For normal BIOSs DS and ES should work fine as flat segments, but in some rare cases (etherboot) the segment limits for DS and ES can be restored to default 64 KB limits.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 11:50 am 
Offline
Member
Member

Joined: Mon Oct 30, 2006 12:48 pm
Posts: 25
Brendan: that is exactlly what I planned to do... however your code seems to enter PMode the get into Real mode and I was thinking on doing the opposite...

My bootloader starts by probing BIOS for some info (PnP info, APM, VESA, RAM...) and then it fixes A20 and enters pmode to setup memory management and determine the best addr to place the kernel and a couple of datatables for paging and mem. handling. After that it checks which file to load as kernel (either for a boot-commandline or the osparam file or default filename), and it is here I wan't to call BIOS.

I have tried to make my own code... but all I get is exceptions or bochs errors, for instance:

Code:
cli

mov eax, cr0
and eax,7FFFFFFFh
mov cr0,eax ;needs to disable paging

pushfd
push dword code16sel
push dword real_mode_readsector
iretd
real_mode_readsector:
bits 16
jmp $


Here is the GDT
Quote:
gdtr
dw gdt_ent-gdt-1
dd gdt
gdt
gdt0
nullseg equ $-gdt0
dw 0,0,0,0

code32sel equ $-gdt0
dw 0xffff, 0h
db 0h, 9ah, 0cfh, 0h

data32sel equ $-gdt0
dw 0xffff, 0h
db 0h, 92h, 0cfh, 0h

code16sel equ $-gdt
dw 0xffff, 0h
db 0h, 9ah 0fh, 0
gdt_end


And all I get is a error on 18h:7c48h according to bochs even that my bootloader is loaded by the bootsector to addr 10000h...

Any pointers?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 1:30 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

Seven11 wrote:
My bootloader starts by probing BIOS for some info (PnP info, APM, VESA, RAM...) and then it fixes A20 and enters pmode to setup memory management and determine the best addr to place the kernel and a couple of datatables for paging and mem. handling. After that it checks which file to load as kernel (either for a boot-commandline or the osparam file or default filename), and it is here I wan't to call BIOS.


Don't switch from real mode to protected mode unless you're finished with real mode! ;)

For example, enable A20, switch from real mode to "unreal mode", probe the BIOS for some info, setup memory management, determine the best place for the kernel and datatables, load the kernel, etc, and only then switch to protected mode (or long mode).

In general there's only one sane reason to switch back to real mode or use virtual 8086 mode, and that's to use video functions long after the OS has booted, however this is becoming increasingly debatable...

Most normal users currently expect hardware accelerated 2D and 3D, support for multiple monitors, etc. By the time you've got the rest of your OS working, it's possible that users will expect support for 3D monitors (stereoscopic, layered LCD, etc) and other stuff. For most normal users there's very little difference between no video support and legacy/BIOS video support, so I'd be tempting not to bother much. IMHO it's enough to allow a default video mode to be set during boot (i.e. before switching to protected mode or long mode), and use the time you would've spent trying to get legacy real mode video code to work after boot on something else (and have a clean "legacy free" OS).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 09, 2006 6:02 pm 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2006 12:00 am
Posts: 1444
Brendan wrote:
Most normal users currently expect hardware accelerated 2D and 3D, support for multiple monitors, etc. By the time you've got the rest of your OS working, it's possible that users will expect support for 3D monitors (stereoscopic, layered LCD, etc) and other stuff. For most normal users there's very little difference between no video support and legacy/BIOS video support, so I'd be tempting not to bother much. IMHO it's enough to allow a default video mode to be set during boot (i.e. before switching to protected mode or long mode), and use the time you would've spent trying to get legacy real mode video code to work after boot on something else (and have a clean "legacy free" OS)
Cheers,

Brendan

Then very same "normal users" would like to boot there OS's as fast as possible and do not want pages of info flashing in front of there eyes, that they do not understand.
So do not get any legacy info, just boot as fast as possible to pmode ;).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 10, 2006 8:57 am 
Offline
Member
Member

Joined: Wed Dec 06, 2006 6:34 am
Posts: 26
Can someone wright how to do it from v86 mode.

_________________
Just do it


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: encryptdthat, Google [Bot] and 43 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group