Begin Adding an ATA (IDE) Driver, Remove the temporary SCANF implementation, Remove secondary license of the Shell and More
This commit is contained in:
parent
6ba33f4e5d
commit
fb7432f76e
@ -1,3 +1,8 @@
|
|||||||
|
;/////////////////////;
|
||||||
|
;Nanite OS ;
|
||||||
|
;COPYRIGHT (C) 2025 ;
|
||||||
|
;Tyler McGurrin ;
|
||||||
|
;/////////////////////;
|
||||||
[bits 32]
|
[bits 32]
|
||||||
|
|
||||||
global i686_reboot
|
global i686_reboot
|
||||||
|
|||||||
54
src/kernel/dri/disk/ata.c
Normal file
54
src/kernel/dri/disk/ata.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#include "ata.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#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);
|
||||||
|
}
|
||||||
20
src/kernel/dri/disk/ata.h
Normal file
20
src/kernel/dri/disk/ata.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*----------------*\
|
||||||
|
|Nanite OS |
|
||||||
|
|Copyright (C) 2025|
|
||||||
|
|Tyler McGurrin |
|
||||||
|
\*----------------*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
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);
|
||||||
@ -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.
|
|
||||||
@ -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;
|
|
||||||
}
|
|
||||||
@ -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 <stdint.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#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_ */
|
|
||||||
@ -6,7 +6,6 @@
|
|||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "c_scan.h"
|
|
||||||
|
|
||||||
char* cursor = "=>";
|
char* cursor = "=>";
|
||||||
|
|
||||||
@ -20,7 +19,6 @@ void shell()
|
|||||||
printf("NANITE Rescue Shell");
|
printf("NANITE Rescue Shell");
|
||||||
while(1 == 1) {
|
while(1 == 1) {
|
||||||
printf("%s", cursor);
|
printf("%s", cursor);
|
||||||
c_scanf("");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,3 +19,4 @@ void append(char s[], char n) {
|
|||||||
s[len] = n;
|
s[len] = n;
|
||||||
s[len + 1] = '\0';
|
s[len + 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,5 +6,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
#define LOGO " _ _____ _ __________________\n / | / / | / | / / _/_ __/ ____/\n / |/ / /| | / |/ // / / / / __/ \n / /| / ___ |/ /| // / / / / /___ \n/_/ |_/_/ |_/_/ |_/___/ /_/ /_____/ \n"
|
||||||
#define VERSION "RD-00002"
|
#define VERSION "RD-00003"
|
||||||
#define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"
|
#define BOOTLOGO " _ ______ ____ ____ ______\n / | / / __ )/ __ \\/ __ /_ __/\n / |/ / __ / / / / / / // / \n / /| / /_/ / /_/ / /_/ // / \n/_/ |_/_____/\\____/\\____//_/ \n"
|
||||||
Loading…
x
Reference in New Issue
Block a user