diff options
author | Marvin Borner | 2021-01-08 22:49:54 +0100 |
---|---|---|
committer | Marvin Borner | 2021-01-08 22:49:54 +0100 |
commit | 45a9df836accd39cf2dbfbb2453496b0e4d93fa5 (patch) | |
tree | f2732f45d4b080644c1ab007be251c5b1eaf060e /kernel/inc | |
parent | 3ad1fce1671c25c5db85977588fd1ceee436e1ba (diff) |
Major IDE/ATA driver rewrite
This adds non-hardcoded multi-disk support. I just need to remove
the boot/load.c loader and fix the max bootloader ext2 loading size.
After that's done I'll try running it on real hardware.
Diffstat (limited to 'kernel/inc')
-rw-r--r-- | kernel/inc/fs.h | 10 | ||||
-rw-r--r-- | kernel/inc/ide.h | 84 |
2 files changed, 68 insertions, 26 deletions
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h index 06154e7..75cb49f 100644 --- a/kernel/inc/fs.h +++ b/kernel/inc/fs.h @@ -10,17 +10,22 @@ * Device */ +enum dev_type { DEV_BLOCK, DEV_CHAR }; + struct device { u32 id; const char *name; - int type; // TODO: Block, char device + enum dev_type type; struct vfs *vfs; + void *data; u32 (*read)(void *buf, u32 offset, u32 count, struct device *dev); u32 (*write)(void *buf, u32 offset, u32 count, struct device *dev); }; void device_install(void); +void device_add(struct device *dev); + /** * VFS */ @@ -42,6 +47,9 @@ struct mount_info { void vfs_install(void); +u32 vfs_path_mounted(const char *path); +u32 vfs_mount(struct device *dev, const char *path); + u32 vfs_read(const char *path, void *buf, u32 offset, u32 count); u32 vfs_write(const char *path, void *buf, u32 offset, u32 count); u32 vfs_stat(const char *path, struct stat *buf); diff --git a/kernel/inc/ide.h b/kernel/inc/ide.h index c145760..6e43ece 100644 --- a/kernel/inc/ide.h +++ b/kernel/inc/ide.h @@ -9,32 +9,66 @@ #define BLOCK_COUNT 256 // BLOCK_SIZE / sizeof(u32) #define SECTOR_SIZE 512 -#define IDE_BUSY (1 << 7) -#define IDE_READY (1 << 6) -#define IDE_DRIVE_FAULT (1 << 5) -#define IDE_ERROR (1 << 0) +#define ATA_PRIMARY_IO 0x1f0 +#define ATA_SECONDARY_IO 0x170 -#define IDE_IO 0x1F0 -#define IDE_DATA 0x0 -#define IDE_FEATURES 0x1 -#define IDE_SECTOR_COUNT 0x2 -#define IDE_LOW 0x3 -#define IDE_MID 0x4 -#define IDE_HIGH 0x5 -#define IDE_SELECT 0x6 -#define IDE_CMD 0x7 -#define IDE_ALTERNATE 0x3F6 +// From spec +#define ATA_PRIMARY 0x00 +#define ATA_SECONDARY 0x01 +#define ATA_READ 0x00 +#define ATA_WRITE 0x013 +#define ATA_MASTER 0x00 +#define ATA_SLAVE 0x01 +#define ATA_SR_BSY 0x80 +#define ATA_SR_DRDY 0x40 +#define ATA_SR_DF 0x20 +#define ATA_SR_DSC 0x10 +#define ATA_SR_DRQ 0x08 +#define ATA_SR_CORR 0x04 +#define ATA_SR_IDX 0x02 +#define ATA_SR_ERR 0x01 +#define ATA_REG_DATA 0x00 +#define ATA_REG_ERROR 0x01 +#define ATA_REG_FEATURES 0x01 +#define ATA_REG_SECCOUNT0 0x02 +#define ATA_REG_LBA0 0x03 +#define ATA_REG_LBA1 0x04 +#define ATA_REG_LBA2 0x05 +#define ATA_REG_HDDEVSEL 0x06 +#define ATA_REG_COMMAND 0x07 +#define ATA_REG_STATUS 0x07 +#define ATA_REG_SECCOUNT1 0x08 +#define ATA_REG_LBA3 0x09 +#define ATA_REG_LBA4 0x0a +#define ATA_REG_LBA5 0x0b +#define ATA_REG_CONTROL 0x0c +#define ATA_REG_ALTSTATUS 0x0c +#define ATA_REG_DEVADDRESS 0x0d +#define ATA_CMD_READ_PIO 0x20 +#define ATA_CMD_READ_PIO_EXT 0x24 +#define ATA_CMD_READ_DMA 0xc8 +#define ATA_CMD_READ_DMA_EXT 0x25 +#define ATA_CMD_WRITE_PIO 0x30 +#define ATA_CMD_WRITE_PIO_EXT 0x34 +#define ATA_CMD_WRITE_DMA 0xca +#define ATA_CMD_WRITE_DMA_EXT 0x35 +#define ATA_CMD_CACHE_FLUSH 0xe7 +#define ATA_CMD_CACHE_FLUSH_EXT 0xea +#define ATA_CMD_PACKET 0xa0 +#define ATA_CMD_IDENTIFY_PACKET 0xa1 +#define ATA_CMD_IDENTIFY 0xec +#define ATA_IDENT_DEVICETYPE 0 +#define ATA_IDENT_CYLINDERS 2 +#define ATA_IDENT_HEADS 6 +#define ATA_IDENT_SECTORS 12 +#define ATA_IDENT_SERIAL 20 +#define ATA_IDENT_MODEL 54 +#define ATA_IDENT_CAPABILITIES 98 +#define ATA_IDENT_FIELDVALID 106 +#define ATA_IDENT_MAX_LBA 120 +#define ATA_IDENT_COMMANDSETS 164 +#define ATA_IDENT_MAX_LBA_EXT 200 -#define LBA_LOW(c) ((u8)(c & 0xFF)) -#define LBA_MID(c) ((u8)(c >> 8) & 0xFF) -#define LBA_HIGH(c) ((u8)(c >> 16) & 0xFF) -#define LBA_LAST(c) ((u8)(c >> 24) & 0xF) - -#define IDE_CMD_READ (BLOCK_SIZE / SECTOR_SIZE == 1) ? 0x20 : 0xC4 -#define IDE_CMD_WRITE (BLOCK_SIZE / SECTOR_SIZE == 1) ? 0x30 : 0xC5 -#define IDE_CMD_READ_MUL 0xC4 -#define IDE_CMD_WRITE_MUL 0xC5 - -void *ide_read(void *b, u32 block); +void ata_install(void); #endif |