source: rtems/c/src/lib/libcpu/i386/cache.c @ 328bd35

Last change on this file since 328bd35 was 328bd35, checked in by Joel Sherrill <joel@…>, on Jan 23, 2016 at 7:06:22 PM

i386: refactor libcpu/cpu.h into rtems/score/i386.h

Fixes #2515.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/*
2 *  Cache Management Support Routines for the i386
3 */
4
5#include <rtems.h>
6#include "cache_.h"
7#include <rtems/score/cpu.h>
8#include <libcpu/page.h>
9
10void _CPU_disable_cache(void)
11{
12  unsigned int regCr0;
13
14  regCr0 = i386_get_cr0();
15  regCr0 |= CR0_PAGE_LEVEL_CACHE_DISABLE;
16  regCr0 |= CR0_NO_WRITE_THROUGH;
17  i386_set_cr0( regCr0 );
18  rtems_cache_flush_entire_data();
19}
20
21/*
22 * Enable the entire cache
23 */
24
25void _CPU_enable_cache(void)
26{
27  unsigned int regCr0;
28
29  regCr0 = i386_get_cr0();
30  regCr0 &= ~(CR0_PAGE_LEVEL_CACHE_DISABLE);
31  regCr0 &= ~(CR0_NO_WRITE_THROUGH);
32  i386_set_cr0( regCr0 );
33  /*rtems_cache_flush_entire_data();*/
34}
35
36/*
37 * CACHE MANAGER: The following functions are CPU-specific.
38 * They provide the basic implementation for the rtems_* cache
39 * management routines. If a given function has no meaning for the CPU,
40 * it does nothing by default.
41 *
42 * FIXME: The routines below should be implemented per CPU,
43 *        to accomodate the capabilities of each.
44 */
45
46#if defined(I386_CACHE_ALIGNMENT)
47void _CPU_cache_flush_1_data_line(const void *d_addr) {}
48void _CPU_cache_invalidate_1_data_line(const void *d_addr) {}
49void _CPU_cache_freeze_data(void) {}
50void _CPU_cache_unfreeze_data(void) {}
51void _CPU_cache_invalidate_1_instruction_line ( const void *d_addr ) {}
52void _CPU_cache_freeze_instruction(void) {}
53void _CPU_cache_unfreeze_instruction(void) {}
54
55void _CPU_cache_flush_entire_data(void)
56{
57  __asm__ volatile ("wbinvd");
58}
59void _CPU_cache_invalidate_entire_data(void)
60{
61  __asm__ volatile ("invd");
62}
63
64void _CPU_cache_enable_data(void)
65{
66        _CPU_enable_cache();
67}
68
69void _CPU_cache_disable_data(void)
70{
71        _CPU_disable_cache();
72}
73
74void _CPU_cache_invalidate_entire_instruction(void)
75{
76  __asm__ volatile ("invd");
77}
78
79void _CPU_cache_enable_instruction(void)
80{
81  _CPU_enable_cache();
82}
83
84void _CPU_cache_disable_instruction( void )
85{
86  _CPU_disable_cache();
87}
88#endif
Note: See TracBrowser for help on using the repository browser.