Added a very small ATA detector. More to come
This commit is contained in:
parent
94c41a2359
commit
0dc8692443
11 changed files with 116 additions and 21 deletions
|
@ -4,5 +4,7 @@ install:
|
||||||
- wget --secure-protocol=TLSv1 dark32.cf/crosscomp-x64.tar.xz
|
- wget --secure-protocol=TLSv1 dark32.cf/crosscomp-x64.tar.xz
|
||||||
- tar -xf crosscomp-x64.tar.xz
|
- tar -xf crosscomp-x64.tar.xz
|
||||||
- popd
|
- popd
|
||||||
script: make
|
script:
|
||||||
after_success: curl --ftp-create-dirs -T mtgos -u $USER:$PASS ftp://dark32.cf/
|
- make
|
||||||
|
- mv mtgos mtgos-i686
|
||||||
|
after_success: curl --ftp-create-dirs -T mtgos-i686 -u $USER:$PASS ftp://dark32.cf/
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
set -o errexit
|
|
||||||
CROSSPATH=$HOME/opt # You can change it to whatever you want
|
CROSSPATH=$HOME/opt # You can change it to whatever you want
|
||||||
export PATH=$CROSSPATH/bin:$PATH
|
export PATH=$CROSSPATH/bin:$PATH
|
||||||
mkdir $CROSSPATH
|
mkdir $CROSSPATH
|
||||||
|
set -o errexit
|
||||||
function buildscript() {
|
function buildscript() {
|
||||||
echo "[$(date +%c)] Building binutils for $1." | tee -a buildlog
|
echo "[$(date +%c)] Building binutils for $1." | tee -a buildlog
|
||||||
mkdir build-binutils
|
mkdir build-binutils
|
||||||
|
|
|
@ -5,8 +5,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||||
CPP = $(PREFIX)g++
|
CPP = $(PREFIX)g++
|
||||||
CC = $(PREFIX)gcc
|
CC = $(PREFIX)gcc
|
||||||
ASFLAGS = -m32
|
ASFLAGS = -m32
|
||||||
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
|
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
|
||||||
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpie
|
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fno-pie
|
||||||
LDFLAGS = -r -melf_i386
|
LDFLAGS = -r -melf_i386
|
||||||
|
|
||||||
|
|
||||||
|
|
69
kernel/hal/x86/blk/BlockDevice.cpp
Normal file
69
kernel/hal/x86/blk/BlockDevice.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#include <base.hpp>
|
||||||
|
#include <blockdev.hpp>
|
||||||
|
#include <io.h>
|
||||||
|
#include <textDISP.hpp>
|
||||||
|
#include <string.h>
|
||||||
|
#define ATAPIO_ERR 0x01
|
||||||
|
#define ATAPIO_DRQ 0x08
|
||||||
|
#define ATAPIO_SRV 0x10
|
||||||
|
#define ATAPIO_DF 0x20
|
||||||
|
#define ATAPIO_RDY 0x40
|
||||||
|
#define ATAPIO_BSY 0x80
|
||||||
|
#define DATA 0
|
||||||
|
#define ATAPI_RESV 1
|
||||||
|
#define SECTOR_CNT 2
|
||||||
|
#define LBAlo 3
|
||||||
|
#define LBAmid 4
|
||||||
|
#define LBAhi 5
|
||||||
|
#define DRV 6
|
||||||
|
#define CMD 7
|
||||||
|
namespace MTGosHAL {
|
||||||
|
uint16_t ataports[4]={0x1F0,0x170,0x1E8,0x168};
|
||||||
|
uint16_t commports[4]={0x3F6,0x376,0x3E6,0x366};
|
||||||
|
BlockDevice::BlockDevice(): numDevices(0), existent(0) {
|
||||||
|
for(int i=0;i<4;i++) {
|
||||||
|
if(inb(ataports[i]+CMD)!=0xFF) {
|
||||||
|
outb(ataports[i]+DRV, 0xE0);
|
||||||
|
outb(ataports[i]+LBAlo,0x55);
|
||||||
|
if(inb(ataports[i]+LBAlo)==0x55) {
|
||||||
|
existent|=1<<(i<<1);
|
||||||
|
numDevices++;
|
||||||
|
}
|
||||||
|
outb(ataports[i]+DRV, 0xF0);
|
||||||
|
outb(ataports[i]+LBAlo,0x55);
|
||||||
|
if(inb(ataports[i]+LBAlo)==0x55) {
|
||||||
|
existent|=1<<((i<<1)+1);
|
||||||
|
numDevices++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(numDevices==0) {
|
||||||
|
err<<"Not a single device was found!\n";
|
||||||
|
}
|
||||||
|
for(int i=0;i<8;i++) {
|
||||||
|
if(!(existent&(1<<i)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto BlockDevice::getDriveCnt() -> uint8_t {return numDevices;}
|
||||||
|
auto BlockDevice::getDriveNumByName(const char * name) -> uint8_t {
|
||||||
|
if(strlen(name)!=5)
|
||||||
|
return -1; //Format is ATA[0-3][sl] (regex)
|
||||||
|
if((name[0]!=name[2])||(name[2]!='A'))
|
||||||
|
return -1;
|
||||||
|
if(name[1]!='T')
|
||||||
|
return -1;
|
||||||
|
uint8_t drivenum=name[3]-0x30;
|
||||||
|
if(drivenum>3)
|
||||||
|
return -1;
|
||||||
|
if((name[4]!='s')&&(name[4]!='l'))
|
||||||
|
return -1;
|
||||||
|
drivenum<<=1;
|
||||||
|
drivenum+=(name[4]=='s')?1:0;
|
||||||
|
if(!(existent&(1<<drivenum)))
|
||||||
|
return -1;
|
||||||
|
return drivenum;
|
||||||
|
}
|
||||||
|
BlockDevice::~BlockDevice() {};
|
||||||
|
}
|
|
@ -1,49 +1,39 @@
|
||||||
#ifndef _IO_H
|
#ifndef _IO_H
|
||||||
#define _IO_H
|
#define _IO_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
static inline void outb(uint16_t port, uint8_t val) __attribute__((always_inline));
|
|
||||||
static inline void outb(uint16_t port, uint8_t val) {
|
static inline void outb(uint16_t port, uint8_t val) {
|
||||||
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
|
asm volatile("outb %0, %1" : : "a"(val), "Nd"(port));
|
||||||
}
|
}
|
||||||
static inline void outw(uint16_t port, uint16_t val) __attribute__((always_inline));
|
|
||||||
static inline void outw(uint16_t port, uint16_t val) {
|
static inline void outw(uint16_t port, uint16_t val) {
|
||||||
asm volatile("outw %0, %1" : : "a"(val), "Nd"(port));
|
asm volatile("outw %0, %1" : : "a"(val), "Nd"(port));
|
||||||
}
|
}
|
||||||
static inline void outl(uint16_t port, uint32_t val) __attribute__((always_inline));
|
|
||||||
static inline void outl(uint16_t port, uint32_t val) {
|
static inline void outl(uint16_t port, uint32_t val) {
|
||||||
asm volatile("outl %0, %1" : : "a"(val), "Nd"(port));
|
asm volatile("outl %0, %1" : : "a"(val), "Nd"(port));
|
||||||
}
|
}
|
||||||
static inline uint8_t inb(uint16_t port) __attribute__((always_inline));
|
|
||||||
static inline uint8_t inb(uint16_t port) {
|
static inline uint8_t inb(uint16_t port) {
|
||||||
uint8_t ret;
|
uint8_t ret;
|
||||||
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
|
asm volatile("inb %1, %0" : "=a"(ret) : "Nd"(port));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static inline uint16_t inw(uint16_t port) __attribute__((always_inline));
|
|
||||||
static inline uint16_t inw(uint16_t port) {
|
static inline uint16_t inw(uint16_t port) {
|
||||||
uint16_t ret;
|
uint16_t ret;
|
||||||
asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
|
asm volatile("inw %1, %0" : "=a"(ret) : "Nd"(port));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static inline uint32_t inl(uint16_t port) __attribute__((always_inline));
|
|
||||||
static inline uint32_t inl(uint16_t port) {
|
static inline uint32_t inl(uint16_t port) {
|
||||||
uint32_t ret;
|
uint32_t ret;
|
||||||
asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
|
asm volatile("inl %1, %0" : "=a"(ret) : "Nd"(port));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static inline void io_wait() __attribute__((always_inline));
|
|
||||||
static inline void io_wait() {
|
static inline void io_wait() {
|
||||||
asm volatile("outb %%al, $0x80" : : "a"(0));
|
asm volatile("outb %%al, $0x80" : : "a"(0));
|
||||||
}
|
}
|
||||||
static inline void cli() __attribute__((always_inline));
|
|
||||||
static inline void cli() {
|
static inline void cli() {
|
||||||
asm volatile("cli");
|
asm volatile("cli");
|
||||||
}
|
}
|
||||||
static inline void sti() __attribute__((always_inline));
|
|
||||||
static inline void sti() {
|
static inline void sti() {
|
||||||
asm volatile("sti");
|
asm volatile("sti");
|
||||||
}
|
}
|
||||||
static inline uint64_t rdtsc() __attribute__((always_inline));
|
|
||||||
static inline uint64_t rdtsc()
|
static inline uint64_t rdtsc()
|
||||||
{
|
{
|
||||||
uint64_t ret;
|
uint64_t ret;
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
#ifndef _STRING_H
|
#ifndef _STRING_H
|
||||||
#define _STRING_H
|
#define _STRING_H
|
||||||
#ifdef _cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
void memmove(void* dst, void* src, uint32_t size);
|
void memmove(void* dst, void* src, uint32_t size);
|
||||||
#ifdef _cplusplus
|
uint32_t strlen(const char* str);
|
||||||
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace MTGosHAL {
|
||||||
class GDT;
|
class GDT;
|
||||||
class IDT;
|
class IDT;
|
||||||
class Multitasking;
|
class Multitasking;
|
||||||
|
class BlockDevice;
|
||||||
enum class BG_color: uint16_t;
|
enum class BG_color: uint16_t;
|
||||||
enum class FG_color: uint16_t;
|
enum class FG_color: uint16_t;
|
||||||
extern Serial debug;
|
extern Serial debug;
|
||||||
|
@ -19,5 +20,6 @@ namespace MTGosHAL {
|
||||||
extern GDT gdt;
|
extern GDT gdt;
|
||||||
extern IDT idt;
|
extern IDT idt;
|
||||||
extern Multitasking tasks;
|
extern Multitasking tasks;
|
||||||
|
extern BlockDevice disk;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
21
kernel/hal/x86/include/blockdev.hpp
Normal file
21
kernel/hal/x86/include/blockdev.hpp
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef __HAL_BLOCKDEV_HPP
|
||||||
|
#define __HAL_BLOCKDEV_HPP
|
||||||
|
#include <stdint.h>
|
||||||
|
namespace MTGosHAL {
|
||||||
|
class BlockDevice {
|
||||||
|
private:
|
||||||
|
uint8_t numDevices;
|
||||||
|
uint8_t existent; //Bitmap showing which of the up to 8 drives are actually existent.
|
||||||
|
public:
|
||||||
|
BlockDevice();
|
||||||
|
~BlockDevice();
|
||||||
|
auto getDriveCnt() -> uint8_t;
|
||||||
|
auto getDriveNumByName(const char *) -> uint8_t; //Returns -1 if device is not existent
|
||||||
|
auto readSector(uint32_t drv, uint64_t sectorNum, uint8_t *buf); //Has to be at least 512 bytes big!
|
||||||
|
auto readSectors(uint32_t drv, uint64_t sectorNum, uint32_t num, uint8_t *buf); //Has to be at least num*512 bytes big!
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* end of include guard: __HAL_BLOCKDEV_HPP */
|
|
@ -7,6 +7,7 @@
|
||||||
#include <keyboard.hpp>
|
#include <keyboard.hpp>
|
||||||
#include <Multitasking.h>
|
#include <Multitasking.h>
|
||||||
#include <multiboot.h>
|
#include <multiboot.h>
|
||||||
|
#include <blockdev.hpp>
|
||||||
extern "C" void intr_stub_0(void);
|
extern "C" void intr_stub_0(void);
|
||||||
void main();
|
void main();
|
||||||
namespace MTGosHAL {
|
namespace MTGosHAL {
|
||||||
|
@ -17,6 +18,7 @@ namespace MTGosHAL {
|
||||||
IDT idt;
|
IDT idt;
|
||||||
GDT gdt;
|
GDT gdt;
|
||||||
Multitasking tasks;
|
Multitasking tasks;
|
||||||
|
BlockDevice disk;
|
||||||
void main(int eax, struct multiboot_info* ebx) {
|
void main(int eax, struct multiboot_info* ebx) {
|
||||||
out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n";
|
||||||
err << BG_color::BLACK << FG_color::RED;
|
err << BG_color::BLACK << FG_color::RED;
|
||||||
|
@ -59,4 +61,3 @@ extern "C" void init(int eax, struct multiboot_info* ebx) {
|
||||||
extern "C" void __cxa_pure_virtual() {
|
extern "C" void __cxa_pure_virtual() {
|
||||||
MTGosHAL::debug << "A pure virtual function just got called.\n";
|
MTGosHAL::debug << "A pure virtual function just got called.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,13 @@ void memmove(void* dst, void* src, uint32_t size) {
|
||||||
to[i]=from[i]; //This would get optimized by gcc to memmove(dst, src, size); if optimizations are enabled.
|
to[i]=from[i]; //This would get optimized by gcc to memmove(dst, src, size); if optimizations are enabled.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
uint32_t strlen(const char* str) {
|
||||||
|
uint32_t i=0;
|
||||||
|
char* str2=(char*)((int)str);
|
||||||
|
while(*str2) {
|
||||||
|
i++;
|
||||||
|
str2++;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
#pragma GCC pop_options
|
#pragma GCC pop_options
|
||||||
|
|
|
@ -4,8 +4,8 @@ OBJS = $(addsuffix .o,$(basename $(SRCS)))
|
||||||
CPP = $(PREFIX)g++
|
CPP = $(PREFIX)g++
|
||||||
CC = $(PREFIX)gcc
|
CC = $(PREFIX)gcc
|
||||||
ASFLAGS = -m32
|
ASFLAGS = -m32
|
||||||
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../hal/dummy/c_include -ffreestanding -march=native -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
|
CFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -Ic_include/ -I../hal/dummy/c_include -ffreestanding -std=c11 -fno-builtin -Werror -nostdlib -g -fpie
|
||||||
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../hal/dummy/include -I../hal/dummy/c_include -fno-rtti -fno-exceptions -ffreestanding -march=native -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpie
|
CPPFLAGS = -m32 -Wall -fno-stack-protector -nostdinc -std=c++14 -Iinclude/ -Ic_include/ -I../hal/dummy/include -I../hal/dummy/c_include -fno-rtti -fno-exceptions -ffreestanding -fno-builtin -Werror -nostdlib -fno-use-cxa-atexit -Wextra -Wno-unused -g -fpie
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
|
|
||||||
%.o: %.cpp
|
%.o: %.cpp
|
||||||
|
|
Loading…
Reference in a new issue