Permalink
Browse files

Hermes' sbrk fix, libsysfs, msgdialog fix, and spu samples fixes.

  • Loading branch information...
1 parent 24ed743 commit 3d23aa84ae62f16f4ae06f472d436a4193ca40c6 Miigotu committed Mar 16, 2011
View
@@ -37,6 +37,11 @@ typedef void (*msgDialog)(msgButton button, void *userdata);
s32 msgDialogOpen(msgType type, const char * msg, msgDialog func, void * userdata, void *unused);
s32 msgDialogOpen_ex(msgType type, const char * msg, opd32 * func, void * userdata, void *unused);
+
+s32 msgDialogOpen2(msgType type, const char * msg, msgDialog func, void * userdata, void *unused);
+s32 msgDialogOpen2_ex(msgType type, const char * msg, opd32 * func, void * userdata, void *unused);
+s32 msgDialogAbort(void);
+
s32 msgDialogClose(void);
s32 msgDialogDelayedClose(float ms);
View
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <psl1ght/types.h>
+#include <psl1ght/lv2/filesystem.h>
+
+EXTERN_BEGIN
+
+typedef struct sysFsAio {
+ s32 fd;
+ u64 offset;
+ u32 addr_buffer;
+ u64 size;
+ u64 userdata;
+} sysFsAio;
+
+
+s32 sysFsOpen(const char* path, s32 oflags, Lv2FsFile* fd, const void* arg, u64 argsize);
+s32 sysFsClose(Lv2FsFile fd);
+s32 sysFsRead(Lv2FsFile fd, void* buf, u64 size, u64* read);
+s32 sysFsWrite(Lv2FsFile fd, const void* buf, u64 size, u64* written);
+s32 sysFsLseek(Lv2FsFile fd, s64 offset, s32 whence, u64* position);
+s32 sysFsStat(const char* path, Lv2FsStat* buf);
+s32 sysFsFstat(Lv2FsFile fd, Lv2FsStat* buf);
+s32 sysFsChmod(const char* path, Lv2FsMode mode);
+s32 sysFsMkdir(const char* path, Lv2FsMode mode);
+s32 sysFsRmdir(const char *path);
+s32 sysFsUnlink(const char *path);
+
+s32 sysFsOpendir(const char *path, Lv2FsFile *fd);
+s32 sysFsClosedir(Lv2FsFile fd);
+s32 sysFsReaddir(Lv2FsFile fd, Lv2FsDirent* entry, u64* read);
+
+s32 sysFsAioInit(const char * path);
+s32 sysFsAioFinish(const char * path);
+s32 sysFsAioCancel(s32 id);
+
+s32 sysFsAioRead (sysFsAio *Aio, s32 *id, void (*func)(sysFsAio *Aio, s32 error, s32 xid, u64 size));
+s32 sysFsAioWrite(sysFsAio *Aio, s32 *id, void (*func)(sysFsAio *Aio, s32 error, s32 xid, u64 size));
+
+s32 sysFsGetFreeSize(const char *path, u32 *blockSize, u64 *freeBlocks);
+
+EXTERN_END
+
+
View
@@ -1,5 +1,4 @@
#include <psl1ght/lv2.h>
-
#include <sys/reent.h>
#include <sys/types.h>
#include <stddef.h>
@@ -17,30 +16,147 @@
((p + round - 1) & ~(round - 1))
// Here's a very lazy and lossy sbrk. It's made of fail, but I'm lazy.
-char* memend = 0;
-char* pageend = 0;
+static char* current_mem = 0;
+static char* end_mem = 0;
+
+#define MAX_PAGES 16
+
+static struct {
+ char *start;
+ char *end;
+} pages[MAX_PAGES];
+
+
caddr_t psl1ght_sbrk_r(struct _reent* r, ptrdiff_t increment)
{
- if (increment == 0)
- return memend;
- if (increment < 0) // >.>
- return memend;
- if (memend + increment <= pageend) {
- void* ret = memend;
- memend += increment;
- return ret;
- }
- size_t allocsize = ROUND_UP(increment, PAGE_SIZE);
- u32 taddr;
- if (Lv2Syscall3(348, allocsize, PAGE_SIZE_FLAG, (u64)&taddr)) {
- r->_errno = ENOMEM;
- return (void*)-1;
- }
- char* addr = (char*)(u64)taddr;
- if (pageend != addr)
- memend = addr;
- pageend = addr + allocsize;
- char* ret = memend;
- memend += increment;
- return ret;
+ static int one = 1;
+ int n, m;
+ char * ret;
+
+ // initialize
+
+ if(one) {
+ one = 0;
+ size_t allocsize = ROUND_UP(MAX_PAGES*1024*1024, PAGE_SIZE);
+ u32 taddr = 0;
+
+ for(n = 0; n < MAX_PAGES; n++) pages[n].start = pages[n].end = NULL;
+
+ if (Lv2Syscall3(348, allocsize, PAGE_SIZE_FLAG, (u64)&taddr)) {
+ r->_errno = ENOMEM;
+ return (void*)-1;
+ }
+
+ char* addr = (char*)(u64)taddr;
+
+ current_mem = pages[0].start = addr;
+ end_mem = pages[0].end = addr + allocsize;
+ }
+
+
+ if(increment > 0) {
+
+ // find current page
+ for(n = 0; n < MAX_PAGES; n++) {
+ if(current_mem >= pages[n].start && current_mem < pages[n].end) break;
+ }
+
+ // if not found or page minor...
+ if(n == MAX_PAGES || (current_mem + increment) > pages[n].end) {
+
+ // test in the next pages
+ if(n < (MAX_PAGES-1)) {
+ for(m = n + 1; m < MAX_PAGES; m++) {
+ if(pages[m].start != NULL && (pages[m].start + increment) <= pages[m].end) break;
+ }
+
+ if(m < MAX_PAGES) {
+ current_mem = pages[m].start;
+ goto return_ok;
+ }
+ }
+
+ size_t allocsize = ROUND_UP(increment, MAX_PAGES*1024*1024);
+ u32 taddr = 0;
+
+ if (Lv2Syscall3(348, allocsize, PAGE_SIZE_FLAG, (u64)&taddr)) {
+ r->_errno = ENOMEM;
+ return (void*)-1;
+ }
+
+ char* addr = (char*)(u64)taddr;
+
+ // error if addr < end_mem
+
+ if(end_mem > addr) {
+ r->_errno = ENOMEM;
+ return (void*)-1;
+ }
+
+ end_mem = addr + allocsize;
+
+ // test for increase the page
+ if(n != MAX_PAGES && pages[n].end == addr) {
+ pages[n].end += allocsize;
+ } else {
+
+ // test empty page
+ for(n = 0; n < MAX_PAGES; n++) if(pages[n].start == NULL) break;
+
+ if(n == MAX_PAGES) {
+ r->_errno = ENOMEM;
+ return (void*)-1;
+ }
+
+
+ pages[n].start = addr;
+ pages[n].end = addr + allocsize;
+
+ current_mem = pages[n].start;
+ }
+ }
+
+
+ } else if(increment < 0){
+
+ buclea:
+
+ // find current page
+ for(n = 0; n < MAX_PAGES; n++) {
+ if(current_mem >= pages[n].start && current_mem < pages[n].end) break;
+ }
+
+ if(n != MAX_PAGES) {
+
+ if(pages[n].start > (current_mem + increment)) {
+
+ if(pages[n].start == current_mem) {
+
+ n--;
+
+ if(n >= 0) {
+
+ int incre = (int) (pages[n].end - pages[n].start);
+
+ // skip pages if increment is very big
+ if(incre < -increment) {increment += incre; current_mem = pages[n].start; goto buclea;}
+
+ if(pages[n].start >= pages[n].end + increment) {ret= current_mem; current_mem = pages[n].end + increment; return ret;}
+ }
+
+ }
+ } else goto return_ok;
+ }
+
+
+ r->_errno = ENOMEM;
+ return (void*)-1;
+ }
+
+return_ok:
+
+ ret = current_mem;
+ current_mem += increment;
+
+ return ret;
}
@@ -34,6 +34,9 @@
int main(int argc, const char* argv[])
{
sysSpuImage image;
+ u32 entry = 0;
+ u32 segmentcount = 0;
+ sysSpuSegment* segments;
u32 group_id;
Lv2SpuThreadAttributes attr = { ptr2ea("mythread"), 8+1, LV2_SPU_THREAD_ATTRIBUTE_NONE };
Lv2SpuThreadGroupAttributes grpattr = { 7+1, ptr2ea("mygroup"), 0, 0 };
@@ -46,6 +49,17 @@ int main(int argc, const char* argv[])
printf("Initializing 6 SPUs... ");
printf("%08x\n", lv2SpuInitialize(6, 0));
+ printf("Getting ELF information... ");
+ printf("%08x\n", sysSpuElfGetInformation(spu_bin, &entry, &segmentcount));
+ printf("\tEntry Point: %08x\n\tSegment Count: %08x\n", entry, segmentcount);
+
+ size_t segmentsize = sizeof(sysSpuSegment) * segmentcount;
+ segments = (sysSpuSegment*)malloc(segmentsize);
+ memset(segments, 0, segmentsize);
+
+ printf("Getting ELF segments... ");
+ printf("%08x\n", sysSpuElfGetSegments(spu_bin, segments, segmentcount));
+
printf("Loading ELF image... ");
printf("%08x\n", sysSpuImageImport(&image, spu_bin, 0));
@@ -13,6 +13,9 @@
int main(int argc, const char* argv[])
{
sysSpuImage image;
+ u32 entry = 0;
+ u32 segmentcount = 0;
+ sysSpuSegment* segments;
u32 thread_id;
u32 group_id;
Lv2SpuThreadAttributes attr = { ptr2ea("mythread"), 8+1, LV2_SPU_THREAD_ATTRIBUTE_NONE };
@@ -26,6 +29,17 @@ int main(int argc, const char* argv[])
printf("Initializing 6 SPUs... ");
printf("%08x\n", lv2SpuInitialize(6, 0));
+ printf("Getting ELF information... ");
+ printf("%08x\n", sysSpuElfGetInformation(spu_bin, &entry, &segmentcount));
+ printf("\tEntry Point: %08x\n\tSegment Count: %08x\n", entry, segmentcount);
+
+ size_t segmentsize = sizeof(sysSpuSegment) * segmentcount;
+ segments = (sysSpuSegment*)malloc(segmentsize);
+ memset(segments, 0, segmentsize);
+
+ printf("Getting ELF segments... ");
+ printf("%08x\n", sysSpuElfGetSegments(spu_bin, segments, segmentcount));
+
printf("Loading ELF image... ");
printf("%08x\n", sysSpuImageImport(&image, spu_bin, 0));
@@ -42,6 +42,9 @@
int main(int argc, const char* argv[])
{
sysSpuImage image;
+ u32 entry = 0;
+ u32 segmentcount = 0;
+ sysSpuSegment* segments;
u32 group_id;
Lv2SpuThreadAttributes attr = { ptr2ea("mythread"), 8+1, LV2_SPU_THREAD_ATTRIBUTE_NONE };
Lv2SpuThreadGroupAttributes grpattr = { 7+1, ptr2ea("mygroup"), 0, 0 };
@@ -54,6 +57,17 @@ int main(int argc, const char* argv[])
printf("Initializing 6 SPUs... ");
printf("%08x\n", lv2SpuInitialize(6, 0));
+ printf("Getting ELF information... ");
+ printf("%08x\n", sysSpuElfGetInformation(spu_bin, &entry, &segmentcount));
+ printf("\tEntry Point: %08x\n\tSegment Count: %08x\n", entry, segmentcount);
+
+ size_t segmentsize = sizeof(sysSpuSegment) * segmentcount;
+ segments = (sysSpuSegment*)malloc(segmentsize);
+ memset(segments, 0, segmentsize);
+
+ printf("Getting ELF segments... ");
+ printf("%08x\n", sysSpuElfGetSegments(spu_bin, segments, segmentcount));
+
printf("Loading ELF image... ");
printf("%08x\n", sysSpuImageImport(&image, spu_bin, 0));
@@ -12,12 +12,26 @@ int main(int argc, const char* argv[])
{
u32 spu = 0;
sysSpuImage image;
+ u32 entry = 0;
+ u32 segmentcount = 0;
+ sysSpuSegment* segments;
printf("Initializing 6 SPUs... ");
printf("%08x\n", lv2SpuInitialize(6, 5));
printf("Initializing raw SPU... ");
printf("%08x\n", lv2SpuRawCreate(&spu, NULL));
+ printf("Getting ELF information... ");
+ printf("%08x\n", sysSpuElfGetInformation(spu_bin, &entry, &segmentcount));
+ printf("\tEntry Point: %08x\n\tSegment Count: %08x\n", entry, segmentcount);
+
+ size_t segmentsize = sizeof(sysSpuSegment) * segmentcount;
+ segments = (sysSpuSegment*)malloc(segmentsize);
+ memset(segments, 0, segmentsize);
+
+ printf("Getting ELF segments... ");
+ printf("%08x\n", sysSpuElfGetSegments(spu_bin, segments, segmentcount));
+
printf("Loading ELF image... ");
printf("%08x\n", sysSpuImageImport(&image, spu_bin, 0));
@@ -13,6 +13,9 @@
int main(int argc, const char* argv[])
{
sysSpuImage image;
+ u32 entry = 0;
+ u32 segmentcount = 0;
+ sysSpuSegment* segments;
u32 thread_id;
u32 group_id;
Lv2SpuThreadAttributes attr = { ptr2ea("mythread"), 8+1, LV2_SPU_THREAD_ATTRIBUTE_NONE };
@@ -25,6 +28,17 @@ int main(int argc, const char* argv[])
printf("Initializing 6 SPUs... ");
printf("%08x\n", lv2SpuInitialize(6, 0));
+ printf("Getting ELF information... ");
+ printf("%08x\n", sysSpuElfGetInformation(spu_bin, &entry, &segmentcount));
+ printf("\tEntry Point: %08x\n\tSegment Count: %08x\n", entry, segmentcount);
+
+ size_t segmentsize = sizeof(sysSpuSegment) * segmentcount;
+ segments = (sysSpuSegment*)malloc(segmentsize);
+ memset(segments, 0, segmentsize);
+
+ printf("Getting ELF segments... ");
+ printf("%08x\n", sysSpuElfGetSegments(spu_bin, segments, segmentcount));
+
printf("Loading ELF image... ");
printf("%08x\n", sysSpuImageImport(&image, spu_bin, 0));
Oops, something went wrong.

0 comments on commit 3d23aa8

Please sign in to comment.