Changeset f24d300 in mainline for kernel/arch/amd64/include/asm.h


Ignore:
Timestamp:
2009-03-03T15:52:55Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e762b43
Parents:
add04f7
Message:

better inline assembler readability using the new symbolic syntax

File:
1 edited

Legend:

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

    radd04f7 rf24d300  
    2727 */
    2828
    29 /** @addtogroup amd64   
     29/** @addtogroup amd64
    3030 * @{
    3131 */
     
    4646 * The stack is assumed to be STACK_SIZE bytes long.
    4747 * The stack must start on page boundary.
     48 *
    4849 */
    4950static inline uintptr_t get_stack_base(void)
     
    5152        uintptr_t v;
    5253       
    53         asm volatile ("andq %%rsp, %0\n" : "=r" (v) : "0" (~((uint64_t)STACK_SIZE-1)));
     54        asm volatile (
     55                "andq %%rsp, %[v]\n"
     56                : [v] "=r" (v)
     57                : "0" (~((uint64_t) STACK_SIZE-1))
     58        );
    5459       
    5560        return v;
     
    7378 * @param port Port to read from
    7479 * @return Value read
     80 *
    7581 */
    7682static inline uint8_t pio_read_8(ioport8_t *port)
    7783{
    7884        uint8_t val;
    79 
    80         asm volatile ("inb %w1, %b0 \n" : "=a" (val) : "d" (port));
     85       
     86        asm volatile (
     87                "inb %w[port], %b[val]\n"
     88                : [val] "=a" (val)
     89                : [port] "d" (port)
     90        );
     91       
    8192        return val;
    8293}
     
    8899 * @param port Port to read from
    89100 * @return Value read
     101 *
    90102 */
    91103static inline uint16_t pio_read_16(ioport16_t *port)
     
    93105        uint16_t val;
    94106       
    95         asm volatile ("inw %w1, %w0 \n" : "=a" (val) : "d" (port));
     107        asm volatile (
     108                "inw %w[port], %w[val]\n"
     109                : [val] "=a" (val)
     110                : [port] "d" (port)
     111        );
     112       
    96113        return val;
    97114}
     
    103120 * @param port Port to read from
    104121 * @return Value read
     122 *
    105123 */
    106124static inline uint32_t pio_read_32(ioport32_t *port)
     
    108126        uint32_t val;
    109127       
    110         asm volatile ("inl %w1, %0 \n" : "=a" (val) : "d" (port));
     128        asm volatile (
     129                "inl %w[port], %[val]\n"
     130                : [val] "=a" (val)
     131                : [port] "d" (port)
     132        );
     133       
    111134        return val;
    112135}
     
    118141 * @param port Port to write to
    119142 * @param val Value to write
     143 *
    120144 */
    121145static inline void pio_write_8(ioport8_t *port, uint8_t val)
    122146{
    123         asm volatile ("outb %b0, %w1\n" : : "a" (val), "d" (port));
     147        asm volatile (
     148                "outb %b[val], %w[port]\n"
     149                :: [val] "a" (val), [port] "d" (port)
     150        );
    124151}
    125152
     
    130157 * @param port Port to write to
    131158 * @param val Value to write
     159 *
    132160 */
    133161static inline void pio_write_16(ioport16_t *port, uint16_t val)
    134162{
    135         asm volatile ("outw %w0, %w1\n" : : "a" (val), "d" (port));
     163        asm volatile (
     164                "outw %w[val], %w[port]\n"
     165                :: [val] "a" (val), [port] "d" (port)
     166        );
    136167}
    137168
     
    142173 * @param port Port to write to
    143174 * @param val Value to write
     175 *
    144176 */
    145177static inline void pio_write_32(ioport32_t *port, uint32_t val)
    146178{
    147         asm volatile ("outl %0, %w1\n" : : "a" (val), "d" (port));
     179        asm volatile (
     180                "outl %[val], %w[port]\n"
     181                :: [val] "a" (val), [port] "d" (port)
     182        );
    148183}
    149184
     
    160195 *
    161196 * @return Old interrupt priority level.
     197 *
    162198 */
    163199static inline ipl_t interrupts_enable(void) {
    164200        ipl_t v;
    165         __asm__ volatile (
     201       
     202        asm volatile (
    166203                "pushfq\n"
    167                 "popq %0\n"
     204                "popq %[v]\n"
    168205                "sti\n"
    169                 : "=r" (v)
    170         );
     206                : [v] "=r" (v)
     207        );
     208       
    171209        return v;
    172210}
     
    178216 *
    179217 * @return Old interrupt priority level.
     218 *
    180219 */
    181220static inline ipl_t interrupts_disable(void) {
    182221        ipl_t v;
    183         __asm__ volatile (
     222       
     223        asm volatile (
    184224                "pushfq\n"
    185                 "popq %0\n"
     225                "popq %[v]\n"
    186226                "cli\n"
    187                 : "=r" (v)
    188                 );
     227                : [v] "=r" (v)
     228        );
     229       
    189230        return v;
    190231}
     
    195236 *
    196237 * @param ipl Saved interrupt priority level.
     238 *
    197239 */
    198240static inline void interrupts_restore(ipl_t ipl) {
    199         __asm__ volatile (
    200                 "pushq %0\n"
     241        asm volatile (
     242                "pushq %[ipl]\n"
    201243                "popfq\n"
    202                 : : "r" (ipl)
    203                 );
     244                :: [ipl] "r" (ipl)
     245        );
    204246}
    205247
     
    209251 *
    210252 * @return Current interrupt priority level.
     253 *
    211254 */
    212255static inline ipl_t interrupts_read(void) {
    213256        ipl_t v;
    214         __asm__ volatile (
     257       
     258        asm volatile (
    215259                "pushfq\n"
    216                 "popq %0\n"
    217                 : "=r" (v)
    218         );
     260                "popq %[v]\n"
     261                : [v] "=r" (v)
     262        );
     263       
    219264        return v;
    220265}
     
    223268static inline void write_msr(uint32_t msr, uint64_t value)
    224269{
    225         __asm__ volatile (
    226                 "wrmsr;" : : "c" (msr),
    227                 "a" ((uint32_t)(value)),
    228                 "d" ((uint32_t)(value >> 32))
    229                 );
     270        asm volatile (
     271                "wrmsr\n"
     272                :: "c" (msr),
     273                   "a" ((uint32_t) (value)),
     274                   "d" ((uint32_t) (value >> 32))
     275        );
    230276}
    231277
     
    233279{
    234280        uint32_t ax, dx;
    235 
    236         __asm__ volatile (
    237                 "rdmsr;" : "=a"(ax), "=d"(dx) : "c" (msr)
    238                 );
    239         return ((uint64_t)dx << 32) | ax;
     281       
     282        asm volatile (
     283                "rdmsr\n"
     284                : "=a" (ax), "=d" (dx)
     285                : "c" (msr)
     286        );
     287       
     288        return ((uint64_t) dx << 32) | ax;
    240289}
    241290
     
    244293 *
    245294 * Enable local APIC in MSR.
     295 *
    246296 */
    247297static inline void enable_l_apic_in_msr()
    248298{
    249         __asm__ volatile (
     299        asm volatile (
    250300                "movl $0x1b, %%ecx\n"
    251301                "rdmsr\n"
    252                 "orl $(1<<11),%%eax\n"
     302                "orl $(1 << 11),%%eax\n"
    253303                "orl $(0xfee00000),%%eax\n"
    254304                "wrmsr\n"
    255                 :
    256                 :
    257                 :"%eax","%ecx","%edx"
    258                 );
     305                ::: "%eax","%ecx","%edx"
     306        );
    259307}
    260308
     
    262310{
    263311        uintptr_t *ip;
    264 
    265         __asm__ volatile (
    266                 "mov %%rip, %0"
    267                 : "=r" (ip)
    268                 );
     312       
     313        asm volatile (
     314                "mov %%rip, %[ip]"
     315                : [ip] "=r" (ip)
     316        );
     317       
    269318        return ip;
    270319}
     
    273322 *
    274323 * @param addr Address on a page whose TLB entry is to be invalidated.
     324 *
    275325 */
    276326static inline void invlpg(uintptr_t addr)
    277327{
    278         __asm__ volatile ("invlpg %0\n" :: "m" (*((unative_t *)addr)));
     328        asm volatile (
     329                "invlpg %[addr]\n"
     330                :: [addr] "m" (*((unative_t *) addr))
     331        );
    279332}
    280333
     
    282335 *
    283336 * @param gdtr_reg Address of memory from where to load GDTR.
     337 *
    284338 */
    285339static inline void gdtr_load(struct ptr_16_64 *gdtr_reg)
    286340{
    287         __asm__ volatile ("lgdtq %0\n" : : "m" (*gdtr_reg));
     341        asm volatile (
     342                "lgdtq %[gdtr_reg]\n"
     343                :: [gdtr_reg] "m" (*gdtr_reg)
     344        );
    288345}
    289346
     
    291348 *
    292349 * @param gdtr_reg Address of memory to where to load GDTR.
     350 *
    293351 */
    294352static inline void gdtr_store(struct ptr_16_64 *gdtr_reg)
    295353{
    296         __asm__ volatile ("sgdtq %0\n" : : "m" (*gdtr_reg));
     354        asm volatile (
     355                "sgdtq %[gdtr_reg]\n"
     356                :: [gdtr_reg] "m" (*gdtr_reg)
     357        );
    297358}
    298359
     
    300361 *
    301362 * @param idtr_reg Address of memory from where to load IDTR.
     363 *
    302364 */
    303365static inline void idtr_load(struct ptr_16_64 *idtr_reg)
    304366{
    305         __asm__ volatile ("lidtq %0\n" : : "m" (*idtr_reg));
     367        asm volatile (
     368                "lidtq %[idtr_reg]\n"
     369                :: [idtr_reg] "m" (*idtr_reg));
    306370}
    307371
     
    309373 *
    310374 * @param sel Selector specifying descriptor of TSS segment.
     375 *
    311376 */
    312377static inline void tr_load(uint16_t sel)
    313378{
    314         __asm__ volatile ("ltr %0" : : "r" (sel));
     379        asm volatile (
     380                "ltr %[sel]"
     381                :: [sel] "r" (sel)
     382        );
    315383}
    316384
    317385#define GEN_READ_REG(reg) static inline unative_t read_ ##reg (void) \
    318     { \
    319         unative_t res; \
    320         __asm__ volatile ("movq %%" #reg ", %0" : "=r" (res) ); \
    321         return res; \
    322     }
     386        { \
     387                unative_t res; \
     388                asm volatile ( \
     389                        "movq %%" #reg ", %[res]" \
     390                        : [res] "=r" (res) \
     391                ); \
     392                return res; \
     393        }
    323394
    324395#define GEN_WRITE_REG(reg) static inline void write_ ##reg (unative_t regn) \
    325     { \
    326         __asm__ volatile ("movq %0, %%" #reg : : "r" (regn)); \
    327     }
     396        { \
     397                asm volatile ( \
     398                        "movq %[regn], %%" #reg \
     399                        :: [regn] "r" (regn) \
     400                ); \
     401        }
    328402
    329403GEN_READ_REG(cr0)
Note: See TracChangeset for help on using the changeset viewer.