summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Source/Kernel/Core/common.wtf.h10
-rw-r--r--Source/Kernel/Core/cppsupport.wtf.cpp37
-rw-r--r--Source/Kernel/Core/kmain.wtf.cpp10
-rw-r--r--Source/Kernel/Core/types.wtf.h19
-rw-r--r--Source/Kernel/Makefile2
-rwxr-xr-xSource/Kernel/Melon.kebin111884 -> 112107 bytes
-rw-r--r--Source/Kernel/VFS/Partition.class.cpp41
-rw-r--r--Source/Kernel/VFS/Partition.class.h4
8 files changed, 107 insertions, 16 deletions
diff --git a/Source/Kernel/Core/common.wtf.h b/Source/Kernel/Core/common.wtf.h
index d3e5abe..ac541d6 100644
--- a/Source/Kernel/Core/common.wtf.h
+++ b/Source/Kernel/Core/common.wtf.h
@@ -7,15 +7,7 @@
#define NULL 0
-typedef unsigned int addr_t;
-typedef unsigned long long u64int;
-typedef unsigned int u32int;
-typedef unsigned short u16int;
-typedef unsigned char u8int;
-typedef long long s64int;
-typedef int s32int;
-typedef short s16int;
-typedef char s8int;
+#include <Core/types.wtf.h>
#include <Core/CMem.ns.h>
#include <Core/Sys.ns.h>
diff --git a/Source/Kernel/Core/cppsupport.wtf.cpp b/Source/Kernel/Core/cppsupport.wtf.cpp
index d495dff..16cd122 100644
--- a/Source/Kernel/Core/cppsupport.wtf.cpp
+++ b/Source/Kernel/Core/cppsupport.wtf.cpp
@@ -1,6 +1,43 @@
//This file just contains a few methods required for some C++ things to work
+#include <Core/types.wtf.h>
extern "C" void __cxa_pure_virtual() {} //Required when using abstract classes
void *__dso_handle; //Required when using global objects
extern "C" int __cxa_atexit(void (*f)(void*), void *p, void *d) { return 0; }
+
+//Functions for quad divisions/modulo. Taken and arranged from klibc include/asm/div64.h
+//These only work with 32-bit divisors and only return 32-bit remainder.
+//TODO : think of some correct quad div/mod algorithms
+extern "C" {
+inline u64int doDiv(u64int dividend, u32int divisor, u32int *remainder) {
+ union {
+ u64int v64;
+ u32int v32[2];
+ } d = { dividend };
+ u32int upper;
+
+ upper = d.v32[1];
+ d.v32[1] = 0;
+ if (upper >= divisor) {
+ d.v32[1] = upper / divisor;
+ upper %= divisor;
+ }
+ asm ("divl %2" : "=a" (d.v32[0]), "=d" (*remainder) :
+ "rm" (divisor), "0" (d.v32[0]), "1" (upper));
+ return d.v64;
+}
+
+u64int __udivdi3(u64int dividend, u64int b) {
+ u32int divisor, remainder;
+ divisor = b;
+ return doDiv(dividend, divisor, &remainder);
+}
+
+u64int __umoddi3(u64int dividend, u64int b) {
+ u32int divisor, remainder;
+ divisor = b;
+ doDiv(dividend, divisor, &remainder);
+ return remainder;
+}
+}
diff --git a/Source/Kernel/Core/kmain.wtf.cpp b/Source/Kernel/Core/kmain.wtf.cpp
index a657cac..cac2da9 100644
--- a/Source/Kernel/Core/kmain.wtf.cpp
+++ b/Source/Kernel/Core/kmain.wtf.cpp
@@ -88,8 +88,7 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
PROCESSING(kvt, "Creating heap...");
Mem::createHeap(); OK(kvt);
- INFO(kvt); *kvt << "Free frames : " << (s32int)PhysMem::free() << "/" <<
- (s32int)PhysMem::total() << "\n";
+ INFO(kvt); *kvt << "Free frames : " << (s32int)PhysMem::free() << "/" << (s32int)PhysMem::total() << "\n";
PROCESSING(kvt, "Registering vgaout...");
Dev::registerDevice(vgaout); OK(kvt);
@@ -145,14 +144,14 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
} else if (tmp == "uptime") {
*kvt << " - Uptime : " << (s32int)(Time::uptime()) << "s.\n";
} else if (tmp == "part") {
- *kvt << " * Dev ID\tClass Name\n";
+ *kvt << " * ID\tClass Name\n";
for (u32int i = 0; i < Part::devices.size(); i++) {
- *kvt << " - " << (s32int)i << "\t\t";
+ *kvt << " - " << (s32int)i << "\t";
if (Part::devices[i] == 0) {
*kvt << "[none]\n";
} else {
*kvt << Part::devices[i]->getClass();
- kvt->setCursorCol(41);
+ kvt->setCursorCol(33);
*kvt << Part::devices[i]->getName() << "\n";
for (u32int j = 0; j < Part::partitions.size(); j++) {
if (Part::partitions[j]->getDevice() == Part::devices[i]) {
@@ -162,7 +161,6 @@ void kmain(multiboot_info_t* mbd, u32int magic) {
}
}
}
- *kvt << "\n";
}
} else if (!tmp.empty()) {
*kvt << " - Unrecognized command: " << tmp << "\n";
diff --git a/Source/Kernel/Core/types.wtf.h b/Source/Kernel/Core/types.wtf.h
new file mode 100644
index 0000000..ca6f73d
--- /dev/null
+++ b/Source/Kernel/Core/types.wtf.h
@@ -0,0 +1,19 @@
+#ifndef DEF_TYPES_WTF_H
+#define DEF_TYPES_WTF_H
+
+//This file defines base types. It's made to be used also by C programs
+
+typedef unsigned int addr_t;
+typedef unsigned long long u64int;
+typedef unsigned int u32int;
+typedef unsigned short u16int;
+typedef unsigned char u8int;
+typedef long long s64int;
+typedef int s32int;
+typedef short s16int;
+typedef char s8int;
+
+#define U64 unsigned long long
+#define S64 long long
+
+#endif
diff --git a/Source/Kernel/Makefile b/Source/Kernel/Makefile
index c0bb18b..87f1594 100644
--- a/Source/Kernel/Makefile
+++ b/Source/Kernel/Makefile
@@ -4,7 +4,7 @@ CC = gcc
CXX = g++
LD = ld
LDFLAGS = -T Link.ld -Map Map.txt --oformat=elf32-i386
-CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -Werror
+CFLAGS = -nostdlib -nostartfiles -nodefaultlibs -fno-builtin -fno-stack-protector -Wall -Wextra -Werror -I .
CXXFLAGS = -nostartfiles -nostdlib -fno-exceptions -fno-rtti -I . -Wall -Werror -Wno-write-strings -funsigned-char
ASM = nasm
ASMFLAGS = -f elf
diff --git a/Source/Kernel/Melon.ke b/Source/Kernel/Melon.ke
index a244f2c..c643803 100755
--- a/Source/Kernel/Melon.ke
+++ b/Source/Kernel/Melon.ke
Binary files differ
diff --git a/Source/Kernel/VFS/Partition.class.cpp b/Source/Kernel/VFS/Partition.class.cpp
index 0c7832b..1032dee 100644
--- a/Source/Kernel/VFS/Partition.class.cpp
+++ b/Source/Kernel/VFS/Partition.class.cpp
@@ -17,6 +17,47 @@ bool Partition::writeBlocks(u64int startblock, u32int count, u8int *data) {
return m_device->writeBlocks(startblock - m_startblock, count, data);
}
+bool Partition::read(u64int start, u32int length, u8int *data) {
+ u32int blksz = m_device->blockSize();
+ u64int startBlock = start / blksz;
+ u32int offset = start % blksz;
+ u32int blocks = (length + offset) / blksz;
+ if ((length + offset) % blksz != 0) blocks++;
+
+ u8int* buff = new u8int [blocks * blksz]; //THIS MAY FAIL :D
+ if (buff == 0) return false;
+
+ if (!readBlocks(startBlock, blocks, buff)) return false;
+ memcpy(data, buff + offset, length);
+
+ delete [] buff;
+ return true;
+}
+
+bool Partition::write(u64int start, u32int length, u8int *data) {
+ u32int blksz = m_device->blockSize();
+ u64int startBlock = start / blksz;
+ u32int offset = start % blksz;
+ u32int blocks = (length + offset) / blksz;
+ if ((length + offset) % blksz != 0) blocks++;
+ u64int lastBlock = startBlock + (u64int)blocks - 1;
+
+ u8int* buff = new u8int [blocks * blksz];
+ if (buff == 0) return false;
+
+ if (offset != 0) {
+ if (!readBlocks(startBlock, 1, buff)) return false;
+ }
+ if (lastBlock != startBlock and (length + offset) % blksz != 0) {
+ if (!readBlocks(lastBlock, 1, buff + ((blocks - 1) * blksize))) return false;
+ }
+ memcpy(buff + offset, data, length);
+ if (!writeBlocks(startBlock, blocks, buff)) return false;
+
+ delete[] buff;
+ return true;
+}
+
//Accessors
BlockDevice* Partition::getDevice() { return m_device; }
u64int Partition::getStartBlock() { return m_startblock; }
diff --git a/Source/Kernel/VFS/Partition.class.h b/Source/Kernel/VFS/Partition.class.h
index e9087bf..8df1c4f 100644
--- a/Source/Kernel/VFS/Partition.class.h
+++ b/Source/Kernel/VFS/Partition.class.h
@@ -15,6 +15,10 @@ class Partition {
bool readBlocks(u64int startblock, u32int count, u8int *data);
bool writeBlocks(u64int startblock, u32int count, u8int *data);
+ //These two just use the readBlocks && writeBlocks defined above
+ bool read(u64int start, u32int length, u8int *data);
+ bool write(u64int start, u32int length, u8int *data);
+
//Accessors :
BlockDevice* getDevice();
u64int getStartBlock();