]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/machine_routines.c
xnu-1504.3.12.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_routines.c
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b 27 */
2d21ac55 28
1c79356b
A
29#include <i386/machine_routines.h>
30#include <i386/io_map_entries.h>
55e303ae
A
31#include <i386/cpuid.h>
32#include <i386/fpu.h>
2d21ac55 33#include <mach/processor.h>
55e303ae 34#include <kern/processor.h>
91447636 35#include <kern/machine.h>
1c79356b 36#include <kern/cpu_data.h>
91447636
A
37#include <kern/cpu_number.h>
38#include <kern/thread.h>
55e303ae 39#include <i386/machine_cpu.h>
593a1d5f 40#include <i386/lapic.h>
55e303ae 41#include <i386/mp_events.h>
0c530ab8 42#include <i386/pmCPU.h>
2d21ac55
A
43#include <i386/tsc.h>
44#include <i386/cpu_threads.h>
b0d623f7 45#include <i386/proc_reg.h>
91447636 46#include <mach/vm_param.h>
b0d623f7
A
47#include <i386/pmap.h>
48#include <i386/misc_protos.h>
0c530ab8 49#if MACH_KDB
b0d623f7 50#include <machine/db_machdep.h>
0c530ab8
A
51#include <ddb/db_aout.h>
52#include <ddb/db_access.h>
53#include <ddb/db_sym.h>
54#include <ddb/db_variables.h>
55#include <ddb/db_command.h>
56#include <ddb/db_output.h>
57#include <ddb/db_expr.h>
58#endif
91447636 59
0c530ab8
A
60#if DEBUG
61#define DBG(x...) kprintf("DBG: " x)
62#else
63#define DBG(x...)
64#endif
65
b0d623f7 66
91447636 67extern void wakeup(void *);
55e303ae
A
68
69static int max_cpus_initialized = 0;
70
2d21ac55
A
71unsigned int LockTimeOut;
72unsigned int LockTimeOutTSC;
73unsigned int MutexSpin;
b0d623f7 74uint64_t LastDebuggerEntryAllowance;
0c530ab8 75
55e303ae
A
76#define MAX_CPUS_SET 0x1
77#define MAX_CPUS_WAIT 0x2
1c79356b
A
78
79/* IO memory map services */
80
81/* Map memory map IO space */
82vm_offset_t ml_io_map(
83 vm_offset_t phys_addr,
84 vm_size_t size)
85{
0c530ab8 86 return(io_map(phys_addr,size,VM_WIMG_IO));
1c79356b
A
87}
88
89/* boot memory allocation */
90vm_offset_t ml_static_malloc(
91447636 91 __unused vm_size_t size)
1c79356b
A
92{
93 return((vm_offset_t)NULL);
94}
95
0c530ab8
A
96
97void ml_get_bouncepool_info(vm_offset_t *phys_addr, vm_size_t *size)
98{
99 *phys_addr = bounce_pool_base;
100 *size = bounce_pool_size;
101}
102
103
1c79356b
A
104vm_offset_t
105ml_static_ptovirt(
106 vm_offset_t paddr)
107{
b0d623f7
A
108#if defined(__x86_64__)
109 return (vm_offset_t)(((unsigned long) paddr) | VM_MIN_KERNEL_ADDRESS);
110#else
111 return (vm_offset_t)((paddr) | LINEAR_KERNEL_ADDRESS);
112#endif
1c79356b
A
113}
114
91447636
A
115
116/*
117 * Routine: ml_static_mfree
118 * Function:
119 */
1c79356b
A
120void
121ml_static_mfree(
91447636
A
122 vm_offset_t vaddr,
123 vm_size_t size)
1c79356b 124{
b0d623f7 125 addr64_t vaddr_cur;
91447636
A
126 ppnum_t ppn;
127
b0d623f7 128 assert(vaddr >= VM_MIN_KERNEL_ADDRESS);
91447636
A
129
130 assert((vaddr & (PAGE_SIZE-1)) == 0); /* must be page aligned */
131
b0d623f7 132
91447636 133 for (vaddr_cur = vaddr;
b0d623f7 134 vaddr_cur < round_page_64(vaddr+size);
91447636 135 vaddr_cur += PAGE_SIZE) {
b0d623f7 136 ppn = pmap_find_phys(kernel_pmap, vaddr_cur);
91447636 137 if (ppn != (vm_offset_t)NULL) {
2d21ac55
A
138 kernel_pmap->stats.resident_count++;
139 if (kernel_pmap->stats.resident_count >
140 kernel_pmap->stats.resident_max) {
141 kernel_pmap->stats.resident_max =
142 kernel_pmap->stats.resident_count;
143 }
b0d623f7 144 pmap_remove(kernel_pmap, vaddr_cur, vaddr_cur+PAGE_SIZE);
91447636
A
145 vm_page_create(ppn,(ppn+1));
146 vm_page_wire_count--;
147 }
148 }
1c79356b
A
149}
150
0c530ab8 151
1c79356b
A
152/* virtual to physical on wired pages */
153vm_offset_t ml_vtophys(
154 vm_offset_t vaddr)
155{
b0d623f7 156 return (vm_offset_t)kvtophys(vaddr);
1c79356b
A
157}
158
2d21ac55
A
159/*
160 * Routine: ml_nofault_copy
161 * Function: Perform a physical mode copy if the source and
162 * destination have valid translations in the kernel pmap.
163 * If translations are present, they are assumed to
164 * be wired; i.e. no attempt is made to guarantee that the
165 * translations obtained remained valid for
166 * the duration of the copy process.
167 */
168
169vm_size_t ml_nofault_copy(
170 vm_offset_t virtsrc, vm_offset_t virtdst, vm_size_t size)
171{
172 addr64_t cur_phys_dst, cur_phys_src;
173 uint32_t count, nbytes = 0;
174
175 while (size > 0) {
176 if (!(cur_phys_src = kvtophys(virtsrc)))
177 break;
178 if (!(cur_phys_dst = kvtophys(virtdst)))
179 break;
180 if (!pmap_valid_page(i386_btop(cur_phys_dst)) || !pmap_valid_page(i386_btop(cur_phys_src)))
181 break;
b0d623f7 182 count = (uint32_t)(PAGE_SIZE - (cur_phys_src & PAGE_MASK));
2d21ac55 183 if (count > (PAGE_SIZE - (cur_phys_dst & PAGE_MASK)))
b0d623f7 184 count = (uint32_t)(PAGE_SIZE - (cur_phys_dst & PAGE_MASK));
2d21ac55 185 if (count > size)
b0d623f7 186 count = (uint32_t)size;
2d21ac55
A
187
188 bcopy_phys(cur_phys_src, cur_phys_dst, count);
189
190 nbytes += count;
191 virtsrc += count;
192 virtdst += count;
193 size -= count;
194 }
195
196 return nbytes;
197}
198
1c79356b
A
199/* Interrupt handling */
200
55e303ae
A
201/* Initialize Interrupts */
202void ml_init_interrupt(void)
203{
204 (void) ml_set_interrupts_enabled(TRUE);
205}
206
b0d623f7
A
207
208
1c79356b
A
209/* Get Interrupts Enabled */
210boolean_t ml_get_interrupts_enabled(void)
211{
212 unsigned long flags;
213
b0d623f7 214 __asm__ volatile("pushf; pop %0" : "=r" (flags));
1c79356b
A
215 return (flags & EFL_IF) != 0;
216}
217
218/* Set Interrupts Enabled */
219boolean_t ml_set_interrupts_enabled(boolean_t enable)
220{
221 unsigned long flags;
222
b0d623f7 223 __asm__ volatile("pushf; pop %0" : "=r" (flags));
1c79356b 224
0c530ab8
A
225 if (enable) {
226 ast_t *myast;
227
228 myast = ast_pending();
229
230 if ( (get_preemption_level() == 0) && (*myast & AST_URGENT) ) {
1c79356b 231 __asm__ volatile("sti");
0c530ab8
A
232 __asm__ volatile ("int $0xff");
233 } else {
234 __asm__ volatile ("sti");
235 }
236 }
237 else {
1c79356b 238 __asm__ volatile("cli");
0c530ab8 239 }
1c79356b
A
240
241 return (flags & EFL_IF) != 0;
242}
243
244/* Check if running at interrupt context */
245boolean_t ml_at_interrupt_context(void)
246{
247 return get_interrupt_level() != 0;
248}
249
250/* Generate a fake interrupt */
251void ml_cause_interrupt(void)
252{
253 panic("ml_cause_interrupt not defined yet on Intel");
254}
255
d52fe63f
A
256void ml_thread_policy(
257 thread_t thread,
2d21ac55 258__unused unsigned policy_id,
d52fe63f
A
259 unsigned policy_info)
260{
55e303ae
A
261 if (policy_info & MACHINE_NETWORK_WORKLOOP) {
262 spl_t s = splsched();
263
264 thread_lock(thread);
265
266 set_priority(thread, thread->priority + 1);
267
268 thread_unlock(thread);
269 splx(s);
270 }
d52fe63f
A
271}
272
1c79356b
A
273/* Initialize Interrupts */
274void ml_install_interrupt_handler(
275 void *nub,
276 int source,
277 void *target,
278 IOInterruptHandler handler,
279 void *refCon)
280{
281 boolean_t current_state;
282
283 current_state = ml_get_interrupts_enabled();
284
285 PE_install_interrupt_handler(nub, source, target,
286 (IOInterruptHandler) handler, refCon);
287
288 (void) ml_set_interrupts_enabled(current_state);
55e303ae 289
2d21ac55 290 initialize_screen(NULL, kPEAcquireScreen);
55e303ae
A
291}
292
91447636 293
1c79356b
A
294void
295machine_signal_idle(
296 processor_t processor)
297{
b0d623f7 298 cpu_interrupt(processor->cpu_id);
55e303ae
A
299}
300
b0d623f7
A
301static kern_return_t
302register_cpu(
303 uint32_t lapic_id,
304 processor_t *processor_out,
305 boolean_t boot_cpu )
55e303ae 306{
55e303ae 307 int target_cpu;
91447636 308 cpu_data_t *this_cpu_datap;
55e303ae 309
91447636
A
310 this_cpu_datap = cpu_data_alloc(boot_cpu);
311 if (this_cpu_datap == NULL) {
55e303ae 312 return KERN_FAILURE;
91447636
A
313 }
314 target_cpu = this_cpu_datap->cpu_number;
55e303ae
A
315 assert((boot_cpu && (target_cpu == 0)) ||
316 (!boot_cpu && (target_cpu != 0)));
317
318 lapic_cpu_map(lapic_id, target_cpu);
91447636 319
b0d623f7
A
320 /* The cpu_id is not known at registration phase. Just do
321 * lapic_id for now
322 */
91447636
A
323 this_cpu_datap->cpu_phys_number = lapic_id;
324
325 this_cpu_datap->cpu_console_buf = console_cpu_alloc(boot_cpu);
326 if (this_cpu_datap->cpu_console_buf == NULL)
327 goto failed;
328
0c530ab8
A
329 this_cpu_datap->cpu_chud = chudxnu_cpu_alloc(boot_cpu);
330 if (this_cpu_datap->cpu_chud == NULL)
331 goto failed;
332
91447636 333 if (!boot_cpu) {
593a1d5f 334 cpu_thread_alloc(this_cpu_datap->cpu_number);
2d21ac55
A
335 if (this_cpu_datap->lcpu.core == NULL)
336 goto failed;
337
338 pmCPUStateInit();
0c530ab8 339
b0d623f7 340#if NCOPY_WINDOWS > 0
91447636
A
341 this_cpu_datap->cpu_pmap = pmap_cpu_alloc(boot_cpu);
342 if (this_cpu_datap->cpu_pmap == NULL)
343 goto failed;
b0d623f7 344#endif
91447636
A
345
346 this_cpu_datap->cpu_processor = cpu_processor_alloc(boot_cpu);
347 if (this_cpu_datap->cpu_processor == NULL)
348 goto failed;
2d21ac55
A
349 /*
350 * processor_init() deferred to topology start
351 * because "slot numbers" a.k.a. logical processor numbers
352 * are not yet finalized.
353 */
91447636
A
354 }
355
356 *processor_out = this_cpu_datap->cpu_processor;
2d21ac55 357
55e303ae 358 return KERN_SUCCESS;
91447636
A
359
360failed:
361 cpu_processor_free(this_cpu_datap->cpu_processor);
b0d623f7 362#if NCOPY_WINDOWS > 0
91447636 363 pmap_cpu_free(this_cpu_datap->cpu_pmap);
b0d623f7 364#endif
0c530ab8 365 chudxnu_cpu_free(this_cpu_datap->cpu_chud);
91447636
A
366 console_cpu_free(this_cpu_datap->cpu_console_buf);
367 return KERN_FAILURE;
1c79356b
A
368}
369
b0d623f7
A
370
371kern_return_t
372ml_processor_register(
373 cpu_id_t cpu_id,
374 uint32_t lapic_id,
375 processor_t *processor_out,
376 boolean_t boot_cpu,
377 boolean_t start )
378{
379 static boolean_t done_topo_sort = FALSE;
380 static uint32_t num_registered = 0;
381
382 /* Register all CPUs first, and track max */
383 if( start == FALSE )
384 {
385 num_registered++;
386
387 DBG( "registering CPU lapic id %d\n", lapic_id );
388
389 return register_cpu( lapic_id, processor_out, boot_cpu );
390 }
391
392 /* Sort by topology before we start anything */
393 if( !done_topo_sort )
394 {
395 DBG( "about to start CPUs. %d registered\n", num_registered );
396
397 cpu_topology_sort( num_registered );
398 done_topo_sort = TRUE;
399 }
400
401 /* Assign the cpu ID */
402 uint32_t cpunum = -1;
403 cpu_data_t *this_cpu_datap = NULL;
404
405 /* find cpu num and pointer */
406 cpunum = ml_get_cpuid( lapic_id );
407
408 if( cpunum == 0xFFFFFFFF ) /* never heard of it? */
409 panic( "trying to start invalid/unregistered CPU %d\n", lapic_id );
410
411 this_cpu_datap = cpu_datap(cpunum);
412
413 /* fix the CPU id */
414 this_cpu_datap->cpu_id = cpu_id;
415
416 /* output arg */
417 *processor_out = this_cpu_datap->cpu_processor;
418
419 /* OK, try and start this CPU */
420 return cpu_topology_start_cpu( cpunum );
421}
422
423
43866e37 424void
91447636 425ml_cpu_get_info(ml_cpu_info_t *cpu_infop)
43866e37 426{
55e303ae
A
427 boolean_t os_supports_sse;
428 i386_cpu_info_t *cpuid_infop;
429
91447636 430 if (cpu_infop == NULL)
55e303ae
A
431 return;
432
433 /*
0c530ab8 434 * Are we supporting MMX/SSE/SSE2/SSE3?
55e303ae
A
435 * As distinct from whether the cpu has these capabilities.
436 */
b0d623f7 437 os_supports_sse = !!(get_cr4() & CR4_XMM);
2d21ac55
A
438 if ((cpuid_features() & CPUID_FEATURE_SSE4_2) && os_supports_sse)
439 cpu_infop->vector_unit = 8;
440 else if ((cpuid_features() & CPUID_FEATURE_SSE4_1) && os_supports_sse)
441 cpu_infop->vector_unit = 7;
442 else if ((cpuid_features() & CPUID_FEATURE_SSSE3) && os_supports_sse)
0c530ab8
A
443 cpu_infop->vector_unit = 6;
444 else if ((cpuid_features() & CPUID_FEATURE_SSE3) && os_supports_sse)
445 cpu_infop->vector_unit = 5;
446 else if ((cpuid_features() & CPUID_FEATURE_SSE2) && os_supports_sse)
91447636 447 cpu_infop->vector_unit = 4;
55e303ae 448 else if ((cpuid_features() & CPUID_FEATURE_SSE) && os_supports_sse)
91447636 449 cpu_infop->vector_unit = 3;
55e303ae 450 else if (cpuid_features() & CPUID_FEATURE_MMX)
91447636 451 cpu_infop->vector_unit = 2;
55e303ae 452 else
91447636 453 cpu_infop->vector_unit = 0;
55e303ae
A
454
455 cpuid_infop = cpuid_info();
456
91447636 457 cpu_infop->cache_line_size = cpuid_infop->cache_linesize;
55e303ae 458
91447636
A
459 cpu_infop->l1_icache_size = cpuid_infop->cache_size[L1I];
460 cpu_infop->l1_dcache_size = cpuid_infop->cache_size[L1D];
55e303ae 461
91447636
A
462 if (cpuid_infop->cache_size[L2U] > 0) {
463 cpu_infop->l2_settings = 1;
464 cpu_infop->l2_cache_size = cpuid_infop->cache_size[L2U];
465 } else {
466 cpu_infop->l2_settings = 0;
467 cpu_infop->l2_cache_size = 0xFFFFFFFF;
468 }
55e303ae 469
91447636 470 if (cpuid_infop->cache_size[L3U] > 0) {
0c530ab8
A
471 cpu_infop->l3_settings = 1;
472 cpu_infop->l3_cache_size = cpuid_infop->cache_size[L3U];
91447636
A
473 } else {
474 cpu_infop->l3_settings = 0;
475 cpu_infop->l3_cache_size = 0xFFFFFFFF;
476 }
43866e37
A
477}
478
479void
480ml_init_max_cpus(unsigned long max_cpus)
481{
55e303ae
A
482 boolean_t current_state;
483
484 current_state = ml_set_interrupts_enabled(FALSE);
485 if (max_cpus_initialized != MAX_CPUS_SET) {
91447636
A
486 if (max_cpus > 0 && max_cpus <= MAX_CPUS) {
487 /*
2d21ac55 488 * Note: max_cpus is the number of enabled processors
91447636
A
489 * that ACPI found; max_ncpus is the maximum number
490 * that the kernel supports or that the "cpus="
491 * boot-arg has set. Here we take int minimum.
492 */
b0d623f7 493 machine_info.max_cpus = (integer_t)MIN(max_cpus, max_ncpus);
91447636 494 }
55e303ae
A
495 if (max_cpus_initialized == MAX_CPUS_WAIT)
496 wakeup((event_t)&max_cpus_initialized);
497 max_cpus_initialized = MAX_CPUS_SET;
498 }
499 (void) ml_set_interrupts_enabled(current_state);
43866e37
A
500}
501
502int
503ml_get_max_cpus(void)
504{
55e303ae 505 boolean_t current_state;
43866e37 506
55e303ae
A
507 current_state = ml_set_interrupts_enabled(FALSE);
508 if (max_cpus_initialized != MAX_CPUS_SET) {
509 max_cpus_initialized = MAX_CPUS_WAIT;
510 assert_wait((event_t)&max_cpus_initialized, THREAD_UNINT);
511 (void)thread_block(THREAD_CONTINUE_NULL);
512 }
513 (void) ml_set_interrupts_enabled(current_state);
514 return(machine_info.max_cpus);
43866e37
A
515}
516
0c530ab8
A
517/*
518 * Routine: ml_init_lock_timeout
519 * Function:
520 */
521void
522ml_init_lock_timeout(void)
523{
524 uint64_t abstime;
b0d623f7
A
525 uint32_t mtxspin;
526 uint64_t default_timeout_ns = NSEC_PER_SEC>>2;
527 uint32_t slto;
528
529 if (PE_parse_boot_argn("slto_us", &slto, sizeof (slto)))
530 default_timeout_ns = slto * NSEC_PER_USEC;
0c530ab8 531
2d21ac55 532 /* LockTimeOut is absolutetime, LockTimeOutTSC is in TSC ticks */
b0d623f7 533 nanoseconds_to_absolutetime(default_timeout_ns, &abstime);
2d21ac55
A
534 LockTimeOut = (uint32_t) abstime;
535 LockTimeOutTSC = (uint32_t) tmrCvt(abstime, tscFCvtn2t);
0c530ab8 536
593a1d5f 537 if (PE_parse_boot_argn("mtxspin", &mtxspin, sizeof (mtxspin))) {
0c530ab8
A
538 if (mtxspin > USEC_PER_SEC>>4)
539 mtxspin = USEC_PER_SEC>>4;
540 nanoseconds_to_absolutetime(mtxspin*NSEC_PER_USEC, &abstime);
541 } else {
542 nanoseconds_to_absolutetime(10*NSEC_PER_USEC, &abstime);
543 }
544 MutexSpin = (unsigned int)abstime;
b0d623f7
A
545
546 nanoseconds_to_absolutetime(2 * NSEC_PER_SEC, &LastDebuggerEntryAllowance);
0c530ab8
A
547}
548
91447636
A
549/*
550 * This is called from the machine-independent routine cpu_up()
551 * to perform machine-dependent info updates. Defer to cpu_thread_init().
552 */
553void
554ml_cpu_up(void)
555{
556 return;
557}
558
559/*
560 * This is called from the machine-independent routine cpu_down()
561 * to perform machine-dependent info updates.
562 */
563void
564ml_cpu_down(void)
565{
566 return;
567}
568
91447636
A
569/*
570 * The following are required for parts of the kernel
571 * that cannot resolve these functions as inlines:
572 */
573extern thread_t current_act(void);
574thread_t
9bccf70c 575current_act(void)
91447636
A
576{
577 return(current_thread_fast());
578}
55e303ae
A
579
580#undef current_thread
91447636 581extern thread_t current_thread(void);
55e303ae
A
582thread_t
583current_thread(void)
584{
91447636 585 return(current_thread_fast());
55e303ae 586}
0c530ab8 587
0c530ab8
A
588
589boolean_t ml_is64bit(void) {
590
591 return (cpu_mode_is64bit());
592}
593
594
595boolean_t ml_thread_is64bit(thread_t thread) {
596
597 return (thread_is_64bit(thread));
598}
599
600
601boolean_t ml_state_is64bit(void *saved_state) {
602
603 return is_saved_state64(saved_state);
604}
605
606void ml_cpu_set_ldt(int selector)
607{
608 /*
609 * Avoid loading the LDT
610 * if we're setting the KERNEL LDT and it's already set.
611 */
612 if (selector == KERNEL_LDT &&
613 current_cpu_datap()->cpu_ldt == KERNEL_LDT)
614 return;
615
b0d623f7 616#if defined(__i386__)
0c530ab8
A
617 /*
618 * If 64bit this requires a mode switch (and back).
619 */
620 if (cpu_mode_is64bit())
621 ml_64bit_lldt(selector);
622 else
623 lldt(selector);
b0d623f7
A
624#else
625 lldt(selector);
626#endif
627 current_cpu_datap()->cpu_ldt = selector;
0c530ab8
A
628}
629
630void ml_fp_setvalid(boolean_t value)
631{
632 fp_setvalid(value);
633}
634
2d21ac55
A
635uint64_t ml_cpu_int_event_time(void)
636{
637 return current_cpu_datap()->cpu_int_event_time;
638}
639
b0d623f7
A
640vm_offset_t ml_stack_remaining(void)
641{
642 uintptr_t local = (uintptr_t) &local;
643
644 if (ml_at_interrupt_context() != 0) {
645 return (local - (current_cpu_datap()->cpu_int_stack_top - INTSTACK_SIZE));
646 } else {
647 return (local - current_thread()->kernel_stack);
648 }
649}
2d21ac55 650
0c530ab8
A
651#if MACH_KDB
652
653/*
654 * Display the global msrs
655 * *
656 * ms
657 */
658void
659db_msr(__unused db_expr_t addr,
660 __unused int have_addr,
661 __unused db_expr_t count,
662 __unused char *modif)
663{
664
665 uint32_t i, msrlow, msrhigh;
666
667 /* Try all of the first 4096 msrs */
668 for (i = 0; i < 4096; i++) {
669 if (!rdmsr_carefully(i, &msrlow, &msrhigh)) {
670 db_printf("%08X - %08X.%08X\n", i, msrhigh, msrlow);
671 }
672 }
673
674 /* Try all of the 4096 msrs at 0x0C000000 */
675 for (i = 0; i < 4096; i++) {
676 if (!rdmsr_carefully(0x0C000000 | i, &msrlow, &msrhigh)) {
677 db_printf("%08X - %08X.%08X\n",
678 0x0C000000 | i, msrhigh, msrlow);
679 }
680 }
681
682 /* Try all of the 4096 msrs at 0xC0000000 */
683 for (i = 0; i < 4096; i++) {
684 if (!rdmsr_carefully(0xC0000000 | i, &msrlow, &msrhigh)) {
685 db_printf("%08X - %08X.%08X\n",
686 0xC0000000 | i, msrhigh, msrlow);
687 }
688 }
689}
690
691#endif