Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / cmos.h
blob56ccc71a917e3ab3fa8b2710a2f36fc3f6e5cc5b
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2008, 2009 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_CMOS_H
20 #define GRUB_CMOS_H 1
22 #include <grub/types.h>
23 #if !defined (__powerpc__) && !defined (__sparc__)
24 #include <grub/cpu/io.h>
25 #include <grub/cpu/cmos.h>
26 #endif
28 #define GRUB_CMOS_INDEX_SECOND 0
29 #define GRUB_CMOS_INDEX_SECOND_ALARM 1
30 #define GRUB_CMOS_INDEX_MINUTE 2
31 #define GRUB_CMOS_INDEX_MINUTE_ALARM 3
32 #define GRUB_CMOS_INDEX_HOUR 4
33 #define GRUB_CMOS_INDEX_HOUR_ALARM 5
34 #define GRUB_CMOS_INDEX_DAY_OF_WEEK 6
35 #define GRUB_CMOS_INDEX_DAY_OF_MONTH 7
36 #define GRUB_CMOS_INDEX_MONTH 8
37 #define GRUB_CMOS_INDEX_YEAR 9
39 #define GRUB_CMOS_INDEX_STATUS_A 0xA
40 #define GRUB_CMOS_INDEX_STATUS_B 0xB
41 #define GRUB_CMOS_INDEX_STATUS_C 0xC
42 #define GRUB_CMOS_INDEX_STATUS_D 0xD
44 #define GRUB_CMOS_STATUS_B_DAYLIGHT 1
45 #define GRUB_CMOS_STATUS_B_24HOUR 2
46 #define GRUB_CMOS_STATUS_B_BINARY 4
48 static inline grub_uint8_t
49 grub_bcd_to_num (grub_uint8_t a)
51 return ((a >> 4) * 10 + (a & 0xF));
54 static inline grub_uint8_t
55 grub_num_to_bcd (grub_uint8_t a)
57 return (((a / 10) << 4) + (a % 10));
60 #if !defined (__powerpc__) && !defined (__sparc__)
61 static inline grub_err_t
62 grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
64 if (index & 0x80)
66 grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
67 *val = grub_inb (GRUB_CMOS_DATA_REG_HI);
69 else
71 grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
72 *val = grub_inb (GRUB_CMOS_DATA_REG);
74 return GRUB_ERR_NONE;
77 static inline grub_err_t
78 grub_cmos_write (grub_uint8_t index, grub_uint8_t value)
80 if (index & 0x80)
82 grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG_HI);
83 grub_outb (value, GRUB_CMOS_DATA_REG_HI);
85 else
87 grub_outb (index & 0x7f, GRUB_CMOS_ADDR_REG);
88 grub_outb (value, GRUB_CMOS_DATA_REG);
90 return GRUB_ERR_NONE;
92 #else
93 grub_err_t grub_cmos_find_port (void);
94 extern volatile grub_uint8_t *grub_cmos_port;
96 static inline grub_err_t
97 grub_cmos_read (grub_uint8_t index, grub_uint8_t *val)
99 if (!grub_cmos_port)
101 grub_err_t err;
102 err = grub_cmos_find_port ();
103 if (err)
104 return err;
106 grub_cmos_port[((index & 0x80) >> 6) | 0] = index & 0x7f;
107 *val = grub_cmos_port[((index & 0x80) >> 6) | 1];
108 return GRUB_ERR_NONE;
111 static inline grub_err_t
112 grub_cmos_write (grub_uint8_t index, grub_uint8_t val)
114 if (!grub_cmos_port)
116 grub_err_t err;
117 err = grub_cmos_find_port ();
118 if (err)
119 return err;
121 grub_cmos_port[((index & 0x80) >> 6) | 0] = index;
122 grub_cmos_port[((index & 0x80) >> 6) | 1] = val;
123 return GRUB_ERR_NONE;
126 #endif
128 #endif /* GRUB_CMOS_H */