the compatibility between bochs and masm

Programming, for all ages and all languages.
Post Reply
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

the compatibility between bochs and masm

Post by david »

I don't think bochs could run 32-bit masm routiue(compiled by masm). but 16-bit masm program is ok.

32-bit masm code:

Code: Select all

	.386P
TEXT segment para use32 public 'CODE'
	assume cs:TEXT, ds:nothing, es:nothing, ss:nothing
Start:
	xor ax, ax
	xor bx, bx
	
	push 07C0h
	push @F
	retf
@@:
	mov ax, cs
	mov ds, ax
	mov es, ax
TEXT ends
	End Start
then, compile and link it by masm.

but use bochs to debug it, the disassembling code is :

Code: Select all

<bochs:3> u /10
00007c00: (                    ): xor eax, eax              ; 6633c0
00007c03: (                    ): xor ebx, ebx              ; 6633db
00007c06: (                    ): push 0x07c0               ; 68c007
00007c09: (                    ): add byte ptr ds:[bx+si], al ; 0000
00007c0b: (                    ): push 0x0011               ; 681100
00007c0e: (                    ): add byte ptr ds:[bx+si], al ; 0000
00007c10: (                    ): retf                      ; cb
00007c11: (                    ): mov ax, cs                ; 668cc8
00007c14: (                    ): mov ds, ax                ; 668ed8
00007c17: (                    ): mov es, ax                ; 668ec0
they are wrong, why?

bochs can't support 32-bit masm routine?

I change use32 to use16, it will be ok.
Just For Fun
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: the compatibility between bochs and masm

Post by NickJohnson »

Are you in protected mode? 32-bit code won't work very well in real mode...
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: the compatibility between bochs and masm

Post by neon »

masm and bochs have nothing to do with each other. I am suspecting something else is at fault.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: the compatibility between bochs and masm

Post by david »

My code is in real-address mode.

but bochs also has the same problem in protected-mode.

I tested it before.
Just For Fun
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: the compatibility between bochs and masm

Post by Brendan »

Hi,

You show some initial boot loader code (which suggests to me that you haven't gone much further than initial boot loader code); and make the mistake of thinking that 32-bit code will run in real mode (and assume it's Boch's fault that the disassembly is messed up when it's disassembling 32-bit code as 16-bit code because of your mistake); and then you expect us to believe that 2 different products (MASM and Bochs) that have been used successfully by lots of people for many years don't work?
david wrote:but bochs also has the same problem in protected-mode.

I tested it before.
Not likely...


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.
ru2aqare
Member
Member
Posts: 342
Joined: Fri Jul 11, 2008 5:15 am
Location: Hungary

Re: the compatibility between bochs and masm

Post by ru2aqare »

david wrote: they are wrong, why?
Because you told masm to emit code that assumes the processor uses 32-bit operands by default. Changing 'use32' to 'use16' emits code that assumes the processor uses 16-bit operands by default.

However if you load the aforementioned code into Bochs, the Bochs CPU is still in real mode, hence it will assume 16-bit operands, and disassemble/interpret your code the wrong way. If you change Bochs into protected mode, it will disassemble your code correctly.

This means that there is no incompatibility or such between the two software. The expected CPU modes were different, and you were using the programs the wrong way.
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: the compatibility between bochs and masm

Post by david »

hey, guys

Thank you for answer my question, In fact I met this problem when i debug some code in protected-mode written by MASM and VC. But i don't want to show you all my code. Because I think you will understand it hardly.(reason: less comments, more functions, etc). I met this question two or three months ago, but I have to resolve it now. Luckly, I found the same problem in real-address mode(the code I show you), so I show you the boot code to look for help. The code is so easy.

Perhaps you are right, I will debug my code seriously tomorrow.

Good night.
Just For Fun
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: the compatibility between bochs and masm

Post by neon »

It may also help posting the version of MASM and Bochs that you are using.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: the compatibility between bochs and masm

Post by david »

MASM: Microsoft (R) Macro Assembler Version 6.15.8803

Bochs: Bochs 2.3.5
Just For Fun
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: the compatibility between bochs and masm

Post by neon »

Try using the newest bochs version (relivant thread)
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
david
Member
Member
Posts: 93
Joined: Tue Aug 21, 2007 4:22 am
Location: Beijing.China
Contact:

Re: the compatibility between bochs and masm

Post by david »

It is OK now! :D
I set D/B=1(D/B in segment descriptor) in my code, data and stack segment descriptor.Then, OK.
D/B=0 before i change it.
Just For Fun
Post Reply