From 35685c20a5dc299edf6f3b76ed898a2e71d0e457 Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sat, 14 Jul 2018 03:42:12 +1000 Subject: con_init() is now called during the kernel's boot sequence in kboot() rather than in kmain() as some subsystems may now require early console I/O. Added 16-bit read/write I/O functions to asm/io.h. These functions are inw() and outw() respectively. Added the file kernel/fs.h which will contain definitions relating to filesystem functions. Defined the type off_t as a signed 32-bit value in sys/types.h. This type will be required for filesystem functionality. Added the directory 'kernel/fs' to the project's source tree. The kernel's makefile has been updated accordingly. This directory will contain any source files relating to filesystem functionality (both assembly and C files). Added the file 'fs/hd.c' to the kernel's source tree. This file currently contains three main functions (which are defined in kernel/hd.h). These functions are as follows; hd_init() to enumerate and initialize the hard disks, hd_read() to read sectors from the disk and hd_write() to write sectors to the disk. Currently, all transfers are done in ATA PIO mode using polling, however this will change in future. The function hd_init() is called during the kernel's boot sequence in kboot(). Added the file hd.img to the project's root directory. This is a 20MB raw image file that will be used by Qemu as a 20MB hard disk. The main makefile has been updated to tell Qemu to use this file on launch. --- include/asm/io.h | 19 ++++++++++++++----- include/kernel/fs.h | 18 ++++++++++++++++++ include/kernel/hd.h | 7 +++++++ include/sys/types.h | 2 ++ 4 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 include/kernel/fs.h create mode 100644 include/kernel/hd.h (limited to 'include') diff --git a/include/asm/io.h b/include/asm/io.h index 1c2e5bc..09294f4 100644 --- a/include/asm/io.h +++ b/include/asm/io.h @@ -5,10 +5,19 @@ */ #define inb(port) ({ \ - unsigned char _val; \ - __asm__ volatile ("inb %%dx, %%al" : "=a" (_val) : "d" (port)); \ - _val; \ - }) + unsigned char _val; \ + __asm__ volatile ("inb %%dx, %%al" : "=a" (_val) : "d" (port)); \ + _val; \ + }) + +#define inw(port) ({ \ + unsigned short _val; \ + __asm__ volatile ("inw %%dx, %%ax" : "=a" (_val) : "d" (port)); \ + _val; \ + }) #define outb(port, val) \ - __asm__ volatile ("outb %%al, %%dx" : : "d" (port), "a" (val)); + __asm__ volatile ("outb %%al, %%dx" :: "d" (port), "a" (val)); + +#define outw(port, val) \ + __asm__ volatile ("outw %%ax, %%dx" :: "d" (port), "a" (val)); diff --git a/include/kernel/fs.h b/include/kernel/fs.h new file mode 100644 index 0000000..8f21110 --- /dev/null +++ b/include/kernel/fs.h @@ -0,0 +1,18 @@ +#ifndef _FS_H +#define _FS_H + +#include +#include + +#define BLOCK_SIZE 1024 +#define NRFILE 128 +#define NROPEN 32 + +struct file { + uint16_t f_mode; + uint16_t f_flags; + /* TODO: inode pointer here */ + off_t f_pos; +}; + +#endif diff --git a/include/kernel/hd.h b/include/kernel/hd.h new file mode 100644 index 0000000..26c705d --- /dev/null +++ b/include/kernel/hd.h @@ -0,0 +1,7 @@ +#ifndef _HD_H +#define _HD_H + +int hd_read(void*, uint32_t, uint8_t); +int hd_write(void*, uint32_t, uint8_t); + +#endif diff --git a/include/sys/types.h b/include/sys/types.h index ace1a62..6c18e16 100644 --- a/include/sys/types.h +++ b/include/sys/types.h @@ -17,4 +17,6 @@ typedef uint32_t size_t; typedef int32_t time_t; #endif +typedef long off_t; + #endif -- cgit v1.3