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

@ -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;
}