From 58ce4315f8dd6f00a14edfb764d6103d55982aea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Strohh=C3=A4cker?= Date: Thu, 11 Jun 2009 16:05:17 +0000 Subject: [PATCH] move callback default segment to bios standard; use fixed default offset for irq0 as well (ripsaw, fixes tinker tales) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3423 --- include/bios.h | 6 ++++ include/callback.h | 31 +++++++++++------ src/cpu/callback.cpp | 71 ++++++++++++++++++++------------------ src/ints/bios.cpp | 17 +++++---- src/ints/bios_keyboard.cpp | 10 +++--- 5 files changed, 77 insertions(+), 58 deletions(-) diff --git a/include/bios.h b/include/bios.h index e3377040..87696b6a 100644 --- a/include/bios.h +++ b/include/bios.h @@ -101,6 +101,12 @@ #define BIOS_VIDEO_SAVEPTR 0x4a8 + +#define BIOS_DEFAULT_HANDLER_LOCATION (RealMake(0xf000,0xff53)) +#define BIOS_DEFAULT_IRQ0_LOCATION (RealMake(0xf000,0xfea5)) +#define BIOS_DEFAULT_IRQ1_LOCATION (RealMake(0xf000,0xe987)) +#define BIOS_DEFAULT_IRQ2_LOCATION (RealMake(0xf000,0xff55)) + /* maximum of scancodes handled by keyboard bios routines */ #define MAX_SCAN_CODE 0x58 diff --git a/include/callback.h b/include/callback.h index a14fd8ce..53bc39c0 100644 --- a/include/callback.h +++ b/include/callback.h @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: callback.h,v 1.24 2009-05-27 09:15:40 qbix79 Exp $ */ +/* $Id: callback.h,v 1.25 2009-06-11 16:05:17 c2woody Exp $ */ #ifndef DOSBOX_CALLBACK_H #define DOSBOX_CALLBACK_H @@ -33,9 +33,10 @@ enum { CB_RETN,CB_RETF,CB_RETF8,CB_IRET,CB_IRETD,CB_IRET_STI,CB_IRET_EOI_PIC1, CB_INT29,CB_INT16,CB_HOOKABLE,CB_TDE_IRET,CB_IPXESR,CB_IPXESR_RET, CB_INT21 }; -#define CB_MAX 128 -#define CB_SIZE 32 -#define CB_SEG 0xF100 +#define CB_MAX 128 +#define CB_SIZE 32 +#define CB_SEG 0xF000 +#define CB_SOFFSET 0x1000 enum { CBRET_NONE=0,CBRET_STOP=1 @@ -44,14 +45,14 @@ enum { extern Bit8u lastint; static INLINE RealPt CALLBACK_RealPointer(Bitu callback) { - return RealMake(CB_SEG,(Bit16u)(callback*CB_SIZE)); + return RealMake(CB_SEG,(Bit16u)(CB_SOFFSET+callback*CB_SIZE)); } static INLINE PhysPt CALLBACK_PhysPointer(Bitu callback) { - return PhysMake(CB_SEG,(Bit16u)(callback*CB_SIZE)); + return PhysMake(CB_SEG,(Bit16u)(CB_SOFFSET+callback*CB_SIZE)); } static INLINE PhysPt CALLBACK_GetBase(void) { - return CB_SEG << 4; + return (CB_SEG << 4) + CB_SOFFSET; } Bitu CALLBACK_Allocate(); @@ -77,7 +78,7 @@ extern Bitu call_priv_io; class CALLBACK_HandlerObject{ private: bool installed; - Bit16u m_callback; + Bitu m_callback; enum {NONE,SETUP,SETUPAT} m_type; struct { RealPt old_vector; @@ -85,15 +86,23 @@ private: bool installed; } vectorhandler; public: - CALLBACK_HandlerObject():installed(false),m_type(NONE){vectorhandler.installed=false;} + CALLBACK_HandlerObject():installed(false),m_type(NONE) { + vectorhandler.installed=false; + } ~CALLBACK_HandlerObject(); + //Install and allocate a callback. void Install(CallBack_Handler handler,Bitu type,const char* description); void Install(CallBack_Handler handler,Bitu type,PhysPt addr,const char* description); + //Only allocate a callback number void Allocate(CallBack_Handler handler,const char* description=0); - Bit16u Get_callback(){return m_callback;} - RealPt Get_RealPointer(){ return CALLBACK_RealPointer(m_callback);} + Bit16u Get_callback() { + return (Bit16u)m_callback; + } + RealPt Get_RealPointer() { + return CALLBACK_RealPointer(m_callback); + } void Set_RealVec(Bit8u vec); }; #endif diff --git a/src/cpu/callback.cpp b/src/cpu/callback.cpp index fd88711f..b5d88089 100644 --- a/src/cpu/callback.cpp +++ b/src/cpu/callback.cpp @@ -16,7 +16,7 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* $Id: callback.cpp,v 1.40 2009-03-03 18:30:41 c2woody Exp $ */ +/* $Id: callback.cpp,v 1.41 2009-06-11 16:05:17 c2woody Exp $ */ #include #include @@ -26,7 +26,7 @@ #include "mem.h" #include "cpu.h" -/* CallBack are located at 0xF100:0 (see CB_SEG in callback.h) +/* CallBack are located at 0xF000:0x1000 (see CB_SEG and CB_SOFFSET in callback.h) And they are 16 bytes each and you can define them to behave in certain ways like a far return or and IRET */ @@ -87,8 +87,8 @@ static Bitu stop_handler(void) { void CALLBACK_RunRealFar(Bit16u seg,Bit16u off) { reg_sp-=4; - mem_writew(SegPhys(ss)+reg_sp,call_stop*CB_SIZE); - mem_writew(SegPhys(ss)+reg_sp+2,CB_SEG); + mem_writew(SegPhys(ss)+reg_sp,RealOff(CALLBACK_RealPointer(call_stop))); + mem_writew(SegPhys(ss)+reg_sp+2,RealSeg(CALLBACK_RealPointer(call_stop))); Bit32u oldeip=reg_eip; Bit16u oldcs=SegValue(cs); reg_eip=off; @@ -101,7 +101,7 @@ void CALLBACK_RunRealFar(Bit16u seg,Bit16u off) { void CALLBACK_RunRealInt(Bit8u intnum) { Bit32u oldeip=reg_eip; Bit16u oldcs=SegValue(cs); - reg_eip=(CB_MAX*CB_SIZE)+(intnum*6); + reg_eip=CB_SOFFSET+(CB_MAX*CB_SIZE)+(intnum*6); SegSet16(cs,CB_SEG); DOSBOX_RunMachine(); reg_eip=oldeip; @@ -141,7 +141,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02, callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xC3); //A RETN Instruction @@ -150,7 +150,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02, callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xCB); //A RETF Instruction @@ -159,7 +159,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02, callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xCA); //A RETF 8 Instruction @@ -169,7 +169,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xCF); //An IRET Instruction @@ -178,7 +178,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x66); //An IRETD Instruction @@ -189,7 +189,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x01,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x02,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x03, callback); //The immediate word + phys_writew(physAddress+0x03,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x01,(Bit8u)0xCF); //An IRET Instruction @@ -198,7 +198,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x50); // push ax @@ -213,7 +213,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x50); // push ax @@ -238,7 +238,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ phys_writew(physAddress+0x08,(Bit16u)0x0473); // jc skip phys_writeb(physAddress+0x0a,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x0b,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x0c,callback); //The immediate word + phys_writew(physAddress+0x0c,(Bit16u)callback); //The immediate word // jump here to (skip): physAddress+=6; } @@ -252,7 +252,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x50); // push ax @@ -272,13 +272,13 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ phys_writeb(physAddress+0x05,(Bit8u)0xfb); // sti phys_writeb(physAddress+0x06,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x07,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x08,callback); //The immediate word + phys_writew(physAddress+0x08,(Bit16u)callback); //The immediate word return 0x0a; case CB_IRQ12_RET: // ps2 mouse int74 return if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xfa); // cli @@ -298,7 +298,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ phys_writew(physAddress+0x05,(Bit16u)0x0674); // je skip phys_writeb(physAddress+0x07,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x08,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x09,callback); //The immediate word + phys_writew(physAddress+0x09,(Bit16u)callback); //The immediate word physAddress+=4; } else { phys_writew(physAddress+0x05,(Bit16u)0x0274); // je skip @@ -318,7 +318,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0xCF); //An IRET Instruction @@ -328,7 +328,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x01,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x02,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x03, callback); //The immediate word + phys_writew(physAddress+0x03,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x01,(Bit8u)0xCF); //An IRET Instruction @@ -339,7 +339,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x50); // push ax @@ -357,7 +357,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x05,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x06,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x07,callback); //The immediate word + phys_writew(physAddress+0x07,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x05,(Bit8u)0xCB); //A RETF Instruction @@ -366,7 +366,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x00,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x01,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x02,callback); //The immediate word + phys_writew(physAddress+0x02,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x00,(Bit8u)0x50); // push ax @@ -388,7 +388,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ phys_writeb(physAddress+0x06,(Bit8u)0x60); // pusha phys_writeb(physAddress+0x07,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x08,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x09,callback); //The immediate word + phys_writew(physAddress+0x09,(Bit16u)callback); //The immediate word phys_writeb(physAddress+0x0b,(Bit8u)0xCB); //A RETF Instruction return 0x0c; case CB_IPXESR_RET: // IPX ESR return @@ -409,7 +409,7 @@ Bitu CALLBACK_SetupExtra(Bitu callback, Bitu type, PhysPt physAddress, bool use_ if (use_cb) { phys_writeb(physAddress+0x01,(Bit8u)0xFE); //GRP 4 phys_writeb(physAddress+0x02,(Bit8u)0x38); //Extra Callback instruction - phys_writew(physAddress+0x03, callback); //The immediate word + phys_writew(physAddress+0x03,(Bit16u)callback); //The immediate word physAddress+=4; } phys_writeb(physAddress+0x01,(Bit8u)0xCF); //An IRET Instruction @@ -502,7 +502,7 @@ void CALLBACK_HandlerObject::Set_RealVec(Bit8u vec){ } else E_Exit ("double usage of vector handler"); } -void CALLBACK_Init(Section* sec) { +void CALLBACK_Init(Section* /*sec*/) { Bitu i; for (i=0;i IRET */ phys_writew(Real2Phys(RealGetVec(0x12))+0x12,0x20); //Hack for Jurresic if (machine==MCH_TANDY) phys_writeb(0xffffe,0xff) ; /* Tandy model */ diff --git a/src/ints/bios_keyboard.cpp b/src/ints/bios_keyboard.cpp index 49cda3a1..e26c11a2 100644 --- a/src/ints/bios_keyboard.cpp +++ b/src/ints/bios_keyboard.cpp @@ -16,6 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +/* $Id: bios_keyboard.cpp,v 1.36 2009-06-11 16:05:17 c2woody Exp $ */ + #include "dosbox.h" #include "callback.h" #include "mem.h" @@ -382,7 +384,7 @@ static Bitu IRQ1_Handler(void) { } if(flags1 &0x08) { Bit8u token = mem_readb(BIOS_KEYBOARD_TOKEN); - token= token*10 + scan_to_scanascii[scancode].alt; + token = token*10 + (Bit8u)(scan_to_scanascii[scancode].alt&0xff); mem_writeb(BIOS_KEYBOARD_TOKEN,token); } else if (flags1 &0x04) { add_key(scan_to_scanascii[scancode].control); @@ -601,12 +603,12 @@ void BIOS_SetupKeyboard(void) { /* Allocate/setup a callback for int 0x16 and for standard IRQ 1 handler */ call_int16=CALLBACK_Allocate(); - CALLBACK_Setup(call_int16,&INT16_Handler,CB_INT16,"keyboard"); + CALLBACK_Setup(call_int16,&INT16_Handler,CB_INT16,"Keyboard"); RealSetVec(0x16,CALLBACK_RealPointer(call_int16)); call_irq1=CALLBACK_Allocate(); - CALLBACK_Setup(call_irq1,&IRQ1_Handler,CB_IRQ1,"keyboard irq"); - RealSetVec(0x9,CALLBACK_RealPointer(call_irq1)); + CALLBACK_Setup(call_irq1,&IRQ1_Handler,CB_IRQ1,Real2Phys(BIOS_DEFAULT_IRQ1_LOCATION),"IRQ 1 Keyboard"); + RealSetVec(0x09,BIOS_DEFAULT_IRQ1_LOCATION); // pseudocode for CB_IRQ1: // push ax // in al, 0x60