Ignore:
Timestamp:
Jun 27, 2011, 6:40:13 PM (14 years ago)
Author:
Markus Thielen
Message:

added support for os2trace (buggy; messages get swallowed); reverted last change that ignored unknown command line arguments

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/os2ahci/libc.c

    r110 r111  
    5858                                                ULONG parm2);
    5959static int              mdelay_cal_end         (void);
     60static int              trace_enabled          (void);
    6061
    6162/* ------------------------ global/static variables ------------------------ */
     
    9899static ULONG heap_phys_addr;
    99100
     101/* global info segment */
     102volatile PGINFOSEG gis;
     103
     104
    100105/* ----------------------------- start of code ----------------------------- */
    101106
     
    105110void init_libc(void)
    106111{
     112  PSEL p;
     113
    107114  DevHelp_CreateSpinLock(&mem_lock);
    108115  DevHelp_CreateSpinLock(&com_lock);
    109116
    110117  DevHelp_VirtToPhys(heap_buf, &heap_phys_addr);
     118
     119  /* get global info segment */
     120  if (DevHelp_GetDOSVar(DHGETDOSV_SYSINFOSEG, 0, (PPVOID) &p) == 0) {
     121    gis = (PGINFOSEG) ((u32) *p << 16);
     122  }
     123
    111124}
    112125
     
    263276  static char buf[1024];
    264277  char *s;
     278  int len;
    265279
    266280  spin_lock(com_lock);
    267281
    268   vsprintf(buf, fmt, va);
     282  len = vsprintf(buf, fmt, va);
     283
     284   if (com_base == 0) {
     285    /* write debug message to trace buffer, not COM port */
     286    trace(debug, len, buf);
     287    spin_unlock(com_lock);
     288    return;
     289  }
    269290
    270291  /* write debug message to serial port */
     
    329350  vsprintf(buf, fmt, va);
    330351
    331   if (debug) {
     352  if (debug && com_base != 0) {
    332353    /* print the same message to COM1 as well */
    333354    printf("%s", buf);
     
    346367 * Print hex buffer to COM port.
    347368 */
    348 void phex(const void _far *p, int len, const char *fmt, ...)
     369void phex(const void _far *p, int len, u16 trace_minor_code, const char *fmt, ...)
    349370{
    350371  va_list va;
     
    353374
    354375  if (!debug) {
     376    return;
     377  }
     378
     379  if (!com_base) {
     380    /* dump to kernel trace buffer, not serial port;
     381     * just dump the buffer, it is formatted by TRACEFMT
     382     *
     383     * NOTE: writing the header to the trace buffer causes
     384     *       the trace facility to hick up and swallow the
     385     *       binary data that follows...
     386     */
     387    trace(trace_minor_code, len, buf);
    355388    return;
    356389  }
     
    705738void msleep(u32 millies)
    706739{
    707   volatile PGINFOSEG gis;
    708740  ULONG start;
    709741  ULONG end;
    710   PSEL p;
    711 
    712   if (DevHelp_GetDOSVar(DHGETDOSV_SYSINFOSEG, 0, (PPVOID) &p)) {
     742
     743  if (gis == NULL) {
    713744    /* no global info segment; use mdelay() */
    714745    mdelay(millies);
    715746    return;
    716747  }
    717   gis = (PGINFOSEG) ((u32) *p << 16);
     748
    718749  start = gis->msecs;
    719750  end = start + millies;
     
    834865  return(mdelay_cal_status == MD_CALIBRATION_END);
    835866}
     867
     868/******************************************************************************
     869 * is_trace_enabled - checks if kernel tracing is enabled
     870 */
     871int is_trace_enabled(void)
     872{
     873  int ret = 1; /* if global info seg is not present/known,
     874                * we enable tracing for now */
     875
     876  /* check global info segment's trace enabled bitmap if our
     877   * major trace code is enabled
     878   */
     879  if (gis) {
     880    u8 trace_bitmap = gis->amecRAS[AHCI_TRACE_MAJOR / 8];
     881    if (trace_bitmap & (0x80 >> (AHCI_TRACE_MAJOR % 8))) {
     882      ret = 1;
     883    } else {
     884      ret = 0;
     885    }
     886  }
     887
     888  return ret;
     889}
     890
     891/******************************************************************************
     892 * trace - write a buffer to the kernel trace buffer
     893 */
     894void trace(u16 minor_code, u16 cb_buf, const char _far *buf)
     895{
     896  if (!is_trace_enabled()) {
     897    return;
     898  }
     899
     900  DevHelp_RAS(AHCI_TRACE_MAJOR, minor_code, cb_buf, (PBYTE) buf);
     901}
     902
Note: See TracChangeset for help on using the changeset viewer.