资源简介
有些学校用的是操作系统概念这本书,然后实验是ucore实验。这里是详尽的lab答案
代码片段和文件信息
#include
#include
#include
/* *********************************************************************
* This a dirt simple boot loader whose sole job is to boot
* an ELF kernel image from the first IDE hard disk.
*
* DISK LAYOUT
* * This program(bootasm.S and bootmain.c) is the bootloader.
* It should be stored in the first sector of the disk.
*
* * The 2nd sector onward holds the kernel image.
*
* * The kernel image must be in ELF format.
*
* BOOT UP STEPS
* * when the CPU boots it loads the BIOS into memory and executes it
*
* * the BIOS intializes devices sets of the interrupt routines and
* reads the first sector of the boot device(e.g. hard-drive)
* into memory and jumps to it.
*
* * Assuming this boot loader is stored in the first sector of the
* hard-drive this code takes over...
*
* * control starts in bootasm.S -- which sets up protected mode
* and a stack so C code then run then calls bootmain()
*
* * bootmain() in this file takes over reads in the kernel and jumps to it.
* */
#define SECTSIZE 512
#define ELFHDR ((struct elfhdr *)0x10000) // scratch space
/* waitdisk - wait for disk ready */
static void
waitdisk(void) {
while ((inb(0x1F7) & 0xC0) != 0x40)
/* do nothing */;
}
/* readsect - read a single sector at @secno into @dst */
static void
readsect(void *dst uint32_t secno) {
// wait for disk to be ready
waitdisk();
outb(0x1F2 1); // count = 1
outb(0x1F3 secno & 0xFF);
outb(0x1F4 (secno >> 8) & 0xFF);
outb(0x1F5 (secno >> 16) & 0xFF);
outb(0x1F6 ((secno >> 24) & 0xF) | 0xE0);
outb(0x1F7 0x20); // cmd 0x20 - read sectors
// wait for disk to be ready
waitdisk();
// read a sector
insl(0x1F0 dst SECTSIZE / 4);
}
/* *
* readseg - read @count bytes at @offset from kernel into virtual address @va
* might copy more than asked.
* */
static void
readseg(uintptr_t va uint32_t count uint32_t offset) {
uintptr_t end_va = va + count;
// round down to sector boundary
va -= offset % SECTSIZE;
// translate from bytes to sectors; kernel starts at sector 1
uint32_t secno = (offset / SECTSIZE) + 1;
// If this is too slow we could read lots of sectors at a time.
// We‘d write more to memory than asked but it doesn‘t matter --
// we load in increasing order.
for (; va < end_va; va += SECTSIZE secno ++) {
readsect((void *)va secno);
}
}
/* bootmain - the entry of bootloader */
void
bootmain(void) {
// read the 1st page off disk
readseg((uintptr_t)ELFHDR SECTSIZE * 8 0);
// is this a valid ELF?
if (ELFHDR->e_magic != ELF_MAGIC) {
goto bad;
}
struct proghdr *ph *eph;
// load each program segment (ignores ph flags)
ph = (struct proghdr *)((uintptr_t)ELFHDR + ELFHDR->e_phoff);
eph = ph + ELFHDR->e_phnum;
for (; ph < eph; ph ++
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-09-28 16:25 mooc_os_lab-master\
文件 52 2014-09-28 16:25 mooc_os_lab-master\.gitignore
文件 20955 2014-09-28 16:25 mooc_os_lab-master\LICENSE
文件 5510 2014-09-28 16:25 mooc_os_lab-master\README
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\
文件 46 2014-09-28 16:25 mooc_os_lab-master\labcodes\autobuild.sh
文件 883 2014-09-28 16:25 mooc_os_lab-master\labcodes\autotest.sh
文件 344 2014-09-28 16:25 mooc_os_lab-master\labcodes\clangbuildall.sh
文件 216 2014-09-28 16:25 mooc_os_lab-master\labcodes\cleanall.sh
文件 264 2014-09-28 16:25 mooc_os_lab-master\labcodes\gccbuildall.sh
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\
文件 3834 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\.ycm_extra_conf.pyc
文件 7171 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\Makefile
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\boot\
文件 961 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\boot\asm.h
文件 3788 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\boot\bootasm.S
文件 3305 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\boot\bootmain.c
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\
文件 946 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\assert.h
文件 11563 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\kdebug.c
文件 217 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\kdebug.h
文件 3136 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\kmonitor.c
文件 351 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\kmonitor.h
文件 957 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\panic.c
文件 2155 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\debug\stab.h
目录 0 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\driver\
文件 1253 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\driver\clock.c
文件 178 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\driver\clock.h
文件 11830 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\driver\console.c
文件 222 2014-09-28 16:25 mooc_os_lab-master\labcodes\lab1\kern\driver\console.h
............此处省略1693个文件信息
- 上一篇:stl模型-机器小人-测试模型
- 下一篇:WireShark教程
评论
共有 条评论