FIRST (semi)WORKING PASS OF SERIAL DEBUGGING FINALLY!!!!!
This commit is contained in:
parent
392cbf0db4
commit
5c32c17474
@ -39,9 +39,9 @@ void clear_fb(void) {
|
||||
|
||||
// Takes the linear indexed position to move the cursos, if there is nothing at that position we should still have something there
|
||||
void fb_move_cursor(u16 position) {
|
||||
serial_control(FB_CMD, FB_HIGH_CMD);
|
||||
serial_control(FB_DATA, ((position >> 8) & 0x00ff) );
|
||||
serial_control(FB_CMD, FB_LOW_CMD);
|
||||
serial_control(FB_DATA, position & 0x00ff);
|
||||
serialport_write_byte(FB_CMD, FB_HIGH_CMD);
|
||||
serialport_write_byte(FB_DATA, ((position >> 8) & 0x00ff) );
|
||||
serialport_write_byte(FB_CMD, FB_LOW_CMD);
|
||||
serialport_write_byte(FB_DATA, position & 0x00ff);
|
||||
}
|
||||
|
||||
|
4
loader.s
4
loader.s
@ -9,7 +9,7 @@ CHECKSUM equ -MAGIC_NUMBER
|
||||
|
||||
; size in bytes of stack
|
||||
KERNEL_STACK_SIZE equ 4096
|
||||
extern test_write
|
||||
extern test_dispatcher
|
||||
|
||||
section .text
|
||||
; align all instructions to 4 byte boundary by the x86 instruction set law
|
||||
@ -20,7 +20,7 @@ align 4
|
||||
dd CHECKSUM
|
||||
|
||||
loader:
|
||||
call test_write
|
||||
call test_dispatcher
|
||||
|
||||
.loop:
|
||||
jmp .loop
|
||||
|
2
ports.h
2
ports.h
@ -3,7 +3,7 @@
|
||||
#ifndef INCLUDE_IO_H
|
||||
#define INCLUDE_IO_H
|
||||
|
||||
void serial_control(const u16, const u16);
|
||||
void serialport_write_byte(const u16, const u16);
|
||||
|
||||
u8 serial_read_buffer(const u16);
|
||||
#endif /* INCLUDE_IO_H */
|
||||
|
23
ports.s
23
ports.s
@ -1,34 +1,21 @@
|
||||
; Helpers for frame buffer which pretty much have to to be
|
||||
; written in asm
|
||||
|
||||
global serial_control
|
||||
global serialport_write_byte
|
||||
global serial_read_buffer
|
||||
|
||||
serial_control:
|
||||
;push ebp
|
||||
;mov ebp, esp
|
||||
;add esp, 0xc ; ebp + 2 local vars (32-bit kernel)
|
||||
|
||||
; write a byte
|
||||
;serialport_write_byte
|
||||
serialport_write_byte:
|
||||
mov al, [esp+8]
|
||||
mov dx, [esp+4]
|
||||
out dx, al
|
||||
|
||||
;mov esp, ebp
|
||||
;pop ebp
|
||||
ret
|
||||
|
||||
; Read byte from serial port
|
||||
;serialport_read_byte
|
||||
serial_read_buffer:
|
||||
;push ebp
|
||||
;mov ebp, esp
|
||||
;push ebx
|
||||
|
||||
xor eax, eax
|
||||
mov dx, [esp + 4] ; grab the address of the targeted port
|
||||
in al, dx ; read byte from the port
|
||||
|
||||
;mov esp, ebp
|
||||
;pop ebx
|
||||
;pop ebp
|
||||
ret
|
||||
|
||||
|
59
serial.c
59
serial.c
@ -17,41 +17,68 @@ void serial_set_baud_rate(const u16 com_port, const u16 divisor) {
|
||||
// send the higher 8 bits first
|
||||
// send the lower 8 bits next
|
||||
|
||||
serial_control(SERIAL_LINE_COMMAND_PORT(com_port),
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(com_port),
|
||||
SERIAL_LINE_ENABLE);
|
||||
|
||||
serial_control(SERIAL_DATA_PORT(com_port),
|
||||
serialport_write_byte(SERIAL_DATA_PORT(com_port),
|
||||
(divisor>>8) & 0x00ff);
|
||||
|
||||
serial_control(SERIAL_DATA_PORT(com_port),
|
||||
serialport_write_byte(SERIAL_DATA_PORT(com_port),
|
||||
divisor & 0x00ff);
|
||||
}
|
||||
|
||||
// Payload described above
|
||||
void serial_configure_line(const u16 line, const u8 payload) {
|
||||
serial_control(SERIAL_LINE_COMMAND_PORT(line), payload);
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(line), payload);
|
||||
}
|
||||
|
||||
|
||||
u8 serial_fifo_empty(const u16 com_port) {
|
||||
// If the 5th bit is set then we know that the fifo queue is empty
|
||||
return serial_read_buffer(SERIAL_LINE_STATUS_PORT(com_port)) & 0x20;
|
||||
// we get back 0x20 if it is empty
|
||||
return serial_read_buffer(SERIAL_LINE_STATUS_PORT(com_port)) &
|
||||
SERIAL_FIFO_EMPTY_CODE;
|
||||
}
|
||||
|
||||
u64 serial_write(const s8* buffer, const u64 size) {
|
||||
u64 serial_write(const char* buffer, const u64 size) {
|
||||
/*
|
||||
* Writes a given buffer to the com1 serial port for debugging in bochs
|
||||
*/
|
||||
u64 idx = 0;
|
||||
serial_set_baud_rate(SERIAL_COM1_BASE, 1); // base baud rate
|
||||
while(idx < size) {
|
||||
if(serial_fifo_empty(SERIAL_COM1_BASE) == 0x20) {
|
||||
serial_control(SERIAL_COM1_BASE, buffer[idx]);
|
||||
idx++;
|
||||
}
|
||||
// otherwise we just wait until the queue is empty
|
||||
else {
|
||||
continue;
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 1, 0x00);
|
||||
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
|
||||
0x00);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 3, 0x80);
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_LINE_ENABLE);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 0, 0x03);
|
||||
serialport_write_byte(SERIAL_COM1_BASE,
|
||||
SERIAL_DEFAULT_LINE_CFG);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 1, 0x00);
|
||||
serialport_write_byte(SERIAL_DATA_PORT_INT_EN(SERIAL_COM1_BASE),
|
||||
0x00);
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 3, 0x03);
|
||||
serialport_write_byte(SERIAL_LINE_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_DEFAULT_LINE_CFG);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 2, 0xC7);
|
||||
serialport_write_byte(SERIAL_FIFO_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
SERIAL_DEFAULT_BUFFER_CFG);
|
||||
|
||||
//serialport_write_byte(SERIAL_COM1_BASE + 4, 0x0B);
|
||||
serialport_write_byte(SERIAL_MODEM_COMMAND_PORT(SERIAL_COM1_BASE),
|
||||
0x0B);
|
||||
|
||||
for(idx = 0; idx < size; idx++) {
|
||||
serialport_write_byte(SERIAL_COM1_BASE, buffer[idx]);
|
||||
/*
|
||||
if(serial_fifo_empty(SERIAL_COM1_BASE == 0x02)) {
|
||||
serialport_write_byte(SERIAL_COM1_BASE, buffer[idx]);
|
||||
}
|
||||
*/
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
7
serial.h
7
serial.h
@ -6,6 +6,7 @@
|
||||
#define SERIAL_COM1_BASE 0x03F8
|
||||
|
||||
#define SERIAL_DATA_PORT(base) (base)
|
||||
#define SERIAL_DATA_PORT_INT_EN(base) (base+1)
|
||||
#define SERIAL_FIFO_COMMAND_PORT(base) (base+2)
|
||||
#define SERIAL_LINE_COMMAND_PORT(base) (base+3)
|
||||
#define SERIAL_MODEM_COMMAND_PORT(base) (base+4)
|
||||
@ -15,14 +16,16 @@
|
||||
|
||||
// Default configurations for serial ports/lines/buffers etc.
|
||||
// Rational can be found here: https://littleosbook.github.io/#configuring-the-buffers
|
||||
#define SERIAL_DEFAULT_LINE_CFG 0X03
|
||||
#define SERIAL_DEFAULT_LINE_CFG 0x03
|
||||
#define SERIAL_DEFAULT_BUFFER_CFG 0xc7
|
||||
#define SERIAL_DEFAULT_MODEM_CFG 0x03
|
||||
|
||||
#define SERIAL_FIFO_EMPTY_CODE 0x20
|
||||
void serial_set_baud_rate(const u16, const u16);
|
||||
|
||||
void serial_configure_line(const u16, const u8);
|
||||
|
||||
u8 serial_fifo_empty(const u16);
|
||||
|
||||
u64 serial_write(const s8* buffer, const u64 size);
|
||||
u64 serial_write(const char* buffer, const u64 size);
|
||||
|
||||
|
12
tests.c
12
tests.c
@ -5,9 +5,13 @@
|
||||
|
||||
void test_write() {
|
||||
clear_fb();
|
||||
char* msg1 = "Imagine literally not \nwriting your own os";
|
||||
serial_write((signed char*)msg1, strlen(msg1));
|
||||
serial_write((signed char*)msg1, strlen(msg1));
|
||||
//write(msg1, strlen(msg1));
|
||||
char* msg1 = "Writing this to fbout\nOh yea and serial 0x3f8";
|
||||
printf(msg1);
|
||||
serial_write(msg1, strlen(msg1));
|
||||
char* msg2 = "\nserial write has finished";
|
||||
printf(msg2);
|
||||
}
|
||||
|
||||
void test_dispatcher() {
|
||||
test_write();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user