Problem with GCC inline asm

Programming, for all ages and all languages.
Post Reply
Frawley
Posts: 9
Joined: Mon Nov 17, 2008 8:13 pm

Problem with GCC inline asm

Post 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.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Problem with GCC inline asm

Post 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.
Frawley
Posts: 9
Joined: Mon Nov 17, 2008 8:13 pm

Re: Problem with GCC inline asm

Post 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.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Problem with GCC inline asm

Post 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. :)
Frawley
Posts: 9
Joined: Mon Nov 17, 2008 8:13 pm

Re: Problem with GCC inline asm

Post 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'.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Problem with GCC inline asm

Post by 01000101 »

You don't have a comma between operands. :wink:

should be:

Code: Select all

__asm__ __volatile__ ("movb $0x03, %ah;");
User avatar
devel
Member
Member
Posts: 62
Joined: Wed Nov 28, 2007 4:15 am
Contact:

Re: Problem with GCC inline asm

Post by devel »

google is your friend ;).
Frawley
Posts: 9
Joined: Mon Nov 17, 2008 8:13 pm

Re: Problem with GCC inline asm

Post by Frawley »

I check google thoroughly before I post on a forum. Thanks for your help guys.
Post Reply