From d95452c5452b4ca7418505fa5597f000596fcb78 Mon Sep 17 00:00:00 2001 From: Alexis211 Date: Sun, 6 Sep 2009 18:05:31 +0200 Subject: Added read() and write() functions to Partition:: These functions make it possible to read or write bytes on a partition without worrying of sectors. --- Source/Kernel/Core/common.wtf.h | 10 +--------- Source/Kernel/Core/cppsupport.wtf.cpp | 37 +++++++++++++++++++++++++++++++++++ Source/Kernel/Core/kmain.wtf.cpp | 10 ++++------ Source/Kernel/Core/types.wtf.h | 19 ++++++++++++++++++ 4 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 Source/Kernel/Core/types.wtf.h (limited to 'Source/Kernel/Core') 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 #include #include 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 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 -- cgit v1.2.3