sbrk16.asm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. ; Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details
  2. ;
  3. ; $Id$
  4. ; $Log$
  5. ; Revision 1.1 2000-07-13 06:30:40 michael
  6. ; + Initial import
  7. ;
  8. ; Revision 1.1 1998/12/21 13:07:03 peter
  9. ; * use -FE
  10. ;
  11. ; Revision 1.1.1.1 1998/03/25 11:18:42 root
  12. ; * Restored version
  13. ;
  14. ; Revision 1.2 1997/11/27 16:28:13 michael
  15. ; Change submitted by Pierre Muller.
  16. ;
  17. ; Revision 2.0 1994/03/14 00:47:04 dj
  18. ; initial version
  19. ;
  20. ;
  21. ;-----------------------------------------------------------------------------
  22. ; sbrk 16-bit helper
  23. ;
  24. ; Transferred to 16-bit code segement to run in protected mode.
  25. ; Will make DPMI segment altering requests and update selectors
  26. ; as needed. Image will always need to allocate an exact
  27. ; multiple of 16 bytes, load offset will always be zero.
  28. ; Number of bytes to copy will always be multiple of four.
  29. ;
  30. ; Application must set cs_selector, ds_selector, and local_ds
  31. ; appropriately. Application uses first word in image to find
  32. ; API entry point. Call with FAR call.
  33. ;
  34. ; Call with: BX:CX = new size
  35. ; SI:DI = old handle
  36. ; Returns: BX:CX = new base
  37. ; SI:DI = new handle
  38. ; all others trashed
  39. .type "bin"
  40. ;-----------------------------------------------------------------------------
  41. ; Start of API header
  42. offset_of_api: ; offset of API function entry point
  43. .dw sbrk_16_helper
  44. cs_selector: ; code selector to be updated
  45. .dw 0
  46. ds_selector: ; data selector to be updated
  47. .dw 0
  48. local_ds: ; selector mapped to same as local cs
  49. .dw 0
  50. bytes_to_allocate: ; number of bytes app allocates for this image
  51. .dw stack
  52. ;-----------------------------------------------------------------------------
  53. ; Start of local data
  54. save_ss:
  55. .dw 0
  56. save_esp:
  57. .dd 0
  58. save_ds:
  59. .dw 0
  60. ;-----------------------------------------------------------------------------
  61. ; Start of code
  62. sbrk_16_helper:
  63. mov ax, ds ; switch to local data segment
  64. mov ds, cs:[local_ds]
  65. mov [save_ds], ax
  66. mov [save_ss], ss ; switch to local stack
  67. mov [save_esp], esp
  68. mov ss, [local_ds]
  69. mov esp, stack
  70. mov ax, 0x0503 ; realloc memory
  71. int 0x31
  72. jc error_return ; bx:cx = base address
  73. mov dx, cx
  74. mov cx, bx ; cx:dx = base address
  75. mov bx, [cs_selector]
  76. mov ax, 0x0007
  77. int 0x31 ; set cs to new base
  78. mov bx, [ds_selector]
  79. mov ax, 0x0007
  80. int 0x31 ; set ds to new base
  81. push es ; reload es
  82. pop es
  83. push fs ; reload fs
  84. pop fs
  85. push gs ; reload gs
  86. pop gs
  87. mov bx, cx
  88. mov cx, dx ; bx:cx = base address
  89. error_return:
  90. mov ss, [save_ss] ; return to old stack
  91. mov esp, [save_esp]
  92. mov ds, [save_ds] ; return to old data segment
  93. .opsize ; 32-bit far return
  94. retf
  95. ;-----------------------------------------------------------------------------
  96. ; Start of stack
  97. .align 4 ; so that image size is longwords
  98. .bss
  99. .align 16 ; so that alloc size is paragraphs
  100. .db 512 .dup 0
  101. stack: