Changeset 18e0a6c in mainline for arch/ia32


Ignore:
Timestamp:
2005-06-09T23:43:45Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
74df77d
Parents:
d896525
Message:

Implement several assembler functions in gcc's asm notation instead of in .s or .S file.
Gain both better speed and size.

Location:
arch/ia32
Files:
8 edited

Legend:

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

    rd896525 r18e0a6c  
    3838
    3939extern void paging_on(void);
    40 extern __address cpu_read_dba(void);
    41 extern void cpu_write_dba(__address dba);
    42 
    43 extern __address cpu_read_cr2(void);
    4440
    4541extern void interrupt_handlers(void);
     
    5551extern void enable_l_apic_in_msr(void);
    5652
    57 extern void halt_cpu(void);
    58 extern void cpu_sleep(void);
     53/** Halt CPU
     54 *
     55 * Halt the current CPU until interrupt event.
     56 */
     57static inline void cpu_halt(void) { __asm__("hlt"); };
     58static inline void cpu_sleep(void) { __asm__("hlt"); };
    5959
    60 static inline void write_dr0(__u32 v);
    61 static inline __u32 read_dr0(void);
     60/** Read CR2
     61 *
     62 * Return value in CR2
     63 *
     64 * @return Value read.
     65 */
     66static inline __u32 read_cr2(void) { __u32 v; __asm__ volatile ("movl %%cr2,%0" : "=r" (v)); return v; }
    6267
    63 inline void write_dr0(__u32 v) { __asm__ volatile ("movl %0,%%dr0\n" : : "r" (v)); }
    64 inline __u32 read_dr0(void) { __u32 v; __asm__ volatile ("movl %%dr0,%0" : "=r" (v)); return v; }
     68/** Write CR3
     69 *
     70 * Write value to CR3.
     71 *
     72 * @param v Value to be written.
     73 */
     74static inline void write_cr3(__u32 v) { __asm__ volatile ("movl %0,%%cr3\n" : : "r" (v)); }
     75
     76/** Read CR3
     77 *
     78 * Return value in CR3
     79 *
     80 * @return Value read.
     81 */
     82static inline __u32 read_cr3(void) { __u32 v; __asm__ volatile ("movl %%cr3,%0" : "=r" (v)); return v; }
     83
     84/** Write DR0
     85 *
     86 * Write value to DR0.
     87 *
     88 * @param v Value to be written.
     89 */
     90static inline void write_dr0(__u32 v) { __asm__ volatile ("movl %0,%%dr0\n" : : "r" (v)); }
     91
     92/** Read DR0
     93 *
     94 * Return value in DR0
     95 *
     96 * @return Value read.
     97 */
     98static inline __u32 read_dr0(void) { __u32 v; __asm__ volatile ("movl %%dr0,%0" : "=r" (v)); return v; }
     99
     100/** Set priority level low
     101 *
     102 * Enable interrupts and return previous
     103 * value of EFLAGS.
     104 */
     105static inline pri_t cpu_priority_low(void) {
     106        pri_t v;
     107        __asm__ volatile (
     108                "pushf\n"
     109                "popl %0\n"
     110                "sti\n"
     111                : "=r" (v)
     112        );
     113        return v;
     114}
     115
     116/** Set priority level high
     117 *
     118 * Disable interrupts and return previous
     119 * value of EFLAGS.
     120 */
     121static inline pri_t cpu_priority_high(void) {
     122        pri_t v;
     123        __asm__ volatile (
     124                "pushf\n"
     125                "popl %0\n"
     126                "cli\n"
     127                : "=r" (v)
     128        );
     129        return v;
     130}
     131
     132/** Restore priority level
     133 *
     134 * Restore EFLAGS.
     135 */
     136static inline void cpu_priority_restore(pri_t pri) {
     137        __asm__ volatile (
     138                "pushl %0\n"
     139                "popf\n"
     140                : : "r" (pri)
     141        );
     142}
     143
     144/** Return raw priority level
     145 *
     146 * Return EFLAFS.
     147 */
     148static inline pri_t cpu_priority_read(void) {
     149        pri_t v;
     150        __asm__ volatile (
     151                "pushf\n"
     152                "popl %0\n"
     153                : "=r" (v)
     154        );
     155        return v;
     156}
    65157
    66158#endif
  • arch/ia32/include/atomic.h

    rd896525 r18e0a6c  
    3232#include <arch/types.h>
    3333
    34 extern void atomic_inc(volatile int *val);
    35 extern void atomic_dec(volatile int *val);
     34static inline void atomic_inc(volatile int *val) {
     35#ifdef __SMP__
     36        __asm__ volatile ("lock incl (%0)\n" : : "r" (val));
     37#else
     38        __asm__ volatile ("incl (%0)\n" : : "r" (val));
     39#endif /* __SMP__ */
     40}
    3641
    37 extern int test_and_set(int *val);
     42static inline void atomic_dec(volatile int *val) {
     43#ifdef __SMP__
     44        __asm__ volatile ("lock decl (%0)\n" : : "r" (val));
     45#else
     46        __asm__ volatile ("decl (%0)\n" : : "r" (val));
     47#endif /* __SMP__ */
     48}
     49
     50static inline int test_and_set(int *val) {
     51        int v;
     52       
     53        __asm__ volatile (
     54                "movl $1, %0\n"
     55                "xchgl %0, (%1)\n"
     56                : "=r" (v)
     57                : "r" (val)
     58        );
     59       
     60        return v;
     61}
     62
     63
    3864extern void spinlock_arch(int *val);
    3965
  • arch/ia32/src/asm.s

    rd896525 r18e0a6c  
    3131.text
    3232
    33 .global cpu_priority_high
    34 .global cpu_priority_low
    35 .global cpu_priority_restore
    36 .global cpu_priority_read
    3733.global cpu_halt
    3834.global cpu_sleep
    3935.global paging_on
    40 .global cpu_read_dba
    41 .global cpu_write_dba
    42 .global cpu_read_cr2
    4336.global enable_l_apic_in_msr
    4437.global interrupt_handlers
     
    5548
    5649
    57 ## Set priority level high
    58 #
    59 # Disable interrupts and return previous
    60 # EFLAGS in EAX.
    61 #
    62 cpu_priority_high:
    63         pushf
    64         pop %eax
    65         cli
    66         ret
    67 
    68 
    69 ## Set priority level low
    70 #
    71 # Enable interrupts and return previous
    72 # EFLAGS in EAX.
    73 #   
    74 cpu_priority_low:
    75         pushf
    76         pop %eax
    77         sti
    78         ret
    79 
    80 
    81 ## Restore priority level
    82 #
    83 # Restore EFLAGS.
    84 #
    85 cpu_priority_restore:
    86         push 4(%esp)
    87         popf
    88         ret
    89 
    90 ## Return raw priority level
    91 #
    92 # Return EFLAFS in EAX.
    93 #
    94 cpu_priority_read:
    95         pushf
    96         pop %eax
    97         ret
    98 
    99 
    100 ## Halt the CPU
    101 #
    102 # Halt the CPU using HLT.
    103 #
    104 cpu_halt:
    105 cpu_sleep:
    106         hlt
    107         ret
    108 
    109 
    11050## Turn paging on
    11151#
     
    12464
    12565
    126 ## Read CR3
    127 #
    128 # Store CR3 in EAX.
    129 #
    130 cpu_read_dba:
    131         movl %cr3,%eax
    132         ret
    133 
    134 
    135 ## Write CR3
    136 #
    137 # Set CR3.
    138 #
    139 cpu_write_dba:
    140         pushl %eax
    141         movl 8(%esp),%eax
    142         movl %eax,%cr3
    143         popl %eax
    144         ret
    145 
    146 
    147 ## Read CR2
    148 #
    149 # Store CR2 in EAX.
    150 #
    151 cpu_read_cr2:
    152         movl %cr2,%eax
    153         ret
    154 
    155 
    15666## Enable local APIC
    15767#
  • arch/ia32/src/atomic.S

    rd896525 r18e0a6c  
    2929.text
    3030
    31 .global atomic_inc
    32 atomic_inc:
    33         pushl %ebx
    34         movl 8(%esp),%ebx
    35 #ifdef __SMP__ 
    36         lock incl (%ebx)
    37 #else
    38         incl (%ebx)
    39 #endif         
    40         popl %ebx
    41         ret
    42 
    43 .global atomic_dec
    44 atomic_dec:
    45         pushl %ebx
    46         movl 8(%esp),%ebx
    47 #ifdef __SMP__ 
    48         lock decl (%ebx)
    49 #else
    50         decl (%ebx)
    51 #endif
    52         popl %ebx
    53         ret
    54        
    55 
    5631#ifdef __SMP__
    5732
    58 
    59 .global test_and_set
    6033.global spinlock_arch
    61 
    62 test_and_set:
    63         pushl %ebx
    64    
    65         movl 8(%esp),%ebx
    66         movl $1,%eax
    67         xchgl %eax,(%ebx)       # xchg implicitly turns on the LOCK signal
    68    
    69         popl %ebx
    70         ret
    71 
    7234
    7335#
  • arch/ia32/src/interrupt.c

    rd896525 r18e0a6c  
    112112void page_fault(__u8 n, __u32 stack[])
    113113{
    114         printf("page fault address: %X\n", cpu_read_cr2());
     114        printf("page fault address: %X\n", read_cr2());
    115115        printf("stack[0]=%X, %%eip=%X, %%cs=%X, flags=%X\n", stack[0], stack[1], stack[2], stack[3]);
    116116        printf("%%eax=%L, %%ebx=%L, %%ecx=%L, %%edx=%L,\n%%edi=%L, %%esi=%L, %%ebp=%L, %%esp=%L\n", stack[-2], stack[-5], stack[-3], stack[-4], stack[-9], stack[-8], stack[-1], stack);
  • arch/ia32/src/mm/page.c

    rd896525 r18e0a6c  
    7070
    7171                trap_register(14, page_fault);
    72                 cpu_write_dba(KA2PA(dba));
     72                write_cr3(KA2PA(dba));
    7373        }
    7474        else {
     
    8282                dba = frame_alloc(FRAME_KA | FRAME_PANIC);
    8383                memcopy(bootstrap_dba, dba, PAGE_SIZE);
    84                 cpu_write_dba(KA2PA(dba));
     84                write_cr3(KA2PA(dba));
    8585        }
    8686
     
    108108
    109109        if (root) dba = root;
    110         else dba = cpu_read_dba();
     110        else dba = read_cr3();
    111111
    112112        pde = page >> 22;               /* page directory entry */
  • arch/ia32/src/mm/tlb.c

    rd896525 r18e0a6c  
    3232void tlb_invalidate(int asid)
    3333{
    34         cpu_write_dba(cpu_read_dba());
     34        write_cr3(read_cr3());
    3535}
  • arch/ia32/src/smp/apic.c

    rd896525 r18e0a6c  
    4545 * Tested on:
    4646 *      Bochs 2.0.2 - Bochs 2.2 with 2-8 CPUs
     47 *      Simics 2.0.28
    4748 *      ASUS P/I-P65UP5 + ASUS C-P55T2D REV. 1.41 with 2x 200Mhz Pentium CPUs
    4849 */
Note: See TracChangeset for help on using the changeset viewer.