_cpuCalibrateDelay: ;;; uint32_t cpuCalibrateDelay() ;;;;;;;;;;;;;;;;;;;; ;;; This function is hand compiled from the calibrate_delay() function ;;; found in in Linux. It does not return BogoMips, but instead returns ;;; loops_per_jiffy. ;;; The comments with C source code reflect the lines in the source code ;;; of the Linux version whose calibrate_delay() function I used as a ;;; basis. push EBX ;; unsigned int lps_precision ; push ECX ;; unsigned int ticks ; push EDX ;; unsigned int loops_per_jiffy ; push ESI ;; unsigned int loopbit ; ;; 166: loops_per_jiffy = (1<<12) ; mov EDX, 4096 ;; 167: lps_precision = 8 ; mov BL, 8 ;; 172: while ( (loops_per_jiffy <<= 1) ) { .Coarse: shl EDX, 1 jz .Interlude ;; 174: ticks = jiffies ; mov ECX, [_jiffies] .Wait1: ;; 175: while ( ticks == jiffies ) ; cmp ECX, [_jiffies] je .Wait1 ;; 178: ticks = jiffies ; mov ECX, [_jiffies] ;; 179: delay(loops_per_jiffy) ; mov EAX, EDX ;; delay() ; .Delay1: ;; -- " -- dec EAX ;; -- " -- jns .Delay1 ;; -- " -- ;; 180: ticks = jiffies - ticks ; mov EAX, [_jiffies] sub EAX, ECX ;; 181: if ( !ticks ) break ; jnz .Coarse ;; 186: } .Interlude: ;; 187: loops_per_jiffy >>= 1 ; shr EDX, 1 ;; 188: loopbit = loops_per_jiffy ; mov ESI, EDX .Fine: ;; 189: while ( lps_precision-- && ( loopbit >>= 1 ) ) { dec BL js .Done shr ESI, 1 jz .Done ;; 190: loops_per_jiffy |= loopbit ; or EDX, ESI ;; 191: ticks = jiffies ; mov ECX, [_jiffies] .Wait2: ;; 192: while ( ticks == jiffies ) ; cmp ECX, [_jiffies] je .Wait2 ;; 193: ticks = jiffies ; mov ECX, [_jiffies] ;; 194: delay(loops_per_jiffy) ; mov EAX, EDX ;; delay() ; .Delay2: ;; == " == dec EAX ;; == " == jns .Delay2 ;; == " == ;; 195: if ( jiffies != ticks ) cmp ECX, [_jiffies] je .Fine ;; 196: loops_per_jiffy &= ~loopbit ; mov EAX, ESI not EAX and EDX, EAX ;; 197: } jmp short .Fine ;; return ( loops_per_jiffy ) ; .Done: mov EAX, EDX pop ESI pop EDX pop ECX pop EBX retn