Skip to content

Commit

Permalink
Cleanup library
Browse files Browse the repository at this point in the history
  • Loading branch information
yhzhang0128 committed Oct 10, 2022
1 parent 3dad9ea commit 4da21ed
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
4 changes: 2 additions & 2 deletions library/egos.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extern struct grass *grass;
#define CRITICAL earth->tty_critical
#endif

/* memory layout */
/* Memory layout */
#define PAGE_SIZE 4096
#define FRAME_CACHE_END 0x80020000
#define FRAME_CACHE_START 0x80004000 /* 112KB frame cache */
Expand All @@ -73,7 +73,7 @@ extern struct grass *grass;
/* 12KB earth data */
/* earth code is in QSPI flash */

/* memory-mapped I/O register access macros */
/* Memory-mapped I/O register access macros */
#define ACCESS(x) (*(__typeof__(*x) volatile *)(x))
#define REGW(base, offset) (ACCESS((unsigned int*)(base + offset)))
#define REGB(base, offset) (ACCESS((unsigned char*)(base + offset)))
8 changes: 4 additions & 4 deletions library/elf/elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

/* Author: Yunhao Zhang
* Description: Load an ELF-format executable file into memory;
* Only using the program header instead of the multiple section headers.
* Description: load an ELF-format executable file into memory
* Only use the program header instead of the multiple section headers.
*/

#include "egos.h"
Expand Down Expand Up @@ -41,7 +41,7 @@ static void load_app(int pid, elf_reader reader,
int frame_no, block_offset = pheader->p_offset / BLOCK_SIZE;
unsigned int code_start = APPS_ENTRY >> 12, stack_start = APPS_ARG >> 12;

/* Load the text, rodata, data and bss sections */
/* Setup the text, rodata, data and bss sections */
for (int off = 0; off < pheader->p_filesz; off += BLOCK_SIZE) {
if (off % PAGE_SIZE == 0) {
earth->mmu_alloc(&frame_no, &base);
Expand All @@ -60,7 +60,7 @@ static void load_app(int pid, elf_reader reader,
memset((char*)base, 0, PAGE_SIZE);
}

/* Allocate two pages for argc, argv and stack */
/* Setup two pages for argc, argv and stack */
earth->mmu_alloc(&frame_no, &base);
earth->mmu_map(pid, stack_start++, frame_no);

Expand Down
12 changes: 6 additions & 6 deletions library/file/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@ static int disk_getsize() { return FS_DISK_SIZE / BLOCK_SIZE; }

static int disk_setsize() { FATAL("disk: cannot set the size"); }

static int disk_read(inode_intf bs, int ino, block_no offset, block_t *block) {
static int disk_read(inode_intf bs, unsigned int ino, block_no offset, block_t *block) {
return earth->disk_read(GRASS_FS_START + offset, 1, block->bytes);
}

static int disk_write(inode_intf bs, int ino, block_no offset, block_t *block) {
static int disk_write(inode_intf bs, unsigned int ino, block_no offset, block_t *block) {
return earth->disk_write(GRASS_FS_START + offset, 1, block->bytes);
}

static inode_store_t disk;

inode_intf fs_disk_init() {
disk.read = (void*)disk_read;
disk.write = (void*)disk_write;
disk.getsize = (void*)disk_getsize;
disk.setsize = (void*)disk_setsize;
disk.read = disk_read;
disk.write = disk_write;
disk.getsize = disk_getsize;
disk.setsize = disk_setsize;

return &disk;
}
5 changes: 3 additions & 2 deletions library/libc/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
extern char __heap_start, __heap_end;
static char* brk = &__heap_start;

/* malloc() and free() manage the memory region [&__heap_start, brk]
* if malloc() finds this region to be too small, it will call _sbrk()
/* malloc() and free() are linked from the compiler's C library;
* malloc() and free() manage the memory region [&__heap_start, brk).
* If malloc() finds this region to be too small, it will call _sbrk().
*/

char *_sbrk(int size) {
Expand Down
5 changes: 3 additions & 2 deletions library/libc/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#include "egos.h"
#include <unistd.h>

/* printf() constructs a string based on its arguments
* and then print the string to tty by calling _write()
/* printf() is linked from the compiler's C library;
* printf() constructs a string based on its arguments
* and prints the string to the tty device by calling _write().
*/

int _write(int file, char *ptr, int len) {
Expand Down
3 changes: 2 additions & 1 deletion library/servers/servers.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
*/

/* Author: Yunhao Zhang
* Description: user friendly interfaces of the system servers
* Description: user friendly interfaces of system processes
* including GPID_PROCESS, GPID_FILE and GPID_DIR
*/

#include "egos.h"
Expand Down

0 comments on commit 4da21ed

Please sign in to comment.