Skip to content

Commit ef6a81d

Browse files
committed
Add SoftCDI system call catch in emulator
1 parent c2a64a6 commit ef6a81d

File tree

12 files changed

+79
-33
lines changed

12 files changed

+79
-33
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
# SoftCDI assembly/macro files are compiled on MS DOS
66
src/CDI/SoftCDI/*.a text eol=crlf
7+
src/CDI/SoftCDI/*.d text eol=crlf
78
src/CDI/SoftCDI/*.m text eol=crlf

src/CDI/SoftCDI/include/NVDRV.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ unsigned char NVDRV[] = {
33
0x05, 0x55, 0x0e, 0x01, 0xa0, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
44
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xc5,
55
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x4a, 0x00, 0x52,
6-
0x00, 0x58, 0x00, 0x5e, 0x00, 0x64, 0x00, 0x6a, 0x00, 0x00, 0x4e, 0x40, 0xff, 0xff, 0xb1, 0x40,
6+
0x00, 0x58, 0x00, 0x5e, 0x00, 0x64, 0x00, 0x6a, 0x00, 0x00, 0x4e, 0x40, 0x01, 0x11, 0xb1, 0x40,
77
0x4e, 0x75, 0x4e, 0x42, 0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x43, 0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x44,
88
0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x45, 0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x46, 0xb1, 0x40, 0x4e, 0x75,
9-
0x6e, 0x76, 0x64, 0x72, 0x76, 0x00, 0x00, 0x52, 0x0a, 0x77
9+
0x6e, 0x76, 0x64, 0x72, 0x76, 0x00, 0x00, 0xc3, 0x01, 0x75
1010
};
1111
unsigned int NVDRV_len = 122;

src/CDI/SoftCDI/include/VIDEO.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
unsigned char VIDEO[] = {
2-
0x4a, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6a,
2+
0x4a, 0xfc, 0x00, 0x01, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6e,
33
0x05, 0x55, 0x0e, 0x01, 0xa0, 0x99, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xd1,
5-
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x4a, 0x00, 0x4e,
6-
0x00, 0x54, 0x00, 0x5a, 0x00, 0x60, 0x00, 0x66, 0x00, 0x00, 0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x48,
7-
0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x49, 0xb1, 0x40, 0x4e, 0x75, 0x4e, 0x4a, 0xb1, 0x40, 0x4e, 0x75,
8-
0x4e, 0x4b, 0xb1, 0x40, 0x4e, 0x75, 0xb1, 0x40, 0x4e, 0x75, 0x76, 0x69, 0x64, 0x65, 0x6f, 0x00,
9-
0x00, 0xd0, 0x05, 0x16
4+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1e, 0xd9,
5+
0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x00, 0x4a, 0x00, 0x50,
6+
0x00, 0x56, 0x00, 0x5c, 0x00, 0x62, 0x00, 0x68, 0x00, 0x00, 0x4e, 0x40, 0x01, 0x01, 0x4e, 0x75,
7+
0x4e, 0x40, 0x01, 0x02, 0x4e, 0x75, 0x4e, 0x40, 0x01, 0x03, 0x4e, 0x75, 0x4e, 0x40, 0x01, 0x04,
8+
0x4e, 0x75, 0x4e, 0x40, 0x01, 0x05, 0x4e, 0x75, 0x4e, 0x40, 0x01, 0x06, 0x4e, 0x75, 0x76, 0x69,
9+
0x64, 0x65, 0x6f, 0x00, 0x00, 0xa1, 0xf2, 0xac
1010
};
11-
unsigned int VIDEO_len = 116;
11+
unsigned int VIDEO_len = 120;

src/CDI/SoftCDI/macros.m

-5
This file was deleted.

src/CDI/SoftCDI/nvdrv.a

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
nam nvdrv
22
use c:\DEFS\OSKDEFS.D
3-
use macros.m
3+
use softcdi.m
44

55
typelang equ (Drivr<<8)+Objct
66
attrrevs equ ((ReEnt+SupStat)<<8)+$99
@@ -21,7 +21,7 @@ EntryTable dc.w Init
2121
dc.w 0 Trap handler
2222

2323
Init
24-
softcdi
24+
softcdi $111
2525
eor.w d0,d0
2626
rts
2727

src/CDI/SoftCDI/softcdi.d

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* SoftCDI system calls values (taken from SoftCDI.hpp)
2+
Ucm_GetStat equ $104
3+
Ucm_SetStat equ $105

src/CDI/SoftCDI/softcdi.m

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
* Macro to invoke the SoftCDI process
2+
softcdi macro
3+
trap #0
4+
dc.w \1
5+
endm

src/CDI/SoftCDI/video.a

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
nam nvdrv
22
use c:\DEFS\OSKDEFS.D
3+
use softcdi.d
4+
use softcdi.m
35

46
typelang equ (Drivr<<8)+Objct
57
attrrevs equ ((ReEnt+SupStat)<<8)+$99 Not reentrant
@@ -18,31 +20,27 @@ EntryTable dc.w Init
1820
dc.w 0 Trap handler
1921

2022
Init
21-
eor.w d0,d0
23+
softcdi $101
2224
rts
2325

2426
Read
25-
trap #8
26-
eor.w d0,d0
27+
softcdi $102
2728
rts
2829

2930
Write
30-
trap #9
31-
eor.w d0,d0
31+
softcdi $103
3232
rts
3333

3434
GetStat
35-
trap #10
36-
eor.w d0,d0
35+
softcdi Ucm_GetStat
3736
rts
3837

3938
SetStat
40-
trap #11
41-
eor.w d0,d0
39+
softcdi Ucm_SetStat
4240
rts
4341

4442
Term
45-
eor.w d0,d0
43+
softcdi $106
4644
rts
4745

4846
vsect

src/CDI/boards/SoftCDI/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ target_sources(CeDImu
33
Bus.cpp
44
SoftCDI.cpp
55
SoftCDI.hpp
6+
SystemCalls.cpp
67
)

src/CDI/boards/SoftCDI/SoftCDI.cpp

+23-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "../../SoftCDI/include/SYSGO.h"
1010

1111
#include <array>
12+
#include <cinttypes>
1213
#include <cstring>
1314
#include <stdexcept>
1415

@@ -32,14 +33,15 @@ SoftCDI::SoftCDI(OS9::BIOS bios, std::span<const uint8_t> nvram, CDIConfig confi
3233
if(!m_bios.ReplaceModule({CSD_450, CSD_450_len}))
3334
throw std::runtime_error("Failed to patch csd");
3435

35-
if(!m_bios.ReplaceModule({NVDRV, NVDRV_len}))
36-
throw std::runtime_error("Failed to patch nvdrv");
36+
// Is it necessary to replace NVDRV ?
37+
// if(!m_bios.ReplaceModule({NVDRV, NVDRV_len}))
38+
// throw std::runtime_error("Failed to patch nvdrv");
3739

3840
if(!m_bios.ReplaceModule({VIDEO, VIDEO_len}))
3941
throw std::runtime_error("Failed to patch video");
4042

41-
if(!m_bios.ReplaceModule({SYSGO, SYSGO_len}))
42-
throw std::runtime_error("Failed to patch sysgo");
43+
// if(!m_bios.ReplaceModule({SYSGO, SYSGO_len}))
44+
// throw std::runtime_error("Failed to patch sysgo");
4345

4446
// Load the reset vector data.
4547
memcpy(m_ram0.data(), &m_bios[0], 8);
@@ -58,8 +60,23 @@ void SoftCDI::Scheduler()
5860
do
5961
{
6062
std::pair<size_t, std::optional<SCC68070::Exception>> res = m_cpu.SingleStepException(25);
61-
if(res.second.has_value()) // custom syscall to SoftCDI.
62-
m_cpu.PushException(res.second->vector);
63+
64+
if(res.second.has_value())
65+
{
66+
if(res.second->vector == SCC68070::Trap0Instruction &&
67+
res.second->data > SystemCalls::_Min) // SoftCDI syscall.
68+
{
69+
const uint16_t syscall = res.second->data;
70+
71+
m_cpu.GetNextWord(); // Skip syscall ID when returning.
72+
printf("softcdi syscall %" PRIX16 "\n", syscall);
73+
DispatchSystemCall(syscall);
74+
}
75+
else // CPU exception/OS-9 syscall.
76+
{
77+
m_cpu.PushException(*res.second);
78+
}
79+
}
6380

6481
const double ns = res.first * m_cpu.cycleDelay;
6582
CDI::IncrementTime(ns);

src/CDI/boards/SoftCDI/SoftCDI.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class SoftCDI : public CDI
6464
// Specifics to allow the BIOS to initialize.
6565
uint8_t m_csr1r; /**< CSR1R register of MCD212 to emulate Display Active. */
6666

67+
void DispatchSystemCall(const uint16_t) noexcept;
68+
6769
/** \brief SoftCDI memory map. */
6870
enum MemoryMap : uint32_t
6971
{
@@ -80,6 +82,14 @@ class SoftCDI : public CDI
8082
MCD212RegistersBegin = 0x4F'FFE0,
8183
MCD212RegistersEnd = 0x50'0000,
8284
};
85+
86+
/** \brief SoftCDI system calls. */
87+
enum SystemCalls : uint16_t
88+
{
89+
_Min = 0x100, /**< Minimal syscall index to not overlap with OS-9. */
90+
UCMGetStat = 0x104,
91+
UCMSetStat = 0x105,
92+
};
8393
};
8494

8595
#endif // CDI_BOARDS_SOFTCDI_SOFTCDI_HPP
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "SoftCDI.hpp"
2+
3+
#include <iostream>
4+
5+
void SoftCDI::DispatchSystemCall(const uint16_t syscall) noexcept
6+
{
7+
switch(syscall)
8+
{
9+
case UCMGetStat:
10+
std::cout << "Get stat" << '\n';
11+
break;
12+
13+
default:
14+
std::cerr << "Unkown system call 0x" << std::hex << syscall << '\n';
15+
}
16+
}

0 commit comments

Comments
 (0)