Skip to content

Commit

Permalink
Revise headers
Browse files Browse the repository at this point in the history
  • Loading branch information
alanjian85 committed Jun 15, 2024
1 parent 9a3fe56 commit a3f4ea3
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 34 deletions.
4 changes: 2 additions & 2 deletions include/compiler.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

#define __section(name) __attribute__((section(#name)))
#define __used __attribute__((used))
#define section(name) __attribute__((section(#name)))
#define used __attribute__((used))
4 changes: 2 additions & 2 deletions include/dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ typedef struct {
} dev_init_t;

#define dev_init(compat, func) \
__section(.init.dev) \
__used static dev_init_t _DEV_INIT = {_MODULE_NAME, compat, func}
section(.init.dev) \
used static dev_init_t _DEV_INIT = {_MODULE_NAME, compat, func}
2 changes: 1 addition & 1 deletion include/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ typedef struct {
i32 (*ioctl)(u32 num, u32 req, va_list args);
} driver_t;

extern driver_t tty_driver;
extern const driver_t TTY_DRIVER;
2 changes: 1 addition & 1 deletion include/drivers/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
#define FONT_WIDTH 8
#define FONT_HEIGHT 16

extern const u8 font[128][16];
extern const u8 FONT[128][16];
11 changes: 5 additions & 6 deletions include/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ typedef struct {
} init_t;

#define module_pre_init(func) \
__section(.init.pre_init) \
__used static const init_t _PRE_INIT = {_MODULE_NAME, func}
section(.init.pre_init) \
used static const init_t _PRE_INIT = {_MODULE_NAME, func}
#define module_init(func) \
__section(.init.init) \
__used static const init_t _INIT = {_MODULE_NAME, func}
section(.init.init) used static const init_t _INIT = {_MODULE_NAME, func}
#define module_post_init(func) \
__section(.init.post_init) \
__used static const init_t _POST_INIT = {_MODULE_NAME, func}
section(.init.post_init) \
used static const init_t _POST_INIT = {_MODULE_NAME, func}

i32 init_modules(void);
1 change: 1 addition & 0 deletions include/intr.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <drivers/plic.h>
#include <types.h>

i32 intr_register_isr(irq_t irq, void (*isr)(void *data), void *data);
void intr_isr(void);
1 change: 0 additions & 1 deletion include/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <list.h>
#include <time.h>
#include <types.h>

typedef struct {
list_node_t node;
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/fbcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void write_char(u32 num, char c) {
ctrl_blk_t *ctrl_blk = &ctrl_blks[num];
for (i32 y = 0; y < FONT_HEIGHT; y++) {
for (i32 x = 0; x < FONT_WIDTH; x++) {
if (font[(u8) c][y] & 1 << (FONT_WIDTH - 1 - x)) {
if (FONT[(u8) c][y] & 1 << (FONT_WIDTH - 1 - x)) {
dev_ioctl(ctrl_blk->fb_dev, FB_WRITE_PIX,
ctrl_blk->cursor.x + x, ctrl_blk->cursor.y + y,
ctrl_blk->fg);
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/font.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <drivers/font.h>

const u8 font[128][16] = {
const u8 FONT[128][16] = {
{
0x00,
0x00,
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static isize write(u32 num, const u8 *buf, usize size) {
return size;
}

driver_t tty_driver = {
const driver_t TTY_DRIVER = {
.read = read,
.write = write,
.ioctl = nullptr,
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static u32 nr_devs = 0;
static void isr(void *data) {
u32 num = (usize) data;
ctrl_blk_t *ctrl_blk = &ctrl_blks[num];
dev_t tty_dev = {.driver = &tty_driver, .num = num};
dev_t tty_dev = {.driver = &TTY_DRIVER, .num = num};
u8 byte = REG(num, RBR);
switch (byte) {
case '\r':
Expand Down
24 changes: 12 additions & 12 deletions src/drivers/virtio-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ static u32 nr_devs = 0;
#define STATUS_FEATURES_OK 8

static virtio_desc_t desc[128];
static virtio_avail_queue_t avail;
static virtio_used_queue_t used;
static virtio_avail_queue_t avail_queue;
static virtio_used_queue_t used_queue;

static struct virtio_gpu_resource_create_2d create_2d;
static struct virtio_gpu_resource_attach_backing attach_backing;
Expand All @@ -148,7 +148,7 @@ static u32 fb[FB_WIDTH * FB_HEIGHT];
static usize offset = 0;

static void flush(u32 num, u32 y, u32 height) {
while (avail.idx != used.idx)
while (avail_queue.idx != used_queue.idx)
;
transfer.r.x = 0;
transfer.r.y = y;
Expand Down Expand Up @@ -181,8 +181,8 @@ static void flush(u32 num, u32 y, u32 height) {
desc[3].flags = VIRTIO_DESC_FLAG_WRITE;
desc[3].next = 0;

avail.ring[avail.idx++ % 128] = 0;
avail.ring[avail.idx++ % 128] = 2;
avail_queue.ring[avail_queue.idx++ % 128] = 0;
avail_queue.ring[avail_queue.idx++ % 128] = 2;
REG(num, NOTIFY) = 0;
}

Expand Down Expand Up @@ -236,8 +236,8 @@ i32 init_virtio_gpu(const dev_node_t *node) {
REG(num, QUEUE_SEL) = 0;
REG(num, QUEUE_NUM) = 128;
REG(num, QUEUE_DESC_LOW) = (usize) desc;
REG(num, QUEUE_DRIVER_LOW) = (usize) &avail;
REG(num, QUEUE_DEVICE_LOW) = (usize) &used;
REG(num, QUEUE_DRIVER_LOW) = (usize) &avail_queue;
REG(num, QUEUE_DEVICE_LOW) = (usize) &used_queue;

REG(num, QUEUE_READY) = 1;

Expand Down Expand Up @@ -349,11 +349,11 @@ i32 init_virtio_gpu(const dev_node_t *node) {
desc[10].flags = VIRTIO_DESC_FLAG_WRITE;
desc[10].next = 0;

avail.ring[avail.idx++] = 0;
avail.ring[avail.idx++] = 2;
avail.ring[avail.idx++] = 5;
avail.ring[avail.idx++] = 7;
avail.ring[avail.idx++] = 9;
avail_queue.ring[avail_queue.idx++] = 0;
avail_queue.ring[avail_queue.idx++] = 2;
avail_queue.ring[avail_queue.idx++] = 5;
avail_queue.ring[avail_queue.idx++] = 7;
avail_queue.ring[avail_queue.idx++] = 9;
REG(num, NOTIFY) = 0;

dev_t dev = {
Expand Down
4 changes: 2 additions & 2 deletions src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static void write(const char *str, usize size) {
}
return;
}
dev_write(make_dev(tty_driver, 0), (const u8 *) str, size);
dev_write(make_dev(TTY_DRIVER, 0), (const u8 *) str, size);
}

static void kvprintf(const char *fmt, va_list args) {
Expand Down Expand Up @@ -87,7 +87,7 @@ void klogf(log_severity_t severity, const char *fmt, ...) {
}

static i32 init(void) {
dev_write(make_dev(tty_driver, 0), (const u8 *) early_log, early_log_tail);
dev_write(make_dev(TTY_DRIVER, 0), (const u8 *) early_log, early_log_tail);
inited = true;
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ i32 proc_init(proc_t *proc, void *entry, u32 flags, proc_t *parent, i32 argc,
i32 stdin_fd = new_fd(proc);
if (stdin_fd < 0)
return stdin_fd;
proc->fds[stdin_fd].dev = make_dev(tty_driver, 0);
proc->fds[stdin_fd].dev = make_dev(TTY_DRIVER, 0);
proc->fds[stdin_fd].flags |= FD_FLAG_READABLE;

i32 stdout_fd = new_fd(proc);
if (stdin_fd < 0)
return stdin_fd;
proc->fds[stdout_fd].dev = make_dev(tty_driver, 0);
proc->fds[stdout_fd].dev = make_dev(TTY_DRIVER, 0);
proc->fds[stdout_fd].flags |= FD_FLAG_WRITABLE;

i32 stderr_fd = new_fd(proc);
if (stdin_fd < 0)
return stdin_fd;
proc->fds[stderr_fd].dev = make_dev(tty_driver, 0);
proc->fds[stderr_fd].dev = make_dev(TTY_DRIVER, 0);
proc->fds[stderr_fd].flags |= FD_FLAG_WRITABLE;

proc->state = PROC_STATE_INIT;
Expand Down

0 comments on commit a3f4ea3

Please sign in to comment.