Skip to content

Commit bab06bf

Browse files
committed
05311427
1 parent c82625d commit bab06bf

File tree

12 files changed

+181
-48
lines changed

12 files changed

+181
-48
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"stdio.h": "c",
1111
"tty.h": "c",
1212
"keyboard.h": "c",
13-
"system.h": "c"
13+
"system.h": "c",
14+
"basic_types.h": "c"
1415
}
1516
}

boot/boot.S

+1-18
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ DISK_WRITE EQU 0x03
1515
ENTRY:
1616
MOV [DRIVE_NUM], DL
1717

18-
; MOV AX, BOOT_SEG
19-
; MOV DS, AX
20-
; MOV SS, AX
21-
; MOV ES, AX
22-
23-
2418
MOV BP, STACK_TOP
2519
MOV SP, BP
2620

@@ -30,25 +24,14 @@ ENTRY:
3024
CALL B_PRINT
3125

3226
; CALL B_INPUT
33-
27+
3428
CALL LOAD_STAGE2
35-
; JMP STAGE2_OFFSET
36-
37-
; CALL kmain
38-
39-
; MOV SI, A20_MSG
40-
; CALL B_PRINT
41-
; CALL CHECK_A20
4229

4330
MOV SI, RM_MSG
4431
CALL B_PRINT
4532

4633
CALL HIDE_CURSOR
4734

48-
; CALL SET_CURSOR
49-
50-
; CALL CLEAR_SCREEN
51-
5235
CLI
5336
LGDT [GDT_DESC]
5437

boot/head.S

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ LOAD_STAGE2:
77

88
MOV DH, 0x30
99
MOV DL, [DRIVE_NUM]
10-
; MOV AX, 0x900 ; Setting ES register to boot segment to use it inorder to
11-
; MOV ES, AX ; accessing it's content after loading data on it
1210
MOV BX, STAGE2_OFFSET ; This is logical address (= 0x10C00 physical)
1311
CALL DISK_IO
1412

devices/cpu/irq.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,26 @@
99

1010
#define PIC_ACK 0x20
1111

12+
Void* irq_callbacks[256] = {0};
13+
1214

1315
Bool pic_acknowledge(
1416
UInt32 int_num
1517
) {
16-
1718
if (int_num < PIC_START_INT || int_num > PIC_END_INT) {
1819
tty_print("None!\n");
1920
return FALSE;
2021
}
21-
2222
else if (int_num < PIC2_START_INT) {
23-
// tty_print("PIC1!\n");
2423
outb(PIC1_PORT_A, PIC_ACK);
2524
}
2625
else {
27-
// tty_print("PIC2!\n");
2826
outb(PIC2_PORT_A, PIC_ACK);
2927
}
3028

3129
return TRUE;
3230
}
3331

34-
Void* irq_callbacks[256] = {0};
3532

