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());
2438

被折叠的 条评论
为什么被折叠?



