-
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.
bios: implement comm_send.../receive..., minor fixes, add comm_echo t…
…ests
- Loading branch information
1 parent
fd33d6e
commit 96c7e34
Showing
13 changed files
with
566 additions
and
8 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,89 @@ | ||
/** | ||
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
.arch i186 | ||
.code16 | ||
.intel_syntax noprefix | ||
|
||
#include "../common.inc" | ||
|
||
// Input: | ||
// - BH = awaited mask (any bit) | ||
// - CX = timeout | ||
// Output: | ||
// - AH = 0 if success, 1 if timeout, 2 if overrun, 3 if cancel | ||
// - AL = (serial status & BH) | ||
// Clobber: AX | ||
// | ||
// TODO: Halt CPU while waiting for serial input. | ||
// Note that the serial send/receive interrupts will loop | ||
// indefinitely until the byte is sent/received. | ||
|
||
.global __comm_wait_timeout | ||
__comm_wait_timeout: | ||
pushf | ||
push dx | ||
sti | ||
|
||
ss mov dx, [tick_count] | ||
add dx, cx // DX = final tick count | ||
|
||
1: | ||
xor ax, ax | ||
in al, IO_SERIAL_STATUS | ||
and al, bh | ||
jnz 8f // received mask? | ||
|
||
cmp cx, 0xFFFF | ||
je 2f // skip timeout? | ||
|
||
test cx, cx | ||
jz 7f // zero timeout? | ||
ss cmp dx, [tick_count] | ||
jle 7f // timeout? | ||
|
||
2: | ||
// check for cancel key | ||
ss mov ax, [comm_cancel_key] | ||
test ax, ax | ||
jz 1b // cancel key not set? | ||
ss and ax, [keys_held] | ||
ss cmp ax, [comm_cancel_key] | ||
jne 1b // cancel key combo not matched? | ||
|
||
mov ah, 3 // return cancel | ||
jmp 9f | ||
|
||
7: | ||
mov ah, 1 // return timeout | ||
jmp 9f | ||
|
||
8: | ||
test al, SERIAL_OVERRUN | ||
jz 9f // not overrun? (only checked if overrun in mask) | ||
mov ah, 2 // return overrun | ||
|
||
9: | ||
pop dx | ||
popf | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
.arch i186 | ||
.code16 | ||
.intel_syntax noprefix | ||
|
||
#include "../common.inc" | ||
|
||
/** | ||
* INT 14h AH=07h - comm_receive_block | ||
* Input: | ||
* - CX = Length, in bytes | ||
* - DS:DX = Input buffer | ||
* Output: | ||
* - AX = Status | ||
* - DX = Number of bytes received | ||
*/ | ||
.global comm_receive_block | ||
comm_receive_block: | ||
push cx | ||
push di | ||
push es | ||
push ds | ||
pop es | ||
mov di, dx | ||
|
||
// check for CX == 0 | ||
xor ax, ax | ||
test cx, cx | ||
jz 9f | ||
|
||
mov dx, ax // DX = 0 | ||
|
||
1: | ||
call comm_receive_char | ||
test ah, ah | ||
jnz 9f // if error, return error | ||
|
||
stosb // write received character | ||
inc dx | ||
loop 1b | ||
|
||
9: | ||
pop es | ||
pop di | ||
pop cx | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/** | ||
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
.arch i186 | ||
.code16 | ||
.intel_syntax noprefix | ||
|
||
#include "../common.inc" | ||
|
||
/** | ||
* INT 14h AH=03h - comm_receive_char | ||
* Input: | ||
* Output: | ||
* - AX = Character or status | ||
*/ | ||
.global comm_receive_char | ||
comm_receive_char: | ||
push cx | ||
ss mov cx, [comm_recv_timeout] | ||
call comm_receive_with_timeout | ||
pop cx | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
.arch i186 | ||
.code16 | ||
.intel_syntax noprefix | ||
|
||
#include "../common.inc" | ||
|
||
/** | ||
* INT 14h AH=04h - comm_receive_with_timeout | ||
* Input: | ||
* - CX = Timeout, in frames | ||
* Output: | ||
* - AX = Character or status | ||
*/ | ||
.global comm_receive_with_timeout | ||
comm_receive_with_timeout: | ||
push bx | ||
|
||
// Clear overrun, in case it occured before. | ||
in al, IO_SERIAL_STATUS | ||
or al, SERIAL_OVERRUN_RESET | ||
out IO_SERIAL_STATUS, al | ||
|
||
mov bh, (SERIAL_OVERRUN | SERIAL_RX_READY) | ||
call __comm_wait_timeout | ||
test ah, ah | ||
jnz 8f | ||
|
||
// receive character | ||
xor ax, ax | ||
in al, IO_SERIAL_DATA | ||
jmp 9f | ||
|
||
8: | ||
// convert __comm_wait_timeout result to error code | ||
xchg ah, al | ||
mov ah, 0x81 | ||
|
||
9: | ||
pop bx | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/** | ||
* Copyright (c) 2023, 2024 Adrian "asie" Siekierka | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
.arch i186 | ||
.code16 | ||
.intel_syntax noprefix | ||
|
||
#include "../common.inc" | ||
|
||
/** | ||
* INT 14h AH=06h - comm_send_block | ||
* Input: | ||
* - CX = Length, in bytes | ||
* - DS:DX = Input buffer | ||
* Output: | ||
* - AX = Status | ||
*/ | ||
.global comm_send_block | ||
comm_send_block: | ||
push cx | ||
push si | ||
mov si, dx | ||
|
||
// check for CX == 0 | ||
xor ax, ax | ||
test cx, cx | ||
jz 9f | ||
|
||
1: | ||
lodsb | ||
mov bl, al | ||
call comm_send_char | ||
test ax, ax | ||
jnz 9f // if error, return error | ||
loop 1b | ||
|
||
9: | ||
pop si | ||
pop cx | ||
ret | ||
|
Oops, something went wrong.