[update] os

This commit is contained in:
bLueriVerLHR
2023-06-26 09:56:22 +08:00
parent 75644e4920
commit c931384e30
10 changed files with 125 additions and 31 deletions

3
laos/src/dev/dev.c Normal file
View File

@@ -0,0 +1,3 @@
#include "dev.h"
char ioports[];

View File

@@ -2,27 +2,27 @@
#include "memio.h"
#include "memlayout.h"
#include "spinlock.h"
#include "dev.h"
void consputc(int c) {
if (c == '\b') {
memb(SERIAL_ADDR) = '\b';
memb(SERIAL_ADDR) = ' ';
memb(SERIAL_ADDR) = '\b';
return;
}
volatile char *out = &ioports[SERIAL_OFFSET];
if (c == '\b') {
*out = '\b';
*out = ' ';
*out = '\b';
return;
}
memb(SERIAL_ADDR) = c;
*out = c;
}
struct {
struct spinlock lock;
// input
#define INPUT_BUF_SIZE 128
char buf[INPUT_BUF_SIZE];
uint r; // Read index
uint w; // Write index
uint e; // Edit index
uint r; // Read index
uint w; // Write index
uint e; // Edit index
} cons;

View File

@@ -29,11 +29,9 @@ int main(int argc, char *argv[]) {
char *tok = strtok(input, " ");
while (tok) {
if (*tok != '\n') {
args = realloc(args, (argc + 1) * sizeof(char *));
args[argc] = tok;
argc += 1;
}
args = realloc(args, (argc + 1) * sizeof(char *));
args[argc] = tok;
argc += 1;
tok = strtok(NULL, " ");
}

71
laos/src/util/filepath.c Normal file
View File

@@ -0,0 +1,71 @@
#include "defs.h"
//
// bnm should be large enough to hold basename
//
char *basename(char *bnm, const char *path) {
const char *p = path;
const char *last_slash = NULL;
while (*p) {
if (*p == '/' || *p == '\\') {
last_slash = p;
}
p++;
}
char *q = bnm;
p = last_slash + 1;
while (*p) {
*q++ = *p++;
}
return bnm;
}
//
// noext should be large enough to hold no-ext name
//
char *rmext(char *noext, const char *fname) {
const char *p = fname;
const char *last_dot = NULL;
while (*p) {
if (*p == '.') {
last_dot = p;
}
p++;
}
char *q = noext;
p = fname;
while (p != last_dot) {
*q++ = *p++;
}
return noext;
}
//
// bnm should be large enough to hold bearname name
//
char *bearname(char *bnm, const char *fname) {
const char *p = fname;
const char *last_slash = NULL;
const char *last_dot = NULL;
while (*p) {
if (*p == '/' || *p == '\\') {
last_slash = p;
} else if (*p == '.') {
last_dot = p;
}
p++;
}
char *q = bnm;
p = last_slash + 1;
while (p != last_dot) {
*q++ = *p++;
}
return bnm;
}