Refactoring assembly entry point
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
OBJS = shell.o fetch.o
|
||||
VER := $(shell git rev-parse --short HEAD)
|
||||
|
||||
CC = i686-elf-gcc # cross-compiler
|
||||
CFLAGS = -DDEFAULT_USER=root -DDEFAULT_HOSTNAME=vulcan -DVULCAN_VERSION=$(VER) -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c
|
||||
|
||||
all:${OBJS}
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
OBJS = shell.o fetch.o
|
||||
VER := $(shell git rev-parse --short HEAD)
|
||||
|
||||
CC = i686-elf-gcc # cross-compiler
|
||||
CFLAGS = -DDEFAULT_USER=root -DDEFAULT_HOSTNAME=vulcan -DVULCAN_VERSION=$(VER) -m32 -fno-stack-protector -ffreestanding -Wall -Wextra -Werror -g -c
|
||||
|
||||
all:${OBJS}
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $< -o $@
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
#include "fetch.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/time.h"
|
||||
#include "../drivers/tty.h"
|
||||
#include "../drivers/cpuid.h"
|
||||
#define STRINGIZE(x) #x
|
||||
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
||||
|
||||
static void get_date();
|
||||
static void get_cpuid();
|
||||
static void get_version();
|
||||
|
||||
void system_fetcher() {
|
||||
uint8_t user[64], hostname[64];
|
||||
#ifdef DEFAULT_USER
|
||||
strcpy(user, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_USER));
|
||||
#else
|
||||
#error "-DDEFAULT_USER flag not set"
|
||||
#endif
|
||||
|
||||
#ifdef DEFAULT_HOSTNAME
|
||||
strcpy(hostname, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_HOSTNAME));
|
||||
#else
|
||||
#error "-DDEFAULT_HOSTNAME flag not set"
|
||||
#endif
|
||||
// print first line
|
||||
printf_color("\n __ __ ___ ___ ", LIGHT_RED, BLACK);
|
||||
printf_color((char*)user, LIGHT_CYAN, BLACK);
|
||||
printf_color("@", LIGHT_RED, BLACK);
|
||||
printf_color((char*)hostname, LIGHT_CYAN, BLACK);
|
||||
// print second line
|
||||
printf_color("\n \\ \\ / / / _ \\/ __| ", LIGHT_RED, BLACK);
|
||||
printf_color("-----------", LIGHT_RED, BLACK);
|
||||
// print third line
|
||||
printf_color("\n \\ V / | (_) \\__ \\ ", LIGHT_RED, BLACK);
|
||||
printf_color("Date: ", LIGHT_CYAN, BLACK);
|
||||
get_date();
|
||||
// print fourth line
|
||||
printf_color("\n \\_/ \\___/|___/ ", LIGHT_RED, BLACK);
|
||||
get_cpuid();
|
||||
// print VulcanOS version
|
||||
get_version();
|
||||
}
|
||||
|
||||
// Date format is D/M/YY
|
||||
void get_date() {
|
||||
printf("%d", get_time(TIME_R_DAY)); // Day
|
||||
printf_color("/", LIGHT_BLUE, BLACK);
|
||||
|
||||
printf("%d", get_time(TIME_R_MONTH)); // Month
|
||||
printf_color("/", LIGHT_BLUE, BLACK);
|
||||
|
||||
printf("%d", get_time(TIME_R_YEAR)); // Year
|
||||
}
|
||||
|
||||
|
||||
void get_cpuid() {
|
||||
printf_color("CPU type: ", LIGHT_CYAN, BLACK);
|
||||
printf("%s", (char*)get_cpu_type()); // Print CPU type
|
||||
printf("%s%s%c", " (", (char*)get_cpu_family(), ')');
|
||||
}
|
||||
|
||||
|
||||
void get_version() {
|
||||
uint8_t version[64];
|
||||
#ifdef VULCAN_VERSION
|
||||
strcpy(version, (uint8_t*)STRINGIZE_VALUE_OF(VULCAN_VERSION));
|
||||
#else
|
||||
#error "-DVULCAN_VERSION flag not set"
|
||||
#endif
|
||||
|
||||
printf_color("\n\t\t\t\t\t Version: ", LIGHT_CYAN, BLACK);
|
||||
printf_color((char*)version, LIGHT_GREEN, BLACK);
|
||||
}
|
||||
#include "fetch.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/time.h"
|
||||
#include "../drivers/tty.h"
|
||||
#include "../drivers/cpuid.h"
|
||||
#define STRINGIZE(x) #x
|
||||
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
|
||||
|
||||
static void get_date();
|
||||
static void get_cpuid();
|
||||
static void get_version();
|
||||
|
||||
void system_fetcher() {
|
||||
uint8_t user[64], hostname[64];
|
||||
#ifdef DEFAULT_USER
|
||||
strcpy(user, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_USER));
|
||||
#else
|
||||
#error "-DDEFAULT_USER flag not set"
|
||||
#endif
|
||||
|
||||
#ifdef DEFAULT_HOSTNAME
|
||||
strcpy(hostname, (uint8_t*)STRINGIZE_VALUE_OF(DEFAULT_HOSTNAME));
|
||||
#else
|
||||
#error "-DDEFAULT_HOSTNAME flag not set"
|
||||
#endif
|
||||
// print first line
|
||||
printf_color("\n __ __ ___ ___ ", LIGHT_RED, BLACK);
|
||||
printf_color((char*)user, LIGHT_CYAN, BLACK);
|
||||
printf_color("@", LIGHT_RED, BLACK);
|
||||
printf_color((char*)hostname, LIGHT_CYAN, BLACK);
|
||||
// print second line
|
||||
printf_color("\n \\ \\ / / / _ \\/ __| ", LIGHT_RED, BLACK);
|
||||
printf_color("-----------", LIGHT_RED, BLACK);
|
||||
// print third line
|
||||
printf_color("\n \\ V / | (_) \\__ \\ ", LIGHT_RED, BLACK);
|
||||
printf_color("Date: ", LIGHT_CYAN, BLACK);
|
||||
get_date();
|
||||
// print fourth line
|
||||
printf_color("\n \\_/ \\___/|___/ ", LIGHT_RED, BLACK);
|
||||
get_cpuid();
|
||||
// print VulcanOS version
|
||||
get_version();
|
||||
}
|
||||
|
||||
// Date format is D/M/YY
|
||||
void get_date() {
|
||||
printf("%d", get_time(TIME_R_DAY)); // Day
|
||||
printf_color("/", LIGHT_BLUE, BLACK);
|
||||
|
||||
printf("%d", get_time(TIME_R_MONTH)); // Month
|
||||
printf_color("/", LIGHT_BLUE, BLACK);
|
||||
|
||||
printf("%d", get_time(TIME_R_YEAR)); // Year
|
||||
}
|
||||
|
||||
|
||||
void get_cpuid() {
|
||||
printf_color("CPU type: ", LIGHT_CYAN, BLACK);
|
||||
printf("%s", (char*)get_cpu_type()); // Print CPU type
|
||||
printf("%s%s%c", " (", (char*)get_cpu_family(), ')');
|
||||
}
|
||||
|
||||
|
||||
void get_version() {
|
||||
uint8_t version[64];
|
||||
#ifdef VULCAN_VERSION
|
||||
strcpy(version, (uint8_t*)STRINGIZE_VALUE_OF(VULCAN_VERSION));
|
||||
#else
|
||||
#error "-DVULCAN_VERSION flag not set"
|
||||
#endif
|
||||
|
||||
printf_color("\n\t\t\t\t\t Version: ", LIGHT_CYAN, BLACK);
|
||||
printf_color((char*)version, LIGHT_GREEN, BLACK);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
/**************************************
|
||||
* VulcanOS Kernel *
|
||||
* Developed by Marco 'icebit' Cetica *
|
||||
* (c) 2019-2021 *
|
||||
* Released under GPLv3 *
|
||||
* https://github.com/ice-bit/iceOS *
|
||||
***************************************/
|
||||
#ifndef FETCH_H
|
||||
#define FETCH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void system_fetcher();
|
||||
|
||||
#endif
|
||||
/**************************************
|
||||
* VulcanOS Kernel *
|
||||
* Developed by Marco 'icebit' Cetica *
|
||||
* (c) 2019-2021 *
|
||||
* Released under GPLv3 *
|
||||
* https://github.com/ice-bit/iceOS *
|
||||
***************************************/
|
||||
#ifndef FETCH_H
|
||||
#define FETCH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void system_fetcher();
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,122 +1,122 @@
|
||||
#include "shell.h"
|
||||
#include "fetch.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "../drivers/tty.h"
|
||||
#include "../drivers/ports.h"
|
||||
#include "../drivers/timer.h"
|
||||
|
||||
void helper() {
|
||||
puts("\nList of available commands:\n"
|
||||
"\nhelp - Print this helper"
|
||||
"\nint - Test some interrupts"
|
||||
"\nbanner - Show banner"
|
||||
"\nclear, cls - Clear the screen"
|
||||
"\nregs - Prints register dump"
|
||||
"\ntimer - Prints timer tick"
|
||||
"\nabout - About this kernel"
|
||||
"\nreboot - Reboot the system"
|
||||
);
|
||||
}
|
||||
|
||||
void test_interrupts() {
|
||||
// Testing some interrupts
|
||||
asm("int $0"); // Division by zero
|
||||
asm("int $4"); // Stack overflow
|
||||
asm("int $1"); // Page fault
|
||||
}
|
||||
|
||||
void about() {
|
||||
printf_color("\n====== IceOS v0.0.1 (c) 2019 Marco 'icebit' Cetica ======\n\n",
|
||||
LIGHT_CYAN, BLACK);
|
||||
printf_color(
|
||||
"iceOS is a x86 monolithic kernel written in C from scratch.\n"
|
||||
"This project doesn't aim to be a fully functional operating system\n"
|
||||
"with tons of drivers and graphical applications,\nit's just a learning tool "
|
||||
"to teach myself concepts like\nOperating Systems, Computer Architecture and Digital Electronics.\n"
|
||||
"\n\n"
|
||||
"iceOS comes with the following features:\n"
|
||||
"- Bare metal booting;\n"
|
||||
"- VGA driver;\n"
|
||||
"- Interrupts implementation;\n"
|
||||
"- PIC & PIT implementation;\n"
|
||||
"- PS2 driver;\n"
|
||||
"- Support for x86 architecture;\n"
|
||||
"- GRUB as bootloader;\n",
|
||||
LIGHT_GREEN, BLACK);
|
||||
}
|
||||
|
||||
void register_dump() {
|
||||
register uint32_t eax_v asm("eax");
|
||||
register uint32_t ebx_v asm("ebx");
|
||||
register uint32_t ecx_v asm("ecx");
|
||||
register uint32_t edx_v asm("edx");
|
||||
register uint32_t esx_v asm("esi");
|
||||
register uint32_t edi_v asm("edi");
|
||||
register uint32_t ebp_v asm("ebp");
|
||||
register uint32_t esp_v asm("esp");
|
||||
|
||||
printf_color("\n===================================\n"
|
||||
" BEGIN 32 BITS CPU REGISTER DUMP \n"
|
||||
"===================================\n",
|
||||
LIGHT_BROWN, BLACK);
|
||||
printf(" EAX: %x\n"
|
||||
" EBX: %x\n"
|
||||
" ECX: %x\n"
|
||||
" EDX: %x\n"
|
||||
" ESX: %x\n"
|
||||
" EDI: %x\n"
|
||||
" EBP: %x\n"
|
||||
" ESP: %x\n",
|
||||
eax_v, ebx_v, ecx_v, edx_v, esx_v, edi_v, ebp_v, esp_v);
|
||||
printf_color("\n==================================\n"
|
||||
" END 32 BITS CPU REGISTER DUMP \n"
|
||||
"==================================\n",
|
||||
LIGHT_BROWN, BLACK);
|
||||
}
|
||||
|
||||
void timer_dump() {
|
||||
uint8_t buf[8];
|
||||
uitoa(tick, buf, 10);
|
||||
|
||||
printf_color("\nTicks since boot: ",
|
||||
LIGHT_GREEN, BLACK);
|
||||
printf_color((const char*)buf,
|
||||
LIGHT_CYAN, BLACK);
|
||||
}
|
||||
void reboot() {
|
||||
uint8_t tmp;
|
||||
asm("cli"); // First disable all interrupts
|
||||
|
||||
// Clear keyboard buffers
|
||||
do {
|
||||
tmp = inb(0x64); // Keyboard interface
|
||||
if(check_flag(tmp, 0) != 0)
|
||||
inb(0x60); // Clear keyboard data
|
||||
} while(check_flag(tmp, 1) != 0);
|
||||
|
||||
outb(0x64, 0xFE); // Reset the CPU
|
||||
}
|
||||
|
||||
void processCommand(uint8_t *cmd) {
|
||||
if(strcmp(cmd, (uint8_t*)"help") == 0)
|
||||
helper();
|
||||
else if(strcmp(cmd, (uint8_t*)"int") == 0)
|
||||
test_interrupts();
|
||||
else if(strcmp(cmd, (uint8_t*)"clear") == 0 || strcmp(cmd, (uint8_t*)"cls") == 0)
|
||||
clear_prompt();
|
||||
else if(strcmp(cmd, (uint8_t*)"about") == 0)
|
||||
about();
|
||||
else if(strcmp(cmd, (uint8_t*)"regs") == 0)
|
||||
register_dump();
|
||||
else if(strcmp(cmd, (uint8_t*)"timer") == 0)
|
||||
timer_dump();
|
||||
else if(strcmp(cmd, (uint8_t*)"fetch") == 0)
|
||||
system_fetcher();
|
||||
else if(strcmp(cmd, (uint8_t*)"reboot") == 0)
|
||||
reboot();
|
||||
else if(strcmp(cmd, (uint8_t*)"") == 0)
|
||||
puts("");
|
||||
else
|
||||
puts("\nCommand not found!");
|
||||
}
|
||||
#include "shell.h"
|
||||
#include "fetch.h"
|
||||
#include "../libc/string.h"
|
||||
#include "../libc/stdio.h"
|
||||
#include "../drivers/tty.h"
|
||||
#include "../drivers/ports.h"
|
||||
#include "../drivers/timer.h"
|
||||
|
||||
void helper() {
|
||||
puts("\nList of available commands:\n"
|
||||
"\nhelp - Print this helper"
|
||||
"\nint - Test some interrupts"
|
||||
"\nbanner - Show banner"
|
||||
"\nclear, cls - Clear the screen"
|
||||
"\nregs - Prints register dump"
|
||||
"\ntimer - Prints timer tick"
|
||||
"\nabout - About this kernel"
|
||||
"\nreboot - Reboot the system"
|
||||
);
|
||||
}
|
||||
|
||||
void test_interrupts() {
|
||||
// Testing some interrupts
|
||||
asm("int $0"); // Division by zero
|
||||
asm("int $4"); // Stack overflow
|
||||
asm("int $1"); // Page fault
|
||||
}
|
||||
|
||||
void about() {
|
||||
printf_color("\n====== IceOS v0.0.1 (c) 2019 Marco 'icebit' Cetica ======\n\n",
|
||||
LIGHT_CYAN, BLACK);
|
||||
printf_color(
|
||||
"iceOS is a x86 monolithic kernel written in C from scratch.\n"
|
||||
"This project doesn't aim to be a fully functional operating system\n"
|
||||
"with tons of drivers and graphical applications,\nit's just a learning tool "
|
||||
"to teach myself concepts like\nOperating Systems, Computer Architecture and Digital Electronics.\n"
|
||||
"\n\n"
|
||||
"iceOS comes with the following features:\n"
|
||||
"- Bare metal booting;\n"
|
||||
"- VGA driver;\n"
|
||||
"- Interrupts implementation;\n"
|
||||
"- PIC & PIT implementation;\n"
|
||||
"- PS2 driver;\n"
|
||||
"- Support for x86 architecture;\n"
|
||||
"- GRUB as bootloader;\n",
|
||||
LIGHT_GREEN, BLACK);
|
||||
}
|
||||
|
||||
void register_dump() {
|
||||
register uint32_t eax_v asm("eax");
|
||||
register uint32_t ebx_v asm("ebx");
|
||||
register uint32_t ecx_v asm("ecx");
|
||||
register uint32_t edx_v asm("edx");
|
||||
register uint32_t esx_v asm("esi");
|
||||
register uint32_t edi_v asm("edi");
|
||||
register uint32_t ebp_v asm("ebp");
|
||||
register uint32_t esp_v asm("esp");
|
||||
|
||||
printf_color("\n===================================\n"
|
||||
" BEGIN 32 BITS CPU REGISTER DUMP \n"
|
||||
"===================================\n",
|
||||
LIGHT_BROWN, BLACK);
|
||||
printf(" EAX: %x\n"
|
||||
" EBX: %x\n"
|
||||
" ECX: %x\n"
|
||||
" EDX: %x\n"
|
||||
" ESX: %x\n"
|
||||
" EDI: %x\n"
|
||||
" EBP: %x\n"
|
||||
" ESP: %x\n",
|
||||
eax_v, ebx_v, ecx_v, edx_v, esx_v, edi_v, ebp_v, esp_v);
|
||||
printf_color("\n==================================\n"
|
||||
" END 32 BITS CPU REGISTER DUMP \n"
|
||||
"==================================\n",
|
||||
LIGHT_BROWN, BLACK);
|
||||
}
|
||||
|
||||
void timer_dump() {
|
||||
uint8_t buf[8];
|
||||
uitoa(tick, buf, 10);
|
||||
|
||||
printf_color("\nTicks since boot: ",
|
||||
LIGHT_GREEN, BLACK);
|
||||
printf_color((const char*)buf,
|
||||
LIGHT_CYAN, BLACK);
|
||||
}
|
||||
void reboot() {
|
||||
uint8_t tmp;
|
||||
asm("cli"); // First disable all interrupts
|
||||
|
||||
// Clear keyboard buffers
|
||||
do {
|
||||
tmp = inb(0x64); // Keyboard interface
|
||||
if(check_flag(tmp, 0) != 0)
|
||||
inb(0x60); // Clear keyboard data
|
||||
} while(check_flag(tmp, 1) != 0);
|
||||
|
||||
outb(0x64, 0xFE); // Reset the CPU
|
||||
}
|
||||
|
||||
void processCommand(uint8_t *cmd) {
|
||||
if(strcmp(cmd, (uint8_t*)"help") == 0)
|
||||
helper();
|
||||
else if(strcmp(cmd, (uint8_t*)"int") == 0)
|
||||
test_interrupts();
|
||||
else if(strcmp(cmd, (uint8_t*)"clear") == 0 || strcmp(cmd, (uint8_t*)"cls") == 0)
|
||||
clear_prompt();
|
||||
else if(strcmp(cmd, (uint8_t*)"about") == 0)
|
||||
about();
|
||||
else if(strcmp(cmd, (uint8_t*)"regs") == 0)
|
||||
register_dump();
|
||||
else if(strcmp(cmd, (uint8_t*)"timer") == 0)
|
||||
timer_dump();
|
||||
else if(strcmp(cmd, (uint8_t*)"fetch") == 0)
|
||||
system_fetcher();
|
||||
else if(strcmp(cmd, (uint8_t*)"reboot") == 0)
|
||||
reboot();
|
||||
else if(strcmp(cmd, (uint8_t*)"") == 0)
|
||||
puts("");
|
||||
else
|
||||
puts("\nCommand not found!");
|
||||
}
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
/**************************************
|
||||
* VulcanOS Kernel *
|
||||
* Developed by Marco 'icebit' Cetica *
|
||||
* (c) 2019-2021 *
|
||||
* Released under GPLv3 *
|
||||
* https://github.com/ice-bit/iceOS *
|
||||
***************************************/
|
||||
#ifndef _SHELL_H_
|
||||
#define _SHELL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define bit(n) (1 << (n))
|
||||
#define check_flag(flags, n) ((flags) & bit(n))
|
||||
|
||||
void helper();
|
||||
void processCommand(uint8_t *cmd);
|
||||
|
||||
#endif
|
||||
/**************************************
|
||||
* VulcanOS Kernel *
|
||||
* Developed by Marco 'icebit' Cetica *
|
||||
* (c) 2019-2021 *
|
||||
* Released under GPLv3 *
|
||||
* https://github.com/ice-bit/iceOS *
|
||||
***************************************/
|
||||
#ifndef _SHELL_H_
|
||||
#define _SHELL_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define bit(n) (1 << (n))
|
||||
#define check_flag(flags, n) ((flags) & bit(n))
|
||||
|
||||
void helper();
|
||||
void processCommand(uint8_t *cmd);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user