sbrk16.asm 3.5 KB

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