KraKern

C++ Kernel
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/KraKern

commit 1f13ddbbba83f2d66b5f6bbb999b25699690658b
parent 768dad6e9bb1ae9cadfd9b5fa93d417c7ddd4f6f
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon,  8 Feb 2016 21:35:51 +0100

Fix(Partitions): Now working

Diffstat:
Mincludes/core/IDE.hpp | 3++-
Mkern.img | 0
Mkernel/File.cpp | 3++-
Mkernel/IDE.cpp | 63++++++++++++++++++++++++++++++++-------------------------------
Mkernel/Io.cpp | 4++--
Mmodules/x86/ModuleExt2.cpp | 3+--
6 files changed, 39 insertions(+), 37 deletions(-)

diff --git a/includes/core/IDE.hpp b/includes/core/IDE.hpp @@ -23,12 +23,13 @@ class IDE { int read(u32 pos, u8 *buffer, u32 size); void get_partitions(void); + struct partition *get_part(int id); private: int _bl_write(int drive, int numblock, int count, char *buf); int _bl_read(int drive, int numblock, int count, char *buf); int _bl_common(int drive, int numblock, int count); - struct partition *_parts; + struct partition **_parts; }; # include <Kernel.hpp> diff --git a/kern.img b/kern.img Binary files differ. diff --git a/kernel/File.cpp b/kernel/File.cpp @@ -3,7 +3,8 @@ File::File(char *n, u8 t) { this->_name = (char *)__kern.mem.kmalloc(strlen(n) + 1); strcpy(this->_name, n); - this->_check_name(); + if (File::_inode_system) + this->_check_name(); this->_inode = File::_inode_system++; this->_size = 0; this->_type = t; diff --git a/kernel/IDE.cpp b/kernel/IDE.cpp @@ -10,76 +10,77 @@ IDE::~IDE(void) { return ; } -int IDE::read(u32 pos, u8 *buffer, u32 size) { - int count = size, offset = pos, bl_begin, bl_end, blocks; +int IDE::read(u32 offset, u8 *buf, u32 count) { char *bl_buffer; + int bl_begin, bl_end, blocks; - if (!buffer) - return -1; - bl_begin = (offset / 512); - bl_end = ((offset + count) / 512); + bl_begin = offset / 512; + bl_end = (offset + count) / 512; blocks = bl_end - bl_begin + 1; - bl_buffer = (char *)__kern.mem.kmalloc(blocks * 512); + bl_buffer = (char *) __kern.mem.kmalloc(blocks * 512); this->_bl_read(0, bl_begin, blocks, bl_buffer); - memcpy((char *)buffer, (char *)((int)bl_buffer + (offset % 512)), count); + memcpy(buf, (char *) (bl_buffer + offset % 512), count); __kern.mem.kfree(bl_buffer); return count; } int IDE::_bl_common(int drive, int numblock, int count) { - while(__kern.io.ibyte(0x1F0 + 0x206) & 0x80); __kern.io.obyte(0x1F1, 0x00); __kern.io.obyte(0x1F2, count); - __kern.io.obyte(0x1F3, numblock); - __kern.io.obyte(0xF14, numblock >> 8); - __kern.io.obyte(0xF15, numblock >> 16); + __kern.io.obyte(0x1F3, (unsigned char) numblock); + __kern.io.obyte(0x1F4, (unsigned char) (numblock >> 8)); + __kern.io.obyte(0x1F5, (unsigned char) (numblock >> 16)); __kern.io.obyte(0x1F6, 0xE0 | (drive << 4) | ((numblock >> 24) & 0x0F)); return 0; } int IDE::_bl_read(int drive, int numblock, int count, char *buf) { - u16 tmp; + u16 tmpword; + int idx; this->_bl_common(drive, numblock, count); __kern.io.obyte(0x1F7, 0x20); - while(__kern.io.ibyte(0x1F0 + 0x206) & 0x80); while (!(__kern.io.ibyte(0x1F7) & 0x08)); - for (int idx = 0; idx < 256 * count; idx++) { - tmp = __kern.io.iword(0x1F0); - buf[idx * 2] = tmp; - buf[idx * 2 + 1] = tmp >> 8; + for (idx = 0; idx < 256 * count; idx++) { + tmpword = __kern.io.iword(0x1F0); + buf[idx * 2] = (unsigned char) tmpword; + buf[idx * 2 + 1] = (unsigned char) (tmpword >> 8); } return count; } int IDE::_bl_write(int drive, int numblock, int count, char *buf) { - u16 tmp; + u16 tmpword; + int idx; this->_bl_common(drive, numblock, count); __kern.io.obyte(0x1F7, 0x30); - while(__kern.io.ibyte(0x1F0 + 0x206) & 0x80); while (!(__kern.io.ibyte(0x1F7) & 0x08)); - for (int idx = 0; idx < 256 * count; idx++) { - tmp = (buf[idx * 2 + 1] << 8) | buf[idx * 2]; - __kern.io.oword(0xF10, tmp); + for (idx = 0; idx < 256 * count; idx++) { + tmpword = (buf[idx * 2 + 1] << 8) | buf[idx * 2]; + __kern.io.oword(0x1F0, tmpword); } return count; } void IDE::get_partitions(void) { struct partition *tmp; - int disk[] = {0x01BE, 0x01CE, 0x01DE, 0x1EE}; - char str[15]; for (int i = 0; i < 4; i++) { tmp = (struct partition *)__kern.mem.kmalloc(sizeof(struct partition)); - this->read(disk[i] + i * sizeof(struct partition), (u8 *)tmp, sizeof(struct partition)); + this->read(0x01be + (i * sizeof(struct partition)), (u8 *)tmp, 16); if (tmp->size) { - __kern.io.puts("Found a partition ! size: "); - itoa(str, tmp->size, 10); - __kern.io.puts(str); - __kern.io.puts("\n"); + if (!this->_parts) { + this->_parts = (struct partition **)__kern.mem.kmalloc(sizeof(struct partition) * 5); + } + this->_parts[i] = tmp; } - tmp = 0x0; } + this->_parts[5] = 0x0; +} + +struct partition *IDE::get_part(int id) { + if (id < 0 || id > 4) + __kern.io.panic("IDE: get_part: Bad argument"); + return this->_parts[id]; } diff --git a/kernel/Io.cpp b/kernel/Io.cpp @@ -166,8 +166,8 @@ void Io::oline(u32 a, u32 v) { asmv("outl %%ax, %%dx" :: "d" (a), "a" (v));; }; // Input u8 Io::ibyte(u32 a) { u8 v; asmv("inb %%dx, %%al" : "=a" (v) : "d" (a)); return v; }; -u16 Io::iword(u32 a) { u16 v; asmv("inb %%dx, %%ax" : "=a" (v) : "d" (a)); return v; }; -u32 Io::iline(u32 a) { u32 v; asmv("inb %%dx, %%eax" : "=a" (v) : "d" (a)); return v; }; +u16 Io::iword(u32 a) { u16 v; asmv("inw %%dx, %%ax" : "=a" (v) : "d" (a)); return v; }; +u32 Io::iline(u32 a) { u32 v; asmv("inl %%dx, %%eax" : "=a" (v) : "d" (a)); return v; }; u32 Io::getX(void) { return (u32)this->_x; }; u32 Io::getY(void) { return (u32)this->_y; }; diff --git a/modules/x86/ModuleExt2.cpp b/modules/x86/ModuleExt2.cpp @@ -65,8 +65,7 @@ struct ext2_inode *ModuleExt2::_read_inode(struct disk *d, int i_num) { gr_num = (i_num - 1) / d->sb->s_inodes_per_group; index = (i_num - 1) & d->sb->s_inodes_per_group; offset = d->gd[gr_num].bg_inode_table * d->blocksize + index * d->sb->s_inode_size; - if (d->dev) - d->dev->read(offset, (u8 *)inode, d->sb->s_inode_size); + __kern.ide.read(__kern.ide.get_part(1)->s_lba * 512 + offset, (u8 *)inode, d->sb->s_inode_size); return inode; }