spawn implemented.
[mit-jos.git] / kern / entry.S
blob4b4f380e98b4427fa8cb9e538dc8c8dab3169f6c
1 /* See COPYRIGHT for copyright information. */
3 #include <inc/mmu.h>
4 #include <inc/memlayout.h>
5 #include <inc/trap.h>
7 # Shift Right Logical 
8 #define SRL(val, shamt)         (((val) >> (shamt)) & ~(-1 << (32 - (shamt))))
11 ###################################################################
12 # The kernel (this code) is linked at address ~(KERNBASE + 1 Meg), 
13 # but the bootloader loads it at address ~1 Meg.
14 #       
15 # RELOC(x) maps a symbol x from its link address to its actual
16 # location in physical memory (its load address).        
17 ###################################################################
19 #define RELOC(x) ((x) - KERNBASE)
22 .set CODE_SEL,0x8               # index of code seg within mygdt
23 .set DATA_SEL,0x10              # index of data seg within mygdt
25 #define MULTIBOOT_PAGE_ALIGN  (1<<0)
26 #define MULTIBOOT_MEMORY_INFO (1<<1)
27 #define MULTIBOOT_HEADER_MAGIC (0x1BADB002)
28 #define MULTIBOOT_HEADER_FLAGS (MULTIBOOT_MEMORY_INFO | MULTIBOOT_PAGE_ALIGN)
29 #define CHECKSUM (-(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS))
31 ###################################################################
32 # entry point
33 ###################################################################
35 .text
37 # The Multiboot header
38 .align 4
39 .long MULTIBOOT_HEADER_MAGIC
40 .long MULTIBOOT_HEADER_FLAGS
41 .long CHECKSUM
43 .globl          _start
44 _start:
45         movw    $0x1234,0x472                   # warm boot
47         # Establish our own GDT in place of the boot loader's temporary GDT.
48         lgdt    RELOC(mygdtdesc)                # load descriptor table
50         # Immediately reload all segment registers (including CS!)
51         # with segment selectors from the new GDT.
52         movl    $DATA_SEL, %eax                 # Data segment selector
53         movw    %ax,%ds                         # -> DS: Data Segment
54         movw    %ax,%es                         # -> ES: Extra Segment
55         movw    %ax,%ss                         # -> SS: Stack Segment
56         ljmp    $CODE_SEL,$relocated            # reload CS by jumping
57 relocated:
59         # Clear the frame pointer register (EBP)
60         # so that once we get into debugging C code,
61         # stack backtraces will be terminated properly.
62         movl    $0x0,%ebp                       # nuke frame pointer
64         # Leave a few words on the stack for the user trap frame
65         movl    $(bootstacktop-SIZEOF_STRUCT_TRAPFRAME),%esp
67         # now to C code
68         call    i386_init
70         # Should never get here, but in case we do, just spin.
71 spin:   jmp     spin
74 ###################################################################     
75 # See <inc/memlayout.h> for a complete description of these two symbols.
76 ###################################################################
77 .data
78         .globl  vpt
79         .set    vpt, VPT
80         .globl  vpd
81         .set    vpd, (VPT + SRL(VPT, 10))
84 ###################################################################
85 # boot stack
86 ###################################################################
87         .p2align        PGSHIFT         # force page alignment
88         .globl          bootstack
89 bootstack:
90         .space          KSTKSIZE
91         .globl          bootstacktop   
92 bootstacktop:
94 ###################################################################
95 # setup the GDT 
96 ###################################################################
97         .p2align        2               # force 4 byte alignment
98 mygdt:
99         SEG_NULL                                # null seg
100         SEG(STA_X|STA_R, -KERNBASE, 0xffffffff) # code seg
101         SEG(STA_W, -KERNBASE, 0xffffffff)       # data seg
102 mygdtdesc:
103         .word   0x17                    # sizeof(mygdt) - 1
104         .long   RELOC(mygdt)            # address mygdt