summaryrefslogtreecommitdiffstats
path: root/src/include/asm
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-01-23 10:41:10 +0800
committerWe-unite <3205135446@qq.com>2025-01-23 10:41:10 +0800
commite6f77b7ea3e38c9853bee60b275f3f89d252a5b3 (patch)
tree80bfbabed9d4cbcf9fa62677f78b34279d7e2f87 /src/include/asm
downloadlinux-0.11-master.tar.gz
linux-0.11-master.zip
Initial commit, makee it usable on newest linuxHEADmaster
Diffstat (limited to 'src/include/asm')
-rw-r--r--src/include/asm/io.h24
-rw-r--r--src/include/asm/memory.h14
-rw-r--r--src/include/asm/segment.h65
-rw-r--r--src/include/asm/system.h67
4 files changed, 170 insertions, 0 deletions
diff --git a/src/include/asm/io.h b/src/include/asm/io.h
new file mode 100644
index 0000000..d5cc42a
--- /dev/null
+++ b/src/include/asm/io.h
@@ -0,0 +1,24 @@
1#define outb(value,port) \
2__asm__ ("outb %%al,%%dx"::"a" (value),"d" (port))
3
4
5#define inb(port) ({ \
6unsigned char _v; \
7__asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \
8_v; \
9})
10
11#define outb_p(value,port) \
12__asm__ ("outb %%al,%%dx\n" \
13 "\tjmp 1f\n" \
14 "1:\tjmp 1f\n" \
15 "1:"::"a" (value),"d" (port))
16
17#define inb_p(port) ({ \
18unsigned char _v; \
19__asm__ volatile ("inb %%dx,%%al\n" \
20 "\tjmp 1f\n" \
21 "1:\tjmp 1f\n" \
22 "1:":"=a" (_v):"d" (port)); \
23_v; \
24})
diff --git a/src/include/asm/memory.h b/src/include/asm/memory.h
new file mode 100644
index 0000000..8aa6d52
--- /dev/null
+++ b/src/include/asm/memory.h
@@ -0,0 +1,14 @@
1/*
2 * NOTE!!! memcpy(dest,src,n) assumes ds=es=normal data segment. This
3 * goes for all kernel functions (ds=es=kernel space, fs=local data,
4 * gs=null), as well as for all well-behaving user programs (ds=es=
5 * user data space). This is NOT a bug, as any user program that changes
6 * es deserves to die if it isn't careful.
7 */
8//#define memcpy(dest,src,n) ({ \
9//void * _res = dest; \
10//__asm__ __volatile__ ("cld;rep;movsb" \
11// ::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \
12// ); \
13//_res; \
14//})
diff --git a/src/include/asm/segment.h b/src/include/asm/segment.h
new file mode 100644
index 0000000..94dd102
--- /dev/null
+++ b/src/include/asm/segment.h
@@ -0,0 +1,65 @@
1static inline unsigned char get_fs_byte(const char * addr)
2{
3 unsigned register char _v;
4
5 __asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr));
6 return _v;
7}
8
9static inline unsigned short get_fs_word(const unsigned short *addr)
10{
11 unsigned short _v;
12
13 __asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr));
14 return _v;
15}
16
17static inline unsigned long get_fs_long(const unsigned long *addr)
18{
19 unsigned long _v;
20
21 __asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \
22 return _v;
23}
24
25static inline void put_fs_byte(char val,char *addr)
26{
27__asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr));
28}
29
30static inline void put_fs_word(short val,short * addr)
31{
32__asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr));
33}
34
35static inline void put_fs_long(unsigned long val,unsigned long * addr)
36{
37__asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr));
38}
39
40/*
41 * Someone who knows GNU asm better than I should double check the followig.
42 * It seems to work, but I don't know if I'm doing something subtly wrong.
43 * --- TYT, 11/24/91
44 * [ nothing wrong here, Linus ]
45 */
46
47static inline unsigned long get_fs()
48{
49 unsigned short _v;
50 __asm__("mov %%fs,%%ax":"=a" (_v):);
51 return _v;
52}
53
54static inline unsigned long get_ds()
55{
56 unsigned short _v;
57 __asm__("mov %%ds,%%ax":"=a" (_v):);
58 return _v;
59}
60
61static inline void set_fs(unsigned long val)
62{
63 __asm__("mov %0,%%fs"::"a" ((unsigned short) val));
64}
65
diff --git a/src/include/asm/system.h b/src/include/asm/system.h
new file mode 100644
index 0000000..9bc027a
--- /dev/null
+++ b/src/include/asm/system.h
@@ -0,0 +1,67 @@
1#define move_to_user_mode() \
2__asm__ ("movl %%esp,%%eax\n\t" \
3 "pushl $0x17\n\t" \
4 "pushl %%eax\n\t" \
5 "pushfl\n\t" \
6 "pushl $0x0f\n\t" \
7 "pushl $1f\n\t" \
8 "iret\n" \
9 "1:\tmovl $0x17,%%eax\n\t" \
10 "movw %%ax,%%ds\n\t" \
11 "movw %%ax,%%es\n\t" \
12 "movw %%ax,%%fs\n\t" \
13 "movw %%ax,%%gs" \
14 :::"ax")
15
16#define sti() __asm__ ("sti"::)
17#define cli() __asm__ ("cli"::)
18#define nop() __asm__ ("nop"::)
19
20#define iret() __asm__ ("iret"::)
21
22#define _set_gate(gate_addr,type,dpl,addr) \
23__asm__ ("movw %%dx,%%ax\n\t" \
24 "movw %0,%%dx\n\t" \
25 "movl %%eax,%1\n\t" \
26 "movl %%edx,%2" \
27 : \
28 : "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
29 "o" (*((char *) (gate_addr))), \
30 "o" (*(4+(char *) (gate_addr))), \
31 "d" ((char *) (addr)),"a" (0x00080000))
32
33#define set_intr_gate(n,addr) \
34 _set_gate(&idt[n],14,0,addr)
35
36#define set_trap_gate(n,addr) \
37 _set_gate(&idt[n],15,0,addr)
38
39#define set_system_gate(n,addr) \
40 _set_gate(&idt[n],15,3,addr)
41
42#define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
43 *(gate_addr) = ((base) & 0xff000000) | \
44 (((base) & 0x00ff0000)>>16) | \
45 ((limit) & 0xf0000) | \
46 ((dpl)<<13) | \
47 (0x00408000) | \
48 ((type)<<8); \
49 *((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \
50 ((limit) & 0x0ffff); }
51
52#define _set_tssldt_desc(n,addr,type) \
53__asm__ ("movw $104,%1\n\t" \
54 "movw %%ax,%2\n\t" \
55 "rorl $16,%%eax\n\t" \
56 "movb %%al,%3\n\t" \
57 "movb $" type ",%4\n\t" \
58 "movb $0x00,%5\n\t" \
59 "movb %%ah,%6\n\t" \
60 "rorl $16,%%eax" \
61 ::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
62 "m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
63 )
64
65#define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x89")
66#define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),((int)(addr)),"0x82")
67