提交 9a05fbf3 编写于 作者: R rain

make assembly macros

上级 03e631dc
......@@ -26,3 +26,5 @@
2021-3-12 1.384: 1384 lines, 20 files, rain
2021-3-13 1.440: 1440 lines, 21 files, rain
......@@ -58,3 +58,6 @@ Cunix kernel
`1.384s-hal`:
    use text VGA mode, and make a file-operations of it.
`1.440s-lib`:
    make some macros about assembly
/* Copyright (C) 2021 Rain */
/* This file is part of Cunix. */
/*
Cunix is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) and later version.
*/
/*
Cunix is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/*
You should have received a copy of the GNU General Public License
along with Cunix. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_SYS_H
#define INCLUDED_SYS_H
#include <kernel/types.h>
#define sgdt(addr) __asm__ __volatile__ ("sgdt %0" : "=m" (addr) : :)
#define lgdt(addr) __asm__ __volatile__ ("lgdt %0" : : "m" (addr))
#define sidt(addr) __asm__ __volatile__ ("sidt %0" : "=m" (addr) : :)
#define lidt(addr) __asm__ __volatile__ ("lidt %0" : : "m" (addr))
#define pause() __asm__ __volatile__ ("pause");
#define nop() __asm__ __volatile__ ("nop");
#define hlt() __asm__ __volatile__ ("hlt");
#endif
......@@ -33,6 +33,10 @@
#define KERNEL_CS 0x0008
#define KERNEL_DS 0x0010
struct inode_desc {
/* this struct is a general descriptor, so we must know
* how big is it. */
......
......@@ -33,7 +33,7 @@
#include <kernel/vgatext.h>
__uint32_t print(struct vga_inode *inode, char *s);
__uint32_t print(char *s);
#endif
......@@ -40,6 +40,7 @@
extern struct file_operations vga;
struct vga_inode {
struct inode_desc inode;
......@@ -55,5 +56,7 @@ struct vga_inode {
__uint32_t x, y;
};
extern struct vga_inode stdout;
#endif
......@@ -38,6 +38,8 @@
__uint32_t next_fd = 1;
struct vga_inode stdout;
struct inode_desc *vga_open(char *name, __uint32_t type, __uint32_t mode, errno_t *errno) {
*errno = -E_NOSUPP;
......@@ -137,9 +139,9 @@ errno_t vga_write(struct vga_inode *inode, char *buffer, __uint64_t l) {
}
errno_t vga_lseek(struct inode_desc *inode, __uint32_t off, __uint32_t seg) {
return -E_HNOSUP;
}
extern errno_t vga_lseek(struct inode_desc *inode, __uint32_t off, __uint32_t seg);
__asm__ ("vga_lseek: ret\n");
void vga_close(struct inode_desc *inode) {
......
......@@ -28,13 +28,16 @@
#include <kernel/types.h>
#include <kernel/errno.h>
#include <kernel/int.h>
#include <kernel/vgatext.h>
#include <kernel/print.h>
void init(void) {
struct vga_inode vi;
vga.fill(NULL, 0, 0, &vi);
print(&vi, "kernel starting\n");
vga.fill(NULL, 0, 0, &stdout);
print("kernel starting\n");
for (;;);
}
......@@ -31,9 +31,9 @@
#include <kernel/vgatext.h>
errno_t print(struct vga_inode *inode, char *s) {
errno_t print(char *s) {
for (; *s; s++) {
vga.write(inode, s, 1);
vga.write(&stdout, s, 1);
}
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册