diff options
author | Matt Fleming <matt.fleming@intel.com> | 2011-10-18 13:13:06 +0100 |
---|---|---|
committer | Matt Fleming <matt.fleming@intel.com> | 2011-12-01 13:14:05 +0000 |
commit | 9f51b69d7c0500e04b3c404bb5138a9234810035 (patch) | |
tree | d566e6984457f331288f34d780f15a680334af94 /core/writehex.c | |
parent | dd5e4935f3e2f8f1940c72d9c3b39a926300c42e (diff) | |
download | syslinux-9f51b69d7c0500e04b3c404bb5138a9234810035.tar.gz |
core: Reimplement lots asm code in C
There is an awful lot of code currently implemented in assembly when
it could just as easily be implemented in C. Having it in C makes it
much easier to share code between the BIOS and forthcoming EFI
firmware backend. The following code fragments have been rewritten,
- timer initialisation
- adjust_screen()
- check_esapes() and mem_init()
- conio.inc
- plaincon.inc
- cleanup.inc
- serirq.inc
- font.inc
- graphics
- writehex
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Diffstat (limited to 'core/writehex.c')
-rw-r--r-- | core/writehex.c | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/core/writehex.c b/core/writehex.c new file mode 100644 index 00000000..fde27037 --- /dev/null +++ b/core/writehex.c @@ -0,0 +1,70 @@ +/* ----------------------------------------------------------------------- + * + * Copyright 1994-2008 H. Peter Anvin - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 53 Temple Place Ste 330, + * Boston MA 02111-1307, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + * ----------------------------------------------------------------------- + */ +#include <core.h> + +/* + * writehex.c + * + * Write hexadecimal numbers to the console + * + */ + +static inline void __writehex(uint32_t h, int digits) +{ + while (digits) { + uint8_t shift; + uint8_t al; + + shift = --digits; + al = ((h & 0x0f << shift) >> shift); + if (al < 10) + al += '0'; + else + al += 'A' - 10; + + writechr(al); + } +} + +/* + * writehex[248]: Write a hex number in (AL, AX, EAX) to the console + */ +void writehex2(uint32_t h) +{ + __writehex(h, 2); +} + +void writehex4(uint8_t h) +{ + __writehex(h, 4); +} + +void writehex8(uint8_t h) +{ + __writehex(h, 8); +} + +void pm_writehex2(com32sys_t *regs) +{ + writehex2(regs->eax.b[0]); +} + +void pm_writehex4(com32sys_t *regs) +{ + writehex4(regs->eax.w[0]); +} + +void pm_writehex8(com32sys_t *regs) +{ + writehex8(regs->eax.l); +} |