3633
Void handler_initer(
3734
IrqType type,
@@ -51,7 +48,7 @@ Void handler_killer(
5148

5249
Void irq_handler(
5350
UInt32 ebx,
54-
Cpu cpu,
51+
Cpu cpu,
5552
UInt32 int_num
5653
) {
5754
if (!pic_acknowledge(int_num)) {
@@ -61,6 +58,7 @@ Void irq_handler(
6158
if (irq_callbacks[int_num] != 0) {
6259
IrsCall handler = irq_callbacks[int_num];
6360
handler();
61+
return;
6462
}
6563

6664
// tty_print("An irq received (IRQ handle not implimented yet!)\n");

devices/keyboard.c

+49-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ Bytes shift_code[] = {
3636
"Keypad *", "LAlt", " "
3737
};
3838

39+
Bytes commands[] = {
40+
"help",
41+
"reboot",
42+
"clear",
43+
"yes"
44+
};
45+
Size com_len = 4;
46+
47+
Bool shift_down = FALSE;
48+
Bool ctrl_down = FALSE;
49+
Char char_buffer[80] = {0};
50+
Size cb_len = 0;
3951

40-
Bool shift_down = FALSE;
41-
Bool ctrl_down = FALSE;
4252

4353
IrsCall keyboard_callback() {
4454

@@ -61,16 +71,41 @@ IrsCall keyboard_callback() {
6171
return;
6272
}
6373
else if (code == ENTER) {
74+
input(char_buffer);
6475
tty_print("\n");
6576
tty_print("> ");
77+
cb_len = 0;
6678
return;
6779
}
6880
else if (code == BACKSPACE) {
6981
tty_print("\b");
82+
83+
char_buffer[cb_len - 1] = '\0';
84+
cb_len--;
85+
7086
return;
7187
}
7288
else if (code == TAB) {
73-
tty_print("\t");
89+
90+
Size len = strlen(char_buffer);
91+
Size contained = 0;
92+
93+
for (Size icom = 0; icom < com_len; icom++) {
94+
for (Size idx = 0; idx < len; idx++) {
95+
96+
if (*char_buffer == *(commands[icom])) {
97+
contained++;
98+
}
99+
}
100+
if (contained == len) {
101+
tty_print(commands[icom] + len);
102+
strcat(char_buffer, commands[icom] + len);
103+
cb_len = strlen(commands[icom]);
104+
contained = 0;
105+
break;
106+
}
107+
108+
}
74109
return;
75110
}
76111
else if (code == LEFT) {
@@ -109,11 +144,22 @@ IrsCall keyboard_callback() {
109144
return;
110145
}
111146

147+
if (ctrl_down && code == 19) {
148+
tty_print("\n> Rebooting...");
149+
wait();
150+
reboot();
151+
return;
152+
}
153+
112154
if (shift_down) {
113155
tty_print(shift_code[code]);
156+
strncat(char_buffer, shift_code[code], 1);
157+
cb_len++;
114158
}
115159
else {
116160
tty_print(nshift_code[code]);
161+
strncat(char_buffer, nshift_code[code], 1);
162+
cb_len++;
117163
}
118164
}
119165
}

inc/cpu/cpu.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ StackState;
4242
#define CPUID_VENDOR_NSC "Geode by NSC"
4343
#define CPUID_VENDOR_RISE "RiseRiseRise"
4444
#define CPUID_VENDOR_VORTEX "Vortex86 SoC"
45-
#define CPUID_VENDOR_VIA "VIA VIA VIA "
45+
// #define CPUID_VENDOR_VIA "VIA VIA VIA "
4646

4747
/*Vendor-strings from Virtual Machines.*/
4848
#define CPUID_VENDOR_VMWARE "VMwareVMware"

inc/kernel/tty.h

+35-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <defs/basic_defs.h>
55
#include <basic_types.h>
66
#include <drivers/ports.h>
7+
#include <string.h>
8+
#include <sys/system.h>
79

810
#define VIDEO_MEM 0xB8000
911
#define VGA_WIDTH 80
@@ -47,9 +49,39 @@ Void go_home();
4749
Void tty_print(Bytes str);
4850

4951

50-
__INLINE__ input(Bytes str) {
51-
keyboard_init();
52-
52+
__INLINE__ Void input(Bytes str) {
53+
54+
if (strcmp(str, "") == 0) {
55+
return;
56+
}
57+
else if (strcmp(str, "reboot") == 0) {
58+
tty_print("\n Rebooting...");
59+
wait();
60+
reboot();
61+
}
62+
else if (strcmp(str, "clear") == 0) {
63+
tty_init(VGA_WHITE, VGA_BLUE);
64+
tty_print("> ");
65+
}
66+
else if (strcmp(str, "help") == 0) {
67+
tty_print("\nKernel shell commands:\n");
68+
tty_print(" clear: Clearing screen\n");
69+
tty_print(" reboot: Rebooting system\n");
70+
tty_print(" yes: Types y forever\n");
71+
}
72+
else if (strcmp(str, "yes") == 0) {
73+
loop {
74+
tty_print("\ny");
75+
}
76+
}
77+
else {
78+
tty_print("\n");
79+
tty_print(str);
80+
tty_print(": ");
81+
tty_print("Command not found. type `help` to see available commands.\n");
82+
}
83+
84+
memset(str, '\0', 80);
5385
}
5486

5587
#endif // __TTY_H

inc/libk/math/pow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <basic_types.h>
77

88

9-
Double pow(UInt32 num, Size rep) {
9+
__INLINE__ Double pow(UInt32 num, Size rep) {
1010

1111
Double res = 1;
1212
for (Size i = 0; i < rep; i++) {

inc/libk/string.h

+38-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __STRING_H
2-
#define __STRING_H
1+
#ifndef __STRING_H_
2+
#define __STRING_H_
33

44
#include <defs/basic_defs.h>
55
#include <basic_types.h>
@@ -90,6 +90,41 @@ __INLINE__ Bytes strncat(
9090
}
9191

9292

93+
__INLINE__ Size strcmp(
94+
const Bytes str_1,
95+
const Bytes str_2
96+
) {
97+
Size ret = 0;
98+
Size len1 = strlen(str_1);
99+
Size len2 = strlen(str_2);
100+
Bytes cur1 = str_1;
101+
Bytes cur2 = str_2;
102+
103+
if (len1 == len2) {
104+
105+
for (Size i = 0; i < len1; i++) {
106+
107+
if (*(cur1) != *(cur2)) {
108+
ret++;
109+
}
110+
// else if (*(cur1) < *(cur2)) {
111+
// ret--;
112+
// }
113+
114+
cur1++;
115+
cur2++;
116+
}
117+
}
118+
else {
119+
ret++;
120+
}
121+
122+
123+
124+
return ret;
125+
}
126+
127+
93128
__INLINE__ Size atoi(
94129
Bytes str
95130
) {
@@ -112,7 +147,7 @@ __INLINE__ Size atoi(
112147
}
113148

114149

115-
Bytes itoa(
150+
__INLINE__ Bytes itoa(
116151
Size num,
117152
Bytes str
118153
) {

inc/sys/system.h

+20-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@
44
#include <defs/basic_defs.h>
55
#include <basic_types.h>
66

7-
Void die() {
7+
8+
__INLINE__ Void die() {
89
__asm__ volatile ("hlt");
910
}
1011

12+
13+
__INLINE__ Void reboot() {
14+
// __asm__ volatile ("jmp 0xFFFF:0x0");
15+
UInt8 good = 0x02;
16+
while (good & 0x02) {
17+
good = inb(0x64);
18+
}
19+
outb(0x64, 0xFE);
20+
die();
21+
}
22+
23+
24+
__INLINE__ Void wait() {
25+
for (Size i = 0; i < 1000000000;) {
26+
i++;
27+
}
28+
}
29+
1130
#endif // __SYSTEM_H

kernel/main

17.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)