the k project
play

The K Project Filesystem Conclusion ATAPI Driver LSE Team EPITA - PowerPoint PPT Presentation

The K Project LSE Team ATAPI Driver ISO The K Project Filesystem Conclusion ATAPI Driver LSE Team EPITA May 17, 2019 LSE Team (EPITA) The K Project May 17, 2019 1 / 19 Introduction The K Project LSE Team ATAPI Driver ISO


  1. The K Project LSE Team ATAPI Driver ISO The K Project Filesystem Conclusion ATAPI Driver LSE Team EPITA May 17, 2019 LSE Team (EPITA) The K Project May 17, 2019 1 / 19

  2. Introduction The K Project LSE Team ATAPI Driver ISO Filesystem Conclusion ATA ( AT Attachment ) original interface standard for hard drives Originally named IDE ( Integrated Drive Electronics ) Replaced by SATA ( Serial ATA ) in 2003 LSE Team (EPITA) The K Project May 17, 2019 2 / 19

  3. ATAPI The K Project LSE Team ATAPI Driver ISO Filesystem ATA Packet Interface Conclusion Designed to use ATA for other devices than hard disks In our case: CD-ROM Part of the ATA standard SCSI commands and responses through the ATA interface LSE Team (EPITA) The K Project May 17, 2019 3 / 19

  4. ATA - IBM PC The K Project LSE Team ATAPI Driver ISO Filesystem Conclusion 2 ATA controllers (buses) IRQ14 and IRQ15 of slave PIC Maximum 2 drives per ATA bus Each controller has a set of I/O ports LSE Team (EPITA) The K Project May 17, 2019 4 / 19

  5. ATA Registers The K Project Primary registers: LSE Team 1st controller: 0x1f0 ATAPI Driver 2nd controller: 0x170 ISO Filesystem Offsets from primary register: Conclusion +0: Data Register +1: Error Register (R) +1: Features Register (W) +2: Sector Count Register +3: LBA Low Register +4: LBA Mid Register +5: LBA High Register +6: Drive/Head Register +7: Status Register (R) +7: Command Register (W) Device Control Register (DCR): 0x3f6 and 0x376 LSE Team (EPITA) The K Project May 17, 2019 5 / 19

  6. Status Register The K Project LSE Team ATAPI Driver Bit 0: Error (ERR) ISO Filesystem Bit 1: Index Mark (IDX) Conclusion Bit 2: Data Corrected (CORR) Bit 3: Data Transfer Requested (DRQ) Bit 4: Seek complete (DSC) Bit 5: Device Fault (DF) Bit 6: Device Ready (DRDY) Bit 7: Busy (BSY) LSE Team (EPITA) The K Project May 17, 2019 6 / 19

  7. Discover ATAPI drive The K Project LSE Team ATAPI Driver ISO Filesystem For each ATA bus: Conclusion Send ‘Software Reset’ to the controller’s DCR Send ‘Disable IRQ’ to the controller’s DCR outb(DCR(port), SOFTWARE_RESET) outb(DCR(port), DISABLE_IRQ) LSE Team (EPITA) The K Project May 17, 2019 7 / 19

  8. Discover ATAPI drive The K Project /* reg == PRIMARY_REG || reg == SECONDARY_REG */ LSE Team for drive in (ATA_PORT_MASTER, ATA_PORT_SLAVE): ATAPI Driver /* Select current drive */ ISO outb(DRIVE_REG(reg), drive); Filesystem Conclusion /* Approx. 4 * inb() */ wait_400ns(); /* Look for ATAPI signature */ sig[0] = inb(SECTOR_COUNT_REG(port)) sig[1] = inb(LBA_LO_REG(port)) sig[2] = inb(LBA_MI_REG(port)) sig[3] = inb(LBA_HI_REG(port)) /* * memcmp(sig, ...) * If it matches: saves (reg, drive) */ LSE Team (EPITA) The K Project May 17, 2019 8 / 19

  9. Read block The K Project LSE Team ATAPI Driver Send SCSI packet with ‘READ 12’ commmand ISO Filesystem To send a packet to the drive: Conclusion busy_wait(); outb(FEATURES_REG(drive), 0); /* No overlap/no DMA outb(SECTOR_CNT_REG(drive), 0); /* No queuing outb(LBA_MI_REG(drive), CDROM_BLK_SIZE); outb(LBA_HI_REG(drive), CDROM_BLK_SIZE >> 8); outb(COMMAND_REG(drive), 0xa0); /* PACKET */ wait_packet_req(); LSE Team (EPITA) The K Project May 17, 2019 9 / 19

  10. Read block The K Project LSE Team ATAPI Driver ISO Filesystem To wait for a packet to be requested: Conclusion Poll the status register until BSY is cleared and DRQ is set Write the SCSI packet to the Data Register One word at a time (you must use outw() ) Read Sector Count Reg while it doesn’t return DATA TRANSMIT (0x2) LSE Team (EPITA) The K Project May 17, 2019 10 / 19

  11. Read block The K Project LSE Team ATAPI Driver ISO Filesystem Once the SCSI packet has been sent: Conclusion Read CDROM BLK SIZE word by word: inw(DATA REGISTER(port)) Read Sector Count Register while it does not return PACKET COMMAND COMPLETE (0x3) LSE Team (EPITA) The K Project May 17, 2019 11 / 19

  12. Recommanded methodology The K Project LSE Team ATAPI Driver ISO Filesystem Write ‘waiting’ helper functions: Conclusion void busy_wait(u16 drive); void wait_device_selection(u16 drive); void wait_packet_request(u16 drive); These functions should only be doing inb() calls and status checking. LSE Team (EPITA) The K Project May 17, 2019 12 / 19

  13. Recommanded methodology The K Project LSE Team ATAPI Driver ISO Filesystem Conclusion Write functions to discover the ATAPI device: void select_drive(u16 bus, u8 slave); bool is_atapi_drive(u16 bus, u8 slave); void discover_atapi_drive(); LSE Team (EPITA) The K Project May 17, 2019 13 / 19

  14. Recommanded methodology The K Project LSE Team ATAPI Driver ISO Filesystem Write functions to read data on the drive: Conclusion int send_packet(struct SCSI_packet *pkt, u16 drive, u16 size); void *read_block(size_t lba); Feel free to modify the proposed function prototypes. LSE Team (EPITA) The K Project May 17, 2019 14 / 19

  15. Introduction The K Project LSE Team ATAPI Driver ISO Filesystem Conclusion On the ATAPI drive, there will be an ISO 9660 filesystem. You should already know how it works. The header you had in myreadiso is given. LSE Team (EPITA) The K Project May 17, 2019 15 / 19

  16. File System Interface The K Project LSE Team ATAPI Driver ISO Filesystem Conclusion int open(const char *pathname, int flags); ssize_t read(int fd, void *buf, size_t count); off_t seek(int fd, off_t offset, int whence); int close(int fd); LSE Team (EPITA) The K Project May 17, 2019 16 / 19

  17. Open and Close The K Project LSE Team ATAPI Driver ISO Filesystem Open: Conclusion locate the file and store the infos you need to retrieve it quickly register an fd in your fd table Close: free the fd LSE Team (EPITA) The K Project May 17, 2019 17 / 19

  18. Read and Seek The K Project LSE Team ATAPI Driver ISO Seek: Filesystem Conclusion modify the file offset according to whence Read: use the informations you stored in open() find the blocks of data to read and copy it modify the file offset LSE Team (EPITA) The K Project May 17, 2019 18 / 19

  19. Contact The K Project LSE Team ATAPI Driver ISO Filesystem k[at]lse.epita.fr Conclusion labos.lse with [K] tag #k (irc.rezosup.org) guillaume.pagnoux[at]lse.epita.fr tom.decrette[at]lse.epita.fr LSE Team (EPITA) The K Project May 17, 2019 19 / 19

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend