- Initial checkin of the freebios2 tree

git-svn-id: svn://svn.coreboot.org/coreboot/trunk@784 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
Eric Biederman
2003-04-22 19:02:15 +00:00
parent b138ac83b5
commit 8ca8d7665d
109 changed files with 13965 additions and 0 deletions

18
src/lib/clog2.c Normal file
View File

@@ -0,0 +1,18 @@
#include <console/console.h>
unsigned long log2(unsigned long x)
{
// assume 8 bits per byte.
unsigned long i = 1 << (sizeof(x)*8 - 1);
unsigned long pow = sizeof(x) * 8 - 1;
if (! x) {
printk_warning("%s called with invalid parameter of 0\n",
__FUNCTION__);
return -1;
}
for(; i > x; i >>= 1, pow--)
;
return pow;
}

View File

@@ -0,0 +1,53 @@
#include <stdint.h>
#include <ip_checksum.h>
unsigned long compute_ip_checksum(void *addr, unsigned long length)
{
uint8_t *ptr;
volatile union {
uint8_t byte[2];
uint16_t word;
} value;
unsigned long sum;
unsigned long i;
/* In the most straight forward way possible,
* compute an ip style checksum.
*/
sum = 0;
ptr = addr;
for(i = 0; i < length; i++) {
unsigned long value;
value = ptr[i];
if (i & 1) {
value <<= 8;
}
/* Add the new value */
sum += value;
/* Wrap around the carry */
if (sum > 0xFFFF) {
sum = (sum + (sum >> 16)) & 0xFFFF;
}
}
value.byte[0] = sum & 0xff;
value.byte[1] = (sum >> 8) & 0xff;
return (~value.word) & 0xFFFF;
}
unsigned long add_ip_checksums(unsigned long offset, unsigned long sum, unsigned long new)
{
unsigned long checksum;
sum = ~sum & 0xFFFF;
new = ~new & 0xFFFF;
if (offset & 1) {
/* byte swap the sum if it came from an odd offset
* since the computation is endian independant this
* works.
*/
new = ((new >> 8) & 0xff) | ((new << 8) & 0xff00);
}
checksum = sum + new;
if (checksum > 0xFFFF) {
checksum -= 0xFFFF;
}
return (~checksum) & 0xFFFF;
}

15
src/lib/delay.c Normal file
View File

@@ -0,0 +1,15 @@
#include <delay.h>
void mdelay(int msecs)
{
int i;
for(i = 0; i < msecs; i++) {
udelay(1000);
}
}
void delay(int secs)
{
int i;
for(i = 0; i < secs; i++) {
mdelay(1000);
}
}

25
src/lib/fallback_boot.c Normal file
View File

@@ -0,0 +1,25 @@
#include <console/console.h>
#include <part/fallback_boot.h>
#include <pc80/mc146818rtc.h>
#include <arch/io.h>
void boot_successful(void)
{
/* Remember I succesfully booted by setting
* the initial boot direction
* to the direction that I booted.
*/
unsigned char index, byte;
index = inb(RTC_PORT(0)) & 0x80;
index |= RTC_BOOT_BYTE;
outb(index, RTC_PORT(0));
byte = inb(RTC_PORT(1));
byte &= 0xfe;
byte |= (byte & 2) >> 1;
/* If we are in normal mode set the boot count to 0 */
if(byte & 1)
byte &= 0x0f;
outb(byte, RTC_PORT(1));
}

52
src/lib/malloc.c Normal file
View File

@@ -0,0 +1,52 @@
#include <stdlib.h>
#include <console/console.h>
#if 0
#define MALLOCDBG(x)
#else
#define MALLOCDBG(x) printk_spew x
#endif
extern unsigned char _heap, _eheap;
static size_t free_mem_ptr = (size_t)&_heap; /* Start of heap */
static size_t free_mem_end_ptr = (size_t)&_eheap; /* End of heap */
void malloc_mark(malloc_mark_t *place)
{
*place = free_mem_ptr;
printk_spew("malloc_mark 0x%08lx\n", (unsigned long)free_mem_ptr);
}
void malloc_release(malloc_mark_t *ptr)
{
free_mem_ptr = *ptr;
printk_spew("malloc_release 0x%08lx\n", (unsigned long)free_mem_ptr);
}
void *malloc(size_t size)
{
void *p;
MALLOCDBG(("%s Enter, size %d, free_mem_ptr %p\n", __FUNCTION__, size, free_mem_ptr));
if (size < 0)
die("Error! malloc: Size < 0");
if (free_mem_ptr <= 0)
die("Error! malloc: Free_mem_ptr <= 0");
free_mem_ptr = (free_mem_ptr + 3) & ~3; /* Align */
p = (void *) free_mem_ptr;
free_mem_ptr += size;
if (free_mem_ptr >= free_mem_end_ptr)
die("Error! malloc: Free_mem_ptr >= free_mem_end_ptr");
MALLOCDBG(("malloc 0x%08lx\n", (unsigned long)p));
return p;
}
void free(void *where)
{
/* Don't care */
}

17
src/lib/memcmp.c Normal file
View File

@@ -0,0 +1,17 @@
#include <string.h>
int memcmp(const void *src1, const void *src2, size_t bytes)
{
const unsigned char *s1, *s2;
int result;
s1 = src1;
s2 = src2;
result = 0;
while((bytes > 0) && (result == 0)) {
result = *s1 - *s2;
bytes--;
s1++;
s2++;
}
return result;
}

