Page 1 of 2

Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 5:39 pm
by Holus
I’m tired off making bootdisks for testing so I thought “I make a simple .ASM to start protected mode directly from MS-DOS”.

In the boot variant everything goes fine but when I made this version the computer started to reboot.

I stripped it till I got only the pmode switch.
But still rebooting and “no fun”

Someone can help me finding the problem?

Code: Select all

[ORG 0x0100]      
JMP BOOTLOADER

GDTINFO:
 	  	DW GDT_END - GDT - 1
 	  	DD GDT
 
GDT		DD 0x0000,0x0000  ; entry 0 is always unused
GDT_CODE	DB 0xFF, 0xFF, 0x00, 0x00, 0x00, 10011010b, 11001111b, 0x00
GDT_DATA    	DB 0xFF, 0xFF, 0x00, 0x00, 0x00, 10010010b, 11001111b, 0x00
GDT_END:


TMP_INFO	TIMES 0xFF	DB	0xFF
VESA_VER			DW	0xFFFF
VESA_MEM			DW	0xFFFF

BOOTLOADER:
        MOV BX,CS
        MOV DS,BX
        SHL BX,4
        ADD BX,PMODE                            ; PMODE = FUNCTION TO JUMP TO
        MOV WORD [JMPSTRING+1],BX       ; BX = CODE ADDRESS WHEN SEGMENT 0
;        JMPSTRING       DB      0xEA,0x00,0x00,0x08,0x00

        XOR AX,AX
        MOV ES,AX
        MOV DS,AX

	CLI

        MOV AL,0xFF
        OUT 0x21,AL
        OUT 0xA1,AL

        LGDT [GDTINFO]

        MOV EAX,CR0         
        OR EAX, 1
        MOV CR0, EAX
        ;JMP PMODE
        JMPSTRING       DB      0xEA,0x00,0x00,0x08,0x00
	
EXIT:
	INT 0x20
JMP EXIT
BITS 32
PMODE:
        MOV AX,0x10
        MOV DS,AX
        MOV ES,AX
        MOV SS,AX

MOV EAX,0x0B8000
MOV EBX,0x000160

NEXT_PIXEL:
        MOV [EAX+EBX],EBX
        SUB EBX,4
        JNZ NEXT_PIXEL 
STOP:
JMP STOP
First I thought the problem was the "JMP PMODE" could not work because MSDOS starts in a segment like [0F53:0100] (segment is always less then 0x1000)

I try solving this problem by adding the JUMPSTRING but still the same rebooting.

When I “debug.com” it with only the jumpcode it seems to work and the jump is to the right place.
But there is still something wrong.

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 5:48 pm
by AndrewBuckley
how are you using EBX in dos?

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 5:54 pm
by Holus
Merlin wrote:how are you using EBX in dos?
That's not the problem. I removed it in the "POST" because it was just junk. :D
I find it strange even debug.com understands EDI, EAX etc. Only the trace is not allway the right display. But I works fine.

Just to be sure I compiled it again. And had the same result.

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:04 pm
by thepowersgang
Make sure you are using a basic MSDOS system, without things like XMM or "DOS Extenders". It may already be in Protected mode, and running the user code in VM8086 mode instead.

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:08 pm
by AndrewBuckley
why is your jump in a bd string?

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:11 pm
by Holus
thepowersgang wrote:Make sure you are using a basic MSDOS system, without things like XMM or "DOS Extenders". It may already be in Protected mode, and running the user code in VM8086 mode instead.
#-o That could be the problem.

c:\>ver
Windows 95. [Version 4.00.1111]

How can I check this? Or do you know the answer when you see the DOS version?

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:15 pm
by AndrewBuckley
are you booting from windows 95's bootloader or its command.com?

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:17 pm
by Holus
Merlin wrote:why is your jump in a bd string?
Because a JMP 0x08:PMODE would jump to 0x08:PMODE and that is not where the code is.
Maybe this is not thinking straight.

But JMP 0x08:PMODE doesnt work. I think it's the VM8086 problem and "thepowersgang" is my hero!!!

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 6:19 pm
by Holus
Merlin wrote:are you booting from windows 95's bootloader or its command.com?
It's command.com

(it's a windows 95 bootdisk looks like old MS-DOS)
Not the graphical interface.

Re: Protected mode from MS-DOS

Posted: Tue Oct 11, 2011 8:05 pm
by Brendan
Hi,
Holus wrote:
thepowersgang wrote:Make sure you are using a basic MSDOS system, without things like XMM or "DOS Extenders". It may already be in Protected mode, and running the user code in VM8086 mode instead.
How can I check this?
Code can check the "VM" bit in EFLAGS to determine if it's running in real mode or V86 mode.

For e.g.:

Code: Select all

    pushfd
    pop eax
    test eax,(1 << 17)
    jne .currently_in_V86_mode
    je .currently_in_real_mode

Cheers,

Brendan

Re: Protected mode from MS-DOS

Posted: Wed Oct 12, 2011 2:09 am
by xenos
berkus wrote:Why not use a nice friendly emulator like Bochs or QEMU?
I guess there is always some point at which everyone wants to run some code on real hardware ;)

My recommendation is to write a multiboot compliant kernel and to boot it with GRUB. You can simply install GRUB on your hard drive and use it to boot whatever you like. You don't even need an extra partition for your kernel.

Re: Protected mode from MS-DOS

Posted: Wed Oct 12, 2011 5:05 am
by Holus
I'm to stubborn to use software designed by others. But sometimes you just have to drop your stubbornness.

Re: Protected mode from MS-DOS

Posted: Wed Oct 12, 2011 6:26 am
by AJ
Hi,
Holus wrote:I'm to stubborn to use software designed by others.
So what is MS-DOS if not "software designed by others"? At least with something like GRUB you can view / modify the source code.

Cheers,
Adam

Re: Protected mode from MS-DOS

Posted: Wed Oct 12, 2011 6:57 am
by Chandra

Code: Select all

LGDT [GDTINFO]
That's a big issue. LGDT expects a Linear Address. You cannot simply supply the offset of your GDT pointer.

Re: Protected mode from MS-DOS

Posted: Wed Oct 12, 2011 7:15 am
by Combuster
Chandra wrote:

Code: Select all

LGDT [GDTINFO]
That's a big issue. LGDT expects a Linear Address. You cannot simply supply the offset of your GDT pointer.
Not exactly, LGDT takes a reference to a GDTR structure as a regular memory operand. Instead, the problem is the GDTR.offset which should be the field holding the linear address where a virtual one is provided (i.e. your GDT is not some random offset into the IVT)