199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 1998 Robert Nordier
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2010 Pawel Jakub Dawidek <pjd@FreeBSD.org>
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms are freely
199767f8919635c4928607450d9e0abb932109ceToomas Soome * permitted provided that the above copyright notice and this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * paragraph and the following disclaimer are duplicated in all
199767f8919635c4928607450d9e0abb932109ceToomas Soome * such forms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This software is provided "AS IS" and without any express or
199767f8919635c4928607450d9e0abb932109ceToomas Soome * implied warranties, including, without limitation, the implied
199767f8919635c4928607450d9e0abb932109ceToomas Soome * warranties of merchantability and fitness for a particular
199767f8919635c4928607450d9e0abb932109ceToomas Soome * purpose.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/cdefs.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome__FBSDID("$FreeBSD$");
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <sys/param.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include <btxv86.h>
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "rbx.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "util.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "drv.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "edd.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef USE_XREAD
199767f8919635c4928607450d9e0abb932109ceToomas Soome#include "xreadorg.h"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef GPT
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct edd_params params;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeuint64_t
199767f8919635c4928607450d9e0abb932109ceToomas Soomedrvsize(struct dsk *dskp)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome params.len = sizeof(struct edd_params);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ctl = V86_FLAGS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = 0x13;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.eax = 0x4800;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.edx = dskp->drive;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ds = VTOPSEG(&params);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.esi = VTOPOFF(&params);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86int();
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (V86_CY(v86.efl)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("error %u\n", v86.eax >> 8 & 0xff);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (params.sectors);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* GPT */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef USE_XREAD
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic struct edd_packet packet;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas Soomedrvread(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome static unsigned c = 0x2d5c7c2f;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!OPT_CHECK(RBX_QUIET))
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%c\b", c = c << 8 | c >> 24);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef USE_XREAD
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.len = sizeof(struct edd_packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.count = nblk;
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.off = VTOPOFF(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.seg = VTOPSEG(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.lba = lba;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ctl = V86_FLAGS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = 0x13;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.eax = 0x4200;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.edx = dskp->drive;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ds = VTOPSEG(&packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.esi = VTOPOFF(&packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#else /* USE_XREAD */
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ctl = V86_ADDR | V86_CALLF | V86_FLAGS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = XREADORG; /* call to xread in boot1 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.es = VTOPSEG(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.eax = lba;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ebx = VTOPOFF(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ecx = lba >> 32;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.edx = nblk << 8 | dskp->drive;
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* USE_XREAD */
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86int();
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (V86_CY(v86.efl)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("%s: error %u lba %u\n",
199767f8919635c4928607450d9e0abb932109ceToomas Soome BOOTPROG, v86.eax >> 8 & 0xff, lba);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef GPT
199767f8919635c4928607450d9e0abb932109ceToomas Soomeint
199767f8919635c4928607450d9e0abb932109ceToomas Soomedrvwrite(struct dsk *dskp, void *buf, daddr_t lba, unsigned nblk)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.len = sizeof(struct edd_packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.count = nblk;
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.off = VTOPOFF(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.seg = VTOPSEG(buf);
199767f8919635c4928607450d9e0abb932109ceToomas Soome packet.lba = lba;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ctl = V86_FLAGS;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.addr = 0x13;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.eax = 0x4300;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.edx = dskp->drive;
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.ds = VTOPSEG(&packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86.esi = VTOPOFF(&packet);
199767f8919635c4928607450d9e0abb932109ceToomas Soome v86int();
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (V86_CY(v86.efl)) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome printf("error %u lba %u\n", v86.eax >> 8 & 0xff, lba);
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (-1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome return (0);
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* GPT */