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?
calling BIOS Interrupts from PMode
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.
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.
Re: calling BIOS Interrupts from PMode
Hi,
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:
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 this I use "unreal mode", which is like real mode except one or more segment limits are changed to 4 GB.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?
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: Select all
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: Select all
;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
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.
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:
Here is the GDT
Any pointers?
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: Select all
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 $
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...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
Any pointers?
Hi,
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
Don't switch from real mode to protected mode unless you're finished with real mode!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.
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.
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.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
So do not get any legacy info, just boot as fast as possible to pmode .