summaryrefslogtreecommitdiffstats
path: root/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
diff options
context:
space:
mode:
authorTill Straumann <strauman@slac.stanford.edu>2006-09-04 23:29:29 +0000
committerTill Straumann <strauman@slac.stanford.edu>2006-09-04 23:29:29 +0000
commit662c1577ac1eab66febb35a900e274c33676f834 (patch)
tree1e38693bb0ebcc1c59953752b83199fd879a8e6c /c/src/lib/libbsp/i386/pc386/startup/bspstart.c
parent * startup/linkcmds: added *(.text.*) *(.data.*) *(.bss.*) (diff)
downloadrtems-662c1577ac1eab66febb35a900e274c33676f834.tar.bz2
* startup/bspstart.c, start/start.S: Since the crude
memory autodetection code can easily fail (boards with 'reserved' regions - I experienced a hard lockup on a dell precision 490 when writing past the bios-reported memory size) I added code that a) tries to save and use multiboot info, if present b) allows applications to override/set memory size via a weak alias.
Diffstat (limited to '')
-rw-r--r--c/src/lib/libbsp/i386/pc386/startup/bspstart.c73
1 files changed, 53 insertions, 20 deletions
diff --git a/c/src/lib/libbsp/i386/pc386/startup/bspstart.c b/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
index d0fe5cd723..c3e2b35640 100644
--- a/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
+++ b/c/src/lib/libbsp/i386/pc386/startup/bspstart.c
@@ -40,12 +40,28 @@
| Global Variables
+--------------------------------------------------------------------------*/
extern uint32_t _end; /* End of BSS. Defined in 'linkcmds'. */
+
+/* rudimentary multiboot info */
+struct multiboot_info {
+ uint32_t flags; /* start.S only raises flags for items actually saved; this allows us to check for the size of the data structure */
+ uint32_t mem_lower; /* avail kB in lower memory */
+ uint32_t mem_upper; /* avail kB in lower memory */
+ /* ... (unimplemented) */
+};
+
+extern struct multiboot_info _boot_multiboot_info;
/*
* Size of heap if it is 0 it will be dynamically defined by memory size,
* otherwise the value should be changed by binary patch
*/
uint32_t _heap_size = 0;
+/* Alternative way to hardcode the board's memory size [rather than heap size].
+ * Can easily be overridden by application.
+ */
+extern uint32_t bsp_mem_size __attribute__ ((weak, alias("bsp_mem_size_default")));
+uint32_t bsp_mem_size_default = 0;
+
/* Size of stack used during initialization. Defined in 'start.s'. */
extern uint32_t _stack_size;
@@ -92,26 +108,43 @@ void bsp_pretasking_hook(void)
if ( lowest < 2 )
lowest = 2;
+ /* The memory detection algorithm is very crude; try
+ * to use multiboot info, if possible (set from start.S)
+ */
+ if ( bsp_mem_size == 0
+ && (_boot_multiboot_info.flags & 1)
+ && _boot_multiboot_info.mem_upper ) {
+ bsp_mem_size = _boot_multiboot_info.mem_upper * 1024;
+ }
+
if (_heap_size == 0) {
- /*
- * We have to dynamically size memory. Memory size can be anything
- * between no less than 2M and 2048M.
- * let us first write
- */
- for (i=2048; i>=lowest; i--) {
- topAddr = i*1024*1024 - 4;
- *(volatile uint32_t*)topAddr = topAddr;
- }
-
- for(i=lowest; i<=2048; i++) {
- topAddr = i*1024*1024 - 4;
- val = *(uint32_t*)topAddr;
- if (val != topAddr) {
- break;
- }
- }
-
- topAddr = (i-1)*1024*1024 - 4;
+
+ if ( bsp_mem_size == 0 ) {
+ /*
+ * We have to dynamically size memory. Memory size can be anything
+ * between no less than 2M and 2048M.
+ * let us first write
+ */
+ for (i=2048; i>=lowest; i--) {
+ topAddr = i*1024*1024 - 4;
+ *(volatile uint32_t*)topAddr = topAddr;
+ }
+
+ for(i=lowest; i<=2048; i++) {
+ topAddr = i*1024*1024 - 4;
+ val = *(uint32_t*)topAddr;
+ if (val != topAddr) {
+ break;
+ }
+ }
+
+ topAddr = (i-1)*1024*1024 - 4;
+
+ } else {
+
+ topAddr = bsp_mem_size;
+
+ }
_heap_size = topAddr - rtemsFreeMemStart;
}
@@ -143,8 +176,8 @@ void bsp_start_default( void )
*/
Calibrate_loop_1ms();
+ /* set the value of start of free memory. */
rtemsFreeMemStart = (uint32_t)&_end + _stack_size;
- /* set the value of start of free memory. */
/* If we don't have command line arguments set default program name. */