Skip to content

Commit 11f629c

Browse files
OpenKernel 1.0 has been released (OpenKernel was developed with the help of ChatGPT, an AI model from OpenAI. It was designed in collaboration with OpenSoftware-World.)
1 parent 35eb9c8 commit 11f629c

File tree

22 files changed

+751
-0
lines changed

22 files changed

+751
-0
lines changed

Boot/Mboot_desc/mboot.asm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
section .multiboot
2+
align 4
3+
4+
multiboot_magic equ 0x1BADB002
5+
multiboot_flags equ 0x00000003
6+
multiboot_checksum equ -(multiboot_magic + multiboot_flags)
7+
8+
dd multiboot_magic
9+
dd multiboot_flags
10+
dd multiboot_checksum

Boot/boot.asm

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
bits 32
2+
3+
%include "Boot/Mboot_desc/mboot.asm"
4+
5+
global _start
6+
extern kernel_main
7+
8+
section .text
9+
_start:
10+
11+
cmp eax, 0x2BADB002
12+
jne hang
13+
cli
14+
mov esp, 0x9FC00
15+
16+
call kernel_main
17+
18+
hang:
19+
hlt
20+
jmp hang

Drivers/Keyboard/keyboard.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include "keyboard.h"
2+
#include "../../SystemLib/SystemIO/io.h"
3+
4+
#define KBD_DATA 0x60
5+
#define KBD_STAT 0x64
6+
7+
static char kmap[128] = {
8+
0, 27, '1','2','3','4','5','6','7','8','9','0','-','=', '\b',
9+
'\t','q','w','e','r','t','y','u','i','o','p','[',']','\n',
10+
0, 'a','s','d','f','g','h','j','k','l',';','\'','`',
11+
0,'\\','z','x','c','v','b','n','m',',','.','/',0,
12+
'*',0,' ',0
13+
};
14+
15+
static char kbf[KEY_BF_SIZE];
16+
static uint8_t buf_head = 0;
17+
static uint8_t buf_tail = 0;
18+
19+
void kbd_init() {
20+
buf_head = 0;
21+
buf_tail = 0;
22+
}
23+
24+
uint8_t kb_check() {
25+
return buf_head != buf_tail;
26+
}
27+
28+
char get_char() {
29+
uint8_t scancode;
30+
31+
while (1) {
32+
while (!(inb(KBD_STAT) & 1));
33+
scancode = inb(KBD_DATA);
34+
35+
if (scancode & 0x80)
36+
continue;
37+
38+
if (scancode < 128)
39+
return kmap[scancode];
40+
}
41+
}
42+
43+
void kbd_hndlr() {
44+
uint8_t status = inb(KBD_STAT);
45+
if (status & 0x01) {
46+
uint8_t scancode = inb(KBD_DATA);
47+
char c = 0;
48+
if (scancode < 128) c = kmap[scancode];
49+
if (c) {
50+
kbf[buf_head] = c;
51+
buf_head = (buf_head + 1) % KEY_BF_SIZE;
52+
}
53+
}
54+
}

Drivers/Keyboard/keyboard.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef KEYBOARD_H
2+
#define KEYBOARD_H
3+
4+
#include "../../SystemLib/Std/types.h"
5+
6+
#define KEY_BF_SIZE 256
7+
8+
void kbd_init();
9+
char get_char();
10+
uint8_t kb_check();
11+
void kbd_hndlr();
12+
13+
#define DRIVER_NAME "OpenKernel Keyboard Driver"
14+
#define DRIVER_VER "0.1"
15+
#define DRIVER_DESC "A simple Keyboard driver for OpenKernel"
16+
#define DRIVER_KRNL_VER "1.0"
17+
18+
#endif

