Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lightning-speed authored Aug 25, 2021
1 parent 0cf0b85 commit 17e3e4e
Show file tree
Hide file tree
Showing 36 changed files with 983 additions and 0 deletions.
21 changes: 21 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
mkdir bin
nasm -f elf32 src\kernel_loader.asm -o kernel_loader.o
gcc -m32 -c -I src\. src\kernel.c -o kernel.o
cd bin
gcc -m32 -c -I ..\src\. ..\src\Drivers\*.c
gcc -m32 -c -I ..\src\. ..\src\System\*.c
gcc -m32 -c -I ..\src\. ..\src\Graphics\*.c
gcc -m32 -c -I ..\src\. ..\src\FS\*.c
gcc -m32 -c -I ..\src\. ..\src\Shell\*.c
gcc -m32 -c -I ..\src\. ..\src\Mego-Runtime\*.c
gcc -m32 -c -I ..\src\. ..\src\Terminal-Runtime\*.c
gcc -m32 -c -I ..\src\. ..\src\Util\*.c
ld ..\kernel_loader.o ..\kernel.o *.o -o kernel.e
del *.o
del ..\*.o
objcopy -Felf32-i386 kernel.e kernel.bin
del *.e
qemu-system-x86_64.exe -kernel kernel.bin
cd ..
del bin
pause
6 changes: 6 additions & 0 deletions limine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

TIMEOUT=0
: limine-boot kernel
KERNEL_PATH=boot:///kernel.bin

PROTOCOL=multiboot
19 changes: 19 additions & 0 deletions linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SECTIONS {
.text ALIGN(2K) : {
*(.text*)
}
.rodata ALIGN(2K) : {
*(.rodata*)
}
.data ALIGN(2K) : {
*(.data*)
}
.bss ALIGN(2K) : {
*(COMMON)
*(.bss*)

_stack_bottom = .;
. += 8K;
_stack_top = .;
}
}
46 changes: 46 additions & 0 deletions src/Drivers/Keyboard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include"Screen.h"
char * keycode = "\e 1234567890-=\b\tqwertyuiop[]\n\0asdfghjkl;'`\0\\zxcvbnm,./\0\0\0 ";
char * keycode2 = "\e !@#$%^&*()_+\b\tQWERTYUIOP{}\n\0ASDFGHJKL:'~\0|ZXCVBNM<>?\0\0\0 ";
int isShift= 0;
#include<System/IO.h>
char readChar(){
int run = 1;
char out = 0;
while(run){
if(inportb(0x64) & 0x1){
if(inportb(0x60)==0x2A&&!isShift)isShift=1;
else if(inportb(0x60)==0xAA&&isShift)isShift=0;
if(!isShift)
out = keycode[inportb(0x60)];
else if(isShift)
out = keycode2[inportb(0x60)];
if(out!=0&&inportb(0x60)<60)run=0;
}
}
return out;
}
char * input(){
char tp=0;
char * out="";
int index = 0;
while((tp=readChar())!='\n'){
out[index]=tp;
out[index+1]=0;
if(out[index]=='\b'){
if(index>0){
out[index]=0;
out[index-1]=0;
backspace();
index-=1;
}
}
else{
printChar(tp,Screen->defaultColor);
index++;
}
}
return out;
}
char getChar(){
if(inportb(0x60)<60&&inportb(0x60)>0&&keycode[inportb(0x60)]>0&&keycode[inportb(0x60)]<254)return keycode[inportb(0x60)];
}
4 changes: 4 additions & 0 deletions src/Drivers/Keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
char readChar();
char * input();
char getChar();
85 changes: 85 additions & 0 deletions src/Drivers/Screen.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include"Screen.h"
#include<System/IO.h>

