Skip to content

Commit 3bc4f34

Browse files
authored
[BOOT][HAL] Fix BCD conversion macros (reactos#8574)
- BCD_INT / INT_BCD: Evaluate macro parameter only once - Remove the stdcall calling convention from PC-98 HAL private functions
1 parent 2f5a67f commit 3bc4f34

6 files changed

Lines changed: 53 additions & 28 deletions

File tree

boot/armllb/hw/omap3-zoom2/hwinfo.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010

1111
TIMEINFO LlbTime;
1212

13-
#define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
13+
static
14+
UCHAR
15+
BCD_INT(
16+
_In_ UCHAR Bcd)
17+
{
18+
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
19+
}
1420

1521
ULONG
1622
NTAPI

boot/freeldr/freeldr/arch/i386/pc/pcrtc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@
1818

1919
#include <freeldr.h>
2020

21-
#define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
21+
static
22+
UCHAR
23+
BCD_INT(
24+
_In_ UCHAR Bcd)
25+
{
26+
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
27+
}
2228

2329
TIMEINFO*
2430
PcGetTime(VOID)

boot/freeldr/freeldr/arch/i386/pc98/pc98rtc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77

88
#include <freeldr.h>
99

10-
#define BCD_INT(bcd) (((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
10+
static
11+
UCHAR
12+
BCD_INT(
13+
_In_ UCHAR Bcd)
14+
{
15+
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
16+
}
1117

1218
TIMEINFO*
1319
Pc98GetTime(VOID)

boot/freeldr/freeldr/arch/i386/xbox/xboxrtc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
#define RTC_REGISTER_A 0x0A
2222
#define RTC_REG_A_UIP 0x80 /* Update In Progress bit */
2323

24-
#define BCD_INT(bcd) (((bcd & 0xf0) >> 4) * 10 + (bcd &0x0f))
24+
static
25+
UCHAR
26+
BCD_INT(
27+
_In_ UCHAR Bcd)
28+
{
29+
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
30+
}
2531

2632
static UCHAR
2733
HalpQueryCMOS(UCHAR Reg)

hal/halx86/include/halp.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,21 @@ VOID
6767
#define HALP_LOW_STUB_SIZE_IN_PAGES 3
6868
#endif
6969

70-
/* Conversion functions */
71-
#define BCD_INT(bcd) \
72-
(((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
73-
#define INT_BCD(int) \
74-
(UCHAR)(((int / 10) << 4) + (int % 10))
70+
FORCEINLINE
71+
UCHAR
72+
BCD_INT(
73+
_In_ UCHAR Bcd)
74+
{
75+
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
76+
}
77+
78+
FORCEINLINE
79+
UCHAR
80+
INT_BCD(
81+
_In_ CSHORT Int)
82+
{
83+
return ((Int / 10) << 4) + (Int % 10);
84+
}
7585

7686
typedef
7787
BOOLEAN

hal/halx86/pc98/cmos.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,17 @@ static ULONG_PTR MappedNvram;
3333

3434
/* PRIVATE FUNCTIONS *********************************************************/
3535

36-
/* Avoid double calls */
37-
#undef BCD_INT
38-
static UCHAR
39-
BCD_INT(
40-
_In_ UCHAR Bcd)
41-
{
42-
return ((Bcd & 0xF0) >> 4) * 10 + (Bcd & 0x0F);
43-
}
44-
45-
static UCHAR
46-
NTAPI
36+
static
37+
UCHAR
4738
HalpReadNvram(
4839
_In_ UCHAR Register)
4940
{
5041
return READ_REGISTER_UCHAR((PUCHAR)(MappedNvram + Register));
5142
}
5243

5344
_Requires_lock_held_(HalpSystemHardwareLock)
54-
static VOID
55-
NTAPI
45+
static
46+
VOID
5647
HalpWriteNvram(
5748
_In_ UCHAR Register,
5849
_In_ UCHAR Value)
@@ -63,8 +54,8 @@ HalpWriteNvram(
6354
}
6455

6556
_Requires_lock_held_(HalpSystemHardwareLock)
66-
static UCHAR
67-
NTAPI
57+
static
58+
UCHAR
6859
HalpRtcReadByte(VOID)
6960
{
7061
UCHAR i;
@@ -86,8 +77,8 @@ HalpRtcReadByte(VOID)
8677
}
8778

8879
_Requires_lock_held_(HalpSystemHardwareLock)
89-
static VOID
90-
NTAPI
80+
static
81+
VOID
9182
HalpRtcWriteBit(
9283
_In_ UCHAR Bit)
9384
{
@@ -101,8 +92,8 @@ HalpRtcWriteBit(
10192
}
10293

10394
_Requires_lock_held_(HalpSystemHardwareLock)
104-
static VOID
105-
NTAPI
95+
static
96+
VOID
10697
HalpRtcWriteCommand(
10798
_In_ UCHAR Command)
10899
{

0 commit comments

Comments
 (0)