From 6becbff5724d79cb3a958db297b5c3310200daea Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 23 Jul 2020 21:06:44 +0200 Subject: Added *very* simple ide and ext2 support --- src/inc/cpu.h | 1 + src/inc/fs.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/inc/ide.h | 40 ++++++++++++++++++++++++ 3 files changed, 138 insertions(+) create mode 100644 src/inc/fs.h create mode 100644 src/inc/ide.h (limited to 'src/inc') diff --git a/src/inc/cpu.h b/src/inc/cpu.h index ad83896..b8897de 100644 --- a/src/inc/cpu.h +++ b/src/inc/cpu.h @@ -8,6 +8,7 @@ u8 inb(u16 port); u16 inw(u16 port); u32 inl(u16 port); +void insl(u16 port, void *addr, int n); void outb(u16 port, u8 data); void outw(u16 port, u16 data); diff --git a/src/inc/fs.h b/src/inc/fs.h new file mode 100644 index 0000000..e5e1ca7 --- /dev/null +++ b/src/inc/fs.h @@ -0,0 +1,97 @@ +// MIT License, Copyright (c) 2020 Marvin Borner +// EXT2 based filesystem + +#ifndef FS_H +#define FS_H + +#include + +#define EXT2_BOOT 0 +#define EXT2_SUPER 1 +#define EXT2_MAGIC 0x0000EF53 + +struct superblock { + u32 total_inodes; + u32 total_blocks; + u32 su_res_blocks; // Superuser reserved + u32 free_blocks; + u32 free_inodes; + u32 superblock_block_num; + u32 log2_block_size; + u32 log2_frag_size; + u32 blocks_per_group; + u32 frags_per_group; + u32 inodes_per_group; + u32 last_mount_time; + u32 last_write_time; + u16 mounts_since_fsck; + u16 max_mounts_since_fsck; + u16 magic; + u16 state; // 1 clean; 2 errors + u16 error_action; + u16 minor_version; + u32 last_fsck_time; + u32 max_time_since_fsck; + u32 creator_os_id; + u32 major_version; + u16 res_block_uid; + u16 res_block_gid; +}; + +struct bgd { + u32 block_bitmap; + u32 inode_bitmap; + u32 inode_table; + u16 free_blocks; + u16 free_inodes; + u16 used_dirs; + u16 pad; + u8 bg_reserved[12]; +}; + +struct inode { + u16 mode; + u16 uid; + u32 size; + + u32 last_access_time; + u32 creation_time; + u32 last_modification_time; + u32 deletion_time; + + u16 gid; + u16 link_count; + u32 blocks; + u32 flags; + u32 os_specific_val1; + u32 block[15]; + u32 generation; + + u32 reserved1; + u32 reserved2; + + u32 fragment_addr; + u8 os_specific_val2[12]; +}; +#define INODE_SIZE (sizeof(struct inode)) + +struct dirent { + u32 inode_num; + u16 total_len; + u8 name_len; + u8 type_indicator; + u8 name[]; +}; + +struct file { + struct inode inode; + u32 pos; + u8 block_index; + u8 *buf; + u32 curr_block_pos; +}; + +// DEMO ;) +void ls_root(); + +#endif diff --git a/src/inc/ide.h b/src/inc/ide.h new file mode 100644 index 0000000..9d753ae --- /dev/null +++ b/src/inc/ide.h @@ -0,0 +1,40 @@ +// MIT License, Copyright (c) 2020 Marvin Borner + +#ifndef IDE_H +#define IDE_H + +#include + +#define BLOCK_SIZE 1024 +#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 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_HEAD 0x6 +#define IDE_CMD 0x7 +#define IDE_ALTERNATE 0x3F6 + +#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 + +int ide_wait(int check); +void *ide_read(void *b, u32 block); + +#endif -- cgit v1.2.3