Guest User

Untitled

a guest
Nov 24th, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .code16
  2. .global _start
  3.  
  4. .equ STACK_SEGMENT, 0x7C00 # We set the stack right before the first sector
  5. .equ ORG_SEGMENT, 0x0
  6. .equ SAFE_ADDRESS, 0x7E00  # We'll move some code here, hopefully the BIOS won't touch it
  7.                # as for 0x7C00
  8.  
  9. .text
  10. _start:
  11.         jmp $ORG_SEGMENT, $(asmain) # Getting CS:IP set up to 0x0000:0x7C00
  12.  
  13. asmain:
  14.         xor %ax, %ax
  15.         mov %ax, %ds
  16.         mov %ax, %es
  17.         mov %ax, %ss
  18.         mov $STACK_SEGMENT, %sp
  19.  
  20.         call setup_shelter
  21.         push $SAFE_ADDRESS
  22.         ret
  23.  
  24. __unreachable__:
  25.         push $0xB800
  26.         pop %es
  27.         xor %di, %di
  28.         movw $0x0455, %es:(%di) # Put a red(0x4) 'U' (0x55)
  29.                     # We've ensured writing to the VGA display
  30.                     # address
  31.                     # isn't affected by the problem.
  32. __stop_u:
  33.         cli
  34.         hlt
  35.         jmp __stop_u
  36.  
  37.  
  38. safe_code:
  39.         # Basic code to show $msg using BIOS interrupts.
  40.         # If int $0x10 is touching a fixed region, it should work.
  41.                 # Otherwise int $0x10 is buggy and corrupts regions depending on
  42.                 # where the code is (wtf) and it'll fail.
  43.        
  44.         cld
  45.         lea msg, %si   
  46.         mov $0xE, %ah
  47.         xor %bx, %bx
  48.        
  49. .loop:
  50.         lodsb
  51.         test %al, %al
  52.         jz .stop
  53.         int $0x10
  54.         jmp .loop
  55.        
  56. .stop:
  57.         cli
  58.         hlt
  59.         jmp .stop
  60.  
  61. .equ SAFE_ADDRESS_SIZE, (. - safe_code)
  62.  
  63. setup_shelter:
  64.  
  65.         # Copy %CX bytes from safe_code to 0x7E00
  66.  
  67.         mov $SAFE_ADDRESS_SIZE, %cx
  68.         mov $SAFE_ADDRESS, %di
  69.         lea safe_code, %si
  70.  
  71.         rep movsb
  72.  
  73.         ret
  74.    
  75. msg:
  76.     .asciz "I beat ya, next time mind your own business AMI BIOS!"
  77.  
  78. .space 510 - (. - _start)
  79. .word 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment