From fb7432f76e04e017895728e42244e884fcbdb0f8 Mon Sep 17 00:00:00 2001 From: Tyler McGurrin Date: Thu, 29 May 2025 20:46:45 -0400 Subject: [PATCH] Begin Adding an ATA (IDE) Driver, Remove the temporary SCANF implementation, Remove secondary license of the Shell and More --- src/kernel/arch/i686/basicfunc.asm | 5 + src/kernel/dri/disk/ata.c | 54 ++++++++ src/kernel/dri/disk/ata.h | 20 +++ src/kernel/shell/LICENSE | 21 --- src/kernel/shell/c_scan.c | 216 ----------------------------- src/kernel/shell/c_scan.h | 42 ------ src/kernel/shell/shell.c | 2 - src/kernel/util/util.c | 1 + src/libs/version.h | 2 +- 9 files changed, 81 insertions(+), 282 deletions(-) create mode 100644 src/kernel/dri/disk/ata.c create mode 100644 src/kernel/dri/disk/ata.h delete mode 100644 src/kernel/shell/LICENSE delete mode 100644 src/kernel/shell/c_scan.c delete mode 100644 src/kernel/shell/c_scan.h diff --git a/src/kernel/arch/i686/basicfunc.asm b/src/kernel/arch/i686/basicfunc.asm index aa00457..62d4f40 100644 --- a/src/kernel/arch/i686/basicfunc.asm +++ b/src/kernel/arch/i686/basicfunc.asm @@ -1,3 +1,8 @@ +;/////////////////////; +;Nanite OS ; +;COPYRIGHT (C) 2025 ; +;Tyler McGurrin ; +;/////////////////////; [bits 32] global i686_reboot diff --git a/src/kernel/dri/disk/ata.c b/src/kernel/dri/disk/ata.c new file mode 100644 index 0000000..48cf668 --- /dev/null +++ b/src/kernel/dri/disk/ata.c @@ -0,0 +1,54 @@ +/*----------------*\ +|Nanite OS | +|Copyright (C) 2025| +|Tyler McGurrin | +\*----------------*/ +#include "ata.h" + +#include + +#define PORT_DRIVE_NUMBER 502 +#define PORT_SECTOR_COUNT 498 +#define PORT_SECTOR_NUMBER 499 +#define PORT_CYLINDER_LOW 500 +#define PORT_CYLINDER_HIGH 501 +#define PORT_COMMAND 503 + +bool ATA_Drive_Init(DISK* disk, uint8_t driveNumber) +{ + uint8_t driveType; + uint16_t cylinders, sectors, heads; + + if (!ATA_Get_Drive_Params(disk->id, &driveType, &cylinders, §ors, &heads)) + return false; + + disk->id = driveNumber; + disk->cylinders = cylinders; + disk->heads = heads; + disk->sectors = sectors; + + return true; +} + +bool ATA_Get_Drive_Params(uint8_t diskID, uint8_t* driveType, uint16_t* cylinders, uint16_t* sectors, uint16_t* heads) +{ + +} + +void ATA_CHS_Read(int number_of_sectors, int drive_number, int buffer) +{ + +} + +void ATA_LBA2CHS(DISK* disk, uint32_t lba, uint16_t* cylinderOut, uint16_t* sectorOut, uint16_t* headOut) { + // sector = (LBA % sectors per track + 1) + *sectorOut = lba % disk->sectors +1; + + // cylinder = (LBA / sects per track / heads) + *cylinderOut = (lba / disk->sectors) / disk->heads; + + // head = (LBA / sects per track % heads) + *headOut = (lba / disk->sectors) % disk->heads; + + // printf("LBA2CHS: lba=%u sect=%u cyl=%u head=%u disk_sectors=%u disk_heads=%u\n", lba, *sectorOut, *cylinderOut, *headOut, disk->sectors, disk->heads); +} \ No newline at end of file diff --git a/src/kernel/dri/disk/ata.h b/src/kernel/dri/disk/ata.h new file mode 100644 index 0000000..b8c37b5 --- /dev/null +++ b/src/kernel/dri/disk/ata.h @@ -0,0 +1,20 @@ +/*----------------*\ +|Nanite OS | +|Copyright (C) 2025| +|Tyler McGurrin | +\*----------------*/ +#pragma once + +#include +#include + +typedef struct { + uint8_t id; + uint16_t cylinders; + uint16_t sectors; + uint16_t heads; +} DISK; + +bool ATA_Drive_Init(DISK* disk, uint8_t driveNumber); +void ATA_LBA2CHS(DISK* disk, uint32_t lba, uint16_t* cylinderOut, uint16_t* sectorOut, uint16_t* headOut); +bool ATA_Get_Drive_Params(uint8_t disk, uint8_t* driveType, uint16_t* cylinders, uint16_t* sectors, uint16_t* heads); \ No newline at end of file diff --git a/src/kernel/shell/LICENSE b/src/kernel/shell/LICENSE deleted file mode 100644 index c2e8c4c..0000000 --- a/src/kernel/shell/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2025 Tyler McGurrin - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file diff --git a/src/kernel/shell/c_scan.c b/src/kernel/shell/c_scan.c deleted file mode 100644 index 0bac656..0000000 --- a/src/kernel/shell/c_scan.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * mini-scanf - Minimal scanf() implementation for embedded projects. - * Copyright (c) 2023 Aleksej Muratov - */ - -#include "c_scan.h" - -// implementation of basic dependencies -// std -int c_isspace(const int c) -{ - switch (c) - { /* in the "C" locale: */ - case ' ': /* space */ - case '\f': /* form feed */ - case '\n': /* new-line */ - case '\r': /* carriage return */ - case '\t': /* horizontal tab */ - case '\v': /* vertical tab */ - return 1; - default: - return 0; - } -} - -// std -int c_isdigit(int c) -{ - if (c >= '0' && c <= '9') - return (1); - else - return (0); -} - -// parodies the standard -#ifdef C_SSCANF - #define NEXTCHAR (PointBuf++) - #define CURCHAR (buff[PointBuf]) - int c_sscanf(const char* buff, char* format, ...) -#else - #define NEXTCHAR (charBuf=c_getch()) - #define CURCHAR (charBuf) - int c_scanf(char* format, ...) -#endif -{ - int count = 0; - - #ifdef C_SSCANF - int PointBuf = 0; - #else - char charBuf = c_getch(); - #endif - - int PointFt = 0; - - va_list ap; - va_start(ap, format); - while (format && format[PointFt]) // Read format - { - if (format[PointFt] == '%') - { - PointFt++; - // for %* - bool save = true; - if (format[PointFt] == '*') - { - save = false; - PointFt++; - } - // for %1234567890 - unsigned len = 0; - bool lenEn = false; - while (c_isdigit(format[PointFt])) - { - lenEn = true; - len *= 10; - len += (format[PointFt] - '0'); - PointFt++; - } - // for %[] - char stop[LENSCANS]; - unsigned stopN = 0; - if (format[PointFt] == '[') - { - while (format[PointFt] != ']') - { - if (format[PointFt] != '[') - { - stop[stopN] = format[PointFt]; - stopN++; - } - PointFt++; - } - } - // %? - switch (format[PointFt]) - { - case 'c': - while (c_isspace(CURCHAR)) // ignore isspace (std) - NEXTCHAR; // - if (save) - *(char*)va_arg(ap, char*) = CURCHAR; - NEXTCHAR; - //if (save) // ignore %* (std) - count++; - break; - case 'u': - case 'd': - int sign = 1; - while (!c_isdigit(CURCHAR)) - { - if (CURCHAR == '+' || CURCHAR == '-') - if (CURCHAR == '-') - //if(format[PointFt] != 'u') // ignore sign (no std) - sign = -1; - NEXTCHAR; - } - long value = 0; - while(c_isdigit(CURCHAR) && (lenEn != true || len > 0)) - { - value *= 10; - value += (int)(CURCHAR - '0'); - NEXTCHAR; - len--; - } - - if (save) - *(int*)va_arg(ap, int*) = value * sign; - //if (save) // ignore %* (std) - count++; - break; - case ']': - case 's': - char* t = save ? va_arg(ap, char*) : NULL; - - while (c_isspace(CURCHAR)) // ignor isspace (std) - NEXTCHAR; // - - while (true) - { - bool con = false; - if (stopN != 0) - { - bool invert = (stop[0] == '^'); - con = !invert; - for (unsigned i = (invert ? 1 : 0); i < stopN; i++) - if (stop[i] == CURCHAR) - { - con = invert; - break; - } - - if (con == true) - break; - } - - if (!c_isspace(CURCHAR) || (!con && stopN != 0) && (lenEn != true || len > 0)) - { - if (save) - *t = CURCHAR; - NEXTCHAR; - t++; - len--; - } - else - break; - } - // add \0 - { - if (save) - *t = '\0'; - t++; - } - //if (save) // ignore %* (std) - count++; - break; - } - #ifndef C_SSCANF - if(format[PointFt] != 'c' - && format[PointFt] != 'u' - && format[PointFt] != 'd') - c_getbackch(CURCHAR); - #endif - } - //else // drop char in buff (no std) - // NEXTCHAR; // - PointFt++; - } - va_end(ap); - return count; -} - -// custom -char backch = 0; -char c_getch() -{ - if(backch == 0) - return (char)getch(); - else - { - char tmp = backch; - backch = 0; - return tmp; - } -} - -// new -bool c_getbackch(char b) -{ - char tmp = backch; - backch = b; - if (tmp != 0) - return 1; - else - return 0; -} \ No newline at end of file diff --git a/src/kernel/shell/c_scan.h b/src/kernel/shell/c_scan.h deleted file mode 100644 index 482dfa7..0000000 --- a/src/kernel/shell/c_scan.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * mini-scanf - Minimal scanf() implementation for embedded projects. - * Copyright (c) 2023 Aleksej Muratov - */ - -#ifndef _C_SCAN_H_ -#define _C_SCAN_H_ - -// conf -// sscanf / scanf -// #define C_SSCANF -// %[..] -#define LENSCANS 10 - -#include -#include -#include - -#ifndef NULL -#define NULL 0 -#endif - -#ifndef EOF -#define EOF -1 -#endif - -int c_isspace(const int c); -int c_isdigit(int c); - -// scan -#ifdef C_SSCANF - int c_sscanf(const char* buff, char* format, ...); -#else - int c_scanf(char* format, ...); -#endif -char c_getch(); //custom -bool c_getbackch(char b); //new - -// HW -int getch(); - -#endif /* _C_SCAN_H_ */ \ No newline at end of file diff --git a/src/kernel/shell/shell.c b/src/kernel/shell/shell.c index 1e2ace2..a7f964f 100644 --- a/src/kernel/shell/shell.c +++ b/src/kernel/shell/shell.c @@ -6,7 +6,6 @@ #include "shell.h" #include -#include "c_scan.h" char* cursor = "=>"; @@ -20,7 +19,6 @@ void shell() printf("NANITE Rescue Shell"); while(1 == 1) { printf("%s", cursor); - c_scanf(""); } } diff --git a/src/kernel/util/util.c b/src/kernel/util/util.c index 774db72..d0aaf59 100644 --- a/src/kernel/util/util.c +++ b/src/kernel/util/util.c @@ -19,3 +19,4 @@ void append(char s[], char n) { s[len] = n; s[len + 1] = '\0'; } + diff --git a/src/libs/version.h b/src/libs/version.h index c0661de..5fbb58e 100644 --- a/src/libs/version.h +++ b/src/libs/version.h @@ -6,5 +6,5 @@ #pragma once #define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n" -#define VERSION "RD-00002" +#define VERSION "RD-00003" #define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n" \ No newline at end of file