diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 31051c7..5f264fb 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -8,6 +8,7 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pit"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 31051c7..5f264fb 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -8,6 +8,7 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pit"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 5d90a70..73309f2 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -51,7 +51,7 @@ for (uint32_t i = 32; i < 48; i++) { subscribeInterrupt(i, irqMaster); } - ioOut(0x21, 0x1, 1); + ioOut(0x21, 0x0, 1); ioOut(0xA1, 0x0, 1); ioOut(0x70, ioIn(0x70, 1) | 0x80, 1); ioIn(0x71, 1); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 31051c7..5f264fb 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -8,6 +8,7 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pit"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 5d90a70..73309f2 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -51,7 +51,7 @@ for (uint32_t i = 32; i < 48; i++) { subscribeInterrupt(i, irqMaster); } - ioOut(0x21, 0x1, 1); + ioOut(0x21, 0x0, 1); ioOut(0xA1, 0x0, 1); ioOut(0x70, ioIn(0x70, 1) | 0x80, 1); ioIn(0x71, 1); diff --git a/src/userland/pit/Makefile b/src/userland/pit/Makefile new file mode 100644 index 0000000..ad7d5fd --- /dev/null +++ b/src/userland/pit/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = pit + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 31051c7..5f264fb 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -8,6 +8,7 @@ printf("HONEY-OS - made by Lukas Eisenhauer\n"); printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); + loadFromInitrd("pit"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/pic/main.c b/src/userland/pic/main.c index 5d90a70..73309f2 100644 --- a/src/userland/pic/main.c +++ b/src/userland/pic/main.c @@ -51,7 +51,7 @@ for (uint32_t i = 32; i < 48; i++) { subscribeInterrupt(i, irqMaster); } - ioOut(0x21, 0x1, 1); + ioOut(0x21, 0x0, 1); ioOut(0xA1, 0x0, 1); ioOut(0x70, ioIn(0x70, 1) | 0x80, 1); ioIn(0x71, 1); diff --git a/src/userland/pit/Makefile b/src/userland/pit/Makefile new file mode 100644 index 0000000..ad7d5fd --- /dev/null +++ b/src/userland/pit/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = pit + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/pit/main.c b/src/userland/pit/main.c new file mode 100644 index 0000000..08d846b --- /dev/null +++ b/src/userland/pit/main.c @@ -0,0 +1,44 @@ +#define ALLOC_MAIN +#include + +#define PIT_A 0x40 +#define PIT_CONTROL 0x43 + +#define PIT_MASK 0xFF +#define PIT_SCALE 1193180 +#define PIT_SET 0x36 + +#define CMD_BINARY 0x00 + +#define CMD_MODE0 0x00 +#define CMD_MODE1 0x02 +#define CMD_MODE2 0x04 +#define CMD_MODE3 0x06 +#define CMD_MODE4 0x08 +#define CMD_MODE5 0x0a + +#define CMD_RW_BOTH 0x30 + +#define CMD_COUNTER0 0x00 +#define CMD_COUNTER2 0x80 + +uint32_t systemTime = 0; + +void interruptHandler() { + systemTime++; + if (!(systemTime % 100)) { + printf("system time: %is\n", systemTime / 100); + } +} + +int32_t main() { + uint32_t service = getService("pic"); + uint32_t event = getEvent(service, "irq0"); + subscribeEvent(service, event, interruptHandler); + uint32_t hz = 100; + int divisor = PIT_SCALE / hz; + ioOut(PIT_CONTROL, CMD_BINARY | CMD_MODE3 | CMD_RW_BOTH | CMD_COUNTER0, 1); + ioOut(PIT_A, (uint8_t)divisor, 1); + ioOut(PIT_A, (uint8_t)(divisor >> 8), 1); + printf("timer handler installed\n"); +}