Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .code16
- .global _start
- .equ STACK_SEGMENT, 0x7C00 # We set the stack right before the first sector
- .equ ORG_SEGMENT, 0x0
- .equ SAFE_ADDRESS, 0x7E00 # We'll move some code here, hopefully the BIOS won't touch it
- # as for 0x7C00
- .text
- _start:
- jmp $ORG_SEGMENT, $(asmain) # Getting CS:IP set up to 0x0000:0x7C00
- asmain:
- xor %ax, %ax
- mov %ax, %ds
- mov %ax, %es
- mov %ax, %ss
- mov $STACK_SEGMENT, %sp
- call setup_shelter
- push $SAFE_ADDRESS
- ret
- __unreachable__:
- push $0xB800
- pop %es
- xor %di, %di
- movw $0x0455, %es:(%di) # Put a red(0x4) 'U' (0x55)
- # We've ensured writing to the VGA display
- # address
- # isn't affected by the problem.
- __stop_u:
- cli
- hlt
- jmp __stop_u
- safe_code:
- # Basic code to show $msg using BIOS interrupts.
- # If int $0x10 is touching a fixed region, it should work.
- # Otherwise int $0x10 is buggy and corrupts regions depending on
- # where the code is (wtf) and it'll fail.
- cld
- lea msg, %si
- mov $0xE, %ah
- xor %bx, %bx
- .loop:
- lodsb
- test %al, %al
- jz .stop
- int $0x10
- jmp .loop
- .stop:
- cli
- hlt
- jmp .stop
- .equ SAFE_ADDRESS_SIZE, (. - safe_code)
- setup_shelter:
- # Copy %CX bytes from safe_code to 0x7E00
- mov $SAFE_ADDRESS_SIZE, %cx
- mov $SAFE_ADDRESS, %di
- lea safe_code, %si
- rep movsb
- ret
- msg:
- .asciz "I beat ya, next time mind your own business AMI BIOS!"
- .space 510 - (. - _start)
- .word 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment