Problem with GCC inline asm
Problem with GCC inline asm
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
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
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.
What you should be doing is
Code: Select all
__asm__ __volatile__("INT $0x13;");
I'd recommend reading this and this.
Website: https://joscor.com
Re: Problem with GCC inline asm
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
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.
I personally have grown fond of the AT&T syntax, it took a long time though.
Website: https://joscor.com
Re: Problem with GCC inline asm
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:
(That is supposed to move 0x03 into the ah register)
Gives error: suffix or operands invalid for `mov'.
Code: Select all
__asm__ __volatile__ ("movb $0x03 %ah;");
Gives error: suffix or operands invalid for `mov'.
Re: Problem with GCC inline asm
You don't have a comma between operands.
should be:
should be:
Code: Select all
__asm__ __volatile__ ("movb $0x03, %ah;");
Website: https://joscor.com
Re: Problem with GCC inline asm
I check google thoroughly before I post on a forum. Thanks for your help guys.