Sparcv9 runs Openboot in 64 bit mode, which means the cell size is 64bit. Use intptr_t where appropriate to make the open firmware calls work. Beware, some values are still 32bit, this matters for example for of_getprop, if you get 32bits into a 64bit variables it will be in the MSB of it (big endian only weakness...) and confuse things. See for example in console.cpp, where the input and output handles are retrieved as 32bit values. It seems wise to check the expected size when using of_getprop in these cases, instead of just checking for errors. Change-Id: Ie72ebc4afe7c6d7602a47478f0bfb6b8247004b8 Reviewed-on: https://review.haiku-os.org/c/1369 Reviewed-by: waddlesplash <[email protected]>
58 lines
1.3 KiB
C++
58 lines
1.3 KiB
C++
/*
|
|
* Copyright 2006, Ingo Weinhold <[email protected]>.
|
|
* Copyright 2010, Andreas Färber <[email protected]>
|
|
* All rights reserved. Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
|
|
#include "real_time_clock.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <boot/kernel_args.h>
|
|
#include <boot/stage2.h>
|
|
#include <platform/openfirmware/devices.h>
|
|
#include <platform/openfirmware/openfirmware.h>
|
|
|
|
|
|
static int sHandle = OF_FAILED;
|
|
|
|
|
|
status_t
|
|
init_real_time_clock(void)
|
|
{
|
|
// find RTC
|
|
intptr_t rtcCookie = 0;
|
|
if (of_get_next_device(&rtcCookie, 0, "rtc",
|
|
gKernelArgs.platform_args.rtc_path,
|
|
sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) {
|
|
printf("init_real_time_clock(): Found no RTC device!");
|
|
return B_ERROR;
|
|
}
|
|
|
|
sHandle = of_open(gKernelArgs.platform_args.rtc_path);
|
|
if (sHandle == OF_FAILED) {
|
|
printf("%s(): Could not open RTC device!\n", __func__);
|
|
return B_ERROR;
|
|
}
|
|
|
|
return B_OK;
|
|
}
|
|
|
|
|
|
bigtime_t
|
|
real_time_clock_usecs(void)
|
|
{
|
|
if (sHandle == OF_FAILED)
|
|
return OF_FAILED;
|
|
int second, minute, hour, day, month, year;
|
|
if (of_call_method(sHandle, "get-time", 0, 6, &year, &month, &day,
|
|
&hour, &minute, &second) == OF_FAILED)
|
|
return OF_FAILED;
|
|
int days = day;
|
|
// TODO: Apply algorithm from kernel
|
|
// to assure monotonically increasing date.
|
|
return (((days * 24 + hour) * 60ULL + minute) * 60ULL + second)
|
|
* 1000000ULL;
|
|
}
|