md5sum /boot/KERNEL.BIN
md5sum KERNEL.BIN
-copy:
+cp:
./scripts/copy.sh
get_value("root", value);
printk("root device %s\n", value);
assert(value[0]=='h' && value[1]=='d' && value[2] == 'a');
- system.root_dev = MAKE_DEV(DEV_MAJOR_HD, atoi(value+3));
+ system.root_dev = MAKE_DEV(DEV_MAJOR_HDA, atoi(value+3));
printk("root device %08x\n", system.root_dev);
}
--- /dev/null
+/*
+ * ------------------------------------------------------------------------
+ * File Name: blk_rw.c
+ * Author: Zhao Yanbai
+ * Tue Jul 8 22:21:37 2014
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#include <fs.h>
+#include <ide.h>
+#include <system.h>
+
+// only support read
+void blk_rw(dev_t dev, u64_t offset, u32_t size, char *buf)
+{
+ assert(DEV_MAJOR(dev) == DEV_MAJOR_HDA);
+ assert(offset % SECT_SIZE == 0);
+ assert(size % SECT_SIZE == 0);
+
+ const part_t *p = ide_get_part(dev);
+
+ u64_t lba = p->lba_start;
+ lba += offset / SECT_SIZE;
+
+ assert(lba < p->lba_end);
+
+ u32_t scnt = size / SECT_SIZE;
+
+ printk("%s lba %u scnt %u\n", __func__, (u32_t)lba, scnt);
+
+ ide_do_read(lba, scnt, buf);
+}
#include <ide.h>
#include <irq.h>
#include <pci.h>
-#include <system.h>
#include <semaphore.h>
#include <wait.h>
#include <string.h>
typedef struct {
u64_t lba;
u32_t scnt;
+ u32_t read_scnt;
char *buf;
bool finish;
wait_queue_head_t wait;
void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd)
{
+ printk("sect_cnt %u sect_nr %u \n", sect_cnt, (u32)sect_nr);
drv.pio_cnt++;
drv.read_mode = cmd;
outb(cmd, REG_CMD(dev));
}
+part_t *ide_get_part(dev_t dev)
+{
+ assert(DEV_MAJOR(dev) == DEV_MAJOR_HDA);
+ assert(DEV_MINOR(dev) < MAX_SUPPORT_PARTITION_CNT);
+
+ return drv.part + DEV_MINOR(dev);
+}
+
void ide_do_read(u64_t lba, u32_t scnt, char *buf)
{
bool finish = false;
r->lba = lba;
r->scnt= scnt;
+ r->read_scnt= 0;
r->buf = buf;
r->finish = false;
init_wait_queue(&r->wait);
void ide_default_intr()
{
+ printk("%s\n", __func__);
u8_t status = inb(REG_STATUS(0));
drv.irq_cnt++;
u16_t sig = 0;
if(drv.read_mode == HD_CMD_READ_EXT)
{
- insl(REG_DATA(0), ide_request.buf, ((ide_request.scnt*SECT_SIZE)>>2));
+ insl(REG_DATA(0), ide_request.buf + ide_request.read_scnt*(SECT_SIZE), (SECT_SIZE)>>2);
+ ide_request.read_scnt++;
sig = *((u16_t *) (ide_request.buf+510));
}
outb(PCI_IDE_CMD_STOP, drv.bus_cmd);
wake_up(&ide_request.wait);
- ide_request.finish = true;
+ if(drv.read_mode == HD_CMD_READ_EXT)
+ {
+ if(ide_request.read_scnt == ide_request.scnt)
+ ide_request.finish = true;
+ }
up(&mutex);
}
#pragma once
+#include <system.h>
+
extern unsigned int HD_CHL0_CMD_BASE;
extern unsigned int HD_CHL1_CMD_BASE;
extern unsigned int HD_CHL0_CTL_BASE;
u64_t lba_start;
u64_t lba_end;
} part_t;
+
+void ide_do_read(u64_t lba, u32_t scnt, char *buf);
+part_t *ide_get_part(dev_t dev);
*--------------------------------------------------------------------------
*/
+#if 0
#include <fs.h>
#include <system.h>
#include <string.h>
printk("i_mode:%04x i_size:%d i_blocks:%d\n",
p->i_mode, p->i_size, p->i_blocks);
}
+#endif
* Description: none
* ------------------------------------------------------------------------
*/
+#include "system.h"
+#include "fs.h"
#include "ext2.h"
+
+struct {
+ ext2_sb_t ext2_sb;
+} ext2_fs;
+
+extern void blk_rw(dev_t dev, u64_t offset, u32_t scnt, char *buf);
+
+#define BLKRW(offset, blkcnt, buf) do { blk_rw(system.root_dev, offset, (blkcnt)*EXT2_BLOCK_SIZE, buf); } while(0)
+
+void ext2_setup_fs()
+{
+ memset(&ext2_fs, 0, sizeof(ext2_fs));
+
+ char *buf = kmalloc(EXT2_BLOCK_SIZE, 0);
+ if(buf == 0)
+ panic("out of memory");
+
+ printk("EXT2_BLOCK_SIZE %u\n", EXT2_BLOCK_SIZE);
+
+ BLKRW(EXT2_SB_OFFSET, 1, buf);
+
+ memcpy(EXT2_SB, buf, sizeof(*(EXT2_SB)));
+
+ if(EXT2_SB->s_magic != EXT2_SUPER_MAGIC)
+ {
+ printk("file system magic %04x\n", EXT2_SB->s_magic);
+ panic("only support ext2 file system...");
+ }
+
+ printk("Ext2 File System Information:\n");
+ printk("inodes cnt %u blocks cnt %u free blocks %u free inodes %u\n",
+ EXT2_SB->s_inodes_count, EXT2_SB->s_blocks_count, EXT2_SB->s_free_blocks_count, EXT2_SB->s_free_inodes_count);
+ printk("block size %u log block size %u first data block %u\n",
+ EXT2_BLOCK_SIZE, EXT2_SB->s_log_block_size, EXT2_SB->s_first_data_block);
+ printk("blocks per group %u inodes per group %u\n", EXT2_SB->s_blocks_per_group, EXT2_SB->s_inodes_per_group);
+}
+
+
+
+
+void setup_fs()
+{
+ ext2_setup_fs();
+}
#include <system.h>
#define SECT_SIZE 512
+#if 0
File file_table[NR_FILES] __attribute__ ((__aligned__(PAGE_SIZE))) = {{0,},};
extern unsigned int ext2_start_sect;
void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count);
void init_file_table();
void save_boot_part(int n, pPartition p, u32 base_sect);
void read_ext_part(u32 base, u32 offset);
-
void setup_fs()
{
int i, minor;
free_virt_pages(buf);
}
+#endif
int sysc_open(const char *path, int flags, mode_t mode)
{
+#if 0
assert(mode == 0); // unsupport now...
assert(flags == O_RDONLY); // support only...
current->fps[fd] = pf;
return fd;
+#endif
}
int sysc_read(int fd, void *buf, size_t count)
{
+#if 0
if(fd<0 || fd>=NR_OPENS)
return -EBADF;
return read_file(inode, buf, count);
+#endif
}
#include <memory.h>
int sysc_stat(int fd, struct stat *stat)
{
+#if 0
if(fd<0 || fd>=NR_OPENS)
return -EBADF;
stat->st_atime = inode->i_atime;
stat->st_mtime = inode->i_mtime;
stat->st_ctime = inode->i_ctime;
+#endif
return 0;
}
#include <types.h>
+#define EXT2_SUPER_MAGIC 0xEF53
+
+#define EXT2_SB_OFFSET 1024
+
#define EXT2_BAD_INO 1
#define EXT2_ROOT_INO 2
#define EXT2_BOOT_LOADER_INO 5
#define EXT2_MAX_BLOCK_SIZE 4096
#define EXT2_MIN_BLOCK_LOG_SIZE 10
+#define EXT2_SB (&ext2_fs.ext2_sb)
#define EXT2_BLOCK_SIZE (EXT2_MIN_BLOCK_SIZE << (EXT2_SB)->s_log_block_size)
#define EXT2_SECT_PER_BLOCK (EXT2_BLOCK_SIZE/512)
#include <types.h>
#include <page.h>
-#include <bak.ext2.h>
-
-typedef struct partition
-{
- u8 State;
- u8 Head;
- u16 StartSC;
- u8 Type;
- u8 EndHead;
- u16 EndSC;
- u32 AbsoluteSectNo;
- u32 PartitionSize;
-} Partition, *pPartition;
-
/* 分区表开始的位置 */
#define PARTS_POS 0x1BE
#define DEV_MAJOR_MEM 0x0001
#define DEV_MAJOR_TTY 0x0002
#define DEV_MAJOR_IDE0 0x0003
-#define DEV_MAJOR_HD DEV_MAJOR_IDE0
+#define DEV_MAJOR_HDA DEV_MAJOR_IDE0
#define DEV_MAJOR_IDE1 0x0004
#define DEV_MAJOR_SCSI0 0x0005
#define DEV_MAJOR_SCSI2 0x0006
-typedef struct
-{
- int count;
- int ino_nr;
- pInode inode;
-} File, *pFile;
+#define MAX_SUPT_FILE_SIZE (1)
+#define NR_FILES (1)
+#define NR_OPENS (1)
+#if 0
#define MAX_SUPT_FILE_SIZE (EXT2_IND_BLOCK*EXT2_BLOCK_SIZE)
#define NR_FILES (PAGE_SIZE/sizeof(File))
#define NR_INODES (2*NR_FILES)
extern Inode inode_table[NR_INODES];
+typedef struct
+{
+ int count;
+ int ino_nr;
+ pInode inode;
+} File, *pFile;
static inline int get_inode_nr(const char *path)
return NULL;
}
+#endif
#endif //_FS_H
list_head_t list;
- pFile fps[NR_OPENS];
+ //pFile fps[NR_OPENS];
};
strcpy(root_task.name, "root_task");
INIT_LIST_HEAD(&root_task.list);
- for(i=0; i<NR_OPENS; i++)
- root_task.fps[i] = 0;
+
+ // TODO
+ //for(i=0; i<NR_OPENS; i++)
+ // root_task.fps[i] = 0;
tss.esp0 = ((unsigned long)&root_task) + sizeof(root_task);
root_task.esp0 = tss.esp0;
extern void setup_pci();
extern void set_tss();
extern void setup_tasks();
-extern void setup_root_dev();
extern void ide_init();
extern void setup_fs();
extern void setup_ext2();
//switch_printk_screen();
void ide_init();
ide_init();
- switch_printk_screen();
detect_cpu();
printk("%s\n", version);
-
- return;
- while(1); // TODO MODIFY CODE BELOW
-
-
- setup_root_dev();
setup_fs();
- setup_ext2();
}
return 0;
}
+int sysc_test() { }
+
void init_sysc_handler_table()
{
int i;
asm("ltr %%ax"::"a"((INDEX_TSS<<3)+3));
}
-void setup_root_dev()
-{
- unsigned char dev;
- dev = (unsigned char)(system.boot_device >> 24);
- printk("root device: %08x\n", system.root_dev);
-}
-
int sysc_reboot(int mode)
{
+++ /dev/null
-/*
- *--------------------------------------------------------------------------
- * File Name: test.c
- *
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
- * Tue Feb 23 17:47:43 2010
- *
- * Description: sysc_test
- *
- *--------------------------------------------------------------------------
- */
-#include <syscall.h>
-#include <printk.h>
-#include <sched.h>
-
-void dump_fd()
-{
- int i;
- for(i=0; i<NR_OPENS; i++)
- {
- pFile pf = current->fps[i];
- if(pf == NULL) continue;
- printk("fd[%d]: %08x\n", i, pf);
-
-
- pInode inode = pf->inode;
- printk("file_desc ino_nr: %04d inode:%08x\n",
- pf->ino_nr, inode);
-
- printk("inode: size: %d\n", inode->i_size);
- }
-}
-
-int sysc_test()
-{
- //dump_fd();
-
- printk(".");
-
- return 0;
-}