Page 1 of 1

Assember error: junk `%dx' after register

Posted: Mon Dec 10, 2012 6:59 am
by DeepakRaj
Hi

I'm following Bran's Kernel Development Tutorials.

I have done with the bare bone start up file in assembly, a linker script and a main.c file for basic functions, a batch file to compile and link.

Problem : When I run the batch file build.bat it shows the following assembler message:

main.c:49:6: warning: return type of 'main' is not 'int' [-Wmain]
/tmp/ccobm6mp.s: Assembler messages:
/tmp/ccobm6mp.s:121: Error: junk `%al' after register
/tmp/ccobm6mp.s:137: Error: junk `%dx' after register

Command that are there in build.bat are as following

$: nasm -f elf -o start.o start.asm
$: i586-elf-gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o main.o main.c
$: i586-elf-ld -T link.ld -o kernel.bin start.o

Help with the error. Please.
I'm a trying the kernel development for the first time. And I know that there may be several flaws in the code. Please suggest what kind of improvement can be made on the same.
I'll be thankful for all the suggestions.

Re: Assember error: junk `%dx' after register

Posted: Mon Dec 10, 2012 7:37 am
by Brendan
Hi,
DeepakRaj wrote:Problem : When I run the batch file build.bat it shows the following assembler message:

main.c:49:6: warning: return type of 'main' is not 'int' [-Wmain]
/tmp/ccobm6mp.s: Assembler messages:
/tmp/ccobm6mp.s:121: Error: junk `%al' after register
/tmp/ccobm6mp.s:137: Error: junk `%dx' after register
You failed to cut & paste properly.

From the tutorial itself:

Code: Select all

   __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
And:

Code: Select all

    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
From your "main.c":

Code: Select all

	__asm__ __volatile__("inb %1 %0" : "=a" (res) : "Nd" (_port));
And:

Code: Select all

	__asm__ __volatile__("outb %1 %0" : : "Nd" (_port), "a" (_data));
The missing commas are what the assembler is complaining about. It's a bit like doing "foo(first second);" in C when you meant "foo(first, second);".


Cheers,

Brendan

Re: Assember error: junk `%dx' after register

Posted: Mon Dec 10, 2012 8:06 am
by DeepakRaj
Brendan wrote:Hi,
DeepakRaj wrote:Problem : When I run the batch file build.bat it shows the following assembler message:

main.c:49:6: warning: return type of 'main' is not 'int' [-Wmain]
/tmp/ccobm6mp.s: Assembler messages:
/tmp/ccobm6mp.s:121: Error: junk `%al' after register
/tmp/ccobm6mp.s:137: Error: junk `%dx' after register
You failed to cut & paste properly.

From the tutorial itself:

Code: Select all

   __asm__ __volatile__ ("inb %1, %0" : "=a" (rv) : "dN" (_port));
And:

Code: Select all

    __asm__ __volatile__ ("outb %1, %0" : : "dN" (_port), "a" (_data));
From your "main.c":

Code: Select all

	__asm__ __volatile__("inb %1 %0" : "=a" (res) : "Nd" (_port));
And:

Code: Select all

	__asm__ __volatile__("outb %1 %0" : : "Nd" (_port), "a" (_data));
The missing commas are what the assembler is complaining about. It's a bit like doing "foo(first second);" in C when you meant "foo(first, second);".


Cheers,

Brendan
Thanks Brendan.
I guessed it would be something silly like this. Actually I typed it rather than coping.
Thanks once again for the help.