void scroll();
void printChar(char ch,int color){
if(ch=='\b'){backspace();return;}
if(Screen->cursorY>=24){scroll();}
if(ch=='\n'||Screen->cursorX==160){
Screen->cursorY++;
Screen->cursorX = 0;
}
if(ch!='\n'){
Screen->vga[(Screen->cursorY*160)+Screen->cursorX]=ch;
Screen->vga[(Screen->cursorY*160)+Screen->cursorX+1]=color;
Screen->cursorX+=2;
}
setCursorPosition(Screen->cursorX,Screen->cursorY);
}
void setCursorPosition(int xe,int ye){
unsigned temp;
temp = ye * 80 + (xe/2);
outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);
}
void printC(char a){
printChar(a,Screen->defaultColor);
}
void print(const char * str,int color){
for(int i = 0;str[i]!=0;i++){
printChar(str[i],color);
}
setCursorPosition(Screen->cursorX,Screen->cursorY);
}
void printW(const char * str){
print(str,Screen->defaultColor);
setCursorPosition(Screen->cursorX,Screen->cursorY);
}
void clearScreen(){
Screen->cursorX = 0;
Screen->cursorY = 0;
for(int i = 0;i<160*25;i+=2){
Screen->vga[i]=0;
}
}

void screen_init(){
Screen->vga = (char *) 0xB8000;
Screen->cursorX = 0;
Screen->cursorY = 0;
Screen->defaultColor = 0x07;
}
void setDefaultColor(int color){
Screen->defaultColor = color;
}
void clearLine(int line){
for(int i = 0;i<160;i++){
Screen->vga[(160*line)+i]=0;
}
}
void setScreenColor(int color){
setDefaultColor(color);
char * vga = (char *) 0xB8000;
for(int i = 1;i<160*26;i+=2){
vga[i] = (color-(color%16))+(vga[i]%16);
}
}
void scroll(){
char * * lines;
for(int i = 1;i<Screen->cursorY+1;i++){
for(int j = 0;j<160;j++){
Screen->vga[(160*(i-1))+j] = Screen->vga[(160*i)+j];
}
}
clearLine(Screen->cursorY);
Screen->cursorY--;
setScreenColor(Screen->defaultColor);
}
void backspace(){
if(Screen->cursorX!=0)Screen->cursorX-=2;
else{Screen->cursorX=160;Screen->cursorY--;}
Screen->vga[(Screen->cursorY*160)+Screen->cursorX]=0;
setCursorPosition(Screen->cursorX,Screen->cursorY);
}
18 changes: 18 additions & 0 deletions src/Drivers/Screen.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
struct sc{
int cursorX;
int cursorY;
int defaultColor;
char * vga;
};
static struct sc * Screen;
void screen_init();
void clearScreen();
void printChar(char ch,int color);
void print(const char * str,int color);
void printW(const char * str);
void setScreenColor(int color);
void setDefaultColor(int color);
void setCursorPosition(int xe,int ye);
void backspace();
void printC(char a);
102 changes: 102 additions & 0 deletions src/FS/fs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#include"fs.h"
#include<Util/string.h>
char * fs = (char *)0x70000;
int fs_index = 0;
int file_index = 0;
void createNativeFiles();
void fs_init(){
createNativeFiles();
}
void createFile(char * fn){
for(int i = fs_index;i<=fs_index+2048;i++){
fs[i] = 0;
}
for(int i = 0;i<length(fn);i++){
fs[fs_index+i] = fn[i];
}
fs_index+=2048;
file_index++;
}
void writeFileAt(int indexF,char * content){
int loc = indexF*2048;
for(int i = loc+32;i<loc+32+length(content);i++){
fs[i]=content[i-(loc+32)];
}
}
char * getFileNameAt(int indexF){
char * out = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; //32-bit name
int loc = indexF*2048;
for(int i = 0;i<32;i++){
out[i]=fs[loc+i];
}
return out;
}
char * getFileContentAt(int indexF){
char * out = (char *)0xEEEE;
int loc = indexF*2048;
for(int i = 0;i<2000;i++){
out[i]=fs[loc+i+32];

}
return out;
}
char * readFile(char * name){
for(int i = 0;i<file_index;i++){
if(equal(name,getFileNameAt(i))){
return getFileContentAt(i);
}
}
}
void writeFile(char * name,char * text){
for(int i = 0;i<file_index;i++){
if(equal(name,getFileNameAt(i))){
writeFileAt(i,text);
}
}
}
int doesFileExists(char * name){
for(int i = 0;i<file_index;i++){
if(equal(name,getFileNameAt(i))){
return 1;
}
}
return 0;
}
int file_size_of(char * name){
return length(readFile(name));
}
char * getFS(){
return fs;
}
int total_files(){
return file_index;
}
void createNativeFiles(){
createFile("test.mex");
char * pro = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char pr[100]={30,1,50,'\e',
45,3,1,'\e',
34,1,1,'\e',
35,1,1,'\e',
41,1,55,'\e',
40,3,1,'\e',
'\r','H','E','L','L','O'};
for(int i = 0;i<37;i++){
pro[i]=pr[i];
}
writeFile("test.mex",pro);
}
void copyFile(char * in,char * des){
char * text = readFile(in);
createFile(des);
writeFile(des,text);
}
void clearFile(char * name){
for(int i = 0;i<file_index;i++){
if(equal(name,getFileNameAt(i))){
for(int j = 0;j<2000;j++){
fs[(i*2048)+j+32]=0;
}
}
}
}
14 changes: 14 additions & 0 deletions src/FS/fs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
void createFile(char * fn);
void fs_init();
char * getFS();
void writeFileAt(int indexF,char * content);
char * getFileNameAt(int indexF);
char * getFileContentAt(int indexF);
int total_files();
int file_size_of(char * name);
char * readFile(char * name);
int doesFileExists(char * name);
void writeFile(char * name,char * text);
void copyFile(char * in,char * des);
void clearFile(char * name);
25 changes: 25 additions & 0 deletions src/Graphics/Graphics.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include<Drivers/Screen.h>

