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,
|
||||
};
|
||||
|
||||
int start_color(void) {
|
||||
int start_color(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -181,38 +181,31 @@ static int cook_scancodes(unsigned char code)
|
|||
case DOWN(SCANCODE_LSHIFT):
|
||||
modifiers |= SHIFT_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case UP(SCANCODE_RSHIFT):
|
||||
case UP(SCANCODE_LSHIFT):
|
||||
modifiers &= ~SHIFT_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case UP(SCANCODE_CAPSLOCK):
|
||||
if (modifiers & CAPSLOCK_MODIFIER)
|
||||
modifiers &= ~CAPSLOCK_MODIFIER;
|
||||
else
|
||||
modifiers |= CAPSLOCK_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case DOWN(SCANCODE_LALT):
|
||||
modifiers |= ALT_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case UP(SCANCODE_LALT):
|
||||
modifiers &= ~ALT_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case DOWN(SCANCODE_LCTRL):
|
||||
modifiers |= CTRL_MODIFIER;
|
||||
return 0;
|
||||
|
||||
case UP(SCANCODE_LCTRL):
|
||||
modifiers &= ~CTRL_MODIFIER;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Only process keys on an upstroke */
|
||||
|
||||
/* Only process keys on an upstroke. */
|
||||
if (!ISUP(code))
|
||||
return 0;
|
||||
|
||||
|
@ -231,8 +224,8 @@ static int cook_scancodes(unsigned char code)
|
|||
return ch;
|
||||
}
|
||||
|
||||
static int curses_getchar(int delay) {
|
||||
|
||||
static int curses_getchar(int delay)
|
||||
{
|
||||
unsigned char c = 0;
|
||||
int ret;
|
||||
|
||||
|
|
|
@ -150,8 +150,10 @@ WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx)
|
|||
int flags = _SUBWIN;
|
||||
|
||||
/* 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
|
||||
|| num_columns < 0)
|
||||
return NULL;
|
||||
|
||||
if (begy + num_lines > orig->_maxy + 1
|
||||
|| begx + num_columns > orig->_maxx + 1)
|
||||
return NULL;
|
||||
|
@ -217,9 +219,7 @@ WINDOW *initscr(void)
|
|||
// def_prog_mode();
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -313,7 +313,8 @@ WINDOW *newwin(int num_lines, int num_columns, int begy, int begx)
|
|||
win->_attrs = A_NORMAL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -570,25 +571,21 @@ int wnoutrefresh(WINDOW *win)
|
|||
|
||||
if (curses_flags & F_ENABLE_CONSOLE) {
|
||||
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 */
|
||||
|
||||
if (attr & A_BOLD) {
|
||||
/* Handle some of the attributes. */
|
||||
if (attr & A_BOLD)
|
||||
c |= 0x0800;
|
||||
}
|
||||
if (attr & A_DIM) {
|
||||
if (attr & A_DIM)
|
||||
c &= ~0x800;
|
||||
}
|
||||
if (attr & A_REVERSE) {
|
||||
unsigned char tmp = (c >> 8) & 0xF;
|
||||
c = (c >> 4) & 0xF00;
|
||||
unsigned char tmp = (c >> 8) & 0xf;
|
||||
c = (c >> 4) & 0xf00;
|
||||
c |= tmp << 12;
|
||||
}
|
||||
|
||||
c |= win->_line[y].text[x].chars[0];
|
||||
|
||||
|
||||
vga_putc(y, x, c);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,11 +78,9 @@ int keyboard_getchar(void)
|
|||
static int modifier;
|
||||
unsigned char ch;
|
||||
int shift;
|
||||
|
||||
int ret = 0;
|
||||
|
||||
while(!keyboard_havechar())
|
||||
;
|
||||
while (!keyboard_havechar()) ;
|
||||
|
||||
ch = keyboard_get_scancode();
|
||||
|
||||
|
@ -91,19 +89,15 @@ int keyboard_getchar(void)
|
|||
case 0x2a:
|
||||
modifier &= ~MOD_SHIFT;
|
||||
break;
|
||||
|
||||
case 0x80 | 0x36:
|
||||
case 0x80 | 0x2a:
|
||||
modifier |= MOD_SHIFT;
|
||||
|
||||
case 0x1d:
|
||||
modifier &= ~MOD_CTRL;
|
||||
break;
|
||||
|
||||
case 0x80 | 0x1d:
|
||||
modifier |= MOD_CTRL;
|
||||
break;
|
||||
|
||||
case 0x3a:
|
||||
if (modifier & MOD_CAPSLOCK)
|
||||
modifier &= ~MOD_CAPSLOCK;
|
||||
|
@ -113,7 +107,8 @@ int keyboard_getchar(void)
|
|||
}
|
||||
|
||||
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];
|
||||
|
||||
if (modifier & MOD_CTRL)
|
||||
|
|
|
@ -41,21 +41,21 @@ void serial_init(void)
|
|||
#ifdef CONFIG_SERIAL_SET_SPEED
|
||||
unsigned char reg;
|
||||
|
||||
/* Disable interrupts */
|
||||
/* Disable interrupts. */
|
||||
outb(0, IOBASE + 0x01);
|
||||
|
||||
/* Assert RTS and DTR */
|
||||
/* Assert RTS and DTR. */
|
||||
outb(3, IOBASE + 0x04);
|
||||
|
||||
/* Set the divisor latch */
|
||||
/* Set the divisor latch. */
|
||||
reg = inb(IOBASE + 0x03);
|
||||
outb(reg | 0x80, IOBASE + 0x03);
|
||||
|
||||
/* Write the divisor */
|
||||
/* Write the divisor. */
|
||||
outb(DIVISOR & 0xFF, IOBASE);
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ static inline void crtc_write(uint8_t data, uint8_t index)
|
|||
static void vga_get_cursor_pos(void)
|
||||
{
|
||||
unsigned int addr;
|
||||
|
||||
addr = ((unsigned int)crtc_read(0x0E)) << 8;
|
||||
addr += crtc_read(0x0E);
|
||||
|
||||
|
@ -102,8 +103,7 @@ void vga_cursor_enable(int state)
|
|||
if (state == 0) {
|
||||
tmp |= (1 << 5);
|
||||
cursor_enabled = 0;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
tmp &= ~(1 << 5);
|
||||
cursor_enabled = 1;
|
||||
vga_fixup_cursor();
|
||||
|
@ -153,7 +153,8 @@ void vga_putc(uint8_t row, uint8_t col, unsigned int c)
|
|||
*ptr = (uint16_t) (c & 0xFFFF);
|
||||
}
|
||||
|
||||
void vga_putchar(unsigned int ch) {
|
||||
void vga_putchar(unsigned int ch)
|
||||
{
|
||||
|
||||
uint16_t *ptr;
|
||||
|
||||
|
@ -193,24 +194,19 @@ int vga_move_cursor(int x, int y)
|
|||
|
||||
void vga_init(void)
|
||||
{
|
||||
/* Get the position of the cursor */
|
||||
/* Get the position of the cursor. */
|
||||
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));
|
||||
|
||||
/* 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) {
|
||||
|
||||
/* Go to the next line */
|
||||
|
||||
/* Go to the next line. */
|
||||
if (cursorx) {
|
||||
cursorx = 0;
|
||||
cursory++;
|
||||
}
|
||||
|
||||
vga_fixup_cursor();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,16 +31,15 @@
|
|||
#include <sysinfo.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,
|
||||
we'll avoid trying to make lots of infrastructure
|
||||
we don't need. If in the future, we want to use
|
||||
coreboot on some other architecture, then take out
|
||||
the generic parsing code and move it elsewhere
|
||||
/*
|
||||
* Some of this is x86 specific, and the rest of it is generic. Right now,
|
||||
* 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 coreboot on some other
|
||||
* architecture, then take out the generic parsing code and move it elsewhere.
|
||||
*/
|
||||
|
||||
/* === 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)
|
||||
{
|
||||
|
@ -84,21 +83,18 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
|||
|
||||
for (i = 0; i < len; i += 16, ptr += 16) {
|
||||
header = (struct cb_header *)ptr;
|
||||
|
||||
if (!strncmp(header->signature, "LBIO", 4))
|
||||
break;
|
||||
}
|
||||
|
||||
/* We walked the entire space and didn't find anything */
|
||||
|
||||
/* We walked the entire space and didn't find anything. */
|
||||
if (i >= len)
|
||||
return -1;
|
||||
|
||||
if (!header->table_bytes)
|
||||
return 0;
|
||||
|
||||
/* Make sure the checksums match */
|
||||
|
||||
/* Make sure the checksums match. */
|
||||
if (ipchksum((uint16_t *) header, sizeof(*header)) != 0)
|
||||
return -1;
|
||||
|
||||
|
@ -106,21 +102,17 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
|||
header->table_bytes) != header->table_checksum)
|
||||
return -1;
|
||||
|
||||
/* Now, walk the tables */
|
||||
/* Now, walk the tables. */
|
||||
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
|
||||
more will be interesting later
|
||||
*/
|
||||
|
||||
/* We only care about a few tags here (maybe more later). */
|
||||
switch (rec->tag) {
|
||||
case CB_TAG_MEMORY:
|
||||
cb_parse_memory(ptr, info);
|
||||
break;
|
||||
|
||||
case CB_TAG_SERIAL:
|
||||
cb_parse_serial(ptr, info);
|
||||
break;
|
||||
|
@ -133,7 +125,7 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
|
|||
}
|
||||
|
||||
/* == Architecture specific == */
|
||||
/* This is the x86 specific stuff */
|
||||
/* This is the x86 specific stuff. */
|
||||
|
||||
int get_coreboot_info(struct sysinfo_t *info)
|
||||
{
|
||||
|
|
|
@ -31,55 +31,50 @@
|
|||
.text
|
||||
.align 4
|
||||
|
||||
/* Our entry point - assume that the CPU is in
|
||||
* 32 bit protected mode and all segments are in a
|
||||
* flat model. Thats our operating mode, so we won't
|
||||
* change anything
|
||||
/*
|
||||
* Our entry point - assume that the CPU is in 32 bit protected mode and
|
||||
* all segments are in a flat model. That's our operating mode, so we won't
|
||||
* change anything.
|
||||
*/
|
||||
|
||||
_entry:
|
||||
call _init
|
||||
|
||||
/* We're back - go back to the bootloader */
|
||||
/* We're back - go back to the bootloader. */
|
||||
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:
|
||||
/* No interrupts, please */
|
||||
/* No interrupts, please. */
|
||||
cli
|
||||
|
||||
/* Get the current stack pointer */
|
||||
/* Get the current stack pointer. */
|
||||
movl %esp, %esi
|
||||
|
||||
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)
|
||||
|
||||
/* Exchange the current stack pointer for the one in
|
||||
the initial stack (which happens to be the new
|
||||
stack pointer) */
|
||||
|
||||
/*
|
||||
* Exchange the current stack pointer for the one in the initial
|
||||
* stack (which happens to be the new stack pointer).
|
||||
*/
|
||||
xchgl %esi, 16(%ebx)
|
||||
|
||||
/* Set the new stack pointer */
|
||||
/* Set the new stack pointer. */
|
||||
movl %esi, %esp
|
||||
|
||||
/* Return into the main entry function
|
||||
and go
|
||||
*/
|
||||
|
||||
/* Return into the main entry function and go. */
|
||||
lret
|
||||
|
||||
_leave:
|
||||
movl _istack, %ebx
|
||||
|
||||
/* Restore the stack pointer from the storage area */
|
||||
/* Restore the stack pointer from the storage area. */
|
||||
movl 16(%ebx), %esp
|
||||
|
||||
/* Return to the original context */
|
||||
/* Return to the original context. */
|
||||
lret
|
||||
|
||||
|
|
|
@ -29,13 +29,11 @@
|
|||
|
||||
#include <arch/types.h>
|
||||
|
||||
/* This structure seeds the stack. We provide
|
||||
the return address of our main function, and
|
||||
further down, the address of the function
|
||||
that we call when we leave and try to restore
|
||||
the original stack. At the very bottom of the
|
||||
stack we store the orignal stack pointer
|
||||
from the calling application
|
||||
/*
|
||||
* This structure seeds the stack. We provide the return address of our main
|
||||
* function, and further down, the address of the function that we call when
|
||||
* we leave and try to restore the original stack. At the very bottom of the
|
||||
* stack we store the orignal stack pointer from the calling application.
|
||||
*/
|
||||
|
||||
static void start_main(void);
|
||||
|
@ -53,27 +51,32 @@ static struct {
|
|||
|
||||
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)
|
||||
{
|
||||
extern int main(void);
|
||||
|
||||
/* Set up the consoles */
|
||||
/* Set up the consoles. */
|
||||
console_init();
|
||||
|
||||
/* Gather system information */
|
||||
/* Gather system information. */
|
||||
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();
|
||||
|
||||
/* 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,11 +30,10 @@
|
|||
#include <libpayload.h>
|
||||
#include <sysinfo.h>
|
||||
|
||||
/* This is a global structure that is used through the
|
||||
library - we set it up initially with some dummy
|
||||
values - hopefully they will be overridden
|
||||
/**
|
||||
* This is a global structure that is used through the library - we set it
|
||||
* up initially with some dummy values - hopefully they will be overridden.
|
||||
*/
|
||||
|
||||
struct sysinfo_t lib_sysinfo = {
|
||||
.cpu_khz = 200,
|
||||
.ser_ioport = CONFIG_SERIAL_IOBASE,
|
||||
|
@ -42,29 +41,18 @@ struct sysinfo_t lib_sysinfo = {
|
|||
|
||||
void lib_get_sysinfo(void)
|
||||
{
|
||||
/* Get the CPU speed (for delays) */
|
||||
/* Get the CPU speed (for delays). */
|
||||
lib_sysinfo.cpu_khz = get_cpu_speed();
|
||||
|
||||
/* Get the memory information */
|
||||
|
||||
/* Get the memory information. */
|
||||
get_coreboot_info(&lib_sysinfo);
|
||||
|
||||
if (!lib_sysinfo.n_memranges) {
|
||||
|
||||
/* If we couldn't get a good memory range,
|
||||
then use a hard coded default */
|
||||
|
||||
/* If we can't get a good memory range, use the default. */
|
||||
lib_sysinfo.n_memranges = 2;
|
||||
|
||||
lib_sysinfo.memrange[0].base = 0;
|
||||
lib_sysinfo.memrange[0].size = 640 * 1024;
|
||||
lib_sysinfo.memrange[1].base = 1024 * 1024;
|
||||
lib_sysinfo.memrange[1].size = 31 * 1024 * 1024;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -32,44 +32,38 @@
|
|||
|
||||
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 long long start, end;
|
||||
|
||||
/* Set up the PPC port - disable the speaker,
|
||||
* enable the T2 gate */
|
||||
|
||||
/* Set up the PPC port - disable the speaker, enable the T2 gate. */
|
||||
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);
|
||||
|
||||
/* Load the counter with 0xFFFF */
|
||||
|
||||
outb(0xFF, 0x42);
|
||||
outb(0xFF, 0x42);
|
||||
|
||||
/* Read the number of ticks during the period */
|
||||
/* Load the counter with 0xffff. */
|
||||
outb(0xff, 0x42);
|
||||
outb(0xff, 0x42);
|
||||
|
||||
/* Read the number of ticks during the period. */
|
||||
start = rdtsc();
|
||||
while (!(inb(0x61) & 0x20)) ;
|
||||
end = rdtsc();
|
||||
|
||||
/* The clock rate is 1193180 Hz
|
||||
* the number of miliseconds for a period
|
||||
* of 0xFFFF is 1193180 / (0xFFFF * 1000)
|
||||
* or .0182. Multiply that by the number of
|
||||
* measured clocks to get the khz value
|
||||
/*
|
||||
* The clock rate is 1193180 Hz, the number of miliseconds for a
|
||||
* period of 0xffff is 1193180 / (0xFFFF * 1000) or .0182.
|
||||
* Multiply that by the number of 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)
|
||||
{
|
||||
unsigned long long timeout = rdtsc() + delta;
|
||||
|
|
|
@ -26,12 +26,12 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
.global halt
|
||||
.text
|
||||
.align 4
|
||||
|
||||
/* This function puts the system into a halt. */
|
||||
|
||||
halt:
|
||||
cli
|
||||
hlt
|
||||
|
|
|
@ -128,7 +128,7 @@ struct cb_console {
|
|||
#define CB_TAG_CONSOLE_SROM 4
|
||||
#define CB_TAG_CONSOLE_EHCI 5
|
||||
|
||||
/* Still to come: CMOS information */
|
||||
/* Still to come: CMOS information. */
|
||||
|
||||
/* Helpful macros */
|
||||
|
||||
|
|
|
@ -27,11 +27,10 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _SYSINFO_H_
|
||||
#define _SYSINFO_H_
|
||||
|
||||
/* Allow a maximum of 16 memory range definitions */
|
||||
#ifndef SYSINFO_H
|
||||
#define SYSINFO_H
|
||||
|
||||
/* Allow a maximum of 16 memory range definitions. */
|
||||
#define SYSINFO_MAX_MEM_RANGES 16
|
||||
|
||||
struct sysinfo_t {
|
||||
|
|
|
@ -84,10 +84,10 @@ int havekey(void)
|
|||
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)
|
||||
{
|
||||
while (1) {
|
||||
|
@ -101,4 +101,3 @@ int getchar(void)
|
|||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,15 +27,17 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* Basic ctype functions */
|
||||
|
||||
#include <libpayload.h>
|
||||
|
||||
int isspace(int c)
|
||||
{
|
||||
switch (c) {
|
||||
case ' ': case '\f': case '\n':
|
||||
case '\r': case '\t': case '\v':
|
||||
case ' ':
|
||||
case '\f':
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\v':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
|
|
|
@ -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>
|
||||
* All rights reserved.
|
||||
|
|
|
@ -27,21 +27,20 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* This is a classically weak malloc() implmentation.
|
||||
We have a relatively small and static heap, so we take
|
||||
the easy route with an O(N) loop through the tree for
|
||||
every malloc() and free(). Obviously, this doesn't scale
|
||||
past a few hundred K (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!)
|
||||
/*
|
||||
* This is a classically weak malloc() implmentation. We have a relatively
|
||||
* small and static heap, so we take the easy route with an O(N) loop
|
||||
* through the tree for every malloc() and free(). Obviously, this doesn't
|
||||
* 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!).
|
||||
*/
|
||||
|
||||
#include <libpayload.h>
|
||||
|
||||
/* Defined in the ldscript */
|
||||
extern char _heap, _eheap;
|
||||
extern char _heap, _eheap; /* Defined in the ldscript. */
|
||||
|
||||
static void *hstart = (void *)&_heap;
|
||||
static void *hend = (void *)&_eheap;
|
||||
|
@ -77,34 +76,32 @@ static void *alloc(int len)
|
|||
hdrtype_t header;
|
||||
void *ptr = hstart;
|
||||
|
||||
/* align the size */
|
||||
/* Align the size. */
|
||||
len = (len + 3) & ~3;
|
||||
|
||||
if (!len || len > 0xFFFFFF)
|
||||
if (!len || len > 0xffffff)
|
||||
return (void *)NULL;
|
||||
|
||||
/* Make sure the region is setup correctly */
|
||||
/* Make sure the region is setup correctly. */
|
||||
if (!HAS_MAGIC(*((hdrtype_t *) ptr)))
|
||||
setup();
|
||||
|
||||
/* Find some free space */
|
||||
|
||||
/* Find some free space. */
|
||||
do {
|
||||
header = *((hdrtype_t *) ptr);
|
||||
int size = SIZE(header);
|
||||
|
||||
if (header & FLAG_FREE) {
|
||||
|
||||
if (len <= size) {
|
||||
void *nptr = ptr + HDRSIZE + len;
|
||||
int nsize = size - (len + 8);
|
||||
|
||||
/* Mark the block as used */
|
||||
/* Mark the block as used. */
|
||||
*((hdrtype_t *) ptr) = USED_BLOCK(len);
|
||||
|
||||
/* If there is still room in this block,
|
||||
* then mark it as such */
|
||||
|
||||
* then mark it as such.
|
||||
*/
|
||||
if (nsize > 0)
|
||||
*((hdrtype_t *) nptr) =
|
||||
FREE_BLOCK(nsize - 4);
|
||||
|
@ -117,7 +114,7 @@ static void *alloc(int len)
|
|||
|
||||
} while (ptr < hend);
|
||||
|
||||
/* Nothing available */
|
||||
/* Nothing available. */
|
||||
return (void *)NULL;
|
||||
}
|
||||
|
||||
|
@ -162,17 +159,17 @@ void free(void *ptr)
|
|||
|
||||
ptr -= HDRSIZE;
|
||||
|
||||
/* Sanity check */
|
||||
/* Sanity check. */
|
||||
if (ptr < hstart || ptr >= hend)
|
||||
return;
|
||||
|
||||
hdr = *((hdrtype_t *) ptr);
|
||||
|
||||
/* Not our header (we're probably poisoned) */
|
||||
/* Not our header (we're probably poisoned). */
|
||||
if (!HAS_MAGIC(hdr))
|
||||
return;
|
||||
|
||||
/* Double free */
|
||||
/* Double free. */
|
||||
if (hdr & FLAG_FREE)
|
||||
return;
|
||||
|
||||
|
@ -198,8 +195,7 @@ void *calloc(size_t nmemb, size_t size)
|
|||
|
||||
void *realloc(void *ptr, size_t size)
|
||||
{
|
||||
void *ret;
|
||||
void *pptr;
|
||||
void *ret, *pptr;
|
||||
unsigned int osize;
|
||||
|
||||
if (ptr == NULL)
|
||||
|
@ -210,32 +206,32 @@ void *realloc(void *ptr, size_t size)
|
|||
if (!HAS_MAGIC(*((hdrtype_t *) pptr)))
|
||||
return NULL;
|
||||
|
||||
/* Get the original size of the block */
|
||||
/* 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 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);
|
||||
|
||||
/* 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)
|
||||
return ret;
|
||||
|
||||
/* Copy the memory to the new location */
|
||||
/* Copy the memory to the new location. */
|
||||
memcpy(ret, ptr, osize > size ? size : osize);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* This is for debugging purposes */
|
||||
/* This is for debugging purposes. */
|
||||
#ifdef TEST
|
||||
|
||||
void print_malloc_map(void)
|
||||
{
|
||||
void *ptr = hstart;
|
||||
|
@ -248,15 +244,13 @@ void print_malloc_map(void)
|
|||
break;
|
||||
}
|
||||
|
||||
/* FIXME: Verify the size of the block */
|
||||
/* FIXME: Verify the size of the block. */
|
||||
|
||||
printf("%x: %s (%x bytes)\n",
|
||||
(unsigned int)(ptr - hstart),
|
||||
hdr & FLAG_FREE ? "FREE" : "USED",
|
||||
SIZE(hdr));
|
||||
hdr & FLAG_FREE ? "FREE" : "USED", SIZE(hdr));
|
||||
|
||||
ptr += HDRSIZE + SIZE(hdr);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -103,8 +103,7 @@ void *memmove(void *dst, const void *src, size_t n)
|
|||
*
|
||||
* @param s1 Pointer to the first 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
|
||||
* length.
|
||||
* @param len Size of the first area in bytes (both must have the same length).
|
||||
* @return If len is 0, return zero. If the areas match, return zero.
|
||||
* Otherwise return non-zero.
|
||||
*/
|
||||
|
|
|
@ -171,7 +171,6 @@ char * strchr(const char *s, int c)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
char *strdup(const char *s)
|
||||
{
|
||||
int n = strlen(s);
|
||||
|
@ -195,5 +194,3 @@ char *strstr(const char *h, const char *n)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ INCLUDES += -I$(shell $(CC) $(CROSS_CFLAGS) -print-search-dirs | head -n 1 | cut
|
|||
|
||||
LIBPAYLOAD = ../libpayload.a
|
||||
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
|
||||
|
||||
|
|
|
@ -31,7 +31,8 @@
|
|||
|
||||
#include <libpayload.h>
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
halt();
|
||||
|
||||
|
|
Loading…
Reference in New Issue