grub显示时间

                                                       grub显示时间

./stage2/asm.S中的getrtsecs处,添加获取年月日时分的方法。

/*
* getrtsecs()
*      if a seconds value can be read, read it and return it (BCD),
*      otherwise return 0xFF
* BIOS call "INT 1AH Function 02H" to check whether a character is pending
*      Call with       %ah = 0x2
*      Return:
*              If RT Clock can give correct values
*                      %ch = hour (BCD)
*                      %cl = minutes (BCD)
*                      %dh = seconds (BCD)
*                      %dl = daylight savings time (00h std, 01h daylight)
*                      Carry flag = clear
*              else
*                      Carry flag = set
*                         (this indicates that the clock is updating, or
*                          that it isn't running)
*/
ENTRY(getrtsecs)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x2, %ah
       int     $0x1a

       DATA32  jnc     gottime
       movb    $0xff, %dh

gottime:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %dh, %al

       pop     %ebp
       ret

改为如下内容:

ENTRY(getrtsecs)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x2, %ah
       int     $0x1a

       DATA32  jnc     gottime
       movb    $0xff, %dh

gottime:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %dh, %al

       pop     %ebp
       ret
ENTRY(getrtmins)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x2, %ah
       int     $0x1a

       DATA32  jnc     gotmin
       movb    $0xff, %dh

gotmin:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %cl, %al

       pop     %ebp
       ret
ENTRY(getrthous)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x2, %ah
       int     $0x1a

       DATA32  jnc     gothou
       movb    $0xff, %dh

gothou:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %ch, %al

       pop     %ebp
       ret

ENTRY(getrtday)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x4, %ah
       int     $0x1a

       DATA32  jnc     gotday
       movb    $0xff, %dh

gotday:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %dh, %al

       pop     %ebp
       ret

ENTRY(getrtmon)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x4, %ah
       int     $0x1a

       DATA32  jnc     gotmon
       movb    $0xff, %dh

gotmon:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %dh, %al

       pop     %ebp
       ret

ENTRY(getrtyea)
       push    %ebp

       call    EXT_C(prot_to_real)     /* enter real mode */
       .code16

       movb    $0x4, %ah
       int     $0x1a

       DATA32  jnc     gotyea
       movb    $0xff, %dh

gotyea:
       DATA32  call    EXT_C(real_to_prot)
       .code32

       movb    %dh, %al

       pop     %ebp
       ret

./stage2/shared.h中的如下位置中

/* low-level timing info */
int getrtsecs (void);
int currticks (void);

添加为如下代码,声明我们添加的方法

/* low-level timing info */
int getrtsecs (void);
int getrtmins (void);
int getrthous (void);
int getrtday (void);
int getrtmon (void);
int getrtyea (void);
int currticks (void);

./grub/asmstub.c中的如下位置中

/* low-level timing info */
int
getrtsecs (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
  return time (0);
}

添加为如下代码,声明我们添加的方法

/* low-level timing info */
int
getrtsecs (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
  return time (0);
} 

int
getrtmins (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
    return time (0);
}

int
getrthous (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
    return time (0);
}

int
getrtday (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
    return time (0);
}

int
getrtmon (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
    return time (0);
}

int
getrtyea (void)
{
  /* FIXME: exact value is not important, so just return time_t for now. */
   return time (0);
}

./stage2/stage2.c中的320行,我们修改为

printf ("/
Press enter to boot the selected OS, /'e/' to edit the/n/
commands before booting, or /'c/' for a command-line.year %d month
%d day %d hour %d min %d second  %d",getrtyea(),getrtmon(),
getrtday(),getrthous(),getrtmins(),getrtsecs());
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值