diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index b0e2cce..167035c 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -50,6 +50,44 @@ return max(size, 2); } +uint32_t power(uint32_t x, uint32_t y) { + uint32_t result = 1; + for (int i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(uint32_t x) { + if (x == 0) { + return 1; + } + for (int i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uint32_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (int i = 10; i >= 0; i--) { + uint32_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + uint32_t getInsertLength(char insertType, uint32_t x) { switch (insertType) { case 's': @@ -58,6 +96,8 @@ return hexLength(x); case 'c': return 1; + case 'i': + return intLength(x); } return 0; } @@ -82,6 +122,8 @@ case 'c': **write = x; return; + case 'i': + putInt(write, x); } } diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index b0e2cce..167035c 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -50,6 +50,44 @@ return max(size, 2); } +uint32_t power(uint32_t x, uint32_t y) { + uint32_t result = 1; + for (int i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(uint32_t x) { + if (x == 0) { + return 1; + } + for (int i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uint32_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (int i = 10; i >= 0; i--) { + uint32_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + uint32_t getInsertLength(char insertType, uint32_t x) { switch (insertType) { case 's': @@ -58,6 +96,8 @@ return hexLength(x); case 'c': return 1; + case 'i': + return intLength(x); } return 0; } @@ -82,6 +122,8 @@ case 'c': **write = x; return; + case 'i': + putInt(write, x); } } diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 20800e6..46071c6 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -63,6 +63,13 @@ setCursorOffset(cursorOffset); } +void clearLine() { + uint8_t y = cursorOffset / VIDEO_WIDTH; + for (int x = 0; x < VIDEO_WIDTH; x++) { + setCharAtOffset(getOffset(x, y), ' ', currentFormat); + } +} + typedef enum { STANDARD, ANSI_ESCAPE } States; typedef enum { BRACKET_OPEN, BUFFER } AnsiEscapeStates; @@ -181,6 +188,11 @@ setCursorOffset(cursorOffset); currentState = STANDARD; return; + case 'k': + setCursorOffset(getOffset(0, cursorOffset / VIDEO_WIDTH)); + clearLine(); + currentState = STANDARD; + return; } } } diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index b0e2cce..167035c 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -50,6 +50,44 @@ return max(size, 2); } +uint32_t power(uint32_t x, uint32_t y) { + uint32_t result = 1; + for (int i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(uint32_t x) { + if (x == 0) { + return 1; + } + for (int i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uint32_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (int i = 10; i >= 0; i--) { + uint32_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + uint32_t getInsertLength(char insertType, uint32_t x) { switch (insertType) { case 's': @@ -58,6 +96,8 @@ return hexLength(x); case 'c': return 1; + case 'i': + return intLength(x); } return 0; } @@ -82,6 +122,8 @@ case 'c': **write = x; return; + case 'i': + putInt(write, x); } } diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 20800e6..46071c6 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -63,6 +63,13 @@ setCursorOffset(cursorOffset); } +void clearLine() { + uint8_t y = cursorOffset / VIDEO_WIDTH; + for (int x = 0; x < VIDEO_WIDTH; x++) { + setCharAtOffset(getOffset(x, y), ' ', currentFormat); + } +} + typedef enum { STANDARD, ANSI_ESCAPE } States; typedef enum { BRACKET_OPEN, BUFFER } AnsiEscapeStates; @@ -181,6 +188,11 @@ setCursorOffset(cursorOffset); currentState = STANDARD; return; + case 'k': + setCursorOffset(getOffset(0, cursorOffset / VIDEO_WIDTH)); + clearLine(); + currentState = STANDARD; + return; } } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index f9b549f..e7452b5 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ printCPUData(); getCurrentTask()->timerTicks = 1000; getCurrentTask()->ticksLeft = 0; + scanPCIDevices(); while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); @@ -37,7 +39,7 @@ printf("%s", message->data); break; case TIMER_UPDATE: - printf("\e[s\e[Htime since power on :0x%x seconds\e[u", + printf("\e[s\e[Htime since power on: %i seconds\e[u", (uint32_t)message->data / 1000); } free(message); diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index b0e2cce..167035c 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -50,6 +50,44 @@ return max(size, 2); } +uint32_t power(uint32_t x, uint32_t y) { + uint32_t result = 1; + for (int i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(uint32_t x) { + if (x == 0) { + return 1; + } + for (int i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uint32_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (int i = 10; i >= 0; i--) { + uint32_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + uint32_t getInsertLength(char insertType, uint32_t x) { switch (insertType) { case 's': @@ -58,6 +96,8 @@ return hexLength(x); case 'c': return 1; + case 'i': + return intLength(x); } return 0; } @@ -82,6 +122,8 @@ case 'c': **write = x; return; + case 'i': + putInt(write, x); } } diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 20800e6..46071c6 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -63,6 +63,13 @@ setCursorOffset(cursorOffset); } +void clearLine() { + uint8_t y = cursorOffset / VIDEO_WIDTH; + for (int x = 0; x < VIDEO_WIDTH; x++) { + setCharAtOffset(getOffset(x, y), ' ', currentFormat); + } +} + typedef enum { STANDARD, ANSI_ESCAPE } States; typedef enum { BRACKET_OPEN, BUFFER } AnsiEscapeStates; @@ -181,6 +188,11 @@ setCursorOffset(cursorOffset); currentState = STANDARD; return; + case 'k': + setCursorOffset(getOffset(0, cursorOffset / VIDEO_WIDTH)); + clearLine(); + currentState = STANDARD; + return; } } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index f9b549f..e7452b5 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ printCPUData(); getCurrentTask()->timerTicks = 1000; getCurrentTask()->ticksLeft = 0; + scanPCIDevices(); while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); @@ -37,7 +39,7 @@ printf("%s", message->data); break; case TIMER_UPDATE: - printf("\e[s\e[Htime since power on :0x%x seconds\e[u", + printf("\e[s\e[Htime since power on: %i seconds\e[u", (uint32_t)message->data / 1000); } free(message); diff --git a/src/kernel/util/ports.c b/src/kernel/util/ports.c index ab0066e..e5bbae8 100644 --- a/src/kernel/util/ports.c +++ b/src/kernel/util/ports.c @@ -2,15 +2,23 @@ #include void outb(uint16_t port, uint8_t val) { - asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) ); + asm volatile("outb %0, %1" : : "a"(val), "Nd"(port)); } uint8_t inb(uint16_t port) { - uint8_t result; - __asm__("in %%dx, %%al" : "=a" (result) : "d" (port)); - return result; + uint8_t result; + __asm__("in %%dx, %%al" : "=a"(result) : "d"(port)); + return result; } -void ioWait() { - asm volatile ( "outb %%al, $0x80" : : "a"(0) ); -} \ No newline at end of file +void outi(uint16_t port, uint32_t val) { + asm volatile("outl %0, %1" : : "a"(val), "Nd"(port)); +} + +uint32_t ini(uint16_t port) { + uint32_t result; + __asm__("in %%dx, %%eax" : "=a"(result) : "d"(port)); + return result; +} + +void ioWait() { asm volatile("outb %%al, $0x80" : : "a"(0)); } diff --git a/Makefile b/Makefile index 0b66ce3..74dfe18 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ GENISO = genisoimage GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os EMU = qemu-system-x86_64 -EMUFLAGS = -m 256M -cdrom +EMUFLAGS = -m 256M -usb BUILD_FOLDER = build @@ -41,4 +41,4 @@ rm -r $(BUILD_FOLDER) tree-os.iso iso/boot/tree-os.elf cleanELF: - rm iso/boot/tree-os.elf \ No newline at end of file + rm iso/boot/tree-os.elf diff --git a/src/include/pci.h b/src/include/pci.h new file mode 100644 index 0000000..8377ed7 --- /dev/null +++ b/src/include/pci.h @@ -0,0 +1,6 @@ +#ifndef PCI_H +#define PCI_H + +extern void scanPCIDevices(); + +#endif diff --git a/src/include/ports.h b/src/include/ports.h index a47812e..758d89e 100644 --- a/src/include/ports.h +++ b/src/include/ports.h @@ -6,6 +6,9 @@ extern void outb(uint16_t port, uint8_t val); extern uint8_t inb(uint16_t port); +extern void outi(uint16_t port, uint32_t val); +extern uint32_t ini(uint16_t port); + extern void ioWait(); -#endif \ No newline at end of file +#endif diff --git a/src/kernel/drivers/interrupts/keyboard/keyboard.c b/src/kernel/drivers/interrupts/keyboard/keyboard.c index 493608c..94b3dad 100644 --- a/src/kernel/drivers/interrupts/keyboard/keyboard.c +++ b/src/kernel/drivers/interrupts/keyboard/keyboard.c @@ -9,9 +9,6 @@ #include #include -uint64_t pressedKeys1 = 0; -uint64_t pressedKeys2 = 0; - enum { MODIFIER_LEFT_SHIFT = 0x01 << 0, MODIFIER_RIGHT_SHIFT = 0x01 << 1, @@ -97,11 +94,17 @@ return; } } + void *data = NULL; if (modifiers & MODIFIER_LEFT_SHIFT || modifiers & MODIFIER_RIGHT_SHIFT) { - printf("%c", capitalKeycodes[scancode]); + data = capitalKeycodes[scancode]; } else { - printf("%c", keycodes[scancode]); + data = keycodes[scancode]; } + Message *message = malloc(sizeof(Message)); + message->data = data; + message->size = 1; + message->type = KEYBOARD_CHAR; + listAdd(&(getKeyboardConsumer()->messages), message); } void setupKeyboard() { setIRQHandler(1, &keyboardHandler); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c new file mode 100644 index 0000000..c0b4336 --- /dev/null +++ b/src/kernel/drivers/pci/pci.c @@ -0,0 +1,63 @@ +#include <_stdio.h> +#include +#include +#include +#include +#include + +uint8_t pciConfigReadByte(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + uint32_t lbus = (uint32_t)bus; + uint32_t lslot = (uint32_t)device; + uint32_t lfunc = (uint32_t)function; + + uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | + (offset & 0xFC) | ((uint32_t)0x80000000)); + outi(0xCF8, address); + ioWait(); + return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); +} + +uint16_t pciConfigReadWord(uint8_t bus, uint8_t device, uint8_t function, + uint8_t offset) { + return (uint16_t)pciConfigReadByte(bus, device, function, offset) << 8 | + (uint16_t)pciConfigReadByte(bus, device, function, offset + 1); +} + +uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadByte(bus, device, function, 0x0D); +} + +uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { + return pciConfigReadWord(bus, device, function, 2); +} + +void checkDevice(uint8_t bus, uint8_t device) { + uint16_t vendorID = getVendorID(bus, device, 0); + if (vendorID == 0xFFFF) + return; + printf("checking device %i;%i\n", bus, device); +} + +void checkBus(uint8_t bus) { + printf("checking bus %i...\n", bus); + yields(); + for (uint8_t device = 0; device < 32; device++) { + checkDevice(bus, device); + yields(); + } +} + +void scanPCIDevices() { + printf("scanning pci devices...\n"); + yields(); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + printf("discovored a single pci bus\n"); + yields(); + // singe bus + checkBus(0); + return; + } + printf("multiple pci buses are not implemented yet!\n"); + yields(); +} diff --git a/src/kernel/drivers/textMode/_stdio.c b/src/kernel/drivers/textMode/_stdio.c index b0e2cce..167035c 100644 --- a/src/kernel/drivers/textMode/_stdio.c +++ b/src/kernel/drivers/textMode/_stdio.c @@ -50,6 +50,44 @@ return max(size, 2); } +uint32_t power(uint32_t x, uint32_t y) { + uint32_t result = 1; + for (int i = 0; i < y; i++) { + result *= x; + } + return result; +} + +uint32_t intLength(uint32_t x) { + if (x == 0) { + return 1; + } + for (int i = 10; i >= 0; i--) { + if (x / power(10, i) > 0) { + return i + 1; + } + } + return 1; +} + +void addChar(char **write, char c) { + **write = c; + (*write)++; +} + +void putInt(char **write, uint32_t x) { + if (x == 0) { + addChar(write, '0'); + return; + } + for (int i = 10; i >= 0; i--) { + uint32_t n = x / power(10, i); + if (n) { + addChar(write, HEX_CHARS[n % 10]); + } + } +} + uint32_t getInsertLength(char insertType, uint32_t x) { switch (insertType) { case 's': @@ -58,6 +96,8 @@ return hexLength(x); case 'c': return 1; + case 'i': + return intLength(x); } return 0; } @@ -82,6 +122,8 @@ case 'c': **write = x; return; + case 'i': + putInt(write, x); } } diff --git a/src/kernel/drivers/textMode/terminal.c b/src/kernel/drivers/textMode/terminal.c index 20800e6..46071c6 100644 --- a/src/kernel/drivers/textMode/terminal.c +++ b/src/kernel/drivers/textMode/terminal.c @@ -63,6 +63,13 @@ setCursorOffset(cursorOffset); } +void clearLine() { + uint8_t y = cursorOffset / VIDEO_WIDTH; + for (int x = 0; x < VIDEO_WIDTH; x++) { + setCharAtOffset(getOffset(x, y), ' ', currentFormat); + } +} + typedef enum { STANDARD, ANSI_ESCAPE } States; typedef enum { BRACKET_OPEN, BUFFER } AnsiEscapeStates; @@ -181,6 +188,11 @@ setCursorOffset(cursorOffset); currentState = STANDARD; return; + case 'k': + setCursorOffset(getOffset(0, cursorOffset / VIDEO_WIDTH)); + clearLine(); + currentState = STANDARD; + return; } } } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index f9b549f..e7452b5 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,7 @@ printCPUData(); getCurrentTask()->timerTicks = 1000; getCurrentTask()->ticksLeft = 0; + scanPCIDevices(); while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); @@ -37,7 +39,7 @@ printf("%s", message->data); break; case TIMER_UPDATE: - printf("\e[s\e[Htime since power on :0x%x seconds\e[u", + printf("\e[s\e[Htime since power on: %i seconds\e[u", (uint32_t)message->data / 1000); } free(message); diff --git a/src/kernel/util/ports.c b/src/kernel/util/ports.c index ab0066e..e5bbae8 100644 --- a/src/kernel/util/ports.c +++ b/src/kernel/util/ports.c @@ -2,15 +2,23 @@ #include void outb(uint16_t port, uint8_t val) { - asm volatile("outb %0, %1" : : "a"(val), "Nd"(port) ); + asm volatile("outb %0, %1" : : "a"(val), "Nd"(port)); } uint8_t inb(uint16_t port) { - uint8_t result; - __asm__("in %%dx, %%al" : "=a" (result) : "d" (port)); - return result; + uint8_t result; + __asm__("in %%dx, %%al" : "=a"(result) : "d"(port)); + return result; } -void ioWait() { - asm volatile ( "outb %%al, $0x80" : : "a"(0) ); -} \ No newline at end of file +void outi(uint16_t port, uint32_t val) { + asm volatile("outl %0, %1" : : "a"(val), "Nd"(port)); +} + +uint32_t ini(uint16_t port) { + uint32_t result; + __asm__("in %%dx, %%eax" : "=a"(result) : "d"(port)); + return result; +} + +void ioWait() { asm volatile("outb %%al, $0x80" : : "a"(0)); } diff --git a/src/kernel/util/tree-os.c b/src/kernel/util/tree-os.c index f2ada34..9e73134 100644 --- a/src/kernel/util/tree-os.c +++ b/src/kernel/util/tree-os.c @@ -12,7 +12,7 @@ void drawLogo() { printf(logo); - printf("TREE-OS v. alpha 0.1 (IN DEVELOPMENT)\n\n"); + printf("TREE-OS (IN DEVELOPMENT)\n\n"); yields(); setTextStyle(0x0F); }