DJGPP Inline Help

Programming, for all ages and all languages.
Post Reply
jake12
Posts: 14
Joined: Mon Nov 24, 2008 7:03 pm

DJGPP Inline Help

Post by jake12 »

What is the format for DJGPP?

Code: Select all

__asm__ __volatile("movl %%cr0, %%eax":"=a"(cr0))::"eax");
When I try to compile my source this line causes an error:
test.c:57: error: expected ';' before ':' token
It looks right to me, but I am no guru. thanks
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: DJGPP Inline Help

Post by Troy Martin »

I think DJGPP takes Intel-syntax assembly.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
jake12
Posts: 14
Joined: Mon Nov 24, 2008 7:03 pm

Re: DJGPP Inline Help

Post by jake12 »

Thoughts so. I am new to this inline asm using DJGPP, any chance you might show me how to structure that inline code I posted above. I am trying to store a copy of the cr0 register in the cr0 variable (not shown). thanks
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: DJGPP Inline Help

Post by Combuster »

its not that - you have a closing brace too much in the middle.

And as long as you haven't told gcc to use something other than AT&T syntax, it will expect AT&T syntax.
"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 ]
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: DJGPP Inline Help

Post by Troy Martin »

Combuster wrote:And as long as you haven't told gcc to use something other than AT&T syntax, it will expect AT&T syntax.
Really? I'd assume a DOS/Win port of gcc would expect Intel syntax.
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Zenith
Member
Member
Posts: 224
Joined: Tue Apr 10, 2007 4:42 pm

Re: DJGPP Inline Help

Post by Zenith »

Well, the point of AT&T syntax was to "standardize" assembly syntax throughout platforms.

GCC will expect AT&T syntax on EVERY platform it is compiled for, unless specified differently...
"Sufficiently advanced stupidity is indistinguishable from malice."
jake12
Posts: 14
Joined: Mon Nov 24, 2008 7:03 pm

Re: DJGPP Inline Help

Post by jake12 »

I pulled that line right out of the wiki, the code is used for probing for RAM. The link is Detecting Memory. So, I took out the extra parenthesis and it worked but now it faults on this line:

Code: Select all

__asm__ __volatile__("movl %%eax, %%cr0", :: "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) : "eax");
It says:

test.c:66: error: expected ':' or ')' before ',' token
If I remove that comma it faults saying:
test.c:95: error: can't find a register in class 'AREG' while reloading 'asm'
test.c:58: error: 'asm' operand has impossible constraints
Here is the entire code, after all changes described above have been made:

Code: Select all

unsigned int mem_end;
unsigned int bse_end;

void count_memory(void)
{
	register unsigned long *mem;
	unsigned long	mem_count, a;
	unsigned short	memkb;
	unsigned char	irq1, irq2;
	unsigned long	cr0;

	/* save IRQ's */
	irq1=inb(0x21);
	irq2=inb(0xA1);

	/* kill all irq's */
	outb(0x21, 0xFF);
	outb(0xA1, 0xFF);

	mem_count=0;
	memkb=0;

	// store a copy of CR0
	__asm__ __volatile("movl %%cr0, %%eax":"=a"(cr0)::"eax");

	// invalidate the cache
	// write-back and invalidate the cache
	__asm__ __volatile__ ("wbinvd");

	// plug cr0 with just PE/CD/NW
	// cache disable(486+), no-writeback(486+), 32bit mode(386+)
	__asm__ __volatile__("movl %%eax, %%cr0" :: "a" (cr0 | 0x00000001 | 0x40000000 | 0x20000000) : "eax");

	do
	{
		memkb++;
		mem_count+=1024*1024;
		mem=(unsigned long*)mem_count;

		a=*mem;

		*mem=0x55AA55AA;
		
		// the empty asm calls tell gcc not to rely on whats in its registers
		// as saved variables (this gets us around GCC optimisations)
		asm("":::"memory");
		if(*mem!=0x55AA55AA)
			mem_count=0;
		else
		{
			*mem=0xAA55AA55;
			asm("":::"memory");
			if(*mem!=0xAA55AA55)
				mem_count=0;
		}

		asm("":::"memory");
		*mem=a;
	}while(memkb<4096 && mem_count!=0);

	__asm__ __volatile__("movl %%eax, %%cr0" :: "a" (cr0) : "eax");

	mem_end=memkb<<20;
	mem=(unsigned long*)0x413;
	bse_end=((*mem)&0xFFFF)<<6;

	outb(0x21, irq1);
	outb(0xA1, irq2);
}
jake12
Posts: 14
Joined: Mon Nov 24, 2008 7:03 pm

Re: DJGPP Inline Help

Post by jake12 »

fixed. take out eax in clobber list. update the wiki.
Post Reply