From ac43dcd8f7ca0f22dbbd71666ecb9191615e4d49 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 13 Feb 2020 15:51:28 +0100 Subject: [PATCH 1/8] WIP: ATA --- include/io/ata.h | 4 ++++ kaleid/kernel/io/ata.c | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/include/io/ata.h b/include/io/ata.h index c8d16af..ea4edac 100644 --- a/include/io/ata.h +++ b/include/io/ata.h @@ -36,6 +36,10 @@ void IoReadATA(void *sectorBuffer, char n, char first); void IoDumpSector(void); +//----------------------------------------------------------------------------// + + + //----------------------------------------------------------------------------// #endif diff --git a/kaleid/kernel/io/ata.c b/kaleid/kernel/io/ata.c index 3df1fae..b7c23b9 100644 --- a/kaleid/kernel/io/ata.c +++ b/kaleid/kernel/io/ata.c @@ -24,6 +24,7 @@ #include #include +#include void IoDumpFirstSector(void) { @@ -41,3 +42,8 @@ void IoDumpFirstSector(void) KernLog("\n\n"); } + +void IoDetectATA(void) +{ + +} From 701b0f0804f62170fd4b9e18f701e8a5b7957cb0 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Mon, 17 Feb 2020 19:10:59 +0100 Subject: [PATCH 2/8] WIP : working on AHCI --- include/io/ata.h | 10 ++++++---- kaleid/kernel/init/init.c | 4 ++++ kaleid/kernel/io/ata.c | 8 ++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/io/ata.h b/include/io/ata.h index ea4edac..1843212 100644 --- a/include/io/ata.h +++ b/include/io/ata.h @@ -33,13 +33,15 @@ //----------------------------------------------------------------------------// +#define MASS_STORAGE_CLASS 0x1 +#define SERIAL_ATA_SUBCLASS 0x6 + +//----------------------------------------------------------------------------// + +void IoDetectATA(void); void IoReadATA(void *sectorBuffer, char n, char first); void IoDumpSector(void); -//----------------------------------------------------------------------------// - - - //----------------------------------------------------------------------------// #endif diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 92cda93..ba3beae 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -88,6 +89,9 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // PCI express IoInitPCI(); + // Drivers + IoDetectATA(); + // Scheduler PsInitSched(); diff --git a/kaleid/kernel/io/ata.c b/kaleid/kernel/io/ata.c index b7c23b9..3c58262 100644 --- a/kaleid/kernel/io/ata.c +++ b/kaleid/kernel/io/ata.c @@ -45,5 +45,13 @@ void IoDumpFirstSector(void) void IoDetectATA(void) { + PciDev_t *ataDevice = IoPciGetDeviceByClass(MASS_STORAGE_CLASS, + SERIAL_ATA_SUBCLASS); + if(!ataDevice) { + return; + } + + DebugLog("AHCI controller found ! PCI config addr = %p\n", + ataDevice->configAddr); } From a1fd3c5e511202614d869ff80b8ba6d6ef28d1e1 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 19 Feb 2020 19:28:30 +0100 Subject: [PATCH 3/8] Reworking on tree --- Makefile | 11 ++++++----- kaleid/{kernel/io => drivers}/ata.asm | 0 kaleid/{kernel/io => drivers}/ata.c | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) rename kaleid/{kernel/io => drivers}/ata.asm (100%) rename kaleid/{kernel/io => drivers}/ata.c (95%) diff --git a/Makefile b/Makefile index ebe01ea..d0963f3 100644 --- a/Makefile +++ b/Makefile @@ -113,10 +113,11 @@ KernSources = kernel/ke/cpuid.c kernel/mm/paging.c \ kernel/ke/rtc.c kernel/io/keyb.c \ kernel/io/spkr.c kernel/po/shtdwn.c \ kernel/sh/shell.c kernel/sh/shcmds.c \ - kernel/sh/musage.c kernel/io/ata.c \ + kernel/sh/musage.c \ kernel/sh/argv.c kernel/ke/pit.c \ kernel/sh/testcmds.c kernel/mm/palloc.c \ - kernel/io/acpi.c kernel/io/pci.c + kernel/io/acpi.c kernel/io/pci.c \ + drivers/ata.c KernObj=$(patsubst %.c,$(KOBJDIR)/%.o,$(KernSources)) KernDep=$(patsubst %.c,$(KOBJDIR)/%.d,$(KernSources)) @@ -219,10 +220,10 @@ $(KOBJDIR)/kernel/mm/gdt.o: $(KALEIDDIR)/kernel/mm/gdt.c \ @rm -f $@.1 $@.2 @echo ${CL2}[$@] ${CL}Compiled.${CL3} -$(KOBJDIR)/kernel/io/ata.o: $(KALEIDDIR)/kernel/io/ata.c \ - $(KALEIDDIR)/kernel/io/ata.asm | $(KOBJDIR) +$(KOBJDIR)/drivers/ata.o: $(KALEIDDIR)/drivers/ata.c \ + $(KALEIDDIR)/drivers/ata.asm | $(KOBJDIR) @mkdir -p $(shell dirname $@) - @$(ASM) $(ASMFLAGS) $(KALEIDDIR)/kernel/io/ata.asm -o $@.1 + @$(ASM) $(ASMFLAGS) $(KALEIDDIR)/drivers/ata.asm -o $@.1 @$(KCC) $< -o $@.2 @$(LD) $(LDFLAGS) -r $@.1 $@.2 -o $@ @rm -f $@.1 $@.2 diff --git a/kaleid/kernel/io/ata.asm b/kaleid/drivers/ata.asm similarity index 100% rename from kaleid/kernel/io/ata.asm rename to kaleid/drivers/ata.asm diff --git a/kaleid/kernel/io/ata.c b/kaleid/drivers/ata.c similarity index 95% rename from kaleid/kernel/io/ata.c rename to kaleid/drivers/ata.c index 3c58262..9ce48f4 100644 --- a/kaleid/kernel/io/ata.c +++ b/kaleid/drivers/ata.c @@ -54,4 +54,4 @@ void IoDetectATA(void) DebugLog("AHCI controller found ! PCI config addr = %p\n", ataDevice->configAddr); -} +} From 52aa9107eacf5ec893c0cfa8b920c36ed38ad90b Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 19 Feb 2020 22:22:38 +0100 Subject: [PATCH 4/8] New tree ok --- kaleid/kernel/init/init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index ba3beae..aa5bb3f 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -32,14 +32,13 @@ #include #include #include -#include #include #include #include #include #include #include - +#include // // Entry point of the Kaleid kernel // From aea2f4470071bb8e7f62182bff9546f01c321c7e Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 19 Feb 2020 22:42:49 +0100 Subject: [PATCH 5/8] misc correction --- Makefile | 14 +++++++------- kaleid/drivers/ata.c | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index ef8b839..41ec9d5 100644 --- a/Makefile +++ b/Makefile @@ -291,21 +291,21 @@ test: all installonimage run: test testnokvm: all installonimage - @qemu-system-x86_64 -vga std -cpu $(cpu) -soundhw pcspk -s \ + @qemu-system-x86_64 -vga std -cpu $(cpu) -machine type=q35 -soundhw pcspk -s \ -rtc base=localtime -m $(ram) -hda $(installdisk) \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & testnosnd: all installonimage - @qemu-system-x86_64 -vga std -enable-kvm -cpu host -s \ + @qemu-system-x86_64 -vga std -enable-kvm -machine type=q35 -cpu host -s \ -rtc base=localtime -m $(ram) -hda $(installdisk) \ -d cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & test32: all installonimage - @qemu-system-i386 -m $(ram) -hda $(installdisk) -d \ + @qemu-system-i386 -m $(ram) -hda $(installdisk) -machine type=q35 -d \ cpu_reset,guest_errors,pcall,int 2> $(BUILDDIR)/qemu.log & gdb: all installonimage - @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \ + @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -machine type=q35 -rtc base=localtime \ -hda $(installdisk) -no-reboot -no-shutdown -d \ cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @gdb \ @@ -315,13 +315,13 @@ gdb: all installonimage -ex "break BtStartKern" \ ddd: all installonimage - @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -rtc base=localtime \ + @setsid qemu-system-x86_64 -m $(ram) -enable-kvm -machine type=q35 -rtc base=localtime \ -hda $(installdisk) -no-reboot -no-shutdown -d \ cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @ddd -n gdbnokvm: all installonimage - @setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \ + @setsid qemu-system-x86_64 -m $(ram) -machine type=q35 -rtc base=localtime \ -hda $(installdisk) -no-reboot -no-shutdown -d \ cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @gdb \ @@ -331,7 +331,7 @@ gdbnokvm: all installonimage -ex "break BtStartKern" \ dddnokvm: all installonimage - @setsid qemu-system-x86_64 -m $(ram) -rtc base=localtime \ + @setsid qemu-system-x86_64 -m $(ram) -machine type=q35 -rtc base=localtime \ -hda $(installdisk) -no-reboot -no-shutdown -d \ cpu_reset,guest_errors,pcall,int -s -S 2> $(BUILDDIR)/qemu.log & @ddd -n diff --git a/kaleid/drivers/ata.c b/kaleid/drivers/ata.c index 8ba1b6a..9eace40 100644 --- a/kaleid/drivers/ata.c +++ b/kaleid/drivers/ata.c @@ -52,6 +52,6 @@ void IoDetectATA(void) return; } - DebugLog("AHCI controller found ! PCI config addr = %p\n", + DebugLog("AHCI controller found at PCI config addr = %p\n", ataDevice->configAddr); } From 295930405ccee69bb6b66f056c0c1d2d1b65c18a Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 20 Feb 2020 01:01:50 +0100 Subject: [PATCH 6/8] WIP : #66 : AHCI controller detected, working on commands --- include/drivers/ata.h | 84 +++++++++++++++++++++++++++++++++++++++++++ kaleid/drivers/ata.c | 9 +++++ 2 files changed, 93 insertions(+) diff --git a/include/drivers/ata.h b/include/drivers/ata.h index 1843212..a44ee76 100644 --- a/include/drivers/ata.h +++ b/include/drivers/ata.h @@ -36,6 +36,90 @@ #define MASS_STORAGE_CLASS 0x1 #define SERIAL_ATA_SUBCLASS 0x6 +enum +{ + REG_H2D = 0x27, // Register FIS - host to device + REG_D2H = 0x34, // Register FIS - device to host + DMA_ACT = 0x39, // DMA activate FIS - device to host + DMA_SETUP = 0x41, // DMA setup FIS - bidirectional + DATA = 0x46, // Data FIS - bidirectional + BIST = 0x58, // BIST activate FIS - bidirectional + PIO_SETUP = 0x5F, // PIO setup FIS - device to host + DEV_BITS = 0xA1 // Set device bits FIS - device to host +}; + +enum +{ + IDENTIFY = 0xEC // CMD IDENTIFY +}; + +struct HostToDeviceFIS +{ + // DWORD 0 + uchar type; // REG_H2D + + uchar pmport:4; // Port multiplier + uchar reserved0:3; // Reserved + uchar c:1; // 1: Command, 0: Control + + uchar command; // Command register + uchar featurel; // Feature register, 7:0 + + // DWORD 1 + uchar lba0; // LBA low register, 7:0 + uchar lba1; // LBA mid register, 15:8 + uchar lba2; // LBA high register, 23:16 + uchar device; // Device register + + // DWORD 2 + uchar lba3; // LBA register, 31:24 + uchar lba4; // LBA register, 39:32 + uchar lba5; // LBA register, 47:40 + uchar featureh; // Feature register, 15:8 + + // DWORD 3 + uchar countl; // Count register, 7:0 + uchar counth; // Count register, 15:8 + uchar icc; // Isochronous command completion + uchar control; // Control register + + // DWORD 4 + uchar reserved1[4]; // Reserved +}; + +struct DMASetupFIS +{ + // DWORD 0 + uchar type; // DMA_SETUP + + uchar pmport:4; // Port multiplier + uchar reserved0:1; // Reserved + uchar d:1; // Data transfer direction, 1 - device to host + uchar i:1; // Interrupt bit + uchar a:1; // Auto-activate. Specifies if DMA Activate FIS + // is needed + + uchar reserved1[2]; // Reserved + + //DWORD 1&2 + ulong DMAbufferID; // DMA Buffer Identifier. + // Used to Identify DMA buffer in host memory. + // SATA Spec says host specific and not in Spec. + // Trying AHCI spec might work. + + //DWORD 3 + uint reserved2; // More reserved + + //DWORD 4 + uint DMAbufOffset; // Byte offset into buffer. First 2 bits must be 0 + + //DWORD 5 + uint TransferCount; // Number of bytes to transfer. Bit 0 must be 0 + + //DWORD 6 + uint reserved3; // Reserved +}; + //----------------------------------------------------------------------------// void IoDetectATA(void); diff --git a/kaleid/drivers/ata.c b/kaleid/drivers/ata.c index 9eace40..cea0ac1 100644 --- a/kaleid/drivers/ata.c +++ b/kaleid/drivers/ata.c @@ -54,4 +54,13 @@ void IoDetectATA(void) DebugLog("AHCI controller found at PCI config addr = %p\n", ataDevice->configAddr); + + struct HostToDeviceFIS fis; + memset(&fis, 0, sizeof(struct HostToDeviceFIS)); + fis.type = REG_H2D; + fis.command = IDENTIFY; + fis.device = 0; // Master + fis.c = 1; // This is a command + + } From 3b85b6b856cd38e75b4c8ed17e8f0c2e39d5b716 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Thu, 20 Feb 2020 08:36:38 +0100 Subject: [PATCH 7/8] Update project tree --- ProjectTree | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ProjectTree b/ProjectTree index 6e0b554..1c05ca4 100644 --- a/ProjectTree +++ b/ProjectTree @@ -26,8 +26,7 @@ . ├── boot │   ├── grub -│   │   ├── grub.cfg -│   │   └── multiboot.pdf +│   │   └── grub.cfg │   ├── loader │   │   ├── cpu │   │   │   ├── cpu32.inc @@ -166,4 +165,4 @@ ├── ProjectTree └── README.md -30 directories, 111 files +30 directories, 110 files From cd755b2e5f85d27186203c1e89d450b2d9d926b9 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 2 Jun 2020 09:48:29 +0200 Subject: [PATCH 8/8] ProjectTree --- ProjectTree | 1 - 1 file changed, 1 deletion(-) diff --git a/ProjectTree b/ProjectTree index 39ebae7..c41e678 100644 --- a/ProjectTree +++ b/ProjectTree @@ -945,4 +945,3 @@ └── README.md 74 directories, 845 files -