Repos / kernel.git / commitdiff
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4834be5)
raw | patch | inline | side by side (parent: 4834be5)
| author | zhaoyanbai <zhaoyanbai@126.com> | |
| Sun, 12 Oct 2014 01:01:27 +0000 (09:01 +0800) | ||
| committer | zhaoyanbai <zhaoyanbai@126.com> | |
| Wed, 3 Nov 2021 02:45:42 +0000 (10:45 +0800) |
| bin/shell.c | patch | blob | history | |
| drivers/console.c | patch | blob | history | |
| fs/bak.ext2.c | [deleted file] | patch | blob | history |
| include/system.h | patch | blob | history | |
| mm/kmalloc.c | [deleted file] | patch | blob | history |
| scripts/grub.cfg | patch | blob | history |
diff --git a/bin/shell.c b/bin/shell.c
--- a/bin/shell.c
+++ b/bin/shell.c
char cmd[256];
read(0, cmd, 256);
+ int len = strlen(cmd);
+ if(len > 0)
+ cmd[len-1] = 0;
+
int pid = fork();
if(pid > 0)
{
diff --git a/drivers/console.c b/drivers/console.c
--- a/drivers/console.c
+++ b/drivers/console.c
if(r)
{
- if(ch != '\n')
- buf[cnt++] = ch;
+ buf[cnt++] = ch;
task->state = TASK_RUNNING;
del_wait_queue(&rdwq, &wait);
diff --git a/fs/bak.ext2.c b/fs/bak.ext2.c
--- a/fs/bak.ext2.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
- *--------------------------------------------------------------------------
- * File Name: ext2.c
- *
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
- * Sun Feb 14 15:52:01 2010
- *
- * Description: none
- *
- *--------------------------------------------------------------------------
- */
-
-#if 0
-#include <fs.h>
-#include <system.h>
-#include <string.h>
-#include <stat.h>
-
-unsigned int ext2_start_sect;
-Inode ext2_root_inode;
-
-void hd_read(dev_t dev, u64 sect_nr, void *buf, u32 count) { /*TODO*/ }
-void ext2_read_block(int block_id, char *buf);
-static void ext2_print_group_descriptor(pGroupDesc p);
-static void ext2_print_inode(pInode p);
-int ext2_search_file(const char *file, const pInode in, pInode out);
-//char *ext2_loadfile(const char *path, size_t *file_size);
-
-/* ext2 super block */
-SuperBlock ext2_sb
- __attribute__((__aligned__(PAGE_SIZE)));
-Inode inode_table[NR_INODES]
- __attribute__((__aligned__(PAGE_SIZE))) = {{0,},};
-/*
- * ext2 group descriptor table
- * 其大小为一个EXT2_BLOCK_SIZE
- */
-static pGroupDesc gdesc;
-
-void setup_ext2()
-{
- int i;
-
- hd_read(ROOT_DEV, ext2_start_sect+2, EXT2_SB, sizeof(SuperBlock));
- printk("EXT2 SB:%x\n", sizeof(SuperBlock));
- printk("inodes count: %d\n", EXT2_SB->s_inodes_count);
- printk("blocks count: %d\n", EXT2_SB->s_blocks_count);
- printk("s_magic: %x\n", EXT2_SB->s_magic);
- printk("LOG BLOCK SIZE:%x\n", EXT2_SB->s_log_block_size);
- printk("Block Size:%d %x\n", EXT2_BLOCK_SIZE, EXT2_BLOCK_SIZE);
-
-
- if(EXT2_SB->s_magic != 0xEF53)
- panic("Only Support Ext2 File System...");
-
- /* 分配group descriptor table 的内存 */
- gdesc = (pGroupDesc) kmalloc_old(EXT2_BLOCK_SIZE);
- if(gdesc == NULL)
- panic("out of memory for ext2 group descritpor table");
- /* 初始化ext2 group descriptor table */
- ext2_read_block(EXT2_FIRST_BLOCK_ID+1, (char *)gdesc);
-#if 0
- printk("-------%d %d %d",
- EXT2_BLOCK_SIZE, EXT2_INODE_SIZE, EXT2_INODES_PER_BLOCK);
- for(i=0; i<12; i++)
- ext2_print_group_descriptor(gdesc+i);
-#endif
-
- ext2_read_inode(2, &ext2_root_inode);
-#if 1
- ext2_print_inode(&ext2_root_inode);
-#endif
-
-#if 0
- Inode boot_ino, grub_ino, grubconf_ino;
- int boot_n, grub_n, grubconf_n;
- boot_n = ext2_search_file("boot", &ext2_root_inode, &boot_ino);
- printk("boot_n:%d size:%d\n", boot_n, boot_ino.i_size);
- grub_n = ext2_search_file("grub", &boot_ino, &grub_ino);
- printk("grub_n:%d size:%d\n", grub_n, grub_ino.i_size);
- grubconf_n = ext2_search_file("grub.conf",
- &grub_ino, &grubconf_ino);
- printk("grubconf_n:%d size:%d\n", grubconf_n, grubconf_ino.i_size);
-#endif
-#if 0
- size_t filesz;
- char *buf=ext2_loadfile("/boot/grub/grub.conf", &filesz);
-
- for(i=0; i<filesz; i++)
- printk("%c", buf[i]);
-#endif
-#if 0
- unsigned char *p = (char *)kmalloc_old(EXT2_BLOCK_SIZE);
- ext2_read_block(0, p);
-
- for(i=0; i<512; i++)
- printk("%02x ", p[i]);
-#endif
-#if 0
- int dly = 0xF000000;
- while(dly--);
-#endif
-}
-
-void ext2_read_block(int block_id, char *buf)
-{
- u64 sect = EXT2_SECT;
- sect += block_id*EXT2_SECT_PER_BLOCK;
-
- //printk("block id: %d sect:%d\n", block_id, sect);
-
- hd_read(ROOT_DEV, sect, buf, EXT2_BLOCK_SIZE);
-}
-
-
-/*
- * 写这版ext2_read_inode的时候我想起了2008.12.16在0.2.1中写的
- * 那个 GetInode. 这两个函数完成的是同样的功能.但是很明显
- * 之前的那个版本写得那是相当的滑稽幼稚.甚至还有大大的BUG.
- * 但是正是这些点滴见证着我的内核的成长.
- */
-int ext2_read_inode(unsigned int n, pInode ino)
-{
- assert(1<=n && n <= EXT2_INODES_COUNT);
- if(n == EXT2_BAD_INO) return 0;
-
- unsigned int gnr; /* inode 所在的group的号 */
- unsigned int gidx; /* inode 所在的group的偏移 */
- unsigned int inotbl; /* inode table 的 block id */
-
-
- gnr = (n-1) / EXT2_INODES_PER_GROUP;
- gidx = (n-1) % EXT2_INODES_PER_GROUP;
-
- inotbl = (gdesc+gnr)->bg_inode_table;
-
- // 跳过完整的BLOCK
- inotbl += (gidx/EXT2_INODES_PER_BLOCK);
- gidx %= EXT2_INODES_PER_BLOCK;
-
-
- char *buf = kmalloc_old(EXT2_BLOCK_SIZE);
- if(buf == NULL)
- panic("faild read inode. out of memory");
- ext2_read_block(inotbl, buf);
-
- memcpy((void *)ino,(void*)(((pInode)buf)+gidx), EXT2_INODE_SIZE);
-
- kfree_old(buf);
-
- return n;
-}
-int ext2_read_file(const pInode ino, void *buf, size_t count)
-{
- int i, blks;
- void *p;
-
- blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
- assert(blks>0);
-
- if(blks > EXT2_NDIR_BLOCKS)
- panic("file too large to read");
-
- p = kmalloc_old(blks*EXT2_BLOCK_SIZE);
-
- if(p == NULL)
- panic("out of memory when search inode in directory");
-
- for(i=0; i<blks; i++)
- {
- ext2_read_block(ino->i_block[i],
- (char *)(i*EXT2_BLOCK_SIZE + (unsigned long)p));
- }
-
- memcpy(buf, p, count);
-
- kfree_old(p);
-
- return count;
-}
-#if 0
-char *load_inode_content(const pInode ino)
-{
- int i, blks;
- char *buf;
-
- blks = (ino->i_size+EXT2_BLOCK_SIZE-1)/EXT2_BLOCK_SIZE;
- assert(blks>0);
- if(blks > EXT2_NDIR_BLOCKS)
- panic("unsupport file large than 12KB");
-
-
- buf = kmalloc_old(blks*EXT2_BLOCK_SIZE);
- if(buf == NULL)
- panic("out of memory when search inode in directory");
- for(i=0; i<blks; i++)
- {
- ext2_read_block(ino->i_block[i], buf + i*EXT2_BLOCK_SIZE);
- }
-
- return buf;
-}
-#endif
-
-/*
- * 从in中查找file从out返回
- * int 型的函数返回值的意思是inode号
- * 失败则返回的是EXT2_BAD_INO
- */
-int ext2_search_file(const char *file, const pInode in, pInode out)
-{
- assert(file != NULL);
- assert(in != NULL);
- assert(S_ISDIR(in->i_mode));
-
- char *buf;
-#if 0
- buf = load_inode_content(in);
-#else
- buf = kmalloc_old(in->i_size);
- ext2_read_file(in, buf, in->i_size);
-#endif
-
- pDirEnt ent = (pDirEnt)buf;
- int len = strlen(file);
- int inode_n = EXT2_BAD_INO;
- while(ent < (pDirEnt)(buf + in->i_size))
- {
- if(ent->name_len == len)
- {
- if(strncmp(file, ent->name, ent->name_len) == 0)
- {
- inode_n = ent->inode;
-#if 0
- printk("file: %s\n", ent->name);
-#endif
- break;
- }
- }
-
-
- ent = (pDirEnt)(ent->rec_len + (unsigned long)ent);
- }
- kfree_old(buf);
-
- ext2_read_inode(inode_n, out);
-
- return inode_n;
-}
-
-
-static int get_filename_from_path(const char *path, char *filename)
-{
- int i = 0;
-
- while(*path != '/' && *path != '\0')
- {
- filename[i++] = *path++;
- }
- filename[i] = 0;
-
-
- return i; // file name len
-}
-
-
-int ext2_get_file_inode_nr(const char *path)
-{
- assert(*path++ == '/'); /* 目前只支持从根目录开始的路径 */
- Inode ino = ext2_root_inode;
- int ino_nr, len;
- char file[EXT2_NAME_LEN];
-
- while((len=get_filename_from_path(path, file)) != 0)
- {
-#if 0
- printk("file: %s ", file);
-#endif
- ino_nr = ext2_search_file(file, &ino, &ino);
-
- path += len;
-
- if(*path != 0)
- path++;
- }
-#if 0
- printk("ino_nr:%d\n", ino_nr);
-#endif
- return ino_nr;
-}
-
-#if 0
-/*
- * 需要自己释放内存
- */
-char *ext2_loadfile(const char *path, size_t *file_size)
-{
- char *buf;
- buf = load_inode_content(&inode);
- *file_size = inode.i_size;
-
- return buf;
-}
-#endif
-
-static void ext2_print_group_descriptor(pGroupDesc p)
-{
- printk("block bitmap:%d inode bitmap:%d inode table:%d\n",
- p->bg_block_bitmap,
- p->bg_inode_bitmap,
- p->bg_inode_table);
-}
-
-static void ext2_print_inode(pInode p)
-{
- printk("i_mode:%04x i_size:%d i_blocks:%d\n",
- p->i_mode, p->i_size, p->i_blocks);
-}
-#endif
diff --git a/include/system.h b/include/system.h
--- a/include/system.h
+++ b/include/system.h
void *kmalloc(size_t size, gfp_t gfpflags);
void kfree(void *addr);
-void *kmalloc_old(size_t size);
-void kfree_old(void *p);
-
-static inline void *get_virt_pages(unsigned int n)
-{
- assert(n>0);
- size_t size = n << PAGE_SHIFT;
- return (void*) kmalloc_old(size);
-}
-static inline void free_virt_pages(void *p)
-{
- kfree_old((void *)p);
-}
-static inline void *get_phys_pages(unsigned int n)
-{
-/*
- assert(n>0);
- size_t size = n << PAGE_SHIFT;
- return (void*) va2pa(kmalloc_old(size));
-*/
- return (void *)va2pa(get_virt_pages(n));
-}
-static inline void free_phys_pages(void *p)
-{
- free_virt_pages((void*)va2pa(p));
-}
-
#define panic(msg, ...) do { \
asm("cli;"); \
printk("PANIC:" \
#define ALIGN(x, a) (((x)+(a)-1) & ~((a)-1))
-
// 1 GB
#define MAX_SUPT_PHYMM_SIZE (1UL<<30)
INDEX_EMP8,
INDEX_TSS,
};
-#if 0
-// pushal push eax, ecx, edx, ebx, esp, ebp, esi, edi
-typedef struct pt_regs
-{
- u32 edi;
- u32 esi;
- u32 ebp;
- u32 ebx;
- u32 edx;
- u32 ecx;
- u32 eax;
- u16 ds, _ds;
- u16 es, _es;
- u16 fs, _fs;
- u16 gs, _gs;
- union
- {
- u32 irq;
- u32 errcode;
- };
- u32 eip;
- u16 cs, _cs;
- u32 eflags;
- u32 esp;
- u16 ss, _ss;
-} __attribute__((packed)) pt_regs_t;
-#else
+
typedef struct pt_regs
{
u32 ebx;
u32 esp;
u16 ss, _ss;
} __attribute__((packed)) pt_regs_t;
-#endif
typedef unsigned long dev_t;
#define REBOOT_RESTART 0x00
#define REBOOT_POWEROFF 0x01
-
-#define ROOT_DEV system.root_dev
-
#define KRNL_INIT_STACK_SIZE 4096
#endif //_SYSTEM_H
diff --git a/mm/kmalloc.c b/mm/kmalloc.c
--- a/mm/kmalloc.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *--------------------------------------------------------------------------
- * File Name: kmalloc_old.c
- *
- * Author: Zhao Yanbai [zhaoyanbai@126.com]
- * Sat Jan 30 12:15:51 2010
- *
- * Description: 现在的版本实现得非常简单,简陋。不能分配大于32*4K的内存
- * 另外小于32*4K的都按32*4K分配
- * 以后再来重写这里吧
- *--------------------------------------------------------------------------
- */
-#include <page.h>
-#include <types.h>
-#include <assert.h>
-#include <system.h>
-
-static int get_order(size_t size)
-{
- int i;
- return i;
-}
-void *kmalloc_old(size_t size)
-{
- void *p;
- return p;
-}
-
-
-void kfree_old(void *p)
-{
-
-}
diff --git a/scripts/grub.cfg b/scripts/grub.cfg
--- a/scripts/grub.cfg
+++ b/scripts/grub.cfg
root=(hd0,msdos1)
menuentry 'Kernel' --class os {
- multiboot /boot/Kernel root=hda0 delay=20000000
+ multiboot /boot/Kernel root=hda0 delay=2
}