Esempio n. 1
0
// 3 word stack frame (68000 only)
STATIC_INLINE void m68ki_stack_frame_3word(uint32_t pc, uint32_t sr)
{
#if 0
	m68ki_push_32(pc);
	m68ki_push_16(sr);
#else
	// Push PC on stack:
	m68k_areg(regs, 7) -= 4;
	m68k_write_memory_32(m68k_areg(regs, 7), pc);
	// Push SR on stack:
	m68k_areg(regs, 7) -= 2;
	m68k_write_memory_16(m68k_areg(regs, 7), sr);
#endif
}
Esempio n. 2
0
int main(int argc, char **argv)
{
    int binary_file;
    void *binary_data;
    struct stat sb;
    struct tos_environment te;
    int argb = 1;
    
    verbose = 0;
    
    /* Program usage */
    if (argc < 2)
    {
        printf("Usage: tosemu [-v] <binary> [<args>]\n\n\t<binary> name of binary to execute\n");
        return -1;
    }
    
    /* Check if we want to be verbose */
    if (argc >= 3 && strcmp("-v", argv[1]) == 0)
    {
        verbose = -1;
        argb++;
    }

    /* Open the provided file */
    binary_file = open(argv[argb], O_RDONLY);
    if (binary_file == -1)
    {
        printf("Error: failed to open '%s'\n", argv[argc-1]);
        return -1;
    }
    
    /* Determine the file size */
    fstat(binary_file, &sb);
    
    /* Mmap the file into memory */
    binary_data = mmap(NULL, sb.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, binary_file, 0);
    if (!binary_data)
    {
        printf("Error: failed to mmap '%s'\n", argv[argc-1]);
        close(binary_file);
        return -1;
    }
    
    /* Check that the binary starts with the magix 0x601a sequence */
    if( ((char*)binary_data)[0] != 0x60 || ((char*)binary_data)[1] != 0x1a)
    {
        printf("Error: invalid magic in '%s'\n", argv[argc-1]);
        close(binary_file);
        return -1;
    }
    
    argb++;
    argv += argb;
    argc -= argb;

    /* Setup a TOS environment for the binary */
    if (init_tos_environment(&te, binary_data, sb.st_size, argc, argv))
    {
        printf("Error: failed to initialize TOS environment\n");
        close(binary_file);
        return -1;
    }
    
    /* Close the binary file */
    close(binary_file);

    /* Start execution */

    /* TODO init cpu */
    m68k_init();
    m68k_set_cpu_type(M68K_CPU_TYPE_68000);
    m68k_pulse_reset();

    /* TODO is this really correct, or should it be the MSP? If so, why does that not work? */
    m68k_set_reg(M68K_REG_ISP, 0x600); /* supervisor stack pointer */
    m68k_set_reg(M68K_REG_USP, te.size-4); /* user stack pointer */
    m68k_write_memory_32(te.size, 0x800); /* big endian 0x800 */
    m68k_set_reg(M68K_REG_PC, 0x900); /* Set PC to the binary entry point */
    disable_supervisor_mode();
    
    /* TODO exec */
    while (keepongoing) {
        m68k_execute(1);
    }
  
    /* Clean up */
    free_tos_environment(&te);
    
    return 0; 
}