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());
### GRUB 引导加载程序的配置与故障排除 GRUB(Grand Unified Bootloader)是一种功能强大的引导加载程序,同时具备引导加载程序和引导管理器的功能[^1]。以下将详细介绍 GRUB 的配置方法以及常见的故障排除方案。 #### 配置 GRUB 引导加载程序 1. **编辑 GRUB 配置文件** GRUB 的主要配置文件通常位于 `/etc/default/grub`。可以通过以下命令编辑该文件: ```bash sudo nano /etc/default/grub ``` 在此文件中可以修改诸如超时时间、默认启动项等参数。例如,设置超时时间为 5 秒并启用菜单显示: ```bash GRUB_TIMEOUT=5 GRUB_HIDDEN_TIMEOUT=0 GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" ``` 2. **更新 GRUB 配置** 编辑完成后,需要通过以下命令更新 GRUB 配置以使更改生效: ```bash sudo update-grub ``` 3. **自定义 GRUB 菜单项** 如果需要添加或修改特定的操作系统启动项,可以在 `/etc/grub.d/` 目录下创建自定义脚本,或者直接编辑生成的 GRUB 配置文件 `/boot/grub/grub.cfg`。需要注意的是,直接编辑 `grub.cfg` 文件可能会在下次运行 `update-grub` 时被覆盖。 #### 故障排除 1. **GRUB 未安装或文件丢失** 如果系统中未安装 GRUB 或其文件已删除,则无法使用基于现有 GRUB 配置的方法进行修复[^2]。此时可以通过 Live CD/USB 启动系统,并重新安装 GRUB: ```bash sudo grub-install /dev/sda sudo update-grub ``` 2. **GRUB 菜单未显示** 在某些情况下,GRUB 菜单可能不会自动显示[^3]。可以通过按下右 Shift 键或 ESC 键强制显示菜单。如果需要永久启用菜单显示,可以修改配置文件中的 `GRUB_HIDDEN_TIMEOUT` 参数为 0。 3. **多操作系统引导问题** 当系统中存在多个操作系统时,GRUB 可能无法正确识别所有分区。可以通过以下命令手动检测并添加分区: ```bash sudo os-prober sudo update-grub ``` 4. **依赖硬件实现的问题** BootLoader 的实现严重依赖于硬件架构,不同体系结构的系统可能存在不同的 BootLoader 实现[^4]。确保使用的 GRUB 版本与目标硬件兼容。 ```python # 示例:检查 GRUB 版本 grub_version = "grub-version" print(f"当前 GRUB 版本: {grub_version}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值