Page 1 of 1

Problem with GCC inline asm

Posted: Mon Nov 17, 2008 8:30 pm
by Frawley
Hello! I am new to kernel and os development and have been trying to write some very minimalistic kernels that output to the screen and just recently, attempting to access the hard disk. In order to access the hard disk, I need to trigger the 0x13 BIOS interrupt but I am having difficulties doing this with the GCC compiler. It doesn't seem to recognize the inline asm opcode `int`. I tried int13 and int 0x13. Neither of them compile properly. Is there any other way to call an interrupt using the gcc compiler? Thank you for any advice you can provide.

Re: Problem with GCC inline asm

Posted: Mon Nov 17, 2008 9:08 pm
by 01000101
AFAIK GCC defaults to using AT&T assembly syntax, which means your "int 0x13" will error with an invalid suffix or something similar.

What you should be doing is

Code: Select all

__asm__ __volatile__("INT $0x13;");
This will use in-line (non-relocatable) assembly with AT&T syntax INT 0x13. Note the "$" prefix to the 0x13, the dollar sign declares the appended value as an integer.

I'd recommend reading this and this.

Re: Problem with GCC inline asm

Posted: Mon Nov 17, 2008 9:41 pm
by Frawley
Thank you. I was unaware that gcc used at&t syntax. I had already seen those two articles you posted but didn't understand the complicated syntax that the inline assembler uses. I am used to nasm and visual studio's inline assembler which are much more simple.

Re: Problem with GCC inline asm

Posted: Mon Nov 17, 2008 9:49 pm
by 01000101
There is a way to switch GCC's default inline assembly syntax. I'm sure if you punch in "GCC INTEL" or something of the sort into the wiki search function, it'll lead you to the right place.

I personally have grown fond of the AT&T syntax, it took a long time though. :)

Re: Problem with GCC inline asm

Posted: Mon Nov 17, 2008 10:09 pm
by Frawley
One more problem I'm getting. I converted my intel style code to at&t (wasn't so bad) and I'm getting assembler errors for all of my mov lines:

Code: Select all

__asm__ __volatile__ ("movb $0x03 %ah;");
(That is supposed to move 0x03 into the ah register)
Gives error: suffix or operands invalid for `mov'.

Re: Problem with GCC inline asm

Posted: Mon Nov 17, 2008 10:23 pm
by 01000101
You don't have a comma between operands. :wink:

should be:

Code: Select all

__asm__ __volatile__ ("movb $0x03, %ah;");

Re: Problem with GCC inline asm

Posted: Tue Nov 18, 2008 12:19 am
by devel
google is your friend ;).

Re: Problem with GCC inline asm

Posted: Tue Nov 18, 2008 5:36 am
by Frawley
I check google thoroughly before I post on a forum. Thanks for your help guys.