[project] Lose the battle between tabs & spaces

I'm a tabs guy. I like tabs, it's an elegant way to represent
indentation instead of brute-forcing it. But I have to admit that the
world seems to be going towards spaces, and tooling tends not to play
nice with tabs. So here we go, changing the whole repo to spaces since
I'm getting tired of all the inconsistent formatting.
This commit is contained in:
F in Chat for Tabs
2021-08-01 17:46:16 -07:00
committed by Justin C. Miller
parent d36b2d8057
commit 8f529046a9
161 changed files with 7958 additions and 7958 deletions

View File

@@ -15,17 +15,17 @@ const static uint8_t unicode_start = 0xfe;
/* bits used in flags */
enum psf2_flags {
psf2_has_unicode = 0x00000001
psf2_has_unicode = 0x00000001
};
struct psf2_header {
uint8_t magic[4];
uint32_t version;
uint32_t header_size; // offset of bitmaps in file
uint32_t flags;
uint32_t length; // number of glyphs
uint32_t charsize; // number of bytes for each character
uint32_t height, width; // max dimensions of glyphs
uint8_t magic[4];
uint32_t version;
uint32_t header_size; // offset of bitmaps in file
uint32_t flags;
uint32_t length; // number of glyphs
uint32_t charsize; // number of bytes for each character
uint32_t height, width; // max dimensions of glyphs
};
const uint8_t default_font[] = {
@@ -34,47 +34,47 @@ const uint8_t default_font[] = {
};
font::font(void const *data) :
m_sizex {0},
m_sizey {0},
m_count {0},
m_data {nullptr}
m_sizex {0},
m_sizey {0},
m_count {0},
m_data {nullptr}
{
if (!data)
data = default_font;
if (!data)
data = default_font;
psf2_header const *psf2 = static_cast<psf2_header const *>(data);
for (int i = 0; i < sizeof(magic); ++i) {
assert(psf2->magic[i] == magic[i] && "Bad font magic number.");
}
psf2_header const *psf2 = static_cast<psf2_header const *>(data);
for (int i = 0; i < sizeof(magic); ++i) {
assert(psf2->magic[i] == magic[i] && "Bad font magic number.");
}
m_data = static_cast<uint8_t const *>(data) + psf2->header_size;
m_sizex = psf2->width;
m_sizey = psf2->height;
m_count = psf2->length;
m_data = static_cast<uint8_t const *>(data) + psf2->header_size;
m_sizex = psf2->width;
m_sizey = psf2->height;
m_count = psf2->length;
}
void
font::draw_glyph(
screen &s,
uint32_t glyph,
screen::pixel_t fg,
screen::pixel_t bg,
unsigned x,
unsigned y) const
screen &s,
uint32_t glyph,
screen::pixel_t fg,
screen::pixel_t bg,
unsigned x,
unsigned y) const
{
unsigned bwidth = (m_sizex+7)/8;
uint8_t const *data = m_data + (glyph * glyph_bytes());
unsigned bwidth = (m_sizex+7)/8;
uint8_t const *data = m_data + (glyph * glyph_bytes());
for (int dy = 0; dy < m_sizey; ++dy) {
for (int dx = 0; dx < bwidth; ++dx) {
uint8_t byte = data[dy * bwidth + dx];
for (int i = 0; i < 8; ++i) {
if (dx*8 + i >= m_sizex) break;
const uint8_t mask = 1 << (7-i);
uint32_t c = (byte & mask) ? fg : bg;
s.draw_pixel(x + dx*8 + i, y + dy, c);
}
}
}
for (int dy = 0; dy < m_sizey; ++dy) {
for (int dx = 0; dx < bwidth; ++dx) {
uint8_t byte = data[dy * bwidth + dx];
for (int i = 0; i < 8; ++i) {
if (dx*8 + i >= m_sizex) break;
const uint8_t mask = 1 << (7-i);
uint32_t c = (byte & mask) ? fg : bg;
s.draw_pixel(x + dx*8 + i, y + dy, c);
}
}
}
}

View File

@@ -6,28 +6,28 @@
class font
{
public:
/// Constructor.
/// \arg data The font data to load. If null, will load the default
/// built-in font.
font(void const *data = nullptr);
/// Constructor.
/// \arg data The font data to load. If null, will load the default
/// built-in font.
font(void const *data = nullptr);
unsigned glyph_bytes() const { return m_sizey * ((m_sizex + 7) / 8); }
unsigned count() const { return m_count; }
unsigned width() const { return m_sizex; }
unsigned height() const { return m_sizey; }
bool valid() const { return m_count > 0; }
unsigned glyph_bytes() const { return m_sizey * ((m_sizex + 7) / 8); }
unsigned count() const { return m_count; }
unsigned width() const { return m_sizex; }
unsigned height() const { return m_sizey; }
bool valid() const { return m_count > 0; }
void draw_glyph(
screen &s,
uint32_t glyph,
screen::pixel_t fg,
screen::pixel_t bg,
unsigned x,
unsigned y) const;
void draw_glyph(
screen &s,
uint32_t glyph,
screen::pixel_t fg,
screen::pixel_t bg,
unsigned x,
unsigned y) const;
private:
unsigned m_sizex, m_sizey;
unsigned m_count;
uint8_t const *m_data;
unsigned m_sizex, m_sizey;
unsigned m_count;
uint8_t const *m_data;
};

View File

@@ -14,8 +14,8 @@
#include "scrollback.h"
extern "C" {
int main(int, const char **);
void _get_init(size_t *initc, struct j6_init_value **initv);
int main(int, const char **);
void _get_init(size_t *initc, struct j6_init_value **initv);
}
extern j6_handle_t __handle_sys;
@@ -23,118 +23,118 @@ extern j6_handle_t __handle_self;
struct entry
{
uint8_t bytes;
uint8_t area;
uint8_t severity;
uint8_t sequence;
char message[0];
uint8_t bytes;
uint8_t area;
uint8_t severity;
uint8_t sequence;
char message[0];
};
int
main(int argc, const char **argv)
{
j6_system_log("fb driver starting");
j6_system_log("fb driver starting");
size_t initc = 0;
j6_init_value *initv = nullptr;
_get_init(&initc, &initv);
size_t initc = 0;
j6_init_value *initv = nullptr;
_get_init(&initc, &initv);
j6_init_framebuffer *fb = nullptr;
for (unsigned i = 0; i < initc; ++i) {
if (initv[i].type == j6_init_desc_framebuffer) {
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].data);
break;
}
}
j6_init_framebuffer *fb = nullptr;
for (unsigned i = 0; i < initc; ++i) {
if (initv[i].type == j6_init_desc_framebuffer) {
fb = reinterpret_cast<j6_init_framebuffer*>(initv[i].data);
break;
}
}
if (!fb || fb->addr == 0) {
j6_system_log("fb driver didn't find a framebuffer, exiting");
return 1;
}
if (!fb || fb->addr == 0) {
j6_system_log("fb driver didn't find a framebuffer, exiting");
return 1;
}
j6_handle_t fb_handle = j6_handle_invalid;
uint32_t flags =
j6_vm_flag_write |
j6_vm_flag_write_combine |
j6_vm_flag_mmio;
j6_status_t s = j6_system_map_phys(__handle_sys, &fb_handle, fb->addr, fb->size, flags);
if (s != j6_status_ok) {
return s;
}
j6_handle_t fb_handle = j6_handle_invalid;
uint32_t flags =
j6_vm_flag_write |
j6_vm_flag_write_combine |
j6_vm_flag_mmio;
j6_status_t s = j6_system_map_phys(__handle_sys, &fb_handle, fb->addr, fb->size, flags);
if (s != j6_status_ok) {
return s;
}
s = j6_vma_map(fb_handle, __handle_self, fb->addr);
if (s != j6_status_ok) {
return s;
}
s = j6_vma_map(fb_handle, __handle_self, fb->addr);
if (s != j6_status_ok) {
return s;
}
const screen::pixel_order order = (fb->flags & 1) ?
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
const screen::pixel_order order = (fb->flags & 1) ?
screen::pixel_order::bgr8 : screen::pixel_order::rgb8;
screen scr(
reinterpret_cast<void*>(fb->addr),
fb->horizontal,
fb->vertical,
fb->scanline,
order);
screen scr(
reinterpret_cast<void*>(fb->addr),
fb->horizontal,
fb->vertical,
fb->scanline,
order);
font fnt;
font fnt;
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
scr.fill(bg);
scr.update();
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
scr.fill(bg);
scr.update();
constexpr int margin = 2;
const unsigned xstride = (margin + fnt.width());
const unsigned ystride = (margin + fnt.height());
const unsigned rows = (scr.height() - margin) / ystride;
const unsigned cols = (scr.width() - margin) / xstride;
constexpr int margin = 2;
const unsigned xstride = (margin + fnt.width());
const unsigned ystride = (margin + fnt.height());
const unsigned rows = (scr.height() - margin) / ystride;
const unsigned cols = (scr.width() - margin) / xstride;
scrollback scroll(rows, cols);
scrollback scroll(rows, cols);
int pending = 0;
constexpr int pending_threshold = 5;
int pending = 0;
constexpr int pending_threshold = 5;
j6_handle_t sys = __handle_sys;
size_t buffer_size = 0;
void *message_buffer = nullptr;
j6_handle_t sys = __handle_sys;
size_t buffer_size = 0;
void *message_buffer = nullptr;
while (true) {
size_t size = buffer_size;
j6_status_t s = j6_system_get_log(sys, message_buffer, &size);
while (true) {
size_t size = buffer_size;
j6_status_t s = j6_system_get_log(sys, message_buffer, &size);
if (s == j6_err_insufficient) {
free(message_buffer);
message_buffer = malloc(size * 2);
buffer_size = size;
continue;
} else if (s != j6_status_ok) {
j6_system_log("fb driver got error from get_log, quitting");
return s;
}
if (s == j6_err_insufficient) {
free(message_buffer);
message_buffer = malloc(size * 2);
buffer_size = size;
continue;
} else if (s != j6_status_ok) {
j6_system_log("fb driver got error from get_log, quitting");
return s;
}
if (size > 0) {
entry *e = reinterpret_cast<entry*>(message_buffer);
if (size > 0) {
entry *e = reinterpret_cast<entry*>(message_buffer);
size_t eom = e->bytes - sizeof(entry);
e->message[eom] = 0;
size_t eom = e->bytes - sizeof(entry);
e->message[eom] = 0;
scroll.add_line(e->message, eom);
if (++pending > pending_threshold) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
} else {
if (pending) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
}
}
scroll.add_line(e->message, eom);
if (++pending > pending_threshold) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
} else {
if (pending) {
scroll.render(scr, fnt);
scr.update();
pending = 0;
}
}
}
j6_system_log("fb driver done, exiting");
return 0;
j6_system_log("fb driver done, exiting");
return 0;
}

View File

@@ -3,46 +3,46 @@
#include "screen.h"
screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order) :
m_fb(static_cast<volatile pixel_t *>(addr)),
m_order(order),
m_scanline(scanline),
m_resx(hres),
m_resy(vres)
m_fb(static_cast<volatile pixel_t *>(addr)),
m_order(order),
m_scanline(scanline),
m_resx(hres),
m_resy(vres)
{
const size_t size = scanline * vres;
m_back = reinterpret_cast<pixel_t*>(malloc(size * sizeof(pixel_t)));
const size_t size = scanline * vres;
m_back = reinterpret_cast<pixel_t*>(malloc(size * sizeof(pixel_t)));
}
screen::pixel_t
screen::color(uint8_t r, uint8_t g, uint8_t b) const
{
switch (m_order) {
case pixel_order::bgr8:
return
(static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16);
switch (m_order) {
case pixel_order::bgr8:
return
(static_cast<uint32_t>(b) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(r) << 16);
case pixel_order::rgb8:
return
(static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(b) << 16);
}
case pixel_order::rgb8:
return
(static_cast<uint32_t>(r) << 0) |
(static_cast<uint32_t>(g) << 8) |
(static_cast<uint32_t>(b) << 16);
}
}
void
screen::fill(pixel_t color)
{
const size_t len = m_scanline * m_resy;
asm volatile ( "rep stosl" : :
"a"(color), "c"(len), "D"(m_back) );
const size_t len = m_scanline * m_resy;
asm volatile ( "rep stosl" : :
"a"(color), "c"(len), "D"(m_back) );
}
void
screen::update()
{
const size_t len = m_scanline * m_resy * sizeof(pixel_t);
asm volatile ( "rep movsb" : :
"c"(len), "S"(m_back), "D"(m_fb) );
const size_t len = m_scanline * m_resy * sizeof(pixel_t);
asm volatile ( "rep movsb" : :
"c"(len), "S"(m_back), "D"(m_fb) );
}

View File

@@ -5,32 +5,32 @@
class screen
{
public:
using pixel_t = uint32_t;
using pixel_t = uint32_t;
enum class pixel_order : uint8_t { bgr8, rgb8, };
enum class pixel_order : uint8_t { bgr8, rgb8, };
screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order);
screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanline, pixel_order order);
unsigned width() const { return m_resx; }
unsigned height() const { return m_resy; }
unsigned width() const { return m_resx; }
unsigned height() const { return m_resy; }
pixel_t color(uint8_t r, uint8_t g, uint8_t b) const;
pixel_t color(uint8_t r, uint8_t g, uint8_t b) const;
void fill(pixel_t color);
void fill(pixel_t color);
inline void draw_pixel(unsigned x, unsigned y, pixel_t color) {
const size_t index = x + y * m_scanline;
m_back[index] = color;
}
inline void draw_pixel(unsigned x, unsigned y, pixel_t color) {
const size_t index = x + y * m_scanline;
m_back[index] = color;
}
void update();
void update();
private:
volatile pixel_t *m_fb;
pixel_t *m_back;
pixel_order m_order;
unsigned m_scanline;
unsigned m_resx, m_resy;
volatile pixel_t *m_fb;
pixel_t *m_back;
pixel_order m_order;
unsigned m_scanline;
unsigned m_resx, m_resy;
screen() = delete;
screen() = delete;
};

View File

@@ -6,53 +6,53 @@
#include "scrollback.h"
scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
m_rows {lines},
m_cols {cols},
m_count {0},
m_margin {margin}
m_rows {lines},
m_cols {cols},
m_count {0},
m_margin {margin}
{
m_data = reinterpret_cast<char*>(malloc(lines*cols));
memset(m_data, ' ', lines*cols);
m_data = reinterpret_cast<char*>(malloc(lines*cols));
memset(m_data, ' ', lines*cols);
}
void
scrollback::add_line(const char *line, size_t len)
{
unsigned i = m_count++ % m_rows;
unsigned i = m_count++ % m_rows;
if (len > m_cols)
len = m_cols;
if (len > m_cols)
len = m_cols;
char *start = m_data + (i * m_cols);
memcpy(start, line, len);
if (len < m_cols)
memset(start + len, ' ', m_cols - len);
char *start = m_data + (i * m_cols);
memcpy(start, line, len);
if (len < m_cols)
memset(start + len, ' ', m_cols - len);
}
char *
scrollback::get_line(unsigned i)
{
unsigned line = (i + m_count) % m_rows;
return &m_data[line*m_cols];
unsigned line = (i + m_count) % m_rows;
return &m_data[line*m_cols];
}
void
scrollback::render(screen &scr, font &fnt)
{
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
const unsigned xstride = (m_margin + fnt.width());
const unsigned ystride = (m_margin + fnt.height());
const unsigned xstride = (m_margin + fnt.width());
const unsigned ystride = (m_margin + fnt.height());
unsigned start = m_count <= m_rows ? 0 :
m_count % m_rows;
unsigned start = m_count <= m_rows ? 0 :
m_count % m_rows;
for (unsigned y = 0; y < m_rows; ++y) {
unsigned i = (start + y) % m_rows;
char *line = &m_data[i*m_cols];
for (unsigned x = 0; x < m_cols; ++x) {
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
}
}
for (unsigned y = 0; y < m_rows; ++y) {
unsigned i = (start + y) % m_rows;
char *line = &m_data[i*m_cols];
for (unsigned x = 0; x < m_cols; ++x) {
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
}
}
}

View File

@@ -7,19 +7,19 @@ class font;
class scrollback
{
public:
scrollback(unsigned lines, unsigned cols, unsigned margin = 2);
scrollback(unsigned lines, unsigned cols, unsigned margin = 2);
void add_line(const char *line, size_t len);
void add_line(const char *line, size_t len);
char * get_line(unsigned i);
char * get_line(unsigned i);
void render(screen &scr, font &fnt);
void render(screen &scr, font &fnt);
private:
char *m_data;
unsigned m_rows, m_cols;
unsigned m_start;
unsigned m_count;
unsigned m_margin;
char *m_data;
unsigned m_rows, m_cols;
unsigned m_start;
unsigned m_count;
unsigned m_margin;
};

View File

@@ -2,7 +2,7 @@
#include "modules.h"
extern "C" {
int main(int, const char **);
int main(int, const char **);
}
uintptr_t _arg_modules_phys; // This gets filled in in _start
@@ -13,8 +13,8 @@ j6_handle_t handle_system = 2; // boot protocol is that init gets the system as
int
main(int argc, const char **argv)
{
j6_system_log("srv.init starting");
modules::load_all(_arg_modules_phys);
j6_system_log("srv.init starting");
modules::load_all(_arg_modules_phys);
return 0;
return 0;
}

View File

@@ -18,53 +18,53 @@ namespace modules {
static const modules_page *
load_page(uintptr_t address)
{
j6_handle_t mods_vma = j6_handle_invalid;
j6_status_t s = j6_system_map_phys(handle_system, &mods_vma, address, 0x1000, 0);
if (s != j6_status_ok)
exit(s);
j6_handle_t mods_vma = j6_handle_invalid;
j6_status_t s = j6_system_map_phys(handle_system, &mods_vma, address, 0x1000, 0);
if (s != j6_status_ok)
exit(s);
s = j6_vma_map(mods_vma, handle_self, address);
if (s != j6_status_ok)
exit(s);
s = j6_vma_map(mods_vma, handle_self, address);
if (s != j6_status_ok)
exit(s);
return reinterpret_cast<modules_page*>(address);
return reinterpret_cast<modules_page*>(address);
}
void
load_all(uintptr_t address)
{
module_framebuffer const *framebuffer = nullptr;
module_framebuffer const *framebuffer = nullptr;
while (address) {
const modules_page *page = load_page(address);
while (address) {
const modules_page *page = load_page(address);
char message[100];
sprintf(message, "srv.init loading %d modules from page at 0x%lx", page->count, address);
j6_system_log(message);
char message[100];
sprintf(message, "srv.init loading %d modules from page at 0x%lx", page->count, address);
j6_system_log(message);
module *mod = page->modules;
size_t count = page->count;
while (count--) {
switch (mod->mod_type) {
case module_type::framebuffer:
framebuffer = reinterpret_cast<const module_framebuffer*>(mod);
break;
module *mod = page->modules;
size_t count = page->count;
while (count--) {
switch (mod->mod_type) {
case module_type::framebuffer:
framebuffer = reinterpret_cast<const module_framebuffer*>(mod);
break;
case module_type::program:
if (mod->mod_flags == module_flags::no_load)
j6_system_log("Loaded program module");
else
j6_system_log("Non-loaded program module");
break;
case module_type::program:
if (mod->mod_flags == module_flags::no_load)
j6_system_log("Loaded program module");
else
j6_system_log("Non-loaded program module");
break;
default:
j6_system_log("Unknown module");
}
mod = offset_ptr<module>(mod, mod->mod_length);
}
default:
j6_system_log("Unknown module");
}
mod = offset_ptr<module>(mod, mod->mod_length);
}
address = page->next;
}
address = page->next;
}
}
} // namespace modules

View File

@@ -3,20 +3,20 @@
uint8_t
inb(uint16_t port)
{
uint8_t val;
__asm__ __volatile__ ( "inb %1, %0" : "=a"(val) : "Nd"(port) );
return val;
uint8_t val;
__asm__ __volatile__ ( "inb %1, %0" : "=a"(val) : "Nd"(port) );
return val;
}
void
outb(uint16_t port, uint8_t val)
{
__asm__ __volatile__ ( "outb %0, %1" :: "a"(val), "Nd"(port) );
__asm__ __volatile__ ( "outb %0, %1" :: "a"(val), "Nd"(port) );
}
void
io_wait(unsigned times)
{
for (unsigned i = 0; i < times; ++i)
outb(0x80, 0);
for (unsigned i = 0; i < times; ++i)
outb(0x80, 0);
}

View File

@@ -14,139 +14,139 @@ extern j6_handle_t __handle_sys;
j6_handle_t endp = j6_handle_invalid;
extern "C" {
int main(int, const char **);
int main(int, const char **);
}
void
thread_proc()
{
j6_system_log("sub thread starting");
j6_system_log("sub thread starting");
char buffer[512];
size_t len = sizeof(buffer);
j6_tag_t tag = 0;
j6_status_t result = j6_endpoint_receive(endp, &tag, &len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
char buffer[512];
size_t len = sizeof(buffer);
j6_tag_t tag = 0;
j6_status_t result = j6_endpoint_receive(endp, &tag, &len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
j6_system_log("sub thread received message");
j6_system_log("sub thread received message");
for (int i = 0; i < len; ++i)
if (buffer[i] >= 'A' && buffer[i] <= 'Z')
buffer[i] += 0x20;
for (int i = 0; i < len; ++i)
if (buffer[i] >= 'A' && buffer[i] <= 'Z')
buffer[i] += 0x20;
tag++;
result = j6_endpoint_send(endp, tag, len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
tag++;
result = j6_endpoint_send(endp, tag, len, (void*)buffer);
if (result != j6_status_ok)
j6_thread_exit(result);
j6_system_log("sub thread sent message");
j6_system_log("sub thread sent message");
for (int i = 1; i < 5; ++i)
j6_thread_sleep(i*10);
for (int i = 1; i < 5; ++i)
j6_thread_sleep(i*10);
j6_system_log("sub thread exiting");
j6_thread_exit(0);
j6_system_log("sub thread exiting");
j6_thread_exit(0);
}
int
main(int argc, const char **argv)
{
j6_handle_t children[2] = {j6_handle_invalid, j6_handle_invalid};
j6_signal_t out = 0;
j6_handle_t children[2] = {j6_handle_invalid, j6_handle_invalid};
j6_signal_t out = 0;
j6_system_log("main thread starting");
j6_system_log("main thread starting");
for (int i = 0; i < argc; ++i)
j6_system_log(argv[i]);
for (int i = 0; i < argc; ++i)
j6_system_log(argv[i]);
void *base = malloc(0x1000);
if (!base)
return 1;
void *base = malloc(0x1000);
if (!base)
return 1;
uint64_t *vma_ptr = reinterpret_cast<uint64_t*>(base);
for (int i = 0; i < 3; ++i)
vma_ptr[i*100] = uint64_t(i);
uint64_t *vma_ptr = reinterpret_cast<uint64_t*>(base);
for (int i = 0; i < 3; ++i)
vma_ptr[i*100] = uint64_t(i);
j6_system_log("main thread wrote to memory area");
j6_system_log("main thread wrote to memory area");
j6_status_t result = j6_endpoint_create(&endp);
if (result != j6_status_ok)
return result;
j6_status_t result = j6_endpoint_create(&endp);
if (result != j6_status_ok)
return result;
j6_system_log("main thread created endpoint");
j6_system_log("main thread created endpoint");
result = j6_thread_create(reinterpret_cast<void*>(&thread_proc), &children[1]);
if (result != j6_status_ok)
return result;
result = j6_thread_create(reinterpret_cast<void*>(&thread_proc), &children[1]);
if (result != j6_status_ok)
return result;
j6_system_log("main thread created sub thread");
j6_system_log("main thread created sub thread");
char message[] = "MAIN THREAD SUCCESSFULLY CALLED SENDRECV IF THIS IS LOWERCASE";
size_t size = sizeof(message);
j6_tag_t tag = 16;
result = j6_endpoint_sendrecv(endp, &tag, &size, (void*)message);
if (result != j6_status_ok)
return result;
char message[] = "MAIN THREAD SUCCESSFULLY CALLED SENDRECV IF THIS IS LOWERCASE";
size_t size = sizeof(message);
j6_tag_t tag = 16;
result = j6_endpoint_sendrecv(endp, &tag, &size, (void*)message);
if (result != j6_status_ok)
return result;
if (tag != 17)
j6_system_log("GOT WRONG TAG FROM SENDRECV");
if (tag != 17)
j6_system_log("GOT WRONG TAG FROM SENDRECV");
result = j6_system_bind_irq(__handle_sys, endp, 3);
if (result != j6_status_ok)
return result;
result = j6_system_bind_irq(__handle_sys, endp, 3);
if (result != j6_status_ok)
return result;
j6_system_log(message);
j6_system_log(message);
j6_system_log("main thread creating a new process");
result = j6_process_create(&children[0]);
if (result != j6_status_ok)
return result;
j6_system_log("main thread creating a new process");
result = j6_process_create(&children[0]);
if (result != j6_status_ok)
return result;
j6_system_log("main thread waiting on children");
j6_system_log("main thread waiting on children");
j6_handle_t outhandle;
result = j6_object_wait_many(children, 2, -1ull, &outhandle, &out);
if (result != j6_status_ok)
return result;
j6_handle_t outhandle;
result = j6_object_wait_many(children, 2, -1ull, &outhandle, &out);
if (result != j6_status_ok)
return result;
if (outhandle == children[1]) {
j6_system_log(" ok from child thread");
} else if (outhandle == children[0]) {
j6_system_log(" ok from child process");
} else {
j6_system_log(" ... got unknown handle");
}
if (outhandle == children[1]) {
j6_system_log(" ok from child thread");
} else if (outhandle == children[0]) {
j6_system_log(" ok from child process");
} else {
j6_system_log(" ... got unknown handle");
}
j6_system_log("main testing irqs");
j6_system_log("main testing irqs");
serial_port com2(COM2);
serial_port com2(COM2);
const char *fgseq = "\x1b[2J";
while (*fgseq)
com2.write(*fgseq++);
const char *fgseq = "\x1b[2J";
while (*fgseq)
com2.write(*fgseq++);
for (int i = 0; i < 10; ++i)
com2.write('%');
for (int i = 0; i < 10; ++i)
com2.write('%');
size_t len = 0;
while (true) {
result = j6_endpoint_receive(endp, &tag, &len, nullptr);
if (result != j6_status_ok)
return result;
size_t len = 0;
while (true) {
result = j6_endpoint_receive(endp, &tag, &len, nullptr);
if (result != j6_status_ok)
return result;
if (j6_tag_is_irq(tag))
j6_system_log("main thread got irq!");
}
if (j6_tag_is_irq(tag))
j6_system_log("main thread got irq!");
}
j6_system_log("main thread closing endpoint");
j6_system_log("main thread closing endpoint");
result = j6_object_close(endp);
if (result != j6_status_ok)
return result;
result = j6_object_close(endp);
if (result != j6_status_ok)
return result;
j6_system_log("main thread done, exiting");
return 0;
j6_system_log("main thread done, exiting");
return 0;
}

View File

@@ -3,39 +3,39 @@
serial_port::serial_port() :
m_port(0)
m_port(0)
{
}
serial_port::serial_port(uint16_t port) :
m_port(port)
m_port(port)
{
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable the Divisor Latch Access Bit
outb(port + 0, 0x01); // Divisor low bit: 1 (115200 baud)
outb(port + 1, 0x00); // Divisor high bit
outb(port + 3, 0x03); // 8-N-1
outb(port + 2, 0xe7); // Clear and enable FIFO, enable 64 byte, 56 byte trigger
outb(port + 4, 0x0b); // Data terminal ready, Request to send, aux output 2 (irq enable)
outb(port + 1, 0x03); // Enable interrupts
outb(port + 1, 0x00); // Disable all interrupts
outb(port + 3, 0x80); // Enable the Divisor Latch Access Bit
outb(port + 0, 0x01); // Divisor low bit: 1 (115200 baud)
outb(port + 1, 0x00); // Divisor high bit
outb(port + 3, 0x03); // 8-N-1
outb(port + 2, 0xe7); // Clear and enable FIFO, enable 64 byte, 56 byte trigger
outb(port + 4, 0x0b); // Data terminal ready, Request to send, aux output 2 (irq enable)
outb(port + 1, 0x03); // Enable interrupts
}
bool serial_port::read_ready() { return (inb(m_port + 5) & 0x01) != 0; }
bool serial_port::write_ready() {
uint8_t lsr = inb(m_port + 5);
return (lsr & 0x20) != 0;
uint8_t lsr = inb(m_port + 5);
return (lsr & 0x20) != 0;
}
char
serial_port::read() {
while (!read_ready());
return inb(m_port);
while (!read_ready());
return inb(m_port);
}
void
serial_port::write(char c) {
while (!write_ready());
outb(m_port, c);
while (!write_ready());
outb(m_port, c);
}

View File

@@ -8,19 +8,19 @@
class serial_port
{
public:
/// Constructor.
/// \arg port The IO address of the serial port
serial_port(uint16_t port);
/// Constructor.
/// \arg port The IO address of the serial port
serial_port(uint16_t port);
serial_port();
serial_port();
void write(char c);
char read();
void write(char c);
char read();
private:
uint16_t m_port;
uint16_t m_port;
bool read_ready();
bool write_ready();
bool read_ready();
bool write_ready();
};