Skip to content

Commit 3fa4feb

Browse files
committed
* Now can change the shell prompt message
* New command export
1 parent 08793d8 commit 3fa4feb

File tree

7 files changed

+116
-31
lines changed

7 files changed

+116
-31
lines changed

Drivers/Keyboard.cpp

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
static int keybufferpoint = 0;
44
static bool isShift = false;
55
static bool isCTRLed = false;
6+
7+
8+
9+
bool isUSRChanged = false;
610
void printf(char*);
711
void printfchar(char st);
812
void printHex(uint8_t key);
@@ -34,6 +38,18 @@ CommandPort(0x64)
3438
Task task2(&gdt, taskB);
3539
taskManager.AddTask(&task1);
3640
taskManager.AddTask(&task2);
41+
42+
for(int i = 0; i < 30; i++)
43+
{
44+
SP[i] = "\0";
45+
}
46+
47+
char* Shell_Prompt[15] = {"r","o","o","t","@","s","e","c","o","s",":","~","#",">", " "};
48+
for (int i = 0; i < 15; i++)
49+
{
50+
SP[SPIndex] = Shell_Prompt[i];
51+
SPIndex++;
52+
}
3753
}
3854

3955
KeyboardDriver::~KeyboardDriver()
@@ -302,6 +318,13 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
302318
{
303319
printf("cannot print null character");
304320
}
321+
else if (key_buffer[5] == "$" && key_buffer[6] == "S" && key_buffer[7] == "P")
322+
{
323+
for (int i = 0; i < SPIndex; i++)
324+
{
325+
printf(SP[i]);
326+
}
327+
}
305328
else
306329
{
307330
for (int i = 5; key_buffer[i] != "\n"; i++)
@@ -328,15 +351,20 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
328351
else if (key_buffer[5] == "3")
329352
printf("Help page 3:\nspi : To print the data in serial port 0x3F8.\nspo : To write data to serial port 0x3F8.\nsysinfo [option] : To get info about system.\nvga : To use experimental vga graphics.");
330353
else if (key_buffer[5] == "4")
331-
printf("Help page 4:\nlspt: To list partitions in a drive.\ntsk:to change instance.[EXPERIMENTAL]");
354+
printf("Help page 4:\nlspt: To list partitions in a drive.\ntsk:to change instance.[EXPERIMENTAL]\nexport [var]=[value] : To change value of a ENV var in shell.");
332355
else
333356
printf("Help page 1:\necho <message> : to print the message in the console \nhelp : to show this message \nclear : to clear the screen \nsd <options> : controls the power of the computer ");
334357
}
335358
else if (key_buffer[0] == "c" & key_buffer[1] == "l" & key_buffer[2] == "e" & key_buffer[3] == "a" & key_buffer[4] == "r")
336359
{
337360
COMNAME = "clear";
338361
printf("\5");
339-
printf("SectorOS Monolithic kernel ");PrintDate();printf(" Type: Shell\n");
362+
363+
printf("SectorOS ");
364+
printf(KERNEL_VERSION);
365+
printf(" ");
366+
PrintDate();
367+
printf(" Type: Shell ");
340368
}
341369
else if (key_buffer[0] == "s" & key_buffer[1] == "d")
342370
{
@@ -487,13 +515,37 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
487515
printf("esp2 is :"); printHex(esp2);
488516
isESPChanged = true;
489517
}
518+
else if (key_buffer[0] == "e" && key_buffer[1] == "x" && key_buffer[2] == "p" && key_buffer[3] == "o" && key_buffer[4] == "r" && key_buffer[5] == "t")
519+
{
520+
COMNAME = "export";
521+
522+
if (key_buffer[7] == "S" && key_buffer[8] == "P" && key_buffer[9] == "=" )
523+
{
524+
SPIndex = 0;
525+
526+
for (int i = 10; key_buffer[i] != "\n"; i++)
527+
{
528+
SP[SPIndex] = key_buffer[i];
529+
SPIndex++;
530+
}
531+
printf("SP is set to : ");
532+
for (int i = 0; i < SPIndex; i++)
533+
{
534+
printf(SP[i]);
535+
}
536+
}
537+
}
490538
else
491539
{
492540
printf("Unknown Command. Type help in console to get all the commands");
493541
}
494542
if(!isTxtMode){
495543
printf("\n");
496-
printf("$: ");
544+
for (int i = 0; SPIndex > i; i++)
545+
{
546+
printf(SP[i]);
547+
}
548+
497549
}
498550
serialport.logToSerialPort("Command interpreter got a command :- "); serialport.logToSerialPort(COMNAME); serialport.logToSerialPort("\n");
499551
clear_key_buffer();
@@ -507,12 +559,17 @@ void KeyboardDriver::returnHScreen()
507559
//ColourPrint(0);
508560
//printf("Welcome to SectorOS Monolithic kernel Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
509561

