mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
Avoid a lot of malloc/free traffic
Each console write caused temporary buffer allocation. Avoid allocations by changing console_draw_str() to use Forth string parameters, which are usually readily available. Signed-off-by: Blue Swirl <blauwirbel@gmail.com> git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@872 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
@@ -85,14 +85,9 @@ stdout_write( void )
|
||||
{
|
||||
int len = POP();
|
||||
char *addr = (char*)POP();
|
||||
char *s = malloc( len + 1 );
|
||||
|
||||
strncpy_nopad( s, addr, len );
|
||||
s[len]=0;
|
||||
|
||||
/* printk( "%s", s ); */
|
||||
console_draw_str( s );
|
||||
free( s );
|
||||
console_draw_fstr(addr, len);
|
||||
|
||||
PUSH( len );
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ extern void draw_pixel( int x, int y, int colind );
|
||||
extern void set_color( int index, unsigned long color );
|
||||
|
||||
/* console.c */
|
||||
extern int console_draw_str( const char *str );
|
||||
extern int console_draw_fstr(const char *str, int len);
|
||||
extern void console_close( void );
|
||||
|
||||
/* pseudodisk.c */
|
||||
|
||||
@@ -70,16 +70,10 @@ stdout_write( void )
|
||||
{
|
||||
int len = POP();
|
||||
char *addr = (char*)POP();
|
||||
char *s = malloc( len + 1 );
|
||||
|
||||
strncpy_nopad( s, addr, len );
|
||||
s[len]=0;
|
||||
|
||||
printk( "%s", s );
|
||||
//vfd_draw_str( s );
|
||||
console_draw_str( s );
|
||||
|
||||
free( s );
|
||||
console_draw_fstr(addr, len);
|
||||
|
||||
PUSH( len );
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
extern int vfd_draw_str( const char *str );
|
||||
extern void vfd_close( void );
|
||||
|
||||
extern int console_draw_str( const char *str );
|
||||
extern int console_draw_fstr(const char *str, int len);
|
||||
|
||||
#include "kernel.h"
|
||||
|
||||
|
||||
@@ -32,12 +32,11 @@ volatile uint32_t *dac;
|
||||
|
||||
static void video_putchar(int c)
|
||||
{
|
||||
char buf[2];
|
||||
char buf;
|
||||
|
||||
buf[0] = c & 0xff;
|
||||
buf[1] = 0;
|
||||
buf = c & 0xff;
|
||||
|
||||
console_draw_str(buf);
|
||||
console_draw_fstr(&buf, 1);
|
||||
}
|
||||
|
||||
static void video_cls(void)
|
||||
|
||||
@@ -35,16 +35,10 @@ stdout_write( void )
|
||||
{
|
||||
int len = POP();
|
||||
char *addr = (char*)POP();
|
||||
char *s = malloc( len + 1 );
|
||||
|
||||
strncpy_nopad( s, addr, len );
|
||||
s[len]=0;
|
||||
|
||||
printk( "%s", s );
|
||||
//vfd_draw_str( s );
|
||||
console_draw_str( s );
|
||||
|
||||
free( s );
|
||||
console_draw_fstr(addr, len);
|
||||
|
||||
PUSH( len );
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define VIDEO_CONSOLE_H
|
||||
|
||||
/* libopenbios/console_common.c */
|
||||
int console_draw_str(const char *str);
|
||||
int console_draw_fstr(const char *str, int len);
|
||||
int console_init(void);
|
||||
void console_close(void);
|
||||
|
||||
|
||||
@@ -382,12 +382,12 @@ do_con_trol(unsigned char ch)
|
||||
}
|
||||
|
||||
int
|
||||
console_draw_str( const char *str )
|
||||
console_draw_fstr(const char *str, int len)
|
||||
{
|
||||
unsigned int y, x;
|
||||
unsigned char ch;
|
||||
|
||||
if (!str) {
|
||||
if (!str || len <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ console_draw_str( const char *str )
|
||||
return -1;
|
||||
|
||||
show_cursor(0);
|
||||
while( (ch=*str++) ) {
|
||||
while((ch = *str++) && len--) {
|
||||
do_con_trol(ch);
|
||||
|
||||
if( cons.x >= cons.w ) {
|
||||
|
||||
@@ -288,11 +288,10 @@ video_write(void)
|
||||
char *addr;
|
||||
int len;
|
||||
|
||||
len = GETTOS();
|
||||
addr = pop_fstr_copy();
|
||||
len = POP();
|
||||
addr = (char *)POP();
|
||||
|
||||
console_draw_str(addr);
|
||||
free(addr);
|
||||
console_draw_fstr(addr, len);
|
||||
PUSH(len);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user