Working on ATA disk driver

This commit is contained in:
notsomeidiot123 2025-08-27 20:30:33 -04:00
parent e9db8f8f67
commit e711ddf15a
5 changed files with 99 additions and 7 deletions

3
.gitignore vendored
View File

@ -8,4 +8,5 @@ diskwrite
*.dump
intlog.*
*.img
.vscode
.vscode
bochsrc

View File

@ -9,7 +9,7 @@ OBJS := $(patsubst src/kernel/%.c, bin/kernel/%.o, $(SRCS))
all: bootloader tools kernel
cp bin/bootloader.bin image.bin
qemu-img resize -f raw image.bin 512M
qemu-img resize -f raw image.bin 64M
./diskwrite idm.elf ifsm.elf kernel.elf -o image.bin
sudo mount image.bin mount
sudo mkdir mount/mod # for kernel modules

View File

@ -1,10 +1,81 @@
#include<stdint.h>
#include "modlib.h"
#define MODULE_NAME "KIDM"
KOS_MAPI_FP api;
inline void outb(uint16_t port, uint8_t data){
asm volatile ("outb %0, %1" :: "a"(data), "Nd"(port));
}
inline void outw(uint16_t port, uint16_t data){
asm volatile ("outw %0, %1" :: "a"(data), "Nd"(port));
}
inline uint8_t inb(uint16_t port){
uint8_t byte = 0;
asm volatile ("inb %1, %0" : "=a"(byte) : "Nd"(port));
return byte;
}
inline uint16_t inw(uint16_t port){
uint16_t word = 0;
asm volatile ("inw %1, %0" : "=a"(word) : "Nd"(port));
return word;
}
/*
TODO:
Register module
IDENTIFY
CREATE ((virtual)) FILES
CREATE interface when reading and writing from virtual files
make fini function to destroy global object, and free any remaining resources.
*/
#define ATA_DATA + 0
#define ATA_ERROR + 1
#define ATA_FEATURES + 1
#define ATA_SECTOR_COUNT + 2
#define ATA_SECTOR_NUMBER + 3
#define ATA_CYLINDER_LOW + 4
#define ATA_CYLINDER_HIGH + 5
#define ATA_DRIVE_HEAD + 6
#define ATA_STATUS + 7
#define ATA_COMMAND + 7
#define ATA_LBA_LOW ATA_SECTOR_NUMBER
#define ATA_LBA_MID ATA_CYLINDER_LOW
#define ATA_LBA_HIH ATA_CYLINDER_HIGH
#define ATA_ALT_STATUS + 0
#define ATA_DEVICE_CONTROL + 0
#define ATA_DRIVE_ADDRESS + 1
#define ATA_IDENTIFY 0xEC
#define ATA_SLAVE_DRIVE 0xF0
#define ATA_MASTER_DRIVE 0xE0
#define ATA_IS_ATA(a) a[0] & 0x8000
#define ATA_GET_SZ28(a) (a[60] | (a[61] << 16))
#define ATA_IS_LBA48(a) (a[83] & (1 << 10))
#define ATA_GET_SZ48L(a) (a[100] | (a[101] << 16))
#define ATA_GET_SZ48H(a) (a[102] | (a[103] << 16))
void fini();
void ata_identify();
void init(KOS_MAPI_FP module_api, uint32_t api_version){
uint16_t *t = (void *)0xb8000;
*t = 0xf000;
api = module_api;
api(MODULE_API_PRINT, MODULE_NAME, "KIDM Storage Driver Module v0.1.0\nSupported interfaces: \n");
return;
}
void ata_identify(){
}
void fini(){
//destroy all objects, free memory, and
}

View File

@ -1,10 +1,14 @@
#include <stdint.h>
#include "modlib.h"
#define MODULE_NAME "KIFSM"
KOS_MAPI_FP api;
void init(KOS_MAPI_FP module_api, uint32_t api_version){
uint16_t *t = (void *)0xb8002;
*t = 0xf000;
api = module_api;
api(MODULE_API_PRINT, MODULE_NAME, "KIFSM Filesystem Driver Module v0.1.0\nSupported Filesystems:\n");
return;
}

View File

@ -1,6 +1,22 @@
#pragma once
#include <stdint.h>
typedef void (*KOS_MAPI_FP)(unsigned int function, ...);
#define MODULE_API_REGISTER 0 //registers the module as active using information provided from the module
#define MODULE_API_ADDFUNC 1 //adds function to kernel API handler
#define MODULE_API_DELFUNC 2 //delete function from kernel API handler
#define MODULE_API_ADDINT 3 //set interrupt handler
#define MODULE_API_DELINT 4 //delete interrupt handler
#define MODULE_API_PRINT 5 //print to terminal
#define MODULE_API_READ 6 //read from virtual file
#define MODULE_API_WRITE 7 //write to virtual file
#define MODULE_API_CREAT 8 //create a virtual file and assigns it to the the proper module (requires having a read and write function passed)
#define MODULE_API_DELET 9 //delete a virtual file
#define MODULE_API_MAP 10 //map physical address to virtual address
#define MODULE_API_UNMAP 11 //unmap physical address to virtual address
#define MODULE_API_MALLOC 12 //allocate memory in 4kb blocks
#define MODULE_API_FREE 13 //free memory allocated by malloc
typedef uint32_t (*KOS_MAPI_FP)(unsigned int function, ...);
typedef struct module{
void *init_entry;
uint32_t id;