OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [arch/] [x86_64/] [kernel/] [acpi_wakeup.S] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
.text
2
#include 
3
#include 
4
#include 
5
#include 
6
 
7
# Copyright 2003 Pavel Machek , distribute under GPLv2
8
#
9
# wakeup_code runs in real mode, and at unknown address (determined at run-time).
10
# Therefore it must only use relative jumps/calls.
11
#
12
# Do we need to deal with A20? It is okay: ACPI specs says A20 must be enabled
13
#
14
# If physical address of wakeup_code is 0x12345, BIOS should call us with
15
# cs = 0x1234, eip = 0x05
16
#
17
 
18
 
19
ALIGN
20
        .align  16
21
ENTRY(wakeup_start)
22
wakeup_code:
23
        wakeup_code_start = .
24
        .code16
25
 
26
# Running in *copy* of this code, somewhere in low 1MB.
27
 
28
        movb    $0xa1, %al      ;  outb %al, $0x80
29
        cli
30
        cld
31
        # setup data segment
32
        movw    %cs, %ax
33
        movw    %ax, %ds                                        # Make ds:0 point to wakeup_start
34
        movw    %ax, %ss
35
        mov     $(wakeup_stack - wakeup_code), %sp              # Private stack is needed for ASUS board
36
 
37
        pushl   $0                                              # Kill any dangerous flags
38
        popfl
39
 
40
        movl    real_magic - wakeup_code, %eax
41
        cmpl    $0x12345678, %eax
42
        jne     bogus_real_magic
43
 
44
        lcall   $0xc000,$3
45
 
46
        movw    $0xb800, %ax
47
        movw    %ax,%fs
48
        movw    $0x0e00 + 'L', %fs:(0x10)
49
 
50
        movb    $0xa2, %al      ;  outb %al, $0x80
51
 
52
        lidt    %ds:idt_48a - wakeup_code
53
        xorl    %eax, %eax
54
        movw    %ds, %ax                        # (Convert %ds:gdt to a linear ptr)
55
        shll    $4, %eax
56
        addl    $(gdta - wakeup_code), %eax
57
        movl    %eax, gdt_48a +2 - wakeup_code
58
        lgdt    %ds:gdt_48a - wakeup_code               # load gdt with whatever is
59
                                                # appropriate
60
 
61
        movl    $1, %eax                        # protected mode (PE) bit
62
        lmsw    %ax                             # This is it!
63
        jmp     1f
64
1:
65
 
66
        .byte 0x66, 0xea                        # prefix + jmpi-opcode
67
        .long   wakeup_32 - __START_KERNEL_map
68
        .word   __KERNEL_CS
69
 
70
        .code32
71
wakeup_32:
72
# Running in this code, but at low address; paging is not yet turned on.
73
        movb    $0xa5, %al      ;  outb %al, $0x80
74
 
75
        /* Check if extended functions are implemented */
76
        movl    $0x80000000, %eax
77
        cpuid
78
        cmpl    $0x80000000, %eax
79
        jbe     bogus_cpu
80
        wbinvd
81
        mov     $0x80000001, %eax
82
        cpuid
83
        btl     $29, %edx
84
        jnc     bogus_cpu
85
        movl    %edx,%edi
86
 
87
        movw    $__KERNEL_DS, %ax
88
        movw    %ax, %ds
89
        movw    %ax, %es
90
        movw    %ax, %fs
91
        movw    %ax, %gs
92
 
93
        movw    $__KERNEL_DS, %ax
94
        movw    %ax, %ss
95
 
96
        mov     $(wakeup_stack - __START_KERNEL_map), %esp
97
        movl    saved_magic - __START_KERNEL_map, %eax
98
        cmpl    $0x9abcdef0, %eax
99
        jne     bogus_32_magic
100
 
101
        /*
102
         * Prepare for entering 64bits mode
103
         */
104
 
105
        /* Enable PAE mode and PGE */
106
        xorl    %eax, %eax
107
        btsl    $5, %eax
108
        btsl    $7, %eax
109
        movl    %eax, %cr4
110
 
111
        /* Setup early boot stage 4 level pagetables */
112
        movl    $(wakeup_level4_pgt - __START_KERNEL_map), %eax
113
        movl    %eax, %cr3
114
 
115
        /* Setup EFER (Extended Feature Enable Register) */
116
        movl    $MSR_EFER, %ecx
117
        rdmsr
118
        /* Fool rdmsr and reset %eax to avoid dependences */
119
        xorl    %eax, %eax
120
        /* Enable Long Mode */
121
        btsl    $_EFER_LME, %eax
122
        /* Enable System Call */
123
        btsl    $_EFER_SCE, %eax
124
 
125
        /* No Execute supported? */
126
        btl     $20,%edi
127
        jnc     1f
128
        btsl    $_EFER_NX, %eax
129
1:
130
 
131
        /* Make changes effective */
132
        wrmsr
133
        wbinvd
134
 
135
        xorl    %eax, %eax
136
        btsl    $31, %eax                       /* Enable paging and in turn activate Long Mode */
137
        btsl    $0, %eax                        /* Enable protected mode */
138
        btsl    $1, %eax                        /* Enable MP */
139
        btsl    $4, %eax                        /* Enable ET */
140
        btsl    $5, %eax                        /* Enable NE */
141
        btsl    $16, %eax                       /* Enable WP */
142
        btsl    $18, %eax                       /* Enable AM */
143
 
144
        /* Make changes effective */
145
        movl    %eax, %cr0
146
        /* At this point:
147
                CR4.PAE must be 1
148
                CS.L must be 0
149
                CR3 must point to PML4
150
                Next instruction must be a branch
151
                This must be on identity-mapped page
152
        */
153
        jmp     reach_compatibility_mode
154
reach_compatibility_mode:
155
        movw    $0x0e00 + 'i', %ds:(0xb8012)
156
        movb    $0xa8, %al      ;  outb %al, $0x80;
157
 
158
        /*
159
         * At this point we're in long mode but in 32bit compatibility mode
160
         * with EFER.LME = 1, CS.L = 0, CS.D = 1 (and in turn
161
         * EFER.LMA = 1). Now we want to jump in 64bit mode, to do that we load
162
         * the new gdt/idt that has __KERNEL_CS with CS.L = 1.
163
         */
164
 
165
        movw    $0x0e00 + 'n', %ds:(0xb8014)
166
        movb    $0xa9, %al      ;  outb %al, $0x80
167
 
168
        /* Load new GDT with the 64bit segment using 32bit descriptor */
169
        movl    $(pGDT32 - __START_KERNEL_map), %eax
170
        lgdt    (%eax)
171
 
172
        movl    $(wakeup_jumpvector - __START_KERNEL_map), %eax
173
        /* Finally jump in 64bit mode */
174
        ljmp    *(%eax)
175
 
176
wakeup_jumpvector:
177
        .long   wakeup_long64 - __START_KERNEL_map
178
        .word   __KERNEL_CS
179
 
180
.code64
181
 
182
        /*      Hooray, we are in Long 64-bit mode (but still running in low memory) */
183
wakeup_long64:
184
        /*
185
         * We must switch to a new descriptor in kernel space for the GDT
186
         * because soon the kernel won't have access anymore to the userspace
187
         * addresses where we're currently running on. We have to do that here
188
         * because in 32bit we couldn't load a 64bit linear address.
189
         */
190
        lgdt    pGDT64 - __START_KERNEL_map
191
 
192
        movw    $0x0e00 + 'u', %ds:(0xb8016)
193
 
194
        nop
195
        nop
196
        movw    $__KERNEL_DS, %ax
197
        movw    %ax, %ss
198
        movw    %ax, %ds
199
        movw    %ax, %es
200
        movw    %ax, %fs
201
        movw    %ax, %gs
202
        movq    saved_esp, %rsp
203
 
204
        movw    $0x0e00 + 'x', %ds:(0xb8018)
205
        movq    saved_ebx, %rbx
