-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c5a0eeb
commit da7fce3
Showing
17 changed files
with
215 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef NANOSHELL_COMMANDS_H | ||
#define NANOSHELL_COMMANDS_H | ||
|
||
#define COMMAND_LENGTH_MAX 256 | ||
|
||
#define COMMAND_NB 4 | ||
#define HALT_COMMAND "halt" | ||
#define STACK_COMMAND "stack" | ||
#define REBOOT_COMMAND "reboot" | ||
#define SHUTDOWN_COMMAND "shutdown" | ||
|
||
typedef struct | ||
{ | ||
char *name; | ||
void (*handler)(char *args); | ||
} command_t; | ||
|
||
extern command_t commands[COMMAND_NB]; | ||
|
||
void halt(char *args); | ||
void stack(char *args); | ||
void reboot(char *args); | ||
void shutdown(char *args); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef NANOSHELL_SHELL_H | ||
#define NANOSHELL_SHELL_H | ||
|
||
#include "commands.h" | ||
|
||
void execute(char *command); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "nanoshell/shell.h" | ||
|
||
command_t commands[] = { | ||
{ "reboot", reboot }, | ||
{ "shutdown", shutdown }, | ||
{ "halt", halt }, | ||
{ "stack", stack }, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "nanoshell/commands.h" | ||
#include "utils.h" | ||
|
||
void halt(__unused char *args) | ||
{ | ||
asm("cli; hlt"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "nanoshell/commands.h" | ||
#include "CPU/port.h" | ||
#include "utils.h" | ||
#include <stdint.h> | ||
|
||
|
||
void reboot(__unused char *args) | ||
{ | ||
uint8_t good = 0x02; | ||
while (good & 0x02) | ||
good = inb(0x64); | ||
outb(0x64, 0xFE); | ||
|
||
loop: | ||
asm volatile("hlt"); | ||
goto loop; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "nanoshell/commands.h" | ||
#include "CPU/port.h" | ||
#include "utils.h" | ||
|
||
void shutdown(__unused char *args) | ||
{ | ||
outw(0x604, 0x2000); // QEMU specific | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "CPU/GDT.h" | ||
#include "nanoshell/commands.h" | ||
#include "utils.h" | ||
|
||
void stack(__unused char *args) | ||
{ | ||
void *sp; | ||
void *sf; | ||
|
||
GET_STACK_POINTER(sp); | ||
GET_STACK_FRAME(sf); | ||
|
||
print_stack(sp - 16, sf + 16); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <string.h> | ||
#include "nanoshell/shell.h" | ||
#include "IO/printk.h" | ||
|
||
void execute(char *command) | ||
{ | ||
int i; | ||
for (i = 0; i < COMMAND_NB; i++) | ||
{ | ||
if (strcmp(commands[i].name, command) == 0) | ||
{ | ||
commands[i].handler(command); | ||
return; | ||
} | ||
} | ||
printk("Unknown command: %s\n", command); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "CPU/GDT.h" | ||
#include <stddef.h> | ||
#include "IO/printk.h" | ||
#include "IO/terminal.h" | ||
|
||
static void fixed_print(uint8_t c) | ||
{ | ||
uint8_t u = c & 0x0F; | ||
uint8_t d = (c & 0xF0) >> 4; | ||
char *hex = "0123456789ABCDEF"; | ||
|
||
printk("%c%c ", hex[d], hex[u]); | ||
} | ||
|
||
void print_stack(void *sp, void *sf) | ||
{ | ||
uint8_t color; | ||
|
||
// Print a hex dump of the stack. | ||
size_t i = 0; | ||
while (sp < sf) | ||
{ | ||
if (i % 16 == 0) | ||
{ | ||
color = vga_entry_color(VGA_COLOR_MAGENTA, VGA_COLOR_BLACK); | ||
terminal_setcolor(color); | ||
printk("%p: ", sp); | ||
color = vga_entry_color(VGA_COLOR_LIGHT_GREY, VGA_COLOR_BLACK); | ||
terminal_setcolor(color); | ||
} | ||
fixed_print(*(uint8_t *)sp); | ||
sp++; | ||
i++; | ||
if (i % 16 == 0) | ||
{ | ||
terminal_putchar('\n'); | ||
} | ||
} | ||
printk("\n\n"); | ||
} |