I want to use the 2nd core of the gp2x. But up to now nothing happens.
Here is the code that is supposed to load the binary that resides in "940bin.hpp"
940bin is created from the following source code, by linking a binary with the current crt0.s of squidge and relocating it with objdump. The tool hexdump creates a char array called compiled_940bin_binary containing the application.
Here is the main940.cpp
When executing the application nothing happens. The application just terminates without error.
Here is the code that is supposed to load the binary that resides in "940bin.hpp"
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <iostream>
#include "940bin.hpp"
enum Registers
{
SystemClocks = 0x0904
, VSync = 0x1182
, ScreenBitDepth = 0x28DA
, ScreenLineWidth = 0x290C
, RGBLayerOddL = 0x290E
, RGBLayerOddH = 0x2910
, RGBLayerEvenL = 0x2912
, RGBLayerEvenH = 0x2914
, Interrupt940_1 = 0x3B40
, Interrupt940_2 = 0x3B42
, MemoryBase940 = 0x3B48
, VideoSync = 0x1182
};
int main()
{
int memory = open("/dev/mem", O_RDWR);
if( memory == -1 )
{
std::cerr << "FOO" << std::endl;
}
unsigned char* upper_memory = reinterpret_cast<unsigned char*>(
mmap(0, sizeof(compiled_940bin_binary), PROT_READ | PROT_WRITE, MAP_SHARED, memory, 0x2000000)
);
volatile unsigned short* registers = reinterpret_cast<unsigned short*>(
mmap(0, 0x10000, PROT_READ | PROT_WRITE, MAP_SHARED, memory, 0xc0000000)
);
registers[SystemClocks>>1] &= ~(1<<0);
registers[MemoryBase940>>1] = (1<<7) | 2;
memcpy( upper_memory , static_cast<void const*>(compiled_940bin_binary), sizeof(compiled_940bin_binary));
registers[Interrupt940_1>>1] = 0;
registers[Interrupt940_2>>1] = 0;
registers[SystemClocks>>1] |= (1<<0);
registers[MemoryBase940>>1] = 2;
munmap( const_cast<unsigned short*>(registers), 0x10000);
munmap( upper_memory, sizeof(compiled_940bin_binary));
close( memory );
}
940bin is created from the following source code, by linking a binary with the current crt0.s of squidge and relocating it with objdump. The tool hexdump creates a char array called compiled_940bin_binary containing the application.
Code:
gcc src/940/main940.cpp -c -I . -I gp2xfw940/
gcc crt0.s -c
ld crt0.o main940.o -o 940bin.elf
arm-gp2x-linux-objcopy -O binary 940bin.elf 940bin
./hexdump 940bin > src/940bin.hpp
Here is the main940.cpp
Code:
enum Registers
{
SystemClocks = 0x0904
, VSync = 0x1182
, ScreenBitDepth = 0x28DA
, ScreenLineWidth = 0x290C
, RGBLayerOddL = 0x290E
, RGBLayerOddH = 0x2910
, RGBLayerEvenL = 0x2912
, RGBLayerEvenH = 0x2914
, Interrupt940_1 = 0x3B40
, Interrupt940_2 = 0x3B42
, MemoryBase940 = 0x3B48
, VideoSync = 0x1182
};
const long GP940_OFFSET = 0x2000000;
// void flip_unsync();
int main()
{
unsigned short* screen;
unsigned short* screens[2];
volatile unsigned short* registers = (volatile unsigned short*)(0xc0000000 - GP940_OFFSET);
unsigned int screen_addr[2];
registers[ScreenBitDepth>>1] = 0x04ab; /* hex(1|1<<1|1<<3|1<<5|1<<7|2<<9) */
registers[ScreenLineWidth>>1] = 0x0280; /* Line width in bytes*/
screen_addr[0] = 0x03101000;
screen_addr[1] = 0x03381000;
screens[0] = (unsigned short*)(screen_addr[0] - GP940_OFFSET);
screens[1] = (unsigned short*)(screen_addr[1] - GP940_OFFSET);
screen = screens[1];
registers[RGBLayerOddL>>1] = registers[RGBLayerEvenL>>1] = screen_addr[0] & 0xFFFF;
registers[RGBLayerOddH>>1] = registers[RGBLayerEvenH>>1] = screen_addr[0] >> 16;
while(true)
{
for( unsigned short color = 0; color < 32000; ++color )
{
for( int j = 0; j < 320*240; ++j )
{
screen[j] = color;
}
if(screen == screens[0])
{
screen = screens[1];
registers[RGBLayerOddL>>1] = registers[RGBLayerEvenL>>1] = screen_addr[0] & 0xFFFF;
registers[RGBLayerOddH>>1] = registers[RGBLayerEvenH>>1] = screen_addr[0] >> 16;
}
else
{
screen = screens[0];
registers[RGBLayerOddL>>1] = registers[RGBLayerEvenL>>1] = screen_addr[1] & 0xFFFF;
registers[RGBLayerOddH>>1] = registers[RGBLayerEvenH>>1] = screen_addr[1] >> 16;
}
while(~registers[VideoSync>>1] & (1 << 4));
}
}
}
When executing the application nothing happens. The application just terminates without error.