Skip to content

Commit 703bc68

Browse files
committed
[fw-isoldr] Added support for NAOMI cart ROM.
Also some NAOMI fixes for Dreamcast compatibility.
1 parent 1d3e27b commit 703bc68

File tree

9 files changed

+106
-31
lines changed

9 files changed

+106
-31
lines changed

firmware/isoldr/loader/gdc_syscall.s

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ gdc_redir_bc:
197197
mov #0, r6
198198
gdc_redir_c0:
199199
mov r7, r0
200-
mov #16, r1
200+
mov #17, r1
201201
cmp/hi r0, r1
202202
bf bad_syscall
203203
mov.l gdc_syscall, r1
@@ -273,7 +273,7 @@ gdcUnk1:
273273
.long _gdcDummy
274274
gdGdcChangeDisc:
275275
.long _gdGdcChangeDisc
276-
gdcUnk3:
277-
.long _gdcDummy
276+
gdGdcCartRead:
277+
.long _gdGdcCartRead
278278
gdcUnk4:
279279
.long _gdcDummy

firmware/isoldr/loader/include/main.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ extern isoldr_info_t *IsoInfo;
7676
extern uint32 loader_size;
7777
extern uint32 loader_addr;
7878
extern uint32 loader_end;
79+
80+
extern uint32 boot_stack;
81+
extern uint32 boot_sr;
82+
extern uint32 boot_vbr;
7983
extern void boot_stub(void *, uint32) __attribute__((noreturn));
84+
8085
void setup_machine(void);
8186
void shutdown_machine(void);
8287
void setup_region(void);

firmware/isoldr/loader/include/syscalls.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef _SYSCALLS_H
88
#define _SYSCALLS_H
99

10+
#include <sys/types.h>
1011
#include <arch/types.h>
1112
#include <dc/cdrom.h>
1213

@@ -224,4 +225,11 @@ int sys_misc_init(void);
224225

225226
void menu_exit(void);
226227

228+
typedef struct gdc_cart_read_params {
229+
uint32_t offset; // absolete offset in dump
230+
void *dst_buf; // pointer to destation buffer
231+
uint32_t size; // size in bytes
232+
uint32_t type; // reading type: 0 - PIO, 1 - DMA
233+
} gdc_cart_read_params_t;
234+
227235
#endif

firmware/isoldr/loader/main.c

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -118,29 +118,59 @@ int main(int argc, char *argv[]) {
118118
}
119119
}
120120

