Skip to content

Commit ae56ec9

Browse files
The functions in the “basic_syscall.h” file have been moved to their respective categories, and a simple system call system has been created for OpenKernel. (Preliminary work for SDK development)
1 parent 1c6d925 commit ae56ec9

6 files changed

Lines changed: 81 additions & 42 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "log.h"
2+
3+
void log_message(const char *mode, const char *message) {
4+
/*
5+
S: Success
6+
E: Error
7+
W: Warning
8+
I: Info
9+
U: Unknown
10+
*/
11+
if (mode[0] == 'S') {
12+
vga_set_text_color(VGA_COLOR_GREEN);
13+
vga_print_scr("[SUCCESS]: ");
14+
} else if (mode[0] == 'E') {
15+
vga_set_text_color(VGA_COLOR_RED);
16+
vga_print_scr("[ERROR]: ");
17+
} else if (mode[0] == 'W') {
18+
vga_set_text_color(VGA_COLOR_LIGHT_BROWN);
19+
vga_print_scr("[WARNING]: ");
20+
} else if (mode[0] == 'I') {
21+
vga_set_text_color(VGA_COLOR_LIGHT_BLUE);
22+
vga_print_scr("[INFO]: ");
23+
} else if (mode[0] == 'U') {
24+
vga_set_text_color(VGA_COLOR_LIGHT_GREY);
25+
vga_print_scr("[UNKNOWN]: ");
26+
}
27+
vga_print_scr_nw(message);
28+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef LOG_H
2+
#define LOG_H
3+
4+
#include "../../../Drivers/Vga/vga.h"
5+
6+
void log_message(const char *mode, const char *message);
7+
8+
#endif

Kernel/KernelServices/SystemManagement/sysmng.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,20 @@ void sys_next_status(const char *mode, uint32_t seconds) {
1616
while (inb(0x64) & 0x02);
1717
outb(0x64, 0xFE);
1818
}
19+
}
20+
21+
void exit_program(const char *mode, const char *message) {
22+
/*
23+
D: Default
24+
C: Custom
25+
*/
26+
if (mode[0] == 'D') {
27+
vga_print_scr_nw("Exiting program...");
28+
} else if (mode[0] == 'C') {
29+
vga_print_scr_nw(message);
30+
}
31+
32+
while (true) {
33+
__asm__ __volatile__ ("hlt");
34+
}
1935
}

Kernel/KernelServices/SystemManagement/sysmng.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "../../../SystemLib/Std/types.h"
55
#include "../../../SystemLib/SystemIO/io.h"
66
#include "../../../SystemLib/TimeMng/time.h"
7+
#include "../../../Drivers/Vga/vga.h"
78

89
void sys_next_status(const char *mode, uint32_t seconds);
10+
void exit_program(const char *mode, const char *message);
911

1012
#endif

SystemLib/SysCalls/basic_syscall.c

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,24 @@
11
#include "basic_syscall.h"
2-
#include "../../Drivers/Vga/vga.h"
32

4-
void exit_program(const char *mode, const char *message) {
5-
/*
6-
D: Default
7-
C: Custom
8-
*/
9-
if (mode[0] == 'D') {
10-
vga_print_scr_nw("Exiting program...");
11-
} else if (mode[0] == 'C') {
12-
vga_print_scr_nw(message);
13-
}
14-
15-
while (true) {
16-
__asm__ __volatile__ ("hlt");
17-
}
3+
int syscall(int id, void* arg) {
4+
return syscall_handler(id, arg);
185
}
196

20-
void log_message(const char *mode, const char *message) {
21-
/*
22-
S: Success
23-
E: Error
24-
W: Warning
25-
I: Info
26-
U: Unknown
27-
*/
28-
if (mode[0] == 'S') {
29-
vga_set_text_color(VGA_COLOR_GREEN);
30-
vga_print_scr("[SUCCESS]: ");
31-
} else if (mode[0] == 'E') {
32-
vga_set_text_color(VGA_COLOR_RED);
33-
vga_print_scr("[ERROR]: ");
34-
} else if (mode[0] == 'W') {
35-
vga_set_text_color(VGA_COLOR_LIGHT_BROWN);
36-
vga_print_scr("[WARNING]: ");
37-
} else if (mode[0] == 'I') {
38-
vga_set_text_color(VGA_COLOR_LIGHT_BLUE);
39-
vga_print_scr("[INFO]: ");
40-
} else if (mode[0] == 'U') {
41-
vga_set_text_color(VGA_COLOR_LIGHT_GREY);
42-
vga_print_scr("[UNKNOWN]: ");
7+
int syscall_handler(int id, void* arg) {
8+
switch(id)
9+
{
10+
case SYSCALL_PRINT:
11+
vga_print_scr((char*)arg);
12+
return 0;
13+
case SYSCALL_CLEAR_SCREEN:
14+
vga_clear_screen("C");
15+
return 0;
16+
case SYSCALL_SHUTDOWN:
17+
sys_next_status("S", 0);
18+
return 0;
19+
case SYSCALL_REBOOT:
20+
sys_next_status("R", 0);
21+
return 0;
4322
}
44-
vga_print_scr_nw(message);
23+
return -1;
4524
}

SystemLib/SysCalls/basic_syscall.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
#ifndef BASIC_SYSCALL_H
22
#define BASIC_SYSCALL_H
33

4-
#include "../../SystemLib/Std/types.h"
4+
#include "../../Drivers/Vga/vga.h"
5+
#include "../../Kernel/KernelServices/SystemManagement/sysmng.h"
56

6-
void exit_program(const char *mode, const char *message);
7-
void log_message(const char *mode, const char *message);
7+
#define SYSCALL_PRINT 0
8+
#define SYSCALL_CLEAR_SCREEN 1
9+
#define SYSCALL_SHUTDOWN 2
10+
#define SYSCALL_REBOOT 3
11+
12+
int syscall(int id, void* arg);
13+
int syscall_handler(int id, void* arg);
814

915
#endif

0 commit comments

Comments
 (0)