summaryrefslogtreecommitdiff
path: root/nuttx/arch/x86/src/qemu/qemu_head.S
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/arch/x86/src/qemu/qemu_head.S')
-rwxr-xr-xnuttx/arch/x86/src/qemu/qemu_head.S125
1 files changed, 104 insertions, 21 deletions
diff --git a/nuttx/arch/x86/src/qemu/qemu_head.S b/nuttx/arch/x86/src/qemu/qemu_head.S
index 9d436b4fd..cf754408f 100755
--- a/nuttx/arch/x86/src/qemu/qemu_head.S
+++ b/nuttx/arch/x86/src/qemu/qemu_head.S
@@ -40,20 +40,37 @@
#include <nuttx/config.h>
/****************************************************************************
- * .text
+ * Pre-processor definitions
+ ****************************************************************************/
+
+/* Memory Map: _sbss is the start of the BSS region (see ld.script) _ebss is
+ * the end of the BSS regsion (see ld.script). The idle task stack starts at
+ * the end of BSS and is of size CONFIG_IDLETHREAD_STACKSIZE. The IDLE thread
+ * is the thread that the system boots on and, eventually, becomes the idle,
+ * do nothing task that runs only when there is nothing else to run. The
+ * heap continues from there until the end of memory. See g_heapbase below.
+ */
+
+#define STACKBASE ((_ebss + 0x1f) & 0xffffffe0)
+#define IDLE_STACK (STACKBASE+CONFIG_IDLETHREAD_STACKSIZE)
+#define HEAP_BASE (STACKBASE+CONFIG_IDLETHREAD_STACKSIZE)
+
+/****************************************************************************
+ * Nasm .text
****************************************************************************/
#ifdef CONFIG_X86_NASM
global __start /* Making entry point visible to linker */
-extern os_start /* os_start is defined elsewhere */
-extern up_lowsetup /* up_lowsetup is defined elsewhere */
+global _g_heapbase /* The start of the heap */
+extern _os_start /* os_start is defined elsewhere */
+extern _up_lowsetup /* up_lowsetup is defined elsewhere */
/* Setting up the Multiboot header - see GRUB docs for details */
MODULEALIGN equ 1<<0 /* Align loaded modules on page boundaries */
MEMINFO equ 1<<1 /* Provide memory map */
FLAGS equ MODULEALIGN | MEMINFO /* This is the Multiboot 'flag' field */
-MAGIC equ 0x1BADB002 /* 'magic number' lets bootloader find the header */
+MAGIC equ 0x1badb002 /* 'magic number' lets bootloader find the header */
CHECKSUM equ -(MAGIC + FLAGS) /* Checksum required */
section .text
@@ -63,63 +80,129 @@ MultiBootHeader:
dd FLAGS
dd CHECKSUM
-/* Reserve initial kernel stack space */
-
-STACKSIZE equ 0x4000 /* That's 16k */
-
__start:
- mov esp, stack+STACKSIZE /* Set up the stack */
+ /* Set up the stack */
+
+ mov esp, idle_stack + CONFIG_IDLETHREAD_STACKSIZE
+
+ /* Multiboot setup */
+
push eax /* Pass Multiboot magic number */
push ebx /* Pass Multiboot info structure */
+
+ /* Initialize and start NuttX */
+
+ call _up_lowsetup /* Low-level, pre-OS initialization */
+ call _os_start /* Start NuttX */
- call up_lowsetup /* Low-level, pre-OS initialization */
- call os_start /* Start NuttX */
-
+ /* NuttX will not return */
+
cli
hang:
hlt /* Halt machine should NuttX return */
jmp hang
+/****************************************************************************
+ * .bss
+ ****************************************************************************/
+
+/* The stack for the IDLE task thread is declared in .bss. NuttX boots and
+ * initializes on the IDLE thread, then at the completion of OS startup, this
+ * thread becomes the thread that executes when there is nothing else to
+ * do in the system (see up_idle()).
+ */
+
section .bss
align 4
-stack:
- resb STACKSIZE /* Reserve 16k stack on a doubleword boundary */
+idle_stack:
+ resb CONFIG_IDLETHREAD_STACKSIZE
+
+/****************************************************************************
+ * .rodata
+ ****************************************************************************/
+
+section .rodata
+
+/* HEAP BASE: _sbss is the start of the BSS region (see ld.script) _ebss is
+ * the end of the BSS region (see ld.script). The heap continues from there
+ * until the end of memory.
+ */
+
+align 4
+g_heapbase:
+ dd _ebss
#else /* !CONFIG_X86_NASM (GAS) */
+/****************************************************************************
+ * GAS .text
+ ****************************************************************************/
+
.global __start /* Making entry point visible to linker */
.global _os_start /* os_start is defined elsewhere */
.global _up_lowsetup /* up_lowsetup is defined elsewhere */
+ .global _g_heapbase /* The start of the heap */
-/* Setting up the Multiboot header - see GRUB docs for details */
+ /* Setting up the Multiboot header - see GRUB docs for details */
.set ALIGN, 1<<0 /* Align loaded modules on page boundaries */
.set MEMINFO, 1<<1 /* Provide memory map */
.set FLAGS, ALIGN | MEMINFO /* This is the Multiboot 'flag' field */
- .set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
+ .set MAGIC, 0x1badb002 /* 'magic number' lets bootloader find the header */
.set CHECKSUM, -(MAGIC + FLAGS) /* Checksum required */
+ .text
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
-/* Reserve initial kernel stack space */
+__start:
+ /* Set up the stack */
- .set STACKSIZE, 0x4000 /* That is, 16k */
- .comm stack, STACKSIZE, 32 /* Reserve 16k stack on a quadword boundary */
+ mov $(idle_stack + CONFIG_IDLETHREAD_STACKSIZE), %esp
+
+ /* Multiboot setup */
-__start:
- mov $(stack + STACKSIZE), %esp /* Set up the stack */
push %eax /* Multiboot magic number */
push %ebx /* Multiboot data structure */
+ /* Initialize and start NuttX */
+
call _up_lowsetup /* Low-level, pre-OS initialization */
call _os_start /* Start NuttX */
+ /* NuttX will not return */
+
cli
hang:
hlt /* Halt machine should NuttX return */
jmp hang
+
+/****************************************************************************
+ * .bss
+ ****************************************************************************/
+
+/* The stack for the IDLE task thread is declared in .bss. NuttX boots and
+ * initializes on the IDLE thread, then at the completion of OS startup, this
+ * thread becomes the thread that executes when there is nothing else to
+ * do in the system (see up_idle()).
+ */
+
+ .comm idle_stack, CONFIG_IDLETHREAD_STACKSIZE, 32
+
+/****************************************************************************
+ * .rodata
+ ****************************************************************************/
+
+ .section .rodata, "a"
+
+/* HEAP BASE: _sbss is the start of the BSS region (see ld.script) _ebss is
+ * the end of the BSS region (see ld.script). The heap continues from there
+ * until the end of memory.
+ */
+
+_g_heapbase:
+ .word _ebss
.end
#endif /* CONFIG_X86_NASM */ \ No newline at end of file