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