Talk:Inline Assembly/Examples: Difference between revisions

From OSDev.wiki
Latest comment: 13 years ago by Solar in topic Problems with article
Jump to navigation Jump to search
Content added Content deleted
No edit summary
No edit summary
Line 1: Line 1:
== Rollback ==

Rolled back edit by imate900 that added the following lgdt function, which is wrong for many reasons. I just did not have time to fix the example yet.
Rolled back edit by imate900 that added the following lgdt function, which is wrong for many reasons. I just did not have time to fix the example yet.
<pre>
<pre>
Line 19: Line 21:
}</pre>
}</pre>
--[[User:Quok|quok]] 19:17, 2 May 2009 (UTC)
--[[User:Quok|quok]] 19:17, 2 May 2009 (UTC)

== Problems with article ==


I see some problems with this article:
I see some problems with this article:
:1. It only provides GCC inline assembly.
# It only provides GCC inline assembly.
:2. It uses GCC-specific extensions although the "inline" keyword was introduced in C99.
# It uses GCC-specific extensions although the "inline" keyword was introduced in C99.
:'''3. More importantly, everything here is more suited as a macro than inline assembly. It is important to understand that "inline" is just a compiler hint and may be ignored entirely as far as optimizations go (and probably will). The only thing one can be sure of is that a pointer to the function cannot be obtained.'''
# '''More importantly, everything here is more suited as a macro than inline assembly. It is important to understand that "inline" is just a compiler hint and may be ignored entirely as far as optimizations go (and probably will). The only thing one can be sure of is that a pointer to the function cannot be obtained.'''
:4. I/O support is directly supported in C (TR 1169).
# I/O support is directly supported in C (TR 1169).
It would be nice if someone explained why this article is neccessary.
It would be nice if someone explained why this article is neccessary.
--[[User:Love4boobies|Love4boobies]] 05:44, 10 March 2011 (UTC)
--[[User:Love4boobies|Love4boobies]] 05:44, 10 March 2011 (UTC)

:# This article is an extension to [[Inline Assembly]], which reads "...this article describes the way it works in GCC since it is by far the most used compiler in the OS world." Feel free to add an example page for MSVC inline assembly if you want.
:# I agree there.
:# The "inline" in "inline assembly" has nothing to do with the "inline" ''keyword''. Any ASM source written in a C source file is "inline", as opposed to ASM source in an external .asm / .s source file. You might want to note that an external ASM function can ''never'' be inlined, as the compiler lacks information on register usage etc. - and for the sake of presentation, I prefer a function declared inline over a preprocessor macro anytime.
:# You probably refer to the header <iohw.h>, which was added with TR18015 and TR18037. GCC still does not even follow C99 by default. The <iohw.h> header is absent from the GCC 4.1.2 installation I have available for quick checking. As such, it is not a viable replacement for the information provided in this article (which aims at providing ''examples'' of the modus operandi, not copy & paste code snippets anyway).
:I hope this helps (some). -- [[User:Solar|Solar]] 12:57, 10 March 2011 (UTC)

Revision as of 12:57, 10 March 2011

Rollback

Rolled back edit by imate900 that added the following lgdt function, which is wrong for many reasons. I just did not have time to fix the example yet.

void *lgdt(void *gdt, int entries)
{
 struct { unsigned short *length, void *base } gdtr_t;
 gdtr_t *gdtr;
 gdtr.length = entries;
 gdtr.base = gdt;
 asm("lgdt (%0)": : "p" (&gdtr));
 asm("mov %ax, 0x10");
 asm("mov %ds, %ax");
 asm("mov %es, %ax");
 asm("mov %fs, %ax");
 asm("mov %gs, %ax");
 asm("mov %ss, %ax");
 goto fix_cs;
fix_cs:
 return;
}

--quok 19:17, 2 May 2009 (UTC)Reply[reply]

Problems with article

I see some problems with this article:

  1. It only provides GCC inline assembly.
  2. It uses GCC-specific extensions although the "inline" keyword was introduced in C99.
  3. More importantly, everything here is more suited as a macro than inline assembly. It is important to understand that "inline" is just a compiler hint and may be ignored entirely as far as optimizations go (and probably will). The only thing one can be sure of is that a pointer to the function cannot be obtained.
  4. I/O support is directly supported in C (TR 1169).

It would be nice if someone explained why this article is neccessary. --Love4boobies 05:44, 10 March 2011 (UTC)Reply[reply]

  1. This article is an extension to Inline Assembly, which reads "...this article describes the way it works in GCC since it is by far the most used compiler in the OS world." Feel free to add an example page for MSVC inline assembly if you want.
  2. I agree there.
  3. The "inline" in "inline assembly" has nothing to do with the "inline" keyword. Any ASM source written in a C source file is "inline", as opposed to ASM source in an external .asm / .s source file. You might want to note that an external ASM function can never be inlined, as the compiler lacks information on register usage etc. - and for the sake of presentation, I prefer a function declared inline over a preprocessor macro anytime.
  4. You probably refer to the header <iohw.h>, which was added with TR18015 and TR18037. GCC still does not even follow C99 by default. The <iohw.h> header is absent from the GCC 4.1.2 installation I have available for quick checking. As such, it is not a viable replacement for the information provided in this article (which aims at providing examples of the modus operandi, not copy & paste code snippets anyway).
I hope this helps (some). -- Solar 12:57, 10 March 2011 (UTC)Reply[reply]