206
        movq    saved_edi, %rdi
207
        movq    saved_esi, %rsi
208
        movq    saved_ebp, %rbp
209
 
210
        movw    $0x0e00 + '!', %ds:(0xb801a)
211
        movq    saved_eip, %rax
212
        jmp     *%rax
213
 
214
.code32
215
 
216
        .align  64
217
gdta:
218
        .word   0, 0, 0, 0                      # dummy
219
 
220
        .word   0, 0, 0, 0                      # unused
221
 
222
        .word   0xFFFF                          # 4Gb - (0x100000*0x1000 = 4Gb)
223
        .word   0                                # base address = 0
224
        .word   0x9B00                          # code read/exec. ??? Why I need 0x9B00 (as opposed to 0x9A00 in order for this to work?)
225
        .word   0x00CF                          # granularity = 4096, 386
226
                                                #  (+5th nibble of limit)
227
 
228
        .word   0xFFFF                          # 4Gb - (0x100000*0x1000 = 4Gb)
229
        .word   0                                # base address = 0
230
        .word   0x9200                          # data read/write
231
        .word   0x00CF                          # granularity = 4096, 386
232
                                                #  (+5th nibble of limit)
233
# this is 64bit descriptor for code
234
        .word   0xFFFF
235
        .word   0
236
        .word   0x9A00                          # code read/exec
237
        .word   0x00AF                          # as above, but it is long mode and with D=0
238
 
239
idt_48a:
240
        .word   0                                # idt limit = 0
241
        .word   0, 0                            # idt base = 0L
242
 
243
gdt_48a:
244
        .word   0x8000                          # gdt limit=2048,
245
                                                #  256 GDT entries
246
        .word   0, 0                            # gdt base (filled in later)
247
 
248
 
249
real_save_gdt:  .word 0
250
                .quad 0
251
real_magic:     .quad 0
252
video_mode:     .quad 0
253
 
254
bogus_real_magic:
255
        movb    $0xba,%al       ;  outb %al,$0x80
256
        jmp bogus_real_magic
257
 
258
bogus_32_magic:
259
        movb    $0xb3,%al       ;  outb %al,$0x80
260
        jmp bogus_32_magic
261
 
262
bogus_31_magic:
263
        movb    $0xb1,%al       ;  outb %al,$0x80
264
        jmp bogus_31_magic
265
 
266
bogus_cpu:
267
        movb    $0xbc,%al       ;  outb %al,$0x80
268
        jmp bogus_cpu
269
 
270
 
271
/* This code uses an extended set of video mode numbers. These include:
272
 * Aliases for standard modes
273
 *      NORMAL_VGA (-1)
274
 *      EXTENDED_VGA (-2)
275
 *      ASK_VGA (-3)
276
 * Video modes numbered by menu position -- NOT RECOMMENDED because of lack
277
 * of compatibility when extending the table. These are between 0x00 and 0xff.
278
 */
279
#define VIDEO_FIRST_MENU 0x0000
280
 
281
/* Standard BIOS video modes (BIOS number + 0x0100) */
282
#define VIDEO_FIRST_BIOS 0x0100
283
 
284
/* VESA BIOS video modes (VESA number + 0x0200) */
285
#define VIDEO_FIRST_VESA 0x0200
286
 
287
/* Video7 special modes (BIOS number + 0x0900) */
288
#define VIDEO_FIRST_V7 0x0900
289
 
290
# Setting of user mode (AX=mode ID) => CF=success
291
mode_seta:
292
        movw    %ax, %bx
293
#if 0
294
        cmpb    $0xff, %ah
295
        jz      setalias
296
 
297
        testb   $VIDEO_RECALC>>8, %ah
298
        jnz     _setrec
299
 
300
        cmpb    $VIDEO_FIRST_RESOLUTION>>8, %ah
301
        jnc     setres
302
 
303
        cmpb    $VIDEO_FIRST_SPECIAL>>8, %ah
304
        jz      setspc
305
 
306
        cmpb    $VIDEO_FIRST_V7>>8, %ah
307
        jz      setv7
308
#endif
309
 
310
        cmpb    $VIDEO_FIRST_VESA>>8, %ah
311
        jnc     check_vesaa
312
#if 0
313
        orb     %ah, %ah
314
        jz      setmenu
315
#endif
316
 
317
        decb    %ah
318
#       jz      setbios                           Add bios modes later
319
 
320
setbada:        clc
321
        ret
322
 
323
check_vesaa:
324
        subb    $VIDEO_FIRST_VESA>>8, %bh
325
        orw     $0x4000, %bx                    # Use linear frame buffer
326
        movw    $0x4f02, %ax                    # VESA BIOS mode set call
327
        int     $0x10
328
        cmpw    $0x004f, %ax                    # AL=4f if implemented
329
        jnz     _setbada                                # AH=0 if OK
330
 
331
        stc
332
        ret
333
 
334
_setbada: jmp setbada
335
 
336
        .code64
337
bogus_magic:
338
        movw    $0x0e00 + 'B', %ds:(0xb8018)
339
        jmp bogus_magic
340
 
341
bogus_magic2:
342
        movw    $0x0e00 + '2', %ds:(0xb8018)
343
        jmp bogus_magic2
344
 
345
 
346
wakeup_stack_begin:     # Stack grows down
347
 
348
.org    0xff0
349
wakeup_stack:           # Just below end of page
350
 
351
ENTRY(wakeup_end)
352
 
353
##
354
# acpi_copy_wakeup_routine
355
#
356
# Copy the above routine to low memory.
357
#
358
# Parameters:
359
# %rdi: place to copy wakeup routine to
360
#
361
# Returned address is location of code in low memory (past data and stack)
362
#
363
ENTRY(acpi_copy_wakeup_routine)
364
        pushq   %rax
365
        pushq   %rcx
366
        pushq   %rdx
367
 
368
        sgdt    saved_gdt
369
        sidt    saved_idt
370
        sldt    saved_ldt
371
        str     saved_tss
372
 
373
        movq    %cr3, %rdx
374
        movq    %rdx, saved_cr3
375
        movq    %cr4, %rdx
376
        movq    %rdx, saved_cr4
377
        movq    %cr0, %rdx
378
        movq    %rdx, saved_cr0
379
        sgdt    real_save_gdt - wakeup_start (,%rdi)
380
        movl    $MSR_EFER, %ecx
381
        rdmsr
382
        movl    %eax, saved_efer
383
        movl    %edx, saved_efer2
384
 
385
#       movq    saved_videomode, %rdx                           # FIXME:         videomode
386
        movq    %rdx, video_mode - wakeup_start (,%rdi)
387
        movq    $0x12345678, real_magic - wakeup_start (,%rdi)
388
        movq    $0x123456789abcdef0, %rdx
389
        movq    %rdx, saved_magic
390
 
391
        movl    saved_magic - __START_KERNEL_map, %eax
392
        cmpl    $0x9abcdef0, %eax
393
        jne     bogus_32_magic
394
 
395
        # make sure %cr4 is set correctly (features, etc)
396
        movl    saved_cr4 - __START_KERNEL_map, %eax
397
        movq    %rax, %cr4
398
 
399
        movl    saved_cr0 - __START_KERNEL_map, %eax
400
        movq    %rax, %cr0
401
        jmp     1f              # Flush pipelines
402
1:
403
        # restore the regs we used
404
        popq    %rdx
405
        popq    %rcx
406
        popq    %rax
407
ENTRY(do_suspend_lowlevel_s4bios)
408
        ret
409
 
410
        .align 2
411
        .p2align 4,,15
412
.globl do_suspend_lowlevel
413
        .type   do_suspend_lowlevel,@function
414
do_suspend_lowlevel:
415
.LFB5:
416
        subq    $8, %rsp
417
.LCFI2:
418
        testl   %edi, %edi
419
        jne     .L99
420
        xorl    %eax, %eax
421
        call    save_processor_state
