在ipxe源码基础上,重新封装读写本地磁盘接口

本文介绍了如何基于ipxe源码重新封装读写本地磁盘的接口,通过测试验证了其功能。对于隐藏本地磁盘和读写转移的相关内容,可参考作者之前的博客。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以下代码经过测试通过。

想隐藏本地磁盘和读写转移,可以查看上两篇博客。

/**
 * bios int 13
 *
 * @author sun (9/22/2015)
 *
 * @param ix86      all register for int 13
 *
 * @return __asmcall void
 */
static __asmcall void int13_bios ( struct i386_all_regs *ix86 __unused) {
    /**
     * for now do nothing.
     */
    //dbg_printf_p(1, "ax:%02x bx:%02x cx:%02x dx:%02x si:%02x\n"
    //                "cs:%02x ds:%02x es:%02x\n",
    //    ix86->regs.ax, ix86->regs.bx, ix86->regs.cx, ix86->regs.dx, ix86->regs.si,
    //    ix86->segs.cs, ix86->segs.ds, ix86->segs.es);
}

/**
 * call bios int13
 *
 * @author sun (9/24/2015)
 *
 * @param ix86      all register for int 13
 *
 * @return int      status
 */
static int int13_call_bios_int13 ( struct i386_all_regs *ix86 ) {
    int status;
    struct segoff es_bx, ds_si, es_di;

    if ( ix86 == NULL ) {
        DBG ( "Call bios INT13 arg err.\n" );
        return -INT13_STATUS_INVALID;
    }

    es_bx.segment = ix86->segs.es;
    es_bx.offset = ix86->regs.bx;

    ds_si.segment = ix86->segs.ds;
    ds_si.offset = ix86->regs.si;

    es_di.segment = ix86->segs.es;
    es_di.offset = ix86->regs.di;

    __asm__  __volatile__ (
        REAL_CODE (
            "pushw %%bp\n\t"
            "movw %%sp, %%bp\n\t"
            "pushw %%ax\n\t"
            "pushw %%dx\n\t"
            /* call int13_bios */
            "orb $0, %%al\n\t"
            "stc\n\t"
            "pushl %1\n\t"
            "pushw %%cs\n\t"
            "call prot_call\n\t"
            /* set es:bx */
            "pushl %%ebx\n\t"
            "popw %%bx\n\t"
            "popw %%es\n\t"
            /* set ds:si */
            "pushl %%esi\n\t"
            "popw %%si\n\t"
            "popw %%ds\n\t"
            /* set es:di */
            "pushl %%edi\n\t"
            "popw %%di\n\t"
            "popw %%es\n\t"
            /* call bios int13 */
            "pushfw\n\t"
            "lcall *%%cs:int13_vector\n\t"
            /* set flag register */
            "pushfw\n\t"
            "popw 6(%%bp)\n\t"
            "movw %%bp, %%sp\n\t"
            "popw %%bp\n\t"
        )
        : "=a" (status)
        : "i" ( int13_bios ),
          "a" (ix86->regs.ax), "b" (es_bx),
          "c" (ix86->regs.cx), "d" (ix86->regs.dx),
          "S" (ds_si), "D" (es_di));

    if ( status < 0 ) {
        DBG ( "Call bios INT13,%02x (%02x) failed with status "
               "%02x\n", ix86->regs.ah, ix86->regs.dl, ix86->regs.ah );
        dbg_printf_p (1, "Call bios INT13,%02x (%02x) failed with status "
               "%02x\n", ix86->regs.ah, ix86->regs.dl, ix86->regs.ah );
        return -INT13_STATUS_INVALID;
    }

    return INT13_STATUS_SUCCESS;
}

/**
 * bios int13 8 function
 *
 * @author sun (9/24/2015)
 *
 * @param drive         such as 0x81
 * @param chs           CHS
 *
 * @return int          status
 */
static int int13_bios_get_parameters (unsigned int drive, struct partition_chs *chs)
{
    /**
     * this function has someting wrong with the return of the
     * register, so need more test in future.
     */

    struct i386_all_regs ix86;
    int status;

    if ( chs == NULL ) {
        DBG ( "get disk parameters by bios INT13 arg err.\n" );
   
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值