]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/IA32_flat_GCC_Galileo_Gen_2/Support_Files/startup.S
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / IA32_flat_GCC_Galileo_Gen_2 / Support_Files / startup.S
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* Set to 1 to enable functionality */\r
71 #define __SHOW_KERNEL_PARAMS__ 0\r
72 \r
73 /* Local definitions boot loader */\r
74 #define MULTIBOOT_SIGNATURE             0x2BADB002\r
75 #define MULTIBOOT_BOOTINFO_MMAP 0x00000040\r
76 \r
77 /* Local definitions for GD table */\r
78 #define GDT_ENTRIES                     8\r
79 #define GDT_ENTRY_SIZE          8\r
80 #define GDT_BYTES                       (GDT_ENTRIES * GDT_ENTRY_SIZE)\r
81 \r
82         /* Globals and externs */\r
83         .global _mboot_hdr\r
84         .global _start\r
85         .global _restart\r
86 \r
87         .extern bootsign\r
88         .extern bootinfo\r
89 \r
90         .extern __text_start\r
91         .extern __text_end\r
92         .extern __data_vma\r
93         .extern __data_lma\r
94         .extern __data_start\r
95         .extern __data_end\r
96         .extern __bss_start\r
97         .extern __bss_end\r
98         .extern __stack_for_main\r
99 \r
100         .global __text_start\r
101         .global __text_end\r
102         .global __data_vma\r
103         .global __data_lma\r
104         .global __data_start\r
105         .global __data_end\r
106         .global __bss_start\r
107         .global __bss_end\r
108 \r
109         .extern setsegs\r
110         .extern CRT_Init\r
111         .extern kernel_load_check\r
112         .extern main\r
113 \r
114         /* Local constants for multiboot section */\r
115         .set ALIGN,     1<<0                    /* align loaded modules on page boundaries */\r
116         .set MEMINFO,   1<<1                    /* provide memory map */\r
117         .set MAGIC,     0x1BADB002              /* 'magic number' lets bootloader find the header */\r
118         .set FLAGS,     ALIGN|MEMINFO           /* this is the multiboot 'flag' field */\r
119         .set CHECKSUM,  -(MAGIC + FLAGS)        /* checksum of above */\r
120 \r
121         /* Set-up GDT */\r
122         .section .data\r
123 \r
124         .align  16\r
125         .globl  gdt\r
126         gdt:    .space  GDT_BYTES\r
127         gdtr:   .word   (GDT_BYTES-1)           /* sizeof _gdt -1 (in bytes) */\r
128         .long   gdt                                                     /* global pointer to the gdt */\r
129 \r
130         /* Start of application text */\r
131         .section .text.entry\r
132 \r
133         /* Skip mb header */\r
134         jmp _start\r
135 \r
136         .align 4\r
137         /* Multiboot header */\r
138         _mboot_hdr:\r
139         .long MAGIC                                                     /* offset = 0 */\r
140         .long FLAGS                                                     /* offset = 4 */\r
141         .long CHECKSUM                                          /* offset = 8 */\r
142         .long _mboot_hdr                                        /* should be header address - offset = 12 */\r
143         .long __text_start                                      /* load address (start of text) - offset = 16 */\r
144         .long __bss_start                                       /* load end address (end of data) - offset = 20*/\r
145         .long __bss_end                                         /* bss end address - offset = 24*/\r
146         .long _start                                            /* entry_addr - offset = 28*/\r
147 \r
148         /* Start of executable code */\r
149         _start:\r
150 \r
151     /* Store boot arguments */\r
152         movl    %eax, bootsign\r
153         movl    %ebx, bootinfo\r
154 \r
155     /* Check to see if kernel is bootstrapped by grub */\r
156         cmpl $MULTIBOOT_SIGNATURE, %eax\r
157         jne _local_loop\r
158         testb   $MULTIBOOT_BOOTINFO_MMAP, (%ebx)\r
159         je      _local_loop\r
160 \r
161         _restart:\r
162 \r
163         /* Initialise the stack pointer */\r
164         movl $__stack_for_main, %esp\r
165 \r
166     /* Reset EFLAGS. */\r
167     pushl $0\r
168     popf\r
169 \r
170         /* Set up the global descriptor table */\r
171         call    setsegs\r
172         lgdt    gdtr\r
173         ljmp    $0x8, $gdt1                                     /* CS descriptor 1 */\r
174         gdt1:\r
175         movl    $0x10, %eax                                     /* DS descriptor 2 */\r
176         movw    %ax, %ds\r
177         movw    %ax, %es\r
178         movw    %ax, %fs\r
179         movw    %ax, %gs\r
180         movl    $0x18, %eax                                     /* SS descriptor 3 */\r
181         movw    %ax, %ss\r
182 \r
183     /* Clear interrupt flag */\r
184         cli\r
185 \r
186     /* Initialise platform */\r
187         call CRT_Init\r
188 \r
189     /* Show kernel parameters and call main, or just call main */\r
190         #if (__SHOW_KERNEL_PARAMS__ == 1)\r
191             /*---------------------------------------------------------------------\r
192                 On successful OS load EAX should contain 0x2BADB002\r
193                 EBX should contain the physical address of multiboot info structure\r
194 \r
195                 Push the pointers to the multiboot information structure\r
196                 and the magic number on the stack and check values returned\r
197             ----------------------------------------------------------------------*/\r
198             movl        bootsign, %eax\r
199                 movl    bootinfo, %ebx\r
200             pushl   %ebx                /* Multiboot information */\r
201             pushl   %eax                /* Magic number */\r
202             call show_kernel_parameters\r
203         #else\r
204             /*---------------------------------------------------------------------\r
205                 Call main() routine\r
206             ----------------------------------------------------------------------*/\r
207                 call main\r
208     #endif\r
209 \r
210         /* Should not get here, but just in case - loop forever */\r
211         cli\r
212         _local_loop:\r
213         hlt\r
214         jmp _local_loop\r
215 \r
216         /*-------------------------------------------------------------------------\r
217                           GLOBAL ASSEMBLY LANGUAGE ROUTINES\r
218         --------------------------------------------------------------------------*/\r
219 \r
220         /* halt */\r
221         .globl  halt\r
222         halt:\r
223         jmp halt\r
224         ret\r
225 \r
226         /* inb */\r
227         .globl  inb\r
228         inb:    movl    4(%esp), %edx\r
229         xorl    %eax, %eax      # clr eax\r
230         inb     %dx, %al\r
231         ret\r
232 \r
233         /* inw */\r
234         .globl  inw\r
235         inw:    movl    4(%esp), %edx\r
236         xorl    %eax, %eax      # clr eax\r
237         inw             %dx, %ax\r
238         ret\r
239 \r
240         /* inl */\r
241         .globl  inl\r
242         inl:    movl    4(%esp), %edx\r
243         xorl    %eax, %eax\r
244         inl             %dx, %eax\r
245         ret\r
246 \r
247         /* outb */\r
248         .globl  outb\r
249         outb:   movl    4(%esp), %edx\r
250         movl    8(%esp), %eax\r
251         outb    %al, %dx\r
252         ret\r
253 \r
254         /* outw */\r
255         .globl  outw\r
256         outw:   movl    4(%esp), %edx\r
257         movl    8(%esp), %eax\r
258         outw    %ax, %dx\r
259         ret\r
260 \r
261         /* outl */\r
262         .globl  outl\r
263         outl:   movl    4(%esp), %edx\r
264         movl    8(%esp), %eax\r
265         outl    %eax, %dx\r
266         ret\r
267 \r
268 .end\r