2024-07-28 10:11:15 -04:00
|
|
|
#include "../lib/strcmp.h"
|
|
|
|
|
2024-10-03 22:13:13 -04:00
|
|
|
static const char test[] = "Hello\n";
|
|
|
|
|
2024-08-06 21:12:43 -04:00
|
|
|
int strlen(const char *str) {
|
|
|
|
const char *s;
|
|
|
|
for (s = str; *s; s++)
|
|
|
|
;
|
|
|
|
|
|
|
|
return s - str;
|
|
|
|
}
|
|
|
|
|
|
|
|
void putc(const char c) {
|
|
|
|
asm volatile (
|
|
|
|
"movl $1, %%eax\n\t"
|
|
|
|
"movl $1, %%edi\n\t"
|
|
|
|
"movl %0, %%esi\n\t"
|
|
|
|
"movl $1, %%edx\n\t"
|
|
|
|
"int $0x80"
|
|
|
|
:
|
|
|
|
: "r"(&c)
|
|
|
|
: "%eax", "%edi", "%esi", "%edx"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-28 10:11:15 -04:00
|
|
|
void puts(const char *str) {
|
|
|
|
asm volatile (
|
|
|
|
"movl $1, %%eax\n\t"
|
|
|
|
"movl $1, %%edi\n\t"
|
|
|
|
"movl %0, %%esi\n\t"
|
2024-08-06 21:12:43 -04:00
|
|
|
"movl %1, %%edx\n\t"
|
2024-07-28 10:11:15 -04:00
|
|
|
"int $0x80"
|
|
|
|
:
|
2024-08-06 21:12:43 -04:00
|
|
|
: "r"(str), "r"(strlen(str))
|
|
|
|
: "%eax", "%edi", "%esi", "%edx"
|
2024-07-28 10:11:15 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
void read(int fd, void *buf, int size) {
|
|
|
|
asm volatile (
|
|
|
|
"movl $0, %%eax\n\t"
|
|
|
|
"int $0x80"
|
|
|
|
:
|
|
|
|
: "D"(fd), "d"(size), "S"(buf)
|
|
|
|
: "eax"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-07-29 19:43:44 -04:00
|
|
|
void reboot() {
|
|
|
|
asm volatile (
|
|
|
|
"movl $2, %%eax\n\t"
|
|
|
|
"int $0x80"
|
|
|
|
:
|
|
|
|
:
|
|
|
|
: "eax"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-08-06 21:12:43 -04:00
|
|
|
uint64_t uptime() {
|
|
|
|
uint32_t low = 0;
|
|
|
|
uint32_t high = 0;
|
|
|
|
asm volatile (
|
|
|
|
"movl $3, %%eax\n\t"
|
|
|
|
"movl %0, %%esi\n\t"
|
|
|
|
"movl %1, %%edi\n\t"
|
|
|
|
"int $0x80"
|
|
|
|
:
|
|
|
|
: "r" (&low), "r" (&high)
|
|
|
|
: "eax", "esi"
|
|
|
|
);
|
|
|
|
|
|
|
|
return (uint64_t)low | ((uint64_t)high << 32);
|
|
|
|
}
|
|
|
|
|
2024-07-28 10:11:15 -04:00
|
|
|
extern char *buf;
|
|
|
|
|
2024-08-06 21:12:43 -04:00
|
|
|
void print_int(int num){
|
|
|
|
if (num < 0)
|
|
|
|
{
|
|
|
|
putc('-');
|
|
|
|
num = -num;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num > 9) print_int(num/10);
|
|
|
|
|
|
|
|
putc(('0'+ (num%10)));
|
|
|
|
}
|
|
|
|
|
2024-07-28 10:11:15 -04:00
|
|
|
void _start() {
|
|
|
|
char buf1[256] = {0};
|
2024-10-03 22:13:13 -04:00
|
|
|
//puts("Welcome to the Hazel user shell!\n");
|
|
|
|
puts(test);
|
2024-07-28 10:11:15 -04:00
|
|
|
while (1) {
|
2024-08-06 21:12:43 -04:00
|
|
|
puts("$ ");
|
2024-07-28 10:11:15 -04:00
|
|
|
read(0, buf1, 256);
|
2024-07-29 19:43:44 -04:00
|
|
|
if (!strcmp(buf1, "SKIBIDI")) {
|
|
|
|
puts("dop dop yes yes!\n");
|
|
|
|
} else if (!strcmp(buf1, "REBOOT")) {
|
|
|
|
reboot();
|
2024-08-06 21:12:43 -04:00
|
|
|
} else if (!strcmp(buf1, "UPTIME")) {
|
|
|
|
uint64_t ticks = uptime();
|
|
|
|
print_int(ticks);
|
|
|
|
puts("\n");
|
2024-07-29 19:43:44 -04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
puts("unknown command!\n");
|
|
|
|
}
|
2024-07-28 10:11:15 -04:00
|
|
|
}
|
|
|
|
}
|