OSDev.org
https://forum.osdev.org/

Inline (was Buffer not filled while reading disk)
https://forum.osdev.org/viewtopic.php?f=13&t=36534
Page 1 of 1

Author:  PeterX [ Mon Feb 24, 2020 11:54 am ]
Post subject:  Inline (was Buffer not filled while reading disk)

In the other thread (" Buffer not filled while reading disk...") we were talking about operating with CPU registers in inline asm.

Octocontrabass wrote:
This is handled by the constraints in the inline assembly. You can read about it in the GCC manual.

psimonson1988 wrote:
Oh by the way, "a"(val), "b"(buffer), "c"((c << 8) | s), "d"((h << 8) | p->drive) is how you set ax, bx, cx, and dx in GNU inline assembly. Just in case you didn't know.

Woooah! That's both too sophisticated for me! I think I stick to Nasm and C, neatly separated...

But ok, I give it a try:
"a"(0x0201), "b"(buffer) etc. where buffer is the variable name for the buffer. Would that be correct?
Edit: I think it must be "a"($0x0201)

But I don't understand the constraints from the GCC manual. Any chnace there's a more easy to understand text about it?

Next thing to learn for me is Git. I hope I can understand at least that. I will get two books about it from the library.

Author:  Octocontrabass [ Mon Feb 24, 2020 12:36 pm ]
Post subject:  Re: Inline (was Buffer not filled while reading disk)

PeterX wrote:
But I don't understand the constraints from the GCC manual. Any chnace there's a more easy to understand text about it?

This page on the wiki might help.

Constraints are the letters inside the quotation marks that tell the compiler where the input or output may be located. To use the quoted code as an example, the "a" and "b" are constraints. The "a" tells the compiler to use AL or AX or EAX for the operand, chosen depending on the operand size. The "b" constraint does the same thing, but for BL/BX/EBX. There are constraints for all kinds of registers, memory references, and immediate values.

The part inside the parentheses is the C expression that describes the input or output. So, for example, an input operand specified as "a"(0x0201) tells the compiler to put the value 0x201 into EAX before running the inline assembly code. (Why EAX instead of AX? In C, integer literals are of type int by default.)

GCC's inline assembly is notoriously difficult, so it's not a good idea to use it if you're not entirely certain it will work how you want.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/