Protected mode from MS-DOS

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Protected mode from MS-DOS

Post 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.
Last edited by Holus on Tue Oct 11, 2011 5:52 pm, edited 1 time in total.
Computer says NOOOO
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: Protected mode from MS-DOS

Post by AndrewBuckley »

how are you using EBX in dos?
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Protected mode from MS-DOS

Post 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.
Computer says NOOOO
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Protected mode from MS-DOS

Post 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.
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: Protected mode from MS-DOS

Post by AndrewBuckley »

why is your jump in a bd string?
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Protected mode from MS-DOS

Post 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?
Computer says NOOOO
AndrewBuckley
Member
Member
Posts: 95
Joined: Thu Jan 29, 2009 9:13 am

Re: Protected mode from MS-DOS

Post by AndrewBuckley »

are you booting from windows 95's bootloader or its command.com?
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Protected mode from MS-DOS

Post 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!!!
Computer says NOOOO
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Protected mode from MS-DOS

Post 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.
Computer says NOOOO
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Protected mode from MS-DOS

Post 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
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.
User avatar
xenos
Member
Member
Posts: 1118
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Protected mode from MS-DOS

Post 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.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Protected mode from MS-DOS

Post by Holus »

I'm to stubborn to use software designed by others. But sometimes you just have to drop your stubbornness.
Computer says NOOOO
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: Protected mode from MS-DOS

Post 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
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Protected mode from MS-DOS

Post 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.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Protected mode from MS-DOS

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply