Skip to content

Commit a6e46af

Browse files
committed
* Added cursor in the shell
1 parent d22f1bf commit a6e46af

File tree

8 files changed

+98
-12
lines changed

8 files changed

+98
-12
lines changed

CPU/PowerControl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "PowerControl.h"
22

3+
extern uint32_t shutdown();
34

45
void PowerControl::reboot()
56
{
@@ -25,4 +26,9 @@ bool PowerControl::getPowerState()
2526
{
2627
port8BIT pt(0xB0);
2728
return pt.ReadFromPort() & 0x01;
29+
}
30+
31+
void PowerControl::shutdown()
32+
{
33+
shutdown();
2834
}

CPU/PowerControl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PowerControl
1313
void halt();
1414
//If running in virtualBox. This function will Stop virtualBox
1515
void StopVirtualBox();
16+
void shutdown(); //!: This function is not implemented yet
1617

1718
//To get the current power state
1819
bool getPowerState();

CPU/shutdown.asm

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[BITS 32]
2+
3+
global shutdown
4+
5+
section .data
6+
7+
section .text
8+
9+
shutdown:
10+
push edi
11+
push ebx
12+
wait_gate1:
13+
in al,64h
14+
and al,2
15+
jnz wait_gate1
16+
mov al,0D1h
17+
out 64h,al
18+
wait_gate2:
19+
in al,64h
20+
and al,2
21+
jnz wait_gate2
22+
mov al,0FEh
23+
out 60h,al
24+
;
25+
xor eax,eax
26+
mov cr3,eax
27+
28+
reset_wait:
29+
jmp reset_wait

Drivers/Keyboard.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "Keyboard.h"
22

33
static bool isCTRLed = false;
4-
4+
bool canNewLine = true;
55

66
bool isUSRChanged = false;
77
void printf(char *);
@@ -88,7 +88,7 @@ void KeyboardDriver::activate()
8888
uint32_t KeyboardDriver::HandleInterrupt(uint32_t esp)
8989
{
9090
esp2 = esp;
91-
91+
9292
if(isESPChanged)
9393
{
9494
printf("\n");
@@ -348,6 +348,7 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
348348
printf(" ");
349349
PrintDate();
350350
printf(" Type: Shell ");
351+
canNewLine = false;
351352
}
352353
else if (key_buffer[0] == "s" & key_buffer[1] == "d")
353354
{
@@ -518,17 +519,27 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
518519
}
519520
}
520521
}
522+
else if (key_buffer[0] == "e" && key_buffer[1] == "x" && key_buffer[2] == "i" && key_buffer[3] == "t")
523+
{
524+
//power.shutdown();
525+
}
521526
else
522527
{
523-
printf("Unknown Command. Type help in console to get all the commands");
528+
printf("Unknown Command \"");
529+
for (int i = 0; key_buffer[i] != "\n"; i++)
530+
{
531+
printf(key_buffer[i]);
532+
}
533+
printf("\". Type help in console to get all the commands");
524534
}
525535
if(!isTxtMode){
526-
printf("\n");
536+
if (canNewLine)
537+
printf("\n");
527538
for (int i = 0; SPIndex > i; i++)
528539
{
529540
printf(SP[i]);
530541
}
531-
542+
canNewLine = true;
532543
}
533544
serialport.logToSerialPort("Command interpreter got a command :- "); serialport.logToSerialPort(COMNAME); serialport.logToSerialPort("\n");
534545
clear_key_buffer();

Filesystem/FATFS.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ void ReadBiosBlock(AdvancedTechnologyAttachment *hd, uint32_t partitionOffset)
4646

4747
if (lst_dir2 == (char*)dirent[i].name)
4848
{
49-
continue;
49+
printf("X");
5050
}
5151
else
5252
{
5353
if (lst_dir == (char *)dirent[i].name)
5454
{
55-
continue;
55+
printf("Y");
5656
}
5757
else
5858
{

Include/Public_VAR.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ inline char* OS_NAME = "SectorOS";
55

66
inline char* KERNEL_NAME = "SectorOS";
77
inline char* KERNEL_VERSION = "V2.2.2";
8-
inline char* KERNEL_BUILD = "Build: 2022-01-07";
8+
inline char* KERNEL_BUILD = "Build: 2022-01-08";
99
inline char* KERNEL_ARCH = "x86";
1010

1111
inline char* SHELL_NAME = "SOSH";

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
CPP=gcc
22
AS=as
33
LD=ld
4+
ASM=nasm
5+
ASMFLAGS= -f elf
46
CPPFLAGS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings
57
ASFLAGS = --32
68
LDFLAGS = -melf_i386
@@ -33,6 +35,9 @@ prep:
3335
@printf "Preparing...\n"
3436
@sudo apt-get install xorriso mtools grub-pc-bin
3537

38+
CPU/PowerControl.o: CPU/PowerControl.cpp CPU/shutdown.o
39+
$(CPP) $(CPPFLAGS) -c -o $@ CPU/PowerControl.cpp CPU/shutdown.o
40+
3641
%.o: %.cpp
3742
@printf "\e[1;32m[1/3]Compiling $<\n\e[0m"
3843
$(CPP) $(DEBUG) $(CPPFLAGS) -c -o $@ $<
@@ -41,6 +46,10 @@ prep:
4146
@printf "\e[1;32m[1/3]Compiling $<\n\e[0m"
4247
$(AS) $(ASFLAGS) -o $@ $<
4348

49+
%.o: %.asm
50+
@printf "\e[1;32m[1/3]Compiling $<\n\e[0m"
51+
$(ASM) $(ASMFLAGS) -o $@ $<
52+
4453
SectorOS_Kernel.bin: LILO/linker.ld $(objects)
4554
@printf "\e[1;33m[2/3]Linking object files\n\e[0m"
4655
@$(LD) $(LDFLAGS) -T $< -o $@ $(objects)

kernel/kernel.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "../Drivers/Keyboard.h"
66
#include "../Shell/Shell.h"
77
#include "../Include/multiboot.h"
8+
#include "../Hardcom/SerialPort.h"
89
#include "../CPU/syscall.h"
910
#include "../Drivers/Mouse.h"
1011
#include "../Drivers/Driver.h"
@@ -525,6 +526,32 @@ char *INTTOCHARPOINT(int num)
525526
return res;
526527
}
527528

529+
void enable_cursor(uint8_t cursor_start, uint8_t cursor_end)
530+
{
531+
port8BIT P1(0x3D4);
532+
port8BIT P2(0x3D5);
533+
534+
P1.WriteToPort(0x0A);
535+
P2.WriteToPort((P2.ReadFromPort() & 0xC0) | cursor_start);
536+
537+
P1.WriteToPort(0x0B);
538+
P2.WriteToPort((P2.ReadFromPort() & 0xE0) | cursor_end);
539+
}
540+
541+
void update_cursor(int x, int y)
542+
{
543+
int VGA_WIDTH = 80;
544+
port8BIT P1(0x3D4);
545+
port8BIT P2(0x3D5);
546+
547+
uint16_t pos = y * VGA_WIDTH + x;
548+
549+
P1.WriteToPort(0x0F);
550+
P2.WriteToPort((uint8_t)(pos & 0xFF));
551+
P1.WriteToPort(0x0E);
552+
P2.WriteToPort((uint8_t)((pos >> 8) & 0xFF));
553+
}
554+
528555
uint16_t GetAvailableMem()
529556
{
530557
port8BIT port(0x70);
@@ -693,6 +720,8 @@ void printf(char *str)
693720
printf(" Type: Shell ");
694721
}
695722
}
723+
724+
update_cursor(x, y + 1);
696725
}
697726

698727
// Uses 10 Character Space
@@ -790,6 +819,8 @@ void printfchar(char st)
790819
x = 0;
791820
y = 0;
792821
}
822+
823+
update_cursor(x, y + 1);
793824
}
794825

795826
void printHex(uint8_t Key)
@@ -828,9 +859,7 @@ void PrintMEM(const void *multiboot_structure)
828859
printf("\n");
829860
}
830861

831-
#define cpuid(in, a, b, c, d) __asm__("cpuid" \
832-
: "=a"(a), "=b"(b), "=c"(c), "=d"(d) \
833-
: "a"(in));
862+
#define cpuid(in, a, b, c, d) __asm__("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d): "a"(in));
834863

835864
int do_intel(void)
836865
{
@@ -1074,6 +1103,7 @@ extern "C" void callConstructors()
10741103

10751104
extern "C" void kernelMain(const void *multiboot_structure, uint32_t multiboot_m)
10761105
{
1106+
enable_cursor(0, 0);
10771107
TaskManager taskManager;
10781108
uint32_t mm = multiboot_m;
10791109
printf("Initializing SectorOS Kernel ");
@@ -1138,7 +1168,7 @@ extern "C" void kernelMain(const void *multiboot_structure, uint32_t multiboot_m
11381168
printf(KERNEL_VERSION);
11391169
printf(" ");
11401170
PrintDate();
1141-
printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
1171+
printf(" Type: Shell\nhttps://github.com/Arun007coder/SectorOS \n");
11421172

11431173
printf("Initializing ");
11441174
printf(SHELL_NAME);

0 commit comments

Comments
 (0)