support for newlines in write call but not printf :(
This commit is contained in:
parent
ed2212c322
commit
c72ac8bf3b
@ -7,4 +7,4 @@ boot: cdrom
|
||||
log: bochslog.txt
|
||||
clock: sync=realtime, time0=local
|
||||
cpu: count=1, ips=1000000
|
||||
com1: enabled=1, mode=file, dev=com1.out
|
||||
com1: enabled=1, mode=file, dev=COM1.out
|
||||
|
33
ports.s
33
ports.s
@ -1,45 +1,34 @@
|
||||
; Helpers for frame buffer which pretty much have to to be
|
||||
; written in asm
|
||||
|
||||
|
||||
; COM1 Base Port
|
||||
%define SERIAL_COM1_BASE 0x3F8
|
||||
|
||||
%define SERIAL_DATA_PORT(base) (base)
|
||||
%define SERIAL_FIFO_COMMAND_PORT(base) (base+2)
|
||||
%define SERIAL_LINE_COMMAND_PORT(base) (base+3)
|
||||
%define SERIAL_MODEM_COMMAND_PORT(base) (base+4)
|
||||
%define SERIAL_LINE_STATUS_PORT(base) (base+5)
|
||||
|
||||
%define SERIAL_DATA_
|
||||
global serial_control
|
||||
global serial_read_buffer
|
||||
|
||||
serial_control:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
add esp, 0xc ; ebp + 2 local vars (32-bit kernel)
|
||||
;push ebp
|
||||
;mov ebp, esp
|
||||
;add esp, 0xc ; ebp + 2 local vars (32-bit kernel)
|
||||
|
||||
mov al, [esp+8]
|
||||
mov dx, [esp+4]
|
||||
out dx, al
|
||||
|
||||
mov esp, ebp
|
||||
pop ebp
|
||||
;mov esp, ebp
|
||||
;pop ebp
|
||||
ret
|
||||
|
||||
; Read byte from serial port
|
||||
serial_read_buffer:
|
||||
push ebp
|
||||
mov ebp, esp
|
||||
push ebx
|
||||
;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
|
||||
;mov esp, ebp
|
||||
;pop ebx
|
||||
;pop ebp
|
||||
ret
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
# Setup script to grab any and all dependancies needed to build this on any of my machines
|
||||
bochs_=$(dpkg --list | grep bochs)
|
||||
if [ "$bochs_" == "" ]
|
||||
|
21
serial.c
21
serial.c
@ -12,7 +12,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
void serial_set_buad_rate(const u16 com_port, const u16 divisor) {
|
||||
void serial_set_baud_rate(const u16 com_port, const u16 divisor) {
|
||||
// Activate line - ready to send higher 8 bits of data
|
||||
// send the higher 8 bits first
|
||||
// send the lower 8 bits next
|
||||
@ -36,3 +36,22 @@ 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;
|
||||
}
|
||||
|
||||
u64 serial_write(const s8* 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;
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
6
serial.h
6
serial.h
@ -3,7 +3,7 @@
|
||||
|
||||
// Serial driver interface
|
||||
|
||||
#define SERIAL_COM1_BASE 0x3F8
|
||||
#define SERIAL_COM1_BASE 0x03F8
|
||||
|
||||
#define SERIAL_DATA_PORT(base) (base)
|
||||
#define SERIAL_FIFO_COMMAND_PORT(base) (base+2)
|
||||
@ -19,8 +19,10 @@
|
||||
#define SERIAL_DEFAULT_BUFFER_CFG 0xc7
|
||||
#define SERIAL_DEFAULT_MODEM_CFG 0x03
|
||||
|
||||
void serial_set_buad_rate(const u16, const u16);
|
||||
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);
|
||||
|
39
stlio.c
39
stlio.c
@ -1,15 +1,52 @@
|
||||
#include "stlio.h"
|
||||
|
||||
static const char _line[52] = {" "};
|
||||
// We are assuming null-terminated strings here
|
||||
u64 strlen(char* buffer) {
|
||||
char* c;
|
||||
for(c = buffer; *c != '\0'; c++); // LULW
|
||||
return (u64)(c - buffer);
|
||||
}
|
||||
void putch(const char c) {
|
||||
write_cell_fb(c, Green, White);
|
||||
}
|
||||
|
||||
u64 write(const char* buffer, const u64 size) {
|
||||
u64 i;
|
||||
for(i = 0; i < size; i++) {
|
||||
write_cell_fb(buffer[i], Green, White);
|
||||
if(buffer[i] == '\n') {
|
||||
write(_line, sizeof(_line));
|
||||
}
|
||||
else {
|
||||
write_cell_fb(buffer[i], Green, White);
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
u64 read(const u64 n) {
|
||||
// read n bytes from keyboard
|
||||
return n;
|
||||
}
|
||||
|
||||
void printf(const s8* fmt, ...) {
|
||||
u64 i = 0;
|
||||
char c = *fmt;
|
||||
while(c != '\0') {
|
||||
/* Check for some kind of contol character
|
||||
* for now we just have \n and \t
|
||||
*/
|
||||
switch(c) {
|
||||
case '\n': {
|
||||
write(_line, sizeof(_line));
|
||||
}
|
||||
case '%': {
|
||||
continue; // eventually there will be more support but for now lmao nah
|
||||
}
|
||||
default: {
|
||||
putch(fmt[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
stlio.h
2
stlio.h
@ -4,3 +4,5 @@
|
||||
|
||||
u64 strlen(char*);
|
||||
u64 write(const char*, const u64);
|
||||
u64 read(const u64);
|
||||
void printf(const s8*, ...);
|
||||
|
7
tests.c
7
tests.c
@ -1,9 +1,12 @@
|
||||
// Module for testing drivers and other things
|
||||
#include "stlio.h"
|
||||
#include "tests.h"
|
||||
#include "serial.h"
|
||||
|
||||
void test_write() {
|
||||
clear_fb();
|
||||
char* msg1 = "bigyeet";
|
||||
write(msg1, strlen(msg1));
|
||||
char* msg1 = "Imagine literally not \nwriting your own os";
|
||||
serial_write((signed char*)msg1, strlen(msg1));
|
||||
//write(msg1, strlen(msg1));
|
||||
printf((signed char*)msg1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user