Cosmetics, coding style fixes (trivial).
Signed-off-by: Uwe Hermann <uwe@hermann-uwe.de> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3180 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
5f4c8abb65
commit
6a441bfb46
|
@ -36,7 +36,8 @@ unsigned char color_pairs[256] = {
|
||||||
[0] = 0x07,
|
[0] = 0x07,
|
||||||
};
|
};
|
||||||
|
|
||||||
int start_color(void) {
|
int start_color(void)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,45 +174,38 @@ struct {
|
||||||
static int cook_scancodes(unsigned char code)
|
static int cook_scancodes(unsigned char code)
|
||||||
{
|
{
|
||||||
static int modifiers = 0;
|
static int modifiers = 0;
|
||||||
int ch = 0, sc, shift;
|
int ch = 0, sc, shift;
|
||||||
|
|
||||||
switch(code) {
|
switch (code) {
|
||||||
case DOWN(SCANCODE_RSHIFT):
|
case DOWN(SCANCODE_RSHIFT):
|
||||||
case DOWN(SCANCODE_LSHIFT):
|
case DOWN(SCANCODE_LSHIFT):
|
||||||
modifiers |= SHIFT_MODIFIER;
|
modifiers |= SHIFT_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case UP(SCANCODE_RSHIFT):
|
case UP(SCANCODE_RSHIFT):
|
||||||
case UP(SCANCODE_LSHIFT):
|
case UP(SCANCODE_LSHIFT):
|
||||||
modifiers &= ~SHIFT_MODIFIER;
|
modifiers &= ~SHIFT_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case UP(SCANCODE_CAPSLOCK):
|
case UP(SCANCODE_CAPSLOCK):
|
||||||
if (modifiers & CAPSLOCK_MODIFIER)
|
if (modifiers & CAPSLOCK_MODIFIER)
|
||||||
modifiers &= ~CAPSLOCK_MODIFIER;
|
modifiers &= ~CAPSLOCK_MODIFIER;
|
||||||
else
|
else
|
||||||
modifiers |= CAPSLOCK_MODIFIER;
|
modifiers |= CAPSLOCK_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case DOWN(SCANCODE_LALT):
|
case DOWN(SCANCODE_LALT):
|
||||||
modifiers |= ALT_MODIFIER;
|
modifiers |= ALT_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case UP(SCANCODE_LALT):
|
case UP(SCANCODE_LALT):
|
||||||
modifiers &= ~ALT_MODIFIER;
|
modifiers &= ~ALT_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case DOWN(SCANCODE_LCTRL):
|
case DOWN(SCANCODE_LCTRL):
|
||||||
modifiers |= CTRL_MODIFIER;
|
modifiers |= CTRL_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case UP(SCANCODE_LCTRL):
|
case UP(SCANCODE_LCTRL):
|
||||||
modifiers &= ~CTRL_MODIFIER;
|
modifiers &= ~CTRL_MODIFIER;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Only process keys on an upstroke */
|
/* Only process keys on an upstroke. */
|
||||||
|
|
||||||
if (!ISUP(code))
|
if (!ISUP(code))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -231,8 +224,8 @@ static int cook_scancodes(unsigned char code)
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int curses_getchar(int delay) {
|
static int curses_getchar(int delay)
|
||||||
|
{
|
||||||
unsigned char c = 0;
|
unsigned char c = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -243,7 +236,7 @@ static int curses_getchar(int delay) {
|
||||||
if ((c & 1) == 0) {
|
if ((c & 1) == 0) {
|
||||||
|
|
||||||
if ((curses_flags & F_ENABLE_SERIAL) &&
|
if ((curses_flags & F_ENABLE_SERIAL) &&
|
||||||
serial_havechar()) {
|
serial_havechar()) {
|
||||||
c = serial_getchar();
|
c = serial_getchar();
|
||||||
return cook_serial(c);
|
return cook_serial(c);
|
||||||
}
|
}
|
||||||
|
@ -258,9 +251,9 @@ static int curses_getchar(int delay) {
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while(1);
|
} while (1);
|
||||||
|
|
||||||
return ERR;
|
return ERR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -150,20 +150,22 @@ WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
|
||||||
int flags = _SUBWIN;
|
int flags = _SUBWIN;
|
||||||
|
|
||||||
/* Make sure window fits inside the original one. */
|
/* Make sure window fits inside the original one. */
|
||||||
if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0 || num_columns < 0)
|
if (begy < 0 || begx < 0 || orig == 0 || num_lines < 0
|
||||||
return NULL;
|
|| num_columns < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (begy + num_lines > orig->_maxy + 1
|
if (begy + num_lines > orig->_maxy + 1
|
||||||
|| begx + num_columns > orig->_maxx + 1)
|
|| begx + num_columns > orig->_maxx + 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (num_lines == 0)
|
if (num_lines == 0)
|
||||||
num_lines = orig->_maxy + 1 - begy;
|
num_lines = orig->_maxy + 1 - begy;
|
||||||
|
|
||||||
if (num_columns == 0)
|
if (num_columns == 0)
|
||||||
num_columns = orig->_maxx + 1 - begx;
|
num_columns = orig->_maxx + 1 - begx;
|
||||||
|
|
||||||
if (orig->_flags & _ISPAD)
|
if (orig->_flags & _ISPAD)
|
||||||
flags |= _ISPAD;
|
flags |= _ISPAD;
|
||||||
|
|
||||||
//// if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
|
//// if ((win = _nc_makenew(num_lines, num_columns, orig->_begy + begy,
|
||||||
//// orig->_begx + begx, flags)) == 0)
|
//// orig->_begx + begx, flags)) == 0)
|
||||||
|
@ -175,7 +177,7 @@ WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
|
||||||
win->_nc_bkgd = orig->_nc_bkgd;
|
win->_nc_bkgd = orig->_nc_bkgd;
|
||||||
|
|
||||||
for (i = 0; i < num_lines; i++)
|
for (i = 0; i < num_lines; i++)
|
||||||
win->_line[i].text = &orig->_line[begy++].text[begx];
|
win->_line[i].text = &orig->_line[begy++].text[begx];
|
||||||
|
|
||||||
win->_parent = orig;
|
win->_parent = orig;
|
||||||
|
|
||||||
|
@ -217,11 +219,9 @@ WINDOW *initscr(void)
|
||||||
// def_prog_mode();
|
// def_prog_mode();
|
||||||
|
|
||||||
if (curses_flags & F_ENABLE_CONSOLE) {
|
if (curses_flags & F_ENABLE_CONSOLE) {
|
||||||
|
/* Clear the screen and kill the cursor. */
|
||||||
/* Clear the screen and kill the cursor */
|
vga_clear();
|
||||||
|
vga_cursor_enable(0);
|
||||||
vga_clear();
|
|
||||||
vga_cursor_enable(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Speaker init?
|
// Speaker init?
|
||||||
|
@ -313,7 +313,8 @@ WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
|
||||||
win->_attrs = A_NORMAL;
|
win->_attrs = A_NORMAL;
|
||||||
|
|
||||||
for (i = 0; i < num_lines; i++)
|
for (i = 0; i < num_lines; i++)
|
||||||
win->_line[i].text = (NCURSES_CH_T *)&linebuf_list[linebuf_count++];
|
win->_line[i].text =
|
||||||
|
(NCURSES_CH_T *)&linebuf_list[linebuf_count++];
|
||||||
|
|
||||||
return win;
|
return win;
|
||||||
}
|
}
|
||||||
|
@ -479,7 +480,7 @@ int wclrtoeol(WINDOW *win) { /* TODO */ return(*(int *)0); }
|
||||||
int wcolor_set(WINDOW *win, short color_pair_number, void *opts)
|
int wcolor_set(WINDOW *win, short color_pair_number, void *opts)
|
||||||
{
|
{
|
||||||
if (!opts && (color_pair_number >= 0)
|
if (!opts && (color_pair_number >= 0)
|
||||||
&& (color_pair_number < COLOR_PAIRS)) {
|
&& (color_pair_number < COLOR_PAIRS)) {
|
||||||
SET_WINDOW_PAIR(win, color_pair_number);
|
SET_WINDOW_PAIR(win, color_pair_number);
|
||||||
if_EXT_COLORS(win->_color = color_pair_number);
|
if_EXT_COLORS(win->_color = color_pair_number);
|
||||||
return OK;
|
return OK;
|
||||||
|
@ -511,7 +512,7 @@ int whline(WINDOW *win, chtype ch, int n)
|
||||||
start = win->_curx;
|
start = win->_curx;
|
||||||
end = start + n - 1;
|
end = start + n - 1;
|
||||||
if (end > win->_maxx)
|
if (end > win->_maxx)
|
||||||
end = win->_maxx;
|
end = win->_maxx;
|
||||||
|
|
||||||
CHANGED_RANGE(line, start, end);
|
CHANGED_RANGE(line, start, end);
|
||||||
|
|
||||||
|
@ -526,8 +527,8 @@ int whline(WINDOW *win, chtype ch, int n)
|
||||||
wch = _nc_render(win, wch);
|
wch = _nc_render(win, wch);
|
||||||
|
|
||||||
while (end >= start) {
|
while (end >= start) {
|
||||||
line->text[end] = wch;
|
line->text[end] = wch;
|
||||||
end--;
|
end--;
|
||||||
}
|
}
|
||||||
|
|
||||||
//// _nc_synchook(win);
|
//// _nc_synchook(win);
|
||||||
|
@ -570,25 +571,21 @@ int wnoutrefresh(WINDOW *win)
|
||||||
|
|
||||||
if (curses_flags & F_ENABLE_CONSOLE) {
|
if (curses_flags & F_ENABLE_CONSOLE) {
|
||||||
attr_t attr = win->_line[y].text[x].attr;
|
attr_t attr = win->_line[y].text[x].attr;
|
||||||
unsigned int c = ((int) color_pairs[PAIR_NUMBER(attr)]) << 8;
|
unsigned int c =
|
||||||
|
((int)color_pairs[PAIR_NUMBER(attr)]) << 8;
|
||||||
|
|
||||||
/* Handle some of the attributes */
|
/* Handle some of the attributes. */
|
||||||
|
if (attr & A_BOLD)
|
||||||
if (attr & A_BOLD) {
|
|
||||||
c |= 0x0800;
|
c |= 0x0800;
|
||||||
}
|
if (attr & A_DIM)
|
||||||
if (attr & A_DIM) {
|
|
||||||
c &= ~0x800;
|
c &= ~0x800;
|
||||||
}
|
|
||||||
if (attr & A_REVERSE) {
|
if (attr & A_REVERSE) {
|
||||||
unsigned char tmp = (c >> 8) & 0xF;
|
unsigned char tmp = (c >> 8) & 0xf;
|
||||||
c = (c >> 4) & 0xF00;
|
c = (c >> 4) & 0xf00;
|
||||||
c |= tmp << 12;
|
c |= tmp << 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
c |= win->_line[y].text[x].chars[0];
|
c |= win->_line[y].text[x].chars[0];
|
||||||
|
|
||||||
|
|
||||||
vga_putc(y, x, c);
|
vga_putc(y, x, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,26 +31,26 @@
|
||||||
#include <libpayload.h>
|
#include <libpayload.h>
|
||||||
|
|
||||||
unsigned char map[2][0x57] = {
|
unsigned char map[2][0x57] = {
|
||||||
{
|
{
|
||||||
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
||||||
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
|
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
|
||||||
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
|
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
|
||||||
0x6F, 0x70, 0x5B, 0x5D, 0x0A, 0x00, 0x61, 0x73,
|
0x6F, 0x70, 0x5B, 0x5D, 0x0A, 0x00, 0x61, 0x73,
|
||||||
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
|
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
|
||||||
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
|
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
|
||||||
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
|
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
|
||||||
0x00, 0x20,
|
0x00, 0x20,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
|
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
|
||||||
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
|
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
|
||||||
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
|
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
|
||||||
0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
|
0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
|
||||||
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
|
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
|
||||||
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
|
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
|
||||||
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
|
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
|
||||||
0x00, 0x20,
|
0x00, 0x20,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MOD_SHIFT 1
|
#define MOD_SHIFT 1
|
||||||
|
@ -78,32 +78,26 @@ int keyboard_getchar(void)
|
||||||
static int modifier;
|
static int modifier;
|
||||||
unsigned char ch;
|
unsigned char ch;
|
||||||
int shift;
|
int shift;
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
while(!keyboard_havechar())
|
while (!keyboard_havechar()) ;
|
||||||
;
|
|
||||||
|
|
||||||
ch = keyboard_get_scancode();
|
ch = keyboard_get_scancode();
|
||||||
|
|
||||||
switch(ch) {
|
switch (ch) {
|
||||||
case 0x36:
|
case 0x36:
|
||||||
case 0x2a:
|
case 0x2a:
|
||||||
modifier &= ~MOD_SHIFT;
|
modifier &= ~MOD_SHIFT;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x80 | 0x36:
|
case 0x80 | 0x36:
|
||||||
case 0x80 | 0x2a:
|
case 0x80 | 0x2a:
|
||||||
modifier |= MOD_SHIFT;
|
modifier |= MOD_SHIFT;
|
||||||
|
|
||||||
case 0x1d:
|
case 0x1d:
|
||||||
modifier &= ~MOD_CTRL;
|
modifier &= ~MOD_CTRL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x80 | 0x1d:
|
case 0x80 | 0x1d:
|
||||||
modifier |= MOD_CTRL;
|
modifier |= MOD_CTRL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x3a:
|
case 0x3a:
|
||||||
if (modifier & MOD_CAPSLOCK)
|
if (modifier & MOD_CAPSLOCK)
|
||||||
modifier &= ~MOD_CAPSLOCK;
|
modifier &= ~MOD_CAPSLOCK;
|
||||||
|
@ -112,12 +106,13 @@ int keyboard_getchar(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ch & 0x80) && ch < 0x57) {
|
if (!(ch & 0x80) && ch < 0x57) {
|
||||||
shift = (modifier & MOD_SHIFT) ^ (modifier & MOD_CAPSLOCK) ? 1 : 0;
|
shift =
|
||||||
|
(modifier & MOD_SHIFT) ^ (modifier & MOD_CAPSLOCK) ? 1 : 0;
|
||||||
ret = map[shift][ch];
|
ret = map[shift][ch];
|
||||||
|
|
||||||
if (modifier & MOD_CTRL)
|
if (modifier & MOD_CTRL)
|
||||||
ret = (ret >= 0x3F && ret <= 0x5F) ? ret & 0x1f : 0;
|
ret = (ret >= 0x3F && ret <= 0x5F) ? ret & 0x1f : 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,32 +37,32 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void serial_init(void)
|
void serial_init(void)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_SERIAL_SET_SPEED
|
#ifdef CONFIG_SERIAL_SET_SPEED
|
||||||
unsigned char reg;
|
unsigned char reg;
|
||||||
|
|
||||||
/* Disable interrupts */
|
/* Disable interrupts. */
|
||||||
outb(0, IOBASE + 0x01);
|
outb(0, IOBASE + 0x01);
|
||||||
|
|
||||||
/* Assert RTS and DTR */
|
/* Assert RTS and DTR. */
|
||||||
outb(3, IOBASE + 0x04);
|
outb(3, IOBASE + 0x04);
|
||||||
|
|
||||||
/* Set the divisor latch */
|
/* Set the divisor latch. */
|
||||||
reg = inb(IOBASE + 0x03);
|
reg = inb(IOBASE + 0x03);
|
||||||
outb(reg | 0x80, IOBASE + 0x03);
|
outb(reg | 0x80, IOBASE + 0x03);
|
||||||
|
|
||||||
/* Write the divisor */
|
/* Write the divisor. */
|
||||||
outb(DIVISOR & 0xFF, IOBASE);
|
outb(DIVISOR & 0xFF, IOBASE);
|
||||||
outb(DIVISOR >> 8 & 0xFF, IOBASE + 1);
|
outb(DIVISOR >> 8 & 0xFF, IOBASE + 1);
|
||||||
|
|
||||||
/* Restore the previous value of the divisor */
|
/* Restore the previous value of the divisor. */
|
||||||
outb(reg &= ~0x80, IOBASE + 0x03);
|
outb(reg &= ~0x80, IOBASE + 0x03);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_putchar(unsigned char c)
|
void serial_putchar(unsigned char c)
|
||||||
{
|
{
|
||||||
while((inb(IOBASE + 0x05) & 0x20) == 0);
|
while ((inb(IOBASE + 0x05) & 0x20) == 0) ;
|
||||||
outb(c, IOBASE);
|
outb(c, IOBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,6 +73,6 @@ int serial_havechar(void)
|
||||||
|
|
||||||
int serial_getchar(void)
|
int serial_getchar(void)
|
||||||
{
|
{
|
||||||
while (!serial_havechar());
|
while (!serial_havechar()) ;
|
||||||
return (int) inb(IOBASE);
|
return (int)inb(IOBASE);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
#define CRTC_INDEX 0x3d4
|
#define CRTC_INDEX 0x3d4
|
||||||
#define CRTC_DATA 0x3d5
|
#define CRTC_DATA 0x3d5
|
||||||
|
|
||||||
#define VIDEO(_r, _c)\
|
#define VIDEO(_r, _c) \
|
||||||
((uint16_t *) (0xB8000 + ((_r) * (WIDTH * 2)) + ((_c) * 2)))
|
((uint16_t *) (0xB8000 + ((_r) * (WIDTH * 2)) + ((_c) * 2)))
|
||||||
|
|
||||||
static int cursor_enabled;
|
static int cursor_enabled;
|
||||||
static int cursorx;
|
static int cursorx;
|
||||||
|
@ -49,24 +49,25 @@ static void vga_scroll_up(void);
|
||||||
|
|
||||||
static inline uint8_t crtc_read(uint8_t index)
|
static inline uint8_t crtc_read(uint8_t index)
|
||||||
{
|
{
|
||||||
outb(index, CRTC_INDEX);
|
outb(index, CRTC_INDEX);
|
||||||
return inb(CRTC_DATA);
|
return inb(CRTC_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void crtc_write(uint8_t data, uint8_t index)
|
static inline void crtc_write(uint8_t data, uint8_t index)
|
||||||
{
|
{
|
||||||
outb(index, CRTC_INDEX);
|
outb(index, CRTC_INDEX);
|
||||||
outb(data, CRTC_DATA);
|
outb(data, CRTC_DATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vga_get_cursor_pos(void)
|
static void vga_get_cursor_pos(void)
|
||||||
{
|
{
|
||||||
unsigned int addr;
|
unsigned int addr;
|
||||||
addr = ((unsigned int) crtc_read(0x0E)) << 8;
|
|
||||||
|
addr = ((unsigned int)crtc_read(0x0E)) << 8;
|
||||||
addr += crtc_read(0x0E);
|
addr += crtc_read(0x0E);
|
||||||
|
|
||||||
cursorx = addr % WIDTH;
|
cursorx = addr % WIDTH;
|
||||||
cursory = addr / WIDTH;
|
cursory = addr / WIDTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vga_fixup_cursor(void)
|
static void vga_fixup_cursor(void)
|
||||||
|
@ -78,16 +79,16 @@ static void vga_fixup_cursor(void)
|
||||||
|
|
||||||
if (cursorx < 0)
|
if (cursorx < 0)
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
|
|
||||||
if (cursory < 0)
|
if (cursory < 0)
|
||||||
cursory = 0;
|
cursory = 0;
|
||||||
|
|
||||||
if (cursorx >= WIDTH) {
|
if (cursorx >= WIDTH) {
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
cursory++;
|
cursory++;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(cursory >= HEIGHT)
|
while (cursory >= HEIGHT)
|
||||||
vga_scroll_up();
|
vga_scroll_up();
|
||||||
|
|
||||||
addr = cursorx + (WIDTH * cursory);
|
addr = cursorx + (WIDTH * cursory);
|
||||||
|
@ -102,8 +103,7 @@ void vga_cursor_enable(int state)
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
tmp |= (1 << 5);
|
tmp |= (1 << 5);
|
||||||
cursor_enabled = 0;
|
cursor_enabled = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
tmp &= ~(1 << 5);
|
tmp &= ~(1 << 5);
|
||||||
cursor_enabled = 1;
|
cursor_enabled = 1;
|
||||||
vga_fixup_cursor();
|
vga_fixup_cursor();
|
||||||
|
@ -117,19 +117,19 @@ void vga_clear_line(uint8_t row, uint8_t ch, uint8_t attr)
|
||||||
int col;
|
int col;
|
||||||
uint16_t *ptr = VIDEO(0, row);
|
uint16_t *ptr = VIDEO(0, row);
|
||||||
|
|
||||||
for(col = 0; col < WIDTH; col++)
|
for (col = 0; col < WIDTH; col++)
|
||||||
ptr[col] = ((attr & 0xFF) << 8) | (ch & 0xFF);
|
ptr[col] = ((attr & 0xFF) << 8) | (ch & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vga_scroll_up(void)
|
static void vga_scroll_up(void)
|
||||||
{
|
{
|
||||||
uint16_t *src = VIDEO(0,1);
|
uint16_t *src = VIDEO(0, 1);
|
||||||
uint16_t *dst = VIDEO(0,0);
|
uint16_t *dst = VIDEO(0, 0);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < (HEIGHT - 1) * WIDTH; i++)
|
for (i = 0; i < (HEIGHT - 1) * WIDTH; i++)
|
||||||
*dst++ = *src++;
|
*dst++ = *src++;
|
||||||
|
|
||||||
vga_clear_line(HEIGHT - 1, ' ', VGA_COLOR_WHITE);
|
vga_clear_line(HEIGHT - 1, ' ', VGA_COLOR_WHITE);
|
||||||
cursory--;
|
cursory--;
|
||||||
}
|
}
|
||||||
|
@ -137,7 +137,7 @@ static void vga_scroll_up(void)
|
||||||
void vga_fill(uint8_t ch, uint8_t attr)
|
void vga_fill(uint8_t ch, uint8_t attr)
|
||||||
{
|
{
|
||||||
uint8_t row;
|
uint8_t row;
|
||||||
for(row = 0; row < HEIGHT; row++)
|
for (row = 0; row < HEIGHT; row++)
|
||||||
vga_clear_line(row, ch, attr);
|
vga_clear_line(row, ch, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,11 +153,12 @@ void vga_putc(uint8_t row, uint8_t col, unsigned int c)
|
||||||
*ptr = (uint16_t) (c & 0xFFFF);
|
*ptr = (uint16_t) (c & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vga_putchar(unsigned int ch) {
|
void vga_putchar(unsigned int ch)
|
||||||
|
{
|
||||||
|
|
||||||
uint16_t *ptr;
|
uint16_t *ptr;
|
||||||
|
|
||||||
switch(ch & 0xFF) {
|
switch (ch & 0xFF) {
|
||||||
case '\r':
|
case '\r':
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
break;
|
break;
|
||||||
|
@ -187,30 +188,25 @@ int vga_move_cursor(int x, int y)
|
||||||
{
|
{
|
||||||
cursorx = x;
|
cursorx = x;
|
||||||
cursory = y;
|
cursory = y;
|
||||||
|
|
||||||
vga_fixup_cursor();
|
vga_fixup_cursor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vga_init(void)
|
void vga_init(void)
|
||||||
{
|
{
|
||||||
/* Get the position of the cursor */
|
/* Get the position of the cursor. */
|
||||||
vga_get_cursor_pos();
|
vga_get_cursor_pos();
|
||||||
|
|
||||||
/* See if it us currently enabled or not */
|
/* See if it currently enabled or not. */
|
||||||
cursor_enabled = !(crtc_read(0x0A) & (1 << 5));
|
cursor_enabled = !(crtc_read(0x0A) & (1 << 5));
|
||||||
|
|
||||||
/* If the cursor is enabled, get us to a sane point */
|
/* If the cursor is enabled, get us to a sane point. */
|
||||||
|
|
||||||
if (cursor_enabled) {
|
if (cursor_enabled) {
|
||||||
|
/* Go to the next line. */
|
||||||
/* Go to the next line */
|
|
||||||
|
|
||||||
if (cursorx) {
|
if (cursorx) {
|
||||||
cursorx = 0;
|
cursorx = 0;
|
||||||
cursory++;
|
cursory++;
|
||||||
}
|
}
|
||||||
|
|
||||||
vga_fixup_cursor();
|
vga_fixup_cursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,20 +31,19 @@
|
||||||
#include <sysinfo.h>
|
#include <sysinfo.h>
|
||||||
#include <coreboot_tables.h>
|
#include <coreboot_tables.h>
|
||||||
|
|
||||||
/* Some of this is x86 specific, and the rest of it
|
/*
|
||||||
is generic. Right now, since we only support x86,
|
* Some of this is x86 specific, and the rest of it is generic. Right now,
|
||||||
we'll avoid trying to make lots of infrastructure
|
* since we only support x86, we'll avoid trying to make lots of infrastructure
|
||||||
we don't need. If in the future, we want to use
|
* we don't need. If in the future, we want to use coreboot on some other
|
||||||
coreboot on some other architecture, then take out
|
* architecture, then take out the generic parsing code and move it elsewhere.
|
||||||
the generic parsing code and move it elsewhere
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
/* === Parsing code === */
|
/* === Parsing code === */
|
||||||
/* This is the generic parsing code */
|
/* This is the generic parsing code. */
|
||||||
|
|
||||||
static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_memory *mem = (struct cb_memory *) ptr;
|
struct cb_memory *mem = (struct cb_memory *)ptr;
|
||||||
int count = MEM_RANGE_COUNT(mem);
|
int count = MEM_RANGE_COUNT(mem);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -53,18 +52,18 @@ static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
|
|
||||||
info->n_memranges = 0;
|
info->n_memranges = 0;
|
||||||
|
|
||||||
for(i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
struct cb_memory_range *range =
|
struct cb_memory_range *range =
|
||||||
(struct cb_memory_range *) MEM_RANGE_PTR(mem, i);
|
(struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
|
||||||
|
|
||||||
if (range->type != CB_MEM_RAM)
|
if (range->type != CB_MEM_RAM)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
info->memrange[info->n_memranges].base =
|
info->memrange[info->n_memranges].base =
|
||||||
UNPACK_CB64(range->start);
|
UNPACK_CB64(range->start);
|
||||||
|
|
||||||
info->memrange[info->n_memranges].size =
|
info->memrange[info->n_memranges].size =
|
||||||
UNPACK_CB64(range->size);
|
UNPACK_CB64(range->size);
|
||||||
|
|
||||||
info->n_memranges++;
|
info->n_memranges++;
|
||||||
}
|
}
|
||||||
|
@ -72,55 +71,48 @@ static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
|
|
||||||
static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_serial(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_serial *ser = (struct cb_serial *) ptr;
|
struct cb_serial *ser = (struct cb_serial *)ptr;
|
||||||
info->ser_ioport = ser->ioport;
|
info->ser_ioport = ser->ioport;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_header *header;
|
struct cb_header *header;
|
||||||
unsigned char *ptr = (unsigned char *) addr;
|
unsigned char *ptr = (unsigned char *)addr;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < len; i += 16, ptr += 16) {
|
for (i = 0; i < len; i += 16, ptr += 16) {
|
||||||
header = (struct cb_header *) ptr;
|
header = (struct cb_header *)ptr;
|
||||||
|
|
||||||
if (!strncmp(header->signature, "LBIO", 4))
|
if (!strncmp(header->signature, "LBIO", 4))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We walked the entire space and didn't find anything */
|
|
||||||
|
|
||||||
|
/* We walked the entire space and didn't find anything. */
|
||||||
if (i >= len)
|
if (i >= len)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!header->table_bytes)
|
if (!header->table_bytes)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Make sure the checksums match */
|
/* Make sure the checksums match. */
|
||||||
|
|
||||||
if (ipchksum((uint16_t *) header, sizeof(*header)) != 0)
|
if (ipchksum((uint16_t *) header, sizeof(*header)) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (ipchksum((uint16_t *) (ptr + sizeof(*header)),
|
if (ipchksum((uint16_t *) (ptr + sizeof(*header)),
|
||||||
header->table_bytes) != header->table_checksum)
|
header->table_bytes) != header->table_checksum)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Now, walk the tables */
|
/* Now, walk the tables. */
|
||||||
ptr += header->header_bytes;
|
ptr += header->header_bytes;
|
||||||
|
|
||||||
for(i = 0; i < header->table_entries; i++) {
|
|
||||||
struct cb_record *rec = (struct cb_record *) ptr;
|
|
||||||
|
|
||||||
/* We only care about a few tags here - maybe
|
for (i = 0; i < header->table_entries; i++) {
|
||||||
more will be interesting later
|
struct cb_record *rec = (struct cb_record *)ptr;
|
||||||
*/
|
|
||||||
|
|
||||||
switch(rec->tag) {
|
/* We only care about a few tags here (maybe more later). */
|
||||||
|
switch (rec->tag) {
|
||||||
case CB_TAG_MEMORY:
|
case CB_TAG_MEMORY:
|
||||||
cb_parse_memory(ptr, info);
|
cb_parse_memory(ptr, info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CB_TAG_SERIAL:
|
case CB_TAG_SERIAL:
|
||||||
cb_parse_serial(ptr, info);
|
cb_parse_serial(ptr, info);
|
||||||
break;
|
break;
|
||||||
|
@ -128,19 +120,19 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
||||||
|
|
||||||
ptr += rec->size;
|
ptr += rec->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* == Architecture specific ==*/
|
/* == Architecture specific == */
|
||||||
/* This is the x86 specific stuff */
|
/* This is the x86 specific stuff. */
|
||||||
|
|
||||||
int get_coreboot_info(struct sysinfo_t *info)
|
int get_coreboot_info(struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
int ret = cb_parse_header((void *) 0x0, 0x1000, info);
|
int ret = cb_parse_header((void *)0x0, 0x1000, info);
|
||||||
|
|
||||||
if (ret != 1)
|
if (ret != 1)
|
||||||
ret = cb_parse_header((void *) 0xf0000, 0x1000, info);
|
ret = cb_parse_header((void *)0xf0000, 0x1000, info);
|
||||||
|
|
||||||
return (ret == 1) ? 0 : -1;
|
return (ret == 1) ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,60 +26,55 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global _entry, _leave
|
.global _entry, _leave
|
||||||
.text
|
.text
|
||||||
.align 4
|
.align 4
|
||||||
|
|
||||||
/* Our entry point - assume that the CPU is in
|
/*
|
||||||
* 32 bit protected mode and all segments are in a
|
* Our entry point - assume that the CPU is in 32 bit protected mode and
|
||||||
* flat model. Thats our operating mode, so we won't
|
* all segments are in a flat model. That's our operating mode, so we won't
|
||||||
* change anything
|
* change anything.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_entry:
|
_entry:
|
||||||
call _init
|
call _init
|
||||||
|
|
||||||
/* We're back - go back to the bootloader */
|
/* We're back - go back to the bootloader. */
|
||||||
ret
|
ret
|
||||||
|
|
||||||
/* This function saves off the previous stack and
|
/*
|
||||||
switches us to our own execution enviornment
|
* This function saves off the previous stack and switches us to our
|
||||||
*/
|
* own execution environment.
|
||||||
|
*/
|
||||||
_init:
|
_init:
|
||||||
/* No interrupts, please */
|
/* No interrupts, please. */
|
||||||
cli
|
cli
|
||||||
|
|
||||||
/* Get the current stack pointer */
|
/* Get the current stack pointer. */
|
||||||
movl %esp, %esi
|
movl %esp, %esi
|
||||||
|
|
||||||
movl _istack, %ebx
|
movl _istack, %ebx
|
||||||
|
|
||||||
/* lret needs %cs in the stack, so copy it over */
|
/* lret needs %cs in the stack, so copy it over. */
|
||||||
movw %cs, 4(%ebx)
|
movw %cs, 4(%ebx)
|
||||||
|
|
||||||
/* Exchange the current stack pointer for the one in
|
/*
|
||||||
the initial stack (which happens to be the new
|
* Exchange the current stack pointer for the one in the initial
|
||||||
stack pointer) */
|
* stack (which happens to be the new stack pointer).
|
||||||
|
*/
|
||||||
xchgl %esi, 16(%ebx)
|
xchgl %esi, 16(%ebx)
|
||||||
|
|
||||||
/* Set the new stack pointer */
|
/* Set the new stack pointer. */
|
||||||
movl %esi, %esp
|
movl %esi, %esp
|
||||||
|
|
||||||
/* Return into the main entry function
|
/* Return into the main entry function and go. */
|
||||||
and go
|
|
||||||
*/
|
|
||||||
|
|
||||||
lret
|
lret
|
||||||
|
|
||||||
_leave:
|
_leave:
|
||||||
movl _istack, %ebx
|
movl _istack, %ebx
|
||||||
|
|
||||||
/* Restore the stack pointer from the storage area */
|
/* Restore the stack pointer from the storage area. */
|
||||||
movl 16(%ebx), %esp
|
movl 16(%ebx), %esp
|
||||||
|
|
||||||
/* Return to the original context */
|
/* Return to the original context. */
|
||||||
lret
|
lret
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,12 @@
|
||||||
|
|
||||||
#include <arch/types.h>
|
#include <arch/types.h>
|
||||||
|
|
||||||
/* This structure seeds the stack. We provide
|
/*
|
||||||
the return address of our main function, and
|
* This structure seeds the stack. We provide the return address of our main
|
||||||
further down, the address of the function
|
* function, and further down, the address of the function that we call when
|
||||||
that we call when we leave and try to restore
|
* we leave and try to restore the original stack. At the very bottom of the
|
||||||
the original stack. At the very bottom of the
|
* stack we store the orignal stack pointer from the calling application.
|
||||||
stack we store the orignal stack pointer
|
*/
|
||||||
from the calling application
|
|
||||||
*/
|
|
||||||
|
|
||||||
static void start_main(void);
|
static void start_main(void);
|
||||||
extern void _leave(void);
|
extern void _leave(void);
|
||||||
|
@ -45,35 +43,40 @@ static struct {
|
||||||
uint32_t eip[2];
|
uint32_t eip[2];
|
||||||
uint32_t raddr[2];
|
uint32_t raddr[2];
|
||||||
uint32_t esp;
|
uint32_t esp;
|
||||||
} initial_stack __attribute__((section (".istack"))) = {
|
} initial_stack __attribute__ ((section(".istack"))) = {
|
||||||
{ (uint32_t) start_main, 0 },
|
{ (uint32_t) start_main, 0 },
|
||||||
{ (uint32_t) _leave, 0 },
|
{ (uint32_t) _leave, 0 },
|
||||||
(uint32_t) &initial_stack,
|
(uint32_t) & initial_stack,
|
||||||
};
|
};
|
||||||
|
|
||||||
void * _istack = &initial_stack;
|
void *_istack = &initial_stack;
|
||||||
|
|
||||||
/* This is our C entry function - set up the system
|
|
||||||
and jump into the payload entry point */
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is our C entry function - set up the system
|
||||||
|
* and jump into the payload entry point.
|
||||||
|
*/
|
||||||
static void start_main(void)
|
static void start_main(void)
|
||||||
{
|
{
|
||||||
extern int main(void);
|
extern int main(void);
|
||||||
|
|
||||||
/* Set up the consoles */
|
/* Set up the consoles. */
|
||||||
console_init();
|
console_init();
|
||||||
|
|
||||||
/* Gather system information */
|
/* Gather system information. */
|
||||||
lib_get_sysinfo();
|
lib_get_sysinfo();
|
||||||
|
|
||||||
/* Any other system init that has to happen before the
|
/*
|
||||||
user gets control goes here. */
|
* Any other system init that has to happen before the
|
||||||
|
* user gets control goes here.
|
||||||
|
*/
|
||||||
|
|
||||||
/* Go to the entry point */
|
/* Go to the entry point. */
|
||||||
|
|
||||||
/* in the future we may care about the return value */
|
/* In the future we may care about the return value. */
|
||||||
(void) main();
|
(void) main();
|
||||||
|
|
||||||
/* Returning here will go to the _leave function to return
|
/*
|
||||||
us to the original context */
|
* Returning here will go to the _leave function to return
|
||||||
|
* us to the original context.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,41 +30,29 @@
|
||||||
#include <libpayload.h>
|
#include <libpayload.h>
|
||||||
#include <sysinfo.h>
|
#include <sysinfo.h>
|
||||||
|
|
||||||
/* This is a global structure that is used through the
|
/**
|
||||||
library - we set it up initially with some dummy
|
* This is a global structure that is used through the library - we set it
|
||||||
values - hopefully they will be overridden
|
* up initially with some dummy values - hopefully they will be overridden.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct sysinfo_t lib_sysinfo = {
|
struct sysinfo_t lib_sysinfo = {
|
||||||
. cpu_khz = 200,
|
.cpu_khz = 200,
|
||||||
. ser_ioport = CONFIG_SERIAL_IOBASE,
|
.ser_ioport = CONFIG_SERIAL_IOBASE,
|
||||||
};
|
};
|
||||||
|
|
||||||
void lib_get_sysinfo(void)
|
void lib_get_sysinfo(void)
|
||||||
{
|
{
|
||||||
/* Get the CPU speed (for delays) */
|
/* Get the CPU speed (for delays). */
|
||||||
lib_sysinfo.cpu_khz = get_cpu_speed();
|
lib_sysinfo.cpu_khz = get_cpu_speed();
|
||||||
|
|
||||||
/* Get the memory information */
|
|
||||||
|
|
||||||
|
/* Get the memory information. */
|
||||||
get_coreboot_info(&lib_sysinfo);
|
get_coreboot_info(&lib_sysinfo);
|
||||||
|
|
||||||
if (!lib_sysinfo.n_memranges) {
|
if (!lib_sysinfo.n_memranges) {
|
||||||
|
/* If we can't get a good memory range, use the default. */
|
||||||
/* If we couldn't get a good memory range,
|
|
||||||
then use a hard coded default */
|
|
||||||
|
|
||||||
lib_sysinfo.n_memranges = 2;
|
lib_sysinfo.n_memranges = 2;
|
||||||
|
|
||||||
lib_sysinfo.memrange[0].base = 0;
|
lib_sysinfo.memrange[0].base = 0;
|
||||||
lib_sysinfo.memrange[0].size = 640 * 1024;
|
lib_sysinfo.memrange[0].size = 640 * 1024;
|
||||||
lib_sysinfo.memrange[1].base = 1024 * 1024;
|
lib_sysinfo.memrange[1].base = 1024 * 1024;
|
||||||
lib_sysinfo.memrange[1].size = 31 * 1024 * 1024;
|
lib_sysinfo.memrange[1].size = 31 * 1024 * 1024;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,53 +32,47 @@
|
||||||
|
|
||||||
static unsigned int cpu_khz;
|
static unsigned int cpu_khz;
|
||||||
|
|
||||||
/* Calculate the speed of the processor for use in delays */
|
/**
|
||||||
|
* Calculate the speed of the processor for use in delays.
|
||||||
|
*
|
||||||
|
* @return The CPU speed in kHz.
|
||||||
|
*/
|
||||||
unsigned int get_cpu_speed(void)
|
unsigned int get_cpu_speed(void)
|
||||||
{
|
{
|
||||||
unsigned long long start, end;
|
unsigned long long start, end;
|
||||||
|
|
||||||
/* Set up the PPC port - disable the speaker,
|
/* Set up the PPC port - disable the speaker, enable the T2 gate. */
|
||||||
* enable the T2 gate */
|
|
||||||
|
|
||||||
outb((inb(0x61) & ~0x02) | 0x01, 0x61);
|
outb((inb(0x61) & ~0x02) | 0x01, 0x61);
|
||||||
|
|
||||||
/* Set the PIT to Mode 0, counter 2, word access */
|
/* Set the PIT to Mode 0, counter 2, word access. */
|
||||||
outb(0xB0, 0x43);
|
outb(0xB0, 0x43);
|
||||||
|
|
||||||
/* Load the counter with 0xFFFF */
|
/* Load the counter with 0xffff. */
|
||||||
|
outb(0xff, 0x42);
|
||||||
outb(0xFF, 0x42);
|
outb(0xff, 0x42);
|
||||||
outb(0xFF, 0x42);
|
|
||||||
|
|
||||||
/* Read the number of ticks during the period */
|
|
||||||
|
|
||||||
|
/* Read the number of ticks during the period. */
|
||||||
start = rdtsc();
|
start = rdtsc();
|
||||||
while(!(inb(0x61) & 0x20));
|
while (!(inb(0x61) & 0x20)) ;
|
||||||
end = rdtsc();
|
end = rdtsc();
|
||||||
|
|
||||||
/* The clock rate is 1193180 Hz
|
/*
|
||||||
* the number of miliseconds for a period
|
* The clock rate is 1193180 Hz, the number of miliseconds for a
|
||||||
* of 0xFFFF is 1193180 / (0xFFFF * 1000)
|
* period of 0xffff is 1193180 / (0xFFFF * 1000) or .0182.
|
||||||
* or .0182. Multiply that by the number of
|
* Multiply that by the number of measured clocks to get the kHz value.
|
||||||
* measured clocks to get the khz value
|
*/
|
||||||
*/
|
cpu_khz = (unsigned int)((end - start) * 1193180U / (1000 * 0xffff));
|
||||||
|
|
||||||
cpu_khz =
|
|
||||||
(unsigned int ) ((end - start) * 1193180U / (1000 * 0xFFFF));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Global delay functions */
|
|
||||||
|
|
||||||
static inline void _delay(unsigned int delta)
|
static inline void _delay(unsigned int delta)
|
||||||
{
|
{
|
||||||
unsigned long long timeout = rdtsc() + delta;
|
unsigned long long timeout = rdtsc() + delta;
|
||||||
while (rdtsc() < timeout);
|
while (rdtsc() < timeout) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ndelay(unsigned int n)
|
void ndelay(unsigned int n)
|
||||||
{
|
{
|
||||||
_delay(n * cpu_khz / 1000000);
|
_delay(n * cpu_khz / 1000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void mdelay(unsigned int m)
|
void mdelay(unsigned int m)
|
||||||
|
|
|
@ -26,12 +26,12 @@
|
||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
.global halt
|
|
||||||
|
.global halt
|
||||||
.text
|
.text
|
||||||
.align 4
|
.align 4
|
||||||
|
|
||||||
/* This function puts the system into a halt. */
|
|
||||||
|
|
||||||
|
/* This function puts the system into a halt. */
|
||||||
halt:
|
halt:
|
||||||
cli
|
cli
|
||||||
hlt
|
hlt
|
||||||
|
|
|
@ -123,21 +123,21 @@ struct cb_console {
|
||||||
|
|
||||||
#define CB_TAG_CONSOLE_SERIAL8250 0
|
#define CB_TAG_CONSOLE_SERIAL8250 0
|
||||||
#define CB_TAG_CONSOLE_VGA 1
|
#define CB_TAG_CONSOLE_VGA 1
|
||||||
#define CB_TAG_CONSOLE_BTEXT 2
|
#define CB_TAG_CONSOLE_BTEXT 2
|
||||||
#define CB_TAG_CONSOLE_LOGBUF 3
|
#define CB_TAG_CONSOLE_LOGBUF 3
|
||||||
#define CB_TAG_CONSOLE_SROM 4
|
#define CB_TAG_CONSOLE_SROM 4
|
||||||
#define CB_TAG_CONSOLE_EHCI 5
|
#define CB_TAG_CONSOLE_EHCI 5
|
||||||
|
|
||||||
/* Still to come: CMOS information */
|
/* Still to come: CMOS information. */
|
||||||
|
|
||||||
/* Helpful macros */
|
/* Helpful macros */
|
||||||
|
|
||||||
#define MEM_RANGE_COUNT(_rec) \
|
#define MEM_RANGE_COUNT(_rec) \
|
||||||
(((_rec)->size - sizeof(*(_rec))) / sizeof((_rec)->map[0]))
|
(((_rec)->size - sizeof(*(_rec))) / sizeof((_rec)->map[0]))
|
||||||
|
|
||||||
#define MEM_RANGE_PTR(_rec, _idx) \
|
#define MEM_RANGE_PTR(_rec, _idx) \
|
||||||
(((uint8_t *) (_rec)) + sizeof(*(_rec)) \
|
(((uint8_t *) (_rec)) + sizeof(*(_rec)) \
|
||||||
+ (sizeof((_rec)->map[0]) * (_idx)))
|
+ (sizeof((_rec)->map[0]) * (_idx)))
|
||||||
|
|
||||||
#define MB_VENDOR_STRING(_mb) \
|
#define MB_VENDOR_STRING(_mb) \
|
||||||
(((unsigned char *) ((_mb)->strings)) + (_mb)->vendor_idx)
|
(((unsigned char *) ((_mb)->strings)) + (_mb)->vendor_idx)
|
||||||
|
|
|
@ -27,11 +27,10 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SYSINFO_H_
|
#ifndef SYSINFO_H
|
||||||
#define _SYSINFO_H_
|
#define SYSINFO_H
|
||||||
|
|
||||||
/* Allow a maximum of 16 memory range definitions */
|
|
||||||
|
|
||||||
|
/* Allow a maximum of 16 memory range definitions. */
|
||||||
#define SYSINFO_MAX_MEM_RANGES 16
|
#define SYSINFO_MAX_MEM_RANGES 16
|
||||||
|
|
||||||
struct sysinfo_t {
|
struct sysinfo_t {
|
||||||
|
|
|
@ -42,7 +42,7 @@ void console_init(void)
|
||||||
static void device_putchar(unsigned char c)
|
static void device_putchar(unsigned char c)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_VGA_CONSOLE
|
#ifdef CONFIG_VGA_CONSOLE
|
||||||
vga_putchar(0x700| c);
|
vga_putchar(0x700 | c);
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_SERIAL_CONSOLE
|
#ifdef CONFIG_SERIAL_CONSOLE
|
||||||
serial_putchar(c);
|
serial_putchar(c);
|
||||||
|
@ -65,10 +65,10 @@ int puts(const char *s)
|
||||||
while (*s) {
|
while (*s) {
|
||||||
putchar(*s++);
|
putchar(*s++);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
|
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
return n+1;
|
return n + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int havekey(void)
|
int havekey(void)
|
||||||
|
@ -81,13 +81,13 @@ int havekey(void)
|
||||||
if (keyboard_havechar())
|
if (keyboard_havechar())
|
||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This returns an ascii value - the two getchar functions
|
/**
|
||||||
cook the respective input from the device
|
* This returns an ASCII value - the two getchar functions
|
||||||
*/
|
* cook the respective input from the device.
|
||||||
|
*/
|
||||||
int getchar(void)
|
int getchar(void)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -101,4 +101,3 @@ int getchar(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,34 +27,36 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Basic ctype functions */
|
|
||||||
|
|
||||||
#include <libpayload.h>
|
#include <libpayload.h>
|
||||||
|
|
||||||
int isspace(int c)
|
int isspace(int c)
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case ' ': case '\f': case '\n':
|
case ' ':
|
||||||
case '\r': case '\t': case '\v':
|
case '\f':
|
||||||
return 1;
|
case '\n':
|
||||||
default:
|
case '\r':
|
||||||
return 0;
|
case '\t':
|
||||||
}
|
case '\v':
|
||||||
|
return 1;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int isdigit(int c)
|
int isdigit(int c)
|
||||||
{
|
{
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '0'...'9':
|
case '0'...'9':
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int tolower(int c)
|
int tolower(int c)
|
||||||
{
|
{
|
||||||
if (c >= 'A' && c <= 'Z')
|
if (c >= 'A' && c <= 'Z')
|
||||||
return c - 'A' + 'a';
|
return c - 'A' + 'a';
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* This file is part of the libpayload project
|
* This file is part of the libpayload project.
|
||||||
|
*
|
||||||
|
* It has orginally been taken from the FreeBSD project.
|
||||||
*
|
*
|
||||||
* Copyright (c) 2001 Charles Mott <cm@linktel.net>
|
* Copyright (c) 2001 Charles Mott <cm@linktel.net>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
|
@ -30,20 +32,20 @@
|
||||||
|
|
||||||
unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes)
|
unsigned short ipchksum(const unsigned short *ptr, unsigned long nbytes)
|
||||||
{
|
{
|
||||||
int sum, oddbyte;
|
int sum, oddbyte;
|
||||||
|
|
||||||
sum = 0;
|
sum = 0;
|
||||||
while (nbytes > 1) {
|
while (nbytes > 1) {
|
||||||
sum += *ptr++;
|
sum += *ptr++;
|
||||||
nbytes -= 2;
|
nbytes -= 2;
|
||||||
}
|
}
|
||||||
if (nbytes == 1) {
|
if (nbytes == 1) {
|
||||||
oddbyte = 0;
|
oddbyte = 0;
|
||||||
((u8 *) &oddbyte)[0] = *(u8 *)ptr;
|
((u8 *) & oddbyte)[0] = *(u8 *) ptr;
|
||||||
((u8 *) &oddbyte)[1] = 0;
|
((u8 *) & oddbyte)[1] = 0;
|
||||||
sum += oddbyte;
|
sum += oddbyte;
|
||||||
}
|
}
|
||||||
sum = (sum >> 16) + (sum & 0xffff);
|
sum = (sum >> 16) + (sum & 0xffff);
|
||||||
sum += (sum >> 16);
|
sum += (sum >> 16);
|
||||||
return (~sum);
|
return (~sum);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,24 +27,23 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* This is a classically weak malloc() implmentation.
|
/*
|
||||||
We have a relatively small and static heap, so we take
|
* This is a classically weak malloc() implmentation. We have a relatively
|
||||||
the easy route with an O(N) loop through the tree for
|
* small and static heap, so we take the easy route with an O(N) loop
|
||||||
every malloc() and free(). Obviously, this doesn't scale
|
* through the tree for every malloc() and free(). Obviously, this doesn't
|
||||||
past a few hundred K (if that).
|
* scale past a few hundred KB (if that).
|
||||||
|
*
|
||||||
|
* We're also susecptable to the usual buffer overun poisoning, though the
|
||||||
|
* risk is within acceptable ranges for this implementation (don't overrun
|
||||||
|
* your buffers, kids!).
|
||||||
|
*/
|
||||||
|
|
||||||
We're also susecptable to the usual buffer overun poisoning,
|
|
||||||
though the risk is within acceptable ranges for this
|
|
||||||
implementation (don't overrun your buffers, kids!)
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <libpayload.h>
|
#include <libpayload.h>
|
||||||
|
|
||||||
/* Defined in the ldscript */
|
extern char _heap, _eheap; /* Defined in the ldscript. */
|
||||||
extern char _heap, _eheap;
|
|
||||||
|
|
||||||
static void *hstart = (void *) &_heap;
|
static void *hstart = (void *)&_heap;
|
||||||
static void *hend = (void *) &_eheap;
|
static void *hend = (void *)&_eheap;
|
||||||
|
|
||||||
typedef unsigned int hdrtype_t;
|
typedef unsigned int hdrtype_t;
|
||||||
|
|
||||||
|
@ -66,66 +65,64 @@ typedef unsigned int hdrtype_t;
|
||||||
|
|
||||||
void print_malloc_map(void);
|
void print_malloc_map(void);
|
||||||
|
|
||||||
static void setup(void)
|
static void setup(void)
|
||||||
{
|
{
|
||||||
int size = (unsigned int) (_heap - _eheap) - HDRSIZE;
|
int size = (unsigned int)(_heap - _eheap) - HDRSIZE;
|
||||||
*((hdrtype_t *) hstart) = FREE_BLOCK(size);
|
*((hdrtype_t *) hstart) = FREE_BLOCK(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *alloc(int len)
|
static void *alloc(int len)
|
||||||
{
|
{
|
||||||
hdrtype_t header;
|
hdrtype_t header;
|
||||||
void *ptr = hstart;
|
void *ptr = hstart;
|
||||||
|
|
||||||
/* align the size */
|
/* Align the size. */
|
||||||
len = (len + 3) & ~3;
|
len = (len + 3) & ~3;
|
||||||
|
|
||||||
if (!len || len > 0xFFFFFF)
|
if (!len || len > 0xffffff)
|
||||||
return (void *) NULL;
|
return (void *)NULL;
|
||||||
|
|
||||||
/* Make sure the region is setup correctly */
|
/* Make sure the region is setup correctly. */
|
||||||
if (!HAS_MAGIC(*((hdrtype_t *) ptr)))
|
if (!HAS_MAGIC(*((hdrtype_t *) ptr)))
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
/* Find some free space */
|
/* Find some free space. */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
header = *((hdrtype_t *) ptr);
|
header = *((hdrtype_t *) ptr);
|
||||||
int size = SIZE(header);
|
int size = SIZE(header);
|
||||||
|
|
||||||
if (header & FLAG_FREE) {
|
if (header & FLAG_FREE) {
|
||||||
|
|
||||||
if (len <= size) {
|
if (len <= size) {
|
||||||
void *nptr = ptr + HDRSIZE + len;
|
void *nptr = ptr + HDRSIZE + len;
|
||||||
int nsize = size - (len + 8);
|
int nsize = size - (len + 8);
|
||||||
|
|
||||||
/* Mark the block as used */
|
/* Mark the block as used. */
|
||||||
*((hdrtype_t *) ptr) = USED_BLOCK(len);
|
*((hdrtype_t *) ptr) = USED_BLOCK(len);
|
||||||
|
|
||||||
/* If there is still room in this block,
|
/* If there is still room in this block,
|
||||||
* then mark it as such */
|
* then mark it as such.
|
||||||
|
*/
|
||||||
if (nsize > 0)
|
if (nsize > 0)
|
||||||
*((hdrtype_t *) nptr) =
|
*((hdrtype_t *) nptr) =
|
||||||
FREE_BLOCK(nsize - 4);
|
FREE_BLOCK(nsize - 4);
|
||||||
|
|
||||||
return (void *) (ptr + HDRSIZE);
|
return (void *)(ptr + HDRSIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ptr += HDRSIZE + size;
|
ptr += HDRSIZE + size;
|
||||||
|
|
||||||
} while(ptr < hend);
|
} while (ptr < hend);
|
||||||
|
|
||||||
/* Nothing available */
|
/* Nothing available. */
|
||||||
return (void *) NULL;
|
return (void *)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _consolidate(void)
|
static void _consolidate(void)
|
||||||
{
|
{
|
||||||
void *ptr = hstart;
|
void *ptr = hstart;
|
||||||
|
|
||||||
while(ptr < hend) {
|
while (ptr < hend) {
|
||||||
void *nptr;
|
void *nptr;
|
||||||
hdrtype_t hdr = *((hdrtype_t *) ptr);
|
hdrtype_t hdr = *((hdrtype_t *) ptr);
|
||||||
unsigned int size = 0;
|
unsigned int size = 0;
|
||||||
|
@ -134,23 +131,23 @@ static void _consolidate(void)
|
||||||
ptr += HDRSIZE + SIZE(hdr);
|
ptr += HDRSIZE + SIZE(hdr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
size = SIZE(hdr);
|
size = SIZE(hdr);
|
||||||
nptr = ptr + HDRSIZE + SIZE(hdr);
|
nptr = ptr + HDRSIZE + SIZE(hdr);
|
||||||
|
|
||||||
while (nptr < hend) {
|
while (nptr < hend) {
|
||||||
hdrtype_t nhdr = *((hdrtype_t *) nptr);
|
hdrtype_t nhdr = *((hdrtype_t *) nptr);
|
||||||
|
|
||||||
if (!(IS_FREE(nhdr)))
|
if (!(IS_FREE(nhdr)))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
size += SIZE(nhdr) + HDRSIZE;
|
size += SIZE(nhdr) + HDRSIZE;
|
||||||
|
|
||||||
*((hdrtype_t *) nptr) = 0;
|
*((hdrtype_t *) nptr) = 0;
|
||||||
|
|
||||||
nptr += (HDRSIZE + SIZE(nhdr));
|
nptr += (HDRSIZE + SIZE(nhdr));
|
||||||
}
|
}
|
||||||
|
|
||||||
*((hdrtype_t *) ptr) = FREE_BLOCK(size);
|
*((hdrtype_t *) ptr) = FREE_BLOCK(size);
|
||||||
ptr = nptr;
|
ptr = nptr;
|
||||||
}
|
}
|
||||||
|
@ -162,20 +159,20 @@ void free(void *ptr)
|
||||||
|
|
||||||
ptr -= HDRSIZE;
|
ptr -= HDRSIZE;
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check. */
|
||||||
if (ptr < hstart || ptr >= hend)
|
if (ptr < hstart || ptr >= hend)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
hdr = *((hdrtype_t *) ptr);
|
hdr = *((hdrtype_t *) ptr);
|
||||||
|
|
||||||
/* Not our header (we're probably poisoned) */
|
/* Not our header (we're probably poisoned). */
|
||||||
if (!HAS_MAGIC(hdr))
|
if (!HAS_MAGIC(hdr))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Double free */
|
/* Double free. */
|
||||||
if (hdr & FLAG_FREE)
|
if (hdr & FLAG_FREE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
*((hdrtype_t *) ptr) = FREE_BLOCK(SIZE(hdr));
|
*((hdrtype_t *) ptr) = FREE_BLOCK(SIZE(hdr));
|
||||||
_consolidate();
|
_consolidate();
|
||||||
}
|
}
|
||||||
|
@ -198,8 +195,7 @@ void *calloc(size_t nmemb, size_t size)
|
||||||
|
|
||||||
void *realloc(void *ptr, size_t size)
|
void *realloc(void *ptr, size_t size)
|
||||||
{
|
{
|
||||||
void *ret;
|
void *ret, *pptr;
|
||||||
void *pptr;
|
|
||||||
unsigned int osize;
|
unsigned int osize;
|
||||||
|
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
|
@ -209,38 +205,38 @@ void *realloc(void *ptr, size_t size)
|
||||||
|
|
||||||
if (!HAS_MAGIC(*((hdrtype_t *) pptr)))
|
if (!HAS_MAGIC(*((hdrtype_t *) pptr)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Get the original size of the block */
|
|
||||||
osize = SIZE(*((hdrtype_t *) pptr));
|
|
||||||
|
|
||||||
/* Free the memory to update the tables - this
|
|
||||||
won't touch the actual memory, so we can still
|
|
||||||
use it for the copy after we have reallocated
|
|
||||||
the new space
|
|
||||||
*/
|
|
||||||
|
|
||||||
free(ptr);
|
/* Get the original size of the block. */
|
||||||
|
osize = SIZE(*((hdrtype_t *) pptr));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free the memory to update the tables - this won't touch the actual
|
||||||
|
* memory, so we can still use it for the copy after we have
|
||||||
|
* reallocated the new space.
|
||||||
|
*/
|
||||||
|
free(ptr);
|
||||||
ret = alloc(size);
|
ret = alloc(size);
|
||||||
|
|
||||||
/* if ret == NULL, then doh - failure.
|
/*
|
||||||
if ret == ptr then woo-hoo! no copy needed */
|
* if ret == NULL, then doh - failure.
|
||||||
|
* if ret == ptr then woo-hoo! no copy needed.
|
||||||
|
*/
|
||||||
if (ret == NULL || ret == ptr)
|
if (ret == NULL || ret == ptr)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
/* Copy the memory to the new location */
|
/* Copy the memory to the new location. */
|
||||||
memcpy(ret, ptr, osize > size ? size : osize);
|
memcpy(ret, ptr, osize > size ? size : osize);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This is for debugging purposes */
|
/* This is for debugging purposes. */
|
||||||
#ifdef TEST
|
#ifdef TEST
|
||||||
|
|
||||||
void print_malloc_map(void)
|
void print_malloc_map(void)
|
||||||
{
|
{
|
||||||
void *ptr = hstart;
|
void *ptr = hstart;
|
||||||
|
|
||||||
while(ptr < hend) {
|
while (ptr < hend) {
|
||||||
hdrtype_t hdr = *((hdrtype_t *) ptr);
|
hdrtype_t hdr = *((hdrtype_t *) ptr);
|
||||||
|
|
||||||
if (!HAS_MAGIC(hdr)) {
|
if (!HAS_MAGIC(hdr)) {
|
||||||
|
@ -248,15 +244,13 @@ void print_malloc_map(void)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* FIXME: Verify the size of the block */
|
/* FIXME: Verify the size of the block. */
|
||||||
|
|
||||||
printf("%x: %s (%x bytes)\n",
|
printf("%x: %s (%x bytes)\n",
|
||||||
(unsigned int) (ptr - hstart),
|
(unsigned int)(ptr - hstart),
|
||||||
hdr & FLAG_FREE ? "FREE" : "USED",
|
hdr & FLAG_FREE ? "FREE" : "USED", SIZE(hdr));
|
||||||
SIZE(hdr));
|
|
||||||
|
|
||||||
ptr += HDRSIZE + SIZE(hdr);
|
ptr += HDRSIZE + SIZE(hdr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -101,12 +101,11 @@ void *memmove(void *dst, const void *src, size_t n)
|
||||||
/**
|
/**
|
||||||
* Compare two memory areas.
|
* Compare two memory areas.
|
||||||
*
|
*
|
||||||
* @param s1 Pointer to the first area to compare.
|
* @param s1 Pointer to the first area to compare.
|
||||||
* @param s2 Pointer to the second area to compare.
|
* @param s2 Pointer to the second area to compare.
|
||||||
* @param len Size of the first area in bytes. Both areas must have the same
|
* @param len Size of the first area in bytes (both must have the same length).
|
||||||
* length.
|
* @return If len is 0, return zero. If the areas match, return zero.
|
||||||
* @return If len is 0, return zero. If the areas match, return zero.
|
* Otherwise return non-zero.
|
||||||
* Otherwise return non-zero.
|
|
||||||
*/
|
*/
|
||||||
int memcmp(const char *s1, const char *s2, size_t len)
|
int memcmp(const char *s1, const char *s2, size_t len)
|
||||||
{
|
{
|
||||||
|
|
|
@ -135,8 +135,8 @@ char *strncpy(char *d, const char *s, int n)
|
||||||
int max = n > strlen(s) + 1 ? strlen(s) + 1 : n;
|
int max = n > strlen(s) + 1 ? strlen(s) + 1 : n;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < max; i++)
|
for (i = 0; i < max; i++)
|
||||||
d[i] = (char) s[i];
|
d[i] = (char)s[i];
|
||||||
|
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
@ -152,18 +152,18 @@ char *strncat(char *d, const char *s, int n)
|
||||||
int max = n > strlen(s) ? strlen(s) : n;
|
int max = n > strlen(s) ? strlen(s) : n;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i < max; i++)
|
for (i = 0; i < max; i++)
|
||||||
p[i] = s[i];
|
p[i] = s[i];
|
||||||
|
|
||||||
p[i] = '\0';
|
p[i] = '\0';
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
char * strchr(const char *s, int c)
|
char *strchr(const char *s, int c)
|
||||||
{
|
{
|
||||||
char *p = (char *) s;
|
char *p = (char *)s;
|
||||||
|
|
||||||
for( ; *p != 0; p++) {
|
for (; *p != 0; p++) {
|
||||||
if (*p == c)
|
if (*p == c)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,6 @@ char * strchr(const char *s, int c)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *strdup(const char *s)
|
char *strdup(const char *s)
|
||||||
{
|
{
|
||||||
int n = strlen(s);
|
int n = strlen(s);
|
||||||
|
@ -189,11 +188,9 @@ char *strstr(const char *h, const char *n)
|
||||||
int nn = strlen(n);
|
int nn = strlen(n);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for(i = 0; i <= hn - nn; i++)
|
for (i = 0; i <= hn - nn; i++)
|
||||||
if (!strcmp(&h[i], n))
|
if (!strcmp(&h[i], n))
|
||||||
return (char *) &h[i];
|
return (char *)&h[i];
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,15 @@
|
||||||
|
|
||||||
# Sample libpayload Makefile.
|
# Sample libpayload Makefile.
|
||||||
|
|
||||||
CC=gcc
|
CC = gcc
|
||||||
CROSS_CFLAGS = -m32
|
CROSS_CFLAGS = -m32
|
||||||
|
|
||||||
INCLUDES=-I../include
|
INCLUDES = -I../include
|
||||||
INCLUDES += -I$(shell $(CC) $(CROSS_CFLAGS) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
|
INCLUDES += -I$(shell $(CC) $(CROSS_CFLAGS) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
|
||||||
|
|
||||||
LIBPAYLOAD=../libpayload.a
|
LIBPAYLOAD = ../libpayload.a
|
||||||
LIBGCC:=$(shell $(CC) $(CROSS_CFLAGS) -print-libgcc-file-name)
|
LIBGCC := $(shell $(CC) $(CROSS_CFLAGS) -print-libgcc-file-name)
|
||||||
CFLAGS := -Werror -fno-stack-protector -nostdinc $(INCLUDES)
|
CFLAGS := -Werror -Os -fno-stack-protector -nostdinc $(INCLUDES)
|
||||||
|
|
||||||
all: hello.elf
|
all: hello.elf
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,8 @@
|
||||||
|
|
||||||
#include <libpayload.h>
|
#include <libpayload.h>
|
||||||
|
|
||||||
int main(void) {
|
int main(void)
|
||||||
|
{
|
||||||
printf("Hello world!\n");
|
printf("Hello world!\n");
|
||||||
halt();
|
halt();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue