| 1 |
/* |
| 2 |
* purgatory: setup code |
| 3 |
* |
| 4 |
* Copyright (C) 2003,2004 Eric Biederman ([email protected]) |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation (version 2 of the License). |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
|
| 21 |
#undef i386 |
| 22 |
|
| 23 |
.text |
| 24 |
.globl purgatory_start |
| 25 |
purgatory_start: |
| 26 |
.code32 |
| 27 |
.arch i386 |
| 28 |
|
| 29 |
/* Load a gdt so I know what the segment registers are */ |
| 30 |
lgdt %cs:gdt |
| 31 |
|
| 32 |
/* load the data segments */ |
| 33 |
movl $0x08, %eax /* data segment */ |
| 34 |
movl %eax, %ds |
| 35 |
movl %eax, %es |
| 36 |
movl %eax, %ss |
| 37 |
movl %eax, %fs |
| 38 |
movl %eax, %gs |
| 39 |
|
| 40 |
/* load the code segment */ |
| 41 |
ljmp $0x10,$1f |
| 42 |
1: |
| 43 |
|
| 44 |
movl 0(%esp), %eax |
| 45 |
movl %eax, jump_back_entry |
| 46 |
|
| 47 |
/* Setup a stack */ |
| 48 |
movl $lstack_end, %esp |
| 49 |
|
| 50 |
/* Call the C code */ |
| 51 |
call purgatory |
| 52 |
jmp entry32 |
| 53 |
|
| 54 |
.section ".rodata" |
| 55 |
.balign 16 |
| 56 |
gdt: |
| 57 |
/* 0x00 unusable segment so used as the gdt ptr */ |
| 58 |
.word gdt_end - gdt - 1 |
| 59 |
.long gdt |
| 60 |
.word 0 |
| 61 |
|
| 62 |
/* 0x8 4GB flat data segment */ |
| 63 |
.word 0xFFFF, 0x0000, 0x9200, 0x00CF |
| 64 |
|
| 65 |
/* 0x10 4GB flat code segment */ |
| 66 |
.word 0xFFFF, 0x0000, 0x9A00, 0x00CF |
| 67 |
gdt_end: |
| 68 |
|
| 69 |
/* A stack for the purgatory code */ |
| 70 |
.bss |
| 71 |
.balign 4096 |
| 72 |
lstack: |
| 73 |
.skip 4096 |
| 74 |
lstack_end: |
| 75 |
|