diff --git a/platform/pc/cmos.c b/platform/pc/cmos.c new file mode 100644 index 00000000..2a4eb2bc --- /dev/null +++ b/platform/pc/cmos.c @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#include + +#include +#include +#include +#include + +static spin_lock_t lock = SPIN_LOCK_INITIAL_VALUE; + +uint8_t cmos_read(uint8_t reg) { + spin_lock_saved_state_t state; + spin_lock_irqsave(&lock, state); + + outp(CMOS_CONTROL_REG, reg | 0x80); + uint8_t val = inp(CMOS_DATA_REG); + + spin_unlock_irqrestore(&lock, state); + + return val; +} + + diff --git a/platform/pc/include/platform/cmos.h b/platform/pc/include/platform/cmos.h new file mode 100644 index 00000000..b5619b0a --- /dev/null +++ b/platform/pc/include/platform/cmos.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2019 Travis Geiselbrecht + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +#pragma once + +#include + +/* cmos map for PC */ +#define CMOS_REG_FLOPPY (0x10) + +uint8_t cmos_read(uint8_t reg); diff --git a/platform/pc/include/platform/pc/iomap.h b/platform/pc/include/platform/pc/iomap.h index e4cb9379..12007011 100644 --- a/platform/pc/include/platform/pc/iomap.h +++ b/platform/pc/include/platform/pc/iomap.h @@ -16,6 +16,10 @@ #define I8042_STATUS_REG 0x64 #define I8042_DATA_REG 0x60 +/* CMOS/RTC registers */ +#define CMOS_CONTROL_REG 0x70 +#define CMOS_DATA_REG 0x71 + /* CGA registers */ #define CGA_INDEX_REG 0x3d4 #define CGA_DATA_REG 0x3d5 diff --git a/platform/pc/rules.mk b/platform/pc/rules.mk index 5234cd51..d4dc0ef5 100644 --- a/platform/pc/rules.mk +++ b/platform/pc/rules.mk @@ -17,6 +17,7 @@ MODULE_DEPS += dev/net/e1000 endif MODULE_SRCS += \ + $(LOCAL_DIR)/cmos.c \ $(LOCAL_DIR)/console.c \ $(LOCAL_DIR)/debug.c \ $(LOCAL_DIR)/ide.c \ diff --git a/platform/pc/timer.c b/platform/pc/timer.c index 96df0464..ba4b852b 100644 --- a/platform/pc/timer.c +++ b/platform/pc/timer.c @@ -147,7 +147,6 @@ static void platform_halt_timers(void) { status_t platform_set_oneshot_timer(platform_timer_callback callback, void *arg, lk_time_t interval) { - uint32_t count; spin_lock_saved_state_t state;