diff --git a/LINES b/LINES
index da28e3865a60695fa285886a3681918b5fbc332b..f016ac91697eea242033e29fe18845343302160c 100644
--- a/LINES
+++ b/LINES
@@ -26,3 +26,5 @@
2021-3-12 1.384: 1384 lines, 20 files, rain
+2021-3-13 1.440: 1440 lines, 21 files, rain
+
diff --git a/README.md b/README.md
index 1582b5b4743d565f9952b439c7c5eac5b8204733..c4da77d5777204522cf863b66a2a7c2e8c2ce77d 100644
--- a/README.md
+++ b/README.md
@@ -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
+
diff --git a/include/arch/sys.h b/include/arch/sys.h
new file mode 100644
index 0000000000000000000000000000000000000000..717202f31213a3ec0eff6b6bbc4b1e702ef21798
--- /dev/null
+++ b/include/arch/sys.h
@@ -0,0 +1,44 @@
+/* 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 .
+*/
+
+
+
+#ifndef INCLUDED_SYS_H
+#define INCLUDED_SYS_H
+
+#include
+
+
+#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
diff --git a/include/kernel/init.h b/include/kernel/init.h
index cb2130bb0a09811f73a5f56a3b3af656fdbacd32..0f2c2b67455bf831c122a3056b7b6de4f98badfd 100644
--- a/include/kernel/init.h
+++ b/include/kernel/init.h
@@ -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. */
diff --git a/include/kernel/print.h b/include/kernel/print.h
index 90a21480133c11baf7ca2a6c0ccc758fb20b36e3..7c79b98bc2c456fa97df1d7b93ca756597260996 100644
--- a/include/kernel/print.h
+++ b/include/kernel/print.h
@@ -33,7 +33,7 @@
#include
-__uint32_t print(struct vga_inode *inode, char *s);
+__uint32_t print(char *s);
#endif
diff --git a/include/kernel/vgatext.h b/include/kernel/vgatext.h
index 18473aec15029f64516ee38c82f49f53a7a925aa..d1135c33473e04dd46c88e43fc09107000438d9a 100644
--- a/include/kernel/vgatext.h
+++ b/include/kernel/vgatext.h
@@ -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
diff --git a/kernel/Makefile b/kernel/Makefile
index 210d2da65f798d9ab3853c2aa1ea8510e873c01b..d3cd48993bcc6c4c0696dcad4f5ae87245e4e5e3 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -4,7 +4,7 @@ default:
make -C lib/
make kernel.bin
-kernel.o: init/main.o hal/vgatext/vgatext.o lib/bitmap.o lib/bitman.o init/print.o
+kernel.o: init/main.o hal/vgatext/vgatext.o lib/bitmap.o lib/bitman.o init/print.o
ld -b elf64-x86-64 -o kernel.o init/main.o init/print.o hal/vgatext/vgatext.o lib/bitmap.o lib/bitman.o -T kernel.lds
kernel.bin: kernel.o
diff --git a/kernel/hal/vgatext/vgatext.c b/kernel/hal/vgatext/vgatext.c
index 631ce1c3fbd85c35af7827fdc9e2822a97b010c8..061082843e19ca71a4fc625f980330357e96ef75 100644
--- a/kernel/hal/vgatext/vgatext.c
+++ b/kernel/hal/vgatext/vgatext.c
@@ -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) {
diff --git a/kernel/init/Makefile b/kernel/init/Makefile
index f6c63cb9256eb632538390121acbf3b210c1a346..a5b9966daa32de5caa3d7e41c411241b2678c83e 100644
--- a/kernel/init/Makefile
+++ b/kernel/init/Makefile
@@ -1,6 +1,6 @@
C_FLAGS = -mcmodel=large -fno-builtin -m64 -I ../../include/
-all: main.o print.o
+all: main.o print.o
%.o: %.c
gcc -c $*.c $(C_FLAGS)
diff --git a/kernel/init/main.c b/kernel/init/main.c
index e30578b52caa167ebf5fb33adc85e809bdc663c7..9ebd8961700570a6dbba8928ad786d1e42ae9a76 100644
--- a/kernel/init/main.c
+++ b/kernel/init/main.c
@@ -28,13 +28,16 @@
#include
#include
+#include
#include
#include
+
+
+
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 (;;);
}
diff --git a/kernel/init/print.c b/kernel/init/print.c
index d65241adee31bbf6c47de05ec15e46fe78c04617..b9ad709111d35101dc65bc27125810ea58fcf0bc 100644
--- a/kernel/init/print.c
+++ b/kernel/init/print.c
@@ -31,9 +31,9 @@
#include
-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;