Skip to content

Commit ca14a11

Browse files
committed
* Implemented task changing
it can change task to certain task * updated INTTOCHARPOINT * Bumped SectorOS kernel version * Added new syscalls
1 parent ba25d17 commit ca14a11

File tree

7 files changed

+818
-474
lines changed

7 files changed

+818
-474
lines changed

CPU/syscall.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
#include "syscall.h"
22

33
void printf(char*);
4+
void printfchar(char);
45
PowerControl syscontrol;
56

7+
inline GlobalDescriptorTable gdt;
8+
void taskA();
9+
void taskB();
10+
11+
Task tsk1(&gdt, taskA);
12+
Task tsk2(&gdt, taskB);
13+
614
SyscallHandler::SyscallHandler(InterruptManager* interruptManager, uint8_t InterruptNumber)
715
:InterruptHandler(InterruptNumber + interruptManager->HardwareInterruptOffset(), interruptManager)
816
{
17+
taskManager.AddTask(&tsk1);
18+
taskManager.AddTask(&tsk2);
919
}
1020

1121
SyscallHandler::~SyscallHandler()
@@ -19,14 +29,22 @@ uint32_t SyscallHandler::HandleInterrupt(uint32_t esp)
1929

2030
switch(cpu->eax)
2131
{
22-
case 1: // sys_print
32+
case 1: // sys_printf
2333
printf((char*)cpu->ebx);
2434
break;
2535

26-
case 2: // sys_reboot
36+
case 2: // sys_printc
37+
printfchar((char)cpu->ebx);
38+
break;
39+
40+
case 3: // sys_reboot
2741
syscontrol.reboot();
2842
break;
2943

44+
case 4: // sys_cng_task
45+
esp = (uint32_t)taskManager.SwitchTask((int)cpu->ebx, (CPUState*)esp);
46+
break;
47+
3048
default:
3149
break;
3250
}

CPU/syscall.h

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include "../Include/types.h"
55
#include "Interrupts.h"
66
#include "PowerControl.h"
7+
#include "../kernel/MultiTask.h"
78

89
class SyscallHandler : public InterruptHandler
910
{
11+
TaskManager taskManager;
1012
public:
1113
SyscallHandler(InterruptManager* interruptManager, uint8_t InterruptNumber);
1214
~SyscallHandler();

Drivers/Keyboard.cpp

+5-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ char* INTTOCHARPOINT(int num);
1212
void ColourPrint(int type);
1313
bool txtcolor;
1414
bool isESPChanged = false;
15-
GlobalDescriptorTable gdt;
15+
inline GlobalDescriptorTable gdt;
1616
void taskA();
1717
void taskB();
1818
const void* mb;
@@ -54,10 +54,6 @@ CommandPort(0x64)
5454
clear_key_buffer();
5555
isTxtMode = false;
5656
this->shell = shell;
57-
Task task1(&gdt, taskA);
58-
Task task2(&gdt, taskB);
59-
taskManager.AddTask(&task1);
60-
taskManager.AddTask(&task2);
6157

6258
for(int i = 0; i < 30; i++)
6359
{
@@ -497,10 +493,10 @@ void KeyboardDriver::CommandInterpreter() // SOSH v1.0.3 [SectorOS SHell]. 11 Co
497493
}
498494
else if(key_buffer[0] == "t" && key_buffer[1] == "s" && key_buffer[2] == "k")
499495
{
500-
esp1 = (uint32_t)taskManager.Schedule((CPUState*)esp1);
501-
printf("esp1 is :"); printHex(esp1); printf("\n");
502-
printf("esp2 is :"); printHex(esp2);
503-
isESPChanged = true;
496+
char* arg1 = key_buffer[4];
497+
int tsknum = arg1[0] - '0';
498+
asm("int $0x80" : : "a" (0x04), "b" (tsknum));
499+
//asm("int $0x80" : : "a" (0x05));
504500
}
505501
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")
506502
{

Include/Public_VAR.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
inline char* OS_NAME = "SectorOS";
55

66
inline char* KERNEL_NAME = "SectorOS";
7-
inline char* KERNEL_VERSION = "V2.1.6";
8-
inline char* KERNEL_BUILD = "Build: 2021-12-11";
7+
inline char* KERNEL_VERSION = "V2.2.1";
8+
inline char* KERNEL_BUILD = "Build: 2022-01-06";
99
inline char* KERNEL_ARCH = "x86";
1010

1111
inline char* SHELL_NAME = "SOSH";
12-
inline char* SHELL_VER = "V1.1.2";
12+
inline char* SHELL_VER = "V1.1.3";
1313

1414
// START Environment variables
1515
inline char* SP[30]; // Shell Prompt

kernel/MultiTask.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,11 @@ CPUState* TaskManager::Schedule(CPUState* cpustate)
6464
if(++currentTask >= numTasks)
6565
currentTask %= numTasks;
6666
return tasks[currentTask]->cpustate;
67+
}
68+
69+
CPUState* TaskManager::SwitchTask(int tasknum, CPUState* CSTATE)
70+
{
71+
if(tasknum >= numTasks)
72+
return tasks[tasknum]->cpustate;
73+
return tasks[tasknum]->cpustate;
6774
}

kernel/MultiTask.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class TaskManager
4848
TaskManager();
4949
~TaskManager();
5050
bool AddTask(Task* task);
51+
CPUState* SwitchTask(int tasknum, CPUState* CSTATE);
5152
CPUState* Schedule(CPUState* cpustate);
5253
};
5354

0 commit comments

Comments
 (0)