we don't talk about this one...
This commit is contained in:
parent
bbe47602b9
commit
89c83809f8
@ -60,7 +60,7 @@ void __attribute__((section(".entry"))) start(BootParams* bootParams) {
|
||||
// Debug Info for Memory :3 i REALLY need to make a like serial debug output thingy
|
||||
// printf("Boot Device: %x\n", bootParams->BootDevice);
|
||||
// printf("Memory Region Count: %x\n", bootParams->Memory.RegionCount);
|
||||
// for (int i = 0; i < bootParams->Memory.RegionCount; i++) {
|
||||
// for (int i = 0; i < bootParams->Memory.RegionCount; i++) {shell example
|
||||
// printf("Memory: start=0x%llx length=0x%llx type=0x%x\n",
|
||||
// bootParams->Memory.Regions[i].Begin, bootParams->Memory.Regions[i].Length, bootParams->Memory.Regions[i].Type);
|
||||
// }
|
||||
|
||||
21
src/kernel/shell/LICENSE
Normal file
21
src/kernel/shell/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
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.
|
||||
216
src/kernel/shell/c_scan.c
Normal file
216
src/kernel/shell/c_scan.c
Normal file
@ -0,0 +1,216 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
42
src/kernel/shell/c_scan.h
Normal file
42
src/kernel/shell/c_scan.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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_ */
|
||||
26
src/kernel/shell/shell.c
Normal file
26
src/kernel/shell/shell.c
Normal file
@ -0,0 +1,26 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2025|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#include "shell.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "c_scan.h"
|
||||
|
||||
char* cursor = "=>";
|
||||
|
||||
/*
|
||||
A simple Rescue shell
|
||||
Because, Yes.
|
||||
*/
|
||||
|
||||
void shell()
|
||||
{
|
||||
printf("NANITE Rescue Shell");
|
||||
while(1 == 1) {
|
||||
printf("%s", cursor);
|
||||
c_scanf("");
|
||||
}
|
||||
|
||||
}
|
||||
8
src/kernel/shell/shell.h
Normal file
8
src/kernel/shell/shell.h
Normal file
@ -0,0 +1,8 @@
|
||||
/*----------------*\
|
||||
|Nanite OS |
|
||||
|Copyright (C) 2025|
|
||||
|Tyler McGurrin |
|
||||
\*----------------*/
|
||||
#pragma once
|
||||
|
||||
void shell();
|
||||
Loading…
x
Reference in New Issue
Block a user