11
src/lib/memcpy.c Normal file
View File

@@ -0,0 +1,11 @@
#include <string.h>
void *memcpy(void *__dest, __const void *__src, size_t __n)
{
int i;
char *d = (char *) __dest, *s = (char *) __src;
for (i = 0; i < __n; i++)
d[i] = s[i];
return __dest;
}

12
src/lib/memset.c Normal file
View File

@@ -0,0 +1,12 @@
#include <string.h>
void *memset(void *s, int c, size_t n)
{
int i;
char *ss = (char *) s;
for (i = 0; i < n; i++)
ss[i] = c;
return s;
}

64
src/lib/uart8250.c Normal file
View File

@@ -0,0 +1,64 @@
#ifndef lint
static char rcsid[] = "$Id$";
#endif
/* Should support 8250, 16450, 16550, 16550A type uarts */
#include <arch/io.h>
#include <uart8250.h>
/* Data */
#define UART_RBR 0x00
#define UART_TBR 0x00
/* Control */
#define UART_IER 0x01
#define UART_IIR 0x02
#define UART_FCR 0x02
#define UART_LCR 0x03
#define UART_MCR 0x04
#define UART_DLL 0x00
#define UART_DLM 0x01
/* Status */
#define UART_LSR 0x05
#define UART_MSR 0x06
#define UART_SCR 0x07
static inline int uart8250_can_tx_byte(unsigned base_port)
{
return inb(base_port + UART_LSR) & 0x20;
}
static inline void uart8250_wait_to_tx_byte(unsigned base_port)
{
while(!uart8250_can_tx_byte(base_port))
;
}
static inline void uart8250_wait_until_sent(unsigned base_port)
{
while(!(inb(base_port + UART_LSR) & 0x40))
;
}
void uart8250_tx_byte(unsigned base_port, unsigned char data)
{
uart8250_wait_to_tx_byte(base_port);
outb(data, base_port + UART_TBR);
/* Make certain the data clears the fifos */
uart8250_wait_until_sent(base_port);
}
void uart8250_init(unsigned base_port, unsigned divisor, unsigned lcs)
{
lcs &= 0x7f;
/* disable interrupts */
outb(0x0, base_port + UART_IER);
/* enable fifo's */
outb(0x01, base_port + UART_FCR);
/* Set Baud Rate Divisor to 12 ==> 115200 Baud */
outb(0x80 | lcs, base_port + UART_LCR);
outb(divisor & 0xFF, base_port + UART_DLL);
outb((divisor >> 8) & 0xFF, base_port + UART_DLM);
outb(lcs, base_port + UART_LCR);
}

62
src/lib/version.c Normal file
View File

@@ -0,0 +1,62 @@
#include <version.h>
#define __STR(X) #X
#define STR(X) __STR(X)
#ifndef MAINBOARD_VENDOR
#error MAINBOARD_VENDOR not defined
#endif
#ifndef MAINBOARD_PART_NUMBER
#error MAINBOARD_PART_NUMBER not defined
#endif
#ifndef LINUXBIOS_VERSION
#error LINUXBIOS_VERSION not defined
#endif
#ifndef LINUXBIOS_BUILD
#error LINUXBIOS_BUILD not defined
#endif
#ifndef LINUXBIOS_COMPILE_TIME
#error LINUXBIOS_COMPILE_TIME not defined
#endif
#ifndef LINUXBIOS_COMPILE_BY
#error LINUXBIOS_COMPILE_BY not defined
#endif
#ifndef LINUXBIOS_COMPILE_HOST
#error LINUXBIOS_COMPILE_HOST not defined
#endif
#ifndef LINUXBIOS_COMPILER
#error LINUXBIOS_COMPILER not defined
#endif
#ifndef LINUXBIOS_LINKER
#error LINUXBIOS_LINKER not defined
#endif
#ifndef LINUXBIOS_ASSEMBLER
#error LINUXBIOS_ASSEMBLER not defined
#endif
#ifndef LINUXBIOS_EXTRA_VERSION
#define LINUXBIOS_EXTRA_VERSION
#endif
const char mainboard_vendor[] = STR(MAINBOARD_VENDOR);
const char mainboard_part_number[] = STR(MAINBOARD_PART_NUMBER);
const char linuxbios_version[] = STR(LINUXBIOS_VERSION);
const char linuxbios_extra_version[] = STR(LINUXBIOS_EXTRA_VERSION);
const char linuxbios_build[] = STR(LINUXBIOS_BUILD);
const char linuxbios_compile_time[] = STR(LINUXBIOS_COMPILE_TIME);
const char linuxbios_compile_by[] = STR(LINUXBIOS_COMPILE_BY);
const char linuxbios_compile_host[] = STR(LINUXBIOS_COMPILE_HOST);
const char linuxbios_compile_domain[] = STR(LINUXBIOS_COMPILE_DOMAIN);
const char linuxbios_compiler[] = STR(LINUXBIOS_COMPILER);
const char linuxbios_linker[] = STR(LINUXBIOS_LINKER);
const char linuxbios_assembler[] = STR(LINUXBIOS_ASSEMBLER);