diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index c0b4336..eb49162 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -5,59 +5,94 @@ #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; +char *classNames[] = { + "Unclassified", + "Mass Storage Controller", + "Network controller", + "Display controller", + "Multimedia controller", + "Memory Controller", + "Bridge", + "Simple Communication controller", + "Base System Peripheral", + "Input Device controller", + "Docking station", + "Processor", + "Serial bus controller", + "Wireless controller", + "intelligent controller", + "sattelite communication controller", + "encryption controller", + "signal processing controller", + "processing accelerator", + "non-essential instrumentation", +}; - uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | - (offset & 0xFC) | ((uint32_t)0x80000000)); +uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, + uint8_t offset) { + uint32_t address = ((bus << 16) | (device << 11) | (function << 8) | + (offset & 0xFC) | 0x80000000); + asm("cli"); outi(0xCF8, address); - ioWait(); - return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); + uint8_t result = (ini(0xCFC) >> ((offset % 4) * 8)); + asm("sti"); + return result; } 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); + return (uint16_t)pciConfigReadByte(bus, device, function, offset) | + ((uint16_t)pciConfigReadByte(bus, device, function, offset + 1) + << 8); } uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadByte(bus, device, function, 0x0D); + return pciConfigReadByte(bus, device, function, 0x0E); } uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadWord(bus, device, function, 2); + return pciConfigReadWord(bus, device, function, 0); +} + +void checkFunction(uint8_t bus, uint8_t device, uint8_t function) { + uint8_t class = pciConfigReadByte(bus, device, function, 0xB); + uint8_t subclass = pciConfigReadByte(bus, device, function, 0xA); + printf("function %i:%i:%i -> %i:%i, a %s\n", bus, device, function, class, + subclass, classNames[class]); } void checkDevice(uint8_t bus, uint8_t device) { uint16_t vendorID = getVendorID(bus, device, 0); - if (vendorID == 0xFFFF) + if (vendorID == 0xFFFF) { return; - printf("checking device %i;%i\n", bus, device); + } + if (getHeaderType(bus, device, 0) & 0x08) { + // multifunction device + for (int function = 0; function < 8; function++) { + if (getVendorID(bus, device, function) != 0xFFFF) { + checkFunction(bus, device, function); + } + } + } else { + checkFunction(bus, device, 0); + } } 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 + printf("discovored a single pci host controller\n"); checkBus(0); - return; + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } } - printf("multiple pci buses are not implemented yet!\n"); yields(); } diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index c0b4336..eb49162 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -5,59 +5,94 @@ #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; +char *classNames[] = { + "Unclassified", + "Mass Storage Controller", + "Network controller", + "Display controller", + "Multimedia controller", + "Memory Controller", + "Bridge", + "Simple Communication controller", + "Base System Peripheral", + "Input Device controller", + "Docking station", + "Processor", + "Serial bus controller", + "Wireless controller", + "intelligent controller", + "sattelite communication controller", + "encryption controller", + "signal processing controller", + "processing accelerator", + "non-essential instrumentation", +}; - uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | - (offset & 0xFC) | ((uint32_t)0x80000000)); +uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, + uint8_t offset) { + uint32_t address = ((bus << 16) | (device << 11) | (function << 8) | + (offset & 0xFC) | 0x80000000); + asm("cli"); outi(0xCF8, address); - ioWait(); - return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); + uint8_t result = (ini(0xCFC) >> ((offset % 4) * 8)); + asm("sti"); + return result; } 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); + return (uint16_t)pciConfigReadByte(bus, device, function, offset) | + ((uint16_t)pciConfigReadByte(bus, device, function, offset + 1) + << 8); } uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadByte(bus, device, function, 0x0D); + return pciConfigReadByte(bus, device, function, 0x0E); } uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadWord(bus, device, function, 2); + return pciConfigReadWord(bus, device, function, 0); +} + +void checkFunction(uint8_t bus, uint8_t device, uint8_t function) { + uint8_t class = pciConfigReadByte(bus, device, function, 0xB); + uint8_t subclass = pciConfigReadByte(bus, device, function, 0xA); + printf("function %i:%i:%i -> %i:%i, a %s\n", bus, device, function, class, + subclass, classNames[class]); } void checkDevice(uint8_t bus, uint8_t device) { uint16_t vendorID = getVendorID(bus, device, 0); - if (vendorID == 0xFFFF) + if (vendorID == 0xFFFF) { return; - printf("checking device %i;%i\n", bus, device); + } + if (getHeaderType(bus, device, 0) & 0x08) { + // multifunction device + for (int function = 0; function < 8; function++) { + if (getVendorID(bus, device, function) != 0xFFFF) { + checkFunction(bus, device, function); + } + } + } else { + checkFunction(bus, device, 0); + } } 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 + printf("discovored a single pci host controller\n"); checkBus(0); - return; + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } } - printf("multiple pci buses are not implemented yet!\n"); yields(); } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e7452b5..15713cc 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -20,11 +20,11 @@ drawLogo(); setupDevices(); setupInterrupts(); - printf("cpu data:\n"); printCPUData(); - getCurrentTask()->timerTicks = 1000; - getCurrentTask()->ticksLeft = 0; scanPCIDevices(); + yields(); + getCurrentTask()->timerTicks = 1000; + getCurrentTask()->ticksLeft = 1000; while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index c0b4336..eb49162 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -5,59 +5,94 @@ #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; +char *classNames[] = { + "Unclassified", + "Mass Storage Controller", + "Network controller", + "Display controller", + "Multimedia controller", + "Memory Controller", + "Bridge", + "Simple Communication controller", + "Base System Peripheral", + "Input Device controller", + "Docking station", + "Processor", + "Serial bus controller", + "Wireless controller", + "intelligent controller", + "sattelite communication controller", + "encryption controller", + "signal processing controller", + "processing accelerator", + "non-essential instrumentation", +}; - uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | - (offset & 0xFC) | ((uint32_t)0x80000000)); +uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, + uint8_t offset) { + uint32_t address = ((bus << 16) | (device << 11) | (function << 8) | + (offset & 0xFC) | 0x80000000); + asm("cli"); outi(0xCF8, address); - ioWait(); - return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); + uint8_t result = (ini(0xCFC) >> ((offset % 4) * 8)); + asm("sti"); + return result; } 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); + return (uint16_t)pciConfigReadByte(bus, device, function, offset) | + ((uint16_t)pciConfigReadByte(bus, device, function, offset + 1) + << 8); } uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadByte(bus, device, function, 0x0D); + return pciConfigReadByte(bus, device, function, 0x0E); } uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadWord(bus, device, function, 2); + return pciConfigReadWord(bus, device, function, 0); +} + +void checkFunction(uint8_t bus, uint8_t device, uint8_t function) { + uint8_t class = pciConfigReadByte(bus, device, function, 0xB); + uint8_t subclass = pciConfigReadByte(bus, device, function, 0xA); + printf("function %i:%i:%i -> %i:%i, a %s\n", bus, device, function, class, + subclass, classNames[class]); } void checkDevice(uint8_t bus, uint8_t device) { uint16_t vendorID = getVendorID(bus, device, 0); - if (vendorID == 0xFFFF) + if (vendorID == 0xFFFF) { return; - printf("checking device %i;%i\n", bus, device); + } + if (getHeaderType(bus, device, 0) & 0x08) { + // multifunction device + for (int function = 0; function < 8; function++) { + if (getVendorID(bus, device, function) != 0xFFFF) { + checkFunction(bus, device, function); + } + } + } else { + checkFunction(bus, device, 0); + } } 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 + printf("discovored a single pci host controller\n"); checkBus(0); - return; + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } } - printf("multiple pci buses are not implemented yet!\n"); yields(); } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e7452b5..15713cc 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -20,11 +20,11 @@ drawLogo(); setupDevices(); setupInterrupts(); - printf("cpu data:\n"); printCPUData(); - getCurrentTask()->timerTicks = 1000; - getCurrentTask()->ticksLeft = 0; scanPCIDevices(); + yields(); + getCurrentTask()->timerTicks = 1000; + getCurrentTask()->ticksLeft = 1000; while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index da46b2e..37ab866 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -26,6 +26,8 @@ void initOSTasks() { setRunningTask(&mainTask); + mainTask.ticksLeft = -1; + mainTask.timerTicks = -1; keyboardConsumer = &mainTask; createTask(&printerTask, (uint32_t)printLoop, 0x0, 0x0); schedule(&printerTask); diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index c0b4336..eb49162 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -5,59 +5,94 @@ #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; +char *classNames[] = { + "Unclassified", + "Mass Storage Controller", + "Network controller", + "Display controller", + "Multimedia controller", + "Memory Controller", + "Bridge", + "Simple Communication controller", + "Base System Peripheral", + "Input Device controller", + "Docking station", + "Processor", + "Serial bus controller", + "Wireless controller", + "intelligent controller", + "sattelite communication controller", + "encryption controller", + "signal processing controller", + "processing accelerator", + "non-essential instrumentation", +}; - uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | - (offset & 0xFC) | ((uint32_t)0x80000000)); +uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, + uint8_t offset) { + uint32_t address = ((bus << 16) | (device << 11) | (function << 8) | + (offset & 0xFC) | 0x80000000); + asm("cli"); outi(0xCF8, address); - ioWait(); - return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); + uint8_t result = (ini(0xCFC) >> ((offset % 4) * 8)); + asm("sti"); + return result; } 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); + return (uint16_t)pciConfigReadByte(bus, device, function, offset) | + ((uint16_t)pciConfigReadByte(bus, device, function, offset + 1) + << 8); } uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadByte(bus, device, function, 0x0D); + return pciConfigReadByte(bus, device, function, 0x0E); } uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadWord(bus, device, function, 2); + return pciConfigReadWord(bus, device, function, 0); +} + +void checkFunction(uint8_t bus, uint8_t device, uint8_t function) { + uint8_t class = pciConfigReadByte(bus, device, function, 0xB); + uint8_t subclass = pciConfigReadByte(bus, device, function, 0xA); + printf("function %i:%i:%i -> %i:%i, a %s\n", bus, device, function, class, + subclass, classNames[class]); } void checkDevice(uint8_t bus, uint8_t device) { uint16_t vendorID = getVendorID(bus, device, 0); - if (vendorID == 0xFFFF) + if (vendorID == 0xFFFF) { return; - printf("checking device %i;%i\n", bus, device); + } + if (getHeaderType(bus, device, 0) & 0x08) { + // multifunction device + for (int function = 0; function < 8; function++) { + if (getVendorID(bus, device, function) != 0xFFFF) { + checkFunction(bus, device, function); + } + } + } else { + checkFunction(bus, device, 0); + } } 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 + printf("discovored a single pci host controller\n"); checkBus(0); - return; + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } } - printf("multiple pci buses are not implemented yet!\n"); yields(); } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e7452b5..15713cc 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -20,11 +20,11 @@ drawLogo(); setupDevices(); setupInterrupts(); - printf("cpu data:\n"); printCPUData(); - getCurrentTask()->timerTicks = 1000; - getCurrentTask()->ticksLeft = 0; scanPCIDevices(); + yields(); + getCurrentTask()->timerTicks = 1000; + getCurrentTask()->ticksLeft = 1000; while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index da46b2e..37ab866 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -26,6 +26,8 @@ void initOSTasks() { setRunningTask(&mainTask); + mainTask.ticksLeft = -1; + mainTask.timerTicks = -1; keyboardConsumer = &mainTask; createTask(&printerTask, (uint32_t)printLoop, 0x0, 0x0); schedule(&printerTask); diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 47f2f69..e001f9f 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -26,7 +26,7 @@ task->stack = stack; task->messages = NULL; task->ticksLeft = -1; - task->timerTicks = 0; + task->timerTicks = -1; } void yield() { diff --git a/README.md b/README.md index 8fcb978..f428588 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # tree-os -An open source operating system, made for x86(_64) \ No newline at end of file +An open source operating system, made for x86(_64) to learn about how and why modern systems what exactly they do. + +Right now, there exists a memory allocation system, a multitasking framework supporting messages between tasks and an interrupt system to for example allow for keyboard input. + +A Pci system is in progress and can currently read the bus and print out the different device types that can be found. + +## screenshot + +![](tree-os.png) diff --git a/src/kernel/drivers/cpu/cpuid.c b/src/kernel/drivers/cpu/cpuid.c index 2ab6e70..436aa2e 100644 --- a/src/kernel/drivers/cpu/cpuid.c +++ b/src/kernel/drivers/cpu/cpuid.c @@ -4,11 +4,9 @@ extern void getVendorId(char *string); +char *vendorID = "xxxxxxxxxxxx"; + void printCPUData() { - char *vendorID = malloc(13 * sizeof(char)); - vendorID[12] = 0x00; getVendorId(vendorID); printf("vendor id: %s\n", vendorID); - free(vendorID); - yields(); } diff --git a/src/kernel/drivers/pci/pci.c b/src/kernel/drivers/pci/pci.c index c0b4336..eb49162 100644 --- a/src/kernel/drivers/pci/pci.c +++ b/src/kernel/drivers/pci/pci.c @@ -5,59 +5,94 @@ #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; +char *classNames[] = { + "Unclassified", + "Mass Storage Controller", + "Network controller", + "Display controller", + "Multimedia controller", + "Memory Controller", + "Bridge", + "Simple Communication controller", + "Base System Peripheral", + "Input Device controller", + "Docking station", + "Processor", + "Serial bus controller", + "Wireless controller", + "intelligent controller", + "sattelite communication controller", + "encryption controller", + "signal processing controller", + "processing accelerator", + "non-essential instrumentation", +}; - uint32_t address = (uint32_t)((lbus << 16) | (lslot << 11) | (lfunc << 8) | - (offset & 0xFC) | ((uint32_t)0x80000000)); +uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, + uint8_t offset) { + uint32_t address = ((bus << 16) | (device << 11) | (function << 8) | + (offset & 0xFC) | 0x80000000); + asm("cli"); outi(0xCF8, address); - ioWait(); - return (uint8_t)(ini(0xCFC) >> ((offset & 3) * 8)); + uint8_t result = (ini(0xCFC) >> ((offset % 4) * 8)); + asm("sti"); + return result; } 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); + return (uint16_t)pciConfigReadByte(bus, device, function, offset) | + ((uint16_t)pciConfigReadByte(bus, device, function, offset + 1) + << 8); } uint8_t getHeaderType(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadByte(bus, device, function, 0x0D); + return pciConfigReadByte(bus, device, function, 0x0E); } uint16_t getVendorID(uint8_t bus, uint8_t device, uint8_t function) { - return pciConfigReadWord(bus, device, function, 2); + return pciConfigReadWord(bus, device, function, 0); +} + +void checkFunction(uint8_t bus, uint8_t device, uint8_t function) { + uint8_t class = pciConfigReadByte(bus, device, function, 0xB); + uint8_t subclass = pciConfigReadByte(bus, device, function, 0xA); + printf("function %i:%i:%i -> %i:%i, a %s\n", bus, device, function, class, + subclass, classNames[class]); } void checkDevice(uint8_t bus, uint8_t device) { uint16_t vendorID = getVendorID(bus, device, 0); - if (vendorID == 0xFFFF) + if (vendorID == 0xFFFF) { return; - printf("checking device %i;%i\n", bus, device); + } + if (getHeaderType(bus, device, 0) & 0x08) { + // multifunction device + for (int function = 0; function < 8; function++) { + if (getVendorID(bus, device, function) != 0xFFFF) { + checkFunction(bus, device, function); + } + } + } else { + checkFunction(bus, device, 0); + } } 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 + printf("discovored a single pci host controller\n"); checkBus(0); - return; + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } } - printf("multiple pci buses are not implemented yet!\n"); yields(); } diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index e7452b5..15713cc 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -20,11 +20,11 @@ drawLogo(); setupDevices(); setupInterrupts(); - printf("cpu data:\n"); printCPUData(); - getCurrentTask()->timerTicks = 1000; - getCurrentTask()->ticksLeft = 0; scanPCIDevices(); + yields(); + getCurrentTask()->timerTicks = 1000; + getCurrentTask()->ticksLeft = 1000; while (1) { if (isTaskQueueEmpty()) { asm volatile("hlt"); diff --git a/src/kernel/task/osTasks.c b/src/kernel/task/osTasks.c index da46b2e..37ab866 100644 --- a/src/kernel/task/osTasks.c +++ b/src/kernel/task/osTasks.c @@ -26,6 +26,8 @@ void initOSTasks() { setRunningTask(&mainTask); + mainTask.ticksLeft = -1; + mainTask.timerTicks = -1; keyboardConsumer = &mainTask; createTask(&printerTask, (uint32_t)printLoop, 0x0, 0x0); schedule(&printerTask); diff --git a/src/kernel/task/task.c b/src/kernel/task/task.c index 47f2f69..e001f9f 100644 --- a/src/kernel/task/task.c +++ b/src/kernel/task/task.c @@ -26,7 +26,7 @@ task->stack = stack; task->messages = NULL; task->ticksLeft = -1; - task->timerTicks = 0; + task->timerTicks = -1; } void yield() { diff --git a/tree-os.png b/tree-os.png new file mode 100644 index 0000000..c586f31 --- /dev/null +++ b/tree-os.png Binary files differ