2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Set to 1 to enable functionality */
\r
30 #define __SHOW_KERNEL_PARAMS__ 0
\r
32 /* Local definitions boot loader */
\r
33 #define MULTIBOOT_SIGNATURE 0x2BADB002
\r
34 #define MULTIBOOT_BOOTINFO_MMAP 0x00000040
\r
36 /* Local definitions for GD table */
\r
37 #define GDT_ENTRIES 8
\r
38 #define GDT_ENTRY_SIZE 8
\r
39 #define GDT_BYTES (GDT_ENTRIES * GDT_ENTRY_SIZE)
\r
41 /* Globals and externs */
\r
49 .extern __text_start
\r
53 .extern __data_start
\r
57 .extern __stack_for_main
\r
59 .global __text_start
\r
63 .global __data_start
\r
70 .extern kernel_load_check
\r
73 /* Local constants for multiboot section */
\r
74 .set ALIGN, 1<<0 /* align loaded modules on page boundaries */
\r
75 .set MEMINFO, 1<<1 /* provide memory map */
\r
76 .set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
\r
77 .set FLAGS, ALIGN|MEMINFO /* this is the multiboot 'flag' field */
\r
78 .set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above */
\r
85 gdt: .space GDT_BYTES
\r
86 gdtr: .word (GDT_BYTES-1) /* sizeof _gdt -1 (in bytes) */
\r
87 .long gdt /* global pointer to the gdt */
\r
89 /* Start of application text */
\r
90 .section .text.entry
\r
92 /* Skip mb header */
\r
96 /* Multiboot header */
\r
98 .long MAGIC /* offset = 0 */
\r
99 .long FLAGS /* offset = 4 */
\r
100 .long CHECKSUM /* offset = 8 */
\r
101 .long _mboot_hdr /* should be header address - offset = 12 */
\r
102 .long __text_start /* load address (start of text) - offset = 16 */
\r
103 .long __bss_start /* load end address (end of data) - offset = 20*/
\r
104 .long __bss_end /* bss end address - offset = 24*/
\r
105 .long _start /* entry_addr - offset = 28*/
\r
107 /* Start of executable code */
\r
110 /* Store boot arguments */
\r
111 movl %eax, bootsign
\r
112 movl %ebx, bootinfo
\r
114 /* Check to see if kernel is bootstrapped by grub */
\r
115 cmpl $MULTIBOOT_SIGNATURE, %eax
\r
117 testb $MULTIBOOT_BOOTINFO_MMAP, (%ebx)
\r
122 /* Initialise the stack pointer */
\r
123 movl $__stack_for_main, %esp
\r
125 /* Reset EFLAGS. */
\r
129 /* Set up the global descriptor table */
\r
132 ljmp $0x8, $gdt1 /* CS descriptor 1 */
\r
134 movl $0x10, %eax /* DS descriptor 2 */
\r
139 movl $0x18, %eax /* SS descriptor 3 */
\r
142 /* Clear interrupt flag */
\r
145 /* Initialise platform */
\r
148 /* Show kernel parameters and call main, or just call main */
\r
149 #if (__SHOW_KERNEL_PARAMS__ == 1)
\r
150 /*---------------------------------------------------------------------
\r
151 On successful OS load EAX should contain 0x2BADB002
\r
152 EBX should contain the physical address of multiboot info structure
\r
154 Push the pointers to the multiboot information structure
\r
155 and the magic number on the stack and check values returned
\r
156 ----------------------------------------------------------------------*/
\r
157 movl bootsign, %eax
\r
158 movl bootinfo, %ebx
\r
159 pushl %ebx /* Multiboot information */
\r
160 pushl %eax /* Magic number */
\r
161 call show_kernel_parameters
\r
163 /*---------------------------------------------------------------------
\r
164 Call main() routine
\r
165 ----------------------------------------------------------------------*/
\r
169 /* Should not get here, but just in case - loop forever */
\r
175 /*-------------------------------------------------------------------------
\r
176 GLOBAL ASSEMBLY LANGUAGE ROUTINES
\r
177 --------------------------------------------------------------------------*/
\r
187 inb: movl 4(%esp), %edx
\r
188 xorl %eax, %eax # clr eax
\r
194 inw: movl 4(%esp), %edx
\r
195 xorl %eax, %eax # clr eax
\r
201 inl: movl 4(%esp), %edx
\r
208 outb: movl 4(%esp), %edx
\r
215 outw: movl 4(%esp), %edx
\r
222 outl: movl 4(%esp), %edx
\r