422
 
423
        movq %rsp, saved_context_esp(%rip)
424
        movq %rax, saved_context_eax(%rip)
425
        movq %rbx, saved_context_ebx(%rip)
426
        movq %rcx, saved_context_ecx(%rip)
427
        movq %rdx, saved_context_edx(%rip)
428
        movq %rbp, saved_context_ebp(%rip)
429
        movq %rsi, saved_context_esi(%rip)
430
        movq %rdi, saved_context_edi(%rip)
431
        movq %r8,  saved_context_r08(%rip)
432
        movq %r9,  saved_context_r09(%rip)
433
        movq %r10, saved_context_r10(%rip)
434
        movq %r11, saved_context_r11(%rip)
435
        movq %r12, saved_context_r12(%rip)
436
        movq %r13, saved_context_r13(%rip)
437
        movq %r14, saved_context_r14(%rip)
438
        movq %r15, saved_context_r15(%rip)
439
        pushfq ; popq saved_context_eflags(%rip)
440
 
441
        movq    $.L97, saved_eip(%rip)
442
 
443
        movq %rsp,saved_esp
444
        movq %rbp,saved_ebp
445
        movq %rbx,saved_ebx
446
        movq %rdi,saved_edi
447
        movq %rsi,saved_esi
448
 
449
        addq    $8, %rsp
450
        movl    $3, %edi
451
        xorl    %eax, %eax
452
        jmp     acpi_enter_sleep_state
453
.L97:
454
        .p2align 4,,7
455
.L99:
456
        .align 4
457
        movl    $24, %eax
458
        movw %ax, %ds
459
        movq    saved_context+58(%rip), %rax
460
        movq %rax, %cr4
461
        movq    saved_context+50(%rip), %rax
462
        movq %rax, %cr3
463
        movq    saved_context+42(%rip), %rax
464
        movq %rax, %cr2
465
        movq    saved_context+34(%rip), %rax
466
        movq %rax, %cr0
467
        pushq saved_context_eflags(%rip) ; popfq
468
        movq saved_context_esp(%rip), %rsp
469
        movq saved_context_ebp(%rip), %rbp
470
        movq saved_context_eax(%rip), %rax
471
        movq saved_context_ebx(%rip), %rbx
472
        movq saved_context_ecx(%rip), %rcx
473
        movq saved_context_edx(%rip), %rdx
474
        movq saved_context_esi(%rip), %rsi
475
        movq saved_context_edi(%rip), %rdi
476
        movq saved_context_r08(%rip), %r8
477
        movq saved_context_r09(%rip), %r9
478
        movq saved_context_r10(%rip), %r10
479
        movq saved_context_r11(%rip), %r11
480
        movq saved_context_r12(%rip), %r12
481
        movq saved_context_r13(%rip), %r13
482
        movq saved_context_r14(%rip), %r14
483
        movq saved_context_r15(%rip), %r15
484
 
485
        xorl    %eax, %eax
486
        addq    $8, %rsp
487
        jmp     restore_processor_state
488
.LFE5:
489
.Lfe5:
490
        .size   do_suspend_lowlevel,.Lfe5-do_suspend_lowlevel
491
 
492
.data
493
ALIGN
494
ENTRY(saved_ebp)        .quad   0
495
ENTRY(saved_esi)        .quad   0
496
ENTRY(saved_edi)        .quad   0
497
ENTRY(saved_ebx)        .quad   0
498
 
499
ENTRY(saved_eip)        .quad   0
500
ENTRY(saved_esp)        .quad   0
501
 
502
ENTRY(saved_magic)      .quad   0
503
 
504
ALIGN
505
# saved registers
506
saved_gdt:      .quad   0,0
507
saved_idt:      .quad   0,0
508
saved_ldt:      .quad   0
509
saved_tss:      .quad   0
510
 
511
saved_cr0:      .quad 0
512
saved_cr3:      .quad 0
513
saved_cr4:      .quad 0
514
saved_efer:     .quad 0
515
saved_efer2:    .quad 0

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.