From: Duje Mihanović Date: Sat, 14 May 2022 11:22:39 +0000 (+0200) Subject: Add Intel 8254 driver and print elapsed seconds X-Git-Url: http://git.dujemihanovic.xyz/projects?a=commitdiff_plain;h=refs%2Fremotes%2Forigin%2Ftiming;p=nameless-os.git Add Intel 8254 driver and print elapsed seconds --- diff --git a/Makefile b/Makefile index f5a33b6..5373d0b 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ export GIT_REV = $(shell git describe --long HEAD) CFLAGS = -std=gnu99 -g -Iinclude/arch/x86 -ffreestanding -DGIT_COMMIT=\"$(GIT_REV)\" -KERNEL_OBJ = kernel/entry.o kernel/arch/x86/tty/tty.o kernel/drivers/irq/i8259a.o kernel/arch/x86/irq/idt.o kernel/arch/x86/irq/sample_handler.o kernel/kernel.o +KERNEL_OBJ = kernel/entry.o kernel/arch/x86/tty/tty.o kernel/drivers/irq/i8259a.o kernel/arch/x86/irq/idt.o kernel/arch/x86/irq/sample_handler.o kernel/arch/x86/time/i8254.o kernel/kernel.o BOOTLOADER_OBJ = boot/x86/mbr boot/x86/vbr-fat32 boot/x86/stage3/LOADER.BIN default: kernel/kernel.elf bootloader diff --git a/include/arch/x86/time/i8254.h b/include/arch/x86/time/i8254.h new file mode 100644 index 0000000..18a8546 --- /dev/null +++ b/include/arch/x86/time/i8254.h @@ -0,0 +1,46 @@ +#ifndef X86_I8254_H +#define X86_I8254_H + +#include +#include +#include + +/* for setting reload value and reading current count */ +#define PORT_CHANNEL_0_DATA 0x40 +#define PORT_CHANNEL_1_DATA 0x41 +#define PORT_CHANNEL_2_DATA 0x42 + +/* for configuring the channels */ +#define PORT_MODE_CMD_REG 0x43 + +/* operating modes */ +#define INT_ON_TERM_CNT 0x0 +#define HW_RETRIGGER_ONESHOT 0x1 +#define RATE_GENERATOR 0x2 +#define SQUARE_WAVE_GENERATOR 0x3 +#define SW_TRIGGERED_STROBE 0x4 +#define HW_TRIGGERED_STROBE 0x5 + +/* access modes */ +#define ACMODE_COUNTER_LATCH_CMD 0x0 +#define ACMODE_LSB_ONLY 0x1 +#define ACMODE_MSB_ONLY 0x2 +#define ACMODE_LSB_MSB 0x3 + +union mode_command { + struct { + unsigned bcd: 1, /* if set, uses BCD for reload value */ + opmode: 3, /* operating mode */ + acmode: 2, /* access mode */ + channel: 2; /* channel to configure */ + } fields; + uint8_t command; +}; + +extern unsigned int ticks; +extern uint16_t reload; + +extern void i8254_configure_channel(char channel, char opmode, uint16_t new_reload); +extern void i8254_irq_enable(); + +#endif diff --git a/include/arch/x86/tty.h b/include/arch/x86/tty.h index 42857ac..d1d3171 100644 --- a/include/arch/x86/tty.h +++ b/include/arch/x86/tty.h @@ -22,8 +22,10 @@ extern void screen_clear(void); extern void kprint(const char *string, uint8_t color); +extern void kprints(const char *string, uint8_t color); extern void kprintb(const uint8_t byte); extern void kprintw(const uint16_t word); extern void kprintd(const uint32_t dword); +extern void kprintc(const char character, uint8_t color); extern int kprintdec(uint32_t num); #endif diff --git a/kernel/arch/x86/irq/sample_handler.c b/kernel/arch/x86/irq/sample_handler.c index f4f4a4b..be68298 100644 --- a/kernel/arch/x86/irq/sample_handler.c +++ b/kernel/arch/x86/irq/sample_handler.c @@ -2,6 +2,9 @@ #include #include #include +#include