510-
printf("SectorOS Monolithic kernel ");
562+
printf("SectorOS ");
563+
printf(KERNEL_VERSION);
564+
printf(" ");
511565
PrintDate();
512-
printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
566+
printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
513567
printf("Run help to get the list of commands which is implemented \n \n");
514568

515-
printf("$: ");
569+
for (int i = 0; SPIndex > i; i++)
570+
{
571+
printf(SP[i]);
572+
}
516573
isTxtMode = false;
517574
}
518575

Hardcom/SerialPort.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void printfchar(char);
55

66
#define PORT 0x3f8
77
#ifndef DEBUG
8-
#define DEBUG 0
8+
#define DEBUG 1
99
#endif
1010

1111
port8BIT dataport(PORT);

Includes/Public_VAR.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
inline char* OS_NAME = "SectorOS";
55

66
inline char* KERNEL_NAME = "SectorOS";
7-
inline char* KERNEL_VERSION = "V2.1.3";
8-
inline char* KERNEL_BUILD = "Build: 2021-12-02";
7+
inline char* KERNEL_VERSION = "V2.1.4";
8+
inline char* KERNEL_BUILD = "Build: 2021-12-05";
99
inline char* KERNEL_ARCH = "x86";
1010

1111
inline char* SHELL_NAME = "SOSH";
12-
inline char* SHELL_VER = "V1.0.8";
12+
inline char* SHELL_VER = "V1.1.2";
13+
14+
// START Environment variables
15+
inline char* SP[30]; // Shell Prompt
16+
inline int SPIndex = 0; // Shell Prompt Index
17+
// END Environment variables
1318

1419
#endif

Makefile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
GCCPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
2-
ASPARAMS = --32
3-
LDPARAMS = -melf_i386
1+
CPP=gcc
2+
CPPFLAGS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
3+
ASFLAGS = --32
4+
LDFLAGS = -melf_i386
45
SHELL = /bin/bash
56
GRUB = ~/local/bin
67

@@ -31,15 +32,15 @@ prep:
3132

3233
%.o: %.cpp
3334
@printf "\e[1;32m[1/3]Compiling $<\n\e[0m"
34-
gcc $(DEBUG) $(GCCPARAMS) -c -o $@ $<
35+
$(CPP) $(DEBUG) $(CPPFLAGS) -c -o $@ $<
3536

3637
%.o: %.s
3738
@printf "\e[1;32m[1/3]Compiling $<\n\e[0m"
38-
as $(ASPARAMS) -o $@ $<
39+
as $(ASFLAGS) -o $@ $<
3940

4041
SectorOS_Kernel.bin: LILO/linker.ld $(objects)
4142
@printf "\e[1;33m[2/3]Linking object files\n\e[0m"
42-
@ld $(LDPARAMS) -T $< -o $@ $(objects)
43+
@ld $(LDFLAGS) -T $< -o $@ $(objects)
4344
@printf "Linking $(objects) to make $@\n"
4445
@printf "Linking finished\n"
4546

@@ -80,6 +81,11 @@ runVBOX: SectorOS.iso
8081
@(killall VirtualBoxVM && sleep 1) || true
8182
VirtualBoxVM --startvm 'SectorOS' --dbg
8283

84+
runBOCHS: SectorOS.iso
85+
@printf "Starting Bochs\n";
86+
@(killall bochs && sleep 1) || true
87+
bochs -q -f bochsrc.txt
88+
8389
stopVBOX:
8490
killall VirtualBoxVM
8591

bochsrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

bochsrc.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
ata0-slave: type=cdrom, path=SectorOS.iso, status=inserted
2+
boot:cdrom
3+
com1: enabled=1, mode=file, dev=serial.log

