mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 15:08:21 +00:00
devman initial implementation
This commit is contained in:
+12
-10
@@ -53,7 +53,17 @@ void kmain(){
|
|||||||
vmm_init();
|
vmm_init();
|
||||||
|
|
||||||
alloc_init();
|
alloc_init();
|
||||||
|
|
||||||
|
acpi_init();
|
||||||
|
|
||||||
|
apic_init();
|
||||||
|
|
||||||
|
apic_lapicinit();
|
||||||
|
|
||||||
|
hpet_init();
|
||||||
|
|
||||||
|
arch_schedtimer_calibrate();
|
||||||
|
|
||||||
vfs_init();
|
vfs_init();
|
||||||
|
|
||||||
printf("Mounting tmpfs in /\n");
|
printf("Mounting tmpfs in /\n");
|
||||||
@@ -63,17 +73,9 @@ void kmain(){
|
|||||||
|
|
||||||
initrd_parse();
|
initrd_parse();
|
||||||
|
|
||||||
acpi_init();
|
devman_init();
|
||||||
|
|
||||||
apic_init();
|
|
||||||
|
|
||||||
apic_lapicinit();
|
|
||||||
|
|
||||||
pci_enumerate();
|
pci_enumerate();
|
||||||
|
|
||||||
hpet_init();
|
|
||||||
|
|
||||||
arch_schedtimer_calibrate();
|
|
||||||
|
|
||||||
smp_init();
|
smp_init();
|
||||||
|
|
||||||
|
|||||||
+6
-4
@@ -3,6 +3,7 @@
|
|||||||
#include <hashtable.h>
|
#include <hashtable.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <kernel/devman.h>
|
||||||
|
|
||||||
dirnode_t* vfsroot;
|
dirnode_t* vfsroot;
|
||||||
hashtable fsfuncs;
|
hashtable fsfuncs;
|
||||||
@@ -66,8 +67,9 @@ int vfs_write(int* error, vnode_t* node, void* buff, size_t count, size_t offset
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
||||||
*error = ENOSYS;
|
int writecount = devman_write(error, node->st.st_rdev, buff, count, offset);
|
||||||
return -1; // TODO change this when the device manager is implemented :)
|
|
||||||
|
return writecount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
int writecount = node->fs->calls->write(error, node, buff, count, offset);
|
||||||
@@ -86,8 +88,8 @@ int vfs_read(int* error, vnode_t* node, void* buff, size_t count, size_t offset)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
if(type == TYPE_BLOCKDEV || type == TYPE_CHARDEV){
|
||||||
*error = ENOSYS;
|
int readcount = devman_read(error, node->st.st_rdev, buff, count, offset);
|
||||||
return -1; // TODO change this when the device manager is implemented :)
|
return readcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
int readcount = node->fs->calls->read(error, node, buff, count, offset);
|
int readcount = node->fs->calls->read(error, node, buff, count, offset);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
void* alloc(size_t);
|
void* alloc(size_t);
|
||||||
void free(void*);
|
void free(void*);
|
||||||
|
void* realloc(void*, size_t);
|
||||||
|
|
||||||
void alloc_init();
|
void alloc_init();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef _DEVMAN_H_INCLUDE
|
||||||
|
#define _DEVMAN_H_INCLUDE
|
||||||
|
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
int (*read)(int* error, int minor, void* buff, size_t count, size_t offset);
|
||||||
|
int (*write)(int* error, int minor, void* buff, size_t count, size_t offset);
|
||||||
|
} devcalls;
|
||||||
|
|
||||||
|
int devman_read(int *error, int dev, void* buff, size_t count, size_t offset);
|
||||||
|
int devman_write(int *error, int dev, void* buff, size_t count, size_t offset);
|
||||||
|
int devman_newdevice(char* name, int type, int major, int minor, devcalls* calls);
|
||||||
|
void devman_init();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#include <kernel/devman.h>
|
||||||
|
#include <kernel/vfs.h>
|
||||||
|
#include <kernel/devfs.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <kernel/alloc.h>
|
||||||
|
#include <sys/sysmacros.h>
|
||||||
|
#include <arch/panic.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
static devcalls** majorcalls;
|
||||||
|
static size_t highestmajor = 0;
|
||||||
|
|
||||||
|
int devman_newdevice(char* name, int type, int major, int minor, devcalls* calls){
|
||||||
|
|
||||||
|
if(major > highestmajor){
|
||||||
|
void* addr = realloc(majorcalls, major*sizeof(devcalls*)+1);
|
||||||
|
if(!addr)
|
||||||
|
return ENOMEM;
|
||||||
|
majorcalls = addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
majorcalls[major] = calls;
|
||||||
|
|
||||||
|
return devfs_newdevice(name, type, makedev(major, minor), 0777);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int devman_write(int *error, int dev, void* buff, size_t count, size_t offset){
|
||||||
|
|
||||||
|
if(major(dev) > highestmajor)
|
||||||
|
return ENODEV;
|
||||||
|
|
||||||
|
|
||||||
|
return majorcalls[major(dev)]->write(error, minor(dev), buff, count, offset);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int devman_read(int *error, int dev, void* buff, size_t count, size_t offset){
|
||||||
|
|
||||||
|
if(major(dev) > highestmajor)
|
||||||
|
return ENODEV;
|
||||||
|
|
||||||
|
|
||||||
|
return majorcalls[major(dev)]->read(error, minor(dev), buff, count, offset);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void devman_init(){
|
||||||
|
|
||||||
|
devfs_init();
|
||||||
|
|
||||||
|
size_t err = vfs_mkdir(vfs_root(), "dev", 0777);
|
||||||
|
if(err && err != EEXIST){
|
||||||
|
printf("Failed to mkdir /dev: %lu\n", err);
|
||||||
|
_panic("Devman initialization failed", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = vfs_mount(vfs_root(), NULL, "dev", "devfs", 0, NULL);
|
||||||
|
|
||||||
|
if(err){
|
||||||
|
printf("Failed to mount devfs in /dev: %lu\n", err);
|
||||||
|
_panic("Devman initialization failed", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("devfs mounted in /dev\n");
|
||||||
|
|
||||||
|
majorcalls = alloc(sizeof(devcalls*));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include <kernel/alloc.h>
|
#include <kernel/alloc.h>
|
||||||
#include <kernel/slab.h>
|
#include <kernel/slab.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void* alloc(size_t size){
|
void* alloc(size_t size){
|
||||||
return slab_alloc(size);
|
return slab_alloc(size);
|
||||||
@@ -12,3 +13,16 @@ void free(void* addr){
|
|||||||
void alloc_init(){
|
void alloc_init(){
|
||||||
slab_init();
|
slab_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* realloc(void* addr, size_t size){
|
||||||
|
void* tmp = alloc(size);
|
||||||
|
if(!tmp)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
memcpy(tmp, addr, size);
|
||||||
|
|
||||||
|
free(addr);
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user