Disable -Os; reformat ata.c.
This commit is contained in:
parent
f564a042d8
commit
e6dc668a3f
14
Makefile
14
Makefile
@ -8,12 +8,15 @@ GDB=x86_64-elf-gdb
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
|
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
|
||||||
-Os -Wall -MD -ggdb -m32 -Werror -fno-omit-frame-pointer
|
-Wall -ggdb -m32 -Werror -fno-omit-frame-pointer
|
||||||
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
||||||
|
|
||||||
run: image.bin
|
run: image.bin
|
||||||
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
|
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
|
||||||
|
|
||||||
|
run-nox: image.bin
|
||||||
|
qemu-system-i386 -nographic -drive format=raw,file=$< -serial mon:stdio
|
||||||
|
|
||||||
debug-preboot-nox: image.bin mbr.elf
|
debug-preboot-nox: image.bin mbr.elf
|
||||||
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
|
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
|
||||||
$(GDB) mbr.elf \
|
$(GDB) mbr.elf \
|
||||||
@ -36,6 +39,13 @@ debug: image.bin
|
|||||||
-ex "break _start" \
|
-ex "break _start" \
|
||||||
-ex "continue"
|
-ex "continue"
|
||||||
|
|
||||||
|
debug-nox: image.bin
|
||||||
|
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
|
||||||
|
$(GDB) kernel.bin \
|
||||||
|
-ex "target remote localhost:1234" \
|
||||||
|
-ex "break _start" \
|
||||||
|
-ex "continue"
|
||||||
|
|
||||||
fs.img: kernel.bin tools/mkfs user/false
|
fs.img: kernel.bin tools/mkfs user/false
|
||||||
tools/mkfs $@ $<
|
tools/mkfs $@ $<
|
||||||
|
|
||||||
@ -64,7 +74,7 @@ mbr.elf: mbr.o
|
|||||||
$(LD) -m elf_i386 -Ttext=0x7c00 $^ -o $@
|
$(LD) -m elf_i386 -Ttext=0x7c00 $^ -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.elf *.img *.bin *.o */*.o tools/mkfs
|
rm -f *.elf *.img *.bin *.o */*.o tools/mkfs user/false
|
||||||
|
|
||||||
tools/%: tools/%.c
|
tools/%: tools/%.c
|
||||||
gcc -Wall -Werror -g $^ -o $@
|
gcc -Wall -Werror -g $^ -o $@
|
||||||
|
|||||||
@ -1,21 +1,12 @@
|
|||||||
// stolen from https://github.com/dhavalhirdhav/LearnOS/blob/master/drivers/ata/ata.c
|
// stolen from
|
||||||
|
// https://github.com/dhavalhirdhav/LearnOS/blob/master/drivers/ata/ata.c
|
||||||
|
|
||||||
|
#include "ata.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "ata.h"
|
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
|
|
||||||
/*
|
|
||||||
BSY: a 1 means that the controller is busy executing a command. No register should be accessed (except the digital output register) while this bit is set.
|
|
||||||
RDY: a 1 means that the controller is ready to accept a command, and the drive is spinning at correct speed..
|
|
||||||
WFT: a 1 means that the controller detected a write fault.
|
|
||||||
SKC: a 1 means that the read/write head is in position (seek completed).
|
|
||||||
DRQ: a 1 means that the controller is expecting data (for a write) or is sending data (for a read). Don't access the data register while this bit is 0.
|
|
||||||
COR: a 1 indicates that the controller had to correct data, by using the ECC bytes (error correction code: extra bytes at the end of the sector that allows to verify its integrity and, sometimes, to correct errors).
|
|
||||||
IDX: a 1 indicates the the controller retected the index mark (which is not a hole on hard-drives).
|
|
||||||
ERR: a 1 indicates that an error occured. An error code has been placed in the error register.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#define STATUS_BSY 0x80
|
#define STATUS_BSY 0x80
|
||||||
#define STATUS_RDY 0x40
|
#define STATUS_RDY 0x40
|
||||||
#define STATUS_DRQ 0x08
|
#define STATUS_DRQ 0x08
|
||||||
@ -23,12 +14,13 @@ ERR: a 1 indicates that an error occured. An error code has been placed in the e
|
|||||||
#define STATUS_ERR 0x01
|
#define STATUS_ERR 0x01
|
||||||
|
|
||||||
// This is really specific to our OS now, assuming ATA bus 0 master
|
// This is really specific to our OS now, assuming ATA bus 0 master
|
||||||
//Source - OsDev wiki
|
// Source - OsDev wiki https://wiki.osdev.org/ATA_PIO_Mode
|
||||||
|
|
||||||
static void ATA_wait_BSY();
|
static void ATA_wait_BSY();
|
||||||
static void ATA_wait_DRQ();
|
static void ATA_wait_RDY();
|
||||||
|
|
||||||
void read_sectors_ATA_PIO(uint32_t target_address, uint32_t LBA, uint8_t sector_count)
|
void read_sectors_ATA_PIO(uint32_t target_address, uint32_t LBA, uint8_t sector_count)
|
||||||
{
|
{
|
||||||
|
|
||||||
ATA_wait_BSY();
|
ATA_wait_BSY();
|
||||||
port_byte_out(0x1F6, 0xE0 | ((LBA >> 24) & 0xF));
|
port_byte_out(0x1F6, 0xE0 | ((LBA >> 24) & 0xF));
|
||||||
port_byte_out(0x1F2, sector_count);
|
port_byte_out(0x1F2, sector_count);
|
||||||
@ -42,7 +34,7 @@ void read_sectors_ATA_PIO(uint32_t target_address, uint32_t LBA, uint8_t sector_
|
|||||||
for (int j = 0; j < sector_count; j++)
|
for (int j = 0; j < sector_count; j++)
|
||||||
{
|
{
|
||||||
ATA_wait_BSY();
|
ATA_wait_BSY();
|
||||||
ATA_wait_DRQ();
|
ATA_wait_RDY();
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
target[i] = port_word_in(0x1F0);
|
target[i] = port_word_in(0x1F0);
|
||||||
target += 256;
|
target += 256;
|
||||||
@ -62,7 +54,7 @@ void write_sectors_ATA_PIO(uint32_t LBA, uint8_t sector_count, uint32_t* bytes)
|
|||||||
for (int j = 0; j < sector_count; j++)
|
for (int j = 0; j < sector_count; j++)
|
||||||
{
|
{
|
||||||
ATA_wait_BSY();
|
ATA_wait_BSY();
|
||||||
ATA_wait_DRQ();
|
ATA_wait_RDY();
|
||||||
for (int i = 0; i < 256; i++)
|
for (int i = 0; i < 256; i++)
|
||||||
{
|
{
|
||||||
port_long_out(0x1F0, bytes[i]);
|
port_long_out(0x1F0, bytes[i]);
|
||||||
@ -72,9 +64,11 @@ void write_sectors_ATA_PIO(uint32_t LBA, uint8_t sector_count, uint32_t* bytes)
|
|||||||
|
|
||||||
static void ATA_wait_BSY() // Wait for bsy to be 0
|
static void ATA_wait_BSY() // Wait for bsy to be 0
|
||||||
{
|
{
|
||||||
while (port_byte_in(0x1F7) & STATUS_BSY);
|
while (port_byte_in(0x1F7) & STATUS_BSY)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
static void ATA_wait_DRQ() //Wait fot drq to be 1
|
static void ATA_wait_RDY() // Wait for rdy to be 1
|
||||||
{
|
{
|
||||||
while(!(port_byte_in(0x1F7) & STATUS_RDY));
|
while (!(port_byte_in(0x1F7) & STATUS_RDY))
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user