Page 1 of 1

looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 3:15 am
by ggodw000
Hi, I have did this before many years ago, implementing code to enter pmode after preparing gdts and disabling interrupts. But recently I am working on the project after losing all the old code, I re-wrote the code. However, it is not working. As soon as I enter pmode by setting the bit in cr0 register, machine resets. I know it is tricky and I can not remember what i did to make it work. I am still trying to fix when the time allows.
Can someone look at my code to see what could be wrong?
I decided to paste the entire code here:
Being able to do is extremely important to me as it blocks all my further development efforts.
I am willing to pay for person who can nail this for me (nego) :)

HEre is the lowdown:
I am using 2 HYPER-V VMs. One is dev machine running XP and
masm32 6.1 + VS.NET2003 (VS is not necesary except for makefile)

I created vfdd (virtual fdd with dos bootable partition from which I launch the pmode program)
conn-fd-dev.ps1 will connect the fdd into dev VM so I can copy the file to it.
conn-fd-boot.ps1 will connect the fdd into target VM from which I run the program from

Code: Select all

=~=~=~=~=~=~=~=~=~=~=~= PuTTY log 2015.12.20 01:10:16 =~=~=~=~=~=~=~=~=~=~=~=
type c:\scrtype C:\scriptstype C:\scripts1\type C:\scripts\.gittype C:\scripts\conn-fd-boot.ps1
write-host "disconnecting floppy from minix development machine..."
Set-VMFloppyDiskDrive -VMName minix.dev.winxp -Path $null
write-host "connecting floppy to minix boot test machine..."
Set-VMFloppyDiskDrive -VMName minix.boot.system -Path j:\hyperv.fdds\fd0.vfd
write-host "starting minix.boot.system"
start-vm minix.boot.system
PS J:\users\Administrator> type c:\scrtype C:\scripts\conntype C:\scripts\conn-fd-boot.ps1type C:\scripts\conn-fd-dev.ps1
write-host "disconnecting floppy from minix boot test machine..."
Set-VMFloppyDiskDrive -VMName minix.boot.system -Path $null
write-host "connecting floppy to minix development machine ..."
Set-VMFloppyDiskDrive -VMName minix.dev.winxp -Path j:\hyperv.fdds\fd0.vfd
write-host "stopping minix.boot.system " 
stop-vm minix.boot.system -f
PS J:\users\Administrator> 
here are the program code, i will provide link to the whole software code along with makefile, libraries if it is necessary

https://github.com/gggh000/exp.git

once code loaded
simply type nmake pmsw to compile the code.

and to make the debugging easier, i made this neat function in the code called parseDesc that will print out every entry in the GDT verbosely.

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 3:58 am
by Techel
You put a bunch of code right here and want us to debug your code?

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 4:20 am
by Combuster
Start with using Bochs and reading the logs when it crashes.

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 4:36 am
by ggodw000
Combuster wrote:Start with using Bochs and reading the logs when it crashes.
what is bochs btw? ???

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 4:37 am
by ggodw000
ok got it. this is the one?

http://bochs.sourceforge.net/

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 4:56 am
by ggodw000
it has to be compiled, duhhh, another project. anything ready to use? is there any compiled installable binary can be available for bochs?
or any x86 emulator to suggest. appreciate it.
Thanks.,

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 4:58 am
by iansjack

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 5:01 am
by ggodw000
ok there is an bochs executable already available on the internet. downloaded and ran it. havent tried my program yet, but i can see it is a sweet stuff!! thanks a BUNCH! i am going to try what i can see when it crashes!

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 6:02 am
by ggodw000
I DONT understand this tool. I have tried HOURS trying to create bootable image and tried to boot. Whatever I managed to create, it never able to boot off it. None of the tools in it works. There are also mtools.zip with bunch of tools inside but really nothing worked. I have tried to create blank disk image, msdos disk image, copy from bootable cdrom image, all fails one way or the other. it mentions about freeDOS which I downloaded but it can not recognize. I am not sure if i should waste any of my time with this. In my opinion, it is hard to use and poorly written.
The help files says there are lot of uncertainty about the how the tool will function.

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 6:32 am
by ggodw000
ok pushing ahead... here is what i found out...

on hyper-v i found there is event viewer can be inspected for VM events.
and i found event log in the hyper-v log that VM has definitely caused a triple-fault obviously due to pmode enter is crashing.

now i recalled, i used the jmp $ to place it in each successive line to see when it crashes vs. when it does not.
and i found that exact point it is causing triple fault:

mov eax, cr0
or eax, 01
mov cr0, eax

