DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
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 
00127 #define BIOS_WAIT_FLAG_POINTER          0x498
00128 #define BIOS_WAIT_FLAG_COUNT            0x49c           
00129 #define BIOS_WAIT_FLAG_ACTIVE                   0x4a0
00130 #define BIOS_WAIT_FLAG_TEMP                             0x4a1
00131 
00132 
00133 #define BIOS_PRINT_SCREEN_FLAG          0x500
00134 
00135 #define BIOS_VIDEO_SAVEPTR              0x4a8
00136 
00137 #define CURSOR_SCAN_LINE_NORMAL                 (0x6)
00138 #define CURSOR_SCAN_LINE_INSERT                 (0x4)
00139 #define CURSOR_SCAN_LINE_END                    (0x7)
00140 
00141 //#define BIOS_DEFAULT_IRQ0_LOCATION            (RealMake(0xf000,0xfea5))
00142 //#define BIOS_DEFAULT_IRQ1_LOCATION            (RealMake(0xf000,0xe987))
00143 //#define BIOS_DEFAULT_IRQ2_LOCATION            (RealMake(0xf000,0xff55))
00144 //#define BIOS_DEFAULT_HANDLER_LOCATION         (RealMake(0xf000,0xff53))
00145 //#define BIOS_VIDEO_TABLE_LOCATION             (RealMake(0xf000,0xf0a4))
00146 //#define BIOS_DEFAULT_RESET_LOCATION           (RealMake(0xf000,0xe05b))
00147 
00148 extern Bitu BIOS_DEFAULT_IRQ0_LOCATION;         // (RealMake(0xf000,0xfea5))
00149 extern Bitu BIOS_DEFAULT_IRQ1_LOCATION;         // (RealMake(0xf000,0xe987))
00150 extern Bitu BIOS_DEFAULT_IRQ2_LOCATION;         // (RealMake(0xf000,0xff55))
00151 extern Bitu BIOS_DEFAULT_HANDLER_LOCATION;      // (RealMake(0xf000,0xff53))
00152 extern Bitu BIOS_VIDEO_TABLE_LOCATION;          // (RealMake(0xf000,0xf0a4))
00153 extern Bitu BIOS_DEFAULT_RESET_LOCATION;        // RealMake(0xf000,0xe05b)
00154 extern Bitu BIOS_VIDEO_TABLE_SIZE;
00155 
00156 Bitu ROMBIOS_GetMemory(Bitu bytes,const char *who=NULL,Bitu alignment=1,Bitu must_be_at=0);
00157 
00158 extern RegionAllocTracking rombios_alloc;
00159 
00160 /* maximum of scancodes handled by keyboard bios routines */
00161 #define MAX_SCAN_CODE 0x58
00162 
00163 /* The Section handling Bios Disk Access */
00164 //#define BIOS_MAX_DISK 10
00165 
00166 //#define MAX_SWAPPABLE_DISKS 20
00167 
00168 void BIOS_ZeroExtendedSize(bool in);
00169 void char_out(Bit8u chr,Bit32u att,Bit8u page);
00170 void INT10_StartUp(void);
00171 void INT16_StartUp(void);
00172 void INT2A_StartUp(void);
00173 void INT2F_StartUp(void);
00174 void INT33_StartUp(void);
00175 void INT13_StartUp(void);
00176 
00177 bool BIOS_AddKeyToBuffer(Bit16u code);
00178 
00179 void INT10_ReloadRomFonts();
00180 
00181 void BIOS_SetComPorts (Bit16u baseaddr[]);
00182 void BIOS_SetLPTPort (Bitu port, Bit16u baseaddr);
00183 
00184 // \brief Synchronizes emulator num lock state with host.
00185 void BIOS_SynchronizeNumLock();
00186 
00187 bool ISAPNP_RegisterSysDev(const unsigned char *raw,Bitu len,bool already=false);
00188 
00189 class ISAPnPDevice {
00190 public:
00191         ISAPnPDevice();
00192         virtual ~ISAPnPDevice();
00193 public:
00194         void checksum_ident();
00195 public:
00196         enum SmallTags {
00197                 PlugAndPlayVersionNumber =              0x1,
00198                 LogicalDeviceID =                       0x2,
00199                 CompatibleDeviceID =                    0x3,
00200                 IRQFormat =                             0x4,
00201                 DMAFormat =                             0x5,
00202                 StartDependentFunctions =               0x6,
00203                 EndDependentFunctions =                 0x7,
00204                 IOPortDescriptor =                      0x8,
00205                 FixedLocationIOPortDescriptor =         0x9,
00206                 SmallVendorDefined =                    0xE,
00207                 EndTag =                                0xF
00208         };
00209         enum LargeTags {
00210                 MemoryRangeDescriptor =                 0x1,
00211                 IdentifierStringANSI =                  0x2,
00212                 IdentifierStringUNICODE =               0x3,
00213                 LargeVendorDefined =                    0x4,
00214                 MemoryRange32Descriptor =               0x5,
00215                 FixedLocationMemoryRangeDescriptor =    0x6
00216         };
00217         // StartDependentFunction config
00218         enum DependentFunctionConfig {
00219                 PreferredDependentConfiguration =       0x0,
00220                 AcceptableDependentConfiguration =      0x1,
00221                 SubOptimalDependentConfiguration =      0x2
00222         };
00223         // IRQ format, signal types (bitfield)
00224         enum {
00225                 IRQFormatInfo_HighTrueEdgeSensitive =   0x1,
00226                 IRQFormatInfo_LowTrueEdgeSensitive =    0x2,
00227                 IRQFormatInfo_HighTrueLevelSensitive =  0x4,
00228                 IRQFormatInfo_LowTrueLevelSensitive =   0x8
00229         };
00230         // IRQ format, helper IRQ mask generator
00231         static inline uint16_t irq2mask(const int IRQ) {
00232                 if (IRQ < 0 || IRQ > 15) return 0;
00233                 return (uint16_t)(1U << (unsigned char)IRQ);
00234         }
00235         static inline uint16_t irq2mask(const int a,const int b) {
00236                 return irq2mask(a) | irq2mask(b);
00237         }
00238         static inline uint16_t irq2mask(const int a,const int b,const int c) {
00239                 return irq2mask(a) | irq2mask(b) | irq2mask(c);
00240         }
00241         static inline uint16_t irq2mask(const int a,const int b,const int c,const int d) {
00242                 return irq2mask(a) | irq2mask(b) | irq2mask(c) | irq2mask(d);
00243         }
00244         static inline uint16_t irq2mask(const int a,const int b,const int c,const int d,const int e) {
00245                 return irq2mask(a) | irq2mask(b) | irq2mask(c) | irq2mask(d) | irq2mask(e);
00246         }
00247         // DMA format transfer type
00248         enum {
00249                 DMATransferType_8bitOnly=0,
00250                 DMATransferType_8_and_16bit=1,
00251                 DMATransferType_16bitOnly=2
00252         };
00253         enum {
00254                 DMASpeedSupported_Compat=0,
00255                 DMASpeedSupported_TypeA=1,
00256                 DMASpeedSupported_TypeB=2,
00257                 DMASpeedSupported_TypeF=3
00258         };
00259         // DMA format
00260         static inline uint16_t dma2mask(const int DMA) {
00261                 if (DMA < 0 || DMA > 7 || DMA == 4) return 0;
00262                 return (uint16_t)(1U << (unsigned char)DMA);
00263         }
00264         static inline uint16_t dma2mask(const int a,const int b) {
00265                 return dma2mask(a) | dma2mask(b);
00266         }
00267         static inline uint16_t dma2mask(const int a,const int b,const int c) {
00268                 return dma2mask(a) | dma2mask(b) | dma2mask(c);
00269         }
00270         static inline uint16_t dma2mask(const int a,const int b,const int c,const int d) {
00271                 return dma2mask(a) | dma2mask(b) | dma2mask(c) | dma2mask(d);
00272         }
00273         static inline uint16_t dma2mask(const int a,const int b,const int c,const int d,const int e) {
00274                 return dma2mask(a) | dma2mask(b) | dma2mask(c) | dma2mask(d) | dma2mask(e);
00275         }
00276 public:
00277         virtual void config(Bitu val);
00278         virtual void wakecsn(Bitu val);
00279         virtual void select_logical_device(Bitu val);
00280         virtual void on_pnp_key();
00281         /* ISA PnP I/O data read/write */
00282         virtual uint8_t read(Bitu addr);
00283         virtual void write(Bitu addr,Bitu val);
00284         virtual bool alloc(size_t sz);
00285         void write_begin_SMALLTAG(const ISAPnPDevice::SmallTags stag,unsigned char len);
00286         void write_begin_LARGETAG(const ISAPnPDevice::LargeTags stag,unsigned int len);
00287         void write_nstring(const char *str,const size_t l);
00288         void write_byte(const unsigned char c);
00289         void begin_write_res();
00290         void end_write_res();
00291         void write_END();
00292         void write_ISAPnP_version(unsigned char major,unsigned char minor,unsigned char vendor);
00293         void write_Identifier_String(const char *str);
00294         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);
00295         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);
00296         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);
00297         void write_Dependent_Function_Start(const ISAPnPDevice::DependentFunctionConfig cfg,const bool force=false);
00298         void write_IRQ_Format(const uint16_t IRQ_mask,const unsigned char IRQ_signal_type=0);
00299         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);
00300         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);
00301         void write_End_Dependent_Functions();
00302 public:
00303         unsigned char           CSN;
00304         unsigned char           logical_device;
00305         unsigned char           ident[9];               /* 72-bit vendor + serial + checksum identity */
00306         unsigned char           ident_bp;               /* bit position of identity read */
00307         unsigned char           ident_2nd;
00308         unsigned char           resource_ident;
00309         unsigned char*          resource_data;
00310         size_t                  resource_data_len;
00311         unsigned int            resource_data_pos;
00312         size_t                  alloc_write;
00313         unsigned char*          alloc_res;
00314         size_t                  alloc_sz;
00315 };
00316 
00317 /* abc = ASCII letters of the alphabet
00318  * defg = hexadecimal digits */
00319 #define ISAPNP_ID(a,b,c,d,e,f,g) \
00320          (((a)&0x1F)    <<  2) | \
00321          (((b)&0x1F)    >>  3) | \
00322         ((((b)&0x1F)&7) << 13) | \
00323          (((c)&0x1F)    <<  8) | \
00324          (((d)&0x1F)    << 20) | \
00325          (((e)&0x1F)    << 16) | \
00326          (((f)&0x1F)    << 28) | \
00327          (((g)&0x1F)    << 24)
00328 
00329 #define ISAPNP_TYPE(a,b,c) (a),(b),(c)
00330 #define ISAPNP_SMALL_TAG(t,l) (((t) << 3) | (l))
00331 
00332 #define ISAPNP_SYSDEV_HEADER(id,type,ctrl) \
00333         ( (id)        & 0xFF), \
00334         (((id) >>  8) & 0xFF), \
00335         (((id) >> 16) & 0xFF), \
00336         (((id) >> 24) & 0xFF), \
00337         type, \
00338         ( (ctrl)       & 0xFF), \
00339         (((ctrl) >> 8) & 0xFF)
00340 
00341 #define ISAPNP_IO_RANGE(info,min,max,align,len) \
00342         ISAPNP_SMALL_TAG(8,7), \
00343         (info), \
00344         ((min) & 0xFF), (((min) >> 8) & 0xFF), \
00345         ((max) & 0xFF), (((max) >> 8) & 0xFF), \
00346         (align), \
00347         (len)
00348 
00349 #define ISAPNP_IRQ_SINGLE(irq,flags) \
00350         ISAPNP_SMALL_TAG(4,3), \
00351         ((1 << (irq)) & 0xFF), \
00352         (((1 << (irq)) >> 8) & 0xFF), \
00353         (flags)
00354 
00355 #define ISAPNP_IRQ(irqmask,flags) \
00356         ISAPNP_SMALL_TAG(4,3), \
00357         ((irqmask) & 0xFF), \
00358         (((irqmask) >> 8) & 0xFF), \
00359         (flags)
00360 
00361 #define ISAPNP_DMA_SINGLE(dma,flags) \
00362         ISAPNP_SMALL_TAG(5,2), \
00363         ((1 << (dma)) & 0xFF), \
00364         (flags)
00365 
00366 #define ISAPNP_DMA(dma,flags) \
00367         ISAPNP_SMALL_TAG(5,2), \
00368         ((dma) & 0xFF), \
00369         (flags)
00370 
00371 #define ISAPNP_END \
00372         ISAPNP_SMALL_TAG(0xF,1), 0x00
00373 
00374 void ISA_PNP_devreg(ISAPnPDevice *x);
00375 #endif