How To use INT DOS in Protected Mode
Posted: Thu Oct 12, 2006 5:02 am
Hi I have project to make program in protected mode. I want use int from DOS in protected mode. Anyone can help me
The Place to Start for Operating System Developers
http://f.osdev.org/
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; VideoModeInt - Uses interrupt 10h from real mode to change text modes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
VideoModeInt:
pushad
push es
mov word [RealModeAX],ax
mov word [RealModeBX],bx
mov word [RealModeCX],cx
mov word [RealModeDX],dx
;; Need to save our stack stuff
mov eax,esp
mov [ProtectedModeStackPointer],eax
mov byte [RealModeError],0
call DisableAllIRQs ; Turn off every IRQ (bitmap is 0FFFFFFFFh or all off)
mov al,11h
out 020h,al
out 0A0h,al
mov al,08h
out 021h,al
mov al,070h
out 0A1h,al
mov al,4
out 021h,al
mov al,2
out 0A1h,al
mov al,1
out 021h,al
out 0A1h,al
jmp 28h:RealModeVGA
use16
RealModeVGA:
mov ax,30h
mov ds,ax
mov ss,ax
nop
mov bx,[RealModeCS]
push bx
lea bx,[DoVideoRealMode]
push bx
mov eax,cr0
and al,0xFE
mov cr0,eax
retf
DoVideoRealMode:
mov ax,cs ; Save CS to AX
mov ds,ax ; Put DS to CS
mov ax,[StackSegment] ; Save original stack segment to AX
mov ss,ax ; Replace original stack segment
mov ax,[StackPointer] ; Save the stack pointer to AX
movzx esp,ax ; and Replace original stack pointer (force 16 bit)
nop ; Take a CPU clock tick
mov es,ax ; Update ES with AX
mov fs,ax ; Update FS with AX
mov gs,ax ; Update GS with AX
;;;;;;;;;;;;;;;;;;;;;;;
;; Load real mode IDTR
;;;;;;;;;;;;;;;;;;;;;;;
lidt [RIDTR] ; Load original IVT from 0000:0000
push cs ; Put CS on stack
pop ds ; Put CS from stack to DS
push ds ; Save DS to the stack
pop es ; Update ES with DS from stack
mov al,0 ; Re-enable realmode IVT by turning on all IRQs
out 0A1h,al ; Updates lower 7 IRQs
out 021h,al ; Updates upper 8 IRQs
sti ; Re-enable interrupts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Now to do the real mode interrupt
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mov ax,word [RealModeAX]
mov bx,word [RealModeBX]
mov cx,word [RealModeCX]
mov dx,word [RealModeDX]
int 10h
jnc .NoError
mov byte [RealModeError],1
.NoError:
mov word [RealModeAX],ax
mov word [RealModeBX],bx
mov word [RealModeCX],cx
mov word [RealModeDX],dx
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Going back to Protected Mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
cli ; Turn off interrupts
lgdt [GDTR] ; Load GDTR
lidt [IDTR] ; Load IDTR
mov eax,cr0
or al,1
mov cr0,eax
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Jump to Protected Mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
jmp 10h:ReturnToProtectedMode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 32-bit Protected Mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
use32
ReturnToProtectedMode:
mov ax,18h
mov ds,ax
mov es,ax
nop
mov fs,ax
mov gs,ax
mov ax,08h
mov es,ax
mov ss,ax
mov eax,[ProtectedModeStackPointer]
mov esp,eax ; Re-establish our ESP
mov al,0FFh ; Disable realmode IVT by turning on all IRQs
out 0A1h,al ; Updates lower 7 IRQs
out 021h,al ; Updates upper 8 IRQs
call RemapPIC ; Remap to smiddyOS
call EnableAllIRQs ; Enabled already mapped IRQs
sti ; Turn them interrupts back oh, honky!
pop es
popad
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RealModeError db 0
RealModeAX dw 0
RealModeBX dw 0
RealModeCX dw 0
RealModeDX dw 0
ProtectedModeStackPointer dd 0
I have only tried INT 10h, though I suspect you can do it with all the others too, except DOS INTs, unless you are running on top of DOS.xavmoss wrote:Thx. I wander if I want use all the interrupt, can I use the same way?
That's hadly surprising when you consider that floppy drivers spend almost all of their time waiting for the sectors to finally come in: Whether it takes 100 or 100000 cycles to send a command is somewhat irrelevant as long as the floppy drive needs several dozen milliseconds to execute the command.Dex wrote:I use this method for a special floppy driver that goes to realmode and back every 512 bytes, to load a program, when timed to load the same file in windows and using this driver, they are about the same in speed
In protected-mode you're meant to write your own drivers. If you want to use BIOS services just stick to real-mode. In case that you really need the DOS calls design your system as a shell running on top of it.xavmoss wrote:I working on DOS, so I can use the same way for DOS interrupt, I want use DOS interrupt in protected mode
Please qualify this statement. I disagree, if BIOS is available why not use it, that makes your job that much easier, instead of reading hardware specs and writing tons of drivers if you're only doing it as a hobby your mainly just trying to accomplish things within your own system, not the world of systems. In his case he is working on top of DOS, since DOS does everything for you, why not use it. Also, there are 32-bit BIOSes out there that can be used within protected mode instead of writing your own lowlevel routines. I think it makes sense to write to what is there and worry about low level programming once you are familiar with your own system. Hardware timing and port programming is far more difficult starting out it can be over whelming. Protected mode is meant to protect and isolate seperate processes, it is not meant for writing low level drivers. Your point about performance on the other hand is right on par, why worry about performance at first. Get it to work, then optimize it until you've tweaked it to a point where not another tweak will make it faster. I am a hoddyist OS developer, not a professional who has the resources and time to develop tons of drivers for others, personally, perhaps you are?gaf wrote:In protected-mode you're meant to write your own drivers. If you want to use BIOS services just stick to real-mode. In case that you really need the DOS calls design your system as a shell running on top of it.
But this is the point, 99% of call are not speed related eg: mode change, even in dos, no one does speed critical stuff using dos functions, but write there own functions, eg: graphics put pixelThat's hadly surprising when you consider that floppy drivers spend almost all of their time waiting for the sectors to finally come in: Whether it takes 100 or 100000 cycles to send a command is somewhat irrelevant as long as the floppy drive needs several dozen milliseconds to execute the command.
Nevetheless all modern operating systems (f.ex. linux, windows) use their own low-level drivers. The x86 BIOS is merely a relic of the 16bit real-mode days that is today hardly ever used for anything more than boot-strapping. It never managed to make the step to a modern architecture and its support for modern devices is still very limited.smiddy wrote:Protected mode is meant to protect and isolate seperate processes, it is not meant for writing low level drivers.
That's the same mistake that Microsoft made with its Win9x series. Danger is that your system will never be anything more than an advanced shell that inherits all the mistakes of the underlying system.smiddy wrote:In his case he is working on top of DOS, since DOS does everything for you, why not use it.
You seem to somewhat overestimate the amount of drivers that would be needed. Almost all of the devices that can be found in a modern computer are based on an open standard, so that you only have to write a single driver for each device class. I would also be very surprised if the BIOS supported any of the non-standard device..smiddy wrote:If BIOS is available why not use it, that makes your job that much easier, instead of reading hardware specs and writing tons of drivers.