Stuff
This commit is contained in:
parent
aeecf185cf
commit
4413a3e98a
11
Makefile
11
Makefile
@ -4,9 +4,13 @@ OBJ = $(C_SOURCES:.c=.o $(shell cat psinfo/$(PLAT)/o.txt))
|
||||
CC = $(shell cat psinfo/$(PLAT)/cc.txt)
|
||||
GDB = $(shell cat psinfo/$(PLAT)/gdb.txt)
|
||||
CFLAGS = -Wall -g -ffreestanding
|
||||
QFLAGS = -m 2G -boot d -cdrom os.iso
|
||||
QFLAGS = -m 2G -boot d -cdrom os.iso -serial vc #-chardev socket,id=s1,port=3000,host=localhost -serial chardev:s1
|
||||
|
||||
all: os.iso
|
||||
|
||||
run: os.iso
|
||||
qemu-system-i386 $(QFLAGS) -monitor stdio
|
||||
|
||||
debug: os.iso kernel/kernel.elf
|
||||
qemu-system-i386 -s $(QFLAGS) &
|
||||
$(GDB) -ex "target remote localhost:1234" -ex "symbol-file kernel/kernel.elf"
|
||||
@ -36,5 +40,10 @@ h_files: cpu/$(PLAT)/memory.h
|
||||
rm -f cpu/memory.h
|
||||
cp cpu/$(PLAT)/memory.h cpu/memory.h
|
||||
|
||||
pipe:
|
||||
rm -f pipe.in pipe.out
|
||||
mkfifo pipe.in
|
||||
ln pipe.in pipe.out
|
||||
|
||||
clean:
|
||||
rm -rf $(OBJ) kernel/cstart.o cpu/memory.h os.iso */*.elf iso/boot/initrd.tar
|
||||
|
101
cpu/i386/isr.c
101
cpu/i386/isr.c
@ -2,11 +2,11 @@
|
||||
#include "idt.h"
|
||||
#include "ports.h"
|
||||
//#include "paging.h"
|
||||
#include "../../drivers/screen.h"
|
||||
//#include "../../drivers/serial.h"
|
||||
#include "../../libc/string.h"
|
||||
#include "../halt.h"
|
||||
#include "../../kernel/kernel.h"
|
||||
#include "../../kernel/klog.h"
|
||||
#include <stdint.h>
|
||||
void irq_handler(registers_t r);
|
||||
isr_t interrupt_handlers[256];
|
||||
@ -121,72 +121,51 @@ char *exception_messages[] = {
|
||||
};
|
||||
|
||||
void isr_handler(registers_t r) {
|
||||
if (r.int_no==80) {
|
||||
switch (r.eax) {
|
||||
default: {
|
||||
char num[10];
|
||||
int_to_ascii(r.eax, num);
|
||||
screen_write_string("PANIC: Invalid syscall no ");
|
||||
screen_write_string(num);
|
||||
screen_write_string("\n");
|
||||
asm volatile("hlt");
|
||||
}
|
||||
switch (r.int_no) {
|
||||
case 13:
|
||||
1;
|
||||
break;
|
||||
case 14: {
|
||||
uint32_t addr;
|
||||
asm("movl %%cr2,%0": "=r"(addr));
|
||||
if (r.err_code==0) {
|
||||
klog("PANIC","Kernel process tried to read a non-present page entry at address %x",addr);
|
||||
} else if (r.err_code==1) {
|
||||
klog("PANIC","Kernel process tried to read a page and caused a protection fault at address %x",addr);
|
||||
} else if (r.err_code==2) {
|
||||
klog("PANIC","Kernel process tried to write to a non-present page entry at address %x",addr);
|
||||
} else if (r.err_code==3) {
|
||||
klog("PANIC","Kernel process tried to write a page and caused a protection fault at address %x",addr);
|
||||
} else if (r.err_code==4) {
|
||||
klog("PANIC","User process tried to read a non-present page entry at address %x",addr);
|
||||
} else if (r.err_code==5) {
|
||||
klog("PANIC","User process tried to read a page and caused a protection fault at address %x",addr);
|
||||
} else if (r.err_code==6) {
|
||||
klog("PANIC","User process tried to write to a non-present page entry at address %x",addr);
|
||||
} else if (r.err_code==7) {
|
||||
klog("PANIC","User process tried to write a page and caused a protection fault at address %x",addr);
|
||||
}
|
||||
} else {
|
||||
// serial_write_string(1,"Received interrupt no ");
|
||||
// char s[3];
|
||||
// int_to_ascii(r.int_no, s);
|
||||
// serial_write_string(1,s);
|
||||
// serial_write_string(1,". (");
|
||||
// serial_write_string(1,exception_messages[r.int_no]);
|
||||
// serial_write_string(1,")\n");
|
||||
if (r.int_no==14) {
|
||||
uint32_t addr;
|
||||
asm("movl %%cr2,%0": "=r"(addr));
|
||||
// if (r.err_code==0) {
|
||||
// serial_write_string(1,"Kernel process tried to read a non-present page entry ");
|
||||
// } else if (r.err_code==1) {
|
||||
// serial_write_string(1,"Kernel process tried to read a page and caused a protection fault ");
|
||||
// } else if (r.err_code==2) {
|
||||
// serial_write_string(1,"Kernel process tried to write to a non-present page entry ");
|
||||
// } else if (r.err_code==3) {
|
||||
// serial_write_string(1,"Kernel process tried to write a page and caused a protection fault ");
|
||||
// } else if (r.err_code==4) {
|
||||
// serial_write_string(1,"User process tried to read a non-present page entry ");
|
||||
// } else if (r.err_code==5) {
|
||||
// serial_write_string(1,"User process tried to read a page and caused a protection fault ");
|
||||
// } else if (r.err_code==6) {
|
||||
// serial_write_string(1,"User process tried to write to a non-present page entry ");
|
||||
// } else if (r.err_code==7) {
|
||||
// serial_write_string(1,"User process tried to write a page and caused a protection fault ");
|
||||
// }
|
||||
// char str[20];
|
||||
// str[0]='\0';
|
||||
// hex_to_ascii(addr,str);
|
||||
// serial_write_string(1,"at address ");
|
||||
// serial_write_string(1,str);
|
||||
// serial_write_string(1,"\n");
|
||||
// write_string("PANIC: Page fault!");
|
||||
// if ((r.err_code&1)==0) {
|
||||
// int dir_entry=(addr&0xFFC00000)>>22;
|
||||
// int table_entry=(addr&0x3FF000)>12;
|
||||
// if (dir_entry_present(dir_entry)) {
|
||||
// set_table_entry(dir_entry,table_entry,((dir_entry*1024)+table_entry)*0x1000,1,1,1);
|
||||
// for(int page=0;page<1024;page++) {
|
||||
// asm volatile("invlpg (%0)"::"r"(((dir_entry*1024)+page)*0x1000):"memory");
|
||||
// }
|
||||
// } else {
|
||||
// for(int page=0;page<1024;page++) {
|
||||
// set_table_entry(dir_entry,page,0x0,1,1,0);
|
||||
// }
|
||||
// set_table_entry(dir_entry,table_entry,((dir_entry*1024)+table_entry)*0x1000,1,1,1);
|
||||
// set_directory_entry(dir_entry,dir_entry,1,1,1);
|
||||
if ((r.err_code&1)==0) {
|
||||
// int dir_entry=(addr&0xFFC00000)>>22;
|
||||
// int table_entry=(addr&0x3FF000)>12;
|
||||
// if (dir_entry_present(dir_entry)) {
|
||||
// set_table_entry(dir_entry,table_entry,((dir_entry*1024)+table_entry)*0x1000,1,1,1);
|
||||
// for(int page=0;page<1024;page++) {
|
||||
// asm volatile("invlpg (%0)"::"r"(((dir_entry*1024)+page)*0x1000):"memory");
|
||||
// }
|
||||
// return;
|
||||
// } else {
|
||||
// for(int page=0;page<1024;page++) {
|
||||
// set_table_entry(dir_entry,page,0x0,1,1,0);
|
||||
// }
|
||||
// set_table_entry(dir_entry,table_entry,((dir_entry*1024)+table_entry)*0x1000,1,1,1);
|
||||
// set_directory_entry(dir_entry,dir_entry,1,1,1);
|
||||
// }
|
||||
// return;
|
||||
}
|
||||
halt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
49
drivers/i386/network.c
Normal file
49
drivers/i386/network.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include "pci.h"
|
||||
#include "../../cpu/i386/ports.h"
|
||||
#include "../../cpu/i386/paging.h"
|
||||
#include "../../libc/string.h"
|
||||
#include "../../libc/stdlib.h"
|
||||
void network_init(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info) {
|
||||
// info->command=info->command|0x4;
|
||||
// pci_set_dev_info(bus,device,func,info);
|
||||
// free(info);
|
||||
// info=pci_get_dev_info(bus,device,func);
|
||||
// if ((info->command&0x4)==0) {
|
||||
// klog("ERROR","Could not set network card to be PCI bus master, aborting");
|
||||
// return;
|
||||
// }
|
||||
// uint32_t io_base=0;
|
||||
// uint32_t bar0=pci_read_config(bus,device,func,0x10);
|
||||
// if ((bar0&0x1)==1) {
|
||||
// io_base=bar0&0xFFFFFFFB;
|
||||
// }
|
||||
// if (io_base==0) {
|
||||
// klog("ERROR","Could not get IO base of network card, aborting");
|
||||
// return;
|
||||
// } else {
|
||||
// // klog("INFO","Network card IO base:%x",io_base);
|
||||
// }
|
||||
// port_byte_out(io_base+0x52,0x0);
|
||||
// // klog("INFO","Network card on");
|
||||
// // klog("INFO","Resetting network card");
|
||||
// port_byte_out(io_base+0x37,0x10);
|
||||
// while ((port_byte_in(io_base+0x37)&0x10)!=0);
|
||||
// // klog("INFO","Reset network card");
|
||||
// // void* rx_buf=malloc(sizeof(char)*9,708);
|
||||
// // void* phys=virt_to_phys(rx_buf);
|
||||
// // port_long_out(io_base+0x30,phys);
|
||||
// // klog("INFO","Setup network card recive buffer");
|
||||
// port_word_out(io_base+0x3C,0x0);
|
||||
// // klog("INFO","Setup network card interrupts");
|
||||
// port_long_out(io_base+0x44,0x2);
|
||||
// // klog("INFO","Setup network card packet filter");
|
||||
// port_byte_out(io_base+0x37,0x04);
|
||||
// // klog("INFO","Network card RX and TX enabled");
|
||||
// char* msg="";
|
||||
// char* message=malloc(sizeof(char)*(strlen(msg)+1));
|
||||
// strcpy(message,msg);
|
||||
// void* phys=virt_to_phys(message);
|
||||
// port_long_out(io_base+0x20,phys);
|
||||
// port_long_out(io_base+0x10,(strlen(msg)+1));
|
||||
// klog("INFO","Sent test message");
|
||||
}
|
6
drivers/i386/network.h
Normal file
6
drivers/i386/network.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
void network_init(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info);
|
||||
|
||||
#endif
|
@ -1,9 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include "../../cpu/i386/ports.h"
|
||||
#include "../../kernel/klog.h"
|
||||
#include "../pci.h"
|
||||
#include "pci.h"
|
||||
#include "../../libc/stdlib.h"
|
||||
#include "network.h"
|
||||
|
||||
pci_dev_common_info** pci_devs;
|
||||
uint32_t pci_max_devs;
|
||||
@ -21,6 +21,17 @@ uint32_t pci_read_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset)
|
||||
return data;
|
||||
}
|
||||
|
||||
void pci_write_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset,uint32_t data) {
|
||||
uint32_t address;
|
||||
uint32_t lbus=(uint32_t)bus;
|
||||
uint32_t ldev=(uint32_t)device;
|
||||
uint32_t lfunc=(uint32_t)func;
|
||||
uint16_t tmp=0;
|
||||
address=(uint32_t)((lbus << 16)|(ldev << 11)|(lfunc<<8)|(offset&0xfc)|((uint32_t)0x80000000));
|
||||
port_long_out(PCI_CONFIG_ADDRESS,address);
|
||||
port_long_out(PCI_CONFIG_DATA,data);
|
||||
}
|
||||
|
||||
pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) {
|
||||
uint32_t* info=malloc(sizeof(uint32_t)*4);
|
||||
info[0]=pci_read_config(bus,device,func,0);
|
||||
@ -30,25 +41,33 @@ pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) {
|
||||
return (pci_dev_common_info*)info;
|
||||
}
|
||||
|
||||
void pci_checkFunction(pci_dev_common_info* info);
|
||||
void pci_set_dev_info(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* inf) {
|
||||
uint32_t* info=(uint32_t*)inf;
|
||||
pci_write_config(bus,device,func,0,info[0]);
|
||||
pci_write_config(bus,device,func,4,info[1]);
|
||||
pci_write_config(bus,device,func,8,info[2]);
|
||||
pci_write_config(bus,device,func,0xC,info[3]);
|
||||
}
|
||||
|
||||
void pci_checkFunction(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info);
|
||||
|
||||
void pci_checkDevice(uint8_t bus, uint8_t device) {
|
||||
pci_dev_common_info* info=pci_get_dev_info(bus,device,0);
|
||||
if(info->vend_id==0xFFFF||info->class_code==0xFF) {
|
||||
return;
|
||||
}
|
||||
pci_checkFunction(info);
|
||||
pci_checkFunction(bus,device,0,info);
|
||||
if((info->header_type&0x80)!=0) {
|
||||
for(uint8_t function=1;function<8;function++) {
|
||||
pci_dev_common_info* info=pci_get_dev_info(bus,device,function);
|
||||
if(info->vend_id!=0xFFFF&&info->class_code!=0xFF) {
|
||||
pci_checkFunction(info);
|
||||
pci_checkFunction(bus,device,function,info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pci_checkFunction(pci_dev_common_info* info) {
|
||||
void pci_checkFunction(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* info) {
|
||||
if (pci_num_devs==pci_max_devs) {
|
||||
pci_max_devs+=32;
|
||||
pci_devs=malloc(sizeof(pci_dev_common_info)*pci_max_devs);
|
||||
@ -56,6 +75,15 @@ void pci_checkFunction(pci_dev_common_info* info) {
|
||||
klog("INFO","Found PCI device. Class code:%x, Subclass:%x Prog IF:%x",info->class_code,info->subclass,info->prog_if);
|
||||
pci_devs[pci_num_devs]=info;
|
||||
pci_num_devs++;
|
||||
if (info->class_code==0x2&&info->subclass==0x0) {
|
||||
klog("INFO","Found network controller, detecting type");
|
||||
if (info->vend_id==0x10ec&&info->dev_id==0x8139) {
|
||||
klog("INFO","Found RTL8139, starting driver");
|
||||
network_init(bus,device,func,info);
|
||||
} else {
|
||||
klog("INFO","Unknown network card");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pci_init() {
|
||||
|
@ -2,9 +2,11 @@
|
||||
#define PCI_INTERN_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "../pci.h"
|
||||
#define PCI_CONFIG_ADDRESS 0xCF8
|
||||
#define PCI_CONFIG_DATA 0xCFC
|
||||
|
||||
uint16_t pci_read_config_word(uint8_t bus,uint8_t slot,uint8_t func,uint8_t reg);
|
||||
uint32_t pci_read_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset);
|
||||
void pci_set_dev_info(uint8_t bus,uint8_t device,uint8_t func,pci_dev_common_info* inf);
|
||||
|
||||
#endif
|
||||
|
@ -52,7 +52,7 @@ static void keyboard_callback(registers_t regs) {
|
||||
} else if (scancode==LSHIFTUP || scancode==RSHIFTUP) {
|
||||
shift=0;
|
||||
} else if (scancode==ENTER) {
|
||||
screen_write_string("\n");
|
||||
putc('\n');
|
||||
got_key('\n');
|
||||
} else if (scancode<=58) {
|
||||
char letter;
|
||||
@ -64,8 +64,7 @@ static void keyboard_callback(registers_t regs) {
|
||||
letter=sc_ascii[(int)scancode];
|
||||
}
|
||||
char str[2]={letter,'\0'};
|
||||
screen_write_string(str);
|
||||
got_key(letter);
|
||||
putc(letter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,9 +83,9 @@ void screen_clear() {
|
||||
}
|
||||
|
||||
void screen_set_cursor_offset(int offset) {
|
||||
offset/=2;
|
||||
port_byte_out(SCREEN_CTRL,14);
|
||||
port_byte_out(SCREEN_DATA,(unsigned char)(offset>>8));
|
||||
port_byte_out(SCREEN_CTRL,15);
|
||||
port_byte_out(SCREEN_DATA,(unsigned char)(offset&0xff));
|
||||
// offset/=2;
|
||||
// port_byte_out(SCREEN_CTRL,14);
|
||||
// port_byte_out(SCREEN_DATA,(unsigned char)(offset>>8));
|
||||
// port_byte_out(SCREEN_CTRL,15);
|
||||
// port_byte_out(SCREEN_DATA,(unsigned char)(offset&0xff));
|
||||
}
|
||||
|
@ -115,12 +115,7 @@ int serial_dev_drv(char* filename,int c,long pos,char wr) {
|
||||
}
|
||||
if (wr) {
|
||||
while (!serial_is_transmit_fifo_empty(com)) continue;
|
||||
if (c=='\n') {
|
||||
port_byte_out(serial_data_port(com),'\r');
|
||||
port_byte_out(serial_data_port(com),'\n');
|
||||
} else {
|
||||
port_byte_out(serial_data_port(com),c);
|
||||
}
|
||||
port_byte_out(serial_data_port(com),c);
|
||||
return 0;
|
||||
} else {
|
||||
return devbuf_get(bufs[com]);
|
||||
|
@ -4,8 +4,8 @@
|
||||
typedef struct {
|
||||
uint16_t vend_id;
|
||||
uint16_t dev_id;
|
||||
uint16_t status;
|
||||
uint16_t command;
|
||||
uint16_t status;
|
||||
uint8_t rev_id;
|
||||
uint8_t prog_if;
|
||||
uint8_t subclass;
|
||||
|
BIN
iso/boot/initrd
BIN
iso/boot/initrd
Binary file not shown.
@ -123,6 +123,4 @@ _start:
|
||||
|
||||
# Infinite loop if the system has nothing more to do.
|
||||
no_multiboot:
|
||||
cli
|
||||
1: hlt
|
||||
jmp 1b
|
||||
loop: jmp loop
|
||||
|
195
kernel/kernel.c
195
kernel/kernel.c
@ -21,6 +21,7 @@
|
||||
#include "kernel.h"
|
||||
#include "vfs.h"
|
||||
#include "klog.h"
|
||||
#include "pppp.h"
|
||||
#include "elf.h"
|
||||
|
||||
#include <stdint.h>
|
||||
@ -35,26 +36,27 @@ uint32_t initrd_sz;
|
||||
devbuf* kbd_buf;
|
||||
|
||||
void switch_to_user_mode() {
|
||||
asm volatile(" \
|
||||
cli; \
|
||||
mov $0x23, %ax; \
|
||||
mov %ax, %ds; \
|
||||
mov %ax, %es; \
|
||||
mov %ax, %fs; \
|
||||
mov %ax, %gs; \
|
||||
\
|
||||
mov %esp, %eax; \
|
||||
pushl $0x23; \
|
||||
pushl %eax; \
|
||||
pushf; \
|
||||
pop %eax; \
|
||||
or $0x200,%eax; \
|
||||
push %eax; \
|
||||
pushl $0x1B; \
|
||||
push $1f; \
|
||||
iret; \
|
||||
1: \
|
||||
");
|
||||
// Set up a stack structure for switching to user mode.
|
||||
asm volatile(" \
|
||||
cli; \
|
||||
mov $0x23, %ax; \
|
||||
mov %ax, %ds; \
|
||||
mov %ax, %es; \
|
||||
mov %ax, %fs; \
|
||||
mov %ax, %gs; \
|
||||
\
|
||||
mov %esp, %eax; \
|
||||
pushl $0x23; \
|
||||
pushl %eax; \
|
||||
pushf; \
|
||||
pop %eax; \
|
||||
or $0x200,%eax; \
|
||||
push %eax; \
|
||||
pushl $0x1B; \
|
||||
push $1f; \
|
||||
iret; \
|
||||
1: \
|
||||
");
|
||||
}
|
||||
|
||||
void get_memory(multiboot_info_t* mbd) {
|
||||
@ -194,156 +196,11 @@ void main(multiboot_info_t* mbd) {
|
||||
// klog("INFO","Waiting for 1 second");
|
||||
// wait(1000);
|
||||
pci_init();
|
||||
//pppp_init();
|
||||
tasking_init();
|
||||
// uint32_t pid=fork();
|
||||
// if (pid==0) {
|
||||
// while (1) {
|
||||
// printf("Child\n");
|
||||
// yield();
|
||||
// }
|
||||
// } else {
|
||||
// while (1) {
|
||||
// printf("Parent. Child PID:%d\n",pid);
|
||||
// yield();
|
||||
// }
|
||||
// }
|
||||
printf(">");
|
||||
while (1) {
|
||||
char str[256];
|
||||
fgets(str,256,stdin);
|
||||
str[strlen(str)-1]='\0';
|
||||
char* cmd=strtok(str," ");
|
||||
if (strcmp(cmd,"cat")==0) {
|
||||
char* file=strtok(NULL," ");
|
||||
FILE* fd=fopen(file,"r");
|
||||
if (fd!=NULL) {
|
||||
for (char c=fgetc(fd);c!=EOF;c=fgetc(fd)) {
|
||||
putc(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcmp(cmd,"mount")==0) {
|
||||
char* dev=strtok(NULL," ");
|
||||
char* mntpnt=strtok(NULL," ");
|
||||
char* type=strtok(NULL," ");
|
||||
mount(mntpnt,dev,type);
|
||||
free(mntpnt);
|
||||
free(dev);
|
||||
free(type);
|
||||
}
|
||||
if (strcmp(cmd,"pci")==0) {
|
||||
char* subcmd=strtok(NULL," ");
|
||||
if (strcmp(subcmd,"list")==0) {
|
||||
for (int i=0;i<pci_num_devs;i++) {
|
||||
pci_dev_common_info* info=pci_devs[i];
|
||||
printf("PCI device %d:\n Main class:",i);
|
||||
switch (info->class_code) {
|
||||
case PCI_CLASS_UNCLASSIFIED:
|
||||
printf("Unclassified\n");
|
||||
break;
|
||||
case PCI_CLASS_STORAGE:
|
||||
printf("Storage\n");
|
||||
break;
|
||||
case PCI_CLASS_NETWORK:
|
||||
printf("Network\n");
|
||||
break;
|
||||
case PCI_CLASS_DISPLAY:
|
||||
printf("Display\n");
|
||||
break;
|
||||
case PCI_CLASS_MULTIMEDIA:
|
||||
printf("Multimedia\n");
|
||||
break;
|
||||
case PCI_CLASS_MEMORY:
|
||||
printf("Memory\n");
|
||||
break;
|
||||
case PCI_CLASS_BRIDGE:
|
||||
printf("Bridge\n");
|
||||
break;
|
||||
case PCI_CLASS_SIMPCOM:
|
||||
printf("Simpcom\n");
|
||||
break;
|
||||
case PCI_CLASS_BASEPERIPH:
|
||||
printf("Baseperiph\n");
|
||||
break;
|
||||
case PCI_CLASS_INPDEV:
|
||||
printf("Inpdev\n");
|
||||
break;
|
||||
case PCI_CLASS_DOCK:
|
||||
printf("Dock\n");
|
||||
break;
|
||||
case PCI_CLASS_CPU:
|
||||
printf("Cpu\n");
|
||||
break;
|
||||
case PCI_CLASS_SERBUS:
|
||||
printf("Serbus\n");
|
||||
break;
|
||||
case PCI_CLASS_WIRELESS:
|
||||
printf("Wireless\n");
|
||||
break;
|
||||
case PCI_CLASS_INTELLIGENT:
|
||||
printf("Intelligent\n");
|
||||
break;
|
||||
case PCI_CLASS_SATELLITE:
|
||||
printf("Satellite\n");
|
||||
break;
|
||||
case PCI_CLASS_ENCRYPTION:
|
||||
printf("Encryption\n");
|
||||
break;
|
||||
case PCI_CLASS_SIGPROCESS:
|
||||
printf("Sigprocess\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (strcmp(subcmd,"cfgdmp")==0) {
|
||||
char* devnumstr=strtok(NULL," ");
|
||||
devnumstr=strrev(devnumstr);
|
||||
uint32_t devnum=0;
|
||||
uint32_t x=1;
|
||||
for (int i=0;i<strlen(devnumstr);i++) {
|
||||
devnum+=(devnumstr[i]-0x30)*x;
|
||||
x=x*10;
|
||||
}
|
||||
free(devnumstr);
|
||||
uint8_t* info=(uint8_t*)pci_devs[devnum];
|
||||
for (int i=0;i<16;i++) {
|
||||
printf("%x ",info[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
free(subcmd);
|
||||
}
|
||||
if (strcmp(cmd,"rdelf")==0) {
|
||||
FILE* file=fopen(strtok(NULL," "),"r");
|
||||
elf_header* header=malloc(sizeof(elf_header));
|
||||
fread(header,sizeof(elf_header),1,file);
|
||||
fseek(file,header->prog_hdr,SEEK_SET);
|
||||
elf_pheader** p_ents=malloc(sizeof(elf_pheader*)*header->pheader_ent_nm);
|
||||
for (int i=0;i<header->pheader_ent_nm;i++) {
|
||||
p_ents[i]=malloc(sizeof(elf_pheader));
|
||||
fread(p_ents[i],sizeof(elf_pheader),1,file);
|
||||
}
|
||||
for (int i=0;i<header->pheader_ent_nm;i++) {
|
||||
if (p_ents[i]->type!=1) {
|
||||
continue;
|
||||
}
|
||||
printf("Copy %d bytes starting at %x in the file to the virtual address %x\n",p_ents[i]->filesz,p_ents[i]->offset,p_ents[i]->vaddr);
|
||||
char* mem=alloc_memory(1);
|
||||
for (size_t j=0;j<p_ents[i]->memsz;j++) {
|
||||
mem[i]=0;
|
||||
}
|
||||
fseek(file,p_ents[i]->offset,SEEK_SET);
|
||||
fread(mem,1,p_ents[i]->filesz,file);
|
||||
alloc_pages(p_ents[i]->vaddr,virt_to_phys(mem),1,1,1,page_directory,page_tables);
|
||||
int (*start)()=header->entry;
|
||||
int ret=start();
|
||||
printf("Return val:%d",ret);
|
||||
}
|
||||
}
|
||||
free(cmd);
|
||||
printf(">");
|
||||
}
|
||||
switch_to_user_mode();
|
||||
//port_byte_out(0,0);
|
||||
switch_to_user_mode();
|
||||
printf("U");
|
||||
for(;;);
|
||||
}
|
||||
|
||||
|
172
kernel/pppp.c
Normal file
172
kernel/pppp.c
Normal file
@ -0,0 +1,172 @@
|
||||
#include "../libc/stdio.h"
|
||||
#include "../libc/stdlib.h"
|
||||
#include "../libc/string.h"
|
||||
#include "klog.h"
|
||||
#include <stdint.h>
|
||||
#include "pppp.h"
|
||||
FILE* ser0;
|
||||
|
||||
|
||||
#define NTP_OFFSET 2208988800
|
||||
#define SECS_YEAR 31556952
|
||||
#define SECS_MONTH 2629746
|
||||
#define SECS_DAY 86400
|
||||
#define SECS_HOUR 3600
|
||||
#define SECS_MIN 60
|
||||
|
||||
void send_16(uint16_t num) {
|
||||
fputc(num&0xFF,ser0);
|
||||
fputc((num&0xFF00)>>8,ser0);
|
||||
}
|
||||
|
||||
void send_32(uint32_t num) {
|
||||
fputc(num&0xFF,ser0);
|
||||
fputc((num&0xFF00)>>8,ser0);
|
||||
fputc((num&0xFF0000)>>16,ser0);
|
||||
fputc((num&0xFF000000)>>24,ser0);
|
||||
}
|
||||
|
||||
void read_32() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
void pppp_init() {
|
||||
ser0=fopen("/dev/ttyS0","r+");
|
||||
if (ser0==NULL) {
|
||||
klog("ERROR","No serial port, cannot initialize PPPP driver");
|
||||
}
|
||||
uint8_t ip[4];
|
||||
fputc(0,ser0);
|
||||
fread(&ip,sizeof(uint8_t),4,ser0);
|
||||
klog("INFO","PPPP IP:%d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]);
|
||||
uint32_t sock_id=udp_new();
|
||||
char* url="example.com";
|
||||
char* labels[4];
|
||||
for (int i=0;i<4;i++) {
|
||||
labels[i]=malloc(strlen(url)+1);
|
||||
labels[i][0]='\0';
|
||||
}
|
||||
int i=0;
|
||||
int label_offset=0;
|
||||
for (int j=0;j<strlen(url);j++) {
|
||||
char ch=url[j];
|
||||
if (ch=='.') {
|
||||
i++;
|
||||
label_offset=0;
|
||||
} else {
|
||||
labels[i][label_offset]=ch;
|
||||
label_offset++;
|
||||
}
|
||||
}
|
||||
char* header="\xaa\xaa\x01\0\0\x01\0\0\0\0\0\0";
|
||||
char* footer="\0\0\x01\0\x01";
|
||||
fputc(4,ser0);
|
||||
send_32(sock_id);
|
||||
fputc(8,ser0);
|
||||
fputc(8,ser0);
|
||||
fputc(8,ser0);
|
||||
fputc(8,ser0);
|
||||
send_16(53);
|
||||
send_16(12+strlen(url)+1+5);
|
||||
for(uint16_t i=0;i<12;i++) {
|
||||
fputc(header[i],ser0);
|
||||
}
|
||||
for (int i=0;i<4;i++) {
|
||||
if (labels[i][0]=='\0') {
|
||||
continue;
|
||||
}
|
||||
fputc(strlen(labels[i]),ser0);
|
||||
fputs(labels[i],ser0);
|
||||
}
|
||||
for(uint16_t i=0;i<5;i++) {
|
||||
fputc(footer[i],ser0);
|
||||
}
|
||||
uint32_t length;
|
||||
char* packet=udp_recv(sock_id,&length);
|
||||
ip[3]=packet[length-1];
|
||||
ip[2]=packet[length-2];
|
||||
ip[1]=packet[length-3];
|
||||
ip[0]=packet[length-4];
|
||||
printf("IP of %s is %d.%d.%d.%d\n",url,ip[0],ip[1],ip[2],ip[3]);
|
||||
uint16_t http_sock=tcp_new(ip,80);
|
||||
char* msg="GET / HTTP/1.1\r\nHost: www.example.com\r\n\r\n";
|
||||
tcp_send(http_sock,strlen(msg),msg);
|
||||
int in_headers=1;
|
||||
char* line;
|
||||
while (1) {
|
||||
printf("GET");
|
||||
line=tcp_recv(http_sock,&length);
|
||||
if (!line) {
|
||||
printf("DONE\n");
|
||||
break;
|
||||
}
|
||||
printf("LINE",line);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t udp_new() {
|
||||
fputc(1,ser0);
|
||||
uint32_t info[2];
|
||||
fread(&info,sizeof(uint32_t),2,ser0);
|
||||
return info[0];
|
||||
}
|
||||
|
||||
void udp_send(uint32_t sock_id,char* ip,uint16_t port,uint16_t len,void* datav) {
|
||||
char* data=(char*)datav;
|
||||
fputc(4,ser0);
|
||||
send_32(sock_id);
|
||||
fputc(ip[0],ser0);
|
||||
fputc(ip[1],ser0);
|
||||
fputc(ip[2],ser0);
|
||||
fputc(ip[3],ser0);
|
||||
send_16(port);
|
||||
send_16(len);
|
||||
for(uint16_t i=0;i<len;i++) {
|
||||
fputc(data[i],ser0);
|
||||
}
|
||||
}
|
||||
|
||||
void* udp_recv(uint32_t sock_id,uint32_t* len) {
|
||||
fputc(5,ser0);
|
||||
send_32(sock_id);
|
||||
fread(len,sizeof(uint32_t),1,ser0);
|
||||
void* data=malloc(*len);
|
||||
fread(data,*len,1,ser0);
|
||||
return data;
|
||||
}
|
||||
|
||||
uint32_t tcp_new(char* ip,uint16_t port) {
|
||||
fputc(7,ser0);
|
||||
fputc(ip[0],ser0);
|
||||
fputc(ip[1],ser0);
|
||||
fputc(ip[2],ser0);
|
||||
fputc(ip[3],ser0);
|
||||
send_16(port);
|
||||
uint32_t id;
|
||||
fread(&id,sizeof(uint32_t),1,ser0);
|
||||
return id;
|
||||
}
|
||||
|
||||
void tcp_send(uint32_t sock_id,uint16_t len,void* datav) {
|
||||
char* data=(char*)datav;
|
||||
fputc(8,ser0);
|
||||
send_32(sock_id);
|
||||
send_16(len);
|
||||
for(uint16_t i=0;i<len;i++) {
|
||||
fputc(data[i],ser0);
|
||||
}
|
||||
}
|
||||
|
||||
void* tcp_recv(uint32_t sock_id,uint32_t* len) {
|
||||
fputc(9,ser0);
|
||||
send_32(sock_id);
|
||||
fread(len,sizeof(uint32_t),1,ser0);
|
||||
if (len==0) {
|
||||
return NULL;
|
||||
}
|
||||
void* data=malloc(*len);
|
||||
// printf("Reading %d bytes\n",*len);
|
||||
fread(data,*len,1,ser0);
|
||||
return data;
|
||||
}
|
13
kernel/pppp.h
Normal file
13
kernel/pppp.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef PPP_H
|
||||
#define PPP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void pppp_init();
|
||||
uint32_t udp_new();
|
||||
void udp_send(uint32_t sock_id,char* ip,uint16_t port,uint16_t len,void* datav);
|
||||
void* udp_recv(uint32_t sock_id,uint32_t* len);
|
||||
uint32_t tcp_new(char* ip,uint16_t port);
|
||||
void tcp_send(uint32_t sock_id,uint16_t len,void* datav);
|
||||
void* tcp_recv(uint32_t sock_id,uint32_t* len);
|
||||
#endif
|
33
log
Normal file
33
log
Normal file
@ -0,0 +1,33 @@
|
||||
[INFO] First PS/2 port OK
|
||||
[INFO] Keyboard on PS/2 port 1
|
||||
[INFO] Registered keyboard driver on PS/2 port 1
|
||||
[INFO] Finished initializing PS/2 driver
|
||||
[INFO] Scanning for serial ports
|
||||
[INFO] Found COM1
|
||||
[INFO] Found COM2
|
||||
[INFO] Scanning for parallel ports
|
||||
[INFO] Found LPT1
|
||||
[INFO] Found PCI device. Class code:0x6, Subclass:0x0 Prog IF:0x0
|
||||
[INFO] Found PCI device. Class code:0x6, Subclass:0x1 Prog IF:0x0
|
||||
[INFO] Found PCI device. Class code:0x1, Subclass:0x1 Prog IF:0x80
|
||||
[INFO] Found PCI device. Class code:0x6, Subclass:0x80 Prog IF:0x0
|
||||
[INFO] Found PCI device. Class code:0x3, Subclass:0x0 Prog IF:0x0
|
||||
[INFO] Found PCI device. Class code:0x2, Subclass:0x0 Prog IF:0x0
|
||||
[INFO] Found network controller, detecting type
|
||||
[INFO] Unknown network card
|
||||
>pci list (Shows PCI devices and types)
|
||||
PCI device 0:
|
||||
Main class:Bridge
|
||||
PCI device 1:
|
||||
Main class:Bridge
|
||||
PCI device 2:
|
||||
Main class:Storage
|
||||
PCI device 3:
|
||||
Main class:Bridge
|
||||
PCI device 4:
|
||||
Main class:Display
|
||||
PCI device 5:
|
||||
Main class:Network
|
||||
>cat /hi.txt (Outputs contents of file)
|
||||
Hello!
|
||||
This is hi.txt!
|
65
network.rb
Normal file
65
network.rb
Normal file
@ -0,0 +1,65 @@
|
||||
require "socket"
|
||||
s=TCPServer.new("localhost",3000)
|
||||
c=s.accept
|
||||
udpsocks=[]
|
||||
tcpsocks=[]
|
||||
next_sock=0
|
||||
puts "Connection established"
|
||||
while true
|
||||
ch=c.getc
|
||||
if ch==nil
|
||||
next
|
||||
end
|
||||
cmd=ch.ord
|
||||
if cmd==0
|
||||
c.print [192,168,0,10].pack("CCCC")
|
||||
end
|
||||
if cmd==1
|
||||
sock=UDPSocket.new()
|
||||
sock.bind("10.0.0.180",0)
|
||||
c.print [next_sock,sock.addr[1]].pack("L<L<")
|
||||
udpsocks[next_sock]=sock
|
||||
next_sock+=1;
|
||||
end
|
||||
if cmd==4
|
||||
info=c.read(12).unpack("L<CCCCS<S<")
|
||||
msg=c.read(info[6])
|
||||
udpsocks[info[0]].send(msg,0,"#{info[1]}.#{info[2]}.#{info[3]}.#{info[4]}",info[5])
|
||||
end
|
||||
if cmd==5
|
||||
id=c.read(4).unpack("L<")[0]
|
||||
msg=udpsocks[id].recv(65536)
|
||||
if msg==""
|
||||
c.print [0].pack("L<")
|
||||
else
|
||||
c.print [msg.length].pack("L<")
|
||||
c.print msg
|
||||
end
|
||||
end
|
||||
if cmd==6
|
||||
id=c.read(4).unpack("L<")[0]
|
||||
udpsocks[id]=nil
|
||||
end
|
||||
if cmd==7
|
||||
info=c.read(6).unpack("CCCCS<")
|
||||
sock=TCPSocket.new("#{info[0]}.#{info[1]}.#{info[2]}.#{info[3]}",info[4])
|
||||
c.print [next_sock].pack("L<")
|
||||
tcpsocks[next_sock]=sock
|
||||
next_sock+=1;
|
||||
end
|
||||
if cmd==8
|
||||
info=c.read(6).unpack("L<S<")
|
||||
msg=c.read(info[1])
|
||||
tcpsocks[info[0]].print msg
|
||||
end
|
||||
if cmd==9
|
||||
id=c.read(4).unpack("L<")[0]
|
||||
if !tcpsocks[id].ready? and tcpsocks[id].closed?
|
||||
c.print [0].pack("L<")
|
||||
else
|
||||
msg=tcpsocks[id].gets
|
||||
c.print [msg.length].pack("L<")
|
||||
c.print msg
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user