home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / gccmsdos.arj / GNU / BINUTY / EXTENDER.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-31  |  28.1 KB  |  1,796 lines

  1. /*   Library program for GCC on DOS-Extender        
  2.  
  3.     (c) Copyright by Keisuke Yoshida, 1989, 1990  ver 0.92
  4.  
  5. */ 
  6.  
  7. /*
  8.     Version:    Inline library V0.12alpha
  9. */
  10. #ifndef EXTENDER_H
  11. #define EXTENDER_H 1
  12.  
  13. extern int  _dos_errno;
  14. extern int  _dos_errclass;
  15. extern int  _dos_errsugested;
  16. extern int  _dos_errlocus;
  17.  
  18. struct _allocation_table_information {
  19.     int  nsectors;    /* # of sectors per cluster */
  20.     char *fat_id;    /* pointer to FAT ID byte */
  21.     int  nbytes;    /* # of bytes per sector */
  22.     int  nclusters;    /* # of sectors per disk */
  23. };
  24.  
  25. struct _system_date {
  26.     int  dayofweek;
  27.     int  year;
  28.     int  month;
  29.     int  day;
  30. };
  31.  
  32. struct _set_system_date {
  33.     short  year;
  34.     char  month;
  35.     char  day;
  36. };
  37.  
  38. struct _system_time {
  39.     int  hours;
  40.     int  minutes;
  41.     int  seconds;
  42.     int  subsecs;
  43. };
  44.  
  45. struct _set_system_time {
  46.     char  hours;
  47.     char  minutes;
  48.     char  seconds;
  49.     char  subsecs;
  50. };
  51.  
  52. struct _file_date_time {
  53.     unsigned int seconds    : 5;
  54.     unsigned int minutes    : 6;
  55.     unsigned int hours    : 5;
  56.     unsigned int day    : 5;
  57.     unsigned int month    : 4;
  58.     unsigned int year    : 7;
  59. };
  60.  
  61. struct _version_info {
  62.     int  major_version;
  63.     int  minor_version;
  64.     union {
  65.         int    version;
  66.         char    version_string[4];
  67.     } extender;
  68. };
  69.  
  70. struct _disk_space {
  71.     int  nsectors;        /* # of sectors per cluster */
  72.     int  free_clusters;    /* # of free cluster per disk */
  73.     int  nbytes;        /* # of bytes per sector */
  74.     int  nclusters;        /* # of clusters per disk */
  75. };
  76.  
  77. static __inline__ void
  78. _dos_terminate()
  79. {
  80.     asm volatile("
  81.     movb %0,%%ah
  82.     int $0x21"
  83.     : /* no output */
  84.     : "i"(0x00)
  85.     : "ax");
  86. }
  87.  
  88. static __inline__ int
  89. _dos_keyboard_input()
  90. {
  91.     int  c;
  92.  
  93.     asm volatile("
  94.     movb %1,%%ah
  95.     int $0x21
  96.     movzbl %%al,%0"
  97.     : "=r" (c)
  98.     : "i"(0x01)
  99.     : "ax");
  100.  
  101.     return c;
  102. }
  103.  
  104. static __inline__ void
  105. _dos_display_output(int c)
  106. {
  107.     asm volatile("
  108.     movb %0,%%dl
  109.     movb %1,%%ah
  110.     int $0x21"
  111.     : /* no output */
  112.     : "g"((unsigned char) c), "i"(0x02)
  113.     : "ax", "dx");
  114. }
  115.  
  116. static __inline__ int
  117. _dos_aux_input()
  118. {
  119.     int c;
  120.  
  121.     asm volatile("
  122.     movb %1,%%ah
  123.     int $0x21
  124.     movzbl %%al,%0"
  125.     : "=r"(c)
  126.     : "i"(0x03)
  127.     : "ax");
  128.  
  129.     return c;
  130. }
  131.  
  132. static __inline__ void
  133. _dos_aux_output(int c)
  134. {
  135.     asm volatile("
  136.     movb %0,%%dl
  137.     movb %1,%%ah
  138.     int $0x21"
  139.     : /* no output */
  140.     : "g"((unsigned char) c), "i"(0x04)
  141.     : "ax", "dx");
  142. }
  143.  
  144. static __inline__ void
  145. _dos_printer_output(int c)
  146. {
  147.     asm volatile("
  148.     movb %0,%%dl
  149.     movb %1,%%ah
  150.     int $0x21"
  151.     : /* no output */
  152.     : "g"((unsigned char) c), "i"(0x05)
  153.     : "ax", "dx");
  154. }
  155.  
  156. static __inline__ int
  157. _dos_direct_console_input()
  158. {
  159.     int  c;
  160.  
  161.     asm volatile("
  162.     movb %1,%%dl
  163.     movb %2,%%ah
  164.     int $0x21
  165.     jnz 0f
  166.     movl %3,%0
  167.     jmp 1f
  168. 0:
  169.     movzbl %%al,%0
  170. 1:"
  171.     : "=r"(c)
  172.     : "i"(0xff), "i"(0x06), "i"(-1)
  173.     : "ax", "dx");
  174.  
  175.     return c;
  176. }
  177.  
  178. static __inline__ void
  179. _dos_direct_console_output(int c)
  180. {
  181.     asm volatile("
  182.     movb %0,%%dl
  183.     movb %1,%%ah
  184.     int $0x21"
  185.     : /* no output */
  186.     : "g"((unsigned char) c), "i"(0x06)
  187.     : "ax", "dx");
  188. }
  189.  
  190. static __inline__ int
  191. _dos_direct_console_input_without_echo()
  192. {
  193.     int  c;
  194.  
  195.     asm volatile("
  196.     movb %1,%%ah
  197.     int $0x21
  198.     movzbl %%al,%0"
  199.     : "=r"(c)
  200.     : "i"(0x07)
  201.     : "ax");
  202.  
  203.     return c;
  204. }
  205.  
  206. static __inline__ int
  207. _dos_keyboard_input_without_echo()
  208. {
  209.     int c;
  210.  
  211.     asm volatile("
  212.     movb %1,%%ah
  213.     int $0x21
  214.     movzbl %%al,%0"
  215.     : "=r"(c)
  216.     : "i"(0x08)
  217.     : "ax");
  218.  
  219.     return c;
  220. }
  221.  
  222. static __inline__ void
  223. _dos_print_string(const char *string)
  224. {
  225.     /* If you need to set %ds, insert here. */
  226.     asm volatile("
  227.     movl %0,%%edx
  228.     movb %1,%%ah
  229.     int $0x21"
  230.     : /* no output */
  231.     : "g"(string), "i"(0x09)
  232.     : "ax", "dx");
  233. }
  234.  
  235. static __inline__ void
  236. _dos_buffered_keyboard_input(char *buffer)
  237. {
  238.     /* If you need to set %ds, insert here. */
  239.     asm volatile("
  240.     movl %0,%%edx
  241.     movb %1,%%ah
  242.     int $0x21"
  243.     : /* no output */
  244.     : "g"(buffer), "i"(0x0a)
  245.     : "ax", "dx");
  246. }
  247.  
  248. static __inline__ int
  249. _dos_check_standard_input_status()
  250. {
  251.     int  result;
  252.  
  253.     asm volatile("
  254.     movb %1,%%ah
  255.     int $0x21
  256.     movzbl %%al,%0"
  257.     : "=r"(result)
  258.     : "i"(0x0b)
  259.     : "ax");
  260.  
  261.     return result;
  262. }
  263.  
  264. static __inline__ int
  265. _dos_clear_keyboard_buffer(int function, char *buffer)
  266. {
  267.     int  c;
  268.     int  request;
  269.  
  270.     switch (function) {
  271.       case 0x01:
  272.         request = 0x0c01;    break;
  273.       case 0x06:
  274.         request = 0x0c06;    break;
  275.       case 0x07:
  276.         request = 0x0c07;    break;
  277.       case 0x08:
  278.         request = 0x0c08;    break;
  279.  
  280.       case 0x0a:
  281.         asm volatile("
  282.         movl %0,%%edx
  283.         movw %1,%%ax
  284.         int $0x21"
  285.         : /* no output */
  286.         : "g"(buffer), "i"(0x0c0a)
  287.         : "ax", "dx");
  288.  
  289.         return 0;
  290.  
  291.       default:
  292.         return -1;
  293.     }
  294.  
  295.     asm volatile("
  296.     movb %1,%%al
  297.     movb %2,%%ah
  298.     int $0x21
  299.     movzbl %%al,%0"
  300.     : "=r"(c)
  301.     : "g"((unsigned char) request), "i"(0x0c)
  302.     : "ax");
  303.  
  304.     return c;
  305. }
  306.  
  307. static __inline__ void
  308. _dos_disk_reset()
  309. {
  310.     asm volatile("
  311.     movb %0,%%ah
  312.     int $0x21"
  313.     : /* no output */
  314.     : "i"(0x0d)
  315.     : "ax");
  316. }
  317.  
  318. static __inline__ int
  319. _dos_select_disk(int drive)
  320. {
  321.     int logical_drives;
  322.  
  323.     asm volatile("
  324.     movb %1,%%dl
  325.     movb %2,%%ah
  326.     int $0x21
  327.     movzbl %%al,%0"
  328.     : "=r"(logical_drives)
  329.     : "g"((unsigned char) drive), "i"(0x0e)
  330.     : "ax", "dx");
  331.  
  332.     return logical_drives;
  333. }
  334.  
  335. static __inline__ int
  336. _dos_get_default_disk_number()
  337. {
  338.     int number;
  339.  
  340.     asm volatile("
  341.     movb %1,%%ah
  342.     int $0x21
  343.     movzbl %%al,%0"
  344.     : "=r"(number)
  345.     : "i"(0x19)
  346.     : "ax");
  347.  
  348.     return number;
  349. }
  350.  
  351. static __inline__ void
  352. _dos_set_disk_transfer_area_address(char *buffer)
  353. {
  354.     /* %ds is currest %ds */
  355.     asm volatile("
  356.     movl %0,%%edx
  357.     movb %1,%%ah
  358.     int $0x21"
  359.     : /* no output */
  360.     : "g"(buffer), "i"(0x1a)
  361.     : "ax", "dx");
  362. }
  363.  
  364. static __inline__ struct _allocation_table_information
  365. _dos_allocation_table_information()
  366. {
  367.     struct _allocation_table_information  info;
  368.  
  369.     asm volatile("
  370.     movb %4,%%ah
  371.     int $0x21
  372.     movzbl %%al,%0
  373.     movl %%ebx,%1
  374.     movzwl %%cx,%2
  375.     movzwl %%dx,%3"
  376.     :"=r"(info.nsectors), "=r"(info.fat_id),
  377.      "=r"(info.nbytes),   "=r"(info.nclusters)
  378.     : "i"(0x1b)
  379.     : "ax", "bx", "cx", "dx");
  380.  
  381.     return info;
  382. }
  383.  
  384. static __inline__ struct _allocation_table_information
  385. _dos_allocation_table_information_for_special_device(int drive)
  386. {
  387.     struct _allocation_table_information  info;
  388.  
  389.     asm volatile("
  390.     movb %4,%%dl
  391.     movb %5,%%ah
  392.     int $0x21
  393.     movzbl %%al,%0
  394.     movl %%ebx,%1
  395.     movzwl %%cx,%2
  396.     movzwl %%dx,%3"
  397.     : "=r"(info.nsectors), "=r"(info.fat_id),
  398.       "=r"(info.nbytes),   "=r"(info.nclusters)
  399.     : "g"((unsigned char) drive), "i"(0x1c)
  400.     : "ax", "bx", "cx", "dx");
  401.  
  402.     return info;
  403. }
  404.  
  405. static __inline__ int
  406. _dos_set_interrupt_vector()
  407. {
  408.     /* not use this */
  409. }
  410.  
  411. static __inline__ int
  412. _dos_create_psp()
  413. {
  414.     /* dos extender not supported */
  415. }
  416.  
  417. static __inline__ struct _system_date
  418. _dos_get_current_date()
  419. {
  420.     struct _system_date date;
  421.  
  422.     asm volatile("
  423.     movb %4,%%ah
  424.     int $0x21
  425.     movzbl %%al,%0
  426.     movzwl %%cx,%1
  427.     movzbl %%dh,%2
  428.     movzbl %%dl,%3"
  429.     : "=r"(date.dayofweek), "=r"(date.year),
  430.       "=r"(date.month),     "=r"(date.day)
  431.     : "i"(0x2a)
  432.     : "ax", "cx", "dx");
  433.  
  434.     return date;
  435. }
  436.  
  437. static __inline__ int
  438. _dos_set_current_date(struct _set_system_date date)
  439. {
  440.     int  result;
  441.     unsigned short year  = (unsigned short) date.year;
  442.     unsigned char  month = (unsigned short) date.month;
  443.     unsigned char  day   = (unsigned short) date.day;
  444.  
  445.     asm volatile("
  446.     movw %1,%%cx
  447.     movb %2,%%dh
  448.     movb %3,%%dl
  449.     movb %4,%%ah
  450.     int $0x21
  451.     movsbl %%al,%0"
  452.     : "=r"(result)
  453.     : "g"(year), "g"(month), "g"(day), "i"(0x2b)
  454.     : "ax", "cx", "dx");
  455.  
  456.     return result;
  457. }
  458.  
  459. static __inline__ struct _system_time
  460. _dos_get_current_time()
  461. {
  462.     struct _system_time time;
  463.  
  464.     asm volatile("
  465.     movb %4,%%ah
  466.     int $0x21
  467.     movzbl %%ch,%0
  468.     movzbl %%cl,%1
  469.     movzbl %%dh,%2
  470.     movzbl %%dl,%3"
  471.     : "=r"(time.hours),   "=r"(time.minutes),
  472.       "=r"(time.seconds), "=r"(time.subsecs)
  473.     : "i"(0x2c)
  474.     : "ax", "cx", "dx");
  475.  
  476.     return time;
  477. }
  478.  
  479. static __inline__ int
  480. _dos_set_current_time(struct _set_system_time time)
  481. {
  482.     int  result;
  483.     unsigned char hours   = (unsigned char) time.hours;
  484.     unsigned char minutes = (unsigned char) time.minutes;
  485.     unsigned char seconds = (unsigned char) time.seconds;
  486.     unsigned char subsecs = (unsigned char) time.subsecs;
  487.  
  488.     asm volatile("
  489.     movb %3,%%dh
  490.     movb %4,%%dl
  491.     movb %1,%%ch
  492.     movb %2,%%cl
  493.     movb %5,%%ah
  494.     int $0x21
  495.     movsbl %%al,%0"
  496.     : "=r"(result)
  497.     : "g"(hours), "g"(minutes), "g"(seconds), "g"(subsecs), "i"(0x2d)
  498.     : "ax", "cx", "dx");
  499.  
  500.     return result;
  501. }
  502.  
  503. static __inline__ int
  504. _dos_set_verify_flag(int flag)
  505. {
  506.     if (!((flag == 0x00) || (flag == 0x01))) return -1;
  507.  
  508.     asm volatile("
  509.     movb %0,%%al
  510.     movb %1,%%ah
  511.     int $0x21"
  512.     : /* no output */
  513.     : "g"((unsigned char) flag), "i"(0x2e)
  514.     : "ax");
  515.  
  516.     return 0;
  517. }
  518.  
  519. static __inline__ char *
  520. _dos_get_disk_transfer_area_address()
  521. {
  522.     char *dta;
  523.  
  524.     /* %es is ignored */
  525.     asm volatile("
  526.     movb %1,%%ah
  527.     int $0x21
  528.     movl %%ebx,%0"
  529.     : "=r"(dta)
  530.     : "i"(0x2f)
  531.     : "ax", "bx");
  532.  
  533.     return dta;
  534. }
  535.  
  536. static __inline__ struct _version_info
  537. _dos_get_dos_version()
  538. {
  539.     char phar[5];
  540.     struct _version_info info;
  541.  
  542.     phar[0] = 'P';
  543.     phar[1] = 'H';
  544.     phar[2] = 'A';
  545.     phar[3] = 'R';
  546.     phar[4] = '\0';
  547.  
  548.     asm volatile("
  549.     movl %3,%%ebx
  550.     movb %4,%%ah
  551.     int $0x21
  552.     movzbl %%al,%0
  553.     movzbl %%ah,%1
  554.     movl %%ebx,%2"
  555.     : "=r"(info.major_version),
  556.       "=r"(info.minor_version),
  557.       "=r"(info.extender.version)
  558.     : "g"(phar), "i"(0x30)
  559.     : "ax", "bx", "cx", "dx");
  560.  
  561.     return info;
  562. }
  563.  
  564. static __inline__ void
  565. _dos_terminate_but_stay_resident(int status)
  566. {
  567.     asm volatile("
  568.     movb %0,%%al
  569.     movb %1,%%ah
  570.     int $0x21"
  571.     : /* no output */
  572.     : "g"((unsigned char) status), "i"(0x31)
  573.     : "ax");
  574. }
  575.  
  576. static __inline__ char *
  577. _dos_get_drive_parameter_block(int drive)
  578. {
  579.     int  result;
  580.     char *parameter_block;
  581.  
  582.     asm volatile("
  583.     movb %2,%%dl
  584.     movb %3,%%ah
  585.     int $0x21
  586.     movsbl %%al,%0
  587.     movl %%ebx,%1"
  588.     : "=r"(result), "=r"(parameter_block)
  589.     : "g"((unsigned char) drive), "i"(0x32)
  590.     : "ax", "bx", "cx");
  591.  
  592.     if (result) return  0;
  593.  
  594.     return  parameter_block;
  595. }
  596.  
  597. static __inline__ int
  598. _dos_get_extended_control_break_checking()
  599. {
  600.     int flag;
  601.  
  602.     asm volatile("
  603.     movw %1,%%ax
  604.     int $0x21
  605.     movzbl %%dl,%0"
  606.     : "=r"(flag)
  607.     : "i"(0x3300)
  608.     : "ax", "dx");
  609.  
  610.     return flag;
  611. }
  612.  
  613. static __inline__ void
  614. _dos_set_extended_control_break_checking(int flag)
  615. {
  616.     asm volatile("
  617.     movb %0,%%dl
  618.     movw %1,%%ax
  619.     int $0x21"
  620.     : /* no output */
  621.     : "g"((unsigned char) flag), "i"(0x3301)
  622.     : "ax", "dx");
  623. }
  624.  
  625. static __inline__ struct _disk_space
  626. _dos_get_disk_space(int drive)
  627. {
  628.     struct _disk_space info;
  629.  
  630.     asm volatile("
  631.     movb %4,%%dl
  632.     movb %5,%%ah
  633.     int $0x21
  634.     movzwl %%ax,%0
  635.     movzwl %%bx,%1
  636.     movzwl %%cx,%2
  637.     movzwl %%dx,%3"
  638.     : "=r"(info.nsectors), "=r"(info.free_clusters),
  639.       "=r"(info.nbytes),   "=r"(info.nclusters)
  640.     : "g"((unsigned char) drive), "i"(0x36)
  641.     : "ax","bx","cx","dx");
  642.  
  643.     return info;
  644. }
  645.  
  646. static __inline__ int
  647. _dos_get_switch()
  648. {
  649.     int  flag;
  650.     int  result;
  651.  
  652.     asm volatile("
  653.     movw %2,%%ax
  654.     int $0x21
  655.     movzbl %%dl,%0
  656.     movzbl %%al,%1"
  657.     : "=r"(flag), "=r"(result)
  658.     : "i"(0x3700)
  659.     : "ax", "dx");
  660.  
  661.     if (result) return -1;
  662.  
  663.     return flag;
  664. }
  665.  
  666. static __inline__ int
  667. _dos_set_switch(int flag)
  668. {
  669.     int  result;
  670.  
  671.     asm volatile("
  672.     movb %1,%%dl
  673.     movw %2,%%ax
  674.     int $0x21
  675.     movsbl %%al,%0"
  676.     : "=r"(result)
  677.     : "g"((unsigned char) flag), "i"(0x3701)
  678.     : "ax", "dx");
  679.  
  680.     return result;
  681. }
  682.  
  683. static __inline__ int
  684. _dos_get_country_dependent_infomation(int country, char *buffer)
  685. {
  686.     int  result;
  687.     int  _al, _bx;
  688.  
  689.     if (country < 255) {
  690.         _al = country;
  691.         _bx = 0;
  692.     } else {
  693.         _al = 0xff;
  694.         _bx = country;
  695.     }
  696.     asm volatile("
  697.     movl %2,%%edx
  698.     movw %3,%%bx
  699.     movb %4,%%al
  700.     movb %5,%%ah
  701.     int $0x21
  702.     jnc 0f
  703.     movzwl %%ax,%0
  704.     movl $-1,%1
  705.     jmp 1f
  706. 0:
  707.     movl $0,%1
  708. 1:"
  709.     : "=r"(_dos_errno), "=r"(result)
  710.     : "g"(buffer),
  711.       "g"((unsigned short) _bx),
  712.       "g"((unsigned char) _al),
  713.       "i"(0x38)
  714.     : "ax", "bx", "dx");
  715.  
  716.     return  result;
  717. }
  718.  
  719. static __inline__ int
  720. _dos_set_country_dependent_infomation(int country)
  721. {
  722.     int  result;
  723.     int  _al, _bx;
  724.  
  725.     if (country < 255) {
  726.         _al = country;
  727.         _bx = 0;
  728.     } else {
  729.         _al = 0xff;
  730.         _bx = country;
  731.     }
  732.     asm volatile("
  733.     movl %2,%%edx
  734.     movw %3,%%bx
  735.     movb %4,%%al
  736.     movb %5,%%ah
  737.     int $0x21
  738.     jnc 0f
  739.     movzwl %%ax,%0
  740.     movl $-1,%1
  741.     jmp 1f
  742. 0:
  743.     movl $0,%1
  744. 1:"
  745.     : "=r"(_dos_errno), "=r"(result)
  746.     : "i"(0xffffffff),
  747.       "g"((unsigned short) _bx),
  748.       "g"((unsigned char) _al),
  749.       "i"(0x38)
  750.     : "ax", "bx", "dx");
  751.  
  752.     return  result;
  753. }
  754.  
  755. static __inline__ int
  756. _dos_mkdir(char *path)
  757. {
  758.     int  result;
  759.  
  760.     asm volatile("
  761.     movl %2,%%edx
  762.     movb %3,%%ah
  763.     int $0x21
  764.     jnc 0f
  765.     movzwl %%ax,%0
  766.     movl $-1,%1
  767.     jmp 1f
  768. 0:
  769.     movl $0,%1
  770. 1:"
  771.     : "=r"(_dos_errno), "=r"(result)
  772.     : "g"(path), "i"(0x39)
  773.     : "ax", "dx");
  774.  
  775.     return  result;
  776. }
  777.  
  778. static __inline__ int
  779. _dos_rmdir(char *path)
  780. {
  781.     register int  result;
  782.  
  783.     asm volatile("
  784.     movl %2,%%edx
  785.     movb %3,%%ah
  786.     int $0x21
  787.     jnc 0f
  788.     movzwl %%ax,%0
  789.     movl $-1,%1
  790.     jmp 1f
  791. 0:
  792.     movl $0,%1
  793. 1:"
  794.     : "=r"(_dos_errno), "=r"(result)
  795.     : "g"(path), "i"(0x3a)
  796.     : "ax", "dx");
  797.  
  798.     return  result;
  799. }
  800.  
  801. static __inline__ int
  802. _dos_chdir(char *path)
  803. {
  804.     int  result;
  805.  
  806.     asm volatile("
  807.     movl %2,%%edx
  808.     movb %3,%%ah
  809.     int $0x21
  810.     jnc 0f
  811.     movzwl %%ax,%0
  812.     movl $-1,%1
  813.     jmp 1f
  814. 0:
  815.     movl $0,%1
  816. 1:"
  817.     : "=r"(_dos_errno), "=r"(result)
  818.     : "g"(path), "i"(0x3b)
  819.     : "ax", "dx");
  820.  
  821.     return  result;
  822. }
  823.  
  824. static __inline__ int
  825. _dos_creat(char *path, int attributes)
  826. {
  827.     int result;
  828.  
  829.     asm volatile("
  830.     movw %2,%%cx
  831.     movl %3,%%edx
  832.     movb %4,%%ah
  833.     int $0x21
  834.     jnc 0f
  835.     movzwl %%ax,%0
  836.     movl $-1,%1
  837.     jmp 1f
  838. 0:
  839.     movzwl %%ax,%1
  840. 1:"
  841.     : "=r"(_dos_errno), "=r"(result)
  842.     : "g"((unsigned short) attributes), "g"(path), "i"(0x3c)
  843.     : "ax", "cx", "dx");
  844.  
  845.     return  result;
  846. }
  847.  
  848. static __inline__ int
  849. _dos_open(char *path, int attributes)
  850. {
  851.     int  result;
  852.  
  853.     asm volatile("
  854.     movl %2,%%edx
  855.     movb %3,%%al
  856.     movb %4,%%ah
  857.     int $0x21
  858.     jnc 0f
  859.     movzwl %%ax,%0
  860.     movl $-1,%1
  861.     jmp 1f
  862. 0:
  863.     movzwl %%ax,%1
  864. 1:"
  865.     : "=r"(_dos_errno), "=r"(result)
  866.     : "g"(path), "g"((unsigned char) attributes), "i"(0x3d)
  867.     : "ax", "dx");
  868.  
  869.     return  result;
  870. }
  871.  
  872. static __inline__ int
  873. _dos_close(int handle)
  874. {
  875.     register int  result;
  876.  
  877.     asm volatile("
  878.     movw %2,%%bx
  879.     movb %3,%%ah
  880.     int $0x21
  881.     jnc 0f
  882.     movzwl %%ax,%0
  883.     movl $-1,%1
  884.     jmp 1f
  885. 0:
  886.     movl $0,%1
  887. 1:"
  888.     : "=r"(_dos_errno), "=r"(result)
  889.     : "g"((unsigned short) handle), "i"(0x3e)
  890.     : "ax", "bx");
  891.  
  892.     return  result;
  893. }
  894.  
  895. static __inline__ int
  896. _dos_read(int handle, char *buffer, int nbytes)
  897. {
  898.     int  result;
  899.  
  900.     asm volatile("
  901.     movw %2,%%bx
  902.     movl %3,%%ecx
  903.     movl %4,%%edx
  904.     movb %5,%%ah
  905.     int $0x21
  906.     jnc 0f
  907.     movzwl %%ax,%0
  908.     movl $-1,%1
  909.     jmp 1f
  910. 0:
  911.     movl %%eax,%1
  912. 1:"
  913.     : "=r"(_dos_errno), "=r"(result)
  914.     : "g"((unsigned short) handle), "g"(nbytes), "g"(buffer), "i"(0x3f)
  915.     : "ax", "bx", "cx", "dx");
  916.  
  917.     return  result;
  918. }
  919.  
  920. static __inline__ int
  921. _dos_write(int handle, const char *buffer, int nbytes)
  922. {
  923.     register int  result;
  924.  
  925.     asm volatile("
  926.     movw %2,%%bx
  927.     movl %3,%%ecx
  928.     movl %4,%%edx
  929.     movb %5,%%ah
  930.     int $0x21
  931.     jnc 0f
  932.     movzwl %%ax,%0
  933.     movl $-1,%1
  934.     jmp 1f
  935. 0:
  936.     movl %%eax,%1
  937. 1:"
  938.     : "=r"(_dos_errno), "=r"(result)
  939.     : "g"((unsigned short) handle), "g"(nbytes), "g"(buffer), "i"(0x40)
  940.     : "ax", "bx", "cx", "dx");
  941.  
  942.     return  result;
  943. }
  944.  
  945. static __inline__ int
  946. _dos_unlink(char *path)
  947. {
  948.     int  result;
  949.  
  950.     asm volatile("
  951.     movl %2,%%edx
  952.     movb %3,%%ah
  953.     int $0x21
  954.     jnc 0f
  955.     movzwl %%ax,%0
  956.     movl $-1,%1
  957.     jmp 1f
  958. 0:
  959.     movl $0,%1
  960. 1:"
  961.     : "=r"(_dos_errno), "=r"(result)
  962.     : "g"(path), "i"(0x41)
  963.     : "ax", "dx");
  964.  
  965.     return  result;
  966. }
  967.  
  968. static __inline__ long
  969. _dos_lseek(int fd, long offset, int whence)
  970. {
  971.     long position;
  972.     int  high = ((unsigned long) offset) >> 16;
  973.     int  low  = ((unsigned long) offset) & 0xffff;
  974.  
  975.     asm volatile("
  976.     movw %2,%%bx
  977.     movw %3,%%cx
  978.     movw %4,%%dx
  979.     movb %5,%%al
  980.     movb %6,%%ah
  981.     int $0x21
  982.     jnc 0f
  983.     movzwl %%ax,%0
  984.     movl $-1,%1
  985.     jmp 1f
  986. 0:
  987.     movzwl %%ax,%1
  988.     shll $16,%%edx
  989.     addl %%edx,%1
  990. 1:"
  991.     : "=r"(_dos_errno), "=r"(position)
  992.     : "g"((unsigned short) fd),
  993.       "g"((unsigned short) high),
  994.       "g"((unsigned short) low),
  995.       "g"((unsigned char) whence),
  996.       "i"(0x42)
  997.     : "ax", "bx", "cx", "dx");
  998.  
  999.     return position;
  1000. }
  1001.  
  1002. static __inline__ int
  1003. _dos_get_file_attributes(char *path)
  1004. {
  1005.     int result;
  1006.  
  1007.     asm volatile("
  1008.     movl %2,%%edx
  1009.     movw %3,%%ax
  1010.     int $0x21
  1011.     jnc 0f
  1012.     movzwl %%ax,%0
  1013.     movl $-1,%1
  1014.     jmp 1f
  1015. 0:
  1016.     movzwl %%ax,%1
  1017. 1:"
  1018.     : "=r"(_dos_errno), "=r"(result)
  1019.     : "g"(path), "i"(0x4300)
  1020.     : "ax", "cx", "dx");
  1021.  
  1022.     return  result;
  1023. }
  1024.  
  1025. static __inline__ int
  1026. _dos_set_file_attributes(char *path, int attributes)
  1027. {
  1028.     int  result;
  1029.  
  1030.     asm volatile("
  1031.     movl %2,%%edx
  1032.     movw %3,%%cx
  1033.     movw %4,%%ax
  1034.     int $0x21
  1035.     jnc 0f
  1036.     movzwl %%ax,%0
  1037.     movl $-1,%1
  1038.     jmp 1f
  1039. 0:
  1040.     movl $0,%1
  1041. 1:"
  1042.     : "=r"(_dos_errno), "=r"(result)
  1043.     : "g"(path), "g"((unsigned short) attributes), "i"(0x4301)
  1044.     : "ax", "cx", "dx");
  1045.  
  1046.     return  result;
  1047. }
  1048.  
  1049. static __inline__ int
  1050. _dos_get_device_infomation(int handle)
  1051. {
  1052.     int  result;
  1053.  
  1054.     asm volatile("
  1055.     movw %2,%%bx
  1056.     movw %3,%%ax
  1057.     int $0x21
  1058.     jnc 0f
  1059.     movzwl %%ax,%0
  1060.     movl $-1,%1
  1061.     jmp 1f
  1062. 0:
  1063.     movl %%edx,%1
  1064. 1:"
  1065.     : "=r"(_dos_errno), "=r"(result)
  1066.     : "g"((unsigned short) handle), "i"(0x4400)
  1067.     : "ax", "bx", "dx");
  1068.  
  1069.     return  result;
  1070. }
  1071.  
  1072. static __inline__ int
  1073. _dos_set_device_infomation(int handle, int info)
  1074. {
  1075.     int  result;
  1076.  
  1077.     asm volatile("
  1078.     movw %2,%%bx
  1079.     movw %3,%%dx
  1080.     movw %4,%%ax
  1081.     int $0x21
  1082.     jnc 0f
  1083.     movzwl %%ax,%0
  1084.     movl   $-1,%1
  1085.     jmp 1f
  1086. 0:
  1087.     movzwl %%ax,%1
  1088. 1:"
  1089.     : "=r"(_dos_errno), "=r"(result)
  1090.     : "g"((unsigned short) handle), "g"((unsigned short) info), "i"(0x4401)
  1091.     : "ax", "bx", "dx");
  1092.  
  1093.     return  result;
  1094. }
  1095.  
  1096. static __inline__ int
  1097. _dos_read_character_device_control_string(int handle, char *buffer, int nbytes)
  1098. {
  1099.     int  result;
  1100.  
  1101.     asm volatile("
  1102.     movw %2,%%bx
  1103.     movw %3,%%cx
  1104.     movl %4,%%edx
  1105.     movw %5,%%ax
  1106.     int $0x21
  1107.     jnc 0f
  1108.     movzwl %%ax,%0
  1109.     movl $-1,%1
  1110.     jmp 1f
  1111. 0:
  1112.     movzwl %%ax,%1
  1113. 1:"
  1114.     : "=r"(_dos_errno), "=r"(result)
  1115.     : "g"((unsigned short) handle), "g"((unsigned short) nbytes),
  1116.       "g"(buffer), "i"(0x4402)
  1117.     : "ax", "bx", "cx", "dx");
  1118.  
  1119.     return  result;
  1120. }
  1121.  
  1122. static __inline__ int
  1123. _dos_write_character_device_control_string(int handle, char *buffer, int nbytes)
  1124. {
  1125.     int result;
  1126.  
  1127.     asm volatile("
  1128.     movw %2,%%bx
  1129.     movw %3,%%cx
  1130.     movl %4,%%edx
  1131.     movw %5,%%ax
  1132.     int $0x21
  1133.     jnc 0f
  1134.     movzwl %%ax,%0
  1135.     movl $-1,%1
  1136.     jmp 1f
  1137. 0:
  1138.     movzwl %%ax,%1
  1139. 1:"
  1140.     : "=r"(_dos_errno), "=r"(result)
  1141.     : "g"((unsigned short) handle), "g"((unsigned short) nbytes),
  1142.       "g"(buffer), "i"(0x4403)
  1143.     : "ax", "bx", "cx", "dx");
  1144.  
  1145.     return  result;
  1146. }
  1147.  
  1148. static __inline__ int
  1149. _dos_read_block_device_control_string(int device, char *buffer, int nbytes)
  1150. {
  1151.     int  result;
  1152.  
  1153.     asm volatile("
  1154.     movb %2,%%bl
  1155.     movw %3,%%cx
  1156.     movl %4,%%edx
  1157.     movw %5,%%ax
  1158.     int $0x21
  1159.     jnc 0f
  1160.     movzwl %%ax,%0
  1161.     movl $-1,%1
  1162.     jmp 1f
  1163. 0:
  1164.     movzwl %%ax,%1
  1165. 1:"
  1166.     : "=r"(_dos_errno), "=r"(result)
  1167.     : "g"((unsigned char) device), "g"((unsigned short) nbytes),
  1168.       "g"(buffer), "i"(0x4404)
  1169.     : "ax", "bx", "cx", "dx");
  1170.  
  1171.     return  result;
  1172. }
  1173.  
  1174. static __inline__ int
  1175. _dos_write_block_device_control_string(int device, char *buffer, int nbytes)
  1176. {
  1177.     int  result;
  1178.  
  1179.     asm volatile("
  1180.     movb %2,%%bl
  1181.     movw %3,%%cx
  1182.     movl %4,%%edx
  1183.     movw %5,%%ax
  1184.     int $0x21
  1185.     jnc 0f
  1186.     movzwl %%ax,%0
  1187.     movl $-1,%1
  1188.     jmp 1f
  1189. 0:
  1190.     movzwl %%ax,%1
  1191. 1:"
  1192.     : "=r"(_dos_errno), "=r"(result)
  1193.     : "g"((unsigned char) device), "g"((unsigned short) nbytes),
  1194.       "g"(buffer), "i"(0x4405)
  1195.     : "ax", "bx", "cx", "dx");
  1196.  
  1197.     return  result;
  1198. }
  1199.  
  1200. static __inline__ int
  1201. _dos_get_input_status(int handle)
  1202. {
  1203.     int  result;
  1204.  
  1205.     asm volatile("
  1206.     movw %1,%%bx
  1207.     movw %2,%%ax
  1208.     int $0x21
  1209.     movzbl %%al,%0"
  1210.     : "=r"(result)
  1211.     : "g"((unsigned short) handle), "i"(0x4406)
  1212.     : "ax", "bx");
  1213.  
  1214.     return result;
  1215. }
  1216.  
  1217. static __inline__ int
  1218. _dos_get_output_status(int handle)
  1219. {
  1220.     int  result;
  1221.  
  1222.     asm volatile("
  1223.     movw %1,%%bx
  1224.     movw %2,%%ax
  1225.     int $0x21
  1226.     movzbl %%al,%0"
  1227.     : "=r"(result)
  1228.     : "g"((unsigned short) handle), "i"(0x4407)
  1229.     : "ax", "bx");
  1230.  
  1231.     return result;
  1232. }
  1233.  
  1234. static __inline__ int
  1235. _dos_block_device_changeable(char drive)
  1236. {
  1237.     int  result;
  1238.  
  1239.     asm volatile("
  1240.     movb %1,%%bl
  1241.     movw %2,%%ax
  1242.     int $0x21
  1243.     movzwl %%ax,%0"
  1244.     : "=r"(result)
  1245.     : "g"((unsigned char) drive), "i"(0x4408)
  1246.     : "ax", "bx");
  1247.  
  1248.     return result;
  1249. }
  1250.  
  1251. static __inline__ int
  1252. _dos_block_device_local(int drive)
  1253. {
  1254.     int  result;
  1255.  
  1256.     asm volatile("
  1257.     movb %1,%%bl
  1258.     movw %2,%%ax
  1259.     int $0x21
  1260.     movzwl %%dx,%0"
  1261.     : "=r"(result)
  1262.     : "g"((unsigned char) drive), "i"(0x4409)
  1263.     : "ax", "bx");
  1264.  
  1265.     return result;
  1266. }
  1267.  
  1268. static __inline__ int
  1269. _dos_handle_local(int handle)
  1270. {
  1271.     int  result;
  1272.  
  1273.     asm volatile("
  1274.     movw %1,%%bx
  1275.     movw %2,%%ax
  1276.     int $0x21
  1277.     movzwl %%dx,%0"
  1278.     : "=r"(result)
  1279.     : "g"((unsigned short) handle), "i"(0x440a)
  1280.     : "ax", "bx", "dx");
  1281.  
  1282.     return result;
  1283. }
  1284.  
  1285. static __inline__ int
  1286. _dos_sharing_entry_count(int handle, int delay, int retry)
  1287. {
  1288.     int  result;
  1289.  
  1290.     asm volatile("
  1291.     movw %2,%%bx
  1292.     movw %3,%%cx
  1293.     movw %4,%%dx
  1294.     movw %5,%%ax
  1295.     int $0x21
  1296.     jnc 0f
  1297.     movzwl %%ax,%0
  1298.     movl $-1,%1
  1299.     jmp 1f
  1300. 0:
  1301.     movl $0,%1
  1302. 1:"
  1303.     : "=r"(_dos_errno), "=r"(result)
  1304.     : "g"((unsigned short) handle), "g"((unsigned short) delay),
  1305.       "g"((unsigned short) retry), "i"(0x440b)
  1306.     : "ax", "bx", "cx", "dx");
  1307.  
  1308.     return result;
  1309. }
  1310.  
  1311. static __inline__ int
  1312. _dos_dup(int handle)
  1313. {
  1314.     int  result;
  1315.  
  1316.     asm volatile("
  1317.     movw %2,%%bx
  1318.     movb %3,%%ah
  1319.     int $0x21
  1320.     jnc 0f
  1321.     movzwl %%ax,%0
  1322.     movl $-1,%1
  1323.     jmp 1f
  1324. 0:
  1325.     movzwl %%ax,%1
  1326. 1:"
  1327.     : "=r"(_dos_errno), "=r"(result)
  1328.     : "g"((unsigned short) handle), "i"(0x45)
  1329.     : "ax","bx");
  1330.  
  1331.     return result;
  1332. }
  1333.  
  1334. static __inline__ int
  1335. _dos_dup2(int oldhandle, int newhandle)
  1336. {
  1337.     int  result;
  1338.  
  1339.     asm volatile("
  1340.     movw %2,%%bx
  1341.     movw %3,%%cx
  1342.     movw %4,%%ax
  1343.     int $0x21
  1344.     jnc 0f
  1345.     movzwl %%ax,%0
  1346.     movl $-1,%1
  1347.     jmp 1f
  1348. 0:
  1349.     movl $0,%0
  1350. 1:"
  1351.     : "=r"(_dos_errno), "=r"(result)
  1352.     : "g"((unsigned short) oldhandle), "g"((unsigned short) newhandle),
  1353.       "i"(0x46)
  1354.     : "ax", "bx", "cx");
  1355.  
  1356.     return result;
  1357. }
  1358.  
  1359. static __inline__ int
  1360. _dos_get_current_directory(int drive, char *buffer)
  1361. {
  1362.     int  result;
  1363.  
  1364.     asm volatile("
  1365.     movb %2,%%dl
  1366.     movl %3,%%esi
  1367.     movb %4,%%ah
  1368.     int $0x21
  1369.     jnc 0f
  1370.     movzwl %%ax,%0
  1371.     movl $-1,%1
  1372.     jmp 1f
  1373. 0:
  1374.     movl $0,%1
  1375. 1:"
  1376.     : "=r"(_dos_errno), "=r"(result)
  1377.     : "g"((unsigned char) drive), "g"(buffer), "i"(0x47)
  1378.     : "ax", "dx", "si");
  1379.  
  1380.     return result;
  1381. }
  1382.  
  1383. static __inline__ int
  1384. _dos_allocate_memory(int npages)
  1385. {
  1386.     int  result;
  1387.  
  1388.     asm volatile("
  1389.     movl %2,%%ebx
  1390.     movb %3,%%ah
  1391.     int $0x21
  1392.     jnc 0f
  1393.     movzwl %%ax,%0
  1394.     movl $-1,%1
  1395.     jmp 1f
  1396. 0:
  1397.     movzwl %%ax,%1
  1398. 1:"
  1399.     : "=r"(_dos_errno), "=r"(result)
  1400.     : "g"(npages), "i"(0x48)
  1401.     : "ax", "bx");
  1402.  
  1403.     return result;
  1404. }
  1405.  
  1406. static __inline__ int
  1407. _dos_free_memory(int segment)
  1408. {
  1409.     int  result;
  1410.  
  1411.     asm volatile("
  1412.     pushl %%es
  1413.     pushl %2
  1414.     popl %%es
  1415.     movb %3,%%ah
  1416.     int $0x21
  1417.     jnc 0f
  1418.     movzwl %%ax,%0
  1419.     movl $-1,%1
  1420.     jmp 1f
  1421. 0:
  1422.     movl $0,%1
  1423. 1:
  1424.     popl %%es"
  1425.     : "=r"(_dos_errno), "=r"(result)
  1426.     : "g"(segment), "i"(0x49)
  1427.     : "ax");
  1428.  
  1429.     return result;
  1430. }
  1431.  
  1432. static __inline__ int
  1433. _dos_adjust_memory_block_size(int segment, int npages)
  1434. {
  1435.     int  result;
  1436.  
  1437.     asm volatile("
  1438.     pushl %%es
  1439.     pushl %2
  1440.     popl %%es
  1441.     movl %3,%%ebx
  1442.     movb %4,%%ah
  1443.     int $0x21
  1444.     jnc 0f
  1445.     movzwl %%ax,%0
  1446.     movl %%ebx,%1
  1447.     jmp 1f
  1448. 0:
  1449.     movl $0,%1
  1450. 1:
  1451.     popl %%es"
  1452.     : "=r"(_dos_errno), "=r"(result)
  1453.     : "g"(segment), "g"(npages), "i"(0x4a)
  1454.     : "ax", "bx");
  1455.  
  1456.     return result;
  1457. }
  1458.  
  1459. static __inline__ int
  1460. _dos_exec(char *parameter, char *program)
  1461. {
  1462.     int  result;
  1463.  
  1464.     asm volatile("
  1465.     movl %2,%%ebx
  1466.     movl %3,%%edx
  1467.     movw %4,%%ax
  1468.     int $0x21
  1469.     jnc 0f
  1470.     movzwl %%ax,%0
  1471.     movl $-1,%1
  1472.     jmp 1f
  1473. 0:
  1474.     movl $0,%1
  1475. 1:"
  1476.     : "=r"(_dos_errno), "=r"(result)
  1477.     : "g"(parameter), "g"(program), "i"(0x4b00)
  1478.     : "ax");
  1479.  
  1480.     return result;
  1481. }
  1482.  
  1483. static __inline__ void
  1484. _dos_exit(int status)
  1485. {
  1486.     asm volatile("
  1487.     movb %0,%%al
  1488.     movb %1,%%ah
  1489.     int $0x21"
  1490.     : /* no output */
  1491.     : "g"((unsigned char) status), "i"(0x4c)
  1492.     : "ax");
  1493. }
  1494.  
  1495. static __inline__ int
  1496. _dos_wait()
  1497. {
  1498.     int  result;
  1499.     asm volatile("
  1500.     movb %1,%%ah
  1501.     int $0x21
  1502.     movzwl %%ax,%0"
  1503.     : "=r"(result)
  1504.     : "i"(0x4d)
  1505.     : "ax");
  1506.  
  1507.     return result;
  1508. }
  1509.  
  1510. static __inline__ int
  1511. _dos_find_dirst(char *path, int attributes)
  1512. {
  1513.     int  result;
  1514.  
  1515.     asm volatile("
  1516.     movl %2,%%edx
  1517.     movw %3,%%cx
  1518.     movb %4,%%ah
  1519.     int $0x21
  1520.     jnc 0f
  1521.     movzwl %%ax,%0
  1522.     movl $-1,%1
  1523.     jmp 1f
  1524. 0:
  1525.     movl $0,%1
  1526. 1:"
  1527.     : "=r"(_dos_errno), "=r"(result)
  1528.     : "g"(path), "g"((unsigned short) attributes), "i"(0x4e)
  1529.     : "ax", "cx", "dx");
  1530.  
  1531.     return result;
  1532. }
  1533.  
  1534. static __inline__ int
  1535. _dos_find_next()
  1536. {
  1537.     int  result;
  1538.  
  1539.     asm volatile("
  1540.     movb %2,%%ah
  1541.     int $0x21
  1542.     jnc j0f
  1543.     movzwl %%ax,%0
  1544.     movl $-1,%1
  1545.     jmp 1f
  1546. 0:
  1547.     movl $0,%1
  1548. 1:"
  1549.     : "=r"(_dos_errno), "=r"(result)
  1550.     : "i"(0x4f)
  1551.     : "ax");
  1552.  
  1553.     return result;
  1554. }
  1555.  
  1556. static __inline__ int
  1557. _dos_get_verify_flag()
  1558. {
  1559.     int  flag;
  1560.  
  1561.     asm volatile("
  1562.     movb %1,%%ah
  1563.     int $0x21
  1564.     movzbl %%al,%0"
  1565.     : "=r"(flag)
  1566.     : "i"(0x54)
  1567.     : "ax");
  1568.  
  1569.     return flag;
  1570. }
  1571.  
  1572. static __inline__ int
  1573. _dos_rename(char *oldname, char *newname)
  1574. {
  1575.     int  result;
  1576.  
  1577.     asm volatile("
  1578.     movl %2,%%edx
  1579.     movl %3,%%edi
  1580.     movb %4,%%ah
  1581.     int $0x21
  1582.     jnc 0f
  1583.     movzwl %%ax,%0
  1584.     movl $-1,%1
  1585.     jmp 1f
  1586. 0:
  1587.     movl $0,%1
  1588. 1:"
  1589.     : "=r"(_dos_errno), "=r"(result)
  1590.     : "g"(oldname), "g"(newname), "i"(0x56)
  1591.     : "ax", "dx", "di");
  1592.  
  1593.     return result;
  1594. }
  1595.  
  1596. static __inline__ struct _file_date_time
  1597. _dos_get_file_date_time(int handle)
  1598. {
  1599.     int  result;
  1600.  
  1601.     union {
  1602.         struct _file_date_time  time;
  1603.         unsigned long int       longword;
  1604.     } result1;
  1605.  
  1606.     asm volatile("
  1607.     movw %2,%%bx
  1608.     movw %3,%%ax
  1609.     int $0x21
  1610.     jnc 0f
  1611.     movzwl %%ax,%0
  1612.     movl $-1,%1
  1613.     jmp 1f
  1614. 0:
  1615.     movzwl %%cx,%1
  1616.     shll $16,%%edx
  1617.     addl %%edx,%1
  1618. 1:"
  1619.     : "=r"(_dos_errno), "=r"(result)
  1620.     : "g"((unsigned short) handle), "i"(0x5700)
  1621.     : "ax", "bx", "cx", "dx");
  1622.  
  1623.     result1.longword = result;
  1624.  
  1625.     return result1.time;
  1626. }
  1627.  
  1628. static __inline__ int
  1629. _dos_set_file_date_time(int handle, struct _file_date_time datetime)
  1630. {
  1631.     int result;
  1632.     int time;
  1633.     int date;
  1634.     union {
  1635.         struct _file_date_time  time;
  1636.         unsigned long int       longword;
  1637.     } datetime1;
  1638.  
  1639.     datetime1.time = datetime;
  1640.     time = ((unsigned int) datetime1.longword >> 16) & 0xffff;
  1641.     date = ((unsigned int) datetime1.longword)       & 0xffff;
  1642.  
  1643.     asm volatile("
  1644.     movw %2,%%bx
  1645.     movw %3,%%cx
  1646.     movw %4,%%dx
  1647.     movw %5,%%ax
  1648.     int $0x21
  1649.     jnc 0f
  1650.     movzwl %%ax,%0
  1651.     movl $-1,%1
  1652.     jmp 1f
  1653. 0:
  1654.     movl $0,%1
  1655. 1:"
  1656.     : "=r"(_dos_errno), "=r"(result)
  1657.     : "g"((unsigned short) handle),
  1658.       "g"((unsigned short) time),  "g"((unsigned short) date),
  1659.       "i"(0x5701)
  1660.     : "ax", "bx", "cx", "dx");
  1661.  
  1662.     return result;
  1663. }
  1664.  
  1665. static __inline__ int
  1666. _dos_get_memory_allocation_strategy()
  1667. {
  1668.     int result;
  1669.  
  1670.     asm volatile("
  1671.     movw %2,%%ax
  1672.     int $0x21
  1673.     jnc 0f
  1674.     movzwl %%ax,%0
  1675.     movl $-1,%1
  1676.     jmp 1f
  1677. 0:
  1678.     movzwl %%ax,%1
  1679. 1:"
  1680.     : "=r"(_dos_errno), "=r"(result)
  1681.     : "i"(0x5800)
  1682.     : "ax");
  1683.  
  1684.     return result;
  1685. }
  1686.  
  1687. static __inline__ int
  1688. _dos_set_memory_allocation_strategy(int strategy)
  1689. {
  1690.     int  result;
  1691.  
  1692.     asm volatile("
  1693.     movw %2,%%bx
  1694.     movw %3,%%ax
  1695.     int $0x21
  1696.     jnc 0f
  1697.     movzwl %%ax,%0
  1698.     movl $-1,%1
  1699.     jmp 1f
  1700. 0:
  1701.     movl $0,%1
  1702. 1:"
  1703.     : "=r"(_dos_errno), "=r"(result)
  1704.     : "g"((unsigned short) strategy), "i"(0x5801)
  1705.     : "ax", "bx");
  1706.  
  1707.     return result;
  1708. }
  1709.  
  1710. static __inline__ void
  1711. _dos_get_extended_error_code()
  1712. {
  1713.     asm volatile("
  1714.     movw $0,%%bx
  1715.     movb %4,%%ah
  1716.     int $0x21
  1717.     movzwl %%ax,%0
  1718.     movzbl %%bh,%1
  1719.     movzbl %%bl,%2
  1720.     movzbl %%ch,%3"
  1721.     : "=r"(_dos_errno),      "=r"(_dos_errclass),
  1722.       "=r"(_dos_errsugested), "=r"(_dos_errlocus)
  1723.     : "i"(0x59)
  1724.     : "ax","bx","cx","dx","si","di","bp");
  1725. }
  1726.  
  1727. static __inline__ int
  1728. _dos_creat_uniq_file(char *path, int attributes)
  1729. {
  1730.     int result;
  1731.  
  1732.     asm volatile("
  1733.     movl %2,%%edx
  1734.     movw %3,%%cx
  1735.     movb %4,%%ah
  1736.     int $0x21
  1737.     jnc 0f
  1738.     movzwl %%ax,%0
  1739.     movl $-1,%1
  1740.     jmp 1f
  1741. 0:
  1742.     movzwl %%ax,%1
  1743. 1:"
  1744.     : "=r"(_dos_errno), "=r"(result)
  1745.     : "g" (path), "g"((unsigned short) attributes), "i"(0x5a)
  1746.     : "ax", "cx", "dx");
  1747.  
  1748.     return result;
  1749. }
  1750.  
  1751. static __inline__ int
  1752. _dos_creat_new_file(char *path, int attributes)
  1753. {
  1754.     int result;
  1755.  
  1756.     asm volatile("
  1757.     movl %2,%%edx
  1758.     movw %3,%%cx
  1759.     movb %4,%%ah
  1760.     int $0x21
  1761.     jnc 0f
  1762.     movzwl %%ax,%0
  1763.     movl $-1,%1
  1764.     jmp 1f
  1765. 0:
  1766.     movzwl %%ax,%1
  1767. 1:"
  1768.     : "=r"(_dos_errno), "=r"(result)
  1769.     : "g"(path), "g"((unsigned short) attributes), "i"(0x5b)
  1770.     : "ax", "cx", "dx");
  1771.  
  1772.     return result;
  1773. }
  1774.  
  1775. /*
  1776. static __inline__ int _dos_lock_file(int handle, int offset, int size);
  1777. static __inline__ int _dos_unlock_file(int handle, int offset, int size);
  1778. */
  1779.  
  1780. static __inline__ int
  1781. _dos_get_psp_address()
  1782. {
  1783.     int  segment;
  1784.  
  1785.     asm volatile("
  1786.     movb %1,%%ah
  1787.     int $0x21
  1788.     movzwl %%bx,%0"
  1789.     : "=r"(segment)
  1790.     : "i"(0x62)
  1791.     : "ax", "bx");
  1792.  
  1793.     return segment;
  1794. }
  1795.  
  1796. #endif