Skip to content

Commit 93e35e0

Browse files
committed
Added
1 parent 9adfab6 commit 93e35e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+20309
-0
lines changed

01/MAKEFILE

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#############################################################
2+
# makefile for TC 2.01 and NASM 0.98 #
3+
# The C compiler, NASM and TLINK must be available via the #
4+
# PATH variable. Make sure TC_PATH is correct (see below). #
5+
#############################################################
6+
7+
TUT_NAME=tut01
8+
9+
TC_PATH=c:\tc
10+
LIB_PATH=$(TC_PATH)\lib
11+
12+
CC=tcc.exe
13+
CC_OPTIONS=-1 -k -c -k -ms
14+
15+
ASM=nasm.exe
16+
ASM_OPTIONS=-f obj
17+
18+
LINK=tlink.exe
19+
LINK_OPTIONS=/c /x
20+
21+
$(TUT_NAME).exe: $(TUT_NAME).obj pm.obj
22+
@$(LINK) $(LINK_OPTIONS) $(LIB_PATH)\c0s $(TUT_NAME) pm, $(TUT_NAME),, $(LIB_PATH)\cs.lib
23+
24+
$(TUT_NAME).obj: $(TUT_NAME).c pm.h
25+
@$(CC) $(CC_OPTIONS) $(TUT_NAME).c
26+
27+
pm.obj: pm.asm pm.h
28+
@$(ASM) pm.asm $(ASM_OPTIONS)
29+
30+
clean:
31+
make
32+
del *.obj

01/PM.ASM

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2+
;; PMode tutorials in C and Asm ;;
3+
;; Copyright (C) 2000 Alexei A. Frounze ;;
4+
;; The programs and sources come under the GPL ;;
5+
;; (GNU General Public License), for more information ;;
6+
;; read the file gnu-gpl.txt (originally named COPYING). ;;
7+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8+
9+
GLOBAL _read_msw, _read_cr0, _write_cr0
10+
11+
SEGMENT _TEXT PUBLIC CLASS=CODE USE16
12+
13+
_read_msw:
14+
smsw ax
15+
retn
16+
17+
_read_cr0:
18+
mov eax, cr0 ; read CR0 to eax
19+
mov edx, eax
20+
shr edx, 16 ; dx:ax = CR0 (return value)
21+
retn
22+
23+
_write_cr0:
24+
push bp
25+
mov bp, sp
26+
mov eax, [ss:bp+4] ; eax = 32-bit parameter
27+
mov cr0, eax
28+
pop bp
29+
retn
30+
31+
SEGMENT _DATA PUBLIC CLASS=DATA
32+


01/PM.H

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
PMode tutorials in C and Asm
3+
Copyright (C) 2000 Alexei A. Frounze
4+
The programs and sources come under the GPL
5+
(GNU General Public License), for more information
6+
read the file gnu-gpl.txt (originally named COPYING).
7+
*/
8+
9+
#ifndef _pm_h_
10+
#define _pm_h_
11+
12+
unsigned int read_msw();
13+
unsigned long read_cr0();
14+
void write_cr0 (unsigned long value);
15+
16+
#endif

01/TUT01.C

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
PMode tutorials in C and Asm
3+
Copyright (C) 2000 Alexei A. Frounze
4+
The programs and sources come under the GPL
5+
(GNU General Public License), for more information
6+
read the file gnu-gpl.txt (originally named COPYING).
7+
*/
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <conio.h>
12+
#include <dos.h>
13+
14+
#include "pm.h"
15+
16+
#define byte unsigned char
17+
#define word unsigned int
18+
19+
byte read_CMOS_reg (byte reg) {
20+
outportb (0x70, reg);
21+
return inportb (0x71);
22+
}
23+
24+
void write_CMOS_reg (byte reg, byte value) {
25+
outportb (0x70, reg);
26+
outportb (0x71, value);
27+
}
28+
29+
void delay_RTC (int secs) {
30+
byte x;
31+
while (secs--) {
32+
x = read_CMOS_reg(0); /* read seconds from RTC */
33+
while (read_CMOS_reg(0) == x); /* wait for the next value */
34+
};
35+
}
36+
37+
void my_exit() {
38+
printf ("\nWe're back...\n");
39+
printf ("\nPMode Tutorial by Alexei A. Frounze (c) 2000\n");
40+
printf ("E-mail : [email protected]\n");
41+
printf ("Homepage: http://alexfru.chat.ru\n");
42+
printf ("Mirror : http://members.xoom.com/alexfru\n");
43+
printf ("PMode...: http://welcome.to/pmode\n");
44+
}
45+
46+
int main() {
47+
unsigned long far *BIOS_timer = MK_FP (0x40, 0x6C);
48+
49+
clrscr();
50+
printf ("Welcome to the 1st PMode tutorial!\n\n");
51+
atexit (my_exit);
52+
53+
if (read_msw() & 1) {
54+
printf ("The CPU is already in PMode.\nAborting...");
55+
return 0;
56+
};
57+
58+
printf ("We're going to PMode using CR0 for 5 seconds...\n");
59+
60+
/* disable interrupts so that IRQs don't cause exceptions */
61+
disable();
62+
63+
/* disable NMIs as well */
64+
outportb (0x70, inportb(0x70) | 0x80);
65+
66+
/* WOW!!! This switches us to PMode just setting up CR0.PM bit to 1 */
67+
write_cr0 (read_cr0() | 1L);
68+
69+
/* a delay for 5 seconds */
70+
delay_RTC (5);
71+
72+
/* get out of PMode clearing CR0.PM bit to 0 */
73+
write_cr0 (read_cr0() & 0xFFFFFFFEL);
74+
75+
*BIOS_timer += 91L; /* 5*18.2 ticks total */
76+
77+
/* enable NMIs */
78+
outportb (0x70, inportb(0x70) & 0x7F);
79+
80+
/* enabling interrupts */
81+
enable();
82+
83+
return 0;
84+
}

01/TUT01.EXE

7.77 KB
Binary file not shown.

0 commit comments

Comments
 (0)