DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/bios.h
00001 /*
00002  *  Copyright (C) 2002-2015  The DOSBox Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 #include <stddef.h>
00021 #include <stdint.h>
00022 
00023 #include "regionalloctracking.h"
00024 
00025 #ifndef DOSBOX_BIOS_H
00026 #define DOSBOX_BIOS_H
00027 
00028 #define BIOS_BASE_ADDRESS_COM1          0x400
00029 #define BIOS_BASE_ADDRESS_COM2          0x402
00030 #define BIOS_BASE_ADDRESS_COM3          0x404
00031 #define BIOS_BASE_ADDRESS_COM4          0x406
00032 #define BIOS_ADDRESS_LPT1               0x408
00033 #define BIOS_ADDRESS_LPT2               0x40a
00034 #define BIOS_ADDRESS_LPT3               0x40c
00035 /* 0x40e is reserved */
00036 #define BIOS_CONFIGURATION              0x410
00037 /* 0x412 is reserved */
00038 #define BIOS_MEMORY_SIZE                0x413
00039 #define BIOS_TRUE_MEMORY_SIZE           0x415
00040 /* #define bios_expansion_memory_size      (*(unsigned int   *) 0x415) */
00041 #define BIOS_KEYBOARD_STATE             0x417
00042 #define BIOS_KEYBOARD_FLAGS1            BIOS_KEYBOARD_STATE
00043 #define BIOS_KEYBOARD_FLAGS1_RSHIFT_PRESSED                     (1 << 0)
00044 #define BIOS_KEYBOARD_FLAGS1_LSHIFT_PRESSED                     (1 << 1)
00045 #define BIOS_KEYBOARD_FLAGS1_CTRL_PRESSED                       (1 << 2)
00046 #define BIOS_KEYBOARD_FLAGS1_ALT_PRESSED                        (1 << 3)
00047 #define BIOS_KEYBOARD_FLAGS1_SCROLL_LOCK_ACTIVE         (1 << 4)
00048 #define BIOS_KEYBOARD_FLAGS1_NUMLOCK_ACTIVE                     (1 << 5)
00049 #define BIOS_KEYBOARD_FLAGS1_CAPS_LOCK_ACTIVE           (1 << 6)
00050 #define BIOS_KEYBOARD_FLAGS1_INSERT_ACTIVE                      (1 << 7)
00051 
00052 #define BIOS_KEYBOARD_FLAGS2            0x418
00053 #define BIOS_KEYBOARD_FLAGS2_LCTRL_PRESSED                      (1 << 0)
00054 #define BIOS_KEYBOARD_FLAGS2_LALT_PRESSED                       (1 << 1)
00055 #define BIOS_KEYBOARD_FLAGS2_SYSTEMKEY_HELD                     (1 << 2)
00056 #define BIOS_KEYBOARD_FLAGS2_SUSPENDKEY_TOGGLED         (1 << 3)
00057 #define BIOS_KEYBOARD_FLAGS2_SCROLL_LOCK_PRESSED        (1 << 4)
00058 #define BIOS_KEYBOARD_FLAGS2_NUM_LOCK_PRESSED           (1 << 5)
00059 #define BIOS_KEYBOARD_FLAGS2_CAPS_LOCK_PRESSED          (1 << 6)
00060 #define BIOS_KEYBOARD_FLAGS2_INSERT_PRESSED                     (1 << 7)
00061 
00062 #define BIOS_KEYBOARD_TOKEN             0x419
00063 /* used for keyboard input with Alt-Number */
00064 #define BIOS_KEYBOARD_BUFFER_HEAD       0x41a
00065 #define BIOS_KEYBOARD_BUFFER_TAIL       0x41c
00066 #define BIOS_KEYBOARD_BUFFER            0x41e
00067 /* #define bios_keyboard_buffer            (*(unsigned int   *) 0x41e) */
00068 #define BIOS_DRIVE_ACTIVE               0x43e
00069 #define BIOS_DRIVE_RUNNING              0x43f
00070 #define BIOS_DISK_MOTOR_TIMEOUT         0x440
00071 #define BIOS_DISK_STATUS                0x441
00072 /* #define bios_fdc_result_buffer          (*(unsigned short *) 0x442) */
00073 #define BIOS_VIDEO_MODE                 0x449
00074 #define BIOS_SCREEN_COLUMNS             0x44a
00075 #define BIOS_VIDEO_MEMORY_USED          0x44c
00076 #define BIOS_VIDEO_MEMORY_ADDRESS       0x44e
00077 #define BIOS_VIDEO_CURSOR_POS           0x450
00078 
00079 
00080 #define BIOS_CURSOR_SHAPE               0x460
00081 #define BIOS_CURSOR_LAST_LINE           0x460
00082 #define BIOS_CURSOR_FIRST_LINE          0x461
00083 #define BIOS_CURRENT_SCREEN_PAGE        0x462
00084 #define BIOS_VIDEO_PORT                 0x463
00085 #define BIOS_VDU_CONTROL                0x465
00086 #define BIOS_VDU_COLOR_REGISTER         0x466
00087 /* 0x467-0x468 is reserved */
00088 #define BIOS_TIMER                      0x46c
00089 #define BIOS_24_HOURS_FLAG              0x470
00090 #define BIOS_CTRL_BREAK_FLAG            0x471
00091 #define BIOS_CTRL_ALT_DEL_FLAG          0x472
00092 #define BIOS_HARDDISK_COUNT             0x475
00093 /* 0x474, 0x476, 0x477 is reserved */
00094 #define BIOS_LPT1_TIMEOUT               0x478
00095 #define BIOS_LPT2_TIMEOUT               0x479
00096 #define BIOS_LPT3_TIMEOUT               0x47a
00097 /* 0x47b is reserved */
00098 #define BIOS_COM1_TIMEOUT               0x47c
00099 #define BIOS_COM2_TIMEOUT               0x47d
00100 #define BIOS_COM3_TIMEOUT               0x47e
00101 #define BIOS_COM4_TIMEOUT               0x47f
00102 /* 0x47e is reserved */ //<- why that?
00103 /* 0x47f-0x4ff is unknow for me */
00104 #define BIOS_KEYBOARD_BUFFER_START      0x480
00105 #define BIOS_KEYBOARD_BUFFER_END        0x482
00106 
00107 #define BIOS_ROWS_ON_SCREEN_MINUS_1     0x484
00108 #define BIOS_FONT_HEIGHT                0x485
00109 
00110 #define BIOS_VIDEO_INFO_0               0x487
00111 #define BIOS_VIDEO_INFO_1               0x488
00112 #define BIOS_VIDEO_INFO_2               0x489
00113 #define BIOS_VIDEO_COMBO                0x48a
00114 
00115 #define BIOS_KEYBOARD_FLAGS3            0x496
00116 #define BIOS_KEYBOARD_FLAGS3_HIDDEN_E1                  (1 << 0)
00117 #define BIOS_KEYBOARD_FLAGS3_HIDDEN_E0                  (1 << 1)
00118 #define BIOS_KEYBOARD_FLAGS3_RCTRL_PRESSED              (1 << 2)
00119 #define BIOS_KEYBOARD_FLAGS3_RALT_PRESSED               (1 << 3)
00120 #define BIOS_KEYBOARD_FLAGS3_ENHANCED_KEYBOARD  (1 << 4)
00121 #define BIOS_KEYBOARD_FLAGS3_NUM_LOCK_FORCED    (1 << 5)
00122 #define BIOS_KEYBOARD_FLAGS3_ID_CHAR_WAS_LAST   (1 << 6)
00123 #define BIOS_KEYBOARD_FLAGS3_ID_READ_IN_PROCESS (1 << 7)
00124 
00125 #define BIOS_KEYBOARD_LEDS              0x497
00126 #define BIOS_KEYBOARD_LEDS_SCROLL_LOCK    (1 << 0)
00127 #define BIOS_KEYBOARD_LEDS_NUM_LOCK       (1 << 1)
00128 #define BIOS_KEYBOARD_LEDS_CAPS_LOCK      (1 << 2)
00129 #define BIOS_KEYBOARD_LEDS_CIRCUS         (1 << 3)
00130 #define BIOS_KEYBOARD_LEDS_ACK            (1 << 4)
00131 #define BIOS_KEYBOARD_LEDS_RESEND         (1 << 5)
00132 #define BIOS_KEYBOARD_LEDS_MODE           (1 << 6)
00133 #define BIOS_KEYBOARD_LEDS_TRANSMIT_ERROR (1 << 7)
00134 
00135 #define BIOS_WAIT_FLAG_POINTER          0x498
00136 #define BIOS_WAIT_FLAG_COUNT            0x49c           
00137 #define BIOS_WAIT_FLAG_ACTIVE                   0x4a0
00138 #define BIOS_WAIT_FLAG_TEMP                             0x4a1
00139 
00140 
00141 #define BIOS_PRINT_SCREEN_FLAG          0x500
00142 
00143 #define BIOS_VIDEO_SAVEPTR              0x4a8
00144 
00145 #define CURSOR_SCAN_LINE_NORMAL                 (0x6)
00146 #define CURSOR_SCAN_LINE_INSERT                 (0x4)
00147 #define CURSOR_SCAN_LINE_END                    (0x7)
00148 
00149 //#define BIOS_DEFAULT_IRQ0_LOCATION            (RealMake(0xf000,0xfea5))
00150 //#define BIOS_DEFAULT_IRQ1_LOCATION            (RealMake(0xf000,0xe987))
00151 //#define BIOS_DEFAULT_IRQ2_LOCATION            (RealMake(0xf000,0xff55))
00152 //#define BIOS_DEFAULT_HANDLER_LOCATION         (RealMake(0xf000,0xff53))
00153 //#define BIOS_VIDEO_TABLE_LOCATION             (RealMake(0xf000,0xf0a4))
00154 //#define BIOS_DEFAULT_RESET_LOCATION           (RealMake(0xf000,0xe05b))
00155 
00156 extern Bitu BIOS_DEFAULT_IRQ0_LOCATION;         // (RealMake(0xf000,0xfea5))
00157 extern Bitu BIOS_DEFAULT_IRQ1_LOCATION;         // (RealMake(0xf000,0xe987))
00158 extern Bitu BIOS_DEFAULT_IRQ2_LOCATION;         // (RealMake(0xf000,0xff55))
00159 extern Bitu BIOS_DEFAULT_HANDLER_LOCATION;      // (RealMake(0xf000,0xff53))
00160 extern Bitu BIOS_VIDEO_TABLE_LOCATION;          // (RealMake(0xf000,0xf0a4))
00161 extern Bitu BIOS_DEFAULT_RESET_LOCATION;        // RealMake(0xf000,0xe05b)
00162 extern Bitu BIOS_VIDEO_TABLE_SIZE;
00163 
00164 Bitu ROMBIOS_GetMemory(Bitu bytes,const char *who=NULL,Bitu alignment=1,Bitu must_be_at=0);
00165 
00166 extern RegionAllocTracking rombios_alloc;
00167 
00168 /* maximum of scancodes handled by keyboard bios routines */
00169 #define MAX_SCAN_CODE 0x58
00170 
00171 /* The Section handling Bios Disk Access */
00172 //#define BIOS_MAX_DISK 10
00173 
00174 //#define MAX_SWAPPABLE_DISKS 20
00175 
00176 void BIOS_ZeroExtendedSize(bool in);
00177 void char_out(Bit8u chr,Bit32u att,Bit8u page);
00178 void INT10_StartUp(void);
00179 void INT16_StartUp(void);
00180 void INT2A_StartUp(void);
00181 void INT2F_StartUp(void);
00182 void INT33_StartUp(void);
00183 void INT13_StartUp(void);
00184 
00185 bool BIOS_AddKeyToBuffer(Bit16u code);
00186 
00187 void INT10_ReloadRomFonts();
00188 
00189 void BIOS_SetComPorts (Bit16u baseaddr[]);
00190 void BIOS_SetLPTPort (Bitu port, Bit16u baseaddr);
00191 
00192 // \brief Synchronizes emulator num lock state with host.
00193 void BIOS_SynchronizeNumLock();
00194 
00195 // \brief Synchronizes emulator caps lock state with host.
00196 void BIOS_SynchronizeCapsLock();
00197 
00198 // \brief Synchronizes emulator scroll lock state with host.
00199 void BIOS_SynchronizeScrollLock();
00200 
00201 bool ISAPNP_RegisterSysDev(const unsigned char *raw,Bitu len,bool already=false);
00202 
00203 class ISAPnPDevice {
00204 public:
00205         ISAPnPDevice();
00206         virtual ~ISAPnPDevice();
00207 public:
00208         void checksum_ident();
00209 public:
00210         enum SmallTags {
00211                 PlugAndPlayVersionNumber =              0x1,
00212                 LogicalDeviceID =                       0x2,
00213                 CompatibleDeviceID =                    0x3,
00214                 IRQFormat =                             0x4,
00215                 DMAFormat =                             0x5,
00216                 StartDependentFunctions =               0x6,
00217                 EndDependentFunctions =                 0x7,
00218                 IOPortDescriptor =                      0x8,
00219                 FixedLocationIOPortDescriptor =         0x9,
00220                 SmallVendorDefined =                    0xE,
00221                 EndTag =                                0xF
00222         };
00223         enum LargeTags {
00224                 MemoryRangeDescriptor =                 0x1,
00225                 IdentifierStringANSI =                  0x2,
00226                 IdentifierStringUNICODE =               0x3,
00227                 LargeVendorDefined =                    0x4,
00228                 MemoryRange32Descriptor =               0x5,
00229                 FixedLocationMemoryRangeDescriptor =    0x6
00230         };
00231         // StartDependentFunction config
00232         enum DependentFunctionConfig {
00233                 PreferredDependentConfiguration =       0x0,
00234                 AcceptableDependentConfiguration =      0x1,
00235                 SubOptimalDependentConfiguration =      0x2
00236         };
00237         // IRQ format, signal types (bitfield)
00238         enum {
00239                 IRQFormatInfo_HighTrueEdgeSensitive =   0x1,
00240                 IRQFormatInfo_LowTrueEdgeSensitive =    0x2,
00241                 IRQFormatInfo_HighTrueLevelSensitive =  0x4,
00242                 IRQFormatInfo_LowTrueLevelSensitive =   0x8
00243         };
00244         // IRQ format, helper IRQ mask generator
00245         static inline uint16_t irq2mask(const int IRQ) {
00246                 if (IRQ < 0 || IRQ > 15) return 0;
00247                 return (uint16_t)(1U << (unsigned char)IRQ);
00248         }
00249         static inline uint16_t irq2mask(const int a,const int b) {
00250                 return irq2mask(a) | irq2mask(b);
00251         }
00252         static inline uint16_t irq2mask(const int a,const int b,const int c) {
00253                 return irq2mask(a) | irq2mask(b) | irq2mask(c);
00254         }
00255         static inline uint16_t irq2mask(const int a,const int b,const int c,const int d) {
00256                 return irq2mask(a) | irq2mask(b) | irq2mask(c) | irq2mask(d);
00257         }
00258         static inline uint16_t irq2mask(const int a,const int b,const int c,const int d,const int e) {
00259                 return irq2mask(a) | irq2mask(b) | irq2mask(c) | irq2mask(d) | irq2mask(e);
00260         }
00261         // DMA format transfer type
00262         enum {
00263                 DMATransferType_8bitOnly=0,
00264                 DMATransferType_8_and_16bit=1,
00265                 DMATransferType_16bitOnly=2
00266         };
00267         enum {
00268                 DMASpeedSupported_Compat=0,
00269                 DMASpeedSupported_TypeA=1,
00270                 DMASpeedSupported_TypeB=2,
00271                 DMASpeedSupported_TypeF=3
00272         };
00273         // DMA format
00274         static inline uint16_t dma2mask(const int DMA) {
00275                 if (DMA < 0 || DMA > 7 || DMA == 4) return 0;
00276                 return (uint16_t)(1U << (unsigned char)DMA);
00277         }
00278         static inline uint16_t dma2mask(const int a,const int b) {
00279                 return dma2mask(a) | dma2mask(b);
00280         }
00281         static inline uint16_t dma2mask(const int a,const int b,const int c) {
00282                 return dma2mask(a) | dma2mask(b) | dma2mask(c);
00283         }
00284         static inline uint16_t dma2mask(const int a,const int b,const int c,const int d) {
00285                 return dma2mask(a) | dma2mask(b) | dma2mask(c) | dma2mask(d);
00286         }
00287         static inline uint16_t dma2mask(const int a,const int b,const int c,const int d,const int e) {
00288                 return dma2mask(a) | dma2mask(b) | dma2mask(c) | dma2mask(d) | dma2mask(e);
00289         }
00290 public:
00291         virtual void config(Bitu val);
00292         virtual void wakecsn(Bitu val);
00293         virtual void select_logical_device(Bitu val);
00294         virtual void on_pnp_key();
00295         /* ISA PnP I/O data read/write */
00296         virtual uint8_t read(Bitu addr);
00297         virtual void write(Bitu addr,Bitu val);
00298         virtual bool alloc(size_t sz);
00299         void write_begin_SMALLTAG(const ISAPnPDevice::SmallTags stag,unsigned char len);
00300         void write_begin_LARGETAG(const ISAPnPDevice::LargeTags stag,unsigned int len);
00301         void write_nstring(const char *str,const size_t l);
00302         void write_byte(const unsigned char c);
00303         void begin_write_res();
00304         void end_write_res();
00305         void write_END();
00306         void write_ISAPnP_version(unsigned char major,unsigned char minor,unsigned char vendor);
00307         void write_Identifier_String(const char *str);
00308         void write_Logical_Device_ID(const char c1,const char c2,const char c3,const char c4,const char c5,const char c6,const char c7);
00309         void write_Compatible_Device_ID(const char c1,const char c2,const char c3,const char c4,const char c5,const char c6,const char c7);
00310         void write_Device_ID(const char c1,const char c2,const char c3,const char c4,const char c5,const char c6,const char c7);
00311         void write_Dependent_Function_Start(const ISAPnPDevice::DependentFunctionConfig cfg,const bool force=false);
00312         void write_IRQ_Format(const uint16_t IRQ_mask,const unsigned char IRQ_signal_type=0);
00313         void write_DMA_Format(const uint8_t DMA_mask,const unsigned char transfer_type_preference,const bool is_bus_master,const bool byte_mode,const bool word_mode,const unsigned char speed_supported);
00314         void write_IO_Port(const uint16_t min_port,const uint16_t max_port,const uint8_t count,const uint8_t alignment=1,const bool full16bitdecode=true);
00315         void write_End_Dependent_Functions();
00316 public:
00317         unsigned char           CSN;
00318         unsigned char           logical_device;
00319         unsigned char           ident[9];               /* 72-bit vendor + serial + checksum identity */
00320         unsigned char           ident_bp;               /* bit position of identity read */
00321         unsigned char           ident_2nd;
00322         unsigned char           resource_ident;
00323         unsigned char*          resource_data;
00324         size_t                  resource_data_len;
00325         unsigned int            resource_data_pos;
00326         size_t                  alloc_write;
00327         unsigned char*          alloc_res;
00328         size_t                  alloc_sz;
00329 };
00330 
00331 /* abc = ASCII letters of the alphabet
00332  * defg = hexadecimal digits */
00333 #define ISAPNP_ID(a,b,c,d,e,f,g) \
00334          (((a)&0x1F)    <<  2) | \
00335          (((b)&0x1F)    >>  3) | \
00336         ((((b)&0x1F)&7) << 13) | \
00337          (((c)&0x1F)    <<  8) | \
00338          (((d)&0x1F)    << 20) | \
00339          (((e)&0x1F)    << 16) | \
00340          (((f)&0x1F)    << 28) | \
00341          (((g)&0x1F)    << 24)
00342 
00343 #define ISAPNP_TYPE(a,b,c) (a),(b),(c)
00344 #define ISAPNP_SMALL_TAG(t,l) (((t) << 3) | (l))
00345 
00346 #define ISAPNP_SYSDEV_HEADER(id,type,ctrl) \
00347         ( (id)        & 0xFF), \
00348         (((id) >>  8) & 0xFF), \
00349         (((id) >> 16) & 0xFF), \
00350         (((id) >> 24) & 0xFF), \
00351         type, \
00352         ( (ctrl)       & 0xFF), \
00353         (((ctrl) >> 8) & 0xFF)
00354 
00355 #define ISAPNP_IO_RANGE(info,min,max,align,len) \
00356         ISAPNP_SMALL_TAG(8,7), \
00357         (info), \
00358         ((min) & 0xFF), (((min) >> 8) & 0xFF), \
00359         ((max) & 0xFF), (((max) >> 8) & 0xFF), \
00360         (align), \
00361         (len)
00362 
00363 #define ISAPNP_IRQ_SINGLE(irq,flags) \
00364         ISAPNP_SMALL_TAG(4,3), \
00365         ((1 << (irq)) & 0xFF), \
00366         (((1 << (irq)) >> 8) & 0xFF), \
00367         (flags)
00368 
00369 #define ISAPNP_IRQ(irqmask,flags) \
00370         ISAPNP_SMALL_TAG(4,3), \
00371         ((irqmask) & 0xFF), \
00372         (((irqmask) >> 8) & 0xFF), \
00373         (flags)
00374 
00375 #define ISAPNP_DMA_SINGLE(dma,flags) \
00376         ISAPNP_SMALL_TAG(5,2), \
00377         ((1 << (dma)) & 0xFF), \
00378         (flags)
00379 
00380 #define ISAPNP_DMA(dma,flags) \
00381         ISAPNP_SMALL_TAG(5,2), \
00382         ((dma) & 0xFF), \
00383         (flags)
00384 
00385 #define ISAPNP_END \
00386         ISAPNP_SMALL_TAG(0xF,1), 0x00
00387 
00388 void ISA_PNP_devreg(ISAPnPDevice *x);
00389 #endif