1 // Code for emulating a drive via high-memory accesses.
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "disk.h" // process_ramdisk_op
8 #include "util.h" // dprintf
9 #include "memmap.h" // add_e820
10 #include "biosvar.h" // GET_GLOBAL
11 #include "bregs.h" // struct bregs
13 #define RAMDISK_SECTOR_SIZE 512
16 describe_ramdisk(int driveid)
18 printf("%s", Drives.drives[driveid].model);
24 if (!CONFIG_COREBOOT_FLASH || !CONFIG_FLASH_FLOPPY)
28 struct cbfs_file *file = cbfs_findprefix("floppyimg/", NULL);
31 u32 size = cbfs_datasize(file);
32 dprintf(3, "Found floppy file %s of size %d\n", cbfs_filename(file), size);
33 int ftype = find_floppy_type(size);
35 dprintf(3, "No floppy type found for ramdisk size\n");
39 // Allocate ram for image.
40 void *pos = memalign_tmphigh(PAGE_SIZE, size);
42 dprintf(3, "Not enough memory for ramdisk\n");
45 add_e820((u32)pos, size, E820_RESERVED);
47 // Copy image into ram.
48 cbfs_copyfile(file, pos, size);
51 dprintf(1, "Mapping CBFS floppy %s to addr %p\n", cbfs_filename(file), pos);
52 int driveid = addFloppy((u32)pos, ftype, DTYPE_RAMDISK);
54 strtcpy(Drives.drives[driveid].model, cbfs_filename(file)
55 , ARRAY_SIZE(Drives.drives[driveid].model));
59 ramdisk_copy(struct disk_op_s *op, int iswrite)
61 u32 offset = GET_GLOBAL(Drives.drives[op->driveid].cntl_id);
62 offset += (u32)op->lba * RAMDISK_SECTOR_SIZE;
63 u64 opd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE((u32)op->buf_fl);
64 u64 ramd = GDT_DATA | GDT_LIMIT(0xfffff) | GDT_BASE(offset);
75 // Call int 1587 to copy data.
77 memset(&br, 0, sizeof(br));
82 br.cx = op->count * RAMDISK_SECTOR_SIZE / 2;
83 call16_int(0x15, &br);
86 return DISK_RET_EBADTRACK;
87 return DISK_RET_SUCCESS;
91 process_ramdisk_op(struct disk_op_s *op)
93 if (!CONFIG_COREBOOT_FLASH || !CONFIG_FLASH_FLOPPY)
96 switch (op->command) {
98 return ramdisk_copy(op, 0);
100 return ramdisk_copy(op, 1);
104 return DISK_RET_SUCCESS;
107 return DISK_RET_EPARAM;