⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdt.c

📁 一个微型操作系统源码
💻 C
字号:
/* * OSV * Copyright (C) 2002 Ciprian DOSOFTEI <rocksoul@mail.com> * All rights reserved. *  * http://backster.free.fr/osv * * This file is part of the OSV project. OSV is free software, also known as * "open source"; you can redistribute it and/or modify it under the terms  * of the GNU General Public License (GPL), version 2, as published by the Free * Software Foundation (FSF). To explore alternate licensing terms, contact  * the author at rocksoul@mail.com or +40740649907. *  * OSV is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE.  See the GPL for more details.  You should have * received a copy of the GPL along with OSV; see the file COPYING.  If * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA. */#include <gdt.h>descriptor *GDT = (descriptor *)0;void setupGDT(void) {    dword GDTR[2];    memset((void *)GDT, 0, GDT_SIZE * sizeof(descriptor));    setupDescriptor(&GDT[1], 0, LIMIT_4GB, 8, 0, 1, 1); /* 0x08 -- KERNEL CODE */    setupDescriptor(&GDT[2], 0, LIMIT_4GB, 2, 0, 1, 1); /* 0x10 -- KERNEL DATA */    setupDescriptor(&GDT[3], 0, LIMIT_4GB, 8, 3, 1, 1); /* 0x1B -- USER CODE */    setupDescriptor(&GDT[4], 0, LIMIT_4GB, 2, 3, 1, 1); /* 0x23 -- USER DATA */    GDTR[0] = ((GDT_SIZE * sizeof(descriptor)) - 1) << 16;    GDTR[1] = (dword)GDT;    __asm__ __volatile__("lgdt (%0)" : : "r" (((byte *)GDTR) + 2));    __asm__ __volatile__("ljmp $8, $__flush\n"          "__flush:");    __asm__ __volatile__("movl $0x10, %eax\n"          "movw %ax, %ss\n"          "movl $0x23, %eax\n"          "movw %ax, %ds\n"          "movw %ax, %es\n"          "movw %ax, %fs\n"          "movw %ax, %gs");}void setupDescriptor(descriptor *d, dword base, dword limit, byte type, byte dpl, byte s, byte db) {    if (limit > LIMIT_1MB) {	limit = limit >> 12;        d->g = 1;    } else d->g = 0;    d->base0_15 = base;    d->base16_23 = base >> 16;    d->base24_31 = base >> 24;    d->limit0_15 = limit;    d->limit16_19 = limit >> 16;    d->type = type;    d->s = s;    d->dpl = dpl;    d->p = 1;    d->avl = 0;    d->zero = 0;    d->db = db;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -