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 <linux/config.h> 18 #include <asm/segment.h> 19 20 .text 21 extrn startup32 22 23 entry start 24 start: 25 ! nop 26 ! jmp start ! Test 27 mov ax,cs ! Code and data in the same place 28 mov ds,ax ! 29 mov cx,ax ! Pass stack info to the 32bit boot 30 add cx,cx 31 add cx,cx 32 add cx,cx 33 add cx,cx ! Segment -> Offset 34 add cx, #4096 ! End of page is wanted 35 mov bx,#1 ! Flag an SMP trampoline 36 cli ! We should be safe anyway 37 38 lidt idt_48 ! load idt with 0,0 39 lgdt gdt_48 ! load gdt with whatever is appropriate 40 41 xor ax,ax 42 inc ax ! protected mode (PE) bit 43 lmsw ax ! Into protected mode 44 jmp flush_instr 45 flush_instr: 46 jmpi 8192+startup32,KERNEL_CS ! Jump to the 32bit trampoline code 47 ! jmpi 0x100000,KERNEL_CS ! Jump into the 32bit startup 48 ! .byte 0x66,0x67 ! 32bit 49 ! .byte 0xea,0x00,0x00,0x10,0x00,0x10,0x00 !jmpi .0x100000,KERNEL_CS 50 51 gdt: 52 .word 0,0,0,0 ! dummy 53 54 .word 0,0,0,0 ! unused 55 56 .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 57 .word 0x0000 ! base address=0 58 .word 0x9A00 ! code read/exec 59 .word 0x00C0 ! granularity=4096, 386 60 61 .word 0x07FF ! 8Mb - limit=2047 (2048*4096=8Mb) 62 .word 0x0000 ! base address=0 63 .word 0x9200 ! data read/write 64 .word 0x00C0 ! granularity=4096, 386 65 66 idt_48: 67 .word 0 ! idt limit=0 68 .word 0,0 ! idt base=0L 69 70 gdt_48: 71 .word 0x800 ! gdt limit=2048, 256 GDT entries 72 .word 8192+gdt,0x0 ! gdt base = 8192+gdt (first SMP CPU) 73 ! we load the others with the first table 74 ! saves rewriting gdt_48 for each 75