Drivers/Vga/vga.c

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#include "vga.h"
2+
#include "../../SystemLib/SystemIO/io.h"
3+
4+
static uint16_t *vgabuffer = (uint16_t *)VBUFFER;
5+
static uint8_t txt_color = VGA_COLOR(VGA_COLOR_BLACK, VGA_COLOR_LIGHT_GREY);
6+
static uint8_t cx = 0;
7+
static uint8_t cy = 0;
8+
9+
void vga_screen_clear() {
10+
for (uint16_t y=0; y < VHEIGHT; y++) {
11+
for (uint16_t x=0; x < VWIDTH; x++) {
12+
vgabuffer[y * VWIDTH + x] = VGA_ENTRY(' ', txt_color);
13+
}
14+
}
15+
cx = 0;
16+
cy = 0;
17+
}
18+
19+
void vga_set_bg_color(uint8_t color) {
20+
uint8_t fg = txt_color & 0x0F;
21+
txt_color = VGA_COLOR(color, fg);
22+
vga_screen_clear();
23+
}
24+
25+
void vga_set_text_color(uint8_t color) {
26+
uint8_t bg = (txt_color >> 4) & 0x0F;
27+
txt_color = VGA_COLOR(bg, color);
28+
}
29+
30+
void vga_set_color_scheme(uint8_t bg_color, uint8_t text_color) {
31+
vga_set_bg_color(bg_color);
32+
vga_set_text_color(text_color);
33+
}
34+
35+
void ptchar(char c) {
36+
if (c == '\n') {
37+
cx = 0;
38+
cy++;
39+
} else {
40+
vgabuffer[cy * VWIDTH + cx] = VGA_ENTRY(c, txt_color);
41+
cx++;
42+
if (cx >= VWIDTH) {
43+
cx = 0;
44+
cy++;
45+
}
46+
}
47+
if (cy >= VHEIGHT) {
48+
vga_screen_clear();
49+
}
50+
vga_set_cursor(cx, cy);
51+
}
52+
53+
void vga_print_scr(const char *str) {
54+
while (*str) {
55+
ptchar(*str++);
56+
}
57+
}
58+
59+
void vga_print_scr_nw(const char *str) {
60+
vga_print_scr(str);
61+
vga_newline();
62+
}
63+
64+
void vga_newline() {
65+
cx = 0;
66+
cy++;
67+
68+
if (cy >= VHEIGHT) {
69+
vga_screen_clear();
70+
}
71+
vga_set_cursor(cx, cy);
72+
}
73+
74+
void vga_init() {
75+
vga_screen_clear();
76+
}
77+
78+
void vga_set_cursor(uint8_t x, uint8_t y) {
79+
uint16_t pos = y * 80 + x;
80+
81+
outb(0x3D4, 0x0F);
82+
outb(0x3D5, (uint8_t)(pos & 0xFF));
83+
outb(0x3D4, 0x0E);
84+
outb(0x3D5, (uint8_t)((pos >> 8) & 0xFF));
85+
}
86+
87+
void vga_bckspc() {
88+
if (cx == 0 && cy == 0) return;
89+
90+
if (cx > 0) {
91+
cx--;
92+
} else {
93+
cy--;
94+
cx = VWIDTH - 1;
95+
}
96+
uint16_t *video = (uint16_t*)VBUFFER;
97+
video[cy * VWIDTH + cx] = VGA_ENTRY(' ', txt_color);
98+
vga_set_cursor(cx, cy);
99+
}