kernel/kernel.cpp

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "../Drivers/IOPorts.h"
55
#include "../Drivers/Keyboard.h"
66
#include "../Includes/multiboot.h"
7+
#include "../CPU/syscall.h"
78
#include "../Drivers/Mouse.h"
89
#include "../Drivers/Driver.h"
910
#include "../Drivers/RTC.h"
@@ -275,7 +276,7 @@ void printf(char* str)
275276
case '\3':
276277
for(int i = 0; i != 2; i++)
277278
x = cursorx;
278-
if (x != 3){
279+
if (x != SPIndex){
279280
x--;
280281
}
281282
VideoMemory[80*y+x] = (VideoMemory[80*y+x] & 0xFF00) | ' ';
@@ -343,15 +344,17 @@ void printf(char* str)
343344
x = 0;
344345
y = 0;
345346
//ColourPrint(0);
346-
printf("SectorOS Monolithic kernel ");
347+
printf("SectorOS ");
348+
printf(KERNEL_VERSION);
349+
printf(" ");
347350
RTC rtclock;
348351
rtclock.read_rtc();
349352
printf(INTTOCHARPOINT(rtclock.day));
350353
printf("/");
351354
printf(INTTOCHARPOINT(rtclock.month));
352355
printf("/");
353356
printf(INTTOCHARPOINT(rtclock.year));
354-
printf(" Type: Shell ");
357+
printf(" Type: Shell ");
355358
}
356359

357360
}
@@ -616,6 +619,8 @@ int do_intel(void)
616619
printf("\n");
617620
}
618621

622+
return 0;
623+
619624
}
620625

621626
void PrintSATA()
@@ -740,6 +745,17 @@ void taskA()
740745

741746
}
742747

748+
void SPOMEMLOC(SerialPort sp)
749+
{
750+
uint16_t value = GetAvailableMem();
751+
uint8_t partA = static_cast<uint8_t>((value & 0xFF00) >> 8);
752+
uint8_t partB = static_cast<uint8_t>(value & 0x00FF);
753+
sp.logToSerialPort("Current memory location: ");
754+
sp.logToSerialPort(hertochar(partA));
755+
sp.logToSerialPort(" ");
756+
sp.logToSerialPort(hertochar(partB));
757+
}
758+
743759

744760
typedef void (*constructor)();
745761
extern "C" constructor start_ctors;
@@ -759,20 +775,18 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t multiboot_m
759775
printf("Initializing SectorOS Kernel ");printf(KERNEL_VERSION); printf(" "); printf(KERNEL_BUILD); printf("....\n");
760776
SerialPort sp;
761777
sp.INITSerial();
762-
uint16_t value = GetAvailableMem();
763-
uint8_t partA = static_cast<uint8_t>((value & 0xFF00) >> 8);
764-
uint8_t partB = static_cast<uint8_t>(value & 0x00FF);
765778

766-
sp.logToSerialPort("Avaliable Memory = ");
767-
sp.logToSerialPort(hertochar(partA));
768-
sp.logToSerialPort(" ");
769-
sp.logToSerialPort(hertochar(partB));
779+
SPOMEMLOC(sp);
770780
sp.logToSerialPort("\nkernel started");
771781

782+
783+
772784
GlobalDescriptorTable gdt;
773785

774786
InterruptManager interrupts(0x20, &gdt, &taskManager);
775787

788+
SyscallHandler syscalls(&interrupts, 0x80);
789+
776790
DriverManager drvmgr;
777791

778792
printf("\nSYSMSG: Initializing Hardwares [Stage 1]...\n");
@@ -831,7 +845,7 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t multiboot_m
831845

832846
sp.logToSerialPort("\nInterrupt manager started");
833847

834-
printf("Welcome to SectorOS Monolithic kernel ");PrintDate();printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
848+
printf("Welcome to SectorOS ");printf(KERNEL_VERSION);printf(" ");PrintDate();printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
835849

836850
printf("Initializing "); printf(SHELL_NAME); printf(" "); printf(SHELL_VER);
837851

@@ -845,7 +859,10 @@ extern "C" void kernelMain(const void* multiboot_structure, uint32_t multiboot_m
845859

846860
sp.logToSerialPort("\nKernel initialization surcessful.\nGiving execution access to the kernel.\nAwaiting user input...");
847861

848-
printf("$: ");
862+
SPIndex = 15;
863+
864+
asm("int $0x80" : : "a" (4), "b" ("root@secos:~#> ")); // Used syscall to print this prompt
865+
SPOMEMLOC(sp);
849866

850867
while(1);
851868
}

0 commit comments

Comments
 (0)