From f739b18d4fe5e93c363dae8896e02a293606b879 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Mon, 7 Jul 2014 10:57:57 -0700 Subject: [PATCH] Fix compiler warnings and some refactoring --- sys/amd64/machine.c | 9 ++++++--- sys/amd64/pmap.c | 9 +++++---- sys/amd64/pmap.h | 12 ++++++++++++ sys/amd64/trap.c | 6 +++--- sys/amd64/trap.h | 3 +++ sys/dev/ahci.c | 29 ++++------------------------- sys/dev/ata.h | 34 ++++++++++++++++++++++++++++++++++ sys/dev/x86/ide.c | 30 +----------------------------- sys/include/kassert.h | 1 + 9 files changed, 69 insertions(+), 64 deletions(-) create mode 100644 sys/dev/ata.h diff --git a/sys/amd64/machine.c b/sys/amd64/machine.c index 33eaba4..24f0286 100644 --- a/sys/amd64/machine.c +++ b/sys/amd64/machine.c @@ -1,4 +1,4 @@ - +#include #include #include @@ -8,8 +8,11 @@ #include "amd64.h" #include "ioapic.h" #include "lapic.h" +#include "trap.h" +#include "pmap.h" -extern void Trap_Init(); +extern void PCI_Init(); +extern void IDE_Init(); #define GDT_MAX 7 @@ -59,7 +62,7 @@ void Machine_TSSInit() TSS[0]._unused2 = 0; TSS[0]._unused3 = 0; TSS[0]._unused4 = 0; - TSS[0].ist1 = &df_stack; + TSS[0].ist1 = (uint64_t)&df_stack; TSS[0].rsp0 = 0; TSS[0].rsp1 = 0; TSS[0].rsp2 = 0; diff --git a/sys/amd64/pmap.c b/sys/amd64/pmap.c index edc67d8..970f6a7 100644 --- a/sys/amd64/pmap.c +++ b/sys/amd64/pmap.c @@ -21,9 +21,6 @@ typedef struct AS AS systemAS; AS *currentAS[MAX_CPUS]; -bool PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags); -void PMapDump(AS *space); - void PMap_Init() { @@ -70,7 +67,7 @@ PMap_Init() } AS* -Map_NewAS() +PMap_NewAS() { int i; AS *as = PAlloc_AllocPage(); @@ -252,10 +249,14 @@ PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags) bool PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages) { + NOT_IMPLEMENTED(); + return false; } bool PMap_SystemUnmap(uint64_t virt, uint64_t pages) { + NOT_IMPLEMENTED(); + return false; } diff --git a/sys/amd64/pmap.h b/sys/amd64/pmap.h index f486f3b..d4883d1 100644 --- a/sys/amd64/pmap.h +++ b/sys/amd64/pmap.h @@ -2,4 +2,16 @@ #define MEM_DIRECTMAP_BASE 0x0000000000000000ULL #define PPN2DMVA(ppn) (((ppn) << PGSIZE) + MEM_DIRECTMAP_BASE) #define DMVA2PPN(dmva) (((dmva) - MEM_DIRECTMAP_BASE) >> PGSIZE) +#define DMVA2PA(dmva) ((dmva) - MEM_DIRECTMAP_BASE) +#define DMPA2VA(pa) ((pa) + MEM_DIRECTMAP_BASE) +//#define VA2PA(va) + +typedef struct AS AS; + +void PMap_Init(); +AS* Map_NewAS(); +void PMap_DestroyAS(AS *space); +bool PMap_SystemLMap(uint64_t phys, uint64_t virt, uint64_t lpages, uint64_t flags); +bool PMap_SystemMap(uint64_t phys, uint64_t virt, uint64_t pages); +bool PMap_SystemUnmap(uint64_t virt, uint64_t pages); diff --git a/sys/amd64/trap.c b/sys/amd64/trap.c index 1804b05..5d0d5dd 100644 --- a/sys/amd64/trap.c +++ b/sys/amd64/trap.c @@ -55,7 +55,7 @@ Trap_Init() } void -trap_dump(TrapFrame *tf) +Trap_Dump(TrapFrame *tf) { kprintf("Interrupt %d Error Code: %016llx\n", tf->vector, tf->errcode); @@ -89,7 +89,7 @@ trap_entry(TrapFrame *tf) // Halt on kernel errors if (tf->vector <= T_CPU_LAST && tf->cs == SEL_KCS) { - trap_dump(tf); + Trap_Dump(tf); while (1) hlt(); @@ -118,7 +118,7 @@ trap_entry(TrapFrame *tf) return; } - trap_dump(tf); + Trap_Dump(tf); while (1) { } } diff --git a/sys/amd64/trap.h b/sys/amd64/trap.h index fee17a4..b8605bd 100644 --- a/sys/amd64/trap.h +++ b/sys/amd64/trap.h @@ -69,5 +69,8 @@ typedef struct TrapFrame uint16_t _unused6; } TrapFrame; +void Trap_Init(); +void Trap_Dump(TrapFrame *tf); + #endif /* __TRAP_H__ */ diff --git a/sys/dev/ahci.c b/sys/dev/ahci.c index 5379932..70d333c 100644 --- a/sys/dev/ahci.c +++ b/sys/dev/ahci.c @@ -7,33 +7,12 @@ #include #include +#include "ata.h" + /* * SATA Definitions */ -typedef struct SATAIdentifyDevice -{ - uint16_t _rsvd0[10]; // 0-9 - uint8_t serial[20]; // 10-19 - Serial - uint16_t _rsvd1[3]; // 20-22 - uint8_t firmware[8]; // 23-26 - Firmware - uint8_t model[40]; // 27-46 - Model - uint16_t _rsvd2[16]; // 47-62 X - uint16_t dmaMode; // 63 - DMA Mode - uint16_t _rsvd3[11]; // 64-74 X - uint16_t queueDepth; // 75 - Queue Depth - uint16_t sataCap; // 76 - SATA Capabilities - uint16_t ncqCap; // 77 - NCQ Capabilities - uint16_t _rsvd4[8]; // 78-85 - uint16_t deviceFlags; // 86 - Device Flags (48-bit Addressing) - uint16_t deviceFlags2; // 87 - Device Flags 2 (SMART) - uint16_t udmaMode; // 88 - Ultra DMA Mode - uint16_t _rsvd5[11]; // 89-99 - uint64_t lbaSectors; // 100-103 - User Addressable Logical Sectors - uint16_t _rsvd6[151]; // 104-254 - uint16_t chksum; // 255 - Checksum -} SATAIdentifyDevice; - typedef struct SATAFIS_REG_H2D { uint8_t type; // 0x27 uint8_t flag; @@ -252,7 +231,7 @@ AHCI_Init(uint32_t bus, uint32_t slot, uint32_t func) ASSERT(sizeof(AHCI) <= PGSIZE); ASSERT(sizeof(AHCICommandList) <= PGSIZE); ASSERT(sizeof(AHCIRecvFIS) <= PGSIZE); - ASSERT(sizeof(SATAIdentifyDevice) == 512); + ASSERT(sizeof(ATAIdentifyDevice) == 512); int deviceIdx = 0; while (deviceList[deviceIdx].device != 0x0) { @@ -349,7 +328,7 @@ AHCI_IdentifyPort(AHCI *ahci, int port) volatile AHCIPort *p = ahci->port[port]; SGArray sga; SATAFIS_REG_H2D fis; - SATAIdentifyDevice ident; + ATAIdentifyDevice ident; kprintf("AHCI: Signature %08x\n", p->sig); diff --git a/sys/dev/ata.h b/sys/dev/ata.h new file mode 100644 index 0000000..806484c --- /dev/null +++ b/sys/dev/ata.h @@ -0,0 +1,34 @@ +/* + * ATA Definitions + */ + +#ifndef __ATA_H__ +#define __ATA_H__ + +typedef struct ATAIdentifyDevice +{ + uint16_t _rsvd0[10]; // 0-9 + uint8_t serial[20]; // 10-19 - Serial + uint16_t _rsvd1[3]; // 20-22 + uint8_t firmware[8]; // 23-26 - Firmware + uint8_t model[40]; // 27-46 - Model + uint16_t _rsvd2[16]; // 47-62 X + uint16_t dmaMode; // 63 - DMA Mode + uint16_t _rsvd3[11]; // 64-74 X + uint16_t queueDepth; // 75 - Queue Depth + uint16_t sataCap; // 76 - SATA Capabilities + uint16_t ncqCap; // 77 - NCQ Capabilities + uint16_t _rsvd4[8]; // 78-85 + uint16_t deviceFlags; // 86 - Device Flags (48-bit Addressing) + uint16_t deviceFlags2; // 87 - Device Flags 2 (SMART) + uint16_t udmaMode; // 88 - Ultra DMA Mode + uint16_t _rsvd5[11]; // 89-99 + uint64_t lbaSectors; // 100-103 - User Addressable Logical Sectors + uint16_t _rsvd6[2]; // 104-105 + uint16_t sectorSize; // 106 - Physical Sector Size + uint16_t _rsvd7[148]; // 107-254 + uint16_t chksum; // 255 - Checksum +} ATAIdentifyDevice; + +#endif /* __ATA_H__ */ + diff --git a/sys/dev/x86/ide.c b/sys/dev/x86/ide.c index c0b8a70..b0baea9 100644 --- a/sys/dev/x86/ide.c +++ b/sys/dev/x86/ide.c @@ -7,35 +7,7 @@ #include #include "ioport.h" - -/* - * ATA Definitions - */ - -typedef struct ATAIdentifyDevice -{ - uint16_t _rsvd0[10]; // 0-9 - uint8_t serial[20]; // 10-19 - Serial - uint16_t _rsvd1[3]; // 20-22 - uint8_t firmware[8]; // 23-26 - Firmware - uint8_t model[40]; // 27-46 - Model - uint16_t _rsvd2[16]; // 47-62 X - uint16_t dmaMode; // 63 - DMA Mode - uint16_t _rsvd3[11]; // 64-74 X - uint16_t queueDepth; // 75 - Queue Depth - uint16_t sataCap; // 76 - SATA Capabilities - uint16_t ncqCap; // 77 - NCQ Capabilities - uint16_t _rsvd4[8]; // 78-85 - uint16_t deviceFlags; // 86 - Device Flags (48-bit Addressing) - uint16_t deviceFlags2; // 87 - Device Flags 2 (SMART) - uint16_t udmaMode; // 88 - Ultra DMA Mode - uint16_t _rsvd5[11]; // 89-99 - uint64_t lbaSectors; // 100-103 - User Addressable Logical Sectors - uint16_t _rsvd6[2]; // 104-105 - uint16_t sectorSize; // 106 - Physical Sector Size - uint16_t _rsvd7[148]; // 107-254 - uint16_t chksum; // 255 - Checksum -} ATAIdentifyDevice; +#include "../ata.h" /* * IDE Definitions diff --git a/sys/include/kassert.h b/sys/include/kassert.h index dc367a3..f00b0ca 100644 --- a/sys/include/kassert.h +++ b/sys/include/kassert.h @@ -5,6 +5,7 @@ #include #define ASSERT(x) if (!(x)) { Panic("ASSERT:"); } +#define NOT_IMPLEMENTED() Panic("NOT_IMPLEMENTED:") #define PANIC Panic NO_RETURN void Panic(const char *str);