Skip to content

Commit

Permalink
first draft done
Browse files Browse the repository at this point in the history
  • Loading branch information
jzm284 committed Apr 20, 2024
1 parent fa22deb commit f6bab44
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 23 deletions.
1 change: 1 addition & 0 deletions history
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Binary file modified kernel/build/kernel.bin
Binary file not shown.
Binary file modified kernel/build/kernel.img
Binary file not shown.
Binary file modified kernel/build/kernel.kernel
Binary file not shown.
11 changes: 6 additions & 5 deletions kernel/pci.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions kernel/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
#define PCI_H

#include <stdint.h>
#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 {
Expand All @@ -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
11 changes: 10 additions & 1 deletion kernel/process.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> Process::kernelProcess = Shared<Process>::make(true);

Expand Down Expand Up @@ -54,6 +54,15 @@ void Process::setupDMABuffers(uint32_t nabm_base)
setupBuffers = true;
}

void Process::fillBuffers(Shared<File> 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<BlockingLock> lock { mutex };

Expand Down
7 changes: 4 additions & 3 deletions kernel/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> files[NFILE]{};
Shared<Semaphore> sems[NSEM]{};
Expand Down Expand Up @@ -45,7 +45,7 @@ class Process

void setupDMABuffers(uint32_t nabm_base);

void fillBuffers(uint32_t fd)
void fillBuffers(Shared<File> file);

int newSemaphore(uint32_t init);

Expand Down Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions kernel/sys.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "shared.h"
#include "kernel.h"
#include "openfilestruct.h"
#include "pci.h"

int strlen(const char *string)
{
Expand Down Expand Up @@ -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

Expand Down
Binary file modified t0.data
Binary file not shown.
17 changes: 8 additions & 9 deletions t0.raw
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -96,4 +95,4 @@ DMA buffers setup completed.
*** $$$$$$$$$$"
*** "$$$""
***
core 3 requested shutdown
core 2 requested shutdown
Expand Down
2 changes: 1 addition & 1 deletion t0.time
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0:02.47
0:01.56

0 comments on commit f6bab44

Please sign in to comment.