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. --- kernel/kmain.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) (limited to 'kernel/kmain.c') diff --git a/kernel/kmain.c b/kernel/kmain.c index 6b550b7..00455b7 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -3,11 +3,40 @@ #include #include +extern int hd_read(void*, uint32_t, uint8_t); +extern int hd_write(void*, uint32_t, uint8_t); + +static char buf[0x1000]; + void kmain(void) { - con_init(); + int i; + int ret; - printk("Kernel booting...\n"); printk("Kernel booted!\n\n"); - sched_init(); + /* sched_init(); */ + + /* try to read some data */ + + ret = hd_read(buf, 0, 2); + if(ret < 0) { + printk("Failed to read data!\n"); + return; + } + printk("Successfully read first and second sectors!\n"); + printk("First dword (sector 0): 0x%08x\n", *((uint32_t*) buf)); + printk("First dword (sector 1): 0x%08x\n", *((uint32_t*) (buf + 512))); + + /* try to write some data */ + + for(i = 0; i < 256; i++) + ((uint16_t*) buf)[i] = i; + + ret = hd_write(buf, 2, 1); + if(ret < 0) { + printk("Failed to write data!\n"); + return; + } + + printk("Successfully wrote to sector 2\n"); } -- cgit v1.3