looking for help tshooting pmode, machine resetting

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

looking for help tshooting pmode, machine resetting

Post 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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: looking for help tshooting pmode, machine resetting

Post by Techel »

You put a bunch of code right here and want us to debug your code?
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: looking for help tshooting pmode, machine resetting

Post by Combuster »

Start with using Bochs and reading the logs when it crashes.
"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 ]
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post by ggodw000 »

Combuster wrote:Start with using Bochs and reading the logs when it crashes.
what is bochs btw? ???
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post by ggodw000 »

ok got it. this is the one?

http://bochs.sourceforge.net/
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post 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.,
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: looking for help tshooting pmode, machine resetting

Post by iansjack »

ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post 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!
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post 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.
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post 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
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
ggodw000
Member
Member
Posts: 396
Joined: Wed Nov 18, 2015 3:04 pm
Location: San Jose San Francisco Bay Area
Contact:

Re: looking for help tshooting pmode, machine resetting

Post by ggodw000 »

i detailed everything in my blog about how i am debugging this
http://x86arch.blogspot.com/2015/12/how ... essor.html
key takeaway after spending yrs on sw industry: big issue small because everyone jumps on it and fixes it. small issue is big since everyone ignores and it causes catastrophy later. #devilisinthedetails
Post Reply