summaryrefslogtreecommitdiff
path: root/payloads/libpayload/i386
diff options
context:
space:
mode:
Diffstat (limited to 'payloads/libpayload/i386')
-rw-r--r--payloads/libpayload/i386/coreboot.c68
-rw-r--r--payloads/libpayload/i386/head.S47
-rw-r--r--payloads/libpayload/i386/main.c47
-rw-r--r--payloads/libpayload/i386/sysinfo.c32
-rw-r--r--payloads/libpayload/i386/timer.c46
-rw-r--r--payloads/libpayload/i386/util.S6
6 files changed, 109 insertions, 137 deletions
diff --git a/payloads/libpayload/i386/coreboot.c b/payloads/libpayload/i386/coreboot.c
index e5d02319a7..0eb76dcf4b 100644
--- a/payloads/libpayload/i386/coreboot.c
+++ b/payloads/libpayload/i386/coreboot.c
@@ -31,20 +31,19 @@
#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)
{
- struct cb_memory *mem = (struct cb_memory *) ptr;
+ struct cb_memory *mem = (struct cb_memory *)ptr;
int count = MEM_RANGE_COUNT(mem);
int i;
@@ -53,18 +52,18 @@ static void cb_parse_memory(unsigned char *ptr, struct sysinfo_t *info)
info->n_memranges = 0;
- for(i = 0; i < count; i++) {
- struct cb_memory_range *range =
- (struct cb_memory_range *) MEM_RANGE_PTR(mem, i);
-
+ for (i = 0; i < count; i++) {
+ struct cb_memory_range *range =
+ (struct cb_memory_range *)MEM_RANGE_PTR(mem, i);
+
if (range->type != CB_MEM_RAM)
continue;
info->memrange[info->n_memranges].base =
- UNPACK_CB64(range->start);
+ UNPACK_CB64(range->start);
info->memrange[info->n_memranges].size =
- UNPACK_CB64(range->size);
+ UNPACK_CB64(range->size);
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)
{
- struct cb_serial *ser = (struct cb_serial *) ptr;
+ struct cb_serial *ser = (struct cb_serial *)ptr;
info->ser_ioport = ser->ioport;
}
static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
{
struct cb_header *header;
- unsigned char *ptr = (unsigned char *) addr;
+ unsigned char *ptr = (unsigned char *)addr;
int i;
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))
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;
if (ipchksum((uint16_t *) (ptr + sizeof(*header)),
- header->table_bytes) != header->table_checksum)
+ 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
- */
+ for (i = 0; i < header->table_entries; i++) {
+ 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:
cb_parse_memory(ptr, info);
break;
-
case CB_TAG_SERIAL:
cb_parse_serial(ptr, info);
break;
@@ -128,19 +120,19 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
ptr += rec->size;
}
-
+
return 1;
}
-/* == Architecture specific ==*/
-/* This is the x86 specific stuff */
+/* == Architecture specific == */
+/* This is the x86 specific stuff. */
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)
- ret = cb_parse_header((void *) 0xf0000, 0x1000, info);
+ ret = cb_parse_header((void *)0xf0000, 0x1000, info);
return (ret == 1) ? 0 : -1;
}
diff --git a/payloads/libpayload/i386/head.S b/payloads/libpayload/i386/head.S
index 1278bdf4ed..e05cb3ed30 100644
--- a/payloads/libpayload/i386/head.S
+++ b/payloads/libpayload/i386/head.S
@@ -26,60 +26,55 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-
+
.global _entry, _leave
.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
-
diff --git a/payloads/libpayload/i386/main.c b/payloads/libpayload/i386/main.c
index 846d46a426..ed5c1b9e9c 100644
--- a/payloads/libpayload/i386/main.c
+++ b/payloads/libpayload/i386/main.c
@@ -29,14 +29,12 @@
#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);
extern void _leave(void);
@@ -45,35 +43,40 @@ static struct {
uint32_t eip[2];
uint32_t raddr[2];
uint32_t esp;
-} initial_stack __attribute__((section (".istack"))) = {
+} initial_stack __attribute__ ((section(".istack"))) = {
{ (uint32_t) start_main, 0 },
{ (uint32_t) _leave, 0 },
- (uint32_t) &initial_stack,
+ (uint32_t) & initial_stack,
};
-void * _istack = &initial_stack;
-
-/* This is our C entry function - set up the system
- and jump into the payload entry point */
+void *_istack = &initial_stack;
+/**
+ * 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.
+ */
}
diff --git a/payloads/libpayload/i386/sysinfo.c b/payloads/libpayload/i386/sysinfo.c
index 1fdf3fc419..cb149ead3a 100644
--- a/payloads/libpayload/i386/sysinfo.c
+++ b/payloads/libpayload/i386/sysinfo.c
@@ -30,41 +30,29 @@
#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,
+ .cpu_khz = 200,
+ .ser_ioport = CONFIG_SERIAL_IOBASE,
};
-
+
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;
}
}
-
-
-
-
-
-
diff --git a/payloads/libpayload/i386/timer.c b/payloads/libpayload/i386/timer.c
index 852cbe6c03..a787646073 100644
--- a/payloads/libpayload/i386/timer.c
+++ b/payloads/libpayload/i386/timer.c
@@ -32,53 +32,47 @@
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));
+ 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
- */
-
- cpu_khz =
- (unsigned int ) ((end - start) * 1193180U / (1000 * 0xFFFF));
+ /*
+ * 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));
}
-/* Global delay functions */
-
static inline void _delay(unsigned int delta)
{
unsigned long long timeout = rdtsc() + delta;
- while (rdtsc() < timeout);
+ while (rdtsc() < timeout) ;
}
void ndelay(unsigned int n)
{
- _delay(n * cpu_khz / 1000000);
+ _delay(n * cpu_khz / 1000000);
}
void mdelay(unsigned int m)
diff --git a/payloads/libpayload/i386/util.S b/payloads/libpayload/i386/util.S
index a0b1b0980d..9858d29b05 100644
--- a/payloads/libpayload/i386/util.S
+++ b/payloads/libpayload/i386/util.S
@@ -26,12 +26,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
- .global halt
+
+ .global halt
.text
.align 4
-
-/* This function puts the system into a halt. */
+/* This function puts the system into a halt. */
halt:
cli
hlt