Changeset add04f7 in mainline for kernel/arch/ia32/include/asm.h


Ignore:
Timestamp:
2009-03-03T15:20:49Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f24d300
Parents:
deca67b
Message:

better inline assembler readability using the new symbolic syntax

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/ia32/include/asm.h

    rdeca67b radd04f7  
    2828 */
    2929
    30 /** @addtogroup ia32   
     30/** @addtogroup ia32
    3131 * @{
    3232 */
     
    5757 *
    5858 * Halt the current CPU until interrupt event.
     59 *
    5960 */
    6061static inline void cpu_halt(void)
     
    6970
    7071#define GEN_READ_REG(reg) static inline unative_t read_ ##reg (void) \
    71     { \
    72         unative_t res; \
    73         asm volatile ("movl %%" #reg ", %0" : "=r" (res) ); \
    74         return res; \
    75     }
     72        { \
     73                unative_t res; \
     74                asm volatile ( \
     75                        "movl %%" #reg ", %[res]" \
     76                        : [res] "=r" (res) \
     77                ); \
     78                return res; \
     79        }
    7680
    7781#define GEN_WRITE_REG(reg) static inline void write_ ##reg (unative_t regn) \
    78     { \
    79         asm volatile ("movl %0, %%" #reg : : "r" (regn)); \
    80     }
     82        { \
     83                asm volatile ( \
     84                        "movl %[regn], %%" #reg \
     85                        :: [regn] "r" (regn) \
     86                ); \
     87        }
    8188
    8289GEN_READ_REG(cr0)
     
    105112 * @param port Port to write to
    106113 * @param val Value to write
     114 *
    107115 */
    108116static inline void pio_write_8(ioport8_t *port, uint8_t val)
    109117{
    110         asm volatile ("outb %b0, %w1\n" : : "a" (val), "d" (port));
     118        asm volatile (
     119                "outb %b[val], %w[port]\n"
     120                :: [val] "a" (val), [port] "d" (port)
     121        );
    111122}
    112123
     
    117128 * @param port Port to write to
    118129 * @param val Value to write
     130 *
    119131 */
    120132static inline void pio_write_16(ioport16_t *port, uint16_t val)
    121133{
    122         asm volatile ("outw %w0, %w1\n" : : "a" (val), "d" (port));
     134        asm volatile (
     135                "outw %w[val], %w[port]\n"
     136                :: [val] "a" (val), [port] "d" (port)
     137        );
    123138}
    124139
     
    129144 * @param port Port to write to
    130145 * @param val Value to write
     146 *
    131147 */
    132148static inline void pio_write_32(ioport32_t *port, uint32_t val)
    133149{
    134         asm volatile ("outl %0, %w1\n" : : "a" (val), "d" (port));
     150        asm volatile (
     151                "outl %[val], %w[port]\n"
     152                :: [val] "a" (val), [port] "d" (port)
     153        );
    135154}
    136155
     
    141160 * @param port Port to read from
    142161 * @return Value read
     162 *
    143163 */
    144164static inline uint8_t pio_read_8(ioport8_t *port)
     
    146166        uint8_t val;
    147167       
    148         asm volatile ("inb %w1, %b0 \n" : "=a" (val) : "d" (port));
     168        asm volatile (
     169                "inb %w[port], %b[val]\n"
     170                : [val] "=a" (val)
     171                : [port] "d" (port)
     172        );
     173       
    149174        return val;
    150175}
     
    156181 * @param port Port to read from
    157182 * @return Value read
     183 *
    158184 */
    159185static inline uint16_t pio_read_16(ioport16_t *port)
     
    161187        uint16_t val;
    162188       
    163         asm volatile ("inw %w1, %w0 \n" : "=a" (val) : "d" (port));
     189        asm volatile (
     190                "inw %w[port], %w[val]\n"
     191                : [val] "=a" (val)
     192                : [port] "d" (port)
     193        );
     194       
    164195        return val;
    165196}
     
    171202 * @param port Port to read from
    172203 * @return Value read
     204 *
    173205 */
    174206static inline uint32_t pio_read_32(ioport32_t *port)
     
    176208        uint32_t val;
    177209       
    178         asm volatile ("inl %w1, %0 \n" : "=a" (val) : "d" (port));
     210        asm volatile (
     211                "inl %w[port], %[val]\n"
     212                : [val] "=a" (val)
     213                : [port] "d" (port)
     214        );
     215       
    179216        return val;
    180217}
     
    186223 *
    187224 * @return Old interrupt priority level.
     225 *
    188226 */
    189227static inline ipl_t interrupts_enable(void)
    190228{
    191229        ipl_t v;
    192         asm volatile (
    193                 "pushf\n\t"
    194                 "popl %0\n\t"
     230       
     231        asm volatile (
     232                "pushf\n"
     233                "popl %[v]\n"
    195234                "sti\n"
    196                 : "=r" (v)
    197         );
     235                : [v] "=r" (v)
     236        );
     237       
    198238        return v;
    199239}
     
    205245 *
    206246 * @return Old interrupt priority level.
     247 *
    207248 */
    208249static inline ipl_t interrupts_disable(void)
    209250{
    210251        ipl_t v;
    211         asm volatile (
    212                 "pushf\n\t"
    213                 "popl %0\n\t"
     252       
     253        asm volatile (
     254                "pushf\n"
     255                "popl %[v]\n"
    214256                "cli\n"
    215                 : "=r" (v)
    216         );
     257                : [v] "=r" (v)
     258        );
     259       
    217260        return v;
    218261}
     
    223266 *
    224267 * @param ipl Saved interrupt priority level.
     268 *
    225269 */
    226270static inline void interrupts_restore(ipl_t ipl)
    227271{
    228272        asm volatile (
    229                 "pushl %0\n\t"
     273                "pushl %[ipl]\n"
    230274                "popf\n"
    231                 : : "r" (ipl)
     275                :: [ipl] "r" (ipl)
    232276        );
    233277}
     
    236280 *
    237281 * @return EFLAFS.
     282 *
    238283 */
    239284static inline ipl_t interrupts_read(void)
    240285{
    241286        ipl_t v;
    242         asm volatile (
    243                 "pushf\n\t"
    244                 "popl %0\n"
    245                 : "=r" (v)
    246         );
     287       
     288        asm volatile (
     289                "pushf\n"
     290                "popl %[v]\n"
     291                : [v] "=r" (v)
     292        );
     293       
    247294        return v;
    248295}
     
    251298static inline void write_msr(uint32_t msr, uint64_t value)
    252299{
    253         asm volatile ("wrmsr" : : "c" (msr), "a" ((uint32_t)(value)),
    254             "d" ((uint32_t)(value >> 32)));
     300        asm volatile (
     301                "wrmsr"
     302                :: "c" (msr), "a" ((uint32_t) (value)),
     303                   "d" ((uint32_t) (value >> 32))
     304        );
    255305}
    256306
     
    258308{
    259309        uint32_t ax, dx;
    260 
    261         asm volatile ("rdmsr" : "=a"(ax), "=d"(dx) : "c" (msr));
    262         return ((uint64_t)dx << 32) | ax;
     310       
     311        asm volatile (
     312                "rdmsr"
     313                : "=a" (ax), "=d" (dx)
     314                : "c" (msr)
     315        );
     316       
     317        return ((uint64_t) dx << 32) | ax;
    263318}
    264319
     
    269324 * The stack is assumed to be STACK_SIZE bytes long.
    270325 * The stack must start on page boundary.
     326 *
    271327 */
    272328static inline uintptr_t get_stack_base(void)
     
    275331       
    276332        asm volatile (
    277                 "andl %%esp, %0\n"
    278                 : "=r" (v)
     333                "andl %%esp, %[v]\n"
     334                : [v] "=r" (v)
    279335                : "0" (~(STACK_SIZE - 1))
    280336        );
     
    287343{
    288344        uintptr_t *ip;
    289 
    290         asm volatile (
    291                 "mov %%eip, %0"
    292                 : "=r" (ip)
    293                 );
     345       
     346        asm volatile (
     347                "mov %%eip, %[ip]"
     348                : [ip] "=r" (ip)
     349        );
     350       
    294351        return ip;
    295352}
     
    298355 *
    299356 * @param addr Address on a page whose TLB entry is to be invalidated.
     357 *
    300358 */
    301359static inline void invlpg(uintptr_t addr)
    302360{
    303         asm volatile ("invlpg %0\n" :: "m" (*(unative_t *)addr));
     361        asm volatile (
     362                "invlpg %[addr]\n"
     363                :: [addr] "m" (*(unative_t *) addr)
     364        );
    304365}
    305366
     
    307368 *
    308369 * @param gdtr_reg Address of memory from where to load GDTR.
     370 *
    309371 */
    310372static inline void gdtr_load(ptr_16_32_t *gdtr_reg)
    311373{
    312         asm volatile ("lgdtl %0\n" : : "m" (*gdtr_reg));
     374        asm volatile (
     375                "lgdtl %[gdtr_reg]\n"
     376                :: [gdtr_reg] "m" (*gdtr_reg)
     377        );
    313378}
    314379
     
    316381 *
    317382 * @param gdtr_reg Address of memory to where to load GDTR.
     383 *
    318384 */
    319385static inline void gdtr_store(ptr_16_32_t *gdtr_reg)
    320386{
    321         asm volatile ("sgdtl %0\n" : : "m" (*gdtr_reg));
     387        asm volatile (
     388                "sgdtl %[gdtr_reg]\n"
     389                :: [gdtr_reg] "m" (*gdtr_reg)
     390        );
    322391}
    323392
     
    325394 *
    326395 * @param idtr_reg Address of memory from where to load IDTR.
     396 *
    327397 */
    328398static inline void idtr_load(ptr_16_32_t *idtr_reg)
    329399{
    330         asm volatile ("lidtl %0\n" : : "m" (*idtr_reg));
     400        asm volatile (
     401                "lidtl %[idtr_reg]\n"
     402                :: [idtr_reg] "m" (*idtr_reg)
     403        );
    331404}
    332405
     
    334407 *
    335408 * @param sel Selector specifying descriptor of TSS segment.
     409 *
    336410 */
    337411static inline void tr_load(uint16_t sel)
    338412{
    339         asm volatile ("ltr %0" : : "r" (sel));
     413        asm volatile (
     414                "ltr %[sel]"
     415                :: [sel] "r" (sel)
     416        );
    340417}
    341418
Note: See TracChangeset for help on using the changeset viewer.