Drivers/Vga/vga.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#ifndef VGA_H
2+
#define VGA_H
3+
4+
#include "../../SystemLib/Std/types.h"
5+
6+
#define VWIDTH 80
7+
#define VHEIGHT 25
8+
#define VBUFFER 0xB8000
9+
10+
void vga_init();
11+
void vga_screen_clear();
12+
void vga_set_bg_color(uint8_t color);
13+
void vga_set_text_color(uint8_t color);
14+
void vga_print_scr(const char *str);
15+
void vga_newline();
16+
void vga_bckspc();
17+
void vga_set_cursor(uint8_t x, uint8_t y);
18+
void ptchar(char c);
19+
void vga_print_scr_nw(const char *str);
20+
void vga_set_color_scheme(uint8_t bg_color, uint8_t text_color);
21+
22+
#define VGA_COLOR_BLACK 0x0
23+
#define VGA_COLOR_BLUE 0x1
24+
#define VGA_COLOR_GREEN 0x2
25+
#define VGA_COLOR_CYAN 0x3
26+
#define VGA_COLOR_RED 0x4
27+
#define VGA_COLOR_MAGENTA 0x5
28+
#define VGA_COLOR_BROWN 0x6
29+
#define VGA_COLOR_LIGHT_GREY 0x7
30+
#define VGA_COLOR_DARK_GREY 0x8
31+
#define VGA_COLOR_LIGHT_BLUE 0x9
32+
#define VGA_COLOR_LIGHT_GREEN 0xA
33+
#define VGA_COLOR_LIGHT_CYAN 0xB
34+
#define VGA_COLOR_LIGHT_RED 0xC
35+
#define VGA_COLOR_LIGHT_MAGENTA 0xD
36+
#define VGA_COLOR_LIGHT_BROWN 0xE
37+
#define VGA_COLOR_WHITE 0xF
38+
39+
#define VGA_COLOR(bg, fg) ((bg << 4) | (fg))
40+
#define VGA_ENTRY(ch, color) ((uint16_t)ch | (color << 8))
41+
42+
#define DRIVER_NAME "OpenKernel VGA Driver"
43+
#define DRIVER_VER "0.1"
44+
#define DRIVER_DESC "A simple VGA text mode driver for OpenKernel"
45+
#define DRIVER_KRNL_VER "1.0"
46+
47+
#endif
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef COMMAND_LS_H
2+
#define COMMAND_LS_H
3+
4+
#define CLEAR_STRING "clear"
5+
#define CLS_STRING "cls"
6+
#define LIST_STRING "list"
7+
#define SEQLIST_STRING "seqlist"
8+
#define VER_STRING "ver"
9+
#define SHELLINFO_STRING "shellinfo"
10+
#define OSFETCH_STRING "osfetch"
11+
#define SHUTDOWN_STRING "shutdown"
12+
#define REBOOT_STRING "reboot"
13+
#define TIME_STRING "time"
14+
#define VERSION_STRING "version"
15+
#define ECHO_STRING "echo "
16+
17+
#endif
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include "shell.h"
2+
#include "command_ls.h"
3+
#include "../../../Drivers/Vga/vga.h"
4+
#include "../../../SystemLib/SysCalls/basic_syscall.h"
5+
#include "../../../SystemLib/TimeMng/time.h"
6+
#include "../../../SystemLib/SystemIO/io.h"
7+
#include "../../../Drivers/Keyboard/keyboard.h"
8+
#include "../../../SystemLib/Std/std.h"
9+
#include "../SystemManagement/sysmng.h"
10+
11+
void shell_inp() {
12+
vga_set_text_color(VGA_COLOR_GREEN);
13+
vga_print_scr("root");
14+
vga_set_text_color(VGA_COLOR_WHITE);
15+
vga_print_scr("@");
16+
vga_set_text_color(VGA_COLOR_CYAN);
17+
vga_print_scr("shell");
18+
vga_set_text_color(VGA_COLOR_WHITE);
19+
vga_print_scr("> ");
20+
}
21+
22+
void shell_init() {
23+
char cmd[MAX_CMD_LEN];
24+
uint8_t idx = 0;
25+
26+
shell_inp();
27+
28+
while (1) {
29+
char c = get_char();
30+
31+
if (c == '\b') {
32+
if (idx > 0) {
33+
idx--;
34+
vga_bckspc();
35+
}
36+
} else if (c == '\n') {
37+
vga_newline();
38+
cmd[idx] = 0;
39+
idx = 0;
40+
41+
if (strcmp(cmd, "list") == 0) {
42+
vga_print_scr("Commands: clear, cls, list, seqlist, ver, shellinfo, osfetch, shutdown, reboot, time, version, echo\n");
43+
} else if (strcmp(cmd, SEQLIST_STRING) == 0) {
44+
vga_print_scr_nw("Commands:");
45+
vga_print_scr_nw("clear");
46+
vga_print_scr_nw("cls");
47+
vga_print_scr_nw("list");
48+
vga_print_scr_nw("seqlist");
49+
vga_print_scr_nw("ver");
50+
vga_print_scr_nw("shellinfo");
51+
vga_print_scr_nw("osfetch");
52+
vga_print_scr_nw("shutdown");
53+
vga_print_scr_nw("reboot");
54+
vga_print_scr_nw("time");
55+
vga_print_scr_nw("version");
56+
vga_print_scr_nw("echo");
57+
} else if (strcmp(cmd, OSFETCH_STRING) == 0) {
58+
59+
vga_print_scr_nw(" ____ _____ root@shell");
60+
vga_print_scr_nw(" / __ \\ / ___/ ----------");
61+
vga_print_scr_nw("| | | | \\__ \\ OS: OpenKernel 1.0");
62+
vga_print_scr_nw("| | | |___/ / Kernel: OpenKernel 1.0");
63+
vga_print_scr_nw("| | | |___/ / Bootloader Name: GNU GRUB Bootloader");
64+
vga_print_scr_nw("| | | ___/ / Bootloader version: 2.12");
65+
vga_print_scr_nw(" \\____/|_____/ Architecture: x86 (32-bit)");
66+
vga_print_scr_nw(" Shell: OpenKernel Shell 1.0");
67+
} else if (strcmp(cmd, CLEAR_STRING) == 0 || strcmp(cmd, CLS_STRING) == 0) {
68+
vga_screen_clear();
69+
} else if (strcmp(cmd, TIME_STRING) == 0) {
70+
print_time();
71+
} else if (strncmp(cmd, ECHO_STRING, 5) == 0) {
72+
vga_print_scr(cmd + 5);
73+
vga_newline();
74+
} else if (strcmp(cmd, SHELLINFO_STRING) == 0) {
75+
vga_print_scr_nw("OpenKernel Shell 1.0");
76+
} else if (strcmp(cmd, SHUTDOWN_STRING) == 0) {
77+
sys_next_status("S");
78+
} else if (strcmp(cmd, REBOOT_STRING) == 0) {
79+
sys_next_status("R");
80+
} else if (strcmp(cmd, VERSION_STRING) == 0 || strcmp(cmd, VER_STRING) == 0) {
81+
vga_print_scr("OpenKernel v1.0");
82+
vga_newline();
83+
} else {
84+
vga_print_scr("The command you entered could not be found. Please type list for a list of all commands.");
85+
vga_newline();
86+
}
87+
88+
shell_inp();
89+
} else {
90+
if (idx < MAX_CMD_LEN - 1) {
91+
cmd[idx++] = c;
92+
ptchar(c);
93+
}
94+
}
95+
}
96+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef SHELL_H
2+
#define SHELL_H
3+
4+
#include "../../../SystemLib/Std/types.h"
5+
6+
void shell_init();
7+
8+
#define MAX_CMD_LEN 64
9+
10+
#endif

0 commit comments

Comments
 (0)