rtc - try implementing RTC / kernel: removed rt from the codebase (released separately)

This commit is contained in:
RaphProductions 2025-05-12 10:24:48 +02:00
parent 6af9752e24
commit 3461dcb1ed
6 changed files with 54 additions and 154 deletions

View file

@ -41,6 +41,7 @@ void idt_init() {
pic_init();
pic_unmask_irq(1);
pic_unmask_irq(8);
__asm__ volatile("lidt %0" : : "m"(idtr)); // load the new IDT
__asm__ volatile("sti"); // set the interrupt flag

View file

@ -45,7 +45,7 @@ void exception_handler(registers_t *regs) {
log("ints - keyboard\n");
} else if (regs->int_no == 32 + 8) {
rtc_handle_interrupt(regs);
log("rtc\n");
} else if (regs->int_no == 0x80 - 32 || regs->int_no == 32) {
pit_handler(regs);
} else if (regs->int_no == 0x80) {

View file

@ -1,28 +1,41 @@
#include "sys/arch/x86_64/idt.h"
#include "sys/arch/x86_64/io.h"
#include <sys/arch/x86_64/pic.h>
#include <sys/arch/x86_64/rtc.h>
#include <sys/printf.h>
#include "rtc.h"
#include "io.h"
void rtc_init() {
asm("cli");
outb(0x70, 0x8A);
outb(0x71, 0x20);
asm("sti");
char bcd;
asm("cli"); // disable interrupts
outb(0x70, 0x8B); // select register B, and disable NMI
char prev = inb(0x71); // read the current value of register B
outb(0x70,
0x8B); // set the index again (a read will reset the index to register D)
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This
// turns on bit 6 of register B
asm("sti");
// pic_unmask_irq(8);
unsigned char read_register(unsigned char reg) {
__asm__ volatile("cli");
outb(RTC_COMMAND, reg);
return inb(RTC_DATA);
__asm__ volatile("sti");
}
void rtc_handle_interrupt(registers_t *regs) {
(void)regs;
printf("RTC!\n");
void write_register(unsigned char reg, unsigned char value) {
__asm__ volatile("cli");
outb(RTC_COMMAND, reg);
outb(RTC_DATA, value);
__asm__ volatile("sti");
}
unsigned char bcd2bin(unsigned char in_bcd) {
return (bcd) ? ((in_bcd >> 4) * 10) + (in_bcd & 0x0F) : in_bcd;
}
int rtc_init() {
__asm__ volatile("cli");
unsigned char status;
status = read_register(RTC_STATUS);
status |= 0x02; // 24 hour clock
status |= 0x10; // update ended interrupts
status &= ~0x20; // no alarm interrupts
status &= ~0x40; // no periodic interrupt
bcd = !(status & 0x04); // check if data type is BCD
write_register(RTC_STATUS, status);
outb(0x70, 0x8B); // select register B, and disable NMI
char prev=inb(0x71); // read the current value of register B
outb(0x70, 0x8B); // set the index again (a read will reset the index to register D)
outb(0x71, prev | 0x40); // write the previous value ORed with 0x40. This turns on bit 6 of register B
__asm__ volatile("sti");
return 0;
}

View file

@ -1,6 +1,18 @@
#pragma once
#ifndef __TIME_H
#define __TIME_H
#include "sys/arch/x86_64/idt.h"
#define RTC_COMMAND 0x70
#define RTC_DATA 0x71
#define RTC_STATUS 0x0B
void rtc_init();
void rtc_handle_interrupt(registers_t *regs);
#define RTC_SECONDS 0x00
#define RTC_MINUTES 0x02
#define RTC_HOURS 0x04
#define RTC_DAY_OF_WEEK 0x06
#define RTC_DAY 0x07
#define RTC_MONTH 0x08
#define RTC_YEAR 0x09
int rtc_init();
#endif // __TIME_H__