The meaning of "__asm__" & "__volatile_()"???

The meaning of "__asm__" & "__volatile_()"???

Post by Bo Li » Mon, 18 Nov 1996 04:00:00



Hi, any experts there willing to help:

I am a new grad trying to learn how to write linux device
driver and started reading the kernel code.

I first try to understand how semaphore is implemented (kernel/sched.c
and includ/asm-i386/semaphore.h) and have encounted several problems:

(1) The meaning of "__asm__" & "__volatile_()" which is used to define
     down and up. (primitive or directive of assembly? or compiler?)
     I cannot find their definitions in (a)*.h file (b) C reference
     mannul (c) the index of a 386/486 assembly book.

(2) why there are two sets of semaphore. down/up and __down/__up.

(3) what does " struct wait_queue **p" point to, which is often the
    first argument passed to functions operating on wait_queue, e.g,

    extern inline void __add_wait_queue(struct wait_queue ** p,
                                        struct wait_queue * wait)
{
        struct wait_queue *head = *p;
        struct wait_queue *next = WAIT_QUEUE_HEAD(p);

        if (head)
                next = head;
        *p = wait;
        wait->next = next;

Quote:}

* Is the address of p always related to the head of queue:
  &p = &head + sizeof(struct wait_queue)?
* Does p always point to the tail of the queue?
* Or is there any order for the queue? It's a circularly linked list.

  One field in the semaphore structure is of "struct wait_queue":

  struct semaphore {
        int count;
        int waiting;
        struct wait_queue * wait;

Quote:};

and is used as

  add_wait_queue(&sem->wait, &wait);

 
 
 

The meaning of "__asm__" & "__volatile_()"???

Post by Brian Hu » Wed, 20 Nov 1996 04:00:00


I can't answer everything, but I can answer some.


>(1) The meaning of "__asm__" & "__volatile_()" which is used to define
>     down and up. (primitive or directive of assembly? or compiler?)
>     I cannot find their definitions in (a)*.h file (b) C reference
>     mannul (c) the index of a 386/486 assembly book.

At the linux command line, type "info gcc".  Note that the 386/486
assembly language is not documented here (I recommend getting intel's
processor reference books if you already know assembly), simply GCC's
inline assembly mechanism.  There is much interesting information here.

-Brian