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 Sep 8, 2021
1 parent ee54c8b commit 1fb60e4
Show file tree
Hide file tree
Showing 48 changed files with 2,089 additions and 0 deletions.
24 changes: 24 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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
nasm -f elf32 ..\src\Drivers\interrupt.asm -o .\inter.o
gcc -m32 -c -I ..\src\. ..\src\System\*.c
gcc -m32 -c -I ..\src\. ..\src\Graphics\*.c
gcc -m32 -c -I ..\src\. ..\src\Timer\*.c
gcc -m32 -c -I ..\src\. ..\src\FS\*.c
gcc -m32 -c -I ..\src\. ..\src\App32\*.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
54 changes: 54 additions & 0 deletions src/App32/Calculator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include<Util/string.h>
#include<Drivers/Screen.h>
#include<Drivers/Keyboard.h>
void calc_init(){
printW("\nEnter First Number: ");
int fn = parseInt(input());
printW("\nEnter Second Number: ");
int sn = parseInt(input());
printW("\nEnter the valid operator: ");
char ae;
int runningC = 1;
while(runningC){
ae = readChar();
if(ae=='+'){
printC(ae);
printW("\nOutput: ");
printW(toString(fn+sn));
runningC = 0;
}
else if(ae=='-'){
printC(ae);
printW("\nOutput: ");
printW(toString(fn-sn));
runningC = 0;
}
else if(ae=='/'){
printC(ae);

printW("\nOutput: ");
printW(toString(fn/sn));
runningC = 0;
}
else if(ae=='*'){
printC(ae);

printW("\nOutput: ");
printW(toString((fn*sn)));
runningC = 0;
}
else if(ae=='%'){
printC(ae);

printW("\nOutput: ");
printW(toString((fn%sn)));
runningC = 0;

}
else{
printC(ae);
printW("\nEnter the valid operator: ");
}

}
}
20 changes: 20 additions & 0 deletions src/App32/ImageViewr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<Util/string.h>
#include<Drivers/Screen.h>
#include<Drivers/Keyboard.h>
#include<Graphics/Image.h>
#include<System/MemoryManager.h>
#include<Graphics/Graphics.h>
#include<FS/fs.h>
char * ftv;
void ImageViewr_pre(){
ftv = new_str(109);
}
void ImageViewr_init(char * fn){
for(int i = 0;i<108;i++){
ftv[i]=0;
}
makeWindow(join("Image Viewr - ",fn));
set((int *)ftv,(int *)readFile(fn));
drawImage(40-ftv[0],12-ftv[1],ftv);
start_window_system();
}
87 changes: 87 additions & 0 deletions src/App32/Mex-Compiler.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
char * process(char * in);
#include<Drivers/Screen.h>
#include<System/SystemTime.h>
#include<Util/string.h>
#include<Drivers/Keyboard.h>
#include<System/MemoryManager.h>
#include<FS/fs.h>
void compile(char * text){
char * command = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
char * total = new_str(216);
int temp = 0;
for(int i = 0;i<length(text);i++){
if(text[i]=='\n'){
total = join(total,process(command));
temp = 0;
command[0]=0;
}
else{
command[temp]=text[i];
command[temp+1]=0;
temp++;
}
}
printC('\n');
printW(total);
total = join(total,"\r\0");
if(!doesFileExists("out.mex"))
createFile("out.mex");
writeFile("out.mex",total);
}
char * process(char * in){
char * out = "\0\0\0\e\0";
if(equalS(in,"movn",4))out[0]=30;
if(equalS(in,"movr",4))out[0]=31;
if(equalS(in,"push",4))out[0]=32;
if(equalS(in,"popr",4))out[0]=33;
if(equalS(in,"cmdn",4))out[0]=34;
if(equalS(in,"addn",4))out[0]=35;
if(equalS(in,"addr",4))out[0]=36;
if(equalS(in,"subn",4))out[0]=37;
if(equalS(in,"subr",4))out[0]=38;
if(equalS(in,"jump",4))out[0]=39;
if(equalS(in,"jnzn",4))out[0]=40;
if(equalS(in,"smal",4))out[0]=41;
if(equalS(in,"bign",4))out[0]=42;
if(equalS(in,"equn",4))out[0]=43;
if(equalS(in,"inbn",4))out[0]=44;
if(equalS(in,"outb",4))out[0]=45;
int sp = 0;
for(int i = 5;i<length(in);i++)if(in[i]==' ')sp = i;
char * arg1 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
set((int *)arg1,(int *)substring(in,5,sp));
char * arg2 = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
set((int *)arg2,(int *)substring(in,sp+1,length(in)));
if(arg1[0]<='9'&&arg1[0]>='0')out[1]=(char)parseInt(arg1);
else{
if(equalS(arg1,"aa",2))out[1]=1;
if(equalS(arg1,"ab",2))out[1]=2;
if(equalS(arg1,"ac",2))out[1]=3;
if(equalS(arg1,"ad",2))out[1]=4;
if(equalS(arg1,"ae",2))out[1]=5;
if(equalS(arg1,"af",2))out[1]=6;
if(equalS(arg1,"ag",2))out[1]=7;
if(equalS(arg1,"ah",2))out[1]=8;
if(equalS(arg1,"ai",2))out[1]=9;
if(equalS(arg1,"aj",2))out[1]=10;
if(equalS(arg1,"ak",2))out[1]=11;
if(equalS(arg1,"al",2))out[1]=12;
}
if(arg2[0]<='9'&&arg2[0]>='0')out[2]=(char)parseInt(arg2);
else{
if(equalS(arg2,"aa",2))out[2]=1;
if(equalS(arg2,"ab",2))out[2]=2;
if(equalS(arg2,"ac",2))out[2]=3;
if(equalS(arg2,"ad",2))out[2]=4;
if(equalS(arg2,"ae",2))out[2]=5;
if(equalS(arg2,"af",2))out[2]=6;
if(equalS(arg2,"ag",2))out[2]=7;
if(equalS(arg2,"ah",2))out[2]=8;
if(equalS(arg2,"ai",2))out[2]=9;
if(equalS(arg2,"aj",2))out[2]=10;
if(equalS(arg2,"ak",2))out[2]=11;
if(equalS(arg2,"al",2))out[2]=12;
}
out[3]='\e';
return out;
}
47 changes: 47 additions & 0 deletions src/Drivers/Keyboard.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#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);
22 changes: 22 additions & 0 deletions src/Drivers/idt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "idt.h"
#include<Util/types.h>
#define low_16(address) (uint16_t)((address) & 0xFFFF)
#define high_16(address) (uint16_t)(((address) >> 16) & 0xFFFF)

idt_gate_t idt[IDT_ENTRIES];
idt_register_t idt_reg;

void set_idt_gate(int n, uint32_t handler) {
idt[n].low_offset = low_16(handler);
idt[n].sel = KERNEL_CS;
idt[n].always0 = 0;
idt[n].flags = 0x8E;
idt[n].high_offset = high_16(handler);
}

void load_idt() {
idt_reg.base = (uint32_t) &idt;
idt_reg.limit = IDT_ENTRIES * sizeof(idt_gate_t) - 1;
/* Don't make the mistake of loading &idt -- always load &idt_reg */
asm volatile("lidt (%0)" : : "r" (&idt_reg));
}
Loading

0 comments on commit 1fb60e4

Please sign in to comment.