int length(char * in);
void setDefaultScreenColor(int color);
void setCharAt(int xex,int ye,char ae,int color){
int xe = xex*2;
char * vga = (char *) 0xB8000;
vga[(ye*160)+xe]=ae;
vga[(ye*160)+xe+1]=color;
}
void printAt(int xe,int ye,char * tex,int color){
for(int i = 0;i<length(tex);i++){
setCharAt(xe+i,ye,tex[i],color);
}
}
void printCenter(int ye,char * text,int color){
printAt(40-(length(text)/2),ye,text,color);
}
void setBlockAt(int x,int y,int color){
Screen->vga[(y*160)+(x*4)]=219;
Screen->vga[(y*160)+(x*4)+1]=color;
Screen->vga[(y*160)+(x*4)+2]=219;
Screen->vga[(y*160)+(x*4)+3]=color;

}
5 changes: 5 additions & 0 deletions src/Graphics/Graphics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
void setCharAt(int xe,int ye,char ae,int color);
void printAt(int xe,int ye,char * tex,int color);
void printCenter(int ye,char * text,int color);
void setBlockAt(int x,int y,int color);
18 changes: 18 additions & 0 deletions src/Graphics/Image.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<Drivers/Screen.h>
typedef int * Image;
int he,we;
void drawImage(int xe,int ye,int * img){
we = img[0];
he = img[1];
int temp = 2;
xe*=2;
for(int i = 0;i<he;i++){
for(int j = 0;j<we*4;j+=4){
Screen->vga[(160*(i+ye))+j+xe]=219;
Screen->vga[(160*(i+ye))+j+1+xe]=img[temp]/16;
Screen->vga[(160*(i+ye))+j+2+xe]=219;
Screen->vga[(160*(i+ye))+j+3+xe]=img[temp]/16;
temp++;
}
}
}
2 changes: 2 additions & 0 deletions src/Graphics/Image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
void drawImage(int xe,int ye,int * img);
7 changes: 7 additions & 0 deletions src/Mego-Runtime/Command.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include"Runtime.h"
#include<Drivers/Screen.h>
void execute_command(int command){
if(command==0x1){
printC(getRegValueOf(3));
}
}
Loading

0 comments on commit 17e3e4e

Please sign in to comment.