xv6

port of xv6 to x86-64
git clone http://frotz.net/git/xv6.git
Log | Files | Refs | README | LICENSE

entryother.S (2202B)


      1 #include "asm.h"
      2 #include "memlayout.h"
      3 #include "mmu.h"
      4 	
      5 # Each non-boot CPU ("AP") is started up in response to a STARTUP
      6 # IPI from the boot CPU.  Section B.4.2 of the Multi-Processor
      7 # Specification says that the AP will start in real mode with CS:IP
      8 # set to XY00:0000, where XY is an 8-bit value sent with the
      9 # STARTUP. Thus this code must start at a 4096-byte boundary.
     10 #
     11 # Because this code sets DS to zero, it must sit
     12 # at an address in the low 2^16 bytes.
     13 #
     14 # Startothers (in main.c) sends the STARTUPs one at a time.
     15 # It copies this code (start) at 0x7000.  It puts the address of
     16 # a newly allocated per-core stack in start-4,the address of the
     17 # place to jump to (mpenter) in start-8, and the physical address
     18 # of entrypgdir in start-12.
     19 #
     20 # This code is identical to bootasm.S except:
     21 #   - it does not need to enable A20
     22 #   - it uses the address at start-4, start-8, and start-12
     23 
     24 .code16           
     25 .globl start
     26 start:
     27   cli            
     28 
     29   xorw    %ax,%ax
     30   movw    %ax,%ds
     31   movw    %ax,%es
     32   movw    %ax,%ss
     33 
     34   lgdt    gdtdesc
     35   movl    %cr0, %eax
     36   orl     $CR0_PE, %eax
     37   movl    %eax, %cr0
     38 
     39 //PAGEBREAK!
     40   ljmpl    $(SEG_KCODE<<3), $(start32)
     41 
     42 .code32
     43 start32:
     44   movw    $(SEG_KDATA<<3), %ax
     45   movw    %ax, %ds
     46   movw    %ax, %es
     47   movw    %ax, %ss
     48   movw    $0, %ax
     49   movw    %ax, %fs
     50   movw    %ax, %gs
     51 
     52 #if X64
     53   # defer paging until we switch to 64bit mode
     54   # set ebx=1 so shared boot code knows we're booting a secondary core
     55   mov     $1, %ebx
     56 #else
     57   # Turn on page size extension for 4Mbyte pages
     58   movl    %cr4, %eax
     59   orl     $(CR4_PSE), %eax
     60   movl    %eax, %cr4
     61   # Use enterpgdir as our initial page table
     62   movl    (start-12), %eax
     63   movl    %eax, %cr3
     64   # Turn on paging.
     65   movl    %cr0, %eax
     66   orl     $(CR0_PE|CR0_PG|CR0_WP), %eax
     67   movl    %eax, %cr0
     68 #endif
     69 
     70   # Switch to the stack allocated by startothers()
     71   movl    (start-4), %esp
     72   # Call mpenter()
     73   call	 *(start-8)
     74 
     75   movw    $0x8a00, %ax
     76   movw    %ax, %dx
     77   outw    %ax, %dx
     78   movw    $0x8ae0, %ax
     79   outw    %ax, %dx
     80 spin:
     81   jmp     spin
     82 
     83 .p2align 2
     84 gdt:
     85   SEG_NULLASM
     86   SEG_ASM(STA_X|STA_R, 0, 0xffffffff)
     87   SEG_ASM(STA_W, 0, 0xffffffff)
     88 
     89 
     90 gdtdesc:
     91   .word   (gdtdesc - gdt - 1)
     92   .long   gdt
     93