# HG changeset patch # User John Tsiombikas # Date 1323361175 -7200 # Node ID 2f555c81ae6748f0d50bfebe8fc7a1b8fd05d47b # Parent a398bf73fe93d2ba9e8d6de8e1992294cc159b0c starting the filesystem diff -r a398bf73fe93 -r 2f555c81ae67 src/ata.c --- a/src/ata.c Thu Dec 08 13:34:47 2011 +0200 +++ b/src/ata.c Thu Dec 08 18:19:35 2011 +0200 @@ -53,11 +53,13 @@ }; +static int readwrite_pio(int devno, uint64_t sect, void *buf, void (*rwdata)(struct device*, void*)); static int identify(struct device *dev, int iface, int id); static void select_dev(struct device *dev); static int wait_busy(struct device *dev); static int wait_drq(struct device *dev); static void read_data(struct device *dev, void *buf); +static void write_data(struct device *dev, void *buf); static inline uint8_t read_reg8(struct device *dev, int reg); static inline uint16_t read_reg16(struct device *dev, int reg); static inline void write_reg8(struct device *dev, int reg, uint8_t val); @@ -110,6 +112,16 @@ int ata_read_pio(int devno, uint64_t sect, void *buf) { + return readwrite_pio(devno, sect, buf, read_data); +} + +int ata_write_pio(int devno, uint64_t sect, void *buf) +{ + return readwrite_pio(devno, sect, buf, write_data); +} + +static int readwrite_pio(int devno, uint64_t sect, void *buf, void (*rwdata)(struct device*, void*)) +{ int use_irq, cmd, st, res = -1; uint32_t sect_low, sect_high; struct device *dev = devices + devno; @@ -171,8 +183,8 @@ goto end; } - /* read the data and we're done */ - read_data(dev, buf); + /* read/write the data and we're done */ + rwdata(dev, buf); res = 0; end: if(use_irq) { @@ -181,14 +193,6 @@ return res; } -int ata_write_pio(int devno, uint64_t sect, void *buf) -{ - if(devices[devno].id == -1) { - return -1; - } - return -1; -} - static int identify(struct device *dev, int iface, int id) { /* base address of the two ATA interfaces */ @@ -301,6 +305,20 @@ } } +static void write_data(struct device *dev, void *buf) +{ + int i; + uint16_t *ptr = buf; + + /* wait for the data request from the device */ + wait_drq(dev); + + /* ready to transfer */ + for(i=0; i<256; i++) { + write_reg16(dev, REG_DATA, *ptr++); + } +} + static inline uint8_t read_reg8(struct device *dev, int reg) { uint8_t val; diff -r a398bf73fe93 -r 2f555c81ae67 src/fs.c --- a/src/fs.c Thu Dec 08 13:34:47 2011 +0200 +++ b/src/fs.c Thu Dec 08 18:19:35 2011 +0200 @@ -1,25 +1,50 @@ #include +#include +#include #include "fs.h" #include "ata.h" #include "part.h" #include "panic.h" -#define PART_TYPE 0xcc +#define MAGIC 0xccf5ccf5 +#define BLKSZ 1024 -static int find_rootfs(int *dev, struct partition *part); +typedef uint32_t blkid; + +struct superblock { + uint32_t magic; + + blkid istart; + unsigned int icount; + + blkid dstart; + unsigned int dcount; +}; + +struct filesys { + int dev; + struct partition part; + + struct superblock *sb; +}; + +static int find_rootfs(struct filesys *fs); /* root device & partition */ -static int rdev; -static struct partition rpart; +static struct filesys root; void init_fs(void) { - if(find_rootfs(&rdev, &rpart) == -1) { + root.sb = malloc(512); + assert(root.sb); + + if(find_rootfs(&root) == -1) { panic("can't find root filesystem\n"); } } -static int find_rootfs(int *dev, struct partition *part) +#define PART_TYPE 0xcc +static int find_rootfs(struct filesys *fs) { int i, num_dev, partid; struct partition *plist, *p; @@ -31,11 +56,17 @@ partid = 0; while(p) { if(get_part_type(p) == PART_TYPE) { - /* found it! */ - printf("using ata%dp%d\n", i, partid); - *dev = i; - *part = *p; - return 0; + /* found the correct partition, now read the superblock + * and make sure it's got the correct magic id + */ + ata_read_pio(i, p->start_sect + 2, fs->sb); + + if(fs->sb->magic == MAGIC) { + printf("found root ata%dp%d\n", i, partid); + fs->dev = i; + fs->part = *p; + return 0; + } } p = p->next; partid++; diff -r a398bf73fe93 -r 2f555c81ae67 src/fs.h --- a/src/fs.h Thu Dec 08 13:34:47 2011 +0200 +++ b/src/fs.h Thu Dec 08 18:19:35 2011 +0200 @@ -3,4 +3,5 @@ void init_fs(void); + #endif /* FS_H_ */