Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the code of chapter9/b has running error #3

Open
heilutan opened this issue Jan 14, 2015 · 0 comments
Open

the code of chapter9/b has running error #3

heilutan opened this issue Jan 14, 2015 · 0 comments

Comments

@heilutan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant