Changeset 5d8d71e in mainline for kernel/arch


Ignore:
Timestamp:
2009-03-03T21:17:45Z (17 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
06f96234
Parents:
c22e964
Message:

Move multiboot parsing to genarch/*/multiboot and adapt it for use with both ia32 and amd64. Multiboot info parsing now supported on amd64, too.

Location:
kernel/arch
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/include/arch.h

    rc22e964 r5d8d71e  
    3636#define KERN_amd64_ARCH_H_
    3737
     38#include <genarch/multiboot/multiboot.h>
     39
     40extern void arch_pre_main(uint32_t, const multiboot_info_t *);
     41
    3842#endif
    3943
  • kernel/arch/amd64/include/boot/boot.h

    rc22e964 r5d8d71e  
    4343#define MULTIBOOT_HEADER_FLAGS  0x00010003
    4444
    45 #define MULTIBOOT_LOADER_MAGIC  0x2BADB002
     45#ifndef __ASM__
     46
     47#ifdef CONFIG_SMP
     48
     49/* This is only a symbol so the type is dummy. Obtain the value using &. */
     50extern int _hardcoded_unmapped_size;
     51
     52#endif /* CONFIG_SMP */
     53
     54#endif /* __ASM__ */
    4655
    4756#endif
  • kernel/arch/amd64/src/amd64.c

    rc22e964 r5d8d71e  
    4040
    4141#include <proc/thread.h>
     42#include <genarch/multiboot/multiboot.h>
    4243#include <genarch/drivers/legacy/ia32/io.h>
    4344#include <genarch/drivers/ega/ega.h>
     
    4647#include <arch/drivers/i8254.h>
    4748#include <arch/drivers/i8259.h>
     49#include <arch/boot/boot.h>
    4850
    4951#ifdef CONFIG_SMP
     
    6668#include <sysinfo/sysinfo.h>
    6769
    68 
    6970/** Disable I/O on non-privileged levels
    7071 *
     
    9596                ::: "%rax"
    9697        );
     98}
     99
     100/** Perform amd64-specific initialization before main_bsp() is called.
     101 *
     102 * @param signature Should contain the multiboot signature.
     103 * @param mi        Pointer to the multiboot information structure.
     104 */
     105void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
     106{
     107        /* Parse multiboot information obtained from the bootloader. */
     108        multiboot_info_parse(signature, mi);
     109       
     110#ifdef CONFIG_SMP
     111        /* Copy AP bootstrap routines below 1 MB. */
     112        memcpy((void *) AP_BOOT_OFFSET, (void *) BOOT_OFFSET,
     113            (size_t) &_hardcoded_unmapped_size);
     114#endif
    97115}
    98116
  • kernel/arch/amd64/src/boot/boot.S

    rc22e964 r5d8d71e  
    176176start64:
    177177        movq $(PA2KA(START_STACK)), %rsp
    178         movl grub_eax, %eax
    179         movl grub_ebx, %ebx
    180        
    181         cmpl $MULTIBOOT_LOADER_MAGIC, %eax                      # compare GRUB signature
    182         je valid_boot
    183                
    184                 xorl %ecx, %ecx                                 # no memory size or map available
    185                 movl %ecx, e820counter
    186                
    187                 jmp invalid_boot
    188                
    189         valid_boot:
    190                
    191                 movl (%ebx), %eax                               # ebx = physical address of struct multiboot_info
    192                
    193                 bt $3, %eax                                     # mbi->flags[3] (mods_count, mods_addr valid)
    194                 jc mods_valid
    195                        
    196                         xorq %rcx, %rcx
    197                         movq %rcx, init
    198                         jmp mods_end
    199                
    200                 mods_valid:
    201                
    202                 xorq %rcx, %rcx
    203                 movl 20(%ebx), %ecx                             # mbi->mods_count
    204                 movq %rcx, init
    205                
    206                 cmpl $0, %ecx
    207                 je mods_end
    208                
    209                 movl 24(%ebx), %esi                             # mbi->mods_addr
    210                 movq $init, %rdi
    211                
    212                 mods_loop:
    213                        
    214                         xorq %rdx, %rdx
    215                         movl 0(%esi), %edx                      # mods->mod_start
    216                         movq $0xffff800000000000, %r10
    217                         addq %r10, %rdx
    218                         movq %rdx, 8(%rdi)
    219                        
    220                         xorq %rdx, %rdx
    221                         movl 4(%esi), %edx
    222                         subl 0(%esi), %edx                      # mods->mod_end - mods->mod_start
    223                         movq %rdx, 16(%rdi)
    224                        
    225                         addl $16, %esi
    226                         addq $48, %rdi
    227                        
    228                         loop mods_loop
    229                        
    230                 mods_end:
    231                
    232                 bt $6, %eax                                     # mbi->flags[6] (mmap_length, mmap_addr valid) 
    233                 jc mmap_valid
    234                        
    235                         xorl %edx, %edx
    236                         jmp mmap_invalid
    237                        
    238                 mmap_valid:
    239                 movl 44(%ebx), %ecx                             # mbi->mmap_length
    240                 movl 48(%ebx), %esi                             # mbi->mmap_addr
    241                 movq $e820table, %rdi
    242                 xorl %edx, %edx
    243                
    244                 mmap_loop:
    245                         cmpl $0, %ecx
    246                         jle mmap_end
    247                        
    248                         movl 4(%esi), %eax                      # mmap->base_addr_low
    249                         movl %eax, (%rdi)
    250                        
    251                         movl 8(%esi), %eax                      # mmap->base_addr_high
    252                         movl %eax, 4(%rdi)
    253                        
    254                         movl 12(%esi), %eax                     # mmap->length_low
    255                         movl %eax, 8(%rdi)
    256                        
    257                         movl 16(%esi), %eax                     # mmap->length_high
    258                         movl %eax, 12(%rdi)
    259                        
    260                         movl 20(%esi), %eax                     # mmap->type
    261                         movl %eax, 16(%rdi)
    262                        
    263                         movl (%esi), %eax                       # mmap->size
    264                         addl $0x4, %eax
    265                         addl %eax, %esi
    266                         subl %eax, %ecx
    267                         addq $MEMMAP_E820_RECORD_SIZE, %rdi
    268                         incl %edx
    269                         jmp mmap_loop
    270                
    271                 mmap_end:
    272                
    273                 mmap_invalid:
    274                 movl %edx, e820counter
    275                
    276         invalid_boot:
    277        
    278 #ifdef CONFIG_SMP
    279        
    280         # copy AP bootstrap routines below 1 MB
    281        
    282         movq $BOOT_OFFSET, %rsi
    283         movq $AP_BOOT_OFFSET, %rdi
    284         movq $_hardcoded_unmapped_size, %rcx
    285         rep movsb
    286        
    287 #endif
    288        
    289         call main_bsp   # never returns
     178
     179        # arch_pre_main(grub_eax, grub_ebx)
     180        xorq %rdi, %rdi
     181        movl grub_eax, %edi
     182        xorq %rsi, %rsi
     183        movl grub_ebx, %esi
     184        call arch_pre_main
     185
     186        call main_bsp 
     187
     188        # Not reached.
    290189       
    291190        cli
  • kernel/arch/ia32/include/arch.h

    rc22e964 r5d8d71e  
    11/*
    2  * Copyright (c) 2005 Martin Decky
     2 * Copyright (c) 2009 Martin Decky
    33 * All rights reserved.
    44 *
     
    3636#define KERN_ia32_ARCH_H_
    3737
    38 #include <arch/boot/multiboot.h>
     38#include <genarch/multiboot/multiboot.h>
    3939
    40 extern void arch_pre_main(uint32_t signature, const mb_info_t *mi);
     40extern void arch_pre_main(uint32_t, const multiboot_info_t *);
    4141
    4242#endif
  • kernel/arch/ia32/include/boot/boot.h

    rc22e964 r5d8d71e  
    4343#define MULTIBOOT_HEADER_FLAGS  0x00010003
    4444
    45 #define MULTIBOOT_LOADER_MAGIC  0x2BADB002
    46 
    4745#ifndef __ASM__
    4846
    4947#ifdef CONFIG_SMP
    5048
     49/* This is only a symbol so the type is dummy. Obtain the value using &. */
    5150extern int _hardcoded_unmapped_size;
    5251
  • kernel/arch/ia32/src/ia32.c

    rc22e964 r5d8d71e  
    4141#include <arch/pm.h>
    4242
     43#include <genarch/multiboot/multiboot.h>
    4344#include <genarch/drivers/legacy/ia32/io.h>
    4445#include <genarch/drivers/ega/ega.h>
     
    6768#include <sysinfo/sysinfo.h>
    6869#include <arch/boot/boot.h>
    69 #include <string.h>
    70 #include <macros.h>
    7170
    7271#ifdef CONFIG_SMP
     
    7473#endif
    7574
    76 /** Extract command name from the multiboot module command line.
    77  *
    78  * @param buf      Destination buffer (will always null-terminate).
    79  * @param n        Size of destination buffer.
    80  * @param cmd_line Input string (the command line).
    81  *
    82  */
    83 static void extract_command(char *buf, size_t n, const char *cmd_line)
    84 {
    85         const char *start, *end, *cp;
    86         size_t max_len;
    87        
    88         /* Find the first space. */
    89         end = strchr(cmd_line, ' ');
    90         if (end == NULL)
    91                 end = cmd_line + strlen(cmd_line);
    92        
    93         /*
    94          * Find last occurence of '/' before 'end'. If found, place start at
    95          * next character. Otherwise, place start at beginning of buffer.
    96          */
    97         cp = end;
    98         start = buf;
    99         while (cp != start) {
    100                 if (*cp == '/') {
    101                         start = cp + 1;
    102                         break;
    103                 }
    104                 --cp;
    105         }
    106        
    107         /* Copy the command and null-terminate the string. */
    108         max_len = min(n - 1, (size_t) (end - start));
    109         strncpy(buf, start, max_len + 1);
    110         buf[max_len] = '\0';
    111 }
    112 
    113 /** C part of ia32 boot sequence.
     75/** Perform ia32-specific initialization before main_bsp() is called.
    11476 *
    11577 * @param signature Should contain the multiboot signature.
    11678 * @param mi        Pointer to the multiboot information structure.
    11779 */
    118 void arch_pre_main(uint32_t signature, const mb_info_t *mi)
    119 {
    120         uint32_t flags;
    121         mb_mod_t *mods;
    122         uint32_t i;
    123        
    124         if (signature == MULTIBOOT_LOADER_MAGIC)
    125                 flags = mi->flags;
    126         else {
    127                 /* No multiboot info available. */
    128                 flags = 0;
    129         }
    130        
    131         /* Copy module information. */
    132        
    133         if ((flags & MBINFO_FLAGS_MODS) != 0) {
    134                 init.cnt = mi->mods_count;
    135                 mods = mi->mods_addr;
    136                
    137                 for (i = 0; i < init.cnt; i++) {
    138                         init.tasks[i].addr = mods[i].start + 0x80000000;
    139                         init.tasks[i].size = mods[i].end - mods[i].start;
    140                        
    141                         /* Copy command line, if available. */
    142                         if (mods[i].string) {
    143                                 extract_command(init.tasks[i].name,
    144                                     CONFIG_TASK_NAME_BUFLEN,
    145                                     mods[i].string);
    146                         } else
    147                                 init.tasks[i].name[0] = '\0';
    148                 }
    149         } else
    150                 init.cnt = 0;
    151        
    152         /* Copy memory map. */
    153        
    154         int32_t mmap_length;
    155         mb_mmap_t *mme;
    156         uint32_t size;
    157        
    158         if ((flags & MBINFO_FLAGS_MMAP) != 0) {
    159                 mmap_length = mi->mmap_length;
    160                 mme = mi->mmap_addr;
    161                 e820counter = 0;
    162                
    163                 i = 0;
    164                 while (mmap_length > 0) {
    165                         e820table[i++] = mme->mm_info;
    166                        
    167                         /* Compute address of next structure. */
    168                         size = sizeof(mme->size) + mme->size;
    169                         mme = ((void *) mme) + size;
    170                         mmap_length -= size;
    171                 }
    172                
    173                 e820counter = i;
    174         } else
    175                 e820counter = 0;
     80void arch_pre_main(uint32_t signature, const multiboot_info_t *mi)
     81{
     82        /* Parse multiboot information obtained from the bootloader. */
     83        multiboot_info_parse(signature, mi);   
    17684       
    17785#ifdef CONFIG_SMP
Note: See TracChangeset for help on using the changeset viewer.