From 595088be0928a7b4b9e3603497c1b5fdc8ca52af Mon Sep 17 00:00:00 2001 From: Jesus Sanchez-Palencia Date: Mon, 16 Mar 2015 10:39:13 -0300 Subject: [PATCH] galileo: Add a bootstrap stack for C runtime All we need to provide to C at this point is a region in memory dedicated to its stack. This is done by allocating a region in .bss and pushing its start address to esp. Since the multiboot spec says it is not safe to rely on the initial stack provided by the bootloader, this patch provides our own stack. Galileo boards have 512Kb of SRAM and 256Mb of DDR3 RAM, so providing 8kb as a start seems safe. Moreover, stack sizes are very application-oriented so it may be too early to provide a bigger (or smaller) stack. --- platform/galileo/loader.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/platform/galileo/loader.S b/platform/galileo/loader.S index 9e0458dda..146665d4a 100644 --- a/platform/galileo/loader.S +++ b/platform/galileo/loader.S @@ -28,6 +28,10 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ +# Kernel +.set STACK_SIZE, 8192 + +# Multiboot .set MAGIC_NUMBER, 0x1BADB002 .set FLAGS, 0x0 .set CHECKSUM, -MAGIC_NUMBER @@ -38,10 +42,14 @@ .long FLAGS .long CHECKSUM +# Reserve space for the C stack. +.lcomm c_stack, STACK_SIZE + .section .text .global start start: cli + movl $(c_stack + STACK_SIZE), %esp call main /* We're not expected to return from main(). But if we do we halt */