Remove unnecessary uints
This commit is contained in:
parent
ec6deb9aa8
commit
a2756266f0
@ -1,5 +1,4 @@
|
||||
#include <dbg.h>
|
||||
#include <grub/text_fb_info.h>
|
||||
#include <ipc/devfs.h>
|
||||
#include <ipc/vfs.h>
|
||||
#include <mailboxes.h>
|
||||
|
21
init/main.c
21
init/main.c
@ -1,6 +1,5 @@
|
||||
#include <dbg.h>
|
||||
#include <elf.h>
|
||||
#include <grub/text_fb_info.h>
|
||||
#include <initrd.h>
|
||||
#include <ipc/vfs.h>
|
||||
#include <memory.h>
|
||||
@ -22,18 +21,18 @@ typedef struct {
|
||||
char typeflag[1];
|
||||
} tar_header;
|
||||
|
||||
uint32_t getsize(const char *in) {
|
||||
uint32_t size=0;
|
||||
uint32_t j;
|
||||
uint32_t count=1;
|
||||
size_t getsize(const char *in) {
|
||||
size_t size=0;
|
||||
size_t j;
|
||||
size_t count=1;
|
||||
for (j=11;j>0;j--,count*=8) {
|
||||
size+=((in[j-1]-'0')*count);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t find_loc(char* name,char* initrd) {
|
||||
uint32_t pos=0;
|
||||
size_t find_loc(char* name,char* initrd) {
|
||||
size_t pos=0;
|
||||
tar_header tar_hdr;
|
||||
for (int i=0;;i++) {
|
||||
char* tar_hdr_ptr=(char*)&tar_hdr;
|
||||
@ -41,7 +40,7 @@ uint32_t find_loc(char* name,char* initrd) {
|
||||
tar_hdr_ptr[i]=initrd[pos+i];
|
||||
}
|
||||
if (tar_hdr.filename[0]=='\0') break;
|
||||
uint32_t size=getsize(tar_hdr.size);
|
||||
size_t size=getsize(tar_hdr.size);
|
||||
pos+=512;
|
||||
if (strcmp(tar_hdr.filename,name)==0) {
|
||||
return pos;
|
||||
@ -55,7 +54,7 @@ uint32_t find_loc(char* name,char* initrd) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char load_proc(uint32_t datapos,char* initrd) {
|
||||
char load_proc(size_t datapos,char* initrd) {
|
||||
int pos=0;
|
||||
elf_header header;
|
||||
pos=datapos;
|
||||
@ -97,7 +96,7 @@ char load_proc(uint32_t datapos,char* initrd) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// char load_proc_devfs(uint32_t datapos) {
|
||||
// char load_proc_devfs(size_t datapos) {
|
||||
// serial_print("load_proc_devfs\n");
|
||||
// FILE* initrd=fopen("/dev/initrd","r");
|
||||
// elf_header header;
|
||||
@ -151,7 +150,7 @@ int main() {
|
||||
// char* initrd=malloc(size);
|
||||
// initrd_get(initrd);
|
||||
// exit(0);
|
||||
// uint32_t datapos=find_loc("vfs",initrd);
|
||||
// size_t datapos=find_loc("vfs",initrd);
|
||||
// load_proc(datapos,initrd);
|
||||
// yield(); // Bochs fails here
|
||||
// rescan_vfs();
|
||||
|
@ -1,5 +1,4 @@
|
||||
#include <dbg.h>
|
||||
#include <grub/text_fb_info.h>
|
||||
#include <initrd.h>
|
||||
#include <ipc/devfs.h>
|
||||
#include <ipc/vfs.h>
|
||||
@ -58,14 +57,14 @@ char* initrd_gets(vfs_message* vfs_msg) {
|
||||
}
|
||||
char* data=malloc(sizeof(char)*vfs_msg->data);
|
||||
for (long i=0;i<vfs_msg->data;i++) {
|
||||
data[i]=(uint8_t)initrd[i+vfs_msg->pos];
|
||||
data[i]=(char)initrd[i+vfs_msg->pos];
|
||||
// if (i<sizeof(vfs_message)) {
|
||||
// serial_print("data[");
|
||||
// char str[256];
|
||||
// int_to_ascii(i,str);
|
||||
// serial_print(str);
|
||||
// serial_print("]=");
|
||||
// hex_to_ascii((uint8_t)data[i],str);
|
||||
// hex_to_ascii((char)data[i],str);
|
||||
// serial_print(str);
|
||||
// serial_print("\n");
|
||||
// }
|
||||
|
@ -1,7 +1,8 @@
|
||||
#include "cpu/paging.h"
|
||||
#include "cpu/arch_consts.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
|
||||
void address_spaces_copy_data(void* cr3, void* data,size_t size,void* virt_addr) {
|
||||
void* old_cr3=get_cr3();
|
||||
void* phys_addr=virt_to_phys(data);
|
||||
load_address_space(cr3);
|
||||
@ -9,7 +10,7 @@ void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_add
|
||||
load_address_space(old_cr3);
|
||||
}
|
||||
|
||||
void* address_spaces_put_data(void* cr3, void* data,uint32_t size) {
|
||||
void* address_spaces_put_data(void* cr3, void* data,size_t size) {
|
||||
void* old_cr3=get_cr3();
|
||||
void* phys_addr=virt_to_phys(data);
|
||||
load_address_space(cr3);
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef ADDRESS_SPACES_H
|
||||
#define ADDRESS_SPACES_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void address_spaces_copy_data(void* cr3, void* data,uint32_t size,void* virt_addr);
|
||||
void* address_spaces_put_data(void* cr3, void* data,uint32_t size);
|
||||
#endif
|
||||
|
@ -137,7 +137,7 @@ void isr_handler(registers_t* r) {
|
||||
switch (r->int_no) {
|
||||
case 14: {
|
||||
serial_write_string("PAGE FAULT\n");
|
||||
uint32_t addr;
|
||||
void* addr;
|
||||
asm("movl %%cr2,%0": "=r"(addr));
|
||||
// serial_write_string("In PID ");
|
||||
char str[11];
|
||||
@ -165,7 +165,7 @@ void isr_handler(registers_t* r) {
|
||||
serial_write_string(", user process tried to write a page and caused a protection fault at address ");
|
||||
}
|
||||
str[0]='\0';
|
||||
hex_to_ascii(addr,str);
|
||||
hex_to_ascii((unsigned int)addr,str);
|
||||
serial_write_string(str);
|
||||
serial_write_string(".");
|
||||
serial_write_string(" Stack is at ");
|
||||
@ -195,7 +195,7 @@ void isr_handler(registers_t* r) {
|
||||
case 80:
|
||||
switch (r->eax) {
|
||||
case SYSCALL_CREATEPROC:
|
||||
tasking_createTask((void*)r->ebx,(void*)r->ecx,0,r->edx,r->esi,r->edx,r->edi,0);
|
||||
tasking_createTask((void*)r->ebx,(void*)r->ecx,0,r->edx,(void*)r->esi,r->edx,(void*)r->edi,0);
|
||||
break;
|
||||
case SYSCALL_YIELD:
|
||||
tasking_yield();
|
||||
@ -254,7 +254,7 @@ void isr_handler(registers_t* r) {
|
||||
memcpy((char*)r->ebx,initrd,initrd_sz);
|
||||
break;
|
||||
case SYSCALL_NEW_THREAD: {
|
||||
uint32_t tid=tasking_new_thread((void*)r->ebx,tasking_getPID(),1,r->edx);
|
||||
uint32_t tid=tasking_new_thread((void*)r->ebx,tasking_getPID(),1,(void*)r->edx);
|
||||
if ((uint32_t*)r->ecx!=NULL) {
|
||||
*((uint32_t*)r->ecx)=tid;
|
||||
}
|
||||
@ -269,7 +269,7 @@ void isr_handler(registers_t* r) {
|
||||
}
|
||||
|
||||
|
||||
void isr_register_handler(uint8_t n,isr_t handler) {
|
||||
void isr_register_handler(int n,isr_t handler) {
|
||||
if (n>16) {
|
||||
return;
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ typedef struct {
|
||||
typedef void (*isr_t)(registers_t*);
|
||||
|
||||
void isr_install();
|
||||
void isr_register_handler(uint8_t n,isr_t handler);
|
||||
void isr_register_handler(int n,isr_t handler);
|
||||
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@ static uint32_t kstack_page_tables[218*1024] __attribute__((aligned(4096)));
|
||||
static uint32_t kmalloc_page_tables[4*1024] __attribute__((aligned(4096)));
|
||||
static uint32_t smap_page_tables[2048] __attribute__((aligned(4096)));
|
||||
static uint32_t* smap=(uint32_t*)0xFF800000;
|
||||
static char is_page_present(int page) {
|
||||
static char is_page_present(size_t page) {
|
||||
int table=page>>10;
|
||||
page=page&0x3FF;
|
||||
if ((smap[table]&0x1)==0) {
|
||||
@ -51,13 +51,13 @@ void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,ch
|
||||
}
|
||||
|
||||
void* find_free_pages(int num_pages) {
|
||||
uint32_t bmap_index;
|
||||
uint32_t remaining_blks;
|
||||
for(uint32_t i=1;i<131072;i++) {
|
||||
size_t bmap_index;
|
||||
size_t remaining_blks;
|
||||
for(size_t i=1;i<131072;i++) {
|
||||
char got_0=0;
|
||||
remaining_blks=num_pages;
|
||||
uint32_t old_j;
|
||||
for (uint32_t j=i*8;;j++) {
|
||||
size_t old_j;
|
||||
for (size_t j=i*8;;j++) {
|
||||
char bit=is_page_present(j);
|
||||
if (got_0) {
|
||||
if (bit) {
|
||||
@ -127,12 +127,11 @@ void invl_page(void* addr) {
|
||||
}
|
||||
|
||||
void* paging_new_address_space() {
|
||||
uint32_t cr3;
|
||||
asm volatile("movl %%cr3, %%eax; movl %%eax, %0;":"=m"(cr3)::"%eax");
|
||||
uint32_t cr3=(uint32_t)get_cr3();
|
||||
void* dir=pmem_alloc(1);
|
||||
smap_page_tables[0]=((uint32_t)dir)|0x3;
|
||||
invl_page(smap);
|
||||
for (uint32_t i=0;i<1024;i++) {
|
||||
for (size_t i=0;i<1024;i++) {
|
||||
smap[i]=page_directory[i];
|
||||
}
|
||||
smap_page_tables[0]=cr3|0x3;
|
||||
@ -143,7 +142,7 @@ void* paging_new_address_space() {
|
||||
void load_smap(void* cr3) {
|
||||
smap_page_tables[0]=(uint32_t)cr3|0x3;
|
||||
invl_page(&smap[0]);
|
||||
for (uint32_t i=1;i<2048;i++) {
|
||||
for (size_t i=1;i<2048;i++) {
|
||||
invl_page(&smap[i*1024]);
|
||||
smap_page_tables[i]=0;
|
||||
}
|
||||
@ -155,11 +154,11 @@ void load_address_space(void* cr3) {
|
||||
load_page_directory((uint32_t*)cr3);
|
||||
}
|
||||
|
||||
void unmap_pages(void* start_virt,uint32_t num_pages) {
|
||||
void unmap_pages(void* start_virt,int num_pages) {
|
||||
uint32_t virt_addr=(uint32_t)start_virt;
|
||||
int dir_entry=(virt_addr&0xFFC00000)>>22;
|
||||
int table_entry=(virt_addr&0x3FF000)>>12;
|
||||
for (uint32_t i=0;i<=num_pages;i++) {
|
||||
for (int i=0;i<=num_pages;i++) {
|
||||
if (smap[dir_entry]&0x1) {
|
||||
smap_page_tables[dir_entry+1]=(smap[dir_entry]&0xFFFFFC00)|0x3;
|
||||
smap[(1024+(1024*dir_entry))+table_entry]=0;
|
||||
@ -174,30 +173,30 @@ void unmap_pages(void* start_virt,uint32_t num_pages) {
|
||||
}
|
||||
|
||||
void paging_init() {
|
||||
for (uint32_t i=0;i<NUM_KERN_FRAMES;i++) {
|
||||
for (size_t i=0;i<NUM_KERN_FRAMES;i++) {
|
||||
kern_page_tables[i]=(i<<12)|0x3;
|
||||
}
|
||||
for (uint32_t i=0;i<218*1024;i++) {
|
||||
for (size_t i=0;i<218*1024;i++) {
|
||||
kstack_page_tables[i]=0;
|
||||
}
|
||||
for (uint32_t i=0;i<4*1024;i++) {
|
||||
for (size_t i=0;i<4*1024;i++) {
|
||||
kmalloc_page_tables[i]=(uint32_t)pmem_alloc(1)|0x3;
|
||||
}
|
||||
smap_page_tables[0]=(((uint32_t)&(page_directory))-0xC0000000)|0x3;
|
||||
for (uint32_t i=1;i<2048;i++) {
|
||||
for (size_t i=1;i<2048;i++) {
|
||||
smap_page_tables[i]=0;
|
||||
}
|
||||
for (uint32_t i=0;i<NUM_KERN_FRAMES/1024;i++) {
|
||||
for (size_t i=0;i<NUM_KERN_FRAMES/1024;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(kern_page_tables[i*1024]);
|
||||
page_directory[i+768]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
page_directory[985]=(uint32_t)(pmem_alloc(1024))|0x83;
|
||||
for (uint32_t i=0;i<4;i++) {
|
||||
for (size_t i=0;i<4;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(kmalloc_page_tables[i*1024]);
|
||||
page_directory[i+1018]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
// page_directory[1018,1021]=(((uint32_t)kmalloc_page_tables)-0xC0000000)|0x3;
|
||||
for (uint32_t i=0;i<2;i++) {
|
||||
for (size_t i=0;i<2;i++) {
|
||||
uint32_t entry_virt=(uint32_t)&(smap_page_tables[i*1024]);
|
||||
page_directory[i+1022]=(entry_virt-0xC0000000)|0x3;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef PAGING_HELPERS_H
|
||||
#define PAGING_HELPERS_H
|
||||
|
||||
void load_page_directory(uint32_t* dir);
|
||||
void load_page_directory(void* dir);
|
||||
|
||||
#endif
|
||||
|
@ -2,20 +2,21 @@
|
||||
#include "../paging.h"
|
||||
#include "../tasking_helpers.h"
|
||||
#include "../../pmem.h"
|
||||
#include <stddef.h>
|
||||
|
||||
static uint32_t* kstacks=(uint32_t*)0xC8000000;
|
||||
static uint32_t kstack_bmap[(218*1024)/8]={0};
|
||||
static void** kstacks=(void*)0xC8000000;
|
||||
static char kstack_bmap[(218*1024)/8]={0};
|
||||
|
||||
static char get_bmap_bit(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static char get_bmap_bit(size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
char entry=kstack_bmap[byte];
|
||||
return (entry&(1<<bit))>0;
|
||||
}
|
||||
|
||||
static void set_bmap_bit(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void set_bmap_bit(size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
kstack_bmap[byte]=kstack_bmap[byte]|(1<<bit);
|
||||
}
|
||||
|
||||
@ -35,26 +36,26 @@ int new_kstack() {
|
||||
return num;
|
||||
}
|
||||
|
||||
void setup_kstack(Thread* thread,uint32_t param1,uint32_t param2,char kmode,void* eip) {
|
||||
void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip) {
|
||||
void* old_cr3=get_cr3();
|
||||
uint32_t kstack_num=new_kstack();
|
||||
size_t kstack_num=new_kstack();
|
||||
load_address_space(thread->cr3);
|
||||
if (kmode) {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-5]));
|
||||
size_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((void*)(&kstacks[top_idx-5]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
kstacks[top_idx-1]=(void*)eip;
|
||||
} else {
|
||||
uint32_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((uint32_t)(&kstacks[top_idx-7]));
|
||||
size_t top_idx=(1024*(kstack_num+1));
|
||||
thread->kernel_esp=((void*)(&kstacks[top_idx-7]));
|
||||
thread->kernel_esp_top=thread->kernel_esp;
|
||||
uint32_t* user_stack=(uint32_t*)(((uint32_t)alloc_pages(2))+0x2000);
|
||||
void** user_stack=(void**)(((char*)alloc_pages(2))+0x2000);
|
||||
user_stack-=2;
|
||||
user_stack[0]=param1;
|
||||
user_stack[1]=param2;
|
||||
kstacks[top_idx-3]=(uint32_t)task_init;
|
||||
kstacks[top_idx-2]=(uint32_t)user_stack;
|
||||
kstacks[top_idx-1]=(uint32_t)eip;
|
||||
kstacks[top_idx-3]=(void*)task_init;
|
||||
kstacks[top_idx-2]=(void*)user_stack;
|
||||
kstacks[top_idx-1]=(void*)eip;
|
||||
}
|
||||
load_address_space(old_cr3);
|
||||
}
|
||||
|
@ -14,6 +14,6 @@ typedef struct {
|
||||
typedef void (*isr_t)(registers_t*);
|
||||
|
||||
void isr_install();
|
||||
void isr_register_handler(uint8_t n,isr_t handler);
|
||||
void isr_register_handler(int n,isr_t handler);
|
||||
|
||||
#endif
|
||||
|
@ -1,11 +1,8 @@
|
||||
#ifndef PAGING_H
|
||||
#define PAGING_H
|
||||
|
||||
#include "arch_consts.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void map_pages(void* virt_addr_ptr,void* phys_addr_ptr,int num_pages,char usr,char wr);
|
||||
void unmap_pages(void* start_virt,uint32_t num_pages);
|
||||
void unmap_pages(void* start_virt,int num_pages);
|
||||
void* alloc_pages(int num_pages);
|
||||
void alloc_pages_virt(int num_pages,void* addr);
|
||||
void paging_init();
|
||||
|
@ -45,7 +45,7 @@ void serial_printf(const char* format,...) {
|
||||
break;
|
||||
}
|
||||
case 'x': {
|
||||
uint32_t i=va_arg(arg,uint32_t);
|
||||
unsigned int i=va_arg(arg,unsigned int);
|
||||
char str[11];
|
||||
str[0]='\0';
|
||||
hex_to_ascii(i,str);
|
||||
|
@ -6,6 +6,6 @@
|
||||
void switch_to_thread_asm(Thread* thread);
|
||||
void task_init();
|
||||
void wait_for_unblocked_thread_asm();
|
||||
void setup_kstack(Thread* thread,uint32_t param1,uint32_t param2,char kmode,void* eip);
|
||||
void setup_kstack(Thread* thread,void* param1,void* param2,char kmode,void* eip);
|
||||
|
||||
#endif
|
||||
|
@ -186,7 +186,7 @@ void isr_handler(registers_t* r) {
|
||||
}
|
||||
}
|
||||
|
||||
void isr_register_handler(uint8_t n,isr_t handler) {
|
||||
void isr_register_handler(int n,isr_t handler) {
|
||||
if (n>16) {
|
||||
return;
|
||||
}
|
||||
|
@ -13,6 +13,6 @@ typedef struct {
|
||||
typedef void (*isr_t)(registers_t*);
|
||||
|
||||
void isr_install();
|
||||
void isr_register_handler(uint8_t n,isr_t handler);
|
||||
void isr_register_handler(int n,isr_t handler);
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "arch_consts.h"
|
||||
#include "paging.h"
|
||||
#include "pmem.h"
|
||||
#include <stdint.h>
|
||||
|
@ -7,9 +7,7 @@
|
||||
#include "vga_err.h"
|
||||
#include <elf.h>
|
||||
#include <grub/multiboot2.h>
|
||||
#include <grub/text_fb_info.h>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tasking.h>
|
||||
@ -45,10 +43,10 @@ static void read_initrd(struct multiboot_boot_header_tag* tags) {
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t getsize(const char *in) {
|
||||
uint32_t size=0;
|
||||
uint32_t j;
|
||||
uint32_t count=1;
|
||||
size_t getsize(const char *in) {
|
||||
size_t size=0;
|
||||
size_t j;
|
||||
size_t count=1;
|
||||
for (j=11;j>0;j--,count*=8) {
|
||||
size+=((in[j-1]-'0')*count);
|
||||
}
|
||||
@ -66,12 +64,12 @@ void kmain(struct multiboot_boot_header_tag* hdr) {
|
||||
vga_init((char*)0xC00B8000);
|
||||
read_initrd(tags);
|
||||
int pos=0;
|
||||
uint32_t datapos;
|
||||
size_t datapos;
|
||||
tar_header* tar_hdr;
|
||||
for (int i=0;;i++) {
|
||||
tar_hdr=(tar_header*)&initrd[pos];
|
||||
if (tar_hdr->filename[0]=='\0') break;
|
||||
uint32_t size=getsize(tar_hdr->size);
|
||||
size_t size=getsize(tar_hdr->size);
|
||||
pos+=512;
|
||||
if (strcmp(&tar_hdr->filename[0],"init")==0) {
|
||||
datapos=pos;
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "cpu/arch_consts.h"
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -10,35 +9,35 @@ static char bitmap[KMALLOC_BMAP_SZ];
|
||||
static void* data=(void*)KMALLOC_START;
|
||||
|
||||
|
||||
static char get_bmap_bit(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static char get_bmap_bit(size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
char entry=bitmap[byte];
|
||||
return (entry&(1<<bit))>0;
|
||||
}
|
||||
|
||||
static void set_bmap_bit(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void set_bmap_bit(size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
bitmap[byte]=bitmap[byte]|(1<<bit);
|
||||
}
|
||||
|
||||
static void clear_bmap_bit(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void clear_bmap_bit(size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
bitmap[byte]=bitmap[byte]&(~(1<<bit));
|
||||
}
|
||||
|
||||
void* kmalloc(uint32_t size) {
|
||||
uint32_t num_4b_grps=(uint32_t)ceilf((float)size/4);
|
||||
void* kmalloc(size_t size) {
|
||||
size_t num_4b_grps=(size_t)ceilf((float)size/4);
|
||||
num_4b_grps+=2;
|
||||
uint32_t bmap_index;
|
||||
uint32_t remaining_blks;
|
||||
for(uint32_t i=0;i<KMALLOC_BMAP_SZ;i++) {
|
||||
size_t bmap_index;
|
||||
size_t remaining_blks;
|
||||
for(size_t i=0;i<KMALLOC_BMAP_SZ;i++) {
|
||||
char got_0=0;
|
||||
remaining_blks=num_4b_grps;
|
||||
uint32_t old_j;
|
||||
for (uint32_t j=i*8;;j++) {
|
||||
size_t old_j;
|
||||
for (size_t j=i*8;;j++) {
|
||||
char bit=get_bmap_bit(j);
|
||||
if (got_0) {
|
||||
if (bit) {
|
||||
@ -72,11 +71,11 @@ void* kmalloc(uint32_t size) {
|
||||
if (remaining_blks!=0) {
|
||||
return NULL;
|
||||
}
|
||||
for (uint32_t i=0;i<num_4b_grps;i++) {
|
||||
for (size_t i=0;i<num_4b_grps;i++) {
|
||||
set_bmap_bit(bmap_index+i);
|
||||
}
|
||||
uint32_t data_offset=(bmap_index*8)+8;
|
||||
uint32_t* info=(void*)(((char*)data)+data_offset-8);
|
||||
size_t data_offset=(bmap_index*8)+8;
|
||||
size_t* info=(void*)(((char*)data)+data_offset-8);
|
||||
info[0]=num_4b_grps;
|
||||
info[1]=bmap_index;
|
||||
return (void*)(((char*)data)+data_offset);
|
||||
@ -84,10 +83,10 @@ void* kmalloc(uint32_t size) {
|
||||
}
|
||||
|
||||
void kfree(void* mem) {
|
||||
uint32_t* info=(uint32_t*)((uint32_t)mem-8);
|
||||
uint32_t num_4b_grps=info[0];
|
||||
uint32_t bmap_index=info[1];
|
||||
for (uint32_t i=0;i<num_4b_grps;i++) {
|
||||
size_t* info=(size_t*)((size_t)mem-8);
|
||||
size_t num_4b_grps=info[0];
|
||||
size_t bmap_index=info[1];
|
||||
for (size_t i=0;i<num_4b_grps;i++) {
|
||||
clear_bmap_bit(bmap_index+i);
|
||||
}
|
||||
}
|
||||
|
@ -42,15 +42,15 @@ void pmem_init(struct multiboot_boot_header_tag* tags) {
|
||||
struct multiboot_mmap_entry* orig_ptr=(struct multiboot_mmap_entry*)(((char*)tag)+16);
|
||||
for (struct multiboot_mmap_entry* ptr=orig_ptr;(char*)ptr<((char*)orig_ptr)+tag->size;ptr++) {
|
||||
if (ptr->type!=MULTIBOOT_MEMORY_AVAILABLE) continue;
|
||||
uint32_t start=ptr->addr;
|
||||
size_t start=ptr->addr;
|
||||
if (start<0x100000) continue;
|
||||
uint32_t end=start+ptr->len-1;
|
||||
size_t end=start+ptr->len-1;
|
||||
if (start&(FRAME_SZ-1)) {
|
||||
start+=FRAME_SZ;
|
||||
}
|
||||
start=start>>FRAME_NO_OFFSET;
|
||||
end=end>>FRAME_NO_OFFSET;
|
||||
for (uint32_t i=start;i<end;i++) {
|
||||
for (size_t i=start;i<end;i++) {
|
||||
clear_bmap_bit(i);
|
||||
}
|
||||
}
|
||||
@ -63,19 +63,19 @@ void pmem_init(struct multiboot_boot_header_tag* tags) {
|
||||
vga_write_string("[PANIC] No memory map supplied by bootloader!");
|
||||
halt();
|
||||
}
|
||||
for (uint32_t i=0;i<NUM_KERN_FRAMES;i++) {
|
||||
for (size_t i=0;i<NUM_KERN_FRAMES;i++) {
|
||||
set_bmap_bit(i);
|
||||
}
|
||||
}
|
||||
|
||||
void* pmem_alloc(int num_pages) {
|
||||
uint32_t bmap_index;
|
||||
uint32_t remaining_blks;
|
||||
for(uint32_t i=0;i<131072;i++) {
|
||||
size_t bmap_index;
|
||||
size_t remaining_blks;
|
||||
for(size_t i=0;i<131072;i++) {
|
||||
char got_0=0;
|
||||
remaining_blks=num_pages;
|
||||
uint32_t old_j;
|
||||
for (uint32_t j=i*8;;j++) {
|
||||
size_t old_j;
|
||||
for (size_t j=i*8;;j++) {
|
||||
char bit=get_bmap_bit(j);
|
||||
if (got_0) {
|
||||
if (bit) {
|
||||
|
@ -11,49 +11,49 @@
|
||||
#define NUM_UNBLOCKED_THREADS(proc) (proc->numThreads-proc->numThreadsBlocked)
|
||||
#define SAME_PROC(thread1,thread2) (thread1->process->pid==thread2->process->pid)
|
||||
#define SAME_THREAD(thread1,thread2) (thread1->process->pid==thread2->process->pid&&thread1->tid==thread2->tid)
|
||||
uint32_t next_pid=0;
|
||||
uint32_t num_procs=0;
|
||||
pid_t next_pid=0;
|
||||
size_t num_procs=0;
|
||||
Process* processes[MAX_PROCS];
|
||||
char proc_schedule_bmap[MAX_PROCS/8];
|
||||
Thread* currentThread;
|
||||
static Thread* readyToRunHead=NULL;
|
||||
static Thread* readyToRunTail=NULL;
|
||||
|
||||
static char is_proc_scheduled(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static char is_proc_scheduled(pid_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
char entry=proc_schedule_bmap[byte];
|
||||
return (entry&(1<<bit))>0;
|
||||
}
|
||||
|
||||
static void mark_proc_scheduled(uint32_t index) {
|
||||
static void mark_proc_scheduled(pid_t index) {
|
||||
if (is_proc_scheduled(index)) {
|
||||
serial_printf("Attempt to schedule a thread in a process with a scheduled thread! (PID %d)\n",index);
|
||||
halt();
|
||||
}
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
proc_schedule_bmap[byte]=proc_schedule_bmap[byte]|(1<<bit);
|
||||
}
|
||||
|
||||
static void unmark_proc_scheduled(uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void unmark_proc_scheduled(pid_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
proc_schedule_bmap[byte]=proc_schedule_bmap[byte]&(~(1<<bit));
|
||||
}
|
||||
|
||||
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg,char isThread) {
|
||||
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread) {
|
||||
if (next_pid>MAX_PROCS && !isThread) {
|
||||
serial_printf("Failed to create a process, as 32k processes have been created already.\n");
|
||||
halt(); //Cannot ever create more than 32k processes, as I don't currently reuse PIDs.
|
||||
}
|
||||
uint32_t param1;
|
||||
void* param1;
|
||||
if (param1_exists) {
|
||||
param1=param1_arg;
|
||||
} else {
|
||||
param1=1;
|
||||
param1=NULL;
|
||||
}
|
||||
uint32_t param2;
|
||||
void* param2;
|
||||
if (param2_exists) {
|
||||
if (isThread) {
|
||||
serial_printf("Param2 in Thread!\n");
|
||||
@ -61,7 +61,7 @@ void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,uint32
|
||||
}
|
||||
param2=param2_arg;
|
||||
} else {
|
||||
param2=2;
|
||||
param2=NULL;
|
||||
}
|
||||
Process* proc;
|
||||
Thread* thread=kmalloc(sizeof(Thread));
|
||||
@ -141,8 +141,8 @@ int* tasking_get_errno_address() {
|
||||
return ¤tThread->errno;
|
||||
}
|
||||
|
||||
uint32_t tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg) {
|
||||
tasking_createTask(start,NULL,0,param_exists,param_arg,0,pid,1);
|
||||
pid_t tasking_new_thread(void* start,pid_t pid,char param_exists,void* param_arg) {
|
||||
tasking_createTask(start,NULL,0,param_exists,param_arg,0,(void*)pid,1);
|
||||
return processes[pid]->firstThread->tid;
|
||||
}
|
||||
|
||||
@ -261,7 +261,7 @@ void tasking_block(ThreadState newstate) {
|
||||
}
|
||||
}
|
||||
}
|
||||
void tasking_unblock(pid_t pid,uint32_t tid) {
|
||||
void tasking_unblock(pid_t pid,pid_t tid) {
|
||||
serial_printf("Unblocking PID %d TID %d\n",pid,tid);
|
||||
if (!processes[pid]) {
|
||||
serial_printf("PID %d does not exist!\n",pid);
|
||||
@ -294,7 +294,7 @@ void tasking_unblock(pid_t pid,uint32_t tid) {
|
||||
}
|
||||
}
|
||||
|
||||
void tasking_exit(uint8_t code) {
|
||||
void tasking_exit(int code) {
|
||||
serial_printf("PID %d is exiting with code %d.\n",currentThread->process->pid,code);
|
||||
if (readyToRunHead&&SAME_PROC(readyToRunHead,currentThread)) {
|
||||
readyToRunHead=readyToRunHead->nextReadyToRun;
|
||||
@ -306,6 +306,7 @@ void tasking_exit(uint8_t code) {
|
||||
readyToRunTail=readyToRunTail->prevReadyToRun;
|
||||
if (readyToRunTail==NULL) {
|
||||
readyToRunHead=NULL;
|
||||
|
||||
}
|
||||
}
|
||||
if (readyToRunHead&&readyToRunHead->nextReadyToRun) {
|
||||
|
@ -19,18 +19,18 @@ struct Thread;
|
||||
|
||||
typedef struct Process {
|
||||
char priv;
|
||||
uint32_t pid;
|
||||
uint32_t next_tid;
|
||||
pid_t pid;
|
||||
pid_t next_tid;
|
||||
int numThreads;
|
||||
int numThreadsBlocked;
|
||||
struct Thread* firstThread;
|
||||
} Process;
|
||||
|
||||
typedef struct Thread {
|
||||
uint32_t kernel_esp;
|
||||
uint32_t kernel_esp_top;
|
||||
void* kernel_esp;
|
||||
void* kernel_esp_top;
|
||||
void* cr3; //In thread to make the task switch asm easier
|
||||
uint32_t tid;
|
||||
pid_t tid;
|
||||
ThreadState state;
|
||||
int errno;
|
||||
struct Thread* nextThreadInProcess;
|
||||
@ -42,16 +42,16 @@ typedef struct Thread {
|
||||
|
||||
extern Thread* currentThread;
|
||||
|
||||
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,uint32_t param1_arg,char param2_exists,uint32_t param2_arg,char isThread);
|
||||
void tasking_createTask(void* eip,void* cr3,char kmode,char param1_exists,void* param1_arg,char param2_exists,void* param2_arg,char isThread);
|
||||
void tasking_init();
|
||||
char tasking_isPrivleged();
|
||||
pid_t tasking_getPID();
|
||||
int* tasking_get_errno_address();
|
||||
uint32_t tasking_new_thread(void* start,pid_t pid,char param_exists,uint32_t param_arg);
|
||||
pid_t tasking_new_thread(void* start,pid_t pid,char param_exists,void* param_arg);
|
||||
|
||||
void tasking_exit(uint8_t code);
|
||||
void tasking_exit(int code);
|
||||
void tasking_block(ThreadState newstate);
|
||||
void tasking_unblock(pid_t pid,uint32_t tid);
|
||||
void tasking_unblock(pid_t pid,pid_t tid);
|
||||
void tasking_yield();
|
||||
|
||||
#endif
|
||||
|
@ -5,7 +5,7 @@
|
||||
#define QUAUX(X) #X
|
||||
#define QU(X) QUAUX(X)
|
||||
|
||||
void* alloc_memory(uint32_t num_pages) {
|
||||
void* alloc_memory(int num_pages) {
|
||||
void* address;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
|
||||
@ -14,7 +14,7 @@ void* alloc_memory(uint32_t num_pages) {
|
||||
return address;
|
||||
}
|
||||
|
||||
void alloc_memory_virt(uint32_t num_pages,void* addr) {
|
||||
void alloc_memory_virt(int num_pages,void* addr) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ALLOC_MEM) ", %%eax; \
|
||||
int $80; \
|
||||
@ -30,14 +30,14 @@ void* new_address_space() {
|
||||
return cr3;
|
||||
}
|
||||
|
||||
void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr) {
|
||||
void copy_data(void* cr3, void* data,size_t size,void* virt_addr) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(cr3),"c"(data),"d"(size),"S"(virt_addr));
|
||||
}
|
||||
|
||||
void* put_data(void* cr3, void* data,uint32_t size) {
|
||||
void* put_data(void* cr3, void* data,size_t size) {
|
||||
void* virt_addr;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_ADDR_SPACES_COPY_DATA) ", %%eax; \
|
||||
@ -46,7 +46,7 @@ void* put_data(void* cr3, void* data,uint32_t size) {
|
||||
return virt_addr;
|
||||
}
|
||||
|
||||
void* map_phys(void* phys_addr,uint32_t num_pages) {
|
||||
void* map_phys(void* phys_addr,size_t num_pages) {
|
||||
void* virt_addr;
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_PRIV_MAP_PAGES) ", %%eax; \
|
||||
|
@ -36,7 +36,7 @@ void __stdio_init() {
|
||||
// }
|
||||
}
|
||||
|
||||
// static vfs_message* make_msg(vfs_message_type type,const char* mode,const char* path, uint32_t fd, int data) {
|
||||
// static vfs_message* make_msg(vfs_message_type type,const char* mode,const char* path, int fd, int data) {
|
||||
// vfs_message* msg_data=malloc(sizeof(vfs_message));
|
||||
// msg_data->type=type;
|
||||
// msg_data->id=0;
|
||||
@ -80,7 +80,7 @@ void __stdio_init() {
|
||||
// return NULL;
|
||||
// } else {
|
||||
// FILE* file=malloc(sizeof(FILE));
|
||||
// *file=vfs_msg->fd; //We're using pointers to FILE even though it's a uint32_t so we can expand to a struct if needed
|
||||
// *file=vfs_msg->fd; //We're using pointers to FILE even though it's an int so we can expand to a struct if needed
|
||||
// free(msg.msg);
|
||||
// return file;
|
||||
// }
|
||||
@ -378,7 +378,7 @@ void __stdio_init() {
|
||||
// break;
|
||||
// }
|
||||
// case 'x': {
|
||||
// uint32_t i=va_arg(arg,uint32_t);
|
||||
// unsigned int i=va_arg(arg, unsigned int);
|
||||
// char str[11];
|
||||
// str[0]='\0';
|
||||
// hex_to_ascii(i,str);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include <math.h>
|
||||
#include <memory.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -8,43 +7,43 @@
|
||||
|
||||
typedef struct {
|
||||
char* bitmap;
|
||||
uint32_t bitmap_byt_size;
|
||||
uint32_t bitmap_bit_size;
|
||||
uint32_t avail_data_size;
|
||||
size_t bitmap_byt_size;
|
||||
size_t bitmap_bit_size;
|
||||
size_t avail_data_size;
|
||||
void* data_block;
|
||||
} heap_block;
|
||||
|
||||
|
||||
static heap_block entries[MAX_BLOCKS];
|
||||
static uint32_t num_used_entries=0;
|
||||
static size_t num_used_entries=0;
|
||||
|
||||
static char get_bmap_bit(char* bmap,uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static char get_bmap_bit(char* bmap,size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
char entry=bmap[byte];
|
||||
return (entry&(1<<bit))>0;
|
||||
}
|
||||
|
||||
static void set_bmap_bit(char* bmap,uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void set_bmap_bit(char* bmap,size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
bmap[byte]=bmap[byte]|(1<<bit);
|
||||
}
|
||||
|
||||
static void clear_bmap_bit(char* bmap,uint32_t index) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void clear_bmap_bit(char* bmap,size_t index) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
bmap[byte]=bmap[byte]&(~(1<<bit));
|
||||
}
|
||||
|
||||
static void reserve_block(uint32_t mem_blks) {
|
||||
uint32_t bmap_byts=((mem_blks*BLK_SZ)/4)/8;
|
||||
entries[num_used_entries].bitmap=alloc_memory((uint32_t)ceilf((double)bmap_byts/BLK_SZ));
|
||||
static void reserve_block(size_t mem_blks) {
|
||||
size_t bmap_byts=((mem_blks*BLK_SZ)/4)/8;
|
||||
entries[num_used_entries].bitmap=alloc_memory((size_t)ceilf((double)bmap_byts/BLK_SZ));
|
||||
entries[num_used_entries].bitmap_byt_size=bmap_byts;
|
||||
entries[num_used_entries].bitmap_bit_size=bmap_byts*8;
|
||||
char* bmap=entries[num_used_entries].bitmap;
|
||||
uint32_t bmap_byt_sz=entries[num_used_entries].bitmap_byt_size;
|
||||
for(uint32_t i=0;i<bmap_byt_sz;i++) {
|
||||
size_t bmap_byt_sz=entries[num_used_entries].bitmap_byt_size;
|
||||
for(size_t i=0;i<bmap_byt_sz;i++) {
|
||||
bmap[i]=0;
|
||||
}
|
||||
entries[num_used_entries].avail_data_size=mem_blks*BLK_SZ;
|
||||
@ -53,22 +52,22 @@ static void reserve_block(uint32_t mem_blks) {
|
||||
}
|
||||
|
||||
void* malloc(size_t size) {
|
||||
uint32_t num_4b_grps=(uint32_t)ceilf((float)size/4);
|
||||
size_t num_4b_grps=(size_t)ceilf((float)size/4);
|
||||
num_4b_grps+=3;
|
||||
int blk_indx=-1;
|
||||
uint32_t bmap_index;
|
||||
size_t bmap_index;
|
||||
heap_block entry;
|
||||
for (uint32_t i=0;i<num_used_entries;i++) {
|
||||
uint32_t remaining_blks;
|
||||
for (size_t i=0;i<num_used_entries;i++) {
|
||||
size_t remaining_blks;
|
||||
entry=entries[i];
|
||||
if (entry.avail_data_size>=size) {
|
||||
char* bmap=entry.bitmap;
|
||||
uint32_t bmap_byt_sz=entry.bitmap_byt_size;
|
||||
for(uint32_t i=0;i<bmap_byt_sz;i++) {
|
||||
size_t bmap_byt_sz=entry.bitmap_byt_size;
|
||||
for(size_t i=0;i<bmap_byt_sz;i++) {
|
||||
char got_0=0;
|
||||
remaining_blks=num_4b_grps;
|
||||
uint32_t old_j;
|
||||
for (uint32_t j=i*8;;j++) {
|
||||
size_t old_j;
|
||||
for (size_t j=i*8;;j++) {
|
||||
char bit=get_bmap_bit(bmap,j);
|
||||
if (got_0) {
|
||||
if (bit) {
|
||||
@ -106,15 +105,15 @@ void* malloc(size_t size) {
|
||||
}
|
||||
}
|
||||
if (blk_indx==-1) {
|
||||
// reserve_block((uint32_t)ceilf((double)size/BLK_SZ));
|
||||
// reserve_block((size_t)ceilf((double)size/BLK_SZ));
|
||||
reserve_block(1024);
|
||||
return malloc(size);
|
||||
}
|
||||
for (uint32_t i=0;i<num_4b_grps;i++) {
|
||||
for (size_t i=0;i<num_4b_grps;i++) {
|
||||
set_bmap_bit(entry.bitmap,bmap_index+i);
|
||||
}
|
||||
uint32_t data_offset=(bmap_index*8)+12;
|
||||
uint32_t* info=(void*)(((char*)entry.data_block)+data_offset-12);
|
||||
size_t data_offset=(bmap_index*8)+12;
|
||||
size_t* info=(void*)(((char*)entry.data_block)+data_offset-12);
|
||||
info[0]=num_4b_grps;
|
||||
info[1]=bmap_index;
|
||||
info[2]=blk_indx;
|
||||
@ -128,7 +127,7 @@ void* realloc(void *mem, size_t new_sz) {
|
||||
if (mem==NULL) {
|
||||
return ptr;
|
||||
}
|
||||
uint32_t num_4b_grps=*((uint32_t*)((char*)mem-12));
|
||||
size_t num_4b_grps=*((size_t*)((char*)mem-12));
|
||||
memcpy(ptr,mem,num_4b_grps*4);
|
||||
free(mem);
|
||||
mem=ptr;
|
||||
@ -136,12 +135,12 @@ void* realloc(void *mem, size_t new_sz) {
|
||||
}
|
||||
|
||||
void free(void* mem) {
|
||||
uint32_t* info=(uint32_t*)((char*)mem-12);
|
||||
uint32_t num_4b_grps=info[0];
|
||||
uint32_t bmap_index=info[1];
|
||||
uint32_t blk_indx=info[2];
|
||||
size_t* info=(size_t*)((char*)mem-12);
|
||||
size_t num_4b_grps=info[0];
|
||||
size_t bmap_index=info[1];
|
||||
size_t blk_indx=info[2];
|
||||
heap_block entry=entries[blk_indx];
|
||||
for (uint32_t i=0;i<num_4b_grps;i++) {
|
||||
for (size_t i=0;i<num_4b_grps;i++) {
|
||||
clear_bmap_bit(entry.bitmap,bmap_index+i);
|
||||
}
|
||||
entry.avail_data_size+=(num_4b_grps*4)+12;
|
||||
|
@ -71,7 +71,7 @@ void int_to_ascii(int n,char* str) {
|
||||
strrev(str);
|
||||
}
|
||||
|
||||
void hex_to_ascii(int n, char* str) {
|
||||
void hex_to_ascii(unsigned int n, char* str) {
|
||||
str[0]='\0';
|
||||
append(str, '0');
|
||||
append(str, 'x');
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <stdint.h>
|
||||
#include <sys/syscalls.h>
|
||||
#include <sys/types.h>
|
||||
#include <tasking.h>
|
||||
@ -20,20 +19,13 @@ void createProcCr3(void* start,void* cr3) {
|
||||
"::"b"(start),"d"(0),"c"(cr3));
|
||||
}
|
||||
|
||||
void createProcCr3Param(void* start,void* cr3,uint32_t param1,uint32_t param2) {
|
||||
void createProcCr3Param(void* start,void* cr3,void* param1,void* param2) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_CREATEPROC) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(start),"c"(cr3),"d"(1),"S"(param1),"D"(param2));
|
||||
}
|
||||
|
||||
void yieldToPID(uint32_t pid) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_YIELD) ", %%eax; \
|
||||
int $80; \
|
||||
"::"b"(pid));
|
||||
}
|
||||
|
||||
__attribute__((noreturn)) void exit(int code) {
|
||||
code=code&0xff;
|
||||
asm volatile(" \
|
||||
@ -51,7 +43,7 @@ void blockThread(ThreadState state) {
|
||||
"::"b"(state));
|
||||
}
|
||||
|
||||
void unblockThread(pid_t pid,uint32_t tid) {
|
||||
void unblockThread(pid_t pid,pid_t tid) {
|
||||
asm volatile(" \
|
||||
mov $" QU(SYSCALL_UNBLOCK) ", %%eax; \
|
||||
int $80; \
|
||||
|
16
pci/pci.c
16
pci/pci.c
@ -1,14 +1,14 @@
|
||||
#include "pci.h"
|
||||
#include "ports.h"
|
||||
#include <sys/ports.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
pci_dev_common_info** pci_devs;
|
||||
static uint32_t max_devs;
|
||||
uint32_t pci_num_devs;
|
||||
static size_t max_devs;
|
||||
size_t pci_num_devs;
|
||||
|
||||
static uint32_t read_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset) {
|
||||
static uint32_t read_config(int bus,int device,int func,int offset) {
|
||||
uint32_t address;
|
||||
uint32_t lbus=(uint32_t)bus;
|
||||
uint32_t ldev=(uint32_t)device;
|
||||
@ -19,7 +19,7 @@ static uint32_t read_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offs
|
||||
return data;
|
||||
}
|
||||
|
||||
static void write_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset,uint32_t data) {
|
||||
static void write_config(int bus,int device,int func,int offset,uint32_t data) {
|
||||
uint32_t address;
|
||||
uint32_t lbus=(uint32_t)bus;
|
||||
uint32_t ldev=(uint32_t)device;
|
||||
@ -29,7 +29,7 @@ static void write_config(uint8_t bus,uint8_t device,uint8_t func,uint8_t offset,
|
||||
port_long_out(PCI_CONFIG_DATA,data);
|
||||
}
|
||||
|
||||
pci_dev_common_info* pci_get_dev_info(uint8_t bus,uint8_t device,uint8_t func) {
|
||||
pci_dev_common_info* pci_get_dev_info(int bus,int device,int func) {
|
||||
uint32_t* info=malloc(sizeof(uint32_t)*5);
|
||||
info[0]=read_config(bus,device,func,0);
|
||||
info[1]=read_config(bus,device,func,4);
|
||||
@ -52,14 +52,14 @@ void pci_set_dev_info(pci_dev_common_info* inf) {
|
||||
|
||||
static void checkFunction(pci_dev_common_info* info);
|
||||
|
||||
static void checkDevice(uint8_t bus, uint8_t device) {
|
||||
static void checkDevice(int bus, int device) {
|
||||
pci_dev_common_info* info=pci_get_dev_info(bus,device,0);
|
||||
if(info->vend_id==0xFFFF||info->class_code==0xFF) {
|
||||
return;
|
||||
}
|
||||
checkFunction(info);
|
||||
if((info->header_type&0x80)!=0) {
|
||||
for(uint8_t function=1;function<8;function++) {
|
||||
for(int 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) {
|
||||
checkFunction(info);
|
||||
|
31
pci/ports.c
31
pci/ports.c
@ -1,31 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t port_byte_in(uint16_t port) {
|
||||
uint8_t result;
|
||||
asm("in %%dx, %%al":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_byte_out(uint16_t port,uint8_t data) {
|
||||
asm("out %%al, %%dx":: "a"(data),"d"(port));
|
||||
}
|
||||
|
||||
uint16_t port_word_in(uint16_t port) {
|
||||
uint16_t result;
|
||||
asm("in %%dx, %%ax":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_word_out(uint16_t port,uint16_t data) {
|
||||
asm("out %%ax, %%dx":: "a" (data), "d" (port));
|
||||
}
|
||||
|
||||
uint32_t port_long_in(uint16_t port) {
|
||||
uint32_t result;
|
||||
asm("inl %%dx, %%eax":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_long_out(uint16_t port,uint32_t data) {
|
||||
asm("outl %%eax, %%dx":: "a" (data), "d" (port));
|
||||
}
|
12
pci/ports.h
12
pci/ports.h
@ -1,12 +0,0 @@
|
||||
#ifndef PORTS_H
|
||||
#define PORTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t port_byte_in(uint16_t port);
|
||||
void port_byte_out(uint16_t port,uint8_t data);
|
||||
uint16_t port_word_in(uint16_t port);
|
||||
void port_word_out(uint16_t port,uint16_t data);
|
||||
uint32_t port_long_in(uint16_t port);
|
||||
void port_long_out(uint16_t port,uint32_t data);
|
||||
#endif
|
@ -11,11 +11,11 @@
|
||||
#define IDE_SEC_CTRL 0x376
|
||||
|
||||
static uint8_t ident[4][512];
|
||||
static uint8_t* sect_data=NULL;
|
||||
static uint32_t last_read_sector=0;
|
||||
static char* sect_data=NULL;
|
||||
static size_t last_read_sector=0;
|
||||
static int last_read_base=0;
|
||||
static int last_read_slave=0;
|
||||
static uint8_t* read_sect(int base,int slave,uint32_t lba) {
|
||||
static char* read_sect(int base,int slave,size_t lba) {
|
||||
if (last_read_sector==lba && last_read_base==base && last_read_slave==slave && sect_data) {
|
||||
return sect_data;
|
||||
}
|
||||
@ -27,7 +27,7 @@ static uint8_t* read_sect(int base,int slave,uint32_t lba) {
|
||||
port_byte_out(base+4,(lba&0xFF00)>>8);
|
||||
port_byte_out(base+5,(lba&0xFF0000)>>16);
|
||||
port_byte_out(base+7,0x20);
|
||||
uint8_t* sect=malloc(sizeof(uint8_t)*512);
|
||||
char* sect=malloc(sizeof(char)*512);
|
||||
while ((port_byte_in(base+7)&0x88)!=0x8);
|
||||
for (int i=0;i<512;i+=2) {
|
||||
uint16_t data=port_word_in(base);
|
||||
@ -44,7 +44,7 @@ static uint8_t* read_sect(int base,int slave,uint32_t lba) {
|
||||
return sect;
|
||||
}
|
||||
|
||||
static void write_sect(int base,int slave,uint32_t lba,uint8_t* sect) {
|
||||
static void write_sect(int base,int slave,size_t lba,char* sect) {
|
||||
if (last_read_sector==lba && last_read_base==base && last_read_slave==slave && sect_data) {
|
||||
sect_data=sect;
|
||||
}
|
||||
@ -91,17 +91,17 @@ static int drv(char* filename,int c,long pos,char wr) {
|
||||
slave=1;
|
||||
}
|
||||
if (wr) {
|
||||
uint32_t lba=pos/512;
|
||||
char lba=pos/512;
|
||||
int offset=pos%512;
|
||||
uint8_t* sect=read_sect(base,slave,lba);
|
||||
sect[offset]=(uint8_t)c;
|
||||
size_t* sect=read_sect(base,slave,lba);
|
||||
sect[offset]=(char)c;
|
||||
write_sect(base,slave,lba,sect);
|
||||
return 1;
|
||||
} else {
|
||||
uint32_t lba=pos/512;
|
||||
size_t lba=pos/512;
|
||||
int offset=pos%512;
|
||||
uint8_t* sect=read_sect(base,slave,lba);
|
||||
uint8_t val=sect[offset];
|
||||
char* sect=read_sect(base,slave,lba);
|
||||
char val=sect[offset];
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
@ -6,15 +6,15 @@
|
||||
|
||||
static char** devices;
|
||||
static dev_drv* dev_drivers;
|
||||
static uint32_t num_devices;
|
||||
static uint32_t max_devices;
|
||||
static size_t num_devices;
|
||||
static size_t max_devices;
|
||||
|
||||
char devfs_drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
if (op==FSOP_MOUNT) {
|
||||
return 1;
|
||||
}
|
||||
if (op==FSOP_OPEN) {
|
||||
for (uint32_t i=0;i<num_devices;i++) {
|
||||
for (size_t i=0;i<num_devices;i++) {
|
||||
if (strcmp(devices[i],stream->path)==0) {
|
||||
return 1;
|
||||
}
|
||||
@ -22,7 +22,7 @@ char devfs_drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
return 0;
|
||||
}
|
||||
if (op==FSOP_GETC) {
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<num_devices;i++) {
|
||||
if (strcmp(devices[i],stream->path)==0) {
|
||||
break;
|
||||
@ -33,7 +33,7 @@ char devfs_drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
return 1;
|
||||
}
|
||||
if (op==FSOP_PUTC) {
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<num_devices;i++) {
|
||||
if (strcmp(devices[i],stream->path)==0) {
|
||||
break;
|
||||
|
124
stuff/fs/ext2.c
124
stuff/fs/ext2.c
@ -11,7 +11,7 @@
|
||||
ext2_superblock* supblks;
|
||||
uint32_t* blk_size;
|
||||
blk_grp** blk_grps;
|
||||
uint32_t* blk_grp_num;
|
||||
size_t* blk_grp_num;
|
||||
char** mnts;
|
||||
char** devs;
|
||||
int num_mnts;
|
||||
@ -30,69 +30,69 @@ typedef struct {
|
||||
char* contents;
|
||||
} file_info;
|
||||
|
||||
static char get_bmap_bit(uint32_t index,uint8_t* bitmap) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static char get_bmap_bit(size_t index,char* bitmap) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
char entry=bitmap[byte];
|
||||
return (entry&(1<<bit))>0;
|
||||
}
|
||||
|
||||
static void set_bmap_bit(uint32_t index,uint8_t* bitmap) {
|
||||
uint32_t byte=index/8;
|
||||
uint32_t bit=index%8;
|
||||
static void set_bmap_bit(size_t index,char* bitmap) {
|
||||
size_t byte=index/8;
|
||||
size_t bit=index%8;
|
||||
bitmap[byte]=bitmap[byte]|(1<<bit);
|
||||
}
|
||||
|
||||
void* read_blk(int blknum,FILE* f,int num) {
|
||||
void* block=malloc(sizeof(uint8_t)*blk_size[num]);
|
||||
char* read_blk(size_t blknum,FILE* f,int num) {
|
||||
char* block=malloc(sizeof(char)*blk_size[num]);
|
||||
fseek(f,blknum*blk_size[num],SEEK_SET);
|
||||
fread(block,1,sizeof(uint8_t)*blk_size[num],f);
|
||||
fread(block,1,sizeof(char)*blk_size[num],f);
|
||||
return block;
|
||||
}
|
||||
|
||||
void write_blk(int blknum,void* block,FILE* f,int num) {
|
||||
void write_blk(size_t blknum,char* block,FILE* f,int num) {
|
||||
fseek(f,blknum*blk_size[num],SEEK_SET);
|
||||
fwrite(block,1,sizeof(uint8_t)*blk_size[num],f);
|
||||
fwrite(block,1,sizeof(char)*blk_size[num],f);
|
||||
}
|
||||
|
||||
inode* read_inode(uint32_t inode_num,FILE* f,int num) {
|
||||
inode* read_inode(size_t inode_num,FILE* f,int num) {
|
||||
ext2_superblock supblk=supblks[num];
|
||||
uint32_t grp=(inode_num-1)/supblk.s_inodes_per_group;
|
||||
uint32_t index=(inode_num-1)%supblk.s_inodes_per_group;
|
||||
uint32_t starting_blk=blk_grps[num][grp].bg_inode_table;
|
||||
size_t grp=(inode_num-1)/supblk.s_inodes_per_group;
|
||||
size_t index=(inode_num-1)%supblk.s_inodes_per_group;
|
||||
size_t starting_blk=blk_grps[num][grp].bg_inode_table;
|
||||
size_t inodes_per_blk=blk_size[num]/sizeof(inode);
|
||||
uint32_t blk=starting_blk+(index/inodes_per_blk);
|
||||
uint32_t offset=index%inodes_per_blk;
|
||||
size_t blk=starting_blk+(index/inodes_per_blk);
|
||||
size_t offset=index%inodes_per_blk;
|
||||
inode* inodes=read_blk(blk,f,num);
|
||||
return &inodes[offset];
|
||||
}
|
||||
|
||||
void write_inode(uint32_t inode_num,inode* node,FILE* f,int num) {
|
||||
void write_inode(size_t inode_num,inode* node,FILE* f,int num) {
|
||||
ext2_superblock supblk=supblks[num];
|
||||
uint32_t grp=(inode_num-1)/supblk.s_inodes_per_group;
|
||||
uint32_t index=(inode_num-1)%supblk.s_inodes_per_group;
|
||||
uint32_t starting_blk=blk_grps[num][grp].bg_inode_table;
|
||||
size_t grp=(inode_num-1)/supblk.s_inodes_per_group;
|
||||
size_t index=(inode_num-1)%supblk.s_inodes_per_group;
|
||||
size_t starting_blk=blk_grps[num][grp].bg_inode_table;
|
||||
size_t inodes_per_blk=blk_size[num]/sizeof(inode);
|
||||
uint32_t blk=starting_blk+(index/inodes_per_blk);
|
||||
uint32_t offset=index%inodes_per_blk;
|
||||
size_t blk=starting_blk+(index/inodes_per_blk);
|
||||
size_t offset=index%inodes_per_blk;
|
||||
inode* inodes=read_blk(blk,f,num);
|
||||
inodes[offset]=*node;
|
||||
write_blk(blk,inodes,f,num);
|
||||
}
|
||||
|
||||
uint32_t reserve_inode(FILE* f,int num) {
|
||||
size_t reserve_inode(FILE* f,int num) {
|
||||
blk_grp* grps=blk_grps[num];
|
||||
for (uint32_t i=0;i<blk_grp_num[num];i++) {
|
||||
for (size_t i=0;i<blk_grp_num[num];i++) {
|
||||
if (grps[i].bg_free_inodes_count==0) {
|
||||
continue;
|
||||
}
|
||||
uint32_t starting_blk=grps[i].bg_inode_bitmap;
|
||||
uint32_t num_blks=((supblks[num].s_inodes_per_group/8)/blk_size[num])+1;
|
||||
uint8_t* bitmap=malloc(sizeof(uint8_t)*num_blks*blk_size[num]);
|
||||
for (uint32_t i=0;i<num_blks;i++) {
|
||||
size_t starting_blk=grps[i].bg_inode_bitmap;
|
||||
size_t num_blks=((supblks[num].s_inodes_per_group/8)/blk_size[num])+1;
|
||||
char* bitmap=malloc(sizeof(char)*num_blks*blk_size[num]);
|
||||
for (size_t i=0;i<num_blks;i++) {
|
||||
memcpy(&bitmap[i*blk_size[num]],read_blk(i+starting_blk,f,num),blk_size[num]);
|
||||
}
|
||||
uint32_t j;
|
||||
size_t j;
|
||||
for (j=0;j<supblks[num].s_inodes_per_group;j++) {
|
||||
if (get_bmap_bit(j,bitmap)==0) break;
|
||||
|
||||
@ -104,7 +104,7 @@ uint32_t reserve_inode(FILE* f,int num) {
|
||||
} else {
|
||||
klog("INFO","Inode reserved");
|
||||
}
|
||||
for (uint32_t i=0;i<num_blks;i++) {
|
||||
for (size_t i=0;i<num_blks;i++) {
|
||||
write_blk(i+starting_blk,&bitmap[i*blk_size[num]],f,num);
|
||||
}
|
||||
return (256*i)+j;
|
||||
@ -162,28 +162,28 @@ int read_char(inode* node,FILE* f,int pos,int num) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void append_char(inode* node,uint32_t inode_num,uint8_t c,FILE* f,int num) {
|
||||
void append_char(inode* node,size_t inode_num,char c,FILE* f,int num) {
|
||||
uint64_t size=get_sz(node,num);
|
||||
uint32_t blk_idx=size/blk_size[num];
|
||||
uint32_t offset=size%blk_size[num];
|
||||
size_t blk_idx=size/blk_size[num];
|
||||
size_t offset=size%blk_size[num];
|
||||
if (blk_idx>12||(node->i_block[blk_idx]==0)) return;
|
||||
uint32_t blk=node->i_block[blk_idx];
|
||||
uint8_t* block=read_blk(blk,f,num);
|
||||
size_t blk=node->i_block[blk_idx];
|
||||
char* block=read_blk(blk,f,num);
|
||||
block[offset]=c;
|
||||
write_blk(blk,block,f,num);
|
||||
inc_sz(node,num);
|
||||
write_inode(inode_num,node,f,num);
|
||||
}
|
||||
|
||||
int write_char(inode* node,uint8_t c,uint64_t pos,FILE* f,int num) {
|
||||
int write_char(inode* node,char c,uint64_t pos,FILE* f,int num) {
|
||||
uint64_t size=get_sz(node,num);
|
||||
uint32_t blk_idx=pos/blk_size[num];
|
||||
size_t blk_idx=pos/blk_size[num];
|
||||
if (pos>size) {
|
||||
if (blk_idx>12) {
|
||||
return EFBIG;
|
||||
} else {
|
||||
if (node->i_block[blk_idx]==0) {
|
||||
for (uint32_t i=0;i<=blk_idx;i++) {
|
||||
for (size_t i=0;i<=blk_idx;i++) {
|
||||
// node.i_block[blk_idx]=reserve_block(f,num);
|
||||
return 0;
|
||||
}
|
||||
@ -192,10 +192,10 @@ int write_char(inode* node,uint8_t c,uint64_t pos,FILE* f,int num) {
|
||||
}
|
||||
}
|
||||
}
|
||||
uint32_t offset=pos%blk_size[num];
|
||||
size_t offset=pos%blk_size[num];
|
||||
if (blk_idx>12||(node->i_block[blk_idx]==0)) return 0;
|
||||
uint32_t blk=node->i_block[blk_idx];
|
||||
uint8_t* block=read_blk(blk,f,num);
|
||||
size_t blk=node->i_block[blk_idx];
|
||||
char* block=read_blk(blk,f,num);
|
||||
block[offset]=c;
|
||||
write_blk(blk,block,f,num);
|
||||
return 0;
|
||||
@ -225,16 +225,16 @@ void* read_inode_contents(inode* node,FILE* f,int num) {
|
||||
return (void*)data;
|
||||
}
|
||||
|
||||
dir_entry* get_dir_listing(uint32_t inode_num,FILE* f,int num) {
|
||||
dir_entry* get_dir_listing(size_t inode_num,FILE* f,int num) {
|
||||
dir_entry* entries=malloc(sizeof(dir_entry)*100);
|
||||
int num_entries_used=0;
|
||||
int max_len=100;
|
||||
inode* dir_inode=read_inode(inode_num,f,num);
|
||||
uint32_t size=dir_inode->i_size;
|
||||
uint32_t tot_size=0;
|
||||
size_t size=dir_inode->i_size;
|
||||
size_t tot_size=0;
|
||||
ext2_dir_entry* dir=read_inode_contents(dir_inode,f,num);
|
||||
ext2_dir_entry* current_entry=dir;
|
||||
for(int i=0;tot_size<size;i++) {
|
||||
for(size_t i=0;tot_size<size;i++) {
|
||||
if (current_entry->file_type==0) {
|
||||
break;
|
||||
}
|
||||
@ -267,14 +267,14 @@ void free_dir_listing(char** names) {
|
||||
// free(names);
|
||||
}
|
||||
|
||||
ext2_dir_entry* read_dir_entry(uint32_t inode_num,uint32_t dir_entry_num,FILE* f,int num) {
|
||||
ext2_dir_entry* read_dir_entry(size_t inode_num,size_t dir_entry_num,FILE* f,int num) {
|
||||
inode* dir_inode=read_inode(inode_num,f,num);
|
||||
uint32_t size=dir_inode->i_size;
|
||||
uint32_t tot_size=0;
|
||||
uint32_t ent_num=0;
|
||||
size_t size=dir_inode->i_size;
|
||||
size_t tot_size=0;
|
||||
size_t ent_num=0;
|
||||
ext2_dir_entry* dir=read_inode_contents(dir_inode,f,num);
|
||||
ext2_dir_entry* current_entry=dir;
|
||||
for(int i=0;tot_size<size;i++) {
|
||||
for(size_t i=0;tot_size<size;i++) {
|
||||
if (current_entry->file_type==0) {
|
||||
break;
|
||||
}
|
||||
@ -288,7 +288,7 @@ ext2_dir_entry* read_dir_entry(uint32_t inode_num,uint32_t dir_entry_num,FILE* f
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t inode_for_fname(uint32_t dir_inode_num, char* name, char* got_inode,FILE* f,int num) {
|
||||
size_t inode_for_fname(size_t dir_inode_num, char* name, char* got_inode,FILE* f,int num) {
|
||||
*got_inode=0;
|
||||
dir_entry* entries=get_dir_listing(dir_inode_num,f,num);
|
||||
for(int i=0;entries[i].inode!=0;i++) {
|
||||
@ -300,7 +300,7 @@ uint32_t inode_for_fname(uint32_t dir_inode_num, char* name, char* got_inode,FIL
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* fname_for_inode(uint32_t dir_inode_num, uint32_t inode_num,FILE* f,int num) {
|
||||
char* fname_for_inode(size_t dir_inode_num, size_t inode_num,FILE* f,int num) {
|
||||
for(int i=0;;i++) {
|
||||
ext2_dir_entry* entry=read_dir_entry(dir_inode_num,i,f,num);
|
||||
if (entry) {
|
||||
@ -323,7 +323,7 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
supblks=realloc(supblks,sizeof(ext2_superblock)*(max_mnts+32));
|
||||
blk_size=realloc(blk_size,sizeof(uint32_t)*(max_mnts+32));
|
||||
blk_grps=realloc(blk_grps,sizeof(blk_grp*)*(max_mnts+32));
|
||||
blk_grp_num=realloc(blk_grp_num,sizeof(uint32_t)*(max_mnts+32));
|
||||
blk_grp_num=realloc(blk_grp_num,sizeof(size_t)*(max_mnts+32));
|
||||
mnts=realloc(mnts,sizeof(char*)*(max_mnts+32));
|
||||
devs=realloc(devs,sizeof(char*)*(max_mnts+32));
|
||||
max_mnts+=32;
|
||||
@ -335,12 +335,12 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
supblks[num_mnts]=*supblk;
|
||||
blk_size[num_mnts]=1024<<(supblk->s_log_blk_size);
|
||||
double num_blk_grps_dbl=supblk->s_blocks_count/(double)supblk->s_blocks_per_group;
|
||||
uint32_t num_blk_grps=ceil(num_blk_grps_dbl);
|
||||
uint32_t num_blks=((sizeof(blk_grp)*num_blk_grps)/blk_size[num_mnts])+1;
|
||||
size_t num_blk_grps=ceil(num_blk_grps_dbl);
|
||||
size_t num_blks=((sizeof(blk_grp)*num_blk_grps)/blk_size[num_mnts])+1;
|
||||
blk_grps[num_mnts]=malloc(sizeof(uint8_t)*num_blks*1024);
|
||||
blk_grp_num[num_mnts]=num_blk_grps;
|
||||
char* data_ptr=(char*)(blk_grps[num_mnts]);
|
||||
for (uint32_t i=0;i<num_blks;i++) {
|
||||
for (size_t i=0;i<num_blks;i++) {
|
||||
memcpy(&data_ptr[i*blk_size[num_mnts]],read_blk(i+2,f,num_mnts),blk_size[num_mnts]);
|
||||
}
|
||||
fclose(f);
|
||||
@ -362,11 +362,11 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
}
|
||||
if (data) {
|
||||
FILE* f=fopen(devs[data->num],"r+");
|
||||
uint32_t inode_num=2;
|
||||
size_t inode_num=2;
|
||||
inode* node;
|
||||
for (char* tok=strtok(stream->path,"/");tok!=NULL;tok=strtok(NULL,"/")) {
|
||||
char got_inode;
|
||||
uint32_t temp_num=inode_for_fname(inode_num,tok,&got_inode,f,data->num);
|
||||
size_t temp_num=inode_for_fname(inode_num,tok,&got_inode,f,data->num);
|
||||
if (got_inode) {
|
||||
inode_num=temp_num;
|
||||
node=read_inode(inode_num,f,data->num);
|
||||
@ -457,7 +457,7 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
if (op==FSOP_PUTC) {
|
||||
file_info* data=stream->data;
|
||||
FILE* f=fopen(devs[data->num],"r+");
|
||||
write_char(data->inode,*((uint8_t*)data1),stream->pos,f,data->num);
|
||||
write_char(data->inode,*((char*)data1),stream->pos,f,data->num);
|
||||
return 1;
|
||||
}
|
||||
if (op==FSOP_CLOSE) {
|
||||
@ -470,7 +470,7 @@ void init_ext2() {
|
||||
supblks=malloc(sizeof(ext2_superblock)*32);
|
||||
blk_size=malloc(sizeof(uint32_t)*32);
|
||||
blk_grps=malloc(sizeof(blk_grp*)*32);
|
||||
blk_grp_num=malloc(sizeof(uint32_t)*32);
|
||||
blk_grp_num=malloc(sizeof(size_t)*32);
|
||||
mnts=malloc(sizeof(char*)*32);
|
||||
devs=malloc(sizeof(char*)*32);
|
||||
num_mnts=0;
|
||||
|
@ -5,9 +5,9 @@
|
||||
#include <string.h>
|
||||
|
||||
static char** names;
|
||||
static uint32_t* offsets;
|
||||
static long* offsets;
|
||||
static unsigned long* sizes;
|
||||
static uint32_t num_files;
|
||||
static size_t num_files;
|
||||
static FILE* initrd_fd;
|
||||
|
||||
static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
@ -16,7 +16,7 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
}
|
||||
if (op==FSOP_OPEN) {
|
||||
char file_exists=0;
|
||||
for (uint32_t i=0;i<num_files;i++) {
|
||||
for (size_t i=0;i<num_files;i++) {
|
||||
if (strcmp(names[i],stream->path)==0) {
|
||||
file_exists=1;
|
||||
}
|
||||
@ -24,7 +24,7 @@ static char drv(fs_op op,FILE* stream,void* data1,void* data2) {
|
||||
return file_exists;
|
||||
}
|
||||
if (op==FSOP_GETC) {
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<num_files;i++) {
|
||||
if (strcmp(names[i],stream->path)==0) {
|
||||
break;
|
||||
@ -52,15 +52,15 @@ void initrd_init() {
|
||||
klog("PANIC","Cannot open initrd!");
|
||||
for(;;) {}
|
||||
}
|
||||
uint32_t max_files=32;
|
||||
size_t max_files=32;
|
||||
num_files=0;
|
||||
names=malloc(sizeof(char*)*32);
|
||||
offsets=malloc(sizeof(uint32_t)*32);
|
||||
offsets=malloc(sizeof(long)*32);
|
||||
sizes=malloc(sizeof(long)*32);
|
||||
for (uint32_t i=0;i<1;i++) {
|
||||
for (size_t i=0;i<1;i++) {
|
||||
if (i==max_files) {
|
||||
names=realloc(names,sizeof(char*)*(max_files+32));
|
||||
offsets=realloc(offsets,sizeof(uint32_t)*(max_files+32));
|
||||
offsets=realloc(offsets,sizeof(long)*(max_files+32));
|
||||
sizes=realloc(sizes,sizeof(long)*(max_files+32));
|
||||
max_files+=32;
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ typedef struct {
|
||||
|
||||
static const char** part_devs=NULL;
|
||||
static partition** parts=NULL;
|
||||
static uint32_t num_part_devs=0;
|
||||
static uint32_t max_part_devs=0;
|
||||
static size_t num_part_devs=0;
|
||||
static size_t max_part_devs=0;
|
||||
|
||||
int drv(char* filename,int c,long pos,char wr) {
|
||||
int part_no;
|
||||
@ -38,14 +38,14 @@ int drv(char* filename,int c,long pos,char wr) {
|
||||
char* str=malloc(sizeof(char)*(strlen(filename)+1));
|
||||
strcpy(str,filename);
|
||||
str[strlen(str)-1]='\0';
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<num_part_devs;i++) {
|
||||
if (strcmp(part_devs[i]+5,str)==0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(str);
|
||||
uint32_t lba=pos/512;
|
||||
size_t lba=pos/512;
|
||||
int offset=pos%512;
|
||||
if (lba>parts[i][part_no].length) {
|
||||
klog("INFO","Outside partition boundary");
|
||||
@ -86,7 +86,7 @@ void load_parts(const char* path) {
|
||||
fread(parts[num_part_devs],sizeof(partition),4,f);
|
||||
for (int i=0;i<4;i++) {
|
||||
if (parts[num_part_devs][i].fs_id!=0) {
|
||||
klog("INFO","Found partition %d of type %x on sectors %d-%d ",i,(uint8_t)parts[num_part_devs][i].fs_id,parts[num_part_devs][i].start_lba,parts[num_part_devs][i].start_lba+parts[num_part_devs][i].length);
|
||||
klog("INFO","Found partition %d of type %x on sectors %d-%d ",i,(char)parts[num_part_devs][i].fs_id,parts[num_part_devs][i].start_lba,parts[num_part_devs][i].start_lba+parts[num_part_devs][i].length);
|
||||
char str[2];
|
||||
int_to_ascii(i+1,str);
|
||||
char* part_path=malloc(sizeof(char)*strlen(path)+2);
|
||||
|
16
stuff/vfs.c
16
stuff/vfs.c
@ -8,14 +8,14 @@
|
||||
|
||||
typedef struct _vfs_mapping_struct {
|
||||
char* mntpnt;
|
||||
uint32_t type;
|
||||
size_t type;
|
||||
struct _vfs_mapping_struct* next;
|
||||
} vfs_mapping;
|
||||
|
||||
static const char** drv_names;
|
||||
static fs_drv* drvs;
|
||||
static uint32_t max_drvs;
|
||||
static uint32_t next_drv_indx;
|
||||
static size_t max_drvs;
|
||||
static size_t next_drv_indx;
|
||||
static vfs_mapping* head_mapping;
|
||||
static vfs_mapping* tail_mapping;
|
||||
|
||||
@ -42,7 +42,7 @@ void init_vfs() {
|
||||
tail_mapping=NULL;
|
||||
}
|
||||
|
||||
uint32_t register_fs(fs_drv drv,const char* type) {
|
||||
size_t register_fs(fs_drv drv,const char* type) {
|
||||
if (next_drv_indx==max_drvs) {
|
||||
drvs=realloc(drvs,sizeof(fs_drv)*(max_drvs+32));
|
||||
drv_names=realloc(drv_names,sizeof(char*)*(max_drvs+32));
|
||||
@ -55,7 +55,7 @@ uint32_t register_fs(fs_drv drv,const char* type) {
|
||||
}
|
||||
|
||||
char mount(char* mntpnt,char* dev,char* type) {
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<next_drv_indx;i++) {
|
||||
const char* name=drv_names[i];
|
||||
if (strcmp(name,type)==0) {
|
||||
@ -90,7 +90,7 @@ FILE* fopen(const char* filename,const char* mode) {
|
||||
vfs_mapping* mnt=head_mapping;
|
||||
vfs_mapping* mntpnt=NULL;
|
||||
const char* path;
|
||||
uint32_t mntpnt_len=0;
|
||||
size_t mntpnt_len=0;
|
||||
for (;mnt!=NULL;mnt=mnt->next) {
|
||||
char* root=mnt->mntpnt;
|
||||
if (strlen(root)>mntpnt_len) {
|
||||
@ -232,7 +232,7 @@ size_t fwrite(void* buffer_ptr,size_t size,size_t count,FILE* stream) {
|
||||
char* buffer=(char*)buffer_ptr;
|
||||
size_t bytes=size*count;
|
||||
for (size_t i=0;i<bytes;i++) {
|
||||
int c=fputc((uint8_t)buffer[i],stream);
|
||||
int c=fputc((char)buffer[i],stream);
|
||||
if (c==EOF) {
|
||||
return (size_t)(i/size);
|
||||
}
|
||||
@ -288,7 +288,7 @@ int vfprintf(FILE* stream,const char* format,va_list arg) {
|
||||
break;
|
||||
}
|
||||
case 'x': {
|
||||
uint32_t i=va_arg(arg,uint32_t);
|
||||
unsigned int i=va_arg(arg,unsigned int);
|
||||
char str[11];
|
||||
str[0]='\0';
|
||||
hex_to_ascii(i,str);
|
||||
|
@ -1,12 +0,0 @@
|
||||
#ifndef GRUB_TEXT_FB_INFO_H
|
||||
#define GRUB_TEXT_FB_INFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
char* address;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
} text_fb_info;
|
||||
|
||||
#endif
|
@ -1,15 +1,15 @@
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define BLK_SZ 4096
|
||||
|
||||
void* alloc_memory(uint32_t num_pages);
|
||||
void alloc_memory_virt(uint32_t num_pages,void* addr);
|
||||
void* alloc_memory(int num_pages);
|
||||
void alloc_memory_virt(int num_pages,void* addr);
|
||||
void* new_address_space();
|
||||
void copy_data(void* cr3, void* data,uint32_t size,void* virt_addr);
|
||||
void* put_data(void* cr3, void* data,uint32_t size);
|
||||
void* map_phys(void* phys_addr,uint32_t num_pages);
|
||||
void copy_data(void* cr3, void* data,size_t size,void* virt_addr);
|
||||
void* put_data(void* cr3, void* data,size_t size);
|
||||
void* map_phys(void* phys_addr,size_t num_pages);
|
||||
|
||||
#endif
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef PTHREAD_H
|
||||
#define PTHREAD_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef uint32_t pthread_t;
|
||||
typedef pid_t pthread_t;
|
||||
typedef int pthread_attr_t; //Created as dummy
|
||||
|
||||
int pthread_create(pthread_t *restrict thread,
|
||||
|
@ -3,9 +3,8 @@
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define FILE uint32_t //We're using pointers to FILE even though it's a uint32_t so we can expand to a struct if needed
|
||||
#define FILE int //We're using pointers to FILE even though it's an int so we can expand to a struct if needed
|
||||
#define SEEK_CUR 1
|
||||
#define SEEK_END 2
|
||||
#define SEEK_SET 3
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define STDLIB_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
|
@ -11,7 +11,7 @@ char* strtok(const char* str, const char* delim);
|
||||
|
||||
char* strrev(char *str);
|
||||
void int_to_ascii(int n,char* str);
|
||||
void hex_to_ascii(int n, char* str);
|
||||
void hex_to_ascii(unsigned int n, char* str);
|
||||
void append(char* s, char n);
|
||||
void backspace(char* s);
|
||||
#endif
|
||||
|
@ -15,12 +15,12 @@ typedef enum ThreadState {
|
||||
#endif
|
||||
|
||||
void yield();
|
||||
void yieldToPID(uint32_t pid);
|
||||
void yieldToPID(pid_t pid);
|
||||
void createProcCr3(void* start,void* cr3);
|
||||
void createProcCr3Param(void* start,void* cr3,uint32_t param1,uint32_t param2);
|
||||
char isPrivleged(uint32_t pid);
|
||||
void createProcCr3Param(void* start,void* cr3,void* param1,void* param2);
|
||||
char isPrivleged(pid_t pid);
|
||||
void blockThread(ThreadState state);
|
||||
void unblockThread(pid_t pid,uint32_t tid);
|
||||
void unblockThread(pid_t pid,pid_t tid);
|
||||
|
||||
|
||||
#endif
|
||||
|
34
vfs/main.c
34
vfs/main.c
@ -10,7 +10,7 @@
|
||||
|
||||
typedef struct _vfs_mapping_struct {
|
||||
char* mntpnt;
|
||||
uint32_t type;
|
||||
size_t type;
|
||||
struct _vfs_mapping_struct* next;
|
||||
} vfs_mapping;
|
||||
|
||||
@ -18,30 +18,30 @@ typedef struct {
|
||||
vfs_mapping* mntpnt;
|
||||
char* path;
|
||||
char* mode;
|
||||
uint32_t pos;
|
||||
size_t pos;
|
||||
char error;
|
||||
void* fs_data;
|
||||
} vfs_file;
|
||||
|
||||
typedef struct {
|
||||
uint32_t fd;
|
||||
int fd;
|
||||
int max_len;
|
||||
} gets_data;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char* path;
|
||||
uint32_t type;
|
||||
size_t type;
|
||||
} mount_data;
|
||||
|
||||
static const char** drv_names;
|
||||
static uint32_t* drvs;
|
||||
static uint32_t max_drvs;
|
||||
static uint32_t num_drvs;
|
||||
static size_t max_drvs;
|
||||
static size_t num_drvs;
|
||||
static vfs_mapping* head_mapping;
|
||||
static vfs_mapping* tail_mapping;
|
||||
vfs_file* fd_tables[32768];
|
||||
uint16_t open_fds[32768];
|
||||
int open_fds[32768];
|
||||
uint32_t box;
|
||||
void** in_progress_data[32768];
|
||||
vfs_message* get_message(Message* msg) {
|
||||
@ -73,7 +73,7 @@ void init_vfs() {
|
||||
tail_mapping=NULL;
|
||||
}
|
||||
|
||||
uint32_t register_fs_intern(uint32_t drv,const char* type) {
|
||||
size_t register_fs_intern(uint32_t drv,const char* type) {
|
||||
if (num_drvs==max_drvs) {
|
||||
drvs=realloc(drvs,sizeof(uint32_t)*(max_drvs+32));
|
||||
drv_names=realloc(drv_names,sizeof(char*)*(max_drvs+32));
|
||||
@ -91,7 +91,7 @@ void vfs_fopen(vfs_message* vfs_msg,uint32_t from) {
|
||||
}
|
||||
vfs_mapping* mnt=head_mapping;
|
||||
vfs_mapping* mntpnt=NULL;
|
||||
uint32_t mntpnt_len=0;
|
||||
size_t mntpnt_len=0;
|
||||
for (;mnt!=NULL;mnt=mnt->next) {
|
||||
char* root=mnt->mntpnt;
|
||||
if (strlen(root)>mntpnt_len) {
|
||||
@ -127,7 +127,7 @@ void vfs_fopen_finish(vfs_message* vfs_msg,uint32_t from) {
|
||||
fd_tables[vfs_msg->orig_mbox]=malloc(PROC_FD_LIMIT*sizeof(vfs_file));
|
||||
open_fds[vfs_msg->orig_mbox]=0;
|
||||
}
|
||||
uint16_t fd=open_fds[vfs_msg->orig_mbox];
|
||||
int fd=open_fds[vfs_msg->orig_mbox];
|
||||
open_fds[vfs_msg->orig_mbox]++;
|
||||
fd_tables[vfs_msg->orig_mbox][fd].mntpnt=mntpnt;
|
||||
fd_tables[vfs_msg->orig_mbox][fd].path=malloc(sizeof(char)*(strlen(&vfs_msg->path[0])+1));
|
||||
@ -157,7 +157,7 @@ void vfs_puts(vfs_message* vfs_msg,uint32_t from) {
|
||||
vfs_msg->flags=2;
|
||||
return;
|
||||
}
|
||||
uint32_t fd=vfs_msg->fd;
|
||||
int fd=vfs_msg->fd;
|
||||
vfs_file file_info=fd_tables[from][fd];
|
||||
strcpy(&vfs_msg->path[0],file_info.path);
|
||||
strcpy(&vfs_msg->mode[0],file_info.mode);
|
||||
@ -172,13 +172,13 @@ void vfs_puts(vfs_message* vfs_msg,uint32_t from) {
|
||||
msg.msg=data;
|
||||
mailbox_send_msg(&msg);
|
||||
free(data);
|
||||
in_progress_data[from][vfs_msg->id]=malloc(sizeof(uint32_t));
|
||||
*((uint32_t*)in_progress_data[from][vfs_msg->id])=fd;
|
||||
in_progress_data[from][vfs_msg->id]=malloc(sizeof(int));
|
||||
*((int*)in_progress_data[from][vfs_msg->id])=fd;
|
||||
vfs_msg->flags=0;
|
||||
}
|
||||
|
||||
void vfs_puts_finish(vfs_message* vfs_msg,uint32_t from) {
|
||||
uint32_t fd=*((uint32_t*)in_progress_data[vfs_msg->orig_mbox][vfs_msg->id]);
|
||||
int fd=*((int*)in_progress_data[vfs_msg->orig_mbox][vfs_msg->id]);
|
||||
free(in_progress_data[vfs_msg->orig_mbox][vfs_msg->id]);
|
||||
fd_tables[vfs_msg->orig_mbox][fd].pos+=vfs_msg->data;
|
||||
vfs_msg->flags=0;
|
||||
@ -189,7 +189,7 @@ void vfs_puts_abort(vfs_message* vfs_msg,uint32_t from) {
|
||||
}
|
||||
|
||||
void vfs_gets(vfs_message* vfs_msg,uint32_t from) {
|
||||
uint32_t fd=vfs_msg->fd;
|
||||
int fd=vfs_msg->fd;
|
||||
vfs_file file_info=fd_tables[from][fd];
|
||||
strcpy(&vfs_msg->path[0],file_info.path);
|
||||
strcpy(&vfs_msg->mode[0],file_info.mode);
|
||||
@ -227,7 +227,7 @@ char* vfs_gets_finish(vfs_message* vfs_msg,uint32_t from) {
|
||||
return NULL;
|
||||
}
|
||||
vfs_msg->data=data->max_len;
|
||||
uint32_t fd=data->fd;
|
||||
int fd=data->fd;
|
||||
free(in_progress_data[vfs_msg->orig_mbox][vfs_msg->id]);
|
||||
fd_tables[vfs_msg->orig_mbox][fd].pos+=vfs_msg->data;
|
||||
vfs_msg->flags=0;
|
||||
@ -270,7 +270,7 @@ void vfs_mount(vfs_message* vfs_msg, uint32_t from) {
|
||||
return;
|
||||
}
|
||||
char found=0;
|
||||
uint32_t i;
|
||||
size_t i;
|
||||
for (i=0;i<num_drvs;i++) {
|
||||
if (strcmp(type,drv_names[i])==0) {
|
||||
found=1;
|
||||
|
@ -1,4 +1,3 @@
|
||||
#include <grub/text_fb_info.h>
|
||||
#include <mailboxes.h>
|
||||
#include <ipc/devfs.h>
|
||||
#include <ipc/vfs.h>
|
||||
@ -17,10 +16,7 @@ int main() {
|
||||
uint32_t box=mailbox_new(16,"vga");
|
||||
devfs_box=mailbox_find_by_name("devfs_driver");
|
||||
text_fb_info info;
|
||||
info.address=map_phys((void*)0xB8000,10);
|
||||
info.width=80;
|
||||
info.height=25;
|
||||
vga_init(info);
|
||||
vga_init();
|
||||
yield();
|
||||
devfs_message* msg_data=malloc(sizeof(devfs_message));
|
||||
msg_data->msg_type=DEVFS_REGISTER;
|
||||
|
@ -1,31 +0,0 @@
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t port_byte_in(uint16_t port) {
|
||||
uint8_t result;
|
||||
asm("in %%dx, %%al":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_byte_out(uint16_t port,uint8_t data) {
|
||||
asm("out %%al, %%dx":: "a"(data),"d"(port));
|
||||
}
|
||||
|
||||
uint16_t port_word_in(uint16_t port) {
|
||||
uint16_t result;
|
||||
asm("in %%dx, %%ax":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_word_out(uint16_t port,uint16_t data) {
|
||||
asm("out %%ax, %%dx":: "a" (data), "d" (port));
|
||||
}
|
||||
|
||||
uint32_t port_long_in(uint16_t port) {
|
||||
uint32_t result;
|
||||
asm("inl %%dx, %%eax":"=a"(result):"d"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void port_long_out(uint16_t port,uint32_t data) {
|
||||
asm("outl %%eax, %%dx":: "a" (data), "d" (port));
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
#ifndef PORTS_H
|
||||
#define PORTS_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t port_byte_in(uint16_t port);
|
||||
void port_byte_out(uint16_t port,uint8_t data);
|
||||
uint16_t port_word_in(uint16_t port);
|
||||
void port_word_out(uint16_t port,uint16_t data);
|
||||
uint32_t port_long_in(uint16_t port);
|
||||
void port_long_out(uint16_t port,uint32_t data);
|
||||
#endif
|
@ -1,6 +1,5 @@
|
||||
#include <grub/text_fb_info.h>
|
||||
#include "vga.h"
|
||||
#include "ports.h"
|
||||
#include <cpu/ports.h>
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include "vtconsole.h"
|
||||
@ -42,10 +41,10 @@ static void set_cursor(struct vtconsole* vtc, vtcursor_t* cur) {
|
||||
port_byte_out(0x3D5,(pos&0xFF00)>>8);
|
||||
}
|
||||
|
||||
void vga_init(text_fb_info framebuffer_info) {
|
||||
screen=framebuffer_info.address;
|
||||
width=framebuffer_info.width;
|
||||
height=framebuffer_info.height;
|
||||
void vga_init() {
|
||||
screen=map_phys((void*)0xB8000,10);
|
||||
width=80;
|
||||
height=25;
|
||||
console=vtconsole(width,height,vt_set_char,set_cursor);
|
||||
port_byte_out(0x3D4,0xA);
|
||||
port_byte_out(0x3D5,(port_byte_in(0x3D5)&0xC0)|14);
|
||||
|
Loading…
x
Reference in New Issue
Block a user