source: mainline/kernel/arch/ia32/src/vreg.c@ 2214382

Last change on this file since 2214382 was 482f968, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

Make FRAME_HIGHMEM fall back to low memory on failure.

Which is what existing users of it are doing, and there is no reason
not to as far as I can see.

Also make sure calls to frame_alloc all have either FRAME_LOWMEM or
FRAME_HIGHMEM explicitly set, as appropriate.

  • Property mode set to 100644
File size: 2.6 KB
RevLine 
[d6f9fff]1/*
2 * Copyright (c) 2016 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[c5429fe]29/** @addtogroup kernel_ia32
[d6f9fff]30 * @{
31 */
32/** @file
33 */
34
35#include <arch/vreg.h>
36#include <arch/pm.h>
37#include <config.h>
38#include <typedefs.h>
39#include <arch/asm.h>
40#include <panic.h>
41#include <mm/km.h>
42#include <mm/frame.h>
43
44/*
45 * During initialization, we need to make sure that context_save() and
46 * context_restore() touch some meaningful address when saving/restoring VREGs.
47 * When a processor is initialized, we set its GS base to a private page and
48 * vreg_ptr to zero.
49 */
50static uint32_t vreg_tp_dummy;
51uint32_t *vreg_ptr = &vreg_tp_dummy;
52
[b0e0140]53/**
54 * Allocate and initialize a per-CPU user page to be accessible via the GS
55 * segment register and to hold the virtual registers.
56 */
[d6f9fff]57void vreg_init(void)
58{
59 uintptr_t frame;
60 uint32_t *page;
61 descriptor_t *gdt_p = (descriptor_t *) gdtr.base;
62
63 frame = frame_alloc(1, FRAME_ATOMIC | FRAME_HIGHMEM, 0);
64 if (!frame)
65 panic("Cannot allocate VREG frame.");
66
[a1b9f63]67 page = (uint32_t *) km_map(frame, PAGE_SIZE, PAGE_SIZE,
[d6f9fff]68 PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
69
70 gdt_setbase(&gdt_p[VREG_DES], (uintptr_t) page);
71 gdt_setlimit(&gdt_p[VREG_DES], sizeof(uint32_t));
72
73 gs_load(GDT_SELECTOR(VREG_DES));
74
[1b20da0]75 vreg_ptr = NULL;
[d6f9fff]76}
77
78/** @}
79 */
Note: See TracBrowser for help on using the repository browser.