121-
if((IsoInfo->boot_mode != BOOT_MODE_DIRECT) ||
122-
((loader_end < CACHED_ADDR(IP_BIN_ADDR) ||
123-
loader_addr > CACHED_ADDR(APP_BIN_ADDR)) &&
124-
(malloc_heap_pos() < CACHED_ADDR(IP_BIN_ADDR) ||
125-
malloc_heap_pos() > CACHED_ADDR(APP_BIN_ADDR)))
126-
) {
127-
printf("Loading IP.BIN...\n");
128-
129-
if(!Load_IPBin(IsoInfo->boot_mode == BOOT_MODE_DIRECT ? 1 : 0)) {
130-
goto error;
121+
if(IsoInfo->image_type == IMAGE_TYPE_ROM_NAOMI) {
122+
123+
/* Clear ROM DMA busy flag */
124+
*((uint32_t *)NONCACHED_ADDR(0x0c0000ac)) = 0;
125+
126+
/* Set VBR address for IRQ vectors */
127+
boot_vbr = CACHED_ADDR(0x0c000000);
128+
LOGF("Setting VBR address to %08lx\n", boot_vbr);
129+
130+
/* Set stack pointer */
131+
boot_stack = CACHED_ADDR(0x0cc00000);
132+
LOGF("Setting stack pointer to %08lx\n", boot_stack);
133+
134+
/* Set SR value */
135+
boot_sr = 0x60000101;
136+
LOGF("Setting SR to %08lx\n", boot_sr);
137+
138+
uint8_t *dst = (uint8_t *) NONCACHED_ADDR(SYSCALLS_FW_ADDR);
139+
uint8_t *src = (uint8_t *) IsoInfo->syscalls;
140+
LOGF("Loading IRQ vectors from %08lx to %08lx %d bytes\n",
141+
(uintptr_t)src, (uintptr_t)dst, 0x4f00);
142+
memcpy(dst, src, 0x4f00);
143+
144+
dst = (uint8_t *) NONCACHED_ADDR(0x0c018000);
145+
src = (uint8_t *) IsoInfo->syscalls + 0x4f00;
146+
LOGF("Loading IRQ handlers from %08lx to %08lx %d bytes\n",
147+
(uintptr_t)src, (uintptr_t)dst, 0x7000);
148+
memcpy(dst, src, 0x7000);
149+
}
150+
else {
151+
if((IsoInfo->boot_mode != BOOT_MODE_DIRECT) ||
152+
((loader_end < CACHED_ADDR(IP_BIN_ADDR) ||
153+
loader_addr > CACHED_ADDR(APP_BIN_ADDR)) &&
154+
(malloc_heap_pos() < CACHED_ADDR(IP_BIN_ADDR) ||
155+
malloc_heap_pos() > CACHED_ADDR(APP_BIN_ADDR)))
156+
) {
157+
printf("Loading IP.BIN...\n");
158+
159+
if(!Load_IPBin(IsoInfo->boot_mode == BOOT_MODE_DIRECT ? 1 : 0)) {
160+
goto error;
161+
}
162+
}
163+
if(IsoInfo->exec.type != BIN_TYPE_KOS) {
164+
/* Patch GDC driver entry */
165+
gdc_syscall_patch();
131166
}
132-
}
133-
134-
if(IsoInfo->exec.type != BIN_TYPE_KOS) {
135-
/* Patch GDC driver entry */
136-
gdc_syscall_patch();
137-
}
138167

139-
if(!is_dreamcast() && IsoInfo->exec.type == BIN_TYPE_KATANA) {
140-
argc = patch_memory(0xff800030, (uint32)(&IsoInfo->cdda_offset[0]), 0);
141-
LOGF("Patch GPIO register: %d\n", argc);
142-
argc = patch_memory(0xffe80000, (uint32)(&IsoInfo->cdda_offset[1]), 0);
143-
LOGF("Patch SCIF register: %d\n", argc);
168+
if(!is_dreamcast() && IsoInfo->exec.type == BIN_TYPE_KATANA) {
169+
/* Patch GPIO register to prevent cable detection */
170+
argc = patch_memory(0xff800030,
171+
IsoInfo->cdda_offset[(sizeof(IsoInfo->cdda_offset) / 4) - 1], 0);
172+
LOGF("Patch GPIO register: %d\n", argc);
173+
}
144174
}
145175

146176
#ifdef HAVE_EXPT
@@ -151,7 +181,7 @@ int main(int argc, char *argv[]) {
151181
#endif
152182

153183
#ifdef HAVE_EXT_SYSCALLS
154-
if(IsoInfo->syscalls) {
184+
if(IsoInfo->syscalls && IsoInfo->image_type != IMAGE_TYPE_ROM_NAOMI) {
155185
printf("Loading syscalls...\n");
156186
Load_Syscalls();
157187
}

firmware/isoldr/loader/reader.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ int ReadSectors(uint8 *buf, int sec, int num, fs_callback_f *cb) {
303303
break;
304304
}
305305
case ISOFS_IMAGE_TYPE_ISO:
306+
case IMAGE_TYPE_ROM_NAOMI:
306307
default:
307308
{
308309
size_t offset = (sec - IsoInfo->track_lba[0]) * IsoInfo->sector_size;

firmware/isoldr/loader/startup.s

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
.globl _bios_patch_end
2323
.globl _boot_stub
2424
.globl _boot_stub_len
25+
.globl _boot_stack
26+
.globl _boot_sr
27+
.globl _boot_vbr
2528

2629
.text
2730
start:
@@ -110,14 +113,17 @@ _bios_patch_end:
110113
_boot_stub:
111114
! Set up some registers we will need to deal with later...
112115
mov r4, r14
113-
mov.l newr15, r15
116+
mov.l newr15, r0
117+
mov.l @r0, r15
114118
ldc r14, spc
115119
mov.l newgbr, r0
116120
mov.l ccr_addr, r3
117121
ldc r0, gbr
118122
mov.l newvbr, r1
123+
mov.l @r1, r1
119124
mov.w ccr_data, r2
120125
mov.l newsr, r4
126+
mov.l @r4, r4
121127
ldc r1, vbr
122128
mov.l newfpscr, r5
123129
ldc r4, sr
@@ -154,14 +160,20 @@ ccr_data:
154160
.align 4
155161
ccr_addr:
156162
.long 0xff00001c
157-
newr15:
163+
_boot_stack:
158164
.long 0x8c00f400 ! r15
165+
newr15:
166+
.long _boot_stack
159167
newgbr:
160168
.long 0x8c000000 ! gbr
161-
newvbr:
169+
_boot_vbr:
162170
.long 0x8c00f400 ! vbr
163-
newsr:
171+
newvbr:
172+
.long _boot_vbr
173+
_boot_sr:
164174
.long 0x700000f0 ! sr
175+
newsr:
176+
.long _boot_sr
165177
newfpscr:
166178
.long 0x00040001 ! fpscr
167179
startaddr:

firmware/isoldr/loader/syscalls.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,8 +744,9 @@ static int init_cmd() {
744744
#endif
745745

746746
if(!is_dreamcast() && IsoInfo->exec.type == BIN_TYPE_KATANA) {
747-
patch_memory(0xff800030, (uint32)(&IsoInfo->cdda_offset[0]), 5 << 20);
748-
patch_memory(0xffe80000, (uint32)(&IsoInfo->cdda_offset[1]), 0);
747+
/* Patch GPIO register to prevent cable detection */
748+
patch_memory(0xff800030,
749+
IsoInfo->cdda_offset[(sizeof(IsoInfo->cdda_offset) / 4) - 1], 5 << 20);
749750
}
750751
return CMD_STAT_COMPLETED;
751752
}
@@ -1396,6 +1397,24 @@ void gdGdcChangeDisc(int disc_num) {
13961397
#endif
13971398
}
13981399

1400+
void gdGdcCartRead(gdc_cart_read_params_t *params) {
1401+
LOGFF("offset=%d dst=%08lx size=%d type=%d\n",
1402+
params->offset, (uint32)params->dst_buf,
1403+
params->size, params->type);
1404+
1405+
if(params->type) {
1406+
fs_enable_dma(FS_DMA_SHARED);
1407+
}
1408+
else {
1409+
fs_enable_dma(FS_DMA_DISABLED);
1410+
}
1411+
1412+
/* TODO: Async DMA support */
1413+
ReadSectors(params->dst_buf,
1414+
params->offset / IsoInfo->sector_size,
1415+
params->size / IsoInfo->sector_size, NULL);
1416+
}
1417+
13991418
void gdcDummy(int gd_chn, int *arg2) {
14001419
LOGFF("%d 0x%08lx 0x%08lx\n", gd_chn, arg2[0], arg2[1]);
14011420
(void)gd_chn;
28 KB
Binary file not shown.
19.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)