[412] | 1 | ///////////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2 | // File : boot.c |
---|
| 3 | // Date : 01/11/2013 |
---|
| 4 | // Author : alain greiner |
---|
| 5 | // Copyright (c) UPMC-LIP6 |
---|
| 6 | ////////////////////////////////////////////////////////////////////////////////////////// |
---|
| 7 | // The boot.c file is part of the GIET-VM nano-kernel. |
---|
| 8 | // |
---|
| 9 | // This nano-kernel has been written for the MIPS32 processor. |
---|
[359] | 10 | // The virtual adresses are on 32 bits and use the (unsigned int) type. The |
---|
[258] | 11 | // physicals addresses can have up to 40 bits, and use the (unsigned long long) type. |
---|
[412] | 12 | // It natively supports clusterised shared memory multi-processors architectures, |
---|
[263] | 13 | // where each processor is identified by a composite index (cluster_xy, local_id), |
---|
[258] | 14 | // and where there is one physical memory bank per cluster. |
---|
| 15 | // |
---|
[359] | 16 | // This code, executed in the boot phase by proc[0,0,0], performs the following tasks: |
---|
| 17 | // - load into memory various binary files, from a FAT32 file system, |
---|
[258] | 18 | // - build the various page tables (one page table per vspace) |
---|
| 19 | // - initialize the shedulers (one scheduler per processor) |
---|
| 20 | // |
---|
| 21 | // 1) The binary files to be loaded are: |
---|
| 22 | // - the "map.bin" file contains the hardware architecture description and the |
---|
| 23 | // mapping directives. It must be stored in the the seg_boot_mapping segment |
---|
[321] | 24 | // (at address SEG_BOOT_MAPPING_BASE defined in hard_config.h file). |
---|
[258] | 25 | // - the "sys.elf" file contains the kernel binary code and data. |
---|
| 26 | // - the various "application.elf" files. |
---|
| 27 | // |
---|
| 28 | // 2) The map.bin file contains the binary representation of the map.xml file defining: |
---|
| 29 | // - the hardware architecture: number of clusters, number or processors, |
---|
| 30 | // size of the memory segments, and peripherals in each cluster. |
---|
| 31 | // - The structure of the various multi-threaded software applications: |
---|
| 32 | // number of tasks, communication channels. |
---|
[309] | 33 | // - The mapping: grouping of virtual objects (vobj) in the virtual segments (vseg), |
---|
[258] | 34 | // placement of virtual segments (vseg) in the physical segments (pseg), placement |
---|
| 35 | // of software tasks on the processors, |
---|
| 36 | // |
---|
| 37 | // 3) The GIET-VM uses the paged virtual memory to provides two services: |
---|
| 38 | // - classical memory protection, when several independant applications compiled |
---|
| 39 | // in different virtual spaces are executing on the same hardware platform. |
---|
[412] | 40 | // - data placement in NUMA architectures, to control the placement |
---|
| 41 | // of the software objects (vsegs) on the physical memory banks (psegs). |
---|
[258] | 42 | // |
---|
[412] | 43 | // The max number of vspaces (GIET_NB_VSPACE_MAX) is a configuration parameter. |
---|
[258] | 44 | // The page table are statically build in the boot phase, and they do not |
---|
[412] | 45 | // change during execution. |
---|
| 46 | // The GIET_VM uses both small pages (4 Kbytes), and big pages (2 Mbytes). |
---|
[258] | 47 | // |
---|
| 48 | // Each page table (one page table per virtual space) is monolithic, and contains |
---|
[412] | 49 | // one PT1 (8 Kbytes) and a variable number of PT2s (4 Kbytes each). For each vspace, |
---|
| 50 | // the numberof PT2s is defined by the size of the PTAB vobj in the mapping. |
---|
| 51 | // The PT1 is indexed by the ix1 field (11 bits) of the VPN. Each entry is 32 bits. |
---|
| 52 | // A PT2 is indexed the ix2 field (9 bits) of the VPN. Each entry is a double word. |
---|
| 53 | // The first word contains the flags, the second word contains the PPN. |
---|
| 54 | // |
---|
| 55 | // The page tables can be distributed in all clusters. |
---|
[263] | 56 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
| 57 | // Implementation Notes: |
---|
| 58 | // |
---|
| 59 | // 1) The cluster_id variable is a linear index in the mapping_info array of clusters. |
---|
| 60 | // We use the cluster_xy variable for the tological index = x << Y_WIDTH + y |
---|
[412] | 61 | // |
---|
[263] | 62 | /////////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 63 | |
---|
[263] | 64 | #include <giet_config.h> |
---|
[258] | 65 | #include <mwmr_channel.h> |
---|
| 66 | #include <barrier.h> |
---|
| 67 | #include <memspace.h> |
---|
| 68 | #include <tty_driver.h> |
---|
| 69 | #include <xcu_driver.h> |
---|
[347] | 70 | #include <bdv_driver.h> |
---|
[258] | 71 | #include <dma_driver.h> |
---|
| 72 | #include <cma_driver.h> |
---|
| 73 | #include <nic_driver.h> |
---|
| 74 | #include <ioc_driver.h> |
---|
[299] | 75 | #include <iob_driver.h> |
---|
[295] | 76 | #include <pic_driver.h> |
---|
[258] | 77 | #include <mwr_driver.h> |
---|
| 78 | #include <ctx_handler.h> |
---|
| 79 | #include <irq_handler.h> |
---|
| 80 | #include <vmem.h> |
---|
[412] | 81 | #include <pmem.h> |
---|
[258] | 82 | #include <utils.h> |
---|
| 83 | #include <elf-types.h> |
---|
| 84 | |
---|
| 85 | // for boot FAT initialisation |
---|
| 86 | #include <fat32.h> |
---|
| 87 | |
---|
| 88 | #include <mips32_registers.h> |
---|
| 89 | #include <stdarg.h> |
---|
| 90 | |
---|
[263] | 91 | #if !defined(X_SIZE) |
---|
[359] | 92 | # error: The X_SIZE value must be defined in the 'hard_config.h' file ! |
---|
[258] | 93 | #endif |
---|
| 94 | |
---|
[263] | 95 | #if !defined(Y_SIZE) |
---|
[359] | 96 | # error: The Y_SIZE value must be defined in the 'hard_config.h' file ! |
---|
[263] | 97 | #endif |
---|
| 98 | |
---|
| 99 | #if !defined(X_WIDTH) |
---|
[359] | 100 | # error: The X_WIDTH value must be defined in the 'hard_config.h' file ! |
---|
[263] | 101 | #endif |
---|
| 102 | |
---|
| 103 | #if !defined(Y_WIDTH) |
---|
[359] | 104 | # error: The Y_WIDTH value must be defined in the 'hard_config.h' file ! |
---|
[263] | 105 | #endif |
---|
| 106 | |
---|
[321] | 107 | #if !defined(SEG_BOOT_MAPPING_BASE) |
---|
[359] | 108 | # error: The SEG_BOOT_MAPPING_BASE value must be defined in the hard_config.h file ! |
---|
[321] | 109 | #endif |
---|
| 110 | |
---|
[359] | 111 | #if !defined(NB_PROCS_MAX) |
---|
| 112 | # error: The NB_PROCS_MAX value must be defined in the 'hard_config.h' file ! |
---|
[321] | 113 | #endif |
---|
| 114 | |
---|
[359] | 115 | #if !defined(GIET_NB_VSPACE_MAX) |
---|
| 116 | # error: The GIET_NB_VSPACE_MAX value must be defined in the 'giet_config.h' file ! |
---|
[321] | 117 | #endif |
---|
| 118 | |
---|
[359] | 119 | #if !defined(GIET_ELF_BUFFER_SIZE) |
---|
| 120 | # error: The GIET_ELF_BUFFER_SIZE value must be defined in the giet_config.h file ! |
---|
[258] | 121 | #endif |
---|
| 122 | |
---|
| 123 | //////////////////////////////////////////////////////////////////////////// |
---|
| 124 | // Global variables for boot code |
---|
| 125 | //////////////////////////////////////////////////////////////////////////// |
---|
| 126 | |
---|
[366] | 127 | extern void boot_entry(); |
---|
| 128 | |
---|
[412] | 129 | // FAT internal representation for boot code |
---|
| 130 | __attribute__((section (".bootdata"))) |
---|
| 131 | fat32_fs_t fat __attribute__((aligned(512))); |
---|
[258] | 132 | |
---|
[412] | 133 | // Temporaty buffer used to load one complete .elf file |
---|
[258] | 134 | __attribute__((section (".bootdata"))) |
---|
[412] | 135 | char boot_elf_buffer[GIET_ELF_BUFFER_SIZE] __attribute__((aligned(512))); |
---|
[258] | 136 | |
---|
[412] | 137 | // Physical memory allocators array (one per cluster) |
---|
[258] | 138 | __attribute__((section (".bootdata"))) |
---|
[412] | 139 | pmem_alloc_t boot_pmem_alloc[X_SIZE][Y_SIZE]; |
---|
[258] | 140 | |
---|
[412] | 141 | // Schedulers virtual base addresses array (one per processor) |
---|
[258] | 142 | __attribute__((section (".bootdata"))) |
---|
[412] | 143 | static_scheduler_t* _schedulers[X_SIZE][Y_SIZE][NB_PROCS_MAX]; |
---|
[258] | 144 | |
---|
[412] | 145 | // Page tables virtual base addresses array (one per vspace) |
---|
[258] | 146 | __attribute__((section (".bootdata"))) |
---|
[412] | 147 | unsigned int _ptabs_vaddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
[258] | 148 | |
---|
[412] | 149 | // Page tables physical base addresses (one per vspace and per cluster) |
---|
[263] | 150 | __attribute__((section (".bootdata"))) |
---|
[412] | 151 | paddr_t _ptabs_paddr[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
[258] | 152 | |
---|
[412] | 153 | // Page tables pt2 allocators (one per vspace and per cluster) |
---|
[359] | 154 | __attribute__((section (".bootdata"))) |
---|
[412] | 155 | unsigned int _ptabs_next_pt2[GIET_NB_VSPACE_MAX][X_SIZE][Y_SIZE]; |
---|
[263] | 156 | |
---|
[412] | 157 | // Page tables max_pt2 (same value for all page tables) |
---|
| 158 | __attribute__((section (".bootdata"))) |
---|
| 159 | unsigned int _ptabs_max_pt2; |
---|
| 160 | |
---|
[258] | 161 | ///////////////////////////////////////////////////////////////////// |
---|
| 162 | // This function checks consistence beween the mapping_info data |
---|
| 163 | // structure (soft), and the giet_config file (hard). |
---|
| 164 | ///////////////////////////////////////////////////////////////////// |
---|
| 165 | void boot_mapping_check() |
---|
| 166 | { |
---|
[321] | 167 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 168 | |
---|
| 169 | // checking mapping availability |
---|
| 170 | if (header->signature != IN_MAPPING_SIGNATURE) |
---|
| 171 | { |
---|
| 172 | _puts("\n[BOOT ERROR] Illegal mapping signature: "); |
---|
| 173 | _putx(header->signature); |
---|
| 174 | _puts("\n"); |
---|
| 175 | _exit(); |
---|
| 176 | } |
---|
[263] | 177 | |
---|
[258] | 178 | // checking number of clusters |
---|
[263] | 179 | if ( (header->x_size != X_SIZE) || |
---|
| 180 | (header->y_size != Y_SIZE) || |
---|
| 181 | (header->x_width != X_WIDTH) || |
---|
| 182 | (header->y_width != Y_WIDTH) ) |
---|
[258] | 183 | { |
---|
[263] | 184 | _puts("\n[BOOT ERROR] Incoherent X_SIZE or Y_SIZE "); |
---|
| 185 | _puts("\n - In hard_config: X_SIZE = "); |
---|
| 186 | _putd( X_SIZE ); |
---|
| 187 | _puts(" / Y_SIZE = "); |
---|
| 188 | _putd( Y_SIZE ); |
---|
| 189 | _puts(" / X_WIDTH = "); |
---|
| 190 | _putd( X_WIDTH ); |
---|
| 191 | _puts(" / Y_WIDTH = "); |
---|
| 192 | _putd( Y_WIDTH ); |
---|
| 193 | _puts("\n - In mapping_info: x_size = "); |
---|
| 194 | _putd( header->x_size ); |
---|
| 195 | _puts(" / y_size = "); |
---|
| 196 | _putd( header->y_size ); |
---|
| 197 | _puts(" / x_width = "); |
---|
| 198 | _putd( header->x_width ); |
---|
| 199 | _puts(" / y_width = "); |
---|
| 200 | _putd( header->y_width ); |
---|
[258] | 201 | _puts("\n"); |
---|
| 202 | _exit(); |
---|
| 203 | } |
---|
| 204 | // checking number of virtual spaces |
---|
| 205 | if (header->vspaces > GIET_NB_VSPACE_MAX) |
---|
| 206 | { |
---|
| 207 | _puts("\n[BOOT ERROR] : number of vspaces > GIET_NB_VSPACE_MAX\n"); |
---|
| 208 | _puts("\n"); |
---|
| 209 | _exit(); |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | #if BOOT_DEBUG_MAPPING |
---|
[263] | 213 | _puts("\n - x_size = "); |
---|
| 214 | _putd( header->x_size ); |
---|
| 215 | _puts("\n - y_size = "); |
---|
| 216 | _putd( header->y_size ); |
---|
[258] | 217 | _puts("\n - procs = "); |
---|
| 218 | _putd( header->procs ); |
---|
| 219 | _puts("\n - periphs = "); |
---|
| 220 | _putd( header->periphs ); |
---|
| 221 | _puts("\n - vspaces = "); |
---|
| 222 | _putd( header->vspaces ); |
---|
| 223 | _puts("\n - tasks = "); |
---|
| 224 | _putd( header->tasks ); |
---|
| 225 | _puts("\n"); |
---|
| 226 | _puts("\n - size of header = "); |
---|
| 227 | _putd( MAPPING_HEADER_SIZE ); |
---|
| 228 | _puts("\n - size of cluster = "); |
---|
| 229 | _putd( MAPPING_CLUSTER_SIZE ); |
---|
| 230 | _puts("\n - size of pseg = "); |
---|
| 231 | _putd( MAPPING_PSEG_SIZE ); |
---|
| 232 | _puts("\n - size of proc = "); |
---|
| 233 | _putd( MAPPING_PROC_SIZE ); |
---|
| 234 | _puts("\n - size of vspace = "); |
---|
| 235 | _putd( MAPPING_VSPACE_SIZE ); |
---|
| 236 | _puts("\n - size of vseg = "); |
---|
| 237 | _putd( MAPPING_VSEG_SIZE ); |
---|
| 238 | _puts("\n - size of vobj = "); |
---|
| 239 | _putd( MAPPING_VOBJ_SIZE ); |
---|
| 240 | _puts("\n - size of task = "); |
---|
| 241 | _putd( MAPPING_TASK_SIZE ); |
---|
| 242 | _puts("\n"); |
---|
| 243 | |
---|
[263] | 244 | unsigned int cluster_id; |
---|
[258] | 245 | mapping_cluster_t * cluster = _get_cluster_base(header); |
---|
[263] | 246 | for( cluster_id = 0; cluster_id < X_SIZE*Y_SIZE ; cluster_id++) |
---|
[258] | 247 | { |
---|
[263] | 248 | _puts("\n - cluster["); |
---|
| 249 | _putd( cluster[cluster_id].x ); |
---|
| 250 | _puts(","); |
---|
| 251 | _putd( cluster[cluster_id].y ); |
---|
| 252 | _puts("]\n procs = "); |
---|
| 253 | _putd( cluster[cluster_id].procs ); |
---|
| 254 | _puts("\n psegs = "); |
---|
| 255 | _putd( cluster[cluster_id].psegs ); |
---|
| 256 | _puts("\n periphs = "); |
---|
| 257 | _putd( cluster[cluster_id].periphs ); |
---|
| 258 | _puts("\n"); |
---|
[258] | 259 | } |
---|
| 260 | #endif |
---|
| 261 | |
---|
| 262 | } // end boot_mapping_check() |
---|
| 263 | |
---|
| 264 | ////////////////////////////////////////////////////////////////////////////// |
---|
[412] | 265 | // This function registers a new PTE1 in the page table defined |
---|
| 266 | // by the vspace_id argument, and the (x,y) coordinates. |
---|
| 267 | // It updates only the first level PT1. |
---|
[258] | 268 | ////////////////////////////////////////////////////////////////////////////// |
---|
[412] | 269 | void boot_add_pte1( unsigned int vspace_id, |
---|
| 270 | unsigned int x, |
---|
| 271 | unsigned int y, |
---|
| 272 | unsigned int vpn, // 20 bits right-justified |
---|
| 273 | unsigned int flags, // 10 bits left-justified |
---|
| 274 | unsigned int ppn ) // 28 bits right-justified |
---|
[258] | 275 | { |
---|
[427] | 276 | |
---|
| 277 | #if (BOOT_DEBUG_PT > 1) |
---|
| 278 | _puts(" - PTE1 in PTAB["); |
---|
| 279 | _putd( vspace_id ); |
---|
| 280 | _puts(","); |
---|
| 281 | _putd( x ); |
---|
| 282 | _puts(","); |
---|
| 283 | _putd( y ); |
---|
| 284 | _puts("] : vpn = "); |
---|
| 285 | _putx( vpn ); |
---|
| 286 | #endif |
---|
| 287 | |
---|
[412] | 288 | // compute index in PT1 |
---|
| 289 | unsigned int ix1 = vpn >> 9; // 11 bits for ix1 |
---|
[258] | 290 | |
---|
[412] | 291 | // get page table physical base address |
---|
| 292 | paddr_t pt1_pbase = _ptabs_paddr[vspace_id][x][y]; |
---|
| 293 | |
---|
| 294 | // check pt1_base |
---|
| 295 | if ( pt1_pbase == 0 ) |
---|
[258] | 296 | { |
---|
[412] | 297 | _puts("\n[BOOT ERROR] in boot_add_pte1() : illegal pbase address for PTAB["); |
---|
| 298 | _putd( vspace_id ); |
---|
| 299 | _puts(","); |
---|
| 300 | _putd( x ); |
---|
| 301 | _puts(","); |
---|
| 302 | _putd( y ); |
---|
| 303 | _puts("]\n"); |
---|
[258] | 304 | _exit(); |
---|
| 305 | } |
---|
| 306 | |
---|
[412] | 307 | // compute pte1 : 2 bits V T / 8 bits flags / 3 bits RSVD / 19 bits bppi |
---|
| 308 | unsigned int pte1 = PTE_V | |
---|
| 309 | (flags & 0x3FC00000) | |
---|
| 310 | ((ppn>>9) & 0x0007FFFF); |
---|
[258] | 311 | |
---|
[412] | 312 | // write pte1 in PT1 |
---|
| 313 | _physical_write( pt1_pbase + 4*ix1, pte1 ); |
---|
| 314 | |
---|
| 315 | #if (BOOT_DEBUG_PT > 1) |
---|
| 316 | _puts(" / ppn = "); |
---|
| 317 | _putx( ppn ); |
---|
| 318 | _puts(" / flags = "); |
---|
| 319 | _putx( flags ); |
---|
| 320 | _puts("\n"); |
---|
| 321 | #endif |
---|
| 322 | |
---|
| 323 | } // end boot_add_pte1() |
---|
| 324 | |
---|
[258] | 325 | ////////////////////////////////////////////////////////////////////////////// |
---|
[412] | 326 | // This function registers a new PTE2 in the page table defined |
---|
[347] | 327 | // by the vspace_id argument, and the (x,y) coordinates. |
---|
[412] | 328 | // It updates both the first level PT1 and the second level PT2. |
---|
[258] | 329 | // As the set of PT2s is implemented as a fixed size array (no dynamic |
---|
| 330 | // allocation), this function checks a possible overflow of the PT2 array. |
---|
| 331 | ////////////////////////////////////////////////////////////////////////////// |
---|
[412] | 332 | void boot_add_pte2( unsigned int vspace_id, |
---|
| 333 | unsigned int x, |
---|
| 334 | unsigned int y, |
---|
| 335 | unsigned int vpn, // 20 bits right-justified |
---|
| 336 | unsigned int flags, // 10 bits left-justified |
---|
| 337 | unsigned int ppn ) // 28 bits right-justified |
---|
[258] | 338 | { |
---|
[427] | 339 | |
---|
| 340 | #if (BOOT_DEBUG_PT > 1) |
---|
| 341 | _puts(" - PTE2 in PTAB["); |
---|
| 342 | _putd( vspace_id ); |
---|
| 343 | _puts(","); |
---|
| 344 | _putd( x ); |
---|
| 345 | _puts(","); |
---|
| 346 | _putd( y ); |
---|
| 347 | _puts("] : vpn = "); |
---|
| 348 | _putx( vpn ); |
---|
| 349 | #endif |
---|
| 350 | |
---|
[258] | 351 | unsigned int ix1; |
---|
| 352 | unsigned int ix2; |
---|
[347] | 353 | paddr_t pt2_pbase; // PT2 physical base address |
---|
[412] | 354 | paddr_t pte2_paddr; // PTE2 physical address |
---|
[258] | 355 | unsigned int pt2_id; // PT2 index |
---|
| 356 | unsigned int ptd; // PTD : entry in PT1 |
---|
| 357 | |
---|
[412] | 358 | ix1 = vpn >> 9; // 11 bits for ix1 |
---|
| 359 | ix2 = vpn & 0x1FF; // 9 bits for ix2 |
---|
[258] | 360 | |
---|
[347] | 361 | // get page table physical base address and size |
---|
| 362 | paddr_t pt1_pbase = _ptabs_paddr[vspace_id][x][y]; |
---|
[258] | 363 | |
---|
[412] | 364 | // check pt1_base |
---|
| 365 | if ( pt1_pbase == 0 ) |
---|
[258] | 366 | { |
---|
[412] | 367 | _puts("\n[BOOT ERROR] in boot_add_pte2() : PTAB["); |
---|
| 368 | _putd( vspace_id ); |
---|
| 369 | _puts(","); |
---|
| 370 | _putd( x ); |
---|
| 371 | _puts(","); |
---|
| 372 | _putd( y ); |
---|
| 373 | _puts("] undefined\n"); |
---|
[258] | 374 | _exit(); |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | // get ptd in PT1 |
---|
| 378 | ptd = _physical_read(pt1_pbase + 4 * ix1); |
---|
| 379 | |
---|
[347] | 380 | if ((ptd & PTE_V) == 0) // undefined PTD: compute PT2 base address, |
---|
[258] | 381 | // and set a new PTD in PT1 |
---|
| 382 | { |
---|
[347] | 383 | pt2_id = _ptabs_next_pt2[vspace_id][x][y]; |
---|
[412] | 384 | if (pt2_id == _ptabs_max_pt2) |
---|
[258] | 385 | { |
---|
[412] | 386 | _puts("\n[BOOT ERROR] in boot_add_pte2() : PTAB["); |
---|
| 387 | _putd( vspace_id ); |
---|
| 388 | _puts(","); |
---|
| 389 | _putd( x ); |
---|
| 390 | _puts(","); |
---|
| 391 | _putd( y ); |
---|
| 392 | _puts("] contains not enough PT2s\n"); |
---|
[258] | 393 | _exit(); |
---|
| 394 | } |
---|
[347] | 395 | |
---|
| 396 | pt2_pbase = pt1_pbase + PT1_SIZE + PT2_SIZE * pt2_id; |
---|
| 397 | ptd = PTE_V | PTE_T | (unsigned int) (pt2_pbase >> 12); |
---|
[412] | 398 | _physical_write( pt1_pbase + 4*ix1, ptd); |
---|
[347] | 399 | _ptabs_next_pt2[vspace_id][x][y] = pt2_id + 1; |
---|
[258] | 400 | } |
---|
| 401 | else // valid PTD: compute PT2 base address |
---|
| 402 | { |
---|
| 403 | pt2_pbase = ((paddr_t)(ptd & 0x0FFFFFFF)) << 12; |
---|
| 404 | } |
---|
| 405 | |
---|
| 406 | // set PTE in PT2 : flags & PPN in two 32 bits words |
---|
[412] | 407 | pte2_paddr = pt2_pbase + 8 * ix2; |
---|
| 408 | _physical_write(pte2_paddr , (PTE_V |flags) ); |
---|
| 409 | _physical_write(pte2_paddr + 4 , ppn); |
---|
[258] | 410 | |
---|
[412] | 411 | #if (BOOT_DEBUG_PT > 1) |
---|
| 412 | _puts(" / ppn = "); |
---|
| 413 | _putx( ppn ); |
---|
| 414 | _puts(" / flags = "); |
---|
| 415 | _putx( flags ); |
---|
[347] | 416 | _puts("\n"); |
---|
[258] | 417 | #endif |
---|
| 418 | |
---|
[412] | 419 | } // end boot_add_pte2() |
---|
[258] | 420 | |
---|
[412] | 421 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 422 | // Align the value of paddr or vaddr to the required alignement, |
---|
| 423 | // defined by alignPow2 == L2(alignement). |
---|
[412] | 424 | //////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 425 | paddr_t paddr_align_to(paddr_t paddr, unsigned int alignPow2) |
---|
| 426 | { |
---|
| 427 | paddr_t mask = (1 << alignPow2) - 1; |
---|
| 428 | return ((paddr + mask) & ~mask); |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | unsigned int vaddr_align_to(unsigned int vaddr, unsigned int alignPow2) |
---|
| 432 | { |
---|
| 433 | unsigned int mask = (1 << alignPow2) - 1; |
---|
| 434 | return ((vaddr + mask) & ~mask); |
---|
| 435 | } |
---|
| 436 | |
---|
[412] | 437 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| 438 | // This function map a vseg identified by the vseg pointer. |
---|
| 439 | // |
---|
| 440 | // A given vseg can be mapped in Big Physical Pages (BPP: 2 Mbytes) or in a |
---|
| 441 | // Small Physical Pages (SPP: 4 Kbytes), depending on the "big" attribute of vseg, |
---|
| 442 | // with the following rules: |
---|
| 443 | // - SPP : There is only one vseg in a small physical page, but a single vseg |
---|
| 444 | // can cover several contiguous small physical pages. |
---|
| 445 | // - BPP : It can exist several vsegs in a single big physical page, and a single |
---|
| 446 | // vseg can cover several contiguous big physical pages. |
---|
| 447 | // |
---|
| 448 | // 1) First step: it computes the vseg length, and register it in vseg->length field. |
---|
| 449 | // It computes - for each vobj - the actual vbase address, taking into |
---|
| 450 | // account the alignment constraints and register it in vobj->vbase field. |
---|
| 451 | // |
---|
| 452 | // 2) Second step: it allocates the required number of physical pages, |
---|
| 453 | // computes the physical base address (if the vseg is not identity mapping), |
---|
| 454 | // and register it in the vseg pbase field. |
---|
| 455 | // Only the 4 vsegs used by the boot code and the peripheral vsegs |
---|
| 456 | // can be identity mapping: The first big physical page in cluster[0,0] |
---|
| 457 | // is reserved for the 4 boot vsegs. |
---|
| 458 | // |
---|
| 459 | // 3) Third step (only for vseg that have the VOBJ_TYPE_PTAB): all page tables |
---|
| 460 | // associated to the various vspaces must be packed in the same vseg. |
---|
| 461 | // We divide the vseg in M sub-segments, and compute the vbase and pbase |
---|
| 462 | // addresses for each page table, and register it in the _ptabs_paddr |
---|
| 463 | // and _ptabs_vaddr arrays. |
---|
| 464 | // |
---|
| 465 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[427] | 466 | void boot_vseg_map( mapping_vseg_t* vseg, |
---|
| 467 | unsigned int vspace_id ) |
---|
[258] | 468 | { |
---|
[412] | 469 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 470 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
| 471 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 472 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
[258] | 473 | |
---|
[412] | 474 | // compute destination cluster pointer & coordinates |
---|
| 475 | pseg = pseg + vseg->psegid; |
---|
| 476 | cluster = cluster + pseg->clusterid; |
---|
| 477 | unsigned int x_dest = cluster->x; |
---|
| 478 | unsigned int y_dest = cluster->y; |
---|
[258] | 479 | |
---|
[412] | 480 | // compute the first vobj global index |
---|
| 481 | unsigned int vobj_id = vseg->vobj_offset; |
---|
| 482 | |
---|
| 483 | // compute the "big" vseg attribute |
---|
| 484 | unsigned int big = vseg->big; |
---|
[258] | 485 | |
---|
[412] | 486 | // compute the "is_ram" vseg attribute |
---|
| 487 | unsigned int is_ram; |
---|
| 488 | if ( pseg->type == PSEG_TYPE_RAM ) is_ram = 1; |
---|
| 489 | else is_ram = 0; |
---|
[258] | 490 | |
---|
[412] | 491 | // compute the "is_ptab" attribute |
---|
| 492 | unsigned int is_ptab; |
---|
| 493 | if ( vobj[vobj_id].type == VOBJ_TYPE_PTAB ) is_ptab = 1; |
---|
| 494 | else is_ptab = 0; |
---|
[258] | 495 | |
---|
[427] | 496 | // compute actual vspace index |
---|
| 497 | unsigned int vsid; |
---|
| 498 | if ( vspace_id == 0xFFFFFFFF ) vsid = 0; |
---|
| 499 | else vsid = vspace_id; |
---|
| 500 | |
---|
[412] | 501 | //////////// First step : compute vseg length and vobj(s) vbase |
---|
[258] | 502 | |
---|
[412] | 503 | unsigned int vobj_vbase = vseg->vbase; // min vbase for first vobj |
---|
[258] | 504 | |
---|
[412] | 505 | for ( vobj_id = vseg->vobj_offset ; |
---|
| 506 | vobj_id < (vseg->vobj_offset + vseg->vobjs) ; |
---|
| 507 | vobj_id++ ) |
---|
[258] | 508 | { |
---|
[412] | 509 | // compute and register vobj vbase |
---|
| 510 | vobj[vobj_id].vbase = vaddr_align_to( vobj_vbase, vobj[vobj_id].align ); |
---|
| 511 | |
---|
| 512 | // compute min vbase for next vobj |
---|
| 513 | vobj_vbase = vobj[vobj_id].vbase + vobj[vobj_id].length; |
---|
[258] | 514 | } |
---|
| 515 | |
---|
[412] | 516 | // compute and register vseg length (multiple of 4 Kbytes) |
---|
| 517 | vseg->length = vaddr_align_to( vobj_vbase - vseg->vbase, 12 ); |
---|
| 518 | |
---|
| 519 | //////////// Second step : compute ppn and npages |
---|
| 520 | //////////// - if identity mapping : ppn <= vpn |
---|
| 521 | //////////// - if vseg is periph : ppn <= pseg.base >> 12 |
---|
| 522 | //////////// - if vseg is ram : ppn <= physical memory allocator |
---|
[258] | 523 | |
---|
[412] | 524 | unsigned int ppn; // first physical page index ( 28 bits = |x|y|bppi|sppi| ) |
---|
| 525 | unsigned int vpn; // first virtual page index ( 20 bits = |ix1|ix2| ) |
---|
| 526 | unsigned int vpn_max; // last virtual page index ( 20 bits = |ix1|ix2| ) |
---|
[258] | 527 | |
---|
[412] | 528 | vpn = vseg->vbase >> 12; |
---|
| 529 | vpn_max = (vseg->vbase + vseg->length - 1) >> 12; |
---|
[258] | 530 | |
---|
[412] | 531 | // compute npages |
---|
| 532 | unsigned int npages; // number of required (big or small) pages |
---|
| 533 | if ( big == 0 ) npages = vpn_max - vpn + 1; // number of small pages |
---|
| 534 | else npages = (vpn_max>>9) - (vpn>>9) + 1; // number of big pages |
---|
| 535 | |
---|
| 536 | // compute ppn |
---|
| 537 | if ( vseg->ident ) // identity mapping |
---|
[258] | 538 | { |
---|
[412] | 539 | ppn = vpn; |
---|
[258] | 540 | } |
---|
[412] | 541 | else // not identity mapping |
---|
[258] | 542 | { |
---|
[412] | 543 | if ( is_ram ) // RAM : physical memory allocation required |
---|
[258] | 544 | { |
---|
[412] | 545 | // compute pointer on physical memory allocator in dest cluster |
---|
| 546 | pmem_alloc_t* palloc = &boot_pmem_alloc[x_dest][y_dest]; |
---|
[258] | 547 | |
---|
[412] | 548 | if ( big == 0 ) // SPP : small physical pages |
---|
| 549 | { |
---|
| 550 | // allocate contiguous small physical pages |
---|
| 551 | ppn = _get_small_ppn( palloc, npages ); |
---|
| 552 | } |
---|
| 553 | else // BPP : big physical pages |
---|
| 554 | { |
---|
| 555 | |
---|
| 556 | // one big page can be shared by several vsegs |
---|
| 557 | // we must chek if BPP already allocated |
---|
| 558 | if ( is_ptab ) // It cannot be mapped |
---|
| 559 | { |
---|
| 560 | ppn = _get_big_ppn( palloc, npages ); |
---|
| 561 | } |
---|
| 562 | else // It can be mapped |
---|
| 563 | { |
---|
| 564 | unsigned int ix1 = vpn >> 9; // 11 bits |
---|
[427] | 565 | paddr_t paddr = _ptabs_paddr[vsid][x_dest][y_dest] + (ix1<<2); |
---|
[412] | 566 | unsigned int pte1 = _physical_read( paddr ); |
---|
| 567 | if ( (pte1 & PTE_V) == 0 ) // BPP not allocated yet |
---|
| 568 | { |
---|
| 569 | // allocate contiguous big physical pages |
---|
[433] | 570 | ppn = _get_big_ppn( palloc, npages ); |
---|
[412] | 571 | } |
---|
| 572 | else // BPP already allocated |
---|
| 573 | { |
---|
[433] | 574 | // test if new vseg has the same mode bits than |
---|
| 575 | // the other vsegs in the same big page |
---|
| 576 | unsigned int pte1_mode = 0; |
---|
| 577 | if (pte1 & PTE_C) pte1_mode |= C_MODE_MASK; |
---|
| 578 | if (pte1 & PTE_X) pte1_mode |= X_MODE_MASK; |
---|
| 579 | if (pte1 & PTE_W) pte1_mode |= W_MODE_MASK; |
---|
| 580 | if (pte1 & PTE_U) pte1_mode |= U_MODE_MASK; |
---|
| 581 | if (vseg->mode != pte1_mode) { |
---|
| 582 | _puts("\n[BOOT ERROR] in boot_vseg_map() : vseg "); |
---|
| 583 | _puts( vseg->name ); |
---|
| 584 | _puts(" has different flags ("); |
---|
| 585 | _putx( vseg->mode ); |
---|
| 586 | _puts(") than other vsegs sharing the same big page ("); |
---|
| 587 | _putx( pte1_mode ); |
---|
| 588 | _puts(")"); |
---|
| 589 | _exit(); |
---|
| 590 | } |
---|
| 591 | |
---|
[412] | 592 | ppn = ((pte1 << 9) & 0x0FFFFE00); |
---|
| 593 | } |
---|
| 594 | } |
---|
| 595 | ppn = ppn | (vpn & 0x1FF); |
---|
| 596 | } |
---|
[258] | 597 | } |
---|
[412] | 598 | else // PERI : no memory allocation required |
---|
[258] | 599 | { |
---|
[412] | 600 | ppn = pseg->base >> 12; |
---|
[258] | 601 | } |
---|
| 602 | } |
---|
| 603 | |
---|
[412] | 604 | // update vseg.pbase field and update vsegs chaining |
---|
| 605 | vseg->pbase = ((paddr_t)ppn) << 12; |
---|
| 606 | vseg->next_vseg = pseg->next_vseg; |
---|
| 607 | pseg->next_vseg = (unsigned int)vseg; |
---|
[258] | 608 | |
---|
[412] | 609 | |
---|
| 610 | //////////// Third step : (only if the vseg is a page table) |
---|
| 611 | //////////// - compute the physical & virtual base address for each vspace |
---|
| 612 | //////////// by dividing the vseg in several sub-segments. |
---|
| 613 | //////////// - register it in _ptabs_vaddr & _ptabs_paddr arrays, |
---|
[427] | 614 | //////////// and initialize next_pt2 allocators. |
---|
| 615 | //////////// - reset all entries in first level page tables |
---|
[412] | 616 | |
---|
| 617 | if ( is_ptab ) |
---|
[258] | 618 | { |
---|
[412] | 619 | unsigned int vs; // vspace index |
---|
| 620 | unsigned int nspaces; // number of vspaces |
---|
| 621 | unsigned int nsp; // number of small pages for one PTAB |
---|
| 622 | unsigned int offset; // address offset for current PTAB |
---|
[258] | 623 | |
---|
[412] | 624 | nspaces = header->vspaces; |
---|
| 625 | offset = 0; |
---|
[258] | 626 | |
---|
[412] | 627 | // each PTAB must be aligned on a 8 Kbytes boundary |
---|
[427] | 628 | nsp = ( vseg->length >> 12 ) / nspaces; |
---|
[412] | 629 | if ( (nsp & 0x1) == 0x1 ) nsp = nsp - 1; |
---|
[258] | 630 | |
---|
[412] | 631 | // compute max_pt2 |
---|
| 632 | _ptabs_max_pt2 = ((nsp<<12) - PT1_SIZE) / PT2_SIZE; |
---|
[433] | 633 | |
---|
[412] | 634 | for ( vs = 0 ; vs < nspaces ; vs++ ) |
---|
[258] | 635 | { |
---|
[433] | 636 | _ptabs_vaddr [vs][x_dest][y_dest] = (vpn + offset) << 12; |
---|
[412] | 637 | _ptabs_paddr [vs][x_dest][y_dest] = ((paddr_t)(ppn + offset)) << 12; |
---|
| 638 | _ptabs_next_pt2[vs][x_dest][y_dest] = 0; |
---|
[427] | 639 | offset += nsp; |
---|
[433] | 640 | |
---|
[427] | 641 | // reset all entries in PT1 (8 Kbytes) |
---|
| 642 | _physical_memset( _ptabs_paddr[vs][x_dest][y_dest], PT1_SIZE, 0 ); |
---|
[258] | 643 | } |
---|
| 644 | } |
---|
| 645 | |
---|
[412] | 646 | #if BOOT_DEBUG_PT |
---|
| 647 | _puts("[BOOT DEBUG] "); |
---|
[433] | 648 | _puts( vseg->name ); |
---|
[412] | 649 | _puts(" in cluster["); |
---|
| 650 | _putd( x_dest ); |
---|
| 651 | _puts(","); |
---|
| 652 | _putd( y_dest ); |
---|
| 653 | _puts("] : vbase = "); |
---|
| 654 | _putx( vseg->vbase ); |
---|
| 655 | _puts(" / length = "); |
---|
| 656 | _putx( vseg->length ); |
---|
| 657 | if ( big ) _puts(" / BIG / npages = "); |
---|
| 658 | else _puts(" / SMALL / npages = "); |
---|
| 659 | _putd( npages ); |
---|
| 660 | _puts(" / pbase = "); |
---|
| 661 | _putl( vseg->pbase ); |
---|
| 662 | _puts("\n"); |
---|
| 663 | #endif |
---|
| 664 | |
---|
| 665 | } // end boot_vseg_map() |
---|
| 666 | |
---|
| 667 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| 668 | // For the vseg defined by the vseg pointer, this function register all PTEs |
---|
| 669 | // in one or several page tables. |
---|
| 670 | // It is a global vseg (system vseg) if (vspace_id == 0xFFFFFFFF). |
---|
| 671 | // The number of involved PTABs depends on the "local" and "global" attributes: |
---|
| 672 | // - PTEs are replicated in all vspaces for a global vseg. |
---|
| 673 | // - PTEs are replicated in all clusters for a non local vseg. |
---|
| 674 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
[427] | 675 | void boot_vseg_pte( mapping_vseg_t* vseg, |
---|
| 676 | unsigned int vspace_id ) |
---|
[412] | 677 | { |
---|
| 678 | // compute the "global" vseg attribute and actual vspace index |
---|
| 679 | unsigned int global; |
---|
| 680 | unsigned int vsid; |
---|
| 681 | if ( vspace_id == 0xFFFFFFFF ) |
---|
[258] | 682 | { |
---|
[412] | 683 | global = 1; |
---|
| 684 | vsid = 0; |
---|
[258] | 685 | } |
---|
[412] | 686 | else |
---|
[258] | 687 | { |
---|
[412] | 688 | global = 0; |
---|
| 689 | vsid = vspace_id; |
---|
[258] | 690 | } |
---|
| 691 | |
---|
[412] | 692 | // compute the "local" and "big" attributes |
---|
| 693 | unsigned int local = vseg->local; |
---|
| 694 | unsigned int big = vseg->big; |
---|
[258] | 695 | |
---|
[412] | 696 | // compute vseg flags |
---|
| 697 | // The three flags (Local, Remote and Dirty) are set to 1 to reduce |
---|
| 698 | // latency of TLB miss (L/R) and write (D): Avoid hardware update |
---|
| 699 | // mechanism for these flags because GIET_VM does use these flags. |
---|
| 700 | unsigned int flags = 0; |
---|
| 701 | if (vseg->mode & C_MODE_MASK) flags |= PTE_C; |
---|
| 702 | if (vseg->mode & X_MODE_MASK) flags |= PTE_X; |
---|
| 703 | if (vseg->mode & W_MODE_MASK) flags |= PTE_W; |
---|
| 704 | if (vseg->mode & U_MODE_MASK) flags |= PTE_U; |
---|
| 705 | if ( global ) flags |= PTE_G; |
---|
| 706 | flags |= PTE_L; |
---|
| 707 | flags |= PTE_R; |
---|
| 708 | flags |= PTE_D; |
---|
[258] | 709 | |
---|
[412] | 710 | // compute VPN, PPN and number of pages (big or small) |
---|
| 711 | unsigned int vpn = vseg->vbase >> 12; |
---|
| 712 | unsigned int vpn_max = (vseg->vbase + vseg->length - 1) >> 12; |
---|
| 713 | unsigned int ppn = (unsigned int)(vseg->pbase >> 12); |
---|
| 714 | unsigned int npages; |
---|
| 715 | if ( big == 0 ) npages = vpn_max - vpn + 1; |
---|
| 716 | else npages = (vpn_max>>9) - (vpn>>9) + 1; |
---|
| 717 | |
---|
| 718 | // compute destination cluster coordinates |
---|
| 719 | unsigned int x_dest; |
---|
| 720 | unsigned int y_dest; |
---|
| 721 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 722 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 723 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
| 724 | pseg = pseg + vseg->psegid; |
---|
| 725 | cluster = cluster + pseg->clusterid; |
---|
| 726 | x_dest = cluster->x; |
---|
| 727 | y_dest = cluster->y; |
---|
| 728 | |
---|
| 729 | unsigned int p; // iterator for physical page index |
---|
| 730 | unsigned int x; // iterator for cluster x coordinate |
---|
| 731 | unsigned int y; // iterator for cluster y coordinate |
---|
| 732 | unsigned int v; // iterator for vspace index |
---|
| 733 | |
---|
| 734 | // loop on PTEs |
---|
| 735 | for ( p = 0 ; p < npages ; p++ ) |
---|
| 736 | { |
---|
| 737 | if ( (local != 0) && (global == 0) ) // one cluster / one vspace |
---|
[258] | 738 | { |
---|
[412] | 739 | if ( big ) // big pages => PTE1s |
---|
| 740 | { |
---|
| 741 | boot_add_pte1( vsid, |
---|
| 742 | x_dest, |
---|
| 743 | y_dest, |
---|
| 744 | vpn + (p<<9), |
---|
| 745 | flags, |
---|
| 746 | ppn + (p<<9) ); |
---|
| 747 | } |
---|
| 748 | else // small pages => PTE2s |
---|
| 749 | { |
---|
| 750 | boot_add_pte2( vsid, |
---|
| 751 | x_dest, |
---|
| 752 | y_dest, |
---|
| 753 | vpn + p, |
---|
| 754 | flags, |
---|
| 755 | ppn + p ); |
---|
| 756 | } |
---|
[258] | 757 | } |
---|
[412] | 758 | else if ( (local == 0) && (global == 0) ) // all clusters / one vspace |
---|
[258] | 759 | { |
---|
[412] | 760 | for ( x = 0 ; x < X_SIZE ; x++ ) |
---|
[258] | 761 | { |
---|
[412] | 762 | for ( y = 0 ; y < Y_SIZE ; y++ ) |
---|
| 763 | { |
---|
| 764 | if ( big ) // big pages => PTE1s |
---|
| 765 | { |
---|
| 766 | boot_add_pte1( vsid, |
---|
| 767 | x, |
---|
| 768 | y, |
---|
| 769 | vpn + (p<<9), |
---|
| 770 | flags, |
---|
| 771 | ppn + (p<<9) ); |
---|
| 772 | } |
---|
| 773 | else // small pages => PTE2s |
---|
| 774 | { |
---|
| 775 | boot_add_pte2( vsid, |
---|
| 776 | x, |
---|
| 777 | y, |
---|
| 778 | vpn + p, |
---|
| 779 | flags, |
---|
| 780 | ppn + p ); |
---|
| 781 | } |
---|
| 782 | } |
---|
[258] | 783 | } |
---|
[412] | 784 | } |
---|
| 785 | else if ( (local != 0) && (global != 0) ) // one cluster / all vspaces |
---|
| 786 | { |
---|
| 787 | for ( v = 0 ; v < header->vspaces ; v++ ) |
---|
[258] | 788 | { |
---|
[412] | 789 | if ( big ) // big pages => PTE1s |
---|
| 790 | { |
---|
| 791 | boot_add_pte1( v, |
---|
| 792 | x_dest, |
---|
| 793 | y_dest, |
---|
| 794 | vpn + (p<<9), |
---|
| 795 | flags, |
---|
| 796 | ppn + (p<<9) ); |
---|
| 797 | } |
---|
| 798 | else // small pages = PTE2s |
---|
| 799 | { |
---|
| 800 | boot_add_pte2( v, |
---|
| 801 | x_dest, |
---|
| 802 | y_dest, |
---|
| 803 | vpn + p, |
---|
| 804 | flags, |
---|
| 805 | ppn + p ); |
---|
| 806 | } |
---|
[258] | 807 | } |
---|
[412] | 808 | } |
---|
| 809 | else if ( (local == 0) && (global != 0) ) // all clusters / all vspaces |
---|
| 810 | { |
---|
| 811 | for ( x = 0 ; x < X_SIZE ; x++ ) |
---|
[258] | 812 | { |
---|
[412] | 813 | for ( y = 0 ; y < Y_SIZE ; y++ ) |
---|
| 814 | { |
---|
| 815 | for ( v = 0 ; v < header->vspaces ; v++ ) |
---|
| 816 | { |
---|
| 817 | if ( big ) // big pages => PTE1s |
---|
| 818 | { |
---|
| 819 | boot_add_pte1( v, |
---|
| 820 | x, |
---|
| 821 | y, |
---|
| 822 | vpn + (p<<9), |
---|
| 823 | flags, |
---|
| 824 | ppn + (p<<9) ); |
---|
| 825 | } |
---|
| 826 | else // small pages -> PTE2s |
---|
| 827 | { |
---|
| 828 | boot_add_pte2( v, |
---|
| 829 | x, |
---|
| 830 | y, |
---|
| 831 | vpn + p, |
---|
| 832 | flags, |
---|
| 833 | ppn + p ); |
---|
| 834 | } |
---|
| 835 | } |
---|
| 836 | } |
---|
[258] | 837 | } |
---|
| 838 | } |
---|
[412] | 839 | } // end for pages |
---|
[427] | 840 | } // end boot_vseg_pte() |
---|
[258] | 841 | |
---|
[412] | 842 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 843 | // This function initialises the page tables for all vspaces defined |
---|
| 844 | // in the mapping_info data structure. |
---|
| 845 | // For each vspace, there is one page table per cluster. |
---|
| 846 | // In each cluster all page tables for the different vspaces must be |
---|
| 847 | // packed in one vseg occupying one single BPP (Big Physical Page). |
---|
[258] | 848 | // |
---|
[412] | 849 | // For each vseg, the mapping is done in two steps: |
---|
| 850 | // |
---|
| 851 | // A) mapping : the boot_vseg_map() function allocates contiguous BPPs |
---|
| 852 | // or SPPs (if the vseg is not associated to a peripheral), and register |
---|
| 853 | // the physical base address in the vseg pbase field. It initialises the |
---|
| 854 | // _ptabs_vaddr and _ptabs_paddr arrays if the vseg is a PTAB. |
---|
| 855 | // |
---|
[427] | 856 | // B) page table initialisation : the boot_vseg_pte() function initialise |
---|
[412] | 857 | // the PTEs (both PTE1 and PTE2) in one or several page tables: |
---|
| 858 | // - PTEs are replicated in all vspaces for a global vseg. |
---|
| 859 | // - PTEs are replicated in all clusters for a non local vseg. |
---|
| 860 | // |
---|
| 861 | // We must handle vsegs in the following order |
---|
| 862 | // 1) all global vsegs containing a page table, |
---|
| 863 | // 2) all global vsegs occupying more than one BPP, |
---|
| 864 | // 3) all others global vsegs |
---|
| 865 | // 4) all private vsegs in user space. |
---|
| 866 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 867 | void _ptabs_init() |
---|
[258] | 868 | { |
---|
[412] | 869 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 870 | mapping_vspace_t* vspace = _get_vspace_base(header); |
---|
| 871 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
| 872 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
[258] | 873 | |
---|
| 874 | unsigned int vspace_id; |
---|
| 875 | unsigned int vseg_id; |
---|
| 876 | |
---|
| 877 | if (header->vspaces == 0 ) |
---|
| 878 | { |
---|
[412] | 879 | _puts("\n[BOOT ERROR] in _ptabs_init() : mapping "); |
---|
[258] | 880 | _puts( header->name ); |
---|
| 881 | _puts(" contains no vspace\n"); |
---|
| 882 | _exit(); |
---|
| 883 | } |
---|
| 884 | |
---|
[412] | 885 | ///////// Phase 1 : global vsegs containing a PTAB (two loops required) |
---|
| 886 | |
---|
[258] | 887 | #if BOOT_DEBUG_PT |
---|
[412] | 888 | _puts("\n[BOOT DEBUG] map PTAB global vsegs\n"); |
---|
[258] | 889 | #endif |
---|
| 890 | |
---|
[412] | 891 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 892 | { |
---|
| 893 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 894 | if ( (vobj[vobj_id].type == VOBJ_TYPE_PTAB) ) |
---|
| 895 | { |
---|
[427] | 896 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 897 | vseg[vseg_id].mapped = 1; |
---|
| 898 | } |
---|
| 899 | } |
---|
[258] | 900 | |
---|
| 901 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 902 | { |
---|
[412] | 903 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 904 | if ( (vobj[vobj_id].type == VOBJ_TYPE_PTAB) ) |
---|
| 905 | { |
---|
[427] | 906 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 907 | vseg[vseg_id].mapped = 1; |
---|
| 908 | } |
---|
[258] | 909 | } |
---|
| 910 | |
---|
[412] | 911 | ///////// Phase 2 : global vsegs occupying more than one BPP (one loop) |
---|
| 912 | |
---|
| 913 | #if BOOT_DEBUG_PT |
---|
| 914 | _puts("\n[BOOT DEBUG] map all multi-BPP global vsegs\n"); |
---|
| 915 | #endif |
---|
| 916 | |
---|
[258] | 917 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 918 | { |
---|
[412] | 919 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 920 | if ( (vobj[vobj_id].length > 0x200000) && |
---|
| 921 | (vseg[vseg_id].mapped == 0) ) |
---|
| 922 | { |
---|
[427] | 923 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 924 | vseg[vseg_id].mapped = 1; |
---|
[427] | 925 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 926 | } |
---|
[258] | 927 | } |
---|
| 928 | |
---|
[412] | 929 | ///////// Phase 3 : all others global vsegs (one loop) |
---|
[347] | 930 | |
---|
[412] | 931 | #if BOOT_DEBUG_PT |
---|
| 932 | _puts("\n[BOOT DEBUG] map all others global vsegs\n"); |
---|
| 933 | #endif |
---|
| 934 | |
---|
| 935 | for (vseg_id = 0; vseg_id < header->globals; vseg_id++) |
---|
| 936 | { |
---|
| 937 | if ( vseg[vseg_id].mapped == 0 ) |
---|
| 938 | { |
---|
[427] | 939 | boot_vseg_map( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 940 | vseg[vseg_id].mapped = 1; |
---|
[427] | 941 | boot_vseg_pte( &vseg[vseg_id], 0xFFFFFFFF ); |
---|
[412] | 942 | } |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | ///////// Phase 4 : all private vsegs (two nested loops) |
---|
| 946 | |
---|
[258] | 947 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
| 948 | { |
---|
| 949 | |
---|
| 950 | #if BOOT_DEBUG_PT |
---|
[412] | 951 | _puts("\n[BOOT DEBUG] map private vsegs for vspace "); |
---|
| 952 | _puts( vspace[vspace_id].name ); |
---|
| 953 | _puts("\n"); |
---|
[258] | 954 | #endif |
---|
| 955 | |
---|
| 956 | for (vseg_id = vspace[vspace_id].vseg_offset; |
---|
| 957 | vseg_id < (vspace[vspace_id].vseg_offset + vspace[vspace_id].vsegs); |
---|
| 958 | vseg_id++) |
---|
| 959 | { |
---|
[427] | 960 | boot_vseg_map( &vseg[vseg_id], vspace_id ); |
---|
[412] | 961 | vseg[vseg_id].mapped = 1; |
---|
[427] | 962 | boot_vseg_pte( &vseg[vseg_id], vspace_id ); |
---|
[258] | 963 | } |
---|
| 964 | } |
---|
| 965 | |
---|
[412] | 966 | #if (BOOT_DEBUG_PT > 1) |
---|
[309] | 967 | mapping_vseg_t* curr; |
---|
| 968 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
| 969 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 970 | unsigned int pseg_id; |
---|
[258] | 971 | for( pseg_id = 0 ; pseg_id < header->psegs ; pseg_id++ ) |
---|
| 972 | { |
---|
[309] | 973 | unsigned int cluster_id = pseg[pseg_id].clusterid; |
---|
[412] | 974 | _puts("\n[BOOT DEBUG] vsegs mapped on pseg "); |
---|
[258] | 975 | _puts( pseg[pseg_id].name ); |
---|
[309] | 976 | _puts(" in cluster["); |
---|
| 977 | _putd( cluster[cluster_id].x ); |
---|
| 978 | _puts(","); |
---|
| 979 | _putd( cluster[cluster_id].y ); |
---|
[412] | 980 | _puts("]\n"); |
---|
[258] | 981 | for( curr = (mapping_vseg_t*)pseg[pseg_id].next_vseg ; |
---|
| 982 | curr != 0 ; |
---|
| 983 | curr = (mapping_vseg_t*)curr->next_vseg ) |
---|
| 984 | { |
---|
| 985 | _puts(" - vseg "); |
---|
| 986 | _puts( curr->name ); |
---|
| 987 | _puts(" : len = "); |
---|
| 988 | _putx( curr->length ); |
---|
| 989 | _puts(" / vbase "); |
---|
[295] | 990 | _putx( curr->vbase ); |
---|
[258] | 991 | _puts(" / pbase "); |
---|
| 992 | _putl( curr->pbase ); |
---|
| 993 | _puts("\n"); |
---|
| 994 | } |
---|
| 995 | } |
---|
| 996 | #endif |
---|
| 997 | |
---|
[412] | 998 | } // end boot_ptabs_init() |
---|
[258] | 999 | |
---|
| 1000 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 1001 | // This function initializes all private vobjs defined in the vspaces, |
---|
| 1002 | // such as mwmr channels, barriers and locks, because these vobjs |
---|
| 1003 | // are not known, and not initialized by the compiler. |
---|
| 1004 | // The MMU is supposed to be activated... |
---|
| 1005 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 1006 | void boot_vobjs_init() |
---|
| 1007 | { |
---|
[321] | 1008 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 1009 | mapping_vspace_t* vspace = _get_vspace_base(header); |
---|
| 1010 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
| 1011 | |
---|
| 1012 | unsigned int vspace_id; |
---|
| 1013 | unsigned int vobj_id; |
---|
| 1014 | |
---|
| 1015 | // loop on the vspaces |
---|
| 1016 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
| 1017 | { |
---|
| 1018 | |
---|
| 1019 | #if BOOT_DEBUG_VOBJS |
---|
| 1020 | _puts("\n[BOOT DEBUG] ****** vobjs initialisation in vspace "); |
---|
| 1021 | _puts(vspace[vspace_id].name); |
---|
| 1022 | _puts(" ******\n"); |
---|
| 1023 | #endif |
---|
| 1024 | |
---|
[347] | 1025 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][0][0] >> 13) ); |
---|
[258] | 1026 | |
---|
| 1027 | // loop on the vobjs |
---|
| 1028 | for (vobj_id = vspace[vspace_id].vobj_offset; |
---|
| 1029 | vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); |
---|
| 1030 | vobj_id++) |
---|
| 1031 | { |
---|
| 1032 | switch (vobj[vobj_id].type) |
---|
| 1033 | { |
---|
| 1034 | case VOBJ_TYPE_MWMR: // storage capacity is (vobj.length/4 - 5) words |
---|
| 1035 | { |
---|
[309] | 1036 | #if BOOT_DEBUG_VOBJS |
---|
| 1037 | _puts("MWMR : "); |
---|
| 1038 | _puts(vobj[vobj_id].name); |
---|
| 1039 | _puts(" / vaddr = "); |
---|
| 1040 | _putx(vobj[vobj_id].vaddr); |
---|
| 1041 | _puts(" / paddr = "); |
---|
| 1042 | _putl(vobj[vobj_id].paddr); |
---|
| 1043 | _puts(" / length = "); |
---|
| 1044 | _putx(vobj[vobj_id].length); |
---|
| 1045 | _puts("\n"); |
---|
| 1046 | #endif |
---|
[412] | 1047 | mwmr_channel_t* mwmr = (mwmr_channel_t *) (vobj[vobj_id].vbase); |
---|
[258] | 1048 | mwmr->ptw = 0; |
---|
| 1049 | mwmr->ptr = 0; |
---|
| 1050 | mwmr->sts = 0; |
---|
| 1051 | mwmr->width = vobj[vobj_id].init; |
---|
| 1052 | mwmr->depth = (vobj[vobj_id].length >> 2) - 6; |
---|
| 1053 | mwmr->lock = 0; |
---|
| 1054 | #if BOOT_DEBUG_VOBJS |
---|
[309] | 1055 | _puts(" fifo depth = "); |
---|
[258] | 1056 | _putd(mwmr->depth); |
---|
| 1057 | _puts(" / width = "); |
---|
| 1058 | _putd(mwmr->width); |
---|
| 1059 | _puts("\n"); |
---|
| 1060 | #endif |
---|
| 1061 | break; |
---|
| 1062 | } |
---|
| 1063 | case VOBJ_TYPE_ELF: // initialisation done by the loader |
---|
| 1064 | { |
---|
| 1065 | #if BOOT_DEBUG_VOBJS |
---|
| 1066 | _puts("ELF : "); |
---|
| 1067 | _puts(vobj[vobj_id].name); |
---|
[309] | 1068 | _puts(" / vaddr = "); |
---|
| 1069 | _putx(vobj[vobj_id].vaddr); |
---|
| 1070 | _puts(" / paddr = "); |
---|
| 1071 | _putl(vobj[vobj_id].paddr); |
---|
[258] | 1072 | _puts(" / length = "); |
---|
| 1073 | _putx(vobj[vobj_id].length); |
---|
| 1074 | _puts("\n"); |
---|
| 1075 | #endif |
---|
| 1076 | break; |
---|
| 1077 | } |
---|
| 1078 | case VOBJ_TYPE_BLOB: // initialisation done by the loader |
---|
| 1079 | { |
---|
| 1080 | #if BOOT_DEBUG_VOBJS |
---|
[309] | 1081 | _puts("BLOB : "); |
---|
[258] | 1082 | _puts(vobj[vobj_id].name); |
---|
[309] | 1083 | _puts(" / vaddr = "); |
---|
| 1084 | _putx(vobj[vobj_id].vaddr); |
---|
| 1085 | _puts(" / paddr = "); |
---|
| 1086 | _putl(vobj[vobj_id].paddr); |
---|
[258] | 1087 | _puts(" / length = "); |
---|
| 1088 | _putx(vobj[vobj_id].length); |
---|
| 1089 | _puts("\n"); |
---|
| 1090 | #endif |
---|
| 1091 | break; |
---|
| 1092 | } |
---|
| 1093 | case VOBJ_TYPE_BARRIER: // init is the number of participants |
---|
| 1094 | { |
---|
[309] | 1095 | #if BOOT_DEBUG_VOBJS |
---|
| 1096 | _puts("BARRIER : "); |
---|
| 1097 | _puts(vobj[vobj_id].name); |
---|
| 1098 | _puts(" / vaddr = "); |
---|
| 1099 | _putx(vobj[vobj_id].vaddr); |
---|
| 1100 | _puts(" / paddr = "); |
---|
| 1101 | _putl(vobj[vobj_id].paddr); |
---|
| 1102 | _puts(" / length = "); |
---|
| 1103 | _putx(vobj[vobj_id].length); |
---|
| 1104 | _puts("\n"); |
---|
| 1105 | #endif |
---|
[412] | 1106 | giet_barrier_t* barrier = (giet_barrier_t *) (vobj[vobj_id].vbase); |
---|
[369] | 1107 | barrier->count = vobj[vobj_id].init; |
---|
| 1108 | barrier->ntasks = vobj[vobj_id].init; |
---|
| 1109 | barrier->sense = 0; |
---|
[258] | 1110 | #if BOOT_DEBUG_VOBJS |
---|
[309] | 1111 | _puts(" init_value = "); |
---|
[258] | 1112 | _putd(barrier->init); |
---|
| 1113 | _puts("\n"); |
---|
| 1114 | #endif |
---|
| 1115 | break; |
---|
| 1116 | } |
---|
| 1117 | case VOBJ_TYPE_LOCK: // init value is "not taken" |
---|
| 1118 | { |
---|
| 1119 | #if BOOT_DEBUG_VOBJS |
---|
| 1120 | _puts("LOCK : "); |
---|
| 1121 | _puts(vobj[vobj_id].name); |
---|
[309] | 1122 | _puts(" / vaddr = "); |
---|
| 1123 | _putx(vobj[vobj_id].vaddr); |
---|
| 1124 | _puts(" / paddr = "); |
---|
| 1125 | _putl(vobj[vobj_id].paddr); |
---|
| 1126 | _puts(" / length = "); |
---|
| 1127 | _putx(vobj[vobj_id].length); |
---|
[258] | 1128 | _puts("\n"); |
---|
| 1129 | #endif |
---|
[412] | 1130 | unsigned int* lock = (unsigned int *) (vobj[vobj_id].vbase); |
---|
[309] | 1131 | *lock = 0; |
---|
[258] | 1132 | break; |
---|
| 1133 | } |
---|
| 1134 | case VOBJ_TYPE_BUFFER: // nothing to initialise |
---|
| 1135 | { |
---|
| 1136 | #if BOOT_DEBUG_VOBJS |
---|
| 1137 | _puts("BUFFER : "); |
---|
| 1138 | _puts(vobj[vobj_id].name); |
---|
[309] | 1139 | _puts(" / vaddr = "); |
---|
| 1140 | _putx(vobj[vobj_id].vaddr); |
---|
[258] | 1141 | _puts(" / paddr = "); |
---|
| 1142 | _putl(vobj[vobj_id].paddr); |
---|
| 1143 | _puts(" / length = "); |
---|
| 1144 | _putx(vobj[vobj_id].length); |
---|
| 1145 | _puts("\n"); |
---|
| 1146 | #endif |
---|
| 1147 | break; |
---|
| 1148 | } |
---|
| 1149 | case VOBJ_TYPE_MEMSPACE: |
---|
| 1150 | { |
---|
| 1151 | #if BOOT_DEBUG_VOBJS |
---|
| 1152 | _puts("MEMSPACE : "); |
---|
| 1153 | _puts(vobj[vobj_id].name); |
---|
| 1154 | _puts(" / vaddr = "); |
---|
| 1155 | _putx(vobj[vobj_id].vaddr); |
---|
[309] | 1156 | _puts(" / paddr = "); |
---|
| 1157 | _putl(vobj[vobj_id].paddr); |
---|
[258] | 1158 | _puts(" / length = "); |
---|
| 1159 | _putx(vobj[vobj_id].length); |
---|
[309] | 1160 | _puts("\n"); |
---|
| 1161 | #endif |
---|
[412] | 1162 | giet_memspace_t* memspace = (giet_memspace_t *) vobj[vobj_id].vbase; |
---|
| 1163 | memspace->buffer = (void *) vobj[vobj_id].vbase + 8; |
---|
[309] | 1164 | memspace->size = vobj[vobj_id].length - 8; |
---|
| 1165 | #if BOOT_DEBUG_VOBJS |
---|
| 1166 | _puts(" buffer vbase = "); |
---|
[258] | 1167 | _putx((unsigned int)memspace->buffer); |
---|
| 1168 | _puts(" / size = "); |
---|
| 1169 | _putx(memspace->size); |
---|
| 1170 | _puts("\n"); |
---|
| 1171 | #endif |
---|
| 1172 | break; |
---|
| 1173 | } |
---|
| 1174 | case VOBJ_TYPE_CONST: |
---|
| 1175 | { |
---|
| 1176 | #if BOOT_DEBUG_VOBJS |
---|
| 1177 | _puts("CONST : "); |
---|
| 1178 | _puts(vobj[vobj_id].name); |
---|
[309] | 1179 | _puts(" / vaddr = "); |
---|
| 1180 | _putx(vobj[vobj_id].vaddr); |
---|
| 1181 | _puts(" / paddr = "); |
---|
[258] | 1182 | _putl(vobj[vobj_id].paddr); |
---|
[309] | 1183 | _puts(" / length = "); |
---|
| 1184 | _putx(vobj[vobj_id].length); |
---|
[258] | 1185 | _puts(" / init = "); |
---|
[309] | 1186 | _putx(vobj[vobj_id].init); |
---|
| 1187 | _puts("\n"); |
---|
| 1188 | #endif |
---|
[412] | 1189 | unsigned int* addr = (unsigned int *) vobj[vobj_id].vbase; |
---|
[309] | 1190 | *addr = vobj[vobj_id].init; |
---|
| 1191 | |
---|
| 1192 | #if BOOT_DEBUG_VOBJS |
---|
| 1193 | _puts(" init = "); |
---|
[258] | 1194 | _putx(*addr); |
---|
| 1195 | _puts("\n"); |
---|
| 1196 | #endif |
---|
| 1197 | break; |
---|
| 1198 | } |
---|
| 1199 | default: |
---|
| 1200 | { |
---|
[412] | 1201 | _puts("\n[BOOT ERROR] in boot_vobjs_init() : Illegal vobj type "); |
---|
| 1202 | _putd( vobj[vobj_id].type ); |
---|
| 1203 | _puts(" in vspace "); |
---|
| 1204 | _puts( vspace[vspace_id].name ); |
---|
[258] | 1205 | _puts("\n"); |
---|
| 1206 | _exit(); |
---|
| 1207 | } |
---|
| 1208 | } // end switch type |
---|
[412] | 1209 | } // end loop on vobjs |
---|
| 1210 | } // end loop on vspaces |
---|
[258] | 1211 | } // end boot_vobjs_init() |
---|
| 1212 | |
---|
| 1213 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 1214 | // This function returns in the vbase and length buffers the virtual base |
---|
| 1215 | // address and the length of the segment allocated to the schedulers array |
---|
| 1216 | // in the cluster defined by the clusterid argument. |
---|
| 1217 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 1218 | void boot_get_sched_vaddr( unsigned int cluster_id, |
---|
| 1219 | unsigned int* vbase, |
---|
| 1220 | unsigned int* length ) |
---|
| 1221 | { |
---|
[321] | 1222 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 1223 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
| 1224 | mapping_vseg_t* vseg = _get_vseg_base(header); |
---|
| 1225 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
| 1226 | |
---|
| 1227 | unsigned int vseg_id; |
---|
| 1228 | unsigned int found = 0; |
---|
| 1229 | |
---|
| 1230 | for ( vseg_id = 0 ; (vseg_id < header->vsegs) && (found == 0) ; vseg_id++ ) |
---|
| 1231 | { |
---|
| 1232 | if ( (vobj[vseg[vseg_id].vobj_offset].type == VOBJ_TYPE_SCHED) && |
---|
[263] | 1233 | (pseg[vseg[vseg_id].psegid].clusterid == cluster_id ) ) |
---|
[258] | 1234 | { |
---|
| 1235 | *vbase = vseg[vseg_id].vbase; |
---|
| 1236 | *length = vobj[vseg[vseg_id].vobj_offset].length; |
---|
| 1237 | found = 1; |
---|
| 1238 | } |
---|
| 1239 | } |
---|
| 1240 | if ( found == 0 ) |
---|
| 1241 | { |
---|
[263] | 1242 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 1243 | _puts("\n[BOOT ERROR] No vobj of type SCHED in cluster ["); |
---|
| 1244 | _putd( cluster[cluster_id].x ); |
---|
| 1245 | _puts(","); |
---|
| 1246 | _putd( cluster[cluster_id].y ); |
---|
| 1247 | _puts("]\n"); |
---|
[258] | 1248 | _exit(); |
---|
| 1249 | } |
---|
| 1250 | } // end boot_get_sched_vaddr() |
---|
| 1251 | |
---|
| 1252 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 1253 | // This function initialises all processors schedulers. |
---|
| 1254 | // This is done by processor 0, and the MMU must be activated. |
---|
[412] | 1255 | // - In Step 1, it initialises the _schedulers[x][y][l] pointers array, and scan |
---|
| 1256 | // the processors for a first initialisation of the schedulers: |
---|
| 1257 | // idle_task context, and HWI / SWI / PTI vectors. |
---|
[321] | 1258 | // - In Step 2, it scan all tasks in all vspaces to complete the tasks contexts, |
---|
| 1259 | // initialisation as specified in the mapping_info data structure. |
---|
[258] | 1260 | //////////////////////////////////////////////////////////////////////////////////// |
---|
| 1261 | void boot_schedulers_init() |
---|
| 1262 | { |
---|
[321] | 1263 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 1264 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 1265 | mapping_vspace_t* vspace = _get_vspace_base(header); |
---|
| 1266 | mapping_task_t* task = _get_task_base(header); |
---|
| 1267 | mapping_vobj_t* vobj = _get_vobj_base(header); |
---|
[295] | 1268 | mapping_periph_t* periph = _get_periph_base(header); |
---|
[258] | 1269 | mapping_irq_t* irq = _get_irq_base(header); |
---|
| 1270 | |
---|
| 1271 | unsigned int cluster_id; // cluster index in mapping_info |
---|
[295] | 1272 | unsigned int periph_id; // peripheral index in mapping_info |
---|
[258] | 1273 | unsigned int irq_id; // irq index in mapping_info |
---|
| 1274 | unsigned int vspace_id; // vspace index in mapping_info |
---|
| 1275 | unsigned int task_id; // task index in mapping_info |
---|
[321] | 1276 | unsigned int vobj_id; // vobj index in mapping_info |
---|
[258] | 1277 | |
---|
[321] | 1278 | unsigned int lpid; // local processor index (for several loops) |
---|
| 1279 | |
---|
| 1280 | // TTY, NIC, CMA, HBA, user timer, and WTI channel allocators to user tasks: |
---|
[258] | 1281 | // - TTY[0] is reserved for the kernel |
---|
| 1282 | // - In all clusters the first NB_PROCS_MAX timers |
---|
| 1283 | // are reserved for the kernel (context switch) |
---|
[321] | 1284 | unsigned int alloc_tty_channel = 1; // global |
---|
| 1285 | unsigned int alloc_nic_channel = 0; // global |
---|
| 1286 | unsigned int alloc_cma_channel = 0; // global |
---|
| 1287 | unsigned int alloc_hba_channel = 0; // global |
---|
| 1288 | unsigned int alloc_tim_channel[X_SIZE*Y_SIZE]; // one per cluster |
---|
[258] | 1289 | |
---|
[321] | 1290 | // WTI allocators to processors |
---|
| 1291 | // In all clusters, first NB_PROCS_MAX WTIs are for WAKUP |
---|
| 1292 | unsigned int alloc_wti_channel[X_SIZE*Y_SIZE]; // one per cluster |
---|
[258] | 1293 | |
---|
[321] | 1294 | // pointers on the XCU and PIC peripherals |
---|
| 1295 | mapping_periph_t* xcu = NULL; |
---|
| 1296 | mapping_periph_t* pic = NULL; |
---|
| 1297 | |
---|
[412] | 1298 | unsigned int sched_vbase; // schedulers array vbase address in a cluster |
---|
| 1299 | unsigned int sched_length; // schedulers array length |
---|
| 1300 | static_scheduler_t* psched; // pointer on processor scheduler |
---|
[321] | 1301 | |
---|
[258] | 1302 | ///////////////////////////////////////////////////////////////////////// |
---|
| 1303 | // Step 1 : loop on the clusters and on the processors |
---|
| 1304 | // to initialize the schedulers[] array of pointers, |
---|
[412] | 1305 | // idle task context and interrupt vectors. |
---|
[258] | 1306 | // Implementation note: |
---|
[347] | 1307 | // We need to use both (proc_id) to scan the mapping info structure, |
---|
| 1308 | // and (x,y,lpid) to access the schedulers array. |
---|
[258] | 1309 | |
---|
[263] | 1310 | for (cluster_id = 0 ; cluster_id < X_SIZE*Y_SIZE ; cluster_id++) |
---|
[258] | 1311 | { |
---|
[263] | 1312 | unsigned int x = cluster[cluster_id].x; |
---|
| 1313 | unsigned int y = cluster[cluster_id].y; |
---|
[258] | 1314 | |
---|
| 1315 | #if BOOT_DEBUG_SCHED |
---|
[263] | 1316 | _puts("\n[BOOT DEBUG] Initialise schedulers in cluster["); |
---|
| 1317 | _putd( x ); |
---|
| 1318 | _puts(","); |
---|
| 1319 | _putd( y ); |
---|
| 1320 | _puts("]\n"); |
---|
[258] | 1321 | #endif |
---|
| 1322 | alloc_tim_channel[cluster_id] = NB_PROCS_MAX; |
---|
[321] | 1323 | alloc_wti_channel[cluster_id] = NB_PROCS_MAX; |
---|
[258] | 1324 | |
---|
| 1325 | // checking processors number |
---|
[295] | 1326 | if ( cluster[cluster_id].procs > NB_PROCS_MAX ) |
---|
[258] | 1327 | { |
---|
[263] | 1328 | _puts("\n[BOOT ERROR] Too much processors in cluster["); |
---|
| 1329 | _putd( x ); |
---|
| 1330 | _puts(","); |
---|
| 1331 | _putd( y ); |
---|
| 1332 | _puts("]\n"); |
---|
[258] | 1333 | _exit(); |
---|
| 1334 | } |
---|
| 1335 | |
---|
[295] | 1336 | // no schedulers initialisation if nprocs == 0 |
---|
| 1337 | if ( cluster[cluster_id].procs > 0 ) |
---|
[258] | 1338 | { |
---|
[412] | 1339 | // get scheduler array virtual base address in cluster[cluster_id] |
---|
[295] | 1340 | boot_get_sched_vaddr( cluster_id, &sched_vbase, &sched_length ); |
---|
[258] | 1341 | |
---|
[412] | 1342 | if ( sched_length < (cluster[cluster_id].procs<<13) ) // 8 Kbytes per scheduler |
---|
[295] | 1343 | { |
---|
| 1344 | _puts("\n[BOOT ERROR] Schedulers segment too small in cluster["); |
---|
| 1345 | _putd( x ); |
---|
| 1346 | _puts(","); |
---|
| 1347 | _putd( y ); |
---|
| 1348 | _puts("]\n"); |
---|
| 1349 | _exit(); |
---|
| 1350 | } |
---|
[263] | 1351 | |
---|
[321] | 1352 | // scan peripherals to find the ICU/XCU and the PIC component |
---|
| 1353 | |
---|
| 1354 | xcu = NULL; |
---|
[295] | 1355 | for ( periph_id = cluster[cluster_id].periph_offset ; |
---|
| 1356 | periph_id < cluster[cluster_id].periph_offset + cluster[cluster_id].periphs; |
---|
| 1357 | periph_id++ ) |
---|
| 1358 | { |
---|
| 1359 | if( (periph[periph_id].type == PERIPH_TYPE_XCU) || |
---|
| 1360 | (periph[periph_id].type == PERIPH_TYPE_ICU) ) |
---|
| 1361 | { |
---|
[321] | 1362 | xcu = &periph[periph_id]; |
---|
| 1363 | |
---|
| 1364 | if ( xcu->arg < cluster[cluster_id].procs ) |
---|
| 1365 | { |
---|
| 1366 | _puts("\n[BOOT ERROR] Not enough inputs for XCU["); |
---|
| 1367 | _putd( x ); |
---|
| 1368 | _puts(","); |
---|
| 1369 | _putd( y ); |
---|
| 1370 | _puts("]\n"); |
---|
| 1371 | _exit(); |
---|
| 1372 | } |
---|
[295] | 1373 | } |
---|
[321] | 1374 | if( periph[periph_id].type == PERIPH_TYPE_PIC ) |
---|
| 1375 | { |
---|
| 1376 | pic = &periph[periph_id]; |
---|
| 1377 | } |
---|
[295] | 1378 | } |
---|
[321] | 1379 | if ( xcu == NULL ) |
---|
[295] | 1380 | { |
---|
| 1381 | _puts("\n[BOOT ERROR] No ICU / XCU component in cluster["); |
---|
| 1382 | _putd( x ); |
---|
| 1383 | _puts(","); |
---|
| 1384 | _putd( y ); |
---|
| 1385 | _puts("]\n"); |
---|
| 1386 | _exit(); |
---|
| 1387 | } |
---|
| 1388 | |
---|
[412] | 1389 | // loop on processors for schedulers default values |
---|
[321] | 1390 | // initialisation, including WTI and PTI vectors |
---|
[295] | 1391 | for ( lpid = 0 ; lpid < cluster[cluster_id].procs ; lpid++ ) |
---|
| 1392 | { |
---|
[412] | 1393 | // pointer on processor scheduler |
---|
| 1394 | psched = (static_scheduler_t*)(sched_vbase + (lpid<<13)); |
---|
[295] | 1395 | |
---|
[412] | 1396 | // initialise the schedulers pointers array |
---|
| 1397 | _schedulers[x][y][lpid] = psched; |
---|
| 1398 | |
---|
[258] | 1399 | #if BOOT_DEBUG_SCHED |
---|
[412] | 1400 | unsigned int sched_vbase = (unsigned int)_schedulers[x][y][lpid]; |
---|
| 1401 | unsigned int sched_ppn; |
---|
| 1402 | unsigned int sched_flags; |
---|
| 1403 | paddr_t sched_pbase; |
---|
| 1404 | |
---|
| 1405 | page_table_t* ptab = (page_table_t*)(_ptabs_vaddr[0][x][y]); |
---|
| 1406 | _v2p_translate( ptab, sched_vbase>>12, &sched_ppn, &sched_flags ); |
---|
| 1407 | sched_pbase = ((paddr_t)sched_ppn)<<12; |
---|
| 1408 | |
---|
[295] | 1409 | _puts("\nProc["); |
---|
[263] | 1410 | _putd( x ); |
---|
[295] | 1411 | _puts(","); |
---|
[263] | 1412 | _putd( y ); |
---|
[295] | 1413 | _puts(","); |
---|
[263] | 1414 | _putd( lpid ); |
---|
[412] | 1415 | _puts("] : scheduler vbase = "); |
---|
| 1416 | _putx( sched_vbase ); |
---|
| 1417 | _puts(" : scheduler pbase = "); |
---|
| 1418 | _putl( sched_pbase ); |
---|
[258] | 1419 | _puts("\n"); |
---|
| 1420 | #endif |
---|
[295] | 1421 | // initialise the "tasks" and "current" variables default values |
---|
[412] | 1422 | psched->tasks = 0; |
---|
| 1423 | psched->current = IDLE_TASK_INDEX; |
---|
[258] | 1424 | |
---|
[321] | 1425 | // default values for HWI / PTI / SWI vectors (valid bit = 0) |
---|
[295] | 1426 | unsigned int slot; |
---|
| 1427 | for (slot = 0; slot < 32; slot++) |
---|
| 1428 | { |
---|
[412] | 1429 | psched->hwi_vector[slot] = 0; |
---|
| 1430 | psched->pti_vector[slot] = 0; |
---|
| 1431 | psched->wti_vector[slot] = 0; |
---|
[295] | 1432 | } |
---|
[258] | 1433 | |
---|
[321] | 1434 | // WTI[lpid] <= ISR_WAKUP / PTI[lpid] <= ISR_TICK |
---|
[412] | 1435 | psched->wti_vector[lpid] = ISR_WAKUP | 0x80000000; |
---|
| 1436 | psched->pti_vector[lpid] = ISR_TICK | 0x80000000; |
---|
[321] | 1437 | |
---|
[295] | 1438 | // initializes the idle_task context in scheduler: |
---|
| 1439 | // - the SR slot is 0xFF03 because this task run in kernel mode. |
---|
| 1440 | // - it uses the page table of vspace[0] |
---|
| 1441 | // - it uses the kernel TTY terminal |
---|
[392] | 1442 | // - slots containing addresses (SP, RA, EPC) |
---|
| 1443 | // must be initialised by kernel_init() |
---|
[258] | 1444 | |
---|
[412] | 1445 | psched->context[IDLE_TASK_INDEX][CTX_CR_ID] = 0; |
---|
| 1446 | psched->context[IDLE_TASK_INDEX][CTX_SR_ID] = 0xFF03; |
---|
| 1447 | psched->context[IDLE_TASK_INDEX][CTX_PTPR_ID] = _ptabs_paddr[0][x][y]>>13; |
---|
| 1448 | psched->context[IDLE_TASK_INDEX][CTX_PTAB_ID] = _ptabs_vaddr[0][x][y]; |
---|
| 1449 | psched->context[IDLE_TASK_INDEX][CTX_TTY_ID] = 0; |
---|
| 1450 | psched->context[IDLE_TASK_INDEX][CTX_LTID_ID] = IDLE_TASK_INDEX; |
---|
| 1451 | psched->context[IDLE_TASK_INDEX][CTX_VSID_ID] = 0; |
---|
| 1452 | psched->context[IDLE_TASK_INDEX][CTX_RUN_ID] = 1; |
---|
| 1453 | |
---|
[321] | 1454 | } // end for processors |
---|
[258] | 1455 | |
---|
[321] | 1456 | // scan HWIs connected to local XCU |
---|
| 1457 | // for round-robin allocation to processors |
---|
| 1458 | lpid = 0; |
---|
| 1459 | for ( irq_id = xcu->irq_offset ; |
---|
| 1460 | irq_id < xcu->irq_offset + xcu->irqs ; |
---|
[295] | 1461 | irq_id++ ) |
---|
[258] | 1462 | { |
---|
[321] | 1463 | unsigned int type = irq[irq_id].srctype; |
---|
| 1464 | unsigned int srcid = irq[irq_id].srcid; |
---|
| 1465 | unsigned int isr = irq[irq_id].isr & 0xFFFF; |
---|
| 1466 | unsigned int channel = irq[irq_id].channel << 16; |
---|
| 1467 | |
---|
| 1468 | if ( (type != IRQ_TYPE_HWI) || (srcid > 31) ) |
---|
[295] | 1469 | { |
---|
[321] | 1470 | _puts("\n[BOOT ERROR] Bad IRQ in XCU of cluster["); |
---|
[295] | 1471 | _putd( x ); |
---|
| 1472 | _puts(","); |
---|
| 1473 | _putd( y ); |
---|
| 1474 | _puts("]\n"); |
---|
| 1475 | _exit(); |
---|
| 1476 | } |
---|
[258] | 1477 | |
---|
[412] | 1478 | _schedulers[x][y][lpid]->hwi_vector[srcid] = isr | channel | 0x80000000; |
---|
[321] | 1479 | lpid = (lpid + 1) % cluster[cluster_id].procs; |
---|
[258] | 1480 | |
---|
[321] | 1481 | } // end for irqs |
---|
| 1482 | } // end if nprocs > 0 |
---|
| 1483 | } // end for clusters |
---|
[258] | 1484 | |
---|
[321] | 1485 | // If there is an external PIC component, we scan HWIs connected to PIC |
---|
| 1486 | // for Round Robin allocation (as WTI) to processors. |
---|
| 1487 | // We allocate one WTI per processor, starting from proc[0,0,0], |
---|
| 1488 | // and we increment (cluster_id, lpid) as required. |
---|
| 1489 | if ( pic != NULL ) |
---|
| 1490 | { |
---|
| 1491 | unsigned int cluster_id = 0; // index in clusters array |
---|
| 1492 | unsigned int lpid = 0; // processor local index |
---|
| 1493 | |
---|
| 1494 | // scan IRQS defined in PIC |
---|
| 1495 | for ( irq_id = pic->irq_offset ; |
---|
| 1496 | irq_id < pic->irq_offset + pic->irqs ; |
---|
| 1497 | irq_id++ ) |
---|
| 1498 | { |
---|
| 1499 | // compute next values for (cluster_id,lpid) |
---|
| 1500 | // if no more procesor available in current cluster |
---|
| 1501 | unsigned int overflow = 0; |
---|
| 1502 | while ( (lpid >= cluster[cluster_id].procs) || |
---|
| 1503 | (alloc_wti_channel[cluster_id] >= xcu->arg) ) |
---|
| 1504 | { |
---|
| 1505 | overflow++; |
---|
| 1506 | cluster_id = (cluster_id + 1) % (X_SIZE*Y_SIZE); |
---|
| 1507 | lpid = 0; |
---|
| 1508 | |
---|
| 1509 | // overflow detection |
---|
| 1510 | if ( overflow > (X_SIZE*Y_SIZE*NB_PROCS_MAX*32) ) |
---|
| 1511 | { |
---|
| 1512 | _puts("\n[BOOT ERROR] Not enough processors for external IRQs\n"); |
---|
| 1513 | _exit(); |
---|
| 1514 | } |
---|
| 1515 | } |
---|
| 1516 | |
---|
| 1517 | unsigned int type = irq[irq_id].srctype; |
---|
| 1518 | unsigned int srcid = irq[irq_id].srcid; |
---|
| 1519 | unsigned int isr = irq[irq_id].isr & 0xFFFF; |
---|
| 1520 | unsigned int channel = irq[irq_id].channel << 16; |
---|
| 1521 | |
---|
| 1522 | if ( (type != IRQ_TYPE_HWI) || (srcid > 31) ) |
---|
| 1523 | { |
---|
| 1524 | _puts("\n[BOOT ERROR] Bad IRQ in PIC component\n"); |
---|
| 1525 | _exit(); |
---|
| 1526 | } |
---|
| 1527 | |
---|
| 1528 | // get scheduler[cluster_id] address |
---|
| 1529 | unsigned int x = cluster[cluster_id].x; |
---|
| 1530 | unsigned int y = cluster[cluster_id].y; |
---|
| 1531 | unsigned int cluster_xy = (x<<Y_WIDTH) + y; |
---|
[412] | 1532 | psched = _schedulers[x][y][lpid]; |
---|
[321] | 1533 | |
---|
| 1534 | // update WTI vector for scheduler[cluster_id][lpid] |
---|
[412] | 1535 | unsigned int index = alloc_wti_channel[cluster_id]; |
---|
| 1536 | psched->wti_vector[index] = isr | channel | 0x80000000; |
---|
[321] | 1537 | alloc_wti_channel[cluster_id] = index + 1; |
---|
[412] | 1538 | lpid = lpid + 1; |
---|
[321] | 1539 | |
---|
| 1540 | // update IRQ fields in mapping for PIC initialisation |
---|
| 1541 | irq[irq_id].dest_id = index; |
---|
| 1542 | irq[irq_id].dest_xy = cluster_xy; |
---|
| 1543 | |
---|
| 1544 | } // end for IRQs |
---|
| 1545 | } // end if PIC |
---|
| 1546 | |
---|
[258] | 1547 | #if BOOT_DEBUG_SCHED |
---|
[321] | 1548 | for ( cluster_id = 0 ; cluster_id < (X_SIZE*Y_SIZE) ; cluster_id++ ) |
---|
| 1549 | { |
---|
| 1550 | unsigned int x = cluster[cluster_id].x; |
---|
| 1551 | unsigned int y = cluster[cluster_id].y; |
---|
| 1552 | unsigned int slot; |
---|
| 1553 | unsigned int entry; |
---|
| 1554 | for ( lpid = 0 ; lpid < cluster[cluster_id].procs ; lpid++ ) |
---|
| 1555 | { |
---|
[412] | 1556 | psched = _schedulers[x][y][lpid]; |
---|
| 1557 | |
---|
[321] | 1558 | _puts("\n*** IRQS for proc["); |
---|
| 1559 | _putd( x ); |
---|
| 1560 | _puts(","); |
---|
| 1561 | _putd( y ); |
---|
[329] | 1562 | _puts(","); |
---|
[321] | 1563 | _putd( lpid ); |
---|
| 1564 | _puts("]\n"); |
---|
| 1565 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
| 1566 | { |
---|
[412] | 1567 | entry = psched->hwi_vector[slot]; |
---|
[321] | 1568 | if ( entry & 0x80000000 ) |
---|
| 1569 | { |
---|
| 1570 | _puts(" - HWI "); |
---|
| 1571 | _putd( slot ); |
---|
| 1572 | _puts(" / isrtype = "); |
---|
| 1573 | _putd( entry & 0xFFFF ); |
---|
| 1574 | _puts(" / channel = "); |
---|
| 1575 | _putd( (entry >> 16) & 0x7FFF ); |
---|
| 1576 | _puts("\n"); |
---|
| 1577 | } |
---|
| 1578 | } |
---|
| 1579 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
| 1580 | { |
---|
[412] | 1581 | entry = psched->wti_vector[slot]; |
---|
[321] | 1582 | if ( entry & 0x80000000 ) |
---|
| 1583 | { |
---|
| 1584 | _puts(" - WTI "); |
---|
| 1585 | _putd( slot ); |
---|
| 1586 | _puts(" / isrtype = "); |
---|
| 1587 | _putd( entry & 0xFFFF ); |
---|
| 1588 | _puts(" / channel = "); |
---|
| 1589 | _putd( (entry >> 16) & 0x7FFF ); |
---|
| 1590 | _puts("\n"); |
---|
| 1591 | } |
---|
| 1592 | } |
---|
| 1593 | for ( slot = 0 ; slot < 32 ; slot++ ) |
---|
| 1594 | { |
---|
[412] | 1595 | entry = psched->pti_vector[slot]; |
---|
[321] | 1596 | if ( entry & 0x80000000 ) |
---|
| 1597 | { |
---|
| 1598 | _puts(" - PTI "); |
---|
| 1599 | _putd( slot ); |
---|
| 1600 | _puts(" / isrtype = "); |
---|
| 1601 | _putd( entry & 0xFFFF ); |
---|
| 1602 | _puts(" / channel = "); |
---|
| 1603 | _putd( (entry >> 16) & 0x7FFF ); |
---|
| 1604 | _puts("\n"); |
---|
| 1605 | } |
---|
| 1606 | } |
---|
| 1607 | } |
---|
| 1608 | } |
---|
[258] | 1609 | #endif |
---|
| 1610 | |
---|
| 1611 | /////////////////////////////////////////////////////////////////// |
---|
[295] | 1612 | // Step 2 : loop on the vspaces and the tasks to complete |
---|
| 1613 | // the schedulers and task contexts initialisation. |
---|
[258] | 1614 | |
---|
| 1615 | for (vspace_id = 0; vspace_id < header->vspaces; vspace_id++) |
---|
| 1616 | { |
---|
| 1617 | // We must set the PTPR depending on the vspace, because the start_vector |
---|
| 1618 | // and the stack address are defined in virtual space. |
---|
[347] | 1619 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[vspace_id][0][0] >> 13) ); |
---|
[258] | 1620 | |
---|
[412] | 1621 | // loop on the tasks in vspace (task_id is the global index in mapping) |
---|
[258] | 1622 | for (task_id = vspace[vspace_id].task_offset; |
---|
| 1623 | task_id < (vspace[vspace_id].task_offset + vspace[vspace_id].tasks); |
---|
| 1624 | task_id++) |
---|
| 1625 | { |
---|
[295] | 1626 | // compute the cluster coordinates & local processor index |
---|
[263] | 1627 | unsigned int x = cluster[task[task_id].clusterid].x; |
---|
| 1628 | unsigned int y = cluster[task[task_id].clusterid].y; |
---|
| 1629 | unsigned int cluster_xy = (x<<Y_WIDTH) + y; |
---|
[295] | 1630 | unsigned int lpid = task[task_id].proclocid; |
---|
[263] | 1631 | |
---|
[258] | 1632 | #if BOOT_DEBUG_SCHED |
---|
| 1633 | _puts("\n[BOOT DEBUG] Initialise context for task "); |
---|
| 1634 | _puts( task[task_id].name ); |
---|
| 1635 | _puts(" in vspace "); |
---|
| 1636 | _puts( vspace[vspace_id].name ); |
---|
[309] | 1637 | _puts("\n"); |
---|
[258] | 1638 | #endif |
---|
| 1639 | // compute gpid (global processor index) and scheduler base address |
---|
[427] | 1640 | unsigned int gpid = (cluster_xy << P_WIDTH) + lpid; |
---|
[347] | 1641 | psched = _schedulers[x][y][lpid]; |
---|
[258] | 1642 | |
---|
| 1643 | // ctx_sr : value required before an eret instruction |
---|
| 1644 | unsigned int ctx_sr = 0x0000FF13; |
---|
| 1645 | |
---|
| 1646 | // ctx_ptpr : page table physical base address (shifted by 13 bit) |
---|
[347] | 1647 | unsigned int ctx_ptpr = (unsigned int)(_ptabs_paddr[vspace_id][x][y] >> 13); |
---|
[258] | 1648 | |
---|
| 1649 | // ctx_ptab : page_table virtual base address |
---|
[412] | 1650 | unsigned int ctx_ptab = _ptabs_vaddr[vspace_id][x][y]; |
---|
[258] | 1651 | |
---|
| 1652 | // ctx_tty : TTY terminal global index provided by the global allocator |
---|
[295] | 1653 | // Each user terminal is a private ressource: the number of |
---|
| 1654 | // requested terminal cannot be larger than NB_TTY_CHANNELS. |
---|
[258] | 1655 | unsigned int ctx_tty = 0xFFFFFFFF; |
---|
| 1656 | if (task[task_id].use_tty) |
---|
| 1657 | { |
---|
| 1658 | if (alloc_tty_channel >= NB_TTY_CHANNELS) |
---|
| 1659 | { |
---|
[295] | 1660 | _puts("\n[BOOT ERROR] TTY channel index too large for task "); |
---|
[258] | 1661 | _puts(task[task_id].name); |
---|
| 1662 | _puts(" in vspace "); |
---|
| 1663 | _puts(vspace[vspace_id].name); |
---|
| 1664 | _puts("\n"); |
---|
| 1665 | _exit(); |
---|
| 1666 | } |
---|
| 1667 | ctx_tty = alloc_tty_channel; |
---|
[295] | 1668 | alloc_tty_channel++; |
---|
| 1669 | } |
---|
| 1670 | |
---|
[258] | 1671 | // ctx_nic : NIC channel global index provided by the global allocator |
---|
[295] | 1672 | // Each channel is a private ressource: the number of |
---|
| 1673 | // requested channels cannot be larger than NB_NIC_CHANNELS. |
---|
[258] | 1674 | unsigned int ctx_nic = 0xFFFFFFFF; |
---|
| 1675 | if (task[task_id].use_nic) |
---|
| 1676 | { |
---|
| 1677 | if (alloc_nic_channel >= NB_NIC_CHANNELS) |
---|
| 1678 | { |
---|
| 1679 | _puts("\n[BOOT ERROR] NIC channel index too large for task "); |
---|
| 1680 | _puts(task[task_id].name); |
---|
| 1681 | _puts(" in vspace "); |
---|
| 1682 | _puts(vspace[vspace_id].name); |
---|
| 1683 | _puts("\n"); |
---|
| 1684 | _exit(); |
---|
| 1685 | } |
---|
| 1686 | ctx_nic = alloc_nic_channel; |
---|
| 1687 | alloc_nic_channel++; |
---|
| 1688 | } |
---|
[295] | 1689 | |
---|
[258] | 1690 | // ctx_cma : CMA channel global index provided by the global allocator |
---|
[295] | 1691 | // Each channel is a private ressource: the number of |
---|
| 1692 | // requested channels cannot be larger than NB_NIC_CHANNELS. |
---|
[258] | 1693 | unsigned int ctx_cma = 0xFFFFFFFF; |
---|
| 1694 | if (task[task_id].use_cma) |
---|
| 1695 | { |
---|
| 1696 | if (alloc_cma_channel >= NB_CMA_CHANNELS) |
---|
| 1697 | { |
---|
| 1698 | _puts("\n[BOOT ERROR] CMA channel index too large for task "); |
---|
| 1699 | _puts(task[task_id].name); |
---|
| 1700 | _puts(" in vspace "); |
---|
| 1701 | _puts(vspace[vspace_id].name); |
---|
| 1702 | _puts("\n"); |
---|
| 1703 | _exit(); |
---|
| 1704 | } |
---|
| 1705 | ctx_cma = alloc_cma_channel; |
---|
| 1706 | alloc_cma_channel++; |
---|
| 1707 | } |
---|
[295] | 1708 | |
---|
[258] | 1709 | // ctx_hba : HBA channel global index provided by the global allocator |
---|
[295] | 1710 | // Each channel is a private ressource: the number of |
---|
| 1711 | // requested channels cannot be larger than NB_NIC_CHANNELS. |
---|
[258] | 1712 | unsigned int ctx_hba = 0xFFFFFFFF; |
---|
| 1713 | if (task[task_id].use_hba) |
---|
| 1714 | { |
---|
[295] | 1715 | if (alloc_hba_channel >= NB_IOC_CHANNELS) |
---|
[258] | 1716 | { |
---|
| 1717 | _puts("\n[BOOT ERROR] IOC channel index too large for task "); |
---|
| 1718 | _puts(task[task_id].name); |
---|
| 1719 | _puts(" in vspace "); |
---|
| 1720 | _puts(vspace[vspace_id].name); |
---|
| 1721 | _puts("\n"); |
---|
| 1722 | _exit(); |
---|
| 1723 | } |
---|
| 1724 | ctx_hba = alloc_hba_channel; |
---|
| 1725 | alloc_hba_channel++; |
---|
| 1726 | } |
---|
[295] | 1727 | // ctx_tim : TIMER local channel index provided by the cluster allocator |
---|
| 1728 | // Each timer is a private ressource |
---|
[258] | 1729 | unsigned int ctx_tim = 0xFFFFFFFF; |
---|
| 1730 | if (task[task_id].use_tim) |
---|
| 1731 | { |
---|
| 1732 | unsigned int cluster_id = task[task_id].clusterid; |
---|
| 1733 | |
---|
| 1734 | if ( alloc_tim_channel[cluster_id] >= NB_TIM_CHANNELS ) |
---|
| 1735 | { |
---|
| 1736 | _puts("\n[BOOT ERROR] local TIMER index too large for task "); |
---|
| 1737 | _puts(task[task_id].name); |
---|
| 1738 | _puts(" in vspace "); |
---|
| 1739 | _puts(vspace[vspace_id].name); |
---|
| 1740 | _puts("\n"); |
---|
| 1741 | _exit(); |
---|
| 1742 | } |
---|
[295] | 1743 | ctx_tim = alloc_tim_channel[cluster_id]; |
---|
| 1744 | alloc_tim_channel[cluster_id]++; |
---|
[258] | 1745 | } |
---|
| 1746 | // ctx_epc : Get the virtual address of the memory location containing |
---|
| 1747 | // the task entry point : the start_vector is stored by GCC in the seg_data |
---|
| 1748 | // segment and we must wait the .elf loading to get the entry point value... |
---|
[321] | 1749 | vobj_id = vspace[vspace_id].start_vobj_id; |
---|
[412] | 1750 | unsigned int ctx_epc = vobj[vobj_id].vbase + (task[task_id].startid)*4; |
---|
[258] | 1751 | |
---|
| 1752 | // ctx_sp : Get the vobj containing the stack |
---|
[321] | 1753 | vobj_id = task[task_id].stack_vobj_id; |
---|
[412] | 1754 | unsigned int ctx_sp = vobj[vobj_id].vbase + vobj[vobj_id].length; |
---|
[258] | 1755 | |
---|
| 1756 | // get local task index in scheduler |
---|
| 1757 | unsigned int ltid = psched->tasks; |
---|
| 1758 | |
---|
[267] | 1759 | // get vspace thread index |
---|
| 1760 | unsigned int thread_id = task[task_id].trdid; |
---|
| 1761 | |
---|
[258] | 1762 | if (ltid >= IDLE_TASK_INDEX) |
---|
| 1763 | { |
---|
| 1764 | _puts("\n[BOOT ERROR] in boot_schedulers_init() : "); |
---|
| 1765 | _putd( ltid ); |
---|
| 1766 | _puts(" tasks allocated to processor "); |
---|
| 1767 | _putd( gpid ); |
---|
| 1768 | _puts(" / max is "); |
---|
| 1769 | _putd( IDLE_TASK_INDEX ); |
---|
| 1770 | _puts("\n"); |
---|
| 1771 | _exit(); |
---|
| 1772 | } |
---|
| 1773 | |
---|
| 1774 | // update the "tasks" and "current" fields in scheduler: |
---|
| 1775 | // the first task to execute is task 0 as soon as there is at least |
---|
| 1776 | // one task allocated to processor. |
---|
| 1777 | psched->tasks = ltid + 1; |
---|
| 1778 | psched->current = 0; |
---|
| 1779 | |
---|
| 1780 | // initializes the task context in scheduler |
---|
[293] | 1781 | psched->context[ltid][CTX_CR_ID] = 0; |
---|
[258] | 1782 | psched->context[ltid][CTX_SR_ID] = ctx_sr; |
---|
| 1783 | psched->context[ltid][CTX_SP_ID] = ctx_sp; |
---|
| 1784 | psched->context[ltid][CTX_EPC_ID] = ctx_epc; |
---|
| 1785 | psched->context[ltid][CTX_PTPR_ID] = ctx_ptpr; |
---|
| 1786 | psched->context[ltid][CTX_TTY_ID] = ctx_tty; |
---|
| 1787 | psched->context[ltid][CTX_CMA_ID] = ctx_cma; |
---|
| 1788 | psched->context[ltid][CTX_HBA_ID] = ctx_hba; |
---|
| 1789 | psched->context[ltid][CTX_NIC_ID] = ctx_nic; |
---|
| 1790 | psched->context[ltid][CTX_TIM_ID] = ctx_tim; |
---|
| 1791 | psched->context[ltid][CTX_PTAB_ID] = ctx_ptab; |
---|
| 1792 | psched->context[ltid][CTX_LTID_ID] = ltid; |
---|
| 1793 | psched->context[ltid][CTX_GTID_ID] = task_id; |
---|
[267] | 1794 | psched->context[ltid][CTX_TRDID_ID] = thread_id; |
---|
[258] | 1795 | psched->context[ltid][CTX_VSID_ID] = vspace_id; |
---|
| 1796 | psched->context[ltid][CTX_RUN_ID] = 1; |
---|
| 1797 | |
---|
| 1798 | #if BOOT_DEBUG_SCHED |
---|
| 1799 | _puts("\nTask "); |
---|
| 1800 | _putd( task_id ); |
---|
[295] | 1801 | _puts(" allocated to processor["); |
---|
[309] | 1802 | _putd( x ); |
---|
[295] | 1803 | _puts(","); |
---|
[309] | 1804 | _putd( y ); |
---|
[295] | 1805 | _puts(","); |
---|
[309] | 1806 | _putd( lpid ); |
---|
[295] | 1807 | _puts("]\n - ctx[LTID] = "); |
---|
[258] | 1808 | _putd( psched->context[ltid][CTX_LTID_ID] ); |
---|
| 1809 | _puts("\n - ctx[SR] = "); |
---|
| 1810 | _putx( psched->context[ltid][CTX_SR_ID] ); |
---|
| 1811 | _puts("\n - ctx[SP] = "); |
---|
| 1812 | _putx( psched->context[ltid][CTX_SP_ID] ); |
---|
| 1813 | _puts("\n - ctx[EPC] = "); |
---|
| 1814 | _putx( psched->context[ltid][CTX_EPC_ID] ); |
---|
| 1815 | _puts("\n - ctx[PTPR] = "); |
---|
| 1816 | _putx( psched->context[ltid][CTX_PTPR_ID] ); |
---|
| 1817 | _puts("\n - ctx[TTY] = "); |
---|
[295] | 1818 | _putx( psched->context[ltid][CTX_TTY_ID] ); |
---|
[258] | 1819 | _puts("\n - ctx[NIC] = "); |
---|
[295] | 1820 | _putx( psched->context[ltid][CTX_NIC_ID] ); |
---|
[258] | 1821 | _puts("\n - ctx[CMA] = "); |
---|
[295] | 1822 | _putx( psched->context[ltid][CTX_CMA_ID] ); |
---|
[258] | 1823 | _puts("\n - ctx[IOC] = "); |
---|
[295] | 1824 | _putx( psched->context[ltid][CTX_HBA_ID] ); |
---|
[258] | 1825 | _puts("\n - ctx[TIM] = "); |
---|
[295] | 1826 | _putx( psched->context[ltid][CTX_TIM_ID] ); |
---|
[258] | 1827 | _puts("\n - ctx[PTAB] = "); |
---|
| 1828 | _putx( psched->context[ltid][CTX_PTAB_ID] ); |
---|
| 1829 | _puts("\n - ctx[GTID] = "); |
---|
[295] | 1830 | _putx( psched->context[ltid][CTX_GTID_ID] ); |
---|
[258] | 1831 | _puts("\n - ctx[VSID] = "); |
---|
[295] | 1832 | _putx( psched->context[ltid][CTX_VSID_ID] ); |
---|
[267] | 1833 | _puts("\n - ctx[TRDID] = "); |
---|
[295] | 1834 | _putx( psched->context[ltid][CTX_TRDID_ID] ); |
---|
[258] | 1835 | _puts("\n"); |
---|
| 1836 | #endif |
---|
| 1837 | |
---|
| 1838 | } // end loop on tasks |
---|
| 1839 | } // end loop on vspaces |
---|
[412] | 1840 | } // end boot_schedulers_init() |
---|
[258] | 1841 | |
---|
| 1842 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 1843 | // This function loads the map.bin file from block device. |
---|
| 1844 | ////////////////////////////////////////////////////////////////////////////////// |
---|
| 1845 | void boot_mapping_init() |
---|
| 1846 | { |
---|
[347] | 1847 | // desactivates IOC interrupt |
---|
[289] | 1848 | _ioc_init( 0 ); |
---|
[258] | 1849 | |
---|
[347] | 1850 | // open file "map.bin" |
---|
[295] | 1851 | int fd_id = _fat_open( IOC_BOOT_MODE, |
---|
[258] | 1852 | "map.bin", |
---|
| 1853 | 0 ); // no creation |
---|
| 1854 | if ( fd_id == -1 ) |
---|
| 1855 | { |
---|
| 1856 | _puts("\n[BOOT ERROR] : map.bin file not found \n"); |
---|
| 1857 | _exit(); |
---|
| 1858 | } |
---|
| 1859 | |
---|
| 1860 | #if BOOT_DEBUG_MAPPING |
---|
| 1861 | _puts("\n[BOOT] map.bin file successfully open at cycle "); |
---|
| 1862 | _putd(_get_proctime()); |
---|
| 1863 | _puts("\n"); |
---|
| 1864 | #endif |
---|
| 1865 | |
---|
[412] | 1866 | // get "map.bin" file size (from fat) and check it |
---|
[258] | 1867 | unsigned int size = fat.fd[fd_id].file_size; |
---|
[347] | 1868 | |
---|
| 1869 | if ( size > SEG_BOOT_MAPPING_SIZE ) |
---|
| 1870 | { |
---|
| 1871 | _puts("\n[BOOT ERROR] : allocated segment too small for map.bin file\n"); |
---|
| 1872 | _exit(); |
---|
| 1873 | } |
---|
| 1874 | |
---|
| 1875 | // load "map.bin" file into buffer |
---|
[258] | 1876 | unsigned int nblocks = size >> 9; |
---|
| 1877 | unsigned int offset = size & 0x1FF; |
---|
| 1878 | if ( offset ) nblocks++; |
---|
| 1879 | |
---|
[295] | 1880 | unsigned int ok = _fat_read( IOC_BOOT_MODE, |
---|
[258] | 1881 | fd_id, |
---|
[321] | 1882 | (unsigned int*)SEG_BOOT_MAPPING_BASE, |
---|
[258] | 1883 | nblocks, |
---|
| 1884 | 0 ); // offset |
---|
| 1885 | if ( ok == -1 ) |
---|
| 1886 | { |
---|
| 1887 | _puts("\n[BOOT ERROR] : unable to load map.bin file \n"); |
---|
| 1888 | _exit(); |
---|
| 1889 | } |
---|
| 1890 | _fat_close( fd_id ); |
---|
| 1891 | |
---|
[347] | 1892 | // close file "map.bin" |
---|
[258] | 1893 | boot_mapping_check(); |
---|
[347] | 1894 | |
---|
[258] | 1895 | } // end boot_mapping_init() |
---|
| 1896 | |
---|
| 1897 | |
---|
[347] | 1898 | ///////////////////////////////////////////////////////////////////////////////////// |
---|
| 1899 | // This function load all loadable segments for one .elf file, identified |
---|
| 1900 | // by the "pathname" argument. Some loadable segments can be copied in several |
---|
| 1901 | // clusters: same virtual address but different physical addresses. |
---|
| 1902 | // - It open the file. |
---|
[359] | 1903 | // - It loads the complete file in the dedicated boot_elf_buffer. |
---|
| 1904 | // - It copies each loadable segments at the virtual address defined in |
---|
| 1905 | // the .elf file, making several copies if the target vseg is not local. |
---|
[347] | 1906 | // - It closes the file. |
---|
[359] | 1907 | // This function is supposed to be executed by processor[0,0,0]. |
---|
[347] | 1908 | // Note: |
---|
| 1909 | // We must use physical addresses to reach the destination buffers that |
---|
| 1910 | // can be located in remote clusters. We use either a _physical_memcpy(), |
---|
| 1911 | // or a _dma_physical_copy() if DMA is available. |
---|
| 1912 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
| 1913 | void load_one_elf_file( unsigned int is_kernel, // kernel file if non zero |
---|
[258] | 1914 | char* pathname, |
---|
[347] | 1915 | unsigned int vspace_id ) // to scan the proper vspace |
---|
[258] | 1916 | { |
---|
[347] | 1917 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 1918 | mapping_vspace_t * vspace = _get_vspace_base(header); |
---|
| 1919 | mapping_vseg_t * vseg = _get_vseg_base(header); |
---|
| 1920 | mapping_vobj_t * vobj = _get_vobj_base(header); |
---|
| 1921 | |
---|
[258] | 1922 | unsigned int seg_id; |
---|
| 1923 | |
---|
| 1924 | #if BOOT_DEBUG_ELF |
---|
| 1925 | _puts("\n[BOOT DEBUG] Start searching file "); |
---|
| 1926 | _puts( pathname ); |
---|
| 1927 | _puts(" at cycle "); |
---|
| 1928 | _putd( _get_proctime() ); |
---|
| 1929 | _puts("\n"); |
---|
| 1930 | #endif |
---|
| 1931 | |
---|
| 1932 | // open .elf file |
---|
[347] | 1933 | int fd_id = _fat_open( IOC_BOOT_MODE, |
---|
[258] | 1934 | pathname, |
---|
| 1935 | 0 ); // no creation |
---|
| 1936 | if ( fd_id < 0 ) |
---|
| 1937 | { |
---|
| 1938 | _puts("\n[BOOT ERROR] load_one_elf_file() : "); |
---|
| 1939 | _puts( pathname ); |
---|
| 1940 | _puts(" not found\n"); |
---|
| 1941 | _exit(); |
---|
| 1942 | } |
---|
| 1943 | |
---|
[359] | 1944 | // check buffer size versus file size |
---|
| 1945 | if ( fat.fd[fd_id].file_size > GIET_ELF_BUFFER_SIZE ) |
---|
[258] | 1946 | { |
---|
| 1947 | _puts("\n[BOOT ERROR] load_one_elf_file() : "); |
---|
| 1948 | _puts( pathname ); |
---|
[359] | 1949 | _puts(" exceeds the GIET_ELF_BUFFERSIZE defined in giet_config.h\n"); |
---|
[258] | 1950 | _exit(); |
---|
| 1951 | } |
---|
| 1952 | |
---|
| 1953 | // compute number of sectors |
---|
| 1954 | unsigned int nbytes = fat.fd[fd_id].file_size; |
---|
| 1955 | unsigned int nsectors = nbytes>>9; |
---|
| 1956 | if( nbytes & 0x1FF) nsectors++; |
---|
| 1957 | |
---|
[359] | 1958 | // load file in elf buffer |
---|
[347] | 1959 | if( _fat_read( IOC_BOOT_MODE, |
---|
[258] | 1960 | fd_id, |
---|
[359] | 1961 | boot_elf_buffer, |
---|
[258] | 1962 | nsectors, |
---|
| 1963 | 0 ) != nsectors ) |
---|
| 1964 | { |
---|
| 1965 | _puts("\n[BOOT ERROR] load_one_elf_file() : unexpected EOF for file "); |
---|
| 1966 | _puts( pathname ); |
---|
| 1967 | _puts("\n"); |
---|
| 1968 | _exit(); |
---|
| 1969 | } |
---|
| 1970 | |
---|
| 1971 | // Check ELF Magic Number in ELF header |
---|
[359] | 1972 | Elf32_Ehdr* elf_header_ptr = (Elf32_Ehdr*)boot_elf_buffer; |
---|
[258] | 1973 | |
---|
| 1974 | if ( (elf_header_ptr->e_ident[EI_MAG0] != ELFMAG0) || |
---|
| 1975 | (elf_header_ptr->e_ident[EI_MAG1] != ELFMAG1) || |
---|
| 1976 | (elf_header_ptr->e_ident[EI_MAG2] != ELFMAG2) || |
---|
| 1977 | (elf_header_ptr->e_ident[EI_MAG3] != ELFMAG3) ) |
---|
| 1978 | { |
---|
| 1979 | _puts("\n[BOOT ERROR] load_elf() : file "); |
---|
| 1980 | _puts( pathname ); |
---|
| 1981 | _puts(" does not use ELF format\n"); |
---|
| 1982 | _exit(); |
---|
| 1983 | } |
---|
| 1984 | |
---|
| 1985 | // get program header table pointer |
---|
| 1986 | unsigned int pht_index = elf_header_ptr->e_phoff; |
---|
| 1987 | if( pht_index == 0 ) |
---|
| 1988 | { |
---|
| 1989 | _puts("\n[BOOT ERROR] load_one_elf_file() : file "); |
---|
| 1990 | _puts( pathname ); |
---|
| 1991 | _puts(" does not contain loadable segment\n"); |
---|
| 1992 | _exit(); |
---|
| 1993 | } |
---|
[359] | 1994 | Elf32_Phdr* elf_pht_ptr = (Elf32_Phdr*)(boot_elf_buffer + pht_index); |
---|
[258] | 1995 | |
---|
| 1996 | // get number of segments |
---|
| 1997 | unsigned int nsegments = elf_header_ptr->e_phnum; |
---|
| 1998 | |
---|
[347] | 1999 | _puts("\n[BOOT] File "); |
---|
| 2000 | _puts( pathname ); |
---|
| 2001 | _puts(" loaded at cycle "); |
---|
| 2002 | _putd( _get_proctime() ); |
---|
| 2003 | _puts("\n"); |
---|
[258] | 2004 | |
---|
[347] | 2005 | // Loop on loadable segments in the .elf file |
---|
[258] | 2006 | for (seg_id = 0 ; seg_id < nsegments ; seg_id++) |
---|
| 2007 | { |
---|
| 2008 | if(elf_pht_ptr[seg_id].p_type == PT_LOAD) |
---|
| 2009 | { |
---|
| 2010 | // Get segment attributes |
---|
| 2011 | unsigned int seg_vaddr = elf_pht_ptr[seg_id].p_vaddr; |
---|
| 2012 | unsigned int seg_offset = elf_pht_ptr[seg_id].p_offset; |
---|
| 2013 | unsigned int seg_filesz = elf_pht_ptr[seg_id].p_filesz; |
---|
| 2014 | unsigned int seg_memsz = elf_pht_ptr[seg_id].p_memsz; |
---|
| 2015 | |
---|
[347] | 2016 | #if BOOT_DEBUG_ELF |
---|
| 2017 | _puts(" - segment "); |
---|
| 2018 | _putd( seg_id ); |
---|
| 2019 | _puts(" / vaddr = "); |
---|
| 2020 | _putx( seg_vaddr ); |
---|
| 2021 | _puts(" / file_size = "); |
---|
| 2022 | _putx( seg_filesz ); |
---|
| 2023 | _puts("\n"); |
---|
| 2024 | #endif |
---|
| 2025 | |
---|
[258] | 2026 | if( seg_memsz < seg_filesz ) |
---|
| 2027 | { |
---|
| 2028 | _puts("\n[BOOT ERROR] load_one_elf_file() : segment at vaddr = "); |
---|
| 2029 | _putx( seg_vaddr ); |
---|
| 2030 | _puts(" in file "); |
---|
| 2031 | _puts( pathname ); |
---|
[359] | 2032 | _puts(" has memsz < filesz \n"); |
---|
[258] | 2033 | _exit(); |
---|
| 2034 | } |
---|
| 2035 | |
---|
| 2036 | // fill empty space with 0 as required |
---|
| 2037 | if( seg_memsz > seg_filesz ) |
---|
| 2038 | { |
---|
| 2039 | unsigned int i; |
---|
[359] | 2040 | for( i = seg_filesz ; i < seg_memsz ; i++ ) boot_elf_buffer[i+seg_offset] = 0; |
---|
[258] | 2041 | } |
---|
| 2042 | |
---|
[359] | 2043 | unsigned int src_vaddr = (unsigned int)boot_elf_buffer + seg_offset; |
---|
[258] | 2044 | |
---|
[347] | 2045 | // search all vsegs matching the virtual address |
---|
| 2046 | unsigned int vseg_first; |
---|
| 2047 | unsigned int vseg_last; |
---|
| 2048 | unsigned int vseg_id; |
---|
| 2049 | unsigned int found = 0; |
---|
| 2050 | if ( is_kernel ) |
---|
| 2051 | { |
---|
| 2052 | vseg_first = 0; |
---|
| 2053 | vseg_last = header->globals; |
---|
| 2054 | } |
---|
| 2055 | else |
---|
| 2056 | { |
---|
| 2057 | vseg_first = vspace[vspace_id].vseg_offset; |
---|
| 2058 | vseg_last = vseg_first + vspace[vspace_id].vsegs; |
---|
| 2059 | } |
---|
| 2060 | |
---|
| 2061 | for ( vseg_id = vseg_first ; vseg_id < vseg_last ; vseg_id++ ) |
---|
| 2062 | { |
---|
| 2063 | if ( seg_vaddr == vseg[vseg_id].vbase ) // matching |
---|
| 2064 | { |
---|
| 2065 | found = 1; |
---|
| 2066 | |
---|
| 2067 | // get destination buffer physical address and size |
---|
| 2068 | paddr_t seg_paddr = vseg[vseg_id].pbase; |
---|
| 2069 | unsigned int vobj_id = vseg[vseg_id].vobj_offset; |
---|
| 2070 | unsigned int seg_size = vobj[vobj_id].length; |
---|
| 2071 | |
---|
[258] | 2072 | #if BOOT_DEBUG_ELF |
---|
[347] | 2073 | _puts(" loaded into vseg "); |
---|
| 2074 | _puts( vseg[vseg_id].name ); |
---|
| 2075 | _puts(" at paddr = "); |
---|
| 2076 | _putl( seg_paddr ); |
---|
| 2077 | _puts(" (buffer size = "); |
---|
| 2078 | _putx( seg_size ); |
---|
| 2079 | _puts(")\n"); |
---|
[258] | 2080 | #endif |
---|
[347] | 2081 | // check vseg size |
---|
| 2082 | if ( seg_size < seg_filesz ) |
---|
| 2083 | { |
---|
| 2084 | _puts("\n[BOOT ERROR] in load_one_elf_file()\n"); |
---|
| 2085 | _puts("vseg "); |
---|
| 2086 | _puts( vseg[vseg_id].name ); |
---|
| 2087 | _puts(" is to small for loadable segment "); |
---|
| 2088 | _putx( seg_vaddr ); |
---|
| 2089 | _puts(" in file "); |
---|
| 2090 | _puts( pathname ); |
---|
| 2091 | _puts(" \n"); |
---|
| 2092 | _exit(); |
---|
| 2093 | } |
---|
[258] | 2094 | |
---|
[347] | 2095 | // copy the segment from boot buffer to destination buffer |
---|
| 2096 | // using DMA channel[0,0,0] if it is available. |
---|
| 2097 | if( NB_DMA_CHANNELS > 0 ) |
---|
| 2098 | { |
---|
| 2099 | _dma_physical_copy( 0, // DMA in cluster[0,0] |
---|
| 2100 | 0, // DMA channel 0 |
---|
| 2101 | (paddr_t)seg_paddr, // destination paddr |
---|
| 2102 | (paddr_t)src_vaddr, // source paddr |
---|
| 2103 | seg_filesz ); // size |
---|
| 2104 | } |
---|
| 2105 | else |
---|
| 2106 | { |
---|
| 2107 | _physical_memcpy( (paddr_t)seg_paddr, // destination paddr |
---|
| 2108 | (paddr_t)src_vaddr, // source paddr |
---|
| 2109 | seg_filesz ); // size |
---|
| 2110 | } |
---|
| 2111 | } |
---|
| 2112 | } // end for vsegs in vspace |
---|
| 2113 | |
---|
| 2114 | // check at least one matching vseg |
---|
| 2115 | if ( found == 0 ) |
---|
[258] | 2116 | { |
---|
[347] | 2117 | _puts("\n[BOOT ERROR] in load_one_elf_file()\n"); |
---|
| 2118 | _puts("vseg for loadable segment "); |
---|
| 2119 | _putx( seg_vaddr ); |
---|
| 2120 | _puts(" in file "); |
---|
| 2121 | _puts( pathname ); |
---|
| 2122 | _puts(" not found \n"); |
---|
| 2123 | _exit(); |
---|
[258] | 2124 | } |
---|
| 2125 | } |
---|
[347] | 2126 | } // end for loadable segments |
---|
[258] | 2127 | |
---|
| 2128 | // close .elf file |
---|
| 2129 | _fat_close( fd_id ); |
---|
| 2130 | |
---|
| 2131 | } // end load_one_elf_file() |
---|
| 2132 | |
---|
| 2133 | |
---|
[347] | 2134 | /////i//////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2135 | // This function uses the map.bin data structure to load the "kernel.elf" file |
---|
[347] | 2136 | // as well as the various "application.elf" files into memory. |
---|
| 2137 | // - The "preloader.elf" file is not loaded, because it has been burned in the ROM. |
---|
| 2138 | // - The "boot.elf" file is not loaded, because it has been loaded by the preloader. |
---|
[295] | 2139 | // This function scans all vobjs defined in the map.bin data structure to collect |
---|
[347] | 2140 | // all .elf files pathnames, and calls the load_one_elf_file() for each .elf file. |
---|
| 2141 | // As the code can be replicated in several vsegs, the same code can be copied |
---|
| 2142 | // in one or several clusters by the load_one_elf_file() function. |
---|
| 2143 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
[258] | 2144 | void boot_elf_load() |
---|
| 2145 | { |
---|
[321] | 2146 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 2147 | mapping_vspace_t* vspace = _get_vspace_base( header ); |
---|
| 2148 | mapping_vobj_t* vobj = _get_vobj_base( header ); |
---|
| 2149 | unsigned int vspace_id; |
---|
| 2150 | unsigned int vobj_id; |
---|
| 2151 | unsigned int found; |
---|
| 2152 | |
---|
| 2153 | // Scan all vobjs corresponding to global vsegs, |
---|
| 2154 | // to find the pathname to the kernel.elf file |
---|
| 2155 | found = 0; |
---|
| 2156 | for( vobj_id = 0 ; vobj_id < header->globals ; vobj_id++ ) |
---|
| 2157 | { |
---|
| 2158 | if(vobj[vobj_id].type == VOBJ_TYPE_ELF) |
---|
| 2159 | { |
---|
| 2160 | found = 1; |
---|
| 2161 | break; |
---|
| 2162 | } |
---|
| 2163 | } |
---|
| 2164 | |
---|
| 2165 | // We need one kernel.elf file |
---|
| 2166 | if (found == 0) |
---|
| 2167 | { |
---|
| 2168 | _puts("[BOOT ERROR] boot_elf_load() : kernel.elf file not found\n"); |
---|
| 2169 | _exit(); |
---|
| 2170 | } |
---|
| 2171 | |
---|
[347] | 2172 | // Load the kernel |
---|
| 2173 | load_one_elf_file( 1, // kernel file |
---|
| 2174 | vobj[vobj_id].binpath, // file pathname |
---|
[258] | 2175 | 0 ); // vspace 0 |
---|
| 2176 | |
---|
[347] | 2177 | // loop on the vspaces, scanning all vobjs in the vspace, |
---|
[258] | 2178 | // to find the pathname of the .elf file associated to the vspace. |
---|
| 2179 | for( vspace_id = 0 ; vspace_id < header->vspaces ; vspace_id++ ) |
---|
| 2180 | { |
---|
| 2181 | // loop on the vobjs in vspace (vobj_id is the global index) |
---|
| 2182 | unsigned int found = 0; |
---|
| 2183 | for (vobj_id = vspace[vspace_id].vobj_offset; |
---|
| 2184 | vobj_id < (vspace[vspace_id].vobj_offset + vspace[vspace_id].vobjs); |
---|
| 2185 | vobj_id++) |
---|
| 2186 | { |
---|
| 2187 | if(vobj[vobj_id].type == VOBJ_TYPE_ELF) |
---|
| 2188 | { |
---|
| 2189 | found = 1; |
---|
| 2190 | break; |
---|
| 2191 | } |
---|
| 2192 | } |
---|
| 2193 | |
---|
| 2194 | // We want one .elf file per vspace |
---|
| 2195 | if (found == 0) |
---|
| 2196 | { |
---|
| 2197 | _puts("[BOOT ERROR] boot_elf_load() : .elf file not found for vspace "); |
---|
| 2198 | _puts( vspace[vspace_id].name ); |
---|
| 2199 | _puts("\n"); |
---|
| 2200 | _exit(); |
---|
| 2201 | } |
---|
| 2202 | |
---|
[347] | 2203 | load_one_elf_file( 0, // not a kernel file |
---|
| 2204 | vobj[vobj_id].binpath, // file pathname |
---|
| 2205 | vspace_id ); // vspace index |
---|
[258] | 2206 | |
---|
| 2207 | } // end for vspaces |
---|
| 2208 | |
---|
| 2209 | } // end boot_elf_load() |
---|
| 2210 | |
---|
| 2211 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 2212 | // This function intializes the periherals and coprocessors, as specified |
---|
| 2213 | // in the mapping_info file. |
---|
| 2214 | //////////////////////////////////////////////////////////////////////////////// |
---|
| 2215 | void boot_peripherals_init() |
---|
| 2216 | { |
---|
[321] | 2217 | mapping_header_t * header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[258] | 2218 | mapping_cluster_t * cluster = _get_cluster_base(header); |
---|
| 2219 | mapping_periph_t * periph = _get_periph_base(header); |
---|
| 2220 | mapping_vobj_t * vobj = _get_vobj_base(header); |
---|
| 2221 | mapping_coproc_t * coproc = _get_coproc_base(header); |
---|
| 2222 | mapping_cp_port_t * cp_port = _get_cp_port_base(header); |
---|
[295] | 2223 | mapping_irq_t * irq = _get_irq_base(header); |
---|
[258] | 2224 | |
---|
| 2225 | unsigned int cluster_id; |
---|
| 2226 | unsigned int periph_id; |
---|
| 2227 | unsigned int coproc_id; |
---|
| 2228 | unsigned int cp_port_id; |
---|
| 2229 | unsigned int channel_id; |
---|
| 2230 | |
---|
[263] | 2231 | // loop on all physical clusters |
---|
| 2232 | for (cluster_id = 0; cluster_id < X_SIZE*Y_SIZE; cluster_id++) |
---|
[258] | 2233 | { |
---|
[263] | 2234 | // computes cluster coordinates |
---|
| 2235 | unsigned int x = cluster[cluster_id].x; |
---|
| 2236 | unsigned int y = cluster[cluster_id].y; |
---|
| 2237 | unsigned int cluster_xy = (x<<Y_WIDTH) + y; |
---|
[258] | 2238 | |
---|
| 2239 | #if BOOT_DEBUG_PERI |
---|
[329] | 2240 | _puts("\n[BOOT DEBUG] Peripherals initialisation in cluster["); |
---|
[263] | 2241 | _putd( x ); |
---|
| 2242 | _puts(","); |
---|
| 2243 | _putd( y ); |
---|
[329] | 2244 | _puts("]\n"); |
---|
[258] | 2245 | #endif |
---|
| 2246 | |
---|
[263] | 2247 | // loop on peripherals |
---|
[258] | 2248 | for (periph_id = cluster[cluster_id].periph_offset; |
---|
| 2249 | periph_id < cluster[cluster_id].periph_offset + |
---|
| 2250 | cluster[cluster_id].periphs; periph_id++) |
---|
| 2251 | { |
---|
| 2252 | unsigned int type = periph[periph_id].type; |
---|
[347] | 2253 | unsigned int subtype = periph[periph_id].subtype; |
---|
[258] | 2254 | unsigned int channels = periph[periph_id].channels; |
---|
| 2255 | |
---|
| 2256 | switch (type) |
---|
| 2257 | { |
---|
| 2258 | case PERIPH_TYPE_IOC: // vci_block_device component |
---|
| 2259 | { |
---|
[347] | 2260 | if ( subtype == PERIPH_SUBTYPE_BDV ) |
---|
[289] | 2261 | { |
---|
[347] | 2262 | _bdv_lock.value = 0; |
---|
[258] | 2263 | #if BOOT_DEBUG_PERI |
---|
[347] | 2264 | _puts("- BDV : channels = "); |
---|
[263] | 2265 | _putd(channels); |
---|
| 2266 | _puts("\n"); |
---|
[258] | 2267 | #endif |
---|
[347] | 2268 | } |
---|
| 2269 | else if ( subtype == PERIPH_SUBTYPE_HBA ) |
---|
| 2270 | { |
---|
| 2271 | // TODO |
---|
| 2272 | } |
---|
| 2273 | else if ( subtype == PERIPH_SUBTYPE_SPI ) |
---|
| 2274 | { |
---|
| 2275 | // TODO |
---|
| 2276 | } |
---|
[258] | 2277 | break; |
---|
| 2278 | } |
---|
[263] | 2279 | case PERIPH_TYPE_CMA: // vci_chbuf_dma component |
---|
| 2280 | { |
---|
| 2281 | for (channel_id = 0; channel_id < channels; channel_id++) |
---|
| 2282 | { |
---|
| 2283 | // TODO |
---|
| 2284 | } |
---|
| 2285 | #if BOOT_DEBUG_PERI |
---|
[309] | 2286 | _puts("- CMA : channels = "); |
---|
[263] | 2287 | _putd(channels); |
---|
| 2288 | _puts("\n"); |
---|
| 2289 | #endif |
---|
| 2290 | break; |
---|
| 2291 | } |
---|
[258] | 2292 | case PERIPH_TYPE_NIC: // vci_multi_nic component |
---|
| 2293 | { |
---|
| 2294 | for (channel_id = 0; channel_id < channels; channel_id++) |
---|
| 2295 | { |
---|
| 2296 | // TODO |
---|
| 2297 | } |
---|
| 2298 | #if BOOT_DEBUG_PERI |
---|
[309] | 2299 | _puts("- NIC : channels = "); |
---|
[263] | 2300 | _putd(channels); |
---|
| 2301 | _puts("\n"); |
---|
[258] | 2302 | #endif |
---|
| 2303 | break; |
---|
| 2304 | } |
---|
[299] | 2305 | case PERIPH_TYPE_TTY: // vci_multi_tty component |
---|
[263] | 2306 | { |
---|
[347] | 2307 | for (channel_id = 0; channel_id < channels; channel_id++) |
---|
| 2308 | { |
---|
| 2309 | _tty_lock[channel_id].value = 0; |
---|
| 2310 | _tty_rx_full[channel_id] = 0; |
---|
| 2311 | } |
---|
[263] | 2312 | #if BOOT_DEBUG_PERI |
---|
[309] | 2313 | _puts("- TTY : channels = "); |
---|
[263] | 2314 | _putd(channels); |
---|
| 2315 | _puts("\n"); |
---|
| 2316 | #endif |
---|
| 2317 | break; |
---|
| 2318 | } |
---|
[299] | 2319 | case PERIPH_TYPE_IOB: // vci_io_bridge component |
---|
[258] | 2320 | { |
---|
[299] | 2321 | if (GIET_USE_IOMMU) |
---|
[258] | 2322 | { |
---|
| 2323 | // TODO |
---|
| 2324 | // get the iommu page table physical address |
---|
| 2325 | // set IOMMU page table address |
---|
| 2326 | // pseg_base[IOB_IOMMU_PTPR] = ptab_pbase; |
---|
| 2327 | // activate IOMMU |
---|
| 2328 | // pseg_base[IOB_IOMMU_ACTIVE] = 1; |
---|
| 2329 | } |
---|
| 2330 | break; |
---|
| 2331 | } |
---|
[295] | 2332 | case PERIPH_TYPE_PIC: // vci_iopic component |
---|
| 2333 | { |
---|
| 2334 | #if BOOT_DEBUG_PERI |
---|
[309] | 2335 | _puts("- PIC : channels = "); |
---|
[295] | 2336 | _putd(channels); |
---|
| 2337 | _puts("\n"); |
---|
| 2338 | #endif |
---|
[309] | 2339 | // scan all IRQs defined in mapping for PIC component, |
---|
[295] | 2340 | // and initialises addresses for WTI IRQs |
---|
| 2341 | for ( channel_id = periph[periph_id].irq_offset ; |
---|
| 2342 | channel_id < periph[periph_id].irq_offset + periph[periph_id].irqs ; |
---|
| 2343 | channel_id++ ) |
---|
| 2344 | { |
---|
[321] | 2345 | unsigned int hwi_id = irq[channel_id].srcid; // HWI index in PIC |
---|
| 2346 | unsigned int wti_id = irq[channel_id].dest_id; // WTI index in XCU |
---|
| 2347 | unsigned int cluster_xy = irq[channel_id].dest_xy; // XCU coordinates |
---|
[295] | 2348 | unsigned int vaddr; |
---|
| 2349 | |
---|
| 2350 | _xcu_get_wti_address( wti_id, &vaddr ); |
---|
[412] | 2351 | _pic_init( hwi_id, vaddr, cluster_xy ); |
---|
[295] | 2352 | |
---|
| 2353 | #if BOOT_DEBUG_PERI |
---|
[412] | 2354 | unsigned int address = _pic_get_register( channel_id, IOPIC_ADDRESS ); |
---|
| 2355 | unsigned int extend = _pic_get_register( channel_id, IOPIC_EXTEND ); |
---|
[295] | 2356 | _puts(" hwi_index = "); |
---|
| 2357 | _putd( hwi_id ); |
---|
| 2358 | _puts(" / wti_index = "); |
---|
| 2359 | _putd( wti_id ); |
---|
| 2360 | _puts(" / vaddr = "); |
---|
| 2361 | _putx( vaddr ); |
---|
| 2362 | _puts(" in cluster["); |
---|
[321] | 2363 | _putd( cluster_xy >> Y_WIDTH ); |
---|
[295] | 2364 | _puts(","); |
---|
[321] | 2365 | _putd( cluster_xy & ((1<<Y_WIDTH)-1) ); |
---|
[412] | 2366 | _puts("] / checked_xcu_paddr = "); |
---|
| 2367 | _putl( (paddr_t)address + (((paddr_t)extend)<<32) ); |
---|
| 2368 | _puts("\n"); |
---|
[295] | 2369 | #endif |
---|
| 2370 | } |
---|
| 2371 | break; |
---|
| 2372 | } |
---|
[258] | 2373 | } // end switch periph type |
---|
| 2374 | } // end for periphs |
---|
| 2375 | |
---|
| 2376 | #if BOOT_DEBUG_PERI |
---|
[329] | 2377 | _puts("\n[BOOT DEBUG] Coprocessors initialisation in cluster["); |
---|
[263] | 2378 | _putd( x ); |
---|
| 2379 | _puts(","); |
---|
| 2380 | _putd( y ); |
---|
[329] | 2381 | _puts("]\n"); |
---|
[258] | 2382 | #endif |
---|
| 2383 | |
---|
[263] | 2384 | // loop on coprocessors |
---|
[258] | 2385 | for ( coproc_id = cluster[cluster_id].coproc_offset; |
---|
| 2386 | coproc_id < cluster[cluster_id].coproc_offset + |
---|
| 2387 | cluster[cluster_id].coprocs; coproc_id++ ) |
---|
| 2388 | { |
---|
| 2389 | |
---|
| 2390 | #if BOOT_DEBUG_PERI |
---|
| 2391 | _puts("- coprocessor name : "); |
---|
| 2392 | _puts(coproc[coproc_id].name); |
---|
| 2393 | _puts(" / nb ports = "); |
---|
| 2394 | _putd((unsigned int) coproc[coproc_id].ports); |
---|
| 2395 | _puts("\n"); |
---|
| 2396 | #endif |
---|
| 2397 | // loop on the coprocessor ports |
---|
| 2398 | for ( cp_port_id = coproc[coproc_id].port_offset; |
---|
| 2399 | cp_port_id < coproc[coproc_id].port_offset + coproc[coproc_id].ports; |
---|
| 2400 | cp_port_id++ ) |
---|
| 2401 | { |
---|
[412] | 2402 | // get global index of associted vobj |
---|
[321] | 2403 | unsigned int vobj_id = cp_port[cp_port_id].mwmr_vobj_id; |
---|
[258] | 2404 | |
---|
[412] | 2405 | // get MWMR channel base address |
---|
| 2406 | page_table_t* ptab = (page_table_t*)_ptabs_vaddr[0][x][y]; |
---|
| 2407 | unsigned int vbase = vobj[vobj_id].vbase; |
---|
| 2408 | unsigned int ppn; |
---|
| 2409 | unsigned int flags; |
---|
| 2410 | paddr_t pbase; |
---|
[258] | 2411 | |
---|
[412] | 2412 | _v2p_translate( ptab, |
---|
| 2413 | vbase>>12 , |
---|
| 2414 | &ppn, |
---|
| 2415 | &flags ); |
---|
| 2416 | |
---|
| 2417 | pbase = ((paddr_t)ppn)<<12; |
---|
| 2418 | |
---|
| 2419 | // initialise cp_port |
---|
[263] | 2420 | _mwr_hw_init( cluster_xy, |
---|
| 2421 | cp_port_id, |
---|
| 2422 | cp_port[cp_port_id].direction, |
---|
[412] | 2423 | pbase ); |
---|
[258] | 2424 | #if BOOT_DEBUG_PERI |
---|
| 2425 | _puts(" port direction: "); |
---|
| 2426 | _putd( (unsigned int)cp_port[cp_port_id].direction ); |
---|
| 2427 | _puts(" / mwmr_channel_pbase = "); |
---|
[412] | 2428 | _putl( pbase ); |
---|
[258] | 2429 | _puts(" / name = "); |
---|
| 2430 | _puts(vobj[vobj_id].name); |
---|
| 2431 | _puts("\n"); |
---|
| 2432 | #endif |
---|
| 2433 | } // end for cp_ports |
---|
| 2434 | } // end for coprocs |
---|
| 2435 | } // end for clusters |
---|
| 2436 | } // end boot_peripherals_init() |
---|
| 2437 | |
---|
| 2438 | ///////////////////////////////////////////////////////////////////////// |
---|
[412] | 2439 | // This function initialises the physical memory allocators in each |
---|
| 2440 | // cluster containing a RAM pseg. |
---|
| 2441 | ///////////////////////////////////////////////////////////////////////// |
---|
| 2442 | void boot_pmem_init() |
---|
| 2443 | { |
---|
| 2444 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
| 2445 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 2446 | mapping_pseg_t* pseg = _get_pseg_base(header); |
---|
| 2447 | |
---|
| 2448 | unsigned int cluster_id; |
---|
| 2449 | unsigned int pseg_id; |
---|
| 2450 | |
---|
| 2451 | // scan all clusters |
---|
| 2452 | for ( cluster_id = 0 ; cluster_id < X_SIZE*Y_SIZE ; cluster_id++ ) |
---|
| 2453 | { |
---|
| 2454 | // scan the psegs in cluster to find first pseg of type RAM |
---|
| 2455 | unsigned int pseg_min = cluster[cluster_id].pseg_offset; |
---|
| 2456 | unsigned int pseg_max = pseg_min + cluster[cluster_id].psegs; |
---|
| 2457 | for ( pseg_id = pseg_min ; pseg_id < pseg_max ; pseg_id++ ) |
---|
| 2458 | { |
---|
| 2459 | if ( pseg[pseg_id].type == PSEG_TYPE_RAM ) |
---|
| 2460 | { |
---|
| 2461 | unsigned int x = cluster[cluster_id].x; |
---|
| 2462 | unsigned int y = cluster[cluster_id].y; |
---|
| 2463 | unsigned int base = (unsigned int)pseg[pseg_id].base; |
---|
| 2464 | unsigned int size = (unsigned int)pseg[pseg_id].length; |
---|
| 2465 | _pmem_alloc_init( x, y, base, size ); |
---|
| 2466 | |
---|
| 2467 | #if BOOT_DEBUG_PT |
---|
| 2468 | _puts("\n[BOOT DEBUG] pmem allocator initialised in cluster["); |
---|
| 2469 | _putd( x ); |
---|
| 2470 | _puts(","); |
---|
| 2471 | _putd( y ); |
---|
| 2472 | _puts("] base = "); |
---|
| 2473 | _putx( base ); |
---|
| 2474 | _puts(" / size = "); |
---|
| 2475 | _putx( size ); |
---|
| 2476 | _puts("\n"); |
---|
| 2477 | #endif |
---|
| 2478 | break; |
---|
| 2479 | } |
---|
| 2480 | } |
---|
| 2481 | } |
---|
| 2482 | } // end boot_pmem_init() |
---|
| 2483 | |
---|
| 2484 | ///////////////////////////////////////////////////////////////////////// |
---|
[258] | 2485 | // This function is the entry point of the boot code for all processors. |
---|
| 2486 | // Most of this code is executed by Processor 0 only. |
---|
| 2487 | ///////////////////////////////////////////////////////////////////////// |
---|
[347] | 2488 | void boot_init() |
---|
[258] | 2489 | { |
---|
[321] | 2490 | mapping_header_t* header = (mapping_header_t *)SEG_BOOT_MAPPING_BASE; |
---|
[295] | 2491 | mapping_cluster_t* cluster = _get_cluster_base(header); |
---|
| 2492 | unsigned int gpid = _get_procid(); |
---|
[258] | 2493 | |
---|
[263] | 2494 | if ( gpid == 0 ) // only Processor 0 does it |
---|
[258] | 2495 | { |
---|
| 2496 | _puts("\n[BOOT] boot_init start at cycle "); |
---|
| 2497 | _putd(_get_proctime()); |
---|
| 2498 | _puts("\n"); |
---|
| 2499 | |
---|
[347] | 2500 | // Load the map.bin file into memory and check it |
---|
[258] | 2501 | boot_mapping_init(); |
---|
| 2502 | |
---|
[295] | 2503 | _puts("\n[BOOT] Mapping \""); |
---|
[258] | 2504 | _puts( header->name ); |
---|
[295] | 2505 | _puts("\" loaded at cycle "); |
---|
[258] | 2506 | _putd(_get_proctime()); |
---|
| 2507 | _puts("\n"); |
---|
| 2508 | |
---|
[412] | 2509 | // Initializes the physical memory allocators |
---|
| 2510 | boot_pmem_init(); |
---|
| 2511 | |
---|
| 2512 | _puts("\n[BOOT] Physical memory allocators initialised at cycle "); |
---|
| 2513 | _putd(_get_proctime()); |
---|
| 2514 | _puts("\n"); |
---|
| 2515 | |
---|
[347] | 2516 | // Build page tables |
---|
[412] | 2517 | _ptabs_init(); |
---|
[258] | 2518 | |
---|
[412] | 2519 | _puts("\n[BOOT] Page tables initialised at cycle "); |
---|
| 2520 | _putd(_get_proctime()); |
---|
| 2521 | _puts("\n"); |
---|
| 2522 | |
---|
[347] | 2523 | // Activate MMU for proc [0,0,0] |
---|
| 2524 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][0][0]>>13) ); |
---|
[258] | 2525 | _set_mmu_mode( 0xF ); |
---|
| 2526 | |
---|
[263] | 2527 | _puts("\n[BOOT] Processor[0,0,0] : MMU activation at cycle "); |
---|
[258] | 2528 | _putd(_get_proctime()); |
---|
| 2529 | _puts("\n"); |
---|
| 2530 | |
---|
[347] | 2531 | // Initialise private vobjs in vspaces |
---|
[258] | 2532 | boot_vobjs_init(); |
---|
| 2533 | |
---|
| 2534 | _puts("\n[BOOT] Private vobjs initialised at cycle "); |
---|
| 2535 | _putd(_get_proctime()); |
---|
| 2536 | _puts("\n"); |
---|
| 2537 | |
---|
[347] | 2538 | // Initialise schedulers |
---|
[258] | 2539 | boot_schedulers_init(); |
---|
| 2540 | |
---|
[295] | 2541 | _puts("\n[BOOT] Schedulers initialised at cycle "); |
---|
[258] | 2542 | _putd(_get_proctime()); |
---|
| 2543 | _puts("\n"); |
---|
| 2544 | |
---|
[347] | 2545 | // Set CP0_SCHED register for proc [0,0,0] |
---|
| 2546 | _set_sched( (unsigned int)_schedulers[0][0][0] ); |
---|
[258] | 2547 | |
---|
[347] | 2548 | // Initialise non replicated peripherals |
---|
[258] | 2549 | boot_peripherals_init(); |
---|
| 2550 | |
---|
[295] | 2551 | _puts("\n[BOOT] Non replicated peripherals initialised at cycle "); |
---|
[258] | 2552 | _putd(_get_proctime()); |
---|
| 2553 | _puts("\n"); |
---|
| 2554 | |
---|
| 2555 | // Loading all .elf files |
---|
| 2556 | boot_elf_load(); |
---|
| 2557 | |
---|
[295] | 2558 | // P0 starts all other processors |
---|
| 2559 | unsigned int clusterid, p; |
---|
[258] | 2560 | |
---|
[295] | 2561 | for ( clusterid = 0 ; clusterid < X_SIZE*Y_SIZE ; clusterid++ ) |
---|
[258] | 2562 | { |
---|
[295] | 2563 | unsigned int nprocs = cluster[clusterid].procs; |
---|
[347] | 2564 | unsigned int x = cluster[clusterid].x; |
---|
| 2565 | unsigned int y = cluster[clusterid].y; |
---|
| 2566 | unsigned int cluster_xy = (x<<Y_WIDTH) + y; |
---|
[295] | 2567 | |
---|
| 2568 | for ( p = 0 ; p < nprocs; p++ ) |
---|
[258] | 2569 | { |
---|
[295] | 2570 | if ( (nprocs > 0) && ((clusterid != 0) || (p != 0)) ) |
---|
[258] | 2571 | { |
---|
[366] | 2572 | _xcu_send_wti( cluster_xy, p, (unsigned int)boot_entry ); |
---|
[258] | 2573 | } |
---|
| 2574 | } |
---|
| 2575 | } |
---|
[295] | 2576 | |
---|
[258] | 2577 | } // end monoprocessor boot |
---|
| 2578 | |
---|
[356] | 2579 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 2580 | // Parallel execution starts actually here |
---|
| 2581 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 2582 | |
---|
| 2583 | // all processor initialise the SCHED register |
---|
| 2584 | // from the _schedulers[x][y][lpid array] |
---|
[427] | 2585 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
| 2586 | unsigned int lpid = gpid & ((1<<P_WIDTH)-1); |
---|
[347] | 2587 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
| 2588 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
| 2589 | _set_sched( (unsigned int)_schedulers[x][y][lpid] ); |
---|
[258] | 2590 | |
---|
[347] | 2591 | // all processors (but Proc[0,0,0]) activate MMU |
---|
[263] | 2592 | if ( gpid != 0 ) |
---|
[258] | 2593 | { |
---|
[347] | 2594 | _set_mmu_ptpr( (unsigned int)(_ptabs_paddr[0][x][y]>>13) ); |
---|
[258] | 2595 | _set_mmu_mode( 0xF ); |
---|
| 2596 | } |
---|
| 2597 | |
---|
[427] | 2598 | // all processors reset BEV bit in the status register to use |
---|
| 2599 | // the GIET_VM exception handler instead of the PRELOADER exception handler |
---|
| 2600 | _set_sr( 0 ); |
---|
| 2601 | |
---|
[356] | 2602 | // all processors jump to kernel_init |
---|
| 2603 | // using the address defined in the giet_vsegs.ld file |
---|
[321] | 2604 | unsigned int kernel_entry = (unsigned int)&kernel_init_vbase; |
---|
[258] | 2605 | asm volatile( "jr %0" ::"r"(kernel_entry) ); |
---|
| 2606 | |
---|
| 2607 | } // end boot_init() |
---|
| 2608 | |
---|
| 2609 | |
---|
| 2610 | // Local Variables: |
---|
| 2611 | // tab-width: 4 |
---|
| 2612 | // c-basic-offset: 4 |
---|
| 2613 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
| 2614 | // indent-tabs-mode: nil |
---|
| 2615 | // End: |
---|
| 2616 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
| 2617 | |
---|