1 ! 2 ! Trampoline.S Derived from Setup.S by Linus Torvalds 3 ! 4 ! Entry: CS:IP point to the start of our code, we are 5 ! in real mode with no stack, but the rest of the 6 ! trampoline page to make our stack and everything else 7 ! is a mystery. 8 ! 9 ! In fact we don't actually need a stack so we don't 10 ! set one up. 11 ! 12 ! We jump into the boot/compressed/head.S code. So you'd 13 ! better be running a compressed kernel image or you 14 ! won't get very far. 15 ! 16 #define __ASSEMBLY__ 17 #include <asm/segment.h> 18 19 .text 20 extrn startup32 21 22 entry start 23 start: 24 ! nop 25 ! jmp start ! Test 26 mov ax,cs ! Code and data in the same place 27 mov ds,ax ! 28 mov cx,ax ! Pass stack info to the 32bit boot 29 add cx,cx 30 add cx,cx 31 add cx,cx 32 add cx,cx ! Segment -> Offset 33 add cx, #4096 ! End of page is wanted 34 mov bx,#1 ! Flag an SMP trampoline 35 cli ! We should be safe anyway 36 37 lidt idt_48 ! load idt with 0,0 38 lgdt gdt_48 ! load gdt with whatever is appropriate 39 40 xor ax,ax 41 inc ax ! protected mode (PE) bit 42 lmsw ax ! Into protected mode 43 jmp flush_instr 44 flush_instr: 45 jmpi 8192+startup32,KERNEL_CS ! Jump to the 32bit trampoline code 46 ! jmpi 0x100000,KERNEL_CS ! Jump into the 32bit startup 47 ! .byte 0x66,0x67 ! 32bit 48 ! .byte 0xea,0x00,0x00,0x10,0x00,0x10,0x00 !jmpi .0x100000,KERNEL_CS 49 50 gdt: 51 .word 0,0,0,0 ! dummy 52 53 .word 0,0,0,0 ! unused 54 55 .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 56 .word 0x0000 ! base address=0 57 .word 0x9A00 ! code read/exec 58 .word 0x00C0 ! granularity=4096, 386 59 60 .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 61 .word 0x0000 ! base address=0 62 .word 0x9200 ! data read/write 63 .word 0x00C0 ! granularity=4096, 386 64 65 idt_48: 66 .word 0 ! idt limit=0 67 .word 0,0 ! idt base=0L 68 69 gdt_48: 70 .word 0x800 ! gdt limit=2048, 256 GDT entries 71 .word 8192+gdt,0x0 ! gdt base = 8192+gdt (first SMP CPU) 72 ! we load the others with the first table 73 ! saves rewriting gdt_48 for each 74