mov ax, 10h
mov ds, ax <---- this caused triple fault, meaning if i put jmp $ before this line, machine stays on, but if i put jmp $ after this, machine triple-fault and reboots.

i created 3 entries in the GDT which the parseDesc displays as follows:
I am currently inspecting which field of it could have caused it, enough for today though.





==============
Descriptor No: 00
===============:
Descriptor Info:
---------------:
Segment base: 00000000
Segment size(lim): 00000000
Rx06[7] - Granularity (0: multiplier 1, 1: multiplier 4K):00
Rx06[6] - Default Rx size: (0: 16-bit, 1: 32-bit):00
Rx06[5:4] - AVL (for O/S use any way):00
Rx05[7] - Present bit: (0: not present, 1: present):00
Rx05[5] - DPL(desc.priv.lvl bit:00
Rx05[4] - Segment bit (0: system segment, 1: data/code segment):00
Rx05[3] - Executable bit (0: data/stack/non-exec, 1: code segment):00
Rx05[2] - X - E0:direction of data seg/E=1:privilege level
(E0: 0: segment expands up(data), 1: segment expands down(stack)):00
Rx05[1] - RW bit
(E1: 0: data segment can NOT be W, 1: data segment can be W:00
Rx05[0] - A bit(accessed, each time CPU accesses it)00
==============
Descriptor No: 01
===============:
Descriptor Info:
---------------:
Segment base: 00000000
Segment size(lim): 0003FFFF
Rx06[7] - Granularity (0: multiplier 1, 1: multiplier 4K):01
Rx06[6] - Default Rx size: (0: 16-bit, 1: 32-bit):00
Rx06[5:4] - AVL (for O/S use any way):00
Rx05[7] - Present bit: (0: not present, 1: present):01
Rx05[5] - DPL(desc.priv.lvl bit:00
Rx05[4] - Segment bit (0: system segment, 1: data/code segment):01
Rx05[3] - Executable bit (0: data/stack/non-exec, 1: code segment):01
Rx05[2] - X - E0:direction of data seg/E=1:privilege level
(E=1: privilege level):01
Rx05[1] - RW bit
(E=1: 0: code segment can NOT be read, 1: code segment can be read):01
Rx05[0] - A bit(accessed, each time CPU accesses it)00
==============
Descriptor No: 02
===============:
Descriptor Info:
---------------:
Segment base: 40000000
Segment size(lim): 0003FFFF
Rx06[7] - Granularity (0: multiplier 1, 1: multiplier 4K):01
Rx06[6] - Default Rx size: (0: 16-bit, 1: 32-bit):00
Rx06[5:4] - AVL (for O/S use any way):00
Rx05[7] - Present bit: (0: not present, 1: present):01
Rx05[5] - DPL(desc.priv.lvl bit:00
Rx05[4] - Segment bit (0: system segment, 1: data/code segment):01
Rx05[3] - Executable bit (0: data/stack/non-exec, 1: code segment):00
Rx05[2] - X - E0:direction of data seg/E=1:privilege level
(E0: 0: segment expands up(data), 1: segment expands down(stack)):00
Rx05[1] - RW bit
(E1: 0: data segment can NOT be W, 1: data segment can be W:01
Rx05[0] - A bit(accessed, each time CPU accesses it)00
==============
Descriptor No: 03
===============:
Descriptor Info:
---------------:
Segment base: 80000000
Segment size(lim): 0003FFFF
Rx06[7] - Granularity (0: multiplier 1, 1: multiplier 4K):01
Rx06[6] - Default Rx size: (0: 16-bit, 1: 32-bit):00
Rx06[5:4] - AVL (for O/S use any way):00
Rx05[7] - Present bit: (0: not present, 1: present):01
Rx05[5] - DPL(desc.priv.lvl bit:00
Rx05[4] - Segment bit (0: system segment, 1: data/code segment):01
Rx05[3] - Executable bit (0: data/stack/non-exec, 1: code segment):00
Rx05[2] - X - E0:direction of data seg/E=1:privilege level
(E0: 0: segment expands up(data), 1: segment expands down(stack)):01
Rx05[1] - RW bit
(E1: 0: data segment can NOT be W, 1: data segment can be W:01
Rx05[0] - A bit(accessed, each time CPU accesses it)00

Re: looking for help tshooting pmode, machine resetting

Posted: Sun Dec 20, 2015 3:10 pm
by ggodw000
i detailed everything in my blog about how i am debugging this
http://x86arch.blogspot.com/2015/12/how ... essor.html