-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba76b33
commit bc271a0
Showing
4 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
pack_chunk_header6: | ||
; pack_chunk_header6 [rax] [rdi] [rsi] | ||
; rax = flags | ||
; rdi = size | ||
; rsi = output buffer | ||
; returns into rax the size written | ||
; will be either 2 for non vital | ||
; or 3 for vital | ||
; | ||
; example: | ||
; | ||
; mov rax, 0 | ||
; set_rax_flag CHUNKFLAG_VITAL | ||
; mov rdi, 10 | ||
; mov rsi, my_chunk_buffer | ||
; call pack_chunk_header | ||
; | ||
push_registers_keep_rax | ||
|
||
; rcx will be used for tmp register holding the return value | ||
; in the end it will be written to rax | ||
; | ||
; return size for non vital chunks | ||
mov rcx, 2 | ||
|
||
; Chunk header (vital) 0.6 | ||
; +---------+---------+-----------------+--------+-----------------+ | ||
; | Flags | Size | Sequence number | Size | Sequence number | | ||
; | 2 bits | 6 bits | 4 bits | 4 bits | 8 bits | | ||
; +---------+---------+-----------------+--------+-----------------+ | ||
|
||
; first byte is 2 bit flags (we xor them in) | ||
; and the remaining 6 bit are the first part of size | ||
mov r8, rdi | ||
shr r8, 6 | ||
and r8b, 0b00111111 | ||
mov byte [rsi], r8b | ||
xor byte [rsi], al | ||
|
||
; second byte is only the size | ||
; the sequence number will also be inserted later if it is vital | ||
mov r8, rdi | ||
and r8, 0b00001111 | ||
mov byte [rsi+1], r8b | ||
|
||
; sequence only included if it is a vital chunk | ||
is_rax_flag CHUNKFLAG_VITAL | ||
jne .pack_chunk_header6_end | ||
|
||
; patch 2 bits in the second byte | ||
; if sequence is bigger than 8 bit | ||
mov r8, 0 | ||
mov r8d, dword [connection_sequence] | ||
shr r8, 2 | ||
and r8, 0b11110000 | ||
or byte [rsi+1], r8b | ||
|
||
; full 8 bit sequence into third byte | ||
mov byte al, [connection_sequence] | ||
mov byte [rsi+2], al | ||
|
||
; return size for vital chunks | ||
mov rcx, 3 | ||
|
||
.pack_chunk_header6_end: | ||
mov rax, rcx | ||
pop_registers_keep_rax | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
%include "tests/assert.asm" | ||
|
||
_start: | ||
init_test __FILE__ | ||
|
||
test_pack_chunk_header6: | ||
mov dword [connection_sequence], 9 | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 6 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
mov al, [assert_actual_buf] | ||
assert_al_eq 0x40, __LINE__ | ||
mov al, [assert_actual_buf + 1] | ||
assert_al_eq 0x06, __LINE__ | ||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0x09, __LINE__ | ||
|
||
; the chunk header packer should not increment the sequence number | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 6 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
|
||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0x09, __LINE__ | ||
|
||
test_pack_chunk_header6_big_size: | ||
mov dword [connection_sequence], 3 | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 69 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
mov al, [assert_actual_buf] | ||
assert_al_eq 0x41, __LINE__ | ||
mov al, [assert_actual_buf + 1] | ||
assert_al_eq 0x05, __LINE__ | ||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0x03, __LINE__ | ||
|
||
; the chunk header packer should not increment the sequence number | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 69 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
|
||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0x03, __LINE__ | ||
|
||
test_pack_chunk_header6_big_size_and_big_seq: | ||
mov dword [connection_sequence], 1023 | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 69 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
mov al, [assert_actual_buf] | ||
assert_al_eq 0x41, __LINE__ | ||
mov al, [assert_actual_buf + 1] | ||
; this is the only difference to the 0.7 test | ||
; I did not check value | ||
; just adjusted the test to pass after implementing it | ||
assert_al_eq 0xf5, __LINE__ | ||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0xff, __LINE__ | ||
|
||
; the chunk header packer should not increment the sequence number | ||
|
||
mov rax, 0 | ||
set_rax_flag CHUNKFLAG_VITAL | ||
mov rdi, 69 | ||
mov rsi, assert_actual_buf | ||
call pack_chunk_header6 | ||
|
||
mov al, [assert_actual_buf + 2] | ||
assert_al_eq 0xff, __LINE__ | ||
|
||
end_test __LINE__ |