blob: 54df9cdfc93145fa75261a12e94ffb0836c7ac87 [file] [log] [blame]
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05001// Definitions for X86 bios disks.
2//
3// Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4//
5// This file may be distributed under the terms of the GNU GPLv3 license.
Kevin O'Connor786502d2008-02-27 10:41:41 -05006#ifndef __DISK_H
7#define __DISK_H
Kevin O'Connorf076a3e2008-02-25 22:25:15 -05008
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "types.h" // u8
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050010
Kevin O'Connore43df9e2008-03-01 22:16:32 -050011#define DISK_RET_SUCCESS 0x00
12#define DISK_RET_EPARAM 0x01
Kevin O'Connorb74102d2008-03-03 21:57:30 -050013#define DISK_RET_EADDRNOTFOUND 0x02
14#define DISK_RET_EWRITEPROTECT 0x03
Kevin O'Connore43df9e2008-03-01 22:16:32 -050015#define DISK_RET_ECHANGED 0x06
16#define DISK_RET_EBOUNDARY 0x09
17#define DISK_RET_EBADTRACK 0x0c
18#define DISK_RET_ECONTROLLER 0x20
19#define DISK_RET_ETIMEOUT 0x80
Kevin O'Connorb74102d2008-03-03 21:57:30 -050020#define DISK_RET_ENOTLOCKED 0xb0
21#define DISK_RET_ELOCKED 0xb1
Kevin O'Connore43df9e2008-03-01 22:16:32 -050022#define DISK_RET_ENOTREMOVABLE 0xb2
Kevin O'Connorb74102d2008-03-03 21:57:30 -050023#define DISK_RET_ETOOMANYLOCKS 0xb4
Kevin O'Connore43df9e2008-03-01 22:16:32 -050024#define DISK_RET_EMEDIA 0xC0
25#define DISK_RET_ENOTREADY 0xAA
26
27// Bios disk structures.
28struct int13ext_s {
29 u8 size;
30 u8 reserved;
31 u16 count;
32 u16 offset;
33 u16 segment;
Kevin O'Connor1bb3b5c2008-05-14 00:43:13 -040034 u64 lba;
Kevin O'Connored128492008-03-11 11:14:59 -040035} PACKED;
Kevin O'Connore43df9e2008-03-01 22:16:32 -050036
37#define GET_INT13EXT(regs,var) \
38 GET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var)
39#define SET_INT13EXT(regs,var,val) \
40 SET_FARVAR((regs)->ds, ((struct int13ext_s*)((regs)->si+0))->var, (val))
41
42// Disk Physical Table definition
43struct int13dpt_s {
44 u16 size;
45 u16 infos;
46 u32 cylinders;
47 u32 heads;
48 u32 spt;
Kevin O'Connor1bb3b5c2008-05-14 00:43:13 -040049 u64 sector_count;
Kevin O'Connore43df9e2008-03-01 22:16:32 -050050 u16 blksize;
51 u16 dpte_offset;
52 u16 dpte_segment;
53 u16 key;
54 u8 dpi_length;
55 u8 reserved1;
56 u16 reserved2;
57 u8 host_bus[4];
58 u8 iface_type[8];
59 u8 iface_path[8];
60 u8 device_path[8];
61 u8 reserved3;
62 u8 checksum;
Kevin O'Connored128492008-03-11 11:14:59 -040063} PACKED;
Kevin O'Connore43df9e2008-03-01 22:16:32 -050064
65#define GET_INT13DPT(regs,var) \
66 GET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var)
67#define SET_INT13DPT(regs,var,val) \
68 SET_FARVAR((regs)->ds, ((struct int13dpt_s*)((regs)->si+0))->var, (val))
69
Kevin O'Connor44c631d2008-03-02 11:24:36 -050070// Floppy "Disk Base Table"
71struct floppy_dbt_s {
72 u8 specify1;
73 u8 specify2;
74 u8 shutoff_ticks;
75 u8 bps_code;
76 u8 sectors;
77 u8 interblock_len;
78 u8 data_len;
79 u8 gap_len;
80 u8 fill_byte;
81 u8 settle_time;
82 u8 startup_time;
Kevin O'Connored128492008-03-11 11:14:59 -040083} PACKED;
Kevin O'Connor44c631d2008-03-02 11:24:36 -050084
85struct floppy_ext_dbt_s {
86 struct floppy_dbt_s dbt;
87 // Extra fields
88 u8 max_track;
89 u8 data_rate;
90 u8 drive_type;
Kevin O'Connored128492008-03-11 11:14:59 -040091} PACKED;
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050092
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -050093// Helper function for setting up a return code.
Kevin O'Connor9521e262008-07-04 13:04:29 -040094struct bregs;
Kevin O'Connor567e4e32008-04-05 11:37:51 -040095void __disk_ret(const char *fname, struct bregs *regs, u8 code);
96#define disk_ret(regs, code) \
97 __disk_ret(__func__, (regs), (code))
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -050098
Kevin O'Connorf076a3e2008-02-25 22:25:15 -050099// floppy.c
Kevin O'Connor941d3e42008-03-04 19:45:04 -0500100extern struct floppy_ext_dbt_s diskette_param_table2;
Kevin O'Connor3bbcc142008-04-13 17:07:33 -0400101void floppy_drive_setup();
Kevin O'Connorf076a3e2008-02-25 22:25:15 -0500102void floppy_13(struct bregs *regs, u8 drive);
103void floppy_tick();
Kevin O'Connor786502d2008-02-27 10:41:41 -0500104
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -0500105// disk.c
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -0500106void disk_13(struct bregs *regs, u8 device);
107void disk_13XX(struct bregs *regs, u8 device);
108
109// cdrom.c
Kevin O'Connoraa2590c2008-03-22 23:13:24 -0400110int cdrom_read_emu(u16 device, u32 lba, u32 count, void *far_buffer);
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -0500111void cdrom_13(struct bregs *regs, u8 device);
112void cdemu_13(struct bregs *regs);
113void cdemu_134b(struct bregs *regs);
Kevin O'Connora05223c2008-06-28 12:15:57 -0400114int cdrom_boot();
Kevin O'Connor31d8c8a2008-03-04 19:56:41 -0500115
116
Kevin O'Connor786502d2008-02-27 10:41:41 -0500117#endif // disk.h