Skip to content

Commit

Permalink
[prefix] Add printing functions to libprefix.S
Browse files Browse the repository at this point in the history
Move the printing functions from pxeprefix.S into libprefix.S, so they
are available for debug from any prefix.
  • Loading branch information
Michael Brown committed Mar 11, 2008
1 parent 12f203c commit 297002d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 128 deletions.
108 changes: 108 additions & 0 deletions src/arch/i386/prefix/libprefix.S
Expand Up @@ -43,6 +43,114 @@

#define CR0_PE 1

/*****************************************************************************
* Utility function: print character (with LF -> LF,CR translation)
*
* Parameters:
* %al : character to print
* Returns:
* Nothing
* Corrupts:
* %ax
*****************************************************************************
*/
.section ".prefix.lib"
.code16
.globl print_character
print_character:
/* Preserve registers */
pushw %bx
pushw %bp
/* Print character */
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
movb $0x0e, %ah /* write char, tty mode */
cmpb $0x0a, %al /* '\n'? */
jne 1f
int $0x10
movb $0x0d, %al
1: int $0x10
/* Restore registers and return */
popw %bp
popw %bx
ret
.size print_character, . - print_character

/*****************************************************************************
* Utility function: print a NUL-terminated string
*
* Parameters:
* %ds:si : string to print
* Returns:
* %ds:si : character after terminating NUL
*****************************************************************************
*/
.section ".prefix.lib"
.code16
.globl print_message
print_message:
/* Preserve registers */
pushw %ax
/* Print string */
1: lodsb
testb %al, %al
je 2f
call print_character
jmp 1b
2: /* Restore registers and return */
popw %ax
ret
.size print_message, . - print_message

/*****************************************************************************
* Utility functions: print hex digit/byte/word/dword
*
* Parameters:
* %al (low nibble) : digit to print
* %al : byte to print
* %ax : word to print
* %eax : dword to print
* Returns:
* Nothing
*****************************************************************************
*/
.section ".prefix.lib"
.code16
.globl print_hex_dword
print_hex_dword:
rorl $16, %eax
call print_hex_word
rorl $16, %eax
/* Fall through */
.size print_hex_dword, . - print_hex_dword
.globl print_hex_word
print_hex_word:
xchgb %al, %ah
call print_hex_byte
xchgb %al, %ah
/* Fall through */
.size print_hex_word, . - print_hex_word
.globl print_hex_byte
print_hex_byte:
rorb $4, %al
call print_hex_nibble
rorb $4, %al
/* Fall through */
.size print_hex_byte, . - print_hex_byte
.globl print_hex_nibble
print_hex_nibble:
/* Preserve registers */
pushw %ax
/* Print digit (technique by Norbert Juffa <norbert.juffa@amd.com> */
andb $0x0f, %al
cmpb $10, %al
sbbb $0x69, %al
das
call print_character
/* Restore registers and return */
popw %ax
ret
.size print_hex_nibble, . - print_hex_nibble

/****************************************************************************
* pm_call (real-mode near call)
*
Expand Down
106 changes: 0 additions & 106 deletions src/arch/i386/prefix/pxeprefix.S
Expand Up @@ -320,112 +320,6 @@ print_free_basemem:
finished:
jmp run_etherboot

/*****************************************************************************
* Subroutine: print character (with LF -> LF,CR translation)
*
* Parameters:
* %al : character to print
* Returns:
* Nothing
*****************************************************************************
*/
print_character:
/* Preserve registers */
pushw %ax
pushw %bx
pushw %bp
/* Print character */
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
movb $0x0e, %ah /* write char, tty mode */
cmpb $0x0a, %al /* '\n'? */
jne 1f
int $0x10
movb $0x0d, %al
1: int $0x10
/* Restore registers and return */
popw %bp
popw %bx
popw %ax
ret

/*****************************************************************************
* Subroutine: print a NUL-terminated string
*
* Parameters:
* %ds:%si : string to print
* Returns:
* Nothing
*****************************************************************************
*/
print_message:
/* Preserve registers */
pushw %ax
pushw %si
/* Print string */
1: lodsb
testb %al, %al
je 2f
call print_character
jmp 1b
2: /* Restore registers and return */
popw %si
popw %ax
ret

/*****************************************************************************
* Subroutine: print hex digit
*
* Parameters:
* %al (low nibble) : digit to print
* Returns:
* Nothing
*****************************************************************************
*/
print_hex_nibble:
/* Preserve registers */
pushw %ax
/* Print digit (technique by Norbert Juffa <norbert.juffa@amd.com> */
andb $0x0f, %al
cmpb $10, %al
sbbb $0x69, %al
das
call print_character
/* Restore registers and return */
popw %ax
ret

/*****************************************************************************
* Subroutine: print hex byte
*
* Parameters:
* %al : byte to print
* Returns:
* Nothing
*****************************************************************************
*/
print_hex_byte:
rorb $4, %al
call print_hex_nibble
rorb $4, %al
call print_hex_nibble
ret

/*****************************************************************************
* Subroutine: print hex word
*
* Parameters:
* %ax : word to print
* Returns:
* Nothing
*****************************************************************************
*/
print_hex_word:
xchgb %al, %ah
call print_hex_byte
xchgb %al, %ah
call print_hex_byte
ret

/*****************************************************************************
* Subroutine: print segment:offset address
*
Expand Down
26 changes: 4 additions & 22 deletions src/arch/i386/prefix/romprefix.S
Expand Up @@ -180,7 +180,8 @@ gotpmm: /* PMM allocation succeeded: copy ROM to PMM block */
/* Shrink ROM and update checksum */
xorw %bx, %bx
xorw %si, %si
movb $_prefix_size_sect, romheader_size
movw $_prefix_size_sect, %cx
movb %cl, romheader_size
shlw $9, %cx
1: lodsb
addb %al, %bl
Expand Down Expand Up @@ -213,7 +214,7 @@ init_message_pmm_failed:
.asciz " (failed)"
.size init_message_pmm_failed, . - init_message_pmm_failed
init_message_crlf:
.asciz "\r\n"
.asciz "\n"
.size init_message_crlf, . - init_message_crlf

/* ROM image location
Expand Down Expand Up @@ -309,7 +310,7 @@ exec: /* Set %ds = %cs */
.previous

exec_message:
.asciz "gPXE starting boot\r\n"
.asciz "gPXE starting boot\n"
.size exec_message, . - exec_message

/* UNDI loader
Expand Down Expand Up @@ -350,22 +351,3 @@ undiloader:
popl %esi
lret
.size undiloader, . - undiloader

/* Utility function: print string
*/
print_message:
pushw %ax
pushw %bx
pushw %bp
movw $0x0007, %bx
1: lodsb
testb %al, %al
je 2f
movb $0x0e, %ah /* write char, tty mode */
int $0x10
jmp 1b
2: popw %bp
popw %bx
popw %ax
ret
.size print_message, . - print_message

0 comments on commit 297002d

Please sign in to comment.