资源简介
重大软院操作系统实验四:虚拟内存,操作系统原理,linux
代码片段和文件信息
/**
* vim: filetype=c:fenc=utf-8:ts=4:et:sw=4:sts=4
*
* Copyright (C) 2005 2008 2013 Hong MingJian
* All rights reserved.
*
* This file is part of the EPOS.
*
* Redistribution and use in source and binary forms are freely
* permitted provided that the above copyright notice and this
* paragraph and the following disclaimer are duplicated in all
* such forms.
*
* This software is provided “AS IS“ and without any express or
* implied warranties including without limitation the implied
* warranties of merchantability and fitness for a particular
* purpose.
*
*/
#include “kernel.h“
#include “syscall-nr.h“
#include “multiboot.h“
#include “sem.h“ //第三次实验第一个小实验
#define IO_ICU1 0x20 /* 8259A Interrupt Controller #1 */
#define IO_ICU2 0xA0 /* 8259A Interrupt Controller #2 */
#define IRQ_SLAVE 0x04
#define ICU_SLAVEID 2
#define ICU_IMR_OFFSET 1 /* IO_ICU{12} + 1 */
/**
* 初始化i8259中断控制器
*/
static void init_i8259(uint8_t idt_offset)
{
outportb(IO_ICU1 0x11);//ICW1
outportb(IO_ICU1+ICU_IMR_OFFSET idt_offset); //ICW2
outportb(IO_ICU1+ICU_IMR_OFFSET IRQ_SLAVE); //ICW3
outportb(IO_ICU1+ICU_IMR_OFFSET 1); //ICW4
outportb(IO_ICU1+ICU_IMR_OFFSET 0xff); //OCW1
outportb(IO_ICU1 0x0a); //OCW3
outportb(IO_ICU2 0x11); //ICW1
outportb(IO_ICU2+ICU_IMR_OFFSET idt_offset+8); //ICW2
outportb(IO_ICU2+ICU_IMR_OFFSET ICU_SLAVEID); //ICW3
outportb(IO_ICU2+ICU_IMR_OFFSET1); //ICW4
outportb(IO_ICU2+ICU_IMR_OFFSET 0xff); //OCW1
outportb(IO_ICU2 0x0a); //OCW3
}
/**
* 初始化i8253定时器
*/
static void init_i8253(uint32_t freq)
{
uint16_t latch = 1193182/freq;
outportb(0x43 0x36);
outportb(0x40 latch&0xff);
outportb(0x40 (latch&0xff00)>>16);
}
/**
* 让中断控制器打开某个中断
*/
void enable_irq(uint32_t irq)
{
uint8_t val;
if(irq < 8){
val = inportb(IO_ICU1+ICU_IMR_OFFSET);
outportb(IO_ICU1+ICU_IMR_OFFSET val & (~(1< } else if(irq < NR_IRQ) {
irq -= 8;
val = inportb(IO_ICU2+ICU_IMR_OFFSET);
outportb(IO_ICU2+ICU_IMR_OFFSET val & (~(1< }
}
/**
* 让中断控制器关闭某个中断
*/
void disable_irq(uint32_t irq)
{
uint8_t val;
if(irq < 8) {
val = inportb(IO_ICU1+ICU_IMR_OFFSET);
outportb(IO_ICU1+ICU_IMR_OFFSET val | (1< } else if(irq < NR_IRQ) {
irq -= 8;
val = inportb(IO_ICU2+ICU_IMR_OFFSET);
outportb(IO_ICU2+ICU_IMR_OFFSET val | (1< }
}
/**
* 把CPU从当前线程切换去运行线程new,即上下文切换(Context switch)
*/
void switch_to(struct tcb *new)
{
__asm__ __volatile__ (
“pushal\n\t“
“pushl $1f\n\t“
“movl %0 %%eax\n\t“
“movl %%esp (%%eax)\n\t“
“addl $36 %%esp\n\t“
:
:“m“(g_task_running)
:“%eax“
);
g_task_running = new;
__asm__ __volat
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2015-12-18 21:47 操作系统实验四\
目录 0 2015-12-18 21:45 操作系统实验四\epos\
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\
文件 3 2015-12-10 20:51 操作系统实验四\epos\.svn\entries
文件 3 2015-12-10 20:51 操作系统实验四\epos\.svn\format
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\01\
文件 14952 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\01\0133bbeec07642e1ed0e38e0a078ee3a3d98fd57.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\02\
文件 8291 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\02\02b0b9520f366c7c15371b07d890ebb5d0e21630.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\17\
文件 1681 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\17\17f230794300383a59af8bae05af6784b4c574db.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\25\
文件 9978 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\25\25472e8d3d2d167b88052ef819efadb3f8e5f80b.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\2a\
文件 1440 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\2a\2a6d7a3d08da647a64cbfba8395d554f9bcba8e2.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\2b\
文件 19393 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\2b\2b73b7375502d4e255039c92d0bd3c88bc49a40c.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\33\
文件 1623 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\33\33584bc8892e89b501e8074affdc42b96d99bda8.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\42\
文件 1466 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\42\42909b6fd8431fbb602ee250f2de562717e97b06.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\43\
文件 181 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\43\432d8e098dda89b4b9caa96a8d2ccf7d30f58bcc.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\5c\
文件 7265 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\5c\5c3a40940b6cdc9bc91eecadec883c53b3a5c729.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\5f\
文件 2777 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\5f\5fab13ea12f18c47a915f375016e3be95dbb236b.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\63\
文件 450 2015-12-10 20:51 操作系统实验四\epos\.svn\pristine\63\6347bbb9f7252ab8038b9a0735717a569fbcf242.svn-ba
目录 0 2015-12-18 21:45 操作系统实验四\epos\.svn\pristine\6c\
............此处省略119个文件信息
评论
共有 条评论