Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NDRAEY committed Aug 16, 2024
2 parents 68e563f + d7582f6 commit 2f8ccc1
Show file tree
Hide file tree
Showing 28 changed files with 494 additions and 501 deletions.
5 changes: 3 additions & 2 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ SOURCES=\
kernel/src/drv/ps2.c \
kernel/src/drv/video/intel.c \
kernel/src/extra/command_parser.c \
kernel/src/drv/network/e1000.c \
kernel/src/kernel.c \
# kernel/src/lib/duktape.c \
kernel/src/toys/piano.c \
Expand Down Expand Up @@ -249,7 +250,7 @@ QEMU_BASE_FLAGS = -cdrom kernel.iso \
QEMU_FLAGS = $(QEMU_BASE_FLAGS) \
-audiodev pa,id=pa0 \
-netdev user,id=net0,net=192.168.111.0,dhcpstart=192.168.111.128,hostfwd=tcp::9999-:9999 \
-device rtl8139,netdev=net0,id=mydev0 \
-device e1000,netdev=net0,id=mydev0 \
-M pcspk-audiodev=pa0 \
-device ich9-intel-hda,debug=0 \
-device hda-output,audiodev=pa0 \
Expand All @@ -265,7 +266,7 @@ QEMU_FLAGS = $(QEMU_BASE_FLAGS) \
# NOTE: -d int works only when using tcg accelerator (no KVM)
QEMU_FLAGS_WSL = $(QEMU_BASE_FLAGS) \
-netdev user,id=net0,net=192.168.111.0,dhcpstart=192.168.111.128 \
-device rtl8139,netdev=net0,id=mydev0 \
-device e1000,netdev=net0,id=mydev0 \
-device AC97 \
-boot d \
-cpu core2duo-v1
1 change: 0 additions & 1 deletion config.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
DEBUG?=# -ggdb3 #-Werror
MEMORY_SIZE?=128M
USE_SSE?=true
OPTIMIZATION_LEVEL?=0
2 changes: 1 addition & 1 deletion kernel/include/drv/input/keyboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ char* getCharKeyboard(int key, bool mode);
void keyboardHandler(registers_t regs);
void keyboardctl(uint8_t param, bool value);
int getCharRaw();
void* getCharKeyboardWait(bool use_int);
volatile void * getCharKeyboardWait(bool ints);
void keyboardInit();
void gets(char *buffer);
bool is_lctrl_key();
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/io/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@ inline static __attribute__((always_inline)) uint32_t getDisplaySize(){

void setPixelAlpha(uint32_t x, uint32_t y, rgba_color color);
void rect_copy(int x, int y, int width, int height);
void clean_screen();
void graphics_update(uint32_t new_width, uint32_t new_height, uint32_t new_pitch);

64 changes: 32 additions & 32 deletions kernel/include/io/tty.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@
#include "io/screen.h"
#include <stdarg.h>

#define NEW_TTY_PRINTF 1

extern bool stateTTY;
typedef enum {
TTY_ATTRIBUTE_COLOR = (1 << 31)
} tty_attribute_type_t;

void tty_fontConfigurate();

void _tty_puts(const char str[]);
void _tty_print(const char *format, va_list args);
void _tty_printf(const char *text, ...);
void tty_init();

#define tty_print(format, args) _tty_print(format, args); punch()
#define tty_puts(str) _tty_puts(str); punch()
void tty_reset_position();
void tty_clear_buffers();
void tty_build_buffers();

static inline void tty_printf(char *text, ...) {
if (stateTTY){
va_list args;
va_start(args, text);
tty_print(text, args);
va_end(args);
}
}
void tty_set_color(uint32_t color);
uint32_t tty_get_color();

void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color);
void setPosX(uint32_t x);
void setPosY(uint32_t y);
void _tty_putc(int c);
void tty_putc(int c);
void _tty_puts(const char* str);
void tty_puts(const char *str);
void _tty_vprintf(const char* format, va_list args);
void tty_vprintf(const char* format, va_list args);

void tty_setcolor(uint32_t color);
uint32_t tty_getcolor();
void tty_set_x(uint32_t x);
void tty_set_y(uint32_t y);

void tty_changeState(bool state);
void tty_set_bgcolor(uint32_t color);
void tty_render();
void tty_scroll();

void set_cursor_enabled(bool en);
void tty_clear();

void _tty_putuint(const size_t i);
void _tty_putint(const ssize_t i);
void _tty_putchar(char c, char c1);
void tty_putchar(char c, char c1);
static inline void tty_printf(const char *text, ...) {
va_list args;
va_start(args, text);
tty_vprintf(text, args);
va_end(args);
}

void clean_screen();
void clean_tty_screen();
void buffer_set_pixel4(uint8_t *buffer, size_t width, size_t height, size_t x, size_t y, size_t color);
void clean_tty_screen_no_update();
static inline void _tty_printf(const char *text, ...) {
va_list args;
va_start(args, text);
_tty_vprintf(text, args);
va_end(args);
}
6 changes: 3 additions & 3 deletions kernel/src/desktop/parallel_desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void parallel_desktop_start() {
size_t frames = 0;

qemu_log("Reached init...");
set_cursor_enabled(false);
// set_cursor_enabled(false);
keyboardctl(KEYBOARD_ECHO, false);

log_window_manager_state();
Expand Down Expand Up @@ -240,11 +240,11 @@ void parallel_desktop_start() {
window_destroy(root_window);
qemu_log("Destroyed root_window");

set_cursor_enabled(true);
// set_cursor_enabled(true);

qemu_log("Exit successfully!!!");

clean_tty_screen();
tty_clear();

tty_printf("Memory allocation info written to COM1 (debug) port!!!");
log_window_manager_state();
Expand Down
20 changes: 10 additions & 10 deletions kernel/src/drv/disk/ata.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,18 @@ void ata_write(uint8_t drive, const uint8_t* buf, size_t location, size_t length

void ata_list() {
for (size_t i = 0; i < 4; i++) {
_tty_printf("\tATA: %s %s: %s ",
tty_printf("\tATA: %s %s: %s ",
PRIM_SEC((i >> 1) & 1),
MAST_SLV(i & 1),
drives[i].online?"online ":"offline"
);

if(!drives[i].online) {
_tty_printf("\n");
tty_printf("\n");
continue;
}

_tty_printf("%u sectors = ", drives[i].capacity);
tty_printf("%u sectors = ", drives[i].capacity);

size_t megabytes;

Expand All @@ -440,24 +440,24 @@ void ata_list() {
megabytes = (drives[i].capacity >> 5) / (1 << 6);
}

_tty_printf("%u MB = %u GB", megabytes, megabytes >> 10);
tty_printf("%u MB = %u GB", megabytes, megabytes >> 10);

if(drives[i].is_packet)
_tty_printf(" [PACKET DEVICE!!!]");
tty_printf(" [PACKET DEVICE!!!]");

if(drives[i].is_sata)
_tty_printf(" [SATA]");
tty_printf(" [SATA]");

if(drives[i].is_dma)
_tty_printf(" [DMA]");
tty_printf(" [DMA]");

qemu_note("Drive %d", i);
qemu_note("'%s' '%s' '%s'", drives[i].model_name, drives[i].fwversion, drives[i].serial_number);

_tty_printf("\n\t|-- Model: \"%s\"; Firmware version: \"%s\";", drives[i].model_name, drives[i].fwversion);
_tty_printf("\n\t|-- Serial number: \"%s\";", drives[i].serial_number);
tty_printf("\n\t|-- Model: \"%s\"; Firmware version: \"%s\";", drives[i].model_name, drives[i].fwversion);
tty_printf("\n\t|-- Serial number: \"%s\";", drives[i].serial_number);

_tty_printf("\n");
tty_printf("\n");
}

tty_printf("\n");
Expand Down
11 changes: 6 additions & 5 deletions kernel/src/drv/input/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ int getIntKeyboardWait(){
return lastKey;
}

void* getCharKeyboardWait(bool ints) {
volatile void * getCharKeyboardWait(bool ints) {
kmode = 2;
while(kmode==2) {
if (lastKey != 0 && !(lastKey & 0x80)) {
Expand All @@ -231,7 +231,7 @@ void* getCharKeyboardWait(bool ints) {
}
}

void kbd_add_char(char *buf, char* key) {
void kbd_add_char(volatile char *buf, char* key) {
if(kmode == 1 && curbuf != 0) {
if (!(lastKey == 0x1C || lastKey == 0x0E)) {
strcat(buf, key);
Expand All @@ -240,7 +240,7 @@ void kbd_add_char(char *buf, char* key) {

if(lastKey == 0x0E) { // BACKSPACE
if(chartyped > 0) {
tty_backspace();
// tty_backspace();
chartyped--;
buf[chartyped] = 0;
}
Expand Down Expand Up @@ -336,8 +336,9 @@ void keyboardHandler(registers_t regs){
char* key = getCharKeyboard(lastKey, false);
if (key != 0 && lastKey < 128){
if(echo) {
if(!key_ctrl && lastKey != 0x0E)
tty_printf("%s", key);
if(!key_ctrl && lastKey != 0x0E) {
tty_puts(key);
}
}
kbd_add_char(curbuf, key);
}
Expand Down
23 changes: 23 additions & 0 deletions kernel/src/drv/network/e1000.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Fuck-Its-Ass driver for Intel E1000

#include "drv/pci.h"
#include "io/ports.h"
#include "common.h"

#define E1000_VEN 0x8086
#define E1000_DEV 0x100E

uint8_t e1000_bus = 0, e1000_slot = 0, e1000_func = 0;

void e1000_init() {
pci_find_device(E1000_VEN, E1000_DEV, &e1000_bus, &e1000_slot, &e1000_func);

uint16_t id = pci_get_device(e1000_bus, e1000_slot, e1000_func);

if(id == PCI_VENDOR_NO_DEVICE) {
qemu_err("No Intel E1000");
return;
} else {
qemu_ok("Found Intel E1000!");
}
}
6 changes: 3 additions & 3 deletions kernel/src/drv/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ void pci_enable_bus_mastering(uint8_t bus, uint8_t slot, uint8_t func) {
}

void pci_print_nth(uint8_t class, uint8_t subclass, uint8_t bus, uint8_t slot, uint8_t hdr, uint16_t vendor, uint16_t device, uint8_t func) {
_tty_printf("%d:%d:%d:%d.%d %s: %s (%x), девайс: %x ",
tty_printf("%d:%d:%d:%d.%d %s: %s (%x), девайс: %x ",
class,
subclass,
bus,
Expand All @@ -453,7 +453,7 @@ void pci_print_nth(uint8_t class, uint8_t subclass, uint8_t bus, uint8_t slot, u
device);

if((hdr & 0x80) == 0) {
_tty_printf("[Multifunc]");
tty_printf("[Multifunc]");
}

uint32_t bar0 = pci_read32(bus, slot, func, 0x10 + (0 * 4));
Expand All @@ -471,7 +471,7 @@ void pci_print_nth(uint8_t class, uint8_t subclass, uint8_t bus, uint8_t slot, u
bar4,
bar5);

_tty_printf("\n");
tty_printf("\n");
}

void pci_scan_everything() {
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/drv/video/intel.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ void igfx_init() {

graphics_update(igfx_width, igfx_height, scanline_w);

clean_tty_screen();
tty_clear();

tty_printf("Screen now tuned to: %dx%d; Size: %d; BackFB: %x\n", igfx_width, igfx_height, framebuffer_size, back_framebuffer_addr);

Expand Down
Loading

0 comments on commit 2f8ccc1

Please sign in to comment.