XINU
Functions
kprintf.c File Reference

Kernel用のputc()、getc()、printf()を提供し、コンソールに対して文字のRead/Writeを行う。 More...

#include <xinu.h>
#include <stdarg.h>
Include dependency graph for kprintf.c:

Go to the source code of this file.

Functions

void _doprnt (char *, va_list, int(*)(int), int)
 
syscall kgetc (void)
 ポーリングI/Oを使用して、コンソールのシリアルラインから文字を読み取る。 More...
 
syscall kprintf (char *fmt,...)
 Kernel用のprintf()であり、コンソールにフォーマットされた文字列を表示する。 More...
 
syscall kputc (byte c)
 ポーリングI/Oを使用して、コンソールのシリアルラインに文字を書き込む。 More...
 

Detailed Description

Kernel用のputc()、getc()、printf()を提供し、コンソールに対して文字のRead/Writeを行う。

Definition in file kprintf.c.

Function Documentation

◆ _doprnt()

void _doprnt ( char *  ,
va_list  ,
int(*)(int)  ,
int   
)

Referenced by kgetc(), and kprintf().

Here is the caller graph for this function:

◆ kgetc()

syscall kgetc ( void  )

ポーリングI/Oを使用して、コンソールのシリアルラインから文字を読み取る。

Definition at line 59 of file kprintf.c.

References _doprnt(), CONSOLE, devtab, disable(), dentry::dvcsr, uart_csreg::ier, uart_csreg::lsr, restore(), and UART_LSR_DR.

60 {
61  int irmask;
62  volatile struct uart_csreg *regptr;
63  byte c;
64  struct dentry *devptr;
65  intmask mask;
66 
67  /* Disable interrupts */
68  mask = disable();
69 
70  devptr = (struct dentry *)&devtab[CONSOLE];
71  regptr = (struct uart_csreg *)devptr->dvcsr;
72 
73  irmask = regptr->ier; /* Save UART interrupt state. */
74  regptr->ier = 0; /* Disable UART interrupts. */
75 
76  while (0 == (regptr->lsr & UART_LSR_DR))
77  {
78  ; /* Do Nothing */
79  }
80 
81  /* Read character from Receive Holding Register */
82 
83  c = regptr->rbr;
84  regptr->ier = irmask; /* Restore UART interrupts. */
85 
86  restore(mask);
87  return c;
88 }
unsigned char byte
符号なし8ビット値(unsigned char)
Definition: kernel.h:7
volatile uint32 lsr
Definition: uart.h:22
void restore(intmask)
#define CONSOLE
Definition: conf.h:28
volatile uint32 ier
Definition: uart.h:17
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
void * dvcsr
Definition: conf.h:19
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
#define UART_LSR_DR
Definition: uart.h:101
Here is the call graph for this function:

◆ kprintf()

syscall kprintf ( char *  fmt,
  ... 
)

Kernel用のprintf()であり、コンソールにフォーマットされた文字列を表示する。

ポーリングI/Oを使用して、フォーマットされた文字列をコンソールに出力する。

Polled I/Oを使用したシステムコール。

Parameters
[in]fmt文字列を表示する際のフォーマット情報
[in]...可変長引数

Definition at line 98 of file kprintf.c.

References _doprnt(), CONSOLE, devtab, kputc(), OK, va_end, and va_start.

Referenced by arp_alloc(), arp_dump(), arp_in(), dhcp_bld_req(), dnslookup(), ethinit(), ethread(), getlocalip(), hexadump(), hexdump(), ip_enqueue(), ip_in(), ipout(), irq_dispatch(), lflcontrol(), lfsckfmt(), lfsopen(), main(), naminit(), nulluser(), panic(), pdump(), pdumph(), rdscomm(), rdscontrol(), rdsopen(), rflread(), rflwrite(), rfscomm(), rfscontrol(), rfsndmsg(), rfsopen(), startup(), stop(), sysinit(), tftp_send1(), tftpget_mb(), xdone(), and xsh_rdstest().

99 {
100  va_list ap;
101 
102  va_start(ap, fmt);
103  _doprnt(fmt, ap, (int (*)(int))kputc, (int)&devtab[CONSOLE]);
104  va_end(ap);
105  return OK;
106 }
#define CONSOLE
Definition: conf.h:28
#define OK
処理が成功した場合
Definition: kernel.h:77
void _doprnt(char *, va_list, int(*)(int), int)
#define va_start(last, va)
va_list型を初期化し、可変長引数の使用を開始する。
Definition: stdarg.h:25
struct dentry devtab[]
Definition: conf.c:11
#define va_end(va)
可変長引数の処理を終了する。
Definition: stdarg.h:42
__builtin_va_list va_list
可変個の実引数を扱うための情報を保持するための型(__builtin_va_listはGCCに定義された型) ...
Definition: stdarg.h:7
syscall kputc(byte c)
ポーリングI/Oを使用して、コンソールのシリアルラインに文字を書き込む。
Definition: kprintf.c:13
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kputc()

syscall kputc ( byte  c)

ポーリングI/Oを使用して、コンソールのシリアルラインに文字を書き込む。

Definition at line 13 of file kprintf.c.

References uart_csreg::buffer, CONSOLE, devtab, disable(), dentry::dvcsr, uart_csreg::lsr, OK, restore(), and UART_LSR_THRE.

Referenced by kprintf().

16 {
17  struct dentry *devptr;
18  volatile struct uart_csreg *csrptr;
19  intmask mask;
20 
21  /* Disable interrupts */
22  mask = disable();
23 
24  /* Get CSR address of the console */
25 
26  devptr = (struct dentry *)&devtab[CONSOLE];
27  csrptr = (struct uart_csreg *)devptr->dvcsr;
28 
29  /* wait for UART transmit queue to empty */
30 
31  while ((csrptr->lsr & UART_LSR_THRE) == 0)
32  {
33  ;
34  }
35 
36  /* write the character */
37 
38  csrptr->buffer = c;
39 
40  /* Honor CRLF - when writing NEWLINE also send CARRIAGE RETURN */
41 
42  if (c == '\n')
43  {
44  while ((csrptr->lsr & UART_LSR_THRE) == 0)
45  {
46  ;
47  }
48  csrptr->buffer = '\r';
49  }
50 
51  restore(mask);
52  return OK;
53 }
volatile uint32 lsr
Definition: uart.h:22
#define UART_LSR_THRE
Definition: uart.h:103
void restore(intmask)
volatile uint32 buffer
Definition: uart.h:15
#define CONSOLE
Definition: conf.h:28
#define OK
処理が成功した場合
Definition: kernel.h:77
Definition: conf.h:6
struct dentry devtab[]
Definition: conf.c:11
uint32 intmask
保存された割り込みマスク
Definition: kernel.h:38
void * dvcsr
Definition: conf.h:19
intmask disable(void)
割り込み禁止(intr.Sに定義がある)
Here is the call graph for this function:
Here is the caller graph for this function: