GithubHelp home page GithubHelp logo

osfs00's Introduction

Operating System From Scratch

This is not one project. This is a project series. Following these steps, you'll see how to write your own Operating System from scratch:

There are many ways to learn OS, but I believe the best way is to learn by practice. There are many open source OS code, but the code bases are huge. You will get lost in the source code labyrinth.

There are good books, Operating System: Design and Implementation by A.S. Tanenbaum and A.S. Woodhull for example, but they don't teach you where to begin either.

That's why you should come here. If Tanenbaum's book is a reference, my project series is a tutorial. Prof. Tanenbaum tells you what. I'll tell you how.

Click here to begin your OS journey.

osfs00's People

Contributors

yyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

osfs00's Issues

the code of chapter9/b has running error

Run the code of chapter9/b, you will find the tty print the follow message:

Exception! --> #UD Invalid Opcode (Undefined Opcode)

EFLAGS:0x11202CS:0x5EIP:0x34976

BaseAddrL BaseAddrH LengthLow LengthHigh Type
00000000h 00000000h 0009FC00h 00000000h 00000001h
0009FC00h 00000000h 00000400h 00000000h 00000002h
000E8000h 00000000h 00018000h 00000000h 00000002h
00100000h 00000000h 01EF0000h 00000000h 00000001h
01FF0000h 00000000h 00010000h 00000000h 00000003h
FFFC0000h 00000000h 00040000h 00000000h 00000002h

RAM size:01FF0000h
-----"cstart" begins-----
-----"cstart" finished-----
-----"kernel_main" begins-----
NrDrives:1.
Task FS begins.

But the right message should be like this:

Booting ............
Ready.

Loading ......................................................................
Ready.

BaseAddrL BaseAddrH LengthLow LengthHigh Type
00000000h 00000000h 0009FC00h 00000000h 00000001h
0009FC00h 00000000h 00000400h 00000000h 00000002h
000E8000h 00000000h 00018000h 00000000h 00000002h
00100000h 00000000h 01EF0000h 00000000h 00000001h
01FF0000h 00000000h 00010000h 00000000h 00000003h
FFFC0000h 00000000h 00040000h 00000000h 00000002h

RAM size:01FF0000h
-----"cstart" begins-----
-----"cstart" finished-----
-----"kernel_main" begins-----
NrDrives:1.
Task FS begins.
HD SN: BXHD00011
HD Model: Generic 1234
LBA supported: Yes
LBA48 supported: Yes
HD size: 83MB
PART_0: base 0(0x0), size 163296(0x27DE0) (in sector)
PART_1: base 63(0x3F), size 20097(0x4E81) (in sector)
PART_2: base 20160(0x4EC0), size 143136(0x22F20) (in sector)
PART_3: base 0(0x0), size 0(0x0) (in sector)
PART_4: base 0(0x0), size 0(0x0) (in sector)
16: base 20223(0x4EFF), size 40257(0x9D41) (in sector)
17: base 60543(0xEC7F), size 30177(0x75E1) (in sector)
18: base 90783(0x1629F), size 42273(0xA521) (in sector)
19: base 133119(0x207FF), size 28161(0x6E01) (in sector)
20: base 161343(0x2763F), size 1953(0x7A1) (in sector)

spinning in FS ...

Then I located the error, hd.c is the hard disk driver program.
task_hd() is the main loop of HD driver, it invoke the init_hd() to initialize the hard disk where will print NrDrives: 1.
After the init_hd() finished, instructions will come to hd_open(), then I go into the hd_open(). Before the "int drive = DRV_OF_DEV(device)", I put printl(), it works. But after the "int drive = DRV_OF_DEV(device)", I put printl(), it didn't work. So the location of error is here.
As you can see, DRV_OF_DEV(device) is a macro define, if the value of device is 0x20, the result of DRV_OF_DEV(0x20) will be 0. Then I replace the device with 0x20, the program runs well. It's odd, isn't it?
If I modify the DRV_OF_DEV(dev) like this:

define DRV_OF_DEV(dev) (dev <= MAX_PRIM ? dev / NR_PRIM_PER_DRIVE : (dev - MINOR_hd1a) / (NR_SUB_PER_DRIVE - 1))

the program runs well.The same condition lies in the chapter9/c, chapter9/d ...

After modified this bug, a new error happened in chapter9/d, tty print message like this:
Booting ............
Ready.

Loading ......................................................................
Ready.

BaseAddrL BaseAddrH LengthLow LengthHigh Type
00000000h 00000000h 0009FC00h 00000000h 00000001h
0009FC00h 00000000h 00000400h 00000000h 00000002h
000E8000h 00000000h 00018000h 00000000h 00000002h
00100000h 00000000h 01EF0000h 00000000h 00000001h
01FF0000h 00000000h 00010000h 00000000h 00000003h
FFFC0000h 00000000h 00040000h 00000000h 00000002h

RAM size:01FF0000h
-----"cstart" begins-----
-----"cstart" finished-----
-----"kernel_main" begins-----
NrDrives:1.
Task FS begins.
HD SN: BXHD00011
HD Model: Generic 1234
LBA supported: Yes
LBA48 supported: Yes
HD size: 83MB
PART_0: base 0(0x0), size 163296(0x27DE0) (in sector)
PART_1: base 63(0x3F), size 20097(0x4E81) (in sector)
PART_2: base 20160(0x4EC0), size 143136(0x22F20) (in sector)
PART_3: base 0(0x0), size 0(0x0) (in sector)
PART_4: base 0(0x0), size 0(0x0) (in sector)
16: base 20223(0x4EFF), size 40257(0x9D41) (in sector)
17: base 60543(0xEC7F), size 30177(0x75E1) (in sector)
18: base 90783(0x1629F), size 42273(0xA521) (in sector)
19: base 133119(0x207FF), size 28161(0x6E01) (in sector)
20: base 161343(0x2763F), size 1953(0x7A1) (in sector)
dev size: 0x9D41 sectors
But the right message should be like this:
Booting ............
Ready.

Loading ......................................................................
Ready.

BaseAddrL BaseAddrH LengthLow LengthHigh Type
00000000h 00000000h 0009FC00h 00000000h 00000001h
0009FC00h 00000000h 00000400h 00000000h 00000002h
000E8000h 00000000h 00018000h 00000000h 00000002h
00100000h 00000000h 01EF0000h 00000000h 00000001h
01FF0000h 00000000h 00010000h 00000000h 00000003h
FFFC0000h 00000000h 00040000h 00000000h 00000002h

RAM size:01FF0000h
-----"cstart" begins-----
-----"cstart" finished-----
-----"kernel_main" begins-----
NrDrives:1.
Task FS begins.
HD SN: BXHD00011
HD Model: Generic 1234
LBA supported: Yes
LBA48 supported: Yes
HD size: 83MB
PART_0: base 0(0x0), size 163296(0x27DE0) (in sector)
PART_1: base 63(0x3F), size 20097(0x4E81) (in sector)
PART_2: base 20160(0x4EC0), size 143136(0x22F20) (in sector)
PART_3: base 0(0x0), size 0(0x0) (in sector)
PART_4: base 0(0x0), size 0(0x0) (in sector)
16: base 20223(0x4EFF), size 40257(0x9D41) (in sector)
17: base 60543(0xEC7F), size 30177(0x75E1) (in sector)
18: base 90783(0x1629F), size 42273(0xA521) (in sector)
19: base 133119(0x207FF), size 28161(0x6E01) (in sector)
20: base 161343(0x2763F), size 1953(0x7A1) (in sector)
dev size: 0x9D41 sectors devbase:0x9DFE00, sb:0x9E0000, imap:0x9E0200, smap:0x9E0400
inodes:0x9E1800, 1st_sector:0xA01800
spinning in FS ...

This time I locate the error from chapter9/d/fs/main.c, in this file you will see task_fs() is the main loop of TASK FS, In the task_fs(), it invokes init_fs(). In the init_fs(), it invokes send_recv(BOTH, dd_map[MAJOR(ROOT_DEV)].driver, &driver_msg). In the send_recv(), it invokes sendrec(). In the sendrec(), it invokes sys_sendrec(). In the sys_sendrec(), it invokes msg_receive(). msg_receive() is the last function which be invoked, and it returns 0. After msg_receive() has returned, the sys_sendrec() return. But after sys_sendrec() return, sendrec() didn't return, I don't know why.
I want to know why the program stop in the sendrec() function and it cannot return.

关于章节4 bootloader 的问题

.../chapter4/c/boot.asm
这里面加载loader前 bootloader 自身能不能先移动自身到其他位置
然后跳转到其他位置继续执行,最后完成加载loader的任务?
比如 将bootloader从 0x7c00h 移动到 0x0600h
长跳转到0x0600h 之后
再将loader 加载并覆盖到 0x7c00h的位置
最后长跳转到0x7c00h 开始执行loader的代码

the code of chapter9/b have running error

run the code of chapter9/b, you will find the tty print the follow message.

Exception! --> #UD Invalid Opcode (Undefined Opcode)

EFLAGS:0x11202CS:0x5EIP:0x34976

BaseAddrL BaseAddrH LengthLow LengthHigh Type
00000000h 00000000h 0009FC00h 00000000h 00000001h
0009FC00h 00000000h 00000400h 00000000h 00000002h
000E8000h 00000000h 00018000h 00000000h 00000002h
00100000h 00000000h 01EF0000h 00000000h 00000001h
01FF0000h 00000000h 00010000h 00000000h 00000003h
FFFC0000h 00000000h 00040000h 00000000h 00000002h

RAM size:01FF0000h
-----"cstart" begins-----
-----"cstart" finished-----
-----"kernel_main" begins-----
NrDrives:1.
Task FS begins.

+-

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.