From e6eb3f50227612725a61bc8ad832e5a66cc25814 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sun, 13 Apr 2008 17:37:41 -0400 Subject: [PATCH] Move timer setup from post.c to clock.c. --- Makefile | 4 ++-- src/clock.c | 31 +++++++++++++++++++++++++++++++ src/post.c | 32 +------------------------------- src/util.h | 1 + 4 files changed, 35 insertions(+), 33 deletions(-) diff --git a/Makefile b/Makefile index 5684af7..3d7c3e2 100644 --- a/Makefile +++ b/Makefile @@ -8,8 +8,8 @@ OUT=out/ # Source files -SRCBOTH=output.c util.c floppy.c ata.c kbd.c pci.c boot.c serial.c -SRC16=$(SRCBOTH) disk.c system.c clock.c mouse.c cdrom.c apm.c pcibios.c +SRCBOTH=output.c util.c floppy.c ata.c kbd.c pci.c boot.c serial.c clock.c +SRC16=$(SRCBOTH) disk.c system.c mouse.c cdrom.c apm.c pcibios.c SRC32=$(SRCBOTH) post.c rombios32.c post_menu.c TABLESRC=font.c cbt.c floppy_dbt.c diff --git a/src/clock.c b/src/clock.c index 4d8643f..ad8347c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -13,6 +13,37 @@ #define DEBUGF1(fmt, args...) bprintf(0, fmt , ##args) #define DEBUGF(fmt, args...) +static void +pit_setup() +{ + // timer0: binary count, 16bit count, mode 2 + outb(0x34, PORT_PIT_MODE); + // maximum count of 0000H = 18.2Hz + outb(0x0, PORT_PIT_COUNTER0); + outb(0x0, PORT_PIT_COUNTER0); +} + +static u32 +bcd2bin(u8 val) +{ + return (val & 0xf) + ((val >> 4) * 10); +} + +void +timer_setup() +{ + pit_setup(); + + u32 seconds = bcd2bin(inb_cmos(CMOS_RTC_SECONDS)); + u32 ticks = (seconds * 18206507) / 1000000; + u32 minutes = bcd2bin(inb_cmos(CMOS_RTC_MINUTES)); + ticks += (minutes * 10923904) / 10000; + u32 hours = bcd2bin(inb_cmos(CMOS_RTC_HOURS)); + ticks += (hours * 65543427) / 1000; + SET_BDA(timer_counter, ticks); + SET_BDA(timer_rollover, 0); +} + static void init_rtc() { diff --git a/src/post.c b/src/post.c index ad60f99..1b9fc5b 100644 --- a/src/post.c +++ b/src/post.c @@ -81,35 +81,6 @@ init_ebda() , offsetof(struct extended_bios_data_area_s, fdpt[1])); } -static void -pit_setup() -{ - // timer0: binary count, 16bit count, mode 2 - outb(0x34, PORT_PIT_MODE); - // maximum count of 0000H = 18.2Hz - outb(0x0, PORT_PIT_COUNTER0); - outb(0x0, PORT_PIT_COUNTER0); -} - -static u32 -bcd2bin(u8 val) -{ - return (val & 0xf) + ((val >> 4) * 10); -} - -static void -timer_setup() -{ - u32 seconds = bcd2bin(inb_cmos(CMOS_RTC_SECONDS)); - u32 ticks = (seconds * 18206507) / 1000000; - u32 minutes = bcd2bin(inb_cmos(CMOS_RTC_MINUTES)); - ticks += (minutes * 10923904) / 10000; - u32 hours = bcd2bin(inb_cmos(CMOS_RTC_HOURS)); - ticks += (hours * 65543427) / 1000; - SET_BDA(timer_counter, ticks); - SET_BDA(timer_rollover, 0); -} - static void pic_setup() { @@ -215,11 +186,10 @@ post() init_handlers(); init_ebda(); - pit_setup(); + timer_setup(); kbd_setup(); lpt_setup(); serial_setup(); - timer_setup(); pic_setup(); rom_scan(0xc0000, 0xc7800); diff --git a/src/util.h b/src/util.h index ec52eac..e304a0b 100644 --- a/src/util.h +++ b/src/util.h @@ -148,6 +148,7 @@ void serial_setup(); void lpt_setup(); // clock.c +void timer_setup(); void handle_1583(struct bregs *regs); // apm.c -- 2.25.1