Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented low level disk functionality in C
- Loading branch information
1 parent
4d9f9a6
commit 7d35fb9
Showing
6 changed files
with
43 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include "io/io.h" | ||
int disk_read_sector(int lba, int total, void* buf) | ||
{ | ||
outb(0x1F6, (lba >> 24) | 0xE0); | ||
outb(0x1F2, total); | ||
outb(0x1F3, (unsigned char)(lba & 0xff)); | ||
outb(0x1F4, (unsigned char)(lba >> 8)); | ||
outb(0x1F5, (unsigned char)(lba >> 16)); | ||
outb(0x1F7, 0x20); | ||
|
||
unsigned short* ptr = (unsigned short*) buf; | ||
for (int b = 0; b < total; b++) | ||
{ | ||
// Wait for the buffer to be ready | ||
char c = insb(0x1F7); | ||
while(!(c & 0x08)) | ||
{ | ||
c = insb(0x1F7); | ||
} | ||
|
||
// Copy from hard disk to memory | ||
for (int i = 0; i < 256; i++) | ||
{ | ||
*ptr = insw(0x1F0); | ||
ptr++; | ||
} | ||
|
||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef DISK_H | ||
#define DISK_H | ||
|
||
int disk_read_sector(int lba, int total, void* buf); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
section .asm | ||
|
||
global insb | ||
global insws | ||
global insw | ||
global outb | ||
global outw | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters