[Novalug] Linux, asm, hardware, protected mode

Ed James edjames at greenbelt.com
Mon Feb 18 04:53:28 EST 2008


This is partly an inline assembly code question, and partly a
linux protected mode question, and maybe something else that
I'm unaware of.

I have a C program compiled with: gcc -Wall foo.c -o foo

I make calls using asm().  I'm trying both AT&T and Intel modes, as
in:

    asm(".att_syntax noprefix");   and
    asm(".intel_syntax noprefix");

but not at the same time, of course.

Most instructions work okay, such as (a bunch of delay code):

    asm("mov bx, 10");       // Outside loop done 10 times
    asm(".outloop:");        // Mark outside loop
    asm("mov cx, 65535");    // Inside loop done many times
    asm(".inloop:");         // Mark inside loop
    asm("dec cx");           // Decrement inside loop counter
    asm("jne .inloop");      // Loop back (inside loop)
    asm("dec bx");           // Decrement outside loop counter
    asm("jne .outloop");     // Loop back (outside loop)

However, an in or out instruction, as in:

    asm("out 0x42, al");  or
    asm("in al, 0x61");

gives a segmentation fault.

I'm trying (THE HARD WAY) to control the pc speaker to make custom sounds.

Basic question is, am I hitting a problem where Linux is protecting the
hardware from me, and forcing me to go thru the system, say with ioctl()
instead?

I've had no problem using ioctl() to control hardware, so I know how to do
it the easy way, btw.

I know Windoze is a pain to try to touch the hardware via homebrew programs,
but I'm not yet aware that Linux does the same thing - or does it?

Ed James



More information about the Novalug mailing list