2 * FreeRTOS Kernel V10.0.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* Set to 1 to enable functionality */
\r
29 #define __SHOW_KERNEL_PARAMS__ 0
\r
31 /* Local definitions boot loader */
\r
32 #define MULTIBOOT_SIGNATURE 0x2BADB002
\r
33 #define MULTIBOOT_BOOTINFO_MMAP 0x00000040
\r
35 /* Local definitions for GD table */
\r
36 #define GDT_ENTRIES 8
\r
37 #define GDT_ENTRY_SIZE 8
\r
38 #define GDT_BYTES (GDT_ENTRIES * GDT_ENTRY_SIZE)
\r
40 /* Globals and externs */
\r
48 .extern __text_start
\r
52 .extern __data_start
\r
56 .extern __stack_for_main
\r
58 .global __text_start
\r
62 .global __data_start
\r
69 .extern kernel_load_check
\r
72 /* Local constants for multiboot section */
\r
73 .set ALIGN, 1<<0 /* align loaded modules on page boundaries */
\r
74 .set MEMINFO, 1<<1 /* provide memory map */
\r
75 .set MAGIC, 0x1BADB002 /* 'magic number' lets bootloader find the header */
\r
76 .set FLAGS, ALIGN|MEMINFO /* this is the multiboot 'flag' field */
\r
77 .set CHECKSUM, -(MAGIC + FLAGS) /* checksum of above */
\r
84 gdt: .space GDT_BYTES
\r
85 gdtr: .word (GDT_BYTES-1) /* sizeof _gdt -1 (in bytes) */
\r
86 .long gdt /* global pointer to the gdt */
\r
88 /* Start of application text */
\r
89 .section .text.entry
\r
91 /* Skip mb header */
\r
95 /* Multiboot header */
\r
97 .long MAGIC /* offset = 0 */
\r
98 .long FLAGS /* offset = 4 */
\r
99 .long CHECKSUM /* offset = 8 */
\r
100 .long _mboot_hdr /* should be header address - offset = 12 */
\r
101 .long __text_start /* load address (start of text) - offset = 16 */
\r
102 .long __bss_start /* load end address (end of data) - offset = 20*/
\r
103 .long __bss_end /* bss end address - offset = 24*/
\r
104 .long _start /* entry_addr - offset = 28*/
\r
106 /* Start of executable code */
\r
109 /* Store boot arguments */
\r
110 movl %eax, bootsign
\r
111 movl %ebx, bootinfo
\r
113 /* Check to see if kernel is bootstrapped by grub */
\r
114 cmpl $MULTIBOOT_SIGNATURE, %eax
\r
116 testb $MULTIBOOT_BOOTINFO_MMAP, (%ebx)
\r
121 /* Initialise the stack pointer */
\r
122 movl $__stack_for_main, %esp
\r
124 /* Reset EFLAGS. */
\r
128 /* Set up the global descriptor table */
\r
131 ljmp $0x8, $gdt1 /* CS descriptor 1 */
\r
133 movl $0x10, %eax /* DS descriptor 2 */
\r
138 movl $0x18, %eax /* SS descriptor 3 */
\r
141 /* Clear interrupt flag */
\r
144 /* Initialise platform */
\r
147 /* Show kernel parameters and call main, or just call main */
\r
148 #if (__SHOW_KERNEL_PARAMS__ == 1)
\r
149 /*---------------------------------------------------------------------
\r
150 On successful OS load EAX should contain 0x2BADB002
\r
151 EBX should contain the physical address of multiboot info structure
\r
153 Push the pointers to the multiboot information structure
\r
154 and the magic number on the stack and check values returned
\r
155 ----------------------------------------------------------------------*/
\r
156 movl bootsign, %eax
\r
157 movl bootinfo, %ebx
\r
158 pushl %ebx /* Multiboot information */
\r
159 pushl %eax /* Magic number */
\r
160 call show_kernel_parameters
\r
162 /*---------------------------------------------------------------------
\r
163 Call main() routine
\r
164 ----------------------------------------------------------------------*/
\r
168 /* Should not get here, but just in case - loop forever */
\r
174 /*-------------------------------------------------------------------------
\r
175 GLOBAL ASSEMBLY LANGUAGE ROUTINES
\r
176 --------------------------------------------------------------------------*/
\r
186 inb: movl 4(%esp), %edx
\r
187 xorl %eax, %eax # clr eax
\r
193 inw: movl 4(%esp), %edx
\r
194 xorl %eax, %eax # clr eax
\r
200 inl: movl 4(%esp), %edx
\r
207 outb: movl 4(%esp), %edx
\r
214 outw: movl 4(%esp), %edx
\r
221 outl: movl 4(%esp), %edx
\r