]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Support_Files/startup.S
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Support_Files / startup.S
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
15  *\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
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* Set to 1 to enable functionality */\r
30 #define __SHOW_KERNEL_PARAMS__ 0\r
31 \r
32 /* Local definitions boot loader */\r
33 #define MULTIBOOT_SIGNATURE             0x2BADB002\r
34 #define MULTIBOOT_BOOTINFO_MMAP 0x00000040\r
35 \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
40 \r
41         /* Globals and externs */\r
42         .global _mboot_hdr\r
43         .global _start\r
44         .global _restart\r
45 \r
46         .extern bootsign\r
47         .extern bootinfo\r
48 \r
49         .extern __text_start\r
50         .extern __text_end\r
51         .extern __data_vma\r
52         .extern __data_lma\r
53         .extern __data_start\r
54         .extern __data_end\r
55         .extern __bss_start\r
56         .extern __bss_end\r
57         .extern __stack_for_main\r
58 \r
59         .global __text_start\r
60         .global __text_end\r
61         .global __data_vma\r
62         .global __data_lma\r
63         .global __data_start\r
64         .global __data_end\r
65         .global __bss_start\r
66         .global __bss_end\r
67 \r
68         .extern setsegs\r
69         .extern CRT_Init\r
70         .extern kernel_load_check\r
71         .extern main\r
72 \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
79 \r
80         /* Set-up GDT */\r
81         .section .data\r
82 \r
83         .align  16\r
84         .globl  gdt\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
88 \r
89         /* Start of application text */\r
90         .section .text.entry\r
91 \r
92         /* Skip mb header */\r
93         jmp _start\r
94 \r
95         .align 4\r
96         /* Multiboot header */\r
97         _mboot_hdr:\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
106 \r
107         /* Start of executable code */\r
108         _start:\r
109 \r
110     /* Store boot arguments */\r
111         movl    %eax, bootsign\r
112         movl    %ebx, bootinfo\r
113 \r
114     /* Check to see if kernel is bootstrapped by grub */\r
115         cmpl $MULTIBOOT_SIGNATURE, %eax\r
116         jne _local_loop\r
117         testb   $MULTIBOOT_BOOTINFO_MMAP, (%ebx)\r
118         je      _local_loop\r
119 \r
120         _restart:\r
121 \r
122         /* Initialise the stack pointer */\r
123         movl $__stack_for_main, %esp\r
124 \r
125     /* Reset EFLAGS. */\r
126     pushl $0\r
127     popf\r
128 \r
129         /* Set up the global descriptor table */\r
130         call    setsegs\r
131         lgdt    gdtr\r
132         ljmp    $0x8, $gdt1                                     /* CS descriptor 1 */\r
133         gdt1:\r
134         movl    $0x10, %eax                                     /* DS descriptor 2 */\r
135         movw    %ax, %ds\r
136         movw    %ax, %es\r
137         movw    %ax, %fs\r
138         movw    %ax, %gs\r
139         movl    $0x18, %eax                                     /* SS descriptor 3 */\r
140         movw    %ax, %ss\r
141 \r
142     /* Clear interrupt flag */\r
143         cli\r
144 \r
145     /* Initialise platform */\r
146         call CRT_Init\r
147 \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
153 \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
162         #else\r
163             /*---------------------------------------------------------------------\r
164                 Call main() routine\r
165             ----------------------------------------------------------------------*/\r
166                 call main\r
167     #endif\r
168 \r
169         /* Should not get here, but just in case - loop forever */\r
170         cli\r
171         _local_loop:\r
172         hlt\r
173         jmp _local_loop\r
174 \r
175         /*-------------------------------------------------------------------------\r
176                           GLOBAL ASSEMBLY LANGUAGE ROUTINES\r
177         --------------------------------------------------------------------------*/\r
178 \r
179         /* halt */\r
180         .globl  halt\r
181         halt:\r
182         jmp halt\r
183         ret\r
184 \r
185         /* inb */\r
186         .globl  inb\r
187         inb:    movl    4(%esp), %edx\r
188         xorl    %eax, %eax      # clr eax\r
189         inb     %dx, %al\r
190         ret\r
191 \r
192         /* inw */\r
193         .globl  inw\r
194         inw:    movl    4(%esp), %edx\r
195         xorl    %eax, %eax      # clr eax\r
196         inw             %dx, %ax\r
197         ret\r
198 \r
199         /* inl */\r
200         .globl  inl\r
201         inl:    movl    4(%esp), %edx\r
202         xorl    %eax, %eax\r
203         inl             %dx, %eax\r
204         ret\r
205 \r
206         /* outb */\r
207         .globl  outb\r
208         outb:   movl    4(%esp), %edx\r
209         movl    8(%esp), %eax\r
210         outb    %al, %dx\r
211         ret\r
212 \r
213         /* outw */\r
214         .globl  outw\r
215         outw:   movl    4(%esp), %edx\r
216         movl    8(%esp), %eax\r
217         outw    %ax, %dx\r
218         ret\r
219 \r
220         /* outl */\r
221         .globl  outl\r
222         outl:   movl    4(%esp), %edx\r
223         movl    8(%esp), %eax\r
224         outl    %eax, %dx\r
225         ret\r
226 \r
227 .end\r