added base src
[xv6-db.git] / bootother.S
blobdd95ff096d204ab436cc11149ef639f4e6b687f8
1 #include "asm.h"
3 # Each non-boot CPU ("AP") is started up in response to a STARTUP
4 # IPI from the boot CPU.  Section B.4.2 of the Multi-Processor
5 # Specification says that the AP will start in real mode with CS:IP
6 # set to XY00:0000, where XY is an 8-bit value sent with the
7 # STARTUP. Thus this code must start at a 4096-byte boundary.
9 # Because this code sets DS to zero, it must sit
10 # at an address in the low 2^16 bytes.
12 # Bootothers (in main.c) sends the STARTUPs one at a time.
13 # It copies this code (start) at 0x7000.
14 # It puts the address of a newly allocated per-core stack in start-4,
15 # and the address of the place to jump to (mpmain) in start-8.
17 # This code is identical to bootasm.S except:
18 #   - it does not need to enable A20
19 #   - it uses the address at start-4 for the %esp
20 #   - it jumps to the address at start-8 instead of calling bootmain
22 #define SEG_KCODE 1
23 #define SEG_KDATA 2
25 #define CR0_PE    1
27 .code16           
28 .globl start
29 start:
30   cli            
32   xorw    %ax,%ax
33   movw    %ax,%ds
34   movw    %ax,%es
35   movw    %ax,%ss
37   lgdt    gdtdesc
38   movl    %cr0, %eax
39   orl     $CR0_PE, %eax
40   movl    %eax, %cr0
42   ljmp    $(SEG_KCODE<<3), $start32
44 .code32
45 start32:
46   movw    $(SEG_KDATA<<3), %ax
47   movw    %ax, %ds
48   movw    %ax, %es
49   movw    %ax, %ss
50   movw    $0, %ax
51   movw    %ax, %fs
52   movw    %ax, %gs
54   # switch to the stack allocated by bootothers()
55   movl    start-4, %esp
57   # call mpmain()
58   call  *(start-8)
60   movw    $0x8a00, %ax
61   movw    %ax, %dx
62   outw    %ax, %dx
63   movw    $0x8ae0, %ax
64   outw    %ax, %dx
65 spin:
66   jmp     spin
68 .p2align 2
69 gdt:
70   SEG_NULLASM
71   SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff)
72   SEG_ASM(STA_W, 0x0, 0xffffffff)
74 gdtdesc:
75   .word   (gdtdesc - gdt - 1)
76   .long   gdt