diff --git a/history b/history index b87d5ae..4baa4ec 100644 --- a/history +++ b/history @@ -19,3 +19,4 @@ t0 fail 0:01.42 [QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.28)] [g++ (U t0 fail 0:01.42 [QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.28)] [g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0] [Wed 17 Apr 2024 08:19:37 PM CDT] t0 fail 0:01.59 [QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.28)] [g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0] [Wed 17 Apr 2024 09:09:26 PM CDT] t0 fail 0:02.47 [QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.28)] [g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0] [Fri 19 Apr 2024 05:56:30 PM CDT] +t0 fail 0:01.56 [QEMU emulator version 4.2.1 (Debian 1:4.2-3ubuntu6.28)] [g++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0] [Fri 19 Apr 2024 07:31:12 PM CDT] diff --git a/kernel/build/kernel.bin b/kernel/build/kernel.bin index e236d9e..86931ae 100755 Binary files a/kernel/build/kernel.bin and b/kernel/build/kernel.bin differ diff --git a/kernel/build/kernel.img b/kernel/build/kernel.img index d002f2d..599dd6e 100644 Binary files a/kernel/build/kernel.img and b/kernel/build/kernel.img differ diff --git a/kernel/build/kernel.kernel b/kernel/build/kernel.kernel index 8cf15eb..ed79e12 100755 Binary files a/kernel/build/kernel.kernel and b/kernel/build/kernel.kernel differ diff --git a/kernel/pci.cc b/kernel/pci.cc index 4df19d8..ca764b3 100644 --- a/kernel/pci.cc +++ b/kernel/pci.cc @@ -22,7 +22,8 @@ namespace AC97 constexpr uint32_t BUFFER_SIZE = 65536; // 64 KB per buffer constexpr uint32_t NUM_BUFFERS = 10; - + uint32_t nam_register; + uint32_t nabm_register; // Initialize AC97 codec and set up basic operation @@ -43,10 +44,8 @@ namespace AC97 Debug::printf("AC97 codec initialized with NAM base I/O address 0x%X and NABM base I/O address 0x%X\n", nam_base, nabm_base); } - void playAudio(uint32_t base_io_address, const uint8_t *audioData, size_t dataSize) - { - // Example of handling audio playback setup - Debug::printf("Preparing to play audio...\n"); + void play(){ + outb(nabm_register + 0x0B, 1); } } @@ -118,6 +117,8 @@ namespace PCI uint32_t nabm_base = pciConfigReadDWord(bus, device, 0, 0x14); nam_base &= ~0x3; nabm_base &= ~0x3; + AC97::nam_register = nam_base; + AC97::nabm_register = nabm_base; AC97::initializeCodec(nam_base, nabm_base); // gheith::current()->process->setupDMABuffers(nabm_base); return; diff --git a/kernel/pci.h b/kernel/pci.h index 9170d3c..d1d1f75 100644 --- a/kernel/pci.h +++ b/kernel/pci.h @@ -3,12 +3,13 @@ #define PCI_H #include +#include "machine.h" // Function declarations namespace PCI { - uint16_t pciConfigReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); - void findAC97(); + extern uint16_t pciConfigReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset); + extern void findAC97(); } namespace AC97 { @@ -17,6 +18,10 @@ namespace AC97 { uint32_t length; // Length of the buffer in samples uint32_t control; // Control flags }; + extern uint32_t nam_register; + extern uint32_t nabm_register; + + extern void play(); } #endif // PCI_H diff --git a/kernel/process.cc b/kernel/process.cc index 5339429..0f5c6c4 100644 --- a/kernel/process.cc +++ b/kernel/process.cc @@ -13,7 +13,7 @@ constexpr static uint32_t PROC = 0x10000000; constexpr static uint32_t SEM = 0x20000000; constexpr static uint32_t INDEX_MASK = 0x0FFFFFFF; constexpr uint32_t BUFFER_SIZE = 65536; // 64 KB per buffer -constexpr uint32_t NUM_BUFFERS = 10; +constexpr uint32_t NUM_BUFFERS = 20; Shared Process::kernelProcess = Shared::make(true); @@ -54,6 +54,15 @@ void Process::setupDMABuffers(uint32_t nabm_base) setupBuffers = true; } +void Process::fillBuffers(Shared file) { + int len = file->size(); + int num_buffers = (len + BUFFER_SIZE) / BUFFER_SIZE; // rounded down len + for (int i = 0; i < num_buffers - 1; i++) { + file->read(&audio_buffers[i], BUFFER_SIZE); + } + file->read(&audio_buffers[num_buffers - 1], len % BUFFER_SIZE); +} + int Process::newSemaphore(uint32_t init) { LockGuard lock { mutex }; diff --git a/kernel/process.h b/kernel/process.h index 79cd1b0..b396bcc 100644 --- a/kernel/process.h +++ b/kernel/process.h @@ -17,7 +17,7 @@ class Process constexpr static int NSEM = 10; constexpr static int NCHILD = 10; constexpr static int NFILE = 10; - constexpr static int NBUFFERS = 10; + constexpr static int NBUFFERS = 20; Shared files[NFILE]{}; Shared sems[NSEM]{}; @@ -45,7 +45,7 @@ class Process void setupDMABuffers(uint32_t nabm_base); - void fillBuffers(uint32_t fd) + void fillBuffers(Shared file); int newSemaphore(uint32_t init); @@ -80,8 +80,9 @@ class Process int close(int id); void exit(uint32_t v) { + output->set(v); - } + } int wait(int id, uint32_t *ptr); static void init(void); diff --git a/kernel/sys.cc b/kernel/sys.cc index 45f2310..2f52039 100644 --- a/kernel/sys.cc +++ b/kernel/sys.cc @@ -13,6 +13,7 @@ #include "shared.h" #include "kernel.h" #include "openfilestruct.h" +#include "pci.h" int strlen(const char *string) { @@ -399,8 +400,8 @@ extern "C" int sysHandler(uint32_t eax, uint32_t *frame) { return -1; } //else if it is a valid audio file - current()->process->setupDMABuffers(); - current()->process->fill_buffers(); + current()->process->setupDMABuffers(AC97::nabm_register); + current()->process->fillBuffers(file); AC97::play(); //set the play bit to 1 diff --git a/t0.data b/t0.data index 4ac6867..92b7c1b 100644 Binary files a/t0.data and b/t0.data differ diff --git a/t0.raw b/t0.raw index 5f1816f..d72a06d 100644 --- a/t0.raw +++ b/t0.raw @@ -5,7 +5,7 @@ iPXE (http://ipxe.org) 00:03.0 CA00 PCI2.10 PnP PMM+07F8F240+07EEF240 CA00 Press Ctrl-B to configure iPXE (PCI 00:03.0)... -Booting from Hard Disk..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +Booting from Hard Disk..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | What just happened? Why am I here? | Discovering my identity and features | CPUID: AuthenticAMD @@ -21,11 +21,10 @@ Booting from Hard Disk..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | physical range 0x600000 0x7fd0000 Enabled PCI register AC97 codec initialized with NAM base I/O address 0xC000 and NABM base I/O address 0xC400 -DMA buffers setup completed. | pitInit freq 1000Hz | pitInit divider 59659 -| APIT running at 1000081554Hz -| APIT counter=1000081 for 1000Hz +| APIT running at 1000046860Hz +| APIT counter=1000046 for 1000Hz | initialize 1 | reset 1 | eip:0x8000 @@ -36,13 +35,13 @@ DMA buffers setup completed. | reset 3 | eip:0x8000 | initializing TSS:ss0 for 2 -| initializing TSS:ss0 for 1 -| 1 enabling interrupts, I'm scared -| 2 enabling interrupts, I'm scared | initializing TSS:ss0 for 3 -| 3 enabling interrupts, I'm scared +| 2 enabling interrupts, I'm scared | initializing TSS:ss0 for 0 +| initializing TSS:ss0 for 1 +| 3 enabling interrupts, I'm scared | 0 enabling interrupts, I'm scared +| 1 enabling interrupts, I'm scared *** 1 *** init *** fd = 3 @@ -96,4 +95,4 @@ DMA buffers setup completed. *** $$$$$$$$$$" *** "$$$"" *** -core 3 requested shutdown +core 2 requested shutdown diff --git a/t0.time b/t0.time index 15a01ea..b77eb88 100644 --- a/t0.time +++ b/t0.time @@ -1 +1 @@ -0:02.47 +0:01.56