sbrk16.asm 2.6 KB

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