Linux SDL GUI + bug fixes + printf->slog

- sdl-gui/sdl.c is a tiny, basically working SDL2-based GUI that can compile and run on linux.
  It still needs PRAM integration and a config file.

- Fixed a dumb bug in shoebill_initialize that was causing sporadic crashes

- Replaced a million printf() calls with slog(), to make the SDL client run more quietly on the CLI

- Added more corruption checking to alloc_pool
This commit is contained in:
Peter Rutenbar 2014-06-09 16:21:12 -04:00
parent 5c1fdf6b73
commit 952fe7ae89
20 changed files with 753 additions and 312 deletions

View File

@ -107,7 +107,7 @@ void init_adb_state()
void adb_start_service_request()
{
//printf("adb_start_service_request: pending_requests = 0x%02x\n", shoe.adb.pending_service_requests);
//slog("adb_start_service_request: pending_requests = 0x%02x\n", shoe.adb.pending_service_requests);
if (shoe.adb.pending_service_requests) {
shoe.adb.service_request = 1;
@ -144,32 +144,33 @@ static void keyboard_talk(uint8_t reg)
else
shoe.adb.timeout = 1;
return ;
break ;
case 2:
// All the modifier keys are up
shoe.adb.data[0] = ~b(01111111);
shoe.adb.data[1] = ~b(11100111);
shoe.adb.data_len = 2;
return ;
break ;
case 1:
shoe.adb.timeout = 1;
return ;
break ;
case 3:
shoe.adb.data[0] = 0;
shoe.adb.data[1] = 0;
shoe.adb.data[0] = 0x02; // device address == 2 -> keyboard
shoe.adb.data[1] = 0x02; // device handler ID == 0x03 -> Apple Extended Keyboard
shoe.adb.data_len = 2;
return ;
break ;
}
slog("keyboard_talk: reg=%u timeout=%u data=0x%02x%02x datalen=%u\n", reg, shoe.adb.timeout, shoe.adb.data[0], shoe.adb.data[1], shoe.adb.data_len);
}
static void mouse_talk(uint8_t reg)
{
shoe.adb.timeout = 0;
printf("mouse_talk: reg=%u\n", reg);
slog("mouse_talk: reg=%u\n", reg);
switch (reg) {
case 0:
@ -180,7 +181,7 @@ static void mouse_talk(uint8_t reg)
int32_t x = shoe.mouse.delta_x;
int32_t y = shoe.mouse.delta_y;
//printf("mouse_talk: x=%d, y=%d button=%u\n", shoe.mouse.delta_x, shoe.mouse.delta_y, shoe.mouse.button_down);
//slog("mouse_talk: x=%d, y=%d button=%u\n", shoe.mouse.delta_x, shoe.mouse.delta_y, shoe.mouse.button_down);
if (x > hi_delta_limit) x = hi_delta_limit;
@ -194,7 +195,7 @@ static void mouse_talk(uint8_t reg)
//shoe.adb.data[1] |= 0x80;
shoe.adb.data[0] |= 0x80;
}
// printf("mouse_talk: ")
// slog("mouse_talk: ")
shoe.adb.data_len = 2;
@ -243,7 +244,7 @@ static void adb_handle_state_zero(uint8_t command_byte, uint8_t is_poll) // "Com
else
assert(!"What is this adb state-0 command? xxxx 01xx");
printf("adb_handle_state_zero: command_byte=0x%02x, id=%u, reg=%u\n", command_byte, id, reg);
slog("adb_handle_state_zero: command_byte=0x%02x, id=%u, reg=%u\n", command_byte, id, reg);
shoe.adb.command_device_id = id;
shoe.adb.command_reg = reg;
@ -279,7 +280,7 @@ static void adb_handle_state_one (void) // "Even" state
{
via_state_t *via = &shoe.via[0];
printf("adb_handle_state_one: ");
slog("adb_handle_state_one: ");
if (shoe.adb.poll) {
// Upon receiving a service request, the adb controller sends a TALK/reg=0 to the last accessed device
adb_handle_state_zero((shoe.adb.command_device_id << 4) | 0x0c, 1);
@ -292,12 +293,12 @@ static void adb_handle_state_one (void) // "Even" state
break;
case adb_talk:
printf("adb_talk: ");
slog("adb_talk: ");
if (shoe.adb.timeout) {
shoe.adb.timeout = 0;
via->regb_input &= ~~VIA_REGB_ADB_STATUS; // adb_status_line cleared == timeout
via_raise_interrupt(1, IFR_SHIFT_REG);
printf("timeout\n");
slog("timeout\n");
return ;
}
@ -306,17 +307,17 @@ static void adb_handle_state_one (void) // "Even" state
else
via->sr = 0;
printf("set sr = 0x%02x\n", via->sr);
slog("set sr = 0x%02x\n", via->sr);
break;
case adb_listen:
printf("adb_listen: ");
slog("adb_listen: ");
if (shoe.adb.timeout) {
shoe.adb.timeout = 0;
via->regb_input &= ~~VIA_REGB_ADB_STATUS; // adb_status_line cleared == timeout
via_raise_interrupt(1, IFR_SHIFT_REG);
printf("timeout\n");
slog("timeout\n");
return ;
}
@ -325,7 +326,7 @@ static void adb_handle_state_one (void) // "Even" state
else
assert(!"OS made us listen to > 8 bytes");
printf("loaded sr = 0x%02x\n", via->sr);
slog("loaded sr = 0x%02x\n", via->sr);
break;
}
@ -338,13 +339,13 @@ static void adb_handle_state_two (void) // "Odd" state
{
via_state_t *via = &shoe.via[0];
printf("adb_handle_state_two: ");
slog("adb_handle_state_two: ");
// If this transaction was part of a service request, clear the service_request flag now
if (shoe.adb.service_request) {
shoe.adb.service_request = 0;
via->regb_input &= ~~VIA_REGB_ADB_STATUS; // adb_status_line cleared == service request
printf("(service request) ");
slog("(service request) ");
}
else
via->regb_input |= VIA_REGB_ADB_STATUS; // adb_status_line set == no-service request
@ -352,25 +353,25 @@ static void adb_handle_state_two (void) // "Odd" state
switch (shoe.adb.command_type) {
case adb_flush:
case adb_reset:
printf("adb_flush/reset\n");
slog("adb_flush/reset\n");
break;
case adb_talk:
printf("adb_talk: ");
slog("adb_talk: ");
if (shoe.adb.data_i < shoe.adb.data_len)
via->sr = shoe.adb.data[shoe.adb.data_i++];
else
via->sr = 0;
printf("set sr = 0x%02x\n", via->sr);
slog("set sr = 0x%02x\n", via->sr);
break;
case adb_listen:
printf("adb_listen: ");
slog("adb_listen: ");
if (shoe.adb.data_i < 8)
shoe.adb.data[shoe.adb.data_i++] = via->sr;
else
assert(!"OS made us listen to > 8 bytes");
printf("read sr = 0x%02x\n", via->sr);
slog("read sr = 0x%02x\n", via->sr);
break;
}
@ -379,7 +380,7 @@ static void adb_handle_state_two (void) // "Odd" state
static void adb_handle_state_three (void) // "idle" state
{
printf("adb_handle_state_three: completed for id %u\n", shoe.adb.command_device_id);
slog("adb_handle_state_three: completed for id %u\n", shoe.adb.command_device_id);
switch (shoe.adb.command_type) {
case adb_reset:
@ -388,7 +389,7 @@ static void adb_handle_state_three (void) // "idle" state
break;
case adb_listen:
printf("adb_handle_state_three: listen completed for id %u, reg %u, data_len = %u {%02x %02x}\n",
slog("adb_handle_state_three: listen completed for id %u, reg %u, data_len = %u {%02x %02x}\n",
shoe.adb.command_device_id, shoe.adb.command_reg, shoe.adb.data_i, shoe.adb.data[0], shoe.adb.data[1]);
break;
}
@ -400,7 +401,7 @@ void adb_handle_state_change(uint8_t old_state, uint8_t new_state)
{
via_state_t *via = &shoe.via[0];
printf("%s: lock\n", __func__); fflush(stdout);
slog("%s: lock\n", __func__); fflush(stdout);
assert(pthread_mutex_lock(&shoe.adb.lock) == 0);
shoe.adb.state = new_state;
@ -424,7 +425,7 @@ void adb_handle_state_change(uint8_t old_state, uint8_t new_state)
break ;
}
printf("%s: unlock\n", __func__); fflush(stdout);
slog("%s: unlock\n", __func__); fflush(stdout);
pthread_mutex_unlock(&shoe.adb.lock);
}

View File

@ -26,6 +26,7 @@
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <string.h>
#include "../core/shoebill.h"
@ -53,6 +54,11 @@ typedef struct _alloc_pool_t {
} alloc_pool_t;
*/
static void _check_pool(alloc_pool_t *pool)
{
}
static alloc_pool_t* _ptr_to_header(void *ptr)
{
alloc_pool_t *apt = (alloc_pool_t*)ptr;
@ -66,7 +72,8 @@ void* p_alloc(alloc_pool_t *pool, uint64_t size)
buf->type = POOL_ALLOC_TYPE;
buf->t.alloc.size = size;
buf->magic = 'moof';
buf->start_magic = POOL_START_MAGIC;
buf->end_magic = POOL_END_MAGIC;
buf->next = pool->next;
buf->prev = pool;
@ -82,7 +89,8 @@ void* p_realloc(void *ptr, uint64_t size)
{
alloc_pool_t *header = _ptr_to_header(ptr);
assert(header->magic == 'moof');
assert(header->start_magic == POOL_START_MAGIC);
assert(header->end_magic == POOL_END_MAGIC);
assert(header->type == POOL_ALLOC_TYPE);
alloc_pool_t *new_header = realloc(header, size + sizeof(alloc_pool_t));
@ -107,7 +115,8 @@ void* p_realloc(void *ptr, uint64_t size)
*/
static void _p_free_any(alloc_pool_t *header)
{
assert(header->magic == 'moof');
assert(header->start_magic == POOL_START_MAGIC);
assert(header->end_magic == POOL_END_MAGIC);
if (header->next)
header->next->prev = header->prev;
@ -125,6 +134,7 @@ void p_free(void *ptr)
{
alloc_pool_t *header = _ptr_to_header(ptr);
assert(header->type == POOL_ALLOC_TYPE);
memset(ptr, 0xaa, header->t.alloc.size);
_p_free_any(header);
}
@ -136,7 +146,8 @@ void p_free_pool(alloc_pool_t *pool)
while (pool) {
alloc_pool_t *cur = pool;
pool = cur->next;
assert(cur->magic == 'moof');
assert(cur->start_magic == POOL_START_MAGIC);
assert(cur->end_magic == POOL_END_MAGIC);
switch (cur->type) {
case POOL_ALLOC_TYPE:
@ -166,7 +177,8 @@ alloc_pool_t* p_new_pool(alloc_pool_t *parent_pool)
{
alloc_pool_t *pool = calloc(sizeof(alloc_pool_t), 1);
pool->magic = 'moof';
pool->start_magic = POOL_START_MAGIC;
pool->end_magic = POOL_END_MAGIC;
pool->type = POOL_HEAD;
if (parent_pool) {

View File

@ -36,7 +36,7 @@ void symb_inorder(rb_node *cur) {
if (!sym)
return ;
symb_inorder(cur->left);
printf("0x%x %s\n", cur->key, sym->name);
slog("0x%x %s\n", cur->key, sym->name);
symb_inorder(cur->right);
}
@ -74,7 +74,7 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// Pull out 20 bytes (the file header)
if (!_coff_buf_read(rawhead, 20)) {
printf("coff_parse: error: this binary is missing its file header\n");
slog("coff_parse: error: this binary is missing its file header\n");
goto fail;
}
@ -93,11 +93,11 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// A little sanity checking...
if (cf->magic != 0x150) {
printf("coff_parse: I don't recognize this magic number: 0x%04x\n", cf->magic);
slog("coff_parse: I don't recognize this magic number: 0x%04x\n", cf->magic);
goto fail;
}
else if (cf->num_sections != 3) {
//printf("coff_parse: warning: there are %u sections in this file (not 3, like I expect)\n", cf->num_sections);
//slog("coff_parse: warning: there are %u sections in this file (not 3, like I expect)\n", cf->num_sections);
// FIXME: investigate all the other possible section types
}
@ -105,7 +105,7 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
if (cf->opt_header_len > 0) {
uint8_t *opt = p_alloc(cf->pool, cf->opt_header_len);
if (!_coff_buf_read(opt, cf->opt_header_len)) {
printf("coff_parse: I ran out of data pulling the optional header (%u bytes)\n", cf->opt_header_len);
slog("coff_parse: I ran out of data pulling the optional header (%u bytes)\n", cf->opt_header_len);
p_free(opt);
goto fail;
}
@ -118,7 +118,7 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// read the header
uint8_t rawsec[40];
if (!_coff_buf_read(rawsec, 40)) {
printf("coff_parse: I ran out of data pulling section #%u\n", i+1);
slog("coff_parse: I ran out of data pulling section #%u\n", i+1);
goto fail;
}
// and copy it into cf->sections[i]
@ -136,7 +136,7 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// a little bit of sanity checking:
if (cf->sections[i].v_addr != cf->sections[i].p_addr) {
//printf("coff_parse: warning: section %u's virtual_addr and physical_addr don't match: p=%x v=%x\n",
//slog("coff_parse: warning: section %u's virtual_addr and physical_addr don't match: p=%x v=%x\n",
// i+1, cf->sections[i].p_addr, cf->sections[i].v_addr);
// This is okay for the unix kernel
}
@ -158,14 +158,14 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// seek to the position in the binary that holds this section's raw data
if (!_coff_buf_seek(cf->sections[i].data_ptr)) {
printf("coff_parse: I couldn't seek to 0x%x in section %u\n", cf->sections[i].data_ptr, i+1);
slog("coff_parse: I couldn't seek to 0x%x in section %u\n", cf->sections[i].data_ptr, i+1);
goto fail;
}
// load the data and attach it to the section struct
data = p_alloc(cf->pool, cf->sections[i].sz); // FIXME: sz might not be a sane value
if (!_coff_buf_read(data, cf->sections[i].sz)) {
printf("coff_parse: I couldn't fread section %u (%s)'s data (%u bytes)\n", i+1, cf->sections[i].name, cf->sections[i].sz);
slog("coff_parse: I couldn't fread section %u (%s)'s data (%u bytes)\n", i+1, cf->sections[i].name, cf->sections[i].sz);
p_free(data);
goto fail;
}
@ -178,19 +178,19 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
return cf; // just return
cf->func_tree = rb_new(cf->pool);
//printf("func_tree = %llx, *func_tree = %llx\n", cf->func_tree, *cf->func_tree);
//slog("func_tree = %llx, *func_tree = %llx\n", cf->func_tree, *cf->func_tree);
cf->symbols = (coff_symbol*)p_alloc(cf->pool, sizeof(coff_symbol) *cf->num_symbols);
// Seek to the symbol table
if (!_coff_buf_seek(cf->symtab_offset)) {
printf("coff_parse: I couldn't seek to symtab_offset, 0x%x\n", cf->symtab_offset);
slog("coff_parse: I couldn't seek to symtab_offset, 0x%x\n", cf->symtab_offset);
goto fail;
}
for (i=0; i < cf->num_symbols; i++) {
uint8_t raw_symb[18];
if (!_coff_buf_read(raw_symb, 18)) {
printf("coff_parse: I ran out of data pulling symbol #%u\n", i+1);
slog("coff_parse: I ran out of data pulling symbol #%u\n", i+1);
goto fail;
}
@ -201,15 +201,15 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
for (j=4, offset=0; j<8; j++) offset = (offset<<8) | raw_symb[j];
idx += offset;
// printf("Loading from external: base idx=0x%x, offset=%u, addr=0x%x\n", idx-offset, offset, idx);
// slog("Loading from external: base idx=0x%x, offset=%u, addr=0x%x\n", idx-offset, offset, idx);
if (!_coff_buf_seek(idx)) {
printf("coff_parse: I ran out of data pulling symbol %u's name (idx=0x%x)\n", i+1, idx);
slog("coff_parse: I ran out of data pulling symbol %u's name (idx=0x%x)\n", i+1, idx);
goto fail;
}
for (j=0; (_coff_buf_read(&tmp_name[j], 1)) && tmp_name[j]; j++) {
if (j >= 255) {
// printf("coff_parse: this symbol's name is too long: %u\n", i+1);
// slog("coff_parse: this symbol's name is too long: %u\n", i+1);
goto fail;
}
}
@ -235,17 +235,17 @@ coff_file* coff_parse(uint8_t *buf, uint32_t buflen, alloc_pool_t *parent_pool)
// FIXME: I need to handle numaux > 0.
//if (cf->symbols[i].numaux > 0) {
printf("%s\n", cf->symbols[i].name);
printf("value=0x%08x scnum=0x%04x type=0x%04x sclass=0x%02x numaux=%u\n\n",
slog("%s\n", cf->symbols[i].name);
slog("value=0x%08x scnum=0x%04x type=0x%04x sclass=0x%02x numaux=%u\n\n",
cf->symbols[i].value, cf->symbols[i].scnum, cf->symbols[i].type, cf->symbols[i].sclass, cf->symbols[i].numaux);
//}
if (cf->symbols[i].sclass == 2 || cf->symbols[i].sclass == 3) {
rb_insert(cf->func_tree, cf->symbols[i].value, &cf->symbols[i], NULL);
//printf("%s addr=0x%x\n", cf->symbols[i].name, cf->symbols[i].value);
//slog("%s addr=0x%x\n", cf->symbols[i].name, cf->symbols[i].value);
}
// printf("%u: %s (class=%u)\n", i+1, cf->symbols[i].name, cf->symbols[i].sclass);
// slog("%u: %s (class=%u)\n", i+1, cf->symbols[i].name, cf->symbols[i].sclass);
}
@ -301,19 +301,19 @@ void print_coff_info(coff_file *coff)
time_t timestamp = coff->timestamp;
uint32_t i;
printf("Magic = 0x%04x\n", coff->magic);
printf("Linked on %s", ctime_r(&timestamp, timebuf));
printf("Num sections = %u\n", coff->num_sections);
slog("Magic = 0x%04x\n", coff->magic);
slog("Linked on %s", ctime_r(&timestamp, timebuf));
slog("Num sections = %u\n", coff->num_sections);
printf("debug: num_symbols=%u, symtab_offset=0x%x\n", coff->num_symbols, coff->symtab_offset);
slog("debug: num_symbols=%u, symtab_offset=0x%x\n", coff->num_symbols, coff->symtab_offset);
for (i=0; i<coff->num_sections; i++) {
coff_section *s = &coff->sections[i];
char name[9];
memcpy(name, s->name, 8);
name[8] = 0;
printf("Section #%u: %s\n", i+1, name);
printf("\taddr=0x%08x, len=0x%x, (debug: paddr=0x%08x, flags=0x%08x)\n", s->v_addr, s->sz, s->p_addr, s->flags);
slog("Section #%u: %s\n", i+1, name);
slog("\taddr=0x%08x, len=0x%x, (debug: paddr=0x%08x, flags=0x%08x)\n", s->v_addr, s->sz, s->p_addr, s->flags);
}
}
@ -333,13 +333,13 @@ coff_symbol* coff_find_func(coff_file *coff, uint32_t addr)
rb_node *cur;
coff_symbol *last = NULL;
// printf("coff->num_symbols = %u\n", coff->num_symbols);
// slog("coff->num_symbols = %u\n", coff->num_symbols);
if (coff->num_symbols == 0)
return NULL;
cur = coff->func_tree->root;
while (cur) {
// printf("... iterating\n");
// slog("... iterating\n");
if (addr < cur->key)
cur = cur->left;
else if (addr > cur->key) {

View File

@ -31,6 +31,7 @@
#include <pthread.h>
#include <unistd.h>
#include <signal.h>
#include <stdarg.h>
#include "../core/shoebill.h"
@ -414,11 +415,11 @@ static uint32_t _open_disk_images (shoebill_config_t *config, scsi_device_t *dis
uint32_t i;
for (i=0; i<8; i++) {
shoe.scsi_devices[i].scsi_id = i;
shoe.scsi_devices[i].block_size = 0;
shoe.scsi_devices[i].num_blocks = 0;
shoe.scsi_devices[i].image_path = "dummy";
shoe.scsi_devices[i].f = NULL;
disks[i].scsi_id = i;
disks[i].block_size = 0;
disks[i].num_blocks = 0;
disks[i].image_path = "dummy";
disks[i].f = NULL;
}
for (i=0; i<7; i++) {
@ -437,7 +438,7 @@ static uint32_t _open_disk_images (shoebill_config_t *config, scsi_device_t *dis
disks[i].scsi_id = i;
disks[i].f = f;
tmp = p_alloc(shoe.pool, strlen(path+1));
tmp = p_alloc(shoe.pool, strlen(path) + 1);
strcpy(tmp, path);
disks[i].image_path = tmp;
@ -505,8 +506,7 @@ fail:
}
uint32_t shoebill_install_video_card(shoebill_config_t *config, uint8_t slotnum,
uint16_t width, uint16_t height,
double refresh_rate)
uint16_t width, uint16_t height)
{
shoebill_card_video_t *ctx;
@ -530,10 +530,8 @@ uint32_t shoebill_install_video_card(shoebill_config_t *config, uint8_t slotnum,
shoe.slots[slotnum].connected = 1;
shoe.slots[slotnum].read_func = nubus_video_read_func;
shoe.slots[slotnum].write_func = nubus_video_write_func;
shoe.slots[slotnum].interrupt_rate = refresh_rate;
shoe.slots[slotnum].last_fired = 0;
shoe.slots[slotnum].interrupts_enabled = 1;
nubus_video_init(ctx, slotnum, width, height, scanline_width, refresh_rate);
nubus_video_init(ctx, slotnum, width, height, scanline_width);
return 1;
}
@ -1008,3 +1006,25 @@ void shoebill_send_vbl_interrupt(uint8_t slotnum)
}
}
void slog(const char *fmt, ...)
{
va_list args;
return ;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
}

View File

@ -138,7 +138,7 @@ static void inst_asx_reg (void) {
uint32_t dat = get_d(r, sz);
const uint32_t tmask = (mib(dat,sz)) << (sz*8-1); // 0 if mib==0, 0x80, 0x8000, or 0x80000000 if mib==1
//printf("asr: dat=%u sz=%u count=%u", dat, sz, count);
//slog("asr: dat=%u sz=%u count=%u", dat, sz, count);
uint8_t i=0, lastb=0;
for (; i < count; i++) {
@ -155,7 +155,7 @@ static void inst_asx_reg (void) {
set_sr_v(0);
set_sr_c(lastb);
//printf(" result=%u\n", get_d(r, sz));
//slog(" result=%u\n", get_d(r, sz));
}
}
@ -182,7 +182,7 @@ static void inst_asx_mem (void) {
const uint16_t R = (uint16_t)(((int16_t)dat) >> 1);
const uint16_t lost = dat & 1;
printf("asr_mem: shifted 0x%04x to 0x%04x lost=%u\n", dat, R, lost);
slog("asr_mem: shifted 0x%04x to 0x%04x lost=%u\n", dat, R, lost);
shoe.dat = R;
call_ea_write(M, 2);
@ -322,7 +322,7 @@ static void inst_rox_reg (void) {
uint8_t count = i ? (shoe.d[c] & 63) : ( c ? c : 8) ;
uint32_t j;
// printf("rox_reg: count = %u\n", count);
// slog("rox_reg: count = %u\n", count);
if (!d) { // right
for (j=0; j<count; j++) {
@ -447,7 +447,7 @@ static void inst_abcd (void) {
uint8_t packed_x, packed_y;
const uint8_t extend = sr_x() ? 1 : 0;
// printf("abcd: pc=0x%08x extend=%u m=%u x=%u y=%u\n", shoe.orig_pc, extend, m, x, y);
// slog("abcd: pc=0x%08x extend=%u m=%u x=%u y=%u\n", shoe.orig_pc, extend, m, x, y);
if (m) {
// predecrement mem to predecrement mem
@ -473,7 +473,7 @@ static void inst_abcd (void) {
const uint8_t carry = (sum >= 100);
const uint8_t packed_sum = ((unpacked_sum / 10) << 4) | (unpacked_sum % 10);
// printf("abcd: packed_x = 0x%02x(%u) packed_y = 0x%02x(%u) sum=0x%02x(%u) carry=%u\n", packed_x, unpacked_x, packed_y, unpacked_y, packed_sum, unpacked_sum, carry);
// slog("abcd: packed_x = 0x%02x(%u) packed_y = 0x%02x(%u) sum=0x%02x(%u) carry=%u\n", packed_x, unpacked_x, packed_y, unpacked_y, packed_sum, unpacked_sum, carry);
if (unpacked_sum)
set_sr_z(0);
@ -508,7 +508,7 @@ static void inst_muls (void) {
const int32_t s_result = ((int32_t)s_a) * ((int32_t)s_b);
const uint32_t result = (uint32_t)s_result;
//printf("muls: %d * %d = %d\n", s_a, s_b, s_result);
//slog("muls: %d * %d = %d\n", s_a, s_b, s_result);
shoe.d[r] = result;
@ -606,7 +606,7 @@ static void inst_rte (void) {
const uint16_t format_word = lget(shoe.a[7]+6, 2);
if (shoe.abort) return ;
// printf("rte: sr=0x%04x pc=0x%08x format=0x%04x, post-pop a7=0x%08x\n", sr, pc, format_word, shoe.a[7]+8);
// slog("rte: sr=0x%04x pc=0x%08x format=0x%04x, post-pop a7=0x%08x\n", sr, pc, format_word, shoe.a[7]+8);
switch (format_word >> 12) {
case 0:
@ -631,7 +631,7 @@ static void inst_rte (void) {
return ;
}
default:
printf("rte?? I don't recognize this exception format! 0x%04x\n", format_word);
slog("rte?? I don't recognize this exception format! 0x%04x\n", format_word);
assert(!"rte?? Don't recognize this exception format!\n");
break;
}
@ -732,8 +732,8 @@ static void inst_moveq (void) {
set_sr_v(0);
set_sr_z(d==0);
set_sr_n(d>>7);
// printf("dat = %x, shoe.d[%u] = %x\n", dat, r, shoe.d[r]);
// printf("I'm called, right?\n");
// slog("dat = %x, shoe.d[%u] = %x\n", dat, r, shoe.d[r]);
// slog("I'm called, right?\n");
}
static void inst_add (void) {
@ -795,7 +795,7 @@ static void inst_addx (void) {
const uint32_t R = shoe.d[y] + extend_bit + shoe.d[x];
// printf("addx: S d[%u] = 0x%x, D d[%u] = 0x%x, R = 0x%x\n", crop(shoe.d[y], sz), crop(shoe.d[x], sz), crop(R, sz));
// slog("addx: S d[%u] = 0x%x, D d[%u] = 0x%x, R = 0x%x\n", crop(shoe.d[y], sz), crop(shoe.d[x], sz), crop(R, sz));
set_d(x, R, sz);
Rm = mib(R, sz);
@ -983,7 +983,7 @@ static void inst_long_mul (void) {
const int64_t R_signed = ((int64_t)S) * ((int64_t)D);
R = R_signed;
//printf("long_muls: %d * %d = (int64_t)%lld (int32_t)%d\n", S, D, R, (uint32_t)(R&0xffffffff));
//slog("long_muls: %d * %d = (int64_t)%lld (int32_t)%d\n", S, D, R, (uint32_t)(R&0xffffffff));
}
shoe.d[L] = (uint32_t)R;
@ -1298,7 +1298,7 @@ static void inst_movec (void) {
case 0x805: // MMUSR
case 0x806: // URP
case 0x807: // SRP
printf("inst_movec: error! I don't support this condition code yet! (0x%03x)\n", c);
slog("inst_movec: error! I don't support this condition code yet! (0x%03x)\n", c);
assert(!"inst_movec: error: unknown condition\n");
return ;
@ -1336,7 +1336,7 @@ static void inst_moves (void) {
// For now, only supporting fc 1 (user data space)
if (fc != 1) {
printf("inst_moves: error: hit fc=%u\n", fc);
slog("inst_moves: error: hit fc=%u\n", fc);
assert(!"inst_moves: error, hit weird function code");
return ;
}
@ -1923,7 +1923,7 @@ static void inst_jsr (void) {
lset(shoe.a[7]-4, 4, shoe.pc);
if (shoe.abort) return ;
// printf("jsr: writing pc (0x%08x) to *0x%08x (phys=0x%08x)\n", shoe.pc, shoe.a[7]-4, shoe.physical_addr);
// slog("jsr: writing pc (0x%08x) to *0x%08x (phys=0x%08x)\n", shoe.pc, shoe.a[7]-4, shoe.physical_addr);
shoe.a[7] -= 4;
shoe.pc = shoe.dat;
@ -2011,7 +2011,7 @@ static void inst_rts (void) {
// return ;
coff_symbol *symb = coff_find_func(shoe.coff, shoe.pc);
if (symb)
printf("RETURN TO %s+%u 0x%08x\n", symb->name, shoe.pc-symb->value, shoe.pc);
slog("RETURN TO %s+%u 0x%08x\n", symb->name, shoe.pc-symb->value, shoe.pc);
}
else if (0){
char *name = (char*)"unknown";
@ -2027,7 +2027,7 @@ static void inst_rts (void) {
}
}
printf("RETURN TO %s+%u 0x%08x\n", name, shoe.pc-value, shoe.pc);
slog("RETURN TO %s+%u 0x%08x\n", name, shoe.pc-value, shoe.pc);
}*/
}
@ -2112,7 +2112,7 @@ static void inst_movem (void) {
if (~bmatch(M, xx100xxx)) { // if predecrement,
uint16_t maskcopy;
// printf("*0x%08x movem %02x\n", shoe.orig_pc, shoe.op);
// slog("*0x%08x movem %02x\n", shoe.orig_pc, shoe.op);
for (maskcopy=mask, i=0; i < 16; i++) {
newmask = (newmask<<1) | (maskcopy & 1); // build a flipped version of mask
@ -2158,7 +2158,7 @@ static void inst_movem (void) {
// if this is pre-dec mode, and we're pushing the address reg specified in the EA
if ( (M>>3) == 4 && (M&7)==i ) {
data -= sz;
printf("movem: For movem %u/%u, deciding to write 0x%08x for a%u\n", M>>3, M&7, data, M&7);
slog("movem: For movem %u/%u, deciding to write 0x%08x for a%u\n", M>>3, M&7, data, M&7);
}
lset(addr, sz, data);
@ -2240,7 +2240,7 @@ void write_bitfield(const uint32_t width, const uint32_t offset, const uint32_t
// call_ea_addr(M);
const uint32_t first_byte_addr = ea + byte_offset;
//printf("debug: extract_bitfield: addr = 0x%08x, first_byte_addr = 0x%08x\n", ea, first_byte_addr);
//slog("debug: extract_bitfield: addr = 0x%08x, first_byte_addr = 0x%08x\n", ea, first_byte_addr);
// if the field is contained entirely within the first byte
@ -2252,8 +2252,8 @@ void write_bitfield(const uint32_t width, const uint32_t offset, const uint32_t
const uint8_t new_byte = (old_byte & (~~byte_mask)) | field_mask;
lset(first_byte_addr, 1, new_byte);
//printf("write_bitfield: byte_mask = 0x%02x field_mask = 0x%02x bit_offset=%u byte_offset=%u\n", byte_mask, field_mask, bit_offset, byte_offset);
//printf("write_bitfield: changing byte at 0x%08x from 0x%02x to 0x%02x\n",
//slog("write_bitfield: byte_mask = 0x%02x field_mask = 0x%02x bit_offset=%u byte_offset=%u\n", byte_mask, field_mask, bit_offset, byte_offset);
//slog("write_bitfield: changing byte at 0x%08x from 0x%02x to 0x%02x\n",
//first_byte_addr, old_byte, new_byte);
if (shoe.abort) return ;
}
@ -2271,10 +2271,10 @@ void write_bitfield(const uint32_t width, const uint32_t offset, const uint32_t
const uint8_t field_chunk = remaining_field >> (32-curwidth);
const uint8_t rotated_chunk = (field_chunk << (8-curwidth)) >> boff;
// printf("mask = 0x%02x\nfield = 0x%02x\n", mask, rotated_chunk);
// slog("mask = 0x%02x\nfield = 0x%02x\n", mask, rotated_chunk);
lset(addr, 1, (byte & mask) | rotated_chunk);
//printf("write_bitfield: changing byte at 0x%08x from 0x%02x to 0x%02x\n",
//slog("write_bitfield: changing byte at 0x%08x from 0x%02x to 0x%02x\n",
//addr, byte, (byte & mask) | rotated_chunk);
if (shoe.abort) return ;
@ -2317,13 +2317,13 @@ uint32_t extract_bitfield(const uint32_t width, const uint32_t offset, const uin
// ea_addr();
// if (shoe.abort) return 0;
//printf("debug: extract_bitfield: offset = 0x%08x, byte_offset = %d, bit_offset = %d\n", offset, byte_offset, bit_offset);
//slog("debug: extract_bitfield: offset = 0x%08x, byte_offset = %d, bit_offset = %d\n", offset, byte_offset, bit_offset);
const uint32_t first_byte_addr = ea + byte_offset;
//printf("debug: extract_bitfield: addr = 0x%08x, first_byte_addr = 0x%08x\n", ea, first_byte_addr);
//slog("debug: extract_bitfield: addr = 0x%08x, first_byte_addr = 0x%08x\n", ea, first_byte_addr);
field = bitchop(lget(first_byte_addr, 1), 8-bit_offset);
//printf("debug: extract_bitfield: first byte field (low %u bits): 0x%02x\n", 8-bit_offset, field);
//slog("debug: extract_bitfield: first byte field (low %u bits): 0x%02x\n", 8-bit_offset, field);
if (shoe.abort) return 0;
if (width > (8-bit_offset)) { // if the data isn't entirely contained in the first byte
uint32_t last_long = lget(first_byte_addr+1, 4);
@ -2534,7 +2534,7 @@ static void inst_bfins (void) {
const uint32_t offset = F ? (shoe.d[f]) : f; // [0, 31]
const uint32_t field = bitchop(shoe.d[r], width);
// printf("write_bitfield: writing %u at offset=%u width=%u\n", field, offset, width);
// slog("write_bitfield: writing %u at offset=%u width=%u\n", field, offset, width);
uint32_t ea = 0;
if (M >> 3) { // If ea isn't data reg mode (handled separately in *_bitfield())
@ -2790,7 +2790,7 @@ static void inst_mc68851_decode (void) {
}
static void inst_unknown (void) {
printf("Unknown instruction (0x%04x)!\n", shoe.op);
slog("Unknown instruction (0x%04x)!\n", shoe.op);
/*if (shoe.op == 0x33fe) {
dump_ring();
assert(!"dumped");
@ -2806,13 +2806,13 @@ static void inst_a_line (void) {
uint32_t fp_op = lget(shoe.a[7]+0, 2);
uint32_t fp_operand_addr = lget(shoe.a[7]+2, 4);
printf("%s : op 0x%04x (", (shoe.op == 0xA9EB) ? "FP68K" : "Elems68K", fp_op);
slog("%s : op 0x%04x (", (shoe.op == 0xA9EB) ? "FP68K" : "Elems68K", fp_op);
uint8_t buf[10];
uint32_t i;
for (i=0; i<10; i++) {
buf[i] = lget(fp_operand_addr+i, 1);
printf("%02x ", buf[i]);
slog("%02x ", buf[i]);
}
{
@ -2821,7 +2821,7 @@ static void inst_a_line (void) {
buf[4], buf[3], buf[2], buf[1], buf[0],
0, 0
};
printf("%Lf)\n", *(long double*)&castable[0]);
slog("%Lf)\n", *(long double*)&castable[0]);
}
@ -2838,7 +2838,7 @@ void trap_debug()
shoe.suppress_exceptions = 1;
const uint32_t syscall = lget(shoe.a[7]+4, 4);
printf("syscall = %u\n", shoe.d[0]);
slog("syscall = %u\n", shoe.d[0]);
switch (shoe.d[0]) {
@ -2846,13 +2846,13 @@ void trap_debug()
uint32_t fd = lget(shoe.a[7]+4, 4);
uint32_t buf = lget(shoe.a[7]+8, 4);
uint32_t len = lget(shoe.a[7]+12, 4);
printf("write(%u, 0x%08x, %u) \"", fd, buf, len);
slog("write(%u, 0x%08x, %u) \"", fd, buf, len);
uint32_t i;
for (i=0; i<len; i++) {
printf("%c", (uint32_t)lget(buf+i, 1));
slog("%c", (uint32_t)lget(buf+i, 1));
}
printf("\"\n");
slog("\"\n");
break;
}
@ -2860,29 +2860,29 @@ void trap_debug()
uint32_t path_p = lget(shoe.a[7]+4, 4);
uint32_t oflag = lget(shoe.a[7]+8, 4);
printf("shoe.orig_pc = 0x%08x\n", shoe.orig_pc);
printf("open(0x%08x, %u) \"", path_p, oflag);
slog("shoe.orig_pc = 0x%08x\n", shoe.orig_pc);
slog("open(0x%08x, %u) \"", path_p, oflag);
uint32_t i;
for (i=0; 1; i++) {
uint8_t c = lget(path_p+i, 1);
if (c == 0) break;
printf("%c", c);
slog("%c", c);
}
printf("\"\n");
slog("\"\n");
break;
}*/
case 59: // exece
case 11: { // exec
char name[64];
uint32_t path_p = lget(shoe.a[7]+4, 4);
printf("exec(0x%08x, ...) \"", path_p);
slog("exec(0x%08x, ...) \"", path_p);
uint32_t i;
for (i=0; i < 64; i++) {
name[i] = lget(path_p+i, 1);
if (name[i] == 0) break;
}
name[63] = 0;
printf("%s\"\n", name);
slog("%s\"\n", name);
break;
}

View File

@ -67,7 +67,7 @@ void disass_ea_extended (char *buf, uint8_t mr)
// z == base displacement size
// I == index/indirect selection
// printf("index_reg_type=%u, index_reg=%u, index_sz=%u, scale=%u, brief/ful=%u, supress_base=%u, suppress_index=%u, base_disp_sz=%u, I=%x\n",
// slog("index_reg_type=%u, index_reg=%u, index_sz=%u, scale=%u, brief/ful=%u, supress_base=%u, suppress_index=%u, base_disp_sz=%u, I=%x\n",
// d, r, w, s, F, b, i, z, I);
if (F == 0) { // If this is the brief extension word

View File

@ -45,7 +45,7 @@ void throw_long_bus_error(uint32_t addr, uint8_t is_write)
// Save this value now, because lset() calls will reset it
const uint8_t fc = shoe.logical_fc;
//printf("throw_long_bus_error(): I'm throwing a LONG bus error (at pc = 0x%08x)!\n", shoe.orig_pc);
//slog("throw_long_bus_error(): I'm throwing a LONG bus error (at pc = 0x%08x)!\n", shoe.orig_pc);
// set supervisor bit
set_sr_s(1);
@ -60,7 +60,7 @@ void throw_long_bus_error(uint32_t addr, uint8_t is_write)
// fetch vector handler address
const uint32_t vector_addr = lget(shoe.vbr + vector_offset, 4);
//printf("throw_long_bus_error(): shoe.vbr=0x%08x, vector_addr=0x%08x, offending addr=0x%08x, shoe.op=0x%04x\n", shoe.vbr, vector_addr, addr, shoe.op);
//slog("throw_long_bus_error(): shoe.vbr=0x%08x, vector_addr=0x%08x, offending addr=0x%08x, shoe.op=0x%04x\n", shoe.vbr, vector_addr, addr, shoe.op);
assert(!shoe.abort); // FIXME: I can't handle another exception here
const uint16_t ssw = SSW_DF | (is_write ? 0 : SSW_IS_READ) | fc;
@ -120,7 +120,7 @@ void throw_bus_error(uint32_t addr, uint8_t is_write)
//dbg_state.running = 0;
//printf("throw_bus_error(): I'm throwing a bus error (at pc = 0x%08x)!\n", shoe.orig_pc);
//slog("throw_bus_error(): I'm throwing a bus error (at pc = 0x%08x)!\n", shoe.orig_pc);
// set supervisor bit
set_sr_s(1);
@ -135,7 +135,7 @@ void throw_bus_error(uint32_t addr, uint8_t is_write)
// fetch vector handler address
const uint32_t vector_addr = lget(shoe.vbr + vector_offset, 4);
//printf("throw_bus_error(): shoe.vbr=0x%08x, vector_addr=0x%08x, offending addr=0x%08x, shoe.op=0x%04x, a7=0x%08x", shoe.vbr, vector_addr, addr, shoe.op, shoe.a[7]);
//slog("throw_bus_error(): shoe.vbr=0x%08x, vector_addr=0x%08x, offending addr=0x%08x, shoe.op=0x%04x, a7=0x%08x", shoe.vbr, vector_addr, addr, shoe.op, shoe.a[7]);
assert(!shoe.abort); // FIXME: I can't handle another exception here
const uint16_t ssw =
@ -143,7 +143,7 @@ void throw_bus_error(uint32_t addr, uint8_t is_write)
(is_write ? 0 : SSW_IS_READ) | // read or write
fc; // a/ux 3.0.1 cares about this - the address space
//printf(" fc=%u\n", shoe.logical_fc);
//slog(" fc=%u\n", shoe.logical_fc);
// Note: We're pushing frame format 0xA
push_a7(0, 4); // internal registers 5 and 4
@ -167,7 +167,7 @@ void throw_bus_error(uint32_t addr, uint8_t is_write)
void throw_address_error()
{
printf("throw_address_error(): I'm throwing an address error!\n");
slog("throw_address_error(): I'm throwing an address error!\n");
assert(!"address error");
shoe.abort = 1;
}
@ -217,7 +217,7 @@ void throw_frame_two (uint16_t sr, uint32_t next_pc, uint32_t vector_num, uint32
void throw_illegal_instruction()
{
//printf("throw_illegal_instruction(): I'm throwing an illegal instruction exception! (shoe.pc = 0x%08x, op=0x%04x, a7=0x%08x)\n", shoe.orig_pc, shoe.op, shoe.a[7]);
//slog("throw_illegal_instruction(): I'm throwing an illegal instruction exception! (shoe.pc = 0x%08x, op=0x%04x, a7=0x%08x)\n", shoe.orig_pc, shoe.op, shoe.a[7]);
/*if ((shoe.op != 0xf010) && ((shoe.op >> 12) != 0xa))
//assert(!"illegal");
@ -231,7 +231,7 @@ void throw_illegal_instruction()
throw_frame_zero(shoe.orig_sr, shoe.orig_pc, vector_num);
/*if ((shoe.op >> 12) == 0xa) {
printf("Atrap: %s\n", atrap_names[shoe.op & 0xfff]?atrap_names[shoe.op & 0xfff]:"???");
slog("Atrap: %s\n", atrap_names[shoe.op & 0xfff]?atrap_names[shoe.op & 0xfff]:"???");
}
else
dbg_state.running = 0;*/
@ -240,7 +240,7 @@ void throw_illegal_instruction()
void throw_privilege_violation()
{
//printf("throw_privilege_violation(): I'm throwing a privilege violation exception! (shoe.orig_pc = 0x%08x op=0x%04x\n", shoe.orig_pc, shoe.op);
//slog("throw_privilege_violation(): I'm throwing a privilege violation exception! (shoe.orig_pc = 0x%08x op=0x%04x\n", shoe.orig_pc, shoe.op);
throw_frame_zero(shoe.orig_sr, shoe.orig_pc, 8);
// shoe.abort = 1;

View File

@ -240,7 +240,7 @@ static disk_t* open_disk (const char *disk_path, char *error_str)
}
}
// printf("sizeof(apple_part_map_t) = %lu\n", sizeof(apple_partition_map_t));
// slog("sizeof(apple_part_map_t) = %lu\n", sizeof(apple_partition_map_t));
// Load the partition maps
@ -269,8 +269,8 @@ static disk_t* open_disk (const char *disk_path, char *error_str)
memcpy(disk->partitions[i].name, disk->partition_maps[i].pmPartName, 32);
memcpy(disk->partitions[i].type, disk->partition_maps[i].pmPartType, 32);
printf("%u type:%s name:%s\n", i, disk->partitions[i].type, disk->partitions[i].name);
printf("bz_magic=0x%08x slice=%u\n", disk->partition_maps[i].bz.magic, disk->partition_maps[i].bz.slice);
slog("%u type:%s name:%s\n", i, disk->partitions[i].type, disk->partitions[i].name);
slog("bz_magic=0x%08x slice=%u\n", disk->partition_maps[i].bz.magic, disk->partition_maps[i].bz.slice);
}
return disk;
@ -332,7 +332,7 @@ static int32_t find_root_partition_number(disk_t *disk, uint8_t clus_num)
partition_t *part = &disk->partitions[i];
apple_partition_map_t *apm = &disk->partition_maps[i];
// printf("%u magic=0x%08x root=%u type=%s\n", i, apm->bz.magic, apm->bz.root, part->type);
// slog("%u magic=0x%08x root=%u type=%s\n", i, apm->bz.magic, apm->bz.root, part->type);
if (apm->bz.magic != 0xabadbabe)
continue;
@ -417,7 +417,7 @@ static uint8_t svfs_read_block(svfs_t *mount, uint8_t *block, uint32_t blockno)
const uint32_t start_sector = blockno * sectors_per_block;
uint32_t i;
// printf("sectors_per_block = %u, start_sector=%u\n", sectors_per_block, start_sector);
// slog("sectors_per_block = %u, start_sector=%u\n", sectors_per_block, start_sector);
for (i=0; i<sectors_per_block; i++) {
part_get_block(mount->part, &block[i * 512], start_sector+i);
@ -637,9 +637,9 @@ svfs_inode_t* svfs_traverse_path(svfs_t *mount, const char *_path)
for (elem = strtok_r(path, "/", &last);
elem;
elem = strtok_r(NULL, "/", &last)) {
//printf("elem = [%s]\n", elem);
//slog("elem = [%s]\n", elem);
const uint32_t num_entries = inode->size / 16;
//printf("inode size = %u\n", inode->size);
//slog("inode size = %u\n", inode->size);
svfs_dir_entry_t *dir = (svfs_dir_entry_t*)svfs_read_inode_data(mount, inode);
if (!dir)
goto fail;
@ -660,7 +660,7 @@ svfs_inode_t* svfs_traverse_path(svfs_t *mount, const char *_path)
goto fail;
}
}
//printf("final inode size = %u\n", inode->size);
//slog("final inode size = %u\n", inode->size);
p_free(path);
return inode;
@ -900,8 +900,8 @@ static uint8_t ufs_load_inode(ufs_t *mount, ufs_inode_t *inode, uint32_t inum)
uint32_t i;
uint8_t *buf = p_alloc(mount->pool, mount->frag_size);
// printf("group_num = %u, ino_offset=%u, addr = 0x%08x, offset = 0x%08x\n", group_num, group_ino_offset, frag_addr, frag_offset);
// printf("mount->superblock.iblkno = 0x%08x\n", mount->superblock.iblkno);
// slog("group_num = %u, ino_offset=%u, addr = 0x%08x, offset = 0x%08x\n", group_num, group_ino_offset, frag_addr, frag_offset);
// slog("mount->superblock.iblkno = 0x%08x\n", mount->superblock.iblkno);
if (!ufs_read_frag(mount, buf, frag_addr))
goto fail;
@ -953,7 +953,7 @@ static uint8_t ufs_read_level(ufs_t *mount,
goto fail;
// for (i=0; i<num_pointers; i++)
// printf("%u 0x%08x\n", i, ntohl(table[i]));
// slog("%u 0x%08x\n", i, ntohl(table[i]));
if (level == 1)
block = p_alloc(mount->pool, mount->block_size);
@ -970,11 +970,11 @@ static uint8_t ufs_read_level(ufs_t *mount,
const uint32_t block_addr = (blockno / mount->frag_per_block) * mount->frag_per_block;
const uint32_t block_offset = (blockno - block_addr) * mount->frag_size;
printf("L%u: raw_blkno=0x%08x len=0x%08x blockno:0x%08x chunk_size=0x%08x\n", level-1, blockno, (uint32_t)*len, block_addr, (uint32_t)chunk_size);
slog("L%u: raw_blkno=0x%08x len=0x%08x blockno:0x%08x chunk_size=0x%08x\n", level-1, blockno, (uint32_t)*len, block_addr, (uint32_t)chunk_size);
// If the chunk_size is a whole block, then we better be reading in a whole block
if (chunk_size == mount->block_size) {
// printf("block_offset = 0x%x\n", block_offset);
// slog("block_offset = 0x%x\n", block_offset);
assert(block_offset == 0);
}
@ -1020,7 +1020,7 @@ static uint8_t* ufs_read_inode_data(ufs_t *mount, ufs_inode_t *inode)
const uint32_t block_addr = (inode->direct[i] / mount->frag_per_block) * mount->frag_per_block;
const uint32_t block_offset = (inode->direct[i] - block_addr) * mount->frag_size;
// printf("block_addr=0x%08x, block_offset")
// slog("block_addr=0x%08x, block_offset")
// If the chunk_size is a whole block, then we better be reading in a whole block
if (chunk_size == mount->block_size)
@ -1032,7 +1032,7 @@ static uint8_t* ufs_read_inode_data(ufs_t *mount, ufs_inode_t *inode)
memcpy(buf + len, block + block_offset, chunk_size);
len += chunk_size;
// printf("direct block %u = 0x%08x\n", i, inode->direct[i]);
// slog("direct block %u = 0x%08x\n", i, inode->direct[i]);
}
@ -1252,7 +1252,7 @@ uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path,
sprintf(error_str, "Couldn't find root partition");
goto done;
}
printf("apm_part_num = %u\n", apm_part_num);
slog("apm_part_num = %u\n", apm_part_num);
svfs_mount_obj = svfs_mount(&disk->partitions[apm_part_num]);
if (svfs_mount_obj) {
@ -1290,7 +1290,7 @@ uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path,
done:
if (strlen(error_str))
printf("error: [%s]\n", error_str);
slog("error: [%s]\n", error_str);
if (disk)
close_disk(disk);
return kernel_data;

View File

@ -54,7 +54,7 @@ uint8_t iwm_dma_read()
const uint8_t reg = ((shoe.iwm.latch >> 5) & 6) |
((shoe.iwm.latch >> 4) & 1);
printf("iwm_dma_read: %s %s (reg = %u%u%u '%s' ",
slog("iwm_dma_read: %s %s (reg = %u%u%u '%s' ",
latch_val ? "setting" : "clearing",
latch_names[latch_addr],
(reg>>2), (reg>>1)&1, reg&1, reg_names[reg]);
@ -89,7 +89,7 @@ uint8_t iwm_dma_read()
}
done:
printf("result=0x%02x)\n", result);
slog("result=0x%02x)\n", result);
return result;
}
@ -109,11 +109,11 @@ void iwm_dma_write()
const uint8_t reg = ((shoe.iwm.latch >> 5) & 6) |
((shoe.iwm.latch >> 4) & 1);
printf("iwm_dma_write: %s %s (reg = %u%u%u '%s' val 0x%02x)\n",
latch_val ? "setting" : "clearing",
latch_names[latch_addr],
(reg>>2), (reg>>1)&1, reg&1, reg_names[reg],
data);
slog("iwm_dma_write: %s %s (reg = %u%u%u '%s' val 0x%02x)\n",
latch_val ? "setting" : "clearing",
latch_names[latch_addr],
(reg>>2), (reg>>1)&1, reg&1, reg_names[reg],
data);
// Allegedly, register writes can only occur when latch_val==1
if (!latch_val) {

View File

@ -257,7 +257,7 @@ void inst_fpu_decode ()
return ;
}
printf("inst_fpu_decode: unhandled instruction: %s op=0x%04x ext = 0x%04x pc=0x%08x\n", fpu_inst_table[name].name, shoe.op, ext, shoe.orig_pc);
slog("inst_fpu_decode: unhandled instruction: %s op=0x%04x ext = 0x%04x pc=0x%08x\n", fpu_inst_table[name].name, shoe.op, ext, shoe.orig_pc);
assert(!"unknown fpu inst");
//dbg_state.running = 0;
@ -339,14 +339,14 @@ void inst_frestore(uint16_t op, uint16_t ext)
else if ((word & 0xff) == 0x00b4)
size = 0xb8; // BUSY state frame
else {
printf("Frestore encountered an unknown state frame 0x%04x\n", word);
slog("Frestore encountered an unknown state frame 0x%04x\n", word);
assert("inst_frestore: bad state frame");
return ;
}
if (m==3) {
shoe.a[r] += size;
printf("frestore: changing shoe.a[%u] += %u\n", r, size);
slog("frestore: changing shoe.a[%u] += %u\n", r, size);
}
}
@ -480,7 +480,7 @@ void inst_fmovecr(uint16_t op, uint16_t ext)
fpu_set_reg_cc(f, r);
printf("inst_fmovecr: set fp%u=%.30Lg\n", r, shoe.fp[r]);
slog("inst_fmovecr: set fp%u=%.30Lg\n", r, shoe.fp[r]);
// fpu_finalize_exceptions();
}
@ -573,7 +573,7 @@ void inst_fmovem_control(uint16_t op, uint16_t ext)
uint8_t newround = shoe.fpcr.b.mc_rnd;
if (round != newround) {
printf("inst_fmovem_control: HEY: round %u -> %u\n", round, newround);
slog("inst_fmovem_control: HEY: round %u -> %u\n", round, newround);
}
}
if (S) shoe.fpsr.raw = buf[i++];
@ -593,7 +593,7 @@ void inst_fmovem_control(uint16_t op, uint16_t ext)
printf("inst_fmove_control: notice: (EA = %u/%u %08x CSI = %u%u%u)\n", m, r, (uint32_t)shoe.dat, C, S, I);
slog("inst_fmove_control: notice: (EA = %u/%u %08x CSI = %u%u%u)\n", m, r, (uint32_t)shoe.dat, C, S, I);
}
void dis_fmovem_control(uint16_t op, uint16_t ext)
@ -670,7 +670,7 @@ void inst_fbcc(uint16_t op, uint16_t ext)
}
if (b) {
printf("inst_fbcc: fixme: Got a CC that wants to set BSUN, not implemented\n");
slog("inst_fbcc: fixme: Got a CC that wants to set BSUN, not implemented\n");
//assert(0); // FIXME: implement BSUN, or uncomment this
}
@ -799,7 +799,7 @@ void inst_fmovem(uint16_t op, uint16_t ext)
assert(p); // assert post-increment mask
}
printf("inst_fmovem: pre=%08x mask=%08x EA=%u/%u addr=0x%08x size=%u %s\n", pre_mask, mask, m, r, addr, size, d?"to mem":"from mem");
slog("inst_fmovem: pre=%08x mask=%08x EA=%u/%u addr=0x%08x size=%u %s\n", pre_mask, mask, m, r, addr, size, d?"to mem":"from mem");
if (d) {
// Write those registers
@ -810,16 +810,16 @@ void inst_fmovem(uint16_t op, uint16_t ext)
uint8_t buf[12];
x87_to_motorola(shoe.fp[i], buf);
printf("inst_fmovem: writing %Lf from fp%u", shoe.fp[i], i);
slog("inst_fmovem: writing %Lf from fp%u", shoe.fp[i], i);
uint32_t j;
for (j=0; j<12; j++) {
printf(" %02x", buf[j]);
slog(" %02x", buf[j]);
lset(addr, 1, buf[j]);
addr++;
if (shoe.abort)
return ;
}
printf("\n");
slog("\n");
}
}
else {
@ -838,7 +838,7 @@ void inst_fmovem(uint16_t op, uint16_t ext)
}
shoe.fp[i] = motorola_to_x87(buf);
printf("inst_fmovem: read %Lf to fp%u\n", shoe.fp[i], i);
slog("inst_fmovem: read %Lf to fp%u\n", shoe.fp[i], i);
}
}
@ -848,7 +848,7 @@ void inst_fmovem(uint16_t op, uint16_t ext)
else if (m == 4)
shoe.a[r] -= size;
//printf("inst_fmovem: notice: not implemented (EA = %u/%u, mask=0x%02x)\n", m, r, mask);
//slog("inst_fmovem: notice: not implemented (EA = %u/%u, mask=0x%02x)\n", m, r, mask);
}
@ -972,11 +972,11 @@ got_address:
uint8_t *ptr = &buf[sizes[format]];
uint32_t i;
printf("inst_f fpu_read_ea: format=%u, data =", format);
slog("inst_f fpu_read_ea: format=%u, data =", format);
for (i=0; i<sizes[format]; i++) {
ptr--;
*ptr = lget(addr+i, 1);
printf(" %02x", *ptr);
slog(" %02x", *ptr);
if (shoe.abort)
return 0.0;
}
@ -1023,7 +1023,7 @@ got_data:
fpu_set_round();
result = data;
fpu_reset_round();
printf(" data=%Lf result=%Lf\n", data, result);
slog(" data=%Lf result=%Lf\n", data, result);
return result;
}
@ -1047,7 +1047,7 @@ static void fpu_write_ea(uint8_t mr, uint8_t format, long double orig_data)
return ;
}
printf("inst_f fpu_write_ea EA=%u/%u data=%Lf format=%u\n", m, r, data, format);
slog("inst_f fpu_write_ea EA=%u/%u data=%Lf format=%u\n", m, r, data, format);
// Convert to the appropriate format
@ -1060,7 +1060,7 @@ static void fpu_write_ea(uint8_t mr, uint8_t format, long double orig_data)
case format_W: {
int16_t tmp = data;
*((int16_t*)ptr) = tmp;
printf("inst_f fpu_write_ea formatted=%u (0x%04x)\n", *((int16_t*)ptr), *((uint16_t*)ptr));
slog("inst_f fpu_write_ea formatted=%u (0x%04x)\n", *((int16_t*)ptr), *((uint16_t*)ptr));
break;
}
case format_L: {
@ -1130,7 +1130,7 @@ write_to_mem:
}
// Copy the formatted data into the EA
printf("inst_f fpu_write_ea: addr=0x%08x\n", addr);
slog("inst_f fpu_write_ea: addr=0x%08x\n", addr);
for (i=0; i < sizes[format]; i++) {
lset(addr + i, 1, buf[i]);
if (shoe.abort)
@ -1208,7 +1208,7 @@ void inst_fmove(uint16_t op, uint16_t ext)
}
const uint8_t sizes[8] = {4, 4, 12, 12, 2, 8, 1, 12};
printf("inst_fmove src=%Lf size=%u a=%u z=%u to-mem=%u useEA=%u EA = %u/%u\n", data, sizes[format], a, z, V, E, m, r);
slog("inst_fmove src=%Lf size=%u a=%u z=%u to-mem=%u useEA=%u EA = %u/%u\n", data, sizes[format], a, z, V, E, m, r);
}
void dis_fnop(uint16_t op, uint16_t ext)
@ -1274,50 +1274,50 @@ void inst_fmath(uint16_t op, uint16_t ext)
if (src_in_ea) {
source = fpu_read_ea(M, source_specifier);
printf("inst_fmath: source = %u/%u = %Lf", M>>3, M&7, source);
slog("inst_fmath: source = %u/%u = %Lf", M>>3, M&7, source);
if ((M>>3) == 3)
printf(" a[%u]=0x%08x", M&7, shoe.a[M&7]);
slog(" a[%u]=0x%08x", M&7, shoe.a[M&7]);
if (shoe.abort)
return ;
}
else {
source = shoe.fp[source_specifier];
printf("inst_fmath: source = fp%u = %Lf", source_specifier, source);
slog("inst_fmath: source = fp%u = %Lf", source_specifier, source);
}
dest = shoe.fp[dest_register];
printf(" dest = fp%u = %Lf\n", dest_register, dest);
slog(" dest = fp%u = %Lf\n", dest_register, dest);
switch (e) {
case ~b(0000001): assert(!"fpu_inst_fint;");
case ~b(0000010): assert(!"fpu_inst_fsinh;");
case ~b(0000011): // fpu_inst_fintrz
printf("inst_fintrz dest = %Lf source = %Lf\n", dest, source);
slog("inst_fintrz dest = %Lf source = %Lf\n", dest, source);
result = truncl(source);
break;
case ~b(0000110): // flognp1
printf("inst_flognp1 dest = %Lf source = %Lf\n", dest, source);
slog("inst_flognp1 dest = %Lf source = %Lf\n", dest, source);
assert(source > -1.0);
result = log1pl(source);
break;
case ~b(0001000): assert(!"fpu_inst_fetoxm1;");
case ~b(0001001): assert(!"fpu_inst_ftanh;");
case ~b(0001010): // fatan
printf("inst_fatan dest = %Lf source = %Lf\n", dest, source);
slog("inst_fatan dest = %Lf source = %Lf\n", dest, source);
result = atanl(source);
break;
case ~b(0001100): assert(!"fpu_inst_fasin;");
case ~b(0001101): assert(!"fpu_inst_fatanh;");
case ~b(0001110): // fsin
printf("inst_fsin dest = %Lf source = %Lf\n", dest, source);
slog("inst_fsin dest = %Lf source = %Lf\n", dest, source);
result = sinl(source);
break;
case ~b(0001111): assert(!"fpu_inst_ftan;");
case ~b(0010000): // fetox
printf("inst_fetox dest = %Lf source = %Lf\n", dest, source);
slog("inst_fetox dest = %Lf source = %Lf\n", dest, source);
result = expl(source);
break;
case ~b(0010001): assert(!"fpu_inst_ftwotox;");
@ -1328,7 +1328,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(0011001): assert(!"fpu_inst_fcosh;");
case ~b(0011100): assert(!"fpu_inst_facos;");
case ~b(0011101): // fcos
printf("fpu_inst_fcos dest = %Lf source = %Lf\n", dest, source);
slog("fpu_inst_fcos dest = %Lf source = %Lf\n", dest, source);
result = cosl(source);
break;
@ -1342,14 +1342,14 @@ void inst_fmath(uint16_t op, uint16_t ext)
assert(source != 0.0);
result = remainderl(dest, source);
fpu_set_fpsr_quotient(dest, source, result);
printf("inst_frem: dest = %Lf source = %Lf quot = %u result = %Lf\n", dest, source, shoe.fpsr.b.qu_quotient, result);
slog("inst_frem: dest = %Lf source = %Lf quot = %u result = %Lf\n", dest, source, shoe.fpsr.b.qu_quotient, result);
break;
}
case ~b(0100110): assert(!"fpu_inst_fscale;");
case ~b(0111000): { // fpu_inst_fcmp
const long double diff = dest - source;
printf("inst_fcmp: dest = %Lf source = %Lf\n", dest, source);
slog("inst_fcmp: dest = %Lf source = %Lf\n", dest, source);
fpu_set_cc(diff);
do_write_back_result = 0; // don't write result back to register
break;
@ -1365,7 +1365,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(1100110):
assert(!"can't handle");
case ~b(0100010): { // fpu_inst_fadd
printf("inst_fadd dest = %Lf source = %Lf\n", dest, source);
slog("inst_fadd dest = %Lf source = %Lf\n", dest, source);
result = dest + source;
break;
}
@ -1375,7 +1375,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
assert(!"can't handle");
case ~b(0100000): { // fpu_inst_fdiv
assert(source != 0.0);
printf("inst_fdiv dest = %Lf source = %Lf\n", dest, source);
slog("inst_fdiv dest = %Lf source = %Lf\n", dest, source);
result = dest / source;
break;
@ -1386,7 +1386,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(1100111):
assert(!"can't handle");
case ~b(0100011): { // fpu_inst_fmul
printf("inst_fmul dest = %Lf source = %Lf\n", dest, source);
slog("inst_fmul dest = %Lf source = %Lf\n", dest, source);
result = source * dest;
break;
}
@ -1395,7 +1395,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(1011110):
assert(!"fneg: can't handle");
case ~b(0011010): // fneg
printf("inst_fneg dest = %Lf source = %Lf\n", dest, source);
slog("inst_fneg dest = %Lf source = %Lf\n", dest, source);
result = -source;
break;
@ -1403,7 +1403,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(1000101):
assert(!"can't handle");
case ~b(0000100): { // fpu_inst_fsqrt
printf("inst_fsqrt dest = %Lf source = %Lf\n", dest, source);
slog("inst_fsqrt dest = %Lf source = %Lf\n", dest, source);
result = sqrtl(source);
break;
}
@ -1412,7 +1412,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
case ~b(1101100):
assert(!"can't handle");
case ~b(0101000): { // fpu_inst_fsub
printf("inst_fsub dest = %Lf source = %Lf\n", dest, source);
slog("inst_fsub dest = %Lf source = %Lf\n", dest, source);
result = dest - source;
break;
}
@ -1428,7 +1428,7 @@ void inst_fmath(uint16_t op, uint16_t ext)
// Only write back the result if necessary (fcmp doesn't do this)
if (do_write_back_result) {
printf("inst_fmath: result = %Lf\n", result);
slog("inst_fmath: result = %Lf\n", result);
fpu_set_reg_cc(result, dest_register);
}
}

View File

@ -36,50 +36,50 @@ extern struct dis_t dis;
extern uint16_t dis_op;
void inst_mc68851_prestore() {
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_psave(){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pbcc(){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pdbcc(uint16_t cond){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_ptrapcc(uint16_t cond){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pscc(uint16_t cond){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pload(uint16_t ext){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pvalid(uint16_t ext){
printf("%s: Error, not implemented!\n", __func__);
slog("%s: Error, not implemented!\n", __func__);
assert(!"blowup");
}
void inst_mc68851_pflushr(uint16_t ext){
verify_supervisor();
printf("pflushr!");
slog("pflushr!");
// Just nuke the entire cache
bzero(shoe.pmmu_cache[0].valid_map, PMMU_CACHE_SIZE/8);
bzero(shoe.pmmu_cache[1].valid_map, PMMU_CACHE_SIZE/8);
@ -87,10 +87,10 @@ void inst_mc68851_pflushr(uint16_t ext){
void inst_mc68851_pflush(uint16_t ext){
verify_supervisor();
printf("pflush!");
slog("pflush!");
bzero(shoe.pmmu_cache[0].valid_map, PMMU_CACHE_SIZE/8);
bzero(shoe.pmmu_cache[1].valid_map, PMMU_CACHE_SIZE/8);
// printf("%s: Error, not implemented!\n", __func__);
// slog("%s: Error, not implemented!\n", __func__);
}
void inst_mc68851_pmove(uint16_t ext){
@ -232,7 +232,7 @@ static int64_t ptest_search(const uint32_t _logical_addr, const uint64_t rootp)
// load the child descriptor
if (_logical_addr == 0)
printf("Loading descriptor s=%llu from addr=0x%08x\n", desc_dt(desc, desc_size) & 1, (uint32_t)desc_table_addr(desc));
slog("Loading descriptor s=%llu from addr=0x%08x\n", desc_dt(desc, desc_size) & 1, (uint32_t)desc_table_addr(desc));
const uint32_t table_base_addr = desc_table_addr(desc);
const uint8_t s = desc_dt(desc, desc_size) & 1;
@ -244,7 +244,7 @@ static int64_t ptest_search(const uint32_t _logical_addr, const uint64_t rootp)
const uint8_t dt = desc_dt(desc, desc_size);
if (_logical_addr == 0)
printf("i=%u desc = 0x%llx dt=%u\n", i, desc, dt);
slog("i=%u desc = 0x%llx dt=%u\n", i, desc, dt);
// If this descriptor is invalid, throw a bus error
if (dt == 0) {
@ -339,7 +339,7 @@ void inst_mc68851_ptest(uint16_t ext){
else if (fc == 5)
rootp = shoe.srp;
else {
printf("ptest: I can't handle this FC: %u pc=0x%08x\n", fc, shoe.orig_pc);
slog("ptest: I can't handle this FC: %u pc=0x%08x\n", fc, shoe.orig_pc);
assert(!"ptest: I can't handle this FC");
}
@ -353,7 +353,7 @@ void inst_mc68851_ptest(uint16_t ext){
// printf("%s: Error, not implemented!\n", __func__);
// slog("%s: Error, not implemented!\n", __func__);
}
void dis_mc68851_prestore() {

View File

@ -24,15 +24,18 @@
*/
#include <stdio.h>
#include <machine/endian.h>
#include <arpa/inet.h>
#include <assert.h>
#include <stdlib.h>
#include "../core/shoebill.h"
#ifdef __APPLE__
#include <machine/endian.h>
#include <libkern/OSByteOrder.h>
#define ntohll(x) OSSwapBigToHostInt64(x)
#elif (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
#define ntohll(_x) ({uint64_t x = (_x); (((uint64_t)ntohl((uint32_t)x))<<32) | ntohl(x>>32);})
#endif
/* --- Physical_get jump table --- */
@ -46,25 +49,11 @@ void _physical_get_ram (void)
else
addr = (uint64_t*)&shoe.physical_mem_base[shoe.physical_addr % shoe.physical_mem_size];
/*if ((shoe.physical_addr >= 0x100) && (shoe.physical_addr < (0x4000+256))) {
uint32_t i, val = 0;
_Bool uninit = 0;
for (i=0; i<shoe.physical_size; i++) {
const uint8_t byte = shoe.physical_mem_base[shoe.physical_addr+i];
val = val << 8;
val |= byte;
if (byte == 0xbc) uninit = 1;
}
if (uninit) {
printf("LOMEM: *0x%08x = 0x%x UNSET\n", shoe.physical_addr, val);
}
}*/
const uint8_t bits = (8 - shoe.physical_size) * 8;
shoe.physical_dat = ntohll(*addr) >> bits;
if ((shoe.physical_addr >= 256) && (shoe.physical_addr < 0x4000)) {
printf("LOMEM get: *0x%08x = 0x%x\n", shoe.physical_addr, (uint32_t)shoe.physical_dat);
slog("LOMEM get: *0x%08x = 0x%x\n", shoe.physical_addr, (uint32_t)shoe.physical_dat);
}
}
@ -83,7 +72,7 @@ void _physical_get_io (void)
via_read_raw();
return ;
case 0x50004000 ... 0x50005fff: {// SCC
//printf("physical_get: got read to SCC\n");
//slog("physical_get: got read to SCC\n");
const uint32_t a = shoe.physical_addr & 0x1fff;
if (a == 2 && shoe.physical_size==1)
shoe.physical_dat = 0x4; // R0TXRDY
@ -101,17 +90,17 @@ void _physical_get_io (void)
shoe.physical_dat = scsi_dma_read();
return ;
case 0x50014000 ... 0x50015fff: // Sound
//printf("physical_get: got read to sound\n");
printf("soundsound read : register 0x%04x sz=%u\n",
//slog("physical_get: got read to sound\n");
slog("soundsound read : register 0x%04x sz=%u\n",
shoe.physical_addr - 0x50014000, shoe.physical_size);
shoe.physical_dat = 0;
return ;
case 0x50016000 ... 0x50017fff: // SWIM (IWM?)
// printf("physical_get: got read to IWM\n");
// slog("physical_get: got read to IWM\n");
shoe.physical_dat = iwm_dma_read();
return ;
default:
//printf("physical_get: got read to UNKNOWN IO ADDR %x\n", shoe.physical_addr);
//slog("physical_get: got read to UNKNOWN IO ADDR %x\n", shoe.physical_addr);
return ;
}
}
@ -170,7 +159,7 @@ void _physical_set_ram (void)
addr = &shoe.physical_mem_base[shoe.physical_addr];
if ((shoe.physical_addr >= 0x100) && (shoe.physical_addr < (0x8000))) {
printf("LOMEM set: *0x%08x = 0x%x\n", shoe.physical_addr, (uint32_t)chop(shoe.physical_dat, shoe.physical_size));
slog("LOMEM set: *0x%08x = 0x%x\n", shoe.physical_addr, (uint32_t)chop(shoe.physical_dat, shoe.physical_size));
}
const uint32_t sz = shoe.physical_size;
@ -215,7 +204,7 @@ void _physical_set_io (void)
via_write_raw();
return ;
case 0x50004000 ... 0x50005fff: // SCC
//printf("physical_set: got write to SCC\n");
//slog("physical_set: got write to SCC\n");
return ;
case 0x50006000 ... 0x50007fff: // SCSI (pseudo-DMA with DRQ?)
assert(shoe.physical_size == 4);
@ -229,16 +218,16 @@ void _physical_set_io (void)
scsi_dma_write(shoe.physical_dat);
return ;
case 0x50014000 ... 0x50015fff: // Sound
printf("soundsound write: register 0x%04x sz=%u dat=0x%x\n",
slog("soundsound write: register 0x%04x sz=%u dat=0x%x\n",
shoe.physical_addr - 0x50014000, shoe.physical_size, (uint32_t)shoe.physical_dat);
// printf("physical_set: got write to sound\n");
// slog("physical_set: got write to sound\n");
return ;
case 0x50016000 ... 0x50017fff: // SWIM (IWM?)
//printf("physical_set: got write to IWM\n");
//slog("physical_set: got write to IWM\n");
iwm_dma_write();
return ;
default:
//printf("physical_set: got write to UNKNOWN IO ADDR %x\n", shoe.physical_addr);
//slog("physical_set: got write to UNKNOWN IO ADDR %x\n", shoe.physical_addr);
return ;
}
}
@ -710,7 +699,7 @@ static void ea_decode_extended()
// the brief extension word is implicitly preindexed
shoe.extended_addr = base_addr + base_disp + index_val;
shoe.extended_len = mypc - start_pc;
//printf("I found address 0x%x\n", shoe.extended_addr);
//slog("I found address 0x%x\n", shoe.extended_addr);
return ;
}
else { // If this is a full extension word,
@ -768,9 +757,9 @@ static void ea_decode_extended()
}
}
//printf("D/A=%u, reg=%u, W/L=%u, Scale=%u, F=%u, BS=%u, IS=%u, BDSize=%u, I/IS=%u\n",
//slog("D/A=%u, reg=%u, W/L=%u, Scale=%u, F=%u, BS=%u, IS=%u, BDSize=%u, I/IS=%u\n",
//d, r, w, s, F, b, i, z, I);
//printf("base_addr=%x, index_val=%x, base_disp=%x, outer_disp=%x\n",
//slog("base_addr=%x, index_val=%x, base_disp=%x, outer_disp=%x\n",
//base_addr, index_val, base_disp, outer_disp);
// Now mash all these numbers together to get an EA
@ -782,7 +771,7 @@ static void ea_decode_extended()
if (shoe.abort) return ;
shoe.extended_addr = intermediate + outer_disp;
shoe.extended_len = mypc - start_pc;
// printf("addr=0x%x len=%u\n", shoe.extended_addr, shoe.extended_len);
// slog("addr=0x%x len=%u\n", shoe.extended_addr, shoe.extended_len);
return ;
}

View File

@ -115,7 +115,7 @@ static _Bool phase_match (void)
static void switch_status_phase (uint8_t status_byte)
{
printf("scsi_reg_something: switching to STATUS phase\n");
slog("scsi_reg_something: switching to STATUS phase\n");
shoe.scsi.phase = STATUS;
shoe.scsi.status_byte = status_byte;
@ -131,7 +131,7 @@ static void switch_status_phase (uint8_t status_byte)
static void switch_command_phase (void)
{
printf("scsi_reg_something: switching to COMMAND phase\n");
slog("scsi_reg_something: switching to COMMAND phase\n");
shoe.scsi.phase = COMMAND;
shoe.scsi.msg = 0;
@ -146,7 +146,7 @@ static void switch_command_phase (void)
static void switch_message_in_phase (uint8_t message_byte)
{
printf("scsi_reg_something: switching to MESSAGE_IN phase\n");
slog("scsi_reg_something: switching to MESSAGE_IN phase\n");
shoe.scsi.phase = MESSAGE_IN;
shoe.scsi.msg = 1;
@ -161,7 +161,7 @@ static void switch_message_in_phase (uint8_t message_byte)
static void switch_bus_free_phase (void)
{
printf("scsi_reg_something: switching to BUS_FREE phase\n");
slog("scsi_reg_something: switching to BUS_FREE phase\n");
shoe.scsi.phase = BUS_FREE;
@ -178,7 +178,7 @@ static void switch_bus_free_phase (void)
static void switch_data_in_phase (void)
{
printf("scsi_reg_something: switching to DATA_IN phase\n");
slog("scsi_reg_something: switching to DATA_IN phase\n");
shoe.scsi.phase = DATA_IN;
@ -192,7 +192,7 @@ static void switch_data_in_phase (void)
static void switch_data_out_phase (void)
{
printf("scsi_reg_something: switching to DATA_OUT phase\n");
slog("scsi_reg_something: switching to DATA_OUT phase\n");
shoe.scsi.phase = DATA_OUT;
@ -306,17 +306,17 @@ static void scsi_buf_set (uint8_t byte)
switch (shoe.scsi.buf[0]) {
case 0: // test unit ready (6)
printf("scsi_buf_set: responding to test-unit-ready\n");
slog("scsi_buf_set: responding to test-unit-ready\n");
switch_status_phase(0); // switch to the status phase, with a status byte of 0
break;
case 0x15: // mode select (6)
printf("scsi_buf_set: responding to mode-select\n");
slog("scsi_buf_set: responding to mode-select\n");
switch_status_phase(0);
break;
case 0x25: // read capacity (10)
printf("scsi_buf_set: responding to read-capacity\n");
slog("scsi_buf_set: responding to read-capacity\n");
// bytes [0,3] -> BE number of blocks
shoe.scsi.buf[0] = (dev->num_blocks >> 24) & 0xff;
shoe.scsi.buf[1] = (dev->num_blocks >> 16) & 0xff;
@ -337,7 +337,7 @@ static void scsi_buf_set (uint8_t byte)
break;
case 0x12: { // inquiry command (6)
printf("scsi_buf_set: responding to inquiry\n");
slog("scsi_buf_set: responding to inquiry\n");
const uint8_t alloc_len = shoe.scsi.buf[4];
scsi_handle_inquiry_command(alloc_len);
@ -353,7 +353,7 @@ static void scsi_buf_set (uint8_t byte)
assert(dev->f);
printf("scsi_buf_set: Responding to read at off=%u len=%u\n", offset, len);
slog("scsi_buf_set: Responding to read at off=%u len=%u\n", offset, len);
//assert(len <= 64);
@ -382,7 +382,7 @@ static void scsi_buf_set (uint8_t byte)
(shoe.scsi.buf[3]);
const uint8_t len = shoe.scsi.buf[4];
printf("scsi_buf_set: Responding to write at off=%u len=%u\n", offset, len);
slog("scsi_buf_set: Responding to write at off=%u len=%u\n", offset, len);
//assert(len <= 64);
@ -422,7 +422,7 @@ void scsi_reg_read ()
{
const uint32_t reg = ((shoe.physical_addr & 0xffff) >> 4) & 0xf;
//printf("\nscsi_reg_read: reading from register %s(%u) ", scsi_read_reg_str[reg], reg);
//slog("\nscsi_reg_read: reading from register %s(%u) ", scsi_read_reg_str[reg], reg);
switch (reg) {
case 0: // Current scsi data bus register
@ -505,7 +505,7 @@ void scsi_reg_read ()
break;
}
//printf("(set to 0x%02x)\n\n", (uint32_t)shoe.physical_dat);
//slog("(set to 0x%02x)\n\n", (uint32_t)shoe.physical_dat);
}
void scsi_reg_write ()
@ -534,7 +534,7 @@ void scsi_reg_write ()
// Asserting SEL in arbitration phase means we switch to selection phase :)
shoe.scsi.phase = SELECTION;
shoe.scsi.target_id = INVALID_ID; // invalid ID
printf("scsi_reg_write: selection phase\n");
slog("scsi_reg_write: selection phase\n");
break;
}
*/
@ -547,7 +547,7 @@ void scsi_reg_write ()
for (id=0; (id < 8) && !(shoe.scsi.data & (1 << id)); id++) ;
assert(id != 8);
shoe.scsi.target_id = id;
printf("scsi_reg_write: selected target id %u\n", id);
slog("scsi_reg_write: selected target id %u\n", id);
shoe.scsi.target_bsy = 1; // target asserts BSY to acknowledge being selected
shoe.scsi.phase = SELECTION;
break;
@ -555,7 +555,7 @@ void scsi_reg_write ()
// SELECTION ends when SEL gets unset
if (!shoe.scsi.sel && shoe.scsi.phase == SELECTION) {
printf("scsi_reg_write: switch to COMMAND phase\n"); // what's next?
slog("scsi_reg_write: switch to COMMAND phase\n"); // what's next?
shoe.scsi.req = 1; // target asserts REQ after initiator deasserts SEL
@ -600,7 +600,7 @@ void scsi_reg_write ()
shoe.scsi.mode = dat;
if (shoe.scsi.mode & MODE_ARBITRATE) {
printf("scsi_reg_write: arbitration phase\n");
slog("scsi_reg_write: arbitration phase\n");
shoe.scsi.phase = ARBITRATION;
shoe.scsi.initiator_command |= INIT_COMM_ARBITRATION_IN_PROGRESS;
}
@ -631,7 +631,7 @@ void scsi_reg_write ()
break;
}
printf("\nscsi_reg_write: writing to register %s(%u) (0x%x)\n\n", scsi_write_reg_str[reg], reg, dat);
slog("\nscsi_reg_write: writing to register %s(%u) (0x%x)\n\n", scsi_write_reg_str[reg], reg, dat);
}
void scsi_dma_write_long(const uint32_t dat)
@ -645,13 +645,13 @@ void scsi_dma_write_long(const uint32_t dat)
void scsi_dma_write (const uint8_t byte)
{
if (shoe.scsi.phase == COMMAND) {
printf("scsi_reg_dma_write: writing COMMAND byte 0x%02x\n", byte);
slog("scsi_reg_dma_write: writing COMMAND byte 0x%02x\n", byte);
scsi_buf_set(byte);
}
else if (shoe.scsi.phase == DATA_OUT && shoe.scsi.dma_send_written) {
shoe.scsi.buf[shoe.scsi.out_i++] = byte;
//printf("scsi_reg_dma_write: writing DATA_OUT byte 0x%02x (%c)\n", byte, isprint(byte)?byte:'.');
//slog("scsi_reg_dma_write: writing DATA_OUT byte 0x%02x (%c)\n", byte, isprint(byte)?byte:'.');
if (shoe.scsi.out_i >= shoe.scsi.out_len) {
assert(shoe.scsi.target_id < 8);
@ -668,10 +668,10 @@ void scsi_dma_write (const uint8_t byte)
}
}
else if (shoe.scsi.phase == DATA_OUT) {
printf("scsi_reg_dma_write: writing DATA_OUT byte (without shoe.scsi.dma_send_written) 0x%02x\n", byte);
slog("scsi_reg_dma_write: writing DATA_OUT byte (without shoe.scsi.dma_send_written) 0x%02x\n", byte);
}
else {
printf("scsi_reg_dma_write: writing 0x%02x in UNKNOWN PHASE!\n", byte);
slog("scsi_reg_dma_write: writing 0x%02x in UNKNOWN PHASE!\n", byte);
}
}
@ -707,7 +707,7 @@ uint8_t scsi_dma_read ()
}
}
//printf("scsi_reg_dma_read: called, returning 0x%02x\n", (uint8_t)result);
//slog("scsi_reg_dma_read: called, returning 0x%02x\n", (uint8_t)result);
return result;
}

View File

@ -86,8 +86,7 @@ void shoebill_restart (void);
/* Call this after shoebill_initialize() to configure a video card */
uint32_t shoebill_install_video_card(shoebill_config_t *config, uint8_t slotnum,
uint16_t width, uint16_t height,
double refresh_rate);
uint16_t width, uint16_t height);
/* Get a video frame from a particular video card */
shoebill_video_frame_info_t shoebill_get_video_frame(uint8_t slotnum, _Bool just_params);
@ -116,6 +115,8 @@ void shoebill_mouse_click(uint8_t down);
void shoebill_start();
void shoebill_stop();
void slog(const char *fmt, ...);
uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path, char *error_str, uint32_t *len);
@ -229,11 +230,13 @@ uint8_t* shoebill_extract_kernel(const char *disk_path, const char *kernel_path,
/*
* alloc_pool.c
*/
#define POOL_START_MAGIC 0x231eb4af
#define POOL_END_MAGIC 0xb09f39f1
#define POOL_ALLOC_TYPE 0
#define POOL_CHILD_LINK 1
#define POOL_HEAD 2
typedef struct _alloc_pool_t {
uint32_t start_magic;
struct _alloc_pool_t *prev, *next;
union {
@ -249,7 +252,7 @@ typedef struct _alloc_pool_t {
} t;
uint32_t type;
uint32_t magic;
uint32_t end_magic;
} alloc_pool_t;
void* p_alloc(alloc_pool_t *pool, uint64_t size);
@ -577,8 +580,6 @@ typedef struct {
_Bool connected;
_Bool interrupts_enabled;
long double interrupt_rate, last_fired; // FIXME: probably don't need these?
void *ctx;
card_names_t card_type;
} nubus_card_t;
@ -972,8 +973,7 @@ void nubus_tfb_write_func(uint32_t, uint32_t, uint32_t, uint8_t);
// Shoebill Virtual Video Card
void nubus_video_init(void *_ctx, uint8_t slotnum,
uint16_t width, uint16_t height, uint16_t scanline_width,
double refresh_rate);
uint16_t width, uint16_t height, uint16_t scanline_width);
uint32_t nubus_video_read_func(const uint32_t rawaddr, const uint32_t size,
const uint8_t slotnum);

View File

@ -207,7 +207,7 @@ uint32_t nubus_tfb_read_func(const uint32_t rawaddr, const uint32_t size, const
if ((addr & 3) == 0) {
const uint32_t rom_addr = (addr >> 2) % 4096;
result = macii_video_rom[rom_addr];
printf("nubus_tfb_read_func: returning %x for addr %x (rom_addr=%x)\n", (uint32_t)result, shoe.physical_addr, rom_addr);
slog("nubus_tfb_read_func: returning %x for addr %x (rom_addr=%x)\n", (uint32_t)result, shoe.physical_addr, rom_addr);
}
else
result = 0;
@ -220,21 +220,21 @@ uint32_t nubus_tfb_read_func(const uint32_t rawaddr, const uint32_t size, const
if (addr == 0xd0000) {
ctx->vsync++;
result = (ctx->vsync >> 7)&1;
printf("nubus_tfb_read_func: reading vsync bit shoe.pc=0x%08x\n", shoe.orig_pc);
slog("nubus_tfb_read_func: reading vsync bit shoe.pc=0x%08x\n", shoe.orig_pc);
// We just need to oscillate the vsync bit, to pretend we're going in and out of the blanking interval.
// The card driver waits until the bit goes low, then waits until it goes high
// FIXME: clean this up
break;
}
else {
printf("nubus_tfb_read_func: unknown read of *0x%08x\n", shoe.physical_addr);
slog("nubus_tfb_read_func: unknown read of *0x%08x\n", shoe.physical_addr);
result = 0;
break;
}
}
default: {
printf("nubus_tfb_read_func: unknown read of *0x%08x\n", shoe.physical_addr);
slog("nubus_tfb_read_func: unknown read of *0x%08x\n", shoe.physical_addr);
result = 0;
break;
}
@ -281,14 +281,14 @@ void nubus_tfb_write_func(const uint32_t rawaddr, const uint32_t size,
return ;
}
else {
printf("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
slog("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
return ;
}
}
case 0x9: { // CLUT registers?
if (addr == 0x90018) { // CLUT
printf("clut[0x%03x (0x%02x+%u)] = 0x%02x\n", ctx->clut_idx, ctx->clut_idx/3, ctx->clut_idx%3, (uint8_t)(data & 0xff));
slog("clut[0x%03x (0x%02x+%u)] = 0x%02x\n", ctx->clut_idx, ctx->clut_idx/3, ctx->clut_idx%3, (uint8_t)(data & 0xff));
ctx->clut[ctx->clut_idx] = 255 - (data & 0xff);
ctx->clut_idx = (ctx->clut_idx == 0) ? 767 : ctx->clut_idx-1;
@ -302,7 +302,7 @@ void nubus_tfb_write_func(const uint32_t rawaddr, const uint32_t size,
ctx->clut_idx = clut_dat * 3 + 2;
}
printf("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
slog("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
return ;
}
@ -314,7 +314,7 @@ void nubus_tfb_write_func(const uint32_t rawaddr, const uint32_t size,
}
default: {
printf("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
slog("video_nubus_set: unknown write to *0x%08x (0x%x)\n", shoe.physical_addr, data);
return ;
}
}

View File

@ -106,7 +106,7 @@ void process_pending_interrupt ()
const uint16_t vector_offset = (priority + 24) * 4;
printf("Interrupt pri %u! mask=%u vector_offset=0x%08x\n", priority, sr_mask(), vector_offset);
slog("Interrupt pri %u! mask=%u vector_offset=0x%08x\n", priority, sr_mask(), vector_offset);
// Save the old SR, and switch to supervisor mode
const uint16_t old_sr = shoe.sr;
@ -114,15 +114,15 @@ void process_pending_interrupt ()
// Write a "format 0" exception frame to ISP or MSP
push_a7(0x0000 | vector_offset, 2);
printf("interrupt: pushed format 0x%04x to 0x%08x\n", 0x0000 | vector_offset, shoe.a[7]);
slog("interrupt: pushed format 0x%04x to 0x%08x\n", 0x0000 | vector_offset, shoe.a[7]);
assert(!shoe.abort);
push_a7(shoe.pc, 4);
printf("interrupt: pushed pc 0x%08x to 0x%08x\n", shoe.pc, shoe.a[7]);
slog("interrupt: pushed pc 0x%08x to 0x%08x\n", shoe.pc, shoe.a[7]);
assert(!shoe.abort);
push_a7(old_sr, 2);
printf("interrupt: pushed sr 0x%04x to 0x%08x\n", old_sr, shoe.a[7]);
slog("interrupt: pushed sr 0x%04x to 0x%08x\n", old_sr, shoe.a[7]);
assert(!shoe.abort);
if (sr_m()) {
@ -152,7 +152,7 @@ void process_pending_interrupt ()
// Fetch the autovector handler address
const uint32_t newpc = lget(shoe.vbr + vector_offset, 4);
printf("autovector handler = *0x%08x = 0x%08x\n", shoe.vbr + vector_offset, newpc);
slog("autovector handler = *0x%08x = 0x%08x\n", shoe.vbr + vector_offset, newpc);
assert(!shoe.abort);
shoe.pc = newpc;
@ -205,7 +205,7 @@ static void handle_pram_write_byte (void)
{
pram_state_t *pram = &shoe.pram;
printf("PRAMPRAM: wrote_byte 0x%02x\n", pram->byte);
slog("PRAMPRAM: wrote_byte 0x%02x\n", pram->byte);
pram->mode = PRAM_READ;
pram->byte = 0;
@ -218,7 +218,7 @@ static void handle_pram_read_byte (void)
assert(pram->command_i < 8);
pram->command[pram->command_i++] = pram->byte;
printf("PRAMPRAM: read_byte: 0x%02x\n", pram->byte);
slog("PRAMPRAM: read_byte: 0x%02x\n", pram->byte);
// If this is a pram-read/write...
if ((pram->command[0] & 0x78) == 0x38) {
@ -232,7 +232,7 @@ static void handle_pram_read_byte (void)
if (pram->callback)
pram->callback(pram->callback_param, addr, pram->command[2]);
printf("PRAMPRAM: setting pram addr 0x%02x = 0x%02x\n", addr, pram->command[2]);
slog("PRAMPRAM: setting pram addr 0x%02x = 0x%02x\n", addr, pram->command[2]);
pram->byte = 0;
pram->command_i = 0;
@ -244,7 +244,7 @@ static void handle_pram_read_byte (void)
pram->byte = pram->data[addr];
pram->command_i = 0;
printf("PRAMPRAM: fetching pram addr 0x%02x (= 0x%02x)\n", addr, pram->byte);
slog("PRAMPRAM: fetching pram addr 0x%02x (= 0x%02x)\n", addr, pram->byte);
return ;
}
@ -265,7 +265,7 @@ static void handle_pram_read_byte (void)
if ((pram->command_i == 2) && !isget) { // complete set command
pram->mode = PRAM_READ; // stay in read-mode
printf("PRAMPRAM: setting time byte %u to 0x%02x (mysterybit=%u)\n", addr, pram->command[1], mysterybit);
slog("PRAMPRAM: setting time byte %u to 0x%02x (mysterybit=%u)\n", addr, pram->command[1], mysterybit);
pram->byte = 0;
pram->command_i = 0;
@ -280,7 +280,7 @@ static void handle_pram_read_byte (void)
pram->byte = now_byte;
pram->command_i = 0;
printf("PRAMPRAM: fetching time byte %u of 0x%08x (mysterybit=%u)\n", addr, now, mysterybit);
slog("PRAMPRAM: fetching time byte %u of 0x%08x (mysterybit=%u)\n", addr, now, mysterybit);
return ;
}
else { // incomplete command, keep reading
@ -295,7 +295,7 @@ static void handle_pram_read_byte (void)
else if (pram->command[0] == 0x35) {
// Arrives in pairs of two bytes
if (pram->command_i == 2) {
printf("PRAMPRAM: mystery command 2 0x%02x 0x%02x (?))\n", pram->command[0], pram->command[1]);
slog("PRAMPRAM: mystery command 2 0x%02x 0x%02x (?))\n", pram->command[0], pram->command[1]);
pram->mode = PRAM_READ;
pram->command_i = 0;
@ -311,7 +311,7 @@ static void handle_pram_read_byte (void)
}
printf("PRAMPRAM: don't understand this command\n");
slog("PRAMPRAM: don't understand this command\n");
pram->command_i = 0;
pram->mode = PRAM_READ;
}
@ -324,7 +324,7 @@ static void handle_pram_state_change (void)
if (pram->last_bits == (shoe.via[0].regb_output & shoe.via[0].ddrb & 6))
return ;
printf("PRAMPRAM: pram->last_bits = %u, (shoe.via[0].regb & 6) = %u\n", pram->last_bits, (shoe.via[0].regb_output & shoe.via[0].ddrb & 6));
slog("PRAMPRAM: pram->last_bits = %u, (shoe.via[0].regb & 6) = %u\n", pram->last_bits, (shoe.via[0].regb_output & shoe.via[0].ddrb & 6));
// it doesn't matter what the last rtcData value was
const _Bool last_rtcClock = (pram->last_bits >> 1) & 1;
@ -334,13 +334,13 @@ static void handle_pram_state_change (void)
const _Bool rtcClock = (shoe.via[0].regb_output >> 1) & 1;
const _Bool rtcEnable = (shoe.via[0].regb_output >> 2) & 1;
printf("PRAMPRAM: bits changed %u%ux -> %u%u%u\n", last_rtcEnable, last_rtcClock, rtcEnable, rtcClock, rtcData);
slog("PRAMPRAM: bits changed %u%ux -> %u%u%u\n", last_rtcEnable, last_rtcClock, rtcEnable, rtcClock, rtcData);
if (rtcEnable) {
// rtcEnable==true => the RTC chip is enabled and we are talking to it
// Not sure what happens when you toggle data/clock bits while rtcEnable is asserted...
if (last_rtcEnable)
printf("PRAMPRAM: toggled bits while rtcEnable was asserted!\n");
slog("PRAMPRAM: toggled bits while rtcEnable was asserted!\n");
goto done;
}
@ -366,7 +366,7 @@ static void handle_pram_state_change (void)
if ((shoe.via[0].ddrb & 1) == 0) {
// This is input-mode -- should be output-mode
printf("PRAMPRAM: BOGUS MODE ddrb&1 == 0\n");
slog("PRAMPRAM: BOGUS MODE ddrb&1 == 0\n");
}
@ -519,7 +519,7 @@ static uint8_t via_read_reg(const uint8_t vianum, const uint8_t reg, const long
{
via_state_t *via = &shoe.via[vianum - 1];
printf("via_reg_read: reading from via%u reg %s (%u) (shoe.pc = 0x%08x)\n", vianum, via_reg_str[reg], reg, shoe.pc);
slog("via_reg_read: reading from via%u reg %s (%u) (shoe.pc = 0x%08x)\n", vianum, via_reg_str[reg], reg, shoe.pc);
switch (reg) {
case VIA_ACR:
@ -547,7 +547,7 @@ static uint8_t via_read_reg(const uint8_t vianum, const uint8_t reg, const long
* if input latching is enabled, then the value of input pins
* is held in escrow until a CB1 transition occurs. I'm not doing that.
*/
printf("via_reg_read: FYI: regb_output=0x%02x regb_input=0x%02x ddrb=0x%02x combined=0x%02x\n",
slog("via_reg_read: FYI: regb_output=0x%02x regb_input=0x%02x ddrb=0x%02x combined=0x%02x\n",
shoe.via[vianum-1].regb_output, shoe.via[vianum-1].regb_input, via->ddrb, VIA_REGB_PINS(vianum));
return VIA_REGB_PINS(vianum);
}
@ -600,7 +600,7 @@ static void via_write_reg(const uint8_t vianum, const uint8_t reg, const uint8_t
{
via_state_t *via = &shoe.via[vianum - 1];
printf("via_reg_write: writing 0x%02x to via%u reg %s (%u) (pc=0x%08x)\n", data, vianum, via_reg_str[reg], reg, shoe.pc);
slog("via_reg_write: writing 0x%02x to via%u reg %s (%u) (pc=0x%08x)\n", data, vianum, via_reg_str[reg], reg, shoe.pc);
switch (reg) {
case VIA_IER: {
@ -710,7 +710,7 @@ void via_write_raw (void)
const long double now = ((reg >= VIA_T1C_LO) && ((reg+1) <= VIA_T2C_HI)) ? _now() : 0.0;
// Uncommon case: writing to two registers simultaneously
printf("via_write_raw: writing to two registers simultaneously %u and %u (0x%x)\n", reg, reg+1 , (uint32_t)shoe.physical_dat);
slog("via_write_raw: writing to two registers simultaneously %u and %u (0x%x)\n", reg, reg+1 , (uint32_t)shoe.physical_dat);
assert(reg != 15); // If A/UX is trying to write to two VIA chips simultanously, that's not cool
@ -741,7 +741,7 @@ void via_read_raw (void)
// Uncommon case: reading from two registers simultaneously
printf("via_read_raw: reading from two registers simultaneously %u and %u\n", reg, reg+1);
slog("via_read_raw: reading from two registers simultaneously %u and %u\n", reg, reg+1);
assert(reg != 15); // If A/UX is trying to read from two VIA chips simultaneously, that's not cool

View File

@ -81,8 +81,7 @@ static void _switch_depth(shoebill_card_video_t *ctx, uint32_t depth)
}
void nubus_video_init(void *_ctx, uint8_t slotnum,
uint16_t width, uint16_t height, uint16_t scanline_width,
double refresh_rate)
uint16_t width, uint16_t height, uint16_t scanline_width)
{
shoebill_card_video_t *ctx = (shoebill_card_video_t*)_ctx;
ctx->width = width;
@ -147,7 +146,7 @@ uint32_t nubus_video_read_func(const uint32_t rawaddr, const uint32_t size,
// ROM and control registers
if ((addr >> 20) == 0xf) {
printf("nubus_video_read_func: got a read to 0x%08x sz=%u\n", rawaddr, size);
slog("nubus_video_read_func: got a read to 0x%08x sz=%u\n", rawaddr, size);
// ROM (0xFsFFxxxx)
if ((addr >> 16) == 0xff) {
@ -191,7 +190,7 @@ void nubus_video_write_func(const uint32_t rawaddr, const uint32_t size,
// ROM and control registers
if ((addr >> 20) == 0xf) {
printf("nubus_video_write_func: got a write to 0x%08x sz=%u data=0x%x\n", rawaddr, size, data);
slog("nubus_video_write_func: got a write to 0x%08x sz=%u data=0x%x\n", rawaddr, size, data);
// ROM (0xFsFFxxxx)
if ((addr >> 16) == 0xff)
@ -231,33 +230,33 @@ void nubus_video_write_func(const uint32_t rawaddr, const uint32_t size,
assert(!"driver tried to set bogus depth");
}
_switch_depth(ctx, newdepth);
printf("nubus_magic: set depth = %u\n", ctx->depth);
slog("nubus_magic: set depth = %u\n", ctx->depth);
break;
}
case 2: { // Gray out screen
// FIXME: implement me
printf("nubus_magic: grey screen\n");
slog("nubus_magic: grey screen\n");
break;
}
case 3: { // Set clut index
ctx->clut_idx = data & 0xff;
// assert(ctx->clut_idx < 256);
printf("nubus_magic: set clut_idx = %u\n", ctx->clut_idx);
slog("nubus_magic: set clut_idx = %u\n", ctx->clut_idx);
break;
}
case 4: { // Set red component of clut
ctx->clut[ctx->clut_idx].r = (data >> 8) & 0xff;
printf("nubus_magic: set %u.red = 0x%04x\n", ctx->clut_idx, data);
slog("nubus_magic: set %u.red = 0x%04x\n", ctx->clut_idx, data);
break;
}
case 5: { // Set green component of clut
ctx->clut[ctx->clut_idx].g = (data >> 8) & 0xff;
printf("nubus_magic: set %u.green = 0x%04x\n", ctx->clut_idx, data);
slog("nubus_magic: set %u.green = 0x%04x\n", ctx->clut_idx, data);
break;
}
case 6: { // Set blue component of clut
ctx->clut[ctx->clut_idx].b = (data >> 8) & 0xff;
printf("nubus_magic: set %u.blue = 0x%04x\n", ctx->clut_idx, data);
slog("nubus_magic: set %u.blue = 0x%04x\n", ctx->clut_idx, data);
break;
}
}

View File

@ -861,8 +861,7 @@ int main (int argc, char **argv)
shoebill_install_video_card(&config,
9, // slotnum
640, // 1024,
480, // 768,
60.0);
480); // 768,
// Start the VIA timer thread
shoebill_start();

View File

@ -287,13 +287,11 @@
- (void) createScreenWindow:(uint8_t)slotnum
height:(uint16_t)height
width:(uint16_t)width
refresh_freq:(double)refresh_freq
{
shoebill_install_video_card(&config,
slotnum,
width,
height,
refresh_freq);
height);
windowController[slotnum] = [[shoeScreenWindowController alloc]
initWithWindowNibName:@"shoeScreenView"
@ -382,7 +380,7 @@ void pram_callback (void *param, const uint8_t addr, const uint8_t byte)
return ;
}
[self createScreenWindow:9 height:height width:width refresh_freq:200.0/3.0];
[self createScreenWindow:9 height:height width:width];
shoebill_start();

423
sdl-gui/sdl.c Normal file
View File

@ -0,0 +1,423 @@
/*
* Copyright (c) 2014, Peter Rutenbar <pruten@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <pthread.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include "../core/shoebill.h"
rb_tree *keymap;
static void _init_keyboard_map (void)
{
#define mapkeymod(u, a, m) do { \
assert((a >> 7) == 0); \
void *value = (void*)(((m) << 8)| (a)); \
rb_insert(keymap, u, value, NULL); \
} while (0)
#define mapkey(_u, a) mapkeymod(_u, a, 0)
keymap = rb_new(p_new_pool(NULL));
// Letters
mapkey('a', 0x00);
mapkey('b', 0x0b);
mapkey('c', 0x08);
mapkey('d', 0x02);
mapkey('e', 0x0e);
mapkey('f', 0x03);
mapkey('g', 0x05);
mapkey('h', 0x04);
mapkey('i', 0x22);
mapkey('j', 0x26);
mapkey('k', 0x28);
mapkey('l', 0x25);
mapkey('m', 0x2e);
mapkey('n', 0x2d);
mapkey('o', 0x1f);
mapkey('p', 0x23);
mapkey('q', 0x0c);
mapkey('r', 0x0f);
mapkey('s', 0x01);
mapkey('t', 0x11);
mapkey('u', 0x20);
mapkey('v', 0x09);
mapkey('w', 0x0d);
mapkey('x', 0x07);
mapkey('y', 0x10);
mapkey('z', 0x06);
// Numbers
mapkey('0', 0x1d);
mapkey('1', 0x12);
mapkey('2', 0x13);
mapkey('3', 0x14);
mapkey('4', 0x15);
mapkey('5', 0x17);
mapkey('6', 0x16);
mapkey('7', 0x1a);
mapkey('8', 0x1c);
mapkey('9', 0x19);
// Top row symbols
mapkeymod(')', 0x1d, modShift);
mapkeymod('!', 0x12, modShift);
mapkeymod('@', 0x13, modShift);
mapkeymod('#', 0x14, modShift);
mapkeymod('$', 0x15, modShift);
mapkeymod('%', 0x17, modShift);
mapkeymod('^', 0x16, modShift);
mapkeymod('&', 0x1a, modShift);
mapkeymod('*', 0x1c, modShift);
mapkeymod('(', 0x19, modShift);
// Other symbols (no shift)
mapkeymod('`', 0x32, 0);
mapkeymod('-', 0x1b, 0);
mapkeymod('=', 0x18, 0);
mapkeymod('[', 0x21, 0);
mapkeymod(']', 0x1e, 0);
mapkeymod('\\', 0x2a, 0);
mapkeymod(';', 0x29, 0);
mapkeymod('\'', 0x27, 0);
mapkeymod(',', 0x2b, 0);
mapkeymod('.', 0x2f, 0);
mapkeymod('/', 0x2c, 0);
// Other symbols (with shift)
mapkeymod('~', 0x32, modShift);
mapkeymod('_', 0x1b, modShift);
mapkeymod('+', 0x18, modShift);
mapkeymod('{', 0x21, modShift);
mapkeymod('}', 0x1e, modShift);
mapkeymod('|', 0x2a, modShift);
mapkeymod(':', 0x29, modShift);
mapkeymod('"', 0x27, modShift);
mapkeymod('<', 0x2b, modShift);
mapkeymod('>', 0x2f, modShift);
mapkeymod('?', 0x2c, modShift);
// Function keys
mapkey(SDLK_F1, 0x7a);
mapkey(SDLK_F2, 0x78);
mapkey(SDLK_F3, 0x63);
mapkey(SDLK_F4, 0x76);
mapkey(SDLK_F5, 0x60);
mapkey(SDLK_F6, 0x61);
mapkey(SDLK_F7, 0x62);
mapkey(SDLK_F8, 0x64);
mapkey(SDLK_F9, 0x65);
mapkey(SDLK_F10, 0x6d);
mapkey(SDLK_F11, 0x67);
mapkey(SDLK_F12, 0x6f);
mapkey(SDLK_F13, 0x69);
mapkey(SDLK_F14, 0x6b);
mapkey(SDLK_F15, 0x71);
// Arrows
mapkey(SDLK_UP, 0x3e);
mapkey(SDLK_DOWN, 0x3d);
mapkey(SDLK_RIGHT, 0x3c);
mapkey(SDLK_LEFT, 0x3b);
// Delete
mapkey(SDLK_DELETE, 0x75);
mapkey(SDLK_BACKSPACE, 0x33);
mapkey(SDLK_BACKSPACE, 0x33);
// Enter, NL, CR
mapkey(SDLK_RETURN2, 0x24);
mapkey(SDLK_RETURN, 0x24);
// mapkey(0x03, 0x24);
// Other keys
mapkey(SDLK_ESCAPE, 0x35); // escape
mapkey(SDLK_SPACE, 0x31); // space
mapkey(SDLK_TAB, 0x30); // tab
}
static void _display_frame (SDL_Window *win)
{
shoebill_video_frame_info_t frame = shoebill_get_video_frame(9, 0);
shoebill_send_vbl_interrupt(9);
glDrawBuffer(GL_BACK);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 1.0);
glViewport(0, 0, frame.width, frame.height);
glRasterPos2i(0, frame.height);
glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelZoom(1.0, -1.0);
glDrawPixels(frame.width,
frame.height,
GL_RGBA,
GL_UNSIGNED_BYTE,
frame.buf);
SDL_GL_SwapWindow(win);
}
struct {
const char *scsi_path[8];
const char *rom_path;
const char *relative_unix_path;
uint32_t height, width;
uint32_t ram_megabytes;
_Bool verbose;
} user_params;
#define equals_arg(name) keylen = strlen(name); value = argv[i]+keylen; if (strncmp((name), argv[i], keylen) == 0)
static void _init_user_params (int argc, char **argv)
{
char *key;
uint32_t i;
for (i=0; i<8; i++)
user_params.scsi_path[i] = NULL;
user_params.rom_path = "macii.rom";
user_params.relative_unix_path = "/unix";
user_params.height = 640;
user_params.width = 800;
user_params.ram_megabytes = 16;
user_params.verbose = 1;
for (i=1; i<argc; i++) {
key = "ram=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.ram_megabytes = strtoul(argv[i]+strlen(key), NULL, 10);
continue;
}
key = "height=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.height = strtoul(argv[i]+strlen(key), NULL, 10);
continue;
}
key = "width=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.width = strtoul(argv[i]+strlen(key), NULL, 10);
continue;
}
key = "verbose=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.verbose = strtoul(argv[i]+strlen(key), NULL, 10);
continue;
}
key = "rom=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.rom_path = argv[i] + strlen(key);
continue;
}
key = "unix-path=";
if (strncmp(key, argv[i], strlen(key)) == 0) {
user_params.relative_unix_path = argv[i] + strlen(key);
continue;
}
if ((strncmp("disk", argv[i], 4) == 0) && (isdigit(argv[i][4])) && (argv[i][5] == '=')) {
uint8_t scsi_num = argv[i][4] - '0';
if (scsi_num < 7) {
user_params.scsi_path[scsi_num] = &argv[i][6];
continue;
}
}
}
}
static _Bool _setup_shoebill (void)
{
uint32_t i;
shoebill_config_t config;
bzero(&config, sizeof(shoebill_config_t));
config.aux_verbose = user_params.verbose;
config.ram_size = user_params.ram_megabytes * 1024 * 1024;
config.aux_kernel_path = user_params.relative_unix_path;
config.rom_path = user_params.rom_path;
for (i=0; i<7; i++)
config.scsi_devices[i].path = user_params.scsi_path[i];
if (!shoebill_initialize(&config)) {
printf("%s\n", config.error_msg);
return 0;
}
shoebill_install_video_card(&config,
9, // slotnum
user_params.width, // 1024,
user_params.height); // 768,
shoebill_start();
return 1;
}
static void _handle_key_event (SDL_Event *event)
{
const SDL_Keycode sym = event->key.keysym.sym;
const _Bool key_down = (event->type == SDL_KEYDOWN);
const SDL_Keymod sdl_mod = SDL_GetModState();
uint16_t adb_mod = 0;
void *_value;
if (sdl_mod & KMOD_SHIFT) adb_mod |= modShift;
if (sdl_mod & KMOD_CTRL) adb_mod |= modControl;
if (sdl_mod & KMOD_ALT) adb_mod |= modOption;
if (sdl_mod & KMOD_GUI) adb_mod |= modCommand;
if (sdl_mod & KMOD_CAPS) adb_mod |= modCapsLock;
if (rb_find(keymap, sym, &_value)) {
const uint16_t value = (uint16_t)_value;
shoebill_key_modifier((value >> 8) | adb_mod);
shoebill_key(key_down, value & 0xff);
}
}
int main (int argc, char **argv)
{
const uint32_t frame_ticks = 1000 / 60;
uint32_t last_frame_ticks;
_Bool capture_cursor;
_init_keyboard_map();
_init_user_params(argc, argv);
if (!_setup_shoebill())
return 0;
shoebill_video_frame_info_t frame = shoebill_get_video_frame(9, 1);
SDL_Init(SDL_INIT_VIDEO);
SDL_Window *win = SDL_CreateWindow("Shoebill",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
frame.width, frame.height,
SDL_WINDOW_OPENGL);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GLContext glctx = SDL_GL_CreateContext(win);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor(0.5, 0.5, 0.5, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, frame.width, 0, frame.height, -1.0, 1.0);
capture_cursor = 1;
SDL_ShowCursor(0);
SDL_SetRelativeMouseMode(1);
last_frame_ticks = SDL_GetTicks();
while (1) {
const uint32_t now = SDL_GetTicks();
uint32_t ticks_to_next_frame;
SDL_Event event;
if ((now - last_frame_ticks) >= frame_ticks) {
_display_frame(win);
last_frame_ticks = now;
ticks_to_next_frame = frame_ticks;
}
else
ticks_to_next_frame = frame_ticks - (now - last_frame_ticks);
event.type = SDL_USEREVENT;
SDL_WaitEventTimeout(&event, ticks_to_next_frame);
switch (event.type) {
case SDL_QUIT:
exit(0);
case SDL_MOUSEBUTTONDOWN: {
if ((event.button.button == SDL_BUTTON_LEFT) && capture_cursor)
shoebill_mouse_click(1);
break;
}
case SDL_MOUSEBUTTONUP: {
// If the cursor isn't captured, then any click will capture it
if (!capture_cursor)
capture_cursor = 1;
// If the cursor is captured, then left clicks get sent to the OS
else if (event.button.button == SDL_BUTTON_LEFT)
shoebill_mouse_click(0);
// If the cursor is captured, then right clicks will uncapture it
else if ((event.button.button == SDL_BUTTON_RIGHT) && capture_cursor)
capture_cursor = 0;
break;
}
case SDL_MOUSEMOTION: {
if (capture_cursor) {
_Bool down = event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT);
shoebill_mouse_click(down);
shoebill_mouse_move_delta(event.motion.xrel, event.motion.yrel);
}
break;
}
case SDL_KEYDOWN:
case SDL_KEYUP:
if (!event.key.repeat)
_handle_key_event(&event);
break;
}
if (capture_cursor) {
SDL_ShowCursor(0);
SDL_SetRelativeMouseMode(1);
}
else {
SDL_ShowCursor(1);
SDL_SetRelativeMouseMode(0);